-rw-r--r-- | libkdepim/kdatepicker.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/libkdepim/kdatepicker.cpp b/libkdepim/kdatepicker.cpp index 25b4e81..68ef943 100644 --- a/libkdepim/kdatepicker.cpp +++ b/libkdepim/kdatepicker.cpp @@ -91,128 +91,132 @@ KDatePicker::~KDatePicker() void KDatePicker::resizeEvent(QResizeEvent*) { QWidget *buttons[] = { yearBackward, monthBackward, selectMonth, selectYear, monthForward, yearForward }; const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); QSize sizes[NoOfButtons]; int buttonHeight=0; int count; int w; int x=0; // ----- calculate button row height: for(count=0; count<NoOfButtons; ++count) { int xS = buttons[count]->sizeHint().width(); int yS = buttons[count]->sizeHint().height(); if ( QApplication::desktop()->width() < 320 ) sizes[count]=QSize ( xS+4, yS ); else sizes[count]=QSize ( xS+10, yS ); buttonHeight=QMAX(buttonHeight, sizes[count].height()); } buttonHeight += 10; // ----- calculate size of the month button: w=0; for(count=0; count<NoOfButtons; ++count) { if(buttons[count]!=selectMonth) { w+=sizes[count].width(); } else { x=count; } } sizes[x].setWidth(width()-w); // stretch the month button // ----- place the buttons: x=0; for(count=0; count<NoOfButtons; ++count) { w=sizes[count].width(); buttons[count]->setGeometry(x, 0, w, buttonHeight); x+=w; } // ----- place the line edit for direct input: sizes[0]=lineDate->sizeHint(); //line->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); int todaywid = todayBut->sizeHint().width(); todayBut->setGeometry(0, height()-sizes[0].height(),todaywid, sizes[0].height()); lineDate->setGeometry(0+todaywid, height()-sizes[0].height(), width()-todaywid, sizes[0].height()); // ----- adjust the table: table->setGeometry(0, buttonHeight, width(), height()-buttonHeight-sizes[0].height()); } void KDatePicker::dateChangedSlot(QDate date) { lineDate->setDate( date );//(KGlobal::locale()->formatDate(date, true)); //line->setText(KGlobal::locale()->formatDate(date, true)); + QString temp; + selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); + temp.setNum(date.year()); + selectYear->setText(temp); emit(dateChanged(date)); } void KDatePicker::tableClickedSlot() { emit(dateSelected(table->getDate())); emit(tableClicked()); } const QDate& KDatePicker::getDate() const { return table->getDate(); } const QDate & KDatePicker::date() const { return table->getDate(); } void KDatePicker::goToday() { slotSetDate( QDate::currentDate() ); } void KDatePicker::slotSetDate( QDate date ) { if(date.isValid()) { QString temp; // ----- table->setDate(date); selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); temp.setNum(date.year()); selectYear->setText(temp); //line->setText(KGlobal::locale()->formatDate(date, true)); lineDate->setDate( date ); } } bool KDatePicker::setDate(const QDate& date) { table->setFocus(); if(date.isValid()) { QString temp; // ----- table->setDate(date); selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); temp.setNum(date.year()); selectYear->setText(temp); //line->setText(KGlobal::locale()->formatDate(date, true)); lineDate->setDate( date ); return true; } else { return false; } } @@ -414,77 +418,81 @@ KDatePicker::sizeHint() const cx=QMAX(cx, tableSize.width()); // line edit ignored if ( cx > QApplication::desktop()->width() -5 ) cx = QApplication::desktop()->width() -5; // ----- calculate height hint: cy+=tableSize.height()+lineDate->sizeHint().height(); return QSize(cx, cy); } void KDatePicker::setFontSize(int s) { QWidget *buttons[]= { // yearBackward, // monthBackward, selectMonth, selectYear, // monthForward, // yearForward }; const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); int count; QFont font; QRect r; // ----- fontsize=s; for(count=0; count<NoOfButtons; ++count) { font=buttons[count]->font(); font.setPointSize(s); buttons[count]->setFont(font); } QFontMetrics metrics(selectMonth->fontMetrics()); for(int i=1; i <= 12; ++i) { // maxMonthRect is used by sizeHint() r=metrics.boundingRect(KGlobal::locale()->monthName(i, false)); maxMonthRect.setWidth(QMAX(r.width(), maxMonthRect.width())); maxMonthRect.setHeight(QMAX(r.height(), maxMonthRect.height())); } table->setFontSize(s); } void KDatePicker::virtual_hook( int id, void* data ) { /*BASE::virtual_hook( id, data );*/ } void KDatePicker::keyPressEvent ( QKeyEvent * e ) { switch ( e->key() ) { case Qt::Key_Right: monthForwardClicked(); break; case Qt::Key_Left: monthBackwardClicked(); break; case Qt::Key_Down: yearForwardClicked(); break; case Qt::Key_Up: yearBackwardClicked(); break; + case Qt::Key_T: + goToday(); + break; + case Qt::Key_Return: case Qt::Key_Enter: case Qt::Key_Space: tableClickedSlot(); break; case Qt::Key_Escape: e->ignore(); break; default: break; } } |