qsplitter.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtGui module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QSPLITTER_H
00043 #define QSPLITTER_H
00044 
00045 #include <QtGui/qframe.h>
00046 #include <QtGui/qsizepolicy.h>
00047 
00048 QT_BEGIN_HEADER
00049 
00050 QT_BEGIN_NAMESPACE
00051 
00052 QT_MODULE(Gui)
00053 
00054 #ifndef QT_NO_SPLITTER
00055 
00056 class QSplitterPrivate;
00057 class QTextStream;
00058 template <typename T> class QList;
00059 
00060 class QSplitterHandle;
00061 
00062 class Q_GUI_EXPORT QSplitter : public QFrame
00063 {
00064     Q_OBJECT
00065 
00066     Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
00067     Q_PROPERTY(bool opaqueResize READ opaqueResize WRITE setOpaqueResize)
00068     Q_PROPERTY(int handleWidth READ handleWidth WRITE setHandleWidth)
00069     Q_PROPERTY(bool childrenCollapsible READ childrenCollapsible WRITE setChildrenCollapsible)
00070 
00071 public:
00072     explicit QSplitter(QWidget* parent = 0);
00073     explicit QSplitter(Qt::Orientation, QWidget* parent = 0);
00074     ~QSplitter();
00075 
00076     void addWidget(QWidget *widget);
00077     void insertWidget(int index, QWidget *widget);
00078 
00079     void setOrientation(Qt::Orientation);
00080     Qt::Orientation orientation() const;
00081 
00082     void setChildrenCollapsible(bool);
00083     bool childrenCollapsible() const;
00084 
00085     void setCollapsible(int index, bool);
00086     bool isCollapsible(int index) const;
00087     void setOpaqueResize(bool opaque = true);
00088     bool opaqueResize() const;
00089     void refresh();
00090 
00091     QSize sizeHint() const;
00092     QSize minimumSizeHint() const;
00093 
00094     QList<int> sizes() const;
00095     void setSizes(const QList<int> &list);
00096 
00097     QByteArray saveState() const;
00098     bool restoreState(const QByteArray &state);
00099 
00100     int handleWidth() const;
00101     void setHandleWidth(int);
00102 
00103     int indexOf(QWidget *w) const;
00104     QWidget *widget(int index) const;
00105     int count() const;
00106 
00107     void getRange(int index, int *, int *) const;
00108     QSplitterHandle *handle(int index) const;
00109 
00110     void setStretchFactor(int index, int stretch);
00111 
00112 Q_SIGNALS:
00113     void splitterMoved(int pos, int index);
00114 
00115 protected:
00116     virtual QSplitterHandle *createHandle();
00117 
00118     void childEvent(QChildEvent *);
00119 
00120     bool event(QEvent *);
00121     void resizeEvent(QResizeEvent *);
00122 
00123     void changeEvent(QEvent *);
00124     void moveSplitter(int pos, int index);
00125     void setRubberBand(int position);
00126     int closestLegalPosition(int, int);
00127 
00128 #ifdef QT3_SUPPORT
00129 public:
00130     QT3_SUPPORT_CONSTRUCTOR QSplitter(QWidget* parent, const char* name);
00131     QT3_SUPPORT_CONSTRUCTOR QSplitter(Qt::Orientation, QWidget* parent, const char* name);
00132     enum ResizeMode { Stretch, KeepSize, FollowSizeHint, Auto };
00133     QT3_SUPPORT void setResizeMode(QWidget *w, ResizeMode mode);
00134     inline QT3_SUPPORT void moveToFirst(QWidget *w) { insertWidget(0,w); }
00135     inline QT3_SUPPORT void moveToLast(QWidget *w) { addWidget(w); }
00136     inline QT3_SUPPORT void setCollapsible(QWidget *w, bool collapse)
00137     { setCollapsible(indexOf(w), collapse); }
00138     QT3_SUPPORT void setMargin(int margin) { setContentsMargins(margin, margin, margin, margin); }
00139     QT3_SUPPORT int margin() const 
00140     { int margin; int dummy; getContentsMargins(&margin, &dummy, &dummy, &dummy);  return margin; }    
00141 #endif
00142 
00143 private:
00144     Q_DISABLE_COPY(QSplitter)
00145     Q_DECLARE_PRIVATE(QSplitter)
00146 private:
00147     friend class QSplitterHandle;
00148 };
00149 
00150 //#ifdef QT3_SUPPORT
00151 #ifndef QT_NO_TEXTSTREAM
00152 Q_GUI_EXPORT QTextStream& operator<<(QTextStream&, const QSplitter&);
00153 Q_GUI_EXPORT QTextStream& operator>>(QTextStream&, QSplitter&);
00154 #endif
00155 //#endif
00156 
00157 class QSplitterHandlePrivate;
00158 class Q_GUI_EXPORT QSplitterHandle : public QWidget
00159 {
00160     Q_OBJECT
00161 public:
00162     QSplitterHandle(Qt::Orientation o, QSplitter *parent);
00163     void setOrientation(Qt::Orientation o);
00164     Qt::Orientation orientation() const;
00165     bool opaqueResize() const;
00166     QSplitter *splitter() const;
00167 
00168     QSize sizeHint() const;
00169 
00170 protected:
00171     void paintEvent(QPaintEvent *);
00172     void mouseMoveEvent(QMouseEvent *);
00173     void mousePressEvent(QMouseEvent *);
00174     void mouseReleaseEvent(QMouseEvent *);
00175     void resizeEvent(QResizeEvent *);
00176     bool event(QEvent *);
00177 
00178     void moveSplitter(int p);
00179     int closestLegalPosition(int p);
00180 
00181 private:
00182     Q_DISABLE_COPY(QSplitterHandle)
00183     Q_DECLARE_PRIVATE(QSplitterHandle)
00184 };
00185 
00186 #endif // QT_NO_SPLITTER
00187 
00188 QT_END_NAMESPACE
00189 
00190 QT_END_HEADER
00191 
00192 #endif // QSPLITTER_H