itom
Loading...
Searching...
No Matches
abstractDockWidget.h
1/* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2020, Institut für Technische Optik (ITO),
5 Universität Stuttgart, Germany
6
7 This file is part of itom.
8
9 itom is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Library General Public Licence as published by
11 the Free Software Foundation; either version 2 of the Licence, or (at
12 your option) any later version.
13
14 itom is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17 General Public Licence for more details.
18
19 You should have received a copy of the GNU Library General Public License
20 along with itom. If not, see <http://www.gnu.org/licenses/>.
21*********************************************************************** */
22
23#ifndef ABSTRACTDOCKWIDGET_H
24#define ABSTRACTDOCKWIDGET_H
25
26#include "../global.h"
27#include "../common/sharedStructures.h"
28#include "shortcutAction.h"
29
30#include <qmainwindow.h>
31#include <qdockwidget.h>
32#include <qmenubar.h>
33#include <qevent.h>
34#include <qmap.h>
35#include <qtoolbar.h>
36#include <qdebug.h>
37#include <qstring.h>
38#include <qaction.h>
39#include <qshortcut.h>
40#include <qrect.h>
41#include <qwidget.h>
42
43
44namespace ito
45{
54 class AbstractDockWidget : public QDockWidget
55 {
56 Q_OBJECT
57
58 //these properties are taken from QWidget in order to redirect them either to the QDockWidget or to the main window (depending on dock status)
59 Q_PROPERTY(bool visible READ isVisible WRITE setVisible DESIGNABLE false)
60 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
61
62 Q_PROPERTY(QRect geometry READ geometry WRITE setGeometry)
63 Q_PROPERTY(QRect frameGeometry READ frameGeometry)
64 Q_PROPERTY(QRect normalGeometry READ normalGeometry)
65 Q_PROPERTY(int x READ x)
66 Q_PROPERTY(int y READ y)
67 Q_PROPERTY(QPoint pos READ pos WRITE move DESIGNABLE false STORED false)
68 Q_PROPERTY(QSize frameSize READ frameSize)
69 Q_PROPERTY(QSize size READ size WRITE resize DESIGNABLE false STORED false)
70 Q_PROPERTY(int width READ width)
71 Q_PROPERTY(int height READ height)
72 Q_PROPERTY(QRect rect READ rect)
73 Q_PROPERTY(QRect childrenRect READ childrenRect)
74 Q_PROPERTY(QRegion childrenRegion READ childrenRegion)
75 Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle)
76
77 public:
78
80
94
101
103
115
116 struct Toolbar
117 {
118 Toolbar() : section(0), key(""), tb(NULL) {}
119 Qt::ToolBarArea area;
120 int section;
121 QString key;
122 QToolBar *tb;
123 };
124
125 AbstractDockWidget(bool docked, bool isDockAvailable, tFloatingStyle floatingStyle, tMovingStyle movingStyle, const QString &title = QString(), const QString &objName = QString(), QWidget *parent = 0);
126 virtual ~AbstractDockWidget();
127
129 bool docked() const
130 {
131 return m_docked;
132 }
133
134 RetVal setTopLevel( tTopLevelStyle topLevel, bool showWindow = true );
135
136 void setParent ( QWidget * parent ) { m_overallParent = parent; QDockWidget::setParent(parent); }
137
138 QWidget *getActiveInstance()
139 {
141 {
142 return m_pWindow;
143 }
144 return this;
145 }
146
147 //these methods are mainly redirected to QDockWidget or QMainWindow (depending on dock status)
148 #define QWIDGETPROPGETTER(gettername) if(m_docked && m_dockAvailable) { return QDockWidget::gettername(); } else { return m_pWindow->gettername(); }
149
150 #define QWIDGETPROPSETTER(settername,...) \
151 if (m_docked) \
152 { \
153 QDockWidget::settername(__VA_ARGS__); \
154 } \
155 else \
156 { \
157 if (m_floatingStyle == floatingWindow) \
158 { \
159 m_pWindow->settername(__VA_ARGS__); \
160 QDockWidget::settername(__VA_ARGS__); \
161 } \
162 else \
163 { \
164 QDockWidget::settername(__VA_ARGS__); \
165 } \
166 }
167
168 #define QWIDGETPROPSETTERSPECIAL(settername,...) \
169 if (m_docked) \
170 { \
171 QDockWidget::settername(__VA_ARGS__); \
172 } \
173 else \
174 { \
175 if (m_floatingStyle == floatingWindow) \
176 { \
177 m_pWindow->settername(__VA_ARGS__); \
178 } \
179 else \
180 { \
181 QDockWidget::settername(__VA_ARGS__); \
182 } \
183 }
184
185 QRect frameGeometry() const;
186 const QRect &geometry() const;
187 QRect normalGeometry() const;
188
189 int x() const;
190 int y() const;
191 QPoint pos() const;
192 QSize frameSize() const;
193 QSize size() const;
194 int width() const;
195 int height() const;
196 QRect rect() const;
197 QRect childrenRect() const;
198 QRegion childrenRegion() const;
199
200 void move(int x, int y);
201 void move(const QPoint &);
202 void resize(int w, int h);
203 void resize(const QSize &);
204 void setGeometry(int x, int y, int w, int h);
205 void setGeometry(const QRect &);
206 void setMinimumSize(const QSize &size);
207
208 QString windowTitle();
209 void setWindowTitle(const QString &title);
210 bool isEnabled() const;
211 bool isVisible() const;
212
213 void saveState(const QString &iniName) const;
214 void restoreState(const QString &iniName);
215
217
218 virtual QSize sizeHint() const;
219 virtual QSize minimumSizeHint() const;
220
221 protected:
222
223 friend class ShortcutAction; //to access canvas of this dock widget
224
226
231 bool eventFilter(QObject *obj, QEvent *event)
232 {
233 if (event->type() == QEvent::Close)
234 {
235 closeEvent((QCloseEvent*)event);
236 if(testAttribute(Qt::WA_DeleteOnClose) && event->isAccepted() ) //if window should be closed and dockwidget is assigned with WA_DeleteOnClose, delete this dockwidget first.
237 {
238 deleteLater();
239 }
240
241 return true;
242 }
243 else
244 {
245 return QObject::eventFilter(obj,event);
246 }
247 };
248
249 void init();
250
251 virtual void closeEvent(QCloseEvent *event);
252
253 virtual void createActions() = 0;
254 virtual void createMenus() = 0;
255 virtual void createToolBars() = 0;
256 virtual void createStatusBar() = 0;
257 virtual void updateActions() {}
258 virtual void updatePythonActions() = 0;
259
260 Qt::WindowFlags modifyFlags(const Qt::WindowFlags &flags, const Qt::WindowFlags &setFlags, const Qt::WindowFlags &unsetFlags);
261
262 virtual void windowStateChanged( bool /*windowNotToolbox*/ ) {}
263
264 void setContentWidget(QWidget *widget);
265 inline QWidget* getContentWidget() const { return m_pWindow->centralWidget(); }
266 inline QMainWindow* getCanvas() { return m_pWindow; }
267
268 inline bool pythonBusy() const { return m_pythonBusy; }
269 inline bool pythonDebugMode() const { return m_pythonDebugMode; }
270 inline bool pythonInWaitingMode() const { return m_pythonInWaitingMode; }
272 //RetVal addAndRegisterToolBar(QToolBar* tb, QString key);
273 //RetVal unregisterToolBar(QString key);
274 QToolBar* getToolBar(QString key) const;
275 inline QMenuBar* getMenuBar() const { return (m_pWindow == NULL) ? NULL : m_pWindow->menuBar(); }
276
277 RetVal addToolBar(QToolBar *tb, const QString &key, Qt::ToolBarArea area = Qt::TopToolBarArea, int section = 1);
278 RetVal removeToolBar(const QString &key);
279
280 QAction *m_actStayOnTop;
281 QAction *m_actStayOnTopOfApp;
282
283 private:
284
285 void contextMenuEvent(QContextMenuEvent *e)
286 {
287 e->accept();
288 qDebug() << "context menu of abstractDockWidget clicked. [placeholder for (un)docking feature.] pos: " << e->pos();
289 }
290
291 QMainWindow *m_pWindow;
292
293 bool m_docked;
297 QString m_basicTitle;
300 QMap<QString,QToolBar*> m_toolBars;
301 QList<Toolbar> m_toolbars;
302
307 QToolBar* m_dockToolbar;
308 QAction* m_actDock;
309 QAction* m_actUndock;
310
312 tTopLevelStyle m_recentTopLevelStyle;
313
314 QSize m_oldMinSize;
315 QSize m_oldMaxSize;
316 QRect m_lastUndockedSize;
317 QByteArray m_pendingGeometryState; //if the window has a loaded geometry state from the settings file, but has been hidden at startup, the geometry is saved here and applied once the window becomes visible. Then, this variable is cleared.
318
319 public Q_SLOTS:
320 void setEnabled(bool);
321 virtual void setVisible(bool visible);
322
323 virtual void pythonStateChanged(tPythonTransitions pyTransition);
324
325 void raiseAndActivate();
326 void mini();
327
328 void setDockSize(int newWidth, int newHeight);
329
330 void dockWidget();
331 void undockWidget(bool show_it = true);
332
333 RetVal setAdvancedWindowTitle(QString newCompleteTitle = QString(), bool appendToBasicTitle = true);
334
335 private slots:
336 void mnuStayOnTop(bool checked);
337 void mnuStayOnTopOfApp(bool checked);
338
339 void returnToOldMinMaxSizes();
340
341 Q_SIGNALS:
342 void dockStateChanged(bool docked);
343 };
344
345} //end namespace ito
346
347#endif
abstract dock widget class which inherits QDockWidget. The content of QDockWidget consists of an inst...
Definition abstractDockWidget.h:55
bool pythonBusy() const
Definition abstractDockWidget.h:268
void raiseAndActivate()
activates this dock widget or window and raises it on top of all opened windows
Definition abstractDockWidget.cpp:1072
tMovingStyle
The configuration if a docked AbstractDockWidget can be moved from one docking area to another one.
Definition abstractDockWidget.h:97
@ movingEnabled
Definition abstractDockWidget.h:99
@ movingDisabled
Definition abstractDockWidget.h:98
virtual ~AbstractDockWidget()
destructor
Definition abstractDockWidget.cpp:129
QToolBar * getToolBar(QString key) const
returns reference to toolbar with given key-value
Definition abstractDockWidget.cpp:721
void dockWidget()
docks this dockWidget.
Definition abstractDockWidget.cpp:798
void setContentWidget(QWidget *widget)
sets any given QWidget as central widget of QMainWindow and inversely sets this QWidget's parent to t...
Definition abstractDockWidget.cpp:526
AbstractDockWidget(bool docked, bool isDockAvailable, tFloatingStyle floatingStyle, tMovingStyle movingStyle, const QString &title=QString(), const QString &objName=QString(), QWidget *parent=0)
constructor
Definition abstractDockWidget.cpp:67
void synchronizeTopLevelState()
synchronizes the top level state of the dock widget with the floating settings of this abstract dock ...
Definition abstractDockWidget.cpp:1179
tTopLevelStyle
The top level style of a widget, derived from AbstractDockWidget.
Definition abstractDockWidget.h:110
@ topLevelOverall
Definition abstractDockWidget.h:111
@ topLevelNothing
Definition abstractDockWidget.h:113
@ topLevelParentOnly
Definition abstractDockWidget.h:112
bool m_pythonInWaitingMode
Definition abstractDockWidget.h:305
bool m_docked
Definition abstractDockWidget.h:293
tFloatingStyle m_floatingStyle
Definition abstractDockWidget.h:295
bool m_pythonBusy
Definition abstractDockWidget.h:303
void undockWidget(bool show_it=true)
undocks this dockWidget.
Definition abstractDockWidget.cpp:873
RetVal setAdvancedWindowTitle(QString newCompleteTitle=QString(), bool appendToBasicTitle=true)
changes the title of widget
Definition abstractDockWidget.cpp:549
tFloatingStyle
The floating style of a widget, derived from AbstractDockWidget.
Definition abstractDockWidget.h:89
@ floatingStandard
Definition abstractDockWidget.h:91
@ floatingWindow
Definition abstractDockWidget.h:92
@ floatingNone
Definition abstractDockWidget.h:90
QString m_completeTitle
Definition abstractDockWidget.h:298
virtual void pythonStateChanged(tPythonTransitions pyTransition)
slot invoked if python state changed. Sets the specific member variables according to the python tran...
Definition abstractDockWidget.cpp:755
bool m_dockAvailable
Definition abstractDockWidget.h:294
QWidget * getContentWidget() const
Definition abstractDockWidget.h:265
void dockStateChanged(bool docked)
emitted if the widget is either docked or undocked from the main window
virtual void closeEvent(QCloseEvent *event)
closeEvent invoked if this AbstractDockWidget should be closed
Definition abstractDockWidget.cpp:744
QWidget * m_overallParent
Definition abstractDockWidget.h:311
bool pythonInWaitingMode() const
Definition abstractDockWidget.h:270
void init()
init method, called by constructor
Definition abstractDockWidget.cpp:152
tMovingStyle m_movingStyle
Definition abstractDockWidget.h:296
bool m_pythonDebugMode
Definition abstractDockWidget.h:304
bool eventFilter(QObject *obj, QEvent *event)
eventFilter for m_pWindow
Definition abstractDockWidget.h:231
bool pythonDebugMode() const
Definition abstractDockWidget.h:269
QString m_basicTitle
Definition abstractDockWidget.h:297
QMap< QString, QToolBar * > m_toolBars
Definition abstractDockWidget.h:300
Class for managing status values (like errors or warning)
Definition retVal.h:54
Definition apiFunctionsGraph.cpp:40
Definition abstractDockWidget.h:117