| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef QMDISUBWINDOW_P_H
|
|---|
| 43 | #define QMDISUBWINDOW_P_H
|
|---|
| 44 |
|
|---|
| 45 | //
|
|---|
| 46 | // W A R N I N G
|
|---|
| 47 | // -------------
|
|---|
| 48 | //
|
|---|
| 49 | // This file is not part of the Qt API. It exists purely as an
|
|---|
| 50 | // implementation detail. This header file may change from version to
|
|---|
| 51 | // version without notice, or even be removed.
|
|---|
| 52 | //
|
|---|
| 53 | // We mean it.
|
|---|
| 54 | //
|
|---|
| 55 |
|
|---|
| 56 | #include "qmdisubwindow.h"
|
|---|
| 57 |
|
|---|
| 58 | #ifndef QT_NO_MDIAREA
|
|---|
| 59 |
|
|---|
| 60 | #include <QStyle>
|
|---|
| 61 | #include <QStyleOptionTitleBar>
|
|---|
| 62 | #include <QMenuBar>
|
|---|
| 63 | #include <QSizeGrip>
|
|---|
| 64 | #include <QPointer>
|
|---|
| 65 | #include <QDebug>
|
|---|
| 66 | #include <private/qwidget_p.h>
|
|---|
| 67 |
|
|---|
| 68 | QT_BEGIN_NAMESPACE
|
|---|
| 69 |
|
|---|
| 70 | class QVBoxLayout;
|
|---|
| 71 | class QMouseEvent;
|
|---|
| 72 |
|
|---|
| 73 | namespace QMdi {
|
|---|
| 74 | template<typename T>
|
|---|
| 75 | class ControlElement : public T
|
|---|
| 76 | {
|
|---|
| 77 | public:
|
|---|
| 78 | ControlElement(QMdiSubWindow *child) : T(child, 0)
|
|---|
| 79 | {
|
|---|
| 80 | Q_ASSERT(child);
|
|---|
| 81 | mdiChild = child;
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | void *qt_metacast(const char *classname)
|
|---|
| 85 | {
|
|---|
| 86 | if (classname && strcmp(classname, "ControlElement") == 0)
|
|---|
| 87 | return this;
|
|---|
| 88 | return 0;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | QPointer<QMdiSubWindow> mdiChild;
|
|---|
| 92 | };
|
|---|
| 93 |
|
|---|
| 94 | class ControlContainer : public QObject
|
|---|
| 95 | {
|
|---|
| 96 | public:
|
|---|
| 97 | ControlContainer(QMdiSubWindow *mdiChild);
|
|---|
| 98 | ~ControlContainer();
|
|---|
| 99 |
|
|---|
| 100 | #ifndef QT_NO_MENUBAR
|
|---|
| 101 | void showButtonsInMenuBar(QMenuBar *menuBar);
|
|---|
| 102 | void removeButtonsFromMenuBar(QMenuBar *menuBar = 0);
|
|---|
| 103 | QMenuBar *menuBar() const { return m_menuBar; }
|
|---|
| 104 | #endif
|
|---|
| 105 | void updateWindowIcon(const QIcon &windowIcon);
|
|---|
| 106 | QWidget *controllerWidget() const { return m_controllerWidget; }
|
|---|
| 107 | QWidget *systemMenuLabel() const { return m_menuLabel; }
|
|---|
| 108 |
|
|---|
| 109 | private:
|
|---|
| 110 | QPointer<QWidget> previousLeft;
|
|---|
| 111 | QPointer<QWidget> previousRight;
|
|---|
| 112 | #ifndef QT_NO_MENUBAR
|
|---|
| 113 | QPointer<QMenuBar> m_menuBar;
|
|---|
| 114 | #endif
|
|---|
| 115 | QPointer<QWidget> m_controllerWidget;
|
|---|
| 116 | QPointer<QWidget> m_menuLabel;
|
|---|
| 117 | QPointer<QMdiSubWindow> mdiChild;
|
|---|
| 118 | };
|
|---|
| 119 | } // namespace QMdi
|
|---|
| 120 |
|
|---|
| 121 | class QMdiSubWindowPrivate : public QWidgetPrivate
|
|---|
| 122 | {
|
|---|
| 123 | Q_DECLARE_PUBLIC(QMdiSubWindow)
|
|---|
| 124 | public:
|
|---|
| 125 | // Enums and typedefs.
|
|---|
| 126 | enum Operation {
|
|---|
| 127 | None,
|
|---|
| 128 | Move,
|
|---|
| 129 | TopResize,
|
|---|
| 130 | BottomResize,
|
|---|
| 131 | LeftResize,
|
|---|
| 132 | RightResize,
|
|---|
| 133 | TopLeftResize,
|
|---|
| 134 | TopRightResize,
|
|---|
| 135 | BottomLeftResize,
|
|---|
| 136 | BottomRightResize
|
|---|
| 137 | };
|
|---|
| 138 |
|
|---|
| 139 | enum ChangeFlag {
|
|---|
| 140 | HMove = 0x01,
|
|---|
| 141 | VMove = 0x02,
|
|---|
| 142 | HResize = 0x04,
|
|---|
| 143 | VResize = 0x08,
|
|---|
| 144 | HResizeReverse = 0x10,
|
|---|
| 145 | VResizeReverse = 0x20
|
|---|
| 146 | };
|
|---|
| 147 |
|
|---|
| 148 | enum WindowStateAction {
|
|---|
| 149 | RestoreAction,
|
|---|
| 150 | MoveAction,
|
|---|
| 151 | ResizeAction,
|
|---|
| 152 | MinimizeAction,
|
|---|
| 153 | MaximizeAction,
|
|---|
| 154 | StayOnTopAction,
|
|---|
| 155 | CloseAction,
|
|---|
| 156 | /* Add new states _above_ this line! */
|
|---|
| 157 | NumWindowStateActions
|
|---|
| 158 | };
|
|---|
| 159 |
|
|---|
| 160 | struct OperationInfo {
|
|---|
| 161 | uint changeFlags;
|
|---|
| 162 | Qt::CursorShape cursorShape;
|
|---|
| 163 | QRegion region;
|
|---|
| 164 | bool hover;
|
|---|
| 165 | OperationInfo(uint changeFlags, Qt::CursorShape cursorShape, bool hover = true)
|
|---|
| 166 | : changeFlags(changeFlags),
|
|---|
| 167 | cursorShape(cursorShape),
|
|---|
| 168 | hover(hover)
|
|---|
| 169 | {}
|
|---|
| 170 | };
|
|---|
| 171 |
|
|---|
| 172 | typedef QMap<Operation, OperationInfo> OperationInfoMap;
|
|---|
| 173 |
|
|---|
| 174 | QMdiSubWindowPrivate();
|
|---|
| 175 |
|
|---|
| 176 | // Variables.
|
|---|
| 177 | QPointer<QWidget> baseWidget;
|
|---|
| 178 | QPointer<QWidget> restoreFocusWidget;
|
|---|
| 179 | QPointer<QMdi::ControlContainer> controlContainer;
|
|---|
| 180 | #ifndef QT_NO_SIZEGRIP
|
|---|
| 181 | QPointer<QSizeGrip> sizeGrip;
|
|---|
| 182 | #endif
|
|---|
| 183 | #ifndef QT_NO_RUBBERBAND
|
|---|
| 184 | QRubberBand *rubberBand;
|
|---|
| 185 | #endif
|
|---|
| 186 | QPoint mousePressPosition;
|
|---|
| 187 | QRect oldGeometry;
|
|---|
| 188 | QSize internalMinimumSize;
|
|---|
| 189 | QSize userMinimumSize;
|
|---|
| 190 | QSize restoreSize;
|
|---|
| 191 | bool resizeEnabled;
|
|---|
| 192 | bool moveEnabled;
|
|---|
| 193 | bool isInInteractiveMode;
|
|---|
| 194 | #ifndef QT_NO_RUBBERBAND
|
|---|
| 195 | bool isInRubberBandMode;
|
|---|
| 196 | #endif
|
|---|
| 197 | bool isShadeMode;
|
|---|
| 198 | bool ignoreWindowTitleChange;
|
|---|
| 199 | bool ignoreNextActivationEvent;
|
|---|
| 200 | bool activationEnabled;
|
|---|
| 201 | bool isShadeRequestFromMinimizeMode;
|
|---|
| 202 | bool isMaximizeMode;
|
|---|
| 203 | bool isWidgetHiddenByUs;
|
|---|
| 204 | bool isActive;
|
|---|
| 205 | bool isExplicitlyDeactivated;
|
|---|
| 206 | int keyboardSingleStep;
|
|---|
| 207 | int keyboardPageStep;
|
|---|
| 208 | int resizeTimerId;
|
|---|
| 209 | Operation currentOperation;
|
|---|
| 210 | QStyle::SubControl hoveredSubControl;
|
|---|
| 211 | QStyle::SubControl activeSubControl;
|
|---|
| 212 | Qt::FocusReason focusInReason;
|
|---|
| 213 | OperationInfoMap operationMap;
|
|---|
| 214 | QPointer<QMenu> systemMenu;
|
|---|
| 215 | #ifndef QT_NO_ACTIONS
|
|---|
| 216 | QPointer<QAction> actions[NumWindowStateActions];
|
|---|
| 217 | #endif
|
|---|
| 218 | QMdiSubWindow::SubWindowOptions options;
|
|---|
| 219 | QString lastChildWindowTitle;
|
|---|
| 220 | QPalette titleBarPalette;
|
|---|
| 221 | QString windowTitle;
|
|---|
| 222 | QFont font;
|
|---|
| 223 | QIcon menuIcon;
|
|---|
| 224 | QStyleOptionTitleBar cachedStyleOptions;
|
|---|
| 225 | QString originalTitle;
|
|---|
| 226 |
|
|---|
| 227 | // Slots.
|
|---|
| 228 | void _q_updateStaysOnTopHint();
|
|---|
| 229 | void _q_enterInteractiveMode();
|
|---|
| 230 | void _q_processFocusChanged(QWidget *old, QWidget *now);
|
|---|
| 231 |
|
|---|
| 232 | // Functions.
|
|---|
| 233 | void leaveInteractiveMode();
|
|---|
| 234 | void removeBaseWidget();
|
|---|
| 235 | void initOperationMap();
|
|---|
| 236 | #ifndef QT_NO_MENU
|
|---|
| 237 | void createSystemMenu();
|
|---|
| 238 | #endif
|
|---|
| 239 | void updateCursor();
|
|---|
| 240 | void updateDirtyRegions();
|
|---|
| 241 | void updateGeometryConstraints();
|
|---|
| 242 | void updateMask();
|
|---|
| 243 | void setNewGeometry(const QPoint &pos);
|
|---|
| 244 | void setMinimizeMode();
|
|---|
| 245 | void setNormalMode();
|
|---|
| 246 | void setMaximizeMode();
|
|---|
| 247 | void setActive(bool activate, bool changeFocus = true);
|
|---|
| 248 | void processClickedSubControl();
|
|---|
| 249 | QRegion getRegion(Operation operation) const;
|
|---|
| 250 | Operation getOperation(const QPoint &pos) const;
|
|---|
| 251 | QStyleOptionTitleBar titleBarOptions() const;
|
|---|
| 252 | void ensureWindowState(Qt::WindowState state);
|
|---|
| 253 | int titleBarHeight(const QStyleOptionTitleBar &options) const;
|
|---|
| 254 | void sizeParameters(int *margin, int *minWidth) const;
|
|---|
| 255 | bool drawTitleBarWhenMaximized() const;
|
|---|
| 256 | #ifndef QT_NO_MENUBAR
|
|---|
| 257 | QMenuBar *menuBar() const;
|
|---|
| 258 | void showButtonsInMenuBar(QMenuBar *menuBar);
|
|---|
| 259 | void removeButtonsFromMenuBar();
|
|---|
| 260 | #endif
|
|---|
| 261 | void updateWindowTitle(bool requestFromChild);
|
|---|
| 262 | #ifndef QT_NO_RUBBERBAND
|
|---|
| 263 | void enterRubberBandMode();
|
|---|
| 264 | void leaveRubberBandMode();
|
|---|
| 265 | #endif
|
|---|
| 266 | QPalette desktopPalette() const;
|
|---|
| 267 | void updateActions();
|
|---|
| 268 | void setFocusWidget();
|
|---|
| 269 | void restoreFocus();
|
|---|
| 270 | void setWindowFlags(Qt::WindowFlags windowFlags);
|
|---|
| 271 | void setVisible(WindowStateAction, bool visible = true);
|
|---|
| 272 | #ifndef QT_NO_ACTION
|
|---|
| 273 | void setEnabled(WindowStateAction, bool enable = true);
|
|---|
| 274 | #ifndef QT_NO_MENU
|
|---|
| 275 | void addToSystemMenu(WindowStateAction, const QString &text, const char *slot);
|
|---|
| 276 | #endif
|
|---|
| 277 | #endif // QT_NO_ACTION
|
|---|
| 278 | QSize iconSize() const;
|
|---|
| 279 | #ifndef QT_NO_SIZEGRIP
|
|---|
| 280 | void setSizeGrip(QSizeGrip *sizeGrip);
|
|---|
| 281 | void setSizeGripVisible(bool visible = true) const;
|
|---|
| 282 | #endif
|
|---|
| 283 | void updateInternalWindowTitle();
|
|---|
| 284 | QString originalWindowTitle();
|
|---|
| 285 | void setNewWindowTitle();
|
|---|
| 286 |
|
|---|
| 287 | inline int titleBarHeight() const
|
|---|
| 288 | {
|
|---|
| 289 | Q_Q(const QMdiSubWindow);
|
|---|
| 290 | if (!parent || q->windowFlags() & Qt::FramelessWindowHint
|
|---|
| 291 | || (q->isMaximized() && !drawTitleBarWhenMaximized())) {
|
|---|
| 292 | return 0;
|
|---|
| 293 | }
|
|---|
| 294 | QStyleOptionTitleBar options = titleBarOptions();
|
|---|
| 295 | int height = options.rect.height();
|
|---|
| 296 | if (hasBorder(options))
|
|---|
| 297 | height += q->isMinimized() ? 8 : 4;
|
|---|
| 298 | return height;
|
|---|
| 299 | }
|
|---|
| 300 |
|
|---|
| 301 | inline QStyle::SubControl getSubControl(const QPoint &pos) const
|
|---|
| 302 | {
|
|---|
| 303 | Q_Q(const QMdiSubWindow);
|
|---|
| 304 | QStyleOptionTitleBar titleBarOptions = this->titleBarOptions();
|
|---|
| 305 | return q->style()->hitTestComplexControl(QStyle::CC_TitleBar, &titleBarOptions, pos, q);
|
|---|
| 306 | }
|
|---|
| 307 |
|
|---|
| 308 | inline void setNewGeometry(QRect *geometry)
|
|---|
| 309 | {
|
|---|
| 310 | Q_Q(QMdiSubWindow);
|
|---|
| 311 | Q_ASSERT(parent);
|
|---|
| 312 | geometry->setSize(geometry->size().expandedTo(internalMinimumSize));
|
|---|
| 313 | #ifndef QT_NO_RUBBERBAND
|
|---|
| 314 | if (isInRubberBandMode)
|
|---|
| 315 | rubberBand->setGeometry(*geometry);
|
|---|
| 316 | else
|
|---|
| 317 | #endif
|
|---|
| 318 | q->setGeometry(*geometry);
|
|---|
| 319 | }
|
|---|
| 320 |
|
|---|
| 321 | inline bool hasBorder(const QStyleOptionTitleBar &options) const
|
|---|
| 322 | {
|
|---|
| 323 | Q_Q(const QMdiSubWindow);
|
|---|
| 324 | return !q->style()->styleHint(QStyle::SH_TitleBar_NoBorder, &options, q);
|
|---|
| 325 | }
|
|---|
| 326 |
|
|---|
| 327 | inline bool autoRaise() const
|
|---|
| 328 | {
|
|---|
| 329 | Q_Q(const QMdiSubWindow);
|
|---|
| 330 | return q->style()->styleHint(QStyle::SH_TitleBar_AutoRaise, 0, q);
|
|---|
| 331 | }
|
|---|
| 332 |
|
|---|
| 333 | inline bool isResizeOperation() const
|
|---|
| 334 | {
|
|---|
| 335 | return currentOperation != None && currentOperation != Move;
|
|---|
| 336 | }
|
|---|
| 337 |
|
|---|
| 338 | inline bool isMoveOperation() const
|
|---|
| 339 | {
|
|---|
| 340 | return currentOperation == Move;
|
|---|
| 341 | }
|
|---|
| 342 | };
|
|---|
| 343 |
|
|---|
| 344 | #endif // QT_NO_MDIAREA
|
|---|
| 345 |
|
|---|
| 346 | QT_END_NAMESPACE
|
|---|
| 347 |
|
|---|
| 348 | #endif // QMDISUBWINDOW_P_H
|
|---|