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 QMDIAREA_H
41 #define QMDIAREA_H
42 
43 #include <QtWidgets/qtwidgetsglobal.h>
44 #include <QtWidgets/qabstractscrollarea.h>
45 #if QT_CONFIG(tabwidget)
46 #include <QtWidgets/qtabwidget.h>
47 #endif
48 
49 QT_REQUIRE_CONFIG(mdiarea);
50 
51 QT_BEGIN_NAMESPACE
52 
53 class QMdiSubWindow;
54 
55 class QMdiAreaPrivate;
56 class Q_WIDGETS_EXPORT QMdiArea : public QAbstractScrollArea
57 {
58     Q_OBJECT
59     Q_PROPERTY(QBrush background READ background WRITE setBackground)
60     Q_PROPERTY(WindowOrder activationOrder READ activationOrder WRITE setActivationOrder)
61     Q_PROPERTY(ViewMode viewMode READ viewMode WRITE setViewMode)
62 #if QT_CONFIG(tabbar)
63     Q_PROPERTY(bool documentMode READ documentMode WRITE setDocumentMode)
64     Q_PROPERTY(bool tabsClosable READ tabsClosable WRITE setTabsClosable)
65     Q_PROPERTY(bool tabsMovable READ tabsMovable WRITE setTabsMovable)
66 #endif
67 #if QT_CONFIG(tabwidget)
68     Q_PROPERTY(QTabWidget::TabShape tabShape READ tabShape WRITE setTabShape)
69     Q_PROPERTY(QTabWidget::TabPosition tabPosition READ tabPosition WRITE setTabPosition)
70 #endif
71 public:
72     enum AreaOption {
73         DontMaximizeSubWindowOnActivation = 0x1
74     };
75     Q_DECLARE_FLAGS(AreaOptions, AreaOption)
76 
77     enum WindowOrder {
78         CreationOrder,
79         StackingOrder,
80         ActivationHistoryOrder
81     };
82     Q_ENUM(WindowOrder)
83 
84     enum ViewMode {
85         SubWindowView,
86         TabbedView
87     };
88     Q_ENUM(ViewMode)
89 
90     QMdiArea(QWidget *parent = nullptr);
91     ~QMdiArea();
92 
93     QSize sizeHint() const override;
94     QSize minimumSizeHint() const override;
95 
96     QMdiSubWindow *currentSubWindow() const;
97     QMdiSubWindow *activeSubWindow() const;
98     QList<QMdiSubWindow *> subWindowList(WindowOrder order = CreationOrder) const;
99 
100     QMdiSubWindow *addSubWindow(QWidget *widget, Qt::WindowFlags flags = Qt::WindowFlags());
101     void removeSubWindow(QWidget *widget);
102 
103     QBrush background() const;
104     void setBackground(const QBrush &background);
105 
106     WindowOrder activationOrder() const;
107     void setActivationOrder(WindowOrder order);
108 
109     void setOption(AreaOption option, bool on = true);
110     bool testOption(AreaOption opton) const;
111 
112     void setViewMode(ViewMode mode);
113     ViewMode viewMode() const;
114 
115 #if QT_CONFIG(tabbar)
116     bool documentMode() const;
117     void setDocumentMode(bool enabled);
118 
119     void setTabsClosable(bool closable);
120     bool tabsClosable() const;
121 
122     void setTabsMovable(bool movable);
123     bool tabsMovable() const;
124 #endif
125 #if QT_CONFIG(tabwidget)
126     void setTabShape(QTabWidget::TabShape shape);
127     QTabWidget::TabShape tabShape() const;
128 
129     void setTabPosition(QTabWidget::TabPosition position);
130     QTabWidget::TabPosition tabPosition() const;
131 #endif
132 
133 Q_SIGNALS:
134     void subWindowActivated(QMdiSubWindow *);
135 
136 public Q_SLOTS:
137     void setActiveSubWindow(QMdiSubWindow *window);
138     void tileSubWindows();
139     void cascadeSubWindows();
140     void closeActiveSubWindow();
141     void closeAllSubWindows();
142     void activateNextSubWindow();
143     void activatePreviousSubWindow();
144 
145 protected Q_SLOTS:
146     void setupViewport(QWidget *viewport) override;
147 
148 protected:
149     bool event(QEvent *event) override;
150     bool eventFilter(QObject *object, QEvent *event) override;
151     void paintEvent(QPaintEvent *paintEvent) override;
152     void childEvent(QChildEvent *childEvent) override;
153     void resizeEvent(QResizeEvent *resizeEvent) override;
154     void timerEvent(QTimerEvent *timerEvent) override;
155     void showEvent(QShowEvent *showEvent) override;
156     bool viewportEvent(QEvent *event) override;
157     void scrollContentsBy(int dx, int dy) override;
158 
159 private:
160     Q_DISABLE_COPY(QMdiArea)
161     Q_DECLARE_PRIVATE(QMdiArea)
162     Q_PRIVATE_SLOT(d_func(), void _q_deactivateAllWindows())
163     Q_PRIVATE_SLOT(d_func(), void _q_processWindowStateChanged(Qt::WindowStates, Qt::WindowStates))
164     Q_PRIVATE_SLOT(d_func(), void _q_currentTabChanged(int))
165     Q_PRIVATE_SLOT(d_func(), void _q_closeTab(int))
166     Q_PRIVATE_SLOT(d_func(), void _q_moveTab(int, int))
167 };
168 
169 Q_DECLARE_OPERATORS_FOR_FLAGS(QMdiArea::AreaOptions)
170 
171 QT_END_NAMESPACE
172 
173 #endif // QMDIAREA_H
174