-rw-r--r-- | microkde/kdatetbl.cpp | 28 | ||||
-rw-r--r-- | microkde/kdatetbl.h | 1 |
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 @@ -82,32 +82,33 @@ KDateTable::KDateTable(QWidget *parent, QDate date_, const char* name, WFlags f) : QGridView(parent, name, f) { setFontSize(10); if(!date_.isValid()) { date_=QDate::currentDate(); } setFocusPolicy( QWidget::StrongFocus ); setNumRows(7); // 6 weeks max + headline setNumCols(7); // 7 days a week setHScrollBarMode(AlwaysOff); setVScrollBarMode(AlwaysOff); viewport()->setBackgroundColor(QColor(220,245,255)); #if 0 viewport()->setEraseColor(lightGray); #endif + mMarkCurrent = false; setDate(date_); // this initializes firstday, numdays, numDaysPrevMonth } void KDateTable::paintCell(QPainter *painter, int row, int col) { QRect rect; QString text; QPen pen; int w=cellWidth(); int h=cellHeight(); int pos; QBrush brushBlue(blue); QBrush brushLightblue(QColor(220,245,255)); QFont font=KGlobalSettings::generalFont(); // ----- @@ -157,46 +158,55 @@ KDateTable::paintCell(QPainter *painter, int row, int col) // ° painting a day of the following month if(pos<firstday) { // previous month text.setNum(numDaysPrevMonth+pos-firstday+1); } else { // following month text.setNum(pos-firstday-numdays+1); } painter->setPen(gray); } else { // paint a day of the current month text.setNum(pos-firstday+1); painter->setPen(black); } pen=painter->pen(); if(firstday+date.day()-1==pos) { + if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos) + painter->setPen(green); + else + painter->setPen(red); if(hasFocus()) - { // draw the currently selected date - painter->setPen(red); - painter->setBrush(darkRed); - pen=white; + { + painter->setBrush(darkRed); + pen=white; } else { - painter->setPen(darkGray); painter->setBrush(darkGray); pen=white; } } else { - painter->setBrush(QColor(220,245,255)); - painter->setPen(QColor(220,245,255)); - } + if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos) + { + painter->setPen(green); + painter->setBrush(darkGreen); + pen=white; + } else { + painter->setBrush(QColor(220,245,255)); + painter->setPen(QColor(220,245,255)); + } + } painter->drawRect(0, 0, w, h); painter->setPen(pen); painter->drawText(0, 0, w, h, AlignCenter, text, -1, &rect); } if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width()); if(rect.height()>maxCell.height()) maxCell.setHeight(rect.height()); } void KDateTable::keyPressEvent( QKeyEvent *e ) { /* // not working properly if ( e->key() == Qt::Key_Prior ) { if ( date.month() == 1 ) { KNotifyClient::beep(); @@ -344,43 +354,45 @@ KDateTable::contentsMousePressEvent(QMouseEvent *e) KNotifyClient::beep(); return; } temp=firstday+date.day()-dayoff-1; setDate(QDate(date.year(), date.month(), pos-firstday+dayoff)); updateCell(temp/7+1, temp%7); // Update the previously selected cell updateCell(row, col); // Update the selected cell // assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid()); emit(tableClicked()); } bool KDateTable::setDate(const QDate& date_) { bool changed=false; QDate temp; + mMarkCurrent = false; // ----- if(!date_.isValid()) { kdDebug() << "KDateTable::setDate: refusing to set invalid date." << endl; return false; } if(date!=date_) { date=date_; changed=true; } + mMarkCurrent = ( date.month() == QDate::currentDate().month() && date.year() == QDate::currentDate().year() ); temp.setYMD(date.year(), date.month(), 1); firstday=temp.dayOfWeek(); if(firstday==1) firstday=8; numdays=date.daysInMonth(); if(date.month()==1) { // set to december of previous year temp.setYMD(date.year()-1, 12, 1); } else { // set to previous month temp.setYMD(date.year(), date.month()-1, 1); } numDaysPrevMonth=temp.daysInMonth(); if(changed) { repaintContents(false); } emit(dateChanged(date)); diff --git a/microkde/kdatetbl.h b/microkde/kdatetbl.h index df7b7ef..b4d3e16 100644 --- a/microkde/kdatetbl.h +++ b/microkde/kdatetbl.h @@ -232,32 +232,33 @@ public: * to be done there anyway. The size is stored in maxCell. The * sizeHint() simply returns a multiple of maxCell. */ virtual QSize sizeHint() const; /** * Set the font size of the date table. */ void setFontSize(int size); /** * Select and display this date. */ bool setDate(const QDate&); const QDate& getDate() const; protected: + bool mMarkCurrent; /** * Paint a cell. */ virtual void paintCell(QPainter*, int, int); /** * Handle the resize events. */ virtual void viewportResizeEvent(QResizeEvent *); /** * React on mouse clicks that select a date. */ virtual void contentsMousePressEvent(QMouseEvent *); virtual void keyPressEvent( QKeyEvent *e ); virtual void focusInEvent( QFocusEvent *e ); virtual void focusOutEvent( QFocusEvent *e ); /** |