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