summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/examples/opieui/okeyconfigwidget/testwidget.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/libopie2/examples/opieui/okeyconfigwidget/testwidget.cpp b/libopie2/examples/opieui/okeyconfigwidget/testwidget.cpp
index 329df09..5553166 100644
--- a/libopie2/examples/opieui/okeyconfigwidget/testwidget.cpp
+++ b/libopie2/examples/opieui/okeyconfigwidget/testwidget.cpp
@@ -1,122 +1,126 @@
1#include "testwidget.h" 1#include "testwidget.h"
2 2
3#include "okeyconfigwidget.h" 3#include "okeyconfigwidget.h"
4 4
5#include <opie2/oapplicationfactory.h> 5#include <opie2/oapplicationfactory.h>
6#include <opie2/otabwidget.h> 6#include <opie2/otabwidget.h>
7 7
8#include <qpe/qpeapplication.h> 8#include <qpe/qpeapplication.h>
9 9
10#include <qevent.h> 10#include <qevent.h>
11#include <qlayout.h> 11#include <qlayout.h>
12#include <qpushbutton.h> 12#include <qpushbutton.h>
13#include <qmainwindow.h> 13#include <qmainwindow.h>
14#include <qdialog.h> 14#include <qdialog.h>
15 15
16 16
17/** 17/**
18 * QObject with signals and slots inside a .cpp 18 * QObject with signals and slots inside a .cpp
19 * requires the .moc at the bottom! and a run of qmake 19 * requires the .moc at the bottom! and a run of qmake
20 */ 20 */
21class MainWindow : public QMainWindow { 21class MainWindow : public QMainWindow {
22 Q_OBJECT 22 Q_OBJECT
23public: 23public:
24 static QString appName() { 24 static QString appName() {
25 return QString::fromLatin1("keyconfig"); 25 return QString::fromLatin1("keyconfig");
26 } 26 }
27 MainWindow( QWidget*, const char*, WFlags fl ); 27 MainWindow( QWidget*, const char*, WFlags fl );
28 ~MainWindow() {} 28 ~MainWindow() {}
29private slots: 29private slots:
30 void slotClicked(); 30 void slotClicked();
31private: 31private:
32 Opie::Ui::OKeyConfigManager *m_manager; 32 Opie::Ui::OKeyConfigManager *m_manager;
33}; 33};
34 34
35 35
36OPIE_EXPORT_APP( Opie::Core::OApplicationFactory<MainWindow> ) 36OPIE_EXPORT_APP( Opie::Core::OApplicationFactory<MainWindow> )
37 37
38 38
39MainWindow::MainWindow( QWidget* parent, const char* name, WFlags fl ) 39MainWindow::MainWindow( QWidget* parent, const char* name, WFlags fl )
40 : QMainWindow( parent, name, fl ) 40 : QMainWindow( parent, name, fl )
41{ 41{
42 QVBoxLayout *lay = new QVBoxLayout( this ); 42 QVBoxLayout *lay = new QVBoxLayout( this );
43 QPushButton *btn = new QPushButton( tr("Configure" ), this ); 43 QPushButton *btn = new QPushButton( tr("Configure" ), this );
44 TestMainWindow *wid = new TestMainWindow( this, "name", 0 ); 44 TestMainWindow *wid = new TestMainWindow( this, "name", 0 );
45 45
46 lay->addWidget( btn ); 46 lay->addWidget( btn );
47 lay->addWidget( wid ); 47 lay->addWidget( wid );
48 m_manager = wid->manager(); 48 m_manager = wid->manager();
49 49
50 connect( btn, SIGNAL(clicked()), this, SLOT(slotClicked()) ); 50 connect( btn, SIGNAL(clicked()), this, SLOT(slotClicked()) );
51} 51}
52 52
53void MainWindow::slotClicked() { 53void MainWindow::slotClicked() {
54 QDialog diag( this, "name", true ); 54 QDialog diag( this, "name", true );
55 QHBoxLayout *lay = new QHBoxLayout( &diag ); 55 QHBoxLayout *lay = new QHBoxLayout( &diag );
56 Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget( &diag, "key config" ); 56 Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget( &diag, "key config" );
57 wid->setChangeMode( Opie::Ui::OKeyConfigWidget::Queue ); 57 wid->setChangeMode( Opie::Ui::OKeyConfigWidget::Queue );
58 wid->insert( tr("MainWindow Options" ), m_manager ); 58 wid->insert( tr("MainWindow Options" ), m_manager );
59 wid->load(); 59 wid->load();
60 60
61 lay->addWidget( wid ); 61 lay->addWidget( wid );
62 62
63 if ( QPEApplication::execDialog( &diag ) == QDialog::Accepted ) { 63 if ( QPEApplication::execDialog( &diag ) == QDialog::Accepted ) {
64 wid->save(); 64 wid->save();
65 } 65 }
66} 66}
67 67
68TestMainWindow::TestMainWindow( QWidget* parent, const char* slot, WFlags fl ) 68TestMainWindow::TestMainWindow( QWidget* parent, const char* slot, WFlags fl )
69 : Opie::Ui::OListView( parent, slot, fl) 69 : Opie::Ui::OListView( parent, slot, fl)
70{ 70{
71 addColumn( tr( "A Doo" ) ); 71 addColumn( tr( "A Doo" ) );
72 addColumn( tr( "B Doo" ) ); 72 addColumn( tr( "B Doo" ) );
73 73
74 m_config = new Opie::Core::OConfig( "test_config_foo" ); 74 m_config = new Opie::Core::OConfig( "test_config_foo" );
75 75
76 /* generate the black list */ 76 /* generate the black list */
77 Opie::Ui::OKeyPair::List blackList; 77 Opie::Ui::OKeyPair::List blackList;
78 blackList.append( Opie::Ui::OKeyPair::leftArrowKey() ); 78 blackList.append( Opie::Ui::OKeyPair::leftArrowKey() );
79 blackList.append( Opie::Ui::OKeyPair::rightArrowKey() ); 79 blackList.append( Opie::Ui::OKeyPair::rightArrowKey() );
80 blackList.append( Opie::Ui::OKeyPair::downArrowKey() ); 80 blackList.append( Opie::Ui::OKeyPair::downArrowKey() );
81 blackList.append( Opie::Ui::OKeyPair::upArrowKey() ); 81 blackList.append( Opie::Ui::OKeyPair::upArrowKey() );
82 82
83 m_manager = new Opie::Ui::OKeyConfigManager( m_config, "Key Group", 83 m_manager = new Opie::Ui::OKeyConfigManager( m_config, "Key Group",
84 blackList, false, this, "Key Manager" ); 84 blackList, false, this, "Key Manager" );
85 85
86 m_manager->addKeyConfig( Opie::Ui::OKeyConfigItem( tr( "Delete Action" ), "delete_key", QPixmap(), 86 m_manager->addKeyConfig( Opie::Ui::OKeyConfigItem( tr( "Delete Action" ), "delete_key", QPixmap(),
87 10, Opie::Ui::OKeyPair( Qt::Key_D, 0 ), this, 87 10, Opie::Ui::OKeyPair( Qt::Key_D, Qt::ShiftButton ), this,
88 SLOT(slotDelete(QWidget*,QKeyEvent*)) ) ); 88 SLOT(slotDelete(QWidget*,QKeyEvent*)) ) );
89 m_manager->addKeyConfig( Opie::Ui::OKeyConfigItem( tr( "Show Action" ), "show_key", QPixmap(),
90 11, Opie::Ui::OKeyPair( Qt::Key_S, Qt::AltButton ) ) );
89 91
90 connect(m_manager, SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&)), 92 connect(m_manager, SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&)),
91 this, SLOT(slotAction(QWidget*, QKeyEvent*, const Opie::Ui::OKeyConfigItem&)) ); 93 this, SLOT(slotAction(QWidget*, QKeyEvent*, const Opie::Ui::OKeyConfigItem&)) );
92// when commenting the line below out the keyPressEvent will work 94// when commenting the line below out the keyPressEvent will work
93 m_manager->handleWidget( this ); 95 m_manager->handleWidget( this );
94 m_manager->load(); 96 m_manager->load();
95} 97}
96 98
97TestMainWindow::~TestMainWindow() { 99TestMainWindow::~TestMainWindow() {
98 m_manager->save(); 100 m_manager->save();
101 delete m_config;
99} 102}
100 103
101Opie::Ui::OKeyConfigManager* TestMainWindow::manager() { 104Opie::Ui::OKeyConfigManager* TestMainWindow::manager() {
102 return m_manager; 105 return m_manager;
103} 106}
104 107
105/* 108/*
106 * This only works if we do not handle the even with m_manager->handleWidget( this ) 109 * This only works if we do not handle the even with m_manager->handleWidget( this )
107 * So this is only for demo purposes 110 * So this is only for demo purposes
108 */ 111 */
109void TestMainWindow::keyPressEvent( QKeyEvent* ev ) { 112void TestMainWindow::keyPressEvent( QKeyEvent* ev ) {
110 qWarning( "String is "+ m_manager->handleKeyEvent( ev ).text() ); 113 qWarning( "String is "+ m_manager->handleKeyEvent( ev ).text() );
111 qWarning( "Id was %d", m_manager->handleKeyEventId( ev ) ); 114 qWarning( "Id was %d %d %d %d", m_manager->handleKeyEventId( ev ),ev->key(),ev->state(), ev->ascii() );
115 ev->ignore();
112} 116}
113 117
114void TestMainWindow::slotDelete( QWidget* wid, QKeyEvent* ev ) { 118void TestMainWindow::slotDelete( QWidget* wid, QKeyEvent* ev ) {
115 qWarning( "Slot Delete %d %d %d", wid, ev->key(), ev->state() ); 119 qWarning( "Slot Delete %d %d %d", wid, ev->key(), ev->state() );
116} 120}
117 121
118void TestMainWindow::slotAction( QWidget* wid, QKeyEvent* ev, const Opie::Ui::OKeyConfigItem& item) { 122void TestMainWindow::slotAction( QWidget* wid, QKeyEvent* ev, const Opie::Ui::OKeyConfigItem& item) {
119 qWarning( "Slot Action %d %d %d %s %d", wid, ev->key(), ev->state(), item.text().latin1(), item.id() ); 123 qWarning( "Slot Action %d %d %d %s %d", wid, ev->key(), ev->state(), item.text().latin1(), item.id() );
120} 124}
121 125
122#include "testwidget.moc" 126#include "testwidget.moc"