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

testwidget.cpp

Go to the documentation of this file.
00001 #include "testwidget.h"
00002 
00003 #include <opie2/okeyconfigwidget.h>
00004 
00005 #include <opie2/oapplicationfactory.h>
00006 #include <opie2/otabwidget.h>
00007 
00008 #include <qpe/qpeapplication.h>
00009 
00010 #include <qevent.h>
00011 #include <qlayout.h>
00012 #include <qpushbutton.h>
00013 #include <qmainwindow.h>
00014 #include <qdialog.h>
00015 
00016 
00021 class MainWindow : public QMainWindow {
00022     Q_OBJECT
00023 public:
00024     static QString appName() {
00025         return QString::fromLatin1("keyconfig");
00026     }
00027     MainWindow( QWidget*, const char*, WFlags fl );
00028     ~MainWindow() {}
00029 private slots:
00030     void slotClicked();
00031 private:
00032     Opie::Core::OKeyConfigManager *m_manager;
00033 };
00034 
00035 
00036 OPIE_EXPORT_APP(  Opie::Core::OApplicationFactory<MainWindow> )
00037 
00038 
00039 MainWindow::MainWindow( QWidget* parent, const char* name, WFlags fl )
00040     : QMainWindow( parent, name, fl )
00041 {
00042     QVBoxLayout *lay = new QVBoxLayout( this );
00043     QPushButton *btn = new QPushButton( tr("Configure" ), this );
00044     TestMainWindow *wid = new TestMainWindow( this, "name", 0 );
00045 
00046     lay->addWidget( btn );
00047     lay->addWidget( wid );
00048     m_manager = wid->manager();
00049 
00050     connect( btn, SIGNAL(clicked()), this, SLOT(slotClicked()) );
00051 }
00052 
00053 void MainWindow::slotClicked() {
00054     QDialog diag( this, "name", true );
00055     diag.setCaption( tr( "Manage Keys" ) );
00056 
00057     QHBoxLayout *lay = new QHBoxLayout( &diag );
00058     Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget( &diag, "key config" );
00059     wid->setChangeMode( Opie::Ui::OKeyConfigWidget::Queue );
00060     wid->insert( tr("MainWindow Options" ), m_manager );
00061     wid->load();
00062 
00063     lay->addWidget( wid );
00064 
00065     if ( QPEApplication::execDialog( &diag ) == QDialog::Accepted ) {
00066         wid->save();
00067     }
00068 }
00069 
00070 TestMainWindow::TestMainWindow( QWidget* parent, const char* slot, WFlags fl )
00071     : Opie::Ui::OListView( parent, slot, fl)
00072 {
00073     addColumn( tr( "A Doo" ) );
00074     addColumn( tr( "B Doo" ) );
00075 
00076     m_config  = new Opie::Core::OConfig( "test_config_foo" );
00077 
00078     /* generate the black list */
00079     Opie::Core::OKeyPair::List blackList;
00080     blackList.append( Opie::Core::OKeyPair::leftArrowKey() );
00081     blackList.append( Opie::Core::OKeyPair::rightArrowKey() );
00082     blackList.append( Opie::Core::OKeyPair::downArrowKey() );
00083     blackList.append( Opie::Core::OKeyPair::upArrowKey() );
00084 
00085     m_manager = new Opie::Core::OKeyConfigManager( m_config, "Key Group",
00086                                                  blackList, false, this, "Key Manager" );
00087 
00088     m_manager->addKeyConfig( Opie::Core::OKeyConfigItem( tr( "Delete Action" ), "delete_key", QPixmap(),
00089                                                        10, Opie::Core::OKeyPair( Qt::Key_D, Qt::ShiftButton ), this,
00090                                                        SLOT(slotDelete(QWidget*,QKeyEvent*)) ) );
00091     m_manager->addKeyConfig( Opie::Core::OKeyConfigItem( tr( "Show Action" ), "show_key", QPixmap(),
00092                                                        11, Opie::Core::OKeyPair( Qt::Key_S, Qt::AltButton ) ) );
00093 
00094     connect(m_manager, SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Core::OKeyConfigItem&)),
00095             this, SLOT(slotAction(QWidget*, QKeyEvent*, const Opie::Core::OKeyConfigItem&)) );
00096 // when commenting the line below out the keyPressEvent will work
00097     m_manager->handleWidget( this );
00098     m_manager->load();
00099 }
00100 
00101 TestMainWindow::~TestMainWindow() {
00102     m_manager->save();
00103     delete m_config;
00104 }
00105 
00106 Opie::Core::OKeyConfigManager* TestMainWindow::manager() {
00107     return m_manager;
00108 }
00109 
00110 /*
00111  * This only works if we do not handle the even with m_manager->handleWidget( this )
00112  * So this is only for demo purposes
00113  */
00114 void TestMainWindow::keyPressEvent( QKeyEvent* ev ) {
00115     owarn << "String is "+ m_manager->handleKeyEvent( ev ).text() << oendl; 
00116     owarn << "Id was " << m_manager->handleKeyEventId( ev ) << " " << ev->key() << " " << ev->state() << " " << ev->ascii() << "" << oendl; 
00117     ev->ignore();
00118 }
00119 
00120 void TestMainWindow::slotDelete( QWidget* wid, QKeyEvent* ev ) {
00121     owarn << "Slot Delete " << wid << " " << ev->key() << " " << ev->state() << "" << oendl; 
00122 }
00123 
00124 void TestMainWindow::slotAction( QWidget* wid, QKeyEvent* ev, const Opie::Core::OKeyConfigItem& item) {
00125     owarn << "Slot Action " << wid << " " << ev->key() << " " << ev->state() << " " << item.text() << " " << item.id() << "" << oendl; 
00126 }
00127 
00128 #include "testwidget.moc"

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