author | zautrix <zautrix> | 2005-02-07 13:33:33 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-02-07 13:33:33 (UTC) |
commit | d3b63db1205720e0a78cdc1a3cd11b2d02c98c6a (patch) (unidiff) | |
tree | e6c9f78b146bd1a05509795c884f4a8d9be039d7 | |
parent | 7de846e9f01ce27b622541493e6a02e26e37bf2c (diff) | |
download | kdepimpi-d3b63db1205720e0a78cdc1a3cd11b2d02c98c6a.zip kdepimpi-d3b63db1205720e0a78cdc1a3cd11b2d02c98c6a.tar.gz kdepimpi-d3b63db1205720e0a78cdc1a3cd11b2d02c98c6a.tar.bz2 |
desktop compile fix
-rw-r--r-- | korganizer/komonthview.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp index 7ba0b2f..9b9e164 100644 --- a/korganizer/komonthview.cpp +++ b/korganizer/komonthview.cpp | |||
@@ -1,1597 +1,1598 @@ | |||
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 <qwhatsthis.h> | 31 | #include <qwhatsthis.h> |
31 | #ifndef DESKTOP_VERSION | 32 | #ifndef DESKTOP_VERSION |
32 | #include <qpe/qpeapplication.h> | 33 | #include <qpe/qpeapplication.h> |
33 | #else | 34 | #else |
34 | #include <qapplication.h> | 35 | #include <qapplication.h> |
35 | #endif | 36 | #endif |
36 | 37 | ||
37 | #include <kdebug.h> | 38 | #include <kdebug.h> |
38 | #include <klocale.h> | 39 | #include <klocale.h> |
39 | #include <kglobal.h> | 40 | #include <kglobal.h> |
40 | #include <kconfig.h> | 41 | #include <kconfig.h> |
41 | #include <kiconloader.h> | 42 | #include <kiconloader.h> |
42 | 43 | ||
43 | #include <kcalendarsystem.h> | 44 | #include <kcalendarsystem.h> |
44 | 45 | ||
45 | #ifndef KORG_NOPRINTER | 46 | #ifndef KORG_NOPRINTER |
46 | #include "calprinter.h" | 47 | #include "calprinter.h" |
47 | #endif | 48 | #endif |
48 | #include "koprefs.h" | 49 | #include "koprefs.h" |
49 | #ifndef KORG_NOPLUGINS | 50 | #ifndef KORG_NOPLUGINS |
50 | #include "kocore.h" | 51 | #include "kocore.h" |
51 | #endif | 52 | #endif |
52 | #include "koglobals.h" | 53 | #include "koglobals.h" |
53 | #include <libkcal/kincidenceformatter.h> | 54 | #include <libkcal/kincidenceformatter.h> |
54 | 55 | ||
55 | #include "komonthview.h" | 56 | #include "komonthview.h" |
56 | 57 | ||
57 | #define PIXMAP_SIZE 5 | 58 | #define PIXMAP_SIZE 5 |
58 | #ifdef DESKTOP_VERSION | 59 | #ifdef DESKTOP_VERSION |
59 | QToolTipGroup *MonthViewCell::mToolTipGroup = 0; | 60 | QToolTipGroup *MonthViewCell::mToolTipGroup = 0; |
60 | #endif | 61 | #endif |
61 | class KNOWhatsThis :public QWhatsThis | 62 | class KNOWhatsThis :public QWhatsThis |
62 | { | 63 | { |
63 | public: | 64 | public: |
64 | KNOWhatsThis( KNoScrollListBox* sbox ) : QWhatsThis( sbox ), _wid( sbox) { }; | 65 | KNOWhatsThis( KNoScrollListBox* sbox ) : QWhatsThis( sbox ), _wid( sbox) { }; |
65 | //~KNOWhatsThis( ) {qDebug("~KNOWhatsThis( ) "); }; | 66 | //~KNOWhatsThis( ) {qDebug("~KNOWhatsThis( ) "); }; |
66 | 67 | ||
67 | protected: | 68 | protected: |
68 | virtual QString text( const QPoint& p) | 69 | virtual QString text( const QPoint& p) |
69 | { | 70 | { |
70 | return _wid->getWhatsThisText(p) ; | 71 | return _wid->getWhatsThisText(p) ; |
71 | }; | 72 | }; |
72 | private: | 73 | private: |
73 | KNoScrollListBox* _wid; | 74 | KNoScrollListBox* _wid; |
74 | 75 | ||
75 | }; | 76 | }; |
76 | 77 | ||
77 | 78 | ||
78 | KNoScrollListBox::KNoScrollListBox(QWidget *parent,const char *name) | 79 | KNoScrollListBox::KNoScrollListBox(QWidget *parent,const char *name) |
79 | : QListBox(parent, name, WRepaintNoErase) | 80 | : QListBox(parent, name, WRepaintNoErase) |
80 | { | 81 | { |
81 | #ifndef DESKTOP_VERSION | 82 | #ifndef DESKTOP_VERSION |
82 | QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); | 83 | QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); |
83 | #endif | 84 | #endif |
84 | mWT = new KNOWhatsThis(this); | 85 | mWT = new KNOWhatsThis(this); |
85 | } | 86 | } |
86 | KNoScrollListBox::~KNoScrollListBox() | 87 | KNoScrollListBox::~KNoScrollListBox() |
87 | { | 88 | { |
88 | 89 | ||
89 | } | 90 | } |
90 | QString KNoScrollListBox::getWhatsThisText(QPoint p) | 91 | QString KNoScrollListBox::getWhatsThisText(QPoint p) |
91 | { | 92 | { |
92 | QListBoxItem* item = itemAt ( p ); | 93 | QListBoxItem* item = itemAt ( p ); |
93 | if ( ! item ) { | 94 | if ( ! item ) { |
94 | return i18n("Click in the cell\nto add an event!"); | 95 | return i18n("Click in the cell\nto add an event!"); |
95 | } | 96 | } |
96 | return KIncidenceFormatter::instance()->getFormattedText(((MonthViewItem*) item)->incidence()); | 97 | return KIncidenceFormatter::instance()->getFormattedText(((MonthViewItem*) item)->incidence()); |
97 | } | 98 | } |
98 | void KNoScrollListBox::keyPressEvent(QKeyEvent *e) | 99 | void KNoScrollListBox::keyPressEvent(QKeyEvent *e) |
99 | { | 100 | { |
100 | 101 | ||
101 | switch(e->key()) { | 102 | switch(e->key()) { |
102 | case Key_Right: | 103 | case Key_Right: |
103 | if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) | 104 | if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) |
104 | { | 105 | { |
105 | e->ignore(); | 106 | e->ignore(); |
106 | return; | 107 | return; |
107 | } | 108 | } |
108 | scrollBy(10,0); | 109 | scrollBy(10,0); |
109 | break; | 110 | break; |
110 | case Key_Left: | 111 | case Key_Left: |
111 | if (e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) | 112 | if (e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) |
112 | { | 113 | { |
113 | e->ignore(); | 114 | e->ignore(); |
114 | return; | 115 | return; |
115 | } | 116 | } |
116 | scrollBy(-10,0); | 117 | scrollBy(-10,0); |
117 | break; | 118 | break; |
118 | case Key_Up: | 119 | case Key_Up: |
119 | if( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { | 120 | if( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { |
120 | e->ignore(); | 121 | e->ignore(); |
121 | break; | 122 | break; |
122 | } | 123 | } |
123 | setCurrentItem((currentItem()+count()-1)%count()); | 124 | setCurrentItem((currentItem()+count()-1)%count()); |
124 | if(!itemVisible(currentItem())) { | 125 | if(!itemVisible(currentItem())) { |
125 | if((unsigned int) currentItem() == (count()-1)) { | 126 | if((unsigned int) currentItem() == (count()-1)) { |
126 | setTopItem(currentItem()-numItemsVisible()+1); | 127 | setTopItem(currentItem()-numItemsVisible()+1); |
127 | } else { | 128 | } else { |
128 | setTopItem(topItem()-1); | 129 | setTopItem(topItem()-1); |
129 | } | 130 | } |
130 | } | 131 | } |
131 | break; | 132 | break; |
132 | case Key_Down: | 133 | case Key_Down: |
133 | if(e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { | 134 | if(e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { |
134 | e->ignore(); | 135 | e->ignore(); |
135 | break; | 136 | break; |
136 | } | 137 | } |
137 | setCurrentItem((currentItem()+1)%count()); | 138 | setCurrentItem((currentItem()+1)%count()); |
138 | if(!itemVisible(currentItem())) { | 139 | if(!itemVisible(currentItem())) { |
139 | if(currentItem() == 0) { | 140 | if(currentItem() == 0) { |
140 | setTopItem(0); | 141 | setTopItem(0); |
141 | } else { | 142 | } else { |
142 | setTopItem(topItem()+1); | 143 | setTopItem(topItem()+1); |
143 | } | 144 | } |
144 | } | 145 | } |
145 | break; | 146 | break; |
146 | case Key_I: | 147 | case Key_I: |
147 | QTimer::singleShot( 11, this, SLOT ( oneDown() ) ); | 148 | QTimer::singleShot( 11, this, SLOT ( oneDown() ) ); |
148 | e->ignore(); | 149 | e->ignore(); |
149 | break; | 150 | break; |
150 | case Key_Shift: | 151 | case Key_Shift: |
151 | emit shiftDown(); | 152 | emit shiftDown(); |
152 | break; | 153 | break; |
153 | default: | 154 | default: |
154 | e->ignore(); | 155 | e->ignore(); |
155 | break; | 156 | break; |
156 | } | 157 | } |
157 | } | 158 | } |
158 | 159 | ||
159 | void KNoScrollListBox::oneDown() | 160 | void KNoScrollListBox::oneDown() |
160 | { | 161 | { |
161 | setCurrentItem((currentItem()+1)%count()); | 162 | setCurrentItem((currentItem()+1)%count()); |
162 | if(!itemVisible(currentItem())) { | 163 | if(!itemVisible(currentItem())) { |
163 | if(currentItem() == 0) { | 164 | if(currentItem() == 0) { |
164 | setTopItem(0); | 165 | setTopItem(0); |
165 | } else { | 166 | } else { |
166 | setTopItem(topItem()+1); | 167 | setTopItem(topItem()+1); |
167 | } | 168 | } |
168 | } | 169 | } |
169 | } | 170 | } |
170 | void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e) | 171 | void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e) |
171 | { | 172 | { |
172 | switch(e->key()) { | 173 | switch(e->key()) { |
173 | case Key_Shift: | 174 | case Key_Shift: |
174 | emit shiftUp(); | 175 | emit shiftUp(); |
175 | break; | 176 | break; |
176 | default: | 177 | default: |
177 | break; | 178 | break; |
178 | } | 179 | } |
179 | } | 180 | } |
180 | 181 | ||
181 | void KNoScrollListBox::mousePressEvent(QMouseEvent *e) | 182 | void KNoScrollListBox::mousePressEvent(QMouseEvent *e) |
182 | { | 183 | { |
183 | QListBox::mousePressEvent(e); | 184 | QListBox::mousePressEvent(e); |
184 | 185 | ||
185 | if(e->button() == RightButton) { | 186 | if(e->button() == RightButton) { |
186 | emit rightClick(); | 187 | emit rightClick(); |
187 | } | 188 | } |
188 | } | 189 | } |
189 | 190 | ||
190 | MonthViewItem::MonthViewItem( Incidence *incidence, QDate qd, const QString & s) | 191 | MonthViewItem::MonthViewItem( Incidence *incidence, QDate qd, const QString & s) |
191 | : QListBoxItem() | 192 | : QListBoxItem() |
192 | { | 193 | { |
193 | setText( s ); | 194 | setText( s ); |
194 | 195 | ||
195 | mIncidence = incidence; | 196 | mIncidence = incidence; |
196 | mDate = qd; | 197 | mDate = qd; |
197 | // QWhatsThis::add(this,KIncidenceFormatter::instance()->getFormattedText( mIncidence )); | 198 | // QWhatsThis::add(this,KIncidenceFormatter::instance()->getFormattedText( mIncidence )); |
198 | mRecur = false; | 199 | mRecur = false; |
199 | mAlarm = false; | 200 | mAlarm = false; |
200 | mReply = false; | 201 | mReply = false; |
201 | mInfo = false; | 202 | mInfo = false; |
202 | } | 203 | } |
203 | 204 | ||
204 | void MonthViewItem::paint(QPainter *p) | 205 | void MonthViewItem::paint(QPainter *p) |
205 | { | 206 | { |
206 | #if QT_VERSION >= 0x030000 | 207 | #if QT_VERSION >= 0x030000 |
207 | bool sel = isSelected(); | 208 | bool sel = isSelected(); |
208 | #else | 209 | #else |
209 | bool sel = selected(); | 210 | bool sel = selected(); |
210 | #endif | 211 | #endif |
211 | 212 | ||
212 | 213 | ||
213 | if (KOPrefs::instance()->mMonthViewUsesCategoryColor) | 214 | if (KOPrefs::instance()->mMonthViewUsesCategoryColor) |
214 | { | 215 | { |
215 | p->setBackgroundColor( palette().color( QPalette::Normal, \ | 216 | p->setBackgroundColor( palette().color( QPalette::Normal, \ |
216 | sel ? QColorGroup::Highlight : QColorGroup::Background ) ); | 217 | sel ? QColorGroup::Highlight : QColorGroup::Background ) ); |
217 | p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) ); | 218 | p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) ); |
218 | } | 219 | } |
219 | int x = 1; | 220 | int x = 1; |
220 | int y = 3;//(height() - mRecurPixmap.height()) /2; | 221 | int y = 3;//(height() - mRecurPixmap.height()) /2; |
221 | int size = PIXMAP_SIZE; | 222 | int size = PIXMAP_SIZE; |
222 | if ( QApplication::desktop()->width() < 300 ) | 223 | if ( QApplication::desktop()->width() < 300 ) |
223 | size = 3; | 224 | size = 3; |
224 | if ( KOPrefs::instance()->mMonthShowIcons ) { | 225 | if ( KOPrefs::instance()->mMonthShowIcons ) { |
225 | if ( mInfo ) { | 226 | if ( mInfo ) { |
226 | p->fillRect ( x, y,size,size, Qt::darkGreen ); | 227 | p->fillRect ( x, y,size,size, Qt::darkGreen ); |
227 | x += size + 1; | 228 | x += size + 1; |
228 | } | 229 | } |
229 | if ( mRecur ) { | 230 | if ( mRecur ) { |
230 | p->fillRect ( x, y,size,size, Qt::blue ); | 231 | p->fillRect ( x, y,size,size, Qt::blue ); |
231 | x += size + 1; | 232 | x += size + 1; |
232 | } | 233 | } |
233 | if ( mAlarm ) { | 234 | if ( mAlarm ) { |
234 | p->fillRect ( x, y,size,size, Qt::red ); | 235 | p->fillRect ( x, y,size,size, Qt::red ); |
235 | x += size + 1; | 236 | x += size + 1; |
236 | } | 237 | } |
237 | if ( mReply ) { | 238 | if ( mReply ) { |
238 | p->fillRect ( x, y,size,size, Qt::yellow ); | 239 | p->fillRect ( x, y,size,size, Qt::yellow ); |
239 | x += size + 1; | 240 | x += size + 1; |
240 | } | 241 | } |
241 | } | 242 | } |
242 | QFontMetrics fm = p->fontMetrics(); | 243 | QFontMetrics fm = p->fontMetrics(); |
243 | int yPos; | 244 | int yPos; |
244 | int pmheight = size; | 245 | int pmheight = size; |
245 | if( pmheight < fm.height() ) | 246 | if( pmheight < fm.height() ) |
246 | yPos = fm.ascent() + fm.leading()/2; | 247 | yPos = fm.ascent() + fm.leading()/2; |
247 | else | 248 | else |
248 | yPos = pmheight/2 - fm.height()/2 + fm.ascent(); | 249 | yPos = pmheight/2 - fm.height()/2 + fm.ascent(); |
249 | p->setPen( palette().color( QPalette::Normal, sel ? \ | 250 | p->setPen( palette().color( QPalette::Normal, sel ? \ |
250 | QColorGroup::HighlightedText : QColorGroup::Foreground ) ); | 251 | QColorGroup::HighlightedText : QColorGroup::Foreground ) ); |
251 | p->drawText( x, yPos, text() ); | 252 | p->drawText( x, yPos, text() ); |
252 | if ( mIncidence->cancelled() ) { | 253 | if ( mIncidence->cancelled() ) { |
253 | int wid = fm.width( text() ); | 254 | int wid = fm.width( text() ); |
254 | p->drawLine( x, yPos- fm.height()/2+3,x+wid, yPos- fm.height()/2 +3); | 255 | p->drawLine( x, yPos- fm.height()/2+3,x+wid, yPos- fm.height()/2 +3); |
255 | } | 256 | } |
256 | 257 | ||
257 | } | 258 | } |
258 | 259 | ||
259 | int MonthViewItem::height(const QListBox *lb) const | 260 | int MonthViewItem::height(const QListBox *lb) const |
260 | { | 261 | { |
261 | return lb->fontMetrics().lineSpacing()+1; | 262 | return lb->fontMetrics().lineSpacing()+1; |
262 | } | 263 | } |
263 | 264 | ||
264 | int MonthViewItem::width(const QListBox *lb) const | 265 | int MonthViewItem::width(const QListBox *lb) const |
265 | { | 266 | { |
266 | int size = PIXMAP_SIZE; | 267 | int size = PIXMAP_SIZE; |
267 | if ( QApplication::desktop()->width() < 300 ) | 268 | if ( QApplication::desktop()->width() < 300 ) |
268 | size = 3; | 269 | size = 3; |
269 | int x = 1; | 270 | int x = 1; |
270 | if ( mInfo ) { | 271 | if ( mInfo ) { |
271 | x += size + 1; | 272 | x += size + 1; |
272 | } | 273 | } |
273 | if( mRecur ) { | 274 | if( mRecur ) { |
274 | x += size+1; | 275 | x += size+1; |
275 | } | 276 | } |
276 | if( mAlarm ) { | 277 | if( mAlarm ) { |
277 | x += size+1; | 278 | x += size+1; |
278 | } | 279 | } |
279 | if( mReply ) { | 280 | if( mReply ) { |
280 | x += size+1; | 281 | x += size+1; |
281 | } | 282 | } |
282 | 283 | ||
283 | return( x + lb->fontMetrics().width( text() ) + 1 ); | 284 | return( x + lb->fontMetrics().width( text() ) + 1 ); |
284 | } | 285 | } |
285 | 286 | ||
286 | 287 | ||
287 | MonthViewCell::MonthViewCell( KOMonthView *parent,QWidget* par ) | 288 | MonthViewCell::MonthViewCell( KOMonthView *parent,QWidget* par ) |
288 | : QWidget( par ), | 289 | : QWidget( par ), |
289 | mMonthView( parent ) | 290 | mMonthView( parent ) |
290 | { | 291 | { |
291 | 292 | ||
292 | QVBoxLayout *topLayout = new QVBoxLayout( this ); | 293 | QVBoxLayout *topLayout = new QVBoxLayout( this ); |
293 | 294 | ||
294 | // mLabel = new QLabel( this );QPushButton | 295 | // mLabel = new QLabel( this );QPushButton |
295 | mLabel = new QPushButton( this ); | 296 | mLabel = new QPushButton( this ); |
296 | //mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain ); | 297 | //mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain ); |
297 | //mLabel->setLineWidth( 1 ); | 298 | //mLabel->setLineWidth( 1 ); |
298 | //mLabel->setAlignment( AlignCenter ); | 299 | //mLabel->setAlignment( AlignCenter ); |
299 | mLabel->setFlat( true ); | 300 | mLabel->setFlat( true ); |
300 | mLabel->setFocusPolicy(NoFocus); | 301 | mLabel->setFocusPolicy(NoFocus); |
301 | mItemList = new KNoScrollListBox( this ); | 302 | mItemList = new KNoScrollListBox( this ); |
302 | mItemList->setMinimumSize( 10, 10 ); | 303 | mItemList->setMinimumSize( 10, 10 ); |
303 | mItemList->setFrameStyle( QFrame::Panel | QFrame::Plain ); | 304 | mItemList->setFrameStyle( QFrame::Panel | QFrame::Plain ); |
304 | mItemList->setLineWidth( 1 ); | 305 | mItemList->setLineWidth( 1 ); |
305 | topLayout->addWidget( mItemList ); | 306 | topLayout->addWidget( mItemList ); |
306 | mLabel->raise(); | 307 | mLabel->raise(); |
307 | // QColor( 0,0,255 ) QColor( 160,1600,255 ) | 308 | // QColor( 0,0,255 ) QColor( 160,1600,255 ) |
308 | mStandardPalette = palette(); | 309 | mStandardPalette = palette(); |
309 | mStandardPalette.setColor(QColorGroup::Base, mStandardPalette.color( QPalette::Normal, QColorGroup::Background ) ); | 310 | mStandardPalette.setColor(QColorGroup::Base, mStandardPalette.color( QPalette::Normal, QColorGroup::Background ) ); |
310 | 311 | ||
311 | enableScrollBars( false ); | 312 | enableScrollBars( false ); |
312 | updateConfig(); | 313 | updateConfig(); |
313 | //connect( mLabel, SIGNAL( clicked( )), SLOT( newEvent() )); | 314 | //connect( mLabel, SIGNAL( clicked( )), SLOT( newEvent() )); |
314 | connect( mLabel, SIGNAL( clicked( )), SLOT( showDay() )); | 315 | connect( mLabel, SIGNAL( clicked( )), SLOT( showDay() )); |
315 | connect( mItemList, SIGNAL( doubleClicked( QListBoxItem *) ), | 316 | connect( mItemList, SIGNAL( doubleClicked( QListBoxItem *) ), |
316 | SLOT( defaultAction( QListBoxItem * ) ) ); | 317 | SLOT( defaultAction( QListBoxItem * ) ) ); |
317 | connect( mItemList, SIGNAL( rightButtonPressed( QListBoxItem *, | 318 | connect( mItemList, SIGNAL( rightButtonPressed( QListBoxItem *, |
318 | const QPoint &) ), | 319 | const QPoint &) ), |
319 | SLOT( contextMenu( QListBoxItem * ) ) ); | 320 | SLOT( contextMenu( QListBoxItem * ) ) ); |
320 | connect( mItemList, SIGNAL( highlighted( QListBoxItem *) ), | 321 | connect( mItemList, SIGNAL( highlighted( QListBoxItem *) ), |
321 | SLOT( selection( QListBoxItem * ) ) ); | 322 | SLOT( selection( QListBoxItem * ) ) ); |
322 | connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ), | 323 | connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ), |
323 | SLOT( cellClicked( QListBoxItem * ) ) ); | 324 | SLOT( cellClicked( QListBoxItem * ) ) ); |
324 | connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ), | 325 | connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ), |
325 | SLOT( selection( QListBoxItem * ) ) ); | 326 | SLOT( selection( QListBoxItem * ) ) ); |
326 | } | 327 | } |
327 | #ifdef DESKTOP_VERSION | 328 | #ifdef DESKTOP_VERSION |
328 | QToolTipGroup *MonthViewCell::toolTipGroup() | 329 | QToolTipGroup *MonthViewCell::toolTipGroup() |
329 | { | 330 | { |
330 | if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0); | 331 | if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0); |
331 | return mToolTipGroup; | 332 | return mToolTipGroup; |
332 | } | 333 | } |
333 | #endif | 334 | #endif |
334 | 335 | ||
335 | void MonthViewCell::setDate( const QDate &date ) | 336 | void MonthViewCell::setDate( const QDate &date ) |
336 | { | 337 | { |
337 | // kdDebug() << "MonthViewCell::setDate(): " << date.toString() << endl; | 338 | // kdDebug() << "MonthViewCell::setDate(): " << date.toString() << endl; |
338 | mDate = date; | 339 | mDate = date; |
339 | 340 | ||
340 | 341 | ||
341 | 342 | ||
342 | //resizeEvent( 0 ); | 343 | //resizeEvent( 0 ); |
343 | } | 344 | } |
344 | 345 | ||
345 | QDate MonthViewCell::date() const | 346 | QDate MonthViewCell::date() const |
346 | { | 347 | { |
347 | return mDate; | 348 | return mDate; |
348 | } | 349 | } |
349 | 350 | ||
350 | void MonthViewCell::setPrimary( bool primary ) | 351 | void MonthViewCell::setPrimary( bool primary ) |
351 | { | 352 | { |
352 | mPrimary = primary; | 353 | mPrimary = primary; |
353 | //setMyPalette(); | 354 | //setMyPalette(); |
354 | } | 355 | } |
355 | void MonthViewCell::setMyPalette() | 356 | void MonthViewCell::setMyPalette() |
356 | { | 357 | { |
357 | 358 | ||
358 | if ( mHoliday) { | 359 | if ( mHoliday) { |
359 | setPalette( mHolidayPalette ); | 360 | setPalette( mHolidayPalette ); |
360 | } else { | 361 | } else { |
361 | if ( mPrimary ) { | 362 | if ( mPrimary ) { |
362 | setPalette( mPrimaryPalette ); | 363 | setPalette( mPrimaryPalette ); |
363 | } else { | 364 | } else { |
364 | setPalette( mNonPrimaryPalette ); | 365 | setPalette( mNonPrimaryPalette ); |
365 | } | 366 | } |
366 | } | 367 | } |
367 | QPalette pal = palette(); | 368 | QPalette pal = palette(); |
368 | 369 | ||
369 | mLabel->setPalette( QPalette ( pal.color( QPalette::Normal,QColorGroup::Base),pal.color(QPalette::Normal,QColorGroup::Base ) )); | 370 | mLabel->setPalette( QPalette ( pal.color( QPalette::Normal,QColorGroup::Base),pal.color(QPalette::Normal,QColorGroup::Base ) )); |
370 | } | 371 | } |
371 | QPalette MonthViewCell::getPalette () | 372 | QPalette MonthViewCell::getPalette () |
372 | { | 373 | { |
373 | if ( !KOPrefs::instance()->mMonthViewUsesDayColors ) | 374 | if ( !KOPrefs::instance()->mMonthViewUsesDayColors ) |
374 | return mStandardPalette; | 375 | return mStandardPalette; |
375 | if ( mHoliday) { | 376 | if ( mHoliday) { |
376 | return mHolidayPalette ; | 377 | return mHolidayPalette ; |
377 | } else { | 378 | } else { |
378 | if ( mPrimary ) { | 379 | if ( mPrimary ) { |
379 | return mPrimaryPalette ; | 380 | return mPrimaryPalette ; |
380 | } | 381 | } |
381 | } | 382 | } |
382 | return mNonPrimaryPalette; | 383 | return mNonPrimaryPalette; |
383 | } | 384 | } |
384 | bool MonthViewCell::isPrimary() const | 385 | bool MonthViewCell::isPrimary() const |
385 | { | 386 | { |
386 | return mPrimary; | 387 | return mPrimary; |
387 | } | 388 | } |
388 | 389 | ||
389 | void MonthViewCell::setHoliday( bool holiday ) | 390 | void MonthViewCell::setHoliday( bool holiday ) |
390 | { | 391 | { |
391 | mHoliday = holiday; | 392 | mHoliday = holiday; |
392 | //setMyPalette(); | 393 | //setMyPalette(); |
393 | } | 394 | } |
394 | 395 | ||
395 | void MonthViewCell::setHoliday( const QString &holiday ) | 396 | void MonthViewCell::setHoliday( const QString &holiday ) |
396 | { | 397 | { |
397 | mHolidayString = holiday; | 398 | mHolidayString = holiday; |
398 | 399 | ||
399 | if ( !holiday.isEmpty() ) { | 400 | if ( !holiday.isEmpty() ) { |
400 | setHoliday( true ); | 401 | setHoliday( true ); |
401 | } | 402 | } |
402 | } | 403 | } |
403 | void MonthViewCell::keyPressEvent ( QKeyEvent * e ) | 404 | void MonthViewCell::keyPressEvent ( QKeyEvent * e ) |
404 | { | 405 | { |
405 | 406 | ||
406 | e->ignore(); | 407 | e->ignore(); |
407 | 408 | ||
408 | } | 409 | } |
409 | 410 | ||
410 | void MonthViewCell::startUpdateCell() | 411 | void MonthViewCell::startUpdateCell() |
411 | { | 412 | { |
412 | 413 | ||
413 | mItemList->setFocusPolicy(NoFocus); | 414 | mItemList->setFocusPolicy(NoFocus); |
414 | if ( !mMonthView->isUpdatePossible() ) | 415 | if ( !mMonthView->isUpdatePossible() ) |
415 | return; | 416 | return; |
416 | 417 | ||
417 | /* | 418 | /* |
418 | if ( !isVisible() ){ | 419 | if ( !isVisible() ){ |
419 | return; | 420 | return; |
420 | } | 421 | } |
421 | */ | 422 | */ |
422 | // qDebug("MonthViewCell::updateCell() "); | 423 | // qDebug("MonthViewCell::updateCell() "); |
423 | setPrimary( mDate.month()%2 ); | 424 | setPrimary( mDate.month()%2 ); |
424 | setHoliday( KOGlobals::self()->calendarSystem()->dayOfWeek(mDate) == KOGlobals::self()->calendarSystem()->weekDayOfPray() || ( mDate.dayOfWeek() == 6 ) && KOPrefs::instance()-> mExcludeSaturdays); | 425 | setHoliday( KOGlobals::self()->calendarSystem()->dayOfWeek(mDate) == KOGlobals::self()->calendarSystem()->weekDayOfPray() || ( mDate.dayOfWeek() == 6 ) && KOPrefs::instance()-> mExcludeSaturdays); |
425 | if ( mDate == QDate::currentDate() ) { | 426 | if ( mDate == QDate::currentDate() ) { |
426 | mItemList->setLineWidth( 3 ); | 427 | mItemList->setLineWidth( 3 ); |
427 | } else { | 428 | } else { |
428 | mItemList->setLineWidth( 1 ); | 429 | mItemList->setLineWidth( 1 ); |
429 | } | 430 | } |
430 | mItemList->clear(); | 431 | mItemList->clear(); |
431 | 432 | ||
432 | #ifdef DESKTOP_VERSION | 433 | #ifdef DESKTOP_VERSION |
433 | QToolTip::remove(this); | 434 | QToolTip::remove(this); |
434 | #endif | 435 | #endif |
435 | mToolTip = ""; | 436 | mToolTip = ""; |
436 | //qApp->processEvents(); | 437 | //qApp->processEvents(); |
437 | if ( !mHolidayString.isEmpty() ) { | 438 | if ( !mHolidayString.isEmpty() ) { |
438 | MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString ); | 439 | MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString ); |
439 | item->setPalette( mHolidayPalette ); | 440 | item->setPalette( mHolidayPalette ); |
440 | mItemList->insertItem( item ); | 441 | mItemList->insertItem( item ); |
441 | mToolTip += mHolidayString+"\n"; | 442 | mToolTip += mHolidayString+"\n"; |
442 | } | 443 | } |
443 | } | 444 | } |
444 | 445 | ||
445 | void MonthViewCell::insertEvent(Event *event) | 446 | void MonthViewCell::insertEvent(Event *event) |
446 | { | 447 | { |
447 | 448 | ||
448 | mItemList->setFocusPolicy(WheelFocus); | 449 | mItemList->setFocusPolicy(WheelFocus); |
449 | if ( !(event->doesRecur() == Recurrence::rNone) ) { | 450 | if ( !(event->doesRecur() == Recurrence::rNone) ) { |
450 | if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily ) | 451 | if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily ) |
451 | return; | 452 | return; |
452 | else | 453 | else |
453 | if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly ) | 454 | if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly ) |
454 | return; | 455 | return; |
455 | } | 456 | } |
456 | 457 | ||
457 | if ( event->categories().contains("Holiday") || | 458 | if ( event->categories().contains("Holiday") || |
458 | event->categories().contains(i18n("Holiday"))) { | 459 | event->categories().contains(i18n("Holiday"))) { |
459 | setHoliday( true ); | 460 | setHoliday( true ); |
460 | if ( mDate.dayOfWeek() == 7 ) | 461 | if ( mDate.dayOfWeek() == 7 ) |
461 | mItemList->setLineWidth( 3 ); | 462 | mItemList->setLineWidth( 3 ); |
462 | } | 463 | } |
463 | QString text; | 464 | QString text; |
464 | if (event->isMultiDay()) { | 465 | if (event->isMultiDay()) { |
465 | QString prefix = "<->"; | 466 | QString prefix = "<->"; |
466 | if ( event->doesRecur() ) { | 467 | if ( event->doesRecur() ) { |
467 | if ( event->recursOn( mDate) ) | 468 | if ( event->recursOn( mDate) ) |
468 | prefix ="->" ; | 469 | prefix ="->" ; |
469 | else { | 470 | else { |
470 | int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); | 471 | int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); |
471 | if ( event->recursOn( mDate.addDays( -days)) ) | 472 | if ( event->recursOn( mDate.addDays( -days)) ) |
472 | prefix ="<-" ; | 473 | prefix ="<-" ; |
473 | } | 474 | } |
474 | 475 | ||
475 | } else { | 476 | } else { |
476 | if (mDate == event->dtStart().date()) { | 477 | if (mDate == event->dtStart().date()) { |
477 | prefix ="->" ; | 478 | prefix ="->" ; |
478 | } else if (mDate == event->dtEnd().date()) { | 479 | } else if (mDate == event->dtEnd().date()) { |
479 | prefix ="<-" ; | 480 | prefix ="<-" ; |
480 | } | 481 | } |
481 | } | 482 | } |
482 | if ( !event->doesFloat() ) { | 483 | if ( !event->doesFloat() ) { |
483 | if ( mDate == event->dtStart().date () ) | 484 | if ( mDate == event->dtStart().date () ) |
484 | prefix += KGlobal::locale()->formatTime(event->dtStart().time())+" "; | 485 | prefix += KGlobal::locale()->formatTime(event->dtStart().time())+" "; |
485 | else if ( mDate == event->dtEnd().date () ) | 486 | else if ( mDate == event->dtEnd().date () ) |
486 | prefix += KGlobal::locale()->formatTime(event->dtEnd().time())+" "; | 487 | prefix += KGlobal::locale()->formatTime(event->dtEnd().time())+" "; |
487 | 488 | ||
488 | } | 489 | } |
489 | text = prefix + event->summary(); | 490 | text = prefix + event->summary(); |
490 | mToolTip += text; | 491 | mToolTip += text; |
491 | } else { | 492 | } else { |
492 | if (event->doesFloat()) { | 493 | if (event->doesFloat()) { |
493 | text = event->summary(); | 494 | text = event->summary(); |
494 | mToolTip += text; | 495 | mToolTip += text; |
495 | } | 496 | } |
496 | else { | 497 | else { |
497 | text = KGlobal::locale()->formatTime(event->dtStart().time()); | 498 | text = KGlobal::locale()->formatTime(event->dtStart().time()); |
498 | text += " " + event->summary(); | 499 | text += " " + event->summary(); |
499 | mToolTip += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); | 500 | mToolTip += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); |
500 | } | 501 | } |
501 | } | 502 | } |
502 | 503 | ||
503 | MonthViewItem *item = new MonthViewItem( event, mDate, text ); | 504 | MonthViewItem *item = new MonthViewItem( event, mDate, text ); |
504 | QPalette pal; | 505 | QPalette pal; |
505 | if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { | 506 | if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { |
506 | QStringList categories = event->categories(); | 507 | QStringList categories = event->categories(); |
507 | QString cat = categories.first(); | 508 | QString cat = categories.first(); |
508 | if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { | 509 | if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { |
509 | pal = getPalette(); | 510 | pal = getPalette(); |
510 | if (cat.isEmpty()) { | 511 | if (cat.isEmpty()) { |
511 | pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); | 512 | pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); |
512 | } else { | 513 | } else { |
513 | pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); | 514 | pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); |
514 | } | 515 | } |
515 | 516 | ||
516 | } else { | 517 | } else { |
517 | if (cat.isEmpty()) { | 518 | if (cat.isEmpty()) { |
518 | pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); | 519 | pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); |
519 | } else { | 520 | } else { |
520 | pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); | 521 | pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); |
521 | } | 522 | } |
522 | } | 523 | } |
523 | 524 | ||
524 | } else { | 525 | } else { |
525 | pal = mStandardPalette ; | 526 | pal = mStandardPalette ; |
526 | } | 527 | } |
527 | item->setPalette( pal ); | 528 | item->setPalette( pal ); |
528 | item->setRecur( event->recurrence()->doesRecur() ); | 529 | item->setRecur( event->recurrence()->doesRecur() ); |
529 | item->setAlarm( event->isAlarmEnabled() ); | 530 | item->setAlarm( event->isAlarmEnabled() ); |
530 | item->setMoreInfo( event->description().length() > 0 ); | 531 | item->setMoreInfo( event->description().length() > 0 ); |
531 | #ifdef DESKTOP_VERSION | 532 | #ifdef DESKTOP_VERSION |
532 | Attendee *me = event->attendeeByMails(KOPrefs::instance()->mAdditionalMails, | 533 | Attendee *me = event->attendeeByMails(KOPrefs::instance()->mAdditionalMails, |
533 | KOPrefs::instance()->email()); | 534 | KOPrefs::instance()->email()); |
534 | if ( me != 0 ) { | 535 | if ( me != 0 ) { |
535 | if ( me->status() == Attendee::NeedsAction && me->RSVP()) | 536 | if ( me->status() == Attendee::NeedsAction && me->RSVP()) |
536 | item->setReply(true); | 537 | item->setReply(true); |
537 | else | 538 | else |
538 | item->setReply(false); | 539 | item->setReply(false); |
539 | } else | 540 | } else |
540 | item->setReply(false); | 541 | item->setReply(false); |
541 | #endif | 542 | #endif |
542 | mItemList->insertItem( item ); | 543 | mItemList->insertItem( item ); |
543 | mToolTip += "\n"; | 544 | mToolTip += "\n"; |
544 | } | 545 | } |
545 | void MonthViewCell::insertTodo(Todo *todo) | 546 | void MonthViewCell::insertTodo(Todo *todo) |
546 | { | 547 | { |
547 | mItemList->setFocusPolicy(WheelFocus); | 548 | mItemList->setFocusPolicy(WheelFocus); |
548 | QString text; | 549 | QString text; |
549 | if (todo->hasDueDate()) { | 550 | if (todo->hasDueDate()) { |
550 | if (!todo->doesFloat()) { | 551 | if (!todo->doesFloat()) { |
551 | text += KGlobal::locale()->formatTime(todo->dtDue().time()); | 552 | text += KGlobal::locale()->formatTime(todo->dtDue().time()); |
552 | text += " "; | 553 | text += " "; |
553 | } | 554 | } |
554 | } | 555 | } |
555 | text += i18n("Td: %1").arg(todo->summary()); | 556 | text += i18n("Td: %1").arg(todo->summary()); |
556 | 557 | ||
557 | MonthViewItem *item = new MonthViewItem( todo, mDate, text ); | 558 | MonthViewItem *item = new MonthViewItem( todo, mDate, text ); |
558 | //item->setPalette( mStandardPalette ); | 559 | //item->setPalette( mStandardPalette ); |
559 | QPalette pal; | 560 | QPalette pal; |
560 | if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { | 561 | if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { |
561 | QStringList categories = todo->categories(); | 562 | QStringList categories = todo->categories(); |
562 | QString cat = categories.first(); | 563 | QString cat = categories.first(); |
563 | if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { | 564 | if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { |
564 | pal = getPalette(); | 565 | pal = getPalette(); |
565 | if (cat.isEmpty()) { | 566 | if (cat.isEmpty()) { |
566 | pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); | 567 | pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); |
567 | } else { | 568 | } else { |
568 | pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); | 569 | pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); |
569 | } | 570 | } |
570 | 571 | ||
571 | } else { | 572 | } else { |
572 | if (cat.isEmpty()) { | 573 | if (cat.isEmpty()) { |
573 | pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); | 574 | pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); |
574 | } else { | 575 | } else { |
575 | pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); | 576 | pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); |
576 | } | 577 | } |
577 | } | 578 | } |
578 | 579 | ||
579 | } else { | 580 | } else { |
580 | pal = mStandardPalette ; | 581 | pal = mStandardPalette ; |
581 | } | 582 | } |
582 | item->setPalette( pal ); | 583 | item->setPalette( pal ); |
583 | mItemList->insertItem( item ); | 584 | mItemList->insertItem( item ); |
584 | mToolTip += text+"\n"; | 585 | mToolTip += text+"\n"; |
585 | } | 586 | } |
586 | void MonthViewCell::finishUpdateCell() | 587 | void MonthViewCell::finishUpdateCell() |
587 | { | 588 | { |
588 | #ifdef DESKTOP_VERSION | 589 | #ifdef DESKTOP_VERSION |
589 | if (mToolTip != "") | 590 | if (mToolTip != "") |
590 | QToolTip::add(this,mToolTip,toolTipGroup(),""); | 591 | QToolTip::add(this,mToolTip,toolTipGroup(),""); |
591 | #endif | 592 | #endif |
592 | mItemList->sort(); | 593 | mItemList->sort(); |
593 | //setMyPalette(); | 594 | //setMyPalette(); |
594 | setMyPalette(); | 595 | setMyPalette(); |
595 | QString text; | 596 | QString text; |
596 | bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog; | 597 | bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog; |
597 | if ( KOPrefs::instance()->mMonthViewWeek || KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) { | 598 | if ( KOPrefs::instance()->mMonthViewWeek || KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) { |
598 | text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " "; | 599 | text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " "; |
599 | mLabel->resize( mLabelBigSize ); | 600 | mLabel->resize( mLabelBigSize ); |
600 | text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); | 601 | text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); |
601 | } else { | 602 | } else { |
602 | mLabel->resize( mLabelSize ); | 603 | mLabel->resize( mLabelSize ); |
603 | text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); | 604 | text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); |
604 | } | 605 | } |
605 | 606 | ||
606 | mLabel->setText( text ); | 607 | mLabel->setText( text ); |
607 | resizeEvent( 0 ); | 608 | resizeEvent( 0 ); |
608 | } | 609 | } |
609 | void MonthViewCell::updateCell() | 610 | void MonthViewCell::updateCell() |
610 | { | 611 | { |
611 | qDebug("MonthViewCell::updateCell() "); | 612 | qDebug("MonthViewCell::updateCell() "); |
612 | if ( !mMonthView->isUpdatePossible() ) | 613 | if ( !mMonthView->isUpdatePossible() ) |
613 | return; | 614 | return; |
614 | startUpdateCell(); | 615 | startUpdateCell(); |
615 | //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); | 616 | //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); |
616 | QPtrList<Event> events = mMonthView->calendar()->events( mDate, true ); | 617 | QPtrList<Event> events = mMonthView->calendar()->events( mDate, true ); |
617 | Event *event; | 618 | Event *event; |
618 | for( event = events.first(); event; event = events.next() ) { // for event | 619 | for( event = events.first(); event; event = events.next() ) { // for event |
619 | insertEvent(event); | 620 | insertEvent(event); |
620 | } | 621 | } |
621 | // insert due todos | 622 | // insert due todos |
622 | QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate ); | 623 | QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate ); |
623 | Todo *todo; | 624 | Todo *todo; |
624 | for(todo = todos.first(); todo; todo = todos.next()) { | 625 | for(todo = todos.first(); todo; todo = todos.next()) { |
625 | insertTodo( todo ); | 626 | insertTodo( todo ); |
626 | } | 627 | } |
627 | finishUpdateCell(); | 628 | finishUpdateCell(); |
628 | // if ( isVisible()) | 629 | // if ( isVisible()) |
629 | //qApp->processEvents(); | 630 | //qApp->processEvents(); |
630 | } | 631 | } |
631 | 632 | ||
632 | void MonthViewCell::updateConfig( bool bigFont ) // = false | 633 | void MonthViewCell::updateConfig( bool bigFont ) // = false |
633 | { | 634 | { |
634 | 635 | ||
635 | if ( bigFont ) { | 636 | if ( bigFont ) { |
636 | QFont fo = KOPrefs::instance()->mMonthViewFont; | 637 | QFont fo = KOPrefs::instance()->mMonthViewFont; |
637 | int ps = fo.pointSize() + 2; | 638 | int ps = fo.pointSize() + 2; |
638 | if ( ps < 18 ) | 639 | if ( ps < 18 ) |
639 | ps += 2; | 640 | ps += 2; |
640 | fo.setPointSize( ps ); | 641 | fo.setPointSize( ps ); |
641 | setFont( fo ); | 642 | setFont( fo ); |
642 | } else | 643 | } else |
643 | setFont( KOPrefs::instance()->mMonthViewFont ); | 644 | setFont( KOPrefs::instance()->mMonthViewFont ); |
644 | 645 | ||
645 | QFontMetrics fm( font() ); | 646 | QFontMetrics fm( font() ); |
646 | mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 ); | 647 | mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 ); |
647 | mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 ); | 648 | mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 ); |
648 | mHolidayPalette = mStandardPalette; | 649 | mHolidayPalette = mStandardPalette; |
649 | mPrimaryPalette = mStandardPalette; | 650 | mPrimaryPalette = mStandardPalette; |
650 | mNonPrimaryPalette = mStandardPalette; | 651 | mNonPrimaryPalette = mStandardPalette; |
651 | if ( KOPrefs::instance()->mMonthViewUsesDayColors ) { | 652 | if ( KOPrefs::instance()->mMonthViewUsesDayColors ) { |
652 | mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor ); | 653 | mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor ); |
653 | mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor ); | 654 | mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor ); |
654 | mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark()); | 655 | mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark()); |
655 | mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark()); | 656 | mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark()); |
656 | mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor); | 657 | mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor); |
657 | mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor); | 658 | mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor); |
658 | mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark()); | 659 | mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark()); |
659 | mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor); | 660 | mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor); |
660 | mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor); | 661 | mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor); |
661 | } | 662 | } |
662 | //updateCell(); | 663 | //updateCell(); |
663 | } | 664 | } |
664 | 665 | ||
665 | void MonthViewCell::enableScrollBars( bool enabled ) | 666 | void MonthViewCell::enableScrollBars( bool enabled ) |
666 | { | 667 | { |
667 | if ( enabled ) { | 668 | if ( enabled ) { |
668 | mItemList->setVScrollBarMode(QScrollView::Auto); | 669 | mItemList->setVScrollBarMode(QScrollView::Auto); |
669 | mItemList->setHScrollBarMode(QScrollView::Auto); | 670 | mItemList->setHScrollBarMode(QScrollView::Auto); |
670 | } else { | 671 | } else { |
671 | mItemList->setVScrollBarMode(QScrollView::AlwaysOff); | 672 | mItemList->setVScrollBarMode(QScrollView::AlwaysOff); |
672 | mItemList->setHScrollBarMode(QScrollView::AlwaysOff); | 673 | mItemList->setHScrollBarMode(QScrollView::AlwaysOff); |
673 | } | 674 | } |
674 | } | 675 | } |
675 | 676 | ||
676 | Incidence *MonthViewCell::selectedIncidence() | 677 | Incidence *MonthViewCell::selectedIncidence() |
677 | { | 678 | { |
678 | int index = mItemList->currentItem(); | 679 | int index = mItemList->currentItem(); |
679 | if ( index < 0 ) return 0; | 680 | if ( index < 0 ) return 0; |
680 | 681 | ||
681 | MonthViewItem *item = | 682 | MonthViewItem *item = |
682 | static_cast<MonthViewItem *>( mItemList->item( index ) ); | 683 | static_cast<MonthViewItem *>( mItemList->item( index ) ); |
683 | 684 | ||
684 | if ( !item ) return 0; | 685 | if ( !item ) return 0; |
685 | 686 | ||
686 | return item->incidence(); | 687 | return item->incidence(); |
687 | } | 688 | } |
688 | 689 | ||
689 | QDate MonthViewCell::selectedIncidenceDate() | 690 | QDate MonthViewCell::selectedIncidenceDate() |
690 | { | 691 | { |
691 | QDate qd; | 692 | QDate qd; |
692 | int index = mItemList->currentItem(); | 693 | int index = mItemList->currentItem(); |
693 | if ( index < 0 ) return qd; | 694 | if ( index < 0 ) return qd; |
694 | 695 | ||
695 | MonthViewItem *item = | 696 | MonthViewItem *item = |
696 | static_cast<MonthViewItem *>( mItemList->item( index ) ); | 697 | static_cast<MonthViewItem *>( mItemList->item( index ) ); |
697 | 698 | ||
698 | if ( !item ) return qd; | 699 | if ( !item ) return qd; |
699 | 700 | ||
700 | return item->incidenceDate(); | 701 | return item->incidenceDate(); |
701 | } | 702 | } |
702 | 703 | ||
703 | void MonthViewCell::deselect() | 704 | void MonthViewCell::deselect() |
704 | { | 705 | { |
705 | mItemList->clearSelection(); | 706 | mItemList->clearSelection(); |
706 | enableScrollBars( false ); | 707 | enableScrollBars( false ); |
707 | // updateCell(); | 708 | // updateCell(); |
708 | } | 709 | } |
709 | void MonthViewCell::select() | 710 | void MonthViewCell::select() |
710 | { | 711 | { |
711 | ;// updateCell(); | 712 | ;// updateCell(); |
712 | } | 713 | } |
713 | 714 | ||
714 | void MonthViewCell::resizeEvent ( QResizeEvent * ) | 715 | void MonthViewCell::resizeEvent ( QResizeEvent * ) |
715 | { | 716 | { |
716 | if ( !mMonthView->isUpdatePossible() ) | 717 | if ( !mMonthView->isUpdatePossible() ) |
717 | return; | 718 | return; |
718 | 719 | ||
719 | int size = height() - mLabel->height() - 2; | 720 | int size = height() - mLabel->height() - 2; |
720 | if ( size > 0 ) | 721 | if ( size > 0 ) |
721 | mItemList->verticalScrollBar()->setMaximumHeight( size ); | 722 | mItemList->verticalScrollBar()->setMaximumHeight( size ); |
722 | size = width() - mLabel->width() -2; | 723 | size = width() - mLabel->width() -2; |
723 | if ( size > 0 ) | 724 | if ( size > 0 ) |
724 | mItemList->horizontalScrollBar()->setMaximumWidth( size ); | 725 | mItemList->horizontalScrollBar()->setMaximumWidth( size ); |
725 | mLabel->move( width()-mItemList->lineWidth() - mLabel->width(), height()-mItemList->lineWidth() - mLabel->height() ); | 726 | mLabel->move( width()-mItemList->lineWidth() - mLabel->width(), height()-mItemList->lineWidth() - mLabel->height() ); |
726 | //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); | 727 | //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); |
727 | } | 728 | } |
728 | 729 | ||
729 | void MonthViewCell::defaultAction( QListBoxItem *item ) | 730 | void MonthViewCell::defaultAction( QListBoxItem *item ) |
730 | { | 731 | { |
731 | if ( !item ) return; | 732 | if ( !item ) return; |
732 | 733 | ||
733 | MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); | 734 | MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); |
734 | Incidence *incidence = eventItem->incidence(); | 735 | Incidence *incidence = eventItem->incidence(); |
735 | if ( incidence ) mMonthView->defaultAction( incidence ); | 736 | if ( incidence ) mMonthView->defaultAction( incidence ); |
736 | } | 737 | } |
737 | void MonthViewCell::showDay() | 738 | void MonthViewCell::showDay() |
738 | { | 739 | { |
739 | emit showDaySignal( date() ); | 740 | emit showDaySignal( date() ); |
740 | } | 741 | } |
741 | void MonthViewCell::newEvent() | 742 | void MonthViewCell::newEvent() |
742 | { | 743 | { |
743 | QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); | 744 | QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); |
744 | emit newEventSignal( dt ); | 745 | emit newEventSignal( dt ); |
745 | } | 746 | } |
746 | void MonthViewCell::cellClicked( QListBoxItem *item ) | 747 | void MonthViewCell::cellClicked( QListBoxItem *item ) |
747 | { | 748 | { |
748 | static QListBoxItem * lastClicked = 0; | 749 | static QListBoxItem * lastClicked = 0; |
749 | if ( item == 0 ) { | 750 | if ( item == 0 ) { |
750 | QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); | 751 | QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); |
751 | emit newEventSignal( dt ); | 752 | emit newEventSignal( dt ); |
752 | return; | 753 | return; |
753 | } | 754 | } |
754 | /* | 755 | /* |
755 | if ( lastClicked ) | 756 | if ( lastClicked ) |
756 | if ( ! item ) { | 757 | if ( ! item ) { |
757 | if ( lastClicked->listBox() != item->listBox() ) | 758 | if ( lastClicked->listBox() != item->listBox() ) |
758 | lastClicked->listBox()->clearSelection(); | 759 | lastClicked->listBox()->clearSelection(); |
759 | } | 760 | } |
760 | */ | 761 | */ |
761 | 762 | ||
762 | mMonthView->setSelectedCell( this ); | 763 | mMonthView->setSelectedCell( this ); |
763 | if( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) enableScrollBars( true ); | 764 | if( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) enableScrollBars( true ); |
764 | select(); | 765 | select(); |
765 | } | 766 | } |
766 | 767 | ||
767 | void MonthViewCell::contextMenu( QListBoxItem *item ) | 768 | void MonthViewCell::contextMenu( QListBoxItem *item ) |
768 | { | 769 | { |
769 | if ( !item ) return; | 770 | if ( !item ) return; |
770 | 771 | ||
771 | MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); | 772 | MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); |
772 | Incidence *incidence = eventItem->incidence(); | 773 | Incidence *incidence = eventItem->incidence(); |
773 | if ( incidence ) mMonthView->showContextMenu( incidence ); | 774 | if ( incidence ) mMonthView->showContextMenu( incidence ); |
774 | } | 775 | } |
775 | 776 | ||
776 | void MonthViewCell::selection( QListBoxItem *item ) | 777 | void MonthViewCell::selection( QListBoxItem *item ) |
777 | { | 778 | { |
778 | if ( !item ) return; | 779 | if ( !item ) return; |
779 | 780 | ||
780 | mMonthView->setSelectedCell( this ); | 781 | mMonthView->setSelectedCell( this ); |
781 | } | 782 | } |
782 | 783 | ||
783 | 784 | ||
784 | // ******************************************************************************* | 785 | // ******************************************************************************* |
785 | // ******************************************************************************* | 786 | // ******************************************************************************* |
786 | // ******************************************************************************* | 787 | // ******************************************************************************* |
787 | 788 | ||
788 | 789 | ||
789 | KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) | 790 | KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) |
790 | : KOEventView( calendar, parent, name ), | 791 | : KOEventView( calendar, parent, name ), |
791 | mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ), | 792 | mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ), |
792 | mShortDayLabels( false ), mWidthLongDayLabel( 0 ), mSelectedCell( 0 ) | 793 | mShortDayLabels( false ), mWidthLongDayLabel( 0 ), mSelectedCell( 0 ) |
793 | { | 794 | { |
794 | skipResize = false; | 795 | skipResize = false; |
795 | clPending = true; | 796 | clPending = true; |
796 | mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" ); | 797 | mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" ); |
797 | mWidStack = new QWidgetStack( this ); | 798 | mWidStack = new QWidgetStack( this ); |
798 | QVBoxLayout* hb = new QVBoxLayout( this ); | 799 | QVBoxLayout* hb = new QVBoxLayout( this ); |
799 | mMonthView = new QWidget( mWidStack ); | 800 | mMonthView = new QWidget( mWidStack ); |
800 | mWeekView = new QWidget( mWidStack ); | 801 | mWeekView = new QWidget( mWidStack ); |
801 | #if QT_VERSION >= 0x030000 | 802 | #if QT_VERSION >= 0x030000 |
802 | mWidStack->addWidget(mMonthView ); | 803 | mWidStack->addWidget(mMonthView ); |
803 | mWidStack->addWidget(mWeekView ); | 804 | mWidStack->addWidget(mWeekView ); |
804 | #else | 805 | #else |
805 | mWidStack->addWidget( mMonthView, 1 ); | 806 | mWidStack->addWidget( mMonthView, 1 ); |
806 | mWidStack->addWidget( mWeekView , 1 ); | 807 | mWidStack->addWidget( mWeekView , 1 ); |
807 | #endif | 808 | #endif |
808 | hb->addWidget( mNavigatorBar ); | 809 | hb->addWidget( mNavigatorBar ); |
809 | hb->addWidget( mWidStack ); | 810 | hb->addWidget( mWidStack ); |
810 | mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); | 811 | mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); |
811 | mShowWeekView = KOPrefs::instance()->mMonthViewWeek; | 812 | mShowWeekView = KOPrefs::instance()->mMonthViewWeek; |
812 | if ( mShowWeekView ) | 813 | if ( mShowWeekView ) |
813 | mWeekStartsMonday = true; | 814 | mWeekStartsMonday = true; |
814 | updatePossible = false; | 815 | updatePossible = false; |
815 | //updatePossible = true; | 816 | //updatePossible = true; |
816 | mCells.setAutoDelete( true ); | 817 | mCells.setAutoDelete( true ); |
817 | mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; | 818 | mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; |
818 | mDayLabels.resize( mDaysPerWeek ); | 819 | mDayLabels.resize( mDaysPerWeek ); |
819 | mDayLabelsW.resize( mDaysPerWeek ); | 820 | mDayLabelsW.resize( mDaysPerWeek ); |
820 | QFont bfont = font(); | 821 | QFont bfont = font(); |
821 | if ( QApplication::desktop()->width() < 650 ) { | 822 | if ( QApplication::desktop()->width() < 650 ) { |
822 | bfont.setPointSize( bfont.pointSize() - 2 ); | 823 | bfont.setPointSize( bfont.pointSize() - 2 ); |
823 | } | 824 | } |
824 | bfont.setBold( true ); | 825 | bfont.setBold( true ); |
825 | int i; | 826 | int i; |
826 | 827 | ||
827 | for( i = 0; i < mDaysPerWeek; i++ ) { | 828 | for( i = 0; i < mDaysPerWeek; i++ ) { |
828 | QLabel *label = new QLabel( mMonthView ); | 829 | QLabel *label = new QLabel( mMonthView ); |
829 | label->setFont(bfont); | 830 | label->setFont(bfont); |
830 | label->setFrameStyle(QFrame::Panel|QFrame::Raised); | 831 | label->setFrameStyle(QFrame::Panel|QFrame::Raised); |
831 | label->setLineWidth(1); | 832 | label->setLineWidth(1); |
832 | label->setAlignment(AlignCenter); | 833 | label->setAlignment(AlignCenter); |
833 | mDayLabels.insert( i, label ); | 834 | mDayLabels.insert( i, label ); |
834 | label = new QLabel( mWeekView ); | 835 | label = new QLabel( mWeekView ); |
835 | label->setFont(bfont); | 836 | label->setFont(bfont); |
836 | label->setFrameStyle(QFrame::Panel|QFrame::Raised); | 837 | label->setFrameStyle(QFrame::Panel|QFrame::Raised); |
837 | label->setLineWidth(1); | 838 | label->setLineWidth(1); |
838 | label->setAlignment(AlignCenter); | 839 | label->setAlignment(AlignCenter); |
839 | mDayLabelsW.insert( i, label ); | 840 | mDayLabelsW.insert( i, label ); |
840 | } | 841 | } |
841 | 842 | ||
842 | bfont.setBold( false ); | 843 | bfont.setBold( false ); |
843 | mWeekLabels.resize( mNumWeeks+1 ); | 844 | mWeekLabels.resize( mNumWeeks+1 ); |
844 | mWeekLabelsW.resize( 2 ); | 845 | mWeekLabelsW.resize( 2 ); |
845 | for( i = 0; i < mNumWeeks+1; i++ ) { | 846 | for( i = 0; i < mNumWeeks+1; i++ ) { |
846 | KOWeekButton *label = new KOWeekButton( mMonthView ); | 847 | KOWeekButton *label = new KOWeekButton( mMonthView ); |
847 | label->setFocusPolicy(NoFocus); | 848 | label->setFocusPolicy(NoFocus); |
848 | label->setFont(bfont); | 849 | label->setFont(bfont); |
849 | connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); | 850 | connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); |
850 | label->setFlat(true); | 851 | label->setFlat(true); |
851 | QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); | 852 | QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); |
852 | //label->setFrameStyle(QFrame::Panel|QFrame::Raised); | 853 | //label->setFrameStyle(QFrame::Panel|QFrame::Raised); |
853 | //label->setLineWidth(1); | 854 | //label->setLineWidth(1); |
854 | //label->setAlignment(AlignCenter); | 855 | //label->setAlignment(AlignCenter); |
855 | mWeekLabels.insert( i, label ); | 856 | mWeekLabels.insert( i, label ); |
856 | } | 857 | } |
857 | mWeekLabels[mNumWeeks]->setText( i18n("W")); | 858 | mWeekLabels[mNumWeeks]->setText( i18n("W")); |
858 | QWhatsThis::add(mWeekLabels[mNumWeeks],i18n("Click on this to\nselect week number")); | 859 | QWhatsThis::add(mWeekLabels[mNumWeeks],i18n("Click on this to\nselect week number")); |
859 | 860 | ||
860 | for( i = 0; i < 1+1; i++ ) { | 861 | for( i = 0; i < 1+1; i++ ) { |
861 | KOWeekButton *label = new KOWeekButton( mWeekView ); | 862 | KOWeekButton *label = new KOWeekButton( mWeekView ); |
862 | label->setFocusPolicy(NoFocus); | 863 | label->setFocusPolicy(NoFocus); |
863 | label->setFont(bfont); | 864 | label->setFont(bfont); |
864 | connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); | 865 | connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); |
865 | label->setFlat(true); | 866 | label->setFlat(true); |
866 | QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); | 867 | QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); |
867 | //label->setFrameStyle(QFrame::Panel|QFrame::Raised); | 868 | //label->setFrameStyle(QFrame::Panel|QFrame::Raised); |
868 | //label->setLineWidth(1); | 869 | //label->setLineWidth(1); |
869 | //label->setAlignment(AlignCenter); | 870 | //label->setAlignment(AlignCenter); |
870 | mWeekLabelsW.insert( i, label ); | 871 | mWeekLabelsW.insert( i, label ); |
871 | } | 872 | } |
872 | mWeekLabelsW[1]->setText( i18n("W")); | 873 | mWeekLabelsW[1]->setText( i18n("W")); |
873 | 874 | ||
874 | 875 | ||
875 | int row, col; | 876 | int row, col; |
876 | mCells.resize( mNumCells ); | 877 | mCells.resize( mNumCells ); |
877 | for( row = 0; row < mNumWeeks; ++row ) { | 878 | for( row = 0; row < mNumWeeks; ++row ) { |
878 | for( col = 0; col < mDaysPerWeek; ++col ) { | 879 | for( col = 0; col < mDaysPerWeek; ++col ) { |
879 | MonthViewCell *cell = new MonthViewCell( this, mMonthView ); | 880 | MonthViewCell *cell = new MonthViewCell( this, mMonthView ); |
880 | mCells.insert( row * mDaysPerWeek + col, cell ); | 881 | mCells.insert( row * mDaysPerWeek + col, cell ); |
881 | 882 | ||
882 | connect( cell, SIGNAL( defaultAction( Incidence * ) ), | 883 | connect( cell, SIGNAL( defaultAction( Incidence * ) ), |
883 | SLOT( defaultAction( Incidence * ) ) ); | 884 | SLOT( defaultAction( Incidence * ) ) ); |
884 | connect( cell, SIGNAL( newEventSignal( QDateTime ) ), | 885 | connect( cell, SIGNAL( newEventSignal( QDateTime ) ), |
885 | SIGNAL( newEventSignal( QDateTime ) ) ); | 886 | SIGNAL( newEventSignal( QDateTime ) ) ); |
886 | connect( cell, SIGNAL( showDaySignal( QDate ) ), | 887 | connect( cell, SIGNAL( showDaySignal( QDate ) ), |
887 | SIGNAL( showDaySignal( QDate ) ) ); | 888 | SIGNAL( showDaySignal( QDate ) ) ); |
888 | } | 889 | } |
889 | } | 890 | } |
890 | mCellsW.resize( mDaysPerWeek ); | 891 | mCellsW.resize( mDaysPerWeek ); |
891 | for( col = 0; col < mDaysPerWeek; ++col ) { | 892 | for( col = 0; col < mDaysPerWeek; ++col ) { |
892 | MonthViewCell *cell = new MonthViewCell( this, mWeekView ); | 893 | MonthViewCell *cell = new MonthViewCell( this, mWeekView ); |
893 | mCellsW.insert( col, cell ); | 894 | mCellsW.insert( col, cell ); |
894 | 895 | ||
895 | connect( cell, SIGNAL( defaultAction( Incidence * ) ), | 896 | connect( cell, SIGNAL( defaultAction( Incidence * ) ), |
896 | SLOT( defaultAction( Incidence * ) ) ); | 897 | SLOT( defaultAction( Incidence * ) ) ); |
897 | connect( cell, SIGNAL( newEventSignal( QDateTime ) ), | 898 | connect( cell, SIGNAL( newEventSignal( QDateTime ) ), |
898 | SIGNAL( newEventSignal( QDateTime ) ) ); | 899 | SIGNAL( newEventSignal( QDateTime ) ) ); |
899 | connect( cell, SIGNAL( showDaySignal( QDate ) ), | 900 | connect( cell, SIGNAL( showDaySignal( QDate ) ), |
900 | SIGNAL( showDaySignal( QDate ) ) ); | 901 | SIGNAL( showDaySignal( QDate ) ) ); |
901 | cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont ); | 902 | cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont ); |
902 | } | 903 | } |
903 | 904 | ||
904 | //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) ); | 905 | //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) ); |
905 | mContextMenu = eventPopup(); | 906 | mContextMenu = eventPopup(); |
906 | // updateConfig(); //useless here... | 907 | // updateConfig(); //useless here... |
907 | // ... but we need mWidthLongDayLabel computed | 908 | // ... but we need mWidthLongDayLabel computed |
908 | QFontMetrics fontmetric(mDayLabels[0]->font()); | 909 | QFontMetrics fontmetric(mDayLabels[0]->font()); |
909 | mWidthLongDayLabel = 0; | 910 | mWidthLongDayLabel = 0; |
910 | for (int i = 0; i < 7; i++) { | 911 | for (int i = 0; i < 7; i++) { |
911 | int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); | 912 | int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); |
912 | if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; | 913 | if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; |
913 | } | 914 | } |
914 | 915 | ||
915 | //mWeekLabels[mNumWeeks]->setText( i18n("W")); | 916 | //mWeekLabels[mNumWeeks]->setText( i18n("W")); |
916 | 917 | ||
917 | if ( mShowWeekView ) | 918 | if ( mShowWeekView ) |
918 | mWidStack->raiseWidget( mWeekView ); | 919 | mWidStack->raiseWidget( mWeekView ); |
919 | else | 920 | else |
920 | mWidStack->raiseWidget( mMonthView ); | 921 | mWidStack->raiseWidget( mMonthView ); |
921 | 922 | ||
922 | emit incidenceSelected( 0 ); | 923 | emit incidenceSelected( 0 ); |
923 | #ifndef DESKTOP_VERSION | 924 | #ifndef DESKTOP_VERSION |
924 | resize( QApplication::desktop()->size() ); | 925 | resize( QApplication::desktop()->size() ); |
925 | computeLayout(); | 926 | computeLayout(); |
926 | #endif | 927 | #endif |
927 | } | 928 | } |
928 | 929 | ||
929 | KOMonthView::~KOMonthView() | 930 | KOMonthView::~KOMonthView() |
930 | { | 931 | { |
931 | delete mContextMenu; | 932 | delete mContextMenu; |
932 | } | 933 | } |
933 | 934 | ||
934 | void KOMonthView::selectInternalWeekNum ( int n ) | 935 | void KOMonthView::selectInternalWeekNum ( int n ) |
935 | { | 936 | { |
936 | switchView(); | 937 | switchView(); |
937 | emit selectWeekNum ( n ); | 938 | emit selectWeekNum ( n ); |
938 | } | 939 | } |
939 | 940 | ||
940 | int KOMonthView::currentWeek() | 941 | int KOMonthView::currentWeek() |
941 | { | 942 | { |
942 | if ( mShowWeekView ) | 943 | if ( mShowWeekView ) |
943 | return mWeekLabelsW[0]->getWeekNum(); | 944 | return mWeekLabelsW[0]->getWeekNum(); |
944 | return mWeekLabels[0]->getWeekNum(); | 945 | return mWeekLabels[0]->getWeekNum(); |
945 | } | 946 | } |
946 | void KOMonthView::switchView() | 947 | void KOMonthView::switchView() |
947 | { | 948 | { |
948 | 949 | ||
949 | if ( selectedCell( ) ) | 950 | if ( selectedCell( ) ) |
950 | selectedCell()->deselect(); | 951 | selectedCell()->deselect(); |
951 | mShowWeekView = !mShowWeekView; | 952 | mShowWeekView = !mShowWeekView; |
952 | KOPrefs::instance()->mMonthViewWeek = mShowWeekView; | 953 | KOPrefs::instance()->mMonthViewWeek = mShowWeekView; |
953 | if ( clPending ) { | 954 | if ( clPending ) { |
954 | computeLayout(); | 955 | computeLayout(); |
955 | updateConfig(); | 956 | updateConfig(); |
956 | } | 957 | } |
957 | if ( mShowWeekView ) | 958 | if ( mShowWeekView ) |
958 | mWidStack->raiseWidget( mWeekView ); | 959 | mWidStack->raiseWidget( mWeekView ); |
959 | else | 960 | else |
960 | mWidStack->raiseWidget( mMonthView ); | 961 | mWidStack->raiseWidget( mMonthView ); |
961 | clPending = false; | 962 | clPending = false; |
962 | } | 963 | } |
963 | 964 | ||
964 | int KOMonthView::maxDatesHint() | 965 | int KOMonthView::maxDatesHint() |
965 | { | 966 | { |
966 | return mNumCells; | 967 | return mNumCells; |
967 | } | 968 | } |
968 | 969 | ||
969 | int KOMonthView::currentDateCount() | 970 | int KOMonthView::currentDateCount() |
970 | { | 971 | { |
971 | return mNumCells; | 972 | return mNumCells; |
972 | } | 973 | } |
973 | 974 | ||
974 | QPtrList<Incidence> KOMonthView::selectedIncidences() | 975 | QPtrList<Incidence> KOMonthView::selectedIncidences() |
975 | { | 976 | { |
976 | QPtrList<Incidence> selected; | 977 | QPtrList<Incidence> selected; |
977 | 978 | ||
978 | if ( mSelectedCell ) { | 979 | if ( mSelectedCell ) { |
979 | Incidence *incidence = mSelectedCell->selectedIncidence(); | 980 | Incidence *incidence = mSelectedCell->selectedIncidence(); |
980 | if ( incidence ) selected.append( incidence ); | 981 | if ( incidence ) selected.append( incidence ); |
981 | } | 982 | } |
982 | 983 | ||
983 | return selected; | 984 | return selected; |
984 | } | 985 | } |
985 | 986 | ||
986 | DateList KOMonthView::selectedDates() | 987 | DateList KOMonthView::selectedDates() |
987 | { | 988 | { |
988 | DateList selected; | 989 | DateList selected; |
989 | 990 | ||
990 | if ( mSelectedCell ) { | 991 | if ( mSelectedCell ) { |
991 | QDate qd = mSelectedCell->selectedIncidenceDate(); | 992 | QDate qd = mSelectedCell->selectedIncidenceDate(); |
992 | if ( qd.isValid() ) selected.append( qd ); | 993 | if ( qd.isValid() ) selected.append( qd ); |
993 | } | 994 | } |
994 | 995 | ||
995 | return selected; | 996 | return selected; |
996 | } | 997 | } |
997 | 998 | ||
998 | void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd, | 999 | void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd, |
999 | const QDate &td) | 1000 | const QDate &td) |
1000 | { | 1001 | { |
1001 | #ifndef KORG_NOPRINTER | 1002 | #ifndef KORG_NOPRINTER |
1002 | calPrinter->preview(CalPrinter::Month, fd, td); | 1003 | calPrinter->preview(CalPrinter::Month, fd, td); |
1003 | #endif | 1004 | #endif |
1004 | } | 1005 | } |
1005 | 1006 | ||
1006 | void KOMonthView::updateConfig() | 1007 | void KOMonthView::updateConfig() |
1007 | { | 1008 | { |
1008 | 1009 | ||
1009 | mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); | 1010 | mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); |
1010 | 1011 | ||
1011 | if ( mShowWeekView ) { | 1012 | if ( mShowWeekView ) { |
1012 | mWeekStartsMonday = true; | 1013 | mWeekStartsMonday = true; |
1013 | } | 1014 | } |
1014 | QFontMetrics fontmetric(mDayLabels[0]->font()); | 1015 | QFontMetrics fontmetric(mDayLabels[0]->font()); |
1015 | mWidthLongDayLabel = 0; | 1016 | mWidthLongDayLabel = 0; |
1016 | 1017 | ||
1017 | for (int i = 0; i < 7; i++) { | 1018 | for (int i = 0; i < 7; i++) { |
1018 | int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); | 1019 | int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); |
1019 | if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; | 1020 | if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; |
1020 | } | 1021 | } |
1021 | bool temp = mShowSatSunComp ; | 1022 | bool temp = mShowSatSunComp ; |
1022 | mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; | 1023 | mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; |
1023 | if ( ! mShowWeekView ) { | 1024 | if ( ! mShowWeekView ) { |
1024 | if ( temp != KOPrefs::instance()->mMonthViewSatSunTog ) | 1025 | if ( temp != KOPrefs::instance()->mMonthViewSatSunTog ) |
1025 | computeLayout(); | 1026 | computeLayout(); |
1026 | } | 1027 | } |
1027 | updateDayLabels(); | 1028 | updateDayLabels(); |
1028 | //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks); | 1029 | //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks); |
1029 | //int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks; | 1030 | //int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks; |
1030 | //resizeEvent( 0 ); | 1031 | //resizeEvent( 0 ); |
1031 | for (uint i = 0; i < mCells.count(); ++i) { | 1032 | for (uint i = 0; i < mCells.count(); ++i) { |
1032 | mCells[i]->updateConfig(); | 1033 | mCells[i]->updateConfig(); |
1033 | } | 1034 | } |
1034 | 1035 | ||
1035 | for (uint i = 0; i < mCellsW.count(); ++i) { | 1036 | for (uint i = 0; i < mCellsW.count(); ++i) { |
1036 | mCellsW[i]->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont); | 1037 | mCellsW[i]->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont); |
1037 | } | 1038 | } |
1038 | #ifdef DESKTOP_VERSION | 1039 | #ifdef DESKTOP_VERSION |
1039 | MonthViewCell::toolTipGroup()->setEnabled(KOPrefs::instance()->mEnableToolTips); | 1040 | MonthViewCell::toolTipGroup()->setEnabled(KOPrefs::instance()->mEnableToolTips); |
1040 | #endif | 1041 | #endif |
1041 | updateView(); | 1042 | updateView(); |
1042 | } | 1043 | } |
1043 | 1044 | ||
1044 | void KOMonthView::updateDayLabels() | 1045 | void KOMonthView::updateDayLabels() |
1045 | { | 1046 | { |
1046 | 1047 | ||
1047 | QPtrVector<QLabel> *mDayLabelsT; | 1048 | QPtrVector<QLabel> *mDayLabelsT; |
1048 | 1049 | ||
1049 | mDayLabelsT = &mDayLabelsW; | 1050 | mDayLabelsT = &mDayLabelsW; |
1050 | for (int i = 0; i < 7; i++) { | 1051 | for (int i = 0; i < 7; i++) { |
1051 | if (mWeekStartsMonday) { | 1052 | if (mWeekStartsMonday) { |
1052 | bool show = mShortDayLabels; | 1053 | bool show = mShortDayLabels; |
1053 | if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) | 1054 | if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) |
1054 | show = true; | 1055 | show = true; |
1055 | (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); | 1056 | (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); |
1056 | } else { | 1057 | } else { |
1057 | if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabels)); | 1058 | if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabels)); |
1058 | else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabels)); | 1059 | else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabels)); |
1059 | 1060 | ||
1060 | } | 1061 | } |
1061 | } | 1062 | } |
1062 | mDayLabelsT = &mDayLabels; | 1063 | mDayLabelsT = &mDayLabels; |
1063 | for (int i = 0; i < 7; i++) { | 1064 | for (int i = 0; i < 7; i++) { |
1064 | if (mWeekStartsMonday) { | 1065 | if (mWeekStartsMonday) { |
1065 | bool show = mShortDayLabels; | 1066 | bool show = mShortDayLabels; |
1066 | if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) | 1067 | if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) |
1067 | show = true; | 1068 | show = true; |
1068 | (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); | 1069 | (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); |
1069 | } else { | 1070 | } else { |
1070 | if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabels)); | 1071 | if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabels)); |
1071 | else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabels)); | 1072 | else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabels)); |
1072 | 1073 | ||
1073 | } | 1074 | } |
1074 | } | 1075 | } |
1075 | 1076 | ||
1076 | } | 1077 | } |
1077 | 1078 | ||
1078 | void KOMonthView::showDates(const QDate &start, const QDate &) | 1079 | void KOMonthView::showDates(const QDate &start, const QDate &) |
1079 | { | 1080 | { |
1080 | // kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl; | 1081 | // kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl; |
1081 | 1082 | ||
1082 | QPtrVector<MonthViewCell> *cells; | 1083 | QPtrVector<MonthViewCell> *cells; |
1083 | QPtrVector<QLabel> *dayLabels; | 1084 | QPtrVector<QLabel> *dayLabels; |
1084 | QPtrVector<KOWeekButton> *weekLabels; | 1085 | QPtrVector<KOWeekButton> *weekLabels; |
1085 | int weekNum = 6; | 1086 | int weekNum = 6; |
1086 | if ( mShowWeekView ) { | 1087 | if ( mShowWeekView ) { |
1087 | weekNum = 1; | 1088 | weekNum = 1; |
1088 | cells = &mCellsW; | 1089 | cells = &mCellsW; |
1089 | dayLabels = &mDayLabelsW; | 1090 | dayLabels = &mDayLabelsW; |
1090 | weekLabels = &mWeekLabelsW; | 1091 | weekLabels = &mWeekLabelsW; |
1091 | } else { | 1092 | } else { |
1092 | cells = &mCells; | 1093 | cells = &mCells; |
1093 | dayLabels = &mDayLabels; | 1094 | dayLabels = &mDayLabels; |
1094 | weekLabels = &mWeekLabels; | 1095 | weekLabels = &mWeekLabels; |
1095 | } | 1096 | } |
1096 | 1097 | ||
1097 | mStartDate = start; | 1098 | mStartDate = start; |
1098 | 1099 | ||
1099 | int startWeekDay = mWeekStartsMonday ? 1 : 7; | 1100 | int startWeekDay = mWeekStartsMonday ? 1 : 7; |
1100 | 1101 | ||
1101 | while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) { | 1102 | while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) { |
1102 | mStartDate = mStartDate.addDays( -1 ); | 1103 | mStartDate = mStartDate.addDays( -1 ); |
1103 | } | 1104 | } |
1104 | 1105 | ||
1105 | bool primary = false; | 1106 | bool primary = false; |
1106 | uint i; | 1107 | uint i; |
1107 | for( i = 0; i < (*cells).size(); ++i ) { | 1108 | for( i = 0; i < (*cells).size(); ++i ) { |
1108 | QDate date = mStartDate.addDays( i ); | 1109 | QDate date = mStartDate.addDays( i ); |
1109 | (*cells)[i]->setDate( date ); | 1110 | (*cells)[i]->setDate( date ); |
1110 | 1111 | ||
1111 | #ifndef KORG_NOPLUGINS | 1112 | #ifndef KORG_NOPLUGINS |
1112 | // add holiday, if present | 1113 | // add holiday, if present |
1113 | QString hstring(KOCore::self()->holiday(date)); | 1114 | QString hstring(KOCore::self()->holiday(date)); |
1114 | (*cells)[i]->setHoliday( hstring ); | 1115 | (*cells)[i]->setHoliday( hstring ); |
1115 | #endif | 1116 | #endif |
1116 | 1117 | ||
1117 | } | 1118 | } |
1118 | QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 ); | 1119 | QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 ); |
1119 | for( i = 0; i < weekNum; ++i ) { | 1120 | for( i = 0; i < weekNum; ++i ) { |
1120 | int wno; | 1121 | int wno; |
1121 | // remember, according to ISO 8601, the first week of the year is the | 1122 | // remember, according to ISO 8601, the first week of the year is the |
1122 | // first week that contains a thursday. Thus we must subtract off 4, | 1123 | // first week that contains a thursday. Thus we must subtract off 4, |
1123 | // not just 1. | 1124 | // not just 1. |
1124 | int dayOfYear = date.dayOfYear(); | 1125 | int dayOfYear = date.dayOfYear(); |
1125 | if (dayOfYear % 7 != 0) | 1126 | if (dayOfYear % 7 != 0) |
1126 | wno = dayOfYear / 7 + 1; | 1127 | wno = dayOfYear / 7 + 1; |
1127 | else | 1128 | else |
1128 | wno =dayOfYear / 7; | 1129 | wno =dayOfYear / 7; |
1129 | (*weekLabels)[i]->setWeekNum( wno ); | 1130 | (*weekLabels)[i]->setWeekNum( wno ); |
1130 | date = date.addDays( 7 ); | 1131 | date = date.addDays( 7 ); |
1131 | } | 1132 | } |
1132 | updateView(); | 1133 | updateView(); |
1133 | } | 1134 | } |
1134 | 1135 | ||
1135 | void KOMonthView::showEvents(QPtrList<Event>) | 1136 | void KOMonthView::showEvents(QPtrList<Event>) |
1136 | { | 1137 | { |
1137 | qDebug("KOMonthView::selectEvents is not implemented yet. "); | 1138 | qDebug("KOMonthView::selectEvents is not implemented yet. "); |
1138 | } | 1139 | } |
1139 | 1140 | ||
1140 | void KOMonthView::changeEventDisplay(Event *, int) | 1141 | void KOMonthView::changeEventDisplay(Event *, int) |
1141 | { | 1142 | { |
1142 | // this should be re-written to be much more efficient, but this | 1143 | // this should be re-written to be much more efficient, but this |
1143 | // quick-and-dirty-hack gets the job done for right now. | 1144 | // quick-and-dirty-hack gets the job done for right now. |
1144 | updateView(); | 1145 | updateView(); |
1145 | } | 1146 | } |
1146 | 1147 | ||
1147 | void KOMonthView::updateView() | 1148 | void KOMonthView::updateView() |
1148 | { | 1149 | { |
1149 | 1150 | ||
1150 | if ( !updatePossible ) | 1151 | if ( !updatePossible ) |
1151 | return; | 1152 | return; |
1152 | //QTime ti; | 1153 | //QTime ti; |
1153 | //ti.start(); | 1154 | //ti.start(); |
1154 | QPtrVector<MonthViewCell> *cells; | 1155 | QPtrVector<MonthViewCell> *cells; |
1155 | if ( mShowWeekView ) { | 1156 | if ( mShowWeekView ) { |
1156 | cells = &mCellsW; | 1157 | cells = &mCellsW; |
1157 | } else { | 1158 | } else { |
1158 | cells = &mCells; | 1159 | cells = &mCells; |
1159 | } | 1160 | } |
1160 | #if 1 | 1161 | #if 1 |
1161 | int i; | 1162 | int i; |
1162 | int timeSpan = (*cells).size()-1; | 1163 | int timeSpan = (*cells).size()-1; |
1163 | if ( KOPrefs::instance()->mMonthViewWeek ) | 1164 | if ( KOPrefs::instance()->mMonthViewWeek ) |
1164 | timeSpan = 6; | 1165 | timeSpan = 6; |
1165 | for( i = 0; i < timeSpan + 1; ++i ) { | 1166 | for( i = 0; i < timeSpan + 1; ++i ) { |
1166 | (*cells)[i]->startUpdateCell(); | 1167 | (*cells)[i]->startUpdateCell(); |
1167 | } | 1168 | } |
1168 | 1169 | ||
1169 | QPtrList<Event> events = calendar()->events(); | 1170 | QPtrList<Event> events = calendar()->events(); |
1170 | Event *event; | 1171 | Event *event; |
1171 | QDateTime dt; | 1172 | QDateTime dt; |
1172 | bool ok; | 1173 | bool ok; |
1173 | QDate endDate = mStartDate.addDays( timeSpan ); | 1174 | QDate endDate = mStartDate.addDays( timeSpan ); |
1174 | for( event = events.first(); event; event = events.next() ) { // for event | 1175 | for( event = events.first(); event; event = events.next() ) { // for event |
1175 | if ( event->doesRecur() ) { | 1176 | if ( event->doesRecur() ) { |
1176 | bool last; | 1177 | bool last; |
1177 | QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); | 1178 | QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); |
1178 | QDateTime incidenceEnd; | 1179 | QDateTime incidenceEnd; |
1179 | int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); | 1180 | int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); |
1180 | bool invalid = false; | 1181 | bool invalid = false; |
1181 | while( true ) { | 1182 | while( true ) { |
1182 | if ( incidenceStart.isValid() ) { | 1183 | if ( incidenceStart.isValid() ) { |
1183 | incidenceEnd = incidenceStart.addDays( eventlen ); | 1184 | incidenceEnd = incidenceStart.addDays( eventlen ); |
1184 | int st = incidenceStart.date().daysTo( endDate ); | 1185 | int st = incidenceStart.date().daysTo( endDate ); |
1185 | if ( st >= 0 ) { // start before timeend | 1186 | if ( st >= 0 ) { // start before timeend |
1186 | int end = mStartDate.daysTo( incidenceEnd.date() ); | 1187 | int end = mStartDate.daysTo( incidenceEnd.date() ); |
1187 | if ( end >= 0 ) { // end after timestart --- got one! | 1188 | if ( end >= 0 ) { // end after timestart --- got one! |
1188 | //normalize | 1189 | //normalize |
1189 | st = timeSpan - st; | 1190 | st = timeSpan - st; |
1190 | if ( st < 0 ) st = 0; | 1191 | if ( st < 0 ) st = 0; |
1191 | if ( end > timeSpan ) end = timeSpan; | 1192 | if ( end > timeSpan ) end = timeSpan; |
1192 | int iii; | 1193 | int iii; |
1193 | //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); | 1194 | //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); |
1194 | for ( iii = st;iii<= end;++iii) | 1195 | for ( iii = st;iii<= end;++iii) |
1195 | (*cells)[iii]->insertEvent( event ); | 1196 | (*cells)[iii]->insertEvent( event ); |
1196 | } | 1197 | } |
1197 | } | 1198 | } |
1198 | } else { | 1199 | } else { |
1199 | if ( invalid ) | 1200 | if ( invalid ) |
1200 | break; | 1201 | break; |
1201 | invalid = true; | 1202 | invalid = true; |
1202 | //qDebug("invalid %s", event->summary().latin1()); | 1203 | //qDebug("invalid %s", event->summary().latin1()); |
1203 | incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; | 1204 | incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; |
1204 | } | 1205 | } |
1205 | if ( last ) | 1206 | if ( last ) |
1206 | break; | 1207 | break; |
1207 | bool ok; | 1208 | bool ok; |
1208 | incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); | 1209 | incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); |
1209 | if ( ! ok ) | 1210 | if ( ! ok ) |
1210 | break; | 1211 | break; |
1211 | if ( incidenceStart.date() > endDate ) | 1212 | if ( incidenceStart.date() > endDate ) |
1212 | break; | 1213 | break; |
1213 | } | 1214 | } |
1214 | } else { // no recur | 1215 | } else { // no recur |
1215 | int st = event->dtStart().date().daysTo( endDate ); | 1216 | int st = event->dtStart().date().daysTo( endDate ); |
1216 | if ( st >= 0 ) { // start before timeend | 1217 | if ( st >= 0 ) { // start before timeend |
1217 | int end = mStartDate.daysTo( event->dtEnd().date() ); | 1218 | int end = mStartDate.daysTo( event->dtEnd().date() ); |
1218 | if ( end >= 0 ) { // end after timestart --- got one! | 1219 | if ( end >= 0 ) { // end after timestart --- got one! |
1219 | //normalize | 1220 | //normalize |
1220 | st = timeSpan - st; | 1221 | st = timeSpan - st; |
1221 | if ( st < 0 ) st = 0; | 1222 | if ( st < 0 ) st = 0; |
1222 | if ( end > timeSpan ) end = timeSpan; | 1223 | if ( end > timeSpan ) end = timeSpan; |
1223 | int iii; | 1224 | int iii; |
1224 | for ( iii = st;iii<= end;++iii) | 1225 | for ( iii = st;iii<= end;++iii) |
1225 | (*cells)[iii]->insertEvent( event ); | 1226 | (*cells)[iii]->insertEvent( event ); |
1226 | } | 1227 | } |
1227 | } | 1228 | } |
1228 | } | 1229 | } |
1229 | } | 1230 | } |
1230 | // insert due todos | 1231 | // insert due todos |
1231 | QPtrList<Todo> todos = calendar()->todos( ); | 1232 | QPtrList<Todo> todos = calendar()->todos( ); |
1232 | Todo *todo; | 1233 | Todo *todo; |
1233 | for(todo = todos.first(); todo; todo = todos.next()) { | 1234 | for(todo = todos.first(); todo; todo = todos.next()) { |
1234 | //insertTodo( todo ); | 1235 | //insertTodo( todo ); |
1235 | if ( todo->hasDueDate() ) { | 1236 | if ( todo->hasDueDate() ) { |
1236 | int day = mStartDate.daysTo( todo->dtDue().date() ); | 1237 | int day = mStartDate.daysTo( todo->dtDue().date() ); |
1237 | if ( day >= 0 && day < timeSpan + 1) { | 1238 | if ( day >= 0 && day < timeSpan + 1) { |
1238 | (*cells)[day]->insertTodo( todo ); | 1239 | (*cells)[day]->insertTodo( todo ); |
1239 | } | 1240 | } |
1240 | } | 1241 | } |
1241 | } | 1242 | } |
1242 | 1243 | ||
1243 | for( i = 0; i < timeSpan+1; ++i ) { | 1244 | for( i = 0; i < timeSpan+1; ++i ) { |
1244 | (*cells)[i]->finishUpdateCell(); | 1245 | (*cells)[i]->finishUpdateCell(); |
1245 | } | 1246 | } |
1246 | processSelectionChange(); | 1247 | processSelectionChange(); |
1247 | (*cells)[0]->setFocus(); | 1248 | (*cells)[0]->setFocus(); |
1248 | 1249 | ||
1249 | 1250 | ||
1250 | #else | 1251 | #else |
1251 | // old code | 1252 | // old code |
1252 | //qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "); | 1253 | //qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "); |
1253 | int i; | 1254 | int i; |
1254 | for( i = 0; i < (*cells).count(); ++i ) { | 1255 | for( i = 0; i < (*cells).count(); ++i ) { |
1255 | (*cells)[i]->updateCell(); | 1256 | (*cells)[i]->updateCell(); |
1256 | } | 1257 | } |
1257 | 1258 | ||
1258 | //qDebug("KOMonthView::updateView() "); | 1259 | //qDebug("KOMonthView::updateView() "); |
1259 | processSelectionChange(); | 1260 | processSelectionChange(); |
1260 | // qDebug("---------------------------------------------------------------------+ "); | 1261 | // qDebug("---------------------------------------------------------------------+ "); |
1261 | (*cells)[0]->setFocus(); | 1262 | (*cells)[0]->setFocus(); |
1262 | #endif | 1263 | #endif |
1263 | 1264 | ||
1264 | //qDebug("update time %d ", ti.elapsed()); | 1265 | //qDebug("update time %d ", ti.elapsed()); |
1265 | } | 1266 | } |
1266 | 1267 | ||
1267 | void KOMonthView::resizeEvent(QResizeEvent * e) | 1268 | void KOMonthView::resizeEvent(QResizeEvent * e) |
1268 | { | 1269 | { |
1269 | //qDebug("KOMonthView::resizeEvent %d %d -- %d %d ", e->size().width(), e->size().height(), e->oldSize().width(), e->oldSize().height()); | 1270 | //qDebug("KOMonthView::resizeEvent %d %d -- %d %d ", e->size().width(), e->size().height(), e->oldSize().width(), e->oldSize().height()); |
1270 | computeLayout(); | 1271 | computeLayout(); |
1271 | clPending = true; | 1272 | clPending = true; |
1272 | if ( mShowWeekView ) | 1273 | if ( mShowWeekView ) |
1273 | mCellsW[0]->setFocus(); | 1274 | mCellsW[0]->setFocus(); |
1274 | else | 1275 | else |
1275 | mCells[0]->setFocus(); | 1276 | mCells[0]->setFocus(); |
1276 | } | 1277 | } |
1277 | void KOMonthView::computeLayoutWeek() | 1278 | void KOMonthView::computeLayoutWeek() |
1278 | { | 1279 | { |
1279 | static int lastWid = 0; | 1280 | static int lastWid = 0; |
1280 | static int lastHei = 0; | 1281 | static int lastHei = 0; |
1281 | int daysToShow; | 1282 | int daysToShow; |
1282 | bool combinedSatSun = false; | 1283 | bool combinedSatSun = false; |
1283 | if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { | 1284 | if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { |
1284 | daysToShow = 6; | 1285 | daysToShow = 6; |
1285 | combinedSatSun = true; | 1286 | combinedSatSun = true; |
1286 | } | 1287 | } |
1287 | int tWid = topLevelWidget()->size().width(); | 1288 | int tWid = topLevelWidget()->size().width(); |
1288 | int tHei = topLevelWidget()->size().height(); | 1289 | int tHei = topLevelWidget()->size().height(); |
1289 | 1290 | ||
1290 | int wid = width();//e | 1291 | int wid = width();//e |
1291 | int hei = height()-1-mNavigatorBar->height(); | 1292 | int hei = height()-1-mNavigatorBar->height(); |
1292 | 1293 | ||
1293 | if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) | 1294 | if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) |
1294 | return; | 1295 | return; |
1295 | 1296 | ||
1296 | if ( lastWid == width() && lastHei == height() ) | 1297 | if ( lastWid == width() && lastHei == height() ) |
1297 | return; | 1298 | return; |
1298 | lastWid = width(); | 1299 | lastWid = width(); |
1299 | lastHei = height(); | 1300 | lastHei = height(); |
1300 | 1301 | ||
1301 | 1302 | ||
1302 | if ( wid < hei ) | 1303 | if ( wid < hei ) |
1303 | daysToShow = 2; | 1304 | daysToShow = 2; |
1304 | else | 1305 | else |
1305 | daysToShow = 3; | 1306 | daysToShow = 3; |
1306 | mShowSatSunComp = true; | 1307 | mShowSatSunComp = true; |
1307 | combinedSatSun = true; | 1308 | combinedSatSun = true; |
1308 | 1309 | ||
1309 | //qDebug("KOMonthView::computeLayout() WWW ------------------------------------ "); | 1310 | //qDebug("KOMonthView::computeLayout() WWW ------------------------------------ "); |
1310 | QFontMetrics fm ( mWeekLabels[0]->font() ); | 1311 | QFontMetrics fm ( mWeekLabels[0]->font() ); |
1311 | int weeklabelwid = fm.width( "888" ); | 1312 | int weeklabelwid = fm.width( "888" ); |
1312 | wid -= weeklabelwid; | 1313 | wid -= weeklabelwid; |
1313 | 1314 | ||
1314 | int colWid = wid / daysToShow; | 1315 | int colWid = wid / daysToShow; |
1315 | int lastCol = wid - ( colWid*6 ); | 1316 | int lastCol = wid - ( colWid*6 ); |
1316 | int dayLabelHei = mDayLabelsW[0]->sizeHint().height(); | 1317 | int dayLabelHei = mDayLabelsW[0]->sizeHint().height(); |
1317 | int cellHei = (hei - (5- daysToShow )*dayLabelHei) /(5- daysToShow ); | 1318 | int cellHei = (hei - (5- daysToShow )*dayLabelHei) /(5- daysToShow ); |
1318 | int colModulo = wid % daysToShow; | 1319 | int colModulo = wid % daysToShow; |
1319 | int rowModulo = (hei- (5- daysToShow )*dayLabelHei) % daysToShow-1; | 1320 | int rowModulo = (hei- (5- daysToShow )*dayLabelHei) % daysToShow-1; |
1320 | //qDebug("rowmod %d ", rowModulo); | 1321 | //qDebug("rowmod %d ", rowModulo); |
1321 | int i; | 1322 | int i; |
1322 | int x,y,w,h; | 1323 | int x,y,w,h; |
1323 | x= 0; | 1324 | x= 0; |
1324 | y= 0; | 1325 | y= 0; |
1325 | w = colWid; | 1326 | w = colWid; |
1326 | h = dayLabelHei ; | 1327 | h = dayLabelHei ; |
1327 | for ( i = 0; i < 7; i++) { | 1328 | for ( i = 0; i < 7; i++) { |
1328 | if ( i && !( i % daysToShow) && i < 6) { | 1329 | if ( i && !( i % daysToShow) && i < 6) { |
1329 | y += hei/(5-daysToShow); | 1330 | y += hei/(5-daysToShow); |
1330 | x = 0; | 1331 | x = 0; |
1331 | w = colWid; | 1332 | w = colWid; |
1332 | } | 1333 | } |
1333 | if ( ((i) % daysToShow) >= daysToShow-colModulo ) { | 1334 | if ( ((i) % daysToShow) >= daysToShow-colModulo ) { |
1334 | ++w; | 1335 | ++w; |
1335 | } | 1336 | } |
1336 | if ( i >= 5 ) { | 1337 | if ( i >= 5 ) { |
1337 | mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,w/2+w%2,h); | 1338 | mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,w/2+w%2,h); |
1338 | x -= (w/2 ); | 1339 | x -= (w/2 ); |
1339 | } | 1340 | } |
1340 | else | 1341 | else |
1341 | mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,w,h); | 1342 | mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,w,h); |
1342 | x += w; | 1343 | x += w; |
1343 | } | 1344 | } |
1344 | x= 0; | 1345 | x= 0; |
1345 | y= dayLabelHei; | 1346 | y= dayLabelHei; |
1346 | w = colWid; | 1347 | w = colWid; |
1347 | h = cellHei; | 1348 | h = cellHei; |
1348 | for ( i = 0; i < mCellsW.count(); ++i) { | 1349 | for ( i = 0; i < mCellsW.count(); ++i) { |
1349 | if ( i > 6 ) { | 1350 | if ( i > 6 ) { |
1350 | mCellsW[i]->hide(); | 1351 | mCellsW[i]->hide(); |
1351 | continue; | 1352 | continue; |
1352 | } | 1353 | } |
1353 | 1354 | ||
1354 | w = colWid; | 1355 | w = colWid; |
1355 | if ( ((i) % daysToShow) >= daysToShow-colModulo ) { | 1356 | if ( ((i) % daysToShow) >= daysToShow-colModulo ) { |
1356 | ++w; | 1357 | ++w; |
1357 | } | 1358 | } |
1358 | if ( i == (daysToShow-1-rowModulo)*7) | 1359 | if ( i == (daysToShow-1-rowModulo)*7) |
1359 | ++h; | 1360 | ++h; |
1360 | 1361 | ||
1361 | if ( i >= 5 ) { | 1362 | if ( i >= 5 ) { |
1362 | if ( i ==5 ) { | 1363 | if ( i ==5 ) { |
1363 | mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h/2 ); | 1364 | mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h/2 ); |
1364 | x -= w ;y += h/2; | 1365 | x -= w ;y += h/2; |
1365 | } else { | 1366 | } else { |
1366 | if ( ((i-1) % daysToShow) >= daysToShow-colModulo ) { | 1367 | if ( ((i-1) % daysToShow) >= daysToShow-colModulo ) { |
1367 | ++w; | 1368 | ++w; |
1368 | } | 1369 | } |
1369 | mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h-h/2 ); | 1370 | mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h-h/2 ); |
1370 | y -= h/2; | 1371 | y -= h/2; |
1371 | } | 1372 | } |
1372 | } else | 1373 | } else |
1373 | mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h ); | 1374 | mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h ); |
1374 | 1375 | ||
1375 | 1376 | ||
1376 | x += w; | 1377 | x += w; |
1377 | if ( x + w/2 > wid ) { | 1378 | if ( x + w/2 > wid ) { |
1378 | x = 0; | 1379 | x = 0; |
1379 | y += h+dayLabelHei ; | 1380 | y += h+dayLabelHei ; |
1380 | } | 1381 | } |
1381 | } | 1382 | } |
1382 | y= dayLabelHei; | 1383 | y= dayLabelHei; |
1383 | h = cellHei ; | 1384 | h = cellHei ; |
1384 | mWeekLabelsW[0]->setGeometry( 0,y,weeklabelwid,hei-dayLabelHei); | 1385 | mWeekLabelsW[0]->setGeometry( 0,y,weeklabelwid,hei-dayLabelHei); |
1385 | mWeekLabelsW[1]->setGeometry( 0,0,weeklabelwid,dayLabelHei); | 1386 | mWeekLabelsW[1]->setGeometry( 0,0,weeklabelwid,dayLabelHei); |
1386 | // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); | 1387 | // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); |
1387 | //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); | 1388 | //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); |
1388 | mShortDayLabels = mDayLabelsW[0]->width() < mWidthLongDayLabel ; | 1389 | mShortDayLabels = mDayLabelsW[0]->width() < mWidthLongDayLabel ; |
1389 | updateDayLabels(); | 1390 | updateDayLabels(); |
1390 | //bool forceUpdate = !updatePossible; | 1391 | //bool forceUpdate = !updatePossible; |
1391 | updatePossible = true; | 1392 | updatePossible = true; |
1392 | //mWeekLabels[mNumWeeks]->setText( i18n("M")); | 1393 | //mWeekLabels[mNumWeeks]->setText( i18n("M")); |
1393 | //if ( forceUpdate ) | 1394 | //if ( forceUpdate ) |
1394 | // updateView(); | 1395 | // updateView(); |
1395 | } | 1396 | } |
1396 | void KOMonthView::computeLayout() | 1397 | void KOMonthView::computeLayout() |
1397 | { | 1398 | { |
1398 | 1399 | ||
1399 | 1400 | ||
1400 | static int lastWid = 0; | 1401 | static int lastWid = 0; |
1401 | static int lastHei = 0; | 1402 | static int lastHei = 0; |
1402 | 1403 | ||
1403 | if ( mShowWeekView ){ | 1404 | if ( mShowWeekView ){ |
1404 | computeLayoutWeek(); | 1405 | computeLayoutWeek(); |
1405 | return; | 1406 | return; |
1406 | } | 1407 | } |
1407 | int daysToShow = 7; | 1408 | int daysToShow = 7; |
1408 | bool combinedSatSun = false; | 1409 | bool combinedSatSun = false; |
1409 | if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { | 1410 | if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { |
1410 | daysToShow = 6; | 1411 | daysToShow = 6; |
1411 | combinedSatSun = true; | 1412 | combinedSatSun = true; |
1412 | } | 1413 | } |
1413 | int tWid = topLevelWidget()->size().width(); | 1414 | int tWid = topLevelWidget()->size().width(); |
1414 | int tHei = topLevelWidget()->size().height(); | 1415 | int tHei = topLevelWidget()->size().height(); |
1415 | 1416 | ||
1416 | int wid = width();//e | 1417 | int wid = width();//e |
1417 | int hei = height()-1-mNavigatorBar->height(); | 1418 | int hei = height()-1-mNavigatorBar->height(); |
1418 | 1419 | ||
1419 | if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) { | 1420 | if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) { |
1420 | return; | 1421 | return; |
1421 | } | 1422 | } |
1422 | if ( lastWid == width() && lastHei == height() ){ | 1423 | if ( lastWid == width() && lastHei == height() ){ |
1423 | return; | 1424 | return; |
1424 | } | 1425 | } |
1425 | 1426 | ||
1426 | lastWid = width(); | 1427 | lastWid = width(); |
1427 | lastHei = height(); | 1428 | lastHei = height(); |
1428 | //qDebug("KOMonthView::computeLayout() MMM ------------------------------------ "); | 1429 | //qDebug("KOMonthView::computeLayout() MMM ------------------------------------ "); |
1429 | QFontMetrics fm ( mWeekLabels[0]->font() ); | 1430 | QFontMetrics fm ( mWeekLabels[0]->font() ); |
1430 | int weeklabelwid = fm.width( "888" ); | 1431 | int weeklabelwid = fm.width( "888" ); |
1431 | wid -= weeklabelwid; | 1432 | wid -= weeklabelwid; |
1432 | 1433 | ||
1433 | int colWid = wid / daysToShow; | 1434 | int colWid = wid / daysToShow; |
1434 | int lastCol = wid - ( colWid*6 ); | 1435 | int lastCol = wid - ( colWid*6 ); |
1435 | int dayLabelHei = mDayLabels[0]->sizeHint().height(); | 1436 | int dayLabelHei = mDayLabels[0]->sizeHint().height(); |
1436 | int cellHei = (hei - dayLabelHei) /6; | 1437 | int cellHei = (hei - dayLabelHei) /6; |
1437 | int colModulo = wid % daysToShow; | 1438 | int colModulo = wid % daysToShow; |
1438 | int rowModulo = (hei- dayLabelHei) % 6; | 1439 | int rowModulo = (hei- dayLabelHei) % 6; |
1439 | //qDebug("rowmod %d ", rowModulo); | 1440 | //qDebug("rowmod %d ", rowModulo); |
1440 | int i; | 1441 | int i; |
1441 | int x,y,w,h; | 1442 | int x,y,w,h; |
1442 | x= 0; | 1443 | x= 0; |
1443 | y= 0; | 1444 | y= 0; |
1444 | w = colWid; | 1445 | w = colWid; |
1445 | h = dayLabelHei ; | 1446 | h = dayLabelHei ; |
1446 | for ( i = 0; i < 7; i++) { | 1447 | for ( i = 0; i < 7; i++) { |
1447 | if ( i == daysToShow-colModulo ) | 1448 | if ( i == daysToShow-colModulo ) |
1448 | ++w; | 1449 | ++w; |
1449 | if ( combinedSatSun ) { | 1450 | if ( combinedSatSun ) { |
1450 | if ( i >= daysToShow-1 ) { | 1451 | if ( i >= daysToShow-1 ) { |
1451 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,w/2,h); | 1452 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,w/2,h); |
1452 | x -= w/2 ; | 1453 | x -= w/2 ; |
1453 | } | 1454 | } |
1454 | else | 1455 | else |
1455 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); | 1456 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); |
1456 | } else | 1457 | } else |
1457 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); | 1458 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); |
1458 | x += w; | 1459 | x += w; |
1459 | } | 1460 | } |
1460 | x= 0; | 1461 | x= 0; |
1461 | y= dayLabelHei; | 1462 | y= dayLabelHei; |
1462 | w = colWid; | 1463 | w = colWid; |
1463 | h = cellHei ; | 1464 | h = cellHei ; |
1464 | for ( i = 0; i < mCells.count(); ++i) { | 1465 | for ( i = 0; i < mCells.count(); ++i) { |
1465 | //qDebug("iii %d ", i); | 1466 | //qDebug("iii %d ", i); |
1466 | w = colWid; | 1467 | w = colWid; |
1467 | if ( ((i) % 7) >= 7-colModulo ) { | 1468 | if ( ((i) % 7) >= 7-colModulo ) { |
1468 | ++w; | 1469 | ++w; |
1469 | } | 1470 | } |
1470 | if ( i == (6-rowModulo)*7) | 1471 | if ( i == (6-rowModulo)*7) |
1471 | ++h; | 1472 | ++h; |
1472 | if ( combinedSatSun ) { | 1473 | if ( combinedSatSun ) { |
1473 | if ( (i)%7 >= daysToShow-1 ) { | 1474 | if ( (i)%7 >= daysToShow-1 ) { |
1474 | if ( (i)%7 == daysToShow-1 ) { | 1475 | if ( (i)%7 == daysToShow-1 ) { |
1475 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,h/2 ); | 1476 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,h/2 ); |
1476 | x -= w ;y += h/2; | 1477 | x -= w ;y += h/2; |
1477 | } else { | 1478 | } else { |
1478 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,h-h/2 ); | 1479 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,h-h/2 ); |
1479 | y -= h/2; | 1480 | y -= h/2; |
1480 | } | 1481 | } |
1481 | } else | 1482 | } else |
1482 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); | 1483 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); |
1483 | 1484 | ||
1484 | } | 1485 | } |
1485 | else | 1486 | else |
1486 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); | 1487 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); |
1487 | x += w; | 1488 | x += w; |
1488 | if ( x + w/2 > wid ) { | 1489 | if ( x + w/2 > wid ) { |
1489 | x = 0; | 1490 | x = 0; |
1490 | y += h; | 1491 | y += h; |
1491 | } | 1492 | } |
1492 | } | 1493 | } |
1493 | y= dayLabelHei; | 1494 | y= dayLabelHei; |
1494 | h = cellHei ; | 1495 | h = cellHei ; |
1495 | for ( i = 0; i < 6; i++) { | 1496 | for ( i = 0; i < 6; i++) { |
1496 | if ( i == (6-rowModulo)) | 1497 | if ( i == (6-rowModulo)) |
1497 | ++h; | 1498 | ++h; |
1498 | mWeekLabels[i]->setGeometry( 0,y,weeklabelwid,h); | 1499 | mWeekLabels[i]->setGeometry( 0,y,weeklabelwid,h); |
1499 | y += h; | 1500 | y += h; |
1500 | } | 1501 | } |
1501 | mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei); | 1502 | mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei); |
1502 | // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); | 1503 | // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); |
1503 | //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); | 1504 | //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); |
1504 | mShortDayLabels = mDayLabels[0]->width() < mWidthLongDayLabel ; | 1505 | mShortDayLabels = mDayLabels[0]->width() < mWidthLongDayLabel ; |
1505 | updateDayLabels(); | 1506 | updateDayLabels(); |
1506 | //bool forceUpdate = !updatePossible; | 1507 | //bool forceUpdate = !updatePossible; |
1507 | updatePossible = true; | 1508 | updatePossible = true; |
1508 | //mWeekLabels[mNumWeeks]->setText( i18n("W")); | 1509 | //mWeekLabels[mNumWeeks]->setText( i18n("W")); |
1509 | } | 1510 | } |
1510 | 1511 | ||
1511 | void KOMonthView::showContextMenu( Incidence *incidence ) | 1512 | void KOMonthView::showContextMenu( Incidence *incidence ) |
1512 | { | 1513 | { |
1513 | mContextMenu->showIncidencePopup(incidence); | 1514 | mContextMenu->showIncidencePopup(incidence); |
1514 | /* | 1515 | /* |
1515 | if( incidence && incidence->type() == "Event" ) { | 1516 | if( incidence && incidence->type() == "Event" ) { |
1516 | Event *event = static_cast<Event *>(incidence); | 1517 | Event *event = static_cast<Event *>(incidence); |
1517 | mContextMenu->showEventPopup(event); | 1518 | mContextMenu->showEventPopup(event); |
1518 | } else { | 1519 | } else { |
1519 | kdDebug() << "MonthView::showContextMenu(): cast failed." << endl; | 1520 | kdDebug() << "MonthView::showContextMenu(): cast failed." << endl; |
1520 | } | 1521 | } |
1521 | */ | 1522 | */ |
1522 | } | 1523 | } |
1523 | MonthViewCell * KOMonthView::selectedCell( ) | 1524 | MonthViewCell * KOMonthView::selectedCell( ) |
1524 | { | 1525 | { |
1525 | return mSelectedCell; | 1526 | return mSelectedCell; |
1526 | } | 1527 | } |
1527 | void KOMonthView::setSelectedCell( MonthViewCell *cell ) | 1528 | void KOMonthView::setSelectedCell( MonthViewCell *cell ) |
1528 | { | 1529 | { |
1529 | // qDebug("KOMonthView::setSelectedCell "); | 1530 | // qDebug("KOMonthView::setSelectedCell "); |
1530 | if ( mSelectedCell && mSelectedCell != cell ) { | 1531 | if ( mSelectedCell && mSelectedCell != cell ) { |
1531 | MonthViewCell * mvc = mSelectedCell; | 1532 | MonthViewCell * mvc = mSelectedCell; |
1532 | mSelectedCell = cell; | 1533 | mSelectedCell = cell; |
1533 | mvc->deselect(); | 1534 | mvc->deselect(); |
1534 | } else | 1535 | } else |
1535 | mSelectedCell = cell; | 1536 | mSelectedCell = cell; |
1536 | // if ( mSelectedCell ) | 1537 | // if ( mSelectedCell ) |
1537 | // mSelectedCell->select(); | 1538 | // mSelectedCell->select(); |
1538 | if ( !mSelectedCell ) | 1539 | if ( !mSelectedCell ) |
1539 | emit incidenceSelected( 0 ); | 1540 | emit incidenceSelected( 0 ); |
1540 | else | 1541 | else |
1541 | emit incidenceSelected( mSelectedCell->selectedIncidence() ); | 1542 | emit incidenceSelected( mSelectedCell->selectedIncidence() ); |
1542 | } | 1543 | } |
1543 | 1544 | ||
1544 | void KOMonthView::processSelectionChange() | 1545 | void KOMonthView::processSelectionChange() |
1545 | { | 1546 | { |
1546 | QPtrList<Incidence> incidences = selectedIncidences(); | 1547 | QPtrList<Incidence> incidences = selectedIncidences(); |
1547 | if (incidences.count() > 0) { | 1548 | if (incidences.count() > 0) { |
1548 | emit incidenceSelected( incidences.first() ); | 1549 | emit incidenceSelected( incidences.first() ); |
1549 | } else { | 1550 | } else { |
1550 | emit incidenceSelected( 0 ); | 1551 | emit incidenceSelected( 0 ); |
1551 | } | 1552 | } |
1552 | } | 1553 | } |
1553 | 1554 | ||
1554 | void KOMonthView::clearSelection() | 1555 | void KOMonthView::clearSelection() |
1555 | { | 1556 | { |
1556 | if ( mSelectedCell ) { | 1557 | if ( mSelectedCell ) { |
1557 | mSelectedCell->deselect(); | 1558 | mSelectedCell->deselect(); |
1558 | mSelectedCell = 0; | 1559 | mSelectedCell = 0; |
1559 | } | 1560 | } |
1560 | } | 1561 | } |
1561 | void KOMonthView::keyPressEvent ( QKeyEvent * e ) | 1562 | void KOMonthView::keyPressEvent ( QKeyEvent * e ) |
1562 | { | 1563 | { |
1563 | //qDebug("KOMonthView::keyPressEvent "); | 1564 | //qDebug("KOMonthView::keyPressEvent "); |
1564 | switch(e->key()) { | 1565 | switch(e->key()) { |
1565 | case Key_Up: | 1566 | case Key_Up: |
1566 | { | 1567 | { |
1567 | emit prevMonth(); | 1568 | emit prevMonth(); |
1568 | if ( mShowWeekView ) | 1569 | if ( mShowWeekView ) |
1569 | mCellsW[0]->setFocus(); | 1570 | mCellsW[0]->setFocus(); |
1570 | else | 1571 | else |
1571 | mCells[0]->setFocus(); | 1572 | mCells[0]->setFocus(); |
1572 | } | 1573 | } |
1573 | e->accept(); | 1574 | e->accept(); |
1574 | break; | 1575 | break; |
1575 | case Key_Down: | 1576 | case Key_Down: |
1576 | { | 1577 | { |
1577 | emit nextMonth(); | 1578 | emit nextMonth(); |
1578 | if ( mShowWeekView ) | 1579 | if ( mShowWeekView ) |
1579 | mCellsW[0]->setFocus(); | 1580 | mCellsW[0]->setFocus(); |
1580 | else | 1581 | else |
1581 | mCells[0]->setFocus(); | 1582 | mCells[0]->setFocus(); |
1582 | 1583 | ||
1583 | } | 1584 | } |
1584 | e->accept(); | 1585 | e->accept(); |
1585 | break; | 1586 | break; |
1586 | case Key_Return: | 1587 | case Key_Return: |
1587 | case Key_Enter: | 1588 | case Key_Enter: |
1588 | { | 1589 | { |
1589 | selectInternalWeekNum ( currentWeek() ); | 1590 | selectInternalWeekNum ( currentWeek() ); |
1590 | } | 1591 | } |
1591 | e->accept(); | 1592 | e->accept(); |
1592 | break; | 1593 | break; |
1593 | default: | 1594 | default: |
1594 | e->ignore(); | 1595 | e->ignore(); |
1595 | break; | 1596 | break; |
1596 | } | 1597 | } |
1597 | } | 1598 | } |