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

keys.cpp

Go to the documentation of this file.
00001 
00002 #include "portable.h"
00003 
00004 #if defined( KDE2_PORT )
00005 #include <kapp.h>
00006 #include <kconfig.h>
00007 #include <klocale.h>
00008 #include <kstddirs.h>
00009 #include <kaccel.h>
00010 
00011 #include <keys.h>
00012 #include <keys.moc>
00013 #elif defined( QPE_PORT )
00014 #include <qaccel.h>
00015 #include <qpe/qpeapplication.h>
00016 #include <qpe/config.h>
00017 #include "keys.h"
00018 #endif
00019 
00020 #include <qpushbt.h>
00021 
00022 Keys::Keys( QWidget *parent, const char *name)
00023     : QDialog( parent, name, TRUE )
00024 {
00025     //KStandardDirs *dirs = KGlobal::dirs();
00026 
00027     QPushButton *okButton  = new QPushButton(this);
00028     okButton->setText(tr("Ok"));
00029     okButton->setFixedSize(okButton->size());
00030     connect( okButton, SIGNAL(clicked()),this, SLOT(ok()) );
00031     okButton->move(20,210);
00032 
00033     QPushButton *defaultButton  = new QPushButton(this);
00034     defaultButton->setText(tr("Defaults"));
00035     defaultButton->setFixedSize(defaultButton->size());
00036     connect( defaultButton, SIGNAL(clicked()),this, SLOT(defaults()) );
00037     defaultButton->move(140,210);
00038 
00039     QPushButton *cancelButton  = new QPushButton(this);
00040     cancelButton->setText(tr("Cancel"));
00041     cancelButton->setFixedSize(cancelButton->size());
00042     connect( cancelButton, SIGNAL(clicked()),this, SLOT(reject()) );
00043     cancelButton->move(260,210);
00044 
00045     QFrame *separator = new QFrame(this);
00046     separator->setFrameStyle( QFrame::HLine | QFrame::Sunken );
00047     separator->setGeometry( 20, 190, 340, 4 );
00048 
00049     for ( int x = 0; x < 4; x++) {
00050             QLabel *l = new QLabel(this);
00051             l->setAlignment(AlignCenter);
00052             labels[x] = l;
00053     }
00054 
00055     labels[0]->setGeometry(120, 20, 140, 20 );
00056     labels[1]->setGeometry(120,160, 140, 20 );
00057     labels[2]->setGeometry( 20, 92, 100, 20 );
00058     labels[3]->setGeometry(265, 92, 100, 20 );
00059 
00060     QString pixPath;
00061 
00062     QPushButton *up = new QPushButton(this);
00063     pixPath = FIND_APP_DATA( "pics/up.xpm" );
00064     up->setPixmap( QPixmap(pixPath));
00065     up->setFixedSize(up->pixmap()->size());
00066     connect( up, SIGNAL(clicked()),this, SLOT(butUp()) );
00067     up->move(180, 50);
00068 
00069     QPushButton *down = new QPushButton(this);
00070     pixPath = FIND_APP_DATA( "pics/down.xpm");
00071     down->setPixmap( QPixmap(pixPath));
00072     down->setFixedSize(down->pixmap()->size());
00073     connect( down, SIGNAL(clicked()),this, SLOT(butDown()) );
00074     down->move(180, 130);
00075 
00076     QPushButton *left = new QPushButton(this);
00077     pixPath = FIND_APP_DATA( "pics/left.xpm");
00078     left->setPixmap( QPixmap(pixPath));
00079     left->setFixedSize(left->pixmap()->size());
00080     connect( left, SIGNAL(clicked()),this, SLOT(butLeft()) );
00081     left->move(140, 90);
00082 
00083     QPushButton *right = new QPushButton(this);
00084     pixPath = FIND_APP_DATA( "pics/right.xpm");
00085     right->setPixmap( QPixmap(pixPath));
00086     right->setFixedSize(right->pixmap()->size());
00087     connect( right, SIGNAL(clicked()),this, SLOT(butRight()) );
00088     right->move(220, 90);
00089 
00090 
00091     setCaption(tr("Change Direction Keys"));
00092     setFixedSize(380, 260);
00093     lab = 0;
00094     init();
00095 }
00096 
00097 void Keys::keyPressEvent( QKeyEvent *e )
00098 {
00099         uint kCode = e->key() & ~(SHIFT | CTRL | ALT);
00100         QString string = KAccel::keyToString(kCode);
00101 
00102         if (lab != 0) {
00103             if ( string.isNull() )
00104                     lab->setText(tr("Undefined key"));
00105             else
00106                 lab->setText(string);
00107         }
00108         else if ( lab == 0 && e->key() == Key_Escape)
00109             reject();
00110 }
00111 
00112 void Keys::butUp()
00113 {
00114     getKey(0);
00115 }
00116 
00117 void Keys::butDown()
00118 {
00119     getKey(1);
00120 }
00121 
00122 void Keys::butLeft()
00123 {
00124     getKey(2);
00125 }
00126 
00127 void Keys::butRight()
00128 {
00129     getKey(3);
00130 }
00131 
00132 void Keys::getKey(int i)
00133 {
00134     if ( lab != 0)
00135             focusOut(lab);
00136 
00137     focusIn(labels[i]);
00138 }
00139 
00140 void Keys::focusOut(QLabel *l)
00141 {
00142     l->setFrameStyle( QFrame::NoFrame );
00143     l->setBackgroundColor(backgroundColor());
00144     l->repaint();
00145 }
00146 
00147 void Keys::focusIn(QLabel *l)
00148 {
00149     lab = l;
00150     lab->setFrameStyle( QFrame::Panel | QFrame::Sunken );
00151     lab->setBackgroundColor(white);
00152     lab->repaint();
00153 }
00154 
00155 void Keys::defaults()
00156 {
00157     if ( lab != 0)
00158             focusOut(lab);
00159 
00160     lab = 0;
00161 
00162     labels[0]->setText("Up");
00163     labels[1]->setText("Down");
00164     labels[2]->setText("Left");
00165     labels[3]->setText("Right");
00166 }
00167 
00168 void Keys::init()
00169 {
00170     APP_CONFIG_BEGIN( cfg );
00171     QString up("Up");
00172     up = cfg->readEntry("upKey", (const char*) up);
00173     labels[0]->setText(up);
00174 
00175     QString down("Down");
00176     down = cfg->readEntry("downKey", (const char*) down);
00177     labels[1]->setText(down);
00178 
00179     QString left("Left");
00180     left = cfg->readEntry("leftKey", (const char*) left);
00181     labels[2]->setText(left);
00182 
00183     QString right("Right");
00184     right = cfg->readEntry("rightKey", (const char*) right);
00185     labels[3]->setText(right);
00186     APP_CONFIG_END( cfg );
00187 }
00188 
00189 void Keys::ok()
00190 {
00191   /*
00192     APP_CONFIG_BEGIN( cfg );
00193     cfg->writeEntry("upKey",   (const char*) labels[0]->text() );
00194     cfg->writeEntry("downKey", (const char*) labels[1]->text() );
00195     cfg->writeEntry("leftKey", (const char*) labels[2]->text() );
00196     cfg->writeEntry("rightKey",(const char*) labels[3]->text() );
00197     APP_CONFIG_END( cfg );
00198   */
00199     accept();
00200 }

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