Diffstat (limited to 'microkde/KDGanttMinimizeSplitter.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | microkde/KDGanttMinimizeSplitter.cpp | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/microkde/KDGanttMinimizeSplitter.cpp b/microkde/KDGanttMinimizeSplitter.cpp index 253175e..2a30346 100644 --- a/microkde/KDGanttMinimizeSplitter.cpp +++ b/microkde/KDGanttMinimizeSplitter.cpp | |||
@@ -1,1459 +1,1455 @@ | |||
1 | /* -*- Mode: C++ -*- | 1 | /* -*- Mode: C++ -*- |
2 | $Id$ | 2 | $Id$ |
3 | */ | 3 | */ |
4 | 4 | ||
5 | /**************************************************************************** | 5 | /**************************************************************************** |
6 | ** Copyright (C) 2002-2004 Klarälvdalens Datakonsult AB. All rights reserved. | 6 | ** Copyright (C) 2002-2004 Klarälvdalens Datakonsult AB. All rights reserved. |
7 | ** | 7 | ** |
8 | ** This file is part of the KDGantt library. | 8 | ** This file is part of the KDGantt library. |
9 | ** | 9 | ** |
10 | ** This file may be distributed and/or modified under the terms of the | 10 | ** This file may be distributed and/or modified under the terms of the |
11 | ** GNU General Public License version 2 as published by the Free Software | 11 | ** GNU General Public License version 2 as published by the Free Software |
12 | ** Foundation and appearing in the file LICENSE.GPL included in the | 12 | ** Foundation and appearing in the file LICENSE.GPL included in the |
13 | ** packaging of this file. | 13 | ** packaging of this file. |
14 | ** | 14 | ** |
15 | ** Licensees holding valid commercial KDGantt licenses may use this file in | 15 | ** Licensees holding valid commercial KDGantt licenses may use this file in |
16 | ** accordance with the KDGantt Commercial License Agreement provided with | 16 | ** accordance with the KDGantt Commercial License Agreement provided with |
17 | ** the Software. | 17 | ** the Software. |
18 | ** | 18 | ** |
19 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 19 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
20 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 20 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
21 | ** | 21 | ** |
22 | ** See http://www.klaralvdalens-datakonsult.se/Public/products/ for | 22 | ** See http://www.klaralvdalens-datakonsult.se/Public/products/ for |
23 | ** information about KDGantt Commercial License Agreements. | 23 | ** information about KDGantt Commercial License Agreements. |
24 | ** | 24 | ** |
25 | ** Contact info@klaralvdalens-datakonsult.se if any conditions of this | 25 | ** Contact info@klaralvdalens-datakonsult.se if any conditions of this |
26 | ** licensing are not clear to you. | 26 | ** licensing are not clear to you. |
27 | ** | 27 | ** |
28 | ** As a special exception, permission is given to link this program | 28 | ** As a special exception, permission is given to link this program |
29 | ** with any edition of Qt, and distribute the resulting executable, | 29 | ** with any edition of Qt, and distribute the resulting executable, |
30 | ** without including the source code for Qt in the source distribution. | 30 | ** without including the source code for Qt in the source distribution. |
31 | ** | 31 | ** |
32 | **********************************************************************/ | 32 | **********************************************************************/ |
33 | 33 | ||
34 | #include "KDGanttMinimizeSplitter.h" | 34 | #include "KDGanttMinimizeSplitter.h" |
35 | #ifndef QT_NO_SPLITTER___ | 35 | #ifndef QT_NO_SPLITTER___ |
36 | 36 | ||
37 | #include "qpainter.h" | 37 | #include "qpainter.h" |
38 | #include "qdrawutil.h" | 38 | #include "qdrawutil.h" |
39 | #include "qbitmap.h" | 39 | #include "qbitmap.h" |
40 | #if QT_VERSION >= 0x030000 | 40 | #if QT_VERSION >= 0x030000 |
41 | #include "qptrlist.h" | 41 | #include "qptrlist.h" |
42 | #include "qmemarray.h" | 42 | #include "qmemarray.h" |
43 | #else | 43 | #else |
44 | #include <qlist.h> | 44 | #include <qlist.h> |
45 | #include <qarray.h> | 45 | #include <qarray.h> |
46 | #define QPtrList QList | 46 | #define QPtrList QList |
47 | #define QMemArray QArray | 47 | #define QMemArray QArray |
48 | #endif | 48 | #endif |
49 | #include "qlayoutengine_p.h" | 49 | #include "qlayoutengine_p.h" |
50 | #include "qobjectlist.h" | 50 | #include "qobjectlist.h" |
51 | #include "qstyle.h" | 51 | #include "qstyle.h" |
52 | #include "qapplication.h" //sendPostedEvents | 52 | #include "qapplication.h" //sendPostedEvents |
53 | #include <qvaluelist.h> | 53 | #include <qvaluelist.h> |
54 | #include <qcursor.h> | 54 | #include <qcursor.h> |
55 | #ifndef KDGANTT_MASTER_CVS | 55 | #ifndef KDGANTT_MASTER_CVS |
56 | //#include "KDGanttMinimizeSplitter.moc" | 56 | //#include "KDGanttMinimizeSplitter.moc" |
57 | #endif | 57 | #endif |
58 | 58 | ||
59 | 59 | ||
60 | 60 | ||
61 | #ifndef DOXYGEN_SKIP_INTERNAL | 61 | #ifndef DOXYGEN_SKIP_INTERNAL |
62 | 62 | ||
63 | #if QT_VERSION >= 232 | 63 | #if QT_VERSION >= 232 |
64 | static int mouseOffset; | 64 | static int mouseOffset; |
65 | static int opaqueOldPos = -1; //### there's only one mouse, but this is a bit risky | 65 | static int opaqueOldPos = -1; //### there's only one mouse, but this is a bit risky |
66 | 66 | ||
67 | 67 | ||
68 | KDGanttSplitterHandle::KDGanttSplitterHandle( Qt::Orientation o, | 68 | KDGanttSplitterHandle::KDGanttSplitterHandle( Qt::Orientation o, |
69 | KDGanttMinimizeSplitter *parent, const char * name ) | 69 | KDGanttMinimizeSplitter *parent, const char * name ) |
70 | : QWidget( parent, name ), _activeButton( 0 ), _collapsed( false ) | 70 | : QWidget( parent, name ), _activeButton( 0 ), _collapsed( false ) |
71 | { | 71 | { |
72 | 72 | ||
73 | if ( QApplication::desktop()->width() > 320 && QApplication::desktop()->width() < 650 ) { | 73 | if ( QApplication::desktop()->width() > 320 && QApplication::desktop()->width() < 650 ) { |
74 | mSizeHint = QSize(7,7); | 74 | mSizeHint = QSize(7,7); |
75 | mUseOffset = true; | 75 | mUseOffset = true; |
76 | } else { | 76 | } else { |
77 | mSizeHint = QSize(6,6); | 77 | mSizeHint = QSize(6,6); |
78 | mUseOffset = false; | 78 | mUseOffset = false; |
79 | } | 79 | } |
80 | s = parent; | 80 | s = parent; |
81 | setOrientation(o); | 81 | setOrientation(o); |
82 | setMouseTracking( true ); | 82 | setMouseTracking( true ); |
83 | mMouseDown = false; | 83 | mMouseDown = false; |
84 | //setMaximumHeight( 5 ); // test only | 84 | //setMaximumHeight( 5 ); // test only |
85 | } | 85 | } |
86 | 86 | ||
87 | QSize KDGanttSplitterHandle::sizeHint() const | 87 | QSize KDGanttSplitterHandle::sizeHint() const |
88 | { | 88 | { |
89 | return mSizeHint; | 89 | return mSizeHint; |
90 | } | 90 | } |
91 | 91 | ||
92 | void KDGanttSplitterHandle::setOrientation( Qt::Orientation o ) | 92 | void KDGanttSplitterHandle::setOrientation( Qt::Orientation o ) |
93 | { | 93 | { |
94 | orient = o; | 94 | orient = o; |
95 | #ifndef QT_NO_CURSOR | 95 | #ifndef QT_NO_CURSOR |
96 | if ( o == KDGanttMinimizeSplitter::Horizontal ) | 96 | if ( o == KDGanttMinimizeSplitter::Horizontal ) |
97 | setCursor( splitHCursor ); | 97 | setCursor( splitHCursor ); |
98 | else | 98 | else |
99 | setCursor( splitVCursor ); | 99 | setCursor( splitVCursor ); |
100 | #endif | 100 | #endif |
101 | } | 101 | } |
102 | 102 | ||
103 | 103 | ||
104 | void KDGanttSplitterHandle::mouseMoveEvent( QMouseEvent *e ) | 104 | void KDGanttSplitterHandle::mouseMoveEvent( QMouseEvent *e ) |
105 | { | 105 | { |
106 | updateCursor( e->pos() ); | 106 | updateCursor( e->pos() ); |
107 | if ( !(e->state()&LeftButton) ) | 107 | if ( !(e->state()&LeftButton) ) |
108 | return; | 108 | return; |
109 | 109 | ||
110 | if ( _activeButton != 0) | 110 | if ( _activeButton != 0) |
111 | return; | 111 | return; |
112 | 112 | ||
113 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) | 113 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) |
114 | - mouseOffset; | 114 | - mouseOffset; |
115 | if ( opaque() ) { | 115 | if ( opaque() ) { |
116 | s->moveSplitter( pos, id() ); | 116 | s->moveSplitter( pos, id() ); |
117 | } else { | 117 | } else { |
118 | int min = pos; int max = pos; | 118 | int min = pos; int max = pos; |
119 | s->getRange( id(), &min, &max ); | 119 | s->getRange( id(), &min, &max ); |
120 | s->setRubberband( QMAX( min, QMIN(max, pos ))); | 120 | s->setRubberband( QMAX( min, QMIN(max, pos ))); |
121 | } | 121 | } |
122 | _collapsed = false; | 122 | _collapsed = false; |
123 | } | 123 | } |
124 | 124 | ||
125 | void KDGanttSplitterHandle::mousePressEvent( QMouseEvent *e ) | 125 | void KDGanttSplitterHandle::mousePressEvent( QMouseEvent *e ) |
126 | { | 126 | { |
127 | if ( e->button() == LeftButton ) { | 127 | if ( e->button() == LeftButton ) { |
128 | _activeButton = onButton( e->pos() ); | 128 | _activeButton = onButton( e->pos() ); |
129 | mouseOffset = s->pick(e->pos()); | 129 | mouseOffset = s->pick(e->pos()); |
130 | mMouseDown = true; | 130 | mMouseDown = true; |
131 | repaint(); | 131 | repaint(); |
132 | updateCursor( e->pos() ); | 132 | updateCursor( e->pos() ); |
133 | } | 133 | } |
134 | } | 134 | } |
135 | 135 | ||
136 | void KDGanttSplitterHandle::updateCursor( const QPoint& p) | 136 | void KDGanttSplitterHandle::updateCursor( const QPoint& p) |
137 | { | 137 | { |
138 | if ( onButton( p ) != 0 ) { | 138 | if ( onButton( p ) != 0 ) { |
139 | setCursor( arrowCursor ); | 139 | setCursor( arrowCursor ); |
140 | } | 140 | } |
141 | else { | 141 | else { |
142 | if ( orient == KDGanttMinimizeSplitter::Horizontal ) | 142 | if ( orient == KDGanttMinimizeSplitter::Horizontal ) |
143 | setCursor( splitHCursor ); | 143 | setCursor( splitHCursor ); |
144 | else | 144 | else |
145 | setCursor( splitVCursor ); | 145 | setCursor( splitVCursor ); |
146 | } | 146 | } |
147 | } | 147 | } |
148 | void KDGanttSplitterHandle::toggle() | 148 | void KDGanttSplitterHandle::toggle() |
149 | { | 149 | { |
150 | int pos; | 150 | int pos; |
151 | int min, max; | 151 | int min, max; |
152 | if ( !_collapsed ) { | 152 | if ( !_collapsed ) { |
153 | s->expandPos( id(), &min, &max ); | 153 | s->expandPos( id(), &min, &max ); |
154 | if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left | 154 | if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left |
155 | || s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) { | 155 | || s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) { |
156 | pos = min; | 156 | pos = min; |
157 | } | 157 | } |
158 | else { | 158 | else { |
159 | pos = max; | 159 | pos = max; |
160 | } | 160 | } |
161 | 161 | ||
162 | _origPos = s->pick(mapToParent( QPoint( 0,0 ) )); | 162 | _origPos = s->pick(mapToParent( QPoint( 0,0 ) )); |
163 | s->moveSplitter( pos, id() ); | 163 | s->moveSplitter( pos, id() ); |
164 | _collapsed = true; | 164 | _collapsed = true; |
165 | } | 165 | } |
166 | else { | 166 | else { |
167 | s->moveSplitter( _origPos, id() ); | 167 | s->moveSplitter( _origPos, id() ); |
168 | _collapsed = false; | 168 | _collapsed = false; |
169 | } | 169 | } |
170 | repaint(); | 170 | repaint(); |
171 | } | 171 | } |
172 | 172 | ||
173 | void KDGanttSplitterHandle::mouseReleaseEvent( QMouseEvent *e ) | 173 | void KDGanttSplitterHandle::mouseReleaseEvent( QMouseEvent *e ) |
174 | { | 174 | { |
175 | mMouseDown = false; | 175 | mMouseDown = false; |
176 | if ( _activeButton != 0 ) { | 176 | if ( _activeButton != 0 ) { |
177 | if ( onButton( e->pos() ) == _activeButton ) | 177 | if ( onButton( e->pos() ) == _activeButton ) |
178 | { | 178 | { |
179 | toggle(); | 179 | toggle(); |
180 | } | 180 | } |
181 | _activeButton = 0; | 181 | _activeButton = 0; |
182 | updateCursor( e->pos() ); | 182 | updateCursor( e->pos() ); |
183 | } | 183 | } |
184 | else { | 184 | else { |
185 | if ( !opaque() && e->button() == LeftButton ) { | 185 | if ( !opaque() && e->button() == LeftButton ) { |
186 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) | 186 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) |
187 | - mouseOffset; | 187 | - mouseOffset; |
188 | s->setRubberband( -1 ); | 188 | s->setRubberband( -1 ); |
189 | s->moveSplitter( pos, id() ); | 189 | s->moveSplitter( pos, id() ); |
190 | } | 190 | } |
191 | } | 191 | } |
192 | if ( s->rubberBand() ) | 192 | if ( s->rubberBand() ) |
193 | s->rubberBand()->hide(); | 193 | s->rubberBand()->hide(); |
194 | repaint(); | 194 | repaint(); |
195 | } | 195 | } |
196 | 196 | ||
197 | int KDGanttSplitterHandle::onButton( const QPoint& p ) | 197 | int KDGanttSplitterHandle::onButton( const QPoint& p ) |
198 | { | 198 | { |
199 | QValueList<QPointArray> list = buttonRegions(); | 199 | QValueList<QPointArray> list = buttonRegions(); |
200 | int index = 1; | 200 | int index = 1; |
201 | int add = 12; | 201 | int add = 12; |
202 | for( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { | 202 | for( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { |
203 | QRect rect = (*it).boundingRect(); | 203 | QRect rect = (*it).boundingRect(); |
204 | rect.setLeft( rect.left()- add ); | 204 | rect.setLeft( rect.left()- add ); |
205 | rect.setRight( rect.right() + add); | 205 | rect.setRight( rect.right() + add); |
206 | rect.setTop( rect.top()- add ); | 206 | rect.setTop( rect.top()- add ); |
207 | rect.setBottom( rect.bottom() + add); | 207 | rect.setBottom( rect.bottom() + add); |
208 | if ( rect.contains( p ) ) { | 208 | if ( rect.contains( p ) ) { |
209 | return index; | 209 | return index; |
210 | } | 210 | } |
211 | index++; | 211 | index++; |
212 | } | 212 | } |
213 | return 0; | 213 | return 0; |
214 | } | 214 | } |
215 | 215 | ||
216 | 216 | ||
217 | QValueList<QPointArray> KDGanttSplitterHandle::buttonRegions() | 217 | QValueList<QPointArray> KDGanttSplitterHandle::buttonRegions() |
218 | { | 218 | { |
219 | QValueList<QPointArray> list; | 219 | QValueList<QPointArray> list; |
220 | 220 | ||
221 | int sw = 8; | 221 | int sw = 8; |
222 | int yyy = 1; | 222 | int yyy = 1; |
223 | int xxx = 1; | 223 | int xxx = 1; |
224 | int voffset[] = { (int) -sw*3, (int) sw*3 }; | 224 | int voffset[] = { (int) -sw*3, (int) sw*3 }; |
225 | for ( int i = 0; i < 2; i++ ) { | 225 | for ( int i = 0; i < 2; i++ ) { |
226 | QPointArray arr; | 226 | QPointArray arr; |
227 | if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right || | 227 | if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right || |
228 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left) { | 228 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left) { |
229 | int mid = height()/2 + voffset[i]; | 229 | int mid = height()/2 + voffset[i]; |
230 | arr.setPoints( 3, | 230 | arr.setPoints( 3, |
231 | 1-xxx, mid - sw + 4, | 231 | 1-xxx, mid - sw + 4, |
232 | sw-3-xxx, mid, | 232 | sw-3-xxx, mid, |
233 | 1-xxx, mid + sw -4); | 233 | 1-xxx, mid + sw -4); |
234 | } | 234 | } |
235 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left || | 235 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left || |
236 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) { | 236 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) { |
237 | int mid = height()/2 + voffset[i]; | 237 | int mid = height()/2 + voffset[i]; |
238 | arr.setPoints( 3, | 238 | arr.setPoints( 3, |
239 | sw-4, mid - sw + 4, | 239 | sw-4, mid - sw + 4, |
240 | 0, mid, | 240 | 0, mid, |
241 | sw-4, mid + sw - 4); | 241 | sw-4, mid + sw - 4); |
242 | } | 242 | } |
243 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up || | 243 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up || |
244 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down) { | 244 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down) { |
245 | int mid = width()/2 + voffset[i]; | 245 | int mid = width()/2 + voffset[i]; |
246 | arr.setPoints( 3, | 246 | arr.setPoints( 3, |
247 | mid - sw + 4, sw-4, | 247 | mid - sw + 4, sw-4, |
248 | mid, 0, | 248 | mid, 0, |
249 | mid + sw - 4, sw-4 ); | 249 | mid + sw - 4, sw-4 ); |
250 | } | 250 | } |
251 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down || | 251 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down || |
252 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) { | 252 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) { |
253 | int mid = width()/2 + voffset[i]; | 253 | int mid = width()/2 + voffset[i]; |
254 | arr.setPoints( 3, | 254 | arr.setPoints( 3, |
255 | mid - sw + 4, 1-yyy, | 255 | mid - sw + 4, 1-yyy, |
256 | mid, sw-3-yyy, | 256 | mid, sw-3-yyy, |
257 | mid + sw -4, 1-yyy); | 257 | mid + sw -4, 1-yyy); |
258 | } | 258 | } |
259 | list.append( arr ); | 259 | list.append( arr ); |
260 | } | 260 | } |
261 | return list; | 261 | return list; |
262 | } | 262 | } |
263 | 263 | ||
264 | void KDGanttSplitterHandle::paintEvent( QPaintEvent * ) | 264 | void KDGanttSplitterHandle::paintEvent( QPaintEvent * ) |
265 | { | 265 | { |
266 | QPixmap buffer( size() ); | 266 | QPixmap buffer( size() ); |
267 | QPainter p( &buffer ); | 267 | QPainter p( &buffer ); |
268 | 268 | ||
269 | //LR | 269 | //LR |
270 | // Draw the splitter rectangle | 270 | // Draw the splitter rectangle |
271 | p.setBrush( colorGroup().background() ); | 271 | p.setBrush( colorGroup().background() ); |
272 | p.setPen( colorGroup().foreground() ); | 272 | p.setPen( colorGroup().foreground() ); |
273 | //p.drawRect( rect() ); | 273 | //p.drawRect( rect() ); |
274 | #ifndef DESKTOP_VERSION | 274 | #ifndef DESKTOP_VERSION |
275 | if ( mMouseDown ) | 275 | if ( mMouseDown ) |
276 | buffer.fill( QColor( 242,27,255 ) ); | 276 | buffer.fill( colorGroup().background().dark() ); |
277 | else | 277 | else |
278 | #endif | 278 | #endif |
279 | buffer.fill( colorGroup().background() ); | 279 | buffer.fill( colorGroup().background() ); |
280 | //buffer.fill( backgroundColor() ); | 280 | //buffer.fill( backgroundColor() ); |
281 | // parentWidget()->style().drawPrimitive( QStyle::PE_Panel, &p, rect(), parentWidget()->colorGroup()); | 281 | // parentWidget()->style().drawPrimitive( QStyle::PE_Panel, &p, rect(), parentWidget()->colorGroup()); |
282 | 282 | ||
283 | int sw = 8; // Hardcoded, given I didn't use styles anymore, I didn't like to use their size | 283 | int sw = 8; // Hardcoded, given I didn't use styles anymore, I didn't like to use their size |
284 | 284 | ||
285 | // arrow color | 285 | // arrow color |
286 | QColor col; | 286 | QColor col; |
287 | if ( _activeButton ) | 287 | if ( _activeButton ) |
288 | col = colorGroup().background().dark( 250 ); | 288 | col = colorGroup().background().dark( 250 ); |
289 | else { | 289 | else { |
290 | if ( mMouseDown ) | 290 | if ( mMouseDown ) |
291 | #ifndef DESKTOP_VERSION | 291 | col = Qt::white; |
292 | col = QColor( 178,18,188);//QColor( 242,27,255 );//Qt::white; | ||
293 | #else | ||
294 | col = Qt::white; | ||
295 | #endif | ||
296 | else | 292 | else |
297 | col = colorGroup().background().dark( 150 ); | 293 | col = colorGroup().background().dark( 150 ); |
298 | } | 294 | } |
299 | //QColor col = backgroundColor().dark( 130 ); | 295 | //QColor col = backgroundColor().dark( 130 ); |
300 | p.setBrush( col ); | 296 | p.setBrush( col ); |
301 | p.setPen( col ); | 297 | p.setPen( col ); |
302 | 298 | ||
303 | QValueList<QPointArray> list = buttonRegions(); | 299 | QValueList<QPointArray> list = buttonRegions(); |
304 | int index = 1; | 300 | int index = 1; |
305 | if ( mUseOffset ) | 301 | if ( mUseOffset ) |
306 | p.translate( 0, 1 ); | 302 | p.translate( 0, 1 ); |
307 | for ( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { | 303 | for ( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { |
308 | if ( index == _activeButton ) { | 304 | if ( index == _activeButton ) { |
309 | 305 | ||
310 | /* | 306 | /* |
311 | if ( ! _collapsed ) { | 307 | if ( ! _collapsed ) { |
312 | p.save(); | 308 | p.save(); |
313 | // p.translate( parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftHorizontal ), | 309 | // p.translate( parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftHorizontal ), |
314 | // parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftVertical ) ); | 310 | // parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftVertical ) ); |
315 | p.translate( -1, 0 ); | 311 | p.translate( -1, 0 ); |
316 | p.drawPolygon( *it, true ); | 312 | p.drawPolygon( *it, true ); |
317 | p.restore(); } else | 313 | p.restore(); } else |
318 | */ | 314 | */ |
319 | p.drawPolygon( *it, true ); | 315 | p.drawPolygon( *it, true ); |
320 | 316 | ||
321 | } | 317 | } |
322 | else { | 318 | else { |
323 | /* | 319 | /* |
324 | if ( ! _collapsed ) { | 320 | if ( ! _collapsed ) { |
325 | p.save(); | 321 | p.save(); |
326 | p.translate( -1, 0 ); | 322 | p.translate( -1, 0 ); |
327 | p.drawPolygon( *it, true ); | 323 | p.drawPolygon( *it, true ); |
328 | p.restore(); | 324 | p.restore(); |
329 | } else | 325 | } else |
330 | */ | 326 | */ |
331 | p.drawPolygon( *it, true ); | 327 | p.drawPolygon( *it, true ); |
332 | 328 | ||
333 | } | 329 | } |
334 | index++; | 330 | index++; |
335 | } | 331 | } |
336 | 332 | ||
337 | // Draw the lines between the arrows | 333 | // Draw the lines between the arrows |
338 | if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left || | 334 | if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left || |
339 | s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) { | 335 | s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) { |
340 | int mid = height()/2; | 336 | int mid = height()/2; |
341 | p.drawLine ( 1, mid - sw, 1, mid + sw ); | 337 | p.drawLine ( 1, mid - sw, 1, mid + sw ); |
342 | p.drawLine ( 3, mid - sw, 3, mid + sw ); | 338 | p.drawLine ( 3, mid - sw, 3, mid + sw ); |
343 | } | 339 | } |
344 | else if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Up || | 340 | else if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Up || |
345 | s->minimizeDirection() == KDGanttMinimizeSplitter::Down ) { | 341 | s->minimizeDirection() == KDGanttMinimizeSplitter::Down ) { |
346 | int mid = width()/2; | 342 | int mid = width()/2; |
347 | p.drawLine( mid -sw, 1, mid +sw, 1 ); | 343 | p.drawLine( mid -sw, 1, mid +sw, 1 ); |
348 | p.drawLine( mid -sw, 3, mid +sw, 3 ); | 344 | p.drawLine( mid -sw, 3, mid +sw, 3 ); |
349 | } | 345 | } |
350 | bitBlt( this, 0, 0, &buffer ); | 346 | bitBlt( this, 0, 0, &buffer ); |
351 | 347 | ||
352 | } | 348 | } |
353 | #endif | 349 | #endif |
354 | 350 | ||
355 | class QSplitterLayoutStruct | 351 | class QSplitterLayoutStruct |
356 | { | 352 | { |
357 | public: | 353 | public: |
358 | KDGanttMinimizeSplitter::ResizeMode mode; | 354 | KDGanttMinimizeSplitter::ResizeMode mode; |
359 | QCOORD sizer; | 355 | QCOORD sizer; |
360 | bool isSplitter; | 356 | bool isSplitter; |
361 | QWidget *wid; | 357 | QWidget *wid; |
362 | }; | 358 | }; |
363 | 359 | ||
364 | class QSplitterData | 360 | class QSplitterData |
365 | { | 361 | { |
366 | public: | 362 | public: |
367 | QSplitterData() : opaque( FALSE ), firstShow( TRUE ) {} | 363 | QSplitterData() : opaque( FALSE ), firstShow( TRUE ) {} |
368 | 364 | ||
369 | QPtrList<QSplitterLayoutStruct> list; | 365 | QPtrList<QSplitterLayoutStruct> list; |
370 | bool opaque; | 366 | bool opaque; |
371 | bool firstShow; | 367 | bool firstShow; |
372 | }; | 368 | }; |
373 | 369 | ||
374 | void kdganttGeomCalc( QMemArray<QLayoutStruct> &chain, int start, int count, int pos, | 370 | void kdganttGeomCalc( QMemArray<QLayoutStruct> &chain, int start, int count, int pos, |
375 | int space, int spacer ); | 371 | int space, int spacer ); |
376 | #endif // DOXYGEN_SKIP_INTERNAL | 372 | #endif // DOXYGEN_SKIP_INTERNAL |
377 | 373 | ||
378 | 374 | ||
379 | /*! | 375 | /*! |
380 | \class KDGanttMinimizeSplitter KDGanttMinimizeSplitter.h | 376 | \class KDGanttMinimizeSplitter KDGanttMinimizeSplitter.h |
381 | \brief The KDGanttMinimizeSplitter class implements a splitter | 377 | \brief The KDGanttMinimizeSplitter class implements a splitter |
382 | widget with minimize buttons. | 378 | widget with minimize buttons. |
383 | 379 | ||
384 | This class (and its documentation) is largely a copy of Qt's | 380 | This class (and its documentation) is largely a copy of Qt's |
385 | QSplitter; the copying was necessary because QSplitter is not | 381 | QSplitter; the copying was necessary because QSplitter is not |
386 | extensible at all. QSplitter and its documentation are licensed | 382 | extensible at all. QSplitter and its documentation are licensed |
387 | according to the GPL and the Qt Professional License (if you hold | 383 | according to the GPL and the Qt Professional License (if you hold |
388 | such a license) and are (C) Trolltech AS. | 384 | such a license) and are (C) Trolltech AS. |
389 | 385 | ||
390 | A splitter lets the user control the size of child widgets by | 386 | A splitter lets the user control the size of child widgets by |
391 | dragging the boundary between the children. Any number of widgets | 387 | dragging the boundary between the children. Any number of widgets |
392 | may be controlled. | 388 | may be controlled. |
393 | 389 | ||
394 | To show a QListBox, a QListView and a QTextEdit side by side: | 390 | To show a QListBox, a QListView and a QTextEdit side by side: |
395 | 391 | ||
396 | \code | 392 | \code |
397 | KDGanttMinimizeSplitter *split = new KDGanttMinimizeSplitter( parent ); | 393 | KDGanttMinimizeSplitter *split = new KDGanttMinimizeSplitter( parent ); |
398 | QListBox *lb = new QListBox( split ); | 394 | QListBox *lb = new QListBox( split ); |
399 | QListView *lv = new QListView( split ); | 395 | QListView *lv = new QListView( split ); |
400 | QTextEdit *ed = new QTextEdit( split ); | 396 | QTextEdit *ed = new QTextEdit( split ); |
401 | \endcode | 397 | \endcode |
402 | 398 | ||
403 | In KDGanttMinimizeSplitter, the boundary can be either horizontal or | 399 | In KDGanttMinimizeSplitter, the boundary can be either horizontal or |
404 | vertical. The default is horizontal (the children are side by side) | 400 | vertical. The default is horizontal (the children are side by side) |
405 | but you can use setOrientation( QSplitter::Vertical ) to set it to | 401 | but you can use setOrientation( QSplitter::Vertical ) to set it to |
406 | vertical. | 402 | vertical. |
407 | 403 | ||
408 | Use setResizeMode() to specify | 404 | Use setResizeMode() to specify |
409 | that a widget should keep its size when the splitter is resized. | 405 | that a widget should keep its size when the splitter is resized. |
410 | 406 | ||
411 | Although KDGanttMinimizeSplitter normally resizes the children only | 407 | Although KDGanttMinimizeSplitter normally resizes the children only |
412 | at the end of a resize operation, if you call setOpaqueResize( TRUE | 408 | at the end of a resize operation, if you call setOpaqueResize( TRUE |
413 | ) the widgets are resized as often as possible. | 409 | ) the widgets are resized as often as possible. |
414 | 410 | ||
415 | The initial distribution of size between the widgets is determined | 411 | The initial distribution of size between the widgets is determined |
416 | by the initial size of each widget. You can also use setSizes() to | 412 | by the initial size of each widget. You can also use setSizes() to |
417 | set the sizes of all the widgets. The function sizes() returns the | 413 | set the sizes of all the widgets. The function sizes() returns the |
418 | sizes set by the user. | 414 | sizes set by the user. |
419 | 415 | ||
420 | If you hide() a child, its space will be distributed among the other | 416 | If you hide() a child, its space will be distributed among the other |
421 | children. It will be reinstated when you show() it again. It is also | 417 | children. It will be reinstated when you show() it again. It is also |
422 | possible to reorder the widgets within the splitter using | 418 | possible to reorder the widgets within the splitter using |
423 | moveToFirst() and moveToLast(). | 419 | moveToFirst() and moveToLast(). |
424 | */ | 420 | */ |
425 | 421 | ||
426 | 422 | ||
427 | 423 | ||
428 | static QSize minSize( const QWidget* /*w*/ ) | 424 | static QSize minSize( const QWidget* /*w*/ ) |
429 | { | 425 | { |
430 | return QSize(0,0); | 426 | return QSize(0,0); |
431 | } | 427 | } |
432 | 428 | ||
433 | // This is the original version of minSize | 429 | // This is the original version of minSize |
434 | static QSize minSizeHint( const QWidget* w ) | 430 | static QSize minSizeHint( const QWidget* w ) |
435 | { | 431 | { |
436 | QSize min = w->minimumSize(); | 432 | QSize min = w->minimumSize(); |
437 | QSize s; | 433 | QSize s; |
438 | if ( min.height() <= 0 || min.width() <= 0 ) | 434 | if ( min.height() <= 0 || min.width() <= 0 ) |
439 | s = w->minimumSizeHint(); | 435 | s = w->minimumSizeHint(); |
440 | if ( min.height() > 0 ) | 436 | if ( min.height() > 0 ) |
441 | s.setHeight( min.height() ); | 437 | s.setHeight( min.height() ); |
442 | if ( min.width() > 0 ) | 438 | if ( min.width() > 0 ) |
443 | s.setWidth( min.width() ); | 439 | s.setWidth( min.width() ); |
444 | return s.expandedTo(QSize(0,0)); | 440 | return s.expandedTo(QSize(0,0)); |
445 | } | 441 | } |
446 | 442 | ||
447 | 443 | ||
448 | /*! | 444 | /*! |
449 | Constructs a horizontal splitter with the \a parent and \a | 445 | Constructs a horizontal splitter with the \a parent and \a |
450 | name arguments being passed on to the QFrame constructor. | 446 | name arguments being passed on to the QFrame constructor. |
451 | */ | 447 | */ |
452 | KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( QWidget *parent, const char *name ) | 448 | KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( QWidget *parent, const char *name ) |
453 | :QFrame(parent,name,WPaintUnclipped) | 449 | :QFrame(parent,name,WPaintUnclipped) |
454 | { | 450 | { |
455 | mRubberBand = 0; | 451 | mRubberBand = 0; |
456 | mFirstHandle = 0; | 452 | mFirstHandle = 0; |
457 | #if QT_VERSION >= 232 | 453 | #if QT_VERSION >= 232 |
458 | orient = Horizontal; | 454 | orient = Horizontal; |
459 | init(); | 455 | init(); |
460 | #endif | 456 | #endif |
461 | } | 457 | } |
462 | 458 | ||
463 | /*! | 459 | /*! |
464 | Constructs a splitter with orientation \a o with the \a parent | 460 | Constructs a splitter with orientation \a o with the \a parent |
465 | and \a name arguments being passed on to the QFrame constructor. | 461 | and \a name arguments being passed on to the QFrame constructor. |
466 | */ | 462 | */ |
467 | KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( Orientation o, QWidget *parent, const char *name ) | 463 | KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( Orientation o, QWidget *parent, const char *name ) |
468 | :QFrame(parent,name,WPaintUnclipped) | 464 | :QFrame(parent,name,WPaintUnclipped) |
469 | { | 465 | { |
470 | 466 | ||
471 | mRubberBand = 0; | 467 | mRubberBand = 0; |
472 | mFirstHandle = 0; | 468 | mFirstHandle = 0; |
473 | #if QT_VERSION >= 232 | 469 | #if QT_VERSION >= 232 |
474 | orient = o; | 470 | orient = o; |
475 | init(); | 471 | init(); |
476 | #endif | 472 | #endif |
477 | } | 473 | } |
478 | 474 | ||
479 | /*! | 475 | /*! |
480 | Destroys the splitter and any children. | 476 | Destroys the splitter and any children. |
481 | */ | 477 | */ |
482 | KDGanttMinimizeSplitter::~KDGanttMinimizeSplitter() | 478 | KDGanttMinimizeSplitter::~KDGanttMinimizeSplitter() |
483 | { | 479 | { |
484 | #if QT_VERSION >= 232 | 480 | #if QT_VERSION >= 232 |
485 | data->list.setAutoDelete( TRUE ); | 481 | data->list.setAutoDelete( TRUE ); |
486 | delete data; | 482 | delete data; |
487 | #endif | 483 | #endif |
488 | if ( mRubberBand ) | 484 | if ( mRubberBand ) |
489 | delete mRubberBand; | 485 | delete mRubberBand; |
490 | } | 486 | } |
491 | 487 | ||
492 | 488 | ||
493 | #if QT_VERSION >= 232 | 489 | #if QT_VERSION >= 232 |
494 | void KDGanttMinimizeSplitter::init() | 490 | void KDGanttMinimizeSplitter::init() |
495 | { | 491 | { |
496 | data = new QSplitterData; | 492 | data = new QSplitterData; |
497 | if ( orient == Horizontal ) | 493 | if ( orient == Horizontal ) |
498 | setSizePolicy( QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum) ); | 494 | setSizePolicy( QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum) ); |
499 | else | 495 | else |
500 | setSizePolicy( QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Expanding) ); | 496 | setSizePolicy( QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Expanding) ); |
501 | #ifndef DESKTOP_VERSION | 497 | #ifndef DESKTOP_VERSION |
502 | setOpaqueResize( false ); | 498 | setOpaqueResize( false ); |
503 | #else | 499 | #else |
504 | setOpaqueResize( true ); | 500 | setOpaqueResize( true ); |
505 | #endif | 501 | #endif |
506 | } | 502 | } |
507 | #endif | 503 | #endif |
508 | 504 | ||
509 | 505 | ||
510 | void KDGanttMinimizeSplitter::toggle() | 506 | void KDGanttMinimizeSplitter::toggle() |
511 | { | 507 | { |
512 | if ( mFirstHandle ) | 508 | if ( mFirstHandle ) |
513 | mFirstHandle->toggle(); | 509 | mFirstHandle->toggle(); |
514 | else | 510 | else |
515 | qDebug("KDGanttMinimizeSplitter::toggle::sorry, handle not available "); | 511 | qDebug("KDGanttMinimizeSplitter::toggle::sorry, handle not available "); |
516 | 512 | ||
517 | } | 513 | } |
518 | 514 | ||
519 | 515 | ||
520 | /*! | 516 | /*! |
521 | \brief the orientation of the splitter | 517 | \brief the orientation of the splitter |
522 | 518 | ||
523 | By default the orientation is horizontal (the widgets are side by side). | 519 | By default the orientation is horizontal (the widgets are side by side). |
524 | The possible orientations are Qt:Vertical and Qt::Horizontal (the default). | 520 | The possible orientations are Qt:Vertical and Qt::Horizontal (the default). |
525 | */ | 521 | */ |
526 | void KDGanttMinimizeSplitter::setOrientation( Orientation o ) | 522 | void KDGanttMinimizeSplitter::setOrientation( Orientation o ) |
527 | { | 523 | { |
528 | #if QT_VERSION >= 232 | 524 | #if QT_VERSION >= 232 |
529 | if ( orient == o ) | 525 | if ( orient == o ) |
530 | return; | 526 | return; |
531 | orient = o; | 527 | orient = o; |
532 | 528 | ||
533 | if ( orient == Horizontal ) | 529 | if ( orient == Horizontal ) |
534 | setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); | 530 | setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); |
535 | else | 531 | else |
536 | setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); | 532 | setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); |
537 | 533 | ||
538 | QSplitterLayoutStruct *s = data->list.first(); | 534 | QSplitterLayoutStruct *s = data->list.first(); |
539 | while ( s ) { | 535 | while ( s ) { |
540 | if ( s->isSplitter ) | 536 | if ( s->isSplitter ) |
541 | ((KDGanttSplitterHandle*)s->wid)->setOrientation( o ); | 537 | ((KDGanttSplitterHandle*)s->wid)->setOrientation( o ); |
542 | s = data->list.next(); // ### next at end of loop, no iterator | 538 | s = data->list.next(); // ### next at end of loop, no iterator |
543 | } | 539 | } |
544 | recalc( isVisible() ); | 540 | recalc( isVisible() ); |
545 | #endif | 541 | #endif |
546 | } | 542 | } |
547 | 543 | ||
548 | 544 | ||
549 | #if QT_VERSION >= 232 | 545 | #if QT_VERSION >= 232 |
550 | /*! | 546 | /*! |
551 | \reimp | 547 | \reimp |
552 | */ | 548 | */ |
553 | void KDGanttMinimizeSplitter::resizeEvent( QResizeEvent * ) | 549 | void KDGanttMinimizeSplitter::resizeEvent( QResizeEvent * ) |
554 | { | 550 | { |
555 | doResize(); | 551 | doResize(); |
556 | } | 552 | } |
557 | 553 | ||
558 | 554 | ||
559 | /* | 555 | /* |
560 | Inserts the widget \a w at the end (or at the beginning if \a first | 556 | Inserts the widget \a w at the end (or at the beginning if \a first |
561 | is TRUE) of the splitter's list of widgets. | 557 | is TRUE) of the splitter's list of widgets. |
562 | 558 | ||
563 | It is the responsibility of the caller of this function to make sure | 559 | It is the responsibility of the caller of this function to make sure |
564 | that \a w is not already in the splitter and to call recalcId if | 560 | that \a w is not already in the splitter and to call recalcId if |
565 | needed. (If \a first is TRUE, then recalcId is very probably | 561 | needed. (If \a first is TRUE, then recalcId is very probably |
566 | needed.) | 562 | needed.) |
567 | */ | 563 | */ |
568 | QSplitterLayoutStruct *KDGanttMinimizeSplitter::addWidget( QWidget *w, bool first ) | 564 | QSplitterLayoutStruct *KDGanttMinimizeSplitter::addWidget( QWidget *w, bool first ) |
569 | { | 565 | { |
570 | QSplitterLayoutStruct *s; | 566 | QSplitterLayoutStruct *s; |
571 | KDGanttSplitterHandle *newHandle = 0; | 567 | KDGanttSplitterHandle *newHandle = 0; |
572 | if ( data->list.count() > 0 ) { | 568 | if ( data->list.count() > 0 ) { |
573 | s = new QSplitterLayoutStruct; | 569 | s = new QSplitterLayoutStruct; |
574 | s->mode = KeepSize; | 570 | s->mode = KeepSize; |
575 | QString tmp = "qt_splithandle_"; | 571 | QString tmp = "qt_splithandle_"; |
576 | tmp += w->name(); | 572 | tmp += w->name(); |
577 | newHandle = new KDGanttSplitterHandle( orientation(), this, tmp.latin1() ); | 573 | newHandle = new KDGanttSplitterHandle( orientation(), this, tmp.latin1() ); |
578 | if ( ! mFirstHandle ) | 574 | if ( ! mFirstHandle ) |
579 | mFirstHandle = newHandle; | 575 | mFirstHandle = newHandle; |
580 | s->wid = newHandle; | 576 | s->wid = newHandle; |
581 | newHandle->setId(data->list.count()); | 577 | newHandle->setId(data->list.count()); |
582 | s->isSplitter = TRUE; | 578 | s->isSplitter = TRUE; |
583 | s->sizer = pick( newHandle->sizeHint() ); | 579 | s->sizer = pick( newHandle->sizeHint() ); |
584 | if ( first ) | 580 | if ( first ) |
585 | data->list.insert( 0, s ); | 581 | data->list.insert( 0, s ); |
586 | else | 582 | else |
587 | data->list.append( s ); | 583 | data->list.append( s ); |
588 | } | 584 | } |
589 | s = new QSplitterLayoutStruct; | 585 | s = new QSplitterLayoutStruct; |
590 | s->mode = Stretch; | 586 | s->mode = Stretch; |
591 | s->wid = w; | 587 | s->wid = w; |
592 | if ( !testWState( WState_Resized ) && w->sizeHint().isValid() ) | 588 | if ( !testWState( WState_Resized ) && w->sizeHint().isValid() ) |
593 | s->sizer = pick( w->sizeHint() ); | 589 | s->sizer = pick( w->sizeHint() ); |
594 | else | 590 | else |
595 | s->sizer = pick( w->size() ); | 591 | s->sizer = pick( w->size() ); |
596 | s->isSplitter = FALSE; | 592 | s->isSplitter = FALSE; |
597 | if ( first ) | 593 | if ( first ) |
598 | data->list.insert( 0, s ); | 594 | data->list.insert( 0, s ); |
599 | else | 595 | else |
600 | data->list.append( s ); | 596 | data->list.append( s ); |
601 | if ( newHandle && isVisible() ) | 597 | if ( newHandle && isVisible() ) |
602 | newHandle->show(); //will trigger sending of post events | 598 | newHandle->show(); //will trigger sending of post events |
603 | return s; | 599 | return s; |
604 | } | 600 | } |
605 | 601 | ||
606 | 602 | ||
607 | /*! | 603 | /*! |
608 | Tells the splitter that a child widget has been inserted or removed. | 604 | Tells the splitter that a child widget has been inserted or removed. |
609 | The event is passed in \a c. | 605 | The event is passed in \a c. |
610 | */ | 606 | */ |
611 | void KDGanttMinimizeSplitter::childEvent( QChildEvent *c ) | 607 | void KDGanttMinimizeSplitter::childEvent( QChildEvent *c ) |
612 | { | 608 | { |
613 | if ( c->type() == QEvent::ChildInserted ) { | 609 | if ( c->type() == QEvent::ChildInserted ) { |
614 | if ( !c->child()->isWidgetType() ) | 610 | if ( !c->child()->isWidgetType() ) |
615 | return; | 611 | return; |
616 | 612 | ||
617 | if ( ((QWidget*)c->child())->testWFlags( WType_TopLevel ) ) | 613 | if ( ((QWidget*)c->child())->testWFlags( WType_TopLevel ) ) |
618 | return; | 614 | return; |
619 | 615 | ||
620 | QSplitterLayoutStruct *s = data->list.first(); | 616 | QSplitterLayoutStruct *s = data->list.first(); |
621 | while ( s ) { | 617 | while ( s ) { |
622 | if ( s->wid == c->child() ) | 618 | if ( s->wid == c->child() ) |
623 | return; | 619 | return; |
624 | s = data->list.next(); | 620 | s = data->list.next(); |
625 | } | 621 | } |
626 | addWidget( (QWidget*)c->child() ); | 622 | addWidget( (QWidget*)c->child() ); |
627 | recalc( isVisible() ); | 623 | recalc( isVisible() ); |
628 | 624 | ||
629 | } else if ( c->type() == QEvent::ChildRemoved ) { | 625 | } else if ( c->type() == QEvent::ChildRemoved ) { |
630 | QSplitterLayoutStruct *p = 0; | 626 | QSplitterLayoutStruct *p = 0; |
631 | if ( data->list.count() > 1 ) | 627 | if ( data->list.count() > 1 ) |
632 | p = data->list.at(1); //remove handle _after_ first widget. | 628 | p = data->list.at(1); //remove handle _after_ first widget. |
633 | QSplitterLayoutStruct *s = data->list.first(); | 629 | QSplitterLayoutStruct *s = data->list.first(); |
634 | while ( s ) { | 630 | while ( s ) { |
635 | if ( s->wid == c->child() ) { | 631 | if ( s->wid == c->child() ) { |
636 | data->list.removeRef( s ); | 632 | data->list.removeRef( s ); |
637 | delete s; | 633 | delete s; |
638 | if ( p && p->isSplitter ) { | 634 | if ( p && p->isSplitter ) { |
639 | data->list.removeRef( p ); | 635 | data->list.removeRef( p ); |
640 | delete p->wid; //will call childEvent | 636 | delete p->wid; //will call childEvent |
641 | delete p; | 637 | delete p; |
642 | } | 638 | } |
643 | recalcId(); | 639 | recalcId(); |
644 | doResize(); | 640 | doResize(); |
645 | return; | 641 | return; |
646 | } | 642 | } |
647 | p = s; | 643 | p = s; |
648 | s = data->list.next(); | 644 | s = data->list.next(); |
649 | } | 645 | } |
650 | } | 646 | } |
651 | } | 647 | } |
652 | 648 | ||
653 | 649 | ||
654 | /*! | 650 | /*! |
655 | Shows a rubber band at position \a p. If \a p is negative, the | 651 | Shows a rubber band at position \a p. If \a p is negative, the |
656 | rubber band is removed. | 652 | rubber band is removed. |
657 | */ | 653 | */ |
658 | void KDGanttMinimizeSplitter::setRubberband( int p ) | 654 | void KDGanttMinimizeSplitter::setRubberband( int p ) |
659 | { | 655 | { |
660 | #ifdef DESKTOP_VERSION | 656 | #ifdef DESKTOP_VERSION |
661 | QPainter paint( this ); | 657 | QPainter paint( this ); |
662 | paint.setPen( gray ); | 658 | paint.setPen( gray ); |
663 | paint.setBrush( gray ); | 659 | paint.setBrush( gray ); |
664 | paint.setRasterOp( XorROP ); | 660 | paint.setRasterOp( XorROP ); |
665 | QRect r = contentsRect(); | 661 | QRect r = contentsRect(); |
666 | const int rBord = 3; //Themable???? | 662 | const int rBord = 3; //Themable???? |
667 | #if QT_VERSION >= 0x030000 | 663 | #if QT_VERSION >= 0x030000 |
668 | int sw = style().pixelMetric(QStyle::PM_SplitterWidth, this); | 664 | int sw = style().pixelMetric(QStyle::PM_SplitterWidth, this); |
669 | #else | 665 | #else |
670 | int sw = style().splitterWidth(); | 666 | int sw = style().splitterWidth(); |
671 | #endif | 667 | #endif |
672 | if ( orient == Horizontal ) { | 668 | if ( orient == Horizontal ) { |
673 | if ( opaqueOldPos >= 0 ) | 669 | if ( opaqueOldPos >= 0 ) |
674 | paint.drawRect( opaqueOldPos + sw/2 - rBord , r.y(), | 670 | paint.drawRect( opaqueOldPos + sw/2 - rBord , r.y(), |
675 | 2*rBord, r.height() ); | 671 | 2*rBord, r.height() ); |
676 | if ( p >= 0 ) | 672 | if ( p >= 0 ) |
677 | paint.drawRect( p + sw/2 - rBord, r.y(), 2*rBord, r.height() ); | 673 | paint.drawRect( p + sw/2 - rBord, r.y(), 2*rBord, r.height() ); |
678 | } else { | 674 | } else { |
679 | if ( opaqueOldPos >= 0 ) | 675 | if ( opaqueOldPos >= 0 ) |
680 | paint.drawRect( r.x(), opaqueOldPos + sw/2 - rBord, | 676 | paint.drawRect( r.x(), opaqueOldPos + sw/2 - rBord, |
681 | r.width(), 2*rBord ); | 677 | r.width(), 2*rBord ); |
682 | if ( p >= 0 ) | 678 | if ( p >= 0 ) |
683 | paint.drawRect( r.x(), p + sw/2 - rBord, r.width(), 2*rBord ); | 679 | paint.drawRect( r.x(), p + sw/2 - rBord, r.width(), 2*rBord ); |
684 | } | 680 | } |
685 | opaqueOldPos = p; | 681 | opaqueOldPos = p; |
686 | #else | 682 | #else |
687 | if ( !mRubberBand ) { | 683 | if ( !mRubberBand ) { |
688 | mRubberBand = new QFrame( 0, "rubber", WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop); | 684 | mRubberBand = new QFrame( 0, "rubber", WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop); |
689 | mRubberBand->setFrameStyle( Box | Raised ); | 685 | mRubberBand->setFrameStyle( Box | Raised ); |
690 | //mRubberBand->setPalette( QPalette ( Qt::red.light(),Qt::red.dark() ) ); | 686 | //mRubberBand->setPalette( QPalette ( Qt::red.light(),Qt::red.dark() ) ); |
691 | mRubberBand->setPalette( QPalette ( QColor( 178,18,188), QColor( 242,27,255 ) )); | 687 | mRubberBand->setPalette( QPalette ( colorGroup().background().light(), colorGroup().background().dark() )); |
692 | } | 688 | } |
693 | QRect r = contentsRect(); | 689 | QRect r = contentsRect(); |
694 | static int rBord = 0; //Themable???? | 690 | static int rBord = 0; //Themable???? |
695 | if ( !rBord ) { | 691 | if ( !rBord ) { |
696 | if (QApplication::desktop()->width() <= 320 ) | 692 | if (QApplication::desktop()->width() <= 320 ) |
697 | rBord = 3; | 693 | rBord = 3; |
698 | else | 694 | else |
699 | rBord = 4; | 695 | rBord = 4; |
700 | } | 696 | } |
701 | int sw = style().splitterWidth(); | 697 | int sw = style().splitterWidth(); |
702 | if ( orient == Horizontal ) { | 698 | if ( orient == Horizontal ) { |
703 | if ( p >= 0 ) { | 699 | if ( p >= 0 ) { |
704 | QPoint geo = mapToGlobal (QPoint ( p + sw/2 - rBord, r.y())); | 700 | QPoint geo = mapToGlobal (QPoint ( p + sw/2 - rBord, r.y())); |
705 | mRubberBand->setGeometry( geo.x(), geo.y(), 2*rBord, r.height() ); | 701 | mRubberBand->setGeometry( geo.x(), geo.y(), 2*rBord, r.height() ); |
706 | } | 702 | } |
707 | } else { | 703 | } else { |
708 | if ( p >= 0 ) { | 704 | if ( p >= 0 ) { |
709 | QPoint geo = mapToGlobal (QPoint ( r.x(), p + sw/2 - rBord)); | 705 | QPoint geo = mapToGlobal (QPoint ( r.x(), p + sw/2 - rBord)); |
710 | mRubberBand->setGeometry( geo.x(), geo.y(), r.width(), 2*rBord); | 706 | mRubberBand->setGeometry( geo.x(), geo.y(), r.width(), 2*rBord); |
711 | } | 707 | } |
712 | } | 708 | } |
713 | opaqueOldPos = p; | 709 | opaqueOldPos = p; |
714 | if ( ! mRubberBand->isVisible() ) { | 710 | if ( ! mRubberBand->isVisible() ) { |
715 | mRubberBand->show(); | 711 | mRubberBand->show(); |
716 | } | 712 | } |
717 | #endif | 713 | #endif |
718 | } | 714 | } |
719 | 715 | ||
720 | 716 | ||
721 | /*! \reimp */ | 717 | /*! \reimp */ |
722 | bool KDGanttMinimizeSplitter::event( QEvent *e ) | 718 | bool KDGanttMinimizeSplitter::event( QEvent *e ) |
723 | { | 719 | { |
724 | if ( e->type() == QEvent::LayoutHint || ( e->type() == QEvent::Show && data->firstShow ) ) { | 720 | if ( e->type() == QEvent::LayoutHint || ( e->type() == QEvent::Show && data->firstShow ) ) { |
725 | recalc( isVisible() ); | 721 | recalc( isVisible() ); |
726 | if ( e->type() == QEvent::Show ) | 722 | if ( e->type() == QEvent::Show ) |
727 | data->firstShow = FALSE; | 723 | data->firstShow = FALSE; |
728 | } | 724 | } |
729 | return QWidget::event( e ); | 725 | return QWidget::event( e ); |
730 | } | 726 | } |
731 | 727 | ||
732 | 728 | ||
733 | /*! | 729 | /*! |
734 | \obsolete | 730 | \obsolete |
735 | 731 | ||
736 | Draws the splitter handle in the rectangle described by \a x, \a y, | 732 | Draws the splitter handle in the rectangle described by \a x, \a y, |
737 | \a w, \a h using painter \a p. | 733 | \a w, \a h using painter \a p. |
738 | \sa QStyle::drawPrimitive() | 734 | \sa QStyle::drawPrimitive() |
739 | */ | 735 | */ |
740 | void KDGanttMinimizeSplitter::drawSplitter( QPainter *p, | 736 | void KDGanttMinimizeSplitter::drawSplitter( QPainter *p, |
741 | QCOORD x, QCOORD y, QCOORD w, QCOORD h ) | 737 | QCOORD x, QCOORD y, QCOORD w, QCOORD h ) |
742 | { | 738 | { |
743 | #if 0 | 739 | #if 0 |
744 | // LR | 740 | // LR |
745 | style().drawPrimitive(QStyle::PE_Splitter, p, QRect(x, y, w, h), colorGroup(), | 741 | style().drawPrimitive(QStyle::PE_Splitter, p, QRect(x, y, w, h), colorGroup(), |
746 | (orientation() == Qt::Horizontal ? | 742 | (orientation() == Qt::Horizontal ? |
747 | QStyle::Style_Horizontal : 0)); | 743 | QStyle::Style_Horizontal : 0)); |
748 | #endif | 744 | #endif |
749 | } | 745 | } |
750 | 746 | ||
751 | 747 | ||
752 | /*! | 748 | /*! |
753 | Returns the id of the splitter to the right of or below the widget \a w, | 749 | Returns the id of the splitter to the right of or below the widget \a w, |
754 | or 0 if there is no such splitter | 750 | or 0 if there is no such splitter |
755 | (i.e. it is either not in this KDGanttMinimizeSplitter or it is at the end). | 751 | (i.e. it is either not in this KDGanttMinimizeSplitter or it is at the end). |
756 | */ | 752 | */ |
757 | int KDGanttMinimizeSplitter::idAfter( QWidget* w ) const | 753 | int KDGanttMinimizeSplitter::idAfter( QWidget* w ) const |
758 | { | 754 | { |
759 | QSplitterLayoutStruct *s = data->list.first(); | 755 | QSplitterLayoutStruct *s = data->list.first(); |
760 | bool seen_w = FALSE; | 756 | bool seen_w = FALSE; |
761 | while ( s ) { | 757 | while ( s ) { |
762 | if ( s->isSplitter && seen_w ) | 758 | if ( s->isSplitter && seen_w ) |
763 | return data->list.at(); | 759 | return data->list.at(); |
764 | if ( !s->isSplitter && s->wid == w ) | 760 | if ( !s->isSplitter && s->wid == w ) |
765 | seen_w = TRUE; | 761 | seen_w = TRUE; |
766 | s = data->list.next(); | 762 | s = data->list.next(); |
767 | } | 763 | } |
768 | return 0; | 764 | return 0; |
769 | } | 765 | } |
770 | 766 | ||
771 | 767 | ||
772 | /*! | 768 | /*! |
773 | Moves the left/top edge of the splitter handle with id \a id as | 769 | Moves the left/top edge of the splitter handle with id \a id as |
774 | close as possible to position \a p, which is the distance from the | 770 | close as possible to position \a p, which is the distance from the |
775 | left (or top) edge of the widget. | 771 | left (or top) edge of the widget. |
776 | 772 | ||
777 | For Arabic and Hebrew the layout is reversed, and using this | 773 | For Arabic and Hebrew the layout is reversed, and using this |
778 | function to set the position of the splitter might lead to | 774 | function to set the position of the splitter might lead to |
779 | unexpected results, since in Arabic and Hebrew the position of | 775 | unexpected results, since in Arabic and Hebrew the position of |
780 | splitter one is to the left of the position of splitter zero. | 776 | splitter one is to the left of the position of splitter zero. |
781 | 777 | ||
782 | \sa idAfter() | 778 | \sa idAfter() |
783 | */ | 779 | */ |
784 | void KDGanttMinimizeSplitter::moveSplitter( QCOORD p, int id ) | 780 | void KDGanttMinimizeSplitter::moveSplitter( QCOORD p, int id ) |
785 | { | 781 | { |
786 | p = adjustPos( p, id ); | 782 | p = adjustPos( p, id ); |
787 | QSplitterLayoutStruct *s = data->list.at(id); | 783 | QSplitterLayoutStruct *s = data->list.at(id); |
788 | int oldP = orient == Horizontal ? s->wid->x() : s->wid->y(); | 784 | int oldP = orient == Horizontal ? s->wid->x() : s->wid->y(); |
789 | bool upLeft; | 785 | bool upLeft; |
790 | if ( false && orient == Horizontal ) { | 786 | if ( false && orient == Horizontal ) { |
791 | p += s->wid->width(); | 787 | p += s->wid->width(); |
792 | upLeft = p > oldP; | 788 | upLeft = p > oldP; |
793 | } else | 789 | } else |
794 | upLeft = p < oldP; | 790 | upLeft = p < oldP; |
795 | 791 | ||
796 | moveAfter( p, id, upLeft ); | 792 | moveAfter( p, id, upLeft ); |
797 | moveBefore( p-1, id-1, upLeft ); | 793 | moveBefore( p-1, id-1, upLeft ); |
798 | 794 | ||
799 | storeSizes(); | 795 | storeSizes(); |
800 | } | 796 | } |
801 | 797 | ||
802 | 798 | ||
803 | void KDGanttMinimizeSplitter::setG( QWidget *w, int p, int s, bool isSplitter ) | 799 | void KDGanttMinimizeSplitter::setG( QWidget *w, int p, int s, bool isSplitter ) |
804 | { | 800 | { |
805 | if ( orient == Horizontal ) { | 801 | if ( orient == Horizontal ) { |
806 | if ( false && orient == Horizontal && !isSplitter ) | 802 | if ( false && orient == Horizontal && !isSplitter ) |
807 | p = contentsRect().width() - p - s; | 803 | p = contentsRect().width() - p - s; |
808 | w->setGeometry( p, contentsRect().y(), s, contentsRect().height() ); | 804 | w->setGeometry( p, contentsRect().y(), s, contentsRect().height() ); |
809 | } else | 805 | } else |
810 | w->setGeometry( contentsRect().x(), p, contentsRect().width(), s ); | 806 | w->setGeometry( contentsRect().x(), p, contentsRect().width(), s ); |
811 | } | 807 | } |
812 | 808 | ||
813 | 809 | ||
814 | /* | 810 | /* |
815 | Places the right/bottom edge of the widget at \a id at position \a pos. | 811 | Places the right/bottom edge of the widget at \a id at position \a pos. |
816 | 812 | ||
817 | \sa idAfter() | 813 | \sa idAfter() |
818 | */ | 814 | */ |
819 | void KDGanttMinimizeSplitter::moveBefore( int pos, int id, bool upLeft ) | 815 | void KDGanttMinimizeSplitter::moveBefore( int pos, int id, bool upLeft ) |
820 | { | 816 | { |
821 | if( id < 0 ) | 817 | if( id < 0 ) |
822 | return; | 818 | return; |
823 | QSplitterLayoutStruct *s = data->list.at(id); | 819 | QSplitterLayoutStruct *s = data->list.at(id); |
824 | if ( !s ) | 820 | if ( !s ) |
825 | return; | 821 | return; |
826 | QWidget *w = s->wid; | 822 | QWidget *w = s->wid; |
827 | if ( w->isHidden() ) { | 823 | if ( w->isHidden() ) { |
828 | moveBefore( pos, id-1, upLeft ); | 824 | moveBefore( pos, id-1, upLeft ); |
829 | } else if ( s->isSplitter ) { | 825 | } else if ( s->isSplitter ) { |
830 | int pos1, pos2; | 826 | int pos1, pos2; |
831 | int dd = s->sizer; | 827 | int dd = s->sizer; |
832 | if( false && orient == Horizontal ) { | 828 | if( false && orient == Horizontal ) { |
833 | pos1 = pos; | 829 | pos1 = pos; |
834 | pos2 = pos + dd; | 830 | pos2 = pos + dd; |
835 | } else { | 831 | } else { |
836 | pos2 = pos - dd; | 832 | pos2 = pos - dd; |
837 | pos1 = pos2 + 1; | 833 | pos1 = pos2 + 1; |
838 | } | 834 | } |
839 | if ( upLeft ) { | 835 | if ( upLeft ) { |
840 | setG( w, pos1, dd, TRUE ); | 836 | setG( w, pos1, dd, TRUE ); |
841 | moveBefore( pos2, id-1, upLeft ); | 837 | moveBefore( pos2, id-1, upLeft ); |
842 | } else { | 838 | } else { |
843 | moveBefore( pos2, id-1, upLeft ); | 839 | moveBefore( pos2, id-1, upLeft ); |
844 | setG( w, pos1, dd, TRUE ); | 840 | setG( w, pos1, dd, TRUE ); |
845 | } | 841 | } |
846 | } else { | 842 | } else { |
847 | int dd, newLeft, nextPos; | 843 | int dd, newLeft, nextPos; |
848 | if( false && orient == Horizontal ) { | 844 | if( false && orient == Horizontal ) { |
849 | dd = w->geometry().right() - pos; | 845 | dd = w->geometry().right() - pos; |
850 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); | 846 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); |
851 | newLeft = pos+1; | 847 | newLeft = pos+1; |
852 | nextPos = newLeft + dd; | 848 | nextPos = newLeft + dd; |
853 | } else { | 849 | } else { |
854 | dd = pos - pick( w->pos() ) + 1; | 850 | dd = pos - pick( w->pos() ) + 1; |
855 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); | 851 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); |
856 | newLeft = pos-dd+1; | 852 | newLeft = pos-dd+1; |
857 | nextPos = newLeft - 1; | 853 | nextPos = newLeft - 1; |
858 | } | 854 | } |
859 | setG( w, newLeft, dd, TRUE ); | 855 | setG( w, newLeft, dd, TRUE ); |
860 | moveBefore( nextPos, id-1, upLeft ); | 856 | moveBefore( nextPos, id-1, upLeft ); |
861 | } | 857 | } |
862 | } | 858 | } |
863 | 859 | ||
864 | 860 | ||
865 | /* | 861 | /* |
866 | Places the left/top edge of the widget at \a id at position \a pos. | 862 | Places the left/top edge of the widget at \a id at position \a pos. |
867 | 863 | ||
868 | \sa idAfter() | 864 | \sa idAfter() |
869 | */ | 865 | */ |
870 | void KDGanttMinimizeSplitter::moveAfter( int pos, int id, bool upLeft ) | 866 | void KDGanttMinimizeSplitter::moveAfter( int pos, int id, bool upLeft ) |
871 | { | 867 | { |
872 | QSplitterLayoutStruct *s = id < int(data->list.count()) ? | 868 | QSplitterLayoutStruct *s = id < int(data->list.count()) ? |
873 | data->list.at(id) : 0; | 869 | data->list.at(id) : 0; |
874 | if ( !s ) | 870 | if ( !s ) |
875 | return; | 871 | return; |
876 | QWidget *w = s->wid; | 872 | QWidget *w = s->wid; |
877 | if ( w->isHidden() ) { | 873 | if ( w->isHidden() ) { |
878 | moveAfter( pos, id+1, upLeft ); | 874 | moveAfter( pos, id+1, upLeft ); |
879 | } else if ( pick( w->pos() ) == pos ) { | 875 | } else if ( pick( w->pos() ) == pos ) { |
880 | //No need to do anything if it's already there. | 876 | //No need to do anything if it's already there. |
881 | return; | 877 | return; |
882 | } else if ( s->isSplitter ) { | 878 | } else if ( s->isSplitter ) { |
883 | int dd = s->sizer; | 879 | int dd = s->sizer; |
884 | int pos1, pos2; | 880 | int pos1, pos2; |
885 | if( false && orient == Horizontal ) { | 881 | if( false && orient == Horizontal ) { |
886 | pos2 = pos - dd; | 882 | pos2 = pos - dd; |
887 | pos1 = pos2 + 1; | 883 | pos1 = pos2 + 1; |
888 | } else { | 884 | } else { |
889 | pos1 = pos; | 885 | pos1 = pos; |
890 | pos2 = pos + dd; | 886 | pos2 = pos + dd; |
891 | } | 887 | } |
892 | if ( upLeft ) { | 888 | if ( upLeft ) { |
893 | setG( w, pos1, dd, TRUE ); | 889 | setG( w, pos1, dd, TRUE ); |
894 | moveAfter( pos2, id+1, upLeft ); | 890 | moveAfter( pos2, id+1, upLeft ); |
895 | } else { | 891 | } else { |
896 | moveAfter( pos2, id+1, upLeft ); | 892 | moveAfter( pos2, id+1, upLeft ); |
897 | setG( w, pos1, dd, TRUE ); | 893 | setG( w, pos1, dd, TRUE ); |
898 | } | 894 | } |
899 | } else { | 895 | } else { |
900 | int left = pick( w->pos() ); | 896 | int left = pick( w->pos() ); |
901 | int right, dd,/* newRight,*/ newLeft, nextPos; | 897 | int right, dd,/* newRight,*/ newLeft, nextPos; |
902 | if ( false && orient == Horizontal ) { | 898 | if ( false && orient == Horizontal ) { |
903 | dd = pos - left + 1; | 899 | dd = pos - left + 1; |
904 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); | 900 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); |
905 | newLeft = pos-dd+1; | 901 | newLeft = pos-dd+1; |
906 | nextPos = newLeft - 1; | 902 | nextPos = newLeft - 1; |
907 | } else { | 903 | } else { |
908 | right = pick( w->geometry().bottomRight() ); | 904 | right = pick( w->geometry().bottomRight() ); |
909 | dd = right - pos + 1; | 905 | dd = right - pos + 1; |
910 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); | 906 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); |
911 | /*newRight = pos+dd-1;*/ | 907 | /*newRight = pos+dd-1;*/ |
912 | newLeft = pos; | 908 | newLeft = pos; |
913 | nextPos = newLeft + dd; | 909 | nextPos = newLeft + dd; |
914 | } | 910 | } |
915 | setG( w, newLeft, dd, TRUE ); | 911 | setG( w, newLeft, dd, TRUE ); |
916 | /*if( right != newRight )*/ | 912 | /*if( right != newRight )*/ |
917 | moveAfter( nextPos, id+1, upLeft ); | 913 | moveAfter( nextPos, id+1, upLeft ); |
918 | } | 914 | } |
919 | } | 915 | } |
920 | 916 | ||
921 | 917 | ||
922 | void KDGanttMinimizeSplitter::expandPos( int id, int* min, int* max ) | 918 | void KDGanttMinimizeSplitter::expandPos( int id, int* min, int* max ) |
923 | { | 919 | { |
924 | QSplitterLayoutStruct *s = data->list.at(id-1); | 920 | QSplitterLayoutStruct *s = data->list.at(id-1); |
925 | QWidget* w = s->wid; | 921 | QWidget* w = s->wid; |
926 | *min = pick( w->mapToParent( QPoint(0,0) ) ); | 922 | *min = pick( w->mapToParent( QPoint(0,0) ) ); |
927 | 923 | ||
928 | if ( (uint) id == data->list.count() ) { | 924 | if ( (uint) id == data->list.count() ) { |
929 | pick( size() ); | 925 | pick( size() ); |
930 | } | 926 | } |
931 | else { | 927 | else { |
932 | QSplitterLayoutStruct *s = data->list.at(id+1); | 928 | QSplitterLayoutStruct *s = data->list.at(id+1); |
933 | QWidget* w = s->wid; | 929 | QWidget* w = s->wid; |
934 | *max = pick( w->mapToParent( QPoint( w->width(), w->height() ) ) ) -8; | 930 | *max = pick( w->mapToParent( QPoint( w->width(), w->height() ) ) ) -8; |
935 | } | 931 | } |
936 | } | 932 | } |
937 | 933 | ||
938 | 934 | ||
939 | /*! | 935 | /*! |
940 | Returns the valid range of the splitter with id \a id in \a *min and \a *max. | 936 | Returns the valid range of the splitter with id \a id in \a *min and \a *max. |
941 | 937 | ||
942 | \sa idAfter() | 938 | \sa idAfter() |
943 | */ | 939 | */ |
944 | 940 | ||
945 | void KDGanttMinimizeSplitter::getRange( int id, int *min, int *max ) | 941 | void KDGanttMinimizeSplitter::getRange( int id, int *min, int *max ) |
946 | { | 942 | { |
947 | int minB = 0;//before | 943 | int minB = 0;//before |
948 | int maxB = 0; | 944 | int maxB = 0; |
949 | int minA = 0; | 945 | int minA = 0; |
950 | int maxA = 0;//after | 946 | int maxA = 0;//after |
951 | int n = data->list.count(); | 947 | int n = data->list.count(); |
952 | if ( id < 0 || id >= n ) | 948 | if ( id < 0 || id >= n ) |
953 | return; | 949 | return; |
954 | int i; | 950 | int i; |
955 | for ( i = 0; i < id; i++ ) { | 951 | for ( i = 0; i < id; i++ ) { |
956 | QSplitterLayoutStruct *s = data->list.at(i); | 952 | QSplitterLayoutStruct *s = data->list.at(i); |
957 | if ( s->wid->isHidden() ) { | 953 | if ( s->wid->isHidden() ) { |
958 | //ignore | 954 | //ignore |
959 | } else if ( s->isSplitter ) { | 955 | } else if ( s->isSplitter ) { |
960 | minB += s->sizer; | 956 | minB += s->sizer; |
961 | maxB += s->sizer; | 957 | maxB += s->sizer; |
962 | } else { | 958 | } else { |
963 | minB += pick( minSize(s->wid) ); | 959 | minB += pick( minSize(s->wid) ); |
964 | maxB += pick( s->wid->maximumSize() ); | 960 | maxB += pick( s->wid->maximumSize() ); |
965 | } | 961 | } |
966 | } | 962 | } |
967 | for ( i = id; i < n; i++ ) { | 963 | for ( i = id; i < n; i++ ) { |
968 | QSplitterLayoutStruct *s = data->list.at(i); | 964 | QSplitterLayoutStruct *s = data->list.at(i); |
969 | if ( s->wid->isHidden() ) { | 965 | if ( s->wid->isHidden() ) { |
970 | //ignore | 966 | //ignore |
971 | } else if ( s->isSplitter ) { | 967 | } else if ( s->isSplitter ) { |
972 | minA += s->sizer; | 968 | minA += s->sizer; |
973 | maxA += s->sizer; | 969 | maxA += s->sizer; |
974 | } else { | 970 | } else { |
975 | minA += pick( minSize(s->wid) ); | 971 | minA += pick( minSize(s->wid) ); |
976 | maxA += pick( s->wid->maximumSize() ); | 972 | maxA += pick( s->wid->maximumSize() ); |
977 | } | 973 | } |
978 | } | 974 | } |
979 | QRect r = contentsRect(); | 975 | QRect r = contentsRect(); |
980 | if ( orient == Horizontal && false ) { | 976 | if ( orient == Horizontal && false ) { |
981 | #if QT_VERSION >= 0x030000 | 977 | #if QT_VERSION >= 0x030000 |
982 | int splitterWidth = style().pixelMetric(QStyle::PM_SplitterWidth, this); | 978 | int splitterWidth = style().pixelMetric(QStyle::PM_SplitterWidth, this); |
983 | #else | 979 | #else |
984 | int splitterWidth = style().splitterWidth(); | 980 | int splitterWidth = style().splitterWidth(); |
985 | #endif | 981 | #endif |
986 | 982 | ||
987 | if ( min ) | 983 | if ( min ) |
988 | *min = pick(r.topRight()) - QMIN( maxB, pick(r.size())-minA ) - splitterWidth; | 984 | *min = pick(r.topRight()) - QMIN( maxB, pick(r.size())-minA ) - splitterWidth; |
989 | if ( max ) | 985 | if ( max ) |
990 | *max = pick(r.topRight()) - QMAX( minB, pick(r.size())-maxA ) - splitterWidth; | 986 | *max = pick(r.topRight()) - QMAX( minB, pick(r.size())-maxA ) - splitterWidth; |
991 | } else { | 987 | } else { |
992 | if ( min ) | 988 | if ( min ) |
993 | *min = pick(r.topLeft()) + QMAX( minB, pick(r.size())-maxA ); | 989 | *min = pick(r.topLeft()) + QMAX( minB, pick(r.size())-maxA ); |
994 | if ( max ) | 990 | if ( max ) |
995 | *max = pick(r.topLeft()) + QMIN( maxB, pick(r.size())-minA ); | 991 | *max = pick(r.topLeft()) + QMIN( maxB, pick(r.size())-minA ); |
996 | } | 992 | } |
997 | } | 993 | } |
998 | 994 | ||
999 | 995 | ||
1000 | /*! | 996 | /*! |
1001 | Returns the closest legal position to \a p of the splitter with id \a id. | 997 | Returns the closest legal position to \a p of the splitter with id \a id. |
1002 | 998 | ||
1003 | \sa idAfter() | 999 | \sa idAfter() |
1004 | */ | 1000 | */ |
1005 | 1001 | ||
1006 | int KDGanttMinimizeSplitter::adjustPos( int p, int id ) | 1002 | int KDGanttMinimizeSplitter::adjustPos( int p, int id ) |
1007 | { | 1003 | { |
1008 | int min = 0; | 1004 | int min = 0; |
1009 | int max = 0; | 1005 | int max = 0; |
1010 | getRange( id, &min, &max ); | 1006 | getRange( id, &min, &max ); |
1011 | p = QMAX( min, QMIN( p, max ) ); | 1007 | p = QMAX( min, QMIN( p, max ) ); |
1012 | 1008 | ||
1013 | return p; | 1009 | return p; |
1014 | } | 1010 | } |
1015 | 1011 | ||
1016 | 1012 | ||
1017 | void KDGanttMinimizeSplitter::doResize() | 1013 | void KDGanttMinimizeSplitter::doResize() |
1018 | { | 1014 | { |
1019 | QRect r = contentsRect(); | 1015 | QRect r = contentsRect(); |
1020 | int i; | 1016 | int i; |
1021 | int n = data->list.count(); | 1017 | int n = data->list.count(); |
1022 | QMemArray<QLayoutStruct> a( n ); | 1018 | QMemArray<QLayoutStruct> a( n ); |
1023 | for ( i = 0; i< n; i++ ) { | 1019 | for ( i = 0; i< n; i++ ) { |
1024 | a[i].init(); | 1020 | a[i].init(); |
1025 | QSplitterLayoutStruct *s = data->list.at(i); | 1021 | QSplitterLayoutStruct *s = data->list.at(i); |
1026 | if ( s->wid->isHidden() ) { | 1022 | if ( s->wid->isHidden() ) { |
1027 | a[i].stretch = 0; | 1023 | a[i].stretch = 0; |
1028 | a[i].sizeHint = a[i].minimumSize = 0; | 1024 | a[i].sizeHint = a[i].minimumSize = 0; |
1029 | a[i].maximumSize = 0; | 1025 | a[i].maximumSize = 0; |
1030 | } else if ( s->isSplitter ) { | 1026 | } else if ( s->isSplitter ) { |
1031 | a[i].stretch = 0; | 1027 | a[i].stretch = 0; |
1032 | a[i].sizeHint = a[i].minimumSize = a[i].maximumSize = s->sizer; | 1028 | a[i].sizeHint = a[i].minimumSize = a[i].maximumSize = s->sizer; |
1033 | a[i].empty = FALSE; | 1029 | a[i].empty = FALSE; |
1034 | } else if ( s->mode == KeepSize ) { | 1030 | } else if ( s->mode == KeepSize ) { |
1035 | a[i].stretch = 0; | 1031 | a[i].stretch = 0; |
1036 | a[i].minimumSize = pick( minSize(s->wid) ); | 1032 | a[i].minimumSize = pick( minSize(s->wid) ); |
1037 | a[i].sizeHint = s->sizer; | 1033 | a[i].sizeHint = s->sizer; |
1038 | a[i].maximumSize = pick( s->wid->maximumSize() ); | 1034 | a[i].maximumSize = pick( s->wid->maximumSize() ); |
1039 | a[i].empty = FALSE; | 1035 | a[i].empty = FALSE; |
1040 | } else if ( s->mode == FollowSizeHint ) { | 1036 | } else if ( s->mode == FollowSizeHint ) { |
1041 | a[i].stretch = 0; | 1037 | a[i].stretch = 0; |
1042 | a[i].minimumSize = a[i].sizeHint = pick( s->wid->sizeHint() ); | 1038 | a[i].minimumSize = a[i].sizeHint = pick( s->wid->sizeHint() ); |
1043 | a[i].maximumSize = pick( s->wid->maximumSize() ); | 1039 | a[i].maximumSize = pick( s->wid->maximumSize() ); |
1044 | a[i].empty = FALSE; | 1040 | a[i].empty = FALSE; |
1045 | } else { //proportional | 1041 | } else { //proportional |
1046 | a[i].stretch = s->sizer; | 1042 | a[i].stretch = s->sizer; |
1047 | a[i].maximumSize = pick( s->wid->maximumSize() ); | 1043 | a[i].maximumSize = pick( s->wid->maximumSize() ); |
1048 | a[i].sizeHint = a[i].minimumSize = pick( minSize(s->wid) ); | 1044 | a[i].sizeHint = a[i].minimumSize = pick( minSize(s->wid) ); |
1049 | a[i].empty = FALSE; | 1045 | a[i].empty = FALSE; |
1050 | } | 1046 | } |
1051 | } | 1047 | } |
1052 | 1048 | ||
1053 | kdganttGeomCalc( a, 0, n, pick( r.topLeft() ), pick( r.size() ), 0 ); | 1049 | kdganttGeomCalc( a, 0, n, pick( r.topLeft() ), pick( r.size() ), 0 ); |
1054 | 1050 | ||
1055 | for ( i = 0; i< n; i++ ) { | 1051 | for ( i = 0; i< n; i++ ) { |
1056 | QSplitterLayoutStruct *s = data->list.at(i); | 1052 | QSplitterLayoutStruct *s = data->list.at(i); |
1057 | setG( s->wid, a[i].pos, a[i].size ); | 1053 | setG( s->wid, a[i].pos, a[i].size ); |
1058 | } | 1054 | } |
1059 | 1055 | ||
1060 | } | 1056 | } |
1061 | 1057 | ||
1062 | 1058 | ||
1063 | void KDGanttMinimizeSplitter::recalc( bool update ) | 1059 | void KDGanttMinimizeSplitter::recalc( bool update ) |
1064 | { | 1060 | { |
1065 | int fi = 2*frameWidth(); | 1061 | int fi = 2*frameWidth(); |
1066 | int maxl = fi; | 1062 | int maxl = fi; |
1067 | int minl = fi; | 1063 | int minl = fi; |
1068 | int maxt = QWIDGETSIZE_MAX; | 1064 | int maxt = QWIDGETSIZE_MAX; |
1069 | int mint = fi; | 1065 | int mint = fi; |
1070 | int n = data->list.count(); | 1066 | int n = data->list.count(); |
1071 | bool first = TRUE; | 1067 | bool first = TRUE; |
1072 | /* | 1068 | /* |
1073 | The splitter before a hidden widget is always hidden. | 1069 | The splitter before a hidden widget is always hidden. |
1074 | The splitter before the first visible widget is hidden. | 1070 | The splitter before the first visible widget is hidden. |
1075 | The splitter before any other visible widget is visible. | 1071 | The splitter before any other visible widget is visible. |
1076 | */ | 1072 | */ |
1077 | for ( int i = 0; i< n; i++ ) { | 1073 | for ( int i = 0; i< n; i++ ) { |
1078 | QSplitterLayoutStruct *s = data->list.at(i); | 1074 | QSplitterLayoutStruct *s = data->list.at(i); |
1079 | if ( !s->isSplitter ) { | 1075 | if ( !s->isSplitter ) { |
1080 | QSplitterLayoutStruct *p = (i > 0) ? p = data->list.at( i-1 ) : 0; | 1076 | QSplitterLayoutStruct *p = (i > 0) ? p = data->list.at( i-1 ) : 0; |
1081 | if ( p && p->isSplitter ) | 1077 | if ( p && p->isSplitter ) |
1082 | if ( first || s->wid->isHidden() ) | 1078 | if ( first || s->wid->isHidden() ) |
1083 | p->wid->hide(); //may trigger new recalc | 1079 | p->wid->hide(); //may trigger new recalc |
1084 | else | 1080 | else |
1085 | p->wid->show(); //may trigger new recalc | 1081 | p->wid->show(); //may trigger new recalc |
1086 | if ( !s->wid->isHidden() ) | 1082 | if ( !s->wid->isHidden() ) |
1087 | first = FALSE; | 1083 | first = FALSE; |
1088 | } | 1084 | } |
1089 | } | 1085 | } |
1090 | 1086 | ||
1091 | bool empty=TRUE; | 1087 | bool empty=TRUE; |
1092 | for ( int j = 0; j< n; j++ ) { | 1088 | for ( int j = 0; j< n; j++ ) { |
1093 | QSplitterLayoutStruct *s = data->list.at(j); | 1089 | QSplitterLayoutStruct *s = data->list.at(j); |
1094 | if ( !s->wid->isHidden() ) { | 1090 | if ( !s->wid->isHidden() ) { |
1095 | empty = FALSE; | 1091 | empty = FALSE; |
1096 | if ( s->isSplitter ) { | 1092 | if ( s->isSplitter ) { |
1097 | minl += s->sizer; | 1093 | minl += s->sizer; |
1098 | maxl += s->sizer; | 1094 | maxl += s->sizer; |
1099 | } else { | 1095 | } else { |
1100 | QSize minS = minSize(s->wid); | 1096 | QSize minS = minSize(s->wid); |
1101 | minl += pick( minS ); | 1097 | minl += pick( minS ); |
1102 | maxl += pick( s->wid->maximumSize() ); | 1098 | maxl += pick( s->wid->maximumSize() ); |
1103 | mint = QMAX( mint, trans( minS )); | 1099 | mint = QMAX( mint, trans( minS )); |
1104 | int tm = trans( s->wid->maximumSize() ); | 1100 | int tm = trans( s->wid->maximumSize() ); |
1105 | if ( tm > 0 ) | 1101 | if ( tm > 0 ) |
1106 | maxt = QMIN( maxt, tm ); | 1102 | maxt = QMIN( maxt, tm ); |
1107 | } | 1103 | } |
1108 | } | 1104 | } |
1109 | } | 1105 | } |
1110 | if ( empty ) { | 1106 | if ( empty ) { |
1111 | if ( parentWidget() != 0 && parentWidget()->inherits("KDGanttMinimizeSplitter") ) { | 1107 | if ( parentWidget() != 0 && parentWidget()->inherits("KDGanttMinimizeSplitter") ) { |
1112 | // nested splitters; be nice | 1108 | // nested splitters; be nice |
1113 | maxl = maxt = 0; | 1109 | maxl = maxt = 0; |
1114 | } else { | 1110 | } else { |
1115 | // KDGanttMinimizeSplitter with no children yet | 1111 | // KDGanttMinimizeSplitter with no children yet |
1116 | maxl = QWIDGETSIZE_MAX; | 1112 | maxl = QWIDGETSIZE_MAX; |
1117 | } | 1113 | } |
1118 | } else { | 1114 | } else { |
1119 | maxl = QMIN( maxl, QWIDGETSIZE_MAX ); | 1115 | maxl = QMIN( maxl, QWIDGETSIZE_MAX ); |
1120 | } | 1116 | } |
1121 | if ( maxt < mint ) | 1117 | if ( maxt < mint ) |
1122 | maxt = mint; | 1118 | maxt = mint; |
1123 | 1119 | ||
1124 | if ( orient == Horizontal ) { | 1120 | if ( orient == Horizontal ) { |
1125 | setMaximumSize( maxl, maxt ); | 1121 | setMaximumSize( maxl, maxt ); |
1126 | setMinimumSize( minl, mint ); | 1122 | setMinimumSize( minl, mint ); |
1127 | } else { | 1123 | } else { |
1128 | setMaximumSize( maxt, maxl ); | 1124 | setMaximumSize( maxt, maxl ); |
1129 | setMinimumSize( mint, minl ); | 1125 | setMinimumSize( mint, minl ); |
1130 | } | 1126 | } |
1131 | if ( update ) | 1127 | if ( update ) |
1132 | doResize(); | 1128 | doResize(); |
1133 | } | 1129 | } |
1134 | 1130 | ||
1135 | /*! | 1131 | /*! |
1136 | Sets resize mode of \a w to \a mode. | 1132 | Sets resize mode of \a w to \a mode. |
1137 | 1133 | ||
1138 | \sa ResizeMode | 1134 | \sa ResizeMode |
1139 | */ | 1135 | */ |
1140 | 1136 | ||
1141 | void KDGanttMinimizeSplitter::setResizeMode( QWidget *w, ResizeMode mode ) | 1137 | void KDGanttMinimizeSplitter::setResizeMode( QWidget *w, ResizeMode mode ) |
1142 | { | 1138 | { |
1143 | processChildEvents(); | 1139 | processChildEvents(); |
1144 | QSplitterLayoutStruct *s = data->list.first(); | 1140 | QSplitterLayoutStruct *s = data->list.first(); |
1145 | while ( s ) { | 1141 | while ( s ) { |
1146 | if ( s->wid == w ) { | 1142 | if ( s->wid == w ) { |
1147 | s->mode = mode; | 1143 | s->mode = mode; |
1148 | return; | 1144 | return; |
1149 | } | 1145 | } |
1150 | s = data->list.next(); | 1146 | s = data->list.next(); |
1151 | } | 1147 | } |
1152 | s = addWidget( w, TRUE ); | 1148 | s = addWidget( w, TRUE ); |
1153 | s->mode = mode; | 1149 | s->mode = mode; |
1154 | } | 1150 | } |
1155 | 1151 | ||
1156 | 1152 | ||
1157 | /*! | 1153 | /*! |
1158 | Returns TRUE if opaque resize is on; otherwise returns FALSE. | 1154 | Returns TRUE if opaque resize is on; otherwise returns FALSE. |
1159 | 1155 | ||
1160 | \sa setOpaqueResize() | 1156 | \sa setOpaqueResize() |
1161 | */ | 1157 | */ |
1162 | 1158 | ||
1163 | bool KDGanttMinimizeSplitter::opaqueResize() const | 1159 | bool KDGanttMinimizeSplitter::opaqueResize() const |
1164 | { | 1160 | { |
1165 | return data->opaque; | 1161 | return data->opaque; |
1166 | } | 1162 | } |
1167 | 1163 | ||
1168 | 1164 | ||
1169 | /*! | 1165 | /*! |
1170 | If \a on is TRUE then opaque resizing is turned on; otherwise | 1166 | If \a on is TRUE then opaque resizing is turned on; otherwise |
1171 | opaque resizing is turned off. | 1167 | opaque resizing is turned off. |
1172 | Opaque resizing is initially turned off. | 1168 | Opaque resizing is initially turned off. |
1173 | 1169 | ||
1174 | \sa opaqueResize() | 1170 | \sa opaqueResize() |
1175 | */ | 1171 | */ |
1176 | 1172 | ||
1177 | void KDGanttMinimizeSplitter::setOpaqueResize( bool on ) | 1173 | void KDGanttMinimizeSplitter::setOpaqueResize( bool on ) |
1178 | { | 1174 | { |
1179 | data->opaque = on; | 1175 | data->opaque = on; |
1180 | } | 1176 | } |
1181 | 1177 | ||
1182 | 1178 | ||
1183 | /*! | 1179 | /*! |
1184 | Moves widget \a w to the leftmost/top position. | 1180 | Moves widget \a w to the leftmost/top position. |
1185 | */ | 1181 | */ |
1186 | 1182 | ||
1187 | void KDGanttMinimizeSplitter::moveToFirst( QWidget *w ) | 1183 | void KDGanttMinimizeSplitter::moveToFirst( QWidget *w ) |
1188 | { | 1184 | { |
1189 | processChildEvents(); | 1185 | processChildEvents(); |
1190 | bool found = FALSE; | 1186 | bool found = FALSE; |
1191 | QSplitterLayoutStruct *s = data->list.first(); | 1187 | QSplitterLayoutStruct *s = data->list.first(); |
1192 | while ( s ) { | 1188 | while ( s ) { |
1193 | if ( s->wid == w ) { | 1189 | if ( s->wid == w ) { |
1194 | found = TRUE; | 1190 | found = TRUE; |
1195 | QSplitterLayoutStruct *p = data->list.prev(); | 1191 | QSplitterLayoutStruct *p = data->list.prev(); |
1196 | if ( p ) { // not already at first place | 1192 | if ( p ) { // not already at first place |
1197 | data->list.take(); //take p | 1193 | data->list.take(); //take p |
1198 | data->list.take(); // take s | 1194 | data->list.take(); // take s |
1199 | data->list.insert( 0, p ); | 1195 | data->list.insert( 0, p ); |
1200 | data->list.insert( 0, s ); | 1196 | data->list.insert( 0, s ); |
1201 | } | 1197 | } |
1202 | break; | 1198 | break; |
1203 | } | 1199 | } |
1204 | s = data->list.next(); | 1200 | s = data->list.next(); |
1205 | } | 1201 | } |
1206 | if ( !found ) | 1202 | if ( !found ) |
1207 | addWidget( w, TRUE ); | 1203 | addWidget( w, TRUE ); |
1208 | recalcId(); | 1204 | recalcId(); |
1209 | } | 1205 | } |
1210 | 1206 | ||
1211 | 1207 | ||
1212 | /*! | 1208 | /*! |
1213 | Moves widget \a w to the rightmost/bottom position. | 1209 | Moves widget \a w to the rightmost/bottom position. |
1214 | */ | 1210 | */ |
1215 | 1211 | ||
1216 | void KDGanttMinimizeSplitter::moveToLast( QWidget *w ) | 1212 | void KDGanttMinimizeSplitter::moveToLast( QWidget *w ) |
1217 | { | 1213 | { |
1218 | processChildEvents(); | 1214 | processChildEvents(); |
1219 | bool found = FALSE; | 1215 | bool found = FALSE; |
1220 | QSplitterLayoutStruct *s = data->list.first(); | 1216 | QSplitterLayoutStruct *s = data->list.first(); |
1221 | while ( s ) { | 1217 | while ( s ) { |
1222 | if ( s->wid == w ) { | 1218 | if ( s->wid == w ) { |
1223 | found = TRUE; | 1219 | found = TRUE; |
1224 | data->list.take(); // take s | 1220 | data->list.take(); // take s |
1225 | QSplitterLayoutStruct *p = data->list.current(); | 1221 | QSplitterLayoutStruct *p = data->list.current(); |
1226 | if ( p ) { // the splitter handle after s | 1222 | if ( p ) { // the splitter handle after s |
1227 | data->list.take(); //take p | 1223 | data->list.take(); //take p |
1228 | data->list.append( p ); | 1224 | data->list.append( p ); |
1229 | } | 1225 | } |
1230 | data->list.append( s ); | 1226 | data->list.append( s ); |
1231 | break; | 1227 | break; |
1232 | } | 1228 | } |
1233 | s = data->list.next(); | 1229 | s = data->list.next(); |
1234 | } | 1230 | } |
1235 | if ( !found ) | 1231 | if ( !found ) |
1236 | addWidget( w); | 1232 | addWidget( w); |
1237 | recalcId(); | 1233 | recalcId(); |
1238 | } | 1234 | } |
1239 | 1235 | ||
1240 | 1236 | ||
1241 | void KDGanttMinimizeSplitter::recalcId() | 1237 | void KDGanttMinimizeSplitter::recalcId() |
1242 | { | 1238 | { |
1243 | int n = data->list.count(); | 1239 | int n = data->list.count(); |
1244 | for ( int i = 0; i < n; i++ ) { | 1240 | for ( int i = 0; i < n; i++ ) { |
1245 | QSplitterLayoutStruct *s = data->list.at(i); | 1241 | QSplitterLayoutStruct *s = data->list.at(i); |
1246 | if ( s->isSplitter ) | 1242 | if ( s->isSplitter ) |
1247 | ((KDGanttSplitterHandle*)s->wid)->setId(i); | 1243 | ((KDGanttSplitterHandle*)s->wid)->setId(i); |
1248 | } | 1244 | } |
1249 | } | 1245 | } |
1250 | 1246 | ||
1251 | 1247 | ||
1252 | /*!\reimp | 1248 | /*!\reimp |
1253 | */ | 1249 | */ |
1254 | QSize KDGanttMinimizeSplitter::sizeHint() const | 1250 | QSize KDGanttMinimizeSplitter::sizeHint() const |
1255 | { | 1251 | { |
1256 | constPolish(); | 1252 | constPolish(); |
1257 | int l = 0; | 1253 | int l = 0; |
1258 | int t = 0; | 1254 | int t = 0; |
1259 | if ( children() ) { | 1255 | if ( children() ) { |
1260 | const QObjectList * c = children(); | 1256 | const QObjectList * c = children(); |
1261 | QObjectListIt it( *c ); | 1257 | QObjectListIt it( *c ); |
1262 | QObject * o; | 1258 | QObject * o; |
1263 | 1259 | ||
1264 | while( (o=it.current()) != 0 ) { | 1260 | while( (o=it.current()) != 0 ) { |
1265 | ++it; | 1261 | ++it; |
1266 | if ( o->isWidgetType() && | 1262 | if ( o->isWidgetType() && |
1267 | !((QWidget*)o)->isHidden() ) { | 1263 | !((QWidget*)o)->isHidden() ) { |
1268 | QSize s = ((QWidget*)o)->sizeHint(); | 1264 | QSize s = ((QWidget*)o)->sizeHint(); |
1269 | if ( s.isValid() ) { | 1265 | if ( s.isValid() ) { |
1270 | l += pick( s ); | 1266 | l += pick( s ); |
1271 | t = QMAX( t, trans( s ) ); | 1267 | t = QMAX( t, trans( s ) ); |
1272 | } | 1268 | } |
1273 | } | 1269 | } |
1274 | } | 1270 | } |
1275 | } | 1271 | } |
1276 | return orientation() == Horizontal ? QSize( l, t ) : QSize( t, l ); | 1272 | return orientation() == Horizontal ? QSize( l, t ) : QSize( t, l ); |
1277 | } | 1273 | } |
1278 | 1274 | ||
1279 | 1275 | ||
1280 | /*! | 1276 | /*! |
1281 | \reimp | 1277 | \reimp |
1282 | */ | 1278 | */ |
1283 | 1279 | ||
1284 | QSize KDGanttMinimizeSplitter::minimumSizeHint() const | 1280 | QSize KDGanttMinimizeSplitter::minimumSizeHint() const |
1285 | { | 1281 | { |
1286 | constPolish(); | 1282 | constPolish(); |
1287 | int l = 0; | 1283 | int l = 0; |
1288 | int t = 0; | 1284 | int t = 0; |
1289 | if ( children() ) { | 1285 | if ( children() ) { |
1290 | const QObjectList * c = children(); | 1286 | const QObjectList * c = children(); |
1291 | QObjectListIt it( *c ); | 1287 | QObjectListIt it( *c ); |
1292 | QObject * o; | 1288 | QObject * o; |
1293 | 1289 | ||
1294 | while( (o=it.current()) != 0 ) { | 1290 | while( (o=it.current()) != 0 ) { |
1295 | ++it; | 1291 | ++it; |
1296 | if ( o->isWidgetType() && | 1292 | if ( o->isWidgetType() && |
1297 | !((QWidget*)o)->isHidden() ) { | 1293 | !((QWidget*)o)->isHidden() ) { |
1298 | QSize s = minSizeHint((QWidget*)o); | 1294 | QSize s = minSizeHint((QWidget*)o); |
1299 | if ( s.isValid() ) { | 1295 | if ( s.isValid() ) { |
1300 | l += pick( s ); | 1296 | l += pick( s ); |
1301 | t = QMAX( t, trans( s ) ); | 1297 | t = QMAX( t, trans( s ) ); |
1302 | } | 1298 | } |
1303 | } | 1299 | } |
1304 | } | 1300 | } |
1305 | } | 1301 | } |
1306 | return orientation() == Horizontal ? QSize( l, t ) : QSize( t, l ); | 1302 | return orientation() == Horizontal ? QSize( l, t ) : QSize( t, l ); |
1307 | } | 1303 | } |
1308 | 1304 | ||
1309 | 1305 | ||
1310 | /* | 1306 | /* |
1311 | Calculates stretch parameters from current sizes | 1307 | Calculates stretch parameters from current sizes |
1312 | */ | 1308 | */ |
1313 | 1309 | ||
1314 | void KDGanttMinimizeSplitter::storeSizes() | 1310 | void KDGanttMinimizeSplitter::storeSizes() |
1315 | { | 1311 | { |
1316 | QSplitterLayoutStruct *s = data->list.first(); | 1312 | QSplitterLayoutStruct *s = data->list.first(); |
1317 | while ( s ) { | 1313 | while ( s ) { |
1318 | if ( !s->isSplitter ) | 1314 | if ( !s->isSplitter ) |
1319 | s->sizer = pick( s->wid->size() ); | 1315 | s->sizer = pick( s->wid->size() ); |
1320 | s = data->list.next(); | 1316 | s = data->list.next(); |
1321 | } | 1317 | } |
1322 | } | 1318 | } |
1323 | 1319 | ||
1324 | 1320 | ||
1325 | #if 0 // ### remove this code ASAP | 1321 | #if 0 // ### remove this code ASAP |
1326 | 1322 | ||
1327 | /*! | 1323 | /*! |
1328 | Hides \a w if \a hide is TRUE and updates the splitter. | 1324 | Hides \a w if \a hide is TRUE and updates the splitter. |
1329 | 1325 | ||
1330 | \warning Due to a limitation in the current implementation, | 1326 | \warning Due to a limitation in the current implementation, |
1331 | calling QWidget::hide() will not work. | 1327 | calling QWidget::hide() will not work. |
1332 | */ | 1328 | */ |
1333 | 1329 | ||
1334 | void KDGanttMinimizeSplitter::setHidden( QWidget *w, bool hide ) | 1330 | void KDGanttMinimizeSplitter::setHidden( QWidget *w, bool hide ) |
1335 | { | 1331 | { |
1336 | if ( w == w1 ) { | 1332 | if ( w == w1 ) { |
1337 | w1show = !hide; | 1333 | w1show = !hide; |
1338 | } else if ( w == w2 ) { | 1334 | } else if ( w == w2 ) { |
1339 | w2show = !hide; | 1335 | w2show = !hide; |
1340 | } else { | 1336 | } else { |
1341 | #ifdef QT_CHECK_RANGE | 1337 | #ifdef QT_CHECK_RANGE |
1342 | qWarning( "KDGanttMinimizeSplitter::setHidden(), unknown widget" ); | 1338 | qWarning( "KDGanttMinimizeSplitter::setHidden(), unknown widget" ); |
1343 | #endif | 1339 | #endif |
1344 | return; | 1340 | return; |
1345 | } | 1341 | } |
1346 | if ( hide ) | 1342 | if ( hide ) |
1347 | w->hide(); | 1343 | w->hide(); |
1348 | else | 1344 | else |
1349 | w->show(); | 1345 | w->show(); |
1350 | recalc( TRUE ); | 1346 | recalc( TRUE ); |
1351 | } | 1347 | } |
1352 | 1348 | ||
1353 | 1349 | ||
1354 | /*! | 1350 | /*! |
1355 | Returns the hidden status of \a w | 1351 | Returns the hidden status of \a w |
1356 | */ | 1352 | */ |
1357 | 1353 | ||
1358 | bool KDGanttMinimizeSplitter::isHidden( QWidget *w ) const | 1354 | bool KDGanttMinimizeSplitter::isHidden( QWidget *w ) const |
1359 | { | 1355 | { |
1360 | if ( w == w1 ) | 1356 | if ( w == w1 ) |
1361 | return !w1show; | 1357 | return !w1show; |
1362 | else if ( w == w2 ) | 1358 | else if ( w == w2 ) |
1363 | return !w2show; | 1359 | return !w2show; |
1364 | #ifdef QT_CHECK_RANGE | 1360 | #ifdef QT_CHECK_RANGE |
1365 | else | 1361 | else |
1366 | qWarning( "KDGanttMinimizeSplitter::isHidden(), unknown widget" ); | 1362 | qWarning( "KDGanttMinimizeSplitter::isHidden(), unknown widget" ); |
1367 | #endif | 1363 | #endif |
1368 | return FALSE; | 1364 | return FALSE; |
1369 | } | 1365 | } |
1370 | #endif | 1366 | #endif |
1371 | 1367 | ||
1372 | 1368 | ||
1373 | /*! | 1369 | /*! |
1374 | Returns a list of the size parameters of all the widgets in this | 1370 | Returns a list of the size parameters of all the widgets in this |
1375 | splitter. | 1371 | splitter. |
1376 | 1372 | ||
1377 | Giving the values to another splitter's setSizes() function will | 1373 | Giving the values to another splitter's setSizes() function will |
1378 | produce a splitter with the same layout as this one. | 1374 | produce a splitter with the same layout as this one. |
1379 | 1375 | ||
1380 | Note that if you want to iterate over the list, you should | 1376 | Note that if you want to iterate over the list, you should |
1381 | iterate over a copy, e.g. | 1377 | iterate over a copy, e.g. |
1382 | \code | 1378 | \code |
1383 | QValueList<int> list = mySplitter.sizes(); | 1379 | QValueList<int> list = mySplitter.sizes(); |
1384 | QValueList<int>::Iterator it = list.begin(); | 1380 | QValueList<int>::Iterator it = list.begin(); |
1385 | while( it != list.end() ) { | 1381 | while( it != list.end() ) { |
1386 | myProcessing( *it ); | 1382 | myProcessing( *it ); |
1387 | ++it; | 1383 | ++it; |
1388 | } | 1384 | } |
1389 | \endcode | 1385 | \endcode |
1390 | 1386 | ||
1391 | \sa setSizes() | 1387 | \sa setSizes() |
1392 | */ | 1388 | */ |
1393 | 1389 | ||
1394 | QValueList<int> KDGanttMinimizeSplitter::sizes() const | 1390 | QValueList<int> KDGanttMinimizeSplitter::sizes() const |
1395 | { | 1391 | { |
1396 | if ( !testWState(WState_Polished) ) { | 1392 | if ( !testWState(WState_Polished) ) { |
1397 | QWidget* that = (QWidget*) this; | 1393 | QWidget* that = (QWidget*) this; |
1398 | that->polish(); | 1394 | that->polish(); |
1399 | } | 1395 | } |
1400 | QValueList<int> list; | 1396 | QValueList<int> list; |
1401 | QSplitterLayoutStruct *s = data->list.first(); | 1397 | QSplitterLayoutStruct *s = data->list.first(); |
1402 | while ( s ) { | 1398 | while ( s ) { |
1403 | if ( !s->isSplitter ) | 1399 | if ( !s->isSplitter ) |
1404 | list.append( s->sizer ); | 1400 | list.append( s->sizer ); |
1405 | s = data->list.next(); | 1401 | s = data->list.next(); |
1406 | } | 1402 | } |
1407 | return list; | 1403 | return list; |
1408 | } | 1404 | } |
1409 | 1405 | ||
1410 | 1406 | ||
1411 | 1407 | ||
1412 | /*! | 1408 | /*! |
1413 | Sets the size parameters to the values given in \a list. | 1409 | Sets the size parameters to the values given in \a list. |
1414 | If the splitter is horizontal, the values set the sizes from | 1410 | If the splitter is horizontal, the values set the sizes from |
1415 | left to right. If it is vertical, the sizes are applied from | 1411 | left to right. If it is vertical, the sizes are applied from |
1416 | top to bottom. | 1412 | top to bottom. |
1417 | Extra values in \a list are ignored. | 1413 | Extra values in \a list are ignored. |
1418 | 1414 | ||
1419 | If \a list contains too few values, the result is undefined | 1415 | If \a list contains too few values, the result is undefined |
1420 | but the program will still be well-behaved. | 1416 | but the program will still be well-behaved. |
1421 | 1417 | ||
1422 | \sa sizes() | 1418 | \sa sizes() |
1423 | */ | 1419 | */ |
1424 | 1420 | ||
1425 | void KDGanttMinimizeSplitter::setSizes( QValueList<int> list ) | 1421 | void KDGanttMinimizeSplitter::setSizes( QValueList<int> list ) |
1426 | { | 1422 | { |
1427 | processChildEvents(); | 1423 | processChildEvents(); |
1428 | QValueList<int>::Iterator it = list.begin(); | 1424 | QValueList<int>::Iterator it = list.begin(); |
1429 | QSplitterLayoutStruct *s = data->list.first(); | 1425 | QSplitterLayoutStruct *s = data->list.first(); |
1430 | while ( s && it != list.end() ) { | 1426 | while ( s && it != list.end() ) { |
1431 | if ( !s->isSplitter ) { | 1427 | if ( !s->isSplitter ) { |
1432 | s->sizer = *it; | 1428 | s->sizer = *it; |
1433 | ++it; | 1429 | ++it; |
1434 | } | 1430 | } |
1435 | s = data->list.next(); | 1431 | s = data->list.next(); |
1436 | } | 1432 | } |
1437 | doResize(); | 1433 | doResize(); |
1438 | } | 1434 | } |
1439 | 1435 | ||
1440 | 1436 | ||
1441 | /*! | 1437 | /*! |
1442 | Gets all posted child events, ensuring that the internal state of | 1438 | Gets all posted child events, ensuring that the internal state of |
1443 | the splitter is consistent. | 1439 | the splitter is consistent. |
1444 | */ | 1440 | */ |
1445 | 1441 | ||
1446 | void KDGanttMinimizeSplitter::processChildEvents() | 1442 | void KDGanttMinimizeSplitter::processChildEvents() |
1447 | { | 1443 | { |
1448 | QApplication::sendPostedEvents( this, QEvent::ChildInserted ); | 1444 | QApplication::sendPostedEvents( this, QEvent::ChildInserted ); |
1449 | } | 1445 | } |
1450 | 1446 | ||
1451 | 1447 | ||
1452 | /*! | 1448 | /*! |
1453 | \reimp | 1449 | \reimp |
1454 | */ | 1450 | */ |
1455 | 1451 | ||
1456 | void KDGanttMinimizeSplitter::styleChange( QStyle& old ) | 1452 | void KDGanttMinimizeSplitter::styleChange( QStyle& old ) |
1457 | { | 1453 | { |
1458 | 1454 | ||
1459 | #if QT_VERSION >= 0x030000 | 1455 | #if QT_VERSION >= 0x030000 |