author | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
commit | 15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff) | |
tree | c2fa0399a2c47fda8e2cd0092c73a809d17f68eb /noncore/apps/tableviewer/browsekeyentry.cpp | |
download | opie-15318cad33835e4e2dc620d033e43cd930676cdd.zip opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2 |
Initial revision
Diffstat (limited to 'noncore/apps/tableviewer/browsekeyentry.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/tableviewer/browsekeyentry.cpp | 242 |
1 files changed, 242 insertions, 0 deletions
diff --git a/noncore/apps/tableviewer/browsekeyentry.cpp b/noncore/apps/tableviewer/browsekeyentry.cpp new file mode 100644 index 0000000..04e7902 --- a/dev/null +++ b/noncore/apps/tableviewer/browsekeyentry.cpp | |||
@@ -0,0 +1,242 @@ | |||
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 | #include "browsekeyentry.h" | ||
21 | |||
22 | #include <qtoolbutton.h> | ||
23 | #include <qwidgetstack.h> | ||
24 | #include <qlayout.h> | ||
25 | #include <qlineedit.h> | ||
26 | #include <qpushbutton.h> | ||
27 | #include <qpopupmenu.h> | ||
28 | #include <qhbox.h> | ||
29 | #include <qdatetime.h> | ||
30 | |||
31 | //#include <iostream.h> | ||
32 | #include <qheader.h> | ||
33 | // For qWarning(const char *) | ||
34 | |||
35 | /*! | ||
36 | \class TVBrowseKeyEntry | ||
37 | \brief a Widget used enter keys into the TVBrowseViewWidget | ||
38 | |||
39 | The TVBrowseKeyEntry Widget provides the facility to enter | ||
40 | various key types to be search on in the table. The key can be changed | ||
41 | and the entry field will update to the correct sort of widget appropriately | ||
42 | */ | ||
43 | |||
44 | /*! | ||
45 | Constructs the widget | ||
46 | */ | ||
47 | TVBrowseKeyEntry::TVBrowseKeyEntry(QWidget *parent, const char *name, WFlags f) | ||
48 | : QWidget(parent, name, f) | ||
49 | { | ||
50 | int stack_elem = 0; | ||
51 | QHBoxLayout *h_layout = new QHBoxLayout(this); | ||
52 | |||
53 | textKey = new QLineEdit(this, 0); | ||
54 | |||
55 | dateKey = new QHBox(this, 0); | ||
56 | dayKey = new QLineEdit(dateKey, 0); | ||
57 | monthKey = new QLineEdit(dateKey, 0); | ||
58 | yearKey = new QLineEdit(dateKey, 0); | ||
59 | |||
60 | timeKey = new QHBox(this, 0); | ||
61 | hourKey = new QLineEdit(timeKey, 0); | ||
62 | minuteKey = new QLineEdit(timeKey, 0); | ||
63 | secondKey = new QLineEdit(timeKey, 0); | ||
64 | |||
65 | resetButton = new QPushButton(this, "reset"); | ||
66 | resetButton->setMinimumSize(QSize(50, 0)); | ||
67 | resetButton->setText(tr("Reset")); | ||
68 | |||
69 | changeKeyButton = new QToolButton(this, "changekey"); | ||
70 | // TODO The icon stuff. | ||
71 | changeKeyButton->setText(tr("key")); | ||
72 | |||
73 | totalKeys = 0; | ||
74 | ts = 0; | ||
75 | keyMenu = new QPopupMenu(this, "keymenu"); | ||
76 | |||
77 | ws = new QWidgetStack(this, 0); | ||
78 | ws->addWidget(textKey, stack_elem++); | ||
79 | ws->addWidget(timeKey, stack_elem++); | ||
80 | ws->addWidget(dateKey, stack_elem++); | ||
81 | |||
82 | ws->raiseWidget(0); | ||
83 | |||
84 | // TODO connect slots and signals.... | ||
85 | connect(changeKeyButton, SIGNAL(clicked()), | ||
86 | this, SLOT(changeKeyMenuSlot())); | ||
87 | connect(resetButton, SIGNAL(clicked()), | ||
88 | this, SLOT(resetKeySlot())); | ||
89 | |||
90 | connect(textKey, SIGNAL(textChanged(const QString&)), | ||
91 | this, SLOT(searchOnText())); | ||
92 | |||
93 | connect(dayKey, SIGNAL(textChanged(const QString&)), | ||
94 | this, SLOT(searchOnText())); | ||
95 | connect(monthKey, SIGNAL(textChanged(const QString&)), | ||
96 | this, SLOT(searchOnText())); | ||
97 | connect(yearKey, SIGNAL(textChanged(const QString&)), | ||
98 | this, SLOT(searchOnText())); | ||
99 | |||
100 | connect(secondKey, SIGNAL(textChanged(const QString&)), | ||
101 | this, SLOT(searchOnText())); | ||
102 | connect(minuteKey, SIGNAL(textChanged(const QString&)), | ||
103 | this, SLOT(searchOnText())); | ||
104 | connect(hourKey, SIGNAL(textChanged(const QString&)), | ||
105 | this, SLOT(searchOnText())); | ||
106 | |||
107 | h_layout->addWidget(ws); | ||
108 | h_layout->addWidget(resetButton); | ||
109 | h_layout->addWidget(changeKeyButton); | ||
110 | } | ||
111 | |||
112 | /*! | ||
113 | Destructs the widget | ||
114 | */ | ||
115 | TVBrowseKeyEntry::~TVBrowseKeyEntry() | ||
116 | { | ||
117 | } | ||
118 | |||
119 | /*! | ||
120 | Changes which key the user intends to search on | ||
121 | |||
122 | \param id_param the index of the key future searches should be base on | ||
123 | */ | ||
124 | void TVBrowseKeyEntry::changeKeySlot(int id_param) | ||
125 | { | ||
126 | emit sortChanged(id_param); | ||
127 | switch(ts->kRep->getKeyType(ts->current_column)) { | ||
128 | /* work out what to raise */ | ||
129 | case kt_string: | ||
130 | case kt_int: | ||
131 | ws->raiseWidget(0); | ||
132 | break; | ||
133 | case kt_time: | ||
134 | ws->raiseWidget(1); | ||
135 | break; | ||
136 | case kt_date: | ||
137 | ws->raiseWidget(2); | ||
138 | break; | ||
139 | default: | ||
140 | return; | ||
141 | } | ||
142 | } | ||
143 | |||
144 | /*! | ||
145 | Opens the change key menu | ||
146 | */ | ||
147 | void TVBrowseKeyEntry::changeKeyMenuSlot() | ||
148 | { | ||
149 | if(ts) | ||
150 | keyMenu->exec(changeKeyButton->mapToGlobal(QPoint(0,0))); | ||
151 | } | ||
152 | /*! | ||
153 | Blanks the key entry widget | ||
154 | \TODO the actual implmentation | ||
155 | */ | ||
156 | void TVBrowseKeyEntry::resetKeySlot() { | ||
157 | ; | ||
158 | } | ||
159 | |||
160 | void TVBrowseKeyEntry::setTableState(TableState *t) { | ||
161 | int i; | ||
162 | ts = t; | ||
163 | |||
164 | /* clear the old */ | ||
165 | keyMenu->clear(); | ||
166 | |||
167 | for (i = 0; i < t->kRep->getNumFields(); i++) { | ||
168 | keyMenu->insertItem(ts->kRep->getKeyName(i), this, | ||
169 | SLOT(changeKeySlot(int)), 0, i); | ||
170 | keyMenu->setItemParameter(i, i); | ||
171 | } | ||
172 | } | ||
173 | |||
174 | /*! | ||
175 | Searches on the current value of the key entry provided that the | ||
176 | current key is of type text WARNING, TODO fix memory leaks | ||
177 | */ | ||
178 | void TVBrowseKeyEntry::searchOnText() | ||
179 | { | ||
180 | void *sendkey; | ||
181 | int tmp; | ||
182 | |||
183 | switch(ts->kRep->getKeyType(ts->current_column)) { | ||
184 | /* work out what to raise */ | ||
185 | case kt_string: | ||
186 | sendkey = (void *)new QString(textKey->text()); | ||
187 | break; | ||
188 | case kt_int: { | ||
189 | bool ok; | ||
190 | tmp = textKey->text().toInt(&ok); | ||
191 | sendkey = &tmp; | ||
192 | if (!ok) | ||
193 | return; | ||
194 | break; | ||
195 | } | ||
196 | case kt_time: { | ||
197 | bool ok; | ||
198 | int s,m,h; | ||
199 | s = secondKey->text().toInt(&ok); | ||
200 | if (!ok) | ||
201 | return; | ||
202 | m = minuteKey->text().toInt(&ok); | ||
203 | if (!ok) | ||
204 | return; | ||
205 | h = hourKey->text().toInt(&ok); | ||
206 | if (!ok) | ||
207 | return; | ||
208 | if(!QTime::isValid(h, m, s)) | ||
209 | return; | ||
210 | sendkey = (void *) new QTime(h, m, s); | ||
211 | break; | ||
212 | } | ||
213 | case kt_date: { | ||
214 | bool ok; | ||
215 | int d,m,y; | ||
216 | d = dayKey->text().toInt(&ok); | ||
217 | if (!ok) | ||
218 | return; | ||
219 | m = monthKey->text().toInt(&ok); | ||
220 | if (!ok) | ||
221 | return; | ||
222 | y = yearKey->text().toInt(&ok); | ||
223 | if (!ok) | ||
224 | return; | ||
225 | if(!QDate::isValid(y, m, d)) | ||
226 | return; | ||
227 | sendkey = (void *) new QDate(y, m, d); | ||
228 | break; | ||
229 | } | ||
230 | default: | ||
231 | qWarning("TVBrowseKeyEntry::searchOnText() " | ||
232 | "cannot work out data type"); | ||
233 | return; | ||
234 | } | ||
235 | emit searchOnKey(ts->current_column, sendkey); | ||
236 | } | ||
237 | |||
238 | /*! \fn void TVBrowseKeyEntry::searchOnKey(int currentKeyId, void *v) | ||
239 | |||
240 | This signal indicates that a search on key index currentKeyId should be | ||
241 | done searching for the value v. | ||
242 | */ | ||