Diffstat (limited to 'microkde/KDGanttMinimizeSplitter.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | microkde/KDGanttMinimizeSplitter.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/microkde/KDGanttMinimizeSplitter.cpp b/microkde/KDGanttMinimizeSplitter.cpp index 84edc0d..c60b566 100644 --- a/microkde/KDGanttMinimizeSplitter.cpp +++ b/microkde/KDGanttMinimizeSplitter.cpp | |||
@@ -59,139 +59,141 @@ | |||
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 | //setMaximumHeight( 5 ); // test only | 84 | //setMaximumHeight( 5 ); // test only |
84 | } | 85 | } |
85 | 86 | ||
86 | QSize KDGanttSplitterHandle::sizeHint() const | 87 | QSize KDGanttSplitterHandle::sizeHint() const |
87 | { | 88 | { |
88 | return mSizeHint; | 89 | return mSizeHint; |
89 | } | 90 | } |
90 | 91 | ||
91 | void KDGanttSplitterHandle::setOrientation( Qt::Orientation o ) | 92 | void KDGanttSplitterHandle::setOrientation( Qt::Orientation o ) |
92 | { | 93 | { |
93 | orient = o; | 94 | orient = o; |
94 | #ifndef QT_NO_CURSOR | 95 | #ifndef QT_NO_CURSOR |
95 | if ( o == KDGanttMinimizeSplitter::Horizontal ) | 96 | if ( o == KDGanttMinimizeSplitter::Horizontal ) |
96 | setCursor( splitHCursor ); | 97 | setCursor( splitHCursor ); |
97 | else | 98 | else |
98 | setCursor( splitVCursor ); | 99 | setCursor( splitVCursor ); |
99 | #endif | 100 | #endif |
100 | } | 101 | } |
101 | 102 | ||
102 | 103 | ||
103 | void KDGanttSplitterHandle::mouseMoveEvent( QMouseEvent *e ) | 104 | void KDGanttSplitterHandle::mouseMoveEvent( QMouseEvent *e ) |
104 | { | 105 | { |
105 | updateCursor( e->pos() ); | 106 | updateCursor( e->pos() ); |
106 | if ( !(e->state()&LeftButton) ) | 107 | if ( !(e->state()&LeftButton) ) |
107 | return; | 108 | return; |
108 | 109 | ||
109 | if ( _activeButton != 0) | 110 | if ( _activeButton != 0) |
110 | return; | 111 | return; |
111 | 112 | ||
112 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) | 113 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) |
113 | - mouseOffset; | 114 | - mouseOffset; |
114 | if ( true /*opaque()*/ ) { | 115 | if ( true /*opaque()*/ ) { |
115 | s->moveSplitter( pos, id() ); | 116 | s->moveSplitter( pos, id() ); |
116 | } else { | 117 | } else { |
117 | int min = pos; int max = pos; | 118 | int min = pos; int max = pos; |
118 | s->getRange( id(), &min, &max ); | 119 | s->getRange( id(), &min, &max ); |
119 | s->setRubberband( QMAX( min, QMIN(max, pos ))); | 120 | s->setRubberband( QMAX( min, QMIN(max, pos ))); |
120 | } | 121 | } |
121 | _collapsed = false; | 122 | _collapsed = false; |
122 | } | 123 | } |
123 | 124 | ||
124 | void KDGanttSplitterHandle::mousePressEvent( QMouseEvent *e ) | 125 | void KDGanttSplitterHandle::mousePressEvent( QMouseEvent *e ) |
125 | { | 126 | { |
126 | if ( e->button() == LeftButton ) { | 127 | if ( e->button() == LeftButton ) { |
127 | _activeButton = onButton( e->pos() ); | 128 | _activeButton = onButton( e->pos() ); |
128 | mouseOffset = s->pick(e->pos()); | 129 | mouseOffset = s->pick(e->pos()); |
129 | if ( _activeButton != 0) | 130 | mMouseDown = true; |
130 | repaint(); | 131 | repaint(); |
131 | updateCursor( e->pos() ); | 132 | updateCursor( e->pos() ); |
132 | } | 133 | } |
133 | } | 134 | } |
134 | 135 | ||
135 | void KDGanttSplitterHandle::updateCursor( const QPoint& p) | 136 | void KDGanttSplitterHandle::updateCursor( const QPoint& p) |
136 | { | 137 | { |
137 | if ( onButton( p ) != 0 ) { | 138 | if ( onButton( p ) != 0 ) { |
138 | setCursor( arrowCursor ); | 139 | setCursor( arrowCursor ); |
139 | } | 140 | } |
140 | else { | 141 | else { |
141 | if ( orient == KDGanttMinimizeSplitter::Horizontal ) | 142 | if ( orient == KDGanttMinimizeSplitter::Horizontal ) |
142 | setCursor( splitHCursor ); | 143 | setCursor( splitHCursor ); |
143 | else | 144 | else |
144 | setCursor( splitVCursor ); | 145 | setCursor( splitVCursor ); |
145 | } | 146 | } |
146 | } | 147 | } |
147 | void KDGanttSplitterHandle::toggle() | 148 | void KDGanttSplitterHandle::toggle() |
148 | { | 149 | { |
149 | int pos; | 150 | int pos; |
150 | int min, max; | 151 | int min, max; |
151 | if ( !_collapsed ) { | 152 | if ( !_collapsed ) { |
152 | s->expandPos( id(), &min, &max ); | 153 | s->expandPos( id(), &min, &max ); |
153 | if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left | 154 | if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left |
154 | || s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) { | 155 | || s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) { |
155 | pos = min; | 156 | pos = min; |
156 | } | 157 | } |
157 | else { | 158 | else { |
158 | pos = max; | 159 | pos = max; |
159 | } | 160 | } |
160 | 161 | ||
161 | _origPos = s->pick(mapToParent( QPoint( 0,0 ) )); | 162 | _origPos = s->pick(mapToParent( QPoint( 0,0 ) )); |
162 | s->moveSplitter( pos, id() ); | 163 | s->moveSplitter( pos, id() ); |
163 | _collapsed = true; | 164 | _collapsed = true; |
164 | } | 165 | } |
165 | else { | 166 | else { |
166 | s->moveSplitter( _origPos, id() ); | 167 | s->moveSplitter( _origPos, id() ); |
167 | _collapsed = false; | 168 | _collapsed = false; |
168 | } | 169 | } |
169 | repaint(); | 170 | repaint(); |
170 | } | 171 | } |
171 | 172 | ||
172 | void KDGanttSplitterHandle::mouseReleaseEvent( QMouseEvent *e ) | 173 | void KDGanttSplitterHandle::mouseReleaseEvent( QMouseEvent *e ) |
173 | { | 174 | { |
175 | mMouseDown = false; | ||
174 | if ( _activeButton != 0 ) { | 176 | if ( _activeButton != 0 ) { |
175 | if ( onButton( e->pos() ) == _activeButton ) | 177 | if ( onButton( e->pos() ) == _activeButton ) |
176 | { | 178 | { |
177 | toggle(); | 179 | toggle(); |
178 | } | 180 | } |
179 | _activeButton = 0; | 181 | _activeButton = 0; |
180 | updateCursor( e->pos() ); | 182 | updateCursor( e->pos() ); |
181 | } | 183 | } |
182 | else { | 184 | else { |
183 | if ( !opaque() && e->button() == LeftButton ) { | 185 | if ( !opaque() && e->button() == LeftButton ) { |
184 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) | 186 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) |
185 | - mouseOffset; | 187 | - mouseOffset; |
186 | s->setRubberband( -1 ); | 188 | s->setRubberband( -1 ); |
187 | s->moveSplitter( pos, id() ); | 189 | s->moveSplitter( pos, id() ); |
188 | } | 190 | } |
189 | } | 191 | } |
190 | repaint(); | 192 | repaint(); |
191 | } | 193 | } |
192 | 194 | ||
193 | int KDGanttSplitterHandle::onButton( const QPoint& p ) | 195 | int KDGanttSplitterHandle::onButton( const QPoint& p ) |
194 | { | 196 | { |
195 | QValueList<QPointArray> list = buttonRegions(); | 197 | QValueList<QPointArray> list = buttonRegions(); |
196 | int index = 1; | 198 | int index = 1; |
197 | int add = 12; | 199 | int add = 12; |
@@ -256,50 +258,54 @@ QValueList<QPointArray> KDGanttSplitterHandle::buttonRegions() | |||
256 | } | 258 | } |
257 | return list; | 259 | return list; |
258 | } | 260 | } |
259 | 261 | ||
260 | void KDGanttSplitterHandle::paintEvent( QPaintEvent * ) | 262 | void KDGanttSplitterHandle::paintEvent( QPaintEvent * ) |
261 | { | 263 | { |
262 | QPixmap buffer( size() ); | 264 | QPixmap buffer( size() ); |
263 | QPainter p( &buffer ); | 265 | QPainter p( &buffer ); |
264 | 266 | ||
265 | //LR | 267 | //LR |
266 | // Draw the splitter rectangle | 268 | // Draw the splitter rectangle |
267 | p.setBrush( colorGroup().background() ); | 269 | p.setBrush( colorGroup().background() ); |
268 | p.setPen( colorGroup().foreground() ); | 270 | p.setPen( colorGroup().foreground() ); |
269 | //p.drawRect( rect() ); | 271 | //p.drawRect( rect() ); |
270 | buffer.fill( colorGroup().background() ); | 272 | buffer.fill( colorGroup().background() ); |
271 | //buffer.fill( backgroundColor() ); | 273 | //buffer.fill( backgroundColor() ); |
272 | // parentWidget()->style().drawPrimitive( QStyle::PE_Panel, &p, rect(), parentWidget()->colorGroup()); | 274 | // parentWidget()->style().drawPrimitive( QStyle::PE_Panel, &p, rect(), parentWidget()->colorGroup()); |
273 | 275 | ||
274 | int sw = 8; // Hardcoded, given I didn't use styles anymore, I didn't like to use their size | 276 | int sw = 8; // Hardcoded, given I didn't use styles anymore, I didn't like to use their size |
275 | 277 | ||
276 | // arrow color | 278 | // arrow color |
277 | QColor col; | 279 | QColor col; |
278 | if ( _activeButton ) | 280 | if ( _activeButton ) |
279 | col = colorGroup().background().dark( 250 ); | 281 | col = colorGroup().background().dark( 250 ); |
280 | else | 282 | else { |
281 | col = colorGroup().background().dark( 150 ); | 283 | if ( mMouseDown ) |
284 | col = Qt::white; | ||
285 | else | ||
286 | col = colorGroup().background().dark( 150 ); | ||
287 | } | ||
282 | //QColor col = backgroundColor().dark( 130 ); | 288 | //QColor col = backgroundColor().dark( 130 ); |
283 | p.setBrush( col ); | 289 | p.setBrush( col ); |
284 | p.setPen( col ); | 290 | p.setPen( col ); |
285 | 291 | ||
286 | QValueList<QPointArray> list = buttonRegions(); | 292 | QValueList<QPointArray> list = buttonRegions(); |
287 | int index = 1; | 293 | int index = 1; |
288 | if ( mUseOffset ) | 294 | if ( mUseOffset ) |
289 | p.translate( 0, 1 ); | 295 | p.translate( 0, 1 ); |
290 | for ( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { | 296 | for ( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { |
291 | if ( index == _activeButton ) { | 297 | if ( index == _activeButton ) { |
292 | 298 | ||
293 | /* | 299 | /* |
294 | if ( ! _collapsed ) { | 300 | if ( ! _collapsed ) { |
295 | p.save(); | 301 | p.save(); |
296 | // p.translate( parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftHorizontal ), | 302 | // p.translate( parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftHorizontal ), |
297 | // parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftVertical ) ); | 303 | // parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftVertical ) ); |
298 | p.translate( -1, 0 ); | 304 | p.translate( -1, 0 ); |
299 | p.drawPolygon( *it, true ); | 305 | p.drawPolygon( *it, true ); |
300 | p.restore(); } else | 306 | p.restore(); } else |
301 | */ | 307 | */ |
302 | p.drawPolygon( *it, true ); | 308 | p.drawPolygon( *it, true ); |
303 | 309 | ||
304 | } | 310 | } |
305 | else { | 311 | else { |