-rw-r--r-- | libkdepim/kdatepicker.cpp | 12 | ||||
-rw-r--r-- | libkdepim/kdatepicker.h | 2 |
2 files changed, 13 insertions, 1 deletions
diff --git a/libkdepim/kdatepicker.cpp b/libkdepim/kdatepicker.cpp index c13734f..77793c4 100644 --- a/libkdepim/kdatepicker.cpp +++ b/libkdepim/kdatepicker.cpp | |||
@@ -42,16 +42,17 @@ | |||
42 | KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name) | 42 | KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name) |
43 | : QFrame(parent,name), | 43 | : QFrame(parent,name), |
44 | yearForward(new QToolButton(this)), | 44 | yearForward(new QToolButton(this)), |
45 | yearBackward(new QToolButton(this)), | 45 | yearBackward(new QToolButton(this)), |
46 | monthForward(new QToolButton(this)), | 46 | monthForward(new QToolButton(this)), |
47 | monthBackward(new QToolButton(this)), | 47 | monthBackward(new QToolButton(this)), |
48 | selectMonth(new QToolButton(this)), | 48 | selectMonth(new QToolButton(this)), |
49 | selectYear(new QToolButton(this)), | 49 | selectYear(new QToolButton(this)), |
50 | todayBut(new QToolButton(this)), | ||
50 | //line(new QLineEdit(this)), | 51 | //line(new QLineEdit(this)), |
51 | val(new KDateValidator(this)) | 52 | val(new KDateValidator(this)) |
52 | //table(new KDateTable(this)), | 53 | //table(new KDateTable(this)), |
53 | //fontsize(1) | 54 | //fontsize(1) |
54 | { | 55 | { |
55 | QFont fo = KGlobalSettings::generalFont(); | 56 | QFont fo = KGlobalSettings::generalFont(); |
56 | int add = 2; | 57 | int add = 2; |
57 | if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 ) | 58 | if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 ) |
@@ -61,25 +62,27 @@ KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name) | |||
61 | table = new KDateTable(this); | 62 | table = new KDateTable(this); |
62 | setFontSize(font().pointSize()); | 63 | setFontSize(font().pointSize()); |
63 | //line->setValidator(val); | 64 | //line->setValidator(val); |
64 | lineDate = new KDateEdit( this, "dateediipicker", true ); | 65 | lineDate = new KDateEdit( this, "dateediipicker", true ); |
65 | yearForward->setPixmap(SmallIcon("2rightarrowB")); | 66 | yearForward->setPixmap(SmallIcon("2rightarrowB")); |
66 | yearBackward->setPixmap(SmallIcon("2leftarrowB")); | 67 | yearBackward->setPixmap(SmallIcon("2leftarrowB")); |
67 | monthForward->setPixmap(SmallIcon("1rightarrowB")); | 68 | monthForward->setPixmap(SmallIcon("1rightarrowB")); |
68 | monthBackward->setPixmap(SmallIcon("1leftarrowB")); | 69 | monthBackward->setPixmap(SmallIcon("1leftarrowB")); |
70 | todayBut->setPixmap(SmallIcon("today")); | ||
69 | setDate(dt); // set button texts | 71 | setDate(dt); // set button texts |
70 | connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate))); | 72 | connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate))); |
71 | connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot())); | 73 | connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot())); |
72 | connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked())); | 74 | connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked())); |
73 | connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked())); | 75 | connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked())); |
74 | connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked())); | 76 | connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked())); |
75 | connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked())); | 77 | connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked())); |
76 | connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked())); | 78 | connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked())); |
77 | connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked())); | 79 | connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked())); |
80 | connect(todayBut, SIGNAL(clicked()), SLOT(goToday())); | ||
78 | //connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); | 81 | //connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); |
79 | connect(lineDate, SIGNAL(dateChanged(QDate)), SLOT(slotSetDate(QDate))); | 82 | connect(lineDate, SIGNAL(dateChanged(QDate)), SLOT(slotSetDate(QDate))); |
80 | connect(lineDate, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); | 83 | connect(lineDate, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); |
81 | table->setFocus(); | 84 | table->setFocus(); |
82 | 85 | ||
83 | } | 86 | } |
84 | 87 | ||
85 | KDatePicker::~KDatePicker() | 88 | KDatePicker::~KDatePicker() |
@@ -131,17 +134,19 @@ KDatePicker::resizeEvent(QResizeEvent*) | |||
131 | { | 134 | { |
132 | w=sizes[count].width(); | 135 | w=sizes[count].width(); |
133 | buttons[count]->setGeometry(x, 0, w, buttonHeight); | 136 | buttons[count]->setGeometry(x, 0, w, buttonHeight); |
134 | x+=w; | 137 | x+=w; |
135 | } | 138 | } |
136 | // ----- place the line edit for direct input: | 139 | // ----- place the line edit for direct input: |
137 | sizes[0]=lineDate->sizeHint(); | 140 | sizes[0]=lineDate->sizeHint(); |
138 | //line->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); | 141 | //line->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); |
139 | lineDate->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); | 142 | int todaywid = todayBut->sizeHint().width(); |
143 | todayBut->setGeometry(0, height()-sizes[0].height(),todaywid, sizes[0].height()); | ||
144 | lineDate->setGeometry(0+todaywid, height()-sizes[0].height(), width()-todaywid, sizes[0].height()); | ||
140 | // ----- adjust the table: | 145 | // ----- adjust the table: |
141 | table->setGeometry(0, buttonHeight, width(), | 146 | table->setGeometry(0, buttonHeight, width(), |
142 | height()-buttonHeight-sizes[0].height()); | 147 | height()-buttonHeight-sizes[0].height()); |
143 | } | 148 | } |
144 | 149 | ||
145 | void | 150 | void |
146 | KDatePicker::dateChangedSlot(QDate date) | 151 | KDatePicker::dateChangedSlot(QDate date) |
147 | { | 152 | { |
@@ -165,16 +170,21 @@ KDatePicker::getDate() const | |||
165 | } | 170 | } |
166 | 171 | ||
167 | const QDate & | 172 | const QDate & |
168 | KDatePicker::date() const | 173 | KDatePicker::date() const |
169 | { | 174 | { |
170 | return table->getDate(); | 175 | return table->getDate(); |
171 | } | 176 | } |
172 | 177 | ||
178 | void KDatePicker::goToday() | ||
179 | { | ||
180 | slotSetDate( QDate::currentDate() ); | ||
181 | |||
182 | } | ||
173 | void KDatePicker::slotSetDate( QDate date ) | 183 | void KDatePicker::slotSetDate( QDate date ) |
174 | { | 184 | { |
175 | 185 | ||
176 | if(date.isValid()) { | 186 | if(date.isValid()) { |
177 | QString temp; | 187 | QString temp; |
178 | // ----- | 188 | // ----- |
179 | table->setDate(date); | 189 | table->setDate(date); |
180 | selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); | 190 | selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); |
diff --git a/libkdepim/kdatepicker.h b/libkdepim/kdatepicker.h index 6625357..3db9a89 100644 --- a/libkdepim/kdatepicker.h +++ b/libkdepim/kdatepicker.h | |||
@@ -102,16 +102,17 @@ public: | |||
102 | /** | 102 | /** |
103 | * Returns the font size of the widget elements. | 103 | * Returns the font size of the widget elements. |
104 | */ | 104 | */ |
105 | int fontSize() const | 105 | int fontSize() const |
106 | { return fontsize; } | 106 | { return fontsize; } |
107 | protected: | 107 | protected: |
108 | /// the resize event | 108 | /// the resize event |
109 | void resizeEvent(QResizeEvent*); | 109 | void resizeEvent(QResizeEvent*); |
110 | QToolButton *todayBut; | ||
110 | /// the year forward button | 111 | /// the year forward button |
111 | QToolButton *yearForward; | 112 | QToolButton *yearForward; |
112 | /// the year backward button | 113 | /// the year backward button |
113 | QToolButton *yearBackward; | 114 | QToolButton *yearBackward; |
114 | /// the month forward button | 115 | /// the month forward button |
115 | QToolButton *monthForward; | 116 | QToolButton *monthForward; |
116 | /// the month backward button | 117 | /// the month backward button |
117 | QToolButton *monthBackward; | 118 | QToolButton *monthBackward; |
@@ -136,16 +137,17 @@ protected slots: | |||
136 | void monthForwardClicked(); | 137 | void monthForwardClicked(); |
137 | void monthBackwardClicked(); | 138 | void monthBackwardClicked(); |
138 | void yearForwardClicked(); | 139 | void yearForwardClicked(); |
139 | void yearBackwardClicked(); | 140 | void yearBackwardClicked(); |
140 | void selectMonthClicked(); | 141 | void selectMonthClicked(); |
141 | void selectYearClicked(); | 142 | void selectYearClicked(); |
142 | void lineEnterPressed(); | 143 | void lineEnterPressed(); |
143 | void slotSetDate(QDate); | 144 | void slotSetDate(QDate); |
145 | void goToday(); | ||
144 | signals: | 146 | signals: |
145 | /** This signal is emitted each time the selected date is changed. | 147 | /** This signal is emitted each time the selected date is changed. |
146 | * Usually, this does not mean that the date has been entered, | 148 | * Usually, this does not mean that the date has been entered, |
147 | * since the date also changes, for example, when another month is | 149 | * since the date also changes, for example, when another month is |
148 | * selected. | 150 | * selected. |
149 | * @see dateSelected | 151 | * @see dateSelected |
150 | */ | 152 | */ |
151 | void dateChanged(QDate); | 153 | void dateChanged(QDate); |