summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdatetbl.cpp28
-rw-r--r--microkde/kdatetbl.h1
2 files changed, 21 insertions, 8 deletions
diff --git a/microkde/kdatetbl.cpp b/microkde/kdatetbl.cpp
index 0a2d1f5..146291b 100644
--- a/microkde/kdatetbl.cpp
+++ b/microkde/kdatetbl.cpp
@@ -74,48 +74,49 @@ KDateValidator::date(const QString& text, QDate& d) const
74 74
75void 75void
76KDateValidator::fixup( QString& ) const 76KDateValidator::fixup( QString& ) const
77{ 77{
78 78
79} 79}
80 80
81KDateTable::KDateTable(QWidget *parent, QDate date_, const char* name, WFlags f) 81KDateTable::KDateTable(QWidget *parent, QDate date_, const char* name, WFlags f)
82 : QGridView(parent, name, f) 82 : QGridView(parent, name, f)
83{ 83{
84 setFontSize(10); 84 setFontSize(10);
85 if(!date_.isValid()) 85 if(!date_.isValid())
86 { 86 {
87 date_=QDate::currentDate(); 87 date_=QDate::currentDate();
88 } 88 }
89 setFocusPolicy( QWidget::StrongFocus ); 89 setFocusPolicy( QWidget::StrongFocus );
90 setNumRows(7); // 6 weeks max + headline 90 setNumRows(7); // 6 weeks max + headline
91 setNumCols(7); // 7 days a week 91 setNumCols(7); // 7 days a week
92 setHScrollBarMode(AlwaysOff); 92 setHScrollBarMode(AlwaysOff);
93 setVScrollBarMode(AlwaysOff); 93 setVScrollBarMode(AlwaysOff);
94 viewport()->setBackgroundColor(QColor(220,245,255)); 94 viewport()->setBackgroundColor(QColor(220,245,255));
95#if 0 95#if 0
96 viewport()->setEraseColor(lightGray); 96 viewport()->setEraseColor(lightGray);
97#endif 97#endif
98 mMarkCurrent = false;
98 setDate(date_); // this initializes firstday, numdays, numDaysPrevMonth 99 setDate(date_); // this initializes firstday, numdays, numDaysPrevMonth
99} 100}
100 101
101void 102void
102KDateTable::paintCell(QPainter *painter, int row, int col) 103KDateTable::paintCell(QPainter *painter, int row, int col)
103{ 104{
104 QRect rect; 105 QRect rect;
105 QString text; 106 QString text;
106 QPen pen; 107 QPen pen;
107 int w=cellWidth(); 108 int w=cellWidth();
108 int h=cellHeight(); 109 int h=cellHeight();
109 int pos; 110 int pos;
110 QBrush brushBlue(blue); 111 QBrush brushBlue(blue);
111 QBrush brushLightblue(QColor(220,245,255)); 112 QBrush brushLightblue(QColor(220,245,255));
112 QFont font=KGlobalSettings::generalFont(); 113 QFont font=KGlobalSettings::generalFont();
113 // ----- 114 // -----
114 font.setPointSize(fontsize); 115 font.setPointSize(fontsize);
115 if(row==0) 116 if(row==0)
116 { // we are drawing the headline 117 { // we are drawing the headline
117 font.setBold(true); 118 font.setBold(true);
118 painter->setFont(font); 119 painter->setFont(font);
119 bool normalday = true; 120 bool normalday = true;
120 QString daystr; 121 QString daystr;
121 if (KGlobal::locale()->weekStartsMonday()) 122 if (KGlobal::locale()->weekStartsMonday())
@@ -149,62 +150,71 @@ KDateTable::paintCell(QPainter *painter, int row, int col)
149 } else { 150 } else {
150 painter->setFont(font); 151 painter->setFont(font);
151 pos=7*(row-1)+col; 152 pos=7*(row-1)+col;
152 if (KGlobal::locale()->weekStartsMonday()) 153 if (KGlobal::locale()->weekStartsMonday())
153 pos++; 154 pos++;
154 if(pos<firstday || (firstday+numdays<=pos)) 155 if(pos<firstday || (firstday+numdays<=pos))
155 { // we are either 156 { // we are either
156 // ° painting a day of the previous month or 157 // ° painting a day of the previous month or
157 // ° painting a day of the following month 158 // ° painting a day of the following month
158 if(pos<firstday) 159 if(pos<firstday)
159 { // previous month 160 { // previous month
160 text.setNum(numDaysPrevMonth+pos-firstday+1); 161 text.setNum(numDaysPrevMonth+pos-firstday+1);
161 } else { // following month 162 } else { // following month
162 text.setNum(pos-firstday-numdays+1); 163 text.setNum(pos-firstday-numdays+1);
163 } 164 }
164 painter->setPen(gray); 165 painter->setPen(gray);
165 } else { // paint a day of the current month 166 } else { // paint a day of the current month
166 text.setNum(pos-firstday+1); 167 text.setNum(pos-firstday+1);
167 painter->setPen(black); 168 painter->setPen(black);
168 } 169 }
169 170
170 pen=painter->pen(); 171 pen=painter->pen();
171 if(firstday+date.day()-1==pos) 172 if(firstday+date.day()-1==pos)
172 { 173 {
174 if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos)
175 painter->setPen(green);
176 else
177 painter->setPen(red);
173 if(hasFocus()) 178 if(hasFocus())
174 { // draw the currently selected date 179 {
175 painter->setPen(red); 180 painter->setBrush(darkRed);
176 painter->setBrush(darkRed); 181 pen=white;
177 pen=white;
178 } else { 182 } else {
179 painter->setPen(darkGray);
180 painter->setBrush(darkGray); 183 painter->setBrush(darkGray);
181 pen=white; 184 pen=white;
182 } 185 }
183 } else { 186 } else {
184 painter->setBrush(QColor(220,245,255)); 187 if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos)
185 painter->setPen(QColor(220,245,255)); 188 {
186 } 189 painter->setPen(green);
190 painter->setBrush(darkGreen);
191 pen=white;
192 } else {
193 painter->setBrush(QColor(220,245,255));
194 painter->setPen(QColor(220,245,255));
195 }
196 }
187 painter->drawRect(0, 0, w, h); 197 painter->drawRect(0, 0, w, h);
188 painter->setPen(pen); 198 painter->setPen(pen);
189 painter->drawText(0, 0, w, h, AlignCenter, text, -1, &rect); 199 painter->drawText(0, 0, w, h, AlignCenter, text, -1, &rect);
190 } 200 }
191 if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width()); 201 if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width());
192 if(rect.height()>maxCell.height()) maxCell.setHeight(rect.height()); 202 if(rect.height()>maxCell.height()) maxCell.setHeight(rect.height());
193} 203}
194 204
195void 205void
196KDateTable::keyPressEvent( QKeyEvent *e ) 206KDateTable::keyPressEvent( QKeyEvent *e )
197{ 207{
198 /* 208 /*
199 // not working properly 209 // not working properly
200 if ( e->key() == Qt::Key_Prior ) { 210 if ( e->key() == Qt::Key_Prior ) {
201 if ( date.month() == 1 ) { 211 if ( date.month() == 1 ) {
202 KNotifyClient::beep(); 212 KNotifyClient::beep();
203 return; 213 return;
204 } 214 }
205 int day = date.day(); 215 int day = date.day();
206 if ( day > 27 ) 216 if ( day > 27 )
207 while ( !QDate::isValid( date.year(), date.month()-1, day ) ) 217 while ( !QDate::isValid( date.year(), date.month()-1, day ) )
208 day--; 218 day--;
209 setDate(QDate(date.year(), date.month()-1, day)); 219 setDate(QDate(date.year(), date.month()-1, day));
210 return; 220 return;
@@ -336,59 +346,61 @@ KDateTable::contentsMousePressEvent(QMouseEvent *e)
336 pos=7*(row-1)+col+1; 346 pos=7*(row-1)+col+1;
337 if(pos+dayoff<=firstday) 347 if(pos+dayoff<=firstday)
338 { // this day is in the previous month 348 { // this day is in the previous month
339 KNotifyClient::beep(); 349 KNotifyClient::beep();
340 return; 350 return;
341 } 351 }
342 if(firstday+numdays<pos+dayoff) 352 if(firstday+numdays<pos+dayoff)
343 { // this date is in the next month 353 { // this date is in the next month
344 KNotifyClient::beep(); 354 KNotifyClient::beep();
345 return; 355 return;
346 } 356 }
347 temp=firstday+date.day()-dayoff-1; 357 temp=firstday+date.day()-dayoff-1;
348 setDate(QDate(date.year(), date.month(), pos-firstday+dayoff)); 358 setDate(QDate(date.year(), date.month(), pos-firstday+dayoff));
349 updateCell(temp/7+1, temp%7); // Update the previously selected cell 359 updateCell(temp/7+1, temp%7); // Update the previously selected cell
350 updateCell(row, col); // Update the selected cell 360 updateCell(row, col); // Update the selected cell
351 // assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid()); 361 // assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid());
352 emit(tableClicked()); 362 emit(tableClicked());
353} 363}
354 364
355bool 365bool
356KDateTable::setDate(const QDate& date_) 366KDateTable::setDate(const QDate& date_)
357{ 367{
358 bool changed=false; 368 bool changed=false;
359 QDate temp; 369 QDate temp;
370 mMarkCurrent = false;
360 // ----- 371 // -----
361 if(!date_.isValid()) 372 if(!date_.isValid())
362 { 373 {
363 kdDebug() << "KDateTable::setDate: refusing to set invalid date." << endl; 374 kdDebug() << "KDateTable::setDate: refusing to set invalid date." << endl;
364 return false; 375 return false;
365 } 376 }
366 if(date!=date_) 377 if(date!=date_)
367 { 378 {
368 date=date_; 379 date=date_;
369 changed=true; 380 changed=true;
370 } 381 }
382 mMarkCurrent = ( date.month() == QDate::currentDate().month() && date.year() == QDate::currentDate().year() );
371 temp.setYMD(date.year(), date.month(), 1); 383 temp.setYMD(date.year(), date.month(), 1);
372 firstday=temp.dayOfWeek(); 384 firstday=temp.dayOfWeek();
373 if(firstday==1) firstday=8; 385 if(firstday==1) firstday=8;
374 numdays=date.daysInMonth(); 386 numdays=date.daysInMonth();
375 if(date.month()==1) 387 if(date.month()==1)
376 { // set to december of previous year 388 { // set to december of previous year
377 temp.setYMD(date.year()-1, 12, 1); 389 temp.setYMD(date.year()-1, 12, 1);
378 } else { // set to previous month 390 } else { // set to previous month
379 temp.setYMD(date.year(), date.month()-1, 1); 391 temp.setYMD(date.year(), date.month()-1, 1);
380 } 392 }
381 numDaysPrevMonth=temp.daysInMonth(); 393 numDaysPrevMonth=temp.daysInMonth();
382 if(changed) 394 if(changed)
383 { 395 {
384 repaintContents(false); 396 repaintContents(false);
385 } 397 }
386 emit(dateChanged(date)); 398 emit(dateChanged(date));
387 return true; 399 return true;
388} 400}
389 401
390const QDate& 402const QDate&
391KDateTable::getDate() const 403KDateTable::getDate() const
392{ 404{
393 return date; 405 return date;
394} 406}
diff --git a/microkde/kdatetbl.h b/microkde/kdatetbl.h
index df7b7ef..b4d3e16 100644
--- a/microkde/kdatetbl.h
+++ b/microkde/kdatetbl.h
@@ -224,48 +224,49 @@ public:
224 */ 224 */
225 KDateTable(QWidget *parent=0, 225 KDateTable(QWidget *parent=0,
226 QDate date=QDate::currentDate(), 226 QDate date=QDate::currentDate(),
227 const char* name=0, WFlags f=0); 227 const char* name=0, WFlags f=0);
228 /** 228 /**
229 * Returns a recommended size for the widget. 229 * Returns a recommended size for the widget.
230 * To save some time, the size of the largest used cell content is 230 * To save some time, the size of the largest used cell content is
231 * calculated in each paintCell() call, since all calculations have 231 * calculated in each paintCell() call, since all calculations have
232 * to be done there anyway. The size is stored in maxCell. The 232 * to be done there anyway. The size is stored in maxCell. The
233 * sizeHint() simply returns a multiple of maxCell. 233 * sizeHint() simply returns a multiple of maxCell.
234 */ 234 */
235 virtual QSize sizeHint() const; 235 virtual QSize sizeHint() const;
236 /** 236 /**
237 * Set the font size of the date table. 237 * Set the font size of the date table.
238 */ 238 */
239 void setFontSize(int size); 239 void setFontSize(int size);
240 /** 240 /**
241 * Select and display this date. 241 * Select and display this date.
242 */ 242 */
243 bool setDate(const QDate&); 243 bool setDate(const QDate&);
244 const QDate& getDate() const; 244 const QDate& getDate() const;
245 245
246 246
247protected: 247protected:
248 bool mMarkCurrent;
248 /** 249 /**
249 * Paint a cell. 250 * Paint a cell.
250 */ 251 */
251 virtual void paintCell(QPainter*, int, int); 252 virtual void paintCell(QPainter*, int, int);
252 /** 253 /**
253 * Handle the resize events. 254 * Handle the resize events.
254 */ 255 */
255 virtual void viewportResizeEvent(QResizeEvent *); 256 virtual void viewportResizeEvent(QResizeEvent *);
256 /** 257 /**
257 * React on mouse clicks that select a date. 258 * React on mouse clicks that select a date.
258 */ 259 */
259 virtual void contentsMousePressEvent(QMouseEvent *); 260 virtual void contentsMousePressEvent(QMouseEvent *);
260 virtual void keyPressEvent( QKeyEvent *e ); 261 virtual void keyPressEvent( QKeyEvent *e );
261 virtual void focusInEvent( QFocusEvent *e ); 262 virtual void focusInEvent( QFocusEvent *e );
262 virtual void focusOutEvent( QFocusEvent *e ); 263 virtual void focusOutEvent( QFocusEvent *e );
263 /** 264 /**
264 * The font size of the displayed text. 265 * The font size of the displayed text.
265 */ 266 */
266 int fontsize; 267 int fontsize;
267 /** 268 /**
268 * The currently selected date. 269 * The currently selected date.
269 */ 270 */
270 QDate date; 271 QDate date;
271 /** 272 /**