src/gui/widgets/qdockwidgetlayout_p.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the QtGui module of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://www.trolltech.com/products/qt/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00017 ** sales department at sales@trolltech.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ****************************************************************************/
00023 
00024 #ifndef QDYNAMICDOCKWIDGETLAYOUT_P_H
00025 #define QDYNAMICDOCKWIDGETLAYOUT_P_H
00026 
00027 //
00028 //  W A R N I N G
00029 //  -------------
00030 //
00031 // This file is not part of the Qt API.  It exists purely as an
00032 // implementation detail.  This header file may change from version to
00033 // version without notice, or even be removed.
00034 //
00035 // We mean it.
00036 //
00037 
00038 #include "QtCore/qlist.h"
00039 #include "QtCore/qrect.h"
00040 #include "QtCore/qpair.h"
00041 #include "QtGui/qsizepolicy.h"
00042 
00043 #ifndef QT_NO_DOCKWIDGET
00044 
00045 class QLayoutItem;
00046 class QWidget;
00047 class QWidgetItem;
00048 class QDockAreaLayoutInfo;
00049 class QDockWidget;
00050 class QMainWindow;
00051 class QWidgetAnimator;
00052 class QMainWindowLayout;
00053 struct QLayoutStruct;
00054 class QTabBar;
00055 
00056 enum IndexOfFlag {
00057     IndexOfFindsVisible,
00058     IndexOfFindsInvisible,
00059     IndexOfFindsAll
00060 };
00061 
00062 struct QDockAreaLayoutItem
00063 {
00064     QDockAreaLayoutItem(QWidgetItem *_widgetItem = 0);
00065     QDockAreaLayoutItem(QDockAreaLayoutInfo *_subinfo);
00066     QDockAreaLayoutItem(const QDockAreaLayoutItem &other);
00067     ~QDockAreaLayoutItem();
00068 
00069     QDockAreaLayoutItem &operator = (const QDockAreaLayoutItem &other);
00070 
00071     bool skip() const;
00072     QSize minimumSize() const;
00073     QSize maximumSize() const;
00074     QSize sizeHint() const;
00075     bool expansive(Qt::Orientation o) const;
00076 
00077     QWidgetItem *widgetItem;
00078     QDockAreaLayoutInfo *subinfo;
00079     int pos;
00080     int size;
00081     bool gap;
00082     bool keep_size;
00083 };
00084 
00085 class QDockAreaLayoutInfo
00086 {
00087 public:
00088     QDockAreaLayoutInfo();
00089     QDockAreaLayoutInfo(int _sep, Qt::Orientation _o, int tbhape, QMainWindow *window);
00090 
00091     QSize minimumSize() const;
00092     QSize maximumSize() const;
00093     QSize sizeHint() const;
00094     QSize size() const;
00095 
00096     bool insertGap(QList<int> path, QWidgetItem *dockWidgetItem);
00097     QWidgetItem *convertToGap(QList<int> path);
00098     QRect convertToWidget(QList<int> path, QWidgetItem *dockWidget);
00099     QList<int> gapIndex(const QPoint &pos, bool nestingEnabled) const;
00100     void remove(QList<int> path);
00101     void unnest(int index);
00102     void split(int index, Qt::Orientation orientation, QWidgetItem *dockWidgetItem);
00103     void tab(int index, QWidgetItem *dockWidgetItem);
00104     QDockAreaLayoutItem &item(QList<int> path);
00105     QDockAreaLayoutInfo *info(QList<int> path);
00106     QDockAreaLayoutInfo *info(QWidget *widget);
00107 
00108     enum { // sentinel values used to validate state data
00109         SequenceMarker = 0xfc,
00110         TabMarker = 0xfa,
00111         WidgetMarker = 0xfb
00112     };
00113     void saveState(QDataStream &stream) const;
00114     bool restoreState(QDataStream &stream, const QList<QDockWidget*> &widgets);
00115 
00116     void fitItems();
00117     bool expansive(Qt::Orientation o) const;
00118     int changeSize(int index, int size, bool below);
00119     QRect itemRect(int index) const;
00120     QRect itemRect(QList<int> path) const;
00121     QRect separatorRect(int index) const;
00122     QRect separatorRect(QList<int> path) const;
00123 
00124     void clear();
00125     bool isEmpty() const;
00126     QList<int> findSeparator(const QPoint &pos) const;
00127     int next(int idx) const;
00128     int prev(int idx) const;
00129 
00130     QList<int> indexOf(QWidget *widget, IndexOfFlag flag = IndexOfFindsVisible) const;
00131 
00132     void apply(bool animate);
00133 
00134     void paintSeparators(QPainter *p, QWidget *widget, const QRegion &clip,
00135                             const QPoint &mouse) const;
00136     QRegion separatorRegion() const;
00137     int separatorMove(int index, int delta, QVector<QLayoutStruct> *cache);
00138 
00139     QLayoutItem *itemAt(int *x, int index) const;
00140     QLayoutItem *takeAt(int *x, int index);
00141     void deleteAllLayoutItems();
00142 
00143     QMainWindowLayout *mainWindowLayout() const;
00144 
00145     int sep;
00146     Qt::Orientation o;
00147     QRect rect;
00148     QMainWindow *mainWindow;
00149     QList<QDockAreaLayoutItem> item_list;
00150 
00151 #ifndef QT_NO_TABBAR
00152     quintptr currentTabId() const;
00153     void setCurrentTab(QWidget *widget);
00154     void setCurrentTabId(quintptr id);
00155     QRect tabContentRect() const;
00156     bool tabbed;
00157     QTabBar *tabBar;
00158     QSize tabBarMin, tabBarHint;
00159     int tabBarShape;
00160     bool tabBarVisible;
00161 
00162     void updateTabBar() const;
00163     QSize tabBarMinimumSize() const;
00164     QSize tabBarSizeHint() const;
00165 
00166     QSet<QTabBar*> usedTabBars() const;
00167 #endif // QT_NO_TABBAR
00168 };
00169 
00170 // utilities
00171 
00172 #endif
00173 
00174 static inline int pick(Qt::Orientation o, const QPoint &pos)
00175 { return o == Qt::Horizontal ? pos.x() : pos.y(); }
00176 
00177 static inline int pick(Qt::Orientation o, const QSize &size)
00178 { return o == Qt::Horizontal ? size.width() : size.height(); }
00179 
00180 #ifndef QT_NO_DOCKWIDGET
00181 
00182 static inline int &rpick(Qt::Orientation o, QPoint &pos)
00183 { return o == Qt::Horizontal ? pos.rx() : pos.ry(); }
00184 
00185 static inline int &rpick(Qt::Orientation o, QSize &size)
00186 { return o == Qt::Horizontal ? size.rwidth() : size.rheight(); }
00187 
00188 static inline QSizePolicy::Policy pick(Qt::Orientation o, const QSizePolicy &policy)
00189 { return o == Qt::Horizontal ? policy.horizontalPolicy() : policy.verticalPolicy(); }
00190 
00191 static inline int perp(Qt::Orientation o, const QPoint &pos)
00192 { return o == Qt::Vertical ? pos.x() : pos.y(); }
00193 
00194 static inline int perp(Qt::Orientation o, const QSize &size)
00195 { return o == Qt::Vertical ? size.width() : size.height(); }
00196 
00197 static inline int &rperp(Qt::Orientation o, QPoint &pos)
00198 { return o == Qt::Vertical ? pos.rx() : pos.ry(); }
00199 
00200 static inline int &rperp(Qt::Orientation o, QSize &size)
00201 { return o == Qt::Vertical ? size.rwidth() : size.rheight(); }
00202 
00203 // the rest of QMainWindow uses this instead...
00204 static inline int pick_perp(Qt::Orientation o, const QPoint &p)
00205 { return o == Qt::Vertical ? p.x() : p.y(); }
00206 static inline int pick_perp(Qt::Orientation o, const QSize &s)
00207 { return o == Qt::Vertical ? s.width() : s.height(); }
00208 
00209 class QWidgetItem;
00210 class QDockWidgetLayout
00211 {
00212 public:
00213     enum DockPos {
00214         LeftPos,
00215         RightPos,
00216         TopPos,
00217         BottomPos,
00218         PosCount,
00219         CenterPos = PosCount
00220     };
00221     enum { EmptyDropAreaSize = 80 }; // when a dock area is empty, how "wide" is it?
00222 
00223     Qt::DockWidgetArea corners[4]; // use a Qt::Corner for indexing
00224     QRect rect;
00225     QWidgetItem *centralWidgetItem;
00226     QMainWindow *mainWindow;
00227     QRect centralWidgetRect;
00228     QDockWidgetLayout(QMainWindow *win);
00229     QDockAreaLayoutInfo docks[4];
00230     int sep; // separator extent
00231 
00232     bool isValid() const;
00233 
00234     enum { DockWidgetStateMarker = 0xfd };
00235     void saveState(QDataStream &stream) const;
00236     bool restoreState(QDataStream &stream, const QList<QDockWidget*> &widgets);
00237 
00238     QList<int> indexOf(QDockWidget *dockWidget, IndexOfFlag flag = IndexOfFindsVisible) const;
00239     QList<int> gapIndex(const QPoint &pos, bool nestingEnabled) const;
00240     QList<int> findSeparator(const QPoint &pos) const;
00241 
00242     QDockAreaLayoutItem &item(QList<int> path);
00243     QDockAreaLayoutInfo *info(QList<int> path);
00244     QDockAreaLayoutInfo *info(QWidget *widget);
00245     QRect itemRect(QList<int> path) const;
00246     QRect separatorRect(int index) const;
00247     QRect separatorRect(QList<int> path) const;
00248 
00249     bool insertGap(QList<int> path, QWidgetItem *dockWidgetItem);
00250     QWidgetItem *convertToGap(QList<int> path);
00251     QRect convertToWidget(QList<int> path, QWidgetItem *dockWidgetItem);
00252     void remove(QList<int> path);
00253 
00254     void fitLayout();
00255 
00256     void clear();
00257 
00258     QSize sizeHint() const;
00259     QSize minimumSize() const;
00260 
00261     void addDockWidget(DockPos pos, QDockWidget *dockWidget, Qt::Orientation orientation);
00262     void splitDockWidget(QDockWidget *after, QDockWidget *dockWidget,
00263                          Qt::Orientation orientation);
00264     void tabifyDockWidget(QDockWidget *first, QDockWidget *second);
00265 
00266     void apply(bool animate);
00267 
00268     void paintSeparators(QPainter *p, QWidget *widget, const QRegion &clip,
00269                             const QPoint &mouse) const;
00270     QRegion separatorRegion() const;
00271     int separatorMove(QList<int> separator, const QPoint &origin, const QPoint &dest,
00272                         QVector<QLayoutStruct> *cache);
00273 
00274     QLayoutItem *itemAt(int *x, int index) const;
00275     QLayoutItem *takeAt(int *x, int index);
00276     void deleteAllLayoutItems();
00277 
00278     void getGrid(QVector<QLayoutStruct> *ver_struct_list,
00279                     QVector<QLayoutStruct> *hor_struct_list);
00280     void setGrid(QVector<QLayoutStruct> *ver_struct_list,
00281                     QVector<QLayoutStruct> *hor_struct_list);
00282 
00283     QRect gapRect(QList<int> path);
00284 
00285     void keepSize(QDockWidget *w);
00286 
00287     QSet<QTabBar*> usedTabBars() const;
00288 };
00289 
00290 // void dump(QDebug debug, const QDockWidgetLayout &layout);
00291 
00292 #endif // QT_NO_MAINWINDOW
00293 
00294 #endif // QDYNAMICDOCKWIDGETLAYOUT_P_H

Generated on Thu Mar 15 11:56:53 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1