00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qlineedit.h>
00022 #include <qlayout.h>
00023 #include <qlabel.h>
00024 #include <qcombobox.h>
00025
00026 #include <qpe/datebookmonth.h>
00027 #include <qpopupmenu.h>
00028 #include <qspinbox.h>
00029 #include "commonwidgets.h"
00030
00031 DateEdit::DateEdit( QWidget *parent, const char *name, WFlags f )
00032 : QToolButton(parent, name)
00033 {
00034 QPopupMenu *m1 = new QPopupMenu(this);
00035 dateSelector = new DateBookMonth(m1, 0, TRUE);
00036 m1->insertItem(dateSelector);
00037 setPopup(m1);
00038 setPopupDelay(0);
00039
00040 connect(dateSelector, SIGNAL(dateClicked(int,int,int)),
00041 this, SLOT(subValueChanged()));
00042
00043 setText(dateSelector->selectedDate().toString());
00044 }
00045
00046
00047 DateEdit::~DateEdit() {}
00048
00049 QDate DateEdit::date() const
00050 {
00051 return dateSelector->selectedDate();
00052 }
00053
00054 void DateEdit::setDate(QDate d)
00055 {
00056 dateSelector->setDate(d.year(), d.month(), d.day());
00057 setText(d.toString());
00058 }
00059
00060 QSizePolicy DateEdit::sizePolicy() const
00061 {
00062 QSizePolicy sp;
00063 sp.setHorData(QToolButton::sizePolicy().horData());
00064 sp.setVerData(QSizePolicy::Fixed);
00065
00066 return sp;
00067 }
00068
00069 void DateEdit::clear()
00070 {
00071 QDate today = QDate::currentDate();
00072
00073 dateSelector->setDate(today.year(), today.month(), today.day());
00074 setText(today.toString());
00075 }
00076
00077 void DateEdit::subValueChanged()
00078 {
00079 QDate current = dateSelector->selectedDate();
00080
00081 setText(current.toString());
00082 emit valueChanged(current);
00083 }
00084
00085 TimeEdit::TimeEdit( QWidget *parent, const char *name, WFlags f )
00086 : QWidget(parent, name, f)
00087 {
00088 QHBoxLayout *layout = new QHBoxLayout(this, 0);
00089
00090 layout->addWidget(hourKey = new QSpinBox(1, 12, 1, this));
00091 hourKey->setWrapping(true);
00092 hourKey->setMinimumWidth(30);
00093 hourKey->setMaximumWidth(35);
00094
00095 layout->addWidget(new QLabel(" : ", this));
00096 layout->addWidget(minuteKey = new QSpinBox(0, 59, 1, this));
00097 minuteKey->setWrapping(true);
00098 minuteKey->setMinimumWidth(30);
00099 minuteKey->setMaximumWidth(35);
00100
00101 layout->addWidget(new QLabel(" : ", this));
00102 layout->addWidget(secondKey = new QSpinBox(0, 59, 1, this, 0));
00103 secondKey->setWrapping(true);
00104 secondKey->setMinimumWidth(30);
00105 secondKey->setMaximumWidth(35);
00106
00107 layout->addWidget(ampm = new QComboBox(this));
00108 ampm->insertItem("AM");
00109 ampm->insertItem("PM");
00110
00111 layout->addStretch(-1);
00112
00113 clear();
00114
00115 connect(secondKey, SIGNAL(valueChanged(const QString&)),
00116 this, SLOT(subValueChanged()));
00117 connect(minuteKey, SIGNAL(valueChanged(const QString&)),
00118 this, SLOT(subValueChanged()));
00119 connect(hourKey, SIGNAL(valueChanged(const QString&)),
00120 this, SLOT(subValueChanged()));
00121 connect(ampm, SIGNAL(activated(int)),
00122 this, SLOT(subValueChanged()));
00123 }
00124
00125
00126 TimeEdit::~TimeEdit() {}
00127
00128 QTime TimeEdit::time() const
00129 {
00130 int s,m,h;
00131
00132 s = secondKey->text().toInt();
00133 m = minuteKey->text().toInt();
00134 h = hourKey->text().toInt();
00135
00136 if(ampm->currentItem() == 1) {
00137
00138 h = h + 12;
00139 }
00140
00141
00142 if (h == 12)
00143 h = 0;
00144 if (h == 24)
00145 h = 12;
00146
00147 if(QTime::isValid(h, m, s))
00148 return QTime(h, m, s);
00149 return QTime(0, 0, 0);
00150 }
00151
00152 void TimeEdit::setTime(QTime t)
00153 {
00154 int h = t.hour();
00155 secondKey->setValue(t.second());
00156 minuteKey->setValue(t.minute());
00157
00158
00159 if (h > 11) {
00160 h -= 12;
00161 ampm->setCurrentItem(1);
00162 } else {
00163 ampm->setCurrentItem(0);
00164 }
00165
00166 if (h == 0) h = 12;
00167 hourKey->setValue(h);
00168 }
00169
00170 QSizePolicy TimeEdit::sizePolicy() const
00171 {
00172 QSizePolicy sp;
00173 sp.setHorData(QSizePolicy::Preferred);
00174 sp.setVerData(QSizePolicy::Fixed);
00175
00176 return sp;
00177 }
00178
00179 void TimeEdit::clear()
00180 {
00181 secondKey->setValue(0);
00182 minuteKey->setValue(0);
00183 hourKey->setValue(12);
00184
00185 ampm->setCurrentItem(0);
00186 }
00187
00188 void TimeEdit::subValueChanged()
00189 {
00190 emit valueChanged(time());
00191 }
00192
00193 IntEdit::IntEdit( QWidget *parent, const char *name, WFlags f )
00194 : QSpinBox(INT_MIN, INT_MAX, 1, parent, name)
00195 {
00196 setValue(0);
00197 }
00198
00199
00200 IntEdit::~IntEdit() {}
00201
00202 int IntEdit::value()
00203 {
00204 return cleanText().toInt();
00205 }
00206
00207 void IntEdit::clear()
00208 {
00209 setValue(0);
00210 }