Diffstat (limited to 'microkde/KDGanttMinimizeSplitter.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | microkde/KDGanttMinimizeSplitter.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/microkde/KDGanttMinimizeSplitter.cpp b/microkde/KDGanttMinimizeSplitter.cpp index 567ae54..84edc0d 100644 --- a/microkde/KDGanttMinimizeSplitter.cpp +++ b/microkde/KDGanttMinimizeSplitter.cpp | |||
@@ -1,738 +1,748 @@ | |||
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 | //setMaximumHeight( 5 ); // test only | 83 | //setMaximumHeight( 5 ); // test only |
84 | } | 84 | } |
85 | 85 | ||
86 | QSize KDGanttSplitterHandle::sizeHint() const | 86 | QSize KDGanttSplitterHandle::sizeHint() const |
87 | { | 87 | { |
88 | return mSizeHint; | 88 | return mSizeHint; |
89 | } | 89 | } |
90 | 90 | ||
91 | void KDGanttSplitterHandle::setOrientation( Qt::Orientation o ) | 91 | void KDGanttSplitterHandle::setOrientation( Qt::Orientation o ) |
92 | { | 92 | { |
93 | orient = o; | 93 | orient = o; |
94 | #ifndef QT_NO_CURSOR | 94 | #ifndef QT_NO_CURSOR |
95 | if ( o == KDGanttMinimizeSplitter::Horizontal ) | 95 | if ( o == KDGanttMinimizeSplitter::Horizontal ) |
96 | setCursor( splitHCursor ); | 96 | setCursor( splitHCursor ); |
97 | else | 97 | else |
98 | setCursor( splitVCursor ); | 98 | setCursor( splitVCursor ); |
99 | #endif | 99 | #endif |
100 | } | 100 | } |
101 | 101 | ||
102 | 102 | ||
103 | void KDGanttSplitterHandle::mouseMoveEvent( QMouseEvent *e ) | 103 | void KDGanttSplitterHandle::mouseMoveEvent( QMouseEvent *e ) |
104 | { | 104 | { |
105 | updateCursor( e->pos() ); | 105 | updateCursor( e->pos() ); |
106 | if ( !(e->state()&LeftButton) ) | 106 | if ( !(e->state()&LeftButton) ) |
107 | return; | 107 | return; |
108 | 108 | ||
109 | if ( _activeButton != 0) | 109 | if ( _activeButton != 0) |
110 | return; | 110 | return; |
111 | 111 | ||
112 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) | 112 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) |
113 | - mouseOffset; | 113 | - mouseOffset; |
114 | if ( true /*opaque()*/ ) { | 114 | if ( true /*opaque()*/ ) { |
115 | s->moveSplitter( pos, id() ); | 115 | s->moveSplitter( pos, id() ); |
116 | } else { | 116 | } else { |
117 | int min = pos; int max = pos; | 117 | int min = pos; int max = pos; |
118 | s->getRange( id(), &min, &max ); | 118 | s->getRange( id(), &min, &max ); |
119 | s->setRubberband( QMAX( min, QMIN(max, pos ))); | 119 | s->setRubberband( QMAX( min, QMIN(max, pos ))); |
120 | } | 120 | } |
121 | _collapsed = false; | 121 | _collapsed = false; |
122 | } | 122 | } |
123 | 123 | ||
124 | void KDGanttSplitterHandle::mousePressEvent( QMouseEvent *e ) | 124 | void KDGanttSplitterHandle::mousePressEvent( QMouseEvent *e ) |
125 | { | 125 | { |
126 | if ( e->button() == LeftButton ) { | 126 | if ( e->button() == LeftButton ) { |
127 | _activeButton = onButton( e->pos() ); | 127 | _activeButton = onButton( e->pos() ); |
128 | mouseOffset = s->pick(e->pos()); | 128 | mouseOffset = s->pick(e->pos()); |
129 | if ( _activeButton != 0) | 129 | if ( _activeButton != 0) |
130 | repaint(); | 130 | repaint(); |
131 | updateCursor( e->pos() ); | 131 | updateCursor( e->pos() ); |
132 | } | 132 | } |
133 | } | 133 | } |
134 | 134 | ||
135 | void KDGanttSplitterHandle::updateCursor( const QPoint& p) | 135 | void KDGanttSplitterHandle::updateCursor( const QPoint& p) |
136 | { | 136 | { |
137 | if ( onButton( p ) != 0 ) { | 137 | if ( onButton( p ) != 0 ) { |
138 | setCursor( arrowCursor ); | 138 | setCursor( arrowCursor ); |
139 | } | 139 | } |
140 | else { | 140 | else { |
141 | if ( orient == KDGanttMinimizeSplitter::Horizontal ) | 141 | if ( orient == KDGanttMinimizeSplitter::Horizontal ) |
142 | setCursor( splitHCursor ); | 142 | setCursor( splitHCursor ); |
143 | else | 143 | else |
144 | setCursor( splitVCursor ); | 144 | setCursor( splitVCursor ); |
145 | } | 145 | } |
146 | } | 146 | } |
147 | void KDGanttSplitterHandle::toggle() | 147 | void KDGanttSplitterHandle::toggle() |
148 | { | 148 | { |
149 | int pos; | 149 | int pos; |
150 | int min, max; | 150 | int min, max; |
151 | if ( !_collapsed ) { | 151 | if ( !_collapsed ) { |
152 | s->expandPos( id(), &min, &max ); | 152 | s->expandPos( id(), &min, &max ); |
153 | if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left | 153 | if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left |
154 | || s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) { | 154 | || s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) { |
155 | pos = min; | 155 | pos = min; |
156 | } | 156 | } |
157 | else { | 157 | else { |
158 | pos = max; | 158 | pos = max; |
159 | } | 159 | } |
160 | 160 | ||
161 | _origPos = s->pick(mapToParent( QPoint( 0,0 ) )); | 161 | _origPos = s->pick(mapToParent( QPoint( 0,0 ) )); |
162 | s->moveSplitter( pos, id() ); | 162 | s->moveSplitter( pos, id() ); |
163 | _collapsed = true; | 163 | _collapsed = true; |
164 | } | 164 | } |
165 | else { | 165 | else { |
166 | s->moveSplitter( _origPos, id() ); | 166 | s->moveSplitter( _origPos, id() ); |
167 | _collapsed = false; | 167 | _collapsed = false; |
168 | } | 168 | } |
169 | repaint(); | ||
169 | } | 170 | } |
170 | 171 | ||
171 | void KDGanttSplitterHandle::mouseReleaseEvent( QMouseEvent *e ) | 172 | void KDGanttSplitterHandle::mouseReleaseEvent( QMouseEvent *e ) |
172 | { | 173 | { |
173 | if ( _activeButton != 0 ) { | 174 | if ( _activeButton != 0 ) { |
174 | if ( onButton( e->pos() ) == _activeButton ) | 175 | if ( onButton( e->pos() ) == _activeButton ) |
175 | { | 176 | { |
176 | toggle(); | 177 | toggle(); |
177 | } | 178 | } |
178 | _activeButton = 0; | 179 | _activeButton = 0; |
179 | updateCursor( e->pos() ); | 180 | updateCursor( e->pos() ); |
180 | } | 181 | } |
181 | else { | 182 | else { |
182 | if ( !opaque() && e->button() == LeftButton ) { | 183 | if ( !opaque() && e->button() == LeftButton ) { |
183 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) | 184 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) |
184 | - mouseOffset; | 185 | - mouseOffset; |
185 | s->setRubberband( -1 ); | 186 | s->setRubberband( -1 ); |
186 | s->moveSplitter( pos, id() ); | 187 | s->moveSplitter( pos, id() ); |
187 | } | 188 | } |
188 | } | 189 | } |
189 | repaint(); | 190 | repaint(); |
190 | } | 191 | } |
191 | 192 | ||
192 | int KDGanttSplitterHandle::onButton( const QPoint& p ) | 193 | int KDGanttSplitterHandle::onButton( const QPoint& p ) |
193 | { | 194 | { |
194 | QValueList<QPointArray> list = buttonRegions(); | 195 | QValueList<QPointArray> list = buttonRegions(); |
195 | int index = 1; | 196 | int index = 1; |
196 | int add = 12; | 197 | int add = 12; |
197 | for( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { | 198 | for( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { |
198 | QRect rect = (*it).boundingRect(); | 199 | QRect rect = (*it).boundingRect(); |
199 | rect.setLeft( rect.left()- add ); | 200 | rect.setLeft( rect.left()- add ); |
200 | rect.setRight( rect.right() + add); | 201 | rect.setRight( rect.right() + add); |
201 | rect.setTop( rect.top()- add ); | 202 | rect.setTop( rect.top()- add ); |
202 | rect.setBottom( rect.bottom() + add); | 203 | rect.setBottom( rect.bottom() + add); |
203 | if ( rect.contains( p ) ) { | 204 | if ( rect.contains( p ) ) { |
204 | return index; | 205 | return index; |
205 | } | 206 | } |
206 | index++; | 207 | index++; |
207 | } | 208 | } |
208 | return 0; | 209 | return 0; |
209 | } | 210 | } |
210 | 211 | ||
211 | 212 | ||
212 | QValueList<QPointArray> KDGanttSplitterHandle::buttonRegions() | 213 | QValueList<QPointArray> KDGanttSplitterHandle::buttonRegions() |
213 | { | 214 | { |
214 | QValueList<QPointArray> list; | 215 | QValueList<QPointArray> list; |
215 | 216 | ||
216 | int sw = 8; | 217 | int sw = 8; |
217 | int yyy = 1; | 218 | int yyy = 1; |
218 | int xxx = 1; | 219 | int xxx = 1; |
219 | int voffset[] = { (int) -sw*3, (int) sw*3 }; | 220 | int voffset[] = { (int) -sw*3, (int) sw*3 }; |
220 | for ( int i = 0; i < 2; i++ ) { | 221 | for ( int i = 0; i < 2; i++ ) { |
221 | QPointArray arr; | 222 | QPointArray arr; |
222 | if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right || | 223 | if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right || |
223 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left) { | 224 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left) { |
224 | int mid = height()/2 + voffset[i]; | 225 | int mid = height()/2 + voffset[i]; |
225 | arr.setPoints( 3, | 226 | arr.setPoints( 3, |
226 | 1-xxx, mid - sw + 4, | 227 | 1-xxx, mid - sw + 4, |
227 | sw-3-xxx, mid, | 228 | sw-3-xxx, mid, |
228 | 1-xxx, mid + sw -4); | 229 | 1-xxx, mid + sw -4); |
229 | } | 230 | } |
230 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left || | 231 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left || |
231 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) { | 232 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) { |
232 | int mid = height()/2 + voffset[i]; | 233 | int mid = height()/2 + voffset[i]; |
233 | arr.setPoints( 3, | 234 | arr.setPoints( 3, |
234 | sw-4, mid - sw + 4, | 235 | sw-4, mid - sw + 4, |
235 | 0, mid, | 236 | 0, mid, |
236 | sw-4, mid + sw - 4); | 237 | sw-4, mid + sw - 4); |
237 | } | 238 | } |
238 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up || | 239 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up || |
239 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down) { | 240 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down) { |
240 | int mid = width()/2 + voffset[i]; | 241 | int mid = width()/2 + voffset[i]; |
241 | arr.setPoints( 3, | 242 | arr.setPoints( 3, |
242 | mid - sw + 4, sw-4, | 243 | mid - sw + 4, sw-4, |
243 | mid, 0, | 244 | mid, 0, |
244 | mid + sw - 4, sw-4 ); | 245 | mid + sw - 4, sw-4 ); |
245 | } | 246 | } |
246 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down || | 247 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down || |
247 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) { | 248 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) { |
248 | int mid = width()/2 + voffset[i]; | 249 | int mid = width()/2 + voffset[i]; |
249 | arr.setPoints( 3, | 250 | arr.setPoints( 3, |
250 | mid - sw + 4, 1-yyy, | 251 | mid - sw + 4, 1-yyy, |
251 | mid, sw-3-yyy, | 252 | mid, sw-3-yyy, |
252 | mid + sw -4, 1-yyy); | 253 | mid + sw -4, 1-yyy); |
253 | } | 254 | } |
254 | list.append( arr ); | 255 | list.append( arr ); |
255 | } | 256 | } |
256 | return list; | 257 | return list; |
257 | } | 258 | } |
258 | 259 | ||
259 | void KDGanttSplitterHandle::paintEvent( QPaintEvent * ) | 260 | void KDGanttSplitterHandle::paintEvent( QPaintEvent * ) |
260 | { | 261 | { |
261 | QPixmap buffer( size() ); | 262 | QPixmap buffer( size() ); |
262 | QPainter p( &buffer ); | 263 | QPainter p( &buffer ); |
263 | 264 | ||
264 | //LR | 265 | //LR |
265 | // Draw the splitter rectangle | 266 | // Draw the splitter rectangle |
266 | p.setBrush( colorGroup().background() ); | 267 | p.setBrush( colorGroup().background() ); |
267 | p.setPen( colorGroup().foreground() ); | 268 | p.setPen( colorGroup().foreground() ); |
268 | //p.drawRect( rect() ); | 269 | //p.drawRect( rect() ); |
269 | buffer.fill( colorGroup().background() ); | 270 | buffer.fill( colorGroup().background() ); |
270 | //buffer.fill( backgroundColor() ); | 271 | //buffer.fill( backgroundColor() ); |
271 | // parentWidget()->style().drawPrimitive( QStyle::PE_Panel, &p, rect(), parentWidget()->colorGroup()); | 272 | // parentWidget()->style().drawPrimitive( QStyle::PE_Panel, &p, rect(), parentWidget()->colorGroup()); |
272 | 273 | ||
273 | int sw = 8; // Hardcoded, given I didn't use styles anymore, I didn't like to use their size | 274 | int sw = 8; // Hardcoded, given I didn't use styles anymore, I didn't like to use their size |
274 | 275 | ||
275 | // arrow color | 276 | // arrow color |
276 | QColor col; | 277 | QColor col; |
277 | if ( _activeButton ) | 278 | if ( _activeButton ) |
278 | col = colorGroup().background().dark( 250 ); | 279 | col = colorGroup().background().dark( 250 ); |
279 | else | 280 | else |
280 | col = colorGroup().background().dark( 150 ); | 281 | col = colorGroup().background().dark( 150 ); |
281 | //QColor col = backgroundColor().dark( 130 ); | 282 | //QColor col = backgroundColor().dark( 130 ); |
282 | p.setBrush( col ); | 283 | p.setBrush( col ); |
283 | p.setPen( col ); | 284 | p.setPen( col ); |
284 | 285 | ||
285 | QValueList<QPointArray> list = buttonRegions(); | 286 | QValueList<QPointArray> list = buttonRegions(); |
286 | int index = 1; | 287 | int index = 1; |
287 | if ( mUseOffset ) | 288 | if ( mUseOffset ) |
288 | p.translate( 0, 1 ); | 289 | p.translate( 0, 1 ); |
289 | for ( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { | 290 | for ( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { |
290 | if ( index == _activeButton ) { | 291 | if ( index == _activeButton ) { |
291 | 292 | ||
292 | /* | 293 | /* |
293 | if ( ! _collapsed ) { | 294 | if ( ! _collapsed ) { |
294 | p.save(); | 295 | p.save(); |
295 | // p.translate( parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftHorizontal ), | 296 | // p.translate( parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftHorizontal ), |
296 | // parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftVertical ) ); | 297 | // parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftVertical ) ); |
297 | p.translate( -1, 0 ); | 298 | p.translate( -1, 0 ); |
298 | p.drawPolygon( *it, true ); | 299 | p.drawPolygon( *it, true ); |
299 | p.restore(); } else | 300 | p.restore(); } else |
300 | */ | 301 | */ |
301 | p.drawPolygon( *it, true ); | 302 | p.drawPolygon( *it, true ); |
302 | 303 | ||
303 | } | 304 | } |
304 | else { | 305 | else { |
305 | /* | 306 | /* |
306 | if ( ! _collapsed ) { | 307 | if ( ! _collapsed ) { |
307 | p.save(); | 308 | p.save(); |
308 | p.translate( -1, 0 ); | 309 | p.translate( -1, 0 ); |
309 | p.drawPolygon( *it, true ); | 310 | p.drawPolygon( *it, true ); |
310 | p.restore(); | 311 | p.restore(); |
311 | } else | 312 | } else |
312 | */ | 313 | */ |
313 | p.drawPolygon( *it, true ); | 314 | p.drawPolygon( *it, true ); |
314 | 315 | ||
315 | } | 316 | } |
316 | index++; | 317 | index++; |
317 | } | 318 | } |
318 | 319 | ||
319 | // Draw the lines between the arrows | 320 | // Draw the lines between the arrows |
320 | if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left || | 321 | if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left || |
321 | s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) { | 322 | s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) { |
322 | int mid = height()/2; | 323 | int mid = height()/2; |
323 | p.drawLine ( 1, mid - sw, 1, mid + sw ); | 324 | p.drawLine ( 1, mid - sw, 1, mid + sw ); |
324 | p.drawLine ( 3, mid - sw, 3, mid + sw ); | 325 | p.drawLine ( 3, mid - sw, 3, mid + sw ); |
325 | } | 326 | } |
326 | else if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Up || | 327 | else if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Up || |
327 | s->minimizeDirection() == KDGanttMinimizeSplitter::Down ) { | 328 | s->minimizeDirection() == KDGanttMinimizeSplitter::Down ) { |
328 | int mid = width()/2; | 329 | int mid = width()/2; |
329 | p.drawLine( mid -sw, 1, mid +sw, 1 ); | 330 | p.drawLine( mid -sw, 1, mid +sw, 1 ); |
330 | p.drawLine( mid -sw, 3, mid +sw, 3 ); | 331 | p.drawLine( mid -sw, 3, mid +sw, 3 ); |
331 | } | 332 | } |
332 | bitBlt( this, 0, 0, &buffer ); | 333 | bitBlt( this, 0, 0, &buffer ); |
333 | 334 | ||
334 | } | 335 | } |
335 | #endif | 336 | #endif |
336 | 337 | ||
337 | class QSplitterLayoutStruct | 338 | class QSplitterLayoutStruct |
338 | { | 339 | { |
339 | public: | 340 | public: |
340 | KDGanttMinimizeSplitter::ResizeMode mode; | 341 | KDGanttMinimizeSplitter::ResizeMode mode; |
341 | QCOORD sizer; | 342 | QCOORD sizer; |
342 | bool isSplitter; | 343 | bool isSplitter; |
343 | QWidget *wid; | 344 | QWidget *wid; |
344 | }; | 345 | }; |
345 | 346 | ||
346 | class QSplitterData | 347 | class QSplitterData |
347 | { | 348 | { |
348 | public: | 349 | public: |
349 | QSplitterData() : opaque( FALSE ), firstShow( TRUE ) {} | 350 | QSplitterData() : opaque( FALSE ), firstShow( TRUE ) {} |
350 | 351 | ||
351 | QPtrList<QSplitterLayoutStruct> list; | 352 | QPtrList<QSplitterLayoutStruct> list; |
352 | bool opaque; | 353 | bool opaque; |
353 | bool firstShow; | 354 | bool firstShow; |
354 | }; | 355 | }; |
355 | 356 | ||
356 | void kdganttGeomCalc( QMemArray<QLayoutStruct> &chain, int start, int count, int pos, | 357 | void kdganttGeomCalc( QMemArray<QLayoutStruct> &chain, int start, int count, int pos, |
357 | int space, int spacer ); | 358 | int space, int spacer ); |
358 | #endif // DOXYGEN_SKIP_INTERNAL | 359 | #endif // DOXYGEN_SKIP_INTERNAL |
359 | 360 | ||
360 | 361 | ||
361 | /*! | 362 | /*! |
362 | \class KDGanttMinimizeSplitter KDGanttMinimizeSplitter.h | 363 | \class KDGanttMinimizeSplitter KDGanttMinimizeSplitter.h |
363 | \brief The KDGanttMinimizeSplitter class implements a splitter | 364 | \brief The KDGanttMinimizeSplitter class implements a splitter |
364 | widget with minimize buttons. | 365 | widget with minimize buttons. |
365 | 366 | ||
366 | This class (and its documentation) is largely a copy of Qt's | 367 | This class (and its documentation) is largely a copy of Qt's |
367 | QSplitter; the copying was necessary because QSplitter is not | 368 | QSplitter; the copying was necessary because QSplitter is not |
368 | extensible at all. QSplitter and its documentation are licensed | 369 | extensible at all. QSplitter and its documentation are licensed |
369 | according to the GPL and the Qt Professional License (if you hold | 370 | according to the GPL and the Qt Professional License (if you hold |
370 | such a license) and are (C) Trolltech AS. | 371 | such a license) and are (C) Trolltech AS. |
371 | 372 | ||
372 | A splitter lets the user control the size of child widgets by | 373 | A splitter lets the user control the size of child widgets by |
373 | dragging the boundary between the children. Any number of widgets | 374 | dragging the boundary between the children. Any number of widgets |
374 | may be controlled. | 375 | may be controlled. |
375 | 376 | ||
376 | To show a QListBox, a QListView and a QTextEdit side by side: | 377 | To show a QListBox, a QListView and a QTextEdit side by side: |
377 | 378 | ||
378 | \code | 379 | \code |
379 | KDGanttMinimizeSplitter *split = new KDGanttMinimizeSplitter( parent ); | 380 | KDGanttMinimizeSplitter *split = new KDGanttMinimizeSplitter( parent ); |
380 | QListBox *lb = new QListBox( split ); | 381 | QListBox *lb = new QListBox( split ); |
381 | QListView *lv = new QListView( split ); | 382 | QListView *lv = new QListView( split ); |
382 | QTextEdit *ed = new QTextEdit( split ); | 383 | QTextEdit *ed = new QTextEdit( split ); |
383 | \endcode | 384 | \endcode |
384 | 385 | ||
385 | In KDGanttMinimizeSplitter, the boundary can be either horizontal or | 386 | In KDGanttMinimizeSplitter, the boundary can be either horizontal or |
386 | vertical. The default is horizontal (the children are side by side) | 387 | vertical. The default is horizontal (the children are side by side) |
387 | but you can use setOrientation( QSplitter::Vertical ) to set it to | 388 | but you can use setOrientation( QSplitter::Vertical ) to set it to |
388 | vertical. | 389 | vertical. |
389 | 390 | ||
390 | Use setResizeMode() to specify | 391 | Use setResizeMode() to specify |
391 | that a widget should keep its size when the splitter is resized. | 392 | that a widget should keep its size when the splitter is resized. |
392 | 393 | ||
393 | Although KDGanttMinimizeSplitter normally resizes the children only | 394 | Although KDGanttMinimizeSplitter normally resizes the children only |
394 | at the end of a resize operation, if you call setOpaqueResize( TRUE | 395 | at the end of a resize operation, if you call setOpaqueResize( TRUE |
395 | ) the widgets are resized as often as possible. | 396 | ) the widgets are resized as often as possible. |
396 | 397 | ||
397 | The initial distribution of size between the widgets is determined | 398 | The initial distribution of size between the widgets is determined |
398 | by the initial size of each widget. You can also use setSizes() to | 399 | by the initial size of each widget. You can also use setSizes() to |
399 | set the sizes of all the widgets. The function sizes() returns the | 400 | set the sizes of all the widgets. The function sizes() returns the |
400 | sizes set by the user. | 401 | sizes set by the user. |
401 | 402 | ||
402 | If you hide() a child, its space will be distributed among the other | 403 | If you hide() a child, its space will be distributed among the other |
403 | children. It will be reinstated when you show() it again. It is also | 404 | children. It will be reinstated when you show() it again. It is also |
404 | possible to reorder the widgets within the splitter using | 405 | possible to reorder the widgets within the splitter using |
405 | moveToFirst() and moveToLast(). | 406 | moveToFirst() and moveToLast(). |
406 | */ | 407 | */ |
407 | 408 | ||
408 | 409 | ||
409 | 410 | ||
410 | static QSize minSize( const QWidget* /*w*/ ) | 411 | static QSize minSize( const QWidget* /*w*/ ) |
411 | { | 412 | { |
412 | return QSize(0,0); | 413 | return QSize(0,0); |
413 | } | 414 | } |
414 | 415 | ||
415 | // This is the original version of minSize | 416 | // This is the original version of minSize |
416 | static QSize minSizeHint( const QWidget* w ) | 417 | static QSize minSizeHint( const QWidget* w ) |
417 | { | 418 | { |
418 | QSize min = w->minimumSize(); | 419 | QSize min = w->minimumSize(); |
419 | QSize s; | 420 | QSize s; |
420 | if ( min.height() <= 0 || min.width() <= 0 ) | 421 | if ( min.height() <= 0 || min.width() <= 0 ) |
421 | s = w->minimumSizeHint(); | 422 | s = w->minimumSizeHint(); |
422 | if ( min.height() > 0 ) | 423 | if ( min.height() > 0 ) |
423 | s.setHeight( min.height() ); | 424 | s.setHeight( min.height() ); |
424 | if ( min.width() > 0 ) | 425 | if ( min.width() > 0 ) |
425 | s.setWidth( min.width() ); | 426 | s.setWidth( min.width() ); |
426 | return s.expandedTo(QSize(0,0)); | 427 | return s.expandedTo(QSize(0,0)); |
427 | } | 428 | } |
428 | 429 | ||
429 | 430 | ||
430 | 431 | ||
431 | /*! | 432 | /*! |
432 | Constructs a horizontal splitter with the \a parent and \a | 433 | Constructs a horizontal splitter with the \a parent and \a |
433 | name arguments being passed on to the QFrame constructor. | 434 | name arguments being passed on to the QFrame constructor. |
434 | */ | 435 | */ |
435 | KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( QWidget *parent, const char *name ) | 436 | KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( QWidget *parent, const char *name ) |
436 | :QFrame(parent,name,WPaintUnclipped) | 437 | :QFrame(parent,name,WPaintUnclipped) |
437 | { | 438 | { |
438 | mFirstHandle = 0; | 439 | mFirstHandle = 0; |
439 | #if QT_VERSION >= 232 | 440 | #if QT_VERSION >= 232 |
440 | orient = Horizontal; | 441 | orient = Horizontal; |
441 | init(); | 442 | init(); |
442 | #endif | 443 | #endif |
443 | } | 444 | } |
444 | 445 | ||
445 | /*! | 446 | /*! |
446 | Constructs a splitter with orientation \a o with the \a parent | 447 | Constructs a splitter with orientation \a o with the \a parent |
447 | and \a name arguments being passed on to the QFrame constructor. | 448 | and \a name arguments being passed on to the QFrame constructor. |
448 | */ | 449 | */ |
449 | KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( Orientation o, QWidget *parent, const char *name ) | 450 | KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( Orientation o, QWidget *parent, const char *name ) |
450 | :QFrame(parent,name,WPaintUnclipped) | 451 | :QFrame(parent,name,WPaintUnclipped) |
451 | { | 452 | { |
452 | mFirstHandle = 0; | 453 | mFirstHandle = 0; |
453 | #if QT_VERSION >= 232 | 454 | #if QT_VERSION >= 232 |
454 | orient = o; | 455 | orient = o; |
455 | init(); | 456 | init(); |
456 | #endif | 457 | #endif |
457 | } | 458 | } |
458 | 459 | ||
459 | /*! | 460 | /*! |
460 | Destroys the splitter and any children. | 461 | Destroys the splitter and any children. |
461 | */ | 462 | */ |
462 | KDGanttMinimizeSplitter::~KDGanttMinimizeSplitter() | 463 | KDGanttMinimizeSplitter::~KDGanttMinimizeSplitter() |
463 | { | 464 | { |
464 | #if QT_VERSION >= 232 | 465 | #if QT_VERSION >= 232 |
465 | data->list.setAutoDelete( TRUE ); | 466 | data->list.setAutoDelete( TRUE ); |
466 | delete data; | 467 | delete data; |
467 | #endif | 468 | #endif |
468 | } | 469 | } |
469 | 470 | ||
470 | 471 | ||
471 | #if QT_VERSION >= 232 | 472 | #if QT_VERSION >= 232 |
472 | void KDGanttMinimizeSplitter::init() | 473 | void KDGanttMinimizeSplitter::init() |
473 | { | 474 | { |
474 | data = new QSplitterData; | 475 | data = new QSplitterData; |
475 | if ( orient == Horizontal ) | 476 | if ( orient == Horizontal ) |
476 | setSizePolicy( QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum) ); | 477 | setSizePolicy( QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum) ); |
477 | else | 478 | else |
478 | setSizePolicy( QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Expanding) ); | 479 | setSizePolicy( QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Expanding) ); |
479 | } | 480 | } |
480 | #endif | 481 | #endif |
481 | 482 | ||
482 | 483 | ||
484 | void KDGanttMinimizeSplitter::toggle() | ||
485 | { | ||
486 | if ( mFirstHandle ) | ||
487 | mFirstHandle->toggle(); | ||
488 | else | ||
489 | qDebug("KDGanttMinimizeSplitter::toggle::sorry, handle not available "); | ||
490 | |||
491 | } | ||
492 | |||
483 | 493 | ||
484 | /*! | 494 | /*! |
485 | \brief the orientation of the splitter | 495 | \brief the orientation of the splitter |
486 | 496 | ||
487 | By default the orientation is horizontal (the widgets are side by side). | 497 | By default the orientation is horizontal (the widgets are side by side). |
488 | The possible orientations are Qt:Vertical and Qt::Horizontal (the default). | 498 | The possible orientations are Qt:Vertical and Qt::Horizontal (the default). |
489 | */ | 499 | */ |
490 | void KDGanttMinimizeSplitter::setOrientation( Orientation o ) | 500 | void KDGanttMinimizeSplitter::setOrientation( Orientation o ) |
491 | { | 501 | { |
492 | #if QT_VERSION >= 232 | 502 | #if QT_VERSION >= 232 |
493 | if ( orient == o ) | 503 | if ( orient == o ) |
494 | return; | 504 | return; |
495 | orient = o; | 505 | orient = o; |
496 | 506 | ||
497 | if ( orient == Horizontal ) | 507 | if ( orient == Horizontal ) |
498 | setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); | 508 | setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); |
499 | else | 509 | else |
500 | setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); | 510 | setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); |
501 | 511 | ||
502 | QSplitterLayoutStruct *s = data->list.first(); | 512 | QSplitterLayoutStruct *s = data->list.first(); |
503 | while ( s ) { | 513 | while ( s ) { |
504 | if ( s->isSplitter ) | 514 | if ( s->isSplitter ) |
505 | ((KDGanttSplitterHandle*)s->wid)->setOrientation( o ); | 515 | ((KDGanttSplitterHandle*)s->wid)->setOrientation( o ); |
506 | s = data->list.next(); // ### next at end of loop, no iterator | 516 | s = data->list.next(); // ### next at end of loop, no iterator |
507 | } | 517 | } |
508 | recalc( isVisible() ); | 518 | recalc( isVisible() ); |
509 | #endif | 519 | #endif |
510 | } | 520 | } |
511 | 521 | ||
512 | 522 | ||
513 | #if QT_VERSION >= 232 | 523 | #if QT_VERSION >= 232 |
514 | /*! | 524 | /*! |
515 | \reimp | 525 | \reimp |
516 | */ | 526 | */ |
517 | void KDGanttMinimizeSplitter::resizeEvent( QResizeEvent * ) | 527 | void KDGanttMinimizeSplitter::resizeEvent( QResizeEvent * ) |
518 | { | 528 | { |
519 | doResize(); | 529 | doResize(); |
520 | } | 530 | } |
521 | 531 | ||
522 | 532 | ||
523 | /* | 533 | /* |
524 | Inserts the widget \a w at the end (or at the beginning if \a first | 534 | Inserts the widget \a w at the end (or at the beginning if \a first |
525 | is TRUE) of the splitter's list of widgets. | 535 | is TRUE) of the splitter's list of widgets. |
526 | 536 | ||
527 | It is the responsibility of the caller of this function to make sure | 537 | It is the responsibility of the caller of this function to make sure |
528 | that \a w is not already in the splitter and to call recalcId if | 538 | that \a w is not already in the splitter and to call recalcId if |
529 | needed. (If \a first is TRUE, then recalcId is very probably | 539 | needed. (If \a first is TRUE, then recalcId is very probably |
530 | needed.) | 540 | needed.) |
531 | */ | 541 | */ |
532 | QSplitterLayoutStruct *KDGanttMinimizeSplitter::addWidget( QWidget *w, bool first ) | 542 | QSplitterLayoutStruct *KDGanttMinimizeSplitter::addWidget( QWidget *w, bool first ) |
533 | { | 543 | { |
534 | QSplitterLayoutStruct *s; | 544 | QSplitterLayoutStruct *s; |
535 | KDGanttSplitterHandle *newHandle = 0; | 545 | KDGanttSplitterHandle *newHandle = 0; |
536 | if ( data->list.count() > 0 ) { | 546 | if ( data->list.count() > 0 ) { |
537 | s = new QSplitterLayoutStruct; | 547 | s = new QSplitterLayoutStruct; |
538 | s->mode = KeepSize; | 548 | s->mode = KeepSize; |
539 | QString tmp = "qt_splithandle_"; | 549 | QString tmp = "qt_splithandle_"; |
540 | tmp += w->name(); | 550 | tmp += w->name(); |
541 | newHandle = new KDGanttSplitterHandle( orientation(), this, tmp.latin1() ); | 551 | newHandle = new KDGanttSplitterHandle( orientation(), this, tmp.latin1() ); |
542 | if ( ! mFirstHandle ) | 552 | if ( ! mFirstHandle ) |
543 | mFirstHandle = newHandle; | 553 | mFirstHandle = newHandle; |
544 | s->wid = newHandle; | 554 | s->wid = newHandle; |
545 | newHandle->setId(data->list.count()); | 555 | newHandle->setId(data->list.count()); |
546 | s->isSplitter = TRUE; | 556 | s->isSplitter = TRUE; |
547 | s->sizer = pick( newHandle->sizeHint() ); | 557 | s->sizer = pick( newHandle->sizeHint() ); |
548 | if ( first ) | 558 | if ( first ) |
549 | data->list.insert( 0, s ); | 559 | data->list.insert( 0, s ); |
550 | else | 560 | else |
551 | data->list.append( s ); | 561 | data->list.append( s ); |
552 | } | 562 | } |
553 | s = new QSplitterLayoutStruct; | 563 | s = new QSplitterLayoutStruct; |
554 | s->mode = Stretch; | 564 | s->mode = Stretch; |
555 | s->wid = w; | 565 | s->wid = w; |
556 | if ( !testWState( WState_Resized ) && w->sizeHint().isValid() ) | 566 | if ( !testWState( WState_Resized ) && w->sizeHint().isValid() ) |
557 | s->sizer = pick( w->sizeHint() ); | 567 | s->sizer = pick( w->sizeHint() ); |
558 | else | 568 | else |
559 | s->sizer = pick( w->size() ); | 569 | s->sizer = pick( w->size() ); |
560 | s->isSplitter = FALSE; | 570 | s->isSplitter = FALSE; |
561 | if ( first ) | 571 | if ( first ) |
562 | data->list.insert( 0, s ); | 572 | data->list.insert( 0, s ); |
563 | else | 573 | else |
564 | data->list.append( s ); | 574 | data->list.append( s ); |
565 | if ( newHandle && isVisible() ) | 575 | if ( newHandle && isVisible() ) |
566 | newHandle->show(); //will trigger sending of post events | 576 | newHandle->show(); //will trigger sending of post events |
567 | return s; | 577 | return s; |
568 | } | 578 | } |
569 | 579 | ||
570 | 580 | ||
571 | /*! | 581 | /*! |
572 | Tells the splitter that a child widget has been inserted or removed. | 582 | Tells the splitter that a child widget has been inserted or removed. |
573 | The event is passed in \a c. | 583 | The event is passed in \a c. |
574 | */ | 584 | */ |
575 | void KDGanttMinimizeSplitter::childEvent( QChildEvent *c ) | 585 | void KDGanttMinimizeSplitter::childEvent( QChildEvent *c ) |
576 | { | 586 | { |
577 | if ( c->type() == QEvent::ChildInserted ) { | 587 | if ( c->type() == QEvent::ChildInserted ) { |
578 | if ( !c->child()->isWidgetType() ) | 588 | if ( !c->child()->isWidgetType() ) |
579 | return; | 589 | return; |
580 | 590 | ||
581 | if ( ((QWidget*)c->child())->testWFlags( WType_TopLevel ) ) | 591 | if ( ((QWidget*)c->child())->testWFlags( WType_TopLevel ) ) |
582 | return; | 592 | return; |
583 | 593 | ||
584 | QSplitterLayoutStruct *s = data->list.first(); | 594 | QSplitterLayoutStruct *s = data->list.first(); |
585 | while ( s ) { | 595 | while ( s ) { |
586 | if ( s->wid == c->child() ) | 596 | if ( s->wid == c->child() ) |
587 | return; | 597 | return; |
588 | s = data->list.next(); | 598 | s = data->list.next(); |
589 | } | 599 | } |
590 | addWidget( (QWidget*)c->child() ); | 600 | addWidget( (QWidget*)c->child() ); |
591 | recalc( isVisible() ); | 601 | recalc( isVisible() ); |
592 | 602 | ||
593 | } else if ( c->type() == QEvent::ChildRemoved ) { | 603 | } else if ( c->type() == QEvent::ChildRemoved ) { |
594 | QSplitterLayoutStruct *p = 0; | 604 | QSplitterLayoutStruct *p = 0; |
595 | if ( data->list.count() > 1 ) | 605 | if ( data->list.count() > 1 ) |
596 | p = data->list.at(1); //remove handle _after_ first widget. | 606 | p = data->list.at(1); //remove handle _after_ first widget. |
597 | QSplitterLayoutStruct *s = data->list.first(); | 607 | QSplitterLayoutStruct *s = data->list.first(); |
598 | while ( s ) { | 608 | while ( s ) { |
599 | if ( s->wid == c->child() ) { | 609 | if ( s->wid == c->child() ) { |
600 | data->list.removeRef( s ); | 610 | data->list.removeRef( s ); |
601 | delete s; | 611 | delete s; |
602 | if ( p && p->isSplitter ) { | 612 | if ( p && p->isSplitter ) { |
603 | data->list.removeRef( p ); | 613 | data->list.removeRef( p ); |
604 | delete p->wid; //will call childEvent | 614 | delete p->wid; //will call childEvent |
605 | delete p; | 615 | delete p; |
606 | } | 616 | } |
607 | recalcId(); | 617 | recalcId(); |
608 | doResize(); | 618 | doResize(); |
609 | return; | 619 | return; |
610 | } | 620 | } |
611 | p = s; | 621 | p = s; |
612 | s = data->list.next(); | 622 | s = data->list.next(); |
613 | } | 623 | } |
614 | } | 624 | } |
615 | } | 625 | } |
616 | 626 | ||
617 | 627 | ||
618 | /*! | 628 | /*! |
619 | Shows a rubber band at position \a p. If \a p is negative, the | 629 | Shows a rubber band at position \a p. If \a p is negative, the |
620 | rubber band is removed. | 630 | rubber band is removed. |
621 | */ | 631 | */ |
622 | void KDGanttMinimizeSplitter::setRubberband( int p ) | 632 | void KDGanttMinimizeSplitter::setRubberband( int p ) |
623 | { | 633 | { |
624 | QPainter paint( this ); | 634 | QPainter paint( this ); |
625 | paint.setPen( gray ); | 635 | paint.setPen( gray ); |
626 | paint.setBrush( gray ); | 636 | paint.setBrush( gray ); |
627 | paint.setRasterOp( XorROP ); | 637 | paint.setRasterOp( XorROP ); |
628 | QRect r = contentsRect(); | 638 | QRect r = contentsRect(); |
629 | const int rBord = 3; //Themable???? | 639 | const int rBord = 3; //Themable???? |
630 | #if QT_VERSION >= 0x030000 | 640 | #if QT_VERSION >= 0x030000 |
631 | int sw = style().pixelMetric(QStyle::PM_SplitterWidth, this); | 641 | int sw = style().pixelMetric(QStyle::PM_SplitterWidth, this); |
632 | #else | 642 | #else |
633 | int sw = style().splitterWidth(); | 643 | int sw = style().splitterWidth(); |
634 | #endif | 644 | #endif |
635 | if ( orient == Horizontal ) { | 645 | if ( orient == Horizontal ) { |
636 | if ( opaqueOldPos >= 0 ) | 646 | if ( opaqueOldPos >= 0 ) |
637 | paint.drawRect( opaqueOldPos + sw/2 - rBord , r.y(), | 647 | paint.drawRect( opaqueOldPos + sw/2 - rBord , r.y(), |
638 | 2*rBord, r.height() ); | 648 | 2*rBord, r.height() ); |
639 | if ( p >= 0 ) | 649 | if ( p >= 0 ) |
640 | paint.drawRect( p + sw/2 - rBord, r.y(), 2*rBord, r.height() ); | 650 | paint.drawRect( p + sw/2 - rBord, r.y(), 2*rBord, r.height() ); |
641 | } else { | 651 | } else { |
642 | if ( opaqueOldPos >= 0 ) | 652 | if ( opaqueOldPos >= 0 ) |
643 | paint.drawRect( r.x(), opaqueOldPos + sw/2 - rBord, | 653 | paint.drawRect( r.x(), opaqueOldPos + sw/2 - rBord, |
644 | r.width(), 2*rBord ); | 654 | r.width(), 2*rBord ); |
645 | if ( p >= 0 ) | 655 | if ( p >= 0 ) |
646 | paint.drawRect( r.x(), p + sw/2 - rBord, r.width(), 2*rBord ); | 656 | paint.drawRect( r.x(), p + sw/2 - rBord, r.width(), 2*rBord ); |
647 | } | 657 | } |
648 | opaqueOldPos = p; | 658 | opaqueOldPos = p; |
649 | } | 659 | } |
650 | 660 | ||
651 | 661 | ||
652 | /*! \reimp */ | 662 | /*! \reimp */ |
653 | bool KDGanttMinimizeSplitter::event( QEvent *e ) | 663 | bool KDGanttMinimizeSplitter::event( QEvent *e ) |
654 | { | 664 | { |
655 | if ( e->type() == QEvent::LayoutHint || ( e->type() == QEvent::Show && data->firstShow ) ) { | 665 | if ( e->type() == QEvent::LayoutHint || ( e->type() == QEvent::Show && data->firstShow ) ) { |
656 | recalc( isVisible() ); | 666 | recalc( isVisible() ); |
657 | if ( e->type() == QEvent::Show ) | 667 | if ( e->type() == QEvent::Show ) |
658 | data->firstShow = FALSE; | 668 | data->firstShow = FALSE; |
659 | } | 669 | } |
660 | return QWidget::event( e ); | 670 | return QWidget::event( e ); |
661 | } | 671 | } |
662 | 672 | ||
663 | 673 | ||
664 | /*! | 674 | /*! |
665 | \obsolete | 675 | \obsolete |
666 | 676 | ||
667 | Draws the splitter handle in the rectangle described by \a x, \a y, | 677 | Draws the splitter handle in the rectangle described by \a x, \a y, |
668 | \a w, \a h using painter \a p. | 678 | \a w, \a h using painter \a p. |
669 | \sa QStyle::drawPrimitive() | 679 | \sa QStyle::drawPrimitive() |
670 | */ | 680 | */ |
671 | void KDGanttMinimizeSplitter::drawSplitter( QPainter *p, | 681 | void KDGanttMinimizeSplitter::drawSplitter( QPainter *p, |
672 | QCOORD x, QCOORD y, QCOORD w, QCOORD h ) | 682 | QCOORD x, QCOORD y, QCOORD w, QCOORD h ) |
673 | { | 683 | { |
674 | #if 0 | 684 | #if 0 |
675 | // LR | 685 | // LR |
676 | style().drawPrimitive(QStyle::PE_Splitter, p, QRect(x, y, w, h), colorGroup(), | 686 | style().drawPrimitive(QStyle::PE_Splitter, p, QRect(x, y, w, h), colorGroup(), |
677 | (orientation() == Qt::Horizontal ? | 687 | (orientation() == Qt::Horizontal ? |
678 | QStyle::Style_Horizontal : 0)); | 688 | QStyle::Style_Horizontal : 0)); |
679 | #endif | 689 | #endif |
680 | } | 690 | } |
681 | 691 | ||
682 | 692 | ||
683 | /*! | 693 | /*! |
684 | Returns the id of the splitter to the right of or below the widget \a w, | 694 | Returns the id of the splitter to the right of or below the widget \a w, |
685 | or 0 if there is no such splitter | 695 | or 0 if there is no such splitter |
686 | (i.e. it is either not in this KDGanttMinimizeSplitter or it is at the end). | 696 | (i.e. it is either not in this KDGanttMinimizeSplitter or it is at the end). |
687 | */ | 697 | */ |
688 | int KDGanttMinimizeSplitter::idAfter( QWidget* w ) const | 698 | int KDGanttMinimizeSplitter::idAfter( QWidget* w ) const |
689 | { | 699 | { |
690 | QSplitterLayoutStruct *s = data->list.first(); | 700 | QSplitterLayoutStruct *s = data->list.first(); |
691 | bool seen_w = FALSE; | 701 | bool seen_w = FALSE; |
692 | while ( s ) { | 702 | while ( s ) { |
693 | if ( s->isSplitter && seen_w ) | 703 | if ( s->isSplitter && seen_w ) |
694 | return data->list.at(); | 704 | return data->list.at(); |
695 | if ( !s->isSplitter && s->wid == w ) | 705 | if ( !s->isSplitter && s->wid == w ) |
696 | seen_w = TRUE; | 706 | seen_w = TRUE; |
697 | s = data->list.next(); | 707 | s = data->list.next(); |
698 | } | 708 | } |
699 | return 0; | 709 | return 0; |
700 | } | 710 | } |
701 | 711 | ||
702 | 712 | ||
703 | /*! | 713 | /*! |
704 | Moves the left/top edge of the splitter handle with id \a id as | 714 | Moves the left/top edge of the splitter handle with id \a id as |
705 | close as possible to position \a p, which is the distance from the | 715 | close as possible to position \a p, which is the distance from the |
706 | left (or top) edge of the widget. | 716 | left (or top) edge of the widget. |
707 | 717 | ||
708 | For Arabic and Hebrew the layout is reversed, and using this | 718 | For Arabic and Hebrew the layout is reversed, and using this |
709 | function to set the position of the splitter might lead to | 719 | function to set the position of the splitter might lead to |
710 | unexpected results, since in Arabic and Hebrew the position of | 720 | unexpected results, since in Arabic and Hebrew the position of |
711 | splitter one is to the left of the position of splitter zero. | 721 | splitter one is to the left of the position of splitter zero. |
712 | 722 | ||
713 | \sa idAfter() | 723 | \sa idAfter() |
714 | */ | 724 | */ |
715 | void KDGanttMinimizeSplitter::moveSplitter( QCOORD p, int id ) | 725 | void KDGanttMinimizeSplitter::moveSplitter( QCOORD p, int id ) |
716 | { | 726 | { |
717 | p = adjustPos( p, id ); | 727 | p = adjustPos( p, id ); |
718 | QSplitterLayoutStruct *s = data->list.at(id); | 728 | QSplitterLayoutStruct *s = data->list.at(id); |
719 | int oldP = orient == Horizontal ? s->wid->x() : s->wid->y(); | 729 | int oldP = orient == Horizontal ? s->wid->x() : s->wid->y(); |
720 | bool upLeft; | 730 | bool upLeft; |
721 | if ( false && orient == Horizontal ) { | 731 | if ( false && orient == Horizontal ) { |
722 | p += s->wid->width(); | 732 | p += s->wid->width(); |
723 | upLeft = p > oldP; | 733 | upLeft = p > oldP; |
724 | } else | 734 | } else |
725 | upLeft = p < oldP; | 735 | upLeft = p < oldP; |
726 | 736 | ||
727 | moveAfter( p, id, upLeft ); | 737 | moveAfter( p, id, upLeft ); |
728 | moveBefore( p-1, id-1, upLeft ); | 738 | moveBefore( p-1, id-1, upLeft ); |
729 | 739 | ||
730 | storeSizes(); | 740 | storeSizes(); |
731 | } | 741 | } |
732 | 742 | ||
733 | 743 | ||
734 | void KDGanttMinimizeSplitter::setG( QWidget *w, int p, int s, bool isSplitter ) | 744 | void KDGanttMinimizeSplitter::setG( QWidget *w, int p, int s, bool isSplitter ) |
735 | { | 745 | { |
736 | if ( orient == Horizontal ) { | 746 | if ( orient == Horizontal ) { |
737 | if ( false && orient == Horizontal && !isSplitter ) | 747 | if ( false && orient == Horizontal && !isSplitter ) |
738 | p = contentsRect().width() - p - s; | 748 | p = contentsRect().width() - p - s; |