gsplash
Loading...
Searching...
No Matches
gsplash_example.cc
Go to the documentation of this file.
1
21// gsplash
22#include "gsplash.h"
23
24// qt
25#include <QApplication>
26#include <QMainWindow>
27
41int main(int argc, char* argv[]) {
42 // Initialize options and logging for the module.
43 auto gopts = std::make_shared<GOptions>(argc, argv, gsplash::defineOptions());
44 auto log = std::make_shared<GLogger>(gopts, SFUNCTION_NAME, GSPLASH_LOGGER);
45
46 // Read runtime configuration:
47 // - gui controls whether we instantiate QApplication and show the splash.
48 // - tt controls how long the example remains active in GUI mode.
49 auto gui = gopts->getSwitch("gui");
50 auto timeout = gopts->getScalarDouble("tt");
51
52 int ret = EXIT_SUCCESS;
53
54 log->info(0, "Starting gsplash example...");
55
56 // Optional GUI setup (only if --gui is passed).
57 QApplication* app = nullptr;
58 QMainWindow* window = nullptr;
59
60 if (gui) {
61 log->info(0, "g4dialog", "Running in GUI mode...");
62
63 // Create the Qt application and a main window to demonstrate returning focus.
64 app = new QApplication(argc, argv);
65 window = new QMainWindow();
66 window->setWindowTitle(QString::fromUtf8("displayUI example"));
67
68 // Create the splash screen and display messages.
69 // The factory returns nullptr when GUI is disabled; here we are in GUI mode by construction.
70 auto gsplash = GSplash::create(gopts, "example.png");
71 if (gsplash) {
72 gsplash->message("Some text I want to show");
73 gsplash->messageAfter(500, "Some other text I want to show");
74 }
75
76 window->show();
77
78 // Quit after timeout. Notice the additional delay needed for the messageAfter.
79 QTimer::singleShot(timeout + 500, [] {
80 QCoreApplication::quit(); // Stop the event loop.
81 });
82
83 ret = QApplication::exec();
84
85 // Clean up heap-allocated Qt objects.
86 delete window;
87 delete app;
88
89 }
90 else {
91 // CLI mode (no QApplication is created).
92 log->info(0, "Running gsplash in command line mode...");
93 }
94
95 return ret;
96}
static std::unique_ptr< GSplash > create(const std::shared_ptr< GOptions > &gopts, const std::string &imageName="gemcArchitecture")
Factory method for creating a GSplash instance.
Definition gsplash.cc:8
#define SFUNCTION_NAME
constexpr const char * GSPLASH_LOGGER
Default logger name used by this module.
Definition gsplash.h:21
Namespace utilities for the GSplash module.
Definition gsplash.h:27
GOptions defineOptions()
Defines the module options for GSplash.
Definition gsplash.h:41
int main(int argc, char *argv[])