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