Diffstat (limited to 'microkde/KDGanttMinimizeSplitter.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | microkde/KDGanttMinimizeSplitter.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/microkde/KDGanttMinimizeSplitter.cpp b/microkde/KDGanttMinimizeSplitter.cpp index c60b566..029f14b 100644 --- a/microkde/KDGanttMinimizeSplitter.cpp +++ b/microkde/KDGanttMinimizeSplitter.cpp | |||
@@ -1,869 +1,874 @@ | |||
1 | /* -*- Mode: C++ -*- | 1 | /* -*- Mode: C++ -*- |
2 | $Id$ | 2 | $Id$ |
3 | */ | 3 | */ |
4 | 4 | ||
5 | /**************************************************************************** | 5 | /**************************************************************************** |
6 | ** Copyright (C) 2002-2004 Klarälvdalens Datakonsult AB. All rights reserved. | 6 | ** Copyright (C) 2002-2004 Klarälvdalens Datakonsult AB. All rights reserved. |
7 | ** | 7 | ** |
8 | ** This file is part of the KDGantt library. | 8 | ** This file is part of the KDGantt library. |
9 | ** | 9 | ** |
10 | ** This file may be distributed and/or modified under the terms of the | 10 | ** This file may be distributed and/or modified under the terms of the |
11 | ** GNU General Public License version 2 as published by the Free Software | 11 | ** GNU General Public License version 2 as published by the Free Software |
12 | ** Foundation and appearing in the file LICENSE.GPL included in the | 12 | ** Foundation and appearing in the file LICENSE.GPL included in the |
13 | ** packaging of this file. | 13 | ** packaging of this file. |
14 | ** | 14 | ** |
15 | ** Licensees holding valid commercial KDGantt licenses may use this file in | 15 | ** Licensees holding valid commercial KDGantt licenses may use this file in |
16 | ** accordance with the KDGantt Commercial License Agreement provided with | 16 | ** accordance with the KDGantt Commercial License Agreement provided with |
17 | ** the Software. | 17 | ** the Software. |
18 | ** | 18 | ** |
19 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 19 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
20 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 20 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
21 | ** | 21 | ** |
22 | ** See http://www.klaralvdalens-datakonsult.se/Public/products/ for | 22 | ** See http://www.klaralvdalens-datakonsult.se/Public/products/ for |
23 | ** information about KDGantt Commercial License Agreements. | 23 | ** information about KDGantt Commercial License Agreements. |
24 | ** | 24 | ** |
25 | ** Contact info@klaralvdalens-datakonsult.se if any conditions of this | 25 | ** Contact info@klaralvdalens-datakonsult.se if any conditions of this |
26 | ** licensing are not clear to you. | 26 | ** licensing are not clear to you. |
27 | ** | 27 | ** |
28 | ** As a special exception, permission is given to link this program | 28 | ** As a special exception, permission is given to link this program |
29 | ** with any edition of Qt, and distribute the resulting executable, | 29 | ** with any edition of Qt, and distribute the resulting executable, |
30 | ** without including the source code for Qt in the source distribution. | 30 | ** without including the source code for Qt in the source distribution. |
31 | ** | 31 | ** |
32 | **********************************************************************/ | 32 | **********************************************************************/ |
33 | 33 | ||
34 | #include "KDGanttMinimizeSplitter.h" | 34 | #include "KDGanttMinimizeSplitter.h" |
35 | #ifndef QT_NO_SPLITTER___ | 35 | #ifndef QT_NO_SPLITTER___ |
36 | 36 | ||
37 | #include "qpainter.h" | 37 | #include "qpainter.h" |
38 | #include "qdrawutil.h" | 38 | #include "qdrawutil.h" |
39 | #include "qbitmap.h" | 39 | #include "qbitmap.h" |
40 | #if QT_VERSION >= 0x030000 | 40 | #if QT_VERSION >= 0x030000 |
41 | #include "qptrlist.h" | 41 | #include "qptrlist.h" |
42 | #include "qmemarray.h" | 42 | #include "qmemarray.h" |
43 | #else | 43 | #else |
44 | #include <qlist.h> | 44 | #include <qlist.h> |
45 | #include <qarray.h> | 45 | #include <qarray.h> |
46 | #define QPtrList QList | 46 | #define QPtrList QList |
47 | #define QMemArray QArray | 47 | #define QMemArray QArray |
48 | #endif | 48 | #endif |
49 | #include "qlayoutengine_p.h" | 49 | #include "qlayoutengine_p.h" |
50 | #include "qobjectlist.h" | 50 | #include "qobjectlist.h" |
51 | #include "qstyle.h" | 51 | #include "qstyle.h" |
52 | #include "qapplication.h" //sendPostedEvents | 52 | #include "qapplication.h" //sendPostedEvents |
53 | #include <qvaluelist.h> | 53 | #include <qvaluelist.h> |
54 | #include <qcursor.h> | 54 | #include <qcursor.h> |
55 | #ifndef KDGANTT_MASTER_CVS | 55 | #ifndef KDGANTT_MASTER_CVS |
56 | //#include "KDGanttMinimizeSplitter.moc" | 56 | //#include "KDGanttMinimizeSplitter.moc" |
57 | #endif | 57 | #endif |
58 | 58 | ||
59 | 59 | ||
60 | 60 | ||
61 | #ifndef DOXYGEN_SKIP_INTERNAL | 61 | #ifndef DOXYGEN_SKIP_INTERNAL |
62 | 62 | ||
63 | #if QT_VERSION >= 232 | 63 | #if QT_VERSION >= 232 |
64 | static int mouseOffset; | 64 | static int mouseOffset; |
65 | static int opaqueOldPos = -1; //### there's only one mouse, but this is a bit risky | 65 | static int opaqueOldPos = -1; //### there's only one mouse, but this is a bit risky |
66 | 66 | ||
67 | 67 | ||
68 | KDGanttSplitterHandle::KDGanttSplitterHandle( Qt::Orientation o, | 68 | KDGanttSplitterHandle::KDGanttSplitterHandle( Qt::Orientation o, |
69 | KDGanttMinimizeSplitter *parent, const char * name ) | 69 | KDGanttMinimizeSplitter *parent, const char * name ) |
70 | : QWidget( parent, name ), _activeButton( 0 ), _collapsed( false ) | 70 | : QWidget( parent, name ), _activeButton( 0 ), _collapsed( false ) |
71 | { | 71 | { |
72 | 72 | ||
73 | if ( QApplication::desktop()->width() > 320 && QApplication::desktop()->width() < 650 ) { | 73 | if ( QApplication::desktop()->width() > 320 && QApplication::desktop()->width() < 650 ) { |
74 | mSizeHint = QSize(7,7); | 74 | mSizeHint = QSize(7,7); |
75 | mUseOffset = true; | 75 | mUseOffset = true; |
76 | } else { | 76 | } else { |
77 | mSizeHint = QSize(6,6); | 77 | mSizeHint = QSize(6,6); |
78 | mUseOffset = false; | 78 | mUseOffset = false; |
79 | } | 79 | } |
80 | s = parent; | 80 | s = parent; |
81 | setOrientation(o); | 81 | setOrientation(o); |
82 | setMouseTracking( true ); | 82 | setMouseTracking( true ); |
83 | mMouseDown = false; | 83 | mMouseDown = false; |
84 | //setMaximumHeight( 5 ); // test only | 84 | //setMaximumHeight( 5 ); // test only |
85 | } | 85 | } |
86 | 86 | ||
87 | QSize KDGanttSplitterHandle::sizeHint() const | 87 | QSize KDGanttSplitterHandle::sizeHint() const |
88 | { | 88 | { |
89 | return mSizeHint; | 89 | return mSizeHint; |
90 | } | 90 | } |
91 | 91 | ||
92 | void KDGanttSplitterHandle::setOrientation( Qt::Orientation o ) | 92 | void KDGanttSplitterHandle::setOrientation( Qt::Orientation o ) |
93 | { | 93 | { |
94 | orient = o; | 94 | orient = o; |
95 | #ifndef QT_NO_CURSOR | 95 | #ifndef QT_NO_CURSOR |
96 | if ( o == KDGanttMinimizeSplitter::Horizontal ) | 96 | if ( o == KDGanttMinimizeSplitter::Horizontal ) |
97 | setCursor( splitHCursor ); | 97 | setCursor( splitHCursor ); |
98 | else | 98 | else |
99 | setCursor( splitVCursor ); | 99 | setCursor( splitVCursor ); |
100 | #endif | 100 | #endif |
101 | } | 101 | } |
102 | 102 | ||
103 | 103 | ||
104 | void KDGanttSplitterHandle::mouseMoveEvent( QMouseEvent *e ) | 104 | void KDGanttSplitterHandle::mouseMoveEvent( QMouseEvent *e ) |
105 | { | 105 | { |
106 | updateCursor( e->pos() ); | 106 | updateCursor( e->pos() ); |
107 | if ( !(e->state()&LeftButton) ) | 107 | if ( !(e->state()&LeftButton) ) |
108 | return; | 108 | return; |
109 | 109 | ||
110 | if ( _activeButton != 0) | 110 | if ( _activeButton != 0) |
111 | return; | 111 | return; |
112 | 112 | ||
113 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) | 113 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) |
114 | - mouseOffset; | 114 | - mouseOffset; |
115 | if ( true /*opaque()*/ ) { | 115 | if ( opaque() ) { |
116 | s->moveSplitter( pos, id() ); | 116 | s->moveSplitter( pos, id() ); |
117 | } else { | 117 | } else { |
118 | int min = pos; int max = pos; | 118 | int min = pos; int max = pos; |
119 | s->getRange( id(), &min, &max ); | 119 | s->getRange( id(), &min, &max ); |
120 | s->setRubberband( QMAX( min, QMIN(max, pos ))); | 120 | s->setRubberband( QMAX( min, QMIN(max, pos ))); |
121 | } | 121 | } |
122 | _collapsed = false; | 122 | _collapsed = false; |
123 | } | 123 | } |
124 | 124 | ||
125 | void KDGanttSplitterHandle::mousePressEvent( QMouseEvent *e ) | 125 | void KDGanttSplitterHandle::mousePressEvent( QMouseEvent *e ) |
126 | { | 126 | { |
127 | if ( e->button() == LeftButton ) { | 127 | if ( e->button() == LeftButton ) { |
128 | _activeButton = onButton( e->pos() ); | 128 | _activeButton = onButton( e->pos() ); |
129 | mouseOffset = s->pick(e->pos()); | 129 | mouseOffset = s->pick(e->pos()); |
130 | mMouseDown = true; | 130 | mMouseDown = true; |
131 | repaint(); | 131 | repaint(); |
132 | updateCursor( e->pos() ); | 132 | updateCursor( e->pos() ); |
133 | } | 133 | } |
134 | } | 134 | } |
135 | 135 | ||
136 | void KDGanttSplitterHandle::updateCursor( const QPoint& p) | 136 | void KDGanttSplitterHandle::updateCursor( const QPoint& p) |
137 | { | 137 | { |
138 | if ( onButton( p ) != 0 ) { | 138 | if ( onButton( p ) != 0 ) { |
139 | setCursor( arrowCursor ); | 139 | setCursor( arrowCursor ); |
140 | } | 140 | } |
141 | else { | 141 | else { |
142 | if ( orient == KDGanttMinimizeSplitter::Horizontal ) | 142 | if ( orient == KDGanttMinimizeSplitter::Horizontal ) |
143 | setCursor( splitHCursor ); | 143 | setCursor( splitHCursor ); |
144 | else | 144 | else |
145 | setCursor( splitVCursor ); | 145 | setCursor( splitVCursor ); |
146 | } | 146 | } |
147 | } | 147 | } |
148 | void KDGanttSplitterHandle::toggle() | 148 | void KDGanttSplitterHandle::toggle() |
149 | { | 149 | { |
150 | int pos; | 150 | int pos; |
151 | int min, max; | 151 | int min, max; |
152 | if ( !_collapsed ) { | 152 | if ( !_collapsed ) { |
153 | s->expandPos( id(), &min, &max ); | 153 | s->expandPos( id(), &min, &max ); |
154 | if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left | 154 | if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left |
155 | || s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) { | 155 | || s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) { |
156 | pos = min; | 156 | pos = min; |
157 | } | 157 | } |
158 | else { | 158 | else { |
159 | pos = max; | 159 | pos = max; |
160 | } | 160 | } |
161 | 161 | ||
162 | _origPos = s->pick(mapToParent( QPoint( 0,0 ) )); | 162 | _origPos = s->pick(mapToParent( QPoint( 0,0 ) )); |
163 | s->moveSplitter( pos, id() ); | 163 | s->moveSplitter( pos, id() ); |
164 | _collapsed = true; | 164 | _collapsed = true; |
165 | } | 165 | } |
166 | else { | 166 | else { |
167 | s->moveSplitter( _origPos, id() ); | 167 | s->moveSplitter( _origPos, id() ); |
168 | _collapsed = false; | 168 | _collapsed = false; |
169 | } | 169 | } |
170 | repaint(); | 170 | repaint(); |
171 | } | 171 | } |
172 | 172 | ||
173 | void KDGanttSplitterHandle::mouseReleaseEvent( QMouseEvent *e ) | 173 | void KDGanttSplitterHandle::mouseReleaseEvent( QMouseEvent *e ) |
174 | { | 174 | { |
175 | mMouseDown = false; | 175 | mMouseDown = false; |
176 | if ( _activeButton != 0 ) { | 176 | if ( _activeButton != 0 ) { |
177 | if ( onButton( e->pos() ) == _activeButton ) | 177 | if ( onButton( e->pos() ) == _activeButton ) |
178 | { | 178 | { |
179 | toggle(); | 179 | toggle(); |
180 | } | 180 | } |
181 | _activeButton = 0; | 181 | _activeButton = 0; |
182 | updateCursor( e->pos() ); | 182 | updateCursor( e->pos() ); |
183 | } | 183 | } |
184 | else { | 184 | else { |
185 | if ( !opaque() && e->button() == LeftButton ) { | 185 | if ( !opaque() && e->button() == LeftButton ) { |
186 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) | 186 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) |
187 | - mouseOffset; | 187 | - mouseOffset; |
188 | s->setRubberband( -1 ); | 188 | s->setRubberband( -1 ); |
189 | s->moveSplitter( pos, id() ); | 189 | s->moveSplitter( pos, id() ); |
190 | } | 190 | } |
191 | } | 191 | } |
192 | repaint(); | 192 | repaint(); |
193 | } | 193 | } |
194 | 194 | ||
195 | int KDGanttSplitterHandle::onButton( const QPoint& p ) | 195 | int KDGanttSplitterHandle::onButton( const QPoint& p ) |
196 | { | 196 | { |
197 | QValueList<QPointArray> list = buttonRegions(); | 197 | QValueList<QPointArray> list = buttonRegions(); |
198 | int index = 1; | 198 | int index = 1; |
199 | int add = 12; | 199 | int add = 12; |
200 | for( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { | 200 | for( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { |
201 | QRect rect = (*it).boundingRect(); | 201 | QRect rect = (*it).boundingRect(); |
202 | rect.setLeft( rect.left()- add ); | 202 | rect.setLeft( rect.left()- add ); |
203 | rect.setRight( rect.right() + add); | 203 | rect.setRight( rect.right() + add); |
204 | rect.setTop( rect.top()- add ); | 204 | rect.setTop( rect.top()- add ); |
205 | rect.setBottom( rect.bottom() + add); | 205 | rect.setBottom( rect.bottom() + add); |
206 | if ( rect.contains( p ) ) { | 206 | if ( rect.contains( p ) ) { |
207 | return index; | 207 | return index; |
208 | } | 208 | } |
209 | index++; | 209 | index++; |
210 | } | 210 | } |
211 | return 0; | 211 | return 0; |
212 | } | 212 | } |
213 | 213 | ||
214 | 214 | ||
215 | QValueList<QPointArray> KDGanttSplitterHandle::buttonRegions() | 215 | QValueList<QPointArray> KDGanttSplitterHandle::buttonRegions() |
216 | { | 216 | { |
217 | QValueList<QPointArray> list; | 217 | QValueList<QPointArray> list; |
218 | 218 | ||
219 | int sw = 8; | 219 | int sw = 8; |
220 | int yyy = 1; | 220 | int yyy = 1; |
221 | int xxx = 1; | 221 | int xxx = 1; |
222 | int voffset[] = { (int) -sw*3, (int) sw*3 }; | 222 | int voffset[] = { (int) -sw*3, (int) sw*3 }; |
223 | for ( int i = 0; i < 2; i++ ) { | 223 | for ( int i = 0; i < 2; i++ ) { |
224 | QPointArray arr; | 224 | QPointArray arr; |
225 | if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right || | 225 | if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right || |
226 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left) { | 226 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left) { |
227 | int mid = height()/2 + voffset[i]; | 227 | int mid = height()/2 + voffset[i]; |
228 | arr.setPoints( 3, | 228 | arr.setPoints( 3, |
229 | 1-xxx, mid - sw + 4, | 229 | 1-xxx, mid - sw + 4, |
230 | sw-3-xxx, mid, | 230 | sw-3-xxx, mid, |
231 | 1-xxx, mid + sw -4); | 231 | 1-xxx, mid + sw -4); |
232 | } | 232 | } |
233 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left || | 233 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left || |
234 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) { | 234 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) { |
235 | int mid = height()/2 + voffset[i]; | 235 | int mid = height()/2 + voffset[i]; |
236 | arr.setPoints( 3, | 236 | arr.setPoints( 3, |
237 | sw-4, mid - sw + 4, | 237 | sw-4, mid - sw + 4, |
238 | 0, mid, | 238 | 0, mid, |
239 | sw-4, mid + sw - 4); | 239 | sw-4, mid + sw - 4); |
240 | } | 240 | } |
241 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up || | 241 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up || |
242 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down) { | 242 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down) { |
243 | int mid = width()/2 + voffset[i]; | 243 | int mid = width()/2 + voffset[i]; |
244 | arr.setPoints( 3, | 244 | arr.setPoints( 3, |
245 | mid - sw + 4, sw-4, | 245 | mid - sw + 4, sw-4, |
246 | mid, 0, | 246 | mid, 0, |
247 | mid + sw - 4, sw-4 ); | 247 | mid + sw - 4, sw-4 ); |
248 | } | 248 | } |
249 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down || | 249 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down || |
250 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) { | 250 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) { |
251 | int mid = width()/2 + voffset[i]; | 251 | int mid = width()/2 + voffset[i]; |
252 | arr.setPoints( 3, | 252 | arr.setPoints( 3, |
253 | mid - sw + 4, 1-yyy, | 253 | mid - sw + 4, 1-yyy, |
254 | mid, sw-3-yyy, | 254 | mid, sw-3-yyy, |
255 | mid + sw -4, 1-yyy); | 255 | mid + sw -4, 1-yyy); |
256 | } | 256 | } |
257 | list.append( arr ); | 257 | list.append( arr ); |
258 | } | 258 | } |
259 | return list; | 259 | return list; |
260 | } | 260 | } |
261 | 261 | ||
262 | void KDGanttSplitterHandle::paintEvent( QPaintEvent * ) | 262 | void KDGanttSplitterHandle::paintEvent( QPaintEvent * ) |
263 | { | 263 | { |
264 | QPixmap buffer( size() ); | 264 | QPixmap buffer( size() ); |
265 | QPainter p( &buffer ); | 265 | QPainter p( &buffer ); |
266 | 266 | ||
267 | //LR | 267 | //LR |
268 | // Draw the splitter rectangle | 268 | // Draw the splitter rectangle |
269 | p.setBrush( colorGroup().background() ); | 269 | p.setBrush( colorGroup().background() ); |
270 | p.setPen( colorGroup().foreground() ); | 270 | p.setPen( colorGroup().foreground() ); |
271 | //p.drawRect( rect() ); | 271 | //p.drawRect( rect() ); |
272 | buffer.fill( colorGroup().background() ); | 272 | buffer.fill( colorGroup().background() ); |
273 | //buffer.fill( backgroundColor() ); | 273 | //buffer.fill( backgroundColor() ); |
274 | // parentWidget()->style().drawPrimitive( QStyle::PE_Panel, &p, rect(), parentWidget()->colorGroup()); | 274 | // parentWidget()->style().drawPrimitive( QStyle::PE_Panel, &p, rect(), parentWidget()->colorGroup()); |
275 | 275 | ||
276 | int sw = 8; // Hardcoded, given I didn't use styles anymore, I didn't like to use their size | 276 | int sw = 8; // Hardcoded, given I didn't use styles anymore, I didn't like to use their size |
277 | 277 | ||
278 | // arrow color | 278 | // arrow color |
279 | QColor col; | 279 | QColor col; |
280 | if ( _activeButton ) | 280 | if ( _activeButton ) |
281 | col = colorGroup().background().dark( 250 ); | 281 | col = colorGroup().background().dark( 250 ); |
282 | else { | 282 | else { |
283 | if ( mMouseDown ) | 283 | if ( mMouseDown ) |
284 | col = Qt::white; | 284 | col = Qt::white; |
285 | else | 285 | else |
286 | col = colorGroup().background().dark( 150 ); | 286 | col = colorGroup().background().dark( 150 ); |
287 | } | 287 | } |
288 | //QColor col = backgroundColor().dark( 130 ); | 288 | //QColor col = backgroundColor().dark( 130 ); |
289 | p.setBrush( col ); | 289 | p.setBrush( col ); |
290 | p.setPen( col ); | 290 | p.setPen( col ); |
291 | 291 | ||
292 | QValueList<QPointArray> list = buttonRegions(); | 292 | QValueList<QPointArray> list = buttonRegions(); |
293 | int index = 1; | 293 | int index = 1; |
294 | if ( mUseOffset ) | 294 | if ( mUseOffset ) |
295 | p.translate( 0, 1 ); | 295 | p.translate( 0, 1 ); |
296 | for ( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { | 296 | for ( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { |
297 | if ( index == _activeButton ) { | 297 | if ( index == _activeButton ) { |
298 | 298 | ||
299 | /* | 299 | /* |
300 | if ( ! _collapsed ) { | 300 | if ( ! _collapsed ) { |
301 | p.save(); | 301 | p.save(); |
302 | // p.translate( parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftHorizontal ), | 302 | // p.translate( parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftHorizontal ), |
303 | // parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftVertical ) ); | 303 | // parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftVertical ) ); |
304 | p.translate( -1, 0 ); | 304 | p.translate( -1, 0 ); |
305 | p.drawPolygon( *it, true ); | 305 | p.drawPolygon( *it, true ); |
306 | p.restore(); } else | 306 | p.restore(); } else |
307 | */ | 307 | */ |
308 | p.drawPolygon( *it, true ); | 308 | p.drawPolygon( *it, true ); |
309 | 309 | ||
310 | } | 310 | } |
311 | else { | 311 | else { |
312 | /* | 312 | /* |
313 | if ( ! _collapsed ) { | 313 | if ( ! _collapsed ) { |
314 | p.save(); | 314 | p.save(); |
315 | p.translate( -1, 0 ); | 315 | p.translate( -1, 0 ); |
316 | p.drawPolygon( *it, true ); | 316 | p.drawPolygon( *it, true ); |
317 | p.restore(); | 317 | p.restore(); |
318 | } else | 318 | } else |
319 | */ | 319 | */ |
320 | p.drawPolygon( *it, true ); | 320 | p.drawPolygon( *it, true ); |
321 | 321 | ||
322 | } | 322 | } |
323 | index++; | 323 | index++; |
324 | } | 324 | } |
325 | 325 | ||
326 | // Draw the lines between the arrows | 326 | // Draw the lines between the arrows |
327 | if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left || | 327 | if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left || |
328 | s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) { | 328 | s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) { |
329 | int mid = height()/2; | 329 | int mid = height()/2; |
330 | p.drawLine ( 1, mid - sw, 1, mid + sw ); | 330 | p.drawLine ( 1, mid - sw, 1, mid + sw ); |
331 | p.drawLine ( 3, mid - sw, 3, mid + sw ); | 331 | p.drawLine ( 3, mid - sw, 3, mid + sw ); |
332 | } | 332 | } |
333 | else if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Up || | 333 | else if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Up || |
334 | s->minimizeDirection() == KDGanttMinimizeSplitter::Down ) { | 334 | s->minimizeDirection() == KDGanttMinimizeSplitter::Down ) { |
335 | int mid = width()/2; | 335 | int mid = width()/2; |
336 | p.drawLine( mid -sw, 1, mid +sw, 1 ); | 336 | p.drawLine( mid -sw, 1, mid +sw, 1 ); |
337 | p.drawLine( mid -sw, 3, mid +sw, 3 ); | 337 | p.drawLine( mid -sw, 3, mid +sw, 3 ); |
338 | } | 338 | } |
339 | bitBlt( this, 0, 0, &buffer ); | 339 | bitBlt( this, 0, 0, &buffer ); |
340 | 340 | ||
341 | } | 341 | } |
342 | #endif | 342 | #endif |
343 | 343 | ||
344 | class QSplitterLayoutStruct | 344 | class QSplitterLayoutStruct |
345 | { | 345 | { |
346 | public: | 346 | public: |
347 | KDGanttMinimizeSplitter::ResizeMode mode; | 347 | KDGanttMinimizeSplitter::ResizeMode mode; |
348 | QCOORD sizer; | 348 | QCOORD sizer; |
349 | bool isSplitter; | 349 | bool isSplitter; |
350 | QWidget *wid; | 350 | QWidget *wid; |
351 | }; | 351 | }; |
352 | 352 | ||
353 | class QSplitterData | 353 | class QSplitterData |
354 | { | 354 | { |
355 | public: | 355 | public: |
356 | QSplitterData() : opaque( FALSE ), firstShow( TRUE ) {} | 356 | QSplitterData() : opaque( FALSE ), firstShow( TRUE ) {} |
357 | 357 | ||
358 | QPtrList<QSplitterLayoutStruct> list; | 358 | QPtrList<QSplitterLayoutStruct> list; |
359 | bool opaque; | 359 | bool opaque; |
360 | bool firstShow; | 360 | bool firstShow; |
361 | }; | 361 | }; |
362 | 362 | ||
363 | void kdganttGeomCalc( QMemArray<QLayoutStruct> &chain, int start, int count, int pos, | 363 | void kdganttGeomCalc( QMemArray<QLayoutStruct> &chain, int start, int count, int pos, |
364 | int space, int spacer ); | 364 | int space, int spacer ); |
365 | #endif // DOXYGEN_SKIP_INTERNAL | 365 | #endif // DOXYGEN_SKIP_INTERNAL |
366 | 366 | ||
367 | 367 | ||
368 | /*! | 368 | /*! |
369 | \class KDGanttMinimizeSplitter KDGanttMinimizeSplitter.h | 369 | \class KDGanttMinimizeSplitter KDGanttMinimizeSplitter.h |
370 | \brief The KDGanttMinimizeSplitter class implements a splitter | 370 | \brief The KDGanttMinimizeSplitter class implements a splitter |
371 | widget with minimize buttons. | 371 | widget with minimize buttons. |
372 | 372 | ||
373 | This class (and its documentation) is largely a copy of Qt's | 373 | This class (and its documentation) is largely a copy of Qt's |
374 | QSplitter; the copying was necessary because QSplitter is not | 374 | QSplitter; the copying was necessary because QSplitter is not |
375 | extensible at all. QSplitter and its documentation are licensed | 375 | extensible at all. QSplitter and its documentation are licensed |
376 | according to the GPL and the Qt Professional License (if you hold | 376 | according to the GPL and the Qt Professional License (if you hold |
377 | such a license) and are (C) Trolltech AS. | 377 | such a license) and are (C) Trolltech AS. |
378 | 378 | ||
379 | A splitter lets the user control the size of child widgets by | 379 | A splitter lets the user control the size of child widgets by |
380 | dragging the boundary between the children. Any number of widgets | 380 | dragging the boundary between the children. Any number of widgets |
381 | may be controlled. | 381 | may be controlled. |
382 | 382 | ||
383 | To show a QListBox, a QListView and a QTextEdit side by side: | 383 | To show a QListBox, a QListView and a QTextEdit side by side: |
384 | 384 | ||
385 | \code | 385 | \code |
386 | KDGanttMinimizeSplitter *split = new KDGanttMinimizeSplitter( parent ); | 386 | KDGanttMinimizeSplitter *split = new KDGanttMinimizeSplitter( parent ); |
387 | QListBox *lb = new QListBox( split ); | 387 | QListBox *lb = new QListBox( split ); |
388 | QListView *lv = new QListView( split ); | 388 | QListView *lv = new QListView( split ); |
389 | QTextEdit *ed = new QTextEdit( split ); | 389 | QTextEdit *ed = new QTextEdit( split ); |
390 | \endcode | 390 | \endcode |
391 | 391 | ||
392 | In KDGanttMinimizeSplitter, the boundary can be either horizontal or | 392 | In KDGanttMinimizeSplitter, the boundary can be either horizontal or |
393 | vertical. The default is horizontal (the children are side by side) | 393 | vertical. The default is horizontal (the children are side by side) |
394 | but you can use setOrientation( QSplitter::Vertical ) to set it to | 394 | but you can use setOrientation( QSplitter::Vertical ) to set it to |
395 | vertical. | 395 | vertical. |
396 | 396 | ||
397 | Use setResizeMode() to specify | 397 | Use setResizeMode() to specify |
398 | that a widget should keep its size when the splitter is resized. | 398 | that a widget should keep its size when the splitter is resized. |
399 | 399 | ||
400 | Although KDGanttMinimizeSplitter normally resizes the children only | 400 | Although KDGanttMinimizeSplitter normally resizes the children only |
401 | at the end of a resize operation, if you call setOpaqueResize( TRUE | 401 | at the end of a resize operation, if you call setOpaqueResize( TRUE |
402 | ) the widgets are resized as often as possible. | 402 | ) the widgets are resized as often as possible. |
403 | 403 | ||
404 | The initial distribution of size between the widgets is determined | 404 | The initial distribution of size between the widgets is determined |
405 | by the initial size of each widget. You can also use setSizes() to | 405 | by the initial size of each widget. You can also use setSizes() to |
406 | set the sizes of all the widgets. The function sizes() returns the | 406 | set the sizes of all the widgets. The function sizes() returns the |
407 | sizes set by the user. | 407 | sizes set by the user. |
408 | 408 | ||
409 | If you hide() a child, its space will be distributed among the other | 409 | If you hide() a child, its space will be distributed among the other |
410 | children. It will be reinstated when you show() it again. It is also | 410 | children. It will be reinstated when you show() it again. It is also |
411 | possible to reorder the widgets within the splitter using | 411 | possible to reorder the widgets within the splitter using |
412 | moveToFirst() and moveToLast(). | 412 | moveToFirst() and moveToLast(). |
413 | */ | 413 | */ |
414 | 414 | ||
415 | 415 | ||
416 | 416 | ||
417 | static QSize minSize( const QWidget* /*w*/ ) | 417 | static QSize minSize( const QWidget* /*w*/ ) |
418 | { | 418 | { |
419 | return QSize(0,0); | 419 | return QSize(0,0); |
420 | } | 420 | } |
421 | 421 | ||
422 | // This is the original version of minSize | 422 | // This is the original version of minSize |
423 | static QSize minSizeHint( const QWidget* w ) | 423 | static QSize minSizeHint( const QWidget* w ) |
424 | { | 424 | { |
425 | QSize min = w->minimumSize(); | 425 | QSize min = w->minimumSize(); |
426 | QSize s; | 426 | QSize s; |
427 | if ( min.height() <= 0 || min.width() <= 0 ) | 427 | if ( min.height() <= 0 || min.width() <= 0 ) |
428 | s = w->minimumSizeHint(); | 428 | s = w->minimumSizeHint(); |
429 | if ( min.height() > 0 ) | 429 | if ( min.height() > 0 ) |
430 | s.setHeight( min.height() ); | 430 | s.setHeight( min.height() ); |
431 | if ( min.width() > 0 ) | 431 | if ( min.width() > 0 ) |
432 | s.setWidth( min.width() ); | 432 | s.setWidth( min.width() ); |
433 | return s.expandedTo(QSize(0,0)); | 433 | return s.expandedTo(QSize(0,0)); |
434 | } | 434 | } |
435 | 435 | ||
436 | 436 | ||
437 | 437 | ||
438 | /*! | 438 | /*! |
439 | Constructs a horizontal splitter with the \a parent and \a | 439 | Constructs a horizontal splitter with the \a parent and \a |
440 | name arguments being passed on to the QFrame constructor. | 440 | name arguments being passed on to the QFrame constructor. |
441 | */ | 441 | */ |
442 | KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( QWidget *parent, const char *name ) | 442 | KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( QWidget *parent, const char *name ) |
443 | :QFrame(parent,name,WPaintUnclipped) | 443 | :QFrame(parent,name,WPaintUnclipped) |
444 | { | 444 | { |
445 | mFirstHandle = 0; | 445 | mFirstHandle = 0; |
446 | #if QT_VERSION >= 232 | 446 | #if QT_VERSION >= 232 |
447 | orient = Horizontal; | 447 | orient = Horizontal; |
448 | init(); | 448 | init(); |
449 | #endif | 449 | #endif |
450 | } | 450 | } |
451 | 451 | ||
452 | /*! | 452 | /*! |
453 | Constructs a splitter with orientation \a o with the \a parent | 453 | Constructs a splitter with orientation \a o with the \a parent |
454 | and \a name arguments being passed on to the QFrame constructor. | 454 | and \a name arguments being passed on to the QFrame constructor. |
455 | */ | 455 | */ |
456 | KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( Orientation o, QWidget *parent, const char *name ) | 456 | KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( Orientation o, QWidget *parent, const char *name ) |
457 | :QFrame(parent,name,WPaintUnclipped) | 457 | :QFrame(parent,name,WPaintUnclipped) |
458 | { | 458 | { |
459 | mFirstHandle = 0; | 459 | mFirstHandle = 0; |
460 | #if QT_VERSION >= 232 | 460 | #if QT_VERSION >= 232 |
461 | orient = o; | 461 | orient = o; |
462 | init(); | 462 | init(); |
463 | #endif | 463 | #endif |
464 | } | 464 | } |
465 | 465 | ||
466 | /*! | 466 | /*! |
467 | Destroys the splitter and any children. | 467 | Destroys the splitter and any children. |
468 | */ | 468 | */ |
469 | KDGanttMinimizeSplitter::~KDGanttMinimizeSplitter() | 469 | KDGanttMinimizeSplitter::~KDGanttMinimizeSplitter() |
470 | { | 470 | { |
471 | #if QT_VERSION >= 232 | 471 | #if QT_VERSION >= 232 |
472 | data->list.setAutoDelete( TRUE ); | 472 | data->list.setAutoDelete( TRUE ); |
473 | delete data; | 473 | delete data; |
474 | #endif | 474 | #endif |
475 | } | 475 | } |
476 | 476 | ||
477 | 477 | ||
478 | #if QT_VERSION >= 232 | 478 | #if QT_VERSION >= 232 |
479 | void KDGanttMinimizeSplitter::init() | 479 | void KDGanttMinimizeSplitter::init() |
480 | { | 480 | { |
481 | data = new QSplitterData; | 481 | data = new QSplitterData; |
482 | if ( orient == Horizontal ) | 482 | if ( orient == Horizontal ) |
483 | setSizePolicy( QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum) ); | 483 | setSizePolicy( QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum) ); |
484 | else | 484 | else |
485 | setSizePolicy( QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Expanding) ); | 485 | setSizePolicy( QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Expanding) ); |
486 | #ifndef DESKTOP_VERSION | ||
487 | setOpaqueResize( false ); | ||
488 | #else | ||
489 | setOpaqueResize( true ); | ||
490 | #endif | ||
486 | } | 491 | } |
487 | #endif | 492 | #endif |
488 | 493 | ||
489 | 494 | ||
490 | void KDGanttMinimizeSplitter::toggle() | 495 | void KDGanttMinimizeSplitter::toggle() |
491 | { | 496 | { |
492 | if ( mFirstHandle ) | 497 | if ( mFirstHandle ) |
493 | mFirstHandle->toggle(); | 498 | mFirstHandle->toggle(); |
494 | else | 499 | else |
495 | qDebug("KDGanttMinimizeSplitter::toggle::sorry, handle not available "); | 500 | qDebug("KDGanttMinimizeSplitter::toggle::sorry, handle not available "); |
496 | 501 | ||
497 | } | 502 | } |
498 | 503 | ||
499 | 504 | ||
500 | /*! | 505 | /*! |
501 | \brief the orientation of the splitter | 506 | \brief the orientation of the splitter |
502 | 507 | ||
503 | By default the orientation is horizontal (the widgets are side by side). | 508 | By default the orientation is horizontal (the widgets are side by side). |
504 | The possible orientations are Qt:Vertical and Qt::Horizontal (the default). | 509 | The possible orientations are Qt:Vertical and Qt::Horizontal (the default). |
505 | */ | 510 | */ |
506 | void KDGanttMinimizeSplitter::setOrientation( Orientation o ) | 511 | void KDGanttMinimizeSplitter::setOrientation( Orientation o ) |
507 | { | 512 | { |
508 | #if QT_VERSION >= 232 | 513 | #if QT_VERSION >= 232 |
509 | if ( orient == o ) | 514 | if ( orient == o ) |
510 | return; | 515 | return; |
511 | orient = o; | 516 | orient = o; |
512 | 517 | ||
513 | if ( orient == Horizontal ) | 518 | if ( orient == Horizontal ) |
514 | setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); | 519 | setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); |
515 | else | 520 | else |
516 | setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); | 521 | setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); |
517 | 522 | ||
518 | QSplitterLayoutStruct *s = data->list.first(); | 523 | QSplitterLayoutStruct *s = data->list.first(); |
519 | while ( s ) { | 524 | while ( s ) { |
520 | if ( s->isSplitter ) | 525 | if ( s->isSplitter ) |
521 | ((KDGanttSplitterHandle*)s->wid)->setOrientation( o ); | 526 | ((KDGanttSplitterHandle*)s->wid)->setOrientation( o ); |
522 | s = data->list.next(); // ### next at end of loop, no iterator | 527 | s = data->list.next(); // ### next at end of loop, no iterator |
523 | } | 528 | } |
524 | recalc( isVisible() ); | 529 | recalc( isVisible() ); |
525 | #endif | 530 | #endif |
526 | } | 531 | } |
527 | 532 | ||
528 | 533 | ||
529 | #if QT_VERSION >= 232 | 534 | #if QT_VERSION >= 232 |
530 | /*! | 535 | /*! |
531 | \reimp | 536 | \reimp |
532 | */ | 537 | */ |
533 | void KDGanttMinimizeSplitter::resizeEvent( QResizeEvent * ) | 538 | void KDGanttMinimizeSplitter::resizeEvent( QResizeEvent * ) |
534 | { | 539 | { |
535 | doResize(); | 540 | doResize(); |
536 | } | 541 | } |
537 | 542 | ||
538 | 543 | ||
539 | /* | 544 | /* |
540 | Inserts the widget \a w at the end (or at the beginning if \a first | 545 | Inserts the widget \a w at the end (or at the beginning if \a first |
541 | is TRUE) of the splitter's list of widgets. | 546 | is TRUE) of the splitter's list of widgets. |
542 | 547 | ||
543 | It is the responsibility of the caller of this function to make sure | 548 | It is the responsibility of the caller of this function to make sure |
544 | that \a w is not already in the splitter and to call recalcId if | 549 | that \a w is not already in the splitter and to call recalcId if |
545 | needed. (If \a first is TRUE, then recalcId is very probably | 550 | needed. (If \a first is TRUE, then recalcId is very probably |
546 | needed.) | 551 | needed.) |
547 | */ | 552 | */ |
548 | QSplitterLayoutStruct *KDGanttMinimizeSplitter::addWidget( QWidget *w, bool first ) | 553 | QSplitterLayoutStruct *KDGanttMinimizeSplitter::addWidget( QWidget *w, bool first ) |
549 | { | 554 | { |
550 | QSplitterLayoutStruct *s; | 555 | QSplitterLayoutStruct *s; |
551 | KDGanttSplitterHandle *newHandle = 0; | 556 | KDGanttSplitterHandle *newHandle = 0; |
552 | if ( data->list.count() > 0 ) { | 557 | if ( data->list.count() > 0 ) { |
553 | s = new QSplitterLayoutStruct; | 558 | s = new QSplitterLayoutStruct; |
554 | s->mode = KeepSize; | 559 | s->mode = KeepSize; |
555 | QString tmp = "qt_splithandle_"; | 560 | QString tmp = "qt_splithandle_"; |
556 | tmp += w->name(); | 561 | tmp += w->name(); |
557 | newHandle = new KDGanttSplitterHandle( orientation(), this, tmp.latin1() ); | 562 | newHandle = new KDGanttSplitterHandle( orientation(), this, tmp.latin1() ); |
558 | if ( ! mFirstHandle ) | 563 | if ( ! mFirstHandle ) |
559 | mFirstHandle = newHandle; | 564 | mFirstHandle = newHandle; |
560 | s->wid = newHandle; | 565 | s->wid = newHandle; |
561 | newHandle->setId(data->list.count()); | 566 | newHandle->setId(data->list.count()); |
562 | s->isSplitter = TRUE; | 567 | s->isSplitter = TRUE; |
563 | s->sizer = pick( newHandle->sizeHint() ); | 568 | s->sizer = pick( newHandle->sizeHint() ); |
564 | if ( first ) | 569 | if ( first ) |
565 | data->list.insert( 0, s ); | 570 | data->list.insert( 0, s ); |
566 | else | 571 | else |
567 | data->list.append( s ); | 572 | data->list.append( s ); |
568 | } | 573 | } |
569 | s = new QSplitterLayoutStruct; | 574 | s = new QSplitterLayoutStruct; |
570 | s->mode = Stretch; | 575 | s->mode = Stretch; |
571 | s->wid = w; | 576 | s->wid = w; |
572 | if ( !testWState( WState_Resized ) && w->sizeHint().isValid() ) | 577 | if ( !testWState( WState_Resized ) && w->sizeHint().isValid() ) |
573 | s->sizer = pick( w->sizeHint() ); | 578 | s->sizer = pick( w->sizeHint() ); |
574 | else | 579 | else |
575 | s->sizer = pick( w->size() ); | 580 | s->sizer = pick( w->size() ); |
576 | s->isSplitter = FALSE; | 581 | s->isSplitter = FALSE; |
577 | if ( first ) | 582 | if ( first ) |
578 | data->list.insert( 0, s ); | 583 | data->list.insert( 0, s ); |
579 | else | 584 | else |
580 | data->list.append( s ); | 585 | data->list.append( s ); |
581 | if ( newHandle && isVisible() ) | 586 | if ( newHandle && isVisible() ) |
582 | newHandle->show(); //will trigger sending of post events | 587 | newHandle->show(); //will trigger sending of post events |
583 | return s; | 588 | return s; |
584 | } | 589 | } |
585 | 590 | ||
586 | 591 | ||
587 | /*! | 592 | /*! |
588 | Tells the splitter that a child widget has been inserted or removed. | 593 | Tells the splitter that a child widget has been inserted or removed. |
589 | The event is passed in \a c. | 594 | The event is passed in \a c. |
590 | */ | 595 | */ |
591 | void KDGanttMinimizeSplitter::childEvent( QChildEvent *c ) | 596 | void KDGanttMinimizeSplitter::childEvent( QChildEvent *c ) |
592 | { | 597 | { |
593 | if ( c->type() == QEvent::ChildInserted ) { | 598 | if ( c->type() == QEvent::ChildInserted ) { |
594 | if ( !c->child()->isWidgetType() ) | 599 | if ( !c->child()->isWidgetType() ) |
595 | return; | 600 | return; |
596 | 601 | ||
597 | if ( ((QWidget*)c->child())->testWFlags( WType_TopLevel ) ) | 602 | if ( ((QWidget*)c->child())->testWFlags( WType_TopLevel ) ) |
598 | return; | 603 | return; |
599 | 604 | ||
600 | QSplitterLayoutStruct *s = data->list.first(); | 605 | QSplitterLayoutStruct *s = data->list.first(); |
601 | while ( s ) { | 606 | while ( s ) { |
602 | if ( s->wid == c->child() ) | 607 | if ( s->wid == c->child() ) |
603 | return; | 608 | return; |
604 | s = data->list.next(); | 609 | s = data->list.next(); |
605 | } | 610 | } |
606 | addWidget( (QWidget*)c->child() ); | 611 | addWidget( (QWidget*)c->child() ); |
607 | recalc( isVisible() ); | 612 | recalc( isVisible() ); |
608 | 613 | ||
609 | } else if ( c->type() == QEvent::ChildRemoved ) { | 614 | } else if ( c->type() == QEvent::ChildRemoved ) { |
610 | QSplitterLayoutStruct *p = 0; | 615 | QSplitterLayoutStruct *p = 0; |
611 | if ( data->list.count() > 1 ) | 616 | if ( data->list.count() > 1 ) |
612 | p = data->list.at(1); //remove handle _after_ first widget. | 617 | p = data->list.at(1); //remove handle _after_ first widget. |
613 | QSplitterLayoutStruct *s = data->list.first(); | 618 | QSplitterLayoutStruct *s = data->list.first(); |
614 | while ( s ) { | 619 | while ( s ) { |
615 | if ( s->wid == c->child() ) { | 620 | if ( s->wid == c->child() ) { |
616 | data->list.removeRef( s ); | 621 | data->list.removeRef( s ); |
617 | delete s; | 622 | delete s; |
618 | if ( p && p->isSplitter ) { | 623 | if ( p && p->isSplitter ) { |
619 | data->list.removeRef( p ); | 624 | data->list.removeRef( p ); |
620 | delete p->wid; //will call childEvent | 625 | delete p->wid; //will call childEvent |
621 | delete p; | 626 | delete p; |
622 | } | 627 | } |
623 | recalcId(); | 628 | recalcId(); |
624 | doResize(); | 629 | doResize(); |
625 | return; | 630 | return; |
626 | } | 631 | } |
627 | p = s; | 632 | p = s; |
628 | s = data->list.next(); | 633 | s = data->list.next(); |
629 | } | 634 | } |
630 | } | 635 | } |
631 | } | 636 | } |
632 | 637 | ||
633 | 638 | ||
634 | /*! | 639 | /*! |
635 | Shows a rubber band at position \a p. If \a p is negative, the | 640 | Shows a rubber band at position \a p. If \a p is negative, the |
636 | rubber band is removed. | 641 | rubber band is removed. |
637 | */ | 642 | */ |
638 | void KDGanttMinimizeSplitter::setRubberband( int p ) | 643 | void KDGanttMinimizeSplitter::setRubberband( int p ) |
639 | { | 644 | { |
640 | QPainter paint( this ); | 645 | QPainter paint( this ); |
641 | paint.setPen( gray ); | 646 | paint.setPen( gray ); |
642 | paint.setBrush( gray ); | 647 | paint.setBrush( gray ); |
643 | paint.setRasterOp( XorROP ); | 648 | paint.setRasterOp( XorROP ); |
644 | QRect r = contentsRect(); | 649 | QRect r = contentsRect(); |
645 | const int rBord = 3; //Themable???? | 650 | const int rBord = 3; //Themable???? |
646 | #if QT_VERSION >= 0x030000 | 651 | #if QT_VERSION >= 0x030000 |
647 | int sw = style().pixelMetric(QStyle::PM_SplitterWidth, this); | 652 | int sw = style().pixelMetric(QStyle::PM_SplitterWidth, this); |
648 | #else | 653 | #else |
649 | int sw = style().splitterWidth(); | 654 | int sw = style().splitterWidth(); |
650 | #endif | 655 | #endif |
651 | if ( orient == Horizontal ) { | 656 | if ( orient == Horizontal ) { |
652 | if ( opaqueOldPos >= 0 ) | 657 | if ( opaqueOldPos >= 0 ) |
653 | paint.drawRect( opaqueOldPos + sw/2 - rBord , r.y(), | 658 | paint.drawRect( opaqueOldPos + sw/2 - rBord , r.y(), |
654 | 2*rBord, r.height() ); | 659 | 2*rBord, r.height() ); |
655 | if ( p >= 0 ) | 660 | if ( p >= 0 ) |
656 | paint.drawRect( p + sw/2 - rBord, r.y(), 2*rBord, r.height() ); | 661 | paint.drawRect( p + sw/2 - rBord, r.y(), 2*rBord, r.height() ); |
657 | } else { | 662 | } else { |
658 | if ( opaqueOldPos >= 0 ) | 663 | if ( opaqueOldPos >= 0 ) |
659 | paint.drawRect( r.x(), opaqueOldPos + sw/2 - rBord, | 664 | paint.drawRect( r.x(), opaqueOldPos + sw/2 - rBord, |
660 | r.width(), 2*rBord ); | 665 | r.width(), 2*rBord ); |
661 | if ( p >= 0 ) | 666 | if ( p >= 0 ) |
662 | paint.drawRect( r.x(), p + sw/2 - rBord, r.width(), 2*rBord ); | 667 | paint.drawRect( r.x(), p + sw/2 - rBord, r.width(), 2*rBord ); |
663 | } | 668 | } |
664 | opaqueOldPos = p; | 669 | opaqueOldPos = p; |
665 | } | 670 | } |
666 | 671 | ||
667 | 672 | ||
668 | /*! \reimp */ | 673 | /*! \reimp */ |
669 | bool KDGanttMinimizeSplitter::event( QEvent *e ) | 674 | bool KDGanttMinimizeSplitter::event( QEvent *e ) |
670 | { | 675 | { |
671 | if ( e->type() == QEvent::LayoutHint || ( e->type() == QEvent::Show && data->firstShow ) ) { | 676 | if ( e->type() == QEvent::LayoutHint || ( e->type() == QEvent::Show && data->firstShow ) ) { |
672 | recalc( isVisible() ); | 677 | recalc( isVisible() ); |
673 | if ( e->type() == QEvent::Show ) | 678 | if ( e->type() == QEvent::Show ) |
674 | data->firstShow = FALSE; | 679 | data->firstShow = FALSE; |
675 | } | 680 | } |
676 | return QWidget::event( e ); | 681 | return QWidget::event( e ); |
677 | } | 682 | } |
678 | 683 | ||
679 | 684 | ||
680 | /*! | 685 | /*! |
681 | \obsolete | 686 | \obsolete |
682 | 687 | ||
683 | Draws the splitter handle in the rectangle described by \a x, \a y, | 688 | Draws the splitter handle in the rectangle described by \a x, \a y, |
684 | \a w, \a h using painter \a p. | 689 | \a w, \a h using painter \a p. |
685 | \sa QStyle::drawPrimitive() | 690 | \sa QStyle::drawPrimitive() |
686 | */ | 691 | */ |
687 | void KDGanttMinimizeSplitter::drawSplitter( QPainter *p, | 692 | void KDGanttMinimizeSplitter::drawSplitter( QPainter *p, |
688 | QCOORD x, QCOORD y, QCOORD w, QCOORD h ) | 693 | QCOORD x, QCOORD y, QCOORD w, QCOORD h ) |
689 | { | 694 | { |
690 | #if 0 | 695 | #if 0 |
691 | // LR | 696 | // LR |
692 | style().drawPrimitive(QStyle::PE_Splitter, p, QRect(x, y, w, h), colorGroup(), | 697 | style().drawPrimitive(QStyle::PE_Splitter, p, QRect(x, y, w, h), colorGroup(), |
693 | (orientation() == Qt::Horizontal ? | 698 | (orientation() == Qt::Horizontal ? |
694 | QStyle::Style_Horizontal : 0)); | 699 | QStyle::Style_Horizontal : 0)); |
695 | #endif | 700 | #endif |
696 | } | 701 | } |
697 | 702 | ||
698 | 703 | ||
699 | /*! | 704 | /*! |
700 | Returns the id of the splitter to the right of or below the widget \a w, | 705 | Returns the id of the splitter to the right of or below the widget \a w, |
701 | or 0 if there is no such splitter | 706 | or 0 if there is no such splitter |
702 | (i.e. it is either not in this KDGanttMinimizeSplitter or it is at the end). | 707 | (i.e. it is either not in this KDGanttMinimizeSplitter or it is at the end). |
703 | */ | 708 | */ |
704 | int KDGanttMinimizeSplitter::idAfter( QWidget* w ) const | 709 | int KDGanttMinimizeSplitter::idAfter( QWidget* w ) const |
705 | { | 710 | { |
706 | QSplitterLayoutStruct *s = data->list.first(); | 711 | QSplitterLayoutStruct *s = data->list.first(); |
707 | bool seen_w = FALSE; | 712 | bool seen_w = FALSE; |
708 | while ( s ) { | 713 | while ( s ) { |
709 | if ( s->isSplitter && seen_w ) | 714 | if ( s->isSplitter && seen_w ) |
710 | return data->list.at(); | 715 | return data->list.at(); |
711 | if ( !s->isSplitter && s->wid == w ) | 716 | if ( !s->isSplitter && s->wid == w ) |
712 | seen_w = TRUE; | 717 | seen_w = TRUE; |
713 | s = data->list.next(); | 718 | s = data->list.next(); |
714 | } | 719 | } |
715 | return 0; | 720 | return 0; |
716 | } | 721 | } |
717 | 722 | ||
718 | 723 | ||
719 | /*! | 724 | /*! |
720 | Moves the left/top edge of the splitter handle with id \a id as | 725 | Moves the left/top edge of the splitter handle with id \a id as |
721 | close as possible to position \a p, which is the distance from the | 726 | close as possible to position \a p, which is the distance from the |
722 | left (or top) edge of the widget. | 727 | left (or top) edge of the widget. |
723 | 728 | ||
724 | For Arabic and Hebrew the layout is reversed, and using this | 729 | For Arabic and Hebrew the layout is reversed, and using this |
725 | function to set the position of the splitter might lead to | 730 | function to set the position of the splitter might lead to |
726 | unexpected results, since in Arabic and Hebrew the position of | 731 | unexpected results, since in Arabic and Hebrew the position of |
727 | splitter one is to the left of the position of splitter zero. | 732 | splitter one is to the left of the position of splitter zero. |
728 | 733 | ||
729 | \sa idAfter() | 734 | \sa idAfter() |
730 | */ | 735 | */ |
731 | void KDGanttMinimizeSplitter::moveSplitter( QCOORD p, int id ) | 736 | void KDGanttMinimizeSplitter::moveSplitter( QCOORD p, int id ) |
732 | { | 737 | { |
733 | p = adjustPos( p, id ); | 738 | p = adjustPos( p, id ); |
734 | QSplitterLayoutStruct *s = data->list.at(id); | 739 | QSplitterLayoutStruct *s = data->list.at(id); |
735 | int oldP = orient == Horizontal ? s->wid->x() : s->wid->y(); | 740 | int oldP = orient == Horizontal ? s->wid->x() : s->wid->y(); |
736 | bool upLeft; | 741 | bool upLeft; |
737 | if ( false && orient == Horizontal ) { | 742 | if ( false && orient == Horizontal ) { |
738 | p += s->wid->width(); | 743 | p += s->wid->width(); |
739 | upLeft = p > oldP; | 744 | upLeft = p > oldP; |
740 | } else | 745 | } else |
741 | upLeft = p < oldP; | 746 | upLeft = p < oldP; |
742 | 747 | ||
743 | moveAfter( p, id, upLeft ); | 748 | moveAfter( p, id, upLeft ); |
744 | moveBefore( p-1, id-1, upLeft ); | 749 | moveBefore( p-1, id-1, upLeft ); |
745 | 750 | ||
746 | storeSizes(); | 751 | storeSizes(); |
747 | } | 752 | } |
748 | 753 | ||
749 | 754 | ||
750 | void KDGanttMinimizeSplitter::setG( QWidget *w, int p, int s, bool isSplitter ) | 755 | void KDGanttMinimizeSplitter::setG( QWidget *w, int p, int s, bool isSplitter ) |
751 | { | 756 | { |
752 | if ( orient == Horizontal ) { | 757 | if ( orient == Horizontal ) { |
753 | if ( false && orient == Horizontal && !isSplitter ) | 758 | if ( false && orient == Horizontal && !isSplitter ) |
754 | p = contentsRect().width() - p - s; | 759 | p = contentsRect().width() - p - s; |
755 | w->setGeometry( p, contentsRect().y(), s, contentsRect().height() ); | 760 | w->setGeometry( p, contentsRect().y(), s, contentsRect().height() ); |
756 | } else | 761 | } else |
757 | w->setGeometry( contentsRect().x(), p, contentsRect().width(), s ); | 762 | w->setGeometry( contentsRect().x(), p, contentsRect().width(), s ); |
758 | } | 763 | } |
759 | 764 | ||
760 | 765 | ||
761 | /* | 766 | /* |
762 | Places the right/bottom edge of the widget at \a id at position \a pos. | 767 | Places the right/bottom edge of the widget at \a id at position \a pos. |
763 | 768 | ||
764 | \sa idAfter() | 769 | \sa idAfter() |
765 | */ | 770 | */ |
766 | void KDGanttMinimizeSplitter::moveBefore( int pos, int id, bool upLeft ) | 771 | void KDGanttMinimizeSplitter::moveBefore( int pos, int id, bool upLeft ) |
767 | { | 772 | { |
768 | if( id < 0 ) | 773 | if( id < 0 ) |
769 | return; | 774 | return; |
770 | QSplitterLayoutStruct *s = data->list.at(id); | 775 | QSplitterLayoutStruct *s = data->list.at(id); |
771 | if ( !s ) | 776 | if ( !s ) |
772 | return; | 777 | return; |
773 | QWidget *w = s->wid; | 778 | QWidget *w = s->wid; |
774 | if ( w->isHidden() ) { | 779 | if ( w->isHidden() ) { |
775 | moveBefore( pos, id-1, upLeft ); | 780 | moveBefore( pos, id-1, upLeft ); |
776 | } else if ( s->isSplitter ) { | 781 | } else if ( s->isSplitter ) { |
777 | int pos1, pos2; | 782 | int pos1, pos2; |
778 | int dd = s->sizer; | 783 | int dd = s->sizer; |
779 | if( false && orient == Horizontal ) { | 784 | if( false && orient == Horizontal ) { |
780 | pos1 = pos; | 785 | pos1 = pos; |
781 | pos2 = pos + dd; | 786 | pos2 = pos + dd; |
782 | } else { | 787 | } else { |
783 | pos2 = pos - dd; | 788 | pos2 = pos - dd; |
784 | pos1 = pos2 + 1; | 789 | pos1 = pos2 + 1; |
785 | } | 790 | } |
786 | if ( upLeft ) { | 791 | if ( upLeft ) { |
787 | setG( w, pos1, dd, TRUE ); | 792 | setG( w, pos1, dd, TRUE ); |
788 | moveBefore( pos2, id-1, upLeft ); | 793 | moveBefore( pos2, id-1, upLeft ); |
789 | } else { | 794 | } else { |
790 | moveBefore( pos2, id-1, upLeft ); | 795 | moveBefore( pos2, id-1, upLeft ); |
791 | setG( w, pos1, dd, TRUE ); | 796 | setG( w, pos1, dd, TRUE ); |
792 | } | 797 | } |
793 | } else { | 798 | } else { |
794 | int dd, newLeft, nextPos; | 799 | int dd, newLeft, nextPos; |
795 | if( false && orient == Horizontal ) { | 800 | if( false && orient == Horizontal ) { |
796 | dd = w->geometry().right() - pos; | 801 | dd = w->geometry().right() - pos; |
797 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); | 802 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); |
798 | newLeft = pos+1; | 803 | newLeft = pos+1; |
799 | nextPos = newLeft + dd; | 804 | nextPos = newLeft + dd; |
800 | } else { | 805 | } else { |
801 | dd = pos - pick( w->pos() ) + 1; | 806 | dd = pos - pick( w->pos() ) + 1; |
802 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); | 807 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); |
803 | newLeft = pos-dd+1; | 808 | newLeft = pos-dd+1; |
804 | nextPos = newLeft - 1; | 809 | nextPos = newLeft - 1; |
805 | } | 810 | } |
806 | setG( w, newLeft, dd, TRUE ); | 811 | setG( w, newLeft, dd, TRUE ); |
807 | moveBefore( nextPos, id-1, upLeft ); | 812 | moveBefore( nextPos, id-1, upLeft ); |
808 | } | 813 | } |
809 | } | 814 | } |
810 | 815 | ||
811 | 816 | ||
812 | /* | 817 | /* |
813 | Places the left/top edge of the widget at \a id at position \a pos. | 818 | Places the left/top edge of the widget at \a id at position \a pos. |
814 | 819 | ||
815 | \sa idAfter() | 820 | \sa idAfter() |
816 | */ | 821 | */ |
817 | void KDGanttMinimizeSplitter::moveAfter( int pos, int id, bool upLeft ) | 822 | void KDGanttMinimizeSplitter::moveAfter( int pos, int id, bool upLeft ) |
818 | { | 823 | { |
819 | QSplitterLayoutStruct *s = id < int(data->list.count()) ? | 824 | QSplitterLayoutStruct *s = id < int(data->list.count()) ? |
820 | data->list.at(id) : 0; | 825 | data->list.at(id) : 0; |
821 | if ( !s ) | 826 | if ( !s ) |
822 | return; | 827 | return; |
823 | QWidget *w = s->wid; | 828 | QWidget *w = s->wid; |
824 | if ( w->isHidden() ) { | 829 | if ( w->isHidden() ) { |
825 | moveAfter( pos, id+1, upLeft ); | 830 | moveAfter( pos, id+1, upLeft ); |
826 | } else if ( pick( w->pos() ) == pos ) { | 831 | } else if ( pick( w->pos() ) == pos ) { |
827 | //No need to do anything if it's already there. | 832 | //No need to do anything if it's already there. |
828 | return; | 833 | return; |
829 | } else if ( s->isSplitter ) { | 834 | } else if ( s->isSplitter ) { |
830 | int dd = s->sizer; | 835 | int dd = s->sizer; |
831 | int pos1, pos2; | 836 | int pos1, pos2; |
832 | if( false && orient == Horizontal ) { | 837 | if( false && orient == Horizontal ) { |
833 | pos2 = pos - dd; | 838 | pos2 = pos - dd; |
834 | pos1 = pos2 + 1; | 839 | pos1 = pos2 + 1; |
835 | } else { | 840 | } else { |
836 | pos1 = pos; | 841 | pos1 = pos; |
837 | pos2 = pos + dd; | 842 | pos2 = pos + dd; |
838 | } | 843 | } |
839 | if ( upLeft ) { | 844 | if ( upLeft ) { |
840 | setG( w, pos1, dd, TRUE ); | 845 | setG( w, pos1, dd, TRUE ); |
841 | moveAfter( pos2, id+1, upLeft ); | 846 | moveAfter( pos2, id+1, upLeft ); |
842 | } else { | 847 | } else { |
843 | moveAfter( pos2, id+1, upLeft ); | 848 | moveAfter( pos2, id+1, upLeft ); |
844 | setG( w, pos1, dd, TRUE ); | 849 | setG( w, pos1, dd, TRUE ); |
845 | } | 850 | } |
846 | } else { | 851 | } else { |
847 | int left = pick( w->pos() ); | 852 | int left = pick( w->pos() ); |
848 | int right, dd,/* newRight,*/ newLeft, nextPos; | 853 | int right, dd,/* newRight,*/ newLeft, nextPos; |
849 | if ( false && orient == Horizontal ) { | 854 | if ( false && orient == Horizontal ) { |
850 | dd = pos - left + 1; | 855 | dd = pos - left + 1; |
851 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); | 856 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); |
852 | newLeft = pos-dd+1; | 857 | newLeft = pos-dd+1; |
853 | nextPos = newLeft - 1; | 858 | nextPos = newLeft - 1; |
854 | } else { | 859 | } else { |
855 | right = pick( w->geometry().bottomRight() ); | 860 | right = pick( w->geometry().bottomRight() ); |
856 | dd = right - pos + 1; | 861 | dd = right - pos + 1; |
857 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); | 862 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); |
858 | /*newRight = pos+dd-1;*/ | 863 | /*newRight = pos+dd-1;*/ |
859 | newLeft = pos; | 864 | newLeft = pos; |
860 | nextPos = newLeft + dd; | 865 | nextPos = newLeft + dd; |
861 | } | 866 | } |
862 | setG( w, newLeft, dd, TRUE ); | 867 | setG( w, newLeft, dd, TRUE ); |
863 | /*if( right != newRight )*/ | 868 | /*if( right != newRight )*/ |
864 | moveAfter( nextPos, id+1, upLeft ); | 869 | moveAfter( nextPos, id+1, upLeft ); |
865 | } | 870 | } |
866 | } | 871 | } |
867 | 872 | ||
868 | 873 | ||
869 | void KDGanttMinimizeSplitter::expandPos( int id, int* min, int* max ) | 874 | void KDGanttMinimizeSplitter::expandPos( int id, int* min, int* max ) |