author | zautrix <zautrix> | 2005-02-08 14:12:31 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-02-08 14:12:31 (UTC) |
commit | 41111b332c2a5f1b2ec152df309b9199f5e9c921 (patch) (unidiff) | |
tree | 3a2e5c5a25cdb52f542b2fe84a03f94599be2fe3 /libkdepim/kdatepicker.cpp | |
parent | 9927a063f34bb826a4b5f7f7029308c9c66acbce (diff) | |
download | kdepimpi-41111b332c2a5f1b2ec152df309b9199f5e9c921.zip kdepimpi-41111b332c2a5f1b2ec152df309b9199f5e9c921.tar.gz kdepimpi-41111b332c2a5f1b2ec152df309b9199f5e9c921.tar.bz2 |
fixes
-rw-r--r-- | libkdepim/kdatepicker.cpp | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/libkdepim/kdatepicker.cpp b/libkdepim/kdatepicker.cpp index d8bc9f5..2be9c9e 100644 --- a/libkdepim/kdatepicker.cpp +++ b/libkdepim/kdatepicker.cpp | |||
@@ -1,253 +1,249 @@ | |||
1 | /* -*- C++ -*- | 1 | /* -*- C++ -*- |
2 | This file is part of the KDE libraries | 2 | This file is part of the KDE libraries |
3 | Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org) | 3 | Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org) |
4 | (C) 1998-2001 Mirko Boehm (mirko@kde.org) | 4 | (C) 1998-2001 Mirko Boehm (mirko@kde.org) |
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include "kdatepicker.h" | 21 | #include "kdatepicker.h" |
22 | #include <kglobal.h> | 22 | #include <kglobal.h> |
23 | #include <kapplication.h> | 23 | #include <kapplication.h> |
24 | #include <klocale.h> | 24 | #include <klocale.h> |
25 | #include <kiconloader.h> | 25 | #include <kiconloader.h> |
26 | #include <qframe.h> | 26 | #include <qframe.h> |
27 | #include <qpainter.h> | 27 | #include <qpainter.h> |
28 | #include <qdialog.h> | 28 | #include <qdialog.h> |
29 | #include <qtoolbutton.h> | 29 | #include <qtoolbutton.h> |
30 | #include <qfont.h> | 30 | #include <qfont.h> |
31 | #include <qapplication.h> | 31 | #include <qapplication.h> |
32 | #include <qlineedit.h> | 32 | #include <qlineedit.h> |
33 | #include <qvalidator.h> | 33 | #include <qvalidator.h> |
34 | #include <kdebug.h> | 34 | #include <kdebug.h> |
35 | #include <knotifyclient.h> | 35 | #include <knotifyclient.h> |
36 | #include <kglobalsettings.h> | ||
36 | #include "kdatetbl.h" | 37 | #include "kdatetbl.h" |
37 | #include "kdateedit.h" | 38 | #include "kdateedit.h" |
38 | //#include "kdatepicker.moc" | 39 | //#include "kdatepicker.moc" |
39 | 40 | ||
40 | 41 | ||
41 | KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name) | 42 | KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name) |
42 | : QFrame(parent,name), | 43 | : QFrame(parent,name), |
43 | yearForward(new QToolButton(this)), | 44 | yearForward(new QToolButton(this)), |
44 | yearBackward(new QToolButton(this)), | 45 | yearBackward(new QToolButton(this)), |
45 | monthForward(new QToolButton(this)), | 46 | monthForward(new QToolButton(this)), |
46 | monthBackward(new QToolButton(this)), | 47 | monthBackward(new QToolButton(this)), |
47 | selectMonth(new QToolButton(this)), | 48 | selectMonth(new QToolButton(this)), |
48 | selectYear(new QToolButton(this)), | 49 | selectYear(new QToolButton(this)), |
49 | //line(new QLineEdit(this)), | 50 | //line(new QLineEdit(this)), |
50 | val(new KDateValidator(this)) | 51 | val(new KDateValidator(this)) |
51 | //table(new KDateTable(this)), | 52 | //table(new KDateTable(this)), |
52 | //fontsize(1) | 53 | //fontsize(1) |
53 | { | 54 | { |
54 | // ----- | 55 | setFont ( KGlobalSettings::generalFont() ); |
55 | int size = 12; | ||
56 | if ( QApplication::desktop()->width() >= 480 ) | ||
57 | size = 18; | ||
58 | fontsize = size; | ||
59 | setFont ( QFont("helvetica",size) ); | ||
60 | table = new KDateTable(this); | 56 | table = new KDateTable(this); |
61 | setFontSize(size); | 57 | setFontSize(font().pointSize()+2); |
62 | //line->setValidator(val); | 58 | //line->setValidator(val); |
63 | lineDate = new KDateEdit( this, "dateediipicker", true ); | 59 | lineDate = new KDateEdit( this, "dateediipicker", true ); |
64 | yearForward->setPixmap(SmallIcon("2rightarrowB")); | 60 | yearForward->setPixmap(SmallIcon("2rightarrowB")); |
65 | yearBackward->setPixmap(SmallIcon("2leftarrowB")); | 61 | yearBackward->setPixmap(SmallIcon("2leftarrowB")); |
66 | monthForward->setPixmap(SmallIcon("1rightarrowB")); | 62 | monthForward->setPixmap(SmallIcon("1rightarrowB")); |
67 | monthBackward->setPixmap(SmallIcon("1leftarrowB")); | 63 | monthBackward->setPixmap(SmallIcon("1leftarrowB")); |
68 | setDate(dt); // set button texts | 64 | setDate(dt); // set button texts |
69 | connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate))); | 65 | connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate))); |
70 | connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot())); | 66 | connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot())); |
71 | connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked())); | 67 | connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked())); |
72 | connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked())); | 68 | connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked())); |
73 | connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked())); | 69 | connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked())); |
74 | connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked())); | 70 | connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked())); |
75 | connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked())); | 71 | connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked())); |
76 | connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked())); | 72 | connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked())); |
77 | //connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); | 73 | //connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); |
78 | connect(lineDate, SIGNAL(dateChanged(QDate)), SLOT(slotSetDate(QDate))); | 74 | connect(lineDate, SIGNAL(dateChanged(QDate)), SLOT(slotSetDate(QDate))); |
79 | connect(lineDate, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); | 75 | connect(lineDate, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); |
80 | table->setFocus(); | 76 | table->setFocus(); |
81 | 77 | ||
82 | } | 78 | } |
83 | 79 | ||
84 | KDatePicker::~KDatePicker() | 80 | KDatePicker::~KDatePicker() |
85 | { | 81 | { |
86 | } | 82 | } |
87 | 83 | ||
88 | void | 84 | void |
89 | KDatePicker::resizeEvent(QResizeEvent*) | 85 | KDatePicker::resizeEvent(QResizeEvent*) |
90 | { | 86 | { |
91 | QWidget *buttons[] = { | 87 | QWidget *buttons[] = { |
92 | yearBackward, | 88 | yearBackward, |
93 | monthBackward, | 89 | monthBackward, |
94 | selectMonth, | 90 | selectMonth, |
95 | selectYear, | 91 | selectYear, |
96 | monthForward, | 92 | monthForward, |
97 | yearForward }; | 93 | yearForward }; |
98 | const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); | 94 | const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); |
99 | QSize sizes[NoOfButtons]; | 95 | QSize sizes[NoOfButtons]; |
100 | int buttonHeight=0; | 96 | int buttonHeight=0; |
101 | int count; | 97 | int count; |
102 | int w; | 98 | int w; |
103 | int x=0; | 99 | int x=0; |
104 | // ----- calculate button row height: | 100 | // ----- calculate button row height: |
105 | for(count=0; count<NoOfButtons; ++count) { | 101 | for(count=0; count<NoOfButtons; ++count) { |
106 | int xS = buttons[count]->sizeHint().width(); | 102 | int xS = buttons[count]->sizeHint().width(); |
107 | int yS = buttons[count]->sizeHint().height(); | 103 | int yS = buttons[count]->sizeHint().height(); |
108 | if ( QApplication::desktop()->width() < 320 ) | 104 | if ( QApplication::desktop()->width() < 320 ) |
109 | sizes[count]=QSize ( xS+4, yS ); | 105 | sizes[count]=QSize ( xS+4, yS ); |
110 | else | 106 | else |
111 | sizes[count]=QSize ( xS+10, yS ); | 107 | sizes[count]=QSize ( xS+10, yS ); |
112 | 108 | ||
113 | buttonHeight=QMAX(buttonHeight, sizes[count].height()); | 109 | buttonHeight=QMAX(buttonHeight, sizes[count].height()); |
114 | } | 110 | } |
115 | buttonHeight += 10; | 111 | buttonHeight += 10; |
116 | // ----- calculate size of the month button: | 112 | // ----- calculate size of the month button: |
117 | w=0; | 113 | w=0; |
118 | for(count=0; count<NoOfButtons; ++count) { | 114 | for(count=0; count<NoOfButtons; ++count) { |
119 | if(buttons[count]!=selectMonth) | 115 | if(buttons[count]!=selectMonth) |
120 | { | 116 | { |
121 | w+=sizes[count].width(); | 117 | w+=sizes[count].width(); |
122 | } else { | 118 | } else { |
123 | x=count; | 119 | x=count; |
124 | } | 120 | } |
125 | } | 121 | } |
126 | sizes[x].setWidth(width()-w); // stretch the month button | 122 | sizes[x].setWidth(width()-w); // stretch the month button |
127 | // ----- place the buttons: | 123 | // ----- place the buttons: |
128 | x=0; | 124 | x=0; |
129 | for(count=0; count<NoOfButtons; ++count) | 125 | for(count=0; count<NoOfButtons; ++count) |
130 | { | 126 | { |
131 | w=sizes[count].width(); | 127 | w=sizes[count].width(); |
132 | buttons[count]->setGeometry(x, 0, w, buttonHeight); | 128 | buttons[count]->setGeometry(x, 0, w, buttonHeight); |
133 | x+=w; | 129 | x+=w; |
134 | } | 130 | } |
135 | // ----- place the line edit for direct input: | 131 | // ----- place the line edit for direct input: |
136 | sizes[0]=lineDate->sizeHint(); | 132 | sizes[0]=lineDate->sizeHint(); |
137 | //line->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); | 133 | //line->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); |
138 | lineDate->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); | 134 | lineDate->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); |
139 | // ----- adjust the table: | 135 | // ----- adjust the table: |
140 | table->setGeometry(0, buttonHeight, width(), | 136 | table->setGeometry(0, buttonHeight, width(), |
141 | height()-buttonHeight-sizes[0].height()); | 137 | height()-buttonHeight-sizes[0].height()); |
142 | } | 138 | } |
143 | 139 | ||
144 | void | 140 | void |
145 | KDatePicker::dateChangedSlot(QDate date) | 141 | KDatePicker::dateChangedSlot(QDate date) |
146 | { | 142 | { |
147 | lineDate->setDate( date );//(KGlobal::locale()->formatDate(date, true)); | 143 | lineDate->setDate( date );//(KGlobal::locale()->formatDate(date, true)); |
148 | //line->setText(KGlobal::locale()->formatDate(date, true)); | 144 | //line->setText(KGlobal::locale()->formatDate(date, true)); |
149 | emit(dateChanged(date)); | 145 | emit(dateChanged(date)); |
150 | } | 146 | } |
151 | 147 | ||
152 | void | 148 | void |
153 | KDatePicker::tableClickedSlot() | 149 | KDatePicker::tableClickedSlot() |
154 | { | 150 | { |
155 | 151 | ||
156 | emit(dateSelected(table->getDate())); | 152 | emit(dateSelected(table->getDate())); |
157 | emit(tableClicked()); | 153 | emit(tableClicked()); |
158 | } | 154 | } |
159 | 155 | ||
160 | const QDate& | 156 | const QDate& |
161 | KDatePicker::getDate() const | 157 | KDatePicker::getDate() const |
162 | { | 158 | { |
163 | return table->getDate(); | 159 | return table->getDate(); |
164 | } | 160 | } |
165 | 161 | ||
166 | const QDate & | 162 | const QDate & |
167 | KDatePicker::date() const | 163 | KDatePicker::date() const |
168 | { | 164 | { |
169 | return table->getDate(); | 165 | return table->getDate(); |
170 | } | 166 | } |
171 | 167 | ||
172 | void KDatePicker::slotSetDate( QDate date ) | 168 | void KDatePicker::slotSetDate( QDate date ) |
173 | { | 169 | { |
174 | 170 | ||
175 | if(date.isValid()) { | 171 | if(date.isValid()) { |
176 | QString temp; | 172 | QString temp; |
177 | // ----- | 173 | // ----- |
178 | table->setDate(date); | 174 | table->setDate(date); |
179 | selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); | 175 | selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); |
180 | temp.setNum(date.year()); | 176 | temp.setNum(date.year()); |
181 | selectYear->setText(temp); | 177 | selectYear->setText(temp); |
182 | //line->setText(KGlobal::locale()->formatDate(date, true)); | 178 | //line->setText(KGlobal::locale()->formatDate(date, true)); |
183 | lineDate->setDate( date ); | 179 | lineDate->setDate( date ); |
184 | } | 180 | } |
185 | 181 | ||
186 | } | 182 | } |
187 | bool | 183 | bool |
188 | KDatePicker::setDate(const QDate& date) | 184 | KDatePicker::setDate(const QDate& date) |
189 | { | 185 | { |
190 | table->setFocus(); | 186 | table->setFocus(); |
191 | if(date.isValid()) { | 187 | if(date.isValid()) { |
192 | QString temp; | 188 | QString temp; |
193 | // ----- | 189 | // ----- |
194 | table->setDate(date); | 190 | table->setDate(date); |
195 | selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); | 191 | selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); |
196 | temp.setNum(date.year()); | 192 | temp.setNum(date.year()); |
197 | selectYear->setText(temp); | 193 | selectYear->setText(temp); |
198 | //line->setText(KGlobal::locale()->formatDate(date, true)); | 194 | //line->setText(KGlobal::locale()->formatDate(date, true)); |
199 | lineDate->setDate( date ); | 195 | lineDate->setDate( date ); |
200 | return true; | 196 | return true; |
201 | } else { | 197 | } else { |
202 | 198 | ||
203 | return false; | 199 | return false; |
204 | } | 200 | } |
205 | 201 | ||
206 | 202 | ||
207 | } | 203 | } |
208 | 204 | ||
209 | void | 205 | void |
210 | KDatePicker::monthForwardClicked() | 206 | KDatePicker::monthForwardClicked() |
211 | { | 207 | { |
212 | QDate temp=table->getDate(); | 208 | QDate temp=table->getDate(); |
213 | int day=temp.day(); | 209 | int day=temp.day(); |
214 | // ----- | 210 | // ----- |
215 | if(temp.month()==12) { | 211 | if(temp.month()==12) { |
216 | temp.setYMD(temp.year()+1, 1, 1); | 212 | temp.setYMD(temp.year()+1, 1, 1); |
217 | } else { | 213 | } else { |
218 | temp.setYMD(temp.year(), temp.month()+1, 1); | 214 | temp.setYMD(temp.year(), temp.month()+1, 1); |
219 | } | 215 | } |
220 | if(temp.daysInMonth()<day) { | 216 | if(temp.daysInMonth()<day) { |
221 | temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); | 217 | temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); |
222 | } else { | 218 | } else { |
223 | temp.setYMD(temp.year(), temp.month(), day); | 219 | temp.setYMD(temp.year(), temp.month(), day); |
224 | } | 220 | } |
225 | // assert(temp.isValid()); | 221 | // assert(temp.isValid()); |
226 | setDate(temp); | 222 | setDate(temp); |
227 | } | 223 | } |
228 | 224 | ||
229 | void | 225 | void |
230 | KDatePicker::monthBackwardClicked() | 226 | KDatePicker::monthBackwardClicked() |
231 | { | 227 | { |
232 | QDate temp=table->getDate(); | 228 | QDate temp=table->getDate(); |
233 | int day=temp.day(); | 229 | int day=temp.day(); |
234 | // ----- | 230 | // ----- |
235 | if(temp.month()==1) | 231 | if(temp.month()==1) |
236 | { | 232 | { |
237 | temp.setYMD(temp.year()-1, 12, 1); | 233 | temp.setYMD(temp.year()-1, 12, 1); |
238 | } else { | 234 | } else { |
239 | temp.setYMD(temp.year(), temp.month()-1, 1); | 235 | temp.setYMD(temp.year(), temp.month()-1, 1); |
240 | } | 236 | } |
241 | if(temp.daysInMonth()<day) | 237 | if(temp.daysInMonth()<day) |
242 | { | 238 | { |
243 | temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); | 239 | temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); |
244 | } else { | 240 | } else { |
245 | temp.setYMD(temp.year(), temp.month(), day); | 241 | temp.setYMD(temp.year(), temp.month(), day); |
246 | } | 242 | } |
247 | // assert(temp.isValid()); | 243 | // assert(temp.isValid()); |
248 | setDate(temp); | 244 | setDate(temp); |
249 | } | 245 | } |
250 | 246 | ||
251 | void | 247 | void |
252 | KDatePicker::yearForwardClicked() | 248 | KDatePicker::yearForwardClicked() |
253 | { | 249 | { |