Qt 4.8
qmdisubwindow_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui 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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
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 
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 
92 };
93 
94 class ControlContainer : public QObject
95 {
96 public:
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:
112 #ifndef QT_NO_MENUBAR
114 #endif
118 };
119 } // namespace QMdi
120 
122 {
124 public:
125  // Enums and typedefs.
126  enum Operation {
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 
156  /* Add new states _above_ this line! */
157  NumWindowStateActions
158  };
159 
160  struct OperationInfo {
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 
173 
175 
176  // Variables.
180 #ifndef QT_NO_SIZEGRIP
182 #endif
183 #ifndef QT_NO_RUBBERBAND
185 #endif
194 #ifndef QT_NO_RUBBERBAND
196 #endif
204  bool isActive;
213  OperationInfoMap operationMap;
215 #ifndef QT_NO_ACTIONS
216  QPointer<QAction> actions[NumWindowStateActions];
217 #endif
218  QMdiSubWindow::SubWindowOptions options;
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  {
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 
347 
348 #endif // QMDISUBWINDOW_P_H
SubControl
This enum describes the available sub controls.
Definition: qstyle.h:402
bool isMoveOperation() const
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QSizeGrip class provides a resize handle for resizing top-level windows.
Definition: qsizegrip.h:55
QPointer< QWidget > restoreFocusWidget
QPointer< QMdiSubWindow > mdiChild
The QStyleOptionTitleBar class is used to describe the parameters for drawing a title bar...
Definition: qstyleoption.h:816
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
int titleBarHeight() const
QSize expandedTo(const QSize &) const
Returns a size holding the maximum width and height of this size and the given otherSize.
Definition: qsize.h:187
QStyleOptionTitleBar cachedStyleOptions
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
QPointer< QWidget > m_controllerWidget
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
QMdiSubWindow::SubWindowOptions options
#define Q_Q(Class)
Definition: qglobal.h:2483
QPointer< QMenuBar > m_menuBar
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void setGeometry(const QRect &r)
Sets the geometry of the rubber band to rect, specified in the coordinate system of its parent widget...
void setNewGeometry(QRect *geometry)
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
void setSize(const QSize &s)
Sets the size of the rectangle to the given size.
Definition: qrect.h:448
QPointer< QWidget > m_menuLabel
unsigned int uint
Definition: qglobal.h:996
QPointer< QMdi::ControlContainer > controlContainer
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
QPointer< QWidget > previousRight
QPointer< QWidget > baseWidget
#define None
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
QPointer< QWidget > previousLeft
ControlElement(QMdiSubWindow *child)
QMenuBar * menuBar() const
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62
Qt::FocusReason focusInReason
FocusReason
Definition: qnamespace.h:1521
bool hasBorder(const QStyleOptionTitleBar &options) const
QPointer< QMdiSubWindow > mdiChild
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
QStyle::SubControl activeSubControl
void * qt_metacast(const char *classname)
CursorShape
Definition: qnamespace.h:1262
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QPointer< QMenu > systemMenu
QRubberBand * rubberBand
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QWidget * controllerWidget() const
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
The QVBoxLayout class lines up widgets vertically.
Definition: qboxlayout.h:149
QStyle::SubControl getSubControl(const QPoint &pos) const
OperationInfo(uint changeFlags, Qt::CursorShape cursorShape, bool hover=true)
The QRubberBand class provides a rectangle or line that can indicate a selection or a boundary...
Definition: qrubberband.h:58
QMap< Operation, OperationInfo > OperationInfoMap
WindowState
Definition: qnamespace.h:366
QWidget * systemMenuLabel() const
QPointer< QSizeGrip > sizeGrip
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
The QMdiSubWindow class provides a subwindow class for QMdiArea.
Definition: qmdisubwindow.h:60
#define text
Definition: qobjectdefs.h:80
bool isResizeOperation() const
QStyle::SubControl hoveredSubControl
OperationInfoMap operationMap
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60