summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/examples/opieui/okeyconfigwidget/keyconfig.pro12
-rw-r--r--libopie2/examples/opieui/okeyconfigwidget/testwidget.cpp122
-rw-r--r--libopie2/examples/opieui/okeyconfigwidget/testwidget.h40
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 @@
1CONFIG += qt debug
2
3TEMPLATE = app
4SOURCES = ../../../../noncore/graphics/opie-eye/lib/okeyconfigwidget.cpp testwidget.cpp
5HEADERS = ../../../../noncore/graphics/opie-eye/lib/okeyconfigwidget.h testwidget.h
6
7INCLUDEPATH += $(OPIEDIR)/include $(OPIEDIR)/noncore/graphics/opie-eye/lib/
8DESTPATH += $(OPIEDIR)/include
9
10LIBS += -lopieui2 -lopiecore2
11
12include ( $(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 */
21class MainWindow : public QMainWindow {
22 Q_OBJECT
23public:
24 static QString appName() {
25 return QString::fromLatin1("keyconfig");
26 }
27 MainWindow( QWidget*, const char*, WFlags fl );
28 ~MainWindow() {}
29private slots:
30 void slotClicked();
31private:
32 Opie::Ui::OKeyConfigManager *m_manager;
33};
34
35
36OPIE_EXPORT_APP( Opie::Core::OApplicationFactory<MainWindow> )
37
38
39MainWindow::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
53void 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
68TestMainWindow::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
97TestMainWindow::~TestMainWindow() {
98 m_manager->save();
99}
100
101Opie::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 */
109void TestMainWindow::keyPressEvent( QKeyEvent* ev ) {
110 qWarning( "String is "+ m_manager->handleKeyEvent( ev ).text() );
111 qWarning( "Id was %d", m_manager->handleKeyEventId( ev ) );
112}
113
114void TestMainWindow::slotDelete( QWidget* wid, QKeyEvent* ev ) {
115 qWarning( "Slot Delete %d %d %d", wid, ev->key(), ev->state() );
116}
117
118void 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
8namespace Opie{
9namespace Ui{
10 class OTabWidget;
11 class OKeyConfigManager;
12 class OListView;
13 class OKeyConfigItem;
14}
15namespace Core {
16 class OConfig;
17}
18}
19class QKeyEvent;
20
21
22class TestMainWindow : public Opie::Ui::OListView {
23 Q_OBJECT
24public:
25
26 TestMainWindow(QWidget* parent, const char*, WFlags fl );
27 ~TestMainWindow();
28
29 Opie::Ui::OKeyConfigManager *manager();
30protected:
31 void keyPressEvent( QKeyEvent* );
32private slots:
33 void slotDelete( QWidget*, QKeyEvent* );
34 void slotAction( QWidget*, QKeyEvent*, const Opie::Ui::OKeyConfigItem& );
35private:
36 Opie::Core::OConfig *m_config;
37 Opie::Ui::OKeyConfigManager *m_manager;
38};
39
40#endif