summaryrefslogtreecommitdiffabout
path: root/microkde/kdatetbl.cpp
Side-by-side diff
Diffstat (limited to 'microkde/kdatetbl.cpp') (more/less context) (show whitespace changes)
-rw-r--r--microkde/kdatetbl.cpp28
1 files changed, 8 insertions, 20 deletions
diff --git a/microkde/kdatetbl.cpp b/microkde/kdatetbl.cpp
index 4271b55..353f78d 100644
--- a/microkde/kdatetbl.cpp
+++ b/microkde/kdatetbl.cpp
@@ -195,136 +195,124 @@ KDateTable::paintCell(QPainter *painter, int row, int col)
}
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();
return;
}
int day = date.day();
if ( day > 27 )
while ( !QDate::isValid( date.year(), date.month()-1, day ) )
day--;
setDate(QDate(date.year(), date.month()-1, day));
return;
}
if ( e->key() == Qt::Key_Next ) {
if ( date.month() == 12 ) {
KNotifyClient::beep();
return;
}
int day = date.day();
if ( day > 27 )
while ( !QDate::isValid( date.year(), date.month()+1, day ) )
day--;
setDate(QDate(date.year(), date.month()+1, day));
return;
}
*/
int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0;
int temp=firstday+date.day()-dayoff;
int pos = temp;
bool irgnore = true;
+ int add = 0;
if ( e->state() != Qt::ControlButton ) {
if ( e->key() == Qt::Key_Up ) {
- pos -= 7;
+ add -= 7;
irgnore = false;
}
if ( e->key() == Qt::Key_Down ) {
- pos += 7;
+ add += 7;
irgnore = false;
}
if ( e->key() == Qt::Key_Left ) {
- pos--;
+ --add;
irgnore = false;
}
if ( e->key() == Qt::Key_Right ) {
- pos++;
+ ++add;
irgnore = false;
}
}
- if ( irgnore )
+ if ( irgnore ) {
e->ignore();
-
- if(pos+dayoff<=firstday)
- { // this day is in the previous month
- KNotifyClient::beep();
- return;
- }
- if(firstday+numdays<pos+dayoff)
- { // this date is in the next month
- KNotifyClient::beep(i18n( "Month not long enough" ));
return;
}
- if ( pos == temp )
- return;
-
- setDate(QDate(date.year(), date.month(), pos-firstday+dayoff));
+ pos += add;
+ setDate(date.addDays( add ));
updateCell(temp/7+1, temp%7); // Update the previously selected cell
updateCell(pos/7+1, pos%7); // Update the selected cell
- assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid());
-
}
void
KDateTable::viewportResizeEvent(QResizeEvent * e)
{
QGridView::viewportResizeEvent(e);
setCellWidth(viewport()->width()/7);
setCellHeight(viewport()->height()/7);
}
void
KDateTable::setFontSize(int size)
{
int count;
QRect rect;
// ----- store rectangles:
fontsize=size;
QFont _font = font();
_font.setPointSize(fontsize);
setFont( _font );
_font.setBold( true );
QFontMetrics metrics(_font);
// ----- find largest day name:
maxCell.setWidth(0);
maxCell.setHeight(0);
for(count=0; count<7; ++count)
{
rect=metrics.boundingRect(KGlobal::locale()->weekDayName(count+1, true));
maxCell.setWidth(QMAX(maxCell.width(), rect.width()));
maxCell.setHeight(QMAX(maxCell.height(), rect.height()));
}
// ----- compare with a real wide number and add some space:
rect=metrics.boundingRect(QString::fromLatin1("88"));
maxCell.setWidth(QMAX(maxCell.width()+2, rect.width()));
#ifdef DESKTOP_VERSION
maxCell.setHeight(QMAX(maxCell.height()+8, rect.height()));
#else
maxCell.setHeight(QMAX(maxCell.height()+4, rect.height()));
#endif
if ( maxCell.width() * 1000 / maxCell.height() > 1900 ) {
maxCell.setHeight(maxCell.width() * 1000 / 1900 );
//qDebug("setmax ");
}
}