KanoopGuiQt 1.3.0
Qt GUI utility library
Loading...
Searching...
No Matches
mainwindowbase.h
1/******************************************************************************************
2**
3** mainwindowbase.h
4**
5** Moved from my Tesseract Engineering repo to open-source
6**
7** Author: Stephen Punak
8** Created: Fri Oct 27 09:12:34 2023
9**
10******************************************************************************************/
11#ifndef MAINWINDOWBASE_H
12#define MAINWINDOWBASE_H
13
14#include <QMainWindow>
15
16#include <Kanoop/utility/loggingbaseclass.h>
17#include <Kanoop/gui/libkanoopgui.h>
18#include <Kanoop/timespan.h>
19#include <Kanoop/gui/widgets/statusbar.h>
20
21class QMdiArea;
22
23/**
24 * @brief QMainWindow subclass providing logging, status bar helpers, and geometry persistence.
25 *
26 * MainWindowBase wires a StatusBar, persists window position/size across sessions, and
27 * exposes slots for showing plain or animated status messages. Call initializeBase()
28 * from the subclass constructor after building the UI.
29 */
30class LIBKANOOPGUI_EXPORT MainWindowBase : public QMainWindow,
31 public LoggingBaseClass
32{
33 Q_OBJECT
34public:
35 /**
36 * @brief Construct with a logging category and optional parent.
37 * @param loggingCategory Category name used for log output
38 * @param parent Optional QWidget parent
39 */
40 explicit MainWindowBase(const QString& loggingCategory, QWidget *parent = nullptr);
41
42 /**
43 * @brief Return whether the window persists its position between sessions.
44 * @return true if position persistence is enabled
45 */
46 bool persistPosition() const { return _persistPosition; }
47
48 /**
49 * @brief Enable or disable position persistence.
50 * @param value true to persist position
51 */
52 void setPersistPosition(bool value) { _persistPosition = value; }
53
54 /**
55 * @brief Return whether the window persists its size between sessions.
56 * @return true if size persistence is enabled
57 */
58 bool persistSize() const { return _persistSize; }
59
60 /**
61 * @brief Enable or disable size persistence.
62 * @param value true to persist size
63 */
64 void setPersistSize(bool value) { _persistSize = value; }
65
66 /**
67 * @brief Return the application-defined window type integer.
68 * @return Window type value
69 */
70 int type() const { return _type; }
71
72 /**
73 * @brief Set the application-defined window type integer.
74 * @param value Window type value
75 */
76 void setType(int value) { _type = value; }
77
78 /**
79 * @brief Return the default window size.
80 * @return Default QSize
81 */
82 QSize defaultSize() const { return _defaultSize; }
83
84 /**
85 * @brief Set the default window size.
86 * @param value Default QSize
87 */
88 void setDefaultSize(const QSize& value) { _defaultSize = value; }
89
90 /**
91 * @brief Set the default window size by width and height.
92 * @param width Default width in pixels
93 * @param height Default height in pixels
94 */
95 void setDefaultSize(int width, int height) { _defaultSize = QSize(width, height); }
96
97public slots:
98 /**
99 * @brief Show a coloured status message with an optional timeout.
100 * @param text Message text
101 * @param textColor Foreground colour for the message
102 * @param timeout Duration before the message is cleared (default: no timeout)
103 */
104 void showStatusBarMessage(const QString &text, const QColor& textColor, const TimeSpan& timeout = TimeSpan());
105
106 /**
107 * @brief Show a default-coloured status message with an optional timeout.
108 * @param text Message text
109 * @param timeout Duration before the message is cleared (default: no timeout)
110 */
111 void showStatusBarMessage(const QString& text, const TimeSpan& timeout = TimeSpan());
112
113 /**
114 * @brief Show an animated progress message in the status bar.
115 * @param text Message text (dots are appended periodically)
116 * @param textColor Foreground colour (default: palette default)
117 */
118 void showStatusBarAnimatedProgressMessage(const QString &text, const QColor& textColor = QColor());
119
120 /** @brief Stop any active status bar animation. */
122
123public:
124 /**
125 * @brief Return the parent QMdiArea if this window is hosted in one.
126 * @return Pointer to the parent MdiArea, or nullptr
127 */
128 QMdiArea* parentMdiArea();
129
130 /**
131 * @brief Return the built-in StatusBar widget.
132 * @return Pointer to the StatusBar
133 */
135
136 /**
137 * @brief Return whether the form has finished loading.
138 * @return true if form load is complete
139 */
140 bool formLoadComplete() const { return _formLoadComplete; }
141
142 /**
143 * @brief Return whether the form failed to load.
144 * @return true if form load failed
145 */
146 bool formLoadFailed() const { return _formLoadFailed; }
147
148protected:
149 /** @brief Perform base-class initialization; call from the subclass constructor. */
151
152 /**
153 * @brief Set the form load completion flag.
154 * @param value true when form load is complete
155 */
156 void setFormLoadComplete(bool value) { _formLoadComplete = value; }
157
158 /**
159 * @brief Set the form load failure flag.
160 * @param value true if form load failed
161 */
162 void setFormLoadFailed(bool value) { _formLoadFailed = value; }
163
164 /** @brief Persist position on move. */
165 virtual void moveEvent(QMoveEvent *event) override;
166 /** @brief Persist size on resize. */
167 virtual void resizeEvent(QResizeEvent *event) override;
168 /** @brief Restore geometry and complete form load on first show. */
169 virtual void showEvent(QShowEvent *event) override;
170
171private:
172 int _type = 0;
173 bool _formLoadComplete = false;
174 bool _formLoadFailed = false;
175 bool _persistPosition = true;
176 bool _persistSize = true;
177 QSize _defaultSize;
178 StatusBar* _statusBar = nullptr;
179
180signals:
181
182public slots:
183 /** @brief Called when application preferences change; override to react. */
184 virtual void onPreferencesChanged();
185
186private slots:
187 /** @brief Persist splitter state when moved. */
188 void onSpliltterMoved();
189
190};
191
192#endif // MAINWINDOWBASE_H
QMainWindow subclass providing logging, status bar helpers, and geometry persistence.
void setType(int value)
Set the application-defined window type integer.
void setFormLoadComplete(bool value)
Set the form load completion flag.
void setDefaultSize(const QSize &value)
Set the default window size.
void setPersistSize(bool value)
Enable or disable size persistence.
void showStatusBarAnimatedProgressMessage(const QString &text, const QColor &textColor=QColor())
Show an animated progress message in the status bar.
bool persistSize() const
Return whether the window persists its size between sessions.
virtual void moveEvent(QMoveEvent *event) override
Persist position on move.
StatusBar * statusBar()
Return the built-in StatusBar widget.
QSize defaultSize() const
Return the default window size.
void setFormLoadFailed(bool value)
Set the form load failure flag.
void stopStatusBarAnimation()
Stop any active status bar animation.
bool persistPosition() const
Return whether the window persists its position between sessions.
void showStatusBarMessage(const QString &text, const TimeSpan &timeout=TimeSpan())
Show a default-coloured status message with an optional timeout.
bool formLoadFailed() const
Return whether the form failed to load.
int type() const
Return the application-defined window type integer.
void initializeBase()
Perform base-class initialization; call from the subclass constructor.
QMdiArea * parentMdiArea()
Return the parent QMdiArea if this window is hosted in one.
virtual void showEvent(QShowEvent *event) override
Restore geometry and complete form load on first show.
bool formLoadComplete() const
Return whether the form has finished loading.
virtual void resizeEvent(QResizeEvent *event) override
Persist size on resize.
void setDefaultSize(int width, int height)
Set the default window size by width and height.
void showStatusBarMessage(const QString &text, const QColor &textColor, const TimeSpan &timeout=TimeSpan())
Show a coloured status message with an optional timeout.
MainWindowBase(const QString &loggingCategory, QWidget *parent=nullptr)
Construct with a logging category and optional parent.
virtual void onPreferencesChanged()
Called when application preferences change; override to react.
void setPersistPosition(bool value)
Enable or disable position persistence.
QStatusBar subclass with timed messages, color styling, and animated progress text.
Definition statusbar.h:18