summaryrefslogtreecommitdiff
path: root/examples/opieui/okeyconfigwidget/testwidget.cpp
authormickeyl <mickeyl>2005-01-29 14:18:51 (UTC)
committer mickeyl <mickeyl>2005-01-29 14:18:51 (UTC)
commit555b999359a5aad999eaaf48632ce85f25125b85 (patch) (side-by-side diff)
tree7414362241e49e06f49486e93a8f504113961b1c /examples/opieui/okeyconfigwidget/testwidget.cpp
parent7b06e36fe27adc6a4fde2004eac13aaf8c0f0f02 (diff)
downloadopie-555b999359a5aad999eaaf48632ce85f25125b85.zip
opie-555b999359a5aad999eaaf48632ce85f25125b85.tar.gz
opie-555b999359a5aad999eaaf48632ce85f25125b85.tar.bz2
examples appear here
Diffstat (limited to 'examples/opieui/okeyconfigwidget/testwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--examples/opieui/okeyconfigwidget/testwidget.cpp128
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 @@
+#include "testwidget.h"
+
+#include <opie2/okeyconfigwidget.h>
+
+#include <opie2/oapplicationfactory.h>
+#include <opie2/otabwidget.h>
+
+#include <qpe/qpeapplication.h>
+
+#include <qevent.h>
+#include <qlayout.h>
+#include <qpushbutton.h>
+#include <qmainwindow.h>
+#include <qdialog.h>
+
+
+/**
+ * QObject with signals and slots inside a .cpp
+ * requires the .moc at the bottom! and a run of qmake
+ */
+class MainWindow : public QMainWindow {
+ Q_OBJECT
+public:
+ static QString appName() {
+ return QString::fromLatin1("keyconfig");
+ }
+ MainWindow( QWidget*, const char*, WFlags fl );
+ ~MainWindow() {}
+private slots:
+ void slotClicked();
+private:
+ Opie::Core::OKeyConfigManager *m_manager;
+};
+
+
+OPIE_EXPORT_APP( Opie::Core::OApplicationFactory<MainWindow> )
+
+
+MainWindow::MainWindow( QWidget* parent, const char* name, WFlags fl )
+ : QMainWindow( parent, name, fl )
+{
+ QVBoxLayout *lay = new QVBoxLayout( this );
+ QPushButton *btn = new QPushButton( tr("Configure" ), this );
+ TestMainWindow *wid = new TestMainWindow( this, "name", 0 );
+
+ lay->addWidget( btn );
+ lay->addWidget( wid );
+ m_manager = wid->manager();
+
+ connect( btn, SIGNAL(clicked()), this, SLOT(slotClicked()) );
+}
+
+void MainWindow::slotClicked() {
+ QDialog diag( this, "name", true );
+ diag.setCaption( tr( "Manage Keys" ) );
+
+ QHBoxLayout *lay = new QHBoxLayout( &diag );
+ Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget( &diag, "key config" );
+ wid->setChangeMode( Opie::Ui::OKeyConfigWidget::Queue );
+ wid->insert( tr("MainWindow Options" ), m_manager );
+ wid->load();
+
+ lay->addWidget( wid );
+
+ if ( QPEApplication::execDialog( &diag ) == QDialog::Accepted ) {
+ wid->save();
+ }
+}
+
+TestMainWindow::TestMainWindow( QWidget* parent, const char* slot, WFlags fl )
+ : Opie::Ui::OListView( parent, slot, fl)
+{
+ addColumn( tr( "A Doo" ) );
+ addColumn( tr( "B Doo" ) );
+
+ m_config = new Opie::Core::OConfig( "test_config_foo" );
+
+ /* generate the black list */
+ Opie::Core::OKeyPair::List blackList;
+ blackList.append( Opie::Core::OKeyPair::leftArrowKey() );
+ blackList.append( Opie::Core::OKeyPair::rightArrowKey() );
+ blackList.append( Opie::Core::OKeyPair::downArrowKey() );
+ blackList.append( Opie::Core::OKeyPair::upArrowKey() );
+
+ m_manager = new Opie::Core::OKeyConfigManager( m_config, "Key Group",
+ blackList, false, this, "Key Manager" );
+
+ m_manager->addKeyConfig( Opie::Core::OKeyConfigItem( tr( "Delete Action" ), "delete_key", QPixmap(),
+ 10, Opie::Core::OKeyPair( Qt::Key_D, Qt::ShiftButton ), this,
+ SLOT(slotDelete(QWidget*,QKeyEvent*)) ) );
+ m_manager->addKeyConfig( Opie::Core::OKeyConfigItem( tr( "Show Action" ), "show_key", QPixmap(),
+ 11, Opie::Core::OKeyPair( Qt::Key_S, Qt::AltButton ) ) );
+
+ connect(m_manager, SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Core::OKeyConfigItem&)),
+ this, SLOT(slotAction(QWidget*, QKeyEvent*, const Opie::Core::OKeyConfigItem&)) );
+// when commenting the line below out the keyPressEvent will work
+ m_manager->handleWidget( this );
+ m_manager->load();
+}
+
+TestMainWindow::~TestMainWindow() {
+ m_manager->save();
+ delete m_config;
+}
+
+Opie::Core::OKeyConfigManager* TestMainWindow::manager() {
+ return m_manager;
+}
+
+/*
+ * This only works if we do not handle the even with m_manager->handleWidget( this )
+ * So this is only for demo purposes
+ */
+void TestMainWindow::keyPressEvent( QKeyEvent* ev ) {
+ owarn << "String is "+ m_manager->handleKeyEvent( ev ).text() << oendl;
+ owarn << "Id was " << m_manager->handleKeyEventId( ev ) << " " << ev->key() << " " << ev->state() << " " << ev->ascii() << "" << oendl;
+ ev->ignore();
+}
+
+void TestMainWindow::slotDelete( QWidget* wid, QKeyEvent* ev ) {
+ owarn << "Slot Delete " << wid << " " << ev->key() << " " << ev->state() << "" << oendl;
+}
+
+void TestMainWindow::slotAction( QWidget* wid, QKeyEvent* ev, const Opie::Core::OKeyConfigItem& item) {
+ owarn << "Slot Action " << wid << " " << ev->key() << " " << ev->state() << " " << item.text() << " " << item.id() << "" << oendl;
+}
+
+#include "testwidget.moc"