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