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