Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qmdisubwindow_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QMDISUBWINDOW_P_H
5#define QMDISUBWINDOW_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtWidgets/private/qtwidgetsglobal_p.h>
19#include "qmdisubwindow.h"
20
21#include <QStyle>
22#include <QStyleOptionTitleBar>
23#if QT_CONFIG(menubar)
24#include <QMenuBar>
25#endif
26#if QT_CONFIG(sizegrip)
27#include <QSizeGrip>
28#endif
29#include <QBasicTimer>
30#include <QPointer>
31#include <private/qwidget_p.h>
32
33QT_REQUIRE_CONFIG(mdiarea);
34
35QT_BEGIN_NAMESPACE
36
37class QVBoxLayout;
38class QMouseEvent;
39
40namespace QMdi {
41template<typename T>
42class ControlElement : public T // ELFVERSION:ignore
43{
44public:
45 ControlElement(QMdiSubWindow *child) : T(nullptr)
46 {
47 Q_ASSERT(child);
48 mdiChild = child;
49 }
50
51 void *qt_metacast(const char *classname) override
52 {
53 if (classname && strcmp(classname, "ControlElement") == 0)
54 return this;
55 return nullptr;
56 }
57
59};
60
61class ControlContainer : public QObject // ELFVERSION:ignore
62{
63public:
64 ControlContainer(QMdiSubWindow *mdiChild);
66
67#if QT_CONFIG(menubar)
70 QMenuBar *menuBar() const { return m_menuBar; }
71#endif
72 void updateWindowIcon(const QIcon &windowIcon);
73 QWidget *controllerWidget() const { return m_controllerWidget; }
74 QWidget *systemMenuLabel() const { return m_menuLabel; }
75
76private:
77 QPointer<QWidget> previousLeft;
78 QPointer<QWidget> previousRight;
79#if QT_CONFIG(menubar)
81#endif
82 QPointer<QWidget> m_controllerWidget;
83 QPointer<QWidget> m_menuLabel;
84 QPointer<QMdiSubWindow> mdiChild;
85};
86} // namespace QMdi
87
88class Q_AUTOTEST_EXPORT QMdiSubWindowPrivate : public QWidgetPrivate
89{
90 Q_DECLARE_PUBLIC(QMdiSubWindow)
91public:
92 // Enums and typedefs.
93 enum Operation {
94 None,
95 Move,
96 TopResize,
97 BottomResize,
98 LeftResize,
99 RightResize,
100 TopLeftResize,
101 TopRightResize,
102 BottomLeftResize,
103 BottomRightResize
104 };
105
106 enum ChangeFlag {
107 HMove = 0x01,
108 VMove = 0x02,
109 HResize = 0x04,
110 VResize = 0x08,
111 HResizeReverse = 0x10,
112 VResizeReverse = 0x20
113 };
114
115 enum WindowStateAction {
116 RestoreAction,
117 MoveAction,
118 ResizeAction,
119 MinimizeAction,
120 MaximizeAction,
121 StayOnTopAction,
122 CloseAction,
123 /* Add new states _above_ this line! */
124 NumWindowStateActions
125 };
126
127 struct OperationInfo {
128 uint changeFlags;
129 Qt::CursorShape cursorShape;
130 QRegion region;
131 bool hover;
132 OperationInfo(uint changeFlags, Qt::CursorShape cursorShape, bool hover = true)
133 : changeFlags(changeFlags),
134 cursorShape(cursorShape),
135 hover(hover)
136 {}
137 };
138
139 typedef QMap<Operation, OperationInfo> OperationInfoMap;
140
141 QMdiSubWindowPrivate();
142
143 // Variables.
144 QPointer<QWidget> baseWidget;
145 QPointer<QWidget> restoreFocusWidget;
146 QPointer<QMdi::ControlContainer> controlContainer;
147#if QT_CONFIG(sizegrip)
148 QPointer<QSizeGrip> sizeGrip;
149#endif
150#if QT_CONFIG(rubberband)
151 QRubberBand *rubberBand;
152#endif
153 QPoint mousePressPosition;
154 QRect oldGeometry;
155 QSize internalMinimumSize;
156 QSize userMinimumSize;
157 QSize restoreSize;
158 bool resizeEnabled;
159 bool moveEnabled;
160 bool isInInteractiveMode;
161#if QT_CONFIG(rubberband)
162 bool isInRubberBandMode;
163#endif
164 bool isShadeMode;
165 bool ignoreWindowTitleChange;
166 bool ignoreNextActivationEvent;
167 bool activationEnabled;
168 bool isShadeRequestFromMinimizeMode;
169 bool isMaximizeMode;
170 bool isWidgetHiddenByUs;
171 bool isActive;
172 bool isExplicitlyDeactivated;
173 int keyboardSingleStep;
174 int keyboardPageStep;
175 QBasicTimer resizeTimer;
176 Operation currentOperation;
177 QStyle::SubControl hoveredSubControl;
178 QStyle::SubControl activeSubControl;
179 Qt::FocusReason focusInReason;
180 OperationInfoMap operationMap;
181 QPointer<QMenu> systemMenu;
182#ifndef QT_NO_ACTION
183 QPointer<QAction> actions[NumWindowStateActions];
184#endif
185 QMdiSubWindow::SubWindowOptions options;
186 QString lastChildWindowTitle;
187 QPalette titleBarPalette;
188 QString windowTitle;
189 QFont font;
190 QIcon menuIcon;
191 QStyleOptionTitleBar cachedStyleOptions;
192 QString originalTitle;
193
194 // Slots.
195 void _q_updateStaysOnTopHint();
196 void _q_enterInteractiveMode();
197 void _q_processFocusChanged(QWidget *old, QWidget *now);
198
199 // Functions.
200 void leaveInteractiveMode();
201 void removeBaseWidget();
202 void initOperationMap();
203#if QT_CONFIG(menu)
204 void createSystemMenu();
205#endif
206 void updateCursor();
207 void updateDirtyRegions();
208 void updateGeometryConstraints();
209 void updateMask();
210 void setNewGeometry(const QPoint &pos);
211 void setMinimizeMode();
212 void setNormalMode();
213 void setMaximizeMode();
214 void setActive(bool activate, bool changeFocus = true);
215 void processClickedSubControl();
216 QRegion getRegion(Operation operation) const;
217 Operation getOperation(const QPoint &pos) const;
218 QStyleOptionTitleBar titleBarOptions() const;
219 void ensureWindowState(Qt::WindowState state);
220 int titleBarHeight(const QStyleOptionTitleBar &options) const;
221 void sizeParameters(int *margin, int *minWidth) const;
222 bool drawTitleBarWhenMaximized() const;
223#if QT_CONFIG(menubar)
224 QMenuBar *menuBar() const;
225 void showButtonsInMenuBar(QMenuBar *menuBar);
226 void removeButtonsFromMenuBar();
227#endif
228 void updateWindowTitle(bool requestFromChild);
229#if QT_CONFIG(rubberband)
230 void enterRubberBandMode();
231 void leaveRubberBandMode();
232#endif
233 QPalette desktopPalette() const;
234 void updateActions();
235 void setFocusWidget();
236 bool restoreFocus();
237 void storeFocusWidget();
238 void setWindowFlags(Qt::WindowFlags windowFlags) override;
239 using QWidgetPrivate::setVisible;
240 void setVisible(WindowStateAction, bool visible = true);
241#ifndef QT_NO_ACTION
242 void setEnabled(WindowStateAction, bool enable = true);
243#if QT_CONFIG(menu)
244 void addToSystemMenu(WindowStateAction, const QString &text, const char *slot);
245#endif
246#endif // QT_NO_ACTION
247 QSize iconSize() const;
248#if QT_CONFIG(sizegrip)
249 void setSizeGrip(QSizeGrip *sizeGrip);
250 void setSizeGripVisible(bool visible = true) const;
251#endif
252 void updateInternalWindowTitle();
253 QString originalWindowTitle();
254 QString originalWindowTitleHelper() const;
255 void setNewWindowTitle();
256
257 inline int titleBarHeight() const
258 {
259 Q_Q(const QMdiSubWindow);
260 if (!parent || q->windowFlags() & Qt::FramelessWindowHint
261 || (q->isMaximized() && !drawTitleBarWhenMaximized())) {
262 return 0;
263 }
264 QStyleOptionTitleBar options = titleBarOptions();
265 int height = options.rect.height();
266 if (hasBorder(options))
267 height += q->isMinimized() ? 8 : 4;
268 return height;
269 }
270
271 inline QStyle::SubControl getSubControl(const QPoint &pos) const
272 {
273 Q_Q(const QMdiSubWindow);
274 QStyleOptionTitleBar titleBarOptions = this->titleBarOptions();
275 return q->style()->hitTestComplexControl(QStyle::CC_TitleBar, &titleBarOptions, pos, q);
276 }
277
278 inline void setNewGeometry(QRect *geometry)
279 {
280 Q_Q(QMdiSubWindow);
281 Q_ASSERT(parent);
282 geometry->setSize(geometry->size().expandedTo(internalMinimumSize));
283#if QT_CONFIG(rubberband)
284 if (isInRubberBandMode)
285 rubberBand->setGeometry(*geometry);
286 else
287#endif
288 q->setGeometry(*geometry);
289 }
290
291 inline bool hasBorder(const QStyleOptionTitleBar &options) const
292 {
293 Q_Q(const QMdiSubWindow);
294 return !q->style()->styleHint(QStyle::SH_TitleBar_NoBorder, &options, q);
295 }
296
297 inline bool autoRaise() const
298 {
299 Q_Q(const QMdiSubWindow);
300 return q->style()->styleHint(QStyle::SH_TitleBar_AutoRaise, nullptr, q);
301 }
302
303 inline bool isResizeOperation() const
304 {
305 return currentOperation != None && currentOperation != Move;
306 }
307
308 inline bool isMoveOperation() const
309 {
310 return currentOperation == Move;
311 }
312};
313
314QT_END_NAMESPACE
315
316#endif // QMDISUBWINDOW_P_H
QWidget * controllerWidget() const
QWidget * systemMenuLabel() const
void updateWindowIcon(const QIcon &windowIcon)
ControlContainer(QMdiSubWindow *mdiChild)
QPointer< QMdiSubWindow > mdiChild
void * qt_metacast(const char *classname) override
ControlElement(QMdiSubWindow *child)
QSize sizeHint() const override
bool event(QEvent *event) override
This virtual function receives events to an object and should return true if the event e was recogniz...
void mousePressEvent(QMouseEvent *mouseEvent) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
void mouseReleaseEvent(QMouseEvent *mouseEvent) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
void mouseDoubleClickEvent(QMouseEvent *mouseEvent) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse double click...
void paintEvent(QPaintEvent *paintEvent) override
This event handler can be reimplemented in a subclass to receive paint events passed in event.
bool event(QEvent *event) override
This virtual function receives events to an object and should return true if the event e was recogniz...
void mousePressEvent(QMouseEvent *event) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
void mouseReleaseEvent(QMouseEvent *event) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
void setControlVisible(QMdiSubWindowPrivate::WindowStateAction action, bool visible)
void mouseMoveEvent(QMouseEvent *event) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
void leaveEvent(QEvent *event) override
This event handler can be reimplemented in a subclass to receive widget leave events which are passed...
QSize sizeHint() const override
bool hasVisibleControls() const
void paintEvent(QPaintEvent *event) override
This event handler can be reimplemented in a subclass to receive paint events passed in event.
Combined button and popup list for selecting options.
static const int BoundaryMargin
static bool isChildOfQMdiSubWindow(const QWidget *child)
static const int NumSubControls
static const QStyle::SubControl SubControls[]
static int getMoveDeltaComponent(uint cflags, uint moveFlag, uint resizeFlag, int delta, int maxDelta, int minDelta)
static bool isHoverControl(QStyle::SubControl control)
static const Qt::WindowFlags CustomizeWindowFlags
static int getResizeDeltaComponent(uint cflags, uint resizeFlag, uint resizeReverseFlag, int delta)
static bool isMacStyle(QStyle *style)
QString qt_setWindowTitle_helperHelper(const QString &, const QWidget *)
Returns a modified window title with the [*] place holder replaced according to the rules described i...
Definition qwidget.cpp:6000
static ControlElement< T > * ptr(QWidget *widget)
static bool isChildOfTabbedQMdiArea(const QMdiSubWindow *child)