src/gui/widgets/qdockwidget_p.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtGui module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    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 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef QDYNAMICDOCKWIDGET_P_H
       
    43 #define QDYNAMICDOCKWIDGET_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 "QtGui/qstyleoption.h"
       
    57 #include "private/qwidget_p.h"
       
    58 #include "QtGui/qboxlayout.h"
       
    59 #include "QtGui/qdockwidget.h"
       
    60 
       
    61 #ifndef QT_NO_DOCKWIDGET
       
    62 
       
    63 QT_BEGIN_NAMESPACE
       
    64 
       
    65 class QGridLayout;
       
    66 class QWidgetResizeHandler;
       
    67 class QRubberBand;
       
    68 class QDockWidgetTitleButton;
       
    69 class QSpacerItem;
       
    70 class QDockWidgetItem;
       
    71 
       
    72 class QDockWidgetPrivate : public QWidgetPrivate
       
    73 {
       
    74     Q_DECLARE_PUBLIC(QDockWidget)
       
    75 
       
    76     struct DragState {
       
    77         QPoint pressPos;
       
    78         bool dragging;
       
    79         QLayoutItem *widgetItem;
       
    80         bool ownWidgetItem;
       
    81         bool nca;
       
    82         bool ctrlDrag;
       
    83     };
       
    84 
       
    85 public:
       
    86     inline QDockWidgetPrivate()
       
    87 	: QWidgetPrivate(), state(0),
       
    88           features(QDockWidget::DockWidgetClosable
       
    89                    | QDockWidget::DockWidgetMovable
       
    90                    | QDockWidget::DockWidgetFloatable),
       
    91           allowedAreas(Qt::AllDockWidgetAreas)
       
    92     { }
       
    93 
       
    94     void init();
       
    95     void _q_toggleView(bool); // private slot
       
    96     void _q_toggleTopLevel(); // private slot
       
    97 
       
    98     void updateButtons();
       
    99     DragState *state;
       
   100 
       
   101     QDockWidget::DockWidgetFeatures features;
       
   102     Qt::DockWidgetAreas allowedAreas;
       
   103 
       
   104     QWidgetResizeHandler *resizer;
       
   105 
       
   106 #ifndef QT_NO_ACTION
       
   107     QAction *toggleViewAction;
       
   108 #endif
       
   109 
       
   110 //    QMainWindow *findMainWindow(QWidget *widget) const;
       
   111     QRect undockedGeometry;
       
   112     QString fixedWindowTitle;
       
   113 
       
   114     bool mousePressEvent(QMouseEvent *event);
       
   115     bool mouseDoubleClickEvent(QMouseEvent *event);
       
   116     bool mouseMoveEvent(QMouseEvent *event);
       
   117     bool mouseReleaseEvent(QMouseEvent *event);
       
   118     void setWindowState(bool floating, bool unplug = false, const QRect &rect = QRect());
       
   119     void nonClientAreaMouseEvent(QMouseEvent *event);
       
   120     void initDrag(const QPoint &pos, bool nca);
       
   121     void startDrag();
       
   122     void endDrag(bool abort = false);
       
   123     void moveEvent(QMoveEvent *event);
       
   124 
       
   125     void unplug(const QRect &rect);
       
   126     void plug(const QRect &rect);
       
   127 
       
   128     bool isAnimating() const;
       
   129 };
       
   130 
       
   131 class Q_GUI_EXPORT QDockWidgetLayout : public QLayout
       
   132 {
       
   133     Q_OBJECT
       
   134 public:
       
   135     QDockWidgetLayout(QWidget *parent = 0);
       
   136     ~QDockWidgetLayout();
       
   137     void addItem(QLayoutItem *item);
       
   138     QLayoutItem *itemAt(int index) const;
       
   139     QLayoutItem *takeAt(int index);
       
   140     int count() const;
       
   141 
       
   142     QSize maximumSize() const;
       
   143     QSize minimumSize() const;
       
   144     QSize sizeHint() const;
       
   145 
       
   146     QSize sizeFromContent(const QSize &content, bool floating) const;
       
   147 
       
   148     void setGeometry(const QRect &r);
       
   149 
       
   150     enum Role { Content, CloseButton, FloatButton, TitleBar, RoleCount };
       
   151     QWidget *widgetForRole(Role r) const;
       
   152     void setWidgetForRole(Role r, QWidget *w);
       
   153     QLayoutItem *itemForRole(Role r) const;
       
   154 
       
   155     QRect titleArea() const { return _titleArea; }
       
   156 
       
   157     int minimumTitleWidth() const;
       
   158     int titleHeight() const;
       
   159     void updateMaxSize();
       
   160     bool nativeWindowDeco() const;
       
   161     bool nativeWindowDeco(bool floating) const;
       
   162 
       
   163     void setVerticalTitleBar(bool b);
       
   164 
       
   165     bool verticalTitleBar;
       
   166 
       
   167 private:
       
   168     QVector<QLayoutItem*> item_list;
       
   169     QRect _titleArea;
       
   170 };
       
   171 
       
   172 /* The size hints of a QDockWidget will depend on wether it is docked or not.
       
   173    This layout item always returns the size hints as if the dock widget was docked. */
       
   174 
       
   175 class QDockWidgetItem : public QWidgetItem
       
   176 {
       
   177 public:
       
   178     QDockWidgetItem(QDockWidget *dockWidget);
       
   179     QSize minimumSize() const;
       
   180     QSize maximumSize() const;
       
   181     QSize sizeHint() const;
       
   182 
       
   183 private:
       
   184     inline QLayoutItem *dockWidgetChildItem() const;
       
   185     inline QDockWidgetLayout *dockWidgetLayout() const;
       
   186 };
       
   187 
       
   188 inline QLayoutItem *QDockWidgetItem::dockWidgetChildItem() const
       
   189 {
       
   190     if (QDockWidgetLayout *layout = dockWidgetLayout())
       
   191         return layout->itemForRole(QDockWidgetLayout::Content);
       
   192     return 0;
       
   193 }
       
   194 
       
   195 inline QDockWidgetLayout *QDockWidgetItem::dockWidgetLayout() const
       
   196 {
       
   197     QWidget *w = const_cast<QDockWidgetItem*>(this)->widget();
       
   198     if (w != 0)
       
   199         return qobject_cast<QDockWidgetLayout*>(w->layout());
       
   200     return 0;
       
   201 }
       
   202 
       
   203 QT_END_NAMESPACE
       
   204 
       
   205 #endif // QT_NO_DOCKWIDGET
       
   206 
       
   207 #endif // QDYNAMICDOCKWIDGET_P_H