1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtWidgets module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QDYNAMICMAINWINDOW_H
41#define QDYNAMICMAINWINDOW_H
42
43#include <QtWidgets/qtwidgetsglobal.h>
44#include <QtWidgets/qwidget.h>
45#if QT_CONFIG(tabwidget)
46#include <QtWidgets/qtabwidget.h>
47#endif
48
49QT_REQUIRE_CONFIG(mainwindow);
50
51QT_BEGIN_NAMESPACE
52
53class QDockWidget;
54class QMainWindowPrivate;
55class QMenuBar;
56class QStatusBar;
57class QToolBar;
58class QMenu;
59
60class Q_WIDGETS_EXPORT QMainWindow : public QWidget
61{
62 Q_OBJECT
63
64 Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
65 Q_PROPERTY(Qt::ToolButtonStyle toolButtonStyle READ toolButtonStyle WRITE setToolButtonStyle)
66#if QT_CONFIG(dockwidget)
67 Q_PROPERTY(bool animated READ isAnimated WRITE setAnimated)
68#if QT_CONFIG(tabbar)
69 Q_PROPERTY(bool documentMode READ documentMode WRITE setDocumentMode)
70#endif // QT_CONFIG(tabbar)
71#if QT_CONFIG(tabwidget)
72 Q_PROPERTY(QTabWidget::TabShape tabShape READ tabShape WRITE setTabShape)
73#endif // QT_CONFIG(tabwidget)
74 Q_PROPERTY(bool dockNestingEnabled READ isDockNestingEnabled WRITE setDockNestingEnabled)
75#endif // QT_CONFIG(dockwidget)
76 Q_PROPERTY(DockOptions dockOptions READ dockOptions WRITE setDockOptions)
77#if QT_CONFIG(toolbar)
78 Q_PROPERTY(bool unifiedTitleAndToolBarOnMac READ unifiedTitleAndToolBarOnMac WRITE setUnifiedTitleAndToolBarOnMac)
79#endif
80
81public:
82 enum DockOption {
83 AnimatedDocks = 0x01,
84 AllowNestedDocks = 0x02,
85 AllowTabbedDocks = 0x04,
86 ForceTabbedDocks = 0x08, // implies AllowTabbedDocks, !AllowNestedDocks
87 VerticalTabs = 0x10, // implies AllowTabbedDocks
88 GroupedDragging = 0x20 // implies AllowTabbedDocks
89 };
90 Q_ENUM(DockOption)
91 Q_DECLARE_FLAGS(DockOptions, DockOption)
92 Q_FLAG(DockOptions)
93
94 explicit QMainWindow(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags());
95 ~QMainWindow();
96
97 QSize iconSize() const;
98 void setIconSize(const QSize &iconSize);
99
100 Qt::ToolButtonStyle toolButtonStyle() const;
101 void setToolButtonStyle(Qt::ToolButtonStyle toolButtonStyle);
102
103#if QT_CONFIG(dockwidget)
104 bool isAnimated() const;
105 bool isDockNestingEnabled() const;
106#endif
107
108#if QT_CONFIG(tabbar)
109 bool documentMode() const;
110 void setDocumentMode(bool enabled);
111#endif
112
113#if QT_CONFIG(tabwidget)
114 QTabWidget::TabShape tabShape() const;
115 void setTabShape(QTabWidget::TabShape tabShape);
116 QTabWidget::TabPosition tabPosition(Qt::DockWidgetArea area) const;
117 void setTabPosition(Qt::DockWidgetAreas areas, QTabWidget::TabPosition tabPosition);
118#endif // QT_CONFIG(tabwidget)
119
120 void setDockOptions(DockOptions options);
121 DockOptions dockOptions() const;
122
123 bool isSeparator(const QPoint &pos) const;
124
125#if QT_CONFIG(menubar)
126 QMenuBar *menuBar() const;
127 void setMenuBar(QMenuBar *menubar);
128
129 QWidget *menuWidget() const;
130 void setMenuWidget(QWidget *menubar);
131#endif
132
133#if QT_CONFIG(statusbar)
134 QStatusBar *statusBar() const;
135 void setStatusBar(QStatusBar *statusbar);
136#endif
137
138 QWidget *centralWidget() const;
139 void setCentralWidget(QWidget *widget);
140
141 QWidget *takeCentralWidget();
142
143#if QT_CONFIG(dockwidget)
144 void setCorner(Qt::Corner corner, Qt::DockWidgetArea area);
145 Qt::DockWidgetArea corner(Qt::Corner corner) const;
146#endif
147
148#if QT_CONFIG(toolbar)
149 void addToolBarBreak(Qt::ToolBarArea area = Qt::TopToolBarArea);
150 void insertToolBarBreak(QToolBar *before);
151
152 void addToolBar(Qt::ToolBarArea area, QToolBar *toolbar);
153 void addToolBar(QToolBar *toolbar);
154 QToolBar *addToolBar(const QString &title);
155 void insertToolBar(QToolBar *before, QToolBar *toolbar);
156 void removeToolBar(QToolBar *toolbar);
157 void removeToolBarBreak(QToolBar *before);
158
159 bool unifiedTitleAndToolBarOnMac() const;
160
161 Qt::ToolBarArea toolBarArea(
162#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
163 const
164#endif
165 QToolBar *toolbar) const;
166 bool toolBarBreak(QToolBar *toolbar) const;
167#endif
168#if QT_CONFIG(dockwidget)
169 void addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockwidget);
170 void addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockwidget,
171 Qt::Orientation orientation);
172 void splitDockWidget(QDockWidget *after, QDockWidget *dockwidget,
173 Qt::Orientation orientation);
174#if QT_CONFIG(tabbar)
175 void tabifyDockWidget(QDockWidget *first, QDockWidget *second);
176 QList<QDockWidget*> tabifiedDockWidgets(QDockWidget *dockwidget) const;
177#endif
178 void removeDockWidget(QDockWidget *dockwidget);
179 bool restoreDockWidget(QDockWidget *dockwidget);
180
181 Qt::DockWidgetArea dockWidgetArea(QDockWidget *dockwidget) const;
182
183 void resizeDocks(const QList<QDockWidget *> &docks,
184 const QList<int> &sizes, Qt::Orientation orientation);
185#endif // QT_CONFIG(dockwidget)
186
187 QByteArray saveState(int version = 0) const;
188 bool restoreState(const QByteArray &state, int version = 0);
189
190#if QT_CONFIG(menu)
191 virtual QMenu *createPopupMenu();
192#endif
193
194public Q_SLOTS:
195#if QT_CONFIG(dockwidget)
196 void setAnimated(bool enabled);
197 void setDockNestingEnabled(bool enabled);
198#endif
199#if QT_CONFIG(toolbar)
200 void setUnifiedTitleAndToolBarOnMac(bool set);
201#endif
202
203Q_SIGNALS:
204 void iconSizeChanged(const QSize &iconSize);
205 void toolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle);
206#if QT_CONFIG(dockwidget)
207 void tabifiedDockWidgetActivated(QDockWidget *dockWidget);
208#endif
209
210protected:
211#ifndef QT_NO_CONTEXTMENU
212 void contextMenuEvent(QContextMenuEvent *event) override;
213#endif
214 bool event(QEvent *event) override;
215
216private:
217 Q_DECLARE_PRIVATE(QMainWindow)
218 Q_DISABLE_COPY(QMainWindow)
219};
220
221Q_DECLARE_OPERATORS_FOR_FLAGS(QMainWindow::DockOptions)
222
223QT_END_NAMESPACE
224
225#endif // QDYNAMICMAINWINDOW_H
226