swift
dockwidget.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2014 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_DOCKWIDGET_H
7 #define SWIFT_GUI_DOCKWIDGET_H
8 
9 #include <QDockWidget>
10 #include <QMargins>
11 #include <QObject>
12 #include <QPoint>
13 #include <QSize>
14 #include <QString>
15 
17 #include "gui/managedstatusbar.h"
20 #include "gui/swiftguiexport.h"
21 #include "misc/statusmessage.h"
22 #include "misc/statusmessagelist.h"
23 
24 class QCloseEvent;
25 class QMenu;
26 class QMouseEvent;
27 class QPaintEvent;
28 class QWidget;
29 class QWidgetAction;
30 
31 namespace swift::gui
32 {
33  namespace components
34  {
35  class CMarginsInput;
36  }
37  namespace menus
38  {
39  class CFontMenu;
40  }
41 
52  {
53  Q_OBJECT
54 
55  public:
57  void setOriginalTitleBar();
58 
60  void setEmptyTitleBar();
61 
63  void setNullTitleBarWidget();
64 
66  const QString &windowTitleBackup() const { return m_windowTitleBackup; }
67 
69  QString windowTitleOrBackup() const;
70 
72  bool showTitleWhenDocked() const { return m_windowTitleWhenDocked; }
73 
75  bool isSelected() const { return m_selected; }
76 
79  bool isWidgetVisible() const;
80 
82  void allowStatusBar(bool allow) { m_allowStatusBar = allow; }
83 
85  void showTitleWhenDocked(bool show);
86 
88  void resetWasAlreadyFloating();
89 
91  bool wasAlreadyFloating() const { return m_wasAlreadyFloating; }
92 
94  void setPreferredSizeWhenFloating(const QSize &size);
95 
97  void setOffsetWhenFloating(const QPoint &point, bool frameless);
98 
100  virtual void setFrameless(bool frameless) override;
101 
103  void toggleFloating();
104 
106  void toggleVisibility();
107 
109  void toggleFrameless();
110 
112  // void toggleFramelessDeferred(int delayMs = 1000);
113 
115  void windowAlwaysOnTop();
116 
118  void windowNotAlwaysOnTop();
119 
121  void setAlwaysOnTop(bool onTop) { m_alwaysOnTop = onTop; }
122 
124  bool restoreFromSettings();
125 
127  void saveCurrentStateToSettings();
128 
130  void resetSettings();
131 
133  void resetPosition();
134 
136  void setWindowTitle(const QString &title);
137 
139  void displayStatusMessage(const swift::misc::CStatusMessage &statusMessage);
140 
142  void displayStatusMessages(const swift::misc::CStatusMessageList &statusMessages);
143 
145  static const QString &propertyOuterWidget();
146 
148  static const QString &propertyInnerWidget();
149 
150  signals:
152  void widgetTopLevelChanged(CDockWidget *, bool topLevel);
153 
156  void fontSizePlus();
159 
160  protected:
162  explicit CDockWidget(QWidget *parent = nullptr);
163 
165  CDockWidget(bool allowStatusBar, QWidget *parent = nullptr);
166 
168  void setMargins();
169 
171  void setMarginsWhenFloating(const QMargins &margins);
172 
174  void setMarginsWhenFloating(int left, int top, int right, int bottom);
175 
177  QMargins getMarginsWhenFloating() const;
178 
180  void setMarginsWhenFramelessFloating(const QMargins &margins);
181 
183  void setMarginsWhenFramelessFloating(int left, int top, int right, int bottom);
184 
186  QMargins getMarginsWhenFramelessFloating() const;
187 
189  void setMarginsWhenDocked(const QMargins &margins);
190 
192  void setMarginsWhenDocked(int left, int top, int right, int bottom);
193 
195  QMargins getMarginsWhenDocked() const;
196 
198  void setAlwaysOnTopFlag(bool onTop);
199 
201  virtual void closeEvent(QCloseEvent *event) override;
202 
204  virtual void paintEvent(QPaintEvent *event) override;
205 
207  virtual void mouseMoveEvent(QMouseEvent *event) override;
208 
210  virtual void keyPressEvent(QKeyEvent *event) override;
211 
213  virtual void mousePressEvent(QMouseEvent *event) override;
214 
216  virtual void addToContextMenu(QMenu *contextMenu) const;
217 
221  virtual void initialFloating();
222 
224  virtual void onStyleSheetsChanged();
225 
226  private:
227  QWidget *m_titleBarWidgetEmpty = nullptr;
228  QWidget *m_titleBarWidgetOriginal = nullptr;
229  QWidgetAction *m_marginMenuAction = nullptr;
230  components::CMarginsInput *m_input = nullptr;
231  menus::CFontMenu *m_fontMenu = nullptr;
232  bool m_allowStatusBar = true;
233  bool m_windowTitleWhenDocked = true;
234  bool m_wasAlreadyFloating = false;
235  bool m_selected = false;
236  bool m_dockWidgetVisible = false;
237  bool m_wasFrameless = false;
238  bool m_alwaysOnTop = false;
239  CManagedStatusBar m_statusBar;
240  QString m_windowTitleBackup;
241  QSize m_preferredSizeWhenFloating;
242  QSize m_initialDockedMinimumSize;
243  QSize m_lastFloatingSize;
244  QPoint m_offsetWhenFloating;
245  QPoint m_lastFloatingPosition;
246  Qt::DockWidgetAreas m_originalAreas;
247 
248  swift::misc::CSetting<swift::gui::settings::TDockWidget> m_settings { this, &CDockWidget::settingsChanged };
249 
251  void onTopLevelChanged(bool topLevel);
252 
254  void showContextMenu(const QPoint &pos);
255 
257  void onVisibilityChanged(bool visible);
258 
260  void menuChangeMargins(const QMargins &margins);
261 
263  void settingsChanged();
264 
266  void dummy();
267 
269  void initTitleBarWidgets();
270 
272  void initStatusBarAndProperties();
273 
275  void forceStyleSheetUpdate();
276 
278  void rememberFloatingSizeAndPosition();
279 
281  void restoreFloatingSizeAndPosition();
282 
284  void restoreFloatingSizeAndPositionDeferred();
285 
287  settings::CDockWidgetSettings getSettings() const;
288 
290  void saveSettings(const swift::gui::settings::CDockWidgetSettings &settings);
291  };
292 } // namespace swift::gui
293 
294 #endif // SWIFT_GUI_DOCKWIDGET_H
Our base class for dockable widgets containing some specialized functionality on top of QDockWidget.
Definition: dockwidget.h:52
void setAlwaysOnTop(bool onTop)
Set always on top.
Definition: dockwidget.h:121
void widgetTopLevelChanged(CDockWidget *, bool topLevel)
Top level has changed for given widget.
void allowStatusBar(bool allow)
Allow a status bar to be displayed.
Definition: dockwidget.h:82
bool wasAlreadyFloating() const
Was widget already floating?
Definition: dockwidget.h:91
void fontSizeMinus()
Font size signals.
bool isSelected() const
Selected when tabbed.
Definition: dockwidget.h:75
void fontSizePlus()
Font size signals.
const QString & windowTitleBackup() const
Window title backup.
Definition: dockwidget.h:66
bool showTitleWhenDocked() const
Window title when window is docked.
Definition: dockwidget.h:72
Main window which can be frameless.
Using this class provides a QDockWidget with the overlay functionality already integrated.
Widget alows to enter margins.
Definition: marginsinput.h:24
Standard font (size, style) menus. Can be used as nested menu or via getActions added manually.
Definition: fontmenus.h:21
Streamable status message, e.g.
Status messages, e.g. from Core -> GUI.
GUI related classes.
#define SWIFT_GUI_EXPORT
Export a class or function from the library.