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

ButtonPrefs.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** Form implementation generated from reading ui file 'Prefs.ui'
00003 **
00004 ** Created: Tue Feb 11 23:53:35 2003
00005 **      by:  The User Interface Compiler (uic)
00006 **
00007 ** WARNING! All changes made in this file will be lost!
00008 ****************************************************************************/
00009 #include "ButtonPrefs.h"
00010 
00011 #include <qcheckbox.h>
00012 #include <qlabel.h>
00013 #include <qpushbutton.h>
00014 #include <qspinbox.h>
00015 #include <qlayout.h>
00016 #include <qvariant.h>
00017 #include <qtooltip.h>
00018 #include <qwhatsthis.h>
00019 #include <qbuttongroup.h>
00020 #include <qmultilineedit.h>
00021 #ifdef USECOMBO
00022 #include <qcombobox.h>
00023 #else
00024 #include <qpe/menubutton.h>
00025 #endif
00026 #include <qfontdatabase.h>
00027 
00028 #include <qlistview.h>
00029 
00030 class MyQListViewItem : public QListViewItem
00031 {
00032   orKey o;
00033 public:
00034   MyQListViewItem(const orKey& _o, QListView* p, const QString& c1, const QString& c2, const QString& c3) : QListViewItem(p, c1, c2, c3), o(_o) { }
00035   orKey getKey() { return o; }
00036 };
00037 
00038 void CButtonPrefs::mapkey(Qt::ButtonState st, int _key)
00039 {
00040   mapkey(st, _key,  action->currentItem());
00041 }
00042 
00043 void CButtonPrefs::mapkey(Qt::ButtonState st, int _key, int act)
00044 {
00045   orKey key(st, _key, ((act == cesScrollMore) || (act == cesScrollLess)));
00046   QMap<orKey,QListViewItem*>::Iterator iter = listmap.find(key);
00047   if (iter != listmap.end())
00048     {
00049       lb->takeItem(iter.data());
00050     }
00051   (*kmap)[key] = act;
00052   listmap[key] = new MyQListViewItem(key, lb, key.text(), action->text(act), (key.isScroll()) ? "*":"");
00053 }
00054 
00055 void CButtonPrefs::keyPressEvent(QKeyEvent* e)
00056 {
00057   switch (e->key())
00058     {
00059     case Key_Shift:
00060     case Key_Control:
00061     case Key_Meta:
00062     case Key_Alt:
00063     case Key_CapsLock:
00064     case Key_NumLock:
00065     case Key_ScrollLock:
00066       e->ignore();
00067       break;
00068     default:
00069       mapkey(e->state(), e->key());
00070       e->accept();
00071       break;
00072     }
00073 }
00074 
00075 #ifdef USECOMBO
00076 void CButtonPrefs::populate(QComboBox *mb)
00077 #else
00078 void CButtonPrefs::populate(MenuButton *mb)
00079 #endif
00080 {
00081     mb->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
00082     mb->insertItem( tr("Open file") );
00083     mb->insertItem( tr("Autoscroll") );
00084     mb->insertItem( tr("Bookmark") );
00085     mb->insertItem( tr("Annotate") );
00086     mb->insertItem( tr("Fullscreen") );
00087 
00088     mb->insertItem( tr("Zoom in") );
00089     mb->insertItem( tr("Zoom out") );
00090     mb->insertItem( tr("Back") );
00091     mb->insertItem( tr("Forward") );
00092     mb->insertItem( tr("Home") );
00093     mb->insertItem( tr("Page up") );
00094     mb->insertItem( tr("Page down") );
00095     mb->insertItem( tr("Line up") );
00096     mb->insertItem( tr("Line down") );
00097     mb->insertItem( tr("Beginning") );
00098     mb->insertItem( tr("End") );
00099     mb->insertItem( tr("Rotate") );
00100     mb->insertItem( tr("Scroll faster") );
00101     mb->insertItem( tr("Scroll slower") );
00102     mb->insertItem( tr("Invert colours") );
00103     mb->insertItem( tr("Toggle tools") );
00104     mb->insertItem( tr("Toggle scrollbar") );
00105     mb->insertItem( tr("Toggle statusbar") );
00106     mb->insertItem( tr("Next link") );
00107     mb->insertItem( tr("Goto link") );
00108 }
00109 
00110 CButtonPrefs::CButtonPrefs( QMap<orKey, int>* _kmap, QWidget* parent,  const char* name, WFlags fl )
00111   : QWidget( parent, name, fl ), kmap(_kmap)
00112 {
00113   QVBoxLayout* vo = new QVBoxLayout(this);
00114   QHBoxLayout* lo = new QHBoxLayout();
00115   setFocusPolicy(QWidget::StrongFocus);
00116 #ifdef USECOMBO
00117     action = new QComboBox( this );
00118 #else
00119     action = new MenuButton( this );
00120 #endif
00121     populate(action);
00122     action->setFocusProxy(this);
00123 
00124 
00125 
00126     QMultiLineEdit* TextLabel1 = new QMultiLineEdit( this );
00127     TextLabel1->setText( tr( "Press the key(s) you want assigned to the highlighted function.\n\nPress the delete button to unmap the key.\n\nUse the \"Close\" button (not the [x]) to finish." ) );
00128     TextLabel1->setReadOnly(true);
00129     TextLabel1->setWordWrap(QMultiLineEdit::WidgetWidth);
00130 
00131     //    lo->addWidget(TextLabel, 0, Qt::AlignTop);
00132     //    lo->addWidget(action, 0, Qt::AlignTop);
00133     lo->addWidget(TextLabel1);
00134     lo->addWidget(action);
00135     vo->addLayout(lo);
00136     lb = new QListView(this);
00137     lb->addColumn( tr( "Key" ) );
00138     lb->addColumn( tr( "Function" ) );
00139     lb->addColumn( tr( "Scroll" ) );
00140     lb->setFocusProxy(this);
00141     vo->addWidget(lb,1);
00142     for (QMap<orKey,int>::Iterator i = kmap->begin(); i != kmap->end(); i++)
00143       {
00144         listmap[i.key()] = new MyQListViewItem(i.key(), lb, i.key().text(), action->text(i.data()), (i.key().isScroll()) ? "*":"");
00145       }
00146 
00147     lo = new QHBoxLayout();
00148     QLabel* TextLabel = new QLabel( this, "TextLabel1" );
00149     TextLabel->setText( tr( "Debounce" ) );
00150     lo->addWidget(TextLabel);
00151 
00152     debounce = new QSpinBox( this, "Debounce" );
00153     debounce->setRange(0,1000);
00154     lo->addWidget(debounce);
00155     /*
00156     QPushButton* assignClose = new QPushButton("Assign\nCancel", this);
00157     lo->addWidget(assignClose);
00158     */
00159     lo->addStretch(1);
00160     QPushButton* delButton = new QPushButton("Delete", this);
00161     connect(delButton, SIGNAL( clicked() ), this, SLOT( erasemapping() ));
00162     lo->addWidget(delButton);     
00163     QPushButton* exitButton = new QPushButton("Close", this);
00164     connect(exitButton, SIGNAL( clicked() ), this, SLOT( slotClosed() ) );
00165     lo->addWidget(exitButton);     
00166     vo->addLayout(lo);
00167 }
00168 
00169 void CButtonPrefs::erasemapping()
00170 {
00171   MyQListViewItem* li = (MyQListViewItem*)lb->selectedItem();
00172   if (li != NULL)
00173     {
00174       orKey key(li->getKey());
00175       qDebug("Tapped %s", (const char*)key.text());
00176       kmap->remove(key);
00177       lb->takeItem(listmap[key]);
00178       listmap.remove(key);
00179     }
00180 }
00181 
00182 CButtonPrefs::~CButtonPrefs()
00183 {
00184     // no need to delete child widgets, Qt does it all for us
00185 }

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