author | zecke <zecke> | 2004-03-26 22:57:49 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-03-26 22:57:49 (UTC) |
commit | dbd543660350e58b7d975e884439b0fbe314ef28 (patch) (unidiff) | |
tree | 7ecbd79cc2031ff38e06a5b8742fbd5b0907798d | |
parent | c54a3c8cc47258743381d4dee4200304d247182d (diff) | |
download | opie-dbd543660350e58b7d975e884439b0fbe314ef28.zip opie-dbd543660350e58b7d975e884439b0fbe314ef28.tar.gz opie-dbd543660350e58b7d975e884439b0fbe314ef28.tar.bz2 |
A small example/test for the OKeyConfigWidget currently
in opie-eye. So you see my intention where it should end
3 files changed, 174 insertions, 0 deletions
diff --git a/libopie2/examples/opieui/okeyconfigwidget/keyconfig.pro b/libopie2/examples/opieui/okeyconfigwidget/keyconfig.pro new file mode 100644 index 0000000..b38cf3b --- a/dev/null +++ b/libopie2/examples/opieui/okeyconfigwidget/keyconfig.pro | |||
@@ -0,0 +1,12 @@ | |||
1 | CONFIG += qt debug | ||
2 | |||
3 | TEMPLATE = app | ||
4 | SOURCES = ../../../../noncore/graphics/opie-eye/lib/okeyconfigwidget.cpp testwidget.cpp | ||
5 | HEADERS = ../../../../noncore/graphics/opie-eye/lib/okeyconfigwidget.h testwidget.h | ||
6 | |||
7 | INCLUDEPATH += $(OPIEDIR)/include $(OPIEDIR)/noncore/graphics/opie-eye/lib/ | ||
8 | DESTPATH += $(OPIEDIR)/include | ||
9 | |||
10 | LIBS += -lopieui2 -lopiecore2 | ||
11 | |||
12 | include ( $(OPIEDIR)/include.pro ) | ||
diff --git a/libopie2/examples/opieui/okeyconfigwidget/testwidget.cpp b/libopie2/examples/opieui/okeyconfigwidget/testwidget.cpp new file mode 100644 index 0000000..329df09 --- a/dev/null +++ b/libopie2/examples/opieui/okeyconfigwidget/testwidget.cpp | |||
@@ -0,0 +1,122 @@ | |||
1 | #include "testwidget.h" | ||
2 | |||
3 | #include "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::Ui::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 | QHBoxLayout *lay = new QHBoxLayout( &diag ); | ||
56 | Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget( &diag, "key config" ); | ||
57 | wid->setChangeMode( Opie::Ui::OKeyConfigWidget::Queue ); | ||
58 | wid->insert( tr("MainWindow Options" ), m_manager ); | ||
59 | wid->load(); | ||
60 | |||
61 | lay->addWidget( wid ); | ||
62 | |||
63 | if ( QPEApplication::execDialog( &diag ) == QDialog::Accepted ) { | ||
64 | wid->save(); | ||
65 | } | ||
66 | } | ||
67 | |||
68 | TestMainWindow::TestMainWindow( QWidget* parent, const char* slot, WFlags fl ) | ||
69 | : Opie::Ui::OListView( parent, slot, fl) | ||
70 | { | ||
71 | addColumn( tr( "A Doo" ) ); | ||
72 | addColumn( tr( "B Doo" ) ); | ||
73 | |||
74 | m_config = new Opie::Core::OConfig( "test_config_foo" ); | ||
75 | |||
76 | /* generate the black list */ | ||
77 | Opie::Ui::OKeyPair::List blackList; | ||
78 | blackList.append( Opie::Ui::OKeyPair::leftArrowKey() ); | ||
79 | blackList.append( Opie::Ui::OKeyPair::rightArrowKey() ); | ||
80 | blackList.append( Opie::Ui::OKeyPair::downArrowKey() ); | ||
81 | blackList.append( Opie::Ui::OKeyPair::upArrowKey() ); | ||
82 | |||
83 | m_manager = new Opie::Ui::OKeyConfigManager( m_config, "Key Group", | ||
84 | blackList, false, this, "Key Manager" ); | ||
85 | |||
86 | m_manager->addKeyConfig( Opie::Ui::OKeyConfigItem( tr( "Delete Action" ), "delete_key", QPixmap(), | ||
87 | 10, Opie::Ui::OKeyPair( Qt::Key_D, 0 ), this, | ||
88 | SLOT(slotDelete(QWidget*,QKeyEvent*)) ) ); | ||
89 | |||
90 | connect(m_manager, SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&)), | ||
91 | this, SLOT(slotAction(QWidget*, QKeyEvent*, const Opie::Ui::OKeyConfigItem&)) ); | ||
92 | // when commenting the line below out the keyPressEvent will work | ||
93 | m_manager->handleWidget( this ); | ||
94 | m_manager->load(); | ||
95 | } | ||
96 | |||
97 | TestMainWindow::~TestMainWindow() { | ||
98 | m_manager->save(); | ||
99 | } | ||
100 | |||
101 | Opie::Ui::OKeyConfigManager* TestMainWindow::manager() { | ||
102 | return m_manager; | ||
103 | } | ||
104 | |||
105 | /* | ||
106 | * This only works if we do not handle the even with m_manager->handleWidget( this ) | ||
107 | * So this is only for demo purposes | ||
108 | */ | ||
109 | void TestMainWindow::keyPressEvent( QKeyEvent* ev ) { | ||
110 | qWarning( "String is "+ m_manager->handleKeyEvent( ev ).text() ); | ||
111 | qWarning( "Id was %d", m_manager->handleKeyEventId( ev ) ); | ||
112 | } | ||
113 | |||
114 | void TestMainWindow::slotDelete( QWidget* wid, QKeyEvent* ev ) { | ||
115 | qWarning( "Slot Delete %d %d %d", wid, ev->key(), ev->state() ); | ||
116 | } | ||
117 | |||
118 | void 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() ); | ||
120 | } | ||
121 | |||
122 | #include "testwidget.moc" | ||
diff --git a/libopie2/examples/opieui/okeyconfigwidget/testwidget.h b/libopie2/examples/opieui/okeyconfigwidget/testwidget.h new file mode 100644 index 0000000..b95c225 --- a/dev/null +++ b/libopie2/examples/opieui/okeyconfigwidget/testwidget.h | |||
@@ -0,0 +1,40 @@ | |||
1 | #ifndef TEST_WIDGET_H | ||
2 | #define TEST_WIDGET_H | ||
3 | |||
4 | #include <qmainwindow.h> | ||
5 | |||
6 | #include <opie2/olistview.h> | ||
7 | |||
8 | namespace Opie{ | ||
9 | namespace Ui{ | ||
10 | class OTabWidget; | ||
11 | class OKeyConfigManager; | ||
12 | class OListView; | ||
13 | class OKeyConfigItem; | ||
14 | } | ||
15 | namespace Core { | ||
16 | class OConfig; | ||
17 | } | ||
18 | } | ||
19 | class QKeyEvent; | ||
20 | |||
21 | |||
22 | class TestMainWindow : public Opie::Ui::OListView { | ||
23 | Q_OBJECT | ||
24 | public: | ||
25 | |||
26 | TestMainWindow(QWidget* parent, const char*, WFlags fl ); | ||
27 | ~TestMainWindow(); | ||
28 | |||
29 | Opie::Ui::OKeyConfigManager *manager(); | ||
30 | protected: | ||
31 | void keyPressEvent( QKeyEvent* ); | ||
32 | private slots: | ||
33 | void slotDelete( QWidget*, QKeyEvent* ); | ||
34 | void slotAction( QWidget*, QKeyEvent*, const Opie::Ui::OKeyConfigItem& ); | ||
35 | private: | ||
36 | Opie::Core::OConfig *m_config; | ||
37 | Opie::Ui::OKeyConfigManager *m_manager; | ||
38 | }; | ||
39 | |||
40 | #endif | ||