Diffstat (limited to 'noncore/apps/tableviewer/ui/commonwidgets.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/tableviewer/ui/commonwidgets.cpp | 209 |
1 files changed, 209 insertions, 0 deletions
diff --git a/noncore/apps/tableviewer/ui/commonwidgets.cpp b/noncore/apps/tableviewer/ui/commonwidgets.cpp new file mode 100644 index 0000000..0b4f3c2 --- a/dev/null +++ b/noncore/apps/tableviewer/ui/commonwidgets.cpp | |||
@@ -0,0 +1,209 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include <qlineedit.h> | ||
22 | #include <qlayout.h> | ||
23 | #include <qlabel.h> | ||
24 | #include <qcombobox.h> | ||
25 | #include <datebookmonth.h> | ||
26 | #include <qpopupmenu.h> | ||
27 | #include <qspinbox.h> | ||
28 | #include "commonwidgets.h" | ||
29 | |||
30 | DateEdit::DateEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ) | ||
31 | : QToolButton(parent, name) | ||
32 | { | ||
33 | QPopupMenu *m1 = new QPopupMenu(this); | ||
34 | dateSelector = new DateBookMonth(m1, 0, TRUE); | ||
35 | m1->insertItem(dateSelector); | ||
36 | setPopup(m1); | ||
37 | setPopupDelay(0); | ||
38 | |||
39 | connect(dateSelector, SIGNAL(dateClicked(int, int, int)), | ||
40 | this, SLOT(subValueChanged())); | ||
41 | |||
42 | setText(dateSelector->selectedDate().toString()); | ||
43 | } | ||
44 | |||
45 | |||
46 | DateEdit::~DateEdit() {} | ||
47 | |||
48 | QDate DateEdit::date() const | ||
49 | { | ||
50 | return dateSelector->selectedDate(); | ||
51 | } | ||
52 | |||
53 | void DateEdit::setDate(QDate d) | ||
54 | { | ||
55 | dateSelector->setDate(d.year(), d.month(), d.day()); | ||
56 | setText(d.toString()); | ||
57 | } | ||
58 | |||
59 | QSizePolicy DateEdit::sizePolicy() const | ||
60 | { | ||
61 | QSizePolicy sp; | ||
62 | sp.setHorData(QToolButton::sizePolicy().horData()); | ||
63 | sp.setVerData(QSizePolicy::Fixed); | ||
64 | |||
65 | return sp; | ||
66 | } | ||
67 | |||
68 | void DateEdit::clear() | ||
69 | { | ||
70 | QDate today = QDate::currentDate(); | ||
71 | |||
72 | dateSelector->setDate(today.year(), today.month(), today.day()); | ||
73 | setText(today.toString()); | ||
74 | } | ||
75 | |||
76 | void DateEdit::subValueChanged() | ||
77 | { | ||
78 | QDate current = dateSelector->selectedDate(); | ||
79 | |||
80 | setText(current.toString()); | ||
81 | emit valueChanged(current); | ||
82 | } | ||
83 | |||
84 | TimeEdit::TimeEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ) | ||
85 | : QWidget(parent, name, f) | ||
86 | { | ||
87 | QHBoxLayout *layout = new QHBoxLayout(this, 0); | ||
88 | |||
89 | layout->addWidget(hourKey = new QSpinBox(1, 12, 1, this)); | ||
90 | hourKey->setWrapping(true); | ||
91 | hourKey->setMinimumWidth(30); | ||
92 | hourKey->setMaximumWidth(35); | ||
93 | |||
94 | layout->addWidget(new QLabel(" : ", this)); | ||
95 | layout->addWidget(minuteKey = new QSpinBox(0, 59, 1, this)); | ||
96 | minuteKey->setWrapping(true); | ||
97 | minuteKey->setMinimumWidth(30); | ||
98 | minuteKey->setMaximumWidth(35); | ||
99 | |||
100 | layout->addWidget(new QLabel(" : ", this)); | ||
101 | layout->addWidget(secondKey = new QSpinBox(0, 59, 1, this, 0)); | ||
102 | secondKey->setWrapping(true); | ||
103 | secondKey->setMinimumWidth(30); | ||
104 | secondKey->setMaximumWidth(35); | ||
105 | |||
106 | layout->addWidget(ampm = new QComboBox(this)); | ||
107 | ampm->insertItem("AM"); | ||
108 | ampm->insertItem("PM"); | ||
109 | |||
110 | layout->addStretch(-1); | ||
111 | |||
112 | clear(); | ||
113 | |||
114 | connect(secondKey, SIGNAL(valueChanged(const QString&)), | ||
115 | this, SLOT(subValueChanged())); | ||
116 | connect(minuteKey, SIGNAL(valueChanged(const QString&)), | ||
117 | this, SLOT(subValueChanged())); | ||
118 | connect(hourKey, SIGNAL(valueChanged(const QString&)), | ||
119 | this, SLOT(subValueChanged())); | ||
120 | connect(ampm, SIGNAL(activated(int)), | ||
121 | this, SLOT(subValueChanged())); | ||
122 | } | ||
123 | |||
124 | |||
125 | TimeEdit::~TimeEdit() {} | ||
126 | |||
127 | QTime TimeEdit::time() const | ||
128 | { | ||
129 | int s,m,h; | ||
130 | |||
131 | s = secondKey->text().toInt(); | ||
132 | m = minuteKey->text().toInt(); | ||
133 | h = hourKey->text().toInt(); | ||
134 | |||
135 | if(ampm->currentItem() == 1) { | ||
136 | /* pm */ | ||
137 | h = h + 12; | ||
138 | } | ||
139 | /* hour now ranges 1->24 */ | ||
140 | |||
141 | if (h == 12) | ||
142 | h = 0; | ||
143 | if (h == 24) | ||
144 | h = 12; | ||
145 | |||
146 | if(QTime::isValid(h, m, s)) | ||
147 | return QTime(h, m, s); | ||
148 | return QTime(0, 0, 0); | ||
149 | } | ||
150 | |||
151 | void TimeEdit::setTime(QTime t) | ||
152 | { | ||
153 | int h = t.hour(); | ||
154 | secondKey->setValue(t.second()); | ||
155 | minuteKey->setValue(t.minute()); | ||
156 | |||
157 | /* h 0..23 */ | ||
158 | if (h > 11) { | ||
159 | h -= 12; | ||
160 | ampm->setCurrentItem(1); | ||
161 | } else { | ||
162 | ampm->setCurrentItem(0); | ||
163 | } | ||
164 | |||
165 | if (h == 0) h = 12; | ||
166 | hourKey->setValue(h); | ||
167 | } | ||
168 | |||
169 | QSizePolicy TimeEdit::sizePolicy() const | ||
170 | { | ||
171 | QSizePolicy sp; | ||
172 | sp.setHorData(QSizePolicy::Preferred); | ||
173 | sp.setVerData(QSizePolicy::Fixed); | ||
174 | |||
175 | return sp; | ||
176 | } | ||
177 | |||
178 | void TimeEdit::clear() | ||
179 | { | ||
180 | secondKey->setValue(0); | ||
181 | minuteKey->setValue(0); | ||
182 | hourKey->setValue(12); | ||
183 | |||
184 | ampm->setCurrentItem(0); | ||
185 | } | ||
186 | |||
187 | void TimeEdit::subValueChanged() | ||
188 | { | ||
189 | emit valueChanged(time()); | ||
190 | } | ||
191 | |||
192 | IntEdit::IntEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ) | ||
193 | : QSpinBox(INT_MIN, INT_MAX, 1, parent, name) | ||
194 | { | ||
195 | setValue(0); | ||
196 | } | ||
197 | |||
198 | |||
199 | IntEdit::~IntEdit() {} | ||
200 | |||
201 | int IntEdit::value() | ||
202 | { | ||
203 | return cleanText().toInt(); | ||
204 | } | ||
205 | |||
206 | void IntEdit::clear() | ||
207 | { | ||
208 | setValue(0); | ||
209 | } | ||