summaryrefslogtreecommitdiffabout
path: root/libkdepim/kdatepicker.cpp
Unidiff
Diffstat (limited to 'libkdepim/kdatepicker.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/kdatepicker.cpp12
1 files changed, 11 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
@@ -38,52 +38,55 @@
38#include "kdateedit.h" 38#include "kdateedit.h"
39//#include "kdatepicker.moc" 39//#include "kdatepicker.moc"
40 40
41 41
42KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name) 42KDatePicker::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 )
58 add += 4; 59 add += 4;
59 fo.setPointSize(fo.pointSize()+add ); 60 fo.setPointSize(fo.pointSize()+add );
60 setFont( fo ); 61 setFont( fo );
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
85KDatePicker::~KDatePicker() 88KDatePicker::~KDatePicker()
86{ 89{
87} 90}
88 91
89void 92void
@@ -127,25 +130,27 @@ KDatePicker::resizeEvent(QResizeEvent*)
127 sizes[x].setWidth(width()-w); // stretch the month button 130 sizes[x].setWidth(width()-w); // stretch the month button
128 // ----- place the buttons: 131 // ----- place the buttons:
129 x=0; 132 x=0;
130 for(count=0; count<NoOfButtons; ++count) 133 for(count=0; count<NoOfButtons; ++count)
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();
143todayBut->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
145void 150void
146KDatePicker::dateChangedSlot(QDate date) 151KDatePicker::dateChangedSlot(QDate date)
147{ 152{
148 lineDate->setDate( date );//(KGlobal::locale()->formatDate(date, true)); 153 lineDate->setDate( date );//(KGlobal::locale()->formatDate(date, true));
149 //line->setText(KGlobal::locale()->formatDate(date, true)); 154 //line->setText(KGlobal::locale()->formatDate(date, true));
150 emit(dateChanged(date)); 155 emit(dateChanged(date));
151} 156}
@@ -161,24 +166,29 @@ KDatePicker::tableClickedSlot()
161const QDate& 166const QDate&
162KDatePicker::getDate() const 167KDatePicker::getDate() const
163{ 168{
164 return table->getDate(); 169 return table->getDate();
165} 170}
166 171
167const QDate & 172const QDate &
168KDatePicker::date() const 173KDatePicker::date() const
169{ 174{
170 return table->getDate(); 175 return table->getDate();
171} 176}
172 177
178void KDatePicker::goToday()
179{
180 slotSetDate( QDate::currentDate() );
181
182}
173void KDatePicker::slotSetDate( QDate date ) 183void 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));
181 temp.setNum(date.year()); 191 temp.setNum(date.year());
182 selectYear->setText(temp); 192 selectYear->setText(temp);
183 //line->setText(KGlobal::locale()->formatDate(date, true)); 193 //line->setText(KGlobal::locale()->formatDate(date, true));
184 lineDate->setDate( date ); 194 lineDate->setDate( date );