swift
Loading...
Searching...
No Matches
guiapplication.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#ifndef SWIFT_GUI_GUIAPPLICATION_H
7#define SWIFT_GUI_GUIAPPLICATION_H
8
9#include <QCommandLineOption>
10#include <QDialog>
11#include <QEvent>
12#include <QObject>
13#include <QPixmap>
14#include <QScopedPointer>
15#include <QScreen>
16#include <QString>
17#include <Qt>
18
19#include "core/application.h"
21#include "gui/mainwindowaccess.h"
24#include "gui/splashscreen.h"
26#include "gui/swiftguiexport.h"
27#include "misc/icons.h"
28#include "misc/statusmessage.h"
29
30class QMenu;
31class QWidget;
32class QMainWindow;
33
34namespace swift::misc
35{
36 class CLogCategoryList;
37}
39{
42} // namespace swift::gui::components
43namespace swift::gui
44{
57 class SWIFT_GUI_EXPORT CGuiApplication : public swift::core::CApplication, public IMainWindowAccess
58 {
60 Q_INTERFACES(swift::gui::IMainWindowAccess)
61
62 public:
64 static CGuiApplication *instance();
65
67 static const QStringList &getLogCategories();
68
70 static const QString &settingsOrganization();
71
74
76 explicit CGuiApplication(
77 const QString &applicationName = executable(),
78 swift::misc::CApplicationInfo::Application application = swift::misc::CApplicationInfo::Unknown,
80
82 ~CGuiApplication() override;
83
86
89
92
95
98
100 void processEventsToRefreshGui() const;
101
104 void initMainApplicationWidget(QWidget *mainWidget);
105
108
110 QString setExtraWindowTitle(const QString &extraInfo,
111 QWidget *mainWindowWidget = mainApplicationWidget()) const;
112
115 void cmdLineErrorMessage(const QString &text, const QString &informativeText) const override;
116 void cmdLineErrorMessage(const swift::misc::CStatusMessageList &msgs) const override;
118
120 bool isCmdWindowSizeResetSet() const;
121
124 bool displayInStatusBar(const swift::misc::CStatusMessage &message) override;
126 std::chrono::milliseconds timeout = std::chrono::milliseconds(0)) override;
128 std::chrono::milliseconds timeout = std::chrono::milliseconds(0)) override;
129 bool displayInOverlayWindow(const QString &html,
130 std::chrono::milliseconds timeout = std::chrono::milliseconds(0)) override;
132
133 // -------- Splash screen related ---------
135 void splashScreen(const QPixmap &pixmap);
136
137 // -------- Splash screen related ---------
138
141
143 void addMenuForStyleSheets(QMenu &menu);
144
146 void addMenuFile(QMenu &menu);
147
149 void addMenuInternals(QMenu &menu);
150
152 void addMenuWindow(QMenu &menu);
153
155 void openUrl(const swift::misc::network::CUrl &url);
156
158 void addMenuHelp(QMenu &menu);
159
161 void showHelp(const QString &subpath = {}) const;
162
164 void showChangelog() const;
165
168
170 QString getWidgetStyle() const;
171
173 bool reloadStyleSheets();
174
177
180
183
185 bool updateFont(const QString &fontFamily, const QString &fontSize, const QString &fontStyle,
186 const QString &fontWeight, const QString &fontColor);
187
189 bool updateFont(const QString &qss);
190
192 bool resetFont();
193
196 void setMinimumSizeInCharacters(int widthChars, int heightChars);
197
200
204
206 void triggerNewVersionCheck(int delayedMs);
207
209 void gracefulShutdown() override;
210
212 bool toggleStayOnTop();
213
216 void windowToFront();
217 void windowToBack();
220
223
225 void setSaveMainWidgetState(bool save) { m_saveMainWidgetState = save; }
226
228 bool saveWindowGeometryAndState(const QMainWindow *window = CGuiApplication::mainApplicationWindow()) const;
229
231 void resetWindowGeometryAndState();
232
234 bool restoreWindowGeometryAndState(QMainWindow *window = CGuiApplication::mainApplicationWindow());
235
238 static void setWindowIcon(const QPixmap &icon);
239
241 static QWidget *mainApplicationWidget();
242
244 void registerMainApplicationWidget(QWidget *mainWidget);
245
247 bool hasMinimumMappingVersion() const override;
248
250 static QMainWindow *mainApplicationWindow();
251
253 static swift::gui::IMainWindowAccess *mainWindowAccess();
254
256 static void exit(int retcode = 0);
257
259 static QScreen *currentScreen();
260
263 static QRect currentScreenGeometry();
264
266 static void modalWindowToFront();
267
268 signals:
271
274
277
279 void alwaysOnTop(bool onTop);
280
281 protected:
283 bool parsingHookIn() override;
284
286 void onCoreFacadeStarted() override;
287
289 void onStartUpCompleted() override;
290
292 void checkNewVersion(bool onlyIfNew);
293
295 QString getFontInfo() const;
296
298 static void registerMetadata();
299
300 private:
301 QPixmap m_windowIcon;
302 QString m_fontFamily;
303 int m_fontPointSize;
304 int m_minWidthChars = -1;
305 int m_minHeightChars = -1;
306 QCommandLineOption m_cmdWindowStateMinimized { "emptyMinimized" };
307 QCommandLineOption m_cmdWindowMode { "emptyWindowMode" };
308 QCommandLineOption m_cmdWindowSizeReset { "emptySizeReset" };
309 CStyleSheetUtility m_styleSheetUtility { this };
310 bool m_uiSetupCompleted = false;
311 bool m_saveMainWidgetState = true;
312 bool m_frontBack = true;
313 bool m_normalizeMinimize = true;
314 QScopedPointer<CSplashScreen> m_splashScreen;
315 components::CUpdateInfoDialog *m_updateDialog = nullptr;
316 components::CApplicationCloseDialog *m_closeDialog =
317 nullptr;
318 swift::misc::CSettingReadOnly<settings::TGeneralGui> m_guiSettings { this, &CGuiApplication::settingsChanged };
319 swift::misc::CSettingReadOnly<settings::TUpdateNotificationSettings> m_updateSetting {
320 this
321 };
322
324 void settingsChanged();
325
327 void checkNewVersionMenu();
328
330 void adjustPalette();
331
333 void onStyleSheetsChanged();
334
336 void setCurrentFontValues();
337
339 void superviseWindowMinSizes();
340
342 static const QString &fileForWindowGeometryAndStateSettings();
343
345 static int hashForStateSettingsSchema(const QMainWindow *window);
346 };
347} // namespace swift::gui
348
351
352#endif // SWIFT_GUI_GUIAPPLICATION_H
static const QString & executable()
executable name
GUI application, a specialized version of swift::core::CApplication for GUI applications.
bool openStandardWidgetStyleSheet()
Opens the standard stylesheet.
bool isCmdWindowSizeResetSet() const
Window size reset mode set.
QString setExtraWindowTitle(const QString &extraInfo, QWidget *mainWindowWidget=mainApplicationWidget()) const
Set window title.
QString getFontInfo() const
Info about font.
void onCoreFacadeStarted()
Called when facade/contexts have been started.
void addWindowResetSizeOption()
CMD line arguments (reset size store).
void addWindowStateOption()
CMD line arguments.
void processEventsToRefreshGui() const
Allow the GUI to refresh by processing events, call the event loop.
Qt::WindowState getWindowState() const
Window state.
static const QString & settingsOrganization()
Organization string used for settings, is the registry key under windows.
void addWindowModeOption()
CMD line arguments.
void triggerNewVersionCheck(int delayedMs)
Trigger new version check.
bool openStandardCrashDumpDirectory()
Opens the standard dumps directory.
static CGuiApplication * instance()
Similar to.
void windowToFront()
Window to front/back.
CEnableForFramelessWindow::WindowMode getWindowMode() const
Window mode (window flags).
void addMenuHelp(QMenu &menu)
Help operations.
void addMenuForStyleSheets(QMenu &menu)
Add menu for style sheets.
bool reloadStyleSheets()
Reload style sheets.
void cmdLineErrorMessage(const QString &text, const QString &informativeText) const
print messages generated during parsing / cmd handling
void addMenuFile(QMenu &menu)
File menu.
void addMenuInternals(QMenu &menu)
Internals menu.
bool displayInOverlayWindow(const swift::misc::CStatusMessage &message, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
direct access to main application window
void checkNewVersion(bool onlyIfNew)
Check for a new version (update).
void splashScreen(const QPixmap &pixmap)
Add a splash screen based on resource, empty means remove splash screen.
void fontChanged()
Font has been changed.
const CStyleSheetUtility & getStyleSheetUtility() const
Style sheet handling.
QDialog::DialogCode showCloseDialog(QMainWindow *mainWindow, QCloseEvent *closeEvent)
Show close dialog.
void windowToBack()
Window to front/back.
void gracefulShutdown()
Graceful shutdown.
void onStartUpCompleted()
Startup completed.
bool toggleStayOnTop()
Toggle stay on top.
void windowToFrontBackToggle()
Window to front/back.
static void registerMetadata()
Register metadata.
bool resetFont()
Reset the font to default.
void setSaveMainWidgetState(bool save)
Save the main widget state?
void displaySetupLoadFailure(swift::misc::CStatusMessageList msgs)
Display the failures caused by loading the setup file.
void windowMinimizeNormalToggle()
Window minimize/normalize.
void addMenuForSettingsAndCache(QMenu &menu)
Add menu items for settings and cache.
bool updateFont(const QString &fontFamily, const QString &fontSize, const QString &fontStyle, const QString &fontWeight, const QString &fontColor)
Update the fonts.
void showHelp(const QString &subpath={}) const
Show help page (online help).
bool displayInStatusBar(const swift::misc::CStatusMessage &message)
direct access to main application window
void alwaysOnTop(bool onTop)
always on top
static QWidget * mainApplicationWidget()
Main application window widget.
static QMainWindow * mainApplicationWindow()
Main application window.
bool parsingHookIn()
Handle parsing of special GUI cmd arguments.
void uiObjectTreeReady()
Object tree ready (means ui->setupUi() completed).
static bool removeAllWindowsSwiftRegistryEntries()
Remove all registry entries.
void openUrl(const swift::misc::network::CUrl &url)
Open a given URL.
bool openStandardLogDirectory()
Opens the standard log directory.
static const QStringList & getLogCategories()
Own log categories.
void addMenuWindow(QMenu &menu)
Window operations.
void initMainApplicationWidget(QWidget *mainWidget)
Init the main application window based on information in this application.
void addWindowFlags(Qt::WindowFlags flags)
Set window flag on main application window.
QString getWidgetStyle() const
Current widget style.
void showChangelog() const
Show changelog popup.
void styleSheetsChanged()
Style sheet changed.
void setMinimumSizeInCharacters(int widthChars, int heightChars)
Set minimum width/height in characters.
CGuiApplication(const QString &applicationName=executable(), swift::misc::CApplicationInfo::Application application=swift::misc::CApplicationInfo::Unknown, const QPixmap &icon=swift::misc::CIcons::swift64())
Constructor.
Reads and provides style sheets.
Application
Enumeration of application roles.
static const QPixmap & swift64()
swift icon
A sequence of log categories.
Streamable status message, e.g.
Status messages, e.g. from Core -> GUI.
Value object encapsulating information of a location, kind of simplified CValueObject compliant versi...
Definition url.h:27
High level reusable GUI components.
GUI related classes.
Free functions in swift::misc.
Q_INTERFACES(...)
Q_OBJECTQ_OBJECT
WindowState
typedef WindowFlags
#define SWIFT_GUI_EXPORT
Export a class or function from the library.