summaryrefslogtreecommitdiffabout
path: root/microkde/KDGanttMinimizeSplitter.cpp
Unidiff
Diffstat (limited to 'microkde/KDGanttMinimizeSplitter.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/KDGanttMinimizeSplitter.cpp194
1 files changed, 103 insertions, 91 deletions
diff --git a/microkde/KDGanttMinimizeSplitter.cpp b/microkde/KDGanttMinimizeSplitter.cpp
index 72c4e60..4172cd0 100644
--- a/microkde/KDGanttMinimizeSplitter.cpp
+++ b/microkde/KDGanttMinimizeSplitter.cpp
@@ -1,1716 +1,1728 @@
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 "q3ptrlist.h"
42#include "qmemarray.h" 42#include "q3memarray.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 Q3PtrList QList
47#define QMemArray QArray 47#define Q3MemArray QArray
48#endif 48#endif
49#include "qlayoutengine_p.h" 49#include "qlayoutengine_p.h"
50#include "qobjectlist.h" 50#include "qobject.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 <q3valuelist.h>
54#include <qcursor.h> 54#include <qcursor.h>
55#include <qframe.h> 55#include <q3frame.h>
56#include <QDesktopWidget>
57//Added by qt3to4:
58#include <Q3PointArray>
59#include <QPixmap>
60#include <QResizeEvent>
61#include <QMouseEvent>
62#include <QChildEvent>
63#include <QEvent>
64#include <QPaintEvent>
56#ifndef KDGANTT_MASTER_CVS 65#ifndef KDGANTT_MASTER_CVS
57//#include "KDGanttMinimizeSplitter.moc" 66//#include "KDGanttMinimizeSplitter.moc"
58#endif 67#endif
59 68
60 69
61 70
62#ifndef DOXYGEN_SKIP_INTERNAL 71#ifndef DOXYGEN_SKIP_INTERNAL
63 72
64#if QT_VERSION >= 232 73#if QT_VERSION >= 232
65static int mouseOffset; 74static int mouseOffset;
66static int opaqueOldPos = -1; //### there's only one mouse, but this is a bit risky 75static int opaqueOldPos = -1; //### there's only one mouse, but this is a bit risky
67 76
68class KDRubberBand: public QFrame 77class KDRubberBand: public Q3Frame
69{ 78{
70public: 79public:
71 KDRubberBand( QWidget *parent, const char * name, WFlags f ) :QFrame ( parent, name, f ) {;} 80 KDRubberBand( QWidget *parent, const char * name, Qt::WFlags f ) :Q3Frame ( parent, name, f ) {;}
72 81
73protected: 82protected:
74 virtual void mousePressEvent ( QMouseEvent * ) 83 virtual void mousePressEvent ( QMouseEvent * )
75 { 84 {
76 close(); 85 close();
77 }; 86 };
78 87
79}; 88};
80 89
81KDGanttSplitterHandle::KDGanttSplitterHandle( Qt::Orientation o, 90KDGanttSplitterHandle::KDGanttSplitterHandle( Qt::Orientation o,
82 KDGanttMinimizeSplitter *parent, const char * name ) 91 KDGanttMinimizeSplitter *parent, const char * name )
83 : QWidget( parent, name ), _activeButton( 0 ), _collapsed( false ) 92 : _activeButton( 0 ), _collapsed( false )
84{ 93{
85 94 setObjectName(name);
95 setParent(parent);
86 if ( QApplication::desktop()->width() > 320 && QApplication::desktop()->width() < 650 ) { 96 if ( QApplication::desktop()->width() > 320 && QApplication::desktop()->width() < 650 ) {
87 mSizeHint = QSize(7,7); 97 mSizeHint = QSize(7,7);
88 mUseOffset = true; 98 mUseOffset = true;
89 } else { 99 } else {
90 mSizeHint = QSize(6,6); 100 mSizeHint = QSize(6,6);
91 mUseOffset = false; 101 mUseOffset = false;
92 } 102 }
93 s = parent; 103 s = parent;
94 setOrientation(o); 104 setOrientation(o);
95 setMouseTracking( true ); 105 setMouseTracking( true );
96 mMouseDown = false; 106 mMouseDown = false;
97 //setMaximumHeight( 5 ); // test only 107 //setMaximumHeight( 5 ); // test only
98} 108}
99 109
100QSize KDGanttSplitterHandle::sizeHint() const 110QSize KDGanttSplitterHandle::sizeHint() const
101{ 111{
102 return mSizeHint; 112 return mSizeHint;
103} 113}
104 114
105void KDGanttSplitterHandle::setOrientation( Qt::Orientation o ) 115void KDGanttSplitterHandle::setOrientation( Qt::Orientation o )
106{ 116{
107 orient = o; 117 orient = o;
108#ifndef QT_NO_CURSOR 118#ifndef QT_NO_CURSOR
109 if ( o == KDGanttMinimizeSplitter::Horizontal ) 119 if ( o == Qt::Horizontal )
110 setCursor( splitHCursor ); 120 setCursor( Qt::splitHCursor );
111 else 121 else
112 setCursor( splitVCursor ); 122 setCursor( Qt::splitVCursor );
113#endif 123#endif
114} 124}
115 125
116 126
117void KDGanttSplitterHandle::mouseMoveEvent( QMouseEvent *e ) 127void KDGanttSplitterHandle::mouseMoveEvent( QMouseEvent *e )
118{ 128{
119 updateCursor( e->pos() ); 129 updateCursor( e->pos() );
120 if ( !(e->state()&LeftButton) ) 130 if ( !(e->state()&Qt::LeftButton) )
121 return; 131 return;
122 132
123 if ( _activeButton != 0) 133 if ( _activeButton != 0)
124 return; 134 return;
125 135
126 QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) 136 QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos()))
127 - mouseOffset; 137 - mouseOffset;
128 if ( opaque() ) { 138 if ( opaque() ) {
129 s->moveSplitter( pos, id() ); 139 s->moveSplitter( pos, id() );
130 } else { 140 } else {
131 int min = pos; int max = pos; 141 int min = pos; int max = pos;
132 s->getRange( id(), &min, &max ); 142 s->getRange( id(), &min, &max );
133 s->setRubberband( QMAX( min, QMIN(max, pos ))); 143 s->setRubberband( QMAX( min, QMIN(max, pos )));
134 } 144 }
135 _collapsed = false; 145 _collapsed = false;
136} 146}
137 147
138void KDGanttSplitterHandle::mousePressEvent( QMouseEvent *e ) 148void KDGanttSplitterHandle::mousePressEvent( QMouseEvent *e )
139{ 149{
140 if ( e->button() == LeftButton ) { 150 if ( e->button() == Qt::LeftButton ) {
141 _activeButton = onButton( e->pos() ); 151 _activeButton = onButton( e->pos() );
142 mouseOffset = s->pick(e->pos()); 152 mouseOffset = s->pick(e->pos());
143 mMouseDown = true; 153 mMouseDown = true;
144 repaint(); 154 repaint();
145 updateCursor( e->pos() ); 155 updateCursor( e->pos() );
146 } 156 }
147} 157}
148 158
149void KDGanttSplitterHandle::updateCursor( const QPoint& p) 159void KDGanttSplitterHandle::updateCursor( const QPoint& p)
150{ 160{
151 if ( onButton( p ) != 0 ) { 161 if ( onButton( p ) != 0 ) {
152 setCursor( arrowCursor ); 162 setCursor( Qt::arrowCursor );
153 } 163 }
154 else { 164 else {
155 if ( orient == KDGanttMinimizeSplitter::Horizontal ) 165 if ( orient == Qt::Horizontal )
156 setCursor( splitHCursor ); 166 setCursor( Qt::splitHCursor );
157 else 167 else
158 setCursor( splitVCursor ); 168 setCursor( Qt::splitVCursor );
159 } 169 }
160} 170}
161void KDGanttSplitterHandle::toggle() 171void KDGanttSplitterHandle::toggle()
162{ 172{
163 int pos; 173 int pos;
164 int min, max; 174 int min, max;
165 if ( !_collapsed ) { 175 if ( !_collapsed ) {
166 s->expandPos( id(), &min, &max ); 176 s->expandPos( id(), &min, &max );
167 if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left 177 if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left
168 || s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) { 178 || s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) {
169 pos = min; 179 pos = min;
170 } 180 }
171 else { 181 else {
172 pos = max; 182 pos = max;
173 } 183 }
174 184
175 _origPos = s->pick(mapToParent( QPoint( 0,0 ) )); 185 _origPos = s->pick(mapToParent( QPoint( 0,0 ) ));
176 s->moveSplitter( pos, id() ); 186 s->moveSplitter( pos, id() );
177 _collapsed = true; 187 _collapsed = true;
178 } 188 }
179 else { 189 else {
180 s->moveSplitter( _origPos, id() ); 190 s->moveSplitter( _origPos, id() );
181 _collapsed = false; 191 _collapsed = false;
182 } 192 }
183 repaint(); 193 repaint();
184} 194}
185 195
186void KDGanttSplitterHandle::mouseReleaseEvent( QMouseEvent *e ) 196void KDGanttSplitterHandle::mouseReleaseEvent( QMouseEvent *e )
187{ 197{
188 mMouseDown = false; 198 mMouseDown = false;
189 if ( _activeButton != 0 ) { 199 if ( _activeButton != 0 ) {
190 if ( onButton( e->pos() ) == _activeButton ) 200 if ( onButton( e->pos() ) == _activeButton )
191 { 201 {
192 toggle(); 202 toggle();
193 } 203 }
194 _activeButton = 0; 204 _activeButton = 0;
195 updateCursor( e->pos() ); 205 updateCursor( e->pos() );
196 } 206 }
197 else { 207 else {
198 if ( !opaque() && e->button() == LeftButton ) { 208 if ( !opaque() && e->button() == Qt::LeftButton ) {
199 QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) 209 QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos()))
200 - mouseOffset; 210 - mouseOffset;
201 s->setRubberband( -1 ); 211 s->setRubberband( -1 );
202 s->moveSplitter( pos, id() ); 212 s->moveSplitter( pos, id() );
203 } 213 }
204 } 214 }
205 if ( s->rubberBand() ) { 215 if ( s->rubberBand() ) {
206 //qDebug("hide rubberband "); 216 //qDebug("hide rubberband ");
207 s->rubberBand()->close(); 217 s->rubberBand()->close();
208 } 218 }
209 repaint(); 219 repaint();
210} 220}
211 221
212int KDGanttSplitterHandle::onButton( const QPoint& p ) 222int KDGanttSplitterHandle::onButton( const QPoint& p )
213{ 223{
214 QValueList<QPointArray> list = buttonRegions(); 224 Q3ValueList<Q3PointArray> list = buttonRegions();
215 int index = 1; 225 int index = 1;
216 int add = 12; 226 int add = 12;
217 for( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { 227 for( Q3ValueList<Q3PointArray>::Iterator it = list.begin(); it != list.end(); ++it ) {
218 QRect rect = (*it).boundingRect(); 228 QRect rect = (*it).boundingRect();
219 rect.setLeft( rect.left()- add ); 229 rect.setLeft( rect.left()- add );
220 rect.setRight( rect.right() + add); 230 rect.setRight( rect.right() + add);
221 rect.setTop( rect.top()- add ); 231 rect.setTop( rect.top()- add );
222 rect.setBottom( rect.bottom() + add); 232 rect.setBottom( rect.bottom() + add);
223 if ( rect.contains( p ) ) { 233 if ( rect.contains( p ) ) {
224 return index; 234 return index;
225 } 235 }
226 index++; 236 index++;
227 } 237 }
228 return 0; 238 return 0;
229} 239}
230 240
231 241
232QValueList<QPointArray> KDGanttSplitterHandle::buttonRegions() 242Q3ValueList<Q3PointArray> KDGanttSplitterHandle::buttonRegions()
233{ 243{
234 QValueList<QPointArray> list; 244 Q3ValueList<Q3PointArray> list;
235 245
236 int sw = 8; 246 int sw = 8;
237 int yyy = 1; 247 int yyy = 1;
238 int xxx = 1; 248 int xxx = 1;
239 int voffset[] = { (int) -sw*3, (int) sw*3 }; 249 int voffset[] = { (int) -sw*3, (int) sw*3 };
240 for ( int i = 0; i < 2; i++ ) { 250 for ( int i = 0; i < 2; i++ ) {
241 QPointArray arr; 251 Q3PointArray arr;
242 if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right || 252 if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right ||
243 _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left) { 253 _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left) {
244 int mid = height()/2 + voffset[i]; 254 int mid = height()/2 + voffset[i];
245 arr.setPoints( 3, 255 arr.setPoints( 3,
246 1-xxx, mid - sw + 4, 256 1-xxx, mid - sw + 4,
247 sw-3-xxx, mid, 257 sw-3-xxx, mid,
248 1-xxx, mid + sw -4); 258 1-xxx, mid + sw -4);
249 } 259 }
250 else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left || 260 else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left ||
251 _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) { 261 _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) {
252 int mid = height()/2 + voffset[i]; 262 int mid = height()/2 + voffset[i];
253 arr.setPoints( 3, 263 arr.setPoints( 3,
254 sw-4, mid - sw + 4, 264 sw-4, mid - sw + 4,
255 0, mid, 265 0, mid,
256 sw-4, mid + sw - 4); 266 sw-4, mid + sw - 4);
257 } 267 }
258 else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up || 268 else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up ||
259 _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down) { 269 _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down) {
260 int mid = width()/2 + voffset[i]; 270 int mid = width()/2 + voffset[i];
261 arr.setPoints( 3, 271 arr.setPoints( 3,
262 mid - sw + 4, sw-4, 272 mid - sw + 4, sw-4,
263 mid, 0, 273 mid, 0,
264 mid + sw - 4, sw-4 ); 274 mid + sw - 4, sw-4 );
265 } 275 }
266 else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down || 276 else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down ||
267 _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) { 277 _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) {
268 int mid = width()/2 + voffset[i]; 278 int mid = width()/2 + voffset[i];
269 arr.setPoints( 3, 279 arr.setPoints( 3,
270 mid - sw + 4, 1-yyy, 280 mid - sw + 4, 1-yyy,
271 mid, sw-3-yyy, 281 mid, sw-3-yyy,
272 mid + sw -4, 1-yyy); 282 mid + sw -4, 1-yyy);
273 } 283 }
274 list.append( arr ); 284 list.append( arr );
275 } 285 }
276 return list; 286 return list;
277} 287}
278 288
279void KDGanttSplitterHandle::paintEvent( QPaintEvent * ) 289void KDGanttSplitterHandle::paintEvent( QPaintEvent * )
280{ 290{
281 QPixmap buffer( size() ); 291 QPixmap buffer( size() );
282 QPainter p( &buffer ); 292 QPainter p( &buffer );
283 293
284 //LR 294 //LR
285 // Draw the splitter rectangle 295 // Draw the splitter rectangle
286 p.setBrush( colorGroup().background() ); 296 p.setBrush( colorGroup().background() );
287 p.setPen( colorGroup().foreground() ); 297 p.setPen( colorGroup().foreground() );
288 //p.drawRect( rect() ); 298 //p.drawRect( rect() );
289#ifndef DESKTOP_VERSION 299#ifndef DESKTOP_VERSION
290 if ( mMouseDown && ! _activeButton) 300 if ( mMouseDown && ! _activeButton)
291 buffer.fill( colorGroup().background().dark() ); 301 buffer.fill( colorGroup().background().dark() );
292 else 302 else
293#endif 303#endif
294 buffer.fill( colorGroup().background() ); 304 buffer.fill( colorGroup().background() );
295 //buffer.fill( backgroundColor() ); 305 //buffer.fill( backgroundColor() );
296 // parentWidget()->style().drawPrimitive( QStyle::PE_Panel, &p, rect(), parentWidget()->colorGroup()); 306 // parentWidget()->style().drawPrimitive( QStyle::PE_Panel, &p, rect(), parentWidget()->colorGroup());
297 307
298 int sw = 8; // Hardcoded, given I didn't use styles anymore, I didn't like to use their size 308 int sw = 8; // Hardcoded, given I didn't use styles anymore, I didn't like to use their size
299 309
300 // arrow color 310 // arrow color
301 QColor col; 311 QColor col;
302 if ( _activeButton ) 312 if ( _activeButton )
303 col = colorGroup().background().dark( 250 ); 313 col = colorGroup().background().dark( 250 );
304 else { 314 else {
305 if ( mMouseDown ) 315 if ( mMouseDown )
306 col = Qt::white; 316 col = Qt::white;
307 else 317 else
308 col = colorGroup().background().dark( 150 ); 318 col = colorGroup().background().dark( 150 );
309 } 319 }
310 //QColor col = backgroundColor().dark( 130 ); 320 //QColor col = backgroundColor().dark( 130 );
311 p.setBrush( col ); 321 p.setBrush( col );
312 p.setPen( col ); 322 p.setPen( col );
313 323
314 QValueList<QPointArray> list = buttonRegions(); 324 Q3ValueList<Q3PointArray> list = buttonRegions();
315 int index = 1; 325 int index = 1;
316 if ( mUseOffset ) 326 if ( mUseOffset )
317 p.translate( 0, 1 ); 327 p.translate( 0, 1 );
318 for ( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { 328 for ( Q3ValueList<Q3PointArray>::Iterator it = list.begin(); it != list.end(); ++it ) {
319 if ( index == _activeButton ) { 329 if ( index == _activeButton ) {
320 330
321 /* 331 /*
322 if ( ! _collapsed ) { 332 if ( ! _collapsed ) {
323 p.save(); 333 p.save();
324 // p.translate( parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftHorizontal ), 334 // p.translate( parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftHorizontal ),
325 // parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftVertical ) ); 335 // parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftVertical ) );
326 p.translate( -1, 0 ); 336 p.translate( -1, 0 );
327 p.drawPolygon( *it, true ); 337 p.drawPolygon( *it, true );
328 p.restore(); } else 338 p.restore(); } else
329 */ 339 */
330 p.drawPolygon( *it, true ); 340 p.drawPolygon( *it, true );
331 341
332 } 342 }
333 else { 343 else {
334 /* 344 /*
335 if ( ! _collapsed ) { 345 if ( ! _collapsed ) {
336 p.save(); 346 p.save();
337 p.translate( -1, 0 ); 347 p.translate( -1, 0 );
338 p.drawPolygon( *it, true ); 348 p.drawPolygon( *it, true );
339 p.restore(); 349 p.restore();
340 } else 350 } else
341 */ 351 */
342 p.drawPolygon( *it, true ); 352 p.drawPolygon( *it, true );
343 353
344 } 354 }
345 index++; 355 index++;
346 } 356 }
347 357
348 // Draw the lines between the arrows 358 // Draw the lines between the arrows
349 if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left || 359 if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left ||
350 s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) { 360 s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) {
351 int mid = height()/2; 361 int mid = height()/2;
352 p.drawLine ( 1, mid - sw, 1, mid + sw ); 362 p.drawLine ( 1, mid - sw, 1, mid + sw );
353 p.drawLine ( 3, mid - sw, 3, mid + sw ); 363 p.drawLine ( 3, mid - sw, 3, mid + sw );
354 } 364 }
355 else if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Up || 365 else if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Up ||
356 s->minimizeDirection() == KDGanttMinimizeSplitter::Down ) { 366 s->minimizeDirection() == KDGanttMinimizeSplitter::Down ) {
357 int mid = width()/2; 367 int mid = width()/2;
358 p.drawLine( mid -sw, 1, mid +sw, 1 ); 368 p.drawLine( mid -sw, 1, mid +sw, 1 );
359 p.drawLine( mid -sw, 3, mid +sw, 3 ); 369 p.drawLine( mid -sw, 3, mid +sw, 3 );
360 } 370 }
361 bitBlt( this, 0, 0, &buffer ); 371 bitBlt( this, 0, 0, &buffer );
362 372
363} 373}
364#endif 374#endif
365 375
366class QSplitterLayoutStruct 376class QSplitterLayoutStruct
367{ 377{
368public: 378public:
369 KDGanttMinimizeSplitter::ResizeMode mode; 379 KDGanttMinimizeSplitter::ResizeMode mode;
370 QCOORD sizer; 380 QCOORD sizer;
371 bool isSplitter; 381 bool isSplitter;
372 QWidget *wid; 382 QWidget *wid;
373}; 383};
374 384
375class QSplitterData 385class QSplitterData
376{ 386{
377public: 387public:
378 QSplitterData() : opaque( FALSE ), firstShow( TRUE ) {} 388 QSplitterData() : opaque( FALSE ), firstShow( TRUE ) {}
379 389
380 QPtrList<QSplitterLayoutStruct> list; 390 Q3PtrList<QSplitterLayoutStruct> list;
381 bool opaque; 391 bool opaque;
382 bool firstShow; 392 bool firstShow;
383}; 393};
384 394
385void kdganttGeomCalc( QMemArray<QLayoutStruct> &chain, int start, int count, int pos, 395void kdganttGeomCalc( Q3MemArray<QLayoutStruct> &chain, int start, int count, int pos,
386 int space, int spacer ); 396 int space, int spacer );
387#endif // DOXYGEN_SKIP_INTERNAL 397#endif // DOXYGEN_SKIP_INTERNAL
388 398
389 399
390/*! 400/*!
391 \class KDGanttMinimizeSplitter KDGanttMinimizeSplitter.h 401 \class KDGanttMinimizeSplitter KDGanttMinimizeSplitter.h
392 \brief The KDGanttMinimizeSplitter class implements a splitter 402 \brief The KDGanttMinimizeSplitter class implements a splitter
393 widget with minimize buttons. 403 widget with minimize buttons.
394 404
395 This class (and its documentation) is largely a copy of Qt's 405 This class (and its documentation) is largely a copy of Qt's
396 QSplitter; the copying was necessary because QSplitter is not 406 QSplitter; the copying was necessary because QSplitter is not
397 extensible at all. QSplitter and its documentation are licensed 407 extensible at all. QSplitter and its documentation are licensed
398 according to the GPL and the Qt Professional License (if you hold 408 according to the GPL and the Qt Professional License (if you hold
399 such a license) and are (C) Trolltech AS. 409 such a license) and are (C) Trolltech AS.
400 410
401 A splitter lets the user control the size of child widgets by 411 A splitter lets the user control the size of child widgets by
402 dragging the boundary between the children. Any number of widgets 412 dragging the boundary between the children. Any number of widgets
403 may be controlled. 413 may be controlled.
404 414
405 To show a QListBox, a QListView and a QTextEdit side by side: 415 To show a QListBox, a QListView and a QTextEdit side by side:
406 416
407 \code 417 \code
408 KDGanttMinimizeSplitter *split = new KDGanttMinimizeSplitter( parent ); 418 KDGanttMinimizeSplitter *split = new KDGanttMinimizeSplitter( parent );
409 QListBox *lb = new QListBox( split ); 419 QListBox *lb = new QListBox( split );
410 QListView *lv = new QListView( split ); 420 QListView *lv = new QListView( split );
411 QTextEdit *ed = new QTextEdit( split ); 421 QTextEdit *ed = new QTextEdit( split );
412 \endcode 422 \endcode
413 423
414 In KDGanttMinimizeSplitter, the boundary can be either horizontal or 424 In KDGanttMinimizeSplitter, the boundary can be either horizontal or
415 vertical. The default is horizontal (the children are side by side) 425 vertical. The default is horizontal (the children are side by side)
416 but you can use setOrientation( QSplitter::Vertical ) to set it to 426 but you can use setOrientation( QSplitter::Vertical ) to set it to
417 vertical. 427 vertical.
418 428
419 Use setResizeMode() to specify 429 Use setResizeMode() to specify
420 that a widget should keep its size when the splitter is resized. 430 that a widget should keep its size when the splitter is resized.
421 431
422 Although KDGanttMinimizeSplitter normally resizes the children only 432 Although KDGanttMinimizeSplitter normally resizes the children only
423 at the end of a resize operation, if you call setOpaqueResize( TRUE 433 at the end of a resize operation, if you call setOpaqueResize( TRUE
424 ) the widgets are resized as often as possible. 434 ) the widgets are resized as often as possible.
425 435
426 The initial distribution of size between the widgets is determined 436 The initial distribution of size between the widgets is determined
427 by the initial size of each widget. You can also use setSizes() to 437 by the initial size of each widget. You can also use setSizes() to
428 set the sizes of all the widgets. The function sizes() returns the 438 set the sizes of all the widgets. The function sizes() returns the
429 sizes set by the user. 439 sizes set by the user.
430 440
431 If you hide() a child, its space will be distributed among the other 441 If you hide() a child, its space will be distributed among the other
432 children. It will be reinstated when you show() it again. It is also 442 children. It will be reinstated when you show() it again. It is also
433 possible to reorder the widgets within the splitter using 443 possible to reorder the widgets within the splitter using
434 moveToFirst() and moveToLast(). 444 moveToFirst() and moveToLast().
435*/ 445*/
436 446
437 447
438 448
439static QSize minSize( const QWidget* /*w*/ ) 449static QSize minSize( const QWidget* /*w*/ )
440{ 450{
441 return QSize(0,0); 451 return QSize(0,0);
442} 452}
443 453
444// This is the original version of minSize 454// This is the original version of minSize
445static QSize minSizeHint( const QWidget* w ) 455static QSize minSizeHint( const QWidget* w )
446{ 456{
447 QSize min = w->minimumSize(); 457 QSize min = w->minimumSize();
448 QSize s; 458 QSize s;
449 if ( min.height() <= 0 || min.width() <= 0 ) 459 if ( min.height() <= 0 || min.width() <= 0 )
450 s = w->minimumSizeHint(); 460 s = w->minimumSizeHint();
451 if ( min.height() > 0 ) 461 if ( min.height() > 0 )
452 s.setHeight( min.height() ); 462 s.setHeight( min.height() );
453 if ( min.width() > 0 ) 463 if ( min.width() > 0 )
454 s.setWidth( min.width() ); 464 s.setWidth( min.width() );
455 return s.expandedTo(QSize(0,0)); 465 return s.expandedTo(QSize(0,0));
456} 466}
457 467
458 468
459/*! 469/*!
460 Constructs a horizontal splitter with the \a parent and \a 470 Constructs a horizontal splitter with the \a parent and \a
461 name arguments being passed on to the QFrame constructor. 471 name arguments being passed on to the QFrame constructor.
462*/ 472*/
463KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( QWidget *parent, const char *name ) 473KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( QWidget *parent, const char *name )
464 :QFrame(parent,name,WPaintUnclipped) 474 :Q3Frame(parent,name)
465{ 475{
476 setAttribute(Qt::WA_PaintUnclipped);
466 mRubberBand = 0; 477 mRubberBand = 0;
467 mFirstHandle = 0; 478 mFirstHandle = 0;
468#if QT_VERSION >= 232 479#if QT_VERSION >= 232
469 orient = Horizontal; 480 orient = Qt::Horizontal;
470 init(); 481 init();
471#endif 482#endif
472} 483}
473 484
474/*! 485/*!
475 Constructs a splitter with orientation \a o with the \a parent 486 Constructs a splitter with orientation \a o with the \a parent
476 and \a name arguments being passed on to the QFrame constructor. 487 and \a name arguments being passed on to the QFrame constructor.
477*/ 488*/
478KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( Orientation o, QWidget *parent, const char *name ) 489KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( Qt::Orientation o, QWidget *parent, const char *name )
479 :QFrame(parent,name,WPaintUnclipped) 490 :Q3Frame(parent,name)
480{ 491{
481 492 setAttribute(Qt::WA_PaintUnclipped);
482 mRubberBand = 0; 493 mRubberBand = 0;
483 mFirstHandle = 0; 494 mFirstHandle = 0;
484#if QT_VERSION >= 232 495#if QT_VERSION >= 232
485 orient = o; 496 orient = o;
486 init(); 497 init();
487#endif 498#endif
488} 499}
489 500
490/*! 501/*!
491 Destroys the splitter and any children. 502 Destroys the splitter and any children.
492*/ 503*/
493KDGanttMinimizeSplitter::~KDGanttMinimizeSplitter() 504KDGanttMinimizeSplitter::~KDGanttMinimizeSplitter()
494{ 505{
495#if QT_VERSION >= 232 506#if QT_VERSION >= 232
496 data->list.setAutoDelete( TRUE ); 507 data->list.setAutoDelete( TRUE );
497 delete data; 508 delete data;
498#endif 509#endif
499 if ( mRubberBand ) 510 if ( mRubberBand )
500 delete mRubberBand; 511 delete mRubberBand;
501} 512}
502 513
503 514
504#if QT_VERSION >= 232 515#if QT_VERSION >= 232
505void KDGanttMinimizeSplitter::init() 516void KDGanttMinimizeSplitter::init()
506{ 517{
507 data = new QSplitterData; 518 data = new QSplitterData;
508 if ( orient == Horizontal ) 519 if ( orient == Qt::Horizontal )
509 setSizePolicy( QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum) ); 520 setSizePolicy( QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum) );
510 else 521 else
511 setSizePolicy( QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Expanding) ); 522 setSizePolicy( QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Expanding) );
512#ifndef DESKTOP_VERSION 523#ifndef DESKTOP_VERSION
513 setOpaqueResize( false ); 524 setOpaqueResize( false );
514#else 525#else
515 setOpaqueResize( true ); 526 setOpaqueResize( true );
516#endif 527#endif
517} 528}
518#endif 529#endif
519 530
520 531
521void KDGanttMinimizeSplitter::toggle() 532void KDGanttMinimizeSplitter::toggle()
522{ 533{
523 if ( mFirstHandle ) 534 if ( mFirstHandle )
524 mFirstHandle->toggle(); 535 mFirstHandle->toggle();
525 else 536 else
526 qDebug("KDGanttMinimizeSplitter::toggle::sorry, handle not available "); 537 qDebug("KDGanttMinimizeSplitter::toggle::sorry, handle not available ");
527 538
528} 539}
529 540
530 541
531/*! 542/*!
532 \brief the orientation of the splitter 543 \brief the orientation of the splitter
533 544
534 By default the orientation is horizontal (the widgets are side by side). 545 By default the orientation is horizontal (the widgets are side by side).
535 The possible orientations are Qt:Vertical and Qt::Horizontal (the default). 546 The possible orientations are Qt:Vertical and Qt::Horizontal (the default).
536*/ 547*/
537void KDGanttMinimizeSplitter::setOrientation( Orientation o ) 548void KDGanttMinimizeSplitter::setOrientation( Qt::Orientation o )
538{ 549{
539#if QT_VERSION >= 232 550#if QT_VERSION >= 232
540 if ( orient == o ) 551 if ( orient == o )
541 return; 552 return;
542 orient = o; 553 orient = o;
543 554
544 if ( orient == Horizontal ) 555 if ( orient == Qt::Horizontal )
545 setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); 556 setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) );
546 else 557 else
547 setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); 558 setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) );
548 559
549 QSplitterLayoutStruct *s = data->list.first(); 560 QSplitterLayoutStruct *s = data->list.first();
550 while ( s ) { 561 while ( s ) {
551 if ( s->isSplitter ) 562 if ( s->isSplitter )
552 ((KDGanttSplitterHandle*)s->wid)->setOrientation( o ); 563 ((KDGanttSplitterHandle*)s->wid)->setOrientation( o );
553 s = data->list.next(); // ### next at end of loop, no iterator 564 s = data->list.next(); // ### next at end of loop, no iterator
554 } 565 }
555 recalc( isVisible() ); 566 recalc( isVisible() );
556#endif 567#endif
557} 568}
558 569
559 570
560#if QT_VERSION >= 232 571#if QT_VERSION >= 232
561/*! 572/*!
562 \reimp 573 \reimp
563*/ 574*/
564void KDGanttMinimizeSplitter::resizeEvent( QResizeEvent * ) 575void KDGanttMinimizeSplitter::resizeEvent( QResizeEvent * )
565{ 576{
566 doResize(); 577 doResize();
567} 578}
568 579
569 580
570/* 581/*
571 Inserts the widget \a w at the end (or at the beginning if \a first 582 Inserts the widget \a w at the end (or at the beginning if \a first
572 is TRUE) of the splitter's list of widgets. 583 is TRUE) of the splitter's list of widgets.
573 584
574 It is the responsibility of the caller of this function to make sure 585 It is the responsibility of the caller of this function to make sure
575 that \a w is not already in the splitter and to call recalcId if 586 that \a w is not already in the splitter and to call recalcId if
576 needed. (If \a first is TRUE, then recalcId is very probably 587 needed. (If \a first is TRUE, then recalcId is very probably
577 needed.) 588 needed.)
578*/ 589*/
579QSplitterLayoutStruct *KDGanttMinimizeSplitter::addWidget( QWidget *w, bool first ) 590QSplitterLayoutStruct *KDGanttMinimizeSplitter::addWidget( QWidget *w, bool first )
580{ 591{
581 QSplitterLayoutStruct *s; 592 QSplitterLayoutStruct *s;
582 KDGanttSplitterHandle *newHandle = 0; 593 KDGanttSplitterHandle *newHandle = 0;
583 if ( data->list.count() > 0 ) { 594 if ( data->list.count() > 0 ) {
584 s = new QSplitterLayoutStruct; 595 s = new QSplitterLayoutStruct;
585 s->mode = KeepSize; 596 s->mode = KeepSize;
586 QString tmp = "qt_splithandle_"; 597 QString tmp = "qt_splithandle_";
587 tmp += w->name(); 598 tmp += w->name();
588 newHandle = new KDGanttSplitterHandle( orientation(), this, tmp.latin1() ); 599 newHandle = new KDGanttSplitterHandle( orientation(), this, tmp.latin1() );
589 if ( ! mFirstHandle ) 600 if ( ! mFirstHandle )
590 mFirstHandle = newHandle; 601 mFirstHandle = newHandle;
591 s->wid = newHandle; 602 s->wid = newHandle;
592 newHandle->setId(data->list.count()); 603 newHandle->setId(data->list.count());
593 s->isSplitter = TRUE; 604 s->isSplitter = TRUE;
594 s->sizer = pick( newHandle->sizeHint() ); 605 s->sizer = pick( newHandle->sizeHint() );
595 if ( first ) 606 if ( first )
596 data->list.insert( 0, s ); 607 data->list.insert( 0, s );
597 else 608 else
598 data->list.append( s ); 609 data->list.append( s );
599 } 610 }
600 s = new QSplitterLayoutStruct; 611 s = new QSplitterLayoutStruct;
601 s->mode = Stretch; 612 s->mode = Stretch;
602 s->wid = w; 613 s->wid = w;
603 if ( !testWState( WState_Resized ) && w->sizeHint().isValid() ) 614 if ( !testAttribute( Qt::WA_Resized ) && w->sizeHint().isValid() )
604 s->sizer = pick( w->sizeHint() ); 615 s->sizer = pick( w->sizeHint() );
605 else 616 else
606 s->sizer = pick( w->size() ); 617 s->sizer = pick( w->size() );
607 s->isSplitter = FALSE; 618 s->isSplitter = FALSE;
608 if ( first ) 619 if ( first )
609 data->list.insert( 0, s ); 620 data->list.insert( 0, s );
610 else 621 else
611 data->list.append( s ); 622 data->list.append( s );
612 if ( newHandle && isVisible() ) 623 if ( newHandle && isVisible() )
613 newHandle->show(); //will trigger sending of post events 624 newHandle->show(); //will trigger sending of post events
614 return s; 625 return s;
615} 626}
616 627
617 628
618/*! 629/*!
619 Tells the splitter that a child widget has been inserted or removed. 630 Tells the splitter that a child widget has been inserted or removed.
620 The event is passed in \a c. 631 The event is passed in \a c.
621*/ 632*/
622void KDGanttMinimizeSplitter::childEvent( QChildEvent *c ) 633void KDGanttMinimizeSplitter::childEvent( QChildEvent *c )
623{ 634{
624 if ( c->type() == QEvent::ChildInserted ) { 635 if ( c->type() == QEvent::ChildAdded ) {
625 if ( !c->child()->isWidgetType() ) 636 if ( !c->child()->isWidgetType() )
626 return; 637 return;
627 638
628 if ( ((QWidget*)c->child())->testWFlags( WType_TopLevel ) ) 639 QWidget *cw = (QWidget*)c->child();
640
641 if ( (cw->windowFlags())&Qt::Window )
642 return;
643
644 // avoid infinite recursion
645 if(cw->objectName().startsWith("qt_splithandle_"))
629 return; 646 return;
630 647
631 QSplitterLayoutStruct *s = data->list.first(); 648 QSplitterLayoutStruct *s = data->list.first();
632 while ( s ) { 649 while ( s ) {
633 if ( s->wid == c->child() ) 650 if ( s->wid == cw )
634 return; 651 return;
635 s = data->list.next(); 652 s = data->list.next();
636 } 653 }
637 addWidget( (QWidget*)c->child() ); 654 addWidget( cw );
638 recalc( isVisible() ); 655 recalc( isVisible() );
639 656
640 } else if ( c->type() == QEvent::ChildRemoved ) { 657 } else if ( c->type() == QEvent::ChildRemoved ) {
641 QSplitterLayoutStruct *p = 0; 658 QSplitterLayoutStruct *p = 0;
642 if ( data->list.count() > 1 ) 659 if ( data->list.count() > 1 )
643 p = data->list.at(1); //remove handle _after_ first widget. 660 p = data->list.at(1); //remove handle _after_ first widget.
644 QSplitterLayoutStruct *s = data->list.first(); 661 QSplitterLayoutStruct *s = data->list.first();
645 while ( s ) { 662 while ( s ) {
646 if ( s->wid == c->child() ) { 663 if ( s->wid == c->child() ) {
647 data->list.removeRef( s ); 664 data->list.removeRef( s );
648 delete s; 665 delete s;
649 if ( p && p->isSplitter ) { 666 if ( p && p->isSplitter ) {
650 data->list.removeRef( p ); 667 data->list.removeRef( p );
651 delete p->wid; //will call childEvent 668 delete p->wid; //will call childEvent
652 delete p; 669 delete p;
653 } 670 }
654 recalcId(); 671 recalcId();
655 doResize(); 672 doResize();
656 return; 673 return;
657 } 674 }
658 p = s; 675 p = s;
659 s = data->list.next(); 676 s = data->list.next();
660 } 677 }
661 } 678 }
662} 679}
663 680
664 681
665/*! 682/*!
666 Shows a rubber band at position \a p. If \a p is negative, the 683 Shows a rubber band at position \a p. If \a p is negative, the
667 rubber band is removed. 684 rubber band is removed.
668*/ 685*/
669void KDGanttMinimizeSplitter::setRubberband( int p ) 686void KDGanttMinimizeSplitter::setRubberband( int p )
670{ 687{
671#ifdef DESKTOP_VERSION 688#ifdef DESKTOP_VERSION
672 QPainter paint( this ); 689 QPainter paint( this );
673 paint.setPen( gray ); 690 paint.setPen( Qt::gray );
674 paint.setBrush( gray ); 691 paint.setBrush( Qt::gray );
675 paint.setRasterOp( XorROP ); 692 paint.setCompositionMode( QPainter::CompositionMode_Xor );
676 QRect r = contentsRect(); 693 QRect r = contentsRect();
677 const int rBord = 3; //Themable???? 694 const int rBord = 3; //Themable????
678#if QT_VERSION >= 0x030000 695#if QT_VERSION >= 0x030000
679 int sw = style().pixelMetric(QStyle::PM_SplitterWidth, this); 696 int sw = style()->pixelMetric(QStyle::PM_SplitterWidth, 0, this);
680#else 697#else
681 int sw = style().splitterWidth(); 698 int sw = style().splitterWidth();
682#endif 699#endif
683 if ( orient == Horizontal ) { 700 if ( orient == Qt::Horizontal ) {
684 if ( opaqueOldPos >= 0 ) 701 if ( opaqueOldPos >= 0 )
685 paint.drawRect( opaqueOldPos + sw/2 - rBord , r.y(), 702 paint.drawRect( opaqueOldPos + sw/2 - rBord , r.y(),
686 2*rBord, r.height() ); 703 2*rBord, r.height() );
687 if ( p >= 0 ) 704 if ( p >= 0 )
688 paint.drawRect( p + sw/2 - rBord, r.y(), 2*rBord, r.height() ); 705 paint.drawRect( p + sw/2 - rBord, r.y(), 2*rBord, r.height() );
689 } else { 706 } else {
690 if ( opaqueOldPos >= 0 ) 707 if ( opaqueOldPos >= 0 )
691 paint.drawRect( r.x(), opaqueOldPos + sw/2 - rBord, 708 paint.drawRect( r.x(), opaqueOldPos + sw/2 - rBord,
692 r.width(), 2*rBord ); 709 r.width(), 2*rBord );
693 if ( p >= 0 ) 710 if ( p >= 0 )
694 paint.drawRect( r.x(), p + sw/2 - rBord, r.width(), 2*rBord ); 711 paint.drawRect( r.x(), p + sw/2 - rBord, r.width(), 2*rBord );
695 } 712 }
696 opaqueOldPos = p; 713 opaqueOldPos = p;
697#else 714#else
698 if ( !mRubberBand ) { 715 if ( !mRubberBand ) {
699 mRubberBand = new KDRubberBand( 0, "rubber", WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop); 716 mRubberBand = new KDRubberBand( 0, "rubber", Qt::WStyle_NoBorder | Qt::WStyle_Customize | Qt::WStyle_StaysOnTop);
700 mRubberBand->setFrameStyle( Box | Raised ); 717 mRubberBand->setFrameStyle( Box | Raised );
701 //mRubberBand->setPalette( QPalette ( Qt::red.light(),Qt::red.dark() ) ); 718 //mRubberBand->setPalette( QPalette ( Qt::red.light(),Qt::red.dark() ) );
702 mRubberBand->setPalette( QPalette ( colorGroup().background().light(), colorGroup().background().dark() )); 719 mRubberBand->setPalette( QPalette ( colorGroup().background().light(), colorGroup().background().dark() ));
703 } 720 }
704 QRect r = contentsRect(); 721 QRect r = contentsRect();
705 static int rBord = 0; //Themable???? 722 static int rBord = 0; //Themable????
706 if ( !rBord ) { 723 if ( !rBord ) {
707 if (QApplication::desktop()->width() <= 320 ) 724 if (QApplication::desktop()->width() <= 320 )
708 rBord = 3; 725 rBord = 3;
709 else 726 else
710 rBord = 4; 727 rBord = 4;
711 } 728 }
712 int sw = style().splitterWidth(); 729 int sw = style().splitterWidth();
713 if ( orient == Horizontal ) { 730 if ( orient == Qt::Horizontal ) {
714 if ( p >= 0 ) { 731 if ( p >= 0 ) {
715 QPoint geo = mapToGlobal (QPoint ( p + sw/2 - rBord, r.y())); 732 QPoint geo = mapToGlobal (QPoint ( p + sw/2 - rBord, r.y()));
716 mRubberBand->setGeometry( geo.x(), geo.y(), 2*rBord, r.height() ); 733 mRubberBand->setGeometry( geo.x(), geo.y(), 2*rBord, r.height() );
717 } 734 }
718 } else { 735 } else {
719 if ( p >= 0 ) { 736 if ( p >= 0 ) {
720 QPoint geo = mapToGlobal (QPoint ( r.x(), p + sw/2 - rBord)); 737 QPoint geo = mapToGlobal (QPoint ( r.x(), p + sw/2 - rBord));
721 mRubberBand->setGeometry( geo.x(), geo.y(), r.width(), 2*rBord); 738 mRubberBand->setGeometry( geo.x(), geo.y(), r.width(), 2*rBord);
722 } 739 }
723 } 740 }
724 opaqueOldPos = p; 741 opaqueOldPos = p;
725 if ( ! mRubberBand->isVisible() ) { 742 if ( ! mRubberBand->isVisible() ) {
726 mRubberBand->show(); 743 mRubberBand->show();
727 } 744 }
728#endif 745#endif
729} 746}
730 747
731 748
732/*! \reimp */ 749/*! \reimp */
733bool KDGanttMinimizeSplitter::event( QEvent *e ) 750bool KDGanttMinimizeSplitter::event( QEvent *e )
734{ 751{
735 if ( e->type() == QEvent::LayoutHint || ( e->type() == QEvent::Show && data->firstShow ) ) { 752 if ( e->type() == QEvent::LayoutRequest || ( e->type() == QEvent::Show && data->firstShow ) ) {
736 recalc( isVisible() ); 753 recalc( isVisible() );
737 if ( e->type() == QEvent::Show ) 754 if ( e->type() == QEvent::Show )
738 data->firstShow = FALSE; 755 data->firstShow = FALSE;
739 } 756 }
740 return QWidget::event( e ); 757 return QWidget::event( e );
741} 758}
742 759
743 760
744/*! 761/*!
745 \obsolete 762 \obsolete
746 763
747 Draws the splitter handle in the rectangle described by \a x, \a y, 764 Draws the splitter handle in the rectangle described by \a x, \a y,
748 \a w, \a h using painter \a p. 765 \a w, \a h using painter \a p.
749 \sa QStyle::drawPrimitive() 766 \sa QStyle::drawPrimitive()
750*/ 767*/
751void KDGanttMinimizeSplitter::drawSplitter( QPainter *p, 768void KDGanttMinimizeSplitter::drawSplitter( QPainter *p,
752 QCOORD x, QCOORD y, QCOORD w, QCOORD h ) 769 QCOORD x, QCOORD y, QCOORD w, QCOORD h )
753{ 770{
754#if 0 771#if 0
755 // LR 772 // LR
756 style().drawPrimitive(QStyle::PE_Splitter, p, QRect(x, y, w, h), colorGroup(), 773 style().drawPrimitive(QStyle::PE_Splitter, p, QRect(x, y, w, h), colorGroup(),
757 (orientation() == Qt::Horizontal ? 774 (orientation() == Qt::Horizontal ?
758 QStyle::Style_Horizontal : 0)); 775 QStyle::State_Horizontal : 0));
759#endif 776#endif
760} 777}
761 778
762 779
763/*! 780/*!
764 Returns the id of the splitter to the right of or below the widget \a w, 781 Returns the id of the splitter to the right of or below the widget \a w,
765 or 0 if there is no such splitter 782 or 0 if there is no such splitter
766 (i.e. it is either not in this KDGanttMinimizeSplitter or it is at the end). 783 (i.e. it is either not in this KDGanttMinimizeSplitter or it is at the end).
767*/ 784*/
768int KDGanttMinimizeSplitter::idAfter( QWidget* w ) const 785int KDGanttMinimizeSplitter::idAfter( QWidget* w ) const
769{ 786{
770 QSplitterLayoutStruct *s = data->list.first(); 787 QSplitterLayoutStruct *s = data->list.first();
771 bool seen_w = FALSE; 788 bool seen_w = FALSE;
772 while ( s ) { 789 while ( s ) {
773 if ( s->isSplitter && seen_w ) 790 if ( s->isSplitter && seen_w )
774 return data->list.at(); 791 return data->list.at();
775 if ( !s->isSplitter && s->wid == w ) 792 if ( !s->isSplitter && s->wid == w )
776 seen_w = TRUE; 793 seen_w = TRUE;
777 s = data->list.next(); 794 s = data->list.next();
778 } 795 }
779 return 0; 796 return 0;
780} 797}
781 798
782 799
783/*! 800/*!
784 Moves the left/top edge of the splitter handle with id \a id as 801 Moves the left/top edge of the splitter handle with id \a id as
785 close as possible to position \a p, which is the distance from the 802 close as possible to position \a p, which is the distance from the
786 left (or top) edge of the widget. 803 left (or top) edge of the widget.
787 804
788 For Arabic and Hebrew the layout is reversed, and using this 805 For Arabic and Hebrew the layout is reversed, and using this
789 function to set the position of the splitter might lead to 806 function to set the position of the splitter might lead to
790 unexpected results, since in Arabic and Hebrew the position of 807 unexpected results, since in Arabic and Hebrew the position of
791 splitter one is to the left of the position of splitter zero. 808 splitter one is to the left of the position of splitter zero.
792 809
793 \sa idAfter() 810 \sa idAfter()
794*/ 811*/
795void KDGanttMinimizeSplitter::moveSplitter( QCOORD p, int id ) 812void KDGanttMinimizeSplitter::moveSplitter( QCOORD p, int id )
796{ 813{
797 p = adjustPos( p, id ); 814 p = adjustPos( p, id );
798 QSplitterLayoutStruct *s = data->list.at(id); 815 QSplitterLayoutStruct *s = data->list.at(id);
799 int oldP = orient == Horizontal ? s->wid->x() : s->wid->y(); 816 int oldP = orient == Qt::Horizontal ? s->wid->x() : s->wid->y();
800 bool upLeft; 817 bool upLeft;
801 if ( false && orient == Horizontal ) { 818 if ( false && orient == Qt::Horizontal ) {
802 p += s->wid->width(); 819 p += s->wid->width();
803 upLeft = p > oldP; 820 upLeft = p > oldP;
804 } else 821 } else
805 upLeft = p < oldP; 822 upLeft = p < oldP;
806 823
807 moveAfter( p, id, upLeft ); 824 moveAfter( p, id, upLeft );
808 moveBefore( p-1, id-1, upLeft ); 825 moveBefore( p-1, id-1, upLeft );
809 826
810 storeSizes(); 827 storeSizes();
811} 828}
812 829
813 830
814void KDGanttMinimizeSplitter::setG( QWidget *w, int p, int s, bool isSplitter ) 831void KDGanttMinimizeSplitter::setG( QWidget *w, int p, int s, bool isSplitter )
815{ 832{
816 if ( orient == Horizontal ) { 833 if ( orient == Qt::Horizontal ) {
817 if ( false && orient == Horizontal && !isSplitter ) 834 if ( false && orient == Qt::Horizontal && !isSplitter )
818 p = contentsRect().width() - p - s; 835 p = contentsRect().width() - p - s;
819 w->setGeometry( p, contentsRect().y(), s, contentsRect().height() ); 836 w->setGeometry( p, contentsRect().y(), s, contentsRect().height() );
820 } else 837 } else
821 w->setGeometry( contentsRect().x(), p, contentsRect().width(), s ); 838 w->setGeometry( contentsRect().x(), p, contentsRect().width(), s );
822} 839}
823 840
824 841
825/* 842/*
826 Places the right/bottom edge of the widget at \a id at position \a pos. 843 Places the right/bottom edge of the widget at \a id at position \a pos.
827 844
828 \sa idAfter() 845 \sa idAfter()
829*/ 846*/
830void KDGanttMinimizeSplitter::moveBefore( int pos, int id, bool upLeft ) 847void KDGanttMinimizeSplitter::moveBefore( int pos, int id, bool upLeft )
831{ 848{
832 if( id < 0 ) 849 if( id < 0 )
833 return; 850 return;
834 QSplitterLayoutStruct *s = data->list.at(id); 851 QSplitterLayoutStruct *s = data->list.at(id);
835 if ( !s ) 852 if ( !s )
836 return; 853 return;
837 QWidget *w = s->wid; 854 QWidget *w = s->wid;
838 if ( w->isHidden() ) { 855 if ( w->isHidden() ) {
839 moveBefore( pos, id-1, upLeft ); 856 moveBefore( pos, id-1, upLeft );
840 } else if ( s->isSplitter ) { 857 } else if ( s->isSplitter ) {
841 int pos1, pos2; 858 int pos1, pos2;
842 int dd = s->sizer; 859 int dd = s->sizer;
843 if( false && orient == Horizontal ) { 860 if( false && orient == Qt::Horizontal ) {
844 pos1 = pos; 861 pos1 = pos;
845 pos2 = pos + dd; 862 pos2 = pos + dd;
846 } else { 863 } else {
847 pos2 = pos - dd; 864 pos2 = pos - dd;
848 pos1 = pos2 + 1; 865 pos1 = pos2 + 1;
849 } 866 }
850 if ( upLeft ) { 867 if ( upLeft ) {
851 setG( w, pos1, dd, TRUE ); 868 setG( w, pos1, dd, TRUE );
852 moveBefore( pos2, id-1, upLeft ); 869 moveBefore( pos2, id-1, upLeft );
853 } else { 870 } else {
854 moveBefore( pos2, id-1, upLeft ); 871 moveBefore( pos2, id-1, upLeft );
855 setG( w, pos1, dd, TRUE ); 872 setG( w, pos1, dd, TRUE );
856 } 873 }
857 } else { 874 } else {
858 int dd, newLeft, nextPos; 875 int dd, newLeft, nextPos;
859 if( false && orient == Horizontal ) { 876 if( false && orient == Qt::Horizontal ) {
860 dd = w->geometry().right() - pos; 877 dd = w->geometry().right() - pos;
861 dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); 878 dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize())));
862 newLeft = pos+1; 879 newLeft = pos+1;
863 nextPos = newLeft + dd; 880 nextPos = newLeft + dd;
864 } else { 881 } else {
865 dd = pos - pick( w->pos() ) + 1; 882 dd = pos - pick( w->pos() ) + 1;
866 dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); 883 dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize())));
867 newLeft = pos-dd+1; 884 newLeft = pos-dd+1;
868 nextPos = newLeft - 1; 885 nextPos = newLeft - 1;
869 } 886 }
870 setG( w, newLeft, dd, TRUE ); 887 setG( w, newLeft, dd, TRUE );
871 moveBefore( nextPos, id-1, upLeft ); 888 moveBefore( nextPos, id-1, upLeft );
872 } 889 }
873} 890}
874 891
875 892
876/* 893/*
877 Places the left/top edge of the widget at \a id at position \a pos. 894 Places the left/top edge of the widget at \a id at position \a pos.
878 895
879 \sa idAfter() 896 \sa idAfter()
880*/ 897*/
881void KDGanttMinimizeSplitter::moveAfter( int pos, int id, bool upLeft ) 898void KDGanttMinimizeSplitter::moveAfter( int pos, int id, bool upLeft )
882{ 899{
883 QSplitterLayoutStruct *s = id < int(data->list.count()) ? 900 QSplitterLayoutStruct *s = id < int(data->list.count()) ?
884 data->list.at(id) : 0; 901 data->list.at(id) : 0;
885 if ( !s ) 902 if ( !s )
886 return; 903 return;
887 QWidget *w = s->wid; 904 QWidget *w = s->wid;
888 if ( w->isHidden() ) { 905 if ( w->isHidden() ) {
889 moveAfter( pos, id+1, upLeft ); 906 moveAfter( pos, id+1, upLeft );
890 } else if ( pick( w->pos() ) == pos ) { 907 } else if ( pick( w->pos() ) == pos ) {
891 //No need to do anything if it's already there. 908 //No need to do anything if it's already there.
892 return; 909 return;
893 } else if ( s->isSplitter ) { 910 } else if ( s->isSplitter ) {
894 int dd = s->sizer; 911 int dd = s->sizer;
895 int pos1, pos2; 912 int pos1, pos2;
896 if( false && orient == Horizontal ) { 913 if( false && orient == Qt::Horizontal ) {
897 pos2 = pos - dd; 914 pos2 = pos - dd;
898 pos1 = pos2 + 1; 915 pos1 = pos2 + 1;
899 } else { 916 } else {
900 pos1 = pos; 917 pos1 = pos;
901 pos2 = pos + dd; 918 pos2 = pos + dd;
902 } 919 }
903 if ( upLeft ) { 920 if ( upLeft ) {
904 setG( w, pos1, dd, TRUE ); 921 setG( w, pos1, dd, TRUE );
905 moveAfter( pos2, id+1, upLeft ); 922 moveAfter( pos2, id+1, upLeft );
906 } else { 923 } else {
907 moveAfter( pos2, id+1, upLeft ); 924 moveAfter( pos2, id+1, upLeft );
908 setG( w, pos1, dd, TRUE ); 925 setG( w, pos1, dd, TRUE );
909 } 926 }
910 } else { 927 } else {
911 int left = pick( w->pos() ); 928 int left = pick( w->pos() );
912 int right, dd,/* newRight,*/ newLeft, nextPos; 929 int right, dd,/* newRight,*/ newLeft, nextPos;
913 if ( false && orient == Horizontal ) { 930 if ( false && orient == Qt::Horizontal ) {
914 dd = pos - left + 1; 931 dd = pos - left + 1;
915 dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); 932 dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize())));
916 newLeft = pos-dd+1; 933 newLeft = pos-dd+1;
917 nextPos = newLeft - 1; 934 nextPos = newLeft - 1;
918 } else { 935 } else {
919 right = pick( w->geometry().bottomRight() ); 936 right = pick( w->geometry().bottomRight() );
920 dd = right - pos + 1; 937 dd = right - pos + 1;
921 dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); 938 dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize())));
922 /*newRight = pos+dd-1;*/ 939 /*newRight = pos+dd-1;*/
923 newLeft = pos; 940 newLeft = pos;
924 nextPos = newLeft + dd; 941 nextPos = newLeft + dd;
925 } 942 }
926 setG( w, newLeft, dd, TRUE ); 943 setG( w, newLeft, dd, TRUE );
927 /*if( right != newRight )*/ 944 /*if( right != newRight )*/
928 moveAfter( nextPos, id+1, upLeft ); 945 moveAfter( nextPos, id+1, upLeft );
929 } 946 }
930} 947}
931 948
932 949
933void KDGanttMinimizeSplitter::expandPos( int id, int* min, int* max ) 950void KDGanttMinimizeSplitter::expandPos( int id, int* min, int* max )
934{ 951{
935 QSplitterLayoutStruct *s = data->list.at(id-1); 952 QSplitterLayoutStruct *s = data->list.at(id-1);
936 QWidget* w = s->wid; 953 QWidget* w = s->wid;
937 *min = pick( w->mapToParent( QPoint(0,0) ) ); 954 *min = pick( w->mapToParent( QPoint(0,0) ) );
938 955
939 if ( (uint) id == data->list.count() ) { 956 if ( (uint) id == data->list.count() ) {
940 pick( size() ); 957 pick( size() );
941 } 958 }
942 else { 959 else {
943 QSplitterLayoutStruct *s = data->list.at(id+1); 960 QSplitterLayoutStruct *s = data->list.at(id+1);
944 QWidget* w = s->wid; 961 QWidget* w = s->wid;
945 *max = pick( w->mapToParent( QPoint( w->width(), w->height() ) ) ) -8; 962 *max = pick( w->mapToParent( QPoint( w->width(), w->height() ) ) ) -8;
946 } 963 }
947} 964}
948 965
949 966
950/*! 967/*!
951 Returns the valid range of the splitter with id \a id in \a *min and \a *max. 968 Returns the valid range of the splitter with id \a id in \a *min and \a *max.
952 969
953 \sa idAfter() 970 \sa idAfter()
954*/ 971*/
955 972
956void KDGanttMinimizeSplitter::getRange( int id, int *min, int *max ) 973void KDGanttMinimizeSplitter::getRange( int id, int *min, int *max )
957{ 974{
958 int minB = 0;//before 975 int minB = 0;//before
959 int maxB = 0; 976 int maxB = 0;
960 int minA = 0; 977 int minA = 0;
961 int maxA = 0;//after 978 int maxA = 0;//after
962 int n = data->list.count(); 979 int n = data->list.count();
963 if ( id < 0 || id >= n ) 980 if ( id < 0 || id >= n )
964 return; 981 return;
965 int i; 982 int i;
966 for ( i = 0; i < id; i++ ) { 983 for ( i = 0; i < id; i++ ) {
967 QSplitterLayoutStruct *s = data->list.at(i); 984 QSplitterLayoutStruct *s = data->list.at(i);
968 if ( s->wid->isHidden() ) { 985 if ( s->wid->isHidden() ) {
969 //ignore 986 //ignore
970 } else if ( s->isSplitter ) { 987 } else if ( s->isSplitter ) {
971 minB += s->sizer; 988 minB += s->sizer;
972 maxB += s->sizer; 989 maxB += s->sizer;
973 } else { 990 } else {
974 minB += pick( minSize(s->wid) ); 991 minB += pick( minSize(s->wid) );
975 maxB += pick( s->wid->maximumSize() ); 992 maxB += pick( s->wid->maximumSize() );
976 } 993 }
977 } 994 }
978 for ( i = id; i < n; i++ ) { 995 for ( i = id; i < n; i++ ) {
979 QSplitterLayoutStruct *s = data->list.at(i); 996 QSplitterLayoutStruct *s = data->list.at(i);
980 if ( s->wid->isHidden() ) { 997 if ( s->wid->isHidden() ) {
981 //ignore 998 //ignore
982 } else if ( s->isSplitter ) { 999 } else if ( s->isSplitter ) {
983 minA += s->sizer; 1000 minA += s->sizer;
984 maxA += s->sizer; 1001 maxA += s->sizer;
985 } else { 1002 } else {
986 minA += pick( minSize(s->wid) ); 1003 minA += pick( minSize(s->wid) );
987 maxA += pick( s->wid->maximumSize() ); 1004 maxA += pick( s->wid->maximumSize() );
988 } 1005 }
989 } 1006 }
990 QRect r = contentsRect(); 1007 QRect r = contentsRect();
991 if ( orient == Horizontal && false ) { 1008 if ( orient == Qt::Horizontal && false ) {
992#if QT_VERSION >= 0x030000 1009#if QT_VERSION >= 0x030000
993 int splitterWidth = style().pixelMetric(QStyle::PM_SplitterWidth, this); 1010 int splitterWidth = style()->pixelMetric(QStyle::PM_SplitterWidth, 0,this);
994#else 1011#else
995 int splitterWidth = style().splitterWidth(); 1012 int splitterWidth = style().splitterWidth();
996#endif 1013#endif
997 1014
998 if ( min ) 1015 if ( min )
999 *min = pick(r.topRight()) - QMIN( maxB, pick(r.size())-minA ) - splitterWidth; 1016 *min = pick(r.topRight()) - QMIN( maxB, pick(r.size())-minA ) - splitterWidth;
1000 if ( max ) 1017 if ( max )
1001 *max = pick(r.topRight()) - QMAX( minB, pick(r.size())-maxA ) - splitterWidth; 1018 *max = pick(r.topRight()) - QMAX( minB, pick(r.size())-maxA ) - splitterWidth;
1002 } else { 1019 } else {
1003 if ( min ) 1020 if ( min )
1004 *min = pick(r.topLeft()) + QMAX( minB, pick(r.size())-maxA ); 1021 *min = pick(r.topLeft()) + QMAX( minB, pick(r.size())-maxA );
1005 if ( max ) 1022 if ( max )
1006 *max = pick(r.topLeft()) + QMIN( maxB, pick(r.size())-minA ); 1023 *max = pick(r.topLeft()) + QMIN( maxB, pick(r.size())-minA );
1007 } 1024 }
1008} 1025}
1009 1026
1010 1027
1011/*! 1028/*!
1012 Returns the closest legal position to \a p of the splitter with id \a id. 1029 Returns the closest legal position to \a p of the splitter with id \a id.
1013 1030
1014 \sa idAfter() 1031 \sa idAfter()
1015*/ 1032*/
1016 1033
1017int KDGanttMinimizeSplitter::adjustPos( int p, int id ) 1034int KDGanttMinimizeSplitter::adjustPos( int p, int id )
1018{ 1035{
1019 int min = 0; 1036 int min = 0;
1020 int max = 0; 1037 int max = 0;
1021 getRange( id, &min, &max ); 1038 getRange( id, &min, &max );
1022 p = QMAX( min, QMIN( p, max ) ); 1039 p = QMAX( min, QMIN( p, max ) );
1023 1040
1024 return p; 1041 return p;
1025} 1042}
1026 1043
1027 1044
1028void KDGanttMinimizeSplitter::doResize() 1045void KDGanttMinimizeSplitter::doResize()
1029{ 1046{
1030 QRect r = contentsRect(); 1047 QRect r = contentsRect();
1031 int i; 1048 int i;
1032 int n = data->list.count(); 1049 int n = data->list.count();
1033 QMemArray<QLayoutStruct> a( n ); 1050 Q3MemArray<QLayoutStruct> a( n );
1034 for ( i = 0; i< n; i++ ) { 1051 for ( i = 0; i< n; i++ ) {
1035 a[i].init(); 1052 a[i].init();
1036 QSplitterLayoutStruct *s = data->list.at(i); 1053 QSplitterLayoutStruct *s = data->list.at(i);
1037 if ( s->wid->isHidden() ) { 1054 if ( s->wid->isHidden() ) {
1038 a[i].stretch = 0; 1055 a[i].stretch = 0;
1039 a[i].sizeHint = a[i].minimumSize = 0; 1056 a[i].sizeHint = a[i].minimumSize = 0;
1040 a[i].maximumSize = 0; 1057 a[i].maximumSize = 0;
1041 } else if ( s->isSplitter ) { 1058 } else if ( s->isSplitter ) {
1042 a[i].stretch = 0; 1059 a[i].stretch = 0;
1043 a[i].sizeHint = a[i].minimumSize = a[i].maximumSize = s->sizer; 1060 a[i].sizeHint = a[i].minimumSize = a[i].maximumSize = s->sizer;
1044 a[i].empty = FALSE; 1061 a[i].empty = FALSE;
1045 } else if ( s->mode == KeepSize ) { 1062 } else if ( s->mode == KeepSize ) {
1046 a[i].stretch = 0; 1063 a[i].stretch = 0;
1047 a[i].minimumSize = pick( minSize(s->wid) ); 1064 a[i].minimumSize = pick( minSize(s->wid) );
1048 a[i].sizeHint = s->sizer; 1065 a[i].sizeHint = s->sizer;
1049 a[i].maximumSize = pick( s->wid->maximumSize() ); 1066 a[i].maximumSize = pick( s->wid->maximumSize() );
1050 a[i].empty = FALSE; 1067 a[i].empty = FALSE;
1051 } else if ( s->mode == FollowSizeHint ) { 1068 } else if ( s->mode == FollowSizeHint ) {
1052 a[i].stretch = 0; 1069 a[i].stretch = 0;
1053 a[i].minimumSize = a[i].sizeHint = pick( s->wid->sizeHint() ); 1070 a[i].minimumSize = a[i].sizeHint = pick( s->wid->sizeHint() );
1054 a[i].maximumSize = pick( s->wid->maximumSize() ); 1071 a[i].maximumSize = pick( s->wid->maximumSize() );
1055 a[i].empty = FALSE; 1072 a[i].empty = FALSE;
1056 } else { //proportional 1073 } else { //proportional
1057 a[i].stretch = s->sizer; 1074 a[i].stretch = s->sizer;
1058 a[i].maximumSize = pick( s->wid->maximumSize() ); 1075 a[i].maximumSize = pick( s->wid->maximumSize() );
1059 a[i].sizeHint = a[i].minimumSize = pick( minSize(s->wid) ); 1076 a[i].sizeHint = a[i].minimumSize = pick( minSize(s->wid) );
1060 a[i].empty = FALSE; 1077 a[i].empty = FALSE;
1061 } 1078 }
1062 } 1079 }
1063 1080
1064 kdganttGeomCalc( a, 0, n, pick( r.topLeft() ), pick( r.size() ), 0 ); 1081 kdganttGeomCalc( a, 0, n, pick( r.topLeft() ), pick( r.size() ), 0 );
1065 1082
1066 for ( i = 0; i< n; i++ ) { 1083 for ( i = 0; i< n; i++ ) {
1067 QSplitterLayoutStruct *s = data->list.at(i); 1084 QSplitterLayoutStruct *s = data->list.at(i);
1068 setG( s->wid, a[i].pos, a[i].size ); 1085 setG( s->wid, a[i].pos, a[i].size );
1069 } 1086 }
1070 1087
1071} 1088}
1072 1089
1073 1090
1074void KDGanttMinimizeSplitter::recalc( bool update ) 1091void KDGanttMinimizeSplitter::recalc( bool update )
1075{ 1092{
1076 int fi = 2*frameWidth(); 1093 int fi = 2*frameWidth();
1077 int maxl = fi; 1094 int maxl = fi;
1078 int minl = fi; 1095 int minl = fi;
1079 int maxt = QWIDGETSIZE_MAX; 1096 int maxt = QWIDGETSIZE_MAX;
1080 int mint = fi; 1097 int mint = fi;
1081 int n = data->list.count(); 1098 int n = data->list.count();
1082 bool first = TRUE; 1099 bool first = TRUE;
1083 /* 1100 /*
1084 The splitter before a hidden widget is always hidden. 1101 The splitter before a hidden widget is always hidden.
1085 The splitter before the first visible widget is hidden. 1102 The splitter before the first visible widget is hidden.
1086 The splitter before any other visible widget is visible. 1103 The splitter before any other visible widget is visible.
1087 */ 1104 */
1088 for ( int i = 0; i< n; i++ ) { 1105 for ( int i = 0; i< n; i++ ) {
1089 QSplitterLayoutStruct *s = data->list.at(i); 1106 QSplitterLayoutStruct *s = data->list.at(i);
1090 if ( !s->isSplitter ) { 1107 if ( !s->isSplitter ) {
1091 QSplitterLayoutStruct *p = (i > 0) ? p = data->list.at( i-1 ) : 0; 1108 QSplitterLayoutStruct *p = (i > 0) ? p = data->list.at( i-1 ) : 0;
1092 if ( p && p->isSplitter ) 1109 if ( p && p->isSplitter )
1093 if ( first || s->wid->isHidden() ) 1110 if ( first || s->wid->isHidden() )
1094 p->wid->hide(); //may trigger new recalc 1111 p->wid->hide(); //may trigger new recalc
1095 else 1112 else
1096 p->wid->show(); //may trigger new recalc 1113 p->wid->show(); //may trigger new recalc
1097 if ( !s->wid->isHidden() ) 1114 if ( !s->wid->isHidden() )
1098 first = FALSE; 1115 first = FALSE;
1099 } 1116 }
1100 } 1117 }
1101 1118
1102 bool empty=TRUE; 1119 bool empty=TRUE;
1103 for ( int j = 0; j< n; j++ ) { 1120 for ( int j = 0; j< n; j++ ) {
1104 QSplitterLayoutStruct *s = data->list.at(j); 1121 QSplitterLayoutStruct *s = data->list.at(j);
1105 if ( !s->wid->isHidden() ) { 1122 if ( !s->wid->isHidden() ) {
1106 empty = FALSE; 1123 empty = FALSE;
1107 if ( s->isSplitter ) { 1124 if ( s->isSplitter ) {
1108 minl += s->sizer; 1125 minl += s->sizer;
1109 maxl += s->sizer; 1126 maxl += s->sizer;
1110 } else { 1127 } else {
1111 QSize minS = minSize(s->wid); 1128 QSize minS = minSize(s->wid);
1112 minl += pick( minS ); 1129 minl += pick( minS );
1113 maxl += pick( s->wid->maximumSize() ); 1130 maxl += pick( s->wid->maximumSize() );
1114 mint = QMAX( mint, trans( minS )); 1131 mint = QMAX( mint, trans( minS ));
1115 int tm = trans( s->wid->maximumSize() ); 1132 int tm = trans( s->wid->maximumSize() );
1116 if ( tm > 0 ) 1133 if ( tm > 0 )
1117 maxt = QMIN( maxt, tm ); 1134 maxt = QMIN( maxt, tm );
1118 } 1135 }
1119 } 1136 }
1120 } 1137 }
1121 if ( empty ) { 1138 if ( empty ) {
1122 if ( parentWidget() != 0 && parentWidget()->inherits("KDGanttMinimizeSplitter") ) { 1139 if ( parentWidget() != 0 && parentWidget()->inherits("KDGanttMinimizeSplitter") ) {
1123 // nested splitters; be nice 1140 // nested splitters; be nice
1124 maxl = maxt = 0; 1141 maxl = maxt = 0;
1125 } else { 1142 } else {
1126 // KDGanttMinimizeSplitter with no children yet 1143 // KDGanttMinimizeSplitter with no children yet
1127 maxl = QWIDGETSIZE_MAX; 1144 maxl = QWIDGETSIZE_MAX;
1128 } 1145 }
1129 } else { 1146 } else {
1130 maxl = QMIN( maxl, QWIDGETSIZE_MAX ); 1147 maxl = QMIN( maxl, QWIDGETSIZE_MAX );
1131 } 1148 }
1132 if ( maxt < mint ) 1149 if ( maxt < mint )
1133 maxt = mint; 1150 maxt = mint;
1134 1151
1135 if ( orient == Horizontal ) { 1152 if ( orient == Qt::Horizontal ) {
1136 setMaximumSize( maxl, maxt ); 1153 setMaximumSize( maxl, maxt );
1137 setMinimumSize( minl, mint ); 1154 setMinimumSize( minl, mint );
1138 } else { 1155 } else {
1139 setMaximumSize( maxt, maxl ); 1156 setMaximumSize( maxt, maxl );
1140 setMinimumSize( mint, minl ); 1157 setMinimumSize( mint, minl );
1141 } 1158 }
1142 if ( update ) 1159 if ( update )
1143 doResize(); 1160 doResize();
1144} 1161}
1145 1162
1146/*! 1163/*!
1147 Sets resize mode of \a w to \a mode. 1164 Sets resize mode of \a w to \a mode.
1148 1165
1149 \sa ResizeMode 1166 \sa ResizeMode
1150*/ 1167*/
1151 1168
1152void KDGanttMinimizeSplitter::setResizeMode( QWidget *w, ResizeMode mode ) 1169void KDGanttMinimizeSplitter::setResizeMode( QWidget *w, ResizeMode mode )
1153{ 1170{
1154 processChildEvents(); 1171 processChildEvents();
1155 QSplitterLayoutStruct *s = data->list.first(); 1172 QSplitterLayoutStruct *s = data->list.first();
1156 while ( s ) { 1173 while ( s ) {
1157 if ( s->wid == w ) { 1174 if ( s->wid == w ) {
1158 s->mode = mode; 1175 s->mode = mode;
1159 return; 1176 return;
1160 } 1177 }
1161 s = data->list.next(); 1178 s = data->list.next();
1162 } 1179 }
1163 s = addWidget( w, TRUE ); 1180 s = addWidget( w, TRUE );
1164 s->mode = mode; 1181 s->mode = mode;
1165} 1182}
1166 1183
1167 1184
1168/*! 1185/*!
1169 Returns TRUE if opaque resize is on; otherwise returns FALSE. 1186 Returns TRUE if opaque resize is on; otherwise returns FALSE.
1170 1187
1171 \sa setOpaqueResize() 1188 \sa setOpaqueResize()
1172*/ 1189*/
1173 1190
1174bool KDGanttMinimizeSplitter::opaqueResize() const 1191bool KDGanttMinimizeSplitter::opaqueResize() const
1175{ 1192{
1176 return data->opaque; 1193 return data->opaque;
1177} 1194}
1178 1195
1179 1196
1180/*! 1197/*!
1181 If \a on is TRUE then opaque resizing is turned on; otherwise 1198 If \a on is TRUE then opaque resizing is turned on; otherwise
1182 opaque resizing is turned off. 1199 opaque resizing is turned off.
1183 Opaque resizing is initially turned off. 1200 Opaque resizing is initially turned off.
1184 1201
1185 \sa opaqueResize() 1202 \sa opaqueResize()
1186*/ 1203*/
1187 1204
1188void KDGanttMinimizeSplitter::setOpaqueResize( bool on ) 1205void KDGanttMinimizeSplitter::setOpaqueResize( bool on )
1189{ 1206{
1190 data->opaque = on; 1207 data->opaque = on;
1191} 1208}
1192 1209
1193 1210
1194/*! 1211/*!
1195 Moves widget \a w to the leftmost/top position. 1212 Moves widget \a w to the leftmost/top position.
1196*/ 1213*/
1197 1214
1198void KDGanttMinimizeSplitter::moveToFirst( QWidget *w ) 1215void KDGanttMinimizeSplitter::moveToFirst( QWidget *w )
1199{ 1216{
1200 processChildEvents(); 1217 processChildEvents();
1201 bool found = FALSE; 1218 bool found = FALSE;
1202 QSplitterLayoutStruct *s = data->list.first(); 1219 QSplitterLayoutStruct *s = data->list.first();
1203 while ( s ) { 1220 while ( s ) {
1204 if ( s->wid == w ) { 1221 if ( s->wid == w ) {
1205 found = TRUE; 1222 found = TRUE;
1206 QSplitterLayoutStruct *p = data->list.prev(); 1223 QSplitterLayoutStruct *p = data->list.prev();
1207 if ( p ) { // not already at first place 1224 if ( p ) { // not already at first place
1208 data->list.take(); //take p 1225 data->list.take(); //take p
1209 data->list.take(); // take s 1226 data->list.take(); // take s
1210 data->list.insert( 0, p ); 1227 data->list.insert( 0, p );
1211 data->list.insert( 0, s ); 1228 data->list.insert( 0, s );
1212 } 1229 }
1213 break; 1230 break;
1214 } 1231 }
1215 s = data->list.next(); 1232 s = data->list.next();
1216 } 1233 }
1217 if ( !found ) 1234 if ( !found )
1218 addWidget( w, TRUE ); 1235 addWidget( w, TRUE );
1219 recalcId(); 1236 recalcId();
1220} 1237}
1221 1238
1222 1239
1223/*! 1240/*!
1224 Moves widget \a w to the rightmost/bottom position. 1241 Moves widget \a w to the rightmost/bottom position.
1225*/ 1242*/
1226 1243
1227void KDGanttMinimizeSplitter::moveToLast( QWidget *w ) 1244void KDGanttMinimizeSplitter::moveToLast( QWidget *w )
1228{ 1245{
1229 processChildEvents(); 1246 processChildEvents();
1230 bool found = FALSE; 1247 bool found = FALSE;
1231 QSplitterLayoutStruct *s = data->list.first(); 1248 QSplitterLayoutStruct *s = data->list.first();
1232 while ( s ) { 1249 while ( s ) {
1233 if ( s->wid == w ) { 1250 if ( s->wid == w ) {
1234 found = TRUE; 1251 found = TRUE;
1235 data->list.take(); // take s 1252 data->list.take(); // take s
1236 QSplitterLayoutStruct *p = data->list.current(); 1253 QSplitterLayoutStruct *p = data->list.current();
1237 if ( p ) { // the splitter handle after s 1254 if ( p ) { // the splitter handle after s
1238 data->list.take(); //take p 1255 data->list.take(); //take p
1239 data->list.append( p ); 1256 data->list.append( p );
1240 } 1257 }
1241 data->list.append( s ); 1258 data->list.append( s );
1242 break; 1259 break;
1243 } 1260 }
1244 s = data->list.next(); 1261 s = data->list.next();
1245 } 1262 }
1246 if ( !found ) 1263 if ( !found )
1247 addWidget( w); 1264 addWidget( w);
1248 recalcId(); 1265 recalcId();
1249} 1266}
1250 1267
1251 1268
1252void KDGanttMinimizeSplitter::recalcId() 1269void KDGanttMinimizeSplitter::recalcId()
1253{ 1270{
1254 int n = data->list.count(); 1271 int n = data->list.count();
1255 for ( int i = 0; i < n; i++ ) { 1272 for ( int i = 0; i < n; i++ ) {
1256 QSplitterLayoutStruct *s = data->list.at(i); 1273 QSplitterLayoutStruct *s = data->list.at(i);
1257 if ( s->isSplitter ) 1274 if ( s->isSplitter )
1258 ((KDGanttSplitterHandle*)s->wid)->setId(i); 1275 ((KDGanttSplitterHandle*)s->wid)->setId(i);
1259 } 1276 }
1260} 1277}
1261 1278
1262 1279
1263/*!\reimp 1280/*!\reimp
1264*/ 1281*/
1265QSize KDGanttMinimizeSplitter::sizeHint() const 1282QSize KDGanttMinimizeSplitter::sizeHint() const
1266{ 1283{
1267 constPolish(); 1284 constPolish();
1268 int l = 0; 1285 int l = 0;
1269 int t = 0; 1286 int t = 0;
1270 if ( children() ) { 1287 if ( !children().empty() ) {
1271 const QObjectList * c = children(); 1288 const QObjectList c = children();
1272 QObjectListIt it( *c ); 1289 for(QObjectList::const_iterator i=c.begin();i!=c.end();++i) {
1273 QObject * o; 1290 QObject * o = *i;
1274
1275 while( (o=it.current()) != 0 ) {
1276 ++it;
1277 if ( o->isWidgetType() && 1291 if ( o->isWidgetType() &&
1278 !((QWidget*)o)->isHidden() ) { 1292 !((QWidget*)o)->isHidden() ) {
1279 QSize s = ((QWidget*)o)->sizeHint(); 1293 QSize s = ((QWidget*)o)->sizeHint();
1280 if ( s.isValid() ) { 1294 if ( s.isValid() ) {
1281 l += pick( s ); 1295 l += pick( s );
1282 t = QMAX( t, trans( s ) ); 1296 t = QMAX( t, trans( s ) );
1283 } 1297 }
1284 } 1298 }
1285 } 1299 }
1286 } 1300 }
1287 return orientation() == Horizontal ? QSize( l, t ) : QSize( t, l ); 1301 return orientation() == Qt::Horizontal ? QSize( l, t ) : QSize( t, l );
1288} 1302}
1289 1303
1290 1304
1291/*! 1305/*!
1292\reimp 1306\reimp
1293*/ 1307*/
1294 1308
1295QSize KDGanttMinimizeSplitter::minimumSizeHint() const 1309QSize KDGanttMinimizeSplitter::minimumSizeHint() const
1296{ 1310{
1297 constPolish(); 1311 constPolish();
1298 int l = 0; 1312 int l = 0;
1299 int t = 0; 1313 int t = 0;
1300 if ( children() ) { 1314 if ( !children().empty() ) {
1301 const QObjectList * c = children(); 1315 const QObjectList c = children();
1302 QObjectListIt it( *c ); 1316 for(QObjectList::const_iterator i=c.begin();i!=c.end();++i) {
1303 QObject * o; 1317 QObject * o = *i;
1304
1305 while( (o=it.current()) != 0 ) {
1306 ++it;
1307 if ( o->isWidgetType() && 1318 if ( o->isWidgetType() &&
1308 !((QWidget*)o)->isHidden() ) { 1319 !((QWidget*)o)->isHidden() ) {
1309 QSize s = minSizeHint((QWidget*)o); 1320 QSize s = minSizeHint((QWidget*)o);
1310 if ( s.isValid() ) { 1321 if ( s.isValid() ) {
1311 l += pick( s ); 1322 l += pick( s );
1312 t = QMAX( t, trans( s ) ); 1323 t = QMAX( t, trans( s ) );
1313 } 1324 }
1314 } 1325 }
1315 } 1326 }
1316 } 1327 }
1317 return orientation() == Horizontal ? QSize( l, t ) : QSize( t, l ); 1328 return orientation() == Qt::Horizontal ? QSize( l, t ) : QSize( t, l );
1318} 1329}
1319 1330
1320 1331
1321/* 1332/*
1322 Calculates stretch parameters from current sizes 1333 Calculates stretch parameters from current sizes
1323*/ 1334*/
1324 1335
1325void KDGanttMinimizeSplitter::storeSizes() 1336void KDGanttMinimizeSplitter::storeSizes()
1326{ 1337{
1327 QSplitterLayoutStruct *s = data->list.first(); 1338 QSplitterLayoutStruct *s = data->list.first();
1328 while ( s ) { 1339 while ( s ) {
1329 if ( !s->isSplitter ) 1340 if ( !s->isSplitter )
1330 s->sizer = pick( s->wid->size() ); 1341 s->sizer = pick( s->wid->size() );
1331 s = data->list.next(); 1342 s = data->list.next();
1332 } 1343 }
1333} 1344}
1334 1345
1335 1346
1336#if 0 // ### remove this code ASAP 1347#if 0 // ### remove this code ASAP
1337 1348
1338/*! 1349/*!
1339 Hides \a w if \a hide is TRUE and updates the splitter. 1350 Hides \a w if \a hide is TRUE and updates the splitter.
1340 1351
1341 \warning Due to a limitation in the current implementation, 1352 \warning Due to a limitation in the current implementation,
1342 calling QWidget::hide() will not work. 1353 calling QWidget::hide() will not work.
1343*/ 1354*/
1344 1355
1345void KDGanttMinimizeSplitter::setHidden( QWidget *w, bool hide ) 1356void KDGanttMinimizeSplitter::setHidden( QWidget *w, bool hide )
1346{ 1357{
1347 if ( w == w1 ) { 1358 if ( w == w1 ) {
1348 w1show = !hide; 1359 w1show = !hide;
1349 } else if ( w == w2 ) { 1360 } else if ( w == w2 ) {
1350 w2show = !hide; 1361 w2show = !hide;
1351 } else { 1362 } else {
1352#ifdef QT_CHECK_RANGE 1363#ifdef QT_CHECK_RANGE
1353 qWarning( "KDGanttMinimizeSplitter::setHidden(), unknown widget" ); 1364 qWarning( "KDGanttMinimizeSplitter::setHidden(), unknown widget" );
1354#endif 1365#endif
1355 return; 1366 return;
1356 } 1367 }
1357 if ( hide ) 1368 if ( hide )
1358 w->hide(); 1369 w->hide();
1359 else 1370 else
1360 w->show(); 1371 w->show();
1361 recalc( TRUE ); 1372 recalc( TRUE );
1362} 1373}
1363 1374
1364 1375
1365/*! 1376/*!
1366 Returns the hidden status of \a w 1377 Returns the hidden status of \a w
1367*/ 1378*/
1368 1379
1369bool KDGanttMinimizeSplitter::isHidden( QWidget *w ) const 1380bool KDGanttMinimizeSplitter::isHidden( QWidget *w ) const
1370{ 1381{
1371 if ( w == w1 ) 1382 if ( w == w1 )
1372 return !w1show; 1383 return !w1show;
1373 else if ( w == w2 ) 1384 else if ( w == w2 )
1374 return !w2show; 1385 return !w2show;
1375#ifdef QT_CHECK_RANGE 1386#ifdef QT_CHECK_RANGE
1376 else 1387 else
1377 qWarning( "KDGanttMinimizeSplitter::isHidden(), unknown widget" ); 1388 qWarning( "KDGanttMinimizeSplitter::isHidden(), unknown widget" );
1378#endif 1389#endif
1379 return FALSE; 1390 return FALSE;
1380} 1391}
1381#endif 1392#endif
1382 1393
1383 1394
1384/*! 1395/*!
1385 Returns a list of the size parameters of all the widgets in this 1396 Returns a list of the size parameters of all the widgets in this
1386 splitter. 1397 splitter.
1387 1398
1388 Giving the values to another splitter's setSizes() function will 1399 Giving the values to another splitter's setSizes() function will
1389 produce a splitter with the same layout as this one. 1400 produce a splitter with the same layout as this one.
1390 1401
1391 Note that if you want to iterate over the list, you should 1402 Note that if you want to iterate over the list, you should
1392 iterate over a copy, e.g. 1403 iterate over a copy, e.g.
1393 \code 1404 \code
1394 QValueList<int> list = mySplitter.sizes(); 1405 QValueList<int> list = mySplitter.sizes();
1395 QValueList<int>::Iterator it = list.begin(); 1406 QValueList<int>::Iterator it = list.begin();
1396 while( it != list.end() ) { 1407 while( it != list.end() ) {
1397 myProcessing( *it ); 1408 myProcessing( *it );
1398 ++it; 1409 ++it;
1399 } 1410 }
1400 \endcode 1411 \endcode
1401 1412
1402 \sa setSizes() 1413 \sa setSizes()
1403*/ 1414*/
1404 1415
1405QValueList<int> KDGanttMinimizeSplitter::sizes() const 1416Q3ValueList<int> KDGanttMinimizeSplitter::sizes() const
1406{ 1417{
1418 /* TODO: hacker
1407 if ( !testWState(WState_Polished) ) { 1419 if ( !testWState(WState_Polished) ) {
1408 QWidget* that = (QWidget*) this; 1420 QWidget* that = (QWidget*) this;
1409 that->polish(); 1421 that->polish();
1410 } 1422 } */
1411 QValueList<int> list; 1423 Q3ValueList<int> list;
1412 QSplitterLayoutStruct *s = data->list.first(); 1424 QSplitterLayoutStruct *s = data->list.first();
1413 while ( s ) { 1425 while ( s ) {
1414 if ( !s->isSplitter ) 1426 if ( !s->isSplitter )
1415 list.append( s->sizer ); 1427 list.append( s->sizer );
1416 s = data->list.next(); 1428 s = data->list.next();
1417 } 1429 }
1418 return list; 1430 return list;
1419} 1431}
1420 1432
1421 1433
1422 1434
1423/*! 1435/*!
1424 Sets the size parameters to the values given in \a list. 1436 Sets the size parameters to the values given in \a list.
1425 If the splitter is horizontal, the values set the sizes from 1437 If the splitter is horizontal, the values set the sizes from
1426 left to right. If it is vertical, the sizes are applied from 1438 left to right. If it is vertical, the sizes are applied from
1427 top to bottom. 1439 top to bottom.
1428 Extra values in \a list are ignored. 1440 Extra values in \a list are ignored.
1429 1441
1430 If \a list contains too few values, the result is undefined 1442 If \a list contains too few values, the result is undefined
1431 but the program will still be well-behaved. 1443 but the program will still be well-behaved.
1432 1444
1433 \sa sizes() 1445 \sa sizes()
1434*/ 1446*/
1435 1447
1436void KDGanttMinimizeSplitter::setSizes( QValueList<int> list ) 1448void KDGanttMinimizeSplitter::setSizes( Q3ValueList<int> list )
1437{ 1449{
1438 processChildEvents(); 1450 processChildEvents();
1439 QValueList<int>::Iterator it = list.begin(); 1451 Q3ValueList<int>::Iterator it = list.begin();
1440 QSplitterLayoutStruct *s = data->list.first(); 1452 QSplitterLayoutStruct *s = data->list.first();
1441 while ( s && it != list.end() ) { 1453 while ( s && it != list.end() ) {
1442 if ( !s->isSplitter ) { 1454 if ( !s->isSplitter ) {
1443 s->sizer = *it; 1455 s->sizer = *it;
1444 ++it; 1456 ++it;
1445 } 1457 }
1446 s = data->list.next(); 1458 s = data->list.next();
1447 } 1459 }
1448 doResize(); 1460 doResize();
1449} 1461}
1450 1462
1451 1463
1452/*! 1464/*!
1453 Gets all posted child events, ensuring that the internal state of 1465 Gets all posted child events, ensuring that the internal state of
1454 the splitter is consistent. 1466 the splitter is consistent.
1455*/ 1467*/
1456 1468
1457void KDGanttMinimizeSplitter::processChildEvents() 1469void KDGanttMinimizeSplitter::processChildEvents()
1458{ 1470{
1459 QApplication::sendPostedEvents( this, QEvent::ChildInserted ); 1471 QApplication::sendPostedEvents( this, QEvent::ChildAdded );
1460} 1472}
1461 1473
1462 1474
1463/*! 1475/*!
1464 \reimp 1476 \reimp
1465*/ 1477*/
1466 1478
1467void KDGanttMinimizeSplitter::styleChange( QStyle& old ) 1479void KDGanttMinimizeSplitter::styleChange( QStyle& old )
1468{ 1480{
1469 1481
1470#if QT_VERSION >= 0x030000 1482#if QT_VERSION >= 0x030000
1471 int sw = style().pixelMetric(QStyle::PM_SplitterWidth, this); 1483 int sw = style()->pixelMetric(QStyle::PM_SplitterWidth, 0, this);
1472#else 1484#else
1473 int sw = style().splitterWidth(); 1485 int sw = style().splitterWidth();
1474#endif 1486#endif
1475 QSplitterLayoutStruct *s = data->list.first(); 1487 QSplitterLayoutStruct *s = data->list.first();
1476 while ( s ) { 1488 while ( s ) {
1477 if ( s->isSplitter ) 1489 if ( s->isSplitter )
1478 s->sizer = sw; 1490 s->sizer = sw;
1479 s = data->list.next(); 1491 s = data->list.next();
1480 } 1492 }
1481 doResize(); 1493 doResize();
1482 QFrame::styleChange( old ); 1494 Q3Frame::styleChange( old );
1483} 1495}
1484 1496
1485#endif 1497#endif
1486 1498
1487/*! 1499/*!
1488 Specifies the direction of the minimize buttons. 1500 Specifies the direction of the minimize buttons.
1489 If the orientation of the splitter is horizontal then with 1501 If the orientation of the splitter is horizontal then with
1490 KDGanttMinimizeSplitter::Left or KDGanttMinimizeSplitter::Right should be used, 1502 KDGanttMinimizeSplitter::Left or KDGanttMinimizeSplitter::Right should be used,
1491 otherwise either KDGanttMinimizeSplitter::Up or KDGanttMinimizeSplitter::Down 1503 otherwise either KDGanttMinimizeSplitter::Up or KDGanttMinimizeSplitter::Down
1492 should be used. 1504 should be used.
1493*/ 1505*/
1494void KDGanttMinimizeSplitter::setMinimizeDirection( Direction direction ) 1506void KDGanttMinimizeSplitter::setMinimizeDirection( Direction direction )
1495{ 1507{
1496 _direction = direction; 1508 _direction = direction;
1497} 1509}
1498 1510
1499/*! 1511/*!
1500 Returns the direction of the minimize buttons. 1512 Returns the direction of the minimize buttons.
1501*/ 1513*/
1502KDGanttMinimizeSplitter::Direction KDGanttMinimizeSplitter::minimizeDirection() const 1514KDGanttMinimizeSplitter::Direction KDGanttMinimizeSplitter::minimizeDirection() const
1503{ 1515{
1504 return _direction; 1516 return _direction;
1505} 1517}
1506 1518
1507/* 1519/*
1508 This is a copy of qGeomCalc() in qlayoutengine.cpp which 1520 This is a copy of qGeomCalc() in qlayoutengine.cpp which
1509 unfortunately isn't exported. 1521 unfortunately isn't exported.
1510*/ 1522*/
1511static inline int toFixed( int i ) { return i * 256; } 1523static inline int toFixed( int i ) { return i * 256; }
1512static inline int fRound( int i ) { 1524static inline int fRound( int i ) {
1513 return ( i % 256 < 128 ) ? i / 256 : 1 + i / 256; 1525 return ( i % 256 < 128 ) ? i / 256 : 1 + i / 256;
1514} 1526}
1515void kdganttGeomCalc( QMemArray<QLayoutStruct> &chain, int start, int count, int pos, 1527void kdganttGeomCalc( Q3MemArray<QLayoutStruct> &chain, int start, int count, int pos,
1516 int space, int spacer ) 1528 int space, int spacer )
1517{ 1529{
1518 typedef int fixed; 1530 typedef int fixed;
1519 int cHint = 0; 1531 int cHint = 0;
1520 int cMin = 0; 1532 int cMin = 0;
1521 int cMax = 0; 1533 int cMax = 0;
1522 int sumStretch = 0; 1534 int sumStretch = 0;
1523 int spacerCount = 0; 1535 int spacerCount = 0;
1524 1536
1525 bool wannaGrow = FALSE; // anyone who really wants to grow? 1537 bool wannaGrow = FALSE; // anyone who really wants to grow?
1526 // bool canShrink = FALSE; // anyone who could be persuaded to shrink? 1538 // bool canShrink = FALSE; // anyone who could be persuaded to shrink?
1527 1539
1528 int i; 1540 int i;
1529 for ( i = start; i < start + count; i++ ) { 1541 for ( i = start; i < start + count; i++ ) {
1530 chain[i].done = FALSE; 1542 chain[i].done = FALSE;
1531 cHint += chain[i].sizeHint; 1543 cHint += chain[i].sizeHint;
1532 cMin += chain[i].minimumSize; 1544 cMin += chain[i].minimumSize;
1533 cMax += chain[i].maximumSize; 1545 cMax += chain[i].maximumSize;
1534 sumStretch += chain[i].stretch; 1546 sumStretch += chain[i].stretch;
1535 if ( !chain[i].empty ) 1547 if ( !chain[i].empty )
1536 spacerCount++; 1548 spacerCount++;
1537 wannaGrow = wannaGrow || chain[i].expansive; 1549 wannaGrow = wannaGrow || chain[i].expansive;
1538 } 1550 }
1539 1551
1540 int extraspace = 0; 1552 int extraspace = 0;
1541 if ( spacerCount ) 1553 if ( spacerCount )
1542 spacerCount--; // only spacers between things 1554 spacerCount--; // only spacers between things
1543 if ( space < cMin + spacerCount * spacer ) { 1555 if ( space < cMin + spacerCount * spacer ) {
1544 //qDebug("not enough space"); 1556 //qDebug("not enough space");
1545 for ( i = start; i < start+count; i++ ) { 1557 for ( i = start; i < start+count; i++ ) {
1546 chain[i].size = chain[i].minimumSize; 1558 chain[i].size = chain[i].minimumSize;
1547 chain[i].done = TRUE; 1559 chain[i].done = TRUE;
1548 } 1560 }
1549 } else if ( space < cHint + spacerCount*spacer ) { 1561 } else if ( space < cHint + spacerCount*spacer ) {
1550 // Less space than sizeHint, but more than minimum. 1562 // Less space than sizeHint, but more than minimum.
1551 // Currently take space equally from each, like in Qt 2.x. 1563 // Currently take space equally from each, like in Qt 2.x.
1552 // Commented-out lines will give more space to stretchier items. 1564 // Commented-out lines will give more space to stretchier items.
1553 int n = count; 1565 int n = count;
1554 int space_left = space - spacerCount*spacer; 1566 int space_left = space - spacerCount*spacer;
1555 int overdraft = cHint - space_left; 1567 int overdraft = cHint - space_left;
1556 //first give to the fixed ones: 1568 //first give to the fixed ones:
1557 for ( i = start; i < start+count; i++ ) { 1569 for ( i = start; i < start+count; i++ ) {
1558 if ( !chain[i].done && chain[i].minimumSize >= chain[i].sizeHint) { 1570 if ( !chain[i].done && chain[i].minimumSize >= chain[i].sizeHint) {
1559 chain[i].size = chain[i].sizeHint; 1571 chain[i].size = chain[i].sizeHint;
1560 chain[i].done = TRUE; 1572 chain[i].done = TRUE;
1561 space_left -= chain[i].sizeHint; 1573 space_left -= chain[i].sizeHint;
1562 // sumStretch -= chain[i].stretch; 1574 // sumStretch -= chain[i].stretch;
1563 n--; 1575 n--;
1564 } 1576 }
1565 } 1577 }
1566 bool finished = n == 0; 1578 bool finished = n == 0;
1567 while ( !finished ) { 1579 while ( !finished ) {
1568 finished = TRUE; 1580 finished = TRUE;
1569 fixed fp_over = toFixed( overdraft ); 1581 fixed fp_over = toFixed( overdraft );
1570 fixed fp_w = 0; 1582 fixed fp_w = 0;
1571 1583
1572 for ( i = start; i < start+count; i++ ) { 1584 for ( i = start; i < start+count; i++ ) {
1573 if ( chain[i].done ) 1585 if ( chain[i].done )
1574 continue; 1586 continue;
1575 // if ( sumStretch <= 0 ) 1587 // if ( sumStretch <= 0 )
1576 fp_w += fp_over / n; 1588 fp_w += fp_over / n;
1577 // else 1589 // else
1578 // fp_w += (fp_over * chain[i].stretch) / sumStretch; 1590 // fp_w += (fp_over * chain[i].stretch) / sumStretch;
1579 int w = fRound( fp_w ); 1591 int w = fRound( fp_w );
1580 chain[i].size = chain[i].sizeHint - w; 1592 chain[i].size = chain[i].sizeHint - w;
1581 fp_w -= toFixed( w ); //give the difference to the next 1593 fp_w -= toFixed( w ); //give the difference to the next
1582 if ( chain[i].size < chain[i].minimumSize ) { 1594 if ( chain[i].size < chain[i].minimumSize ) {
1583 chain[i].done = TRUE; 1595 chain[i].done = TRUE;
1584 chain[i].size = chain[i].minimumSize; 1596 chain[i].size = chain[i].minimumSize;
1585 finished = FALSE; 1597 finished = FALSE;
1586 overdraft -= chain[i].sizeHint - chain[i].minimumSize; 1598 overdraft -= chain[i].sizeHint - chain[i].minimumSize;
1587 // sumStretch -= chain[i].stretch; 1599 // sumStretch -= chain[i].stretch;
1588 n--; 1600 n--;
1589 break; 1601 break;
1590 } 1602 }
1591 } 1603 }
1592 } 1604 }
1593 } else { //extra space 1605 } else { //extra space
1594 int n = count; 1606 int n = count;
1595 int space_left = space - spacerCount*spacer; 1607 int space_left = space - spacerCount*spacer;
1596 // first give to the fixed ones, and handle non-expansiveness 1608 // first give to the fixed ones, and handle non-expansiveness
1597 for ( i = start; i < start + count; i++ ) { 1609 for ( i = start; i < start + count; i++ ) {
1598 if ( !chain[i].done && (chain[i].maximumSize <= chain[i].sizeHint 1610 if ( !chain[i].done && (chain[i].maximumSize <= chain[i].sizeHint
1599 || wannaGrow && !chain[i].expansive) ) { 1611 || wannaGrow && !chain[i].expansive) ) {
1600 chain[i].size = chain[i].sizeHint; 1612 chain[i].size = chain[i].sizeHint;
1601 chain[i].done = TRUE; 1613 chain[i].done = TRUE;
1602 space_left -= chain[i].sizeHint; 1614 space_left -= chain[i].sizeHint;
1603 sumStretch -= chain[i].stretch; 1615 sumStretch -= chain[i].stretch;
1604 n--; 1616 n--;
1605 } 1617 }
1606 } 1618 }
1607 extraspace = space_left; 1619 extraspace = space_left;
1608 /* 1620 /*
1609 Do a trial distribution and calculate how much it is off. 1621 Do a trial distribution and calculate how much it is off.
1610 If there are more deficit pixels than surplus pixels, give 1622 If there are more deficit pixels than surplus pixels, give
1611 the minimum size items what they need, and repeat. 1623 the minimum size items what they need, and repeat.
1612 Otherwise give to the maximum size items, and repeat. 1624 Otherwise give to the maximum size items, and repeat.
1613 1625
1614 I have a wonderful mathematical proof for the correctness 1626 I have a wonderful mathematical proof for the correctness
1615 of this principle, but unfortunately this comment is too 1627 of this principle, but unfortunately this comment is too
1616 small to contain it. 1628 small to contain it.
1617 */ 1629 */
1618 int surplus, deficit; 1630 int surplus, deficit;
1619 do { 1631 do {
1620 surplus = deficit = 0; 1632 surplus = deficit = 0;
1621 fixed fp_space = toFixed( space_left ); 1633 fixed fp_space = toFixed( space_left );
1622 fixed fp_w = 0; 1634 fixed fp_w = 0;
1623 for ( i = start; i < start+count; i++ ) { 1635 for ( i = start; i < start+count; i++ ) {
1624 if ( chain[i].done ) 1636 if ( chain[i].done )
1625 continue; 1637 continue;
1626 extraspace = 0; 1638 extraspace = 0;
1627 if ( sumStretch <= 0 ) 1639 if ( sumStretch <= 0 )
1628 fp_w += fp_space / n; 1640 fp_w += fp_space / n;
1629 else 1641 else
1630 fp_w += (fp_space * chain[i].stretch) / sumStretch; 1642 fp_w += (fp_space * chain[i].stretch) / sumStretch;
1631 int w = fRound( fp_w ); 1643 int w = fRound( fp_w );
1632 chain[i].size = w; 1644 chain[i].size = w;
1633 fp_w -= toFixed( w ); // give the difference to the next 1645 fp_w -= toFixed( w ); // give the difference to the next
1634 if ( w < chain[i].sizeHint ) { 1646 if ( w < chain[i].sizeHint ) {
1635 deficit += chain[i].sizeHint - w; 1647 deficit += chain[i].sizeHint - w;
1636 } else if ( w > chain[i].maximumSize ) { 1648 } else if ( w > chain[i].maximumSize ) {
1637 surplus += w - chain[i].maximumSize; 1649 surplus += w - chain[i].maximumSize;
1638 } 1650 }
1639 } 1651 }
1640 if ( deficit > 0 && surplus <= deficit ) { 1652 if ( deficit > 0 && surplus <= deficit ) {
1641 // give to the ones that have too little 1653 // give to the ones that have too little
1642 for ( i = start; i < start+count; i++ ) { 1654 for ( i = start; i < start+count; i++ ) {
1643 if ( !chain[i].done && 1655 if ( !chain[i].done &&
1644 chain[i].size < chain[i].sizeHint ) { 1656 chain[i].size < chain[i].sizeHint ) {
1645 chain[i].size = chain[i].sizeHint; 1657 chain[i].size = chain[i].sizeHint;
1646 chain[i].done = TRUE; 1658 chain[i].done = TRUE;
1647 space_left -= chain[i].sizeHint; 1659 space_left -= chain[i].sizeHint;
1648 sumStretch -= chain[i].stretch; 1660 sumStretch -= chain[i].stretch;
1649 n--; 1661 n--;
1650 } 1662 }
1651 } 1663 }
1652 } 1664 }
1653 if ( surplus > 0 && surplus >= deficit ) { 1665 if ( surplus > 0 && surplus >= deficit ) {
1654 // take from the ones that have too much 1666 // take from the ones that have too much
1655 for ( i = start; i < start+count; i++ ) { 1667 for ( i = start; i < start+count; i++ ) {
1656 if ( !chain[i].done && 1668 if ( !chain[i].done &&
1657 chain[i].size > chain[i].maximumSize ) { 1669 chain[i].size > chain[i].maximumSize ) {
1658 chain[i].size = chain[i].maximumSize; 1670 chain[i].size = chain[i].maximumSize;
1659 chain[i].done = TRUE; 1671 chain[i].done = TRUE;
1660 space_left -= chain[i].maximumSize; 1672 space_left -= chain[i].maximumSize;
1661 sumStretch -= chain[i].stretch; 1673 sumStretch -= chain[i].stretch;
1662 n--; 1674 n--;
1663 } 1675 }
1664 } 1676 }
1665 } 1677 }
1666 } while ( n > 0 && surplus != deficit ); 1678 } while ( n > 0 && surplus != deficit );
1667 if ( n == 0 ) 1679 if ( n == 0 )
1668 extraspace = space_left; 1680 extraspace = space_left;
1669 } 1681 }
1670 1682
1671 // as a last resort, we distribute the unwanted space equally 1683 // as a last resort, we distribute the unwanted space equally
1672 // among the spacers (counting the start and end of the chain). 1684 // among the spacers (counting the start and end of the chain).
1673 1685
1674 //### should do a sub-pixel allocation of extra space 1686 //### should do a sub-pixel allocation of extra space
1675 int extra = extraspace / ( spacerCount + 2 ); 1687 int extra = extraspace / ( spacerCount + 2 );
1676 int p = pos + extra; 1688 int p = pos + extra;
1677 for ( i = start; i < start+count; i++ ) { 1689 for ( i = start; i < start+count; i++ ) {
1678 chain[i].pos = p; 1690 chain[i].pos = p;
1679 p = p + chain[i].size; 1691 p = p + chain[i].size;
1680 if ( !chain[i].empty ) 1692 if ( !chain[i].empty )
1681 p += spacer+extra; 1693 p += spacer+extra;
1682 } 1694 }
1683} 1695}
1684 1696
1685#endif 1697#endif
1686 1698
1687/*! 1699/*!
1688 \enum KDGanttMinimizeSplitter::Direction 1700 \enum KDGanttMinimizeSplitter::Direction
1689 1701
1690 The values of this enumeration describe into which direction the 1702 The values of this enumeration describe into which direction the
1691 splitter will collapse its child widgets. By extension, it also 1703 splitter will collapse its child widgets. By extension, it also
1692 specifies the orientation of the splitter; collapsing to the left or 1704 specifies the orientation of the splitter; collapsing to the left or
1693 to the right results in a horizontal splitter, collapsing to the top 1705 to the right results in a horizontal splitter, collapsing to the top
1694 or bottom in a vertical splitter. 1706 or bottom in a vertical splitter.
1695*/ 1707*/
1696 1708
1697/*! 1709/*!
1698 \fn Orientation KDGanttMinimizeSplitter::orientation() const 1710 \fn Orientation KDGanttMinimizeSplitter::orientation() const
1699 1711
1700 Returns the orientation of the splitter. 1712 Returns the orientation of the splitter.
1701*/ 1713*/
1702 1714
1703/*! \enum KDGanttMinimizeSplitter::ResizeMode 1715/*! \enum KDGanttMinimizeSplitter::ResizeMode
1704 1716
1705 This enum type describes how KDGanttMinimizeSplitter will resize each of its child widgets. The currently defined values are: 1717 This enum type describes how KDGanttMinimizeSplitter will resize each of its child widgets. The currently defined values are:
1706 1718
1707 Stretch: the widget will be resized when the splitter 1719 Stretch: the widget will be resized when the splitter
1708 itself is resized. 1720 itself is resized.
1709 1721
1710 KeepSize: KDGanttMinimizeSplitter will try to keep this widget's size 1722 KeepSize: KDGanttMinimizeSplitter will try to keep this widget's size
1711 unchanged. 1723 unchanged.
1712 1724
1713 FollowSizeHint: KDGanttMinimizeSplitter will resize the widget when the 1725 FollowSizeHint: KDGanttMinimizeSplitter will resize the widget when the
1714 widget's size hint changes. 1726 widget's size hint changes.
1715*/ 1727*/
1716 1728