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