author | zautrix <zautrix> | 2005-04-21 12:32:52 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-04-21 12:32:52 (UTC) |
commit | 0a13a3490ec3bf4735e3435f80f58fa7d50b4448 (patch) (unidiff) | |
tree | c7f28c49b52e479f47da0dce9f0bfe9189ecdca4 | |
parent | 4d96d7b681ce99d76746a843c289b75f5e7dba64 (diff) | |
download | kdepimpi-0a13a3490ec3bf4735e3435f80f58fa7d50b4448.zip kdepimpi-0a13a3490ec3bf4735e3435f80f58fa7d50b4448.tar.gz kdepimpi-0a13a3490ec3bf4735e3435f80f58fa7d50b4448.tar.bz2 |
rubberband fix
-rw-r--r-- | korganizer/komonthview.cpp | 2 | ||||
-rw-r--r-- | microkde/KDGanttMinimizeSplitter.cpp | 21 | ||||
-rw-r--r-- | microkde/KDGanttMinimizeSplitter.h | 5 |
3 files changed, 22 insertions, 6 deletions
diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp index 7927307..8ee1363 100644 --- a/korganizer/komonthview.cpp +++ b/korganizer/komonthview.cpp | |||
@@ -1,2086 +1,2086 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KOrganizer. | 2 | This file is part of KOrganizer. |
3 | Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | #include <qpopupmenu.h> | 20 | #include <qpopupmenu.h> |
21 | #include <qfont.h> | 21 | #include <qfont.h> |
22 | #include <qfontmetrics.h> | 22 | #include <qfontmetrics.h> |
23 | #include <qkeycode.h> | 23 | #include <qkeycode.h> |
24 | #include <qhbox.h> | 24 | #include <qhbox.h> |
25 | #include <qvbox.h> | 25 | #include <qvbox.h> |
26 | #include <qwidgetstack.h> | 26 | #include <qwidgetstack.h> |
27 | #include <qpushbutton.h> | 27 | #include <qpushbutton.h> |
28 | #include <qtooltip.h> | 28 | #include <qtooltip.h> |
29 | #include <qpainter.h> | 29 | #include <qpainter.h> |
30 | #include <qtimer.h> | 30 | #include <qtimer.h> |
31 | #include <qwhatsthis.h> | 31 | #include <qwhatsthis.h> |
32 | #ifndef DESKTOP_VERSION | 32 | #ifndef DESKTOP_VERSION |
33 | #include <qpe/qpeapplication.h> | 33 | #include <qpe/qpeapplication.h> |
34 | #else | 34 | #else |
35 | #include <qapplication.h> | 35 | #include <qapplication.h> |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | #include <kdebug.h> | 38 | #include <kdebug.h> |
39 | #include <klocale.h> | 39 | #include <klocale.h> |
40 | #include <kglobal.h> | 40 | #include <kglobal.h> |
41 | #include <kconfig.h> | 41 | #include <kconfig.h> |
42 | #include <kiconloader.h> | 42 | #include <kiconloader.h> |
43 | 43 | ||
44 | #include <kcalendarsystem.h> | 44 | #include <kcalendarsystem.h> |
45 | 45 | ||
46 | #ifndef KORG_NOPRINTER | 46 | #ifndef KORG_NOPRINTER |
47 | #include "calprinter.h" | 47 | #include "calprinter.h" |
48 | #endif | 48 | #endif |
49 | #include "koprefs.h" | 49 | #include "koprefs.h" |
50 | #ifndef KORG_NOPLUGINS | 50 | #ifndef KORG_NOPLUGINS |
51 | #include "kocore.h" | 51 | #include "kocore.h" |
52 | #endif | 52 | #endif |
53 | #include "koglobals.h" | 53 | #include "koglobals.h" |
54 | #include <libkcal/kincidenceformatter.h> | 54 | #include <libkcal/kincidenceformatter.h> |
55 | 55 | ||
56 | #include "komonthview.h" | 56 | #include "komonthview.h" |
57 | 57 | ||
58 | #define PIXMAP_SIZE 5 | 58 | #define PIXMAP_SIZE 5 |
59 | #ifdef DESKTOP_VERSION | 59 | #ifdef DESKTOP_VERSION |
60 | QToolTipGroup *MonthViewCell::mToolTipGroup = 0; | 60 | QToolTipGroup *MonthViewCell::mToolTipGroup = 0; |
61 | #endif | 61 | #endif |
62 | class KNOWhatsThis :public QWhatsThis | 62 | class KNOWhatsThis :public QWhatsThis |
63 | { | 63 | { |
64 | public: | 64 | public: |
65 | KNOWhatsThis( KNoScrollListBox* sbox ) : QWhatsThis( sbox ), _wid( sbox) { }; | 65 | KNOWhatsThis( KNoScrollListBox* sbox ) : QWhatsThis( sbox ), _wid( sbox) { }; |
66 | //~KNOWhatsThis( ) {qDebug("~KNOWhatsThis( ) "); }; | 66 | //~KNOWhatsThis( ) {qDebug("~KNOWhatsThis( ) "); }; |
67 | 67 | ||
68 | protected: | 68 | protected: |
69 | virtual QString text( const QPoint& p) | 69 | virtual QString text( const QPoint& p) |
70 | { | 70 | { |
71 | return _wid->getWhatsThisText(p) ; | 71 | return _wid->getWhatsThisText(p) ; |
72 | }; | 72 | }; |
73 | private: | 73 | private: |
74 | KNoScrollListBox* _wid; | 74 | KNoScrollListBox* _wid; |
75 | 75 | ||
76 | }; | 76 | }; |
77 | 77 | ||
78 | 78 | ||
79 | KNoScrollListBox::KNoScrollListBox(QWidget *parent,const char *name) | 79 | KNoScrollListBox::KNoScrollListBox(QWidget *parent,const char *name) |
80 | : QListBox(parent, name, WRepaintNoErase) | 80 | : QListBox(parent, name, WRepaintNoErase) |
81 | { | 81 | { |
82 | #ifndef DESKTOP_VERSION | 82 | #ifndef DESKTOP_VERSION |
83 | QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); | 83 | QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); |
84 | #endif | 84 | #endif |
85 | mWT = new KNOWhatsThis(this); | 85 | mWT = new KNOWhatsThis(this); |
86 | resetOnFocusIn = true; | 86 | resetOnFocusIn = true; |
87 | setVScrollBarMode(QScrollView::AlwaysOff); | 87 | setVScrollBarMode(QScrollView::AlwaysOff); |
88 | setHScrollBarMode(QScrollView::AlwaysOff); | 88 | setHScrollBarMode(QScrollView::AlwaysOff); |
89 | } | 89 | } |
90 | KNoScrollListBox::~KNoScrollListBox() | 90 | KNoScrollListBox::~KNoScrollListBox() |
91 | { | 91 | { |
92 | #if QT_VERSION >= 0x030000 | 92 | #if QT_VERSION >= 0x030000 |
93 | 93 | ||
94 | #else | 94 | #else |
95 | delete mWT; | 95 | delete mWT; |
96 | #endif | 96 | #endif |
97 | } | 97 | } |
98 | 98 | ||
99 | 99 | ||
100 | void KNoScrollListBox::focusInEvent ( QFocusEvent * e ) | 100 | void KNoScrollListBox::focusInEvent ( QFocusEvent * e ) |
101 | { | 101 | { |
102 | QListBox::focusInEvent ( e ); | 102 | QListBox::focusInEvent ( e ); |
103 | if ( count() ){ | 103 | if ( count() ){ |
104 | int ci = currentItem(); | 104 | int ci = currentItem(); |
105 | if ( ci < 0 ) ci = 0; | 105 | if ( ci < 0 ) ci = 0; |
106 | 106 | ||
107 | setCurrentItem( ci ); | 107 | setCurrentItem( ci ); |
108 | setSelected ( ci, true ); | 108 | setSelected ( ci, true ); |
109 | emit highlighted( item ( ci ) ); | 109 | emit highlighted( item ( ci ) ); |
110 | 110 | ||
111 | resetOnFocusIn = true; | 111 | resetOnFocusIn = true; |
112 | 112 | ||
113 | if ( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) { | 113 | if ( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) { |
114 | QListBoxItem *fi = firstItem (); | 114 | QListBoxItem *fi = firstItem (); |
115 | if (fi ) { | 115 | if (fi ) { |
116 | int ihei = fi->height( this ); | 116 | int ihei = fi->height( this ); |
117 | int hei = numRows () * ihei; | 117 | int hei = numRows () * ihei; |
118 | if ( hei < height() - horizontalScrollBar()->height () ) { | 118 | if ( hei < height() - horizontalScrollBar()->height () ) { |
119 | setVScrollBarMode(QScrollView::AlwaysOff); | 119 | setVScrollBarMode(QScrollView::AlwaysOff); |
120 | } | 120 | } |
121 | else | 121 | else |
122 | setVScrollBarMode(QScrollView::Auto); | 122 | setVScrollBarMode(QScrollView::Auto); |
123 | if ( ihei *3 > height() ) { | 123 | if ( ihei *3 > height() ) { |
124 | setHScrollBarMode(QScrollView::AlwaysOff); | 124 | setHScrollBarMode(QScrollView::AlwaysOff); |
125 | } | 125 | } |
126 | else { | 126 | else { |
127 | setHScrollBarMode(QScrollView::Auto); | 127 | setHScrollBarMode(QScrollView::Auto); |
128 | } | 128 | } |
129 | } else { | 129 | } else { |
130 | setVScrollBarMode(QScrollView::Auto); | 130 | setVScrollBarMode(QScrollView::Auto); |
131 | setHScrollBarMode(QScrollView::Auto); | 131 | setHScrollBarMode(QScrollView::Auto); |
132 | } | 132 | } |
133 | } | 133 | } |
134 | } | 134 | } |
135 | } | 135 | } |
136 | void KNoScrollListBox::focusOutEvent ( QFocusEvent * e ) | 136 | void KNoScrollListBox::focusOutEvent ( QFocusEvent * e ) |
137 | { | 137 | { |
138 | int i = currentItem (); | 138 | int i = currentItem (); |
139 | if ( i >= 0 ) { | 139 | if ( i >= 0 ) { |
140 | setSelected ( i, false ); | 140 | setSelected ( i, false ); |
141 | } | 141 | } |
142 | QListBox::focusOutEvent ( e ); | 142 | QListBox::focusOutEvent ( e ); |
143 | setVScrollBarMode(QScrollView::AlwaysOff); | 143 | setVScrollBarMode(QScrollView::AlwaysOff); |
144 | setHScrollBarMode(QScrollView::AlwaysOff); | 144 | setHScrollBarMode(QScrollView::AlwaysOff); |
145 | } | 145 | } |
146 | 146 | ||
147 | QString KNoScrollListBox::getWhatsThisText(QPoint p) | 147 | QString KNoScrollListBox::getWhatsThisText(QPoint p) |
148 | { | 148 | { |
149 | QListBoxItem* item = itemAt ( p ); | 149 | QListBoxItem* item = itemAt ( p ); |
150 | if ( ! item ) { | 150 | if ( ! item ) { |
151 | return i18n("Click in the cell\nto add an event!"); | 151 | return i18n("Click in the cell\nto add an event!"); |
152 | } | 152 | } |
153 | return KIncidenceFormatter::instance()->getFormattedText(((MonthViewItem*) item)->incidence(), | 153 | return KIncidenceFormatter::instance()->getFormattedText(((MonthViewItem*) item)->incidence(), |
154 | KOPrefs::instance()->mWTshowDetails, | 154 | KOPrefs::instance()->mWTshowDetails, |
155 | KOPrefs::instance()->mWTshowCreated, | 155 | KOPrefs::instance()->mWTshowCreated, |
156 | KOPrefs::instance()->mWTshowChanged); | 156 | KOPrefs::instance()->mWTshowChanged); |
157 | } | 157 | } |
158 | void KNoScrollListBox::keyPressEvent(QKeyEvent *e) | 158 | void KNoScrollListBox::keyPressEvent(QKeyEvent *e) |
159 | { | 159 | { |
160 | //qDebug("KNoScrollListBox::keyPressEvent "); | 160 | //qDebug("KNoScrollListBox::keyPressEvent "); |
161 | switch(e->key()) { | 161 | switch(e->key()) { |
162 | case Key_Right: | 162 | case Key_Right: |
163 | if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) | 163 | if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) |
164 | { | 164 | { |
165 | e->ignore(); | 165 | e->ignore(); |
166 | return; | 166 | return; |
167 | } | 167 | } |
168 | scrollBy(10,0); | 168 | scrollBy(10,0); |
169 | break; | 169 | break; |
170 | case Key_Left: | 170 | case Key_Left: |
171 | if (e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) | 171 | if (e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) |
172 | { | 172 | { |
173 | e->ignore(); | 173 | e->ignore(); |
174 | return; | 174 | return; |
175 | } | 175 | } |
176 | scrollBy(-10,0); | 176 | scrollBy(-10,0); |
177 | break; | 177 | break; |
178 | case Key_Up: | 178 | case Key_Up: |
179 | if( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { | 179 | if( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { |
180 | e->ignore(); | 180 | e->ignore(); |
181 | break; | 181 | break; |
182 | } | 182 | } |
183 | if ( count() ) { | 183 | if ( count() ) { |
184 | if ( currentItem() == 0 ) { | 184 | if ( currentItem() == 0 ) { |
185 | emit prevCell(); | 185 | emit prevCell(); |
186 | } else { | 186 | } else { |
187 | setCurrentItem((currentItem()+count()-1)%count()); | 187 | setCurrentItem((currentItem()+count()-1)%count()); |
188 | if(!itemVisible(currentItem())) { | 188 | if(!itemVisible(currentItem())) { |
189 | if((unsigned int) currentItem() == (count()-1)) { | 189 | if((unsigned int) currentItem() == (count()-1)) { |
190 | setTopItem(currentItem()-numItemsVisible()+1); | 190 | setTopItem(currentItem()-numItemsVisible()+1); |
191 | } else { | 191 | } else { |
192 | setTopItem(topItem()-1); | 192 | setTopItem(topItem()-1); |
193 | } | 193 | } |
194 | } | 194 | } |
195 | } | 195 | } |
196 | } | 196 | } |
197 | break; | 197 | break; |
198 | case Key_Down: | 198 | case Key_Down: |
199 | if(e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { | 199 | if(e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { |
200 | e->ignore(); | 200 | e->ignore(); |
201 | break; | 201 | break; |
202 | } | 202 | } |
203 | if ( count () ) { | 203 | if ( count () ) { |
204 | if ( currentItem()+1 == count () ) { | 204 | if ( currentItem()+1 == count () ) { |
205 | emit nextCell(); | 205 | emit nextCell(); |
206 | } else { | 206 | } else { |
207 | setCurrentItem((currentItem()+1)%count()); | 207 | setCurrentItem((currentItem()+1)%count()); |
208 | if(!itemVisible(currentItem())) { | 208 | if(!itemVisible(currentItem())) { |
209 | if(currentItem() == 0) { | 209 | if(currentItem() == 0) { |
210 | setTopItem(0); | 210 | setTopItem(0); |
211 | } else { | 211 | } else { |
212 | setTopItem(topItem()+1); | 212 | setTopItem(topItem()+1); |
213 | } | 213 | } |
214 | } | 214 | } |
215 | } | 215 | } |
216 | } | 216 | } |
217 | break; | 217 | break; |
218 | case Key_I: | 218 | case Key_I: |
219 | QTimer::singleShot( 1, this, SLOT ( oneDown() ) ); | 219 | QTimer::singleShot( 1, this, SLOT ( oneDown() ) ); |
220 | e->ignore(); | 220 | e->ignore(); |
221 | break; | 221 | break; |
222 | case Key_Return: | 222 | case Key_Return: |
223 | case Key_Enter: | 223 | case Key_Enter: |
224 | { | 224 | { |
225 | if ( currentItem() >= 0 ) { | 225 | if ( currentItem() >= 0 ) { |
226 | emit doubleClicked( item( currentItem() ) ); | 226 | emit doubleClicked( item( currentItem() ) ); |
227 | e->accept(); | 227 | e->accept(); |
228 | } else { | 228 | } else { |
229 | e->ignore(); | 229 | e->ignore(); |
230 | } | 230 | } |
231 | } | 231 | } |
232 | break; | 232 | break; |
233 | case Key_Shift: | 233 | case Key_Shift: |
234 | emit shiftDown(); | 234 | emit shiftDown(); |
235 | break; | 235 | break; |
236 | default: | 236 | default: |
237 | e->ignore(); | 237 | e->ignore(); |
238 | break; | 238 | break; |
239 | } | 239 | } |
240 | } | 240 | } |
241 | 241 | ||
242 | void KNoScrollListBox::oneDown() | 242 | void KNoScrollListBox::oneDown() |
243 | { | 243 | { |
244 | if ( count () ) { | 244 | if ( count () ) { |
245 | if ( currentItem()+1 == count () ) { | 245 | if ( currentItem()+1 == count () ) { |
246 | emit nextCell(); | 246 | emit nextCell(); |
247 | } else { | 247 | } else { |
248 | resetOnFocusIn = false; | 248 | resetOnFocusIn = false; |
249 | setCurrentItem((currentItem()+1)%count()); | 249 | setCurrentItem((currentItem()+1)%count()); |
250 | if(!itemVisible(currentItem())) { | 250 | if(!itemVisible(currentItem())) { |
251 | if(currentItem() == 0) { | 251 | if(currentItem() == 0) { |
252 | setTopItem(0); | 252 | setTopItem(0); |
253 | } else { | 253 | } else { |
254 | setTopItem(topItem()+1); | 254 | setTopItem(topItem()+1); |
255 | } | 255 | } |
256 | } | 256 | } |
257 | } | 257 | } |
258 | } | 258 | } |
259 | } | 259 | } |
260 | void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e) | 260 | void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e) |
261 | { | 261 | { |
262 | switch(e->key()) { | 262 | switch(e->key()) { |
263 | case Key_Shift: | 263 | case Key_Shift: |
264 | emit shiftUp(); | 264 | emit shiftUp(); |
265 | break; | 265 | break; |
266 | default: | 266 | default: |
267 | break; | 267 | break; |
268 | } | 268 | } |
269 | } | 269 | } |
270 | 270 | ||
271 | void KNoScrollListBox::mousePressEvent(QMouseEvent *e) | 271 | void KNoScrollListBox::mousePressEvent(QMouseEvent *e) |
272 | { | 272 | { |
273 | QListBox::mousePressEvent(e); | 273 | QListBox::mousePressEvent(e); |
274 | 274 | ||
275 | if(e->button() == RightButton) { | 275 | if(e->button() == RightButton) { |
276 | emit rightClick(); | 276 | emit rightClick(); |
277 | } | 277 | } |
278 | } | 278 | } |
279 | 279 | ||
280 | MonthViewItem::MonthViewItem( Incidence *incidence, QDate qd, const QString & s) | 280 | MonthViewItem::MonthViewItem( Incidence *incidence, QDate qd, const QString & s) |
281 | : QListBoxItem() | 281 | : QListBoxItem() |
282 | { | 282 | { |
283 | mblockRepaint = true; | 283 | mblockRepaint = true; |
284 | setText( s ); | 284 | setText( s ); |
285 | mMultiday = 0; | 285 | mMultiday = 0; |
286 | mIncidence = incidence; | 286 | mIncidence = incidence; |
287 | mDate = qd; | 287 | mDate = qd; |
288 | mRecur = false; | 288 | mRecur = false; |
289 | mAlarm = false; | 289 | mAlarm = false; |
290 | mReply = false; | 290 | mReply = false; |
291 | mInfo = false; | 291 | mInfo = false; |
292 | mdayPos = 0; | 292 | mdayPos = 0; |
293 | isWeekItem = KOPrefs::instance()->mMonthViewWeek; | 293 | isWeekItem = KOPrefs::instance()->mMonthViewWeek; |
294 | } | 294 | } |
295 | void MonthViewItem::recycle( Incidence *incidence, QDate qd, const QString & s) | 295 | void MonthViewItem::recycle( Incidence *incidence, QDate qd, const QString & s) |
296 | { | 296 | { |
297 | setText( s ); | 297 | setText( s ); |
298 | mMultiday = 0; | 298 | mMultiday = 0; |
299 | mIncidence = incidence; | 299 | mIncidence = incidence; |
300 | mDate = qd; | 300 | mDate = qd; |
301 | mRecur = false; | 301 | mRecur = false; |
302 | mAlarm = false; | 302 | mAlarm = false; |
303 | mReply = false; | 303 | mReply = false; |
304 | mInfo = false; | 304 | mInfo = false; |
305 | mdayPos = 0; | 305 | mdayPos = 0; |
306 | } | 306 | } |
307 | 307 | ||
308 | void MonthViewItem::paint(QPainter *p) | 308 | void MonthViewItem::paint(QPainter *p) |
309 | { | 309 | { |
310 | if ( mblockRepaint ) { | 310 | if ( mblockRepaint ) { |
311 | return; | 311 | return; |
312 | } | 312 | } |
313 | #if QT_VERSION >= 0x030000 | 313 | #if QT_VERSION >= 0x030000 |
314 | bool sel = isSelected(); | 314 | bool sel = isSelected(); |
315 | #else | 315 | #else |
316 | bool sel = selected(); | 316 | bool sel = selected(); |
317 | #endif | 317 | #endif |
318 | 318 | ||
319 | 319 | ||
320 | if (KOPrefs::instance()->mMonthViewUsesCategoryColor) | 320 | if (KOPrefs::instance()->mMonthViewUsesCategoryColor) |
321 | { | 321 | { |
322 | p->setBackgroundColor( palette().color( QPalette::Normal, \ | 322 | p->setBackgroundColor( palette().color( QPalette::Normal, \ |
323 | sel ? QColorGroup::Highlight : QColorGroup::Background ) ); | 323 | sel ? QColorGroup::Highlight : QColorGroup::Background ) ); |
324 | p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) ); | 324 | p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) ); |
325 | } | 325 | } |
326 | int x = 1; | 326 | int x = 1; |
327 | //int y = 3;//(height() - mRecurPixmap.height()) /2; | 327 | //int y = 3;//(height() - mRecurPixmap.height()) /2; |
328 | int size = PIXMAP_SIZE; | 328 | int size = PIXMAP_SIZE; |
329 | if ( QApplication::desktop()->width() < 300 ) | 329 | if ( QApplication::desktop()->width() < 300 ) |
330 | size = 3; | 330 | size = 3; |
331 | int heihei = height( listBox () ); | 331 | int heihei = height( listBox () ); |
332 | int y = (heihei - size -1 ) /2; | 332 | int y = (heihei - size -1 ) /2; |
333 | 333 | ||
334 | if ( KOPrefs::instance()->mMonthShowIcons ) { | 334 | if ( KOPrefs::instance()->mMonthShowIcons ) { |
335 | if ( mInfo ) { | 335 | if ( mInfo ) { |
336 | p->fillRect ( x, y,size,size, Qt::darkGreen ); | 336 | p->fillRect ( x, y,size,size, Qt::darkGreen ); |
337 | x += size + 1; | 337 | x += size + 1; |
338 | } | 338 | } |
339 | if ( mRecur ) { | 339 | if ( mRecur ) { |
340 | p->fillRect ( x, y,size,size, Qt::blue ); | 340 | p->fillRect ( x, y,size,size, Qt::blue ); |
341 | x += size + 1; | 341 | x += size + 1; |
342 | } | 342 | } |
343 | if ( mAlarm ) { | 343 | if ( mAlarm ) { |
344 | p->fillRect ( x, y,size,size, Qt::red ); | 344 | p->fillRect ( x, y,size,size, Qt::red ); |
345 | x += size + 1; | 345 | x += size + 1; |
346 | } | 346 | } |
347 | if ( mReply ) { | 347 | if ( mReply ) { |
348 | p->fillRect ( x, y,size,size, Qt::yellow ); | 348 | p->fillRect ( x, y,size,size, Qt::yellow ); |
349 | x += size + 1; | 349 | x += size + 1; |
350 | } | 350 | } |
351 | } | 351 | } |
352 | if ( mMultiday ) { | 352 | if ( mMultiday ) { |
353 | int yyy = y+(size/2); | 353 | int yyy = y+(size/2); |
354 | int sizeM = size+2; | 354 | int sizeM = size+2; |
355 | p->setBrush( QBrush::SolidPattern ); | 355 | p->setBrush( QBrush::SolidPattern ); |
356 | p->drawLine ( x+1, yyy, x +sizeM +sizeM/2-1, yyy ) ; | 356 | p->drawLine ( x+1, yyy, x +sizeM +sizeM/2-1, yyy ) ; |
357 | if ( mMultiday == 2 || mMultiday == 3 ) { | 357 | if ( mMultiday == 2 || mMultiday == 3 ) { |
358 | QPointArray pa ( 3 ); | 358 | QPointArray pa ( 3 ); |
359 | pa.setPoint (0, x, yyy ); | 359 | pa.setPoint (0, x, yyy ); |
360 | pa.setPoint (1, x+sizeM/2, yyy+sizeM/2 ); | 360 | pa.setPoint (1, x+sizeM/2, yyy+sizeM/2 ); |
361 | pa.setPoint (2, x+sizeM/2, yyy-sizeM/2 ); | 361 | pa.setPoint (2, x+sizeM/2, yyy-sizeM/2 ); |
362 | p->drawPolygon( pa ); | 362 | p->drawPolygon( pa ); |
363 | } | 363 | } |
364 | if ( mMultiday == 2 || mMultiday == 1 ) { | 364 | if ( mMultiday == 2 || mMultiday == 1 ) { |
365 | QPointArray pa ( 3 ); | 365 | QPointArray pa ( 3 ); |
366 | pa.setPoint (0, x+sizeM +sizeM/2, yyy ); | 366 | pa.setPoint (0, x+sizeM +sizeM/2, yyy ); |
367 | pa.setPoint (1, x+sizeM, yyy+sizeM/2 ); | 367 | pa.setPoint (1, x+sizeM, yyy+sizeM/2 ); |
368 | pa.setPoint (2, x+sizeM, yyy-sizeM/2 ); | 368 | pa.setPoint (2, x+sizeM, yyy-sizeM/2 ); |
369 | p->drawPolygon( pa ); | 369 | p->drawPolygon( pa ); |
370 | } | 370 | } |
371 | if ( mMultiday == 1 ) { | 371 | if ( mMultiday == 1 ) { |
372 | // p->fillRect ( x, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) ); | 372 | // p->fillRect ( x, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) ); |
373 | 373 | ||
374 | p->drawLine ( x+1, yyy-sizeM/2, x+1, yyy+sizeM/2 ); | 374 | p->drawLine ( x+1, yyy-sizeM/2, x+1, yyy+sizeM/2 ); |
375 | } | 375 | } |
376 | if ( mMultiday == 3 ) { | 376 | if ( mMultiday == 3 ) { |
377 | // p->fillRect ( x+sizeM, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) ); | 377 | // p->fillRect ( x+sizeM, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) ); |
378 | p->drawLine ( x+sizeM +sizeM/2-1, yyy-sizeM/2, x+sizeM +sizeM/2-1, yyy+sizeM/2 ); | 378 | p->drawLine ( x+sizeM +sizeM/2-1, yyy-sizeM/2, x+sizeM +sizeM/2-1, yyy+sizeM/2 ); |
379 | 379 | ||
380 | } | 380 | } |
381 | x += sizeM/2 + 1; | 381 | x += sizeM/2 + 1; |
382 | x += sizeM + 1; | 382 | x += sizeM + 1; |
383 | } | 383 | } |
384 | 384 | ||
385 | if ( mIncidence->type() == "Todo" ){ | 385 | if ( mIncidence->type() == "Todo" ){ |
386 | Todo* td = ( Todo* ) mIncidence; | 386 | Todo* td = ( Todo* ) mIncidence; |
387 | if ( td->isCompleted() ) { | 387 | if ( td->isCompleted() ) { |
388 | int half = size/2; | 388 | int half = size/2; |
389 | p->drawLine ( x, heihei/2, x +half , heihei/2 +half ) ; | 389 | p->drawLine ( x, heihei/2, x +half , heihei/2 +half ) ; |
390 | p->drawLine ( x +half , heihei/2 +half , x +half+half +2 , heihei/2 -2 ) ; | 390 | p->drawLine ( x +half , heihei/2 +half , x +half+half +2 , heihei/2 -2 ) ; |
391 | x += half+half + 4; | 391 | x += half+half + 4; |
392 | 392 | ||
393 | } else { | 393 | } else { |
394 | int val = td->percentComplete()/20; | 394 | int val = td->percentComplete()/20; |
395 | p->fillRect ( x+1, y-2, val ,size+4,Qt::black ); | 395 | p->fillRect ( x+1, y-2, val ,size+4,Qt::black ); |
396 | p->drawRect ( x, y-2,7,size+4); | 396 | p->drawRect ( x, y-2,7,size+4); |
397 | x += size + 3; | 397 | x += size + 3; |
398 | } | 398 | } |
399 | } | 399 | } |
400 | QFontMetrics fm = p->fontMetrics(); | 400 | QFontMetrics fm = p->fontMetrics(); |
401 | int yPos; | 401 | int yPos; |
402 | int pmheight = size; | 402 | int pmheight = size; |
403 | if( pmheight < fm.height() ) | 403 | if( pmheight < fm.height() ) |
404 | yPos = fm.ascent() + fm.leading()/2; | 404 | yPos = fm.ascent() + fm.leading()/2; |
405 | else | 405 | else |
406 | yPos = pmheight/2 - fm.height()/2 + fm.ascent(); | 406 | yPos = pmheight/2 - fm.height()/2 + fm.ascent(); |
407 | p->setPen( palette().color( QPalette::Normal, sel ? \ | 407 | p->setPen( palette().color( QPalette::Normal, sel ? \ |
408 | QColorGroup::HighlightedText : QColorGroup::Foreground ) ); | 408 | QColorGroup::HighlightedText : QColorGroup::Foreground ) ); |
409 | if ( KOPrefs::instance()->mMonthShowTimes || isWeekItem) { | 409 | if ( KOPrefs::instance()->mMonthShowTimes || isWeekItem) { |
410 | p->drawText( x, yPos, text() ); | 410 | p->drawText( x, yPos, text() ); |
411 | if ( mIncidence->cancelled() ) { | 411 | if ( mIncidence->cancelled() ) { |
412 | int wid = fm.width( text() ); | 412 | int wid = fm.width( text() ); |
413 | p->drawLine( x, heihei/2 ,x+wid, heihei/2 ); | 413 | p->drawLine( x, heihei/2 ,x+wid, heihei/2 ); |
414 | } | 414 | } |
415 | } else { | 415 | } else { |
416 | QString pText = text(); | 416 | QString pText = text(); |
417 | if( pText.mid(2,1) == ":" ) | 417 | if( pText.mid(2,1) == ":" ) |
418 | pText = pText.mid( 6 ); | 418 | pText = pText.mid( 6 ); |
419 | p->drawText( x, yPos, pText ); | 419 | p->drawText( x, yPos, pText ); |
420 | if ( mIncidence->cancelled() ) { | 420 | if ( mIncidence->cancelled() ) { |
421 | int wid = fm.width( pText ); | 421 | int wid = fm.width( pText ); |
422 | p->drawLine( x, heihei/2 ,x+wid, heihei/2 ); | 422 | p->drawLine( x, heihei/2 ,x+wid, heihei/2 ); |
423 | } | 423 | } |
424 | } | 424 | } |
425 | } | 425 | } |
426 | 426 | ||
427 | int MonthViewItem::height(const QListBox *lb) const | 427 | int MonthViewItem::height(const QListBox *lb) const |
428 | { | 428 | { |
429 | int ret = 10; | 429 | int ret = 10; |
430 | if ( lb ) | 430 | if ( lb ) |
431 | ret = lb->fontMetrics().lineSpacing()+1; | 431 | ret = lb->fontMetrics().lineSpacing()+1; |
432 | return ret; | 432 | return ret; |
433 | } | 433 | } |
434 | 434 | ||
435 | int MonthViewItem::width(const QListBox *lb) const | 435 | int MonthViewItem::width(const QListBox *lb) const |
436 | { | 436 | { |
437 | if( KOPrefs::instance()->mEnableMonthScroll || isWeekItem ) { | 437 | if( KOPrefs::instance()->mEnableMonthScroll || isWeekItem ) { |
438 | int size = PIXMAP_SIZE; | 438 | int size = PIXMAP_SIZE; |
439 | if ( QApplication::desktop()->width() < 300 ) | 439 | if ( QApplication::desktop()->width() < 300 ) |
440 | size = 3; | 440 | size = 3; |
441 | int x = 1; | 441 | int x = 1; |
442 | if ( KOPrefs::instance()->mMonthShowIcons ) { | 442 | if ( KOPrefs::instance()->mMonthShowIcons ) { |
443 | if ( mInfo ) { | 443 | if ( mInfo ) { |
444 | x += size + 1; | 444 | x += size + 1; |
445 | } | 445 | } |
446 | if( mRecur ) { | 446 | if( mRecur ) { |
447 | x += size+1; | 447 | x += size+1; |
448 | } | 448 | } |
449 | if( mAlarm ) { | 449 | if( mAlarm ) { |
450 | x += size+1; | 450 | x += size+1; |
451 | } | 451 | } |
452 | if( mReply ) { | 452 | if( mReply ) { |
453 | x += size+1; | 453 | x += size+1; |
454 | } | 454 | } |
455 | } | 455 | } |
456 | if( mMultiday ) { | 456 | if( mMultiday ) { |
457 | x += size+1+2+size/2; | 457 | x += size+1+2+size/2; |
458 | } | 458 | } |
459 | return( x + lb->fontMetrics().width( text() ) + 1 ); | 459 | return( x + lb->fontMetrics().width( text() ) + 1 ); |
460 | } | 460 | } |
461 | if ( ! lb ) | 461 | if ( ! lb ) |
462 | return 10; | 462 | return 10; |
463 | return lb->width(); | 463 | return lb->width(); |
464 | } | 464 | } |
465 | 465 | ||
466 | 466 | ||
467 | MonthViewCell::MonthViewCell( KOMonthView *parent,QWidget* par ) | 467 | MonthViewCell::MonthViewCell( KOMonthView *parent,QWidget* par ) |
468 | : KNoScrollListBox( par ), | 468 | : KNoScrollListBox( par ), |
469 | mMonthView( parent ) | 469 | mMonthView( parent ) |
470 | { | 470 | { |
471 | //QVBoxLayout *topLayout = new QVBoxLayout( this ); | 471 | //QVBoxLayout *topLayout = new QVBoxLayout( this ); |
472 | currentPalette = 0; | 472 | currentPalette = 0; |
473 | // mLabel = new QLabel( this );QPushButton | 473 | // mLabel = new QLabel( this );QPushButton |
474 | mLabel = new QPushButton( this ); | 474 | mLabel = new QPushButton( this ); |
475 | //mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain ); | 475 | //mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain ); |
476 | //mLabel->setLineWidth( 1 ); | 476 | //mLabel->setLineWidth( 1 ); |
477 | //mLabel->setAlignment( AlignCenter ); | 477 | //mLabel->setAlignment( AlignCenter ); |
478 | mLabel->setFlat( true ); | 478 | mLabel->setFlat( true ); |
479 | mLabel->setFocusPolicy(NoFocus); | 479 | mLabel->setFocusPolicy(NoFocus); |
480 | //mItemList = new KNoScrollListBox( this ); | 480 | //mItemList = new KNoScrollListBox( this ); |
481 | setMinimumSize( 10, 10 ); | 481 | setMinimumSize( 10, 10 ); |
482 | setFrameStyle( QFrame::Panel | QFrame::Plain ); | 482 | setFrameStyle( QFrame::Panel | QFrame::Plain ); |
483 | setLineWidth( 1 ); | 483 | setLineWidth( 1 ); |
484 | //topLayout->addWidget( mItemList ); | 484 | //topLayout->addWidget( mItemList ); |
485 | mLabel->raise(); | 485 | mLabel->raise(); |
486 | // QColor( 0,0,255 ) QColor( 160,1600,255 ) | 486 | // QColor( 0,0,255 ) QColor( 160,1600,255 ) |
487 | mStandardPalette = palette(); | 487 | mStandardPalette = palette(); |
488 | mStandardPalette.setColor(QColorGroup::Base, mStandardPalette.color( QPalette::Normal, QColorGroup::Background ) ); | 488 | mStandardPalette.setColor(QColorGroup::Base, mStandardPalette.color( QPalette::Normal, QColorGroup::Background ) ); |
489 | 489 | ||
490 | enableScrollBars( false ); | 490 | enableScrollBars( false ); |
491 | updateConfig(); | 491 | updateConfig(); |
492 | //connect( mLabel, SIGNAL( clicked( )), SLOT( newEvent() )); | 492 | //connect( mLabel, SIGNAL( clicked( )), SLOT( newEvent() )); |
493 | connect( mLabel, SIGNAL( clicked( )), SLOT( showDay() )); | 493 | connect( mLabel, SIGNAL( clicked( )), SLOT( showDay() )); |
494 | connect( this , SIGNAL( doubleClicked( QListBoxItem *) ), | 494 | connect( this , SIGNAL( doubleClicked( QListBoxItem *) ), |
495 | SLOT( defaultAction( QListBoxItem * ) ) ); | 495 | SLOT( defaultAction( QListBoxItem * ) ) ); |
496 | connect( this, SIGNAL( rightButtonPressed( QListBoxItem *, | 496 | connect( this, SIGNAL( rightButtonPressed( QListBoxItem *, |
497 | const QPoint &) ), | 497 | const QPoint &) ), |
498 | SLOT( contextMenu( QListBoxItem * ) ) ); | 498 | SLOT( contextMenu( QListBoxItem * ) ) ); |
499 | connect( this, SIGNAL( highlighted( QListBoxItem *) ), | 499 | connect( this, SIGNAL( highlighted( QListBoxItem *) ), |
500 | SLOT( selection( QListBoxItem * ) ) ); | 500 | SLOT( selection( QListBoxItem * ) ) ); |
501 | 501 | ||
502 | /* | 502 | /* |
503 | connect( this, SIGNAL( clicked( QListBoxItem * ) ), | 503 | connect( this, SIGNAL( clicked( QListBoxItem * ) ), |
504 | SLOT( selection( QListBoxItem * ) ) ); | 504 | SLOT( selection( QListBoxItem * ) ) ); |
505 | */ | 505 | */ |
506 | } | 506 | } |
507 | #ifdef DESKTOP_VERSION | 507 | #ifdef DESKTOP_VERSION |
508 | QToolTipGroup *MonthViewCell::toolTipGroup() | 508 | QToolTipGroup *MonthViewCell::toolTipGroup() |
509 | { | 509 | { |
510 | if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0); | 510 | if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0); |
511 | return mToolTipGroup; | 511 | return mToolTipGroup; |
512 | } | 512 | } |
513 | #endif | 513 | #endif |
514 | 514 | ||
515 | void MonthViewCell::setDate( const QDate &date ) | 515 | void MonthViewCell::setDate( const QDate &date ) |
516 | { | 516 | { |
517 | // kdDebug() << "MonthViewCell::setDate(): " << date.toString() << endl; | 517 | // kdDebug() << "MonthViewCell::setDate(): " << date.toString() << endl; |
518 | mDate = date; | 518 | mDate = date; |
519 | 519 | ||
520 | 520 | ||
521 | 521 | ||
522 | //resizeEvent( 0 ); | 522 | //resizeEvent( 0 ); |
523 | } | 523 | } |
524 | 524 | ||
525 | QDate MonthViewCell::date() const | 525 | QDate MonthViewCell::date() const |
526 | { | 526 | { |
527 | return mDate; | 527 | return mDate; |
528 | } | 528 | } |
529 | 529 | ||
530 | void MonthViewCell::setPrimary( bool primary ) | 530 | void MonthViewCell::setPrimary( bool primary ) |
531 | { | 531 | { |
532 | mPrimary = primary; | 532 | mPrimary = primary; |
533 | //setMyPalette(); | 533 | //setMyPalette(); |
534 | } | 534 | } |
535 | void MonthViewCell::setMyPalette() | 535 | void MonthViewCell::setMyPalette() |
536 | { | 536 | { |
537 | 537 | ||
538 | if ( mHoliday) { | 538 | if ( mHoliday) { |
539 | if ( currentPalette == 1 ) return; | 539 | if ( currentPalette == 1 ) return; |
540 | mLabel->setPalette( QPalette ( mHolidayPalette.color( QPalette::Normal,QColorGroup::Base),mHolidayPalette.color(QPalette::Normal,QColorGroup::Base ) )); | 540 | mLabel->setPalette( QPalette ( mHolidayPalette.color( QPalette::Normal,QColorGroup::Base),mHolidayPalette.color(QPalette::Normal,QColorGroup::Base ) )); |
541 | setPalette( mHolidayPalette ); | 541 | setPalette( mHolidayPalette ); |
542 | //mLabel->setPalette( mHolidayPalette ); | 542 | //mLabel->setPalette( mHolidayPalette ); |
543 | currentPalette = 1; | 543 | currentPalette = 1; |
544 | 544 | ||
545 | } else { | 545 | } else { |
546 | if ( mPrimary ) { | 546 | if ( mPrimary ) { |
547 | if ( currentPalette == 2 ) return; | 547 | if ( currentPalette == 2 ) return; |
548 | mLabel->setPalette( QPalette ( mPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) )); | 548 | mLabel->setPalette( QPalette ( mPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) )); |
549 | //mLabel->setPalette( mPrimaryPalette ); | 549 | //mLabel->setPalette( mPrimaryPalette ); |
550 | setPalette( mPrimaryPalette ); | 550 | setPalette( mPrimaryPalette ); |
551 | currentPalette = 2; | 551 | currentPalette = 2; |
552 | 552 | ||
553 | } else { | 553 | } else { |
554 | if ( currentPalette == 3 ) return; | 554 | if ( currentPalette == 3 ) return; |
555 | setPalette( mNonPrimaryPalette ); | 555 | setPalette( mNonPrimaryPalette ); |
556 | mLabel->setPalette( QPalette ( mNonPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mNonPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) )); | 556 | mLabel->setPalette( QPalette ( mNonPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mNonPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) )); |
557 | //mLabel->setPalette( mNonPrimaryPalette );; | 557 | //mLabel->setPalette( mNonPrimaryPalette );; |
558 | currentPalette = 3; | 558 | currentPalette = 3; |
559 | } | 559 | } |
560 | } | 560 | } |
561 | //QPalette pal = palette(); | 561 | //QPalette pal = palette(); |
562 | 562 | ||
563 | //mLabel->setPalette( QPalette ( pal.color( QPalette::Normal,QColorGroup::Base),pal.color(QPalette::Normal,QColorGroup::Base ) )); | 563 | //mLabel->setPalette( QPalette ( pal.color( QPalette::Normal,QColorGroup::Base),pal.color(QPalette::Normal,QColorGroup::Base ) )); |
564 | } | 564 | } |
565 | QPalette MonthViewCell::getPalette () | 565 | QPalette MonthViewCell::getPalette () |
566 | { | 566 | { |
567 | if ( !KOPrefs::instance()->mMonthViewUsesDayColors ) | 567 | if ( !KOPrefs::instance()->mMonthViewUsesDayColors ) |
568 | return mStandardPalette; | 568 | return mStandardPalette; |
569 | if ( mHoliday) { | 569 | if ( mHoliday) { |
570 | return mHolidayPalette ; | 570 | return mHolidayPalette ; |
571 | } else { | 571 | } else { |
572 | if ( mPrimary ) { | 572 | if ( mPrimary ) { |
573 | return mPrimaryPalette ; | 573 | return mPrimaryPalette ; |
574 | } | 574 | } |
575 | } | 575 | } |
576 | return mNonPrimaryPalette; | 576 | return mNonPrimaryPalette; |
577 | } | 577 | } |
578 | bool MonthViewCell::isPrimary() const | 578 | bool MonthViewCell::isPrimary() const |
579 | { | 579 | { |
580 | return mPrimary; | 580 | return mPrimary; |
581 | } | 581 | } |
582 | 582 | ||
583 | void MonthViewCell::setHoliday( bool holiday ) | 583 | void MonthViewCell::setHoliday( bool holiday ) |
584 | { | 584 | { |
585 | mHoliday = holiday; | 585 | mHoliday = holiday; |
586 | //setMyPalette(); | 586 | //setMyPalette(); |
587 | } | 587 | } |
588 | 588 | ||
589 | void MonthViewCell::setHoliday( const QString &holiday ) | 589 | void MonthViewCell::setHoliday( const QString &holiday ) |
590 | { | 590 | { |
591 | mHolidayString = holiday; | 591 | mHolidayString = holiday; |
592 | 592 | ||
593 | if ( !holiday.isEmpty() ) { | 593 | if ( !holiday.isEmpty() ) { |
594 | setHoliday( true ); | 594 | setHoliday( true ); |
595 | } | 595 | } |
596 | } | 596 | } |
597 | 597 | ||
598 | void MonthViewCell::startUpdateCell() | 598 | void MonthViewCell::startUpdateCell() |
599 | { | 599 | { |
600 | mdayCount = 0; | 600 | mdayCount = 0; |
601 | setFocusPolicy(NoFocus); | 601 | setFocusPolicy(NoFocus); |
602 | if ( !mMonthView->isUpdatePossible() ) | 602 | if ( !mMonthView->isUpdatePossible() ) |
603 | return; | 603 | return; |
604 | MonthViewItem *mitem = (MonthViewItem*) firstItem (); | 604 | MonthViewItem *mitem = (MonthViewItem*) firstItem (); |
605 | while ( mitem ) { | 605 | while ( mitem ) { |
606 | mitem->setBlockRepaint( true ); | 606 | mitem->setBlockRepaint( true ); |
607 | mitem = (MonthViewItem *)mitem->next(); | 607 | mitem = (MonthViewItem *)mitem->next(); |
608 | } | 608 | } |
609 | if ( mAvailItemList.count() > 20 ) { | 609 | if ( mAvailItemList.count() > 20 ) { |
610 | mAvailItemList.setAutoDelete( true ); | 610 | mAvailItemList.setAutoDelete( true ); |
611 | mAvailItemList.clear(); | 611 | mAvailItemList.clear(); |
612 | mAvailItemList.setAutoDelete( false ); | 612 | mAvailItemList.setAutoDelete( false ); |
613 | } | 613 | } |
614 | 614 | ||
615 | setPrimary( mDate.month()%2 ); | 615 | setPrimary( mDate.month()%2 ); |
616 | setHoliday( KOGlobals::self()->calendarSystem()->dayOfWeek(mDate) == KOGlobals::self()->calendarSystem()->weekDayOfPray() || ( mDate.dayOfWeek() == 6 ) && KOPrefs::instance()-> mExcludeSaturdays); | 616 | setHoliday( KOGlobals::self()->calendarSystem()->dayOfWeek(mDate) == KOGlobals::self()->calendarSystem()->weekDayOfPray() || ( mDate.dayOfWeek() == 6 ) && KOPrefs::instance()-> mExcludeSaturdays); |
617 | if ( mDate == QDate::currentDate() ) { | 617 | if ( mDate == QDate::currentDate() ) { |
618 | setLineWidth( 3 ); | 618 | setLineWidth( 3 ); |
619 | } else { | 619 | } else { |
620 | setLineWidth( 1 ); | 620 | setLineWidth( 1 ); |
621 | } | 621 | } |
622 | MonthViewItem* CurrentAvailItem = (MonthViewItem*) firstItem (); | 622 | MonthViewItem* CurrentAvailItem = (MonthViewItem*) firstItem (); |
623 | //clear(); | 623 | //clear(); |
624 | while ( CurrentAvailItem ) { | 624 | while ( CurrentAvailItem ) { |
625 | MonthViewItem *item = CurrentAvailItem; | 625 | MonthViewItem *item = CurrentAvailItem; |
626 | CurrentAvailItem = (MonthViewItem *)item->next(); | 626 | CurrentAvailItem = (MonthViewItem *)item->next(); |
627 | mAvailItemList.append( item ); | 627 | mAvailItemList.append( item ); |
628 | takeItem ( item ); | 628 | takeItem ( item ); |
629 | } | 629 | } |
630 | 630 | ||
631 | #ifdef DESKTOP_VERSION | 631 | #ifdef DESKTOP_VERSION |
632 | QToolTip::remove(this); | 632 | QToolTip::remove(this); |
633 | #endif | 633 | #endif |
634 | mToolTip.clear(); | 634 | mToolTip.clear(); |
635 | //qApp->processEvents(); | 635 | //qApp->processEvents(); |
636 | #if 0 | 636 | #if 0 |
637 | if ( !mHolidayString.isEmpty() ) { | 637 | if ( !mHolidayString.isEmpty() ) { |
638 | MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString ); | 638 | MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString ); |
639 | item->setPalette( mHolidayPalette ); | 639 | item->setPalette( mHolidayPalette ); |
640 | insertItem( item ); | 640 | insertItem( item ); |
641 | mToolTip.append ( mHolidayString ); | 641 | mToolTip.append ( mHolidayString ); |
642 | } | 642 | } |
643 | #endif | 643 | #endif |
644 | } | 644 | } |
645 | 645 | ||
646 | int MonthViewCell::insertEvent(Event *event) | 646 | int MonthViewCell::insertEvent(Event *event) |
647 | { | 647 | { |
648 | bool useToolTips = true; | 648 | bool useToolTips = true; |
649 | #ifndef DESKTOP_VERSION | 649 | #ifndef DESKTOP_VERSION |
650 | useToolTips = false; | 650 | useToolTips = false; |
651 | #endif | 651 | #endif |
652 | QString mToolTipText; | 652 | QString mToolTipText; |
653 | setFocusPolicy(WheelFocus); | 653 | setFocusPolicy(WheelFocus); |
654 | if ( !(event->doesRecur() == Recurrence::rNone) ) { | 654 | if ( !(event->doesRecur() == Recurrence::rNone) ) { |
655 | if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily ) | 655 | if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily ) |
656 | return mdayCount; | 656 | return mdayCount; |
657 | else | 657 | else |
658 | if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly ) | 658 | if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly ) |
659 | return mdayCount; | 659 | return mdayCount; |
660 | } | 660 | } |
661 | 661 | ||
662 | if ( event->isHoliday()) { | 662 | if ( event->isHoliday()) { |
663 | setHoliday( true ); | 663 | setHoliday( true ); |
664 | if ( mDate.dayOfWeek() == 7 ) | 664 | if ( mDate.dayOfWeek() == 7 ) |
665 | setLineWidth( 3 ); | 665 | setLineWidth( 3 ); |
666 | } | 666 | } |
667 | QString text; | 667 | QString text; |
668 | int multiday = 0;// 1 = start, 2 = midddle, 3 = end day | 668 | int multiday = 0;// 1 = start, 2 = midddle, 3 = end day |
669 | if (event->isMultiDay()) { | 669 | if (event->isMultiDay()) { |
670 | QString prefix = "<->";multiday = 2; | 670 | QString prefix = "<->";multiday = 2; |
671 | QString time; | 671 | QString time; |
672 | if ( event->doesRecur() ) { | 672 | if ( event->doesRecur() ) { |
673 | if ( event->recursOn( mDate) ) { | 673 | if ( event->recursOn( mDate) ) { |
674 | prefix ="->" ;multiday = 1; | 674 | prefix ="->" ;multiday = 1; |
675 | } | 675 | } |
676 | else { | 676 | else { |
677 | int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); | 677 | int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); |
678 | if ( event->recursOn( mDate.addDays( -days)) ) { | 678 | if ( event->recursOn( mDate.addDays( -days)) ) { |
679 | prefix ="<-" ;multiday = 3; | 679 | prefix ="<-" ;multiday = 3; |
680 | } | 680 | } |
681 | } | 681 | } |
682 | 682 | ||
683 | } else { | 683 | } else { |
684 | if (mDate == event->dtStart().date()) { | 684 | if (mDate == event->dtStart().date()) { |
685 | prefix ="->" ;multiday = 1; | 685 | prefix ="->" ;multiday = 1; |
686 | } else if (mDate == event->dtEnd().date()) { | 686 | } else if (mDate == event->dtEnd().date()) { |
687 | prefix ="<-" ;multiday = 3; | 687 | prefix ="<-" ;multiday = 3; |
688 | } | 688 | } |
689 | } | 689 | } |
690 | if ( !event->doesFloat() ) { | 690 | if ( !event->doesFloat() ) { |
691 | if ( mDate == event->dtStart().date () ) | 691 | if ( mDate == event->dtStart().date () ) |
692 | time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; | 692 | time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; |
693 | else if ( mDate == event->dtEnd().date () ) | 693 | else if ( mDate == event->dtEnd().date () ) |
694 | time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; | 694 | time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; |
695 | 695 | ||
696 | } | 696 | } |
697 | text = time + event->summary(); | 697 | text = time + event->summary(); |
698 | if ( useToolTips ) | 698 | if ( useToolTips ) |
699 | mToolTipText += prefix + text; | 699 | mToolTipText += prefix + text; |
700 | } else { | 700 | } else { |
701 | if (event->doesFloat()) { | 701 | if (event->doesFloat()) { |
702 | text = event->summary(); | 702 | text = event->summary(); |
703 | if ( useToolTips ) | 703 | if ( useToolTips ) |
704 | mToolTipText += text; | 704 | mToolTipText += text; |
705 | } | 705 | } |
706 | else { | 706 | else { |
707 | text = KGlobal::locale()->formatTime(event->dtStart().time()); | 707 | text = KGlobal::locale()->formatTime(event->dtStart().time()); |
708 | text += " " + event->summary(); | 708 | text += " " + event->summary(); |
709 | if ( useToolTips ) | 709 | if ( useToolTips ) |
710 | mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); | 710 | mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); |
711 | } | 711 | } |
712 | } | 712 | } |
713 | if ( useToolTips && ! event->location().isEmpty() ) { | 713 | if ( useToolTips && ! event->location().isEmpty() ) { |
714 | mToolTipText += " (" + event->location() +")"; | 714 | mToolTipText += " (" + event->location() +")"; |
715 | } | 715 | } |
716 | MonthViewItem *item ; | 716 | MonthViewItem *item ; |
717 | 717 | ||
718 | if ( mAvailItemList.count() ) { | 718 | if ( mAvailItemList.count() ) { |
719 | item = mAvailItemList.first(); | 719 | item = mAvailItemList.first(); |
720 | mAvailItemList.remove( item ); | 720 | mAvailItemList.remove( item ); |
721 | item->recycle( event, mDate, text ); | 721 | item->recycle( event, mDate, text ); |
722 | } else { | 722 | } else { |
723 | item = new MonthViewItem( event, mDate, text ); | 723 | item = new MonthViewItem( event, mDate, text ); |
724 | } | 724 | } |
725 | 725 | ||
726 | QPalette pal; | 726 | QPalette pal; |
727 | if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { | 727 | if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { |
728 | QStringList categories = event->categories(); | 728 | QStringList categories = event->categories(); |
729 | QString cat = categories.first(); | 729 | QString cat = categories.first(); |
730 | if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { | 730 | if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { |
731 | pal = getPalette(); | 731 | pal = getPalette(); |
732 | if (cat.isEmpty()) { | 732 | if (cat.isEmpty()) { |
733 | pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); | 733 | pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); |
734 | } else { | 734 | } else { |
735 | pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); | 735 | pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); |
736 | } | 736 | } |
737 | 737 | ||
738 | } else { | 738 | } else { |
739 | if (cat.isEmpty()) { | 739 | if (cat.isEmpty()) { |
740 | pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); | 740 | pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); |
741 | } else { | 741 | } else { |
742 | pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); | 742 | pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); |
743 | } | 743 | } |
744 | } | 744 | } |
745 | 745 | ||
746 | } else { | 746 | } else { |
747 | pal = mStandardPalette ; | 747 | pal = mStandardPalette ; |
748 | } | 748 | } |
749 | item->setPalette( pal ); | 749 | item->setPalette( pal ); |
750 | item->setRecur( event->recurrence()->doesRecur() ); | 750 | item->setRecur( event->recurrence()->doesRecur() ); |
751 | item->setAlarm( event->isAlarmEnabled() && multiday < 2 ); | 751 | item->setAlarm( event->isAlarmEnabled() && multiday < 2 ); |
752 | item->setMoreInfo( event->description().length() > 0 ); | 752 | item->setMoreInfo( event->description().length() > 0 ); |
753 | #ifdef DESKTOP_VERSION | 753 | #ifdef DESKTOP_VERSION |
754 | Attendee *me = event->attendeeByMails(KOPrefs::instance()->mAdditionalMails, | 754 | Attendee *me = event->attendeeByMails(KOPrefs::instance()->mAdditionalMails, |
755 | KOPrefs::instance()->email()); | 755 | KOPrefs::instance()->email()); |
756 | if ( me != 0 ) { | 756 | if ( me != 0 ) { |
757 | if ( me->status() == Attendee::NeedsAction && me->RSVP()) | 757 | if ( me->status() == Attendee::NeedsAction && me->RSVP()) |
758 | item->setReply(true && multiday < 2); | 758 | item->setReply(true && multiday < 2); |
759 | else | 759 | else |
760 | item->setReply(false); | 760 | item->setReply(false); |
761 | } else | 761 | } else |
762 | item->setReply(false); | 762 | item->setReply(false); |
763 | #endif | 763 | #endif |
764 | item->setMultiDay( multiday ); | 764 | item->setMultiDay( multiday ); |
765 | if ( multiday ) { | 765 | if ( multiday ) { |
766 | insertItem( item ,mdayCount); | 766 | insertItem( item ,mdayCount); |
767 | ++mdayCount; | 767 | ++mdayCount; |
768 | } else { | 768 | } else { |
769 | uint i; | 769 | uint i; |
770 | int pos = mdayCount; | 770 | int pos = mdayCount; |
771 | for ( i = mdayCount; i < count();++i ) { | 771 | for ( i = mdayCount; i < count();++i ) { |
772 | QListBoxItem* it = this->item ( i ); | 772 | QListBoxItem* it = this->item ( i ); |
773 | if ( text < it->text() ) { | 773 | if ( it && text < it->text() ) { |
774 | pos = i; | 774 | pos = i; |
775 | break; | 775 | break; |
776 | } | 776 | } |
777 | ++pos; | 777 | ++pos; |
778 | } | 778 | } |
779 | insertItem( item ,pos); | 779 | insertItem( item ,pos); |
780 | } | 780 | } |
781 | if ( useToolTips ) { | 781 | if ( useToolTips ) { |
782 | mToolTip.append( mToolTipText ); | 782 | mToolTip.append( mToolTipText ); |
783 | } | 783 | } |
784 | return mdayCount; | 784 | return mdayCount; |
785 | } | 785 | } |
786 | void MonthViewCell::insertTodo(Todo *todo) | 786 | void MonthViewCell::insertTodo(Todo *todo) |
787 | { | 787 | { |
788 | setFocusPolicy(WheelFocus); | 788 | setFocusPolicy(WheelFocus); |
789 | QString text; | 789 | QString text; |
790 | if (todo->hasDueDate()) { | 790 | if (todo->hasDueDate()) { |
791 | if (!todo->doesFloat()) { | 791 | if (!todo->doesFloat()) { |
792 | text += KGlobal::locale()->formatTime(todo->dtDue().time()); | 792 | text += KGlobal::locale()->formatTime(todo->dtDue().time()); |
793 | text += " "; | 793 | text += " "; |
794 | } | 794 | } |
795 | } | 795 | } |
796 | text += todo->summary(); | 796 | text += todo->summary(); |
797 | MonthViewItem *item ; | 797 | MonthViewItem *item ; |
798 | if ( mAvailItemList.count() ) { | 798 | if ( mAvailItemList.count() ) { |
799 | item = mAvailItemList.first(); | 799 | item = mAvailItemList.first(); |
800 | mAvailItemList.remove( item ); | 800 | mAvailItemList.remove( item ); |
801 | item->recycle( todo, mDate, text ); | 801 | item->recycle( todo, mDate, text ); |
802 | } else { | 802 | } else { |
803 | item = new MonthViewItem( todo, mDate, text ); | 803 | item = new MonthViewItem( todo, mDate, text ); |
804 | } | 804 | } |
805 | //MonthViewItem *item = new MonthViewItem( todo, mDate, text ); | 805 | //MonthViewItem *item = new MonthViewItem( todo, mDate, text ); |
806 | //item->setPalette( mStandardPalette ); | 806 | //item->setPalette( mStandardPalette ); |
807 | QPalette pal; | 807 | QPalette pal; |
808 | if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { | 808 | if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { |
809 | QStringList categories = todo->categories(); | 809 | QStringList categories = todo->categories(); |
810 | QString cat = categories.first(); | 810 | QString cat = categories.first(); |
811 | if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { | 811 | if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { |
812 | pal = getPalette(); | 812 | pal = getPalette(); |
813 | if (cat.isEmpty()) { | 813 | if (cat.isEmpty()) { |
814 | pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); | 814 | pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); |
815 | } else { | 815 | } else { |
816 | pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); | 816 | pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); |
817 | } | 817 | } |
818 | 818 | ||
819 | } else { | 819 | } else { |
820 | if (cat.isEmpty()) { | 820 | if (cat.isEmpty()) { |
821 | pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); | 821 | pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); |
822 | } else { | 822 | } else { |
823 | pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); | 823 | pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); |
824 | } | 824 | } |
825 | } | 825 | } |
826 | 826 | ||
827 | } else { | 827 | } else { |
828 | pal = mStandardPalette ; | 828 | pal = mStandardPalette ; |
829 | } | 829 | } |
830 | item->setPalette( pal ); | 830 | item->setPalette( pal ); |
831 | item->setRecur( todo->recurrence()->doesRecur() ); | 831 | item->setRecur( todo->recurrence()->doesRecur() ); |
832 | item->setAlarm( todo->isAlarmEnabled() ); | 832 | item->setAlarm( todo->isAlarmEnabled() ); |
833 | item->setMoreInfo( todo->description().length() > 0 ); | 833 | item->setMoreInfo( todo->description().length() > 0 ); |
834 | insertItem( item , count()); | 834 | insertItem( item , count()); |
835 | #ifdef DESKTOP_VERSION | 835 | #ifdef DESKTOP_VERSION |
836 | mToolTip.append( text ); | 836 | mToolTip.append( text ); |
837 | #endif | 837 | #endif |
838 | } | 838 | } |
839 | void MonthViewCell::repaintfinishUpdateCell() | 839 | void MonthViewCell::repaintfinishUpdateCell() |
840 | { | 840 | { |
841 | MonthViewItem *mitem = (MonthViewItem*) firstItem (); | 841 | MonthViewItem *mitem = (MonthViewItem*) firstItem (); |
842 | while ( mitem ) { | 842 | while ( mitem ) { |
843 | mitem->setBlockRepaint( false ); | 843 | mitem->setBlockRepaint( false ); |
844 | updateItem ( mitem ); | 844 | updateItem ( mitem ); |
845 | mitem = (MonthViewItem *)mitem->next(); | 845 | mitem = (MonthViewItem *)mitem->next(); |
846 | } | 846 | } |
847 | } | 847 | } |
848 | void MonthViewCell::finishUpdateCell() | 848 | void MonthViewCell::finishUpdateCell() |
849 | { | 849 | { |
850 | 850 | ||
851 | 851 | ||
852 | 852 | ||
853 | #ifdef DESKTOP_VERSION | 853 | #ifdef DESKTOP_VERSION |
854 | if (mToolTip.count() > 0 ) { | 854 | if (mToolTip.count() > 0 ) { |
855 | mToolTip.sort(); | 855 | mToolTip.sort(); |
856 | QToolTip::add(this,mToolTip.join("\n"),toolTipGroup(),""); | 856 | QToolTip::add(this,mToolTip.join("\n"),toolTipGroup(),""); |
857 | } | 857 | } |
858 | #endif | 858 | #endif |
859 | //sort(); | 859 | //sort(); |
860 | //setMyPalette(); | 860 | //setMyPalette(); |
861 | setMyPalette(); | 861 | setMyPalette(); |
862 | 862 | ||
863 | resizeEvent( 0 ); | 863 | resizeEvent( 0 ); |
864 | 864 | ||
865 | } | 865 | } |
866 | void MonthViewCell::updateCell() | 866 | void MonthViewCell::updateCell() |
867 | { | 867 | { |
868 | if ( !mMonthView->isUpdatePossible() ) | 868 | if ( !mMonthView->isUpdatePossible() ) |
869 | return; | 869 | return; |
870 | startUpdateCell(); | 870 | startUpdateCell(); |
871 | //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); | 871 | //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); |
872 | QPtrList<Event> events = mMonthView->calendar()->events( mDate, true ); | 872 | QPtrList<Event> events = mMonthView->calendar()->events( mDate, true ); |
873 | Event *event; | 873 | Event *event; |
874 | for( event = events.first(); event; event = events.next() ) { // for event | 874 | for( event = events.first(); event; event = events.next() ) { // for event |
875 | insertEvent(event); | 875 | insertEvent(event); |
876 | } | 876 | } |
877 | // insert due todos | 877 | // insert due todos |
878 | QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate ); | 878 | QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate ); |
879 | Todo *todo; | 879 | Todo *todo; |
880 | for(todo = todos.first(); todo; todo = todos.next()) { | 880 | for(todo = todos.first(); todo; todo = todos.next()) { |
881 | insertTodo( todo ); | 881 | insertTodo( todo ); |
882 | } | 882 | } |
883 | finishUpdateCell(); | 883 | finishUpdateCell(); |
884 | // if ( isVisible()) | 884 | // if ( isVisible()) |
885 | //qApp->processEvents(); | 885 | //qApp->processEvents(); |
886 | } | 886 | } |
887 | 887 | ||
888 | void MonthViewCell::updateConfig( bool bigFont ) // = false | 888 | void MonthViewCell::updateConfig( bool bigFont ) // = false |
889 | { | 889 | { |
890 | 890 | ||
891 | if ( bigFont ) { | 891 | if ( bigFont ) { |
892 | QFont fo = KOPrefs::instance()->mMonthViewFont; | 892 | QFont fo = KOPrefs::instance()->mMonthViewFont; |
893 | int ps = fo.pointSize() + 2; | 893 | int ps = fo.pointSize() + 2; |
894 | if ( ps < 18 ) | 894 | if ( ps < 18 ) |
895 | ps += 2; | 895 | ps += 2; |
896 | fo.setPointSize( ps ); | 896 | fo.setPointSize( ps ); |
897 | setFont( fo ); | 897 | setFont( fo ); |
898 | } else | 898 | } else |
899 | setFont( KOPrefs::instance()->mMonthViewFont ); | 899 | setFont( KOPrefs::instance()->mMonthViewFont ); |
900 | 900 | ||
901 | QFontMetrics fm( font() ); | 901 | QFontMetrics fm( font() ); |
902 | mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 ); | 902 | mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 ); |
903 | mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 ); | 903 | mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 ); |
904 | mHolidayPalette = mStandardPalette; | 904 | mHolidayPalette = mStandardPalette; |
905 | mPrimaryPalette = mStandardPalette; | 905 | mPrimaryPalette = mStandardPalette; |
906 | mNonPrimaryPalette = mStandardPalette; | 906 | mNonPrimaryPalette = mStandardPalette; |
907 | if ( KOPrefs::instance()->mMonthViewUsesDayColors ) { | 907 | if ( KOPrefs::instance()->mMonthViewUsesDayColors ) { |
908 | mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor ); | 908 | mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor ); |
909 | mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor ); | 909 | mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor ); |
910 | mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark()); | 910 | mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark()); |
911 | mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark()); | 911 | mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark()); |
912 | mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor); | 912 | mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor); |
913 | mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor); | 913 | mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor); |
914 | mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark()); | 914 | mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark()); |
915 | mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor); | 915 | mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor); |
916 | mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor); | 916 | mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor); |
917 | } | 917 | } |
918 | //updateCell(); | 918 | //updateCell(); |
919 | } | 919 | } |
920 | 920 | ||
921 | void MonthViewCell::enableScrollBars( bool enabled ) | 921 | void MonthViewCell::enableScrollBars( bool enabled ) |
922 | { | 922 | { |
923 | 923 | ||
924 | return; | 924 | return; |
925 | if ( enabled ) { | 925 | if ( enabled ) { |
926 | QListBoxItem *fi = firstItem (); | 926 | QListBoxItem *fi = firstItem (); |
927 | if (fi ) { | 927 | if (fi ) { |
928 | int ihei = fi->height( this ); | 928 | int ihei = fi->height( this ); |
929 | int hei = numRows () * ihei; | 929 | int hei = numRows () * ihei; |
930 | if ( hei < height() - horizontalScrollBar()->height () ) { | 930 | if ( hei < height() - horizontalScrollBar()->height () ) { |
931 | setVScrollBarMode(QScrollView::AlwaysOff); | 931 | setVScrollBarMode(QScrollView::AlwaysOff); |
932 | } | 932 | } |
933 | else | 933 | else |
934 | setVScrollBarMode(QScrollView::Auto); | 934 | setVScrollBarMode(QScrollView::Auto); |
935 | if ( ihei *3 > height() ) { | 935 | if ( ihei *3 > height() ) { |
936 | setHScrollBarMode(QScrollView::AlwaysOff); | 936 | setHScrollBarMode(QScrollView::AlwaysOff); |
937 | } | 937 | } |
938 | else { | 938 | else { |
939 | setHScrollBarMode(QScrollView::Auto); | 939 | setHScrollBarMode(QScrollView::Auto); |
940 | } | 940 | } |
941 | } else { | 941 | } else { |
942 | setVScrollBarMode(QScrollView::Auto); | 942 | setVScrollBarMode(QScrollView::Auto); |
943 | setHScrollBarMode(QScrollView::Auto); | 943 | setHScrollBarMode(QScrollView::Auto); |
944 | } | 944 | } |
945 | } else { | 945 | } else { |
946 | setVScrollBarMode(QScrollView::AlwaysOff); | 946 | setVScrollBarMode(QScrollView::AlwaysOff); |
947 | setHScrollBarMode(QScrollView::AlwaysOff); | 947 | setHScrollBarMode(QScrollView::AlwaysOff); |
948 | } | 948 | } |
949 | } | 949 | } |
950 | 950 | ||
951 | Incidence *MonthViewCell::selectedIncidence() | 951 | Incidence *MonthViewCell::selectedIncidence() |
952 | { | 952 | { |
953 | int index = currentItem(); | 953 | int index = currentItem(); |
954 | if ( index < 0 ) return 0; | 954 | if ( index < 0 ) return 0; |
955 | 955 | ||
956 | MonthViewItem *mitem = | 956 | MonthViewItem *mitem = |
957 | static_cast<MonthViewItem *>( item( index ) ); | 957 | static_cast<MonthViewItem *>( item( index ) ); |
958 | 958 | ||
959 | if ( !mitem ) return 0; | 959 | if ( !mitem ) return 0; |
960 | 960 | ||
961 | return mitem->incidence(); | 961 | return mitem->incidence(); |
962 | } | 962 | } |
963 | 963 | ||
964 | QDate MonthViewCell::selectedIncidenceDate() | 964 | QDate MonthViewCell::selectedIncidenceDate() |
965 | { | 965 | { |
966 | QDate qd; | 966 | QDate qd; |
967 | int index = currentItem(); | 967 | int index = currentItem(); |
968 | if ( index < 0 ) return qd; | 968 | if ( index < 0 ) return qd; |
969 | 969 | ||
970 | MonthViewItem *mitem = | 970 | MonthViewItem *mitem = |
971 | static_cast<MonthViewItem *>( item( index ) ); | 971 | static_cast<MonthViewItem *>( item( index ) ); |
972 | 972 | ||
973 | if ( !mitem ) return qd; | 973 | if ( !mitem ) return qd; |
974 | 974 | ||
975 | return mitem->incidenceDate(); | 975 | return mitem->incidenceDate(); |
976 | } | 976 | } |
977 | 977 | ||
978 | void MonthViewCell::deselect() | 978 | void MonthViewCell::deselect() |
979 | { | 979 | { |
980 | clearSelection(); | 980 | clearSelection(); |
981 | enableScrollBars( false ); | 981 | enableScrollBars( false ); |
982 | // updateCell(); | 982 | // updateCell(); |
983 | } | 983 | } |
984 | void MonthViewCell::select() | 984 | void MonthViewCell::select() |
985 | { | 985 | { |
986 | ;// updateCell(); | 986 | ;// updateCell(); |
987 | } | 987 | } |
988 | 988 | ||
989 | void MonthViewCell::resizeEvent ( QResizeEvent * e ) | 989 | void MonthViewCell::resizeEvent ( QResizeEvent * e ) |
990 | { | 990 | { |
991 | if ( !mMonthView->isUpdatePossible() ) | 991 | if ( !mMonthView->isUpdatePossible() ) |
992 | return; | 992 | return; |
993 | //qDebug("++++++++++++++MonthViewCell::resizeEvent %d %d ", width(), height()); | 993 | //qDebug("++++++++++++++MonthViewCell::resizeEvent %d %d ", width(), height()); |
994 | deselect(); | 994 | deselect(); |
995 | mLabel->setMaximumHeight( height() - lineWidth()*2 ); | 995 | mLabel->setMaximumHeight( height() - lineWidth()*2 ); |
996 | 996 | ||
997 | QString text; | 997 | QString text; |
998 | mLabel->setText( text ); | 998 | mLabel->setText( text ); |
999 | bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog; | 999 | bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog; |
1000 | if ( KOPrefs::instance()->mMonthViewWeek || KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) { | 1000 | if ( KOPrefs::instance()->mMonthViewWeek || KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) { |
1001 | text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " "; | 1001 | text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " "; |
1002 | mLabel->resize( mLabelBigSize ); | 1002 | mLabel->resize( mLabelBigSize ); |
1003 | text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); | 1003 | text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); |
1004 | } else { | 1004 | } else { |
1005 | mLabel->resize( mLabelSize ); | 1005 | mLabel->resize( mLabelSize ); |
1006 | text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); | 1006 | text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); |
1007 | } | 1007 | } |
1008 | mLabel->setText( text ); | 1008 | mLabel->setText( text ); |
1009 | 1009 | ||
1010 | int size = height() - mLabel->height() - lineWidth()-1; | 1010 | int size = height() - mLabel->height() - lineWidth()-1; |
1011 | //qDebug("LW %d ", lineWidth()); | 1011 | //qDebug("LW %d ", lineWidth()); |
1012 | if ( size > 0 ) | 1012 | if ( size > 0 ) |
1013 | verticalScrollBar()->setMaximumHeight( size ); | 1013 | verticalScrollBar()->setMaximumHeight( size ); |
1014 | size = width() - mLabel->width() -lineWidth()-1; | 1014 | size = width() - mLabel->width() -lineWidth()-1; |
1015 | if ( size > 0 ) | 1015 | if ( size > 0 ) |
1016 | horizontalScrollBar()->setMaximumWidth( size ); | 1016 | horizontalScrollBar()->setMaximumWidth( size ); |
1017 | mLabel->move( width()-lineWidth() - mLabel->width(), height()-lineWidth() - mLabel->height() ); | 1017 | mLabel->move( width()-lineWidth() - mLabel->width(), height()-lineWidth() - mLabel->height() ); |
1018 | //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); | 1018 | //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); |
1019 | // mItemList->resize ( width(), height () ); | 1019 | // mItemList->resize ( width(), height () ); |
1020 | if ( e ) | 1020 | if ( e ) |
1021 | KNoScrollListBox::resizeEvent ( e ); | 1021 | KNoScrollListBox::resizeEvent ( e ); |
1022 | } | 1022 | } |
1023 | 1023 | ||
1024 | void MonthViewCell::defaultAction( QListBoxItem *item ) | 1024 | void MonthViewCell::defaultAction( QListBoxItem *item ) |
1025 | { | 1025 | { |
1026 | 1026 | ||
1027 | if ( !item ) { | 1027 | if ( !item ) { |
1028 | QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); | 1028 | QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); |
1029 | emit newEventSignal( dt ); | 1029 | emit newEventSignal( dt ); |
1030 | return; | 1030 | return; |
1031 | } | 1031 | } |
1032 | 1032 | ||
1033 | MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); | 1033 | MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); |
1034 | Incidence *incidence = eventItem->incidence(); | 1034 | Incidence *incidence = eventItem->incidence(); |
1035 | if ( incidence ) mMonthView->defaultAction( incidence ); | 1035 | if ( incidence ) mMonthView->defaultAction( incidence ); |
1036 | } | 1036 | } |
1037 | void MonthViewCell::showDay() | 1037 | void MonthViewCell::showDay() |
1038 | { | 1038 | { |
1039 | emit showDaySignal( date() ); | 1039 | emit showDaySignal( date() ); |
1040 | } | 1040 | } |
1041 | void MonthViewCell::newEvent() | 1041 | void MonthViewCell::newEvent() |
1042 | { | 1042 | { |
1043 | QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); | 1043 | QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); |
1044 | emit newEventSignal( dt ); | 1044 | emit newEventSignal( dt ); |
1045 | } | 1045 | } |
1046 | void MonthViewCell::cellClicked( QListBoxItem *item ) | 1046 | void MonthViewCell::cellClicked( QListBoxItem *item ) |
1047 | { | 1047 | { |
1048 | mMonthView->setSelectedCell( this ); | 1048 | mMonthView->setSelectedCell( this ); |
1049 | if ( item == 0 ) { | 1049 | if ( item == 0 ) { |
1050 | QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); | 1050 | QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); |
1051 | emit newEventSignal( dt ); | 1051 | emit newEventSignal( dt ); |
1052 | return; | 1052 | return; |
1053 | } | 1053 | } |
1054 | 1054 | ||
1055 | } | 1055 | } |
1056 | 1056 | ||
1057 | void MonthViewCell::contextMenu( QListBoxItem *item ) | 1057 | void MonthViewCell::contextMenu( QListBoxItem *item ) |
1058 | { | 1058 | { |
1059 | mMonthView->setPopupCell( this ); | 1059 | mMonthView->setPopupCell( this ); |
1060 | if ( !item ) { | 1060 | if ( !item ) { |
1061 | mMonthView->showContextMenu( 0 ); | 1061 | mMonthView->showContextMenu( 0 ); |
1062 | return; | 1062 | return; |
1063 | } | 1063 | } |
1064 | MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); | 1064 | MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); |
1065 | Incidence *incidence = eventItem->incidence(); | 1065 | Incidence *incidence = eventItem->incidence(); |
1066 | if ( incidence ) mMonthView->showContextMenu( incidence ); | 1066 | if ( incidence ) mMonthView->showContextMenu( incidence ); |
1067 | } | 1067 | } |
1068 | 1068 | ||
1069 | void MonthViewCell::selection( QListBoxItem *item ) | 1069 | void MonthViewCell::selection( QListBoxItem *item ) |
1070 | { | 1070 | { |
1071 | if ( !item ) return; | 1071 | if ( !item ) return; |
1072 | 1072 | ||
1073 | mMonthView->setSelectedCell( this ); | 1073 | mMonthView->setSelectedCell( this ); |
1074 | } | 1074 | } |
1075 | 1075 | ||
1076 | 1076 | ||
1077 | // ******************************************************************************* | 1077 | // ******************************************************************************* |
1078 | // ******************************************************************************* | 1078 | // ******************************************************************************* |
1079 | // ******************************************************************************* | 1079 | // ******************************************************************************* |
1080 | 1080 | ||
1081 | 1081 | ||
1082 | KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) | 1082 | KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) |
1083 | : KOEventView( calendar, parent, name ), | 1083 | : KOEventView( calendar, parent, name ), |
1084 | mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ), | 1084 | mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ), |
1085 | mWidthLongDayLabel( 0 ), mSelectedCell( 0 ) | 1085 | mWidthLongDayLabel( 0 ), mSelectedCell( 0 ) |
1086 | { | 1086 | { |
1087 | mFlagKeyPressed = false; | 1087 | mFlagKeyPressed = false; |
1088 | mShortDayLabelsM = false; | 1088 | mShortDayLabelsM = false; |
1089 | mShortDayLabelsW = false; | 1089 | mShortDayLabelsW = false; |
1090 | skipResize = false; | 1090 | skipResize = false; |
1091 | clPending = true; | 1091 | clPending = true; |
1092 | mPopupCell = 0; | 1092 | mPopupCell = 0; |
1093 | mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" ); | 1093 | mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" ); |
1094 | mWidStack = new QWidgetStack( this ); | 1094 | mWidStack = new QWidgetStack( this ); |
1095 | QVBoxLayout* hb = new QVBoxLayout( this ); | 1095 | QVBoxLayout* hb = new QVBoxLayout( this ); |
1096 | mMonthView = new QWidget( mWidStack ); | 1096 | mMonthView = new QWidget( mWidStack ); |
1097 | mWeekView = new QWidget( mWidStack ); | 1097 | mWeekView = new QWidget( mWidStack ); |
1098 | #if QT_VERSION >= 0x030000 | 1098 | #if QT_VERSION >= 0x030000 |
1099 | mWidStack->addWidget(mMonthView ); | 1099 | mWidStack->addWidget(mMonthView ); |
1100 | mWidStack->addWidget(mWeekView ); | 1100 | mWidStack->addWidget(mWeekView ); |
1101 | #else | 1101 | #else |
1102 | mWidStack->addWidget( mMonthView, 1 ); | 1102 | mWidStack->addWidget( mMonthView, 1 ); |
1103 | mWidStack->addWidget( mWeekView , 1 ); | 1103 | mWidStack->addWidget( mWeekView , 1 ); |
1104 | #endif | 1104 | #endif |
1105 | hb->addWidget( mNavigatorBar ); | 1105 | hb->addWidget( mNavigatorBar ); |
1106 | hb->addWidget( mWidStack ); | 1106 | hb->addWidget( mWidStack ); |
1107 | mShowWeekView = KOPrefs::instance()->mMonthViewWeek; | 1107 | mShowWeekView = KOPrefs::instance()->mMonthViewWeek; |
1108 | updatePossible = false; | 1108 | updatePossible = false; |
1109 | //updatePossible = true; | 1109 | //updatePossible = true; |
1110 | mCells.setAutoDelete( true ); | 1110 | mCells.setAutoDelete( true ); |
1111 | mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; | 1111 | mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; |
1112 | mDayLabels.resize( mDaysPerWeek ); | 1112 | mDayLabels.resize( mDaysPerWeek ); |
1113 | mDayLabelsW.resize( mDaysPerWeek ); | 1113 | mDayLabelsW.resize( mDaysPerWeek ); |
1114 | QFont bfont = font(); | 1114 | QFont bfont = font(); |
1115 | if ( QApplication::desktop()->width() < 650 ) { | 1115 | if ( QApplication::desktop()->width() < 650 ) { |
1116 | bfont.setPointSize( bfont.pointSize() - 2 ); | 1116 | bfont.setPointSize( bfont.pointSize() - 2 ); |
1117 | } | 1117 | } |
1118 | bfont.setBold( true ); | 1118 | bfont.setBold( true ); |
1119 | int i; | 1119 | int i; |
1120 | 1120 | ||
1121 | for( i = 0; i < mDaysPerWeek; i++ ) { | 1121 | for( i = 0; i < mDaysPerWeek; i++ ) { |
1122 | QLabel *label = new QLabel( mMonthView ); | 1122 | QLabel *label = new QLabel( mMonthView ); |
1123 | label->setFont(bfont); | 1123 | label->setFont(bfont); |
1124 | label->setFrameStyle(QFrame::Panel|QFrame::Raised); | 1124 | label->setFrameStyle(QFrame::Panel|QFrame::Raised); |
1125 | label->setLineWidth(1); | 1125 | label->setLineWidth(1); |
1126 | label->setAlignment(AlignCenter); | 1126 | label->setAlignment(AlignCenter); |
1127 | mDayLabels.insert( i, label ); | 1127 | mDayLabels.insert( i, label ); |
1128 | label = new QLabel( mWeekView ); | 1128 | label = new QLabel( mWeekView ); |
1129 | label->setFont(bfont); | 1129 | label->setFont(bfont); |
1130 | label->setFrameStyle(QFrame::Panel|QFrame::Raised); | 1130 | label->setFrameStyle(QFrame::Panel|QFrame::Raised); |
1131 | label->setLineWidth(1); | 1131 | label->setLineWidth(1); |
1132 | label->setAlignment(AlignCenter); | 1132 | label->setAlignment(AlignCenter); |
1133 | mDayLabelsW.insert( i, label ); | 1133 | mDayLabelsW.insert( i, label ); |
1134 | } | 1134 | } |
1135 | 1135 | ||
1136 | bfont.setBold( false ); | 1136 | bfont.setBold( false ); |
1137 | mWeekLabels.resize( mNumWeeks+1 ); | 1137 | mWeekLabels.resize( mNumWeeks+1 ); |
1138 | mWeekLabelsW.resize( 2 ); | 1138 | mWeekLabelsW.resize( 2 ); |
1139 | for( i = 0; i < mNumWeeks+1; i++ ) { | 1139 | for( i = 0; i < mNumWeeks+1; i++ ) { |
1140 | KOWeekButton *label = new KOWeekButton( mMonthView ); | 1140 | KOWeekButton *label = new KOWeekButton( mMonthView ); |
1141 | label->setFocusPolicy(NoFocus); | 1141 | label->setFocusPolicy(NoFocus); |
1142 | label->setFont(bfont); | 1142 | label->setFont(bfont); |
1143 | connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); | 1143 | connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); |
1144 | label->setFlat(true); | 1144 | label->setFlat(true); |
1145 | QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); | 1145 | QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); |
1146 | //label->setFrameStyle(QFrame::Panel|QFrame::Raised); | 1146 | //label->setFrameStyle(QFrame::Panel|QFrame::Raised); |
1147 | //label->setLineWidth(1); | 1147 | //label->setLineWidth(1); |
1148 | //label->setAlignment(AlignCenter); | 1148 | //label->setAlignment(AlignCenter); |
1149 | mWeekLabels.insert( i, label ); | 1149 | mWeekLabels.insert( i, label ); |
1150 | } | 1150 | } |
1151 | mWeekLabels[mNumWeeks]->setText( i18n("W")); | 1151 | mWeekLabels[mNumWeeks]->setText( i18n("W")); |
1152 | mWeekLabels[mNumWeeks]->setFocusPolicy(WheelFocus); | 1152 | mWeekLabels[mNumWeeks]->setFocusPolicy(WheelFocus); |
1153 | QWhatsThis::add(mWeekLabels[mNumWeeks],i18n("Click on this to\nselect week number")); | 1153 | QWhatsThis::add(mWeekLabels[mNumWeeks],i18n("Click on this to\nselect week number")); |
1154 | 1154 | ||
1155 | for( i = 0; i < 1+1; i++ ) { | 1155 | for( i = 0; i < 1+1; i++ ) { |
1156 | KOWeekButton *label = new KOWeekButton( mWeekView ); | 1156 | KOWeekButton *label = new KOWeekButton( mWeekView ); |
1157 | label->setFocusPolicy(NoFocus); | 1157 | label->setFocusPolicy(NoFocus); |
1158 | label->setFont(bfont); | 1158 | label->setFont(bfont); |
1159 | connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); | 1159 | connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); |
1160 | label->setFlat(true); | 1160 | label->setFlat(true); |
1161 | QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); | 1161 | QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); |
1162 | //label->setFrameStyle(QFrame::Panel|QFrame::Raised); | 1162 | //label->setFrameStyle(QFrame::Panel|QFrame::Raised); |
1163 | //label->setLineWidth(1); | 1163 | //label->setLineWidth(1); |
1164 | //label->setAlignment(AlignCenter); | 1164 | //label->setAlignment(AlignCenter); |
1165 | mWeekLabelsW.insert( i, label ); | 1165 | mWeekLabelsW.insert( i, label ); |
1166 | } | 1166 | } |
1167 | mWeekLabelsW[1]->setText( i18n("W")); | 1167 | mWeekLabelsW[1]->setText( i18n("W")); |
1168 | mWeekLabelsW[1]->setFocusPolicy(WheelFocus); | 1168 | mWeekLabelsW[1]->setFocusPolicy(WheelFocus); |
1169 | 1169 | ||
1170 | 1170 | ||
1171 | int row, col; | 1171 | int row, col; |
1172 | mCells.resize( mNumCells ); | 1172 | mCells.resize( mNumCells ); |
1173 | for( row = 0; row < mNumWeeks; ++row ) { | 1173 | for( row = 0; row < mNumWeeks; ++row ) { |
1174 | for( col = 0; col < mDaysPerWeek; ++col ) { | 1174 | for( col = 0; col < mDaysPerWeek; ++col ) { |
1175 | MonthViewCell *cell = new MonthViewCell( this, mMonthView ); | 1175 | MonthViewCell *cell = new MonthViewCell( this, mMonthView ); |
1176 | mCells.insert( row * mDaysPerWeek + col, cell ); | 1176 | mCells.insert( row * mDaysPerWeek + col, cell ); |
1177 | 1177 | ||
1178 | connect( cell, SIGNAL( defaultAction( Incidence * ) ), | 1178 | connect( cell, SIGNAL( defaultAction( Incidence * ) ), |
1179 | SLOT( defaultAction( Incidence * ) ) ); | 1179 | SLOT( defaultAction( Incidence * ) ) ); |
1180 | connect( cell, SIGNAL( newEventSignal( QDateTime ) ), | 1180 | connect( cell, SIGNAL( newEventSignal( QDateTime ) ), |
1181 | SIGNAL( newEventSignal( QDateTime ) ) ); | 1181 | SIGNAL( newEventSignal( QDateTime ) ) ); |
1182 | connect( cell, SIGNAL( showDaySignal( QDate ) ), | 1182 | connect( cell, SIGNAL( showDaySignal( QDate ) ), |
1183 | SIGNAL( showDaySignal( QDate ) ) ); | 1183 | SIGNAL( showDaySignal( QDate ) ) ); |
1184 | connect( cell, SIGNAL( nextCell() ), | 1184 | connect( cell, SIGNAL( nextCell() ), |
1185 | SLOT( nextCell() ) ); | 1185 | SLOT( nextCell() ) ); |
1186 | connect( cell, SIGNAL( prevCell() ), | 1186 | connect( cell, SIGNAL( prevCell() ), |
1187 | SLOT( prevCell() ) ); | 1187 | SLOT( prevCell() ) ); |
1188 | } | 1188 | } |
1189 | } | 1189 | } |
1190 | mCellsW.resize( mDaysPerWeek ); | 1190 | mCellsW.resize( mDaysPerWeek ); |
1191 | for( col = 0; col < mDaysPerWeek; ++col ) { | 1191 | for( col = 0; col < mDaysPerWeek; ++col ) { |
1192 | MonthViewCell *cell = new MonthViewCell( this, mWeekView ); | 1192 | MonthViewCell *cell = new MonthViewCell( this, mWeekView ); |
1193 | mCellsW.insert( col, cell ); | 1193 | mCellsW.insert( col, cell ); |
1194 | 1194 | ||
1195 | connect( cell, SIGNAL( defaultAction( Incidence * ) ), | 1195 | connect( cell, SIGNAL( defaultAction( Incidence * ) ), |
1196 | SLOT( defaultAction( Incidence * ) ) ); | 1196 | SLOT( defaultAction( Incidence * ) ) ); |
1197 | connect( cell, SIGNAL( newEventSignal( QDateTime ) ), | 1197 | connect( cell, SIGNAL( newEventSignal( QDateTime ) ), |
1198 | SIGNAL( newEventSignal( QDateTime ) ) ); | 1198 | SIGNAL( newEventSignal( QDateTime ) ) ); |
1199 | connect( cell, SIGNAL( showDaySignal( QDate ) ), | 1199 | connect( cell, SIGNAL( showDaySignal( QDate ) ), |
1200 | SIGNAL( showDaySignal( QDate ) ) ); | 1200 | SIGNAL( showDaySignal( QDate ) ) ); |
1201 | connect( cell, SIGNAL( nextCell() ), | 1201 | connect( cell, SIGNAL( nextCell() ), |
1202 | SLOT( nextCell() ) ); | 1202 | SLOT( nextCell() ) ); |
1203 | connect( cell, SIGNAL( prevCell() ), | 1203 | connect( cell, SIGNAL( prevCell() ), |
1204 | SLOT( prevCell() ) ); | 1204 | SLOT( prevCell() ) ); |
1205 | cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont ); | 1205 | cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont ); |
1206 | } | 1206 | } |
1207 | 1207 | ||
1208 | //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) ); | 1208 | //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) ); |
1209 | mContextMenu = eventPopup(); | 1209 | mContextMenu = eventPopup(); |
1210 | mContextMenu->addAdditionalItem(QIconSet(QPixmap()), | 1210 | mContextMenu->addAdditionalItem(QIconSet(QPixmap()), |
1211 | i18n("New Event..."),this, | 1211 | i18n("New Event..."),this, |
1212 | SLOT(slotNewEvent()),false); | 1212 | SLOT(slotNewEvent()),false); |
1213 | mContextMenu->addAdditionalItem(QIconSet(QPixmap()), | 1213 | mContextMenu->addAdditionalItem(QIconSet(QPixmap()), |
1214 | i18n("New Todo..."),this, | 1214 | i18n("New Todo..."),this, |
1215 | SLOT(slotNewTodo()),false); | 1215 | SLOT(slotNewTodo()),false); |
1216 | mContextMenu->addAdditionalItem(QIconSet(QPixmap()), | 1216 | mContextMenu->addAdditionalItem(QIconSet(QPixmap()), |
1217 | i18n("Journal"),this, | 1217 | i18n("Journal"),this, |
1218 | SLOT(slotEditJournal()),false); | 1218 | SLOT(slotEditJournal()),false); |
1219 | 1219 | ||
1220 | 1220 | ||
1221 | 1221 | ||
1222 | QString pathString = ""; | 1222 | QString pathString = ""; |
1223 | if ( !KOPrefs::instance()->mToolBarMiniIcons ) { | 1223 | if ( !KOPrefs::instance()->mToolBarMiniIcons ) { |
1224 | if ( QApplication::desktop()->width() < 480 ) | 1224 | if ( QApplication::desktop()->width() < 480 ) |
1225 | pathString += "icons16/"; | 1225 | pathString += "icons16/"; |
1226 | } else | 1226 | } else |
1227 | pathString += "iconsmini/"; | 1227 | pathString += "iconsmini/"; |
1228 | mNewItemMenu = new QPopupMenu( this ); | 1228 | mNewItemMenu = new QPopupMenu( this ); |
1229 | mNewItemMenu->insertItem( SmallIcon( pathString +"newevent" ), i18n("New Event..."),this, SLOT(slotNewEvent())); | 1229 | mNewItemMenu->insertItem( SmallIcon( pathString +"newevent" ), i18n("New Event..."),this, SLOT(slotNewEvent())); |
1230 | mNewItemMenu->insertItem( SmallIcon( pathString +"newtodo" ),i18n("New Todo..."),this,SLOT(slotNewTodo()),false); | 1230 | mNewItemMenu->insertItem( SmallIcon( pathString +"newtodo" ),i18n("New Todo..."),this,SLOT(slotNewTodo()),false); |
1231 | mNewItemMenu->insertItem( SmallIcon( pathString +"journal" ),i18n("Journal"),this,SLOT(slotEditJournal()),false); | 1231 | mNewItemMenu->insertItem( SmallIcon( pathString +"journal" ),i18n("Journal"),this,SLOT(slotEditJournal()),false); |
1232 | 1232 | ||
1233 | // updateConfig(); //useless here... | 1233 | // updateConfig(); //useless here... |
1234 | // ... but we need mWidthLongDayLabel computed | 1234 | // ... but we need mWidthLongDayLabel computed |
1235 | QFontMetrics fontmetric(mDayLabels[0]->font()); | 1235 | QFontMetrics fontmetric(mDayLabels[0]->font()); |
1236 | mWidthLongDayLabel = 0; | 1236 | mWidthLongDayLabel = 0; |
1237 | for (int i = 0; i < 7; i++) { | 1237 | for (int i = 0; i < 7; i++) { |
1238 | int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); | 1238 | int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); |
1239 | if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; | 1239 | if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; |
1240 | } | 1240 | } |
1241 | 1241 | ||
1242 | //mWeekLabels[mNumWeeks]->setText( i18n("W")); | 1242 | //mWeekLabels[mNumWeeks]->setText( i18n("W")); |
1243 | 1243 | ||
1244 | #if 0 | 1244 | #if 0 |
1245 | if ( mShowWeekView ) | 1245 | if ( mShowWeekView ) |
1246 | mWidStack->raiseWidget( mWeekView ); | 1246 | mWidStack->raiseWidget( mWeekView ); |
1247 | else | 1247 | else |
1248 | mWidStack->raiseWidget( mMonthView ); | 1248 | mWidStack->raiseWidget( mMonthView ); |
1249 | #endif | 1249 | #endif |
1250 | 1250 | ||
1251 | emit incidenceSelected( 0 ); | 1251 | emit incidenceSelected( 0 ); |
1252 | 1252 | ||
1253 | mComputeLayoutTimer = new QTimer( this ); | 1253 | mComputeLayoutTimer = new QTimer( this ); |
1254 | connect (mComputeLayoutTimer ,SIGNAL(timeout()), this, SLOT ( slotComputeLayout())); | 1254 | connect (mComputeLayoutTimer ,SIGNAL(timeout()), this, SLOT ( slotComputeLayout())); |
1255 | 1255 | ||
1256 | 1256 | ||
1257 | #ifndef DESKTOP_VERSION | 1257 | #ifndef DESKTOP_VERSION |
1258 | resize( QApplication::desktop()->size() ); | 1258 | resize( QApplication::desktop()->size() ); |
1259 | #else | 1259 | #else |
1260 | resize(640, 480 ); | 1260 | resize(640, 480 ); |
1261 | updatePossible = true; | 1261 | updatePossible = true; |
1262 | #endif | 1262 | #endif |
1263 | computeLayout(); | 1263 | computeLayout(); |
1264 | 1264 | ||
1265 | if ( mShowWeekView ) | 1265 | if ( mShowWeekView ) |
1266 | mWidStack->raiseWidget( mWeekView ); | 1266 | mWidStack->raiseWidget( mWeekView ); |
1267 | else | 1267 | else |
1268 | mWidStack->raiseWidget( mMonthView ); | 1268 | mWidStack->raiseWidget( mMonthView ); |
1269 | } | 1269 | } |
1270 | 1270 | ||
1271 | KOMonthView::~KOMonthView() | 1271 | KOMonthView::~KOMonthView() |
1272 | { | 1272 | { |
1273 | delete mContextMenu; | 1273 | delete mContextMenu; |
1274 | } | 1274 | } |
1275 | 1275 | ||
1276 | void KOMonthView::selectInternalWeekNum ( int n ) | 1276 | void KOMonthView::selectInternalWeekNum ( int n ) |
1277 | { | 1277 | { |
1278 | switchView(); | 1278 | switchView(); |
1279 | if ( !KOPrefs::instance()->mMonthViewWeek ) | 1279 | if ( !KOPrefs::instance()->mMonthViewWeek ) |
1280 | emit selectMonth (); | 1280 | emit selectMonth (); |
1281 | else | 1281 | else |
1282 | emit selectWeekNum ( n ); | 1282 | emit selectWeekNum ( n ); |
1283 | } | 1283 | } |
1284 | 1284 | ||
1285 | int KOMonthView::currentWeek() | 1285 | int KOMonthView::currentWeek() |
1286 | { | 1286 | { |
1287 | if ( mShowWeekView ) | 1287 | if ( mShowWeekView ) |
1288 | return mWeekLabelsW[0]->getWeekNum(); | 1288 | return mWeekLabelsW[0]->getWeekNum(); |
1289 | return mWeekLabels[0]->getWeekNum(); | 1289 | return mWeekLabels[0]->getWeekNum(); |
1290 | } | 1290 | } |
1291 | void KOMonthView::switchView() | 1291 | void KOMonthView::switchView() |
1292 | { | 1292 | { |
1293 | if ( selectedCell( ) ) | 1293 | if ( selectedCell( ) ) |
1294 | selectedCell()->deselect(); | 1294 | selectedCell()->deselect(); |
1295 | mShowWeekView = !mShowWeekView; | 1295 | mShowWeekView = !mShowWeekView; |
1296 | KOPrefs::instance()->mMonthViewWeek = mShowWeekView; | 1296 | KOPrefs::instance()->mMonthViewWeek = mShowWeekView; |
1297 | if ( clPending ) { | 1297 | if ( clPending ) { |
1298 | computeLayout(); | 1298 | computeLayout(); |
1299 | updateConfig(); | 1299 | updateConfig(); |
1300 | } | 1300 | } |
1301 | if ( mShowWeekView ) | 1301 | if ( mShowWeekView ) |
1302 | mWidStack->raiseWidget( mWeekView ); | 1302 | mWidStack->raiseWidget( mWeekView ); |
1303 | else | 1303 | else |
1304 | mWidStack->raiseWidget( mMonthView ); | 1304 | mWidStack->raiseWidget( mMonthView ); |
1305 | clPending = false; | 1305 | clPending = false; |
1306 | } | 1306 | } |
1307 | 1307 | ||
1308 | int KOMonthView::maxDatesHint() | 1308 | int KOMonthView::maxDatesHint() |
1309 | { | 1309 | { |
1310 | return mNumCells; | 1310 | return mNumCells; |
1311 | } | 1311 | } |
1312 | 1312 | ||
1313 | int KOMonthView::currentDateCount() | 1313 | int KOMonthView::currentDateCount() |
1314 | { | 1314 | { |
1315 | return mNumCells; | 1315 | return mNumCells; |
1316 | } | 1316 | } |
1317 | 1317 | ||
1318 | QPtrList<Incidence> KOMonthView::selectedIncidences() | 1318 | QPtrList<Incidence> KOMonthView::selectedIncidences() |
1319 | { | 1319 | { |
1320 | QPtrList<Incidence> selected; | 1320 | QPtrList<Incidence> selected; |
1321 | 1321 | ||
1322 | if ( mSelectedCell ) { | 1322 | if ( mSelectedCell ) { |
1323 | Incidence *incidence = mSelectedCell->selectedIncidence(); | 1323 | Incidence *incidence = mSelectedCell->selectedIncidence(); |
1324 | if ( incidence ) selected.append( incidence ); | 1324 | if ( incidence ) selected.append( incidence ); |
1325 | } | 1325 | } |
1326 | 1326 | ||
1327 | return selected; | 1327 | return selected; |
1328 | } | 1328 | } |
1329 | 1329 | ||
1330 | DateList KOMonthView::selectedDates() | 1330 | DateList KOMonthView::selectedDates() |
1331 | { | 1331 | { |
1332 | DateList selected; | 1332 | DateList selected; |
1333 | 1333 | ||
1334 | if ( mSelectedCell ) { | 1334 | if ( mSelectedCell ) { |
1335 | QDate qd = mSelectedCell->selectedIncidenceDate(); | 1335 | QDate qd = mSelectedCell->selectedIncidenceDate(); |
1336 | if ( qd.isValid() ) selected.append( qd ); | 1336 | if ( qd.isValid() ) selected.append( qd ); |
1337 | } | 1337 | } |
1338 | 1338 | ||
1339 | return selected; | 1339 | return selected; |
1340 | } | 1340 | } |
1341 | 1341 | ||
1342 | void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd, | 1342 | void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd, |
1343 | const QDate &td) | 1343 | const QDate &td) |
1344 | { | 1344 | { |
1345 | #ifndef KORG_NOPRINTER | 1345 | #ifndef KORG_NOPRINTER |
1346 | calPrinter->preview(CalPrinter::Month, fd, td); | 1346 | calPrinter->preview(CalPrinter::Month, fd, td); |
1347 | #endif | 1347 | #endif |
1348 | } | 1348 | } |
1349 | 1349 | ||
1350 | void KOMonthView::updateConfig() | 1350 | void KOMonthView::updateConfig() |
1351 | { | 1351 | { |
1352 | 1352 | ||
1353 | int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); | 1353 | int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); |
1354 | 1354 | ||
1355 | if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) { | 1355 | if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) { |
1356 | mWeekStartsMonday = true; | 1356 | mWeekStartsMonday = true; |
1357 | } | 1357 | } |
1358 | QFontMetrics fontmetric(mDayLabels[0]->font()); | 1358 | QFontMetrics fontmetric(mDayLabels[0]->font()); |
1359 | mWidthLongDayLabel = 0; | 1359 | mWidthLongDayLabel = 0; |
1360 | 1360 | ||
1361 | for (int i = 0; i < 7; i++) { | 1361 | for (int i = 0; i < 7; i++) { |
1362 | int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); | 1362 | int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); |
1363 | if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; | 1363 | if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; |
1364 | } | 1364 | } |
1365 | bool temp = mShowSatSunComp ; | 1365 | bool temp = mShowSatSunComp ; |
1366 | mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; | 1366 | mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; |
1367 | if ( ! mShowWeekView ) { | 1367 | if ( ! mShowWeekView ) { |
1368 | if ( temp != KOPrefs::instance()->mMonthViewSatSunTog ) | 1368 | if ( temp != KOPrefs::instance()->mMonthViewSatSunTog ) |
1369 | computeLayout(); | 1369 | computeLayout(); |
1370 | } | 1370 | } |
1371 | updateDayLabels(); | 1371 | updateDayLabels(); |
1372 | //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks); | 1372 | //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks); |
1373 | //int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks; | 1373 | //int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks; |
1374 | //resizeEvent( 0 ); | 1374 | //resizeEvent( 0 ); |
1375 | for (uint i = 0; i < mCells.count(); ++i) { | 1375 | for (uint i = 0; i < mCells.count(); ++i) { |
1376 | mCells[i]->updateConfig(); | 1376 | mCells[i]->updateConfig(); |
1377 | } | 1377 | } |
1378 | 1378 | ||
1379 | for (uint i = 0; i < mCellsW.count(); ++i) { | 1379 | for (uint i = 0; i < mCellsW.count(); ++i) { |
1380 | mCellsW[i]->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont); | 1380 | mCellsW[i]->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont); |
1381 | } | 1381 | } |
1382 | #ifdef DESKTOP_VERSION | 1382 | #ifdef DESKTOP_VERSION |
1383 | MonthViewCell::toolTipGroup()->setEnabled(KOPrefs::instance()->mEnableToolTips); | 1383 | MonthViewCell::toolTipGroup()->setEnabled(KOPrefs::instance()->mEnableToolTips); |
1384 | #endif | 1384 | #endif |
1385 | updateView(); | 1385 | updateView(); |
1386 | } | 1386 | } |
1387 | 1387 | ||
1388 | void KOMonthView::updateDayLabels() | 1388 | void KOMonthView::updateDayLabels() |
1389 | { | 1389 | { |
1390 | 1390 | ||
1391 | QPtrVector<QLabel> *mDayLabelsT; | 1391 | QPtrVector<QLabel> *mDayLabelsT; |
1392 | 1392 | ||
1393 | mDayLabelsT = &mDayLabelsW; | 1393 | mDayLabelsT = &mDayLabelsW; |
1394 | for (int i = 0; i < 7; i++) { | 1394 | for (int i = 0; i < 7; i++) { |
1395 | { | 1395 | { |
1396 | bool show = mShortDayLabelsW; | 1396 | bool show = mShortDayLabelsW; |
1397 | if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) | 1397 | if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) |
1398 | show = true; | 1398 | show = true; |
1399 | (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); | 1399 | (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); |
1400 | } | 1400 | } |
1401 | } | 1401 | } |
1402 | mDayLabelsT = &mDayLabels; | 1402 | mDayLabelsT = &mDayLabels; |
1403 | for (int i = 0; i < 7; i++) { | 1403 | for (int i = 0; i < 7; i++) { |
1404 | if (KGlobal::locale()->weekStartsMonday() || KOPrefs::instance()->mMonthViewSatSunTog ) { | 1404 | if (KGlobal::locale()->weekStartsMonday() || KOPrefs::instance()->mMonthViewSatSunTog ) { |
1405 | bool show = mShortDayLabelsM; | 1405 | bool show = mShortDayLabelsM; |
1406 | if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) | 1406 | if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) |
1407 | show = true; | 1407 | show = true; |
1408 | (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); | 1408 | (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); |
1409 | } else { | 1409 | } else { |
1410 | if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsM)); | 1410 | if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsM)); |
1411 | else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsM)); | 1411 | else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsM)); |
1412 | 1412 | ||
1413 | } | 1413 | } |
1414 | } | 1414 | } |
1415 | 1415 | ||
1416 | } | 1416 | } |
1417 | 1417 | ||
1418 | void KOMonthView::showDates(const QDate &start, const QDate &) | 1418 | void KOMonthView::showDates(const QDate &start, const QDate &) |
1419 | { | 1419 | { |
1420 | // kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl; | 1420 | // kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl; |
1421 | 1421 | ||
1422 | QPtrVector<MonthViewCell> *cells; | 1422 | QPtrVector<MonthViewCell> *cells; |
1423 | QPtrVector<QLabel> *dayLabels; | 1423 | QPtrVector<QLabel> *dayLabels; |
1424 | QPtrVector<KOWeekButton> *weekLabels; | 1424 | QPtrVector<KOWeekButton> *weekLabels; |
1425 | int weekNum = 6; | 1425 | int weekNum = 6; |
1426 | mStartDate = start; | 1426 | mStartDate = start; |
1427 | if ( mShowWeekView ) { | 1427 | if ( mShowWeekView ) { |
1428 | weekNum = 1; | 1428 | weekNum = 1; |
1429 | cells = &mCellsW; | 1429 | cells = &mCellsW; |
1430 | dayLabels = &mDayLabelsW; | 1430 | dayLabels = &mDayLabelsW; |
1431 | weekLabels = &mWeekLabelsW; | 1431 | weekLabels = &mWeekLabelsW; |
1432 | if ( !KGlobal::locale()->weekStartsMonday() ) { | 1432 | if ( !KGlobal::locale()->weekStartsMonday() ) { |
1433 | mStartDate = mStartDate.addDays( 1 ); | 1433 | mStartDate = mStartDate.addDays( 1 ); |
1434 | } | 1434 | } |
1435 | } else { | 1435 | } else { |
1436 | cells = &mCells; | 1436 | cells = &mCells; |
1437 | dayLabels = &mDayLabels; | 1437 | dayLabels = &mDayLabels; |
1438 | weekLabels = &mWeekLabels; | 1438 | weekLabels = &mWeekLabels; |
1439 | } | 1439 | } |
1440 | 1440 | ||
1441 | int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); | 1441 | int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); |
1442 | 1442 | ||
1443 | if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) { | 1443 | if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) { |
1444 | mWeekStartsMonday = true; | 1444 | mWeekStartsMonday = true; |
1445 | } | 1445 | } |
1446 | int startWeekDay = mWeekStartsMonday ? 1 : 7; | 1446 | int startWeekDay = mWeekStartsMonday ? 1 : 7; |
1447 | 1447 | ||
1448 | while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) { | 1448 | while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) { |
1449 | mStartDate = mStartDate.addDays( -1 ); | 1449 | mStartDate = mStartDate.addDays( -1 ); |
1450 | } | 1450 | } |
1451 | bool primary = false; | 1451 | bool primary = false; |
1452 | uint i; | 1452 | uint i; |
1453 | for( i = 0; i < (*cells).size(); ++i ) { | 1453 | for( i = 0; i < (*cells).size(); ++i ) { |
1454 | QDate date = mStartDate.addDays( i ); | 1454 | QDate date = mStartDate.addDays( i ); |
1455 | (*cells)[i]->setDate( date ); | 1455 | (*cells)[i]->setDate( date ); |
1456 | 1456 | ||
1457 | #ifndef KORG_NOPLUGINS | 1457 | #ifndef KORG_NOPLUGINS |
1458 | // add holiday, if present | 1458 | // add holiday, if present |
1459 | QString hstring(KOCore::self()->holiday(date)); | 1459 | QString hstring(KOCore::self()->holiday(date)); |
1460 | (*cells)[i]->setHoliday( hstring ); | 1460 | (*cells)[i]->setHoliday( hstring ); |
1461 | #endif | 1461 | #endif |
1462 | 1462 | ||
1463 | } | 1463 | } |
1464 | QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 ); | 1464 | QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 ); |
1465 | for( i = 0; i < weekNum; ++i ) { | 1465 | for( i = 0; i < weekNum; ++i ) { |
1466 | int wno; | 1466 | int wno; |
1467 | // remember, according to ISO 8601, the first week of the year is the | 1467 | // remember, according to ISO 8601, the first week of the year is the |
1468 | // first week that contains a thursday. Thus we must subtract off 4, | 1468 | // first week that contains a thursday. Thus we must subtract off 4, |
1469 | // not just 1. | 1469 | // not just 1. |
1470 | int dayOfYear = date.dayOfYear(); | 1470 | int dayOfYear = date.dayOfYear(); |
1471 | if (dayOfYear % 7 != 0) | 1471 | if (dayOfYear % 7 != 0) |
1472 | wno = dayOfYear / 7 + 1; | 1472 | wno = dayOfYear / 7 + 1; |
1473 | else | 1473 | else |
1474 | wno =dayOfYear / 7; | 1474 | wno =dayOfYear / 7; |
1475 | (*weekLabels)[i]->setWeekNum( wno ); | 1475 | (*weekLabels)[i]->setWeekNum( wno ); |
1476 | date = date.addDays( 7 ); | 1476 | date = date.addDays( 7 ); |
1477 | } | 1477 | } |
1478 | updateView(); | 1478 | updateView(); |
1479 | } | 1479 | } |
1480 | 1480 | ||
1481 | void KOMonthView::showEvents(QPtrList<Event>) | 1481 | void KOMonthView::showEvents(QPtrList<Event>) |
1482 | { | 1482 | { |
1483 | qDebug("KOMonthView::selectEvents is not implemented yet. "); | 1483 | qDebug("KOMonthView::selectEvents is not implemented yet. "); |
1484 | } | 1484 | } |
1485 | 1485 | ||
1486 | void KOMonthView::changeEventDisplay(Event *, int) | 1486 | void KOMonthView::changeEventDisplay(Event *, int) |
1487 | { | 1487 | { |
1488 | // this should be re-written to be much more efficient, but this | 1488 | // this should be re-written to be much more efficient, but this |
1489 | // quick-and-dirty-hack gets the job done for right now. | 1489 | // quick-and-dirty-hack gets the job done for right now. |
1490 | //qDebug("KOMonthView::changeEventDisplay "); | 1490 | //qDebug("KOMonthView::changeEventDisplay "); |
1491 | updateView(); | 1491 | updateView(); |
1492 | } | 1492 | } |
1493 | 1493 | ||
1494 | void KOMonthView::updateView() | 1494 | void KOMonthView::updateView() |
1495 | { | 1495 | { |
1496 | 1496 | ||
1497 | if ( !updatePossible ) | 1497 | if ( !updatePossible ) |
1498 | return; | 1498 | return; |
1499 | //qDebug("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU "); | 1499 | //qDebug("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU "); |
1500 | //QTime ti; | 1500 | //QTime ti; |
1501 | //ti.start(); | 1501 | //ti.start(); |
1502 | clearSelection(); | 1502 | clearSelection(); |
1503 | QPtrVector<MonthViewCell> *cells; | 1503 | QPtrVector<MonthViewCell> *cells; |
1504 | if ( mShowWeekView ) { | 1504 | if ( mShowWeekView ) { |
1505 | cells = &mCellsW; | 1505 | cells = &mCellsW; |
1506 | } else { | 1506 | } else { |
1507 | cells = &mCells; | 1507 | cells = &mCells; |
1508 | } | 1508 | } |
1509 | #if 1 | 1509 | #if 1 |
1510 | int i; | 1510 | int i; |
1511 | int timeSpan = (*cells).size()-1; | 1511 | int timeSpan = (*cells).size()-1; |
1512 | if ( KOPrefs::instance()->mMonthViewWeek ) | 1512 | if ( KOPrefs::instance()->mMonthViewWeek ) |
1513 | timeSpan = 6; | 1513 | timeSpan = 6; |
1514 | for( i = 0; i < timeSpan + 1; ++i ) { | 1514 | for( i = 0; i < timeSpan + 1; ++i ) { |
1515 | (*cells)[i]->startUpdateCell(); | 1515 | (*cells)[i]->startUpdateCell(); |
1516 | } | 1516 | } |
1517 | 1517 | ||
1518 | QPtrList<Event> events = calendar()->events(); | 1518 | QPtrList<Event> events = calendar()->events(); |
1519 | Event *event; | 1519 | Event *event; |
1520 | QDateTime dt; | 1520 | QDateTime dt; |
1521 | bool ok; | 1521 | bool ok; |
1522 | QDate endDate = mStartDate.addDays( timeSpan ); | 1522 | QDate endDate = mStartDate.addDays( timeSpan ); |
1523 | for( event = events.first(); event; event = events.next() ) { // for event | 1523 | for( event = events.first(); event; event = events.next() ) { // for event |
1524 | if ( event->doesRecur() ) { | 1524 | if ( event->doesRecur() ) { |
1525 | bool last; | 1525 | bool last; |
1526 | QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); | 1526 | QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); |
1527 | QDateTime incidenceEnd; | 1527 | QDateTime incidenceEnd; |
1528 | int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); | 1528 | int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); |
1529 | bool invalid = false; | 1529 | bool invalid = false; |
1530 | while( true ) { | 1530 | while( true ) { |
1531 | if ( incidenceStart.isValid() ) { | 1531 | if ( incidenceStart.isValid() ) { |
1532 | incidenceEnd = incidenceStart.addDays( eventlen ); | 1532 | incidenceEnd = incidenceStart.addDays( eventlen ); |
1533 | int st = incidenceStart.date().daysTo( endDate ); | 1533 | int st = incidenceStart.date().daysTo( endDate ); |
1534 | if ( st >= 0 ) { // start before timeend | 1534 | if ( st >= 0 ) { // start before timeend |
1535 | int end = mStartDate.daysTo( incidenceEnd.date() ); | 1535 | int end = mStartDate.daysTo( incidenceEnd.date() ); |
1536 | if ( end >= 0 ) { // end after timestart --- got one! | 1536 | if ( end >= 0 ) { // end after timestart --- got one! |
1537 | //normalize | 1537 | //normalize |
1538 | st = timeSpan - st; | 1538 | st = timeSpan - st; |
1539 | if ( st < 0 ) st = 0; | 1539 | if ( st < 0 ) st = 0; |
1540 | if ( end > timeSpan ) end = timeSpan; | 1540 | if ( end > timeSpan ) end = timeSpan; |
1541 | int iii; | 1541 | int iii; |
1542 | //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); | 1542 | //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); |
1543 | for ( iii = st;iii<= end;++iii) | 1543 | for ( iii = st;iii<= end;++iii) |
1544 | (*cells)[iii]->insertEvent( event ); | 1544 | (*cells)[iii]->insertEvent( event ); |
1545 | } | 1545 | } |
1546 | } | 1546 | } |
1547 | } else { | 1547 | } else { |
1548 | if ( invalid ) | 1548 | if ( invalid ) |
1549 | break; | 1549 | break; |
1550 | invalid = true; | 1550 | invalid = true; |
1551 | //qDebug("invalid %s", event->summary().latin1()); | 1551 | //qDebug("invalid %s", event->summary().latin1()); |
1552 | incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; | 1552 | incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; |
1553 | } | 1553 | } |
1554 | if ( last ) | 1554 | if ( last ) |
1555 | break; | 1555 | break; |
1556 | bool ok; | 1556 | bool ok; |
1557 | incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); | 1557 | incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); |
1558 | if ( ! ok ) | 1558 | if ( ! ok ) |
1559 | break; | 1559 | break; |
1560 | if ( incidenceStart.date() > endDate ) | 1560 | if ( incidenceStart.date() > endDate ) |
1561 | break; | 1561 | break; |
1562 | } | 1562 | } |
1563 | } else { // no recur | 1563 | } else { // no recur |
1564 | if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") ) | 1564 | if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") ) |
1565 | if ( event->uid().left(15) == QString("last-syncEvent-") ) | 1565 | if ( event->uid().left(15) == QString("last-syncEvent-") ) |
1566 | continue; | 1566 | continue; |
1567 | int st = event->dtStart().date().daysTo( endDate ); | 1567 | int st = event->dtStart().date().daysTo( endDate ); |
1568 | if ( st >= 0 ) { // start before timeend | 1568 | if ( st >= 0 ) { // start before timeend |
1569 | int end = mStartDate.daysTo( event->dtEnd().date() ); | 1569 | int end = mStartDate.daysTo( event->dtEnd().date() ); |
1570 | if ( end >= 0 ) { // end after timestart --- got one! | 1570 | if ( end >= 0 ) { // end after timestart --- got one! |
1571 | //normalize | 1571 | //normalize |
1572 | st = timeSpan - st; | 1572 | st = timeSpan - st; |
1573 | if ( st < 0 ) st = 0; | 1573 | if ( st < 0 ) st = 0; |
1574 | if ( end > timeSpan ) end = timeSpan; | 1574 | if ( end > timeSpan ) end = timeSpan; |
1575 | int iii; | 1575 | int iii; |
1576 | for ( iii = st;iii<= end;++iii) | 1576 | for ( iii = st;iii<= end;++iii) |
1577 | (*cells)[iii]->insertEvent( event ); | 1577 | (*cells)[iii]->insertEvent( event ); |
1578 | } | 1578 | } |
1579 | } | 1579 | } |
1580 | } | 1580 | } |
1581 | } | 1581 | } |
1582 | // insert due todos | 1582 | // insert due todos |
1583 | QPtrList<Todo> todos = calendar()->todos( ); | 1583 | QPtrList<Todo> todos = calendar()->todos( ); |
1584 | Todo *todo; | 1584 | Todo *todo; |
1585 | for(todo = todos.first(); todo; todo = todos.next()) { | 1585 | for(todo = todos.first(); todo; todo = todos.next()) { |
1586 | //insertTodo( todo ); | 1586 | //insertTodo( todo ); |
1587 | if ( todo->hasDueDate() ) { | 1587 | if ( todo->hasDueDate() ) { |
1588 | int day = mStartDate.daysTo( todo->dtDue().date() ); | 1588 | int day = mStartDate.daysTo( todo->dtDue().date() ); |
1589 | if ( day >= 0 && day < timeSpan + 1) { | 1589 | if ( day >= 0 && day < timeSpan + 1) { |
1590 | (*cells)[day]->insertTodo( todo ); | 1590 | (*cells)[day]->insertTodo( todo ); |
1591 | } | 1591 | } |
1592 | } | 1592 | } |
1593 | } | 1593 | } |
1594 | 1594 | ||
1595 | for( i = 0; i < timeSpan+1; ++i ) { | 1595 | for( i = 0; i < timeSpan+1; ++i ) { |
1596 | (*cells)[i]->finishUpdateCell(); | 1596 | (*cells)[i]->finishUpdateCell(); |
1597 | } | 1597 | } |
1598 | processSelectionChange(); | 1598 | processSelectionChange(); |
1599 | //qApp->processEvents(); | 1599 | //qApp->processEvents(); |
1600 | for( i = 0; i < timeSpan+1; ++i ) { | 1600 | for( i = 0; i < timeSpan+1; ++i ) { |
1601 | (*cells)[i]->repaintfinishUpdateCell(); | 1601 | (*cells)[i]->repaintfinishUpdateCell(); |
1602 | } | 1602 | } |
1603 | setKeyBFocus(); | 1603 | setKeyBFocus(); |
1604 | #else | 1604 | #else |
1605 | // old code | 1605 | // old code |
1606 | //qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "); | 1606 | //qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "); |
1607 | int i; | 1607 | int i; |
1608 | for( i = 0; i < (*cells).count(); ++i ) { | 1608 | for( i = 0; i < (*cells).count(); ++i ) { |
1609 | (*cells)[i]->updateCell(); | 1609 | (*cells)[i]->updateCell(); |
1610 | } | 1610 | } |
1611 | 1611 | ||
1612 | //qDebug("KOMonthView::updateView() "); | 1612 | //qDebug("KOMonthView::updateView() "); |
1613 | processSelectionChange(); | 1613 | processSelectionChange(); |
1614 | // qDebug("---------------------------------------------------------------------+ "); | 1614 | // qDebug("---------------------------------------------------------------------+ "); |
1615 | (*cells)[0]->setFocus(); | 1615 | (*cells)[0]->setFocus(); |
1616 | #endif | 1616 | #endif |
1617 | 1617 | ||
1618 | //qDebug("update time %d ", ti.elapsed()); | 1618 | //qDebug("update time %d ", ti.elapsed()); |
1619 | } | 1619 | } |
1620 | 1620 | ||
1621 | void KOMonthView::setKeyBoardFocus() | 1621 | void KOMonthView::setKeyBoardFocus() |
1622 | { | 1622 | { |
1623 | //qDebug("KOMonthView::setKeyBoardFocus() "); | 1623 | //qDebug("KOMonthView::setKeyBoardFocus() "); |
1624 | bool shootAgain = false; | 1624 | bool shootAgain = false; |
1625 | if ( mShowWeekView ) { | 1625 | if ( mShowWeekView ) { |
1626 | shootAgain = !mWeekLabelsW[1]->hasFocus(); | 1626 | shootAgain = !mWeekLabelsW[1]->hasFocus(); |
1627 | mWeekLabelsW[1]->setFocus(); | 1627 | mWeekLabelsW[1]->setFocus(); |
1628 | } | 1628 | } |
1629 | else { | 1629 | else { |
1630 | shootAgain = !mWeekLabels[mNumWeeks]->hasFocus(); | 1630 | shootAgain = !mWeekLabels[mNumWeeks]->hasFocus(); |
1631 | mWeekLabels[mNumWeeks]->setFocus(); | 1631 | mWeekLabels[mNumWeeks]->setFocus(); |
1632 | } | 1632 | } |
1633 | if ( shootAgain ) { | 1633 | if ( shootAgain ) { |
1634 | QTimer::singleShot( 0, this, SLOT ( setKeyBFocus() ) ); | 1634 | QTimer::singleShot( 0, this, SLOT ( setKeyBFocus() ) ); |
1635 | } | 1635 | } |
1636 | } | 1636 | } |
1637 | void KOMonthView::setKeyBFocus() | 1637 | void KOMonthView::setKeyBFocus() |
1638 | { | 1638 | { |
1639 | //qDebug("KOMonthView::setKeyBFocus() "); | 1639 | //qDebug("KOMonthView::setKeyBFocus() "); |
1640 | QTimer::singleShot( 0, this, SLOT ( setKeyBoardFocus() ) ); | 1640 | QTimer::singleShot( 0, this, SLOT ( setKeyBoardFocus() ) ); |
1641 | } | 1641 | } |
1642 | void KOMonthView::resizeEvent(QResizeEvent * e) | 1642 | void KOMonthView::resizeEvent(QResizeEvent * e) |
1643 | { | 1643 | { |
1644 | //qDebug("KOMonthView::resizeEvent %d %d -- %d %d ", e->size().width(), e->size().height(), e->oldSize().width(), e->oldSize().height()); | 1644 | //qDebug("KOMonthView::resizeEvent %d %d -- %d %d ", e->size().width(), e->size().height(), e->oldSize().width(), e->oldSize().height()); |
1645 | if ( isVisible() ) { | 1645 | if ( isVisible() ) { |
1646 | //qDebug("KOMonthView::isVisible "); | 1646 | //qDebug("KOMonthView::isVisible "); |
1647 | slotComputeLayout(); | 1647 | slotComputeLayout(); |
1648 | } else | 1648 | } else |
1649 | mComputeLayoutTimer->start( 100 ); | 1649 | mComputeLayoutTimer->start( 100 ); |
1650 | } | 1650 | } |
1651 | 1651 | ||
1652 | void KOMonthView::slotComputeLayout() | 1652 | void KOMonthView::slotComputeLayout() |
1653 | { | 1653 | { |
1654 | mComputeLayoutTimer->stop(); | 1654 | mComputeLayoutTimer->stop(); |
1655 | //qDebug("KOMonthView::Post - resizeEvent %d %d ", width(), height() ); | 1655 | //qDebug("KOMonthView::Post - resizeEvent %d %d ", width(), height() ); |
1656 | computeLayout(); | 1656 | computeLayout(); |
1657 | clPending = true; | 1657 | clPending = true; |
1658 | setKeyBFocus(); | 1658 | setKeyBFocus(); |
1659 | } | 1659 | } |
1660 | void KOMonthView::computeLayoutWeek() | 1660 | void KOMonthView::computeLayoutWeek() |
1661 | { | 1661 | { |
1662 | static int lastWid = 0; | 1662 | static int lastWid = 0; |
1663 | static int lastHei = 0; | 1663 | static int lastHei = 0; |
1664 | int daysToShow; | 1664 | int daysToShow; |
1665 | bool combinedSatSun = false; | 1665 | bool combinedSatSun = false; |
1666 | if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { | 1666 | if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { |
1667 | daysToShow = 6; | 1667 | daysToShow = 6; |
1668 | combinedSatSun = true; | 1668 | combinedSatSun = true; |
1669 | } | 1669 | } |
1670 | int tWid = topLevelWidget()->size().width(); | 1670 | int tWid = topLevelWidget()->size().width(); |
1671 | int tHei = topLevelWidget()->size().height(); | 1671 | int tHei = topLevelWidget()->size().height(); |
1672 | 1672 | ||
1673 | int wid = width();//e | 1673 | int wid = width();//e |
1674 | int hei = height()-1-mNavigatorBar->height(); | 1674 | int hei = height()-1-mNavigatorBar->height(); |
1675 | 1675 | ||
1676 | if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) | 1676 | if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) |
1677 | return; | 1677 | return; |
1678 | 1678 | ||
1679 | if ( lastWid == width() && lastHei == height() ) { | 1679 | if ( lastWid == width() && lastHei == height() ) { |
1680 | //qDebug("KOListWeekView::No compute layout needed "); | 1680 | //qDebug("KOListWeekView::No compute layout needed "); |
1681 | return; | 1681 | return; |
1682 | } | 1682 | } |
1683 | lastWid = width(); | 1683 | lastWid = width(); |
1684 | lastHei = height(); | 1684 | lastHei = height(); |
1685 | 1685 | ||
1686 | 1686 | ||
1687 | if ( wid < hei ) | 1687 | if ( wid < hei ) |
1688 | daysToShow = 2; | 1688 | daysToShow = 2; |
1689 | else | 1689 | else |
1690 | daysToShow = 3; | 1690 | daysToShow = 3; |
1691 | mShowSatSunComp = true; | 1691 | mShowSatSunComp = true; |
1692 | combinedSatSun = true; | 1692 | combinedSatSun = true; |
1693 | 1693 | ||
1694 | //qDebug("KOMonthView::computeLayout() WWW ------------------------------------ "); | 1694 | //qDebug("KOMonthView::computeLayout() WWW ------------------------------------ "); |
1695 | QFontMetrics fm ( mWeekLabels[0]->font() ); | 1695 | QFontMetrics fm ( mWeekLabels[0]->font() ); |
1696 | int weeklabelwid = fm.width( "888" ); | 1696 | int weeklabelwid = fm.width( "888" ); |
1697 | wid -= weeklabelwid; | 1697 | wid -= weeklabelwid; |
1698 | 1698 | ||
1699 | int colWid = wid / daysToShow; | 1699 | int colWid = wid / daysToShow; |
1700 | int lastCol = wid - ( colWid*6 ); | 1700 | int lastCol = wid - ( colWid*6 ); |
1701 | int dayLabelHei = mDayLabelsW[0]->sizeHint().height(); | 1701 | int dayLabelHei = mDayLabelsW[0]->sizeHint().height(); |
1702 | int cellHei = (hei - (5- daysToShow )*dayLabelHei) /(5- daysToShow ); | 1702 | int cellHei = (hei - (5- daysToShow )*dayLabelHei) /(5- daysToShow ); |
1703 | int colModulo = wid % daysToShow; | 1703 | int colModulo = wid % daysToShow; |
1704 | int rowModulo = (hei- (5- daysToShow )*dayLabelHei) % daysToShow-1; | 1704 | int rowModulo = (hei- (5- daysToShow )*dayLabelHei) % daysToShow-1; |
1705 | //qDebug("rowmod %d ", rowModulo); | 1705 | //qDebug("rowmod %d ", rowModulo); |
1706 | int i; | 1706 | int i; |
1707 | int x,y,w,h; | 1707 | int x,y,w,h; |
1708 | x= 0; | 1708 | x= 0; |
1709 | y= 0; | 1709 | y= 0; |
1710 | w = colWid; | 1710 | w = colWid; |
1711 | h = dayLabelHei ; | 1711 | h = dayLabelHei ; |
1712 | for ( i = 0; i < 7; i++) { | 1712 | for ( i = 0; i < 7; i++) { |
1713 | if ( i && !( i % daysToShow) && i < 6) { | 1713 | if ( i && !( i % daysToShow) && i < 6) { |
1714 | y += hei/(5-daysToShow); | 1714 | y += hei/(5-daysToShow); |
1715 | x = 0; | 1715 | x = 0; |
1716 | w = colWid; | 1716 | w = colWid; |
1717 | } | 1717 | } |
1718 | if ( ((i) % daysToShow) >= daysToShow-colModulo ) { | 1718 | if ( ((i) % daysToShow) >= daysToShow-colModulo ) { |
1719 | ++w; | 1719 | ++w; |
1720 | } | 1720 | } |
1721 | if ( i >= 5 ) { | 1721 | if ( i >= 5 ) { |
1722 | int wi = width() - x - weeklabelwid; | 1722 | int wi = width() - x - weeklabelwid; |
1723 | if ( i == 5 ) { | 1723 | if ( i == 5 ) { |
1724 | mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,wi/2+wi%2,h); | 1724 | mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,wi/2+wi%2,h); |
1725 | } else { | 1725 | } else { |
1726 | mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,wi,h); | 1726 | mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,wi,h); |
1727 | } | 1727 | } |
1728 | x = x - w + wi - (wi/2 ); | 1728 | x = x - w + wi - (wi/2 ); |
1729 | } | 1729 | } |
1730 | else { | 1730 | else { |
1731 | int wi = w; | 1731 | int wi = w; |
1732 | if ( !(( i+1) % daysToShow)) { | 1732 | if ( !(( i+1) % daysToShow)) { |
1733 | wi = width() - x - weeklabelwid; | 1733 | wi = width() - x - weeklabelwid; |
1734 | } | 1734 | } |
1735 | mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,wi,h); | 1735 | mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,wi,h); |
1736 | } | 1736 | } |
1737 | x += w; | 1737 | x += w; |
1738 | } | 1738 | } |
1739 | x= 0; | 1739 | x= 0; |
1740 | y= dayLabelHei; | 1740 | y= dayLabelHei; |
1741 | w = colWid; | 1741 | w = colWid; |
1742 | h = cellHei; | 1742 | h = cellHei; |
1743 | int max = 0; | 1743 | int max = 0; |
1744 | for ( i = 0; i < mCellsW.count(); ++i) { | 1744 | for ( i = 0; i < mCellsW.count(); ++i) { |
1745 | if ( i > 6 ) { | 1745 | if ( i > 6 ) { |
1746 | mCellsW[i]->hide(); | 1746 | mCellsW[i]->hide(); |
1747 | continue; | 1747 | continue; |
1748 | } | 1748 | } |
1749 | 1749 | ||
1750 | w = colWid; | 1750 | w = colWid; |
1751 | if ( ((i) % daysToShow) >= daysToShow-colModulo ) { | 1751 | if ( ((i) % daysToShow) >= daysToShow-colModulo ) { |
1752 | ++w; | 1752 | ++w; |
1753 | } | 1753 | } |
1754 | if ( i == (daysToShow-1-rowModulo)*7) | 1754 | if ( i == (daysToShow-1-rowModulo)*7) |
1755 | ++h; | 1755 | ++h; |
1756 | 1756 | ||
1757 | if ( i >= 5 ) { | 1757 | if ( i >= 5 ) { |
1758 | if ( i ==5 ) { | 1758 | if ( i ==5 ) { |
1759 | max = h/2; | 1759 | max = h/2; |
1760 | mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,max ); | 1760 | mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,max ); |
1761 | x -= w ;y += h/2; | 1761 | x -= w ;y += h/2; |
1762 | } else { | 1762 | } else { |
1763 | if ( ((i-1) % daysToShow) >= daysToShow-colModulo ) { | 1763 | if ( ((i-1) % daysToShow) >= daysToShow-colModulo ) { |
1764 | ++w; | 1764 | ++w; |
1765 | } | 1765 | } |
1766 | max = h-h/2; | 1766 | max = h-h/2; |
1767 | mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,max ); | 1767 | mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,max ); |
1768 | y -= h/2; | 1768 | y -= h/2; |
1769 | } | 1769 | } |
1770 | } else { | 1770 | } else { |
1771 | max = h; | 1771 | max = h; |
1772 | mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h ); | 1772 | mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h ); |
1773 | } | 1773 | } |
1774 | 1774 | ||
1775 | 1775 | ||
1776 | x += w; | 1776 | x += w; |
1777 | if ( x + w/2 > wid ) { | 1777 | if ( x + w/2 > wid ) { |
1778 | x = 0; | 1778 | x = 0; |
1779 | y += h+dayLabelHei ; | 1779 | y += h+dayLabelHei ; |
1780 | } | 1780 | } |
1781 | //mCellsW[i]->dateLabel()->setMaximumHeight( max - mCellsW[i]->lineWidth()*2 ); | 1781 | //mCellsW[i]->dateLabel()->setMaximumHeight( max - mCellsW[i]->lineWidth()*2 ); |
1782 | } | 1782 | } |
1783 | y= dayLabelHei; | 1783 | y= dayLabelHei; |
1784 | h = cellHei ; | 1784 | h = cellHei ; |
1785 | mWeekLabelsW[0]->setGeometry( 0,y,weeklabelwid,hei-dayLabelHei); | 1785 | mWeekLabelsW[0]->setGeometry( 0,y,weeklabelwid,hei-dayLabelHei); |
1786 | mWeekLabelsW[1]->setGeometry( 0,0,weeklabelwid,dayLabelHei); | 1786 | mWeekLabelsW[1]->setGeometry( 0,0,weeklabelwid,dayLabelHei); |
1787 | // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); | 1787 | // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); |
1788 | //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); | 1788 | //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); |
1789 | mShortDayLabelsW = mDayLabelsW[0]->width()-2 < mWidthLongDayLabel ; | 1789 | mShortDayLabelsW = mDayLabelsW[0]->width()-2 < mWidthLongDayLabel ; |
1790 | updateDayLabels(); | 1790 | updateDayLabels(); |
1791 | //bool forceUpdate = !updatePossible; | 1791 | //bool forceUpdate = !updatePossible; |
1792 | updatePossible = true; | 1792 | updatePossible = true; |
1793 | //mWeekLabels[mNumWeeks]->setText( i18n("M")); | 1793 | //mWeekLabels[mNumWeeks]->setText( i18n("M")); |
1794 | //if ( forceUpdate ) | 1794 | //if ( forceUpdate ) |
1795 | // updateView(); | 1795 | // updateView(); |
1796 | } | 1796 | } |
1797 | void KOMonthView::computeLayout() | 1797 | void KOMonthView::computeLayout() |
1798 | { | 1798 | { |
1799 | 1799 | ||
1800 | 1800 | ||
1801 | static int lastWid = 0; | 1801 | static int lastWid = 0; |
1802 | static int lastHei = 0; | 1802 | static int lastHei = 0; |
1803 | 1803 | ||
1804 | if ( mShowWeekView ){ | 1804 | if ( mShowWeekView ){ |
1805 | computeLayoutWeek(); | 1805 | computeLayoutWeek(); |
1806 | return; | 1806 | return; |
1807 | } | 1807 | } |
1808 | int daysToShow = 7; | 1808 | int daysToShow = 7; |
1809 | bool combinedSatSun = false; | 1809 | bool combinedSatSun = false; |
1810 | if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { | 1810 | if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { |
1811 | daysToShow = 6; | 1811 | daysToShow = 6; |
1812 | combinedSatSun = true; | 1812 | combinedSatSun = true; |
1813 | } | 1813 | } |
1814 | int tWid = topLevelWidget()->size().width(); | 1814 | int tWid = topLevelWidget()->size().width(); |
1815 | int tHei = topLevelWidget()->size().height(); | 1815 | int tHei = topLevelWidget()->size().height(); |
1816 | 1816 | ||
1817 | int wid = width();//e | 1817 | int wid = width();//e |
1818 | int hei = height()-1-mNavigatorBar->height(); | 1818 | int hei = height()-1-mNavigatorBar->height(); |
1819 | 1819 | ||
1820 | if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) { | 1820 | if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) { |
1821 | return; | 1821 | return; |
1822 | } | 1822 | } |
1823 | if ( lastWid == width() && lastHei == height() ){ | 1823 | if ( lastWid == width() && lastHei == height() ){ |
1824 | //qDebug("KOMonthview::No compute layout needed "); | 1824 | //qDebug("KOMonthview::No compute layout needed "); |
1825 | return; | 1825 | return; |
1826 | } | 1826 | } |
1827 | 1827 | ||
1828 | lastWid = width(); | 1828 | lastWid = width(); |
1829 | lastHei = height(); | 1829 | lastHei = height(); |
1830 | //qDebug("KOMonthView::computeLayout() MMM ------------------- "); | 1830 | //qDebug("KOMonthView::computeLayout() MMM ------------------- "); |
1831 | QFontMetrics fm ( mWeekLabels[0]->font() ); | 1831 | QFontMetrics fm ( mWeekLabels[0]->font() ); |
1832 | int weeklabelwid = fm.width( "888" ); | 1832 | int weeklabelwid = fm.width( "888" ); |
1833 | wid -= weeklabelwid; | 1833 | wid -= weeklabelwid; |
1834 | 1834 | ||
1835 | int colWid = wid / daysToShow; | 1835 | int colWid = wid / daysToShow; |
1836 | int lastCol = wid - ( colWid*6 ); | 1836 | int lastCol = wid - ( colWid*6 ); |
1837 | int dayLabelHei = mDayLabels[0]->sizeHint().height(); | 1837 | int dayLabelHei = mDayLabels[0]->sizeHint().height(); |
1838 | int cellHei = (hei - dayLabelHei) /6; | 1838 | int cellHei = (hei - dayLabelHei) /6; |
1839 | int colModulo = wid % daysToShow; | 1839 | int colModulo = wid % daysToShow; |
1840 | int rowModulo = (hei- dayLabelHei) % 6; | 1840 | int rowModulo = (hei- dayLabelHei) % 6; |
1841 | //qDebug("rowmod %d ", rowModulo); | 1841 | //qDebug("rowmod %d ", rowModulo); |
1842 | int i; | 1842 | int i; |
1843 | int x,y,w,h; | 1843 | int x,y,w,h; |
1844 | x= 0; | 1844 | x= 0; |
1845 | y= 0; | 1845 | y= 0; |
1846 | w = colWid; | 1846 | w = colWid; |
1847 | h = dayLabelHei ; | 1847 | h = dayLabelHei ; |
1848 | for ( i = 0; i < 7; i++) { | 1848 | for ( i = 0; i < 7; i++) { |
1849 | if ( i == daysToShow-colModulo ) | 1849 | if ( i == daysToShow-colModulo ) |
1850 | ++w; | 1850 | ++w; |
1851 | if ( combinedSatSun ) { | 1851 | if ( combinedSatSun ) { |
1852 | if ( i >= daysToShow-1 ) { | 1852 | if ( i >= daysToShow-1 ) { |
1853 | 1853 | ||
1854 | if ( i == 6 ) | 1854 | if ( i == 6 ) |
1855 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,width()-x-weeklabelwid,h); | 1855 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,width()-x-weeklabelwid,h); |
1856 | else | 1856 | else |
1857 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,w/2,h); | 1857 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,w/2,h); |
1858 | x -= w/2 ; | 1858 | x -= w/2 ; |
1859 | } | 1859 | } |
1860 | else | 1860 | else |
1861 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); | 1861 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); |
1862 | } else | 1862 | } else |
1863 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); | 1863 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); |
1864 | x += w; | 1864 | x += w; |
1865 | } | 1865 | } |
1866 | x= 0; | 1866 | x= 0; |
1867 | y= dayLabelHei; | 1867 | y= dayLabelHei; |
1868 | w = colWid; | 1868 | w = colWid; |
1869 | h = cellHei ; | 1869 | h = cellHei ; |
1870 | int max = 0; | 1870 | int max = 0; |
1871 | for ( i = 0; i < mCells.count(); ++i) { | 1871 | for ( i = 0; i < mCells.count(); ++i) { |
1872 | //qDebug("iii %d ", i); | 1872 | //qDebug("iii %d ", i); |
1873 | w = colWid; | 1873 | w = colWid; |
1874 | if ( ((i) % 7) >= 7-colModulo ) { | 1874 | if ( ((i) % 7) >= 7-colModulo ) { |
1875 | ++w; | 1875 | ++w; |
1876 | } | 1876 | } |
1877 | if ( i == (6-rowModulo)*7) | 1877 | if ( i == (6-rowModulo)*7) |
1878 | ++h; | 1878 | ++h; |
1879 | if ( combinedSatSun ) { | 1879 | if ( combinedSatSun ) { |
1880 | if ( (i)%7 >= daysToShow-1 ) { | 1880 | if ( (i)%7 >= daysToShow-1 ) { |
1881 | if ( (i)%7 == daysToShow-1 ) { | 1881 | if ( (i)%7 == daysToShow-1 ) { |
1882 | w = width()-x-weeklabelwid; | 1882 | w = width()-x-weeklabelwid; |
1883 | max = h/2; | 1883 | max = h/2; |
1884 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,max ); | 1884 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,max ); |
1885 | x -= w ;y += h/2; | 1885 | x -= w ;y += h/2; |
1886 | } else { | 1886 | } else { |
1887 | w = width()-x-weeklabelwid; | 1887 | w = width()-x-weeklabelwid; |
1888 | max = h-h/2; | 1888 | max = h-h/2; |
1889 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,max ); | 1889 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,max ); |
1890 | y -= h/2; | 1890 | y -= h/2; |
1891 | } | 1891 | } |
1892 | } else { | 1892 | } else { |
1893 | max = h; | 1893 | max = h; |
1894 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); | 1894 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); |
1895 | } | 1895 | } |
1896 | 1896 | ||
1897 | } | 1897 | } |
1898 | else { | 1898 | else { |
1899 | max = h; | 1899 | max = h; |
1900 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); | 1900 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); |
1901 | } | 1901 | } |
1902 | x += w; | 1902 | x += w; |
1903 | if ( x + w/2 > wid ) { | 1903 | if ( x + w/2 > wid ) { |
1904 | x = 0; | 1904 | x = 0; |
1905 | y += h; | 1905 | y += h; |
1906 | } | 1906 | } |
1907 | //mCells[i]->dateLabel()->setMaximumHeight( max- mCells[i]->lineWidth()*2 ); | 1907 | //mCells[i]->dateLabel()->setMaximumHeight( max- mCells[i]->lineWidth()*2 ); |
1908 | } | 1908 | } |
1909 | y= dayLabelHei; | 1909 | y= dayLabelHei; |
1910 | h = cellHei ; | 1910 | h = cellHei ; |
1911 | for ( i = 0; i < 6; i++) { | 1911 | for ( i = 0; i < 6; i++) { |
1912 | if ( i == (6-rowModulo)) | 1912 | if ( i == (6-rowModulo)) |
1913 | ++h; | 1913 | ++h; |
1914 | mWeekLabels[i]->setGeometry( 0,y,weeklabelwid,h); | 1914 | mWeekLabels[i]->setGeometry( 0,y,weeklabelwid,h); |
1915 | y += h; | 1915 | y += h; |
1916 | } | 1916 | } |
1917 | mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei); | 1917 | mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei); |
1918 | // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); | 1918 | // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); |
1919 | //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); | 1919 | //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); |
1920 | mShortDayLabelsM = mDayLabels[0]->width()-2 < mWidthLongDayLabel ; | 1920 | mShortDayLabelsM = mDayLabels[0]->width()-2 < mWidthLongDayLabel ; |
1921 | updateDayLabels(); | 1921 | updateDayLabels(); |
1922 | //bool forceUpdate = !updatePossible; | 1922 | //bool forceUpdate = !updatePossible; |
1923 | updatePossible = true; | 1923 | updatePossible = true; |
1924 | //mWeekLabels[mNumWeeks]->setText( i18n("W")); | 1924 | //mWeekLabels[mNumWeeks]->setText( i18n("W")); |
1925 | } | 1925 | } |
1926 | 1926 | ||
1927 | void KOMonthView::showContextMenu( Incidence *incidence ) | 1927 | void KOMonthView::showContextMenu( Incidence *incidence ) |
1928 | { | 1928 | { |
1929 | if( incidence ) | 1929 | if( incidence ) |
1930 | mContextMenu->showIncidencePopup(incidence); | 1930 | mContextMenu->showIncidencePopup(incidence); |
1931 | else { | 1931 | else { |
1932 | //qDebug("KOMonthView::showContextMenu "); | 1932 | //qDebug("KOMonthView::showContextMenu "); |
1933 | mNewItemMenu->popup(QCursor::pos()); | 1933 | mNewItemMenu->popup(QCursor::pos()); |
1934 | } | 1934 | } |
1935 | /* | 1935 | /* |
1936 | if( incidence && incidence->type() == "Event" ) { | 1936 | if( incidence && incidence->type() == "Event" ) { |
1937 | Event *event = static_cast<Event *>(incidence); | 1937 | Event *event = static_cast<Event *>(incidence); |
1938 | mContextMenu->showEventPopup(event); | 1938 | mContextMenu->showEventPopup(event); |
1939 | } else { | 1939 | } else { |
1940 | kdDebug() << "MonthView::showContextMenu(): cast failed." << endl; | 1940 | kdDebug() << "MonthView::showContextMenu(): cast failed." << endl; |
1941 | } | 1941 | } |
1942 | */ | 1942 | */ |
1943 | } | 1943 | } |
1944 | MonthViewCell * KOMonthView::selectedCell( ) | 1944 | MonthViewCell * KOMonthView::selectedCell( ) |
1945 | { | 1945 | { |
1946 | return mSelectedCell; | 1946 | return mSelectedCell; |
1947 | } | 1947 | } |
1948 | void KOMonthView::setSelectedCell( MonthViewCell *cell ) | 1948 | void KOMonthView::setSelectedCell( MonthViewCell *cell ) |
1949 | { | 1949 | { |
1950 | //qDebug("KOMonthView::setSelectedCell %d", cell); | 1950 | //qDebug("KOMonthView::setSelectedCell %d", cell); |
1951 | if ( mSelectedCell && mSelectedCell != cell ) { | 1951 | if ( mSelectedCell && mSelectedCell != cell ) { |
1952 | MonthViewCell * mvc = mSelectedCell; | 1952 | MonthViewCell * mvc = mSelectedCell; |
1953 | mSelectedCell = cell; | 1953 | mSelectedCell = cell; |
1954 | mvc->deselect(); | 1954 | mvc->deselect(); |
1955 | } else | 1955 | } else |
1956 | mSelectedCell = cell; | 1956 | mSelectedCell = cell; |
1957 | // if ( mSelectedCell ) | 1957 | // if ( mSelectedCell ) |
1958 | // mSelectedCell->select(); | 1958 | // mSelectedCell->select(); |
1959 | if ( !mSelectedCell ) | 1959 | if ( !mSelectedCell ) |
1960 | emit incidenceSelected( 0 ); | 1960 | emit incidenceSelected( 0 ); |
1961 | else | 1961 | else |
1962 | emit incidenceSelected( mSelectedCell->selectedIncidence() ); | 1962 | emit incidenceSelected( mSelectedCell->selectedIncidence() ); |
1963 | } | 1963 | } |
1964 | 1964 | ||
1965 | void KOMonthView::processSelectionChange() | 1965 | void KOMonthView::processSelectionChange() |
1966 | { | 1966 | { |
1967 | QPtrList<Incidence> incidences = selectedIncidences(); | 1967 | QPtrList<Incidence> incidences = selectedIncidences(); |
1968 | if (incidences.count() > 0) { | 1968 | if (incidences.count() > 0) { |
1969 | emit incidenceSelected( incidences.first() ); | 1969 | emit incidenceSelected( incidences.first() ); |
1970 | } else { | 1970 | } else { |
1971 | emit incidenceSelected( 0 ); | 1971 | emit incidenceSelected( 0 ); |
1972 | clearSelection(); | 1972 | clearSelection(); |
1973 | } | 1973 | } |
1974 | } | 1974 | } |
1975 | 1975 | ||
1976 | void KOMonthView::clearSelection() | 1976 | void KOMonthView::clearSelection() |
1977 | { | 1977 | { |
1978 | if ( mSelectedCell ) { | 1978 | if ( mSelectedCell ) { |
1979 | mSelectedCell->deselect(); | 1979 | mSelectedCell->deselect(); |
1980 | mSelectedCell = 0; | 1980 | mSelectedCell = 0; |
1981 | } | 1981 | } |
1982 | } | 1982 | } |
1983 | 1983 | ||
1984 | void KOMonthView::keyReleaseEvent ( QKeyEvent * e) | 1984 | void KOMonthView::keyReleaseEvent ( QKeyEvent * e) |
1985 | { | 1985 | { |
1986 | if ( !e->isAutoRepeat() ) { | 1986 | if ( !e->isAutoRepeat() ) { |
1987 | mFlagKeyPressed = false; | 1987 | mFlagKeyPressed = false; |
1988 | } | 1988 | } |
1989 | } | 1989 | } |
1990 | 1990 | ||
1991 | void KOMonthView::keyPressEvent ( QKeyEvent * e ) | 1991 | void KOMonthView::keyPressEvent ( QKeyEvent * e ) |
1992 | { | 1992 | { |
1993 | 1993 | ||
1994 | qApp->processEvents(); | 1994 | qApp->processEvents(); |
1995 | if ( e->isAutoRepeat() && !mFlagKeyPressed ) { | 1995 | if ( e->isAutoRepeat() && !mFlagKeyPressed ) { |
1996 | //e->ignore(); | 1996 | //e->ignore(); |
1997 | e->accept(); | 1997 | e->accept(); |
1998 | return; | 1998 | return; |
1999 | } | 1999 | } |
2000 | if (! e->isAutoRepeat() ) | 2000 | if (! e->isAutoRepeat() ) |
2001 | mFlagKeyPressed = true; | 2001 | mFlagKeyPressed = true; |
2002 | switch(e->key()) { | 2002 | switch(e->key()) { |
2003 | case Key_Up: | 2003 | case Key_Up: |
2004 | { | 2004 | { |
2005 | if ( mShowWeekView ) { | 2005 | if ( mShowWeekView ) { |
2006 | emit selectWeekNum ( currentWeek() - 1 ); | 2006 | emit selectWeekNum ( currentWeek() - 1 ); |
2007 | } | 2007 | } |
2008 | else { | 2008 | else { |
2009 | emit prevMonth(); | 2009 | emit prevMonth(); |
2010 | } | 2010 | } |
2011 | } | 2011 | } |
2012 | e->accept(); | 2012 | e->accept(); |
2013 | break; | 2013 | break; |
2014 | case Key_Down: | 2014 | case Key_Down: |
2015 | { | 2015 | { |
2016 | if ( mShowWeekView ) { | 2016 | if ( mShowWeekView ) { |
2017 | emit selectWeekNum ( currentWeek() +1); | 2017 | emit selectWeekNum ( currentWeek() +1); |
2018 | } | 2018 | } |
2019 | else { | 2019 | else { |
2020 | emit nextMonth(); | 2020 | emit nextMonth(); |
2021 | } | 2021 | } |
2022 | 2022 | ||
2023 | } | 2023 | } |
2024 | e->accept(); | 2024 | e->accept(); |
2025 | break; | 2025 | break; |
2026 | case Key_Return: | 2026 | case Key_Return: |
2027 | case Key_Enter: | 2027 | case Key_Enter: |
2028 | { | 2028 | { |
2029 | selectInternalWeekNum ( currentWeek() ); | 2029 | selectInternalWeekNum ( currentWeek() ); |
2030 | } | 2030 | } |
2031 | e->accept(); | 2031 | e->accept(); |
2032 | break; | 2032 | break; |
2033 | case Key_D: | 2033 | case Key_D: |
2034 | if ( mSelectedCell ) { | 2034 | if ( mSelectedCell ) { |
2035 | mSelectedCell->showDay(); | 2035 | mSelectedCell->showDay(); |
2036 | e->accept(); | 2036 | e->accept(); |
2037 | } else { | 2037 | } else { |
2038 | e->ignore(); | 2038 | e->ignore(); |
2039 | } | 2039 | } |
2040 | break; | 2040 | break; |
2041 | default: | 2041 | default: |
2042 | e->ignore(); | 2042 | e->ignore(); |
2043 | break; | 2043 | break; |
2044 | } | 2044 | } |
2045 | } | 2045 | } |
2046 | 2046 | ||
2047 | void KOMonthView::nextCell() | 2047 | void KOMonthView::nextCell() |
2048 | { | 2048 | { |
2049 | bool res = focusNextPrevChild ( true ); | 2049 | bool res = focusNextPrevChild ( true ); |
2050 | } | 2050 | } |
2051 | void KOMonthView::prevCell() | 2051 | void KOMonthView::prevCell() |
2052 | { | 2052 | { |
2053 | focusNextPrevChild ( false ); | 2053 | focusNextPrevChild ( false ); |
2054 | } | 2054 | } |
2055 | 2055 | ||
2056 | void KOMonthView::slotNewTodo() | 2056 | void KOMonthView::slotNewTodo() |
2057 | { | 2057 | { |
2058 | //qDebug("KOMonthView::slotNewTodo() "); | 2058 | //qDebug("KOMonthView::slotNewTodo() "); |
2059 | if ( mPopupCell ){ | 2059 | if ( mPopupCell ){ |
2060 | QDateTime dt( mPopupCell->date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); | 2060 | QDateTime dt( mPopupCell->date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); |
2061 | emit newTodoSignal(dt,true); | 2061 | emit newTodoSignal(dt,true); |
2062 | } | 2062 | } |
2063 | mPopupCell = 0; | 2063 | mPopupCell = 0; |
2064 | } | 2064 | } |
2065 | void KOMonthView::slotNewEvent() | 2065 | void KOMonthView::slotNewEvent() |
2066 | { | 2066 | { |
2067 | if ( mPopupCell ) { | 2067 | if ( mPopupCell ) { |
2068 | QDateTime dt( mPopupCell->date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); | 2068 | QDateTime dt( mPopupCell->date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); |
2069 | emit newEventSignal( dt ); | 2069 | emit newEventSignal( dt ); |
2070 | } | 2070 | } |
2071 | //qDebug("KOMonthView::slotNewEvent() "); | 2071 | //qDebug("KOMonthView::slotNewEvent() "); |
2072 | mPopupCell = 0; | 2072 | mPopupCell = 0; |
2073 | } | 2073 | } |
2074 | 2074 | ||
2075 | void KOMonthView::slotEditJournal() | 2075 | void KOMonthView::slotEditJournal() |
2076 | { | 2076 | { |
2077 | if ( mPopupCell ) | 2077 | if ( mPopupCell ) |
2078 | emit showJournalSignal( 7, mPopupCell->date() ); | 2078 | emit showJournalSignal( 7, mPopupCell->date() ); |
2079 | //qDebug("KOMonthView::slotEditJournal() "); | 2079 | //qDebug("KOMonthView::slotEditJournal() "); |
2080 | mPopupCell = 0; | 2080 | mPopupCell = 0; |
2081 | } | 2081 | } |
2082 | 2082 | ||
2083 | void KOMonthView::setPopupCell( MonthViewCell * c) | 2083 | void KOMonthView::setPopupCell( MonthViewCell * c) |
2084 | { | 2084 | { |
2085 | mPopupCell = c; | 2085 | mPopupCell = c; |
2086 | } | 2086 | } |
diff --git a/microkde/KDGanttMinimizeSplitter.cpp b/microkde/KDGanttMinimizeSplitter.cpp index fb5d4e3..72c4e60 100644 --- a/microkde/KDGanttMinimizeSplitter.cpp +++ b/microkde/KDGanttMinimizeSplitter.cpp | |||
@@ -1,1701 +1,1716 @@ | |||
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 | #include <qframe.h> | ||
55 | #ifndef KDGANTT_MASTER_CVS | 56 | #ifndef KDGANTT_MASTER_CVS |
56 | //#include "KDGanttMinimizeSplitter.moc" | 57 | //#include "KDGanttMinimizeSplitter.moc" |
57 | #endif | 58 | #endif |
58 | 59 | ||
59 | 60 | ||
60 | 61 | ||
61 | #ifndef DOXYGEN_SKIP_INTERNAL | 62 | #ifndef DOXYGEN_SKIP_INTERNAL |
62 | 63 | ||
63 | #if QT_VERSION >= 232 | 64 | #if QT_VERSION >= 232 |
64 | static int mouseOffset; | 65 | static int mouseOffset; |
65 | static int opaqueOldPos = -1; //### there's only one mouse, but this is a bit risky | 66 | static int opaqueOldPos = -1; //### there's only one mouse, but this is a bit risky |
66 | 67 | ||
68 | class KDRubberBand: public QFrame | ||
69 | { | ||
70 | public: | ||
71 | KDRubberBand( QWidget *parent, const char * name, WFlags f ) :QFrame ( parent, name, f ) {;} | ||
72 | |||
73 | protected: | ||
74 | virtual void mousePressEvent ( QMouseEvent * ) | ||
75 | { | ||
76 | close(); | ||
77 | }; | ||
78 | |||
79 | }; | ||
67 | 80 | ||
68 | KDGanttSplitterHandle::KDGanttSplitterHandle( Qt::Orientation o, | 81 | KDGanttSplitterHandle::KDGanttSplitterHandle( Qt::Orientation o, |
69 | KDGanttMinimizeSplitter *parent, const char * name ) | 82 | KDGanttMinimizeSplitter *parent, const char * name ) |
70 | : QWidget( parent, name ), _activeButton( 0 ), _collapsed( false ) | 83 | : QWidget( parent, name ), _activeButton( 0 ), _collapsed( false ) |
71 | { | 84 | { |
72 | 85 | ||
73 | if ( QApplication::desktop()->width() > 320 && QApplication::desktop()->width() < 650 ) { | 86 | if ( QApplication::desktop()->width() > 320 && QApplication::desktop()->width() < 650 ) { |
74 | mSizeHint = QSize(7,7); | 87 | mSizeHint = QSize(7,7); |
75 | mUseOffset = true; | 88 | mUseOffset = true; |
76 | } else { | 89 | } else { |
77 | mSizeHint = QSize(6,6); | 90 | mSizeHint = QSize(6,6); |
78 | mUseOffset = false; | 91 | mUseOffset = false; |
79 | } | 92 | } |
80 | s = parent; | 93 | s = parent; |
81 | setOrientation(o); | 94 | setOrientation(o); |
82 | setMouseTracking( true ); | 95 | setMouseTracking( true ); |
83 | mMouseDown = false; | 96 | mMouseDown = false; |
84 | //setMaximumHeight( 5 ); // test only | 97 | //setMaximumHeight( 5 ); // test only |
85 | } | 98 | } |
86 | 99 | ||
87 | QSize KDGanttSplitterHandle::sizeHint() const | 100 | QSize KDGanttSplitterHandle::sizeHint() const |
88 | { | 101 | { |
89 | return mSizeHint; | 102 | return mSizeHint; |
90 | } | 103 | } |
91 | 104 | ||
92 | void KDGanttSplitterHandle::setOrientation( Qt::Orientation o ) | 105 | void KDGanttSplitterHandle::setOrientation( Qt::Orientation o ) |
93 | { | 106 | { |
94 | orient = o; | 107 | orient = o; |
95 | #ifndef QT_NO_CURSOR | 108 | #ifndef QT_NO_CURSOR |
96 | if ( o == KDGanttMinimizeSplitter::Horizontal ) | 109 | if ( o == KDGanttMinimizeSplitter::Horizontal ) |
97 | setCursor( splitHCursor ); | 110 | setCursor( splitHCursor ); |
98 | else | 111 | else |
99 | setCursor( splitVCursor ); | 112 | setCursor( splitVCursor ); |
100 | #endif | 113 | #endif |
101 | } | 114 | } |
102 | 115 | ||
103 | 116 | ||
104 | void KDGanttSplitterHandle::mouseMoveEvent( QMouseEvent *e ) | 117 | void KDGanttSplitterHandle::mouseMoveEvent( QMouseEvent *e ) |
105 | { | 118 | { |
106 | updateCursor( e->pos() ); | 119 | updateCursor( e->pos() ); |
107 | if ( !(e->state()&LeftButton) ) | 120 | if ( !(e->state()&LeftButton) ) |
108 | return; | 121 | return; |
109 | 122 | ||
110 | if ( _activeButton != 0) | 123 | if ( _activeButton != 0) |
111 | return; | 124 | return; |
112 | 125 | ||
113 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) | 126 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) |
114 | - mouseOffset; | 127 | - mouseOffset; |
115 | if ( opaque() ) { | 128 | if ( opaque() ) { |
116 | s->moveSplitter( pos, id() ); | 129 | s->moveSplitter( pos, id() ); |
117 | } else { | 130 | } else { |
118 | int min = pos; int max = pos; | 131 | int min = pos; int max = pos; |
119 | s->getRange( id(), &min, &max ); | 132 | s->getRange( id(), &min, &max ); |
120 | s->setRubberband( QMAX( min, QMIN(max, pos ))); | 133 | s->setRubberband( QMAX( min, QMIN(max, pos ))); |
121 | } | 134 | } |
122 | _collapsed = false; | 135 | _collapsed = false; |
123 | } | 136 | } |
124 | 137 | ||
125 | void KDGanttSplitterHandle::mousePressEvent( QMouseEvent *e ) | 138 | void KDGanttSplitterHandle::mousePressEvent( QMouseEvent *e ) |
126 | { | 139 | { |
127 | if ( e->button() == LeftButton ) { | 140 | if ( e->button() == LeftButton ) { |
128 | _activeButton = onButton( e->pos() ); | 141 | _activeButton = onButton( e->pos() ); |
129 | mouseOffset = s->pick(e->pos()); | 142 | mouseOffset = s->pick(e->pos()); |
130 | mMouseDown = true; | 143 | mMouseDown = true; |
131 | repaint(); | 144 | repaint(); |
132 | updateCursor( e->pos() ); | 145 | updateCursor( e->pos() ); |
133 | } | 146 | } |
134 | } | 147 | } |
135 | 148 | ||
136 | void KDGanttSplitterHandle::updateCursor( const QPoint& p) | 149 | void KDGanttSplitterHandle::updateCursor( const QPoint& p) |
137 | { | 150 | { |
138 | if ( onButton( p ) != 0 ) { | 151 | if ( onButton( p ) != 0 ) { |
139 | setCursor( arrowCursor ); | 152 | setCursor( arrowCursor ); |
140 | } | 153 | } |
141 | else { | 154 | else { |
142 | if ( orient == KDGanttMinimizeSplitter::Horizontal ) | 155 | if ( orient == KDGanttMinimizeSplitter::Horizontal ) |
143 | setCursor( splitHCursor ); | 156 | setCursor( splitHCursor ); |
144 | else | 157 | else |
145 | setCursor( splitVCursor ); | 158 | setCursor( splitVCursor ); |
146 | } | 159 | } |
147 | } | 160 | } |
148 | void KDGanttSplitterHandle::toggle() | 161 | void KDGanttSplitterHandle::toggle() |
149 | { | 162 | { |
150 | int pos; | 163 | int pos; |
151 | int min, max; | 164 | int min, max; |
152 | if ( !_collapsed ) { | 165 | if ( !_collapsed ) { |
153 | s->expandPos( id(), &min, &max ); | 166 | s->expandPos( id(), &min, &max ); |
154 | if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left | 167 | if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left |
155 | || s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) { | 168 | || s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) { |
156 | pos = min; | 169 | pos = min; |
157 | } | 170 | } |
158 | else { | 171 | else { |
159 | pos = max; | 172 | pos = max; |
160 | } | 173 | } |
161 | 174 | ||
162 | _origPos = s->pick(mapToParent( QPoint( 0,0 ) )); | 175 | _origPos = s->pick(mapToParent( QPoint( 0,0 ) )); |
163 | s->moveSplitter( pos, id() ); | 176 | s->moveSplitter( pos, id() ); |
164 | _collapsed = true; | 177 | _collapsed = true; |
165 | } | 178 | } |
166 | else { | 179 | else { |
167 | s->moveSplitter( _origPos, id() ); | 180 | s->moveSplitter( _origPos, id() ); |
168 | _collapsed = false; | 181 | _collapsed = false; |
169 | } | 182 | } |
170 | repaint(); | 183 | repaint(); |
171 | } | 184 | } |
172 | 185 | ||
173 | void KDGanttSplitterHandle::mouseReleaseEvent( QMouseEvent *e ) | 186 | void KDGanttSplitterHandle::mouseReleaseEvent( QMouseEvent *e ) |
174 | { | 187 | { |
175 | mMouseDown = false; | 188 | mMouseDown = false; |
176 | if ( _activeButton != 0 ) { | 189 | if ( _activeButton != 0 ) { |
177 | if ( onButton( e->pos() ) == _activeButton ) | 190 | if ( onButton( e->pos() ) == _activeButton ) |
178 | { | 191 | { |
179 | toggle(); | 192 | toggle(); |
180 | } | 193 | } |
181 | _activeButton = 0; | 194 | _activeButton = 0; |
182 | updateCursor( e->pos() ); | 195 | updateCursor( e->pos() ); |
183 | } | 196 | } |
184 | else { | 197 | else { |
185 | if ( !opaque() && e->button() == LeftButton ) { | 198 | if ( !opaque() && e->button() == LeftButton ) { |
186 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) | 199 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) |
187 | - mouseOffset; | 200 | - mouseOffset; |
188 | s->setRubberband( -1 ); | 201 | s->setRubberband( -1 ); |
189 | s->moveSplitter( pos, id() ); | 202 | s->moveSplitter( pos, id() ); |
190 | } | 203 | } |
191 | } | 204 | } |
192 | if ( s->rubberBand() ) | 205 | if ( s->rubberBand() ) { |
193 | s->rubberBand()->hide(); | 206 | //qDebug("hide rubberband "); |
207 | s->rubberBand()->close(); | ||
208 | } | ||
194 | repaint(); | 209 | repaint(); |
195 | } | 210 | } |
196 | 211 | ||
197 | int KDGanttSplitterHandle::onButton( const QPoint& p ) | 212 | int KDGanttSplitterHandle::onButton( const QPoint& p ) |
198 | { | 213 | { |
199 | QValueList<QPointArray> list = buttonRegions(); | 214 | QValueList<QPointArray> list = buttonRegions(); |
200 | int index = 1; | 215 | int index = 1; |
201 | int add = 12; | 216 | int add = 12; |
202 | for( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { | 217 | for( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { |
203 | QRect rect = (*it).boundingRect(); | 218 | QRect rect = (*it).boundingRect(); |
204 | rect.setLeft( rect.left()- add ); | 219 | rect.setLeft( rect.left()- add ); |
205 | rect.setRight( rect.right() + add); | 220 | rect.setRight( rect.right() + add); |
206 | rect.setTop( rect.top()- add ); | 221 | rect.setTop( rect.top()- add ); |
207 | rect.setBottom( rect.bottom() + add); | 222 | rect.setBottom( rect.bottom() + add); |
208 | if ( rect.contains( p ) ) { | 223 | if ( rect.contains( p ) ) { |
209 | return index; | 224 | return index; |
210 | } | 225 | } |
211 | index++; | 226 | index++; |
212 | } | 227 | } |
213 | return 0; | 228 | return 0; |
214 | } | 229 | } |
215 | 230 | ||
216 | 231 | ||
217 | QValueList<QPointArray> KDGanttSplitterHandle::buttonRegions() | 232 | QValueList<QPointArray> KDGanttSplitterHandle::buttonRegions() |
218 | { | 233 | { |
219 | QValueList<QPointArray> list; | 234 | QValueList<QPointArray> list; |
220 | 235 | ||
221 | int sw = 8; | 236 | int sw = 8; |
222 | int yyy = 1; | 237 | int yyy = 1; |
223 | int xxx = 1; | 238 | int xxx = 1; |
224 | int voffset[] = { (int) -sw*3, (int) sw*3 }; | 239 | int voffset[] = { (int) -sw*3, (int) sw*3 }; |
225 | for ( int i = 0; i < 2; i++ ) { | 240 | for ( int i = 0; i < 2; i++ ) { |
226 | QPointArray arr; | 241 | QPointArray arr; |
227 | if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right || | 242 | if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right || |
228 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left) { | 243 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left) { |
229 | int mid = height()/2 + voffset[i]; | 244 | int mid = height()/2 + voffset[i]; |
230 | arr.setPoints( 3, | 245 | arr.setPoints( 3, |
231 | 1-xxx, mid - sw + 4, | 246 | 1-xxx, mid - sw + 4, |
232 | sw-3-xxx, mid, | 247 | sw-3-xxx, mid, |
233 | 1-xxx, mid + sw -4); | 248 | 1-xxx, mid + sw -4); |
234 | } | 249 | } |
235 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left || | 250 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left || |
236 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) { | 251 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) { |
237 | int mid = height()/2 + voffset[i]; | 252 | int mid = height()/2 + voffset[i]; |
238 | arr.setPoints( 3, | 253 | arr.setPoints( 3, |
239 | sw-4, mid - sw + 4, | 254 | sw-4, mid - sw + 4, |
240 | 0, mid, | 255 | 0, mid, |
241 | sw-4, mid + sw - 4); | 256 | sw-4, mid + sw - 4); |
242 | } | 257 | } |
243 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up || | 258 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up || |
244 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down) { | 259 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down) { |
245 | int mid = width()/2 + voffset[i]; | 260 | int mid = width()/2 + voffset[i]; |
246 | arr.setPoints( 3, | 261 | arr.setPoints( 3, |
247 | mid - sw + 4, sw-4, | 262 | mid - sw + 4, sw-4, |
248 | mid, 0, | 263 | mid, 0, |
249 | mid + sw - 4, sw-4 ); | 264 | mid + sw - 4, sw-4 ); |
250 | } | 265 | } |
251 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down || | 266 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down || |
252 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) { | 267 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) { |
253 | int mid = width()/2 + voffset[i]; | 268 | int mid = width()/2 + voffset[i]; |
254 | arr.setPoints( 3, | 269 | arr.setPoints( 3, |
255 | mid - sw + 4, 1-yyy, | 270 | mid - sw + 4, 1-yyy, |
256 | mid, sw-3-yyy, | 271 | mid, sw-3-yyy, |
257 | mid + sw -4, 1-yyy); | 272 | mid + sw -4, 1-yyy); |
258 | } | 273 | } |
259 | list.append( arr ); | 274 | list.append( arr ); |
260 | } | 275 | } |
261 | return list; | 276 | return list; |
262 | } | 277 | } |
263 | 278 | ||
264 | void KDGanttSplitterHandle::paintEvent( QPaintEvent * ) | 279 | void KDGanttSplitterHandle::paintEvent( QPaintEvent * ) |
265 | { | 280 | { |
266 | QPixmap buffer( size() ); | 281 | QPixmap buffer( size() ); |
267 | QPainter p( &buffer ); | 282 | QPainter p( &buffer ); |
268 | 283 | ||
269 | //LR | 284 | //LR |
270 | // Draw the splitter rectangle | 285 | // Draw the splitter rectangle |
271 | p.setBrush( colorGroup().background() ); | 286 | p.setBrush( colorGroup().background() ); |
272 | p.setPen( colorGroup().foreground() ); | 287 | p.setPen( colorGroup().foreground() ); |
273 | //p.drawRect( rect() ); | 288 | //p.drawRect( rect() ); |
274 | #ifndef DESKTOP_VERSION | 289 | #ifndef DESKTOP_VERSION |
275 | if ( mMouseDown && ! _activeButton) | 290 | if ( mMouseDown && ! _activeButton) |
276 | buffer.fill( colorGroup().background().dark() ); | 291 | buffer.fill( colorGroup().background().dark() ); |
277 | else | 292 | else |
278 | #endif | 293 | #endif |
279 | buffer.fill( colorGroup().background() ); | 294 | buffer.fill( colorGroup().background() ); |
280 | //buffer.fill( backgroundColor() ); | 295 | //buffer.fill( backgroundColor() ); |
281 | // parentWidget()->style().drawPrimitive( QStyle::PE_Panel, &p, rect(), parentWidget()->colorGroup()); | 296 | // parentWidget()->style().drawPrimitive( QStyle::PE_Panel, &p, rect(), parentWidget()->colorGroup()); |
282 | 297 | ||
283 | int sw = 8; // Hardcoded, given I didn't use styles anymore, I didn't like to use their size | 298 | int sw = 8; // Hardcoded, given I didn't use styles anymore, I didn't like to use their size |
284 | 299 | ||
285 | // arrow color | 300 | // arrow color |
286 | QColor col; | 301 | QColor col; |
287 | if ( _activeButton ) | 302 | if ( _activeButton ) |
288 | col = colorGroup().background().dark( 250 ); | 303 | col = colorGroup().background().dark( 250 ); |
289 | else { | 304 | else { |
290 | if ( mMouseDown ) | 305 | if ( mMouseDown ) |
291 | col = Qt::white; | 306 | col = Qt::white; |
292 | else | 307 | else |
293 | col = colorGroup().background().dark( 150 ); | 308 | col = colorGroup().background().dark( 150 ); |
294 | } | 309 | } |
295 | //QColor col = backgroundColor().dark( 130 ); | 310 | //QColor col = backgroundColor().dark( 130 ); |
296 | p.setBrush( col ); | 311 | p.setBrush( col ); |
297 | p.setPen( col ); | 312 | p.setPen( col ); |
298 | 313 | ||
299 | QValueList<QPointArray> list = buttonRegions(); | 314 | QValueList<QPointArray> list = buttonRegions(); |
300 | int index = 1; | 315 | int index = 1; |
301 | if ( mUseOffset ) | 316 | if ( mUseOffset ) |
302 | p.translate( 0, 1 ); | 317 | p.translate( 0, 1 ); |
303 | for ( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { | 318 | for ( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { |
304 | if ( index == _activeButton ) { | 319 | if ( index == _activeButton ) { |
305 | 320 | ||
306 | /* | 321 | /* |
307 | if ( ! _collapsed ) { | 322 | if ( ! _collapsed ) { |
308 | p.save(); | 323 | p.save(); |
309 | // p.translate( parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftHorizontal ), | 324 | // p.translate( parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftHorizontal ), |
310 | // parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftVertical ) ); | 325 | // parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftVertical ) ); |
311 | p.translate( -1, 0 ); | 326 | p.translate( -1, 0 ); |
312 | p.drawPolygon( *it, true ); | 327 | p.drawPolygon( *it, true ); |
313 | p.restore(); } else | 328 | p.restore(); } else |
314 | */ | 329 | */ |
315 | p.drawPolygon( *it, true ); | 330 | p.drawPolygon( *it, true ); |
316 | 331 | ||
317 | } | 332 | } |
318 | else { | 333 | else { |
319 | /* | 334 | /* |
320 | if ( ! _collapsed ) { | 335 | if ( ! _collapsed ) { |
321 | p.save(); | 336 | p.save(); |
322 | p.translate( -1, 0 ); | 337 | p.translate( -1, 0 ); |
323 | p.drawPolygon( *it, true ); | 338 | p.drawPolygon( *it, true ); |
324 | p.restore(); | 339 | p.restore(); |
325 | } else | 340 | } else |
326 | */ | 341 | */ |
327 | p.drawPolygon( *it, true ); | 342 | p.drawPolygon( *it, true ); |
328 | 343 | ||
329 | } | 344 | } |
330 | index++; | 345 | index++; |
331 | } | 346 | } |
332 | 347 | ||
333 | // Draw the lines between the arrows | 348 | // Draw the lines between the arrows |
334 | if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left || | 349 | if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left || |
335 | s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) { | 350 | s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) { |
336 | int mid = height()/2; | 351 | int mid = height()/2; |
337 | p.drawLine ( 1, mid - sw, 1, mid + sw ); | 352 | p.drawLine ( 1, mid - sw, 1, mid + sw ); |
338 | p.drawLine ( 3, mid - sw, 3, mid + sw ); | 353 | p.drawLine ( 3, mid - sw, 3, mid + sw ); |
339 | } | 354 | } |
340 | else if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Up || | 355 | else if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Up || |
341 | s->minimizeDirection() == KDGanttMinimizeSplitter::Down ) { | 356 | s->minimizeDirection() == KDGanttMinimizeSplitter::Down ) { |
342 | int mid = width()/2; | 357 | int mid = width()/2; |
343 | p.drawLine( mid -sw, 1, mid +sw, 1 ); | 358 | p.drawLine( mid -sw, 1, mid +sw, 1 ); |
344 | p.drawLine( mid -sw, 3, mid +sw, 3 ); | 359 | p.drawLine( mid -sw, 3, mid +sw, 3 ); |
345 | } | 360 | } |
346 | bitBlt( this, 0, 0, &buffer ); | 361 | bitBlt( this, 0, 0, &buffer ); |
347 | 362 | ||
348 | } | 363 | } |
349 | #endif | 364 | #endif |
350 | 365 | ||
351 | class QSplitterLayoutStruct | 366 | class QSplitterLayoutStruct |
352 | { | 367 | { |
353 | public: | 368 | public: |
354 | KDGanttMinimizeSplitter::ResizeMode mode; | 369 | KDGanttMinimizeSplitter::ResizeMode mode; |
355 | QCOORD sizer; | 370 | QCOORD sizer; |
356 | bool isSplitter; | 371 | bool isSplitter; |
357 | QWidget *wid; | 372 | QWidget *wid; |
358 | }; | 373 | }; |
359 | 374 | ||
360 | class QSplitterData | 375 | class QSplitterData |
361 | { | 376 | { |
362 | public: | 377 | public: |
363 | QSplitterData() : opaque( FALSE ), firstShow( TRUE ) {} | 378 | QSplitterData() : opaque( FALSE ), firstShow( TRUE ) {} |
364 | 379 | ||
365 | QPtrList<QSplitterLayoutStruct> list; | 380 | QPtrList<QSplitterLayoutStruct> list; |
366 | bool opaque; | 381 | bool opaque; |
367 | bool firstShow; | 382 | bool firstShow; |
368 | }; | 383 | }; |
369 | 384 | ||
370 | void kdganttGeomCalc( QMemArray<QLayoutStruct> &chain, int start, int count, int pos, | 385 | void kdganttGeomCalc( QMemArray<QLayoutStruct> &chain, int start, int count, int pos, |
371 | int space, int spacer ); | 386 | int space, int spacer ); |
372 | #endif // DOXYGEN_SKIP_INTERNAL | 387 | #endif // DOXYGEN_SKIP_INTERNAL |
373 | 388 | ||
374 | 389 | ||
375 | /*! | 390 | /*! |
376 | \class KDGanttMinimizeSplitter KDGanttMinimizeSplitter.h | 391 | \class KDGanttMinimizeSplitter KDGanttMinimizeSplitter.h |
377 | \brief The KDGanttMinimizeSplitter class implements a splitter | 392 | \brief The KDGanttMinimizeSplitter class implements a splitter |
378 | widget with minimize buttons. | 393 | widget with minimize buttons. |
379 | 394 | ||
380 | This class (and its documentation) is largely a copy of Qt's | 395 | This class (and its documentation) is largely a copy of Qt's |
381 | QSplitter; the copying was necessary because QSplitter is not | 396 | QSplitter; the copying was necessary because QSplitter is not |
382 | extensible at all. QSplitter and its documentation are licensed | 397 | extensible at all. QSplitter and its documentation are licensed |
383 | according to the GPL and the Qt Professional License (if you hold | 398 | according to the GPL and the Qt Professional License (if you hold |
384 | such a license) and are (C) Trolltech AS. | 399 | such a license) and are (C) Trolltech AS. |
385 | 400 | ||
386 | A splitter lets the user control the size of child widgets by | 401 | A splitter lets the user control the size of child widgets by |
387 | dragging the boundary between the children. Any number of widgets | 402 | dragging the boundary between the children. Any number of widgets |
388 | may be controlled. | 403 | may be controlled. |
389 | 404 | ||
390 | To show a QListBox, a QListView and a QTextEdit side by side: | 405 | To show a QListBox, a QListView and a QTextEdit side by side: |
391 | 406 | ||
392 | \code | 407 | \code |
393 | KDGanttMinimizeSplitter *split = new KDGanttMinimizeSplitter( parent ); | 408 | KDGanttMinimizeSplitter *split = new KDGanttMinimizeSplitter( parent ); |
394 | QListBox *lb = new QListBox( split ); | 409 | QListBox *lb = new QListBox( split ); |
395 | QListView *lv = new QListView( split ); | 410 | QListView *lv = new QListView( split ); |
396 | QTextEdit *ed = new QTextEdit( split ); | 411 | QTextEdit *ed = new QTextEdit( split ); |
397 | \endcode | 412 | \endcode |
398 | 413 | ||
399 | In KDGanttMinimizeSplitter, the boundary can be either horizontal or | 414 | In KDGanttMinimizeSplitter, the boundary can be either horizontal or |
400 | vertical. The default is horizontal (the children are side by side) | 415 | vertical. The default is horizontal (the children are side by side) |
401 | but you can use setOrientation( QSplitter::Vertical ) to set it to | 416 | but you can use setOrientation( QSplitter::Vertical ) to set it to |
402 | vertical. | 417 | vertical. |
403 | 418 | ||
404 | Use setResizeMode() to specify | 419 | Use setResizeMode() to specify |
405 | that a widget should keep its size when the splitter is resized. | 420 | that a widget should keep its size when the splitter is resized. |
406 | 421 | ||
407 | Although KDGanttMinimizeSplitter normally resizes the children only | 422 | Although KDGanttMinimizeSplitter normally resizes the children only |
408 | at the end of a resize operation, if you call setOpaqueResize( TRUE | 423 | at the end of a resize operation, if you call setOpaqueResize( TRUE |
409 | ) the widgets are resized as often as possible. | 424 | ) the widgets are resized as often as possible. |
410 | 425 | ||
411 | The initial distribution of size between the widgets is determined | 426 | The initial distribution of size between the widgets is determined |
412 | by the initial size of each widget. You can also use setSizes() to | 427 | by the initial size of each widget. You can also use setSizes() to |
413 | set the sizes of all the widgets. The function sizes() returns the | 428 | set the sizes of all the widgets. The function sizes() returns the |
414 | sizes set by the user. | 429 | sizes set by the user. |
415 | 430 | ||
416 | If you hide() a child, its space will be distributed among the other | 431 | If you hide() a child, its space will be distributed among the other |
417 | children. It will be reinstated when you show() it again. It is also | 432 | children. It will be reinstated when you show() it again. It is also |
418 | possible to reorder the widgets within the splitter using | 433 | possible to reorder the widgets within the splitter using |
419 | moveToFirst() and moveToLast(). | 434 | moveToFirst() and moveToLast(). |
420 | */ | 435 | */ |
421 | 436 | ||
422 | 437 | ||
423 | 438 | ||
424 | static QSize minSize( const QWidget* /*w*/ ) | 439 | static QSize minSize( const QWidget* /*w*/ ) |
425 | { | 440 | { |
426 | return QSize(0,0); | 441 | return QSize(0,0); |
427 | } | 442 | } |
428 | 443 | ||
429 | // This is the original version of minSize | 444 | // This is the original version of minSize |
430 | static QSize minSizeHint( const QWidget* w ) | 445 | static QSize minSizeHint( const QWidget* w ) |
431 | { | 446 | { |
432 | QSize min = w->minimumSize(); | 447 | QSize min = w->minimumSize(); |
433 | QSize s; | 448 | QSize s; |
434 | if ( min.height() <= 0 || min.width() <= 0 ) | 449 | if ( min.height() <= 0 || min.width() <= 0 ) |
435 | s = w->minimumSizeHint(); | 450 | s = w->minimumSizeHint(); |
436 | if ( min.height() > 0 ) | 451 | if ( min.height() > 0 ) |
437 | s.setHeight( min.height() ); | 452 | s.setHeight( min.height() ); |
438 | if ( min.width() > 0 ) | 453 | if ( min.width() > 0 ) |
439 | s.setWidth( min.width() ); | 454 | s.setWidth( min.width() ); |
440 | return s.expandedTo(QSize(0,0)); | 455 | return s.expandedTo(QSize(0,0)); |
441 | } | 456 | } |
442 | 457 | ||
443 | 458 | ||
444 | /*! | 459 | /*! |
445 | Constructs a horizontal splitter with the \a parent and \a | 460 | Constructs a horizontal splitter with the \a parent and \a |
446 | name arguments being passed on to the QFrame constructor. | 461 | name arguments being passed on to the QFrame constructor. |
447 | */ | 462 | */ |
448 | KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( QWidget *parent, const char *name ) | 463 | KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( QWidget *parent, const char *name ) |
449 | :QFrame(parent,name,WPaintUnclipped) | 464 | :QFrame(parent,name,WPaintUnclipped) |
450 | { | 465 | { |
451 | mRubberBand = 0; | 466 | mRubberBand = 0; |
452 | mFirstHandle = 0; | 467 | mFirstHandle = 0; |
453 | #if QT_VERSION >= 232 | 468 | #if QT_VERSION >= 232 |
454 | orient = Horizontal; | 469 | orient = Horizontal; |
455 | init(); | 470 | init(); |
456 | #endif | 471 | #endif |
457 | } | 472 | } |
458 | 473 | ||
459 | /*! | 474 | /*! |
460 | Constructs a splitter with orientation \a o with the \a parent | 475 | Constructs a splitter with orientation \a o with the \a parent |
461 | and \a name arguments being passed on to the QFrame constructor. | 476 | and \a name arguments being passed on to the QFrame constructor. |
462 | */ | 477 | */ |
463 | KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( Orientation o, QWidget *parent, const char *name ) | 478 | KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( Orientation o, QWidget *parent, const char *name ) |
464 | :QFrame(parent,name,WPaintUnclipped) | 479 | :QFrame(parent,name,WPaintUnclipped) |
465 | { | 480 | { |
466 | 481 | ||
467 | mRubberBand = 0; | 482 | mRubberBand = 0; |
468 | mFirstHandle = 0; | 483 | mFirstHandle = 0; |
469 | #if QT_VERSION >= 232 | 484 | #if QT_VERSION >= 232 |
470 | orient = o; | 485 | orient = o; |
471 | init(); | 486 | init(); |
472 | #endif | 487 | #endif |
473 | } | 488 | } |
474 | 489 | ||
475 | /*! | 490 | /*! |
476 | Destroys the splitter and any children. | 491 | Destroys the splitter and any children. |
477 | */ | 492 | */ |
478 | KDGanttMinimizeSplitter::~KDGanttMinimizeSplitter() | 493 | KDGanttMinimizeSplitter::~KDGanttMinimizeSplitter() |
479 | { | 494 | { |
480 | #if QT_VERSION >= 232 | 495 | #if QT_VERSION >= 232 |
481 | data->list.setAutoDelete( TRUE ); | 496 | data->list.setAutoDelete( TRUE ); |
482 | delete data; | 497 | delete data; |
483 | #endif | 498 | #endif |
484 | if ( mRubberBand ) | 499 | if ( mRubberBand ) |
485 | delete mRubberBand; | 500 | delete mRubberBand; |
486 | } | 501 | } |
487 | 502 | ||
488 | 503 | ||
489 | #if QT_VERSION >= 232 | 504 | #if QT_VERSION >= 232 |
490 | void KDGanttMinimizeSplitter::init() | 505 | void KDGanttMinimizeSplitter::init() |
491 | { | 506 | { |
492 | data = new QSplitterData; | 507 | data = new QSplitterData; |
493 | if ( orient == Horizontal ) | 508 | if ( orient == Horizontal ) |
494 | setSizePolicy( QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum) ); | 509 | setSizePolicy( QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum) ); |
495 | else | 510 | else |
496 | setSizePolicy( QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Expanding) ); | 511 | setSizePolicy( QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Expanding) ); |
497 | #ifndef DESKTOP_VERSION | 512 | #ifndef DESKTOP_VERSION |
498 | setOpaqueResize( false ); | 513 | setOpaqueResize( false ); |
499 | #else | 514 | #else |
500 | setOpaqueResize( true ); | 515 | setOpaqueResize( true ); |
501 | #endif | 516 | #endif |
502 | } | 517 | } |
503 | #endif | 518 | #endif |
504 | 519 | ||
505 | 520 | ||
506 | void KDGanttMinimizeSplitter::toggle() | 521 | void KDGanttMinimizeSplitter::toggle() |
507 | { | 522 | { |
508 | if ( mFirstHandle ) | 523 | if ( mFirstHandle ) |
509 | mFirstHandle->toggle(); | 524 | mFirstHandle->toggle(); |
510 | else | 525 | else |
511 | qDebug("KDGanttMinimizeSplitter::toggle::sorry, handle not available "); | 526 | qDebug("KDGanttMinimizeSplitter::toggle::sorry, handle not available "); |
512 | 527 | ||
513 | } | 528 | } |
514 | 529 | ||
515 | 530 | ||
516 | /*! | 531 | /*! |
517 | \brief the orientation of the splitter | 532 | \brief the orientation of the splitter |
518 | 533 | ||
519 | By default the orientation is horizontal (the widgets are side by side). | 534 | By default the orientation is horizontal (the widgets are side by side). |
520 | The possible orientations are Qt:Vertical and Qt::Horizontal (the default). | 535 | The possible orientations are Qt:Vertical and Qt::Horizontal (the default). |
521 | */ | 536 | */ |
522 | void KDGanttMinimizeSplitter::setOrientation( Orientation o ) | 537 | void KDGanttMinimizeSplitter::setOrientation( Orientation o ) |
523 | { | 538 | { |
524 | #if QT_VERSION >= 232 | 539 | #if QT_VERSION >= 232 |
525 | if ( orient == o ) | 540 | if ( orient == o ) |
526 | return; | 541 | return; |
527 | orient = o; | 542 | orient = o; |
528 | 543 | ||
529 | if ( orient == Horizontal ) | 544 | if ( orient == Horizontal ) |
530 | setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); | 545 | setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); |
531 | else | 546 | else |
532 | setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); | 547 | setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); |
533 | 548 | ||
534 | QSplitterLayoutStruct *s = data->list.first(); | 549 | QSplitterLayoutStruct *s = data->list.first(); |
535 | while ( s ) { | 550 | while ( s ) { |
536 | if ( s->isSplitter ) | 551 | if ( s->isSplitter ) |
537 | ((KDGanttSplitterHandle*)s->wid)->setOrientation( o ); | 552 | ((KDGanttSplitterHandle*)s->wid)->setOrientation( o ); |
538 | s = data->list.next(); // ### next at end of loop, no iterator | 553 | s = data->list.next(); // ### next at end of loop, no iterator |
539 | } | 554 | } |
540 | recalc( isVisible() ); | 555 | recalc( isVisible() ); |
541 | #endif | 556 | #endif |
542 | } | 557 | } |
543 | 558 | ||
544 | 559 | ||
545 | #if QT_VERSION >= 232 | 560 | #if QT_VERSION >= 232 |
546 | /*! | 561 | /*! |
547 | \reimp | 562 | \reimp |
548 | */ | 563 | */ |
549 | void KDGanttMinimizeSplitter::resizeEvent( QResizeEvent * ) | 564 | void KDGanttMinimizeSplitter::resizeEvent( QResizeEvent * ) |
550 | { | 565 | { |
551 | doResize(); | 566 | doResize(); |
552 | } | 567 | } |
553 | 568 | ||
554 | 569 | ||
555 | /* | 570 | /* |
556 | Inserts the widget \a w at the end (or at the beginning if \a first | 571 | Inserts the widget \a w at the end (or at the beginning if \a first |
557 | is TRUE) of the splitter's list of widgets. | 572 | is TRUE) of the splitter's list of widgets. |
558 | 573 | ||
559 | It is the responsibility of the caller of this function to make sure | 574 | It is the responsibility of the caller of this function to make sure |
560 | that \a w is not already in the splitter and to call recalcId if | 575 | that \a w is not already in the splitter and to call recalcId if |
561 | needed. (If \a first is TRUE, then recalcId is very probably | 576 | needed. (If \a first is TRUE, then recalcId is very probably |
562 | needed.) | 577 | needed.) |
563 | */ | 578 | */ |
564 | QSplitterLayoutStruct *KDGanttMinimizeSplitter::addWidget( QWidget *w, bool first ) | 579 | QSplitterLayoutStruct *KDGanttMinimizeSplitter::addWidget( QWidget *w, bool first ) |
565 | { | 580 | { |
566 | QSplitterLayoutStruct *s; | 581 | QSplitterLayoutStruct *s; |
567 | KDGanttSplitterHandle *newHandle = 0; | 582 | KDGanttSplitterHandle *newHandle = 0; |
568 | if ( data->list.count() > 0 ) { | 583 | if ( data->list.count() > 0 ) { |
569 | s = new QSplitterLayoutStruct; | 584 | s = new QSplitterLayoutStruct; |
570 | s->mode = KeepSize; | 585 | s->mode = KeepSize; |
571 | QString tmp = "qt_splithandle_"; | 586 | QString tmp = "qt_splithandle_"; |
572 | tmp += w->name(); | 587 | tmp += w->name(); |
573 | newHandle = new KDGanttSplitterHandle( orientation(), this, tmp.latin1() ); | 588 | newHandle = new KDGanttSplitterHandle( orientation(), this, tmp.latin1() ); |
574 | if ( ! mFirstHandle ) | 589 | if ( ! mFirstHandle ) |
575 | mFirstHandle = newHandle; | 590 | mFirstHandle = newHandle; |
576 | s->wid = newHandle; | 591 | s->wid = newHandle; |
577 | newHandle->setId(data->list.count()); | 592 | newHandle->setId(data->list.count()); |
578 | s->isSplitter = TRUE; | 593 | s->isSplitter = TRUE; |
579 | s->sizer = pick( newHandle->sizeHint() ); | 594 | s->sizer = pick( newHandle->sizeHint() ); |
580 | if ( first ) | 595 | if ( first ) |
581 | data->list.insert( 0, s ); | 596 | data->list.insert( 0, s ); |
582 | else | 597 | else |
583 | data->list.append( s ); | 598 | data->list.append( s ); |
584 | } | 599 | } |
585 | s = new QSplitterLayoutStruct; | 600 | s = new QSplitterLayoutStruct; |
586 | s->mode = Stretch; | 601 | s->mode = Stretch; |
587 | s->wid = w; | 602 | s->wid = w; |
588 | if ( !testWState( WState_Resized ) && w->sizeHint().isValid() ) | 603 | if ( !testWState( WState_Resized ) && w->sizeHint().isValid() ) |
589 | s->sizer = pick( w->sizeHint() ); | 604 | s->sizer = pick( w->sizeHint() ); |
590 | else | 605 | else |
591 | s->sizer = pick( w->size() ); | 606 | s->sizer = pick( w->size() ); |
592 | s->isSplitter = FALSE; | 607 | s->isSplitter = FALSE; |
593 | if ( first ) | 608 | if ( first ) |
594 | data->list.insert( 0, s ); | 609 | data->list.insert( 0, s ); |
595 | else | 610 | else |
596 | data->list.append( s ); | 611 | data->list.append( s ); |
597 | if ( newHandle && isVisible() ) | 612 | if ( newHandle && isVisible() ) |
598 | newHandle->show(); //will trigger sending of post events | 613 | newHandle->show(); //will trigger sending of post events |
599 | return s; | 614 | return s; |
600 | } | 615 | } |
601 | 616 | ||
602 | 617 | ||
603 | /*! | 618 | /*! |
604 | Tells the splitter that a child widget has been inserted or removed. | 619 | Tells the splitter that a child widget has been inserted or removed. |
605 | The event is passed in \a c. | 620 | The event is passed in \a c. |
606 | */ | 621 | */ |
607 | void KDGanttMinimizeSplitter::childEvent( QChildEvent *c ) | 622 | void KDGanttMinimizeSplitter::childEvent( QChildEvent *c ) |
608 | { | 623 | { |
609 | if ( c->type() == QEvent::ChildInserted ) { | 624 | if ( c->type() == QEvent::ChildInserted ) { |
610 | if ( !c->child()->isWidgetType() ) | 625 | if ( !c->child()->isWidgetType() ) |
611 | return; | 626 | return; |
612 | 627 | ||
613 | if ( ((QWidget*)c->child())->testWFlags( WType_TopLevel ) ) | 628 | if ( ((QWidget*)c->child())->testWFlags( WType_TopLevel ) ) |
614 | return; | 629 | return; |
615 | 630 | ||
616 | QSplitterLayoutStruct *s = data->list.first(); | 631 | QSplitterLayoutStruct *s = data->list.first(); |
617 | while ( s ) { | 632 | while ( s ) { |
618 | if ( s->wid == c->child() ) | 633 | if ( s->wid == c->child() ) |
619 | return; | 634 | return; |
620 | s = data->list.next(); | 635 | s = data->list.next(); |
621 | } | 636 | } |
622 | addWidget( (QWidget*)c->child() ); | 637 | addWidget( (QWidget*)c->child() ); |
623 | recalc( isVisible() ); | 638 | recalc( isVisible() ); |
624 | 639 | ||
625 | } else if ( c->type() == QEvent::ChildRemoved ) { | 640 | } else if ( c->type() == QEvent::ChildRemoved ) { |
626 | QSplitterLayoutStruct *p = 0; | 641 | QSplitterLayoutStruct *p = 0; |
627 | if ( data->list.count() > 1 ) | 642 | if ( data->list.count() > 1 ) |
628 | p = data->list.at(1); //remove handle _after_ first widget. | 643 | p = data->list.at(1); //remove handle _after_ first widget. |
629 | QSplitterLayoutStruct *s = data->list.first(); | 644 | QSplitterLayoutStruct *s = data->list.first(); |
630 | while ( s ) { | 645 | while ( s ) { |
631 | if ( s->wid == c->child() ) { | 646 | if ( s->wid == c->child() ) { |
632 | data->list.removeRef( s ); | 647 | data->list.removeRef( s ); |
633 | delete s; | 648 | delete s; |
634 | if ( p && p->isSplitter ) { | 649 | if ( p && p->isSplitter ) { |
635 | data->list.removeRef( p ); | 650 | data->list.removeRef( p ); |
636 | delete p->wid; //will call childEvent | 651 | delete p->wid; //will call childEvent |
637 | delete p; | 652 | delete p; |
638 | } | 653 | } |
639 | recalcId(); | 654 | recalcId(); |
640 | doResize(); | 655 | doResize(); |
641 | return; | 656 | return; |
642 | } | 657 | } |
643 | p = s; | 658 | p = s; |
644 | s = data->list.next(); | 659 | s = data->list.next(); |
645 | } | 660 | } |
646 | } | 661 | } |
647 | } | 662 | } |
648 | 663 | ||
649 | 664 | ||
650 | /*! | 665 | /*! |
651 | Shows a rubber band at position \a p. If \a p is negative, the | 666 | Shows a rubber band at position \a p. If \a p is negative, the |
652 | rubber band is removed. | 667 | rubber band is removed. |
653 | */ | 668 | */ |
654 | void KDGanttMinimizeSplitter::setRubberband( int p ) | 669 | void KDGanttMinimizeSplitter::setRubberband( int p ) |
655 | { | 670 | { |
656 | #ifdef DESKTOP_VERSION | 671 | #ifdef DESKTOP_VERSION |
657 | QPainter paint( this ); | 672 | QPainter paint( this ); |
658 | paint.setPen( gray ); | 673 | paint.setPen( gray ); |
659 | paint.setBrush( gray ); | 674 | paint.setBrush( gray ); |
660 | paint.setRasterOp( XorROP ); | 675 | paint.setRasterOp( XorROP ); |
661 | QRect r = contentsRect(); | 676 | QRect r = contentsRect(); |
662 | const int rBord = 3; //Themable???? | 677 | const int rBord = 3; //Themable???? |
663 | #if QT_VERSION >= 0x030000 | 678 | #if QT_VERSION >= 0x030000 |
664 | int sw = style().pixelMetric(QStyle::PM_SplitterWidth, this); | 679 | int sw = style().pixelMetric(QStyle::PM_SplitterWidth, this); |
665 | #else | 680 | #else |
666 | int sw = style().splitterWidth(); | 681 | int sw = style().splitterWidth(); |
667 | #endif | 682 | #endif |
668 | if ( orient == Horizontal ) { | 683 | if ( orient == Horizontal ) { |
669 | if ( opaqueOldPos >= 0 ) | 684 | if ( opaqueOldPos >= 0 ) |
670 | paint.drawRect( opaqueOldPos + sw/2 - rBord , r.y(), | 685 | paint.drawRect( opaqueOldPos + sw/2 - rBord , r.y(), |
671 | 2*rBord, r.height() ); | 686 | 2*rBord, r.height() ); |
672 | if ( p >= 0 ) | 687 | if ( p >= 0 ) |
673 | paint.drawRect( p + sw/2 - rBord, r.y(), 2*rBord, r.height() ); | 688 | paint.drawRect( p + sw/2 - rBord, r.y(), 2*rBord, r.height() ); |
674 | } else { | 689 | } else { |
675 | if ( opaqueOldPos >= 0 ) | 690 | if ( opaqueOldPos >= 0 ) |
676 | paint.drawRect( r.x(), opaqueOldPos + sw/2 - rBord, | 691 | paint.drawRect( r.x(), opaqueOldPos + sw/2 - rBord, |
677 | r.width(), 2*rBord ); | 692 | r.width(), 2*rBord ); |
678 | if ( p >= 0 ) | 693 | if ( p >= 0 ) |
679 | paint.drawRect( r.x(), p + sw/2 - rBord, r.width(), 2*rBord ); | 694 | paint.drawRect( r.x(), p + sw/2 - rBord, r.width(), 2*rBord ); |
680 | } | 695 | } |
681 | opaqueOldPos = p; | 696 | opaqueOldPos = p; |
682 | #else | 697 | #else |
683 | if ( !mRubberBand ) { | 698 | if ( !mRubberBand ) { |
684 | mRubberBand = new QFrame( 0, "rubber", WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop); | 699 | mRubberBand = new KDRubberBand( 0, "rubber", WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop); |
685 | mRubberBand->setFrameStyle( Box | Raised ); | 700 | mRubberBand->setFrameStyle( Box | Raised ); |
686 | //mRubberBand->setPalette( QPalette ( Qt::red.light(),Qt::red.dark() ) ); | 701 | //mRubberBand->setPalette( QPalette ( Qt::red.light(),Qt::red.dark() ) ); |
687 | mRubberBand->setPalette( QPalette ( colorGroup().background().light(), colorGroup().background().dark() )); | 702 | mRubberBand->setPalette( QPalette ( colorGroup().background().light(), colorGroup().background().dark() )); |
688 | } | 703 | } |
689 | QRect r = contentsRect(); | 704 | QRect r = contentsRect(); |
690 | static int rBord = 0; //Themable???? | 705 | static int rBord = 0; //Themable???? |
691 | if ( !rBord ) { | 706 | if ( !rBord ) { |
692 | if (QApplication::desktop()->width() <= 320 ) | 707 | if (QApplication::desktop()->width() <= 320 ) |
693 | rBord = 3; | 708 | rBord = 3; |
694 | else | 709 | else |
695 | rBord = 4; | 710 | rBord = 4; |
696 | } | 711 | } |
697 | int sw = style().splitterWidth(); | 712 | int sw = style().splitterWidth(); |
698 | if ( orient == Horizontal ) { | 713 | if ( orient == Horizontal ) { |
699 | if ( p >= 0 ) { | 714 | if ( p >= 0 ) { |
700 | QPoint geo = mapToGlobal (QPoint ( p + sw/2 - rBord, r.y())); | 715 | QPoint geo = mapToGlobal (QPoint ( p + sw/2 - rBord, r.y())); |
701 | mRubberBand->setGeometry( geo.x(), geo.y(), 2*rBord, r.height() ); | 716 | mRubberBand->setGeometry( geo.x(), geo.y(), 2*rBord, r.height() ); |
702 | } | 717 | } |
703 | } else { | 718 | } else { |
704 | if ( p >= 0 ) { | 719 | if ( p >= 0 ) { |
705 | QPoint geo = mapToGlobal (QPoint ( r.x(), p + sw/2 - rBord)); | 720 | QPoint geo = mapToGlobal (QPoint ( r.x(), p + sw/2 - rBord)); |
706 | mRubberBand->setGeometry( geo.x(), geo.y(), r.width(), 2*rBord); | 721 | mRubberBand->setGeometry( geo.x(), geo.y(), r.width(), 2*rBord); |
707 | } | 722 | } |
708 | } | 723 | } |
709 | opaqueOldPos = p; | 724 | opaqueOldPos = p; |
710 | if ( ! mRubberBand->isVisible() ) { | 725 | if ( ! mRubberBand->isVisible() ) { |
711 | mRubberBand->show(); | 726 | mRubberBand->show(); |
712 | } | 727 | } |
713 | #endif | 728 | #endif |
714 | } | 729 | } |
715 | 730 | ||
716 | 731 | ||
717 | /*! \reimp */ | 732 | /*! \reimp */ |
718 | bool KDGanttMinimizeSplitter::event( QEvent *e ) | 733 | bool KDGanttMinimizeSplitter::event( QEvent *e ) |
719 | { | 734 | { |
720 | if ( e->type() == QEvent::LayoutHint || ( e->type() == QEvent::Show && data->firstShow ) ) { | 735 | if ( e->type() == QEvent::LayoutHint || ( e->type() == QEvent::Show && data->firstShow ) ) { |
721 | recalc( isVisible() ); | 736 | recalc( isVisible() ); |
722 | if ( e->type() == QEvent::Show ) | 737 | if ( e->type() == QEvent::Show ) |
723 | data->firstShow = FALSE; | 738 | data->firstShow = FALSE; |
724 | } | 739 | } |
725 | return QWidget::event( e ); | 740 | return QWidget::event( e ); |
726 | } | 741 | } |
727 | 742 | ||
728 | 743 | ||
729 | /*! | 744 | /*! |
730 | \obsolete | 745 | \obsolete |
731 | 746 | ||
732 | Draws the splitter handle in the rectangle described by \a x, \a y, | 747 | Draws the splitter handle in the rectangle described by \a x, \a y, |
733 | \a w, \a h using painter \a p. | 748 | \a w, \a h using painter \a p. |
734 | \sa QStyle::drawPrimitive() | 749 | \sa QStyle::drawPrimitive() |
735 | */ | 750 | */ |
736 | void KDGanttMinimizeSplitter::drawSplitter( QPainter *p, | 751 | void KDGanttMinimizeSplitter::drawSplitter( QPainter *p, |
737 | QCOORD x, QCOORD y, QCOORD w, QCOORD h ) | 752 | QCOORD x, QCOORD y, QCOORD w, QCOORD h ) |
738 | { | 753 | { |
739 | #if 0 | 754 | #if 0 |
740 | // LR | 755 | // LR |
741 | style().drawPrimitive(QStyle::PE_Splitter, p, QRect(x, y, w, h), colorGroup(), | 756 | style().drawPrimitive(QStyle::PE_Splitter, p, QRect(x, y, w, h), colorGroup(), |
742 | (orientation() == Qt::Horizontal ? | 757 | (orientation() == Qt::Horizontal ? |
743 | QStyle::Style_Horizontal : 0)); | 758 | QStyle::Style_Horizontal : 0)); |
744 | #endif | 759 | #endif |
745 | } | 760 | } |
746 | 761 | ||
747 | 762 | ||
748 | /*! | 763 | /*! |
749 | Returns the id of the splitter to the right of or below the widget \a w, | 764 | Returns the id of the splitter to the right of or below the widget \a w, |
750 | or 0 if there is no such splitter | 765 | or 0 if there is no such splitter |
751 | (i.e. it is either not in this KDGanttMinimizeSplitter or it is at the end). | 766 | (i.e. it is either not in this KDGanttMinimizeSplitter or it is at the end). |
752 | */ | 767 | */ |
753 | int KDGanttMinimizeSplitter::idAfter( QWidget* w ) const | 768 | int KDGanttMinimizeSplitter::idAfter( QWidget* w ) const |
754 | { | 769 | { |
755 | QSplitterLayoutStruct *s = data->list.first(); | 770 | QSplitterLayoutStruct *s = data->list.first(); |
756 | bool seen_w = FALSE; | 771 | bool seen_w = FALSE; |
757 | while ( s ) { | 772 | while ( s ) { |
758 | if ( s->isSplitter && seen_w ) | 773 | if ( s->isSplitter && seen_w ) |
759 | return data->list.at(); | 774 | return data->list.at(); |
760 | if ( !s->isSplitter && s->wid == w ) | 775 | if ( !s->isSplitter && s->wid == w ) |
761 | seen_w = TRUE; | 776 | seen_w = TRUE; |
762 | s = data->list.next(); | 777 | s = data->list.next(); |
763 | } | 778 | } |
764 | return 0; | 779 | return 0; |
765 | } | 780 | } |
766 | 781 | ||
767 | 782 | ||
768 | /*! | 783 | /*! |
769 | Moves the left/top edge of the splitter handle with id \a id as | 784 | Moves the left/top edge of the splitter handle with id \a id as |
770 | close as possible to position \a p, which is the distance from the | 785 | close as possible to position \a p, which is the distance from the |
771 | left (or top) edge of the widget. | 786 | left (or top) edge of the widget. |
772 | 787 | ||
773 | For Arabic and Hebrew the layout is reversed, and using this | 788 | For Arabic and Hebrew the layout is reversed, and using this |
774 | function to set the position of the splitter might lead to | 789 | function to set the position of the splitter might lead to |
775 | unexpected results, since in Arabic and Hebrew the position of | 790 | unexpected results, since in Arabic and Hebrew the position of |
776 | splitter one is to the left of the position of splitter zero. | 791 | splitter one is to the left of the position of splitter zero. |
777 | 792 | ||
778 | \sa idAfter() | 793 | \sa idAfter() |
779 | */ | 794 | */ |
780 | void KDGanttMinimizeSplitter::moveSplitter( QCOORD p, int id ) | 795 | void KDGanttMinimizeSplitter::moveSplitter( QCOORD p, int id ) |
781 | { | 796 | { |
782 | p = adjustPos( p, id ); | 797 | p = adjustPos( p, id ); |
783 | QSplitterLayoutStruct *s = data->list.at(id); | 798 | QSplitterLayoutStruct *s = data->list.at(id); |
784 | int oldP = orient == Horizontal ? s->wid->x() : s->wid->y(); | 799 | int oldP = orient == Horizontal ? s->wid->x() : s->wid->y(); |
785 | bool upLeft; | 800 | bool upLeft; |
786 | if ( false && orient == Horizontal ) { | 801 | if ( false && orient == Horizontal ) { |
787 | p += s->wid->width(); | 802 | p += s->wid->width(); |
788 | upLeft = p > oldP; | 803 | upLeft = p > oldP; |
789 | } else | 804 | } else |
790 | upLeft = p < oldP; | 805 | upLeft = p < oldP; |
791 | 806 | ||
792 | moveAfter( p, id, upLeft ); | 807 | moveAfter( p, id, upLeft ); |
793 | moveBefore( p-1, id-1, upLeft ); | 808 | moveBefore( p-1, id-1, upLeft ); |
794 | 809 | ||
795 | storeSizes(); | 810 | storeSizes(); |
796 | } | 811 | } |
797 | 812 | ||
798 | 813 | ||
799 | void KDGanttMinimizeSplitter::setG( QWidget *w, int p, int s, bool isSplitter ) | 814 | void KDGanttMinimizeSplitter::setG( QWidget *w, int p, int s, bool isSplitter ) |
800 | { | 815 | { |
801 | if ( orient == Horizontal ) { | 816 | if ( orient == Horizontal ) { |
802 | if ( false && orient == Horizontal && !isSplitter ) | 817 | if ( false && orient == Horizontal && !isSplitter ) |
803 | p = contentsRect().width() - p - s; | 818 | p = contentsRect().width() - p - s; |
804 | w->setGeometry( p, contentsRect().y(), s, contentsRect().height() ); | 819 | w->setGeometry( p, contentsRect().y(), s, contentsRect().height() ); |
805 | } else | 820 | } else |
806 | w->setGeometry( contentsRect().x(), p, contentsRect().width(), s ); | 821 | w->setGeometry( contentsRect().x(), p, contentsRect().width(), s ); |
807 | } | 822 | } |
808 | 823 | ||
809 | 824 | ||
810 | /* | 825 | /* |
811 | Places the right/bottom edge of the widget at \a id at position \a pos. | 826 | Places the right/bottom edge of the widget at \a id at position \a pos. |
812 | 827 | ||
813 | \sa idAfter() | 828 | \sa idAfter() |
814 | */ | 829 | */ |
815 | void KDGanttMinimizeSplitter::moveBefore( int pos, int id, bool upLeft ) | 830 | void KDGanttMinimizeSplitter::moveBefore( int pos, int id, bool upLeft ) |
816 | { | 831 | { |
817 | if( id < 0 ) | 832 | if( id < 0 ) |
818 | return; | 833 | return; |
819 | QSplitterLayoutStruct *s = data->list.at(id); | 834 | QSplitterLayoutStruct *s = data->list.at(id); |
820 | if ( !s ) | 835 | if ( !s ) |
821 | return; | 836 | return; |
822 | QWidget *w = s->wid; | 837 | QWidget *w = s->wid; |
823 | if ( w->isHidden() ) { | 838 | if ( w->isHidden() ) { |
824 | moveBefore( pos, id-1, upLeft ); | 839 | moveBefore( pos, id-1, upLeft ); |
825 | } else if ( s->isSplitter ) { | 840 | } else if ( s->isSplitter ) { |
826 | int pos1, pos2; | 841 | int pos1, pos2; |
827 | int dd = s->sizer; | 842 | int dd = s->sizer; |
828 | if( false && orient == Horizontal ) { | 843 | if( false && orient == Horizontal ) { |
829 | pos1 = pos; | 844 | pos1 = pos; |
830 | pos2 = pos + dd; | 845 | pos2 = pos + dd; |
831 | } else { | 846 | } else { |
832 | pos2 = pos - dd; | 847 | pos2 = pos - dd; |
833 | pos1 = pos2 + 1; | 848 | pos1 = pos2 + 1; |
834 | } | 849 | } |
835 | if ( upLeft ) { | 850 | if ( upLeft ) { |
836 | setG( w, pos1, dd, TRUE ); | 851 | setG( w, pos1, dd, TRUE ); |
837 | moveBefore( pos2, id-1, upLeft ); | 852 | moveBefore( pos2, id-1, upLeft ); |
838 | } else { | 853 | } else { |
839 | moveBefore( pos2, id-1, upLeft ); | 854 | moveBefore( pos2, id-1, upLeft ); |
840 | setG( w, pos1, dd, TRUE ); | 855 | setG( w, pos1, dd, TRUE ); |
841 | } | 856 | } |
842 | } else { | 857 | } else { |
843 | int dd, newLeft, nextPos; | 858 | int dd, newLeft, nextPos; |
844 | if( false && orient == Horizontal ) { | 859 | if( false && orient == Horizontal ) { |
845 | dd = w->geometry().right() - pos; | 860 | dd = w->geometry().right() - pos; |
846 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); | 861 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); |
847 | newLeft = pos+1; | 862 | newLeft = pos+1; |
848 | nextPos = newLeft + dd; | 863 | nextPos = newLeft + dd; |
849 | } else { | 864 | } else { |
850 | dd = pos - pick( w->pos() ) + 1; | 865 | dd = pos - pick( w->pos() ) + 1; |
851 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); | 866 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); |
852 | newLeft = pos-dd+1; | 867 | newLeft = pos-dd+1; |
853 | nextPos = newLeft - 1; | 868 | nextPos = newLeft - 1; |
854 | } | 869 | } |
855 | setG( w, newLeft, dd, TRUE ); | 870 | setG( w, newLeft, dd, TRUE ); |
856 | moveBefore( nextPos, id-1, upLeft ); | 871 | moveBefore( nextPos, id-1, upLeft ); |
857 | } | 872 | } |
858 | } | 873 | } |
859 | 874 | ||
860 | 875 | ||
861 | /* | 876 | /* |
862 | Places the left/top edge of the widget at \a id at position \a pos. | 877 | Places the left/top edge of the widget at \a id at position \a pos. |
863 | 878 | ||
864 | \sa idAfter() | 879 | \sa idAfter() |
865 | */ | 880 | */ |
866 | void KDGanttMinimizeSplitter::moveAfter( int pos, int id, bool upLeft ) | 881 | void KDGanttMinimizeSplitter::moveAfter( int pos, int id, bool upLeft ) |
867 | { | 882 | { |
868 | QSplitterLayoutStruct *s = id < int(data->list.count()) ? | 883 | QSplitterLayoutStruct *s = id < int(data->list.count()) ? |
869 | data->list.at(id) : 0; | 884 | data->list.at(id) : 0; |
870 | if ( !s ) | 885 | if ( !s ) |
871 | return; | 886 | return; |
872 | QWidget *w = s->wid; | 887 | QWidget *w = s->wid; |
873 | if ( w->isHidden() ) { | 888 | if ( w->isHidden() ) { |
874 | moveAfter( pos, id+1, upLeft ); | 889 | moveAfter( pos, id+1, upLeft ); |
875 | } else if ( pick( w->pos() ) == pos ) { | 890 | } else if ( pick( w->pos() ) == pos ) { |
876 | //No need to do anything if it's already there. | 891 | //No need to do anything if it's already there. |
877 | return; | 892 | return; |
878 | } else if ( s->isSplitter ) { | 893 | } else if ( s->isSplitter ) { |
879 | int dd = s->sizer; | 894 | int dd = s->sizer; |
880 | int pos1, pos2; | 895 | int pos1, pos2; |
881 | if( false && orient == Horizontal ) { | 896 | if( false && orient == Horizontal ) { |
882 | pos2 = pos - dd; | 897 | pos2 = pos - dd; |
883 | pos1 = pos2 + 1; | 898 | pos1 = pos2 + 1; |
884 | } else { | 899 | } else { |
885 | pos1 = pos; | 900 | pos1 = pos; |
886 | pos2 = pos + dd; | 901 | pos2 = pos + dd; |
887 | } | 902 | } |
888 | if ( upLeft ) { | 903 | if ( upLeft ) { |
889 | setG( w, pos1, dd, TRUE ); | 904 | setG( w, pos1, dd, TRUE ); |
890 | moveAfter( pos2, id+1, upLeft ); | 905 | moveAfter( pos2, id+1, upLeft ); |
891 | } else { | 906 | } else { |
892 | moveAfter( pos2, id+1, upLeft ); | 907 | moveAfter( pos2, id+1, upLeft ); |
893 | setG( w, pos1, dd, TRUE ); | 908 | setG( w, pos1, dd, TRUE ); |
894 | } | 909 | } |
895 | } else { | 910 | } else { |
896 | int left = pick( w->pos() ); | 911 | int left = pick( w->pos() ); |
897 | int right, dd,/* newRight,*/ newLeft, nextPos; | 912 | int right, dd,/* newRight,*/ newLeft, nextPos; |
898 | if ( false && orient == Horizontal ) { | 913 | if ( false && orient == Horizontal ) { |
899 | dd = pos - left + 1; | 914 | dd = pos - left + 1; |
900 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); | 915 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); |
901 | newLeft = pos-dd+1; | 916 | newLeft = pos-dd+1; |
902 | nextPos = newLeft - 1; | 917 | nextPos = newLeft - 1; |
903 | } else { | 918 | } else { |
904 | right = pick( w->geometry().bottomRight() ); | 919 | right = pick( w->geometry().bottomRight() ); |
905 | dd = right - pos + 1; | 920 | dd = right - pos + 1; |
906 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); | 921 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); |
907 | /*newRight = pos+dd-1;*/ | 922 | /*newRight = pos+dd-1;*/ |
908 | newLeft = pos; | 923 | newLeft = pos; |
909 | nextPos = newLeft + dd; | 924 | nextPos = newLeft + dd; |
910 | } | 925 | } |
911 | setG( w, newLeft, dd, TRUE ); | 926 | setG( w, newLeft, dd, TRUE ); |
912 | /*if( right != newRight )*/ | 927 | /*if( right != newRight )*/ |
913 | moveAfter( nextPos, id+1, upLeft ); | 928 | moveAfter( nextPos, id+1, upLeft ); |
914 | } | 929 | } |
915 | } | 930 | } |
916 | 931 | ||
917 | 932 | ||
918 | void KDGanttMinimizeSplitter::expandPos( int id, int* min, int* max ) | 933 | void KDGanttMinimizeSplitter::expandPos( int id, int* min, int* max ) |
919 | { | 934 | { |
920 | QSplitterLayoutStruct *s = data->list.at(id-1); | 935 | QSplitterLayoutStruct *s = data->list.at(id-1); |
921 | QWidget* w = s->wid; | 936 | QWidget* w = s->wid; |
922 | *min = pick( w->mapToParent( QPoint(0,0) ) ); | 937 | *min = pick( w->mapToParent( QPoint(0,0) ) ); |
923 | 938 | ||
924 | if ( (uint) id == data->list.count() ) { | 939 | if ( (uint) id == data->list.count() ) { |
925 | pick( size() ); | 940 | pick( size() ); |
926 | } | 941 | } |
927 | else { | 942 | else { |
928 | QSplitterLayoutStruct *s = data->list.at(id+1); | 943 | QSplitterLayoutStruct *s = data->list.at(id+1); |
929 | QWidget* w = s->wid; | 944 | QWidget* w = s->wid; |
930 | *max = pick( w->mapToParent( QPoint( w->width(), w->height() ) ) ) -8; | 945 | *max = pick( w->mapToParent( QPoint( w->width(), w->height() ) ) ) -8; |
931 | } | 946 | } |
932 | } | 947 | } |
933 | 948 | ||
934 | 949 | ||
935 | /*! | 950 | /*! |
936 | Returns the valid range of the splitter with id \a id in \a *min and \a *max. | 951 | Returns the valid range of the splitter with id \a id in \a *min and \a *max. |
937 | 952 | ||
938 | \sa idAfter() | 953 | \sa idAfter() |
939 | */ | 954 | */ |
940 | 955 | ||
941 | void KDGanttMinimizeSplitter::getRange( int id, int *min, int *max ) | 956 | void KDGanttMinimizeSplitter::getRange( int id, int *min, int *max ) |
942 | { | 957 | { |
943 | int minB = 0;//before | 958 | int minB = 0;//before |
944 | int maxB = 0; | 959 | int maxB = 0; |
945 | int minA = 0; | 960 | int minA = 0; |
946 | int maxA = 0;//after | 961 | int maxA = 0;//after |
947 | int n = data->list.count(); | 962 | int n = data->list.count(); |
948 | if ( id < 0 || id >= n ) | 963 | if ( id < 0 || id >= n ) |
949 | return; | 964 | return; |
950 | int i; | 965 | int i; |
951 | for ( i = 0; i < id; i++ ) { | 966 | for ( i = 0; i < id; i++ ) { |
952 | QSplitterLayoutStruct *s = data->list.at(i); | 967 | QSplitterLayoutStruct *s = data->list.at(i); |
953 | if ( s->wid->isHidden() ) { | 968 | if ( s->wid->isHidden() ) { |
954 | //ignore | 969 | //ignore |
955 | } else if ( s->isSplitter ) { | 970 | } else if ( s->isSplitter ) { |
956 | minB += s->sizer; | 971 | minB += s->sizer; |
957 | maxB += s->sizer; | 972 | maxB += s->sizer; |
958 | } else { | 973 | } else { |
959 | minB += pick( minSize(s->wid) ); | 974 | minB += pick( minSize(s->wid) ); |
960 | maxB += pick( s->wid->maximumSize() ); | 975 | maxB += pick( s->wid->maximumSize() ); |
961 | } | 976 | } |
962 | } | 977 | } |
963 | for ( i = id; i < n; i++ ) { | 978 | for ( i = id; i < n; i++ ) { |
964 | QSplitterLayoutStruct *s = data->list.at(i); | 979 | QSplitterLayoutStruct *s = data->list.at(i); |
965 | if ( s->wid->isHidden() ) { | 980 | if ( s->wid->isHidden() ) { |
966 | //ignore | 981 | //ignore |
967 | } else if ( s->isSplitter ) { | 982 | } else if ( s->isSplitter ) { |
968 | minA += s->sizer; | 983 | minA += s->sizer; |
969 | maxA += s->sizer; | 984 | maxA += s->sizer; |
970 | } else { | 985 | } else { |
971 | minA += pick( minSize(s->wid) ); | 986 | minA += pick( minSize(s->wid) ); |
972 | maxA += pick( s->wid->maximumSize() ); | 987 | maxA += pick( s->wid->maximumSize() ); |
973 | } | 988 | } |
974 | } | 989 | } |
975 | QRect r = contentsRect(); | 990 | QRect r = contentsRect(); |
976 | if ( orient == Horizontal && false ) { | 991 | if ( orient == Horizontal && false ) { |
977 | #if QT_VERSION >= 0x030000 | 992 | #if QT_VERSION >= 0x030000 |
978 | int splitterWidth = style().pixelMetric(QStyle::PM_SplitterWidth, this); | 993 | int splitterWidth = style().pixelMetric(QStyle::PM_SplitterWidth, this); |
979 | #else | 994 | #else |
980 | int splitterWidth = style().splitterWidth(); | 995 | int splitterWidth = style().splitterWidth(); |
981 | #endif | 996 | #endif |
982 | 997 | ||
983 | if ( min ) | 998 | if ( min ) |
984 | *min = pick(r.topRight()) - QMIN( maxB, pick(r.size())-minA ) - splitterWidth; | 999 | *min = pick(r.topRight()) - QMIN( maxB, pick(r.size())-minA ) - splitterWidth; |
985 | if ( max ) | 1000 | if ( max ) |
986 | *max = pick(r.topRight()) - QMAX( minB, pick(r.size())-maxA ) - splitterWidth; | 1001 | *max = pick(r.topRight()) - QMAX( minB, pick(r.size())-maxA ) - splitterWidth; |
987 | } else { | 1002 | } else { |
988 | if ( min ) | 1003 | if ( min ) |
989 | *min = pick(r.topLeft()) + QMAX( minB, pick(r.size())-maxA ); | 1004 | *min = pick(r.topLeft()) + QMAX( minB, pick(r.size())-maxA ); |
990 | if ( max ) | 1005 | if ( max ) |
991 | *max = pick(r.topLeft()) + QMIN( maxB, pick(r.size())-minA ); | 1006 | *max = pick(r.topLeft()) + QMIN( maxB, pick(r.size())-minA ); |
992 | } | 1007 | } |
993 | } | 1008 | } |
994 | 1009 | ||
995 | 1010 | ||
996 | /*! | 1011 | /*! |
997 | Returns the closest legal position to \a p of the splitter with id \a id. | 1012 | Returns the closest legal position to \a p of the splitter with id \a id. |
998 | 1013 | ||
999 | \sa idAfter() | 1014 | \sa idAfter() |
1000 | */ | 1015 | */ |
1001 | 1016 | ||
1002 | int KDGanttMinimizeSplitter::adjustPos( int p, int id ) | 1017 | int KDGanttMinimizeSplitter::adjustPos( int p, int id ) |
1003 | { | 1018 | { |
1004 | int min = 0; | 1019 | int min = 0; |
1005 | int max = 0; | 1020 | int max = 0; |
1006 | getRange( id, &min, &max ); | 1021 | getRange( id, &min, &max ); |
1007 | p = QMAX( min, QMIN( p, max ) ); | 1022 | p = QMAX( min, QMIN( p, max ) ); |
1008 | 1023 | ||
1009 | return p; | 1024 | return p; |
1010 | } | 1025 | } |
1011 | 1026 | ||
1012 | 1027 | ||
1013 | void KDGanttMinimizeSplitter::doResize() | 1028 | void KDGanttMinimizeSplitter::doResize() |
1014 | { | 1029 | { |
1015 | QRect r = contentsRect(); | 1030 | QRect r = contentsRect(); |
1016 | int i; | 1031 | int i; |
1017 | int n = data->list.count(); | 1032 | int n = data->list.count(); |
1018 | QMemArray<QLayoutStruct> a( n ); | 1033 | QMemArray<QLayoutStruct> a( n ); |
1019 | for ( i = 0; i< n; i++ ) { | 1034 | for ( i = 0; i< n; i++ ) { |
1020 | a[i].init(); | 1035 | a[i].init(); |
1021 | QSplitterLayoutStruct *s = data->list.at(i); | 1036 | QSplitterLayoutStruct *s = data->list.at(i); |
1022 | if ( s->wid->isHidden() ) { | 1037 | if ( s->wid->isHidden() ) { |
1023 | a[i].stretch = 0; | 1038 | a[i].stretch = 0; |
1024 | a[i].sizeHint = a[i].minimumSize = 0; | 1039 | a[i].sizeHint = a[i].minimumSize = 0; |
1025 | a[i].maximumSize = 0; | 1040 | a[i].maximumSize = 0; |
1026 | } else if ( s->isSplitter ) { | 1041 | } else if ( s->isSplitter ) { |
1027 | a[i].stretch = 0; | 1042 | a[i].stretch = 0; |
1028 | a[i].sizeHint = a[i].minimumSize = a[i].maximumSize = s->sizer; | 1043 | a[i].sizeHint = a[i].minimumSize = a[i].maximumSize = s->sizer; |
1029 | a[i].empty = FALSE; | 1044 | a[i].empty = FALSE; |
1030 | } else if ( s->mode == KeepSize ) { | 1045 | } else if ( s->mode == KeepSize ) { |
1031 | a[i].stretch = 0; | 1046 | a[i].stretch = 0; |
1032 | a[i].minimumSize = pick( minSize(s->wid) ); | 1047 | a[i].minimumSize = pick( minSize(s->wid) ); |
1033 | a[i].sizeHint = s->sizer; | 1048 | a[i].sizeHint = s->sizer; |
1034 | a[i].maximumSize = pick( s->wid->maximumSize() ); | 1049 | a[i].maximumSize = pick( s->wid->maximumSize() ); |
1035 | a[i].empty = FALSE; | 1050 | a[i].empty = FALSE; |
1036 | } else if ( s->mode == FollowSizeHint ) { | 1051 | } else if ( s->mode == FollowSizeHint ) { |
1037 | a[i].stretch = 0; | 1052 | a[i].stretch = 0; |
1038 | a[i].minimumSize = a[i].sizeHint = pick( s->wid->sizeHint() ); | 1053 | a[i].minimumSize = a[i].sizeHint = pick( s->wid->sizeHint() ); |
1039 | a[i].maximumSize = pick( s->wid->maximumSize() ); | 1054 | a[i].maximumSize = pick( s->wid->maximumSize() ); |
1040 | a[i].empty = FALSE; | 1055 | a[i].empty = FALSE; |
1041 | } else { //proportional | 1056 | } else { //proportional |
1042 | a[i].stretch = s->sizer; | 1057 | a[i].stretch = s->sizer; |
1043 | a[i].maximumSize = pick( s->wid->maximumSize() ); | 1058 | a[i].maximumSize = pick( s->wid->maximumSize() ); |
1044 | a[i].sizeHint = a[i].minimumSize = pick( minSize(s->wid) ); | 1059 | a[i].sizeHint = a[i].minimumSize = pick( minSize(s->wid) ); |
1045 | a[i].empty = FALSE; | 1060 | a[i].empty = FALSE; |
1046 | } | 1061 | } |
1047 | } | 1062 | } |
1048 | 1063 | ||
1049 | kdganttGeomCalc( a, 0, n, pick( r.topLeft() ), pick( r.size() ), 0 ); | 1064 | kdganttGeomCalc( a, 0, n, pick( r.topLeft() ), pick( r.size() ), 0 ); |
1050 | 1065 | ||
1051 | for ( i = 0; i< n; i++ ) { | 1066 | for ( i = 0; i< n; i++ ) { |
1052 | QSplitterLayoutStruct *s = data->list.at(i); | 1067 | QSplitterLayoutStruct *s = data->list.at(i); |
1053 | setG( s->wid, a[i].pos, a[i].size ); | 1068 | setG( s->wid, a[i].pos, a[i].size ); |
1054 | } | 1069 | } |
1055 | 1070 | ||
1056 | } | 1071 | } |
1057 | 1072 | ||
1058 | 1073 | ||
1059 | void KDGanttMinimizeSplitter::recalc( bool update ) | 1074 | void KDGanttMinimizeSplitter::recalc( bool update ) |
1060 | { | 1075 | { |
1061 | int fi = 2*frameWidth(); | 1076 | int fi = 2*frameWidth(); |
1062 | int maxl = fi; | 1077 | int maxl = fi; |
1063 | int minl = fi; | 1078 | int minl = fi; |
1064 | int maxt = QWIDGETSIZE_MAX; | 1079 | int maxt = QWIDGETSIZE_MAX; |
1065 | int mint = fi; | 1080 | int mint = fi; |
1066 | int n = data->list.count(); | 1081 | int n = data->list.count(); |
1067 | bool first = TRUE; | 1082 | bool first = TRUE; |
1068 | /* | 1083 | /* |
1069 | The splitter before a hidden widget is always hidden. | 1084 | The splitter before a hidden widget is always hidden. |
1070 | The splitter before the first visible widget is hidden. | 1085 | The splitter before the first visible widget is hidden. |
1071 | The splitter before any other visible widget is visible. | 1086 | The splitter before any other visible widget is visible. |
1072 | */ | 1087 | */ |
1073 | for ( int i = 0; i< n; i++ ) { | 1088 | for ( int i = 0; i< n; i++ ) { |
1074 | QSplitterLayoutStruct *s = data->list.at(i); | 1089 | QSplitterLayoutStruct *s = data->list.at(i); |
1075 | if ( !s->isSplitter ) { | 1090 | if ( !s->isSplitter ) { |
1076 | QSplitterLayoutStruct *p = (i > 0) ? p = data->list.at( i-1 ) : 0; | 1091 | QSplitterLayoutStruct *p = (i > 0) ? p = data->list.at( i-1 ) : 0; |
1077 | if ( p && p->isSplitter ) | 1092 | if ( p && p->isSplitter ) |
1078 | if ( first || s->wid->isHidden() ) | 1093 | if ( first || s->wid->isHidden() ) |
1079 | p->wid->hide(); //may trigger new recalc | 1094 | p->wid->hide(); //may trigger new recalc |
1080 | else | 1095 | else |
1081 | p->wid->show(); //may trigger new recalc | 1096 | p->wid->show(); //may trigger new recalc |
1082 | if ( !s->wid->isHidden() ) | 1097 | if ( !s->wid->isHidden() ) |
1083 | first = FALSE; | 1098 | first = FALSE; |
1084 | } | 1099 | } |
1085 | } | 1100 | } |
1086 | 1101 | ||
1087 | bool empty=TRUE; | 1102 | bool empty=TRUE; |
1088 | for ( int j = 0; j< n; j++ ) { | 1103 | for ( int j = 0; j< n; j++ ) { |
1089 | QSplitterLayoutStruct *s = data->list.at(j); | 1104 | QSplitterLayoutStruct *s = data->list.at(j); |
1090 | if ( !s->wid->isHidden() ) { | 1105 | if ( !s->wid->isHidden() ) { |
1091 | empty = FALSE; | 1106 | empty = FALSE; |
1092 | if ( s->isSplitter ) { | 1107 | if ( s->isSplitter ) { |
1093 | minl += s->sizer; | 1108 | minl += s->sizer; |
1094 | maxl += s->sizer; | 1109 | maxl += s->sizer; |
1095 | } else { | 1110 | } else { |
1096 | QSize minS = minSize(s->wid); | 1111 | QSize minS = minSize(s->wid); |
1097 | minl += pick( minS ); | 1112 | minl += pick( minS ); |
1098 | maxl += pick( s->wid->maximumSize() ); | 1113 | maxl += pick( s->wid->maximumSize() ); |
1099 | mint = QMAX( mint, trans( minS )); | 1114 | mint = QMAX( mint, trans( minS )); |
1100 | int tm = trans( s->wid->maximumSize() ); | 1115 | int tm = trans( s->wid->maximumSize() ); |
1101 | if ( tm > 0 ) | 1116 | if ( tm > 0 ) |
1102 | maxt = QMIN( maxt, tm ); | 1117 | maxt = QMIN( maxt, tm ); |
1103 | } | 1118 | } |
1104 | } | 1119 | } |
1105 | } | 1120 | } |
1106 | if ( empty ) { | 1121 | if ( empty ) { |
1107 | if ( parentWidget() != 0 && parentWidget()->inherits("KDGanttMinimizeSplitter") ) { | 1122 | if ( parentWidget() != 0 && parentWidget()->inherits("KDGanttMinimizeSplitter") ) { |
1108 | // nested splitters; be nice | 1123 | // nested splitters; be nice |
1109 | maxl = maxt = 0; | 1124 | maxl = maxt = 0; |
1110 | } else { | 1125 | } else { |
1111 | // KDGanttMinimizeSplitter with no children yet | 1126 | // KDGanttMinimizeSplitter with no children yet |
1112 | maxl = QWIDGETSIZE_MAX; | 1127 | maxl = QWIDGETSIZE_MAX; |
1113 | } | 1128 | } |
1114 | } else { | 1129 | } else { |
1115 | maxl = QMIN( maxl, QWIDGETSIZE_MAX ); | 1130 | maxl = QMIN( maxl, QWIDGETSIZE_MAX ); |
1116 | } | 1131 | } |
1117 | if ( maxt < mint ) | 1132 | if ( maxt < mint ) |
1118 | maxt = mint; | 1133 | maxt = mint; |
1119 | 1134 | ||
1120 | if ( orient == Horizontal ) { | 1135 | if ( orient == Horizontal ) { |
1121 | setMaximumSize( maxl, maxt ); | 1136 | setMaximumSize( maxl, maxt ); |
1122 | setMinimumSize( minl, mint ); | 1137 | setMinimumSize( minl, mint ); |
1123 | } else { | 1138 | } else { |
1124 | setMaximumSize( maxt, maxl ); | 1139 | setMaximumSize( maxt, maxl ); |
1125 | setMinimumSize( mint, minl ); | 1140 | setMinimumSize( mint, minl ); |
1126 | } | 1141 | } |
1127 | if ( update ) | 1142 | if ( update ) |
1128 | doResize(); | 1143 | doResize(); |
1129 | } | 1144 | } |
1130 | 1145 | ||
1131 | /*! | 1146 | /*! |
1132 | Sets resize mode of \a w to \a mode. | 1147 | Sets resize mode of \a w to \a mode. |
1133 | 1148 | ||
1134 | \sa ResizeMode | 1149 | \sa ResizeMode |
1135 | */ | 1150 | */ |
1136 | 1151 | ||
1137 | void KDGanttMinimizeSplitter::setResizeMode( QWidget *w, ResizeMode mode ) | 1152 | void KDGanttMinimizeSplitter::setResizeMode( QWidget *w, ResizeMode mode ) |
1138 | { | 1153 | { |
1139 | processChildEvents(); | 1154 | processChildEvents(); |
1140 | QSplitterLayoutStruct *s = data->list.first(); | 1155 | QSplitterLayoutStruct *s = data->list.first(); |
1141 | while ( s ) { | 1156 | while ( s ) { |
1142 | if ( s->wid == w ) { | 1157 | if ( s->wid == w ) { |
1143 | s->mode = mode; | 1158 | s->mode = mode; |
1144 | return; | 1159 | return; |
1145 | } | 1160 | } |
1146 | s = data->list.next(); | 1161 | s = data->list.next(); |
1147 | } | 1162 | } |
1148 | s = addWidget( w, TRUE ); | 1163 | s = addWidget( w, TRUE ); |
1149 | s->mode = mode; | 1164 | s->mode = mode; |
1150 | } | 1165 | } |
1151 | 1166 | ||
1152 | 1167 | ||
1153 | /*! | 1168 | /*! |
1154 | Returns TRUE if opaque resize is on; otherwise returns FALSE. | 1169 | Returns TRUE if opaque resize is on; otherwise returns FALSE. |
1155 | 1170 | ||
1156 | \sa setOpaqueResize() | 1171 | \sa setOpaqueResize() |
1157 | */ | 1172 | */ |
1158 | 1173 | ||
1159 | bool KDGanttMinimizeSplitter::opaqueResize() const | 1174 | bool KDGanttMinimizeSplitter::opaqueResize() const |
1160 | { | 1175 | { |
1161 | return data->opaque; | 1176 | return data->opaque; |
1162 | } | 1177 | } |
1163 | 1178 | ||
1164 | 1179 | ||
1165 | /*! | 1180 | /*! |
1166 | If \a on is TRUE then opaque resizing is turned on; otherwise | 1181 | If \a on is TRUE then opaque resizing is turned on; otherwise |
1167 | opaque resizing is turned off. | 1182 | opaque resizing is turned off. |
1168 | Opaque resizing is initially turned off. | 1183 | Opaque resizing is initially turned off. |
1169 | 1184 | ||
1170 | \sa opaqueResize() | 1185 | \sa opaqueResize() |
1171 | */ | 1186 | */ |
1172 | 1187 | ||
1173 | void KDGanttMinimizeSplitter::setOpaqueResize( bool on ) | 1188 | void KDGanttMinimizeSplitter::setOpaqueResize( bool on ) |
1174 | { | 1189 | { |
1175 | data->opaque = on; | 1190 | data->opaque = on; |
1176 | } | 1191 | } |
1177 | 1192 | ||
1178 | 1193 | ||
1179 | /*! | 1194 | /*! |
1180 | Moves widget \a w to the leftmost/top position. | 1195 | Moves widget \a w to the leftmost/top position. |
1181 | */ | 1196 | */ |
1182 | 1197 | ||
1183 | void KDGanttMinimizeSplitter::moveToFirst( QWidget *w ) | 1198 | void KDGanttMinimizeSplitter::moveToFirst( QWidget *w ) |
1184 | { | 1199 | { |
1185 | processChildEvents(); | 1200 | processChildEvents(); |
1186 | bool found = FALSE; | 1201 | bool found = FALSE; |
1187 | QSplitterLayoutStruct *s = data->list.first(); | 1202 | QSplitterLayoutStruct *s = data->list.first(); |
1188 | while ( s ) { | 1203 | while ( s ) { |
1189 | if ( s->wid == w ) { | 1204 | if ( s->wid == w ) { |
1190 | found = TRUE; | 1205 | found = TRUE; |
1191 | QSplitterLayoutStruct *p = data->list.prev(); | 1206 | QSplitterLayoutStruct *p = data->list.prev(); |
1192 | if ( p ) { // not already at first place | 1207 | if ( p ) { // not already at first place |
1193 | data->list.take(); //take p | 1208 | data->list.take(); //take p |
1194 | data->list.take(); // take s | 1209 | data->list.take(); // take s |
1195 | data->list.insert( 0, p ); | 1210 | data->list.insert( 0, p ); |
1196 | data->list.insert( 0, s ); | 1211 | data->list.insert( 0, s ); |
1197 | } | 1212 | } |
1198 | break; | 1213 | break; |
1199 | } | 1214 | } |
1200 | s = data->list.next(); | 1215 | s = data->list.next(); |
1201 | } | 1216 | } |
1202 | if ( !found ) | 1217 | if ( !found ) |
1203 | addWidget( w, TRUE ); | 1218 | addWidget( w, TRUE ); |
1204 | recalcId(); | 1219 | recalcId(); |
1205 | } | 1220 | } |
1206 | 1221 | ||
1207 | 1222 | ||
1208 | /*! | 1223 | /*! |
1209 | Moves widget \a w to the rightmost/bottom position. | 1224 | Moves widget \a w to the rightmost/bottom position. |
1210 | */ | 1225 | */ |
1211 | 1226 | ||
1212 | void KDGanttMinimizeSplitter::moveToLast( QWidget *w ) | 1227 | void KDGanttMinimizeSplitter::moveToLast( QWidget *w ) |
1213 | { | 1228 | { |
1214 | processChildEvents(); | 1229 | processChildEvents(); |
1215 | bool found = FALSE; | 1230 | bool found = FALSE; |
1216 | QSplitterLayoutStruct *s = data->list.first(); | 1231 | QSplitterLayoutStruct *s = data->list.first(); |
1217 | while ( s ) { | 1232 | while ( s ) { |
1218 | if ( s->wid == w ) { | 1233 | if ( s->wid == w ) { |
1219 | found = TRUE; | 1234 | found = TRUE; |
1220 | data->list.take(); // take s | 1235 | data->list.take(); // take s |
1221 | QSplitterLayoutStruct *p = data->list.current(); | 1236 | QSplitterLayoutStruct *p = data->list.current(); |
1222 | if ( p ) { // the splitter handle after s | 1237 | if ( p ) { // the splitter handle after s |
1223 | data->list.take(); //take p | 1238 | data->list.take(); //take p |
1224 | data->list.append( p ); | 1239 | data->list.append( p ); |
1225 | } | 1240 | } |
1226 | data->list.append( s ); | 1241 | data->list.append( s ); |
1227 | break; | 1242 | break; |
1228 | } | 1243 | } |
1229 | s = data->list.next(); | 1244 | s = data->list.next(); |
1230 | } | 1245 | } |
1231 | if ( !found ) | 1246 | if ( !found ) |
1232 | addWidget( w); | 1247 | addWidget( w); |
1233 | recalcId(); | 1248 | recalcId(); |
1234 | } | 1249 | } |
1235 | 1250 | ||
1236 | 1251 | ||
1237 | void KDGanttMinimizeSplitter::recalcId() | 1252 | void KDGanttMinimizeSplitter::recalcId() |
1238 | { | 1253 | { |
1239 | int n = data->list.count(); | 1254 | int n = data->list.count(); |
1240 | for ( int i = 0; i < n; i++ ) { | 1255 | for ( int i = 0; i < n; i++ ) { |
1241 | QSplitterLayoutStruct *s = data->list.at(i); | 1256 | QSplitterLayoutStruct *s = data->list.at(i); |
1242 | if ( s->isSplitter ) | 1257 | if ( s->isSplitter ) |
1243 | ((KDGanttSplitterHandle*)s->wid)->setId(i); | 1258 | ((KDGanttSplitterHandle*)s->wid)->setId(i); |
1244 | } | 1259 | } |
1245 | } | 1260 | } |
1246 | 1261 | ||
1247 | 1262 | ||
1248 | /*!\reimp | 1263 | /*!\reimp |
1249 | */ | 1264 | */ |
1250 | QSize KDGanttMinimizeSplitter::sizeHint() const | 1265 | QSize KDGanttMinimizeSplitter::sizeHint() const |
1251 | { | 1266 | { |
1252 | constPolish(); | 1267 | constPolish(); |
1253 | int l = 0; | 1268 | int l = 0; |
1254 | int t = 0; | 1269 | int t = 0; |
1255 | if ( children() ) { | 1270 | if ( children() ) { |
1256 | const QObjectList * c = children(); | 1271 | const QObjectList * c = children(); |
1257 | QObjectListIt it( *c ); | 1272 | QObjectListIt it( *c ); |
1258 | QObject * o; | 1273 | QObject * o; |
1259 | 1274 | ||
1260 | while( (o=it.current()) != 0 ) { | 1275 | while( (o=it.current()) != 0 ) { |
1261 | ++it; | 1276 | ++it; |
1262 | if ( o->isWidgetType() && | 1277 | if ( o->isWidgetType() && |
1263 | !((QWidget*)o)->isHidden() ) { | 1278 | !((QWidget*)o)->isHidden() ) { |
1264 | QSize s = ((QWidget*)o)->sizeHint(); | 1279 | QSize s = ((QWidget*)o)->sizeHint(); |
1265 | if ( s.isValid() ) { | 1280 | if ( s.isValid() ) { |
1266 | l += pick( s ); | 1281 | l += pick( s ); |
1267 | t = QMAX( t, trans( s ) ); | 1282 | t = QMAX( t, trans( s ) ); |
1268 | } | 1283 | } |
1269 | } | 1284 | } |
1270 | } | 1285 | } |
1271 | } | 1286 | } |
1272 | return orientation() == Horizontal ? QSize( l, t ) : QSize( t, l ); | 1287 | return orientation() == Horizontal ? QSize( l, t ) : QSize( t, l ); |
1273 | } | 1288 | } |
1274 | 1289 | ||
1275 | 1290 | ||
1276 | /*! | 1291 | /*! |
1277 | \reimp | 1292 | \reimp |
1278 | */ | 1293 | */ |
1279 | 1294 | ||
1280 | QSize KDGanttMinimizeSplitter::minimumSizeHint() const | 1295 | QSize KDGanttMinimizeSplitter::minimumSizeHint() const |
1281 | { | 1296 | { |
1282 | constPolish(); | 1297 | constPolish(); |
1283 | int l = 0; | 1298 | int l = 0; |
1284 | int t = 0; | 1299 | int t = 0; |
1285 | if ( children() ) { | 1300 | if ( children() ) { |
1286 | const QObjectList * c = children(); | 1301 | const QObjectList * c = children(); |
1287 | QObjectListIt it( *c ); | 1302 | QObjectListIt it( *c ); |
1288 | QObject * o; | 1303 | QObject * o; |
1289 | 1304 | ||
1290 | while( (o=it.current()) != 0 ) { | 1305 | while( (o=it.current()) != 0 ) { |
1291 | ++it; | 1306 | ++it; |
1292 | if ( o->isWidgetType() && | 1307 | if ( o->isWidgetType() && |
1293 | !((QWidget*)o)->isHidden() ) { | 1308 | !((QWidget*)o)->isHidden() ) { |
1294 | QSize s = minSizeHint((QWidget*)o); | 1309 | QSize s = minSizeHint((QWidget*)o); |
1295 | if ( s.isValid() ) { | 1310 | if ( s.isValid() ) { |
1296 | l += pick( s ); | 1311 | l += pick( s ); |
1297 | t = QMAX( t, trans( s ) ); | 1312 | t = QMAX( t, trans( s ) ); |
1298 | } | 1313 | } |
1299 | } | 1314 | } |
1300 | } | 1315 | } |
1301 | } | 1316 | } |
1302 | return orientation() == Horizontal ? QSize( l, t ) : QSize( t, l ); | 1317 | return orientation() == Horizontal ? QSize( l, t ) : QSize( t, l ); |
1303 | } | 1318 | } |
1304 | 1319 | ||
1305 | 1320 | ||
1306 | /* | 1321 | /* |
1307 | Calculates stretch parameters from current sizes | 1322 | Calculates stretch parameters from current sizes |
1308 | */ | 1323 | */ |
1309 | 1324 | ||
1310 | void KDGanttMinimizeSplitter::storeSizes() | 1325 | void KDGanttMinimizeSplitter::storeSizes() |
1311 | { | 1326 | { |
1312 | QSplitterLayoutStruct *s = data->list.first(); | 1327 | QSplitterLayoutStruct *s = data->list.first(); |
1313 | while ( s ) { | 1328 | while ( s ) { |
1314 | if ( !s->isSplitter ) | 1329 | if ( !s->isSplitter ) |
1315 | s->sizer = pick( s->wid->size() ); | 1330 | s->sizer = pick( s->wid->size() ); |
1316 | s = data->list.next(); | 1331 | s = data->list.next(); |
1317 | } | 1332 | } |
1318 | } | 1333 | } |
1319 | 1334 | ||
1320 | 1335 | ||
1321 | #if 0 // ### remove this code ASAP | 1336 | #if 0 // ### remove this code ASAP |
1322 | 1337 | ||
1323 | /*! | 1338 | /*! |
1324 | Hides \a w if \a hide is TRUE and updates the splitter. | 1339 | Hides \a w if \a hide is TRUE and updates the splitter. |
1325 | 1340 | ||
1326 | \warning Due to a limitation in the current implementation, | 1341 | \warning Due to a limitation in the current implementation, |
1327 | calling QWidget::hide() will not work. | 1342 | calling QWidget::hide() will not work. |
1328 | */ | 1343 | */ |
1329 | 1344 | ||
1330 | void KDGanttMinimizeSplitter::setHidden( QWidget *w, bool hide ) | 1345 | void KDGanttMinimizeSplitter::setHidden( QWidget *w, bool hide ) |
1331 | { | 1346 | { |
1332 | if ( w == w1 ) { | 1347 | if ( w == w1 ) { |
1333 | w1show = !hide; | 1348 | w1show = !hide; |
1334 | } else if ( w == w2 ) { | 1349 | } else if ( w == w2 ) { |
1335 | w2show = !hide; | 1350 | w2show = !hide; |
1336 | } else { | 1351 | } else { |
1337 | #ifdef QT_CHECK_RANGE | 1352 | #ifdef QT_CHECK_RANGE |
1338 | qWarning( "KDGanttMinimizeSplitter::setHidden(), unknown widget" ); | 1353 | qWarning( "KDGanttMinimizeSplitter::setHidden(), unknown widget" ); |
1339 | #endif | 1354 | #endif |
1340 | return; | 1355 | return; |
1341 | } | 1356 | } |
1342 | if ( hide ) | 1357 | if ( hide ) |
1343 | w->hide(); | 1358 | w->hide(); |
1344 | else | 1359 | else |
1345 | w->show(); | 1360 | w->show(); |
1346 | recalc( TRUE ); | 1361 | recalc( TRUE ); |
1347 | } | 1362 | } |
1348 | 1363 | ||
1349 | 1364 | ||
1350 | /*! | 1365 | /*! |
1351 | Returns the hidden status of \a w | 1366 | Returns the hidden status of \a w |
1352 | */ | 1367 | */ |
1353 | 1368 | ||
1354 | bool KDGanttMinimizeSplitter::isHidden( QWidget *w ) const | 1369 | bool KDGanttMinimizeSplitter::isHidden( QWidget *w ) const |
1355 | { | 1370 | { |
1356 | if ( w == w1 ) | 1371 | if ( w == w1 ) |
1357 | return !w1show; | 1372 | return !w1show; |
1358 | else if ( w == w2 ) | 1373 | else if ( w == w2 ) |
1359 | return !w2show; | 1374 | return !w2show; |
1360 | #ifdef QT_CHECK_RANGE | 1375 | #ifdef QT_CHECK_RANGE |
1361 | else | 1376 | else |
1362 | qWarning( "KDGanttMinimizeSplitter::isHidden(), unknown widget" ); | 1377 | qWarning( "KDGanttMinimizeSplitter::isHidden(), unknown widget" ); |
1363 | #endif | 1378 | #endif |
1364 | return FALSE; | 1379 | return FALSE; |
1365 | } | 1380 | } |
1366 | #endif | 1381 | #endif |
1367 | 1382 | ||
1368 | 1383 | ||
1369 | /*! | 1384 | /*! |
1370 | Returns a list of the size parameters of all the widgets in this | 1385 | Returns a list of the size parameters of all the widgets in this |
1371 | splitter. | 1386 | splitter. |
1372 | 1387 | ||
1373 | Giving the values to another splitter's setSizes() function will | 1388 | Giving the values to another splitter's setSizes() function will |
1374 | produce a splitter with the same layout as this one. | 1389 | produce a splitter with the same layout as this one. |
1375 | 1390 | ||
1376 | Note that if you want to iterate over the list, you should | 1391 | Note that if you want to iterate over the list, you should |
1377 | iterate over a copy, e.g. | 1392 | iterate over a copy, e.g. |
1378 | \code | 1393 | \code |
1379 | QValueList<int> list = mySplitter.sizes(); | 1394 | QValueList<int> list = mySplitter.sizes(); |
1380 | QValueList<int>::Iterator it = list.begin(); | 1395 | QValueList<int>::Iterator it = list.begin(); |
1381 | while( it != list.end() ) { | 1396 | while( it != list.end() ) { |
1382 | myProcessing( *it ); | 1397 | myProcessing( *it ); |
1383 | ++it; | 1398 | ++it; |
1384 | } | 1399 | } |
1385 | \endcode | 1400 | \endcode |
1386 | 1401 | ||
1387 | \sa setSizes() | 1402 | \sa setSizes() |
1388 | */ | 1403 | */ |
1389 | 1404 | ||
1390 | QValueList<int> KDGanttMinimizeSplitter::sizes() const | 1405 | QValueList<int> KDGanttMinimizeSplitter::sizes() const |
1391 | { | 1406 | { |
1392 | if ( !testWState(WState_Polished) ) { | 1407 | if ( !testWState(WState_Polished) ) { |
1393 | QWidget* that = (QWidget*) this; | 1408 | QWidget* that = (QWidget*) this; |
1394 | that->polish(); | 1409 | that->polish(); |
1395 | } | 1410 | } |
1396 | QValueList<int> list; | 1411 | QValueList<int> list; |
1397 | QSplitterLayoutStruct *s = data->list.first(); | 1412 | QSplitterLayoutStruct *s = data->list.first(); |
1398 | while ( s ) { | 1413 | while ( s ) { |
1399 | if ( !s->isSplitter ) | 1414 | if ( !s->isSplitter ) |
1400 | list.append( s->sizer ); | 1415 | list.append( s->sizer ); |
1401 | s = data->list.next(); | 1416 | s = data->list.next(); |
1402 | } | 1417 | } |
1403 | return list; | 1418 | return list; |
1404 | } | 1419 | } |
1405 | 1420 | ||
1406 | 1421 | ||
1407 | 1422 | ||
1408 | /*! | 1423 | /*! |
1409 | Sets the size parameters to the values given in \a list. | 1424 | Sets the size parameters to the values given in \a list. |
1410 | If the splitter is horizontal, the values set the sizes from | 1425 | If the splitter is horizontal, the values set the sizes from |
1411 | left to right. If it is vertical, the sizes are applied from | 1426 | left to right. If it is vertical, the sizes are applied from |
1412 | top to bottom. | 1427 | top to bottom. |
1413 | Extra values in \a list are ignored. | 1428 | Extra values in \a list are ignored. |
1414 | 1429 | ||
1415 | If \a list contains too few values, the result is undefined | 1430 | If \a list contains too few values, the result is undefined |
1416 | but the program will still be well-behaved. | 1431 | but the program will still be well-behaved. |
1417 | 1432 | ||
1418 | \sa sizes() | 1433 | \sa sizes() |
1419 | */ | 1434 | */ |
1420 | 1435 | ||
1421 | void KDGanttMinimizeSplitter::setSizes( QValueList<int> list ) | 1436 | void KDGanttMinimizeSplitter::setSizes( QValueList<int> list ) |
1422 | { | 1437 | { |
1423 | processChildEvents(); | 1438 | processChildEvents(); |
1424 | QValueList<int>::Iterator it = list.begin(); | 1439 | QValueList<int>::Iterator it = list.begin(); |
1425 | QSplitterLayoutStruct *s = data->list.first(); | 1440 | QSplitterLayoutStruct *s = data->list.first(); |
1426 | while ( s && it != list.end() ) { | 1441 | while ( s && it != list.end() ) { |
1427 | if ( !s->isSplitter ) { | 1442 | if ( !s->isSplitter ) { |
1428 | s->sizer = *it; | 1443 | s->sizer = *it; |
1429 | ++it; | 1444 | ++it; |
1430 | } | 1445 | } |
1431 | s = data->list.next(); | 1446 | s = data->list.next(); |
1432 | } | 1447 | } |
1433 | doResize(); | 1448 | doResize(); |
1434 | } | 1449 | } |
1435 | 1450 | ||
1436 | 1451 | ||
1437 | /*! | 1452 | /*! |
1438 | Gets all posted child events, ensuring that the internal state of | 1453 | Gets all posted child events, ensuring that the internal state of |
1439 | the splitter is consistent. | 1454 | the splitter is consistent. |
1440 | */ | 1455 | */ |
1441 | 1456 | ||
1442 | void KDGanttMinimizeSplitter::processChildEvents() | 1457 | void KDGanttMinimizeSplitter::processChildEvents() |
1443 | { | 1458 | { |
1444 | QApplication::sendPostedEvents( this, QEvent::ChildInserted ); | 1459 | QApplication::sendPostedEvents( this, QEvent::ChildInserted ); |
1445 | } | 1460 | } |
1446 | 1461 | ||
1447 | 1462 | ||
1448 | /*! | 1463 | /*! |
1449 | \reimp | 1464 | \reimp |
1450 | */ | 1465 | */ |
1451 | 1466 | ||
1452 | void KDGanttMinimizeSplitter::styleChange( QStyle& old ) | 1467 | void KDGanttMinimizeSplitter::styleChange( QStyle& old ) |
1453 | { | 1468 | { |
1454 | 1469 | ||
1455 | #if QT_VERSION >= 0x030000 | 1470 | #if QT_VERSION >= 0x030000 |
1456 | int sw = style().pixelMetric(QStyle::PM_SplitterWidth, this); | 1471 | int sw = style().pixelMetric(QStyle::PM_SplitterWidth, this); |
1457 | #else | 1472 | #else |
1458 | int sw = style().splitterWidth(); | 1473 | int sw = style().splitterWidth(); |
1459 | #endif | 1474 | #endif |
1460 | QSplitterLayoutStruct *s = data->list.first(); | 1475 | QSplitterLayoutStruct *s = data->list.first(); |
1461 | while ( s ) { | 1476 | while ( s ) { |
1462 | if ( s->isSplitter ) | 1477 | if ( s->isSplitter ) |
1463 | s->sizer = sw; | 1478 | s->sizer = sw; |
1464 | s = data->list.next(); | 1479 | s = data->list.next(); |
1465 | } | 1480 | } |
1466 | doResize(); | 1481 | doResize(); |
1467 | QFrame::styleChange( old ); | 1482 | QFrame::styleChange( old ); |
1468 | } | 1483 | } |
1469 | 1484 | ||
1470 | #endif | 1485 | #endif |
1471 | 1486 | ||
1472 | /*! | 1487 | /*! |
1473 | Specifies the direction of the minimize buttons. | 1488 | Specifies the direction of the minimize buttons. |
1474 | If the orientation of the splitter is horizontal then with | 1489 | If the orientation of the splitter is horizontal then with |
1475 | KDGanttMinimizeSplitter::Left or KDGanttMinimizeSplitter::Right should be used, | 1490 | KDGanttMinimizeSplitter::Left or KDGanttMinimizeSplitter::Right should be used, |
1476 | otherwise either KDGanttMinimizeSplitter::Up or KDGanttMinimizeSplitter::Down | 1491 | otherwise either KDGanttMinimizeSplitter::Up or KDGanttMinimizeSplitter::Down |
1477 | should be used. | 1492 | should be used. |
1478 | */ | 1493 | */ |
1479 | void KDGanttMinimizeSplitter::setMinimizeDirection( Direction direction ) | 1494 | void KDGanttMinimizeSplitter::setMinimizeDirection( Direction direction ) |
1480 | { | 1495 | { |
1481 | _direction = direction; | 1496 | _direction = direction; |
1482 | } | 1497 | } |
1483 | 1498 | ||
1484 | /*! | 1499 | /*! |
1485 | Returns the direction of the minimize buttons. | 1500 | Returns the direction of the minimize buttons. |
1486 | */ | 1501 | */ |
1487 | KDGanttMinimizeSplitter::Direction KDGanttMinimizeSplitter::minimizeDirection() const | 1502 | KDGanttMinimizeSplitter::Direction KDGanttMinimizeSplitter::minimizeDirection() const |
1488 | { | 1503 | { |
1489 | return _direction; | 1504 | return _direction; |
1490 | } | 1505 | } |
1491 | 1506 | ||
1492 | /* | 1507 | /* |
1493 | This is a copy of qGeomCalc() in qlayoutengine.cpp which | 1508 | This is a copy of qGeomCalc() in qlayoutengine.cpp which |
1494 | unfortunately isn't exported. | 1509 | unfortunately isn't exported. |
1495 | */ | 1510 | */ |
1496 | static inline int toFixed( int i ) { return i * 256; } | 1511 | static inline int toFixed( int i ) { return i * 256; } |
1497 | static inline int fRound( int i ) { | 1512 | static inline int fRound( int i ) { |
1498 | return ( i % 256 < 128 ) ? i / 256 : 1 + i / 256; | 1513 | return ( i % 256 < 128 ) ? i / 256 : 1 + i / 256; |
1499 | } | 1514 | } |
1500 | void kdganttGeomCalc( QMemArray<QLayoutStruct> &chain, int start, int count, int pos, | 1515 | void kdganttGeomCalc( QMemArray<QLayoutStruct> &chain, int start, int count, int pos, |
1501 | int space, int spacer ) | 1516 | int space, int spacer ) |
1502 | { | 1517 | { |
1503 | typedef int fixed; | 1518 | typedef int fixed; |
1504 | int cHint = 0; | 1519 | int cHint = 0; |
1505 | int cMin = 0; | 1520 | int cMin = 0; |
1506 | int cMax = 0; | 1521 | int cMax = 0; |
1507 | int sumStretch = 0; | 1522 | int sumStretch = 0; |
1508 | int spacerCount = 0; | 1523 | int spacerCount = 0; |
1509 | 1524 | ||
1510 | bool wannaGrow = FALSE; // anyone who really wants to grow? | 1525 | bool wannaGrow = FALSE; // anyone who really wants to grow? |
1511 | // bool canShrink = FALSE; // anyone who could be persuaded to shrink? | 1526 | // bool canShrink = FALSE; // anyone who could be persuaded to shrink? |
1512 | 1527 | ||
1513 | int i; | 1528 | int i; |
1514 | for ( i = start; i < start + count; i++ ) { | 1529 | for ( i = start; i < start + count; i++ ) { |
1515 | chain[i].done = FALSE; | 1530 | chain[i].done = FALSE; |
1516 | cHint += chain[i].sizeHint; | 1531 | cHint += chain[i].sizeHint; |
1517 | cMin += chain[i].minimumSize; | 1532 | cMin += chain[i].minimumSize; |
1518 | cMax += chain[i].maximumSize; | 1533 | cMax += chain[i].maximumSize; |
1519 | sumStretch += chain[i].stretch; | 1534 | sumStretch += chain[i].stretch; |
1520 | if ( !chain[i].empty ) | 1535 | if ( !chain[i].empty ) |
1521 | spacerCount++; | 1536 | spacerCount++; |
1522 | wannaGrow = wannaGrow || chain[i].expansive; | 1537 | wannaGrow = wannaGrow || chain[i].expansive; |
1523 | } | 1538 | } |
1524 | 1539 | ||
1525 | int extraspace = 0; | 1540 | int extraspace = 0; |
1526 | if ( spacerCount ) | 1541 | if ( spacerCount ) |
1527 | spacerCount--; // only spacers between things | 1542 | spacerCount--; // only spacers between things |
1528 | if ( space < cMin + spacerCount * spacer ) { | 1543 | if ( space < cMin + spacerCount * spacer ) { |
1529 | //qDebug("not enough space"); | 1544 | //qDebug("not enough space"); |
1530 | for ( i = start; i < start+count; i++ ) { | 1545 | for ( i = start; i < start+count; i++ ) { |
1531 | chain[i].size = chain[i].minimumSize; | 1546 | chain[i].size = chain[i].minimumSize; |
1532 | chain[i].done = TRUE; | 1547 | chain[i].done = TRUE; |
1533 | } | 1548 | } |
1534 | } else if ( space < cHint + spacerCount*spacer ) { | 1549 | } else if ( space < cHint + spacerCount*spacer ) { |
1535 | // Less space than sizeHint, but more than minimum. | 1550 | // Less space than sizeHint, but more than minimum. |
1536 | // Currently take space equally from each, like in Qt 2.x. | 1551 | // Currently take space equally from each, like in Qt 2.x. |
1537 | // Commented-out lines will give more space to stretchier items. | 1552 | // Commented-out lines will give more space to stretchier items. |
1538 | int n = count; | 1553 | int n = count; |
1539 | int space_left = space - spacerCount*spacer; | 1554 | int space_left = space - spacerCount*spacer; |
1540 | int overdraft = cHint - space_left; | 1555 | int overdraft = cHint - space_left; |
1541 | //first give to the fixed ones: | 1556 | //first give to the fixed ones: |
1542 | for ( i = start; i < start+count; i++ ) { | 1557 | for ( i = start; i < start+count; i++ ) { |
1543 | if ( !chain[i].done && chain[i].minimumSize >= chain[i].sizeHint) { | 1558 | if ( !chain[i].done && chain[i].minimumSize >= chain[i].sizeHint) { |
1544 | chain[i].size = chain[i].sizeHint; | 1559 | chain[i].size = chain[i].sizeHint; |
1545 | chain[i].done = TRUE; | 1560 | chain[i].done = TRUE; |
1546 | space_left -= chain[i].sizeHint; | 1561 | space_left -= chain[i].sizeHint; |
1547 | // sumStretch -= chain[i].stretch; | 1562 | // sumStretch -= chain[i].stretch; |
1548 | n--; | 1563 | n--; |
1549 | } | 1564 | } |
1550 | } | 1565 | } |
1551 | bool finished = n == 0; | 1566 | bool finished = n == 0; |
1552 | while ( !finished ) { | 1567 | while ( !finished ) { |
1553 | finished = TRUE; | 1568 | finished = TRUE; |
1554 | fixed fp_over = toFixed( overdraft ); | 1569 | fixed fp_over = toFixed( overdraft ); |
1555 | fixed fp_w = 0; | 1570 | fixed fp_w = 0; |
1556 | 1571 | ||
1557 | for ( i = start; i < start+count; i++ ) { | 1572 | for ( i = start; i < start+count; i++ ) { |
1558 | if ( chain[i].done ) | 1573 | if ( chain[i].done ) |
1559 | continue; | 1574 | continue; |
1560 | // if ( sumStretch <= 0 ) | 1575 | // if ( sumStretch <= 0 ) |
1561 | fp_w += fp_over / n; | 1576 | fp_w += fp_over / n; |
1562 | // else | 1577 | // else |
1563 | // fp_w += (fp_over * chain[i].stretch) / sumStretch; | 1578 | // fp_w += (fp_over * chain[i].stretch) / sumStretch; |
1564 | int w = fRound( fp_w ); | 1579 | int w = fRound( fp_w ); |
1565 | chain[i].size = chain[i].sizeHint - w; | 1580 | chain[i].size = chain[i].sizeHint - w; |
1566 | fp_w -= toFixed( w ); //give the difference to the next | 1581 | fp_w -= toFixed( w ); //give the difference to the next |
1567 | if ( chain[i].size < chain[i].minimumSize ) { | 1582 | if ( chain[i].size < chain[i].minimumSize ) { |
1568 | chain[i].done = TRUE; | 1583 | chain[i].done = TRUE; |
1569 | chain[i].size = chain[i].minimumSize; | 1584 | chain[i].size = chain[i].minimumSize; |
1570 | finished = FALSE; | 1585 | finished = FALSE; |
1571 | overdraft -= chain[i].sizeHint - chain[i].minimumSize; | 1586 | overdraft -= chain[i].sizeHint - chain[i].minimumSize; |
1572 | // sumStretch -= chain[i].stretch; | 1587 | // sumStretch -= chain[i].stretch; |
1573 | n--; | 1588 | n--; |
1574 | break; | 1589 | break; |
1575 | } | 1590 | } |
1576 | } | 1591 | } |
1577 | } | 1592 | } |
1578 | } else { //extra space | 1593 | } else { //extra space |
1579 | int n = count; | 1594 | int n = count; |
1580 | int space_left = space - spacerCount*spacer; | 1595 | int space_left = space - spacerCount*spacer; |
1581 | // first give to the fixed ones, and handle non-expansiveness | 1596 | // first give to the fixed ones, and handle non-expansiveness |
1582 | for ( i = start; i < start + count; i++ ) { | 1597 | for ( i = start; i < start + count; i++ ) { |
1583 | if ( !chain[i].done && (chain[i].maximumSize <= chain[i].sizeHint | 1598 | if ( !chain[i].done && (chain[i].maximumSize <= chain[i].sizeHint |
1584 | || wannaGrow && !chain[i].expansive) ) { | 1599 | || wannaGrow && !chain[i].expansive) ) { |
1585 | chain[i].size = chain[i].sizeHint; | 1600 | chain[i].size = chain[i].sizeHint; |
1586 | chain[i].done = TRUE; | 1601 | chain[i].done = TRUE; |
1587 | space_left -= chain[i].sizeHint; | 1602 | space_left -= chain[i].sizeHint; |
1588 | sumStretch -= chain[i].stretch; | 1603 | sumStretch -= chain[i].stretch; |
1589 | n--; | 1604 | n--; |
1590 | } | 1605 | } |
1591 | } | 1606 | } |
1592 | extraspace = space_left; | 1607 | extraspace = space_left; |
1593 | /* | 1608 | /* |
1594 | Do a trial distribution and calculate how much it is off. | 1609 | Do a trial distribution and calculate how much it is off. |
1595 | If there are more deficit pixels than surplus pixels, give | 1610 | If there are more deficit pixels than surplus pixels, give |
1596 | the minimum size items what they need, and repeat. | 1611 | the minimum size items what they need, and repeat. |
1597 | Otherwise give to the maximum size items, and repeat. | 1612 | Otherwise give to the maximum size items, and repeat. |
1598 | 1613 | ||
1599 | I have a wonderful mathematical proof for the correctness | 1614 | I have a wonderful mathematical proof for the correctness |
1600 | of this principle, but unfortunately this comment is too | 1615 | of this principle, but unfortunately this comment is too |
1601 | small to contain it. | 1616 | small to contain it. |
1602 | */ | 1617 | */ |
1603 | int surplus, deficit; | 1618 | int surplus, deficit; |
1604 | do { | 1619 | do { |
1605 | surplus = deficit = 0; | 1620 | surplus = deficit = 0; |
1606 | fixed fp_space = toFixed( space_left ); | 1621 | fixed fp_space = toFixed( space_left ); |
1607 | fixed fp_w = 0; | 1622 | fixed fp_w = 0; |
1608 | for ( i = start; i < start+count; i++ ) { | 1623 | for ( i = start; i < start+count; i++ ) { |
1609 | if ( chain[i].done ) | 1624 | if ( chain[i].done ) |
1610 | continue; | 1625 | continue; |
1611 | extraspace = 0; | 1626 | extraspace = 0; |
1612 | if ( sumStretch <= 0 ) | 1627 | if ( sumStretch <= 0 ) |
1613 | fp_w += fp_space / n; | 1628 | fp_w += fp_space / n; |
1614 | else | 1629 | else |
1615 | fp_w += (fp_space * chain[i].stretch) / sumStretch; | 1630 | fp_w += (fp_space * chain[i].stretch) / sumStretch; |
1616 | int w = fRound( fp_w ); | 1631 | int w = fRound( fp_w ); |
1617 | chain[i].size = w; | 1632 | chain[i].size = w; |
1618 | fp_w -= toFixed( w ); // give the difference to the next | 1633 | fp_w -= toFixed( w ); // give the difference to the next |
1619 | if ( w < chain[i].sizeHint ) { | 1634 | if ( w < chain[i].sizeHint ) { |
1620 | deficit += chain[i].sizeHint - w; | 1635 | deficit += chain[i].sizeHint - w; |
1621 | } else if ( w > chain[i].maximumSize ) { | 1636 | } else if ( w > chain[i].maximumSize ) { |
1622 | surplus += w - chain[i].maximumSize; | 1637 | surplus += w - chain[i].maximumSize; |
1623 | } | 1638 | } |
1624 | } | 1639 | } |
1625 | if ( deficit > 0 && surplus <= deficit ) { | 1640 | if ( deficit > 0 && surplus <= deficit ) { |
1626 | // give to the ones that have too little | 1641 | // give to the ones that have too little |
1627 | for ( i = start; i < start+count; i++ ) { | 1642 | for ( i = start; i < start+count; i++ ) { |
1628 | if ( !chain[i].done && | 1643 | if ( !chain[i].done && |
1629 | chain[i].size < chain[i].sizeHint ) { | 1644 | chain[i].size < chain[i].sizeHint ) { |
1630 | chain[i].size = chain[i].sizeHint; | 1645 | chain[i].size = chain[i].sizeHint; |
1631 | chain[i].done = TRUE; | 1646 | chain[i].done = TRUE; |
1632 | space_left -= chain[i].sizeHint; | 1647 | space_left -= chain[i].sizeHint; |
1633 | sumStretch -= chain[i].stretch; | 1648 | sumStretch -= chain[i].stretch; |
1634 | n--; | 1649 | n--; |
1635 | } | 1650 | } |
1636 | } | 1651 | } |
1637 | } | 1652 | } |
1638 | if ( surplus > 0 && surplus >= deficit ) { | 1653 | if ( surplus > 0 && surplus >= deficit ) { |
1639 | // take from the ones that have too much | 1654 | // take from the ones that have too much |
1640 | for ( i = start; i < start+count; i++ ) { | 1655 | for ( i = start; i < start+count; i++ ) { |
1641 | if ( !chain[i].done && | 1656 | if ( !chain[i].done && |
1642 | chain[i].size > chain[i].maximumSize ) { | 1657 | chain[i].size > chain[i].maximumSize ) { |
1643 | chain[i].size = chain[i].maximumSize; | 1658 | chain[i].size = chain[i].maximumSize; |
1644 | chain[i].done = TRUE; | 1659 | chain[i].done = TRUE; |
1645 | space_left -= chain[i].maximumSize; | 1660 | space_left -= chain[i].maximumSize; |
1646 | sumStretch -= chain[i].stretch; | 1661 | sumStretch -= chain[i].stretch; |
1647 | n--; | 1662 | n--; |
1648 | } | 1663 | } |
1649 | } | 1664 | } |
1650 | } | 1665 | } |
1651 | } while ( n > 0 && surplus != deficit ); | 1666 | } while ( n > 0 && surplus != deficit ); |
1652 | if ( n == 0 ) | 1667 | if ( n == 0 ) |
1653 | extraspace = space_left; | 1668 | extraspace = space_left; |
1654 | } | 1669 | } |
1655 | 1670 | ||
1656 | // as a last resort, we distribute the unwanted space equally | 1671 | // as a last resort, we distribute the unwanted space equally |
1657 | // among the spacers (counting the start and end of the chain). | 1672 | // among the spacers (counting the start and end of the chain). |
1658 | 1673 | ||
1659 | //### should do a sub-pixel allocation of extra space | 1674 | //### should do a sub-pixel allocation of extra space |
1660 | int extra = extraspace / ( spacerCount + 2 ); | 1675 | int extra = extraspace / ( spacerCount + 2 ); |
1661 | int p = pos + extra; | 1676 | int p = pos + extra; |
1662 | for ( i = start; i < start+count; i++ ) { | 1677 | for ( i = start; i < start+count; i++ ) { |
1663 | chain[i].pos = p; | 1678 | chain[i].pos = p; |
1664 | p = p + chain[i].size; | 1679 | p = p + chain[i].size; |
1665 | if ( !chain[i].empty ) | 1680 | if ( !chain[i].empty ) |
1666 | p += spacer+extra; | 1681 | p += spacer+extra; |
1667 | } | 1682 | } |
1668 | } | 1683 | } |
1669 | 1684 | ||
1670 | #endif | 1685 | #endif |
1671 | 1686 | ||
1672 | /*! | 1687 | /*! |
1673 | \enum KDGanttMinimizeSplitter::Direction | 1688 | \enum KDGanttMinimizeSplitter::Direction |
1674 | 1689 | ||
1675 | The values of this enumeration describe into which direction the | 1690 | The values of this enumeration describe into which direction the |
1676 | splitter will collapse its child widgets. By extension, it also | 1691 | splitter will collapse its child widgets. By extension, it also |
1677 | specifies the orientation of the splitter; collapsing to the left or | 1692 | specifies the orientation of the splitter; collapsing to the left or |
1678 | to the right results in a horizontal splitter, collapsing to the top | 1693 | to the right results in a horizontal splitter, collapsing to the top |
1679 | or bottom in a vertical splitter. | 1694 | or bottom in a vertical splitter. |
1680 | */ | 1695 | */ |
1681 | 1696 | ||
1682 | /*! | 1697 | /*! |
1683 | \fn Orientation KDGanttMinimizeSplitter::orientation() const | 1698 | \fn Orientation KDGanttMinimizeSplitter::orientation() const |
1684 | 1699 | ||
1685 | Returns the orientation of the splitter. | 1700 | Returns the orientation of the splitter. |
1686 | */ | 1701 | */ |
1687 | 1702 | ||
1688 | /*! \enum KDGanttMinimizeSplitter::ResizeMode | 1703 | /*! \enum KDGanttMinimizeSplitter::ResizeMode |
1689 | 1704 | ||
1690 | This enum type describes how KDGanttMinimizeSplitter will resize each of its child widgets. The currently defined values are: | 1705 | This enum type describes how KDGanttMinimizeSplitter will resize each of its child widgets. The currently defined values are: |
1691 | 1706 | ||
1692 | Stretch: the widget will be resized when the splitter | 1707 | Stretch: the widget will be resized when the splitter |
1693 | itself is resized. | 1708 | itself is resized. |
1694 | 1709 | ||
1695 | KeepSize: KDGanttMinimizeSplitter will try to keep this widget's size | 1710 | KeepSize: KDGanttMinimizeSplitter will try to keep this widget's size |
1696 | unchanged. | 1711 | unchanged. |
1697 | 1712 | ||
1698 | FollowSizeHint: KDGanttMinimizeSplitter will resize the widget when the | 1713 | FollowSizeHint: KDGanttMinimizeSplitter will resize the widget when the |
1699 | widget's size hint changes. | 1714 | widget's size hint changes. |
1700 | */ | 1715 | */ |
1701 | 1716 | ||
diff --git a/microkde/KDGanttMinimizeSplitter.h b/microkde/KDGanttMinimizeSplitter.h index 585298d..3042e0a 100644 --- a/microkde/KDGanttMinimizeSplitter.h +++ b/microkde/KDGanttMinimizeSplitter.h | |||
@@ -1,191 +1,192 @@ | |||
1 | /* -*- Mode: C++ -*- | 1 | /* -*- Mode: C++ -*- |
2 | $Id$ | 2 | $Id$ |
3 | */ | 3 | */ |
4 | 4 | ||
5 | /**************************************************************************** | 5 | /**************************************************************************** |
6 | ** Copyright (C) 2001-2004 Klarälvdalens Datakonsult AB. All rights reserved. | 6 | ** Copyright (C) 2001-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 | #ifndef KDGANTTMINIMIZESPLITTER_H | 34 | #ifndef KDGANTTMINIMIZESPLITTER_H |
35 | #define KDGANTTMINIMIZESPLITTER_H | 35 | #define KDGANTTMINIMIZESPLITTER_H |
36 | 36 | ||
37 | #ifndef QT_H | 37 | #ifndef QT_H |
38 | #include "qframe.h" | 38 | #include "qframe.h" |
39 | #include "qvaluelist.h" | 39 | #include "qvaluelist.h" |
40 | #endif // QT_H | 40 | #endif // QT_H |
41 | 41 | ||
42 | #ifndef QT_NO_SPLITTER___ | 42 | #ifndef QT_NO_SPLITTER___ |
43 | class QSplitterData; | 43 | class QSplitterData; |
44 | class QSplitterLayoutStruct; | 44 | class QSplitterLayoutStruct; |
45 | class KDGanttSplitterHandle; | 45 | class KDGanttSplitterHandle; |
46 | class KDRubberBand; | ||
46 | class KDGanttMinimizeSplitter : public QFrame | 47 | class KDGanttMinimizeSplitter : public QFrame |
47 | { | 48 | { |
48 | Q_OBJECT | 49 | Q_OBJECT |
49 | // Q_ENUMS( Direction ) | 50 | // Q_ENUMS( Direction ) |
50 | // Q_PROPERTY( Orientation orientation READ orientation WRITE setOrientation ) | 51 | // Q_PROPERTY( Orientation orientation READ orientation WRITE setOrientation ) |
51 | // Q_PROPERTY( Direction minimizeDirection READ minimizeDirection WRITE setMinimizeDirection ) | 52 | // Q_PROPERTY( Direction minimizeDirection READ minimizeDirection WRITE setMinimizeDirection ) |
52 | 53 | ||
53 | public: | 54 | public: |
54 | enum ResizeMode { Stretch, KeepSize, FollowSizeHint }; | 55 | enum ResizeMode { Stretch, KeepSize, FollowSizeHint }; |
55 | enum Direction { Left, Right, Up, Down }; | 56 | enum Direction { Left, Right, Up, Down }; |
56 | 57 | ||
57 | KDGanttMinimizeSplitter( QWidget* parent=0, const char* name=0 ); | 58 | KDGanttMinimizeSplitter( QWidget* parent=0, const char* name=0 ); |
58 | KDGanttMinimizeSplitter( Orientation, QWidget* parent=0, const char* name=0 ); | 59 | KDGanttMinimizeSplitter( Orientation, QWidget* parent=0, const char* name=0 ); |
59 | ~KDGanttMinimizeSplitter(); | 60 | ~KDGanttMinimizeSplitter(); |
60 | 61 | ||
61 | virtual void setOrientation( Orientation ); | 62 | virtual void setOrientation( Orientation ); |
62 | Orientation orientation() const { return orient; } | 63 | Orientation orientation() const { return orient; } |
63 | 64 | ||
64 | void setMinimizeDirection( Direction ); | 65 | void setMinimizeDirection( Direction ); |
65 | Direction minimizeDirection() const; | 66 | Direction minimizeDirection() const; |
66 | 67 | ||
67 | #if QT_VERSION >= 232 | 68 | #if QT_VERSION >= 232 |
68 | virtual void setResizeMode( QWidget *w, ResizeMode ); | 69 | virtual void setResizeMode( QWidget *w, ResizeMode ); |
69 | virtual void setOpaqueResize( bool = TRUE ); | 70 | virtual void setOpaqueResize( bool = TRUE ); |
70 | bool opaqueResize() const; | 71 | bool opaqueResize() const; |
71 | 72 | ||
72 | void moveToFirst( QWidget * ); | 73 | void moveToFirst( QWidget * ); |
73 | void moveToLast( QWidget * ); | 74 | void moveToLast( QWidget * ); |
74 | 75 | ||
75 | void refresh() { recalc( TRUE ); } | 76 | void refresh() { recalc( TRUE ); } |
76 | QSize sizeHint() const; | 77 | QSize sizeHint() const; |
77 | QSize minimumSizeHint() const; | 78 | QSize minimumSizeHint() const; |
78 | 79 | ||
79 | QValueList<int> sizes() const; | 80 | QValueList<int> sizes() const; |
80 | void setSizes( QValueList<int> ); | 81 | void setSizes( QValueList<int> ); |
81 | KDGanttSplitterHandle* firstHandle(){ return mFirstHandle;} | 82 | KDGanttSplitterHandle* firstHandle(){ return mFirstHandle;} |
82 | void expandPos( int id, int* min, int* max ); | 83 | void expandPos( int id, int* min, int* max ); |
83 | QFrame* rubberBand() { return mRubberBand ;} | 84 | KDRubberBand* rubberBand() { return mRubberBand ;} |
84 | public slots: | 85 | public slots: |
85 | void toggle(); | 86 | void toggle(); |
86 | protected: | 87 | protected: |
87 | void childEvent( QChildEvent * ); | 88 | void childEvent( QChildEvent * ); |
88 | 89 | ||
89 | bool event( QEvent * ); | 90 | bool event( QEvent * ); |
90 | void resizeEvent( QResizeEvent * ); | 91 | void resizeEvent( QResizeEvent * ); |
91 | 92 | ||
92 | int idAfter( QWidget* ) const; | 93 | int idAfter( QWidget* ) const; |
93 | 94 | ||
94 | void moveSplitter( QCOORD pos, int id ); | 95 | void moveSplitter( QCOORD pos, int id ); |
95 | virtual void drawSplitter( QPainter*, QCOORD x, QCOORD y, | 96 | virtual void drawSplitter( QPainter*, QCOORD x, QCOORD y, |
96 | QCOORD w, QCOORD h ); | 97 | QCOORD w, QCOORD h ); |
97 | void styleChange( QStyle& ); | 98 | void styleChange( QStyle& ); |
98 | int adjustPos( int , int ); | 99 | int adjustPos( int , int ); |
99 | virtual void setRubberband( int ); | 100 | virtual void setRubberband( int ); |
100 | void getRange( int id, int*, int* ); | 101 | void getRange( int id, int*, int* ); |
101 | 102 | ||
102 | private: | 103 | private: |
103 | QFrame* mRubberBand; | 104 | KDRubberBand* mRubberBand; |
104 | void init(); | 105 | void init(); |
105 | void recalc( bool update = FALSE ); | 106 | void recalc( bool update = FALSE ); |
106 | void doResize(); | 107 | void doResize(); |
107 | void storeSizes(); | 108 | void storeSizes(); |
108 | void processChildEvents(); | 109 | void processChildEvents(); |
109 | QSplitterLayoutStruct *addWidget( QWidget*, bool first = FALSE ); | 110 | QSplitterLayoutStruct *addWidget( QWidget*, bool first = FALSE ); |
110 | void recalcId(); | 111 | void recalcId(); |
111 | void moveBefore( int pos, int id, bool upLeft ); | 112 | void moveBefore( int pos, int id, bool upLeft ); |
112 | void moveAfter( int pos, int id, bool upLeft ); | 113 | void moveAfter( int pos, int id, bool upLeft ); |
113 | void setG( QWidget *w, int p, int s, bool isSplitter = FALSE ); | 114 | void setG( QWidget *w, int p, int s, bool isSplitter = FALSE ); |
114 | 115 | ||
115 | QCOORD pick( const QPoint &p ) const | 116 | QCOORD pick( const QPoint &p ) const |
116 | { return orient == Horizontal ? p.x() : p.y(); } | 117 | { return orient == Horizontal ? p.x() : p.y(); } |
117 | QCOORD pick( const QSize &s ) const | 118 | QCOORD pick( const QSize &s ) const |
118 | { return orient == Horizontal ? s.width() : s.height(); } | 119 | { return orient == Horizontal ? s.width() : s.height(); } |
119 | 120 | ||
120 | QCOORD trans( const QPoint &p ) const | 121 | QCOORD trans( const QPoint &p ) const |
121 | { return orient == Vertical ? p.x() : p.y(); } | 122 | { return orient == Vertical ? p.x() : p.y(); } |
122 | QCOORD trans( const QSize &s ) const | 123 | QCOORD trans( const QSize &s ) const |
123 | { return orient == Vertical ? s.width() : s.height(); } | 124 | { return orient == Vertical ? s.width() : s.height(); } |
124 | KDGanttSplitterHandle* mFirstHandle; | 125 | KDGanttSplitterHandle* mFirstHandle; |
125 | QSplitterData *data; | 126 | QSplitterData *data; |
126 | #endif | 127 | #endif |
127 | 128 | ||
128 | private: | 129 | private: |
129 | Orientation orient; | 130 | Orientation orient; |
130 | Direction _direction; | 131 | Direction _direction; |
131 | #ifndef DOXYGEN_SKIP_INTERNAL | 132 | #ifndef DOXYGEN_SKIP_INTERNAL |
132 | friend class KDGanttSplitterHandle; | 133 | friend class KDGanttSplitterHandle; |
133 | #endif | 134 | #endif |
134 | private:// Disabled copy constructor and operator= | 135 | private:// Disabled copy constructor and operator= |
135 | #if defined(Q_DISABLE_COPY) | 136 | #if defined(Q_DISABLE_COPY) |
136 | KDGanttMinimizeSplitter( const KDGanttMinimizeSplitter & ); | 137 | KDGanttMinimizeSplitter( const KDGanttMinimizeSplitter & ); |
137 | KDGanttMinimizeSplitter& operator=( const KDGanttMinimizeSplitter & ); | 138 | KDGanttMinimizeSplitter& operator=( const KDGanttMinimizeSplitter & ); |
138 | #endif | 139 | #endif |
139 | }; | 140 | }; |
140 | 141 | ||
141 | #ifndef DOXYGEN_SKIP_INTERNAL | 142 | #ifndef DOXYGEN_SKIP_INTERNAL |
142 | // This class was continued from a verbatim copy of the | 143 | // This class was continued from a verbatim copy of the |
143 | // QSplitterHandle pertaining to the Qt Enterprise License and the | 144 | // QSplitterHandle pertaining to the Qt Enterprise License and the |
144 | // GPL. It has only been renamed to KDGanttSplitterHandler in order to | 145 | // GPL. It has only been renamed to KDGanttSplitterHandler in order to |
145 | // avoid a symbol clash on some platforms. | 146 | // avoid a symbol clash on some platforms. |
146 | class KDGanttSplitterHandle : public QWidget | 147 | class KDGanttSplitterHandle : public QWidget |
147 | { | 148 | { |
148 | Q_OBJECT | 149 | Q_OBJECT |
149 | #if QT_VERSION >= 232 | 150 | #if QT_VERSION >= 232 |
150 | public: | 151 | public: |
151 | KDGanttSplitterHandle( Qt::Orientation o, | 152 | KDGanttSplitterHandle( Qt::Orientation o, |
152 | KDGanttMinimizeSplitter *parent, const char* name=0 ); | 153 | KDGanttMinimizeSplitter *parent, const char* name=0 ); |
153 | void setOrientation( Qt::Orientation o ); | 154 | void setOrientation( Qt::Orientation o ); |
154 | Qt::Orientation orientation() const { return orient; } | 155 | Qt::Orientation orientation() const { return orient; } |
155 | 156 | ||
156 | bool opaque() const { return s->opaqueResize(); } | 157 | bool opaque() const { return s->opaqueResize(); } |
157 | 158 | ||
158 | QSize sizeHint() const; | 159 | QSize sizeHint() const; |
159 | void toggle(); | 160 | void toggle(); |
160 | 161 | ||
161 | int id() const { return myId; } // data->list.at(id())->wid == this | 162 | int id() const { return myId; } // data->list.at(id())->wid == this |
162 | void setId( int i ) { myId = i; } | 163 | void setId( int i ) { myId = i; } |
163 | 164 | ||
164 | protected: | 165 | protected: |
165 | QValueList<QPointArray> buttonRegions(); | 166 | QValueList<QPointArray> buttonRegions(); |
166 | void paintEvent( QPaintEvent * ); | 167 | void paintEvent( QPaintEvent * ); |
167 | void mouseMoveEvent( QMouseEvent * ); | 168 | void mouseMoveEvent( QMouseEvent * ); |
168 | void mousePressEvent( QMouseEvent * ); | 169 | void mousePressEvent( QMouseEvent * ); |
169 | void mouseReleaseEvent( QMouseEvent * ); | 170 | void mouseReleaseEvent( QMouseEvent * ); |
170 | int onButton( const QPoint& p ); | 171 | int onButton( const QPoint& p ); |
171 | void updateCursor( const QPoint& p ); | 172 | void updateCursor( const QPoint& p ); |
172 | 173 | ||
173 | private: | 174 | private: |
174 | bool mMouseDown; | 175 | bool mMouseDown; |
175 | QSize mSizeHint; | 176 | QSize mSizeHint; |
176 | bool mUseOffset; | 177 | bool mUseOffset; |
177 | Qt::Orientation orient; | 178 | Qt::Orientation orient; |
178 | bool opaq; | 179 | bool opaq; |
179 | int myId; | 180 | int myId; |
180 | 181 | ||
181 | KDGanttMinimizeSplitter *s; | 182 | KDGanttMinimizeSplitter *s; |
182 | int _activeButton; | 183 | int _activeButton; |
183 | bool _collapsed; | 184 | bool _collapsed; |
184 | int _origPos; | 185 | int _origPos; |
185 | #endif | 186 | #endif |
186 | }; | 187 | }; |
187 | #endif | 188 | #endif |
188 | 189 | ||
189 | #endif // QT_NO_SPLITTER | 190 | #endif // QT_NO_SPLITTER |
190 | 191 | ||
191 | #endif // KDGANTTMINIMIZESPLITTER_H | 192 | #endif // KDGANTTMINIMIZESPLITTER_H |