Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

browsekeyentry.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 #include "browsekeyentry.h"
00021 #include "commonwidgets.h"
00022 
00023 #include <opie2/odebug.h>
00024 using namespace Opie::Core;
00025 
00026 #include <qtoolbutton.h>
00027 #include <qwidgetstack.h>
00028 #include <qlayout.h>
00029 #include <qlineedit.h>
00030 #include <qpushbutton.h>
00031 #include <qpopupmenu.h>
00032 #include <qhbox.h>
00033 #include <qdatetime.h>
00034 
00047 TVBrowseKeyEntry::TVBrowseKeyEntry(QWidget *parent, const char *name, WFlags f)
00048     : QWidget(parent, name, f)
00049 {
00050     QHBoxLayout *h_layout = new QHBoxLayout(this);
00051 
00052     textKey = new QLineEdit(this, 0);
00053     intKey = new IntEdit(this, 0);
00054     dateKey = new DateEdit(this, 0);
00055     timeKey = new TimeEdit(this, 0);
00056 
00057     resetButton = new QPushButton(this, "reset");
00058     resetButton->setMinimumSize(QSize(50, 0));
00059     resetButton->setText(tr("Reset"));
00060 
00061     changeKeyButton = new QToolButton(this, "changekey");
00062     // TODO The icon stuff.
00063     changeKeyButton->setText(tr("key"));
00064 
00065     totalKeys = 0;
00066     ts = 0;
00067     keyMenu = new QPopupMenu(this, "keymenu");
00068 
00069     ws = new QWidgetStack(this, 0);
00070     ws->addWidget(textKey, TVVariant::String);
00071     ws->addWidget(intKey, TVVariant::Int);
00072     ws->addWidget(timeKey, TVVariant::Time);
00073     ws->addWidget(dateKey, TVVariant::Date);
00074 
00075     ws->raiseWidget(TVVariant::String);
00076 
00077     // TODO connect slots and signals....
00078     connect(changeKeyButton, SIGNAL(clicked()),
00079             this, SLOT(changeKeyMenuSlot()));
00080 
00081     connect(resetButton, SIGNAL(clicked()),
00082             textKey, SLOT(clear()));
00083     connect(resetButton, SIGNAL(clicked()),
00084             intKey, SLOT(clear()));
00085     connect(resetButton, SIGNAL(clicked()),
00086             dateKey, SLOT(clear()));
00087     connect(resetButton, SIGNAL(clicked()),
00088             timeKey, SLOT(clear()));
00089 
00090     h_layout->addWidget(ws);
00091     h_layout->addWidget(resetButton);
00092     h_layout->addWidget(changeKeyButton);
00093 
00094     connect(textKey, SIGNAL(textChanged(const QString&)),
00095             this, SLOT(searchOnText()));
00096     connect(intKey, SIGNAL(valueChanged(int)),
00097             this, SLOT(searchOnText()));
00098     connect(dateKey, SIGNAL(valueChanged(const QDate&)),
00099             this, SLOT(searchOnText()));
00100     connect(timeKey, SIGNAL(valueChanged(const QTime&)),
00101             this, SLOT(searchOnText()));
00102 }
00103 
00107 TVBrowseKeyEntry::~TVBrowseKeyEntry()
00108 {
00109 }
00110 
00116 void TVBrowseKeyEntry::changeKeySlot(int id_param)
00117 {
00118     if(ts) {
00119         emit sortChanged(id_param);
00120         ws->raiseWidget(ts->kRep->getKeyType(ts->current_column));
00121     }
00122 }
00123 
00127 void TVBrowseKeyEntry::changeKeyMenuSlot()
00128 {
00129     if(ts)
00130         keyMenu->exec(changeKeyButton->mapToGlobal(QPoint(0,0)));
00131 }
00132 
00133 
00134 void TVBrowseKeyEntry::setTableState(TableState *t) {
00135     ts = t;
00136 }
00137 
00138 void TVBrowseKeyEntry::rebuildKeys() {
00139     int i;
00140     if (!ts) return;
00141     if (!ts->kRep) return;
00142 
00143     /* clear the old */
00144     keyMenu->clear();
00145 
00146     KeyListIterator it(*ts->kRep);
00147 
00148     for (i = 0; i < ts->kRep->getNumFields(); i++) {
00149         keyMenu->insertItem(it.current()->name(), this,
00150                 SLOT(changeKeySlot(int)), 0, i);
00151         keyMenu->setItemParameter(i, it.currentKey());
00152         ++it;
00153     }
00154 }
00155 
00156 void TVBrowseKeyEntry::reset()
00157 {
00158     textKey->clear();
00159     intKey->clear();
00160     dateKey->clear();
00161     timeKey->clear();
00162 
00163     keyMenu->clear();
00164 }
00169 void TVBrowseKeyEntry::searchOnText()
00170 {
00171     TVVariant sendkey;
00172 
00173     if (!ts)
00174         return;
00175 
00176     switch(ts->kRep->getKeyType(ts->current_column)) {
00177         case TVVariant::String:
00178             sendkey = TVVariant(QString(textKey->text()));
00179             break;
00180         case TVVariant::Int: {
00181             sendkey = TVVariant(intKey->value());
00182             break;
00183         }
00184         case TVVariant::Time: {
00185             sendkey = TVVariant(QTime(timeKey->time()));
00186             break;
00187         }
00188         case TVVariant::Date: {
00189             sendkey = TVVariant(QDate(dateKey->date()));
00190             break;
00191         }
00192     case TVVariant::Invalid:
00193         break;
00194         default:
00195             owarn << "TVBrowseKeyEntry::searchOnText() cannot work out data type" << oendl;
00196             return;
00197     }
00198     emit searchOnKey(ts->current_column, sendkey);
00199 }
00200 

Generated on Sat Nov 5 16:17:07 2005 for OPIE by  doxygen 1.4.2