-rw-r--r-- | libqtaux/qsplitter.cpp | 4 |
1 files changed, 0 insertions, 4 deletions
diff --git a/libqtaux/qsplitter.cpp b/libqtaux/qsplitter.cpp index ab6e01b..39321f8 100644 --- a/libqtaux/qsplitter.cpp +++ b/libqtaux/qsplitter.cpp | |||
@@ -1,236 +1,232 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
2 | ** $Id$ | 2 | ** $Id$ |
3 | ** | 3 | ** |
4 | ** Splitter widget | 4 | ** Splitter widget |
5 | ** | 5 | ** |
6 | ** Created: 980105 | 6 | ** Created: 980105 |
7 | ** | 7 | ** |
8 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. | 8 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. |
9 | ** | 9 | ** |
10 | ** This file is part of the widgets module of the Qt GUI Toolkit. | 10 | ** This file is part of the widgets module of the Qt GUI Toolkit. |
11 | ** | 11 | ** |
12 | ** This file may be distributed under the terms of the Q Public License | 12 | ** This file may be distributed under the terms of the Q Public License |
13 | ** as defined by Trolltech AS of Norway and appearing in the file | 13 | ** as defined by Trolltech AS of Norway and appearing in the file |
14 | ** LICENSE.QPL included in the packaging of this file. | 14 | ** LICENSE.QPL included in the packaging of this file. |
15 | ** | 15 | ** |
16 | ** This file may be distributed and/or modified under the terms of the | 16 | ** This file may be distributed and/or modified under the terms of the |
17 | ** GNU General Public License version 2 as published by the Free Software | 17 | ** GNU General Public License version 2 as published by the Free Software |
18 | ** Foundation and appearing in the file LICENSE.GPL included in the | 18 | ** Foundation and appearing in the file LICENSE.GPL included in the |
19 | ** packaging of this file. | 19 | ** packaging of this file. |
20 | ** | 20 | ** |
21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | 21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition |
22 | ** licenses may use this file in accordance with the Qt Commercial License | 22 | ** licenses may use this file in accordance with the Qt Commercial License |
23 | ** Agreement provided with the Software. | 23 | ** Agreement provided with the Software. |
24 | ** | 24 | ** |
25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
27 | ** | 27 | ** |
28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | 28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for |
29 | ** information about Qt Commercial License Agreements. | 29 | ** information about Qt Commercial License Agreements. |
30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. | 30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. |
31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
32 | ** | 32 | ** |
33 | ** Contact info@trolltech.com if any conditions of this licensing are | 33 | ** Contact info@trolltech.com if any conditions of this licensing are |
34 | ** not clear to you. | 34 | ** not clear to you. |
35 | ** | 35 | ** |
36 | **********************************************************************/ | 36 | **********************************************************************/ |
37 | #include "qsplitter.h" | 37 | #include "qsplitter.h" |
38 | 38 | ||
39 | #include "qpainter.h" | ||
40 | #include "qdrawutil.h" | 39 | #include "qdrawutil.h" |
41 | #include "qbitmap.h" | ||
42 | #include "qlayoutengine_p.h" | 40 | #include "qlayoutengine_p.h" |
43 | #include "qlist.h" | ||
44 | #include "qarray.h" | ||
45 | #include "qobjectlist.h" | 41 | #include "qobjectlist.h" |
46 | #include "qapplication.h" //sendPostedEvents | 42 | #include "qapplication.h" //sendPostedEvents |
47 | 43 | ||
48 | class QSplitterHandle : public QWidget | 44 | class QSplitterHandle : public QWidget |
49 | { | 45 | { |
50 | public: | 46 | public: |
51 | QSplitterHandle( Qt::Orientation o, | 47 | QSplitterHandle( Qt::Orientation o, |
52 | QSplitter *parent, const char* name=0 ); | 48 | QSplitter *parent, const char* name=0 ); |
53 | void setOrientation( Qt::Orientation o ); | 49 | void setOrientation( Qt::Orientation o ); |
54 | Qt::Orientation orientation() const { return orient; } | 50 | Qt::Orientation orientation() const { return orient; } |
55 | 51 | ||
56 | bool opaque() const { return s->opaqueResize(); } | 52 | bool opaque() const { return s->opaqueResize(); } |
57 | 53 | ||
58 | QSize sizeHint() const; | 54 | QSize sizeHint() const; |
59 | QSizePolicy sizePolicy() const; | 55 | QSizePolicy sizePolicy() const; |
60 | 56 | ||
61 | int id() const { return myId; } // data->list.at(id())->wid == this | 57 | int id() const { return myId; } // data->list.at(id())->wid == this |
62 | void setId( int i ) { myId = i; } | 58 | void setId( int i ) { myId = i; } |
63 | 59 | ||
64 | protected: | 60 | protected: |
65 | void paintEvent( QPaintEvent * ); | 61 | void paintEvent( QPaintEvent * ); |
66 | void mouseMoveEvent( QMouseEvent * ); | 62 | void mouseMoveEvent( QMouseEvent * ); |
67 | void mousePressEvent( QMouseEvent * ); | 63 | void mousePressEvent( QMouseEvent * ); |
68 | void mouseReleaseEvent( QMouseEvent * ); | 64 | void mouseReleaseEvent( QMouseEvent * ); |
69 | 65 | ||
70 | private: | 66 | private: |
71 | Qt::Orientation orient; | 67 | Qt::Orientation orient; |
72 | bool opaq; | 68 | bool opaq; |
73 | int myId; | 69 | int myId; |
74 | 70 | ||
75 | QSplitter *s; | 71 | QSplitter *s; |
76 | }; | 72 | }; |
77 | 73 | ||
78 | static int mouseOffset; | 74 | static int mouseOffset; |
79 | static int opaqueOldPos = -1; //### there's only one mouse, but this is a bit risky | 75 | static int opaqueOldPos = -1; //### there's only one mouse, but this is a bit risky |
80 | 76 | ||
81 | 77 | ||
82 | QSplitterHandle::QSplitterHandle( Qt::Orientation o, | 78 | QSplitterHandle::QSplitterHandle( Qt::Orientation o, |
83 | QSplitter *parent, const char * name ) | 79 | QSplitter *parent, const char * name ) |
84 | : QWidget( parent, name ) | 80 | : QWidget( parent, name ) |
85 | { | 81 | { |
86 | s = parent; | 82 | s = parent; |
87 | setOrientation(o); | 83 | setOrientation(o); |
88 | } | 84 | } |
89 | 85 | ||
90 | QSizePolicy QSplitterHandle::sizePolicy() const | 86 | QSizePolicy QSplitterHandle::sizePolicy() const |
91 | { | 87 | { |
92 | //### removeme 3.0 | 88 | //### removeme 3.0 |
93 | return QWidget::sizePolicy(); | 89 | return QWidget::sizePolicy(); |
94 | } | 90 | } |
95 | 91 | ||
96 | QSize QSplitterHandle::sizeHint() const | 92 | QSize QSplitterHandle::sizeHint() const |
97 | { | 93 | { |
98 | int sw = style().splitterWidth(); | 94 | int sw = style().splitterWidth(); |
99 | return QSize(sw,sw).expandedTo( QApplication::globalStrut() ); | 95 | return QSize(sw,sw).expandedTo( QApplication::globalStrut() ); |
100 | } | 96 | } |
101 | 97 | ||
102 | void QSplitterHandle::setOrientation( Qt::Orientation o ) | 98 | void QSplitterHandle::setOrientation( Qt::Orientation o ) |
103 | { | 99 | { |
104 | orient = o; | 100 | orient = o; |
105 | #ifndef QT_NO_CURSOR | 101 | #ifndef QT_NO_CURSOR |
106 | if ( o == QSplitter::Horizontal ) | 102 | if ( o == QSplitter::Horizontal ) |
107 | setCursor( splitHCursor ); | 103 | setCursor( splitHCursor ); |
108 | else | 104 | else |
109 | setCursor( splitVCursor ); | 105 | setCursor( splitVCursor ); |
110 | #endif | 106 | #endif |
111 | } | 107 | } |
112 | 108 | ||
113 | 109 | ||
114 | void QSplitterHandle::mouseMoveEvent( QMouseEvent *e ) | 110 | void QSplitterHandle::mouseMoveEvent( QMouseEvent *e ) |
115 | { | 111 | { |
116 | if ( !(e->state()&LeftButton) ) | 112 | if ( !(e->state()&LeftButton) ) |
117 | return; | 113 | return; |
118 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) | 114 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) |
119 | - mouseOffset; | 115 | - mouseOffset; |
120 | if ( opaque() ) { | 116 | if ( opaque() ) { |
121 | s->moveSplitter( pos, id() ); | 117 | s->moveSplitter( pos, id() ); |
122 | } else { | 118 | } else { |
123 | int min = pos; int max = pos; | 119 | int min = pos; int max = pos; |
124 | s->getRange( id(), &min, &max ); | 120 | s->getRange( id(), &min, &max ); |
125 | s->setRubberband( QMAX( min, QMIN(max, pos ))); | 121 | s->setRubberband( QMAX( min, QMIN(max, pos ))); |
126 | } | 122 | } |
127 | } | 123 | } |
128 | 124 | ||
129 | void QSplitterHandle::mousePressEvent( QMouseEvent *e ) | 125 | void QSplitterHandle::mousePressEvent( QMouseEvent *e ) |
130 | { | 126 | { |
131 | if ( e->button() == LeftButton ) | 127 | if ( e->button() == LeftButton ) |
132 | mouseOffset = s->pick(e->pos()); | 128 | mouseOffset = s->pick(e->pos()); |
133 | } | 129 | } |
134 | 130 | ||
135 | void QSplitterHandle::mouseReleaseEvent( QMouseEvent *e ) | 131 | void QSplitterHandle::mouseReleaseEvent( QMouseEvent *e ) |
136 | { | 132 | { |
137 | if ( !opaque() && e->button() == LeftButton ) { | 133 | if ( !opaque() && e->button() == LeftButton ) { |
138 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())); | 134 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())); |
139 | s->setRubberband( -1 ); | 135 | s->setRubberband( -1 ); |
140 | s->moveSplitter( pos, id() ); | 136 | s->moveSplitter( pos, id() ); |
141 | } | 137 | } |
142 | } | 138 | } |
143 | 139 | ||
144 | void QSplitterHandle::paintEvent( QPaintEvent * ) | 140 | void QSplitterHandle::paintEvent( QPaintEvent * ) |
145 | { | 141 | { |
146 | QPainter p( this ); | 142 | QPainter p( this ); |
147 | s->drawSplitter( &p, 0, 0, width(), height() ); | 143 | s->drawSplitter( &p, 0, 0, width(), height() ); |
148 | } | 144 | } |
149 | 145 | ||
150 | 146 | ||
151 | class QSplitterLayoutStruct | 147 | class QSplitterLayoutStruct |
152 | { | 148 | { |
153 | public: | 149 | public: |
154 | QSplitter::ResizeMode mode; | 150 | QSplitter::ResizeMode mode; |
155 | QCOORD sizer; | 151 | QCOORD sizer; |
156 | bool isSplitter; | 152 | bool isSplitter; |
157 | QWidget *wid; | 153 | QWidget *wid; |
158 | }; | 154 | }; |
159 | 155 | ||
160 | class QSplitterData | 156 | class QSplitterData |
161 | { | 157 | { |
162 | public: | 158 | public: |
163 | QSplitterData() : opaque( FALSE ), firstShow( TRUE ) {} | 159 | QSplitterData() : opaque( FALSE ), firstShow( TRUE ) {} |
164 | 160 | ||
165 | QList<QSplitterLayoutStruct> list; | 161 | QList<QSplitterLayoutStruct> list; |
166 | bool opaque; | 162 | bool opaque; |
167 | bool firstShow; | 163 | bool firstShow; |
168 | }; | 164 | }; |
169 | 165 | ||
170 | 166 | ||
171 | // NOT REVISED | 167 | // NOT REVISED |
172 | /*! | 168 | /*! |
173 | \class QSplitter qsplitter.h | 169 | \class QSplitter qsplitter.h |
174 | \brief The QSplitter class implements a splitter widget. | 170 | \brief The QSplitter class implements a splitter widget. |
175 | 171 | ||
176 | \ingroup organizers | 172 | \ingroup organizers |
177 | 173 | ||
178 | A splitter lets the user control the size of child widgets by | 174 | A splitter lets the user control the size of child widgets by |
179 | dragging the boundary between the children. Any number of widgets | 175 | dragging the boundary between the children. Any number of widgets |
180 | may be controlled. | 176 | may be controlled. |
181 | 177 | ||
182 | To show a QListBox, a QListView and a QMultiLineEdit side by side: | 178 | To show a QListBox, a QListView and a QMultiLineEdit side by side: |
183 | 179 | ||
184 | \code | 180 | \code |
185 | QSplitter *split = new QSplitter( parent ); | 181 | QSplitter *split = new QSplitter( parent ); |
186 | QListBox *lb = new QListBox( split ); | 182 | QListBox *lb = new QListBox( split ); |
187 | QListView *lv = new QListView( split ); | 183 | QListView *lv = new QListView( split ); |
188 | QMultiLineEdit *ed = new QMultiLineEdit( split ); | 184 | QMultiLineEdit *ed = new QMultiLineEdit( split ); |
189 | \endcode | 185 | \endcode |
190 | 186 | ||
191 | In QSplitter the boundary can be either horizontal or vertical. The | 187 | In QSplitter the boundary can be either horizontal or vertical. The |
192 | default is horizontal (the children are side by side) and you | 188 | default is horizontal (the children are side by side) and you |
193 | can use setOrientation( QSplitter::Vertical ) to set it to vertical. | 189 | can use setOrientation( QSplitter::Vertical ) to set it to vertical. |
194 | 190 | ||
195 | By default, all widgets can be as large or as small as the user | 191 | By default, all widgets can be as large or as small as the user |
196 | wishes, down to \link QWidget::minimumSizeHint() minimumSizeHint()\endlink. | 192 | wishes, down to \link QWidget::minimumSizeHint() minimumSizeHint()\endlink. |
197 | You can naturally use setMinimumSize() and/or | 193 | You can naturally use setMinimumSize() and/or |
198 | setMaximumSize() on the children. Use setResizeMode() to specify that | 194 | setMaximumSize() on the children. Use setResizeMode() to specify that |
199 | a widget should keep its size when the splitter is resized. | 195 | a widget should keep its size when the splitter is resized. |
200 | 196 | ||
201 | QSplitter normally resizes the children only at the end of a | 197 | QSplitter normally resizes the children only at the end of a |
202 | resize operation, but if you call setOpaqueResize( TRUE ), the | 198 | resize operation, but if you call setOpaqueResize( TRUE ), the |
203 | widgets are resized as often as possible. | 199 | widgets are resized as often as possible. |
204 | 200 | ||
205 | The initial distribution of size between the widgets is determined | 201 | The initial distribution of size between the widgets is determined |
206 | by the initial size of each widget. You can also use setSizes() to | 202 | by the initial size of each widget. You can also use setSizes() to |
207 | set the sizes of all the widgets. The function sizes() returns the | 203 | set the sizes of all the widgets. The function sizes() returns the |
208 | sizes set by the user. | 204 | sizes set by the user. |
209 | 205 | ||
210 | If you hide() a child, its space will be distributed among the other | 206 | If you hide() a child, its space will be distributed among the other |
211 | children. When you show() it again, it will be reinstated. | 207 | children. When you show() it again, it will be reinstated. |
212 | 208 | ||
213 | <img src=qsplitter-m.png> <img src=qsplitter-w.png> | 209 | <img src=qsplitter-m.png> <img src=qsplitter-w.png> |
214 | 210 | ||
215 | \sa QTabBar | 211 | \sa QTabBar |
216 | */ | 212 | */ |
217 | 213 | ||
218 | 214 | ||
219 | 215 | ||
220 | static QSize minSize( const QWidget *w ) | 216 | static QSize minSize( const QWidget *w ) |
221 | { | 217 | { |
222 | QSize min = w->minimumSize(); | 218 | QSize min = w->minimumSize(); |
223 | QSize s; | 219 | QSize s; |
224 | if ( min.height() <= 0 || min.width() <= 0 ) | 220 | if ( min.height() <= 0 || min.width() <= 0 ) |
225 | s = w->minimumSizeHint(); | 221 | s = w->minimumSizeHint(); |
226 | if ( min.height() > 0 ) | 222 | if ( min.height() > 0 ) |
227 | s.setHeight( min.height() ); | 223 | s.setHeight( min.height() ); |
228 | if ( min.width() > 0 ) | 224 | if ( min.width() > 0 ) |
229 | s.setWidth( min.width() ); | 225 | s.setWidth( min.width() ); |
230 | return s.expandedTo(QSize(0,0)); | 226 | return s.expandedTo(QSize(0,0)); |
231 | } | 227 | } |
232 | 228 | ||
233 | /*! | 229 | /*! |
234 | Constructs a horizontal splitter. | 230 | Constructs a horizontal splitter. |
235 | */ | 231 | */ |
236 | 232 | ||