-rw-r--r-- | libkdepim/kdatepicker.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/libkdepim/kdatepicker.cpp b/libkdepim/kdatepicker.cpp index 2be9c9e..d6e9b51 100644 --- a/libkdepim/kdatepicker.cpp +++ b/libkdepim/kdatepicker.cpp @@ -9,97 +9,100 @@ This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "kdatepicker.h" #include <kglobal.h> #include <kapplication.h> #include <klocale.h> #include <kiconloader.h> #include <qframe.h> #include <qpainter.h> #include <qdialog.h> #include <qtoolbutton.h> #include <qfont.h> #include <qapplication.h> #include <qlineedit.h> #include <qvalidator.h> #include <kdebug.h> #include <knotifyclient.h> #include <kglobalsettings.h> #include "kdatetbl.h" #include "kdateedit.h" //#include "kdatepicker.moc" KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name) : QFrame(parent,name), yearForward(new QToolButton(this)), yearBackward(new QToolButton(this)), monthForward(new QToolButton(this)), monthBackward(new QToolButton(this)), selectMonth(new QToolButton(this)), selectYear(new QToolButton(this)), //line(new QLineEdit(this)), val(new KDateValidator(this)) //table(new KDateTable(this)), //fontsize(1) { setFont ( KGlobalSettings::generalFont() ); table = new KDateTable(this); - setFontSize(font().pointSize()+2); + int add = 2; + if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 ) + add += 4; + setFontSize(font().pointSize()+add); //line->setValidator(val); lineDate = new KDateEdit( this, "dateediipicker", true ); yearForward->setPixmap(SmallIcon("2rightarrowB")); yearBackward->setPixmap(SmallIcon("2leftarrowB")); monthForward->setPixmap(SmallIcon("1rightarrowB")); monthBackward->setPixmap(SmallIcon("1leftarrowB")); setDate(dt); // set button texts connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate))); connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot())); connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked())); connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked())); connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked())); connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked())); connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked())); connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked())); //connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); connect(lineDate, SIGNAL(dateChanged(QDate)), SLOT(slotSetDate(QDate))); connect(lineDate, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); table->setFocus(); } 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 ); @@ -238,97 +241,97 @@ KDatePicker::monthBackwardClicked() { temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); } else { temp.setYMD(temp.year(), temp.month(), day); } // assert(temp.isValid()); setDate(temp); } void KDatePicker::yearForwardClicked() { QDate temp=table->getDate(); int day=temp.day(); // ----- temp.setYMD(temp.year()+1, temp.month(), 1); if(temp.daysInMonth()<day) { temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); } else { temp.setYMD(temp.year(), temp.month(), day); } // assert(temp.isValid()); setDate(temp); } void KDatePicker::yearBackwardClicked() { QDate temp=table->getDate(); int day=temp.day(); // ----- temp.setYMD(temp.year()-1, temp.month(), 1); if(temp.daysInMonth()<day) { temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); } else { temp.setYMD(temp.year(), temp.month(), day); } // assert(temp.isValid()); setDate(temp); } void KDatePicker::selectMonthClicked() { int month; KPopupFrame* popup = new KPopupFrame(this); - KDateInternalMonthPicker* picker = new KDateInternalMonthPicker(fontsize, popup); + KDateInternalMonthPicker* picker = new KDateInternalMonthPicker(popup); // ----- picker->resize(picker->sizeHint()); popup->setMainWidget(picker); picker->setFocus(); connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); if(popup->exec(selectMonth->mapToGlobal(QPoint(0, selectMonth->height())))) { QDate date; int day; // ----- month=picker->getResult(); date=table->getDate(); day=date.day(); // ----- construct a valid date in this month: date.setYMD(date.year(), month, 1); date.setYMD(date.year(), month, QMIN(day, date.daysInMonth())); // ----- set this month setDate(date); } else { KNotifyClient::beep(); } delete popup; } void KDatePicker::selectYearClicked() { int year; KPopupFrame* popup = new KPopupFrame(this); KDateInternalYearSelector* picker = new KDateInternalYearSelector(fontsize, popup); // ----- picker->resize(picker->sizeHint()); popup->setMainWidget(picker); connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); picker->setFocus(); if(popup->exec(selectYear->mapToGlobal(QPoint(0, selectMonth->height())))) { QDate date; int day; // ----- year=picker->getYear(); date=table->getDate(); day=date.day(); // ----- construct a valid date in this month: date.setYMD(year, date.month(), 1); date.setYMD(year, date.month(), QMIN(day, date.daysInMonth())); // ----- set this month setDate(date); |