00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "browsekeyentry.h"
00021
00022
00023 #include <opie2/odebug.h>
00024 using namespace Opie::Core;
00025
00026
00027 #include <qtoolbutton.h>
00028 #include <qwidgetstack.h>
00029 #include <qlayout.h>
00030 #include <qlineedit.h>
00031 #include <qpushbutton.h>
00032 #include <qpopupmenu.h>
00033 #include <qhbox.h>
00034 #include <qdatetime.h>
00035
00036
00049 TVBrowseKeyEntry::TVBrowseKeyEntry(QWidget *parent, const char *name, WFlags f)
00050 : QWidget(parent, name, f)
00051 {
00052 int stack_elem = 0;
00053 QHBoxLayout *h_layout = new QHBoxLayout(this);
00054
00055 textKey = new QLineEdit(this, 0);
00056
00057 dateKey = new QHBox(this, 0);
00058 dayKey = new QLineEdit(dateKey, 0);
00059 monthKey = new QLineEdit(dateKey, 0);
00060 yearKey = new QLineEdit(dateKey, 0);
00061
00062 timeKey = new QHBox(this, 0);
00063 hourKey = new QLineEdit(timeKey, 0);
00064 minuteKey = new QLineEdit(timeKey, 0);
00065 secondKey = new QLineEdit(timeKey, 0);
00066
00067 resetButton = new QPushButton(this, "reset");
00068 resetButton->setMinimumSize(QSize(50, 0));
00069 resetButton->setText(tr("Reset"));
00070
00071 changeKeyButton = new QToolButton(this, "changekey");
00072
00073 changeKeyButton->setText(tr("key"));
00074
00075 totalKeys = 0;
00076 ts = 0;
00077 keyMenu = new QPopupMenu(this, "keymenu");
00078
00079 ws = new QWidgetStack(this, 0);
00080 ws->addWidget(textKey, stack_elem++);
00081 ws->addWidget(timeKey, stack_elem++);
00082 ws->addWidget(dateKey, stack_elem++);
00083
00084 ws->raiseWidget(0);
00085
00086
00087 connect(changeKeyButton, SIGNAL(clicked()),
00088 this, SLOT(changeKeyMenuSlot()));
00089 connect(resetButton, SIGNAL(clicked()),
00090 this, SLOT(resetKeySlot()));
00091
00092 connect(textKey, SIGNAL(textChanged(const QString&)),
00093 this, SLOT(searchOnText()));
00094
00095 connect(dayKey, SIGNAL(textChanged(const QString&)),
00096 this, SLOT(searchOnText()));
00097 connect(monthKey, SIGNAL(textChanged(const QString&)),
00098 this, SLOT(searchOnText()));
00099 connect(yearKey, SIGNAL(textChanged(const QString&)),
00100 this, SLOT(searchOnText()));
00101
00102 connect(secondKey, SIGNAL(textChanged(const QString&)),
00103 this, SLOT(searchOnText()));
00104 connect(minuteKey, SIGNAL(textChanged(const QString&)),
00105 this, SLOT(searchOnText()));
00106 connect(hourKey, SIGNAL(textChanged(const QString&)),
00107 this, SLOT(searchOnText()));
00108
00109 h_layout->addWidget(ws);
00110 h_layout->addWidget(resetButton);
00111 h_layout->addWidget(changeKeyButton);
00112 }
00113
00117 TVBrowseKeyEntry::~TVBrowseKeyEntry()
00118 {
00119 }
00120
00126 void TVBrowseKeyEntry::changeKeySlot(int id_param)
00127 {
00128 emit sortChanged(id_param);
00129 switch(ts->kRep->getKeyType(ts->current_column)) {
00130
00131 case kt_string:
00132 case kt_int:
00133 ws->raiseWidget(0);
00134 break;
00135 case kt_time:
00136 ws->raiseWidget(1);
00137 break;
00138 case kt_date:
00139 ws->raiseWidget(2);
00140 break;
00141 default:
00142 return;
00143 }
00144 }
00145
00149 void TVBrowseKeyEntry::changeKeyMenuSlot()
00150 {
00151 if(ts)
00152 keyMenu->exec(changeKeyButton->mapToGlobal(QPoint(0,0)));
00153 }
00158 void TVBrowseKeyEntry::resetKeySlot() {
00159 ;
00160 }
00161
00162 void TVBrowseKeyEntry::setTableState(TableState *t) {
00163 int i;
00164 ts = t;
00165
00166
00167 keyMenu->clear();
00168
00169 for (i = 0; i < t->kRep->getNumFields(); i++) {
00170 keyMenu->insertItem(ts->kRep->getKeyName(i), this,
00171 SLOT(changeKeySlot(int)), 0, i);
00172 keyMenu->setItemParameter(i, i);
00173 }
00174 }
00175
00180 void TVBrowseKeyEntry::searchOnText()
00181 {
00182 void *sendkey;
00183 int tmp;
00184
00185 switch(ts->kRep->getKeyType(ts->current_column)) {
00186
00187 case kt_string:
00188 sendkey = (void *)new QString(textKey->text());
00189 break;
00190 case kt_int: {
00191 bool ok;
00192 tmp = textKey->text().toInt(&ok);
00193 sendkey = &tmp;
00194 if (!ok)
00195 return;
00196 break;
00197 }
00198 case kt_time: {
00199 bool ok;
00200 int s,m,h;
00201 s = secondKey->text().toInt(&ok);
00202 if (!ok)
00203 return;
00204 m = minuteKey->text().toInt(&ok);
00205 if (!ok)
00206 return;
00207 h = hourKey->text().toInt(&ok);
00208 if (!ok)
00209 return;
00210 if(!QTime::isValid(h, m, s))
00211 return;
00212 sendkey = (void *) new QTime(h, m, s);
00213 break;
00214 }
00215 case kt_date: {
00216 bool ok;
00217 int d,m,y;
00218 d = dayKey->text().toInt(&ok);
00219 if (!ok)
00220 return;
00221 m = monthKey->text().toInt(&ok);
00222 if (!ok)
00223 return;
00224 y = yearKey->text().toInt(&ok);
00225 if (!ok)
00226 return;
00227 if(!QDate::isValid(y, m, d))
00228 return;
00229 sendkey = (void *) new QDate(y, m, d);
00230 break;
00231 }
00232 default:
00233 owarn << "TVBrowseKeyEntry::searchOnText() cannot work out data type" << oendl;
00234 return;
00235 }
00236 emit searchOnKey(ts->current_column, sendkey);
00237 }
00238