author | zecke <zecke> | 2004-04-13 14:53:58 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-04-13 14:53:58 (UTC) |
commit | b51d88d7b0b517b71ae3b59d8228335f38ca9fc7 (patch) (unidiff) | |
tree | 302377973a897934c944c7a126e5e0a510694979 | |
parent | c4c842558e1457f64d43b237f24f6ea1a4f9d76b (diff) | |
download | opie-b51d88d7b0b517b71ae3b59d8228335f38ca9fc7.zip opie-b51d88d7b0b517b71ae3b59d8228335f38ca9fc7.tar.gz opie-b51d88d7b0b517b71ae3b59d8228335f38ca9fc7.tar.bz2 |
Split the KeyConfig Manager and Widget into Ui and Core parts
Adjust the only user...
Don't add a 2nd example to core but mention the one for the classes
in opieui/okeyconfigwidget
-rw-r--r-- | libopie2/examples/opiecore/okeyconfigmanager/README | 1 | ||||
-rw-r--r-- | libopie2/examples/opieui/okeyconfigwidget/testwidget.cpp | 30 | ||||
-rw-r--r-- | libopie2/examples/opieui/okeyconfigwidget/testwidget.h | 10 | ||||
-rw-r--r-- | libopie2/opiecore/okeyconfigmanager.cpp | 733 | ||||
-rw-r--r-- | libopie2/opiecore/okeyconfigmanager.h | 205 | ||||
-rw-r--r-- | libopie2/opiecore/okeyconfigmanager_p.h | 9 | ||||
-rw-r--r-- | libopie2/opiecore/opiecore.pro | 2 | ||||
-rw-r--r-- | libopie2/opieui/okeyconfigwidget.cpp | 742 | ||||
-rw-r--r-- | libopie2/opieui/okeyconfigwidget.h | 199 | ||||
-rw-r--r-- | libopie2/opieui/okeyconfigwidget_p.h | 22 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/iconview.cpp | 28 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/iconview.h | 6 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/imageinfoui.cpp | 26 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/imageinfoui.h | 6 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/imageview.cpp | 22 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/imageview.h | 6 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/mainwindow.h | 4 |
17 files changed, 1046 insertions, 1005 deletions
diff --git a/libopie2/examples/opiecore/okeyconfigmanager/README b/libopie2/examples/opiecore/okeyconfigmanager/README new file mode 100644 index 0000000..327b7c2 --- a/dev/null +++ b/libopie2/examples/opiecore/okeyconfigmanager/README | |||
@@ -0,0 +1 @@ | |||
See opieui/okeyconfigwidget for an example of possible usage \ No newline at end of file | |||
diff --git a/libopie2/examples/opieui/okeyconfigwidget/testwidget.cpp b/libopie2/examples/opieui/okeyconfigwidget/testwidget.cpp index 10b52f9..5c7bac2 100644 --- a/libopie2/examples/opieui/okeyconfigwidget/testwidget.cpp +++ b/libopie2/examples/opieui/okeyconfigwidget/testwidget.cpp | |||
@@ -1,128 +1,128 @@ | |||
1 | #include "testwidget.h" | 1 | #include "testwidget.h" |
2 | 2 | ||
3 | #include <opie2/okeyconfigwidget.h> | 3 | #include <opie2/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 | */ |
21 | class MainWindow : public QMainWindow { | 21 | class MainWindow : public QMainWindow { |
22 | Q_OBJECT | 22 | Q_OBJECT |
23 | public: | 23 | public: |
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() {} |
29 | private slots: | 29 | private slots: |
30 | void slotClicked(); | 30 | void slotClicked(); |
31 | private: | 31 | private: |
32 | Opie::Ui::OKeyConfigManager *m_manager; | 32 | Opie::Core::OKeyConfigManager *m_manager; |
33 | }; | 33 | }; |
34 | 34 | ||
35 | 35 | ||
36 | OPIE_EXPORT_APP( Opie::Core::OApplicationFactory<MainWindow> ) | 36 | OPIE_EXPORT_APP( Opie::Core::OApplicationFactory<MainWindow> ) |
37 | 37 | ||
38 | 38 | ||
39 | MainWindow::MainWindow( QWidget* parent, const char* name, WFlags fl ) | 39 | MainWindow::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 | ||
53 | void MainWindow::slotClicked() { | 53 | void MainWindow::slotClicked() { |
54 | QDialog diag( this, "name", true ); | 54 | QDialog diag( this, "name", true ); |
55 | diag.setCaption( tr( "Manage Keys" ) ); | 55 | diag.setCaption( tr( "Manage Keys" ) ); |
56 | 56 | ||
57 | QHBoxLayout *lay = new QHBoxLayout( &diag ); | 57 | QHBoxLayout *lay = new QHBoxLayout( &diag ); |
58 | Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget( &diag, "key config" ); | 58 | Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget( &diag, "key config" ); |
59 | wid->setChangeMode( Opie::Ui::OKeyConfigWidget::Queue ); | 59 | wid->setChangeMode( Opie::Ui::OKeyConfigWidget::Queue ); |
60 | wid->insert( tr("MainWindow Options" ), m_manager ); | 60 | wid->insert( tr("MainWindow Options" ), m_manager ); |
61 | wid->load(); | 61 | wid->load(); |
62 | 62 | ||
63 | lay->addWidget( wid ); | 63 | lay->addWidget( wid ); |
64 | 64 | ||
65 | if ( QPEApplication::execDialog( &diag ) == QDialog::Accepted ) { | 65 | if ( QPEApplication::execDialog( &diag ) == QDialog::Accepted ) { |
66 | wid->save(); | 66 | wid->save(); |
67 | } | 67 | } |
68 | } | 68 | } |
69 | 69 | ||
70 | TestMainWindow::TestMainWindow( QWidget* parent, const char* slot, WFlags fl ) | 70 | TestMainWindow::TestMainWindow( QWidget* parent, const char* slot, WFlags fl ) |
71 | : Opie::Ui::OListView( parent, slot, fl) | 71 | : Opie::Ui::OListView( parent, slot, fl) |
72 | { | 72 | { |
73 | addColumn( tr( "A Doo" ) ); | 73 | addColumn( tr( "A Doo" ) ); |
74 | addColumn( tr( "B Doo" ) ); | 74 | addColumn( tr( "B Doo" ) ); |
75 | 75 | ||
76 | m_config = new Opie::Core::OConfig( "test_config_foo" ); | 76 | m_config = new Opie::Core::OConfig( "test_config_foo" ); |
77 | 77 | ||
78 | /* generate the black list */ | 78 | /* generate the black list */ |
79 | Opie::Ui::OKeyPair::List blackList; | 79 | Opie::Core::OKeyPair::List blackList; |
80 | blackList.append( Opie::Ui::OKeyPair::leftArrowKey() ); | 80 | blackList.append( Opie::Core::OKeyPair::leftArrowKey() ); |
81 | blackList.append( Opie::Ui::OKeyPair::rightArrowKey() ); | 81 | blackList.append( Opie::Core::OKeyPair::rightArrowKey() ); |
82 | blackList.append( Opie::Ui::OKeyPair::downArrowKey() ); | 82 | blackList.append( Opie::Core::OKeyPair::downArrowKey() ); |
83 | blackList.append( Opie::Ui::OKeyPair::upArrowKey() ); | 83 | blackList.append( Opie::Core::OKeyPair::upArrowKey() ); |
84 | 84 | ||
85 | m_manager = new Opie::Ui::OKeyConfigManager( m_config, "Key Group", | 85 | m_manager = new Opie::Core::OKeyConfigManager( m_config, "Key Group", |
86 | blackList, false, this, "Key Manager" ); | 86 | blackList, false, this, "Key Manager" ); |
87 | 87 | ||
88 | m_manager->addKeyConfig( Opie::Ui::OKeyConfigItem( tr( "Delete Action" ), "delete_key", QPixmap(), | 88 | m_manager->addKeyConfig( Opie::Core::OKeyConfigItem( tr( "Delete Action" ), "delete_key", QPixmap(), |
89 | 10, Opie::Ui::OKeyPair( Qt::Key_D, Qt::ShiftButton ), this, | 89 | 10, Opie::Core::OKeyPair( Qt::Key_D, Qt::ShiftButton ), this, |
90 | SLOT(slotDelete(QWidget*,QKeyEvent*)) ) ); | 90 | SLOT(slotDelete(QWidget*,QKeyEvent*)) ) ); |
91 | m_manager->addKeyConfig( Opie::Ui::OKeyConfigItem( tr( "Show Action" ), "show_key", QPixmap(), | 91 | m_manager->addKeyConfig( Opie::Core::OKeyConfigItem( tr( "Show Action" ), "show_key", QPixmap(), |
92 | 11, Opie::Ui::OKeyPair( Qt::Key_S, Qt::AltButton ) ) ); | 92 | 11, Opie::Core::OKeyPair( Qt::Key_S, Qt::AltButton ) ) ); |
93 | 93 | ||
94 | connect(m_manager, SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&)), | 94 | connect(m_manager, SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Core::OKeyConfigItem&)), |
95 | this, SLOT(slotAction(QWidget*, QKeyEvent*, const Opie::Ui::OKeyConfigItem&)) ); | 95 | this, SLOT(slotAction(QWidget*, QKeyEvent*, const Opie::Core::OKeyConfigItem&)) ); |
96 | // when commenting the line below out the keyPressEvent will work | 96 | // when commenting the line below out the keyPressEvent will work |
97 | m_manager->handleWidget( this ); | 97 | m_manager->handleWidget( this ); |
98 | m_manager->load(); | 98 | m_manager->load(); |
99 | } | 99 | } |
100 | 100 | ||
101 | TestMainWindow::~TestMainWindow() { | 101 | TestMainWindow::~TestMainWindow() { |
102 | m_manager->save(); | 102 | m_manager->save(); |
103 | delete m_config; | 103 | delete m_config; |
104 | } | 104 | } |
105 | 105 | ||
106 | Opie::Ui::OKeyConfigManager* TestMainWindow::manager() { | 106 | Opie::Core::OKeyConfigManager* TestMainWindow::manager() { |
107 | return m_manager; | 107 | return m_manager; |
108 | } | 108 | } |
109 | 109 | ||
110 | /* | 110 | /* |
111 | * This only works if we do not handle the even with m_manager->handleWidget( this ) | 111 | * This only works if we do not handle the even with m_manager->handleWidget( this ) |
112 | * So this is only for demo purposes | 112 | * So this is only for demo purposes |
113 | */ | 113 | */ |
114 | void TestMainWindow::keyPressEvent( QKeyEvent* ev ) { | 114 | void TestMainWindow::keyPressEvent( QKeyEvent* ev ) { |
115 | qWarning( "String is "+ m_manager->handleKeyEvent( ev ).text() ); | 115 | qWarning( "String is "+ m_manager->handleKeyEvent( ev ).text() ); |
116 | qWarning( "Id was %d %d %d %d", m_manager->handleKeyEventId( ev ),ev->key(),ev->state(), ev->ascii() ); | 116 | qWarning( "Id was %d %d %d %d", m_manager->handleKeyEventId( ev ),ev->key(),ev->state(), ev->ascii() ); |
117 | ev->ignore(); | 117 | ev->ignore(); |
118 | } | 118 | } |
119 | 119 | ||
120 | void TestMainWindow::slotDelete( QWidget* wid, QKeyEvent* ev ) { | 120 | void TestMainWindow::slotDelete( QWidget* wid, QKeyEvent* ev ) { |
121 | qWarning( "Slot Delete %d %d %d", wid, ev->key(), ev->state() ); | 121 | qWarning( "Slot Delete %d %d %d", wid, ev->key(), ev->state() ); |
122 | } | 122 | } |
123 | 123 | ||
124 | void TestMainWindow::slotAction( QWidget* wid, QKeyEvent* ev, const Opie::Ui::OKeyConfigItem& item) { | 124 | void TestMainWindow::slotAction( QWidget* wid, QKeyEvent* ev, const Opie::Core::OKeyConfigItem& item) { |
125 | qWarning( "Slot Action %d %d %d %s %d", wid, ev->key(), ev->state(), item.text().latin1(), item.id() ); | 125 | qWarning( "Slot Action %d %d %d %s %d", wid, ev->key(), ev->state(), item.text().latin1(), item.id() ); |
126 | } | 126 | } |
127 | 127 | ||
128 | #include "testwidget.moc" | 128 | #include "testwidget.moc" |
diff --git a/libopie2/examples/opieui/okeyconfigwidget/testwidget.h b/libopie2/examples/opieui/okeyconfigwidget/testwidget.h index b95c225..6ecb346 100644 --- a/libopie2/examples/opieui/okeyconfigwidget/testwidget.h +++ b/libopie2/examples/opieui/okeyconfigwidget/testwidget.h | |||
@@ -1,40 +1,40 @@ | |||
1 | #ifndef TEST_WIDGET_H | 1 | #ifndef TEST_WIDGET_H |
2 | #define TEST_WIDGET_H | 2 | #define TEST_WIDGET_H |
3 | 3 | ||
4 | #include <qmainwindow.h> | 4 | #include <qmainwindow.h> |
5 | 5 | ||
6 | #include <opie2/olistview.h> | 6 | #include <opie2/olistview.h> |
7 | 7 | ||
8 | namespace Opie{ | 8 | namespace Opie{ |
9 | namespace Ui{ | 9 | namespace Ui{ |
10 | class OTabWidget; | 10 | class OTabWidget; |
11 | class OKeyConfigManager; | ||
12 | class OListView; | 11 | class OListView; |
13 | class OKeyConfigItem; | ||
14 | } | 12 | } |
15 | namespace Core { | 13 | namespace Core { |
16 | class OConfig; | 14 | class OConfig; |
15 | class OKeyConfigManager; | ||
16 | class OKeyConfigItem; | ||
17 | } | 17 | } |
18 | } | 18 | } |
19 | class QKeyEvent; | 19 | class QKeyEvent; |
20 | 20 | ||
21 | 21 | ||
22 | class TestMainWindow : public Opie::Ui::OListView { | 22 | class TestMainWindow : public Opie::Ui::OListView { |
23 | Q_OBJECT | 23 | Q_OBJECT |
24 | public: | 24 | public: |
25 | 25 | ||
26 | TestMainWindow(QWidget* parent, const char*, WFlags fl ); | 26 | TestMainWindow(QWidget* parent, const char*, WFlags fl ); |
27 | ~TestMainWindow(); | 27 | ~TestMainWindow(); |
28 | 28 | ||
29 | Opie::Ui::OKeyConfigManager *manager(); | 29 | Opie::Core::OKeyConfigManager *manager(); |
30 | protected: | 30 | protected: |
31 | void keyPressEvent( QKeyEvent* ); | 31 | void keyPressEvent( QKeyEvent* ); |
32 | private slots: | 32 | private slots: |
33 | void slotDelete( QWidget*, QKeyEvent* ); | 33 | void slotDelete( QWidget*, QKeyEvent* ); |
34 | void slotAction( QWidget*, QKeyEvent*, const Opie::Ui::OKeyConfigItem& ); | 34 | void slotAction( QWidget*, QKeyEvent*, const Opie::Core::OKeyConfigItem& ); |
35 | private: | 35 | private: |
36 | Opie::Core::OConfig *m_config; | 36 | Opie::Core::OConfig *m_config; |
37 | Opie::Ui::OKeyConfigManager *m_manager; | 37 | Opie::Core::OKeyConfigManager *m_manager; |
38 | }; | 38 | }; |
39 | 39 | ||
40 | #endif | 40 | #endif |
diff --git a/libopie2/opiecore/okeyconfigmanager.cpp b/libopie2/opiecore/okeyconfigmanager.cpp new file mode 100644 index 0000000..e6055e0 --- a/dev/null +++ b/libopie2/opiecore/okeyconfigmanager.cpp | |||
@@ -0,0 +1,733 @@ | |||
1 | #include "okeyconfigmanager.h" | ||
2 | |||
3 | #include "okeyconfigmanager_p.h" | ||
4 | |||
5 | namespace Opie { | ||
6 | namespace Core { | ||
7 | namespace Internal { | ||
8 | /* | ||
9 | * the virtual and hardware key events have both issues... | ||
10 | */ | ||
11 | void fixupKeys( int& key, int &mod, QKeyEvent* e ) { | ||
12 | key = e->key(); | ||
13 | mod = e->state(); | ||
14 | /* | ||
15 | * virtual keyboard | ||
16 | * else change the button mod only | ||
17 | */ | ||
18 | if ( key == 0 ) { | ||
19 | key = e->ascii(); | ||
20 | if ( key > 96 && key < 123) | ||
21 | key -= 32; | ||
22 | }else{ | ||
23 | int new_mod = 0; | ||
24 | if ( mod & 256 ) | ||
25 | new_mod |= Qt::ShiftButton; | ||
26 | else if ( mod & 512 ) | ||
27 | new_mod |= Qt::ControlButton; | ||
28 | else if ( mod & 1024 ) | ||
29 | new_mod |= Qt::AltButton; | ||
30 | |||
31 | mod = new_mod == 0? mod : new_mod; | ||
32 | } | ||
33 | } | ||
34 | } | ||
35 | |||
36 | /** | ||
37 | * The default Constructor of a OKeyPair. | ||
38 | * A Key and a Modifier ( Alt/Shift/Ctrl ) | ||
39 | * needs to be supplied. | ||
40 | * Use Qt::Key for the information. | ||
41 | * The default arguments create an Empty OKeyPair. If you | ||
42 | * want to get an empty OKeyPair use the static method for getting | ||
43 | * the emptyKey() | ||
44 | * | ||
45 | * @see OKeyPair OKeyPair::emptyKey() | ||
46 | */ | ||
47 | OKeyPair::OKeyPair( int key, int mod ) | ||
48 | : m_key( key ), m_mod( mod ) | ||
49 | {} | ||
50 | |||
51 | /** | ||
52 | * The destructor | ||
53 | */ | ||
54 | OKeyPair::~OKeyPair() {} | ||
55 | |||
56 | |||
57 | /** | ||
58 | * Is this OKeyPair empty/valid? | ||
59 | */ | ||
60 | bool OKeyPair::isEmpty()const { | ||
61 | return ( ( m_key == -1 )&& ( m_mod == -1 ) ); | ||
62 | } | ||
63 | |||
64 | /** | ||
65 | * get the keycode for this OKeyPair. The Key relates to Qt::Key. | ||
66 | * | ||
67 | * @see Qt::Key | ||
68 | * @see setKey | ||
69 | */ | ||
70 | int OKeyPair::keycode()const { | ||
71 | return m_key; | ||
72 | } | ||
73 | |||
74 | /** | ||
75 | * get the modifier key for this OKeyPair. The Modifier State relates | ||
76 | * to the Qt::ButtonState | ||
77 | * | ||
78 | * @see Qt::ButtonState | ||
79 | * @see setModifier | ||
80 | */ | ||
81 | int OKeyPair::modifier()const { | ||
82 | return m_mod; | ||
83 | } | ||
84 | |||
85 | |||
86 | /** | ||
87 | * Set the keycode | ||
88 | * @param key The Keycode to set | ||
89 | * | ||
90 | * @see keycode() | ||
91 | * @see Qt::Key | ||
92 | */ | ||
93 | void OKeyPair::setKeycode( int key ) { | ||
94 | m_key = key; | ||
95 | } | ||
96 | |||
97 | /** | ||
98 | * Set the modifier key | ||
99 | * | ||
100 | * @param the Modifier key | ||
101 | * @see Qt::ButtonState | ||
102 | * @see modifier() | ||
103 | */ | ||
104 | void OKeyPair::setModifier( int mod ) { | ||
105 | m_mod = mod; | ||
106 | } | ||
107 | |||
108 | /** | ||
109 | * Return an OKeyPair for the Return Key without any modifier. | ||
110 | */ | ||
111 | OKeyPair OKeyPair::returnKey() { | ||
112 | return OKeyPair( Qt::Key_Return, 0 ); | ||
113 | } | ||
114 | |||
115 | /** | ||
116 | * Return an OKeyPair for the Left Arrow Key | ||
117 | * without any modifier Key | ||
118 | */ | ||
119 | OKeyPair OKeyPair::leftArrowKey() { | ||
120 | return OKeyPair( Qt::Key_Left, 0 ); | ||
121 | } | ||
122 | |||
123 | /** | ||
124 | * Return an OKeyPair for the Right Arrow Key | ||
125 | * without any modifier Key | ||
126 | */ | ||
127 | OKeyPair OKeyPair::rightArrowKey() { | ||
128 | return OKeyPair( Qt::Key_Right, 0 ); | ||
129 | } | ||
130 | |||
131 | /** | ||
132 | * Return an OKeyPair for the Up Arrow Key | ||
133 | * without any modifier Key | ||
134 | */ | ||
135 | OKeyPair OKeyPair::upArrowKey() { | ||
136 | return OKeyPair( Qt::Key_Up, 0 ); | ||
137 | } | ||
138 | |||
139 | /** | ||
140 | * Return an OKeyPair for the Down Arrow Key | ||
141 | * without any modifier Key | ||
142 | */ | ||
143 | OKeyPair OKeyPair::downArrowKey() { | ||
144 | return OKeyPair( Qt::Key_Down, 0 ); | ||
145 | } | ||
146 | |||
147 | /** | ||
148 | * Return an Empty OKeyPair | ||
149 | */ | ||
150 | OKeyPair OKeyPair::emptyKey() { | ||
151 | return OKeyPair(); | ||
152 | } | ||
153 | |||
154 | /** | ||
155 | * This functions uses the Opie::Core::ODevice::buttons | ||
156 | * for OKeyPairList | ||
157 | * | ||
158 | * @see Opie::Core::ODevice | ||
159 | * @see Opie::Core::ODeviceButton | ||
160 | * @see Opie::Core::ODevice::button | ||
161 | */ | ||
162 | OKeyPair::List OKeyPair::hardwareKeys() { | ||
163 | const QValueList<Opie::Core::ODeviceButton> but = Opie::Core::ODevice::inst()->buttons(); | ||
164 | OKeyPair::List lst; | ||
165 | |||
166 | for ( QValueList<Opie::Core::ODeviceButton>::ConstIterator it = but.begin(); | ||
167 | it != but.end(); ++it ) | ||
168 | lst.append( OKeyPair( (*it).keycode(), 0 ) ); | ||
169 | |||
170 | |||
171 | return lst; | ||
172 | } | ||
173 | |||
174 | /** | ||
175 | * Equals operator. Check if two OKeyPairs have the same key and modifier | ||
176 | * @see operator!= | ||
177 | */ | ||
178 | bool OKeyPair::operator==( const OKeyPair& pair)const { | ||
179 | if ( m_key != pair.m_key ) return false; | ||
180 | if ( m_mod != pair.m_mod ) return false; | ||
181 | |||
182 | return true; | ||
183 | } | ||
184 | |||
185 | /** | ||
186 | * Not equal operator. calls the equal operator internally | ||
187 | */ | ||
188 | bool OKeyPair::operator!=( const OKeyPair& pair)const { | ||
189 | return !(*this == pair); | ||
190 | } | ||
191 | |||
192 | |||
193 | /** | ||
194 | * The normal Constructor to create a OKeyConfigItem | ||
195 | * | ||
196 | * You can set the the key paramater of this item but if | ||
197 | * you use this item with the OKeyConfigManager your setting | ||
198 | * will be overwritten. | ||
199 | * You can also specify a QObject and slot which sould get called | ||
200 | * once this item is activated. This slot only works if you | ||
201 | * use the OKeyConfigManager. | ||
202 | * The actual Key is read by load() | ||
203 | * | ||
204 | * \code | ||
205 | * void MySlot::create(){ | ||
206 | * OKeyConfigItem item(tr("Delete"),"delete",Resource::loadPixmap("trash"), | ||
207 | * 123, OKeyPair(Qt::Key_D,Qt::ControlButton), | ||
208 | * this,SLOT(slotDelete(QWidget*,QKeyEvent*))); | ||
209 | * } | ||
210 | * \endcode | ||
211 | * | ||
212 | * @param text The text exposed to the user | ||
213 | * @param config_key The key used in the config | ||
214 | * @param pix A Pixmap associated with this Item | ||
215 | * @param def The OKeyPair used as default | ||
216 | * @param caller The object where the slot exists | ||
217 | * @param slot The slot which should get called | ||
218 | * | ||
219 | */ | ||
220 | OKeyConfigItem::OKeyConfigItem( const QString& text, const QCString& config_key, | ||
221 | const QPixmap& pix, int id, const OKeyPair& def, | ||
222 | QObject *caller, | ||
223 | const char* slot ) | ||
224 | : m_text( text ), m_config( config_key ), m_pix( pix ), | ||
225 | m_id( id ), m_def( def ), | ||
226 | m_obj( caller ), m_str( slot ) {} | ||
227 | |||
228 | /** | ||
229 | * A special Constructor for converting from an Opie::Core::ODeviceButton | ||
230 | * delivered by Opie::Core::ODevice::buttons() | ||
231 | * There is no Config Key set and both default key and key are set | ||
232 | * to Opie::Core::ODeviceButton::keycode() and 0 to modifier | ||
233 | * | ||
234 | * @see Opie::Core::ODevice | ||
235 | * @see Opie::Core::ODeviceButton | ||
236 | * @see Opie::Core::ODevice::buttons() | ||
237 | */ | ||
238 | OKeyConfigItem::OKeyConfigItem( const Opie::Core::ODeviceButton& b ) | ||
239 | : m_text( b.userText() ), m_pix( b.pixmap() ), m_id( -1 ), | ||
240 | m_key( OKeyPair( b.keycode(), 0 ) ), m_def( OKeyPair( b.keycode(), 0 ) ) | ||
241 | {} | ||
242 | |||
243 | |||
244 | /** | ||
245 | * Destructor | ||
246 | */ | ||
247 | OKeyConfigItem::~OKeyConfigItem() {} | ||
248 | |||
249 | |||
250 | /** | ||
251 | * The text exposed to the user | ||
252 | * | ||
253 | * @see setText | ||
254 | */ | ||
255 | QString OKeyConfigItem::text()const { | ||
256 | return m_text; | ||
257 | } | ||
258 | |||
259 | /** | ||
260 | * The pixmap shown to the user for your action/key | ||
261 | * | ||
262 | * @see setPixmap | ||
263 | */ | ||
264 | QPixmap OKeyConfigItem::pixmap()const { | ||
265 | return m_pix; | ||
266 | } | ||
267 | |||
268 | /** | ||
269 | * Return the OKeyPair this OKeyConfigItem is configured for. | ||
270 | * | ||
271 | * @see setKeyPair | ||
272 | */ | ||
273 | OKeyPair OKeyConfigItem::keyPair()const { | ||
274 | return m_key; | ||
275 | } | ||
276 | |||
277 | /** | ||
278 | * Return the default OKeyPair | ||
279 | * @see setDefaultKeyPair | ||
280 | */ | ||
281 | OKeyPair OKeyConfigItem::defaultKeyPair()const { | ||
282 | return m_def; | ||
283 | } | ||
284 | |||
285 | |||
286 | /** | ||
287 | * Return the Id you assigned to this item. | ||
288 | * setting is only possible by the constructor | ||
289 | */ | ||
290 | int OKeyConfigItem::id()const{ | ||
291 | return m_id; | ||
292 | } | ||
293 | |||
294 | /** | ||
295 | * reutrn the Config Key. Setting it is only possible | ||
296 | * by the constructor | ||
297 | */ | ||
298 | QCString OKeyConfigItem::configKey()const { | ||
299 | return m_config; | ||
300 | } | ||
301 | |||
302 | /** | ||
303 | * @internal | ||
304 | */ | ||
305 | QObject* OKeyConfigItem::object()const{ | ||
306 | return m_obj; | ||
307 | } | ||
308 | |||
309 | /** | ||
310 | * @internal | ||
311 | */ | ||
312 | QCString OKeyConfigItem::slot()const { | ||
313 | return m_str; | ||
314 | } | ||
315 | |||
316 | /** | ||
317 | * Set the text | ||
318 | * | ||
319 | * @param text Set the Text of this Action to text | ||
320 | * @see text() | ||
321 | */ | ||
322 | void OKeyConfigItem::setText( const QString& text ) { | ||
323 | m_text = text; | ||
324 | } | ||
325 | |||
326 | /** | ||
327 | * Set the pixmap of this action | ||
328 | * | ||
329 | * @param pix The Pixmap to set | ||
330 | * @see pixmap() | ||
331 | */ | ||
332 | void OKeyConfigItem::setPixmap( const QPixmap& pix ) { | ||
333 | m_pix = pix; | ||
334 | } | ||
335 | |||
336 | /** | ||
337 | * Set the KeyPair the OKeyConfigItem uses. | ||
338 | * Your set Key could get overwritten if you use | ||
339 | * the manager or GUI to configure the key | ||
340 | * | ||
341 | * @param key Set the OKeyPair used | ||
342 | * @see keyPair() | ||
343 | */ | ||
344 | void OKeyConfigItem::setKeyPair( const OKeyPair& key) { | ||
345 | m_key = key; | ||
346 | } | ||
347 | |||
348 | /** | ||
349 | * Set the default KeyPair. | ||
350 | * | ||
351 | * @param key The default keypair | ||
352 | * @see defaultKeyPair() | ||
353 | */ | ||
354 | void OKeyConfigItem::setDefaultKeyPair( const OKeyPair& key ) { | ||
355 | m_def = key; | ||
356 | } | ||
357 | |||
358 | /** | ||
359 | * @internal | ||
360 | */ | ||
361 | void OKeyConfigItem::setConfigKey( const QCString& str) { | ||
362 | m_config = str; | ||
363 | m_config.detach(); | ||
364 | } | ||
365 | |||
366 | /** | ||
367 | * @internal | ||
368 | */ | ||
369 | void OKeyConfigItem::setId( int id ) { | ||
370 | m_id = id; | ||
371 | } | ||
372 | |||
373 | /** | ||
374 | * If the item is not configured isEmpty() will return true | ||
375 | * It is empty if no text is present and no default | ||
376 | * and no configured key | ||
377 | */ | ||
378 | bool OKeyConfigItem::isEmpty()const { | ||
379 | if ( !m_def.isEmpty() ) return false; | ||
380 | if ( !m_key.isEmpty() ) return false; | ||
381 | if ( !m_text.isEmpty() ) return false; | ||
382 | if ( m_id != -1 ) return false; | ||
383 | |||
384 | return true; | ||
385 | } | ||
386 | |||
387 | /** | ||
388 | * Check if the KeyPairs are the same | ||
389 | */ | ||
390 | bool OKeyConfigItem::operator==( const OKeyConfigItem& conf )const { | ||
391 | /* if ( isEmpty() == conf.isEmpty() ) return true; | ||
392 | else if ( isEmpty() != conf.isEmpty() ) return false; | ||
393 | else if ( !isEmpty()!= conf.isEmpty() ) return false; | ||
394 | */ | ||
395 | |||
396 | if ( m_id != conf.m_id ) return false; | ||
397 | if ( m_obj != conf.m_obj ) return false; | ||
398 | if ( m_text != conf.m_text ) return false; | ||
399 | if ( m_key != conf.m_key ) return false; | ||
400 | if ( m_def != conf.m_def ) return false; | ||
401 | |||
402 | |||
403 | |||
404 | return true; | ||
405 | |||
406 | } | ||
407 | |||
408 | bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf )const { | ||
409 | return !( *this == conf ); | ||
410 | } | ||
411 | |||
412 | /** | ||
413 | * \brief c'tor | ||
414 | * The Constructor for a OKeyConfigManager | ||
415 | * | ||
416 | * You can use this manager in multiple ways. Either make it handle | ||
417 | * QKeyEvents | ||
418 | * | ||
419 | * \code | ||
420 | * Opie::Core::Config conf = oApp->config(); | ||
421 | * Opie::Core::OKeyPairList blackList; | ||
422 | * blackList.append(Opie::Core::OKeyPair::leftArrowKey()); | ||
423 | * blackList.append(Opie::Core::OKeyPair::rightArrowKey()); | ||
424 | * Opie::Core::OKeyConfigManager *manager = new Opie::Core::OKeyConfigManager(conf,"key_actions",blackList, | ||
425 | * false); | ||
426 | * QListView *view = new QListView(); | ||
427 | * manager->handleWidget(view); | ||
428 | * manager->addKeyConfig( Opie::Core::OKeyPair::returnKey()); | ||
429 | * manager->load(); | ||
430 | * | ||
431 | * connect(manager,SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Core::OKeyConfigItem&)), | ||
432 | * this,SLOT(slotHandleKey(QWidget*,QKeyEvent*,const Opie::Core::OKeyConfigItem&))); | ||
433 | * | ||
434 | * .... | ||
435 | * | ||
436 | * void update(){ | ||
437 | * QDialog diag(true); | ||
438 | * QHBoxLayout *lay = new QHBoxLayout(&diag); | ||
439 | * Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget(manager,&diag); | ||
440 | * wid->setChangeMode(Opie::Ui::OKeyConfigWidget::Queu); | ||
441 | * lay->addWidget(wid); | ||
442 | * if(QPEApplication::execDialog( &diag)== QDialog::Accepted){ | ||
443 | * wid->save(); | ||
444 | * } | ||
445 | * } | ||
446 | * | ||
447 | * .... | ||
448 | * MyListView::keyPressEvent( QKeyEvent* e ){ | ||
449 | * Opie::Ui::OKeyConfigItem item = manager->handleKeyEvent(e); | ||
450 | * if(!item.isEmpty() ){ | ||
451 | * switch(item.id()){ | ||
452 | * case My_Delete_Key: | ||
453 | * break; | ||
454 | * } | ||
455 | * } | ||
456 | * } | ||
457 | * | ||
458 | * \endcode | ||
459 | * | ||
460 | * @param conf The Config where the KeySetting should be stored | ||
461 | * @param group The group where the KeySetting will be stored | ||
462 | * @param black Which keys shouldn't be allowed to handle | ||
463 | * @param grabkeyboard Calls QPEApplication::grabKeyboard to allow handling of DeviceButtons | ||
464 | * @param par The parent/owner of this manager | ||
465 | * @param name The name of this object | ||
466 | */ | ||
467 | OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf, | ||
468 | const QString& group, | ||
469 | const OKeyPair::List& black, | ||
470 | bool grabkeyboard, QObject* par, | ||
471 | const char* name) | ||
472 | : QObject( par, name ), m_conf( conf ), m_group( group ), | ||
473 | m_blackKeys( black ), m_grab( grabkeyboard ), m_map( 0 ){ | ||
474 | if ( m_grab ) | ||
475 | QPEApplication::grabKeyboard(); | ||
476 | } | ||
477 | |||
478 | |||
479 | /** | ||
480 | * Destructor | ||
481 | */ | ||
482 | OKeyConfigManager::~OKeyConfigManager() { | ||
483 | if ( m_grab ) | ||
484 | QPEApplication::ungrabKeyboard(); | ||
485 | } | ||
486 | |||
487 | /** | ||
488 | * Load the Configuration from the OConfig | ||
489 | * If a Key is restricted but was in the config we will | ||
490 | * make it be the empty key paur | ||
491 | * We will change the group but restore to the previous. | ||
492 | * | ||
493 | * @see OKeyPair::emptyKey | ||
494 | */ | ||
495 | void OKeyConfigManager::load() { | ||
496 | Opie::Core::OConfigGroupSaver( m_conf, m_group ); | ||
497 | |||
498 | /* | ||
499 | * Read each item | ||
500 | */ | ||
501 | int key, mod; | ||
502 | for( OKeyConfigItem::List::Iterator it = m_keys.begin(); it != m_keys.end(); ++it ) { | ||
503 | key = m_conf->readNumEntry( (*it).configKey()+"key", (*it).defaultKeyPair().keycode() ); | ||
504 | mod = m_conf->readNumEntry( (*it).configKey()+"mod", (*it).defaultKeyPair().modifier() ); | ||
505 | OKeyPair okey( key, mod ); | ||
506 | |||
507 | if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 ) | ||
508 | (*it).setKeyPair( OKeyPair(key, mod) ); | ||
509 | else | ||
510 | (*it).setKeyPair( OKeyPair::emptyKey() ); | ||
511 | } | ||
512 | delete m_map; m_map = 0; | ||
513 | } | ||
514 | |||
515 | /** | ||
516 | * We will save the current configuration | ||
517 | * to the OConfig. We will change the group but restore | ||
518 | * to the previous | ||
519 | */ | ||
520 | void OKeyConfigManager::save() { | ||
521 | Opie::Core::OConfigGroupSaver( m_conf, m_group ); | ||
522 | |||
523 | /* | ||
524 | * Write each item | ||
525 | */ | ||
526 | for( OKeyConfigItem::List::Iterator it = m_keys.begin();it != m_keys.end(); ++it ) { | ||
527 | /* skip empty items */ | ||
528 | if ( (*it).isEmpty() ) | ||
529 | continue; | ||
530 | OKeyPair pair = (*it).keyPair(); | ||
531 | OKeyPair deft = (*it).defaultKeyPair(); | ||
532 | /* | ||
533 | * don't write if it is the default setting | ||
534 | * FIXME allow to remove Keys from config | ||
535 | if ( (pair.keycode() == deft.keycode()) && | ||
536 | (pair.modifier()== deft.modifier() ) ) | ||
537 | return; | ||
538 | */ | ||
539 | |||
540 | m_conf->writeEntry((*it).configKey()+"key", pair.keycode() ); | ||
541 | m_conf->writeEntry((*it).configKey()+"mod", pair.modifier() ); | ||
542 | } | ||
543 | m_conf->write(); | ||
544 | } | ||
545 | |||
546 | /** | ||
547 | * This is function uses a QMap internally but you can have the same keycode | ||
548 | * with different modifier key. The behaviour is undefined if you add a OKeyConfigItem | ||
549 | * with same keycode and modifier key. The GUI takes care that a user can't | ||
550 | * cofigure two keys. | ||
551 | * | ||
552 | * Make sure you call e->ignore if you don't want to handle this event | ||
553 | */ | ||
554 | OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) { | ||
555 | /* | ||
556 | * Fix Up issues with Qt/E, my keybard, and virtual input | ||
557 | * methods | ||
558 | * First my Keyboard delivers 256,512,1024 for shift/ctrl/alt instead of the button state | ||
559 | * Also key() on virtual inputmethods are zero and only ascii. We need to fix upper and lower | ||
560 | * case ascii | ||
561 | */ | ||
562 | int key, mod; | ||
563 | Opie::Core::Internal::fixupKeys( key, mod, e ); | ||
564 | |||
565 | OKeyConfigItem::List _keyList = keyList( key ); | ||
566 | if ( _keyList.isEmpty() ) | ||
567 | return OKeyConfigItem(); | ||
568 | |||
569 | OKeyConfigItem item; | ||
570 | for ( OKeyConfigItem::List::Iterator it = _keyList.begin(); it != _keyList.end(); | ||
571 | ++it ) { | ||
572 | if ( (*it).keyPair().modifier() == mod ) { | ||
573 | item = *it; | ||
574 | break; | ||
575 | } | ||
576 | |||
577 | } | ||
578 | |||
579 | return item; | ||
580 | } | ||
581 | |||
582 | /** | ||
583 | * Return the associated id of the item or -1 if no item | ||
584 | * matched the key | ||
585 | * | ||
586 | * @see handleKeyEvent | ||
587 | */ | ||
588 | int OKeyConfigManager::handleKeyEventId( QKeyEvent* ev) { | ||
589 | return handleKeyEvent( ev ).id(); | ||
590 | } | ||
591 | |||
592 | /** | ||
593 | * Add Key Config to the List of items | ||
594 | */ | ||
595 | void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) { | ||
596 | m_keys.append( item ); | ||
597 | delete m_map; m_map = 0; | ||
598 | } | ||
599 | |||
600 | /** | ||
601 | * Remove the Key from the Config. Internal lists will be destroyed | ||
602 | * and rebuild on demand later | ||
603 | */ | ||
604 | void OKeyConfigManager::removeKeyConfig( const OKeyConfigItem& item ) { | ||
605 | m_keys.remove( item ); | ||
606 | delete m_map; m_map = 0; | ||
607 | } | ||
608 | |||
609 | /** | ||
610 | * Clears the complete list | ||
611 | */ | ||
612 | void OKeyConfigManager::clearKeyConfig() { | ||
613 | m_keys.clear(); | ||
614 | delete m_map; m_map = 0; | ||
615 | } | ||
616 | |||
617 | /** | ||
618 | * | ||
619 | */ | ||
620 | Opie::Core::OKeyConfigItem::List OKeyConfigManager::keyConfigList()const{ | ||
621 | return m_keys; | ||
622 | } | ||
623 | |||
624 | /** | ||
625 | * Add this OKeyPair to the blackList. | ||
626 | * Internal lists will be destroyed | ||
627 | */ | ||
628 | void OKeyConfigManager::addToBlackList( const OKeyPair& key) { | ||
629 | m_blackKeys.append( key ); | ||
630 | delete m_map; m_map = 0; | ||
631 | } | ||
632 | |||
633 | |||
634 | /** | ||
635 | * Remove this OKeyPair from the black List | ||
636 | * Internal lists will be destroyed | ||
637 | */ | ||
638 | void OKeyConfigManager::removeFromBlackList( const OKeyPair& key ) { | ||
639 | m_blackKeys.remove( key ); | ||
640 | delete m_map; m_map = 0; | ||
641 | } | ||
642 | |||
643 | |||
644 | /** | ||
645 | * Clear the blackList | ||
646 | */ | ||
647 | void OKeyConfigManager::clearBlackList() { | ||
648 | m_blackKeys.clear(); | ||
649 | delete m_map; m_map = 0; | ||
650 | } | ||
651 | |||
652 | |||
653 | /** | ||
654 | * Return a copy of the blackList | ||
655 | */ | ||
656 | OKeyPair::List OKeyConfigManager::blackList()const { | ||
657 | return m_blackKeys; | ||
658 | } | ||
659 | |||
660 | |||
661 | /** | ||
662 | * Ask the Manager to handle KeyEvents for you. | ||
663 | * All handled keys will emit a QSignal and return true | ||
664 | * that it handled the keyevent | ||
665 | */ | ||
666 | void OKeyConfigManager::handleWidget( QWidget* wid ) { | ||
667 | wid->installEventFilter( this ); | ||
668 | } | ||
669 | |||
670 | /** | ||
671 | * @internal | ||
672 | */ | ||
673 | bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) { | ||
674 | if ( !obj->isWidgetType() ) | ||
675 | return false; | ||
676 | |||
677 | if ( ev->type() != QEvent::KeyPress && ev->type() != QEvent::KeyRelease ) | ||
678 | return false; | ||
679 | |||
680 | QKeyEvent *key = static_cast<QKeyEvent*>( ev ); | ||
681 | OKeyConfigItem item = handleKeyEvent( key ); | ||
682 | |||
683 | if ( item.isEmpty() ) | ||
684 | return false; | ||
685 | |||
686 | QWidget *wid = static_cast<QWidget*>( obj ); | ||
687 | |||
688 | if ( item.object() && !item.slot().isEmpty() ) { | ||
689 | connect( this, SIGNAL( actionActivated(QWidget*, QKeyEvent*)), | ||
690 | item.object(), item.slot().data() ); | ||
691 | emit actionActivated(wid, key); | ||
692 | disconnect( this, SIGNAL(actionActivated(QWidget*,QKeyEvent*)), | ||
693 | item.object(), item.slot().data() ); | ||
694 | } | ||
695 | emit actionActivated( wid, key, item ); | ||
696 | |||
697 | return true; | ||
698 | } | ||
699 | |||
700 | /** | ||
701 | * @internal | ||
702 | */ | ||
703 | OKeyConfigItem::List OKeyConfigManager::keyList( int keycode) { | ||
704 | /* | ||
705 | * Create the map if not existing anymore | ||
706 | */ | ||
707 | if ( !m_map ) { | ||
708 | m_map = new OKeyMapConfigPrivate; | ||
709 | /* for every key */ | ||
710 | for ( OKeyConfigItem::List::Iterator it = m_keys.begin(); | ||
711 | it!= m_keys.end(); ++it ) { | ||
712 | |||
713 | bool add = true; | ||
714 | /* see if this key is blocked */ | ||
715 | OKeyPair pair = (*it).keyPair(); | ||
716 | for ( OKeyPair::List::Iterator pairIt = m_blackKeys.begin(); | ||
717 | pairIt != m_blackKeys.end(); ++pairIt ) { | ||
718 | if ( (*pairIt).keycode() == pair.keycode() && | ||
719 | (*pairIt).modifier() == pair.modifier() ) { | ||
720 | add = false; | ||
721 | break; | ||
722 | } | ||
723 | } | ||
724 | /* check if we added it */ | ||
725 | if ( add ) | ||
726 | (*m_map)[pair.keycode()].append( *it ); | ||
727 | } | ||
728 | } | ||
729 | return (*m_map)[keycode]; | ||
730 | } | ||
731 | |||
732 | } | ||
733 | } | ||
diff --git a/libopie2/opiecore/okeyconfigmanager.h b/libopie2/opiecore/okeyconfigmanager.h new file mode 100644 index 0000000..d610375 --- a/dev/null +++ b/libopie2/opiecore/okeyconfigmanager.h | |||
@@ -0,0 +1,205 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2004 | ||
3 | * LGPL v2 zecke@handhelds.org | ||
4 | */ | ||
5 | |||
6 | |||
7 | #ifndef ODP_KEY_MANAGER_WIDGET_H | ||
8 | #define ODP_KEY_MANAGER_WIDGET_H | ||
9 | |||
10 | #include <opie2/oconfig.h> | ||
11 | #include <opie2/odevice.h> | ||
12 | |||
13 | #include <qstring.h> | ||
14 | #include <qpixmap.h> | ||
15 | #include <qcstring.h> | ||
16 | #include <qvaluelist.h> | ||
17 | |||
18 | namespace Opie { | ||
19 | namespace Core { | ||
20 | |||
21 | /** | ||
22 | * \brief small class representing a Key with possible modifiers | ||
23 | * This class holds information about key code and possible | ||
24 | * modifier state. That is the lowest level of the key input | ||
25 | * functions. | ||
26 | * There are also static methods to get special keys. | ||
27 | * OKeyPair will be used with \see OKeyConfigItem | ||
28 | * | ||
29 | * @since 1.2 | ||
30 | */ | ||
31 | class OKeyPair { | ||
32 | public: | ||
33 | typedef QValueList<OKeyPair> List; | ||
34 | OKeyPair( int key = -1, int modifier = -1); | ||
35 | ~OKeyPair(); | ||
36 | |||
37 | bool operator==( const OKeyPair& )const; | ||
38 | bool operator!=( const OKeyPair& )const; | ||
39 | |||
40 | bool isEmpty()const; | ||
41 | |||
42 | int keycode()const; | ||
43 | int modifier()const; | ||
44 | |||
45 | void setKeycode( int ); | ||
46 | void setModifier( int ); | ||
47 | |||
48 | static OKeyPair returnKey(); | ||
49 | static OKeyPair leftArrowKey(); | ||
50 | static OKeyPair rightArrowKey(); | ||
51 | static OKeyPair upArrowKey(); | ||
52 | static OKeyPair downArrowKey(); | ||
53 | static OKeyPair emptyKey(); | ||
54 | static OKeyPair::List hardwareKeys(); | ||
55 | |||
56 | private: | ||
57 | int m_key; | ||
58 | int m_mod; | ||
59 | class Private; | ||
60 | Private* d; | ||
61 | }; | ||
62 | |||
63 | /** | ||
64 | * A class to represent an OKeyPair. | ||
65 | * It consists out of a Text exposed to the user, Config Key Item, | ||
66 | * Pixmap, A default OKeyPair and the set OKeyPair. | ||
67 | * You can also pass an id to it | ||
68 | * | ||
69 | * @since 1.1.2 | ||
70 | */ | ||
71 | class OKeyConfigItem { | ||
72 | friend class OKeyConfigManager; | ||
73 | public: | ||
74 | typedef QValueList<OKeyConfigItem> List; | ||
75 | OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(), | ||
76 | const QPixmap& symbol = QPixmap(), | ||
77 | int id = -1, | ||
78 | const OKeyPair& def = OKeyPair::emptyKey(), | ||
79 | QObject *caller = 0, const char* slot = 0); | ||
80 | OKeyConfigItem( const Opie::Core::ODeviceButton& ); | ||
81 | ~OKeyConfigItem(); | ||
82 | |||
83 | bool operator==( const OKeyConfigItem& )const; | ||
84 | bool operator!=( const OKeyConfigItem& )const; | ||
85 | |||
86 | QString text()const; | ||
87 | QPixmap pixmap()const; | ||
88 | int id()const; | ||
89 | |||
90 | |||
91 | |||
92 | OKeyPair keyPair()const; | ||
93 | OKeyPair defaultKeyPair()const; | ||
94 | QCString configKey()const; | ||
95 | |||
96 | |||
97 | void setText( const QString& text ); | ||
98 | void setPixmap( const QPixmap& ); | ||
99 | void setKeyPair( const OKeyPair& ); | ||
100 | void setDefaultKeyPair( const OKeyPair& ); | ||
101 | |||
102 | bool isEmpty()const; | ||
103 | |||
104 | protected: | ||
105 | QObject *object()const; | ||
106 | QCString slot()const; | ||
107 | void setId( int id ); | ||
108 | void setConfigKey( const QCString& ); | ||
109 | |||
110 | private: | ||
111 | QString m_text; | ||
112 | QCString m_config; | ||
113 | QPixmap m_pix; | ||
114 | int m_id; | ||
115 | OKeyPair m_key; | ||
116 | OKeyPair m_def; | ||
117 | QObject *m_obj; | ||
118 | QCString m_str; | ||
119 | class Private; | ||
120 | Private *d; | ||
121 | }; | ||
122 | |||
123 | |||
124 | |||
125 | /** | ||
126 | * \brief A manager to load and save Key Actions and get notified | ||
127 | * This is the Manager for KeyActions. | ||
128 | * You can say from which config and group to read data, to grab the | ||
129 | * keyboard to handle hardware keys, you can supply a blacklist of | ||
130 | * keys which should not be used by allowed to be used. | ||
131 | * You can even pass this manager to a Widget to do the configuration for you. | ||
132 | * You need to add OKeyConfigItem for your keys and then issue a load() to | ||
133 | * read the Key information. | ||
134 | * You can either handle the QKeyEvent yourself and ask this class if it is | ||
135 | * handled by your action and let give you the action. Or you can install | ||
136 | * the event filter and get a signal. | ||
137 | * You need to load ans save yourself! | ||
138 | * | ||
139 | * @since 1.1.2 | ||
140 | */ | ||
141 | class OKeyConfigManager : public QObject { | ||
142 | Q_OBJECT | ||
143 | typedef QMap<int, OKeyConfigItem::List> OKeyMapConfigPrivate; | ||
144 | public: | ||
145 | OKeyConfigManager(Opie::Core::OConfig *conf = 0, | ||
146 | const QString& group = QString::null, | ||
147 | const OKeyPair::List &block = OKeyPair::List(), | ||
148 | bool grabkeyboard = false, QObject * par = 0, | ||
149 | const char* name = 0 ); | ||
150 | ~OKeyConfigManager(); | ||
151 | |||
152 | void load(); | ||
153 | void save(); | ||
154 | |||
155 | OKeyConfigItem handleKeyEvent( QKeyEvent* ); | ||
156 | int handleKeyEventId( QKeyEvent* ); | ||
157 | |||
158 | void addKeyConfig( const OKeyConfigItem& ); | ||
159 | void removeKeyConfig( const OKeyConfigItem& ); | ||
160 | void clearKeyConfig(); | ||
161 | |||
162 | void addToBlackList( const OKeyPair& ); | ||
163 | void removeFromBlackList( const OKeyPair& ); | ||
164 | void clearBlackList(); | ||
165 | OKeyPair::List blackList()const; | ||
166 | |||
167 | void handleWidget( QWidget* ); | ||
168 | |||
169 | bool eventFilter( QObject*, QEvent* ); | ||
170 | |||
171 | OKeyConfigItem::List keyConfigList()const; | ||
172 | signals: | ||
173 | /** | ||
174 | * The Signals are triggered on KeyPress and KeyRelease! | ||
175 | * You can check the isDown of the QKeyEvent | ||
176 | * @see QKeyEvent | ||
177 | */ | ||
178 | void actionActivated( QWidget*, QKeyEvent*, const Opie::Core::OKeyConfigItem& ); | ||
179 | |||
180 | /** | ||
181 | * This Signal correspondents to the OKeyConfigItem slot | ||
182 | * and object | ||
183 | * | ||
184 | * @see OKeyConfigItem::slot | ||
185 | * @see OKeyConfigItem::object | ||
186 | */ | ||
187 | void actionActivated( QWidget* par, QKeyEvent* key); | ||
188 | |||
189 | private: | ||
190 | OKeyConfigItem::List keyList( int ); | ||
191 | OKeyConfigItem::List m_keys; | ||
192 | QValueList<QWidget*> m_widgets; | ||
193 | Opie::Core::OConfig *m_conf; | ||
194 | QString m_group; | ||
195 | OKeyPair::List m_blackKeys; | ||
196 | bool m_grab : 1; | ||
197 | OKeyMapConfigPrivate *m_map; | ||
198 | class Private; | ||
199 | Private *d; | ||
200 | }; | ||
201 | |||
202 | } | ||
203 | } | ||
204 | |||
205 | #endif | ||
diff --git a/libopie2/opiecore/okeyconfigmanager_p.h b/libopie2/opiecore/okeyconfigmanager_p.h new file mode 100644 index 0000000..0fe1056 --- a/dev/null +++ b/libopie2/opiecore/okeyconfigmanager_p.h | |||
@@ -0,0 +1,9 @@ | |||
1 | |||
2 | namespace Opie { | ||
3 | namespace Core { | ||
4 | namespace Internal { | ||
5 | void fixupKeys( int&, int&, QKeyEvent* ); | ||
6 | } | ||
7 | } | ||
8 | } | ||
9 | |||
diff --git a/libopie2/opiecore/opiecore.pro b/libopie2/opiecore/opiecore.pro index ae0af77..171bb0c 100644 --- a/libopie2/opiecore/opiecore.pro +++ b/libopie2/opiecore/opiecore.pro | |||
@@ -1,41 +1,43 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | CONFIG += qt warn_on | 2 | CONFIG += qt warn_on |
3 | DESTDIR = $(OPIEDIR)/lib | 3 | DESTDIR = $(OPIEDIR)/lib |
4 | HEADERS = oapplication.h \ | 4 | HEADERS = oapplication.h \ |
5 | oconfig.h \ | 5 | oconfig.h \ |
6 | odebug.h \ | 6 | odebug.h \ |
7 | oglobal.h \ | 7 | oglobal.h \ |
8 | oglobalsettings.h \ | 8 | oglobalsettings.h \ |
9 | okeyconfigmanager.h \ | ||
9 | oprocess.h \ | 10 | oprocess.h \ |
10 | oprocctrl.h \ | 11 | oprocctrl.h \ |
11 | osmartpointer.h \ | 12 | osmartpointer.h \ |
12 | ostorageinfo.h \ | 13 | ostorageinfo.h \ |
13 | xmltree.h | 14 | xmltree.h |
14 | 15 | ||
15 | SOURCES = oapplication.cpp \ | 16 | SOURCES = oapplication.cpp \ |
16 | oconfig.cpp \ | 17 | oconfig.cpp \ |
17 | odebug.cpp \ | 18 | odebug.cpp \ |
18 | oglobal.cpp \ | 19 | oglobal.cpp \ |
19 | oglobalsettings.cpp \ | 20 | oglobalsettings.cpp \ |
21 | okeyconfigmanager.cpp \ | ||
20 | oprocess.cpp \ | 22 | oprocess.cpp \ |
21 | oprocctrl.cpp \ | 23 | oprocctrl.cpp \ |
22 | ostorageinfo.cpp \ | 24 | ostorageinfo.cpp \ |
23 | xmltree.cpp | 25 | xmltree.cpp |
24 | 26 | ||
25 | include ( device/device.pro ) | 27 | include ( device/device.pro ) |
26 | 28 | ||
27 | INTERFACES = | 29 | INTERFACES = |
28 | TARGET = opiecore2 | 30 | TARGET = opiecore2 |
29 | VERSION = 1.9.0 | 31 | VERSION = 1.9.0 |
30 | INCLUDEPATH += $(OPIEDIR)/include | 32 | INCLUDEPATH += $(OPIEDIR)/include |
31 | DEPENDPATH += $(OPIEDIR)/include | 33 | DEPENDPATH += $(OPIEDIR)/include |
32 | 34 | ||
33 | !contains( platform, x11 ) { | 35 | !contains( platform, x11 ) { |
34 | LIBS = -lqpe | 36 | LIBS = -lqpe |
35 | include ( $(OPIEDIR)/include.pro ) | 37 | include ( $(OPIEDIR)/include.pro ) |
36 | } | 38 | } |
37 | 39 | ||
38 | contains( platform, x11 ) { | 40 | contains( platform, x11 ) { |
39 | LIBS = -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib | 41 | LIBS = -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib |
40 | } | 42 | } |
41 | 43 | ||
diff --git a/libopie2/opieui/okeyconfigwidget.cpp b/libopie2/opieui/okeyconfigwidget.cpp index d6d34f5..1991381 100644 --- a/libopie2/opieui/okeyconfigwidget.cpp +++ b/libopie2/opieui/okeyconfigwidget.cpp | |||
@@ -1,1249 +1,527 @@ | |||
1 | #include "okeyconfigwidget.h" | 1 | #include "okeyconfigwidget.h" |
2 | #include "okeyconfigwidget_p.h" | 2 | #include "okeyconfigwidget_p.h" |
3 | 3 | ||
4 | 4 | ||
5 | #include <qgroupbox.h> | 5 | #include <qgroupbox.h> |
6 | #include <qradiobutton.h> | 6 | #include <qradiobutton.h> |
7 | #include <qpushbutton.h> | 7 | #include <qpushbutton.h> |
8 | #include <qbuttongroup.h> | 8 | #include <qbuttongroup.h> |
9 | #include <qmessagebox.h> | 9 | #include <qmessagebox.h> |
10 | #include <qaccel.h> | 10 | #include <qaccel.h> |
11 | #include <qlayout.h> | 11 | #include <qlayout.h> |
12 | #include <qlabel.h> | 12 | #include <qlabel.h> |
13 | 13 | ||
14 | /* non gui */ | 14 | /* non gui */ |
15 | #include <qtimer.h> | 15 | #include <qtimer.h> |
16 | 16 | ||
17 | 17 | using Opie::Core::OKeyConfigItem; | |
18 | using namespace Opie::Ui; | 18 | using Opie::Core::OKeyPair; |
19 | 19 | using Opie::Core::OKeyConfigManager; | |
20 | |||
21 | |||
22 | /** | ||
23 | * The default Constructor of a OKeyPair. | ||
24 | * A Key and a Modifier ( Alt/Shift/Ctrl ) | ||
25 | * needs to be supplied. | ||
26 | * Use Qt::Key for the information. | ||
27 | * The default arguments create an Empty OKeyPair. If you | ||
28 | * want to get an empty OKeyPair use the static method for getting | ||
29 | * the emptyKey() | ||
30 | * | ||
31 | * @see OKeyPair OKeyPair::emptyKey() | ||
32 | */ | ||
33 | OKeyPair::OKeyPair( int key, int mod ) | ||
34 | : m_key( key ), m_mod( mod ) | ||
35 | {} | ||
36 | |||
37 | /** | ||
38 | * The destructor | ||
39 | */ | ||
40 | OKeyPair::~OKeyPair() {} | ||
41 | |||
42 | |||
43 | /** | ||
44 | * Is this OKeyPair empty/valid? | ||
45 | */ | ||
46 | bool OKeyPair::isEmpty()const { | ||
47 | return ( ( m_key == -1 )&& ( m_mod == -1 ) ); | ||
48 | } | ||
49 | |||
50 | /** | ||
51 | * get the keycode for this OKeyPair. The Key relates to Qt::Key. | ||
52 | * | ||
53 | * @see Qt::Key | ||
54 | * @see setKey | ||
55 | */ | ||
56 | int OKeyPair::keycode()const { | ||
57 | return m_key; | ||
58 | } | ||
59 | |||
60 | /** | ||
61 | * get the modifier key for this OKeyPair. The Modifier State relates | ||
62 | * to the Qt::ButtonState | ||
63 | * | ||
64 | * @see Qt::ButtonState | ||
65 | * @see setModifier | ||
66 | */ | ||
67 | int OKeyPair::modifier()const { | ||
68 | return m_mod; | ||
69 | } | ||
70 | |||
71 | |||
72 | /** | ||
73 | * Set the keycode | ||
74 | * @param key The Keycode to set | ||
75 | * | ||
76 | * @see keycode() | ||
77 | * @see Qt::Key | ||
78 | */ | ||
79 | void OKeyPair::setKeycode( int key ) { | ||
80 | m_key = key; | ||
81 | } | ||
82 | |||
83 | /** | ||
84 | * Set the modifier key | ||
85 | * | ||
86 | * @param the Modifier key | ||
87 | * @see Qt::ButtonState | ||
88 | * @see modifier() | ||
89 | */ | ||
90 | void OKeyPair::setModifier( int mod ) { | ||
91 | m_mod = mod; | ||
92 | } | ||
93 | |||
94 | /** | ||
95 | * Return an OKeyPair for the Return Key without any modifier. | ||
96 | */ | ||
97 | OKeyPair OKeyPair::returnKey() { | ||
98 | return OKeyPair( Qt::Key_Return, 0 ); | ||
99 | } | ||
100 | |||
101 | /** | ||
102 | * Return an OKeyPair for the Left Arrow Key | ||
103 | * without any modifier Key | ||
104 | */ | ||
105 | OKeyPair OKeyPair::leftArrowKey() { | ||
106 | return OKeyPair( Qt::Key_Left, 0 ); | ||
107 | } | ||
108 | |||
109 | /** | ||
110 | * Return an OKeyPair for the Right Arrow Key | ||
111 | * without any modifier Key | ||
112 | */ | ||
113 | OKeyPair OKeyPair::rightArrowKey() { | ||
114 | return OKeyPair( Qt::Key_Right, 0 ); | ||
115 | } | ||
116 | |||
117 | /** | ||
118 | * Return an OKeyPair for the Up Arrow Key | ||
119 | * without any modifier Key | ||
120 | */ | ||
121 | OKeyPair OKeyPair::upArrowKey() { | ||
122 | return OKeyPair( Qt::Key_Up, 0 ); | ||
123 | } | ||
124 | |||
125 | /** | ||
126 | * Return an OKeyPair for the Down Arrow Key | ||
127 | * without any modifier Key | ||
128 | */ | ||
129 | OKeyPair OKeyPair::downArrowKey() { | ||
130 | return OKeyPair( Qt::Key_Down, 0 ); | ||
131 | } | ||
132 | |||
133 | /** | ||
134 | * Return an Empty OKeyPair | ||
135 | */ | ||
136 | OKeyPair OKeyPair::emptyKey() { | ||
137 | return OKeyPair(); | ||
138 | } | ||
139 | |||
140 | /** | ||
141 | * This functions uses the Opie::Core::ODevice::buttons | ||
142 | * for OKeyPairList | ||
143 | * | ||
144 | * @see Opie::Core::ODevice | ||
145 | * @see Opie::Core::ODeviceButton | ||
146 | * @see Opie::Core::ODevice::button | ||
147 | */ | ||
148 | OKeyPair::List OKeyPair::hardwareKeys() { | ||
149 | const QValueList<Opie::Core::ODeviceButton> but = Opie::Core::ODevice::inst()->buttons(); | ||
150 | OKeyPair::List lst; | ||
151 | |||
152 | for ( QValueList<Opie::Core::ODeviceButton>::ConstIterator it = but.begin(); | ||
153 | it != but.end(); ++it ) | ||
154 | lst.append( OKeyPair( (*it).keycode(), 0 ) ); | ||
155 | |||
156 | |||
157 | return lst; | ||
158 | } | ||
159 | |||
160 | /** | ||
161 | * Equals operator. Check if two OKeyPairs have the same key and modifier | ||
162 | * @see operator!= | ||
163 | */ | ||
164 | bool OKeyPair::operator==( const OKeyPair& pair)const { | ||
165 | if ( m_key != pair.m_key ) return false; | ||
166 | if ( m_mod != pair.m_mod ) return false; | ||
167 | |||
168 | return true; | ||
169 | } | ||
170 | |||
171 | /** | ||
172 | * Not equal operator. calls the equal operator internally | ||
173 | */ | ||
174 | bool OKeyPair::operator!=( const OKeyPair& pair)const { | ||
175 | return !(*this == pair); | ||
176 | } | ||
177 | |||
178 | |||
179 | /** | ||
180 | * The normal Constructor to create a OKeyConfigItem | ||
181 | * | ||
182 | * You can set the the key paramater of this item but if | ||
183 | * you use this item with the OKeyConfigManager your setting | ||
184 | * will be overwritten. | ||
185 | * You can also specify a QObject and slot which sould get called | ||
186 | * once this item is activated. This slot only works if you | ||
187 | * use the OKeyConfigManager. | ||
188 | * The actual Key is read by load() | ||
189 | * | ||
190 | * \code | ||
191 | * void MySlot::create(){ | ||
192 | * OKeyConfigItem item(tr("Delete"),"delete",Resource::loadPixmap("trash"), | ||
193 | * 123, OKeyPair(Qt::Key_D,Qt::ControlButton), | ||
194 | * this,SLOT(slotDelete(QWidget*,QKeyEvent*))); | ||
195 | * } | ||
196 | * \endcode | ||
197 | * | ||
198 | * @param text The text exposed to the user | ||
199 | * @param config_key The key used in the config | ||
200 | * @param pix A Pixmap associated with this Item | ||
201 | * @param def The OKeyPair used as default | ||
202 | * @param caller The object where the slot exists | ||
203 | * @param slot The slot which should get called | ||
204 | * | ||
205 | */ | ||
206 | OKeyConfigItem::OKeyConfigItem( const QString& text, const QCString& config_key, | ||
207 | const QPixmap& pix, int id, const OKeyPair& def, | ||
208 | QObject *caller, | ||
209 | const char* slot ) | ||
210 | : m_text( text ), m_config( config_key ), m_pix( pix ), | ||
211 | m_id( id ), m_def( def ), | ||
212 | m_obj( caller ), m_str( slot ) {} | ||
213 | |||
214 | /** | ||
215 | * A special Constructor for converting from an Opie::Core::ODeviceButton | ||
216 | * delivered by Opie::Core::ODevice::buttons() | ||
217 | * There is no Config Key set and both default key and key are set | ||
218 | * to Opie::Core::ODeviceButton::keycode() and 0 to modifier | ||
219 | * | ||
220 | * @see Opie::Core::ODevice | ||
221 | * @see Opie::Core::ODeviceButton | ||
222 | * @see Opie::Core::ODevice::buttons() | ||
223 | */ | ||
224 | OKeyConfigItem::OKeyConfigItem( const Opie::Core::ODeviceButton& b ) | ||
225 | : m_text( b.userText() ), m_pix( b.pixmap() ), m_id( -1 ), | ||
226 | m_key( OKeyPair( b.keycode(), 0 ) ), m_def( OKeyPair( b.keycode(), 0 ) ) | ||
227 | {} | ||
228 | |||
229 | |||
230 | /** | ||
231 | * Destructor | ||
232 | */ | ||
233 | OKeyConfigItem::~OKeyConfigItem() {} | ||
234 | |||
235 | |||
236 | /** | ||
237 | * The text exposed to the user | ||
238 | * | ||
239 | * @see setText | ||
240 | */ | ||
241 | QString OKeyConfigItem::text()const { | ||
242 | return m_text; | ||
243 | } | ||
244 | |||
245 | /** | ||
246 | * The pixmap shown to the user for your action/key | ||
247 | * | ||
248 | * @see setPixmap | ||
249 | */ | ||
250 | QPixmap OKeyConfigItem::pixmap()const { | ||
251 | return m_pix; | ||
252 | } | ||
253 | |||
254 | /** | ||
255 | * Return the OKeyPair this OKeyConfigItem is configured for. | ||
256 | * | ||
257 | * @see setKeyPair | ||
258 | */ | ||
259 | OKeyPair OKeyConfigItem::keyPair()const { | ||
260 | return m_key; | ||
261 | } | ||
262 | |||
263 | /** | ||
264 | * Return the default OKeyPair | ||
265 | * @see setDefaultKeyPair | ||
266 | */ | ||
267 | OKeyPair OKeyConfigItem::defaultKeyPair()const { | ||
268 | return m_def; | ||
269 | } | ||
270 | |||
271 | |||
272 | /** | ||
273 | * Return the Id you assigned to this item. | ||
274 | * setting is only possible by the constructor | ||
275 | */ | ||
276 | int OKeyConfigItem::id()const{ | ||
277 | return m_id; | ||
278 | } | ||
279 | |||
280 | /** | ||
281 | * reutrn the Config Key. Setting it is only possible | ||
282 | * by the constructor | ||
283 | */ | ||
284 | QCString OKeyConfigItem::configKey()const { | ||
285 | return m_config; | ||
286 | } | ||
287 | |||
288 | /** | ||
289 | * @internal | ||
290 | */ | ||
291 | QObject* OKeyConfigItem::object()const{ | ||
292 | return m_obj; | ||
293 | } | ||
294 | |||
295 | /** | ||
296 | * @internal | ||
297 | */ | ||
298 | QCString OKeyConfigItem::slot()const { | ||
299 | return m_str; | ||
300 | } | ||
301 | |||
302 | /** | ||
303 | * Set the text | ||
304 | * | ||
305 | * @param text Set the Text of this Action to text | ||
306 | * @see text() | ||
307 | */ | ||
308 | void OKeyConfigItem::setText( const QString& text ) { | ||
309 | m_text = text; | ||
310 | } | ||
311 | |||
312 | /** | ||
313 | * Set the pixmap of this action | ||
314 | * | ||
315 | * @param pix The Pixmap to set | ||
316 | * @see pixmap() | ||
317 | */ | ||
318 | void OKeyConfigItem::setPixmap( const QPixmap& pix ) { | ||
319 | m_pix = pix; | ||
320 | } | ||
321 | |||
322 | /** | ||
323 | * Set the KeyPair the OKeyConfigItem uses. | ||
324 | * Your set Key could get overwritten if you use | ||
325 | * the manager or GUI to configure the key | ||
326 | * | ||
327 | * @param key Set the OKeyPair used | ||
328 | * @see keyPair() | ||
329 | */ | ||
330 | void OKeyConfigItem::setKeyPair( const OKeyPair& key) { | ||
331 | m_key = key; | ||
332 | } | ||
333 | |||
334 | /** | ||
335 | * Set the default KeyPair. | ||
336 | * | ||
337 | * @param key The default keypair | ||
338 | * @see defaultKeyPair() | ||
339 | */ | ||
340 | void OKeyConfigItem::setDefaultKeyPair( const OKeyPair& key ) { | ||
341 | m_def = key; | ||
342 | } | ||
343 | |||
344 | /** | ||
345 | * @internal | ||
346 | */ | ||
347 | void OKeyConfigItem::setConfigKey( const QCString& str) { | ||
348 | m_config = str; | ||
349 | m_config.detach(); | ||
350 | } | ||
351 | |||
352 | /** | ||
353 | * @internal | ||
354 | */ | ||
355 | void OKeyConfigItem::setId( int id ) { | ||
356 | m_id = id; | ||
357 | } | ||
358 | |||
359 | /** | ||
360 | * If the item is not configured isEmpty() will return true | ||
361 | * It is empty if no text is present and no default | ||
362 | * and no configured key | ||
363 | */ | ||
364 | bool OKeyConfigItem::isEmpty()const { | ||
365 | if ( !m_def.isEmpty() ) return false; | ||
366 | if ( !m_key.isEmpty() ) return false; | ||
367 | if ( !m_text.isEmpty() ) return false; | ||
368 | if ( m_id != -1 ) return false; | ||
369 | |||
370 | return true; | ||
371 | } | ||
372 | |||
373 | /** | ||
374 | * Check if the KeyPairs are the same | ||
375 | */ | ||
376 | bool OKeyConfigItem::operator==( const OKeyConfigItem& conf )const { | ||
377 | /* if ( isEmpty() == conf.isEmpty() ) return true; | ||
378 | else if ( isEmpty() != conf.isEmpty() ) return false; | ||
379 | else if ( !isEmpty()!= conf.isEmpty() ) return false; | ||
380 | */ | ||
381 | |||
382 | if ( m_id != conf.m_id ) return false; | ||
383 | if ( m_obj != conf.m_obj ) return false; | ||
384 | if ( m_text != conf.m_text ) return false; | ||
385 | if ( m_key != conf.m_key ) return false; | ||
386 | if ( m_def != conf.m_def ) return false; | ||
387 | |||
388 | |||
389 | |||
390 | return true; | ||
391 | |||
392 | } | ||
393 | |||
394 | bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf )const { | ||
395 | return !( *this == conf ); | ||
396 | } | ||
397 | |||
398 | /** | ||
399 | * \brief c'tor | ||
400 | * The Constructor for a OKeyConfigManager | ||
401 | * | ||
402 | * You can use this manager in multiple ways. Either make it handle | ||
403 | * QKeyEvents | ||
404 | * | ||
405 | * \code | ||
406 | * Opie::Core::Config conf = oApp->config(); | ||
407 | * Opie::Ui::OKeyPairList blackList; | ||
408 | * blackList.append(Opie::Ui::OKeyPair::leftArrowKey()); | ||
409 | * blackList.append(Opie::Ui::OKeyPair::rightArrowKey()); | ||
410 | * Opie::Ui::OKeyConfigManager *manager = new Opie::Ui::OKeyConfigManager(conf,"key_actions",blackList, | ||
411 | * false); | ||
412 | * QListView *view = new QListView(); | ||
413 | * manager->handleWidget(view); | ||
414 | * manager->addKeyConfig( Opie::Ui::OKeyPair::returnKey()); | ||
415 | * manager->load(); | ||
416 | * | ||
417 | * connect(manager,SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&)), | ||
418 | * this,SLOT(slotHandleKey(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&))); | ||
419 | * | ||
420 | * .... | ||
421 | * | ||
422 | * void update(){ | ||
423 | * QDialog diag(true); | ||
424 | * QHBoxLayout *lay = new QHBoxLayout(&diag); | ||
425 | * Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget(manager,&diag); | ||
426 | * wid->setChangeMode(Opie::Ui::OKeyConfigWidget::Queu); | ||
427 | * lay->addWidget(wid); | ||
428 | * if(QPEApplication::execDialog( &diag)== QDialog::Accepted){ | ||
429 | * wid->save(); | ||
430 | * } | ||
431 | * } | ||
432 | * | ||
433 | * .... | ||
434 | * MyListView::keyPressEvent( QKeyEvent* e ){ | ||
435 | * Opie::Ui::OKeyConfigItem item = manager->handleKeyEvent(e); | ||
436 | * if(!item.isEmpty() ){ | ||
437 | * switch(item.id()){ | ||
438 | * case My_Delete_Key: | ||
439 | * break; | ||
440 | * } | ||
441 | * } | ||
442 | * } | ||
443 | * | ||
444 | * \endcode | ||
445 | * | ||
446 | * @param conf The Config where the KeySetting should be stored | ||
447 | * @param group The group where the KeySetting will be stored | ||
448 | * @param black Which keys shouldn't be allowed to handle | ||
449 | * @param grabkeyboard Calls QPEApplication::grabKeyboard to allow handling of DeviceButtons | ||
450 | * @param par The parent/owner of this manager | ||
451 | * @param name The name of this object | ||
452 | */ | ||
453 | OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf, | ||
454 | const QString& group, | ||
455 | const OKeyPair::List& black, | ||
456 | bool grabkeyboard, QObject* par, | ||
457 | const char* name) | ||
458 | : QObject( par, name ), m_conf( conf ), m_group( group ), | ||
459 | m_blackKeys( black ), m_grab( grabkeyboard ), m_map( 0 ){ | ||
460 | if ( m_grab ) | ||
461 | QPEApplication::grabKeyboard(); | ||
462 | } | ||
463 | |||
464 | |||
465 | /** | ||
466 | * Destructor | ||
467 | */ | ||
468 | OKeyConfigManager::~OKeyConfigManager() { | ||
469 | if ( m_grab ) | ||
470 | QPEApplication::ungrabKeyboard(); | ||
471 | } | ||
472 | |||
473 | /** | ||
474 | * Load the Configuration from the OConfig | ||
475 | * If a Key is restricted but was in the config we will | ||
476 | * make it be the empty key paur | ||
477 | * We will change the group but restore to the previous. | ||
478 | * | ||
479 | * @see OKeyPair::emptyKey | ||
480 | */ | ||
481 | void OKeyConfigManager::load() { | ||
482 | Opie::Core::OConfigGroupSaver( m_conf, m_group ); | ||
483 | |||
484 | /* | ||
485 | * Read each item | ||
486 | */ | ||
487 | int key, mod; | ||
488 | for( OKeyConfigItem::List::Iterator it = m_keys.begin(); it != m_keys.end(); ++it ) { | ||
489 | key = m_conf->readNumEntry( (*it).configKey()+"key", (*it).defaultKeyPair().keycode() ); | ||
490 | mod = m_conf->readNumEntry( (*it).configKey()+"mod", (*it).defaultKeyPair().modifier() ); | ||
491 | OKeyPair okey( key, mod ); | ||
492 | |||
493 | if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 ) | ||
494 | (*it).setKeyPair( OKeyPair(key, mod) ); | ||
495 | else | ||
496 | (*it).setKeyPair( OKeyPair::emptyKey() ); | ||
497 | } | ||
498 | delete m_map; m_map = 0; | ||
499 | } | ||
500 | |||
501 | /** | ||
502 | * We will save the current configuration | ||
503 | * to the OConfig. We will change the group but restore | ||
504 | * to the previous | ||
505 | */ | ||
506 | void OKeyConfigManager::save() { | ||
507 | Opie::Core::OConfigGroupSaver( m_conf, m_group ); | ||
508 | |||
509 | /* | ||
510 | * Write each item | ||
511 | */ | ||
512 | for( OKeyConfigItem::List::Iterator it = m_keys.begin();it != m_keys.end(); ++it ) { | ||
513 | /* skip empty items */ | ||
514 | if ( (*it).isEmpty() ) | ||
515 | continue; | ||
516 | OKeyPair pair = (*it).keyPair(); | ||
517 | OKeyPair deft = (*it).defaultKeyPair(); | ||
518 | /* | ||
519 | * don't write if it is the default setting | ||
520 | * FIXME allow to remove Keys from config | ||
521 | if ( (pair.keycode() == deft.keycode()) && | ||
522 | (pair.modifier()== deft.modifier() ) ) | ||
523 | return; | ||
524 | */ | ||
525 | |||
526 | m_conf->writeEntry((*it).configKey()+"key", pair.keycode() ); | ||
527 | m_conf->writeEntry((*it).configKey()+"mod", pair.modifier() ); | ||
528 | } | ||
529 | m_conf->write(); | ||
530 | } | ||
531 | |||
532 | /** | ||
533 | * This is function uses a QMap internally but you can have the same keycode | ||
534 | * with different modifier key. The behaviour is undefined if you add a OKeyConfigItem | ||
535 | * with same keycode and modifier key. The GUI takes care that a user can't | ||
536 | * cofigure two keys. | ||
537 | * | ||
538 | * Make sure you call e->ignore if you don't want to handle this event | ||
539 | */ | ||
540 | OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) { | ||
541 | /* | ||
542 | * Fix Up issues with Qt/E, my keybard, and virtual input | ||
543 | * methods | ||
544 | * First my Keyboard delivers 256,512,1024 for shift/ctrl/alt instead of the button state | ||
545 | * Also key() on virtual inputmethods are zero and only ascii. We need to fix upper and lower | ||
546 | * case ascii | ||
547 | */ | ||
548 | int key, mod; | ||
549 | Opie::Ui::Internal::fixupKeys( key, mod, e ); | ||
550 | |||
551 | OKeyConfigItem::List _keyList = keyList( key ); | ||
552 | if ( _keyList.isEmpty() ) | ||
553 | return OKeyConfigItem(); | ||
554 | |||
555 | OKeyConfigItem item; | ||
556 | for ( OKeyConfigItem::List::Iterator it = _keyList.begin(); it != _keyList.end(); | ||
557 | ++it ) { | ||
558 | if ( (*it).keyPair().modifier() == mod ) { | ||
559 | item = *it; | ||
560 | break; | ||
561 | } | ||
562 | |||
563 | } | ||
564 | |||
565 | return item; | ||
566 | } | ||
567 | |||
568 | /** | ||
569 | * Return the associated id of the item or -1 if no item | ||
570 | * matched the key | ||
571 | * | ||
572 | * @see handleKeyEvent | ||
573 | */ | ||
574 | int OKeyConfigManager::handleKeyEventId( QKeyEvent* ev) { | ||
575 | return handleKeyEvent( ev ).id(); | ||
576 | } | ||
577 | |||
578 | /** | ||
579 | * Add Key Config to the List of items | ||
580 | */ | ||
581 | void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) { | ||
582 | m_keys.append( item ); | ||
583 | delete m_map; m_map = 0; | ||
584 | } | ||
585 | |||
586 | /** | ||
587 | * Remove the Key from the Config. Internal lists will be destroyed | ||
588 | * and rebuild on demand later | ||
589 | */ | ||
590 | void OKeyConfigManager::removeKeyConfig( const OKeyConfigItem& item ) { | ||
591 | m_keys.remove( item ); | ||
592 | delete m_map; m_map = 0; | ||
593 | } | ||
594 | |||
595 | /** | ||
596 | * Clears the complete list | ||
597 | */ | ||
598 | void OKeyConfigManager::clearKeyConfig() { | ||
599 | m_keys.clear(); | ||
600 | delete m_map; m_map = 0; | ||
601 | } | ||
602 | |||
603 | /** | ||
604 | * | ||
605 | */ | ||
606 | Opie::Ui::OKeyConfigItem::List OKeyConfigManager::keyConfigList()const{ | ||
607 | return m_keys; | ||
608 | } | ||
609 | |||
610 | /** | ||
611 | * Add this OKeyPair to the blackList. | ||
612 | * Internal lists will be destroyed | ||
613 | */ | ||
614 | void OKeyConfigManager::addToBlackList( const OKeyPair& key) { | ||
615 | m_blackKeys.append( key ); | ||
616 | delete m_map; m_map = 0; | ||
617 | } | ||
618 | |||
619 | |||
620 | /** | ||
621 | * Remove this OKeyPair from the black List | ||
622 | * Internal lists will be destroyed | ||
623 | */ | ||
624 | void OKeyConfigManager::removeFromBlackList( const OKeyPair& key ) { | ||
625 | m_blackKeys.remove( key ); | ||
626 | delete m_map; m_map = 0; | ||
627 | } | ||
628 | |||
629 | |||
630 | /** | ||
631 | * Clear the blackList | ||
632 | */ | ||
633 | void OKeyConfigManager::clearBlackList() { | ||
634 | m_blackKeys.clear(); | ||
635 | delete m_map; m_map = 0; | ||
636 | } | ||
637 | |||
638 | |||
639 | /** | ||
640 | * Return a copy of the blackList | ||
641 | */ | ||
642 | OKeyPair::List OKeyConfigManager::blackList()const { | ||
643 | return m_blackKeys; | ||
644 | } | ||
645 | |||
646 | |||
647 | /** | ||
648 | * Ask the Manager to handle KeyEvents for you. | ||
649 | * All handled keys will emit a QSignal and return true | ||
650 | * that it handled the keyevent | ||
651 | */ | ||
652 | void OKeyConfigManager::handleWidget( QWidget* wid ) { | ||
653 | wid->installEventFilter( this ); | ||
654 | } | ||
655 | |||
656 | /** | ||
657 | * @internal | ||
658 | */ | ||
659 | bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) { | ||
660 | if ( !obj->isWidgetType() ) | ||
661 | return false; | ||
662 | |||
663 | if ( ev->type() != QEvent::KeyPress && ev->type() != QEvent::KeyRelease ) | ||
664 | return false; | ||
665 | |||
666 | QKeyEvent *key = static_cast<QKeyEvent*>( ev ); | ||
667 | OKeyConfigItem item = handleKeyEvent( key ); | ||
668 | |||
669 | if ( item.isEmpty() ) | ||
670 | return false; | ||
671 | |||
672 | QWidget *wid = static_cast<QWidget*>( obj ); | ||
673 | |||
674 | if ( item.object() && !item.slot().isEmpty() ) { | ||
675 | connect( this, SIGNAL( actionActivated(QWidget*, QKeyEvent*)), | ||
676 | item.object(), item.slot().data() ); | ||
677 | emit actionActivated(wid, key); | ||
678 | disconnect( this, SIGNAL(actionActivated(QWidget*,QKeyEvent*)), | ||
679 | item.object(), item.slot().data() ); | ||
680 | } | ||
681 | emit actionActivated( wid, key, item ); | ||
682 | |||
683 | return true; | ||
684 | } | ||
685 | |||
686 | /** | ||
687 | * @internal | ||
688 | */ | ||
689 | OKeyConfigItem::List OKeyConfigManager::keyList( int keycode) { | ||
690 | /* | ||
691 | * Create the map if not existing anymore | ||
692 | */ | ||
693 | if ( !m_map ) { | ||
694 | m_map = new OKeyMapConfigPrivate; | ||
695 | /* for every key */ | ||
696 | for ( OKeyConfigItem::List::Iterator it = m_keys.begin(); | ||
697 | it!= m_keys.end(); ++it ) { | ||
698 | |||
699 | bool add = true; | ||
700 | /* see if this key is blocked */ | ||
701 | OKeyPair pair = (*it).keyPair(); | ||
702 | for ( OKeyPair::List::Iterator pairIt = m_blackKeys.begin(); | ||
703 | pairIt != m_blackKeys.end(); ++pairIt ) { | ||
704 | if ( (*pairIt).keycode() == pair.keycode() && | ||
705 | (*pairIt).modifier() == pair.modifier() ) { | ||
706 | add = false; | ||
707 | break; | ||
708 | } | ||
709 | } | ||
710 | /* check if we added it */ | ||
711 | if ( add ) | ||
712 | (*m_map)[pair.keycode()].append( *it ); | ||
713 | } | ||
714 | } | ||
715 | return (*m_map)[keycode]; | ||
716 | } | ||
717 | |||
718 | 20 | ||
719 | namespace Opie { | 21 | namespace Opie { |
720 | namespace Ui { | 22 | namespace Ui { |
721 | namespace Internal { | 23 | namespace Internal { |
722 | 24 | ||
723 | OKeyListViewItem::OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager* man, OListViewItem* parent) | 25 | OKeyListViewItem::OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager* man, OListViewItem* parent) |
724 | : Opie::Ui::OListViewItem( parent ), m_manager( man ) { | 26 | : Opie::Ui::OListViewItem( parent ), m_manager( man ) { |
725 | m_origItem = item; | 27 | m_origItem = item; |
726 | setItem( item ); | 28 | setItem( item ); |
727 | } | 29 | } |
728 | OKeyListViewItem::~OKeyListViewItem() {} | 30 | OKeyListViewItem::~OKeyListViewItem() {} |
729 | OKeyConfigItem &OKeyListViewItem::item(){ | 31 | OKeyConfigItem &OKeyListViewItem::item(){ |
730 | return m_item; | 32 | return m_item; |
731 | } | 33 | } |
732 | OKeyConfigItem OKeyListViewItem::origItem() const{ | 34 | OKeyConfigItem OKeyListViewItem::origItem() const{ |
733 | return m_origItem; | 35 | return m_origItem; |
734 | } | 36 | } |
735 | OKeyConfigManager* OKeyListViewItem::manager() { | 37 | OKeyConfigManager* OKeyListViewItem::manager() { |
736 | return m_manager; | 38 | return m_manager; |
737 | } | 39 | } |
738 | void OKeyListViewItem::setItem( const OKeyConfigItem& item ) { | 40 | void OKeyListViewItem::setItem( const OKeyConfigItem& item ) { |
739 | m_item = item; | 41 | m_item = item; |
740 | setPixmap( 0, m_item.pixmap() ); | 42 | setPixmap( 0, m_item.pixmap() ); |
741 | setText ( 1, m_item.text() ); | 43 | setText ( 1, m_item.text() ); |
742 | m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) : | 44 | m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) : |
743 | setText( 2, keyToString( m_item.keyPair() ) ); | 45 | setText( 2, keyToString( m_item.keyPair() ) ); |
744 | 46 | ||
745 | m_item.defaultKeyPair().isEmpty() ? setText( 3, QObject::tr( "None" ) ) : | 47 | m_item.defaultKeyPair().isEmpty() ? setText( 3, QObject::tr( "None" ) ) : |
746 | setText ( 3, keyToString( m_item.defaultKeyPair() ) ); | 48 | setText ( 3, keyToString( m_item.defaultKeyPair() ) ); |
747 | } | 49 | } |
748 | void OKeyListViewItem::updateText() { | 50 | void OKeyListViewItem::updateText() { |
749 | m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) : | 51 | m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) : |
750 | setText( 2, keyToString( m_item.keyPair() ) ); | 52 | setText( 2, keyToString( m_item.keyPair() ) ); |
751 | } | 53 | } |
752 | 54 | ||
753 | QString keyToString( const OKeyPair& pair ) { | 55 | QString keyToString( const OKeyPair& pair ) { |
754 | int mod = 0; | 56 | int mod = 0; |
755 | if ( pair.modifier() & Qt::ShiftButton ) | 57 | if ( pair.modifier() & Qt::ShiftButton ) |
756 | mod |= Qt::SHIFT; | 58 | mod |= Qt::SHIFT; |
757 | if ( pair.modifier() & Qt::ControlButton ) | 59 | if ( pair.modifier() & Qt::ControlButton ) |
758 | mod |= Qt::CTRL; | 60 | mod |= Qt::CTRL; |
759 | if ( pair.modifier() & Qt::AltButton ) | 61 | if ( pair.modifier() & Qt::AltButton ) |
760 | mod |= Qt::ALT; | 62 | mod |= Qt::ALT; |
761 | 63 | ||
762 | return QAccel::keyToString( mod + pair.keycode() ); | 64 | return QAccel::keyToString( mod + pair.keycode() ); |
763 | } | 65 | } |
764 | 66 | ||
765 | /* | ||
766 | * the virtual and hardware key events have both issues... | ||
767 | */ | ||
768 | void fixupKeys( int& key, int &mod, QKeyEvent* e ) { | ||
769 | key = e->key(); | ||
770 | mod = e->state(); | ||
771 | /* | ||
772 | * virtual keyboard | ||
773 | * else change the button mod only | ||
774 | */ | ||
775 | if ( key == 0 ) { | ||
776 | key = e->ascii(); | ||
777 | if ( key > 96 && key < 123) | ||
778 | key -= 32; | ||
779 | }else{ | ||
780 | int new_mod = 0; | ||
781 | if ( mod & 256 ) | ||
782 | new_mod |= Qt::ShiftButton; | ||
783 | else if ( mod & 512 ) | ||
784 | new_mod |= Qt::ControlButton; | ||
785 | else if ( mod & 1024 ) | ||
786 | new_mod |= Qt::AltButton; | ||
787 | |||
788 | mod = new_mod == 0? mod : new_mod; | ||
789 | } | ||
790 | } | ||
791 | |||
792 | struct OKeyConfigWidgetPrivate{ | 67 | struct OKeyConfigWidgetPrivate{ |
793 | OKeyConfigWidgetPrivate(const QString& = QString::null, | 68 | OKeyConfigWidgetPrivate(const QString& = QString::null, |
794 | OKeyConfigManager* = 0); | 69 | OKeyConfigManager* = 0); |
795 | bool operator==( const OKeyConfigWidgetPrivate& ); | 70 | bool operator==( const OKeyConfigWidgetPrivate& ); |
796 | QString name; | 71 | QString name; |
797 | OKeyConfigManager *manager; | 72 | OKeyConfigManager *manager; |
798 | }; | 73 | }; |
799 | 74 | ||
800 | OKeyConfigWidgetPrivate::OKeyConfigWidgetPrivate( const QString& _name, | 75 | OKeyConfigWidgetPrivate::OKeyConfigWidgetPrivate( const QString& _name, |
801 | OKeyConfigManager* man ) | 76 | OKeyConfigManager* man ) |
802 | : name( _name ), manager( man ){} | 77 | : name( _name ), manager( man ){} |
803 | 78 | ||
804 | bool OKeyConfigWidgetPrivate::operator==( const OKeyConfigWidgetPrivate& item) { | 79 | bool OKeyConfigWidgetPrivate::operator==( const OKeyConfigWidgetPrivate& item) { |
805 | if ( manager != item.manager) return false; | 80 | if ( manager != item.manager) return false; |
806 | if ( name != item.name ) return false; | 81 | if ( name != item.name ) return false; |
807 | 82 | ||
808 | return true; | 83 | return true; |
809 | } | 84 | } |
810 | 85 | ||
811 | } | 86 | } |
812 | } | 87 | |
813 | } | ||
814 | 88 | ||
815 | 89 | ||
816 | 90 | ||
817 | //////////////////////// | 91 | //////////////////////// |
818 | //////////////////////// | 92 | //////////////////////// |
819 | //////// Widget Starts Here | 93 | //////// Widget Starts Here |
820 | 94 | ||
821 | 95 | ||
822 | 96 | ||
823 | 97 | ||
824 | /** | 98 | /** |
825 | * | 99 | * |
826 | * This is a c'tor. You still need to pass the OKeyConfigManager | 100 | * This is a c'tor. You still need to pass the OKeyConfigManager |
827 | * and then issue a load. | 101 | * and then issue a load. |
828 | * The default mode is Immediate | 102 | * The default mode is Immediate |
829 | * | 103 | * |
830 | */ | 104 | */ |
831 | OKeyConfigWidget::OKeyConfigWidget( QWidget* parent, const char *name, WFlags fl ) | 105 | OKeyConfigWidget::OKeyConfigWidget( QWidget* parent, const char *name, WFlags fl ) |
832 | : QWidget( parent, name, fl ) { | 106 | : QWidget( parent, name, fl ) { |
833 | initUi(); | 107 | initUi(); |
834 | } | 108 | } |
835 | 109 | ||
836 | 110 | ||
837 | 111 | ||
838 | /** | 112 | /** |
839 | * c'tor | 113 | * c'tor |
840 | */ | 114 | */ |
841 | OKeyConfigWidget::~OKeyConfigWidget() { | 115 | OKeyConfigWidget::~OKeyConfigWidget() { |
842 | } | 116 | } |
843 | 117 | ||
844 | 118 | ||
845 | /** | 119 | /** |
846 | * @internal | 120 | * @internal |
847 | */ | 121 | */ |
848 | void OKeyConfigWidget::initUi() { | 122 | void OKeyConfigWidget::initUi() { |
849 | QBoxLayout *layout = new QVBoxLayout( this ); | 123 | QBoxLayout *layout = new QVBoxLayout( this ); |
850 | QGridLayout *gridLay = new QGridLayout( 2, 2 ); | 124 | QGridLayout *gridLay = new QGridLayout( 2, 2 ); |
851 | layout->addLayout( gridLay, 10 ); | 125 | layout->addLayout( gridLay, 10 ); |
852 | gridLay->setRowStretch( 1, 10 ); // let only the ListView strecth | 126 | gridLay->setRowStretch( 1, 10 ); // let only the ListView strecth |
853 | 127 | ||
854 | /* | 128 | /* |
855 | * LISTVIEW with the Keys | 129 | * LISTVIEW with the Keys |
856 | */ | 130 | */ |
857 | m_view = new Opie::Ui::OListView( this ); | 131 | m_view = new Opie::Ui::OListView( this ); |
858 | m_view->setFocus(); | 132 | m_view->setFocus(); |
859 | m_view->setAllColumnsShowFocus( true ); | 133 | m_view->setAllColumnsShowFocus( true ); |
860 | m_view->addColumn( tr("Pixmap") ); | 134 | m_view->addColumn( tr("Pixmap") ); |
861 | m_view->addColumn( tr("Name","Name of the Action in the ListView Header" ) ); | 135 | m_view->addColumn( tr("Name","Name of the Action in the ListView Header" ) ); |
862 | m_view->addColumn( tr("Key" ) ); | 136 | m_view->addColumn( tr("Key" ) ); |
863 | m_view->addColumn( tr("Default Key" ) ); | 137 | m_view->addColumn( tr("Default Key" ) ); |
864 | m_view->setRootIsDecorated( true ); | 138 | m_view->setRootIsDecorated( true ); |
865 | connect(m_view, SIGNAL(currentChanged(QListViewItem*)), | 139 | connect(m_view, SIGNAL(currentChanged(QListViewItem*)), |
866 | this, SLOT(slotListViewItem(QListViewItem*)) ); | 140 | this, SLOT(slotListViewItem(QListViewItem*)) ); |
867 | 141 | ||
868 | gridLay->addMultiCellWidget( m_view, 1, 1, 0, 1 ); | 142 | gridLay->addMultiCellWidget( m_view, 1, 1, 0, 1 ); |
869 | 143 | ||
870 | /* | 144 | /* |
871 | * GROUP with button info | 145 | * GROUP with button info |
872 | */ | 146 | */ |
873 | 147 | ||
874 | QGroupBox *box = new QGroupBox( this ); | 148 | QGroupBox *box = new QGroupBox( this ); |
875 | box ->setTitle( tr("Shortcut for Selected Action") ); | 149 | box ->setTitle( tr("Shortcut for Selected Action") ); |
876 | box ->setFrameStyle( QFrame::Box | QFrame::Sunken ); | 150 | box ->setFrameStyle( QFrame::Box | QFrame::Sunken ); |
877 | layout->addWidget( box, 1 ); | 151 | layout->addWidget( box, 1 ); |
878 | 152 | ||
879 | gridLay = new QGridLayout( box, 3, 4 ); | 153 | gridLay = new QGridLayout( box, 3, 4 ); |
880 | gridLay->addRowSpacing( 0, fontMetrics().lineSpacing() ); | 154 | gridLay->addRowSpacing( 0, fontMetrics().lineSpacing() ); |
881 | gridLay->setMargin( 4 ); | 155 | gridLay->setMargin( 4 ); |
882 | 156 | ||
883 | QButtonGroup *gr = new QButtonGroup( box ); | 157 | QButtonGroup *gr = new QButtonGroup( box ); |
884 | gr->hide(); | 158 | gr->hide(); |
885 | gr->setExclusive( true ); | 159 | gr->setExclusive( true ); |
886 | 160 | ||
887 | QRadioButton *rad = new QRadioButton( tr( "&None" ), box ); | 161 | QRadioButton *rad = new QRadioButton( tr( "&None" ), box ); |
888 | connect( rad, SIGNAL(clicked()), | 162 | connect( rad, SIGNAL(clicked()), |
889 | this, SLOT(slotNoKey()) ); | 163 | this, SLOT(slotNoKey()) ); |
890 | gr->insert( rad, 10 ); | 164 | gr->insert( rad, 10 ); |
891 | gridLay->addWidget( rad, 1, 0 ); | 165 | gridLay->addWidget( rad, 1, 0 ); |
892 | m_none = rad; | 166 | m_none = rad; |
893 | 167 | ||
894 | rad = new QRadioButton( tr("&Default" ), box ); | 168 | rad = new QRadioButton( tr("&Default" ), box ); |
895 | connect( rad, SIGNAL(clicked()), | 169 | connect( rad, SIGNAL(clicked()), |
896 | this, SLOT(slotDefaultKey()) ); | 170 | this, SLOT(slotDefaultKey()) ); |
897 | gr->insert( rad, 11 ); | 171 | gr->insert( rad, 11 ); |
898 | gridLay->addWidget( rad, 1, 1 ); | 172 | gridLay->addWidget( rad, 1, 1 ); |
899 | m_def = rad; | 173 | m_def = rad; |
900 | 174 | ||
901 | rad = new QRadioButton( tr("C&ustom"), box ); | 175 | rad = new QRadioButton( tr("C&ustom"), box ); |
902 | connect( rad, SIGNAL(clicked()), | 176 | connect( rad, SIGNAL(clicked()), |
903 | this, SLOT(slotCustomKey()) ); | 177 | this, SLOT(slotCustomKey()) ); |
904 | gr->insert( rad, 12 ); | 178 | gr->insert( rad, 12 ); |
905 | gridLay->addWidget( rad, 1, 2 ); | 179 | gridLay->addWidget( rad, 1, 2 ); |
906 | m_cus = rad; | 180 | m_cus = rad; |
907 | 181 | ||
908 | m_btn = new QPushButton( tr("Configure Key"), box ); | 182 | m_btn = new QPushButton( tr("Configure Key"), box ); |
909 | gridLay->addWidget( m_btn, 1, 4 ); | 183 | gridLay->addWidget( m_btn, 1, 4 ); |
910 | 184 | ||
911 | m_lbl= new QLabel( tr( "Default: " ), box ); | 185 | m_lbl= new QLabel( tr( "Default: " ), box ); |
912 | gridLay->addWidget( m_lbl, 2, 0 ); | 186 | gridLay->addWidget( m_lbl, 2, 0 ); |
913 | 187 | ||
914 | connect(m_btn, SIGNAL(clicked()), | 188 | connect(m_btn, SIGNAL(clicked()), |
915 | this, SLOT(slotConfigure())); | 189 | this, SLOT(slotConfigure())); |
916 | 190 | ||
917 | m_box = box; | 191 | m_box = box; |
918 | } | 192 | } |
919 | 193 | ||
920 | /** | 194 | /** |
921 | * Set the ChangeMode. | 195 | * Set the ChangeMode. |
922 | * You need to call this function prior to load | 196 | * You need to call this function prior to load |
923 | * If you call this function past load the behaviour is undefined | 197 | * If you call this function past load the behaviour is undefined |
924 | * But caling load again is safe | 198 | * But caling load again is safe |
925 | */ | 199 | */ |
926 | void OKeyConfigWidget::setChangeMode( enum ChangeMode mode) { | 200 | void OKeyConfigWidget::setChangeMode( enum ChangeMode mode) { |
927 | m_mode = mode; | 201 | m_mode = mode; |
928 | } | 202 | } |
929 | 203 | ||
930 | 204 | ||
931 | /** | 205 | /** |
932 | * return the current mode | 206 | * return the current mode |
933 | */ | 207 | */ |
934 | OKeyConfigWidget::ChangeMode OKeyConfigWidget::changeMode()const { | 208 | OKeyConfigWidget::ChangeMode OKeyConfigWidget::changeMode()const { |
935 | return m_mode; | 209 | return m_mode; |
936 | } | 210 | } |
937 | 211 | ||
938 | 212 | ||
939 | /** | 213 | /** |
940 | * insert these items before calling load | 214 | * insert these items before calling load |
941 | */ | 215 | */ |
942 | void OKeyConfigWidget::insert( const QString& str, OKeyConfigManager* man ) { | 216 | void OKeyConfigWidget::insert( const QString& str, OKeyConfigManager* man ) { |
943 | Opie::Ui::Internal::OKeyConfigWidgetPrivate root( str, man ); | 217 | Opie::Ui::Internal::OKeyConfigWidgetPrivate root( str, man ); |
944 | m_list.append(root); | 218 | m_list.append(root); |
945 | } | 219 | } |
946 | 220 | ||
947 | 221 | ||
948 | /** | 222 | /** |
949 | * loads the items and allows editing them | 223 | * loads the items and allows editing them |
950 | */ | 224 | */ |
951 | void OKeyConfigWidget::load() { | 225 | void OKeyConfigWidget::load() { |
952 | Opie::Ui::Internal::OKeyConfigWidgetPrivateList::Iterator it; | 226 | Opie::Ui::Internal::OKeyConfigWidgetPrivateList::Iterator it; |
953 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { | 227 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { |
954 | OListViewItem *item = new OListViewItem( m_view, (*it).name ); | 228 | OListViewItem *item = new OListViewItem( m_view, (*it).name ); |
955 | OKeyConfigItem::List list = (*it).manager->keyConfigList(); | 229 | OKeyConfigItem::List list = (*it).manager->keyConfigList(); |
956 | for (OKeyConfigItem::List::Iterator keyIt = list.begin(); keyIt != list.end();++keyIt ) | 230 | for (OKeyConfigItem::List::Iterator keyIt = list.begin(); keyIt != list.end();++keyIt ) |
957 | (void )new Opie::Ui::Internal::OKeyListViewItem(*keyIt, (*it).manager, item ); | 231 | (void )new Opie::Ui::Internal::OKeyListViewItem(*keyIt, (*it).manager, item ); |
958 | 232 | ||
959 | } | 233 | } |
960 | } | 234 | } |
961 | 235 | ||
962 | /** | 236 | /** |
963 | * Saves if in Queue Mode. It'll update the supplied | 237 | * Saves if in Queue Mode. It'll update the supplied |
964 | * OKeyConfigManager objects. | 238 | * OKeyConfigManager objects. |
965 | * If in Queue mode it'll just return | 239 | * If in Queue mode it'll just return |
966 | */ | 240 | */ |
967 | void OKeyConfigWidget::save() { | 241 | void OKeyConfigWidget::save() { |
968 | /* | 242 | /* |
969 | * Iterate over all config items | 243 | * Iterate over all config items |
970 | */ | 244 | */ |
971 | QListViewItemIterator it( m_view ); | 245 | QListViewItemIterator it( m_view ); |
972 | while ( it.current() ) { | 246 | while ( it.current() ) { |
973 | if (it.current()->parent() ) { | 247 | if (it.current()->parent() ) { |
974 | Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>( it.current() ); | 248 | Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>( it.current() ); |
975 | OKeyConfigManager *man = item->manager(); | 249 | OKeyConfigManager *man = item->manager(); |
976 | man->removeKeyConfig( item->origItem() ); | 250 | man->removeKeyConfig( item->origItem() ); |
977 | man->addKeyConfig( item->item() ); | 251 | man->addKeyConfig( item->item() ); |
978 | } | 252 | } |
979 | ++it; | 253 | ++it; |
980 | } | 254 | } |
981 | 255 | ||
982 | 256 | ||
983 | } | 257 | } |
984 | 258 | ||
985 | 259 | ||
986 | /** | 260 | /** |
987 | * @internal | 261 | * @internal |
988 | */ | 262 | */ |
989 | void OKeyConfigWidget::slotListViewItem( QListViewItem* _item) { | 263 | void OKeyConfigWidget::slotListViewItem( QListViewItem* _item) { |
990 | if ( !_item || !_item->parent() ) { | 264 | if ( !_item || !_item->parent() ) { |
991 | m_box->setEnabled( false ); | 265 | m_box->setEnabled( false ); |
992 | m_none->setChecked( true ); | 266 | m_none->setChecked( true ); |
993 | m_btn ->setEnabled( false ); | 267 | m_btn ->setEnabled( false ); |
994 | m_def ->setChecked( false ); | 268 | m_def ->setChecked( false ); |
995 | m_cus ->setChecked( false ); | 269 | m_cus ->setChecked( false ); |
996 | }else{ | 270 | }else{ |
997 | m_box->setEnabled( true ); | 271 | m_box->setEnabled( true ); |
998 | Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>( _item ); | 272 | Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>( _item ); |
999 | OKeyConfigItem keyItem= item->item(); | 273 | OKeyConfigItem keyItem= item->item(); |
1000 | m_lbl->setText( tr("Default: " )+ item->text( 3 ) ); | 274 | m_lbl->setText( tr("Default: " )+ item->text( 3 ) ); |
1001 | if ( keyItem.keyPair().isEmpty() ) { | 275 | if ( keyItem.keyPair().isEmpty() ) { |
1002 | m_none->setChecked( true ); | 276 | m_none->setChecked( true ); |
1003 | m_btn ->setEnabled( false ); | 277 | m_btn ->setEnabled( false ); |
1004 | m_def ->setChecked( false ); | 278 | m_def ->setChecked( false ); |
1005 | m_cus ->setChecked( false ); | 279 | m_cus ->setChecked( false ); |
1006 | }else { | 280 | }else { |
1007 | m_none->setChecked( false ); | 281 | m_none->setChecked( false ); |
1008 | m_cus ->setChecked( true ); | 282 | m_cus ->setChecked( true ); |
1009 | m_btn ->setEnabled( true ); | 283 | m_btn ->setEnabled( true ); |
1010 | m_def ->setChecked( false ); | 284 | m_def ->setChecked( false ); |
1011 | } | 285 | } |
1012 | } | 286 | } |
1013 | } | 287 | } |
1014 | 288 | ||
1015 | void OKeyConfigWidget::slotNoKey() { | 289 | void OKeyConfigWidget::slotNoKey() { |
1016 | m_none->setChecked( true ); | 290 | m_none->setChecked( true ); |
1017 | m_cus ->setChecked( false ); | 291 | m_cus ->setChecked( false ); |
1018 | m_btn ->setEnabled( false ); | 292 | m_btn ->setEnabled( false ); |
1019 | m_def ->setChecked( false ); | 293 | m_def ->setChecked( false ); |
1020 | 294 | ||
1021 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) | 295 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) |
1022 | return; | 296 | return; |
1023 | 297 | ||
1024 | 298 | ||
1025 | 299 | ||
1026 | /* | 300 | /* |
1027 | * If immediate we need to remove and readd the key | 301 | * If immediate we need to remove and readd the key |
1028 | */ | 302 | */ |
1029 | Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>(m_view->currentItem()); | 303 | Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>(m_view->currentItem()); |
1030 | updateItem( item, OKeyPair::emptyKey() ); | 304 | updateItem( item, OKeyPair::emptyKey() ); |
1031 | } | 305 | } |
1032 | 306 | ||
1033 | void OKeyConfigWidget::slotDefaultKey() { | 307 | void OKeyConfigWidget::slotDefaultKey() { |
1034 | m_none->setChecked( false ); | 308 | m_none->setChecked( false ); |
1035 | m_cus ->setChecked( false ); | 309 | m_cus ->setChecked( false ); |
1036 | m_btn ->setEnabled( false ); | 310 | m_btn ->setEnabled( false ); |
1037 | m_def ->setChecked( true ); | 311 | m_def ->setChecked( true ); |
1038 | 312 | ||
1039 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) | 313 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) |
1040 | return; | 314 | return; |
1041 | 315 | ||
1042 | Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>(m_view->currentItem()); | 316 | Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>(m_view->currentItem()); |
1043 | updateItem( item, item->item().defaultKeyPair() ); | 317 | updateItem( item, item->item().defaultKeyPair() ); |
1044 | } | 318 | } |
1045 | 319 | ||
1046 | void OKeyConfigWidget::slotCustomKey() { | 320 | void OKeyConfigWidget::slotCustomKey() { |
1047 | m_cus ->setChecked( true ); | 321 | m_cus ->setChecked( true ); |
1048 | m_btn ->setEnabled( true ); | 322 | m_btn ->setEnabled( true ); |
1049 | m_def ->setChecked( false ); | 323 | m_def ->setChecked( false ); |
1050 | m_none->setChecked( false ); | 324 | m_none->setChecked( false ); |
1051 | 325 | ||
1052 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) | 326 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) |
1053 | return; | 327 | return; |
1054 | 328 | ||
1055 | 329 | ||
1056 | } | 330 | } |
1057 | 331 | ||
1058 | void OKeyConfigWidget::slotConfigure() { | 332 | void OKeyConfigWidget::slotConfigure() { |
1059 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) | 333 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) |
1060 | return; | 334 | return; |
1061 | 335 | ||
1062 | /* FIXME make use of OModalHelper */ | 336 | /* FIXME make use of OModalHelper */ |
1063 | OKeyChooserConfigDialog dlg( this, "Dialog Name", true ); | 337 | OKeyChooserConfigDialog dlg( this, "Dialog Name", true ); |
1064 | dlg.setCaption(tr("Configure Key")); | 338 | dlg.setCaption(tr("Configure Key")); |
1065 | connect(&dlg, SIGNAL(keyCaptured()), &dlg, SLOT(accept()) ); | 339 | connect(&dlg, SIGNAL(keyCaptured()), &dlg, SLOT(accept()) ); |
1066 | 340 | ||
1067 | if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ) { | 341 | if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ) { |
1068 | Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>(m_view->currentItem()); | 342 | Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>(m_view->currentItem()); |
1069 | updateItem( item, dlg.keyPair() ); | 343 | updateItem( item, dlg.keyPair() ); |
1070 | } | 344 | } |
1071 | 345 | ||
1072 | 346 | ||
1073 | } | 347 | } |
1074 | 348 | ||
1075 | bool OKeyConfigWidget::sanityCheck( Opie::Ui::Internal::OKeyListViewItem* item, | 349 | bool OKeyConfigWidget::sanityCheck( Opie::Ui::Internal::OKeyListViewItem* item, |
1076 | const OKeyPair& newItem ) { | 350 | const OKeyPair& newItem ) { |
1077 | OKeyPair::List bList = item->manager()->blackList(); | 351 | OKeyPair::List bList = item->manager()->blackList(); |
1078 | for ( OKeyPair::List::Iterator it = bList.begin(); it != bList.end(); ++it ) { | 352 | for ( OKeyPair::List::Iterator it = bList.begin(); it != bList.end(); ++it ) { |
1079 | /* black list matched */ | 353 | /* black list matched */ |
1080 | if ( *it == newItem ) { | 354 | if ( *it == newItem ) { |
1081 | QMessageBox::warning( 0, tr("Key is on BlackList" ), | 355 | QMessageBox::warning( 0, tr("Key is on BlackList" ), |
1082 | tr("<qt>The Key you choose is on the black list " | 356 | tr("<qt>The Key you choose is on the black list " |
1083 | "and may not be used with this manager. Please " | 357 | "and may not be used with this manager. Please " |
1084 | "use a different key.</qt>" ) ); | 358 | "use a different key.</qt>" ) ); |
1085 | return false; | 359 | return false; |
1086 | } | 360 | } |
1087 | } | 361 | } |
1088 | /* no we need to check the other items which is dog slow */ | 362 | /* no we need to check the other items which is dog slow */ |
1089 | QListViewItemIterator it( item->parent() ); | 363 | QListViewItemIterator it( item->parent() ); |
1090 | while ( it.current() ) { | 364 | while ( it.current() ) { |
1091 | /* if not our parent and not us */ | 365 | /* if not our parent and not us */ |
1092 | if (it.current()->parent() && it.current() != item) { | 366 | if (it.current()->parent() && it.current() != item) { |
1093 | /* damn already given away*/ | 367 | /* damn already given away*/ |
1094 | if ( newItem == static_cast<Opie::Ui::Internal::OKeyListViewItem*>(it.current() )->item().keyPair() ) { | 368 | if ( newItem == static_cast<Opie::Ui::Internal::OKeyListViewItem*>(it.current() )->item().keyPair() ) { |
1095 | QMessageBox::warning( 0, tr("Key is already assigned" ), | 369 | QMessageBox::warning( 0, tr("Key is already assigned" ), |
1096 | tr("<qt>The Key you choose is already taken by " | 370 | tr("<qt>The Key you choose is already taken by " |
1097 | "a different Item of your config. Please try" | 371 | "a different Item of your config. Please try" |
1098 | "using a different key.</qt>" ) ); | 372 | "using a different key.</qt>" ) ); |
1099 | return false; | 373 | return false; |
1100 | } | 374 | } |
1101 | } | 375 | } |
1102 | ++it; | 376 | ++it; |
1103 | } | 377 | } |
1104 | 378 | ||
1105 | return true; | 379 | return true; |
1106 | } | 380 | } |
1107 | 381 | ||
1108 | void OKeyConfigWidget::updateItem( Opie::Ui::Internal::OKeyListViewItem *item, | 382 | void OKeyConfigWidget::updateItem( Opie::Ui::Internal::OKeyListViewItem *item, |
1109 | const OKeyPair& newItem) { | 383 | const OKeyPair& newItem) { |
1110 | /* sanity check | 384 | /* sanity check |
1111 | * check against the blacklist of the manager | 385 | * check against the blacklist of the manager |
1112 | * check if another item uses this key which is o(n) at least | 386 | * check if another item uses this key which is o(n) at least |
1113 | */ | 387 | */ |
1114 | if ( !newItem.isEmpty() && !sanityCheck(item, newItem )) | 388 | if ( !newItem.isEmpty() && !sanityCheck(item, newItem )) |
1115 | return; | 389 | return; |
1116 | 390 | ||
1117 | 391 | ||
1118 | 392 | ||
1119 | /* | 393 | /* |
1120 | * If immediate we need to remove and readd the key | 394 | * If immediate we need to remove and readd the key |
1121 | */ | 395 | */ |
1122 | if ( m_mode == Imediate ) | 396 | if ( m_mode == Imediate ) |
1123 | item->manager()->removeKeyConfig( item->item() ); | 397 | item->manager()->removeKeyConfig( item->item() ); |
1124 | 398 | ||
1125 | item->item().setKeyPair( newItem ); | 399 | item->item().setKeyPair( newItem ); |
1126 | item->updateText(); | 400 | item->updateText(); |
1127 | 401 | ||
1128 | if ( m_mode == Imediate ) | 402 | if ( m_mode == Imediate ) |
1129 | item->manager()->addKeyConfig( item->item() ); | 403 | item->manager()->addKeyConfig( item->item() ); |
1130 | } | 404 | } |
1131 | 405 | ||
1132 | 406 | ||
1133 | 407 | ||
1134 | ///// | 408 | ///// |
1135 | OKeyChooserConfigDialog::OKeyChooserConfigDialog( QWidget* par, const char* nam, | 409 | OKeyChooserConfigDialog::OKeyChooserConfigDialog( QWidget* par, const char* nam, |
1136 | bool mod, WFlags fl ) | 410 | bool mod, WFlags fl ) |
1137 | : QDialog( par, nam, mod, fl ), m_virtKey( false ), m_keyPair( OKeyPair::emptyKey() ) , | 411 | : QDialog( par, nam, mod, fl ), m_virtKey( false ), m_keyPair( OKeyPair::emptyKey() ) , |
1138 | m_key( 0 ), m_mod( 0 ) { | 412 | m_key( 0 ), m_mod( 0 ) { |
1139 | setFocusPolicy( StrongFocus ); | 413 | setFocusPolicy( StrongFocus ); |
1140 | 414 | ||
1141 | QHBoxLayout *lay = new QHBoxLayout( this ); | 415 | QHBoxLayout *lay = new QHBoxLayout( this ); |
1142 | 416 | ||
1143 | QLabel *lbl = new QLabel( tr("Configure Key" ), this ); | 417 | QLabel *lbl = new QLabel( tr("Configure Key" ), this ); |
1144 | lay->addWidget( lbl ); | 418 | lay->addWidget( lbl ); |
1145 | lbl->setFocusPolicy( NoFocus ); | 419 | lbl->setFocusPolicy( NoFocus ); |
1146 | 420 | ||
1147 | m_lbl = new QLabel( this ); | 421 | m_lbl = new QLabel( this ); |
1148 | lay->addWidget( m_lbl ); | 422 | lay->addWidget( m_lbl ); |
1149 | m_lbl->setFocusPolicy( NoFocus ); | 423 | m_lbl->setFocusPolicy( NoFocus ); |
1150 | 424 | ||
1151 | m_timer = new QTimer( this ); | 425 | m_timer = new QTimer( this ); |
1152 | connect(m_timer, SIGNAL(timeout()), | 426 | connect(m_timer, SIGNAL(timeout()), |
1153 | this, SLOT(slotTimeUp()) ); | 427 | this, SLOT(slotTimeUp()) ); |
1154 | } | 428 | } |
1155 | 429 | ||
1156 | OKeyChooserConfigDialog::~OKeyChooserConfigDialog() { | 430 | OKeyChooserConfigDialog::~OKeyChooserConfigDialog() { |
1157 | } | 431 | } |
1158 | 432 | ||
1159 | Opie::Ui::OKeyPair OKeyChooserConfigDialog::keyPair()const{ | 433 | Opie::Core::OKeyPair OKeyChooserConfigDialog::keyPair()const{ |
1160 | return m_keyPair; | 434 | return m_keyPair; |
1161 | } | 435 | } |
1162 | 436 | ||
1163 | void OKeyChooserConfigDialog::keyPressEvent( QKeyEvent* ev ) { | 437 | void OKeyChooserConfigDialog::keyPressEvent( QKeyEvent* ev ) { |
1164 | QDialog::keyPressEvent( ev ); | 438 | QDialog::keyPressEvent( ev ); |
1165 | 439 | ||
1166 | if ( ev->isAutoRepeat() ) | 440 | if ( ev->isAutoRepeat() ) |
1167 | return; | 441 | return; |
1168 | 442 | ||
1169 | int mod, key; | 443 | int mod, key; |
1170 | Opie::Ui::Internal::fixupKeys( key,mod, ev ); | 444 | Opie::Core::Internal::fixupKeys( key,mod, ev ); |
1171 | 445 | ||
1172 | /* either we used software keyboard | 446 | /* either we used software keyboard |
1173 | * or we've true support | 447 | * or we've true support |
1174 | */ | 448 | */ |
1175 | if ( !m_virtKey && !ev->key()) { | 449 | if ( !m_virtKey && !ev->key()) { |
1176 | m_virtKey = true; | 450 | m_virtKey = true; |
1177 | m_keyPair = OKeyPair( key, mod ); | 451 | m_keyPair = OKeyPair( key, mod ); |
1178 | }else{ | 452 | }else{ |
1179 | mod = 0; | 453 | mod = 0; |
1180 | switch( key ) { | 454 | switch( key ) { |
1181 | case Qt::Key_Control: | 455 | case Qt::Key_Control: |
1182 | mod = Qt::ControlButton; | 456 | mod = Qt::ControlButton; |
1183 | break; | 457 | break; |
1184 | case Qt::Key_Shift: | 458 | case Qt::Key_Shift: |
1185 | mod = Qt::ShiftButton; | 459 | mod = Qt::ShiftButton; |
1186 | break; | 460 | break; |
1187 | case Qt::Key_Alt: | 461 | case Qt::Key_Alt: |
1188 | mod = Qt::AltButton; | 462 | mod = Qt::AltButton; |
1189 | break; | 463 | break; |
1190 | default: | 464 | default: |
1191 | break; | 465 | break; |
1192 | } | 466 | } |
1193 | if (mod ) { | 467 | if (mod ) { |
1194 | m_mod |= mod; | 468 | m_mod |= mod; |
1195 | key = 0; | 469 | key = 0; |
1196 | }else | 470 | }else |
1197 | m_key = key; | 471 | m_key = key; |
1198 | 472 | ||
1199 | if ( ( !mod || m_key || key ) && !m_timer->isActive() ) | 473 | if ( ( !mod || m_key || key ) && !m_timer->isActive() ) |
1200 | m_timer->start( 150, true ); | 474 | m_timer->start( 150, true ); |
1201 | 475 | ||
1202 | m_keyPair = OKeyPair( m_key, m_mod ); | 476 | m_keyPair = OKeyPair( m_key, m_mod ); |
1203 | } | 477 | } |
1204 | 478 | ||
1205 | m_lbl->setText( Opie::Ui::Internal::keyToString( m_keyPair ) ); | 479 | m_lbl->setText( Opie::Ui::Internal::keyToString( m_keyPair ) ); |
1206 | 480 | ||
1207 | } | 481 | } |
1208 | 482 | ||
1209 | void OKeyChooserConfigDialog::keyReleaseEvent( QKeyEvent* ev ) { | 483 | void OKeyChooserConfigDialog::keyReleaseEvent( QKeyEvent* ev ) { |
1210 | m_timer->stop(); | 484 | m_timer->stop(); |
1211 | QDialog::keyPressEvent( ev ); | 485 | QDialog::keyPressEvent( ev ); |
1212 | 486 | ||
1213 | if ( ev->isAutoRepeat() ) | 487 | if ( ev->isAutoRepeat() ) |
1214 | return; | 488 | return; |
1215 | 489 | ||
1216 | 490 | ||
1217 | if ( m_virtKey && !ev->key()) { | 491 | if ( m_virtKey && !ev->key()) { |
1218 | m_virtKey = false; | 492 | m_virtKey = false; |
1219 | slotTimeUp(); | 493 | slotTimeUp(); |
1220 | }else { | 494 | }else { |
1221 | int mod = 0; | 495 | int mod = 0; |
1222 | int key = ev->key(); | 496 | int key = ev->key(); |
1223 | switch( key ) { | 497 | switch( key ) { |
1224 | case Qt::Key_Control: | 498 | case Qt::Key_Control: |
1225 | mod = Qt::ControlButton; | 499 | mod = Qt::ControlButton; |
1226 | break; | 500 | break; |
1227 | case Qt::Key_Shift: | 501 | case Qt::Key_Shift: |
1228 | mod = Qt::ShiftButton; | 502 | mod = Qt::ShiftButton; |
1229 | break; | 503 | break; |
1230 | case Qt::Key_Alt: | 504 | case Qt::Key_Alt: |
1231 | mod = Qt::AltButton; | 505 | mod = Qt::AltButton; |
1232 | break; | 506 | break; |
1233 | default: | 507 | default: |
1234 | break; | 508 | break; |
1235 | } | 509 | } |
1236 | if (mod ) | 510 | if (mod ) |
1237 | m_mod &= ~mod; | 511 | m_mod &= ~mod; |
1238 | else | 512 | else |
1239 | m_key = key; | 513 | m_key = key; |
1240 | m_keyPair = OKeyPair( m_key, m_mod ); | 514 | m_keyPair = OKeyPair( m_key, m_mod ); |
1241 | m_lbl->setText( Opie::Ui::Internal::keyToString( m_keyPair ) ); | 515 | m_lbl->setText( Opie::Ui::Internal::keyToString( m_keyPair ) ); |
1242 | } | 516 | } |
1243 | } | 517 | } |
1244 | 518 | ||
1245 | 519 | ||
1246 | void OKeyChooserConfigDialog::slotTimeUp() { | 520 | void OKeyChooserConfigDialog::slotTimeUp() { |
1247 | m_mod = m_key = 0; | 521 | m_mod = m_key = 0; |
1248 | QTimer::singleShot(0, this, SIGNAL(keyCaptured()) ); | 522 | QTimer::singleShot(0, this, SIGNAL(keyCaptured()) ); |
1249 | } | 523 | } |
524 | |||
525 | |||
526 | } | ||
527 | } | ||
diff --git a/libopie2/opieui/okeyconfigwidget.h b/libopie2/opieui/okeyconfigwidget.h index bb8eb6c..d11054c 100644 --- a/libopie2/opieui/okeyconfigwidget.h +++ b/libopie2/opieui/okeyconfigwidget.h | |||
@@ -1,322 +1,137 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2004 | 2 | * Copyright (C) 2004 |
3 | * LGPL v2 zecke@handhelds.org | 3 | * LGPL v2 zecke@handhelds.org |
4 | */ | 4 | */ |
5 | 5 | ||
6 | 6 | ||
7 | #ifndef ODP_KEY_CONFIG_WIDGET_H | 7 | #ifndef ODP_KEY_CONFIG_WIDGET_H |
8 | #define ODP_KEY_CONFIG_WIDGET_H | 8 | #define ODP_KEY_CONFIG_WIDGET_H |
9 | 9 | ||
10 | #include <opie2/oconfig.h> | 10 | #include <opie2/okeyconfigmanager.h> |
11 | #include <opie2/odevice.h> | ||
12 | 11 | ||
13 | #include <qstring.h> | ||
14 | #include <qpixmap.h> | ||
15 | #include <qcstring.h> | ||
16 | #include <qhbox.h> | 12 | #include <qhbox.h> |
17 | #include <qvaluelist.h> | 13 | |
18 | 14 | ||
19 | class QKeyEvent; | 15 | class QKeyEvent; |
20 | class QLabel; | 16 | class QLabel; |
21 | class QPushButton; | 17 | class QPushButton; |
22 | class QListViewItem; | 18 | class QListViewItem; |
23 | class QRadioButton; | 19 | class QRadioButton; |
24 | class QTimer; | 20 | class QTimer; |
25 | 21 | ||
26 | namespace Opie { | 22 | namespace Opie { |
27 | namespace Ui { | 23 | namespace Ui { |
28 | namespace Internal { | 24 | namespace Internal { |
29 | class OKeyConfigWidgetPrivate; | 25 | class OKeyConfigWidgetPrivate; |
30 | typedef QValueList<OKeyConfigWidgetPrivate> OKeyConfigWidgetPrivateList; | 26 | typedef QValueList<OKeyConfigWidgetPrivate> OKeyConfigWidgetPrivateList; |
31 | class OKeyListViewItem; | 27 | class OKeyListViewItem; |
32 | } | 28 | } |
33 | class OListViewItem; | 29 | class OListViewItem; |
34 | class OListView; | 30 | class OListView; |
35 | 31 | ||
36 | /** | ||
37 | * \brief small class representing a Key with possible modifiers | ||
38 | * This class holds information about key code and possible | ||
39 | * modifier state. That is the lowest level of the key input | ||
40 | * functions. | ||
41 | * There are also static methods to get special keys. | ||
42 | * OKeyPair will be used with \see OKeyConfigItem | ||
43 | * | ||
44 | * @since 1.2 | ||
45 | */ | ||
46 | class OKeyPair { | ||
47 | public: | ||
48 | typedef QValueList<OKeyPair> List; | ||
49 | OKeyPair( int key = -1, int modifier = -1); | ||
50 | ~OKeyPair(); | ||
51 | |||
52 | bool operator==( const OKeyPair& )const; | ||
53 | bool operator!=( const OKeyPair& )const; | ||
54 | |||
55 | bool isEmpty()const; | ||
56 | |||
57 | int keycode()const; | ||
58 | int modifier()const; | ||
59 | |||
60 | void setKeycode( int ); | ||
61 | void setModifier( int ); | ||
62 | |||
63 | static OKeyPair returnKey(); | ||
64 | static OKeyPair leftArrowKey(); | ||
65 | static OKeyPair rightArrowKey(); | ||
66 | static OKeyPair upArrowKey(); | ||
67 | static OKeyPair downArrowKey(); | ||
68 | static OKeyPair emptyKey(); | ||
69 | static OKeyPair::List hardwareKeys(); | ||
70 | |||
71 | private: | ||
72 | int m_key; | ||
73 | int m_mod; | ||
74 | class Private; | ||
75 | Private* d; | ||
76 | }; | ||
77 | |||
78 | /** | ||
79 | * A class to represent an OKeyPair. | ||
80 | * It consists out of a Text exposed to the user, Config Key Item, | ||
81 | * Pixmap, A default OKeyPair and the set OKeyPair. | ||
82 | * You can also pass an id to it | ||
83 | * | ||
84 | * @since 1.1.2 | ||
85 | */ | ||
86 | class OKeyConfigItem { | ||
87 | friend class OKeyConfigManager; | ||
88 | public: | ||
89 | typedef QValueList<OKeyConfigItem> List; | ||
90 | OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(), | ||
91 | const QPixmap& symbol = QPixmap(), | ||
92 | int id = -1, | ||
93 | const OKeyPair& def = OKeyPair::emptyKey(), | ||
94 | QObject *caller = 0, const char* slot = 0); | ||
95 | OKeyConfigItem( const Opie::Core::ODeviceButton& ); | ||
96 | ~OKeyConfigItem(); | ||
97 | |||
98 | bool operator==( const OKeyConfigItem& )const; | ||
99 | bool operator!=( const OKeyConfigItem& )const; | ||
100 | |||
101 | QString text()const; | ||
102 | QPixmap pixmap()const; | ||
103 | int id()const; | ||
104 | |||
105 | |||
106 | |||
107 | OKeyPair keyPair()const; | ||
108 | OKeyPair defaultKeyPair()const; | ||
109 | QCString configKey()const; | ||
110 | |||
111 | |||
112 | void setText( const QString& text ); | ||
113 | void setPixmap( const QPixmap& ); | ||
114 | void setKeyPair( const OKeyPair& ); | ||
115 | void setDefaultKeyPair( const OKeyPair& ); | ||
116 | |||
117 | bool isEmpty()const; | ||
118 | |||
119 | protected: | ||
120 | QObject *object()const; | ||
121 | QCString slot()const; | ||
122 | void setId( int id ); | ||
123 | void setConfigKey( const QCString& ); | ||
124 | |||
125 | private: | ||
126 | QString m_text; | ||
127 | QCString m_config; | ||
128 | QPixmap m_pix; | ||
129 | int m_id; | ||
130 | OKeyPair m_key; | ||
131 | OKeyPair m_def; | ||
132 | QObject *m_obj; | ||
133 | QCString m_str; | ||
134 | class Private; | ||
135 | Private *d; | ||
136 | }; | ||
137 | |||
138 | |||
139 | |||
140 | /** | ||
141 | * \brief A manager to load and save Key Actions and get notified | ||
142 | * This is the Manager for KeyActions. | ||
143 | * You can say from which config and group to read data, to grab the | ||
144 | * keyboard to handle hardware keys, you can supply a blacklist of | ||
145 | * keys which should not be used by allowed to be used. | ||
146 | * You can even pass this manager to a Widget to do the configuration for you. | ||
147 | * You need to add OKeyConfigItem for your keys and then issue a load() to | ||
148 | * read the Key information. | ||
149 | * You can either handle the QKeyEvent yourself and ask this class if it is | ||
150 | * handled by your action and let give you the action. Or you can install | ||
151 | * the event filter and get a signal. | ||
152 | * You need to load ans save yourself! | ||
153 | * | ||
154 | * @since 1.1.2 | ||
155 | */ | ||
156 | class OKeyConfigManager : public QObject { | ||
157 | Q_OBJECT | ||
158 | typedef QMap<int, OKeyConfigItem::List> OKeyMapConfigPrivate; | ||
159 | public: | ||
160 | OKeyConfigManager(Opie::Core::OConfig *conf = 0, | ||
161 | const QString& group = QString::null, | ||
162 | const OKeyPair::List &block = OKeyPair::List(), | ||
163 | bool grabkeyboard = false, QObject * par = 0, | ||
164 | const char* name = 0 ); | ||
165 | ~OKeyConfigManager(); | ||
166 | |||
167 | void load(); | ||
168 | void save(); | ||
169 | |||
170 | OKeyConfigItem handleKeyEvent( QKeyEvent* ); | ||
171 | int handleKeyEventId( QKeyEvent* ); | ||
172 | |||
173 | void addKeyConfig( const OKeyConfigItem& ); | ||
174 | void removeKeyConfig( const OKeyConfigItem& ); | ||
175 | void clearKeyConfig(); | ||
176 | |||
177 | void addToBlackList( const OKeyPair& ); | ||
178 | void removeFromBlackList( const OKeyPair& ); | ||
179 | void clearBlackList(); | ||
180 | OKeyPair::List blackList()const; | ||
181 | |||
182 | void handleWidget( QWidget* ); | ||
183 | |||
184 | bool eventFilter( QObject*, QEvent* ); | ||
185 | |||
186 | OKeyConfigItem::List keyConfigList()const; | ||
187 | signals: | ||
188 | /** | ||
189 | * The Signals are triggered on KeyPress and KeyRelease! | ||
190 | * You can check the isDown of the QKeyEvent | ||
191 | * @see QKeyEvent | ||
192 | */ | ||
193 | void actionActivated( QWidget*, QKeyEvent*, const Opie::Ui::OKeyConfigItem& ); | ||
194 | |||
195 | /** | ||
196 | * This Signal correspondents to the OKeyConfigItem slot | ||
197 | * and object | ||
198 | * | ||
199 | * @see OKeyConfigItem::slot | ||
200 | * @see OKeyConfigItem::object | ||
201 | */ | ||
202 | void actionActivated( QWidget* par, QKeyEvent* key); | ||
203 | |||
204 | private: | ||
205 | OKeyConfigItem::List keyList( int ); | ||
206 | OKeyConfigItem::List m_keys; | ||
207 | QValueList<QWidget*> m_widgets; | ||
208 | Opie::Core::OConfig *m_conf; | ||
209 | QString m_group; | ||
210 | OKeyPair::List m_blackKeys; | ||
211 | bool m_grab : 1; | ||
212 | OKeyMapConfigPrivate *m_map; | ||
213 | class Private; | ||
214 | Private *d; | ||
215 | }; | ||
216 | |||
217 | 32 | ||
218 | /** | 33 | /** |
219 | * With this Widget you can let the Keyboard Shortcuts | 34 | * With this Widget you can let the Keyboard Shortcuts |
220 | * be configured by the user. | 35 | * be configured by the user. |
221 | * There are two ways you can use this widget. Either in a tab were | 36 | * There are two ways you can use this widget. Either in a tab were |
222 | * all changes are immediately getting into effect or in a queue | 37 | * all changes are immediately getting into effect or in a queue |
223 | * were you ask for saving. Save won't write the data but only set | 38 | * were you ask for saving. Save won't write the data but only set |
224 | * it to the OKeyConfigManager | 39 | * it to the OKeyConfigManager |
225 | * | 40 | * |
226 | * @since 1.2 | 41 | * @since 1.2 |
227 | */ | 42 | */ |
228 | class OKeyConfigWidget : public QWidget { | 43 | class OKeyConfigWidget : public QWidget { |
229 | Q_OBJECT | 44 | Q_OBJECT |
230 | 45 | ||
231 | public: | 46 | public: |
232 | /** | 47 | /** |
233 | * Immediate Apply the change directly to the underlying OKeyConfigManager | 48 | * Immediate Apply the change directly to the underlying OKeyConfigManager |
234 | * Queue Save all items and then apply when you save() | 49 | * Queue Save all items and then apply when you save() |
235 | */ | 50 | */ |
236 | enum ChangeMode { Imediate, Queue }; | 51 | enum ChangeMode { Imediate, Queue }; |
237 | OKeyConfigWidget( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | 52 | OKeyConfigWidget( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); |
238 | ~OKeyConfigWidget(); | 53 | ~OKeyConfigWidget(); |
239 | 54 | ||
240 | void setChangeMode( enum ChangeMode ); | 55 | void setChangeMode( enum ChangeMode ); |
241 | ChangeMode changeMode()const; | 56 | ChangeMode changeMode()const; |
242 | 57 | ||
243 | void insert( const QString& name, OKeyConfigManager* ); | 58 | void insert( const QString& name, Opie::Core::OKeyConfigManager* ); |
244 | 59 | ||
245 | void load(); | 60 | void load(); |
246 | void save(); | 61 | void save(); |
247 | 62 | ||
248 | private slots: | 63 | private slots: |
249 | void slotListViewItem( QListViewItem* ); | 64 | void slotListViewItem( QListViewItem* ); |
250 | void slotNoKey(); | 65 | void slotNoKey(); |
251 | void slotDefaultKey(); | 66 | void slotDefaultKey(); |
252 | void slotCustomKey(); | 67 | void slotCustomKey(); |
253 | void slotConfigure(); | 68 | void slotConfigure(); |
254 | 69 | ||
255 | private: | 70 | private: |
256 | static bool sanityCheck( Opie::Ui::Internal::OKeyListViewItem* man, | 71 | static bool sanityCheck( Opie::Ui::Internal::OKeyListViewItem* man, |
257 | const OKeyPair& newItem ); | 72 | const Opie::Core::OKeyPair& newItem ); |
258 | void updateItem( Opie::Ui::Internal::OKeyListViewItem* man, | 73 | void updateItem( Opie::Ui::Internal::OKeyListViewItem* man, |
259 | const OKeyPair& newItem); | 74 | const Opie::Core::OKeyPair& newItem); |
260 | void initUi(); | 75 | void initUi(); |
261 | Opie::Ui::OListView *m_view; | 76 | Opie::Ui::OListView *m_view; |
262 | Opie::Ui::Internal::OKeyConfigWidgetPrivateList m_list; | 77 | Opie::Ui::Internal::OKeyConfigWidgetPrivateList m_list; |
263 | QLabel *m_lbl; | 78 | QLabel *m_lbl; |
264 | QPushButton *m_btn; | 79 | QPushButton *m_btn; |
265 | QRadioButton *m_def, *m_cus, *m_none; | 80 | QRadioButton *m_def, *m_cus, *m_none; |
266 | QWidget* m_box; | 81 | QWidget* m_box; |
267 | ChangeMode m_mode; | 82 | ChangeMode m_mode; |
268 | class Private; | 83 | class Private; |
269 | Private *d; | 84 | Private *d; |
270 | }; | 85 | }; |
271 | 86 | ||
272 | 87 | ||
273 | /** | 88 | /** |
274 | * This is a small dialog that allows you to | 89 | * This is a small dialog that allows you to |
275 | * capture a key sequence. | 90 | * capture a key sequence. |
276 | * If you want it to close after a key was captured you | 91 | * If you want it to close after a key was captured you |
277 | * can use this code snippet. | 92 | * can use this code snippet. |
278 | * | 93 | * |
279 | * \code | 94 | * \code |
280 | * OKeyChooserConfigDialog diag(0,0,true); | 95 | * OKeyChooserConfigDialog diag(0,0,true); |
281 | * connect(&diag,SIGNAL(keyCaptured()), | 96 | * connect(&diag,SIGNAL(keyCaptured()), |
282 | * this,SLOT(accept())); | 97 | * this,SLOT(accept())); |
283 | * if( QPEApplication::execDialog(&diag) == QDialog::Accept ){ | 98 | * if( QPEApplication::execDialog(&diag) == QDialog::Accept ){ |
284 | * take_the_key_and_do_something | 99 | * take_the_key_and_do_something |
285 | * } | 100 | * } |
286 | * | 101 | * |
287 | * \endcode | 102 | * \endcode |
288 | * | 103 | * |
289 | */ | 104 | */ |
290 | class OKeyChooserConfigDialog : public QDialog { | 105 | class OKeyChooserConfigDialog : public QDialog { |
291 | Q_OBJECT | 106 | Q_OBJECT |
292 | public: | 107 | public: |
293 | OKeyChooserConfigDialog( QWidget* parent = 0, const char* name = 0, bool modal = false, WFlags fl = 0 ); | 108 | OKeyChooserConfigDialog( QWidget* parent = 0, const char* name = 0, bool modal = false, WFlags fl = 0 ); |
294 | ~OKeyChooserConfigDialog(); | 109 | ~OKeyChooserConfigDialog(); |
295 | 110 | ||
296 | OKeyPair keyPair()const; | 111 | Opie::Core::OKeyPair keyPair()const; |
297 | 112 | ||
298 | protected: | 113 | protected: |
299 | void keyPressEvent( QKeyEvent* ); | 114 | void keyPressEvent( QKeyEvent* ); |
300 | void keyReleaseEvent( QKeyEvent* ); | 115 | void keyReleaseEvent( QKeyEvent* ); |
301 | 116 | ||
302 | signals: | 117 | signals: |
303 | void keyCaptured(); | 118 | void keyCaptured(); |
304 | 119 | ||
305 | private slots: | 120 | private slots: |
306 | void slotTimeUp(); | 121 | void slotTimeUp(); |
307 | 122 | ||
308 | private: | 123 | private: |
309 | QTimer *m_timer; | 124 | QTimer *m_timer; |
310 | QLabel *m_lbl; | 125 | QLabel *m_lbl; |
311 | bool m_virtKey : 1; | 126 | bool m_virtKey : 1; |
312 | OKeyPair m_keyPair; | 127 | Opie::Core::OKeyPair m_keyPair; |
313 | int m_key, m_mod; | 128 | int m_key, m_mod; |
314 | class Private; | 129 | class Private; |
315 | Private *d; | 130 | Private *d; |
316 | }; | 131 | }; |
317 | 132 | ||
318 | } | 133 | } |
319 | } | 134 | } |
320 | 135 | ||
321 | 136 | ||
322 | #endif | 137 | #endif |
diff --git a/libopie2/opieui/okeyconfigwidget_p.h b/libopie2/opieui/okeyconfigwidget_p.h index 7690846..4dece4d 100644 --- a/libopie2/opieui/okeyconfigwidget_p.h +++ b/libopie2/opieui/okeyconfigwidget_p.h | |||
@@ -1,33 +1,35 @@ | |||
1 | /* | 1 | /* |
2 | * Only Internal implemented in the same .cpp file anyway | 2 | * Only Internal implemented in the same .cpp file anyway |
3 | */ | 3 | */ |
4 | #include <opie2/olistview.h> | 4 | #include <opie2/olistview.h> |
5 | 5 | ||
6 | #include <opie2/okeyconfigmanager_p.h> | ||
6 | 7 | ||
7 | namespace Opie { | 8 | namespace Opie { |
8 | namespace Ui { | 9 | namespace Ui { |
9 | namespace Internal { | 10 | namespace Internal { |
10 | static QString keyToString( const OKeyPair& ); | 11 | static QString keyToString( const Opie::Core::OKeyPair& ); |
11 | static void fixupKeys( int&, int&, QKeyEvent* ); | ||
12 | class OKeyListViewItem : public Opie::Ui::OListViewItem { | 12 | class OKeyListViewItem : public Opie::Ui::OListViewItem { |
13 | public: | 13 | public: |
14 | OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager*, Opie::Ui::OListViewItem* parent); | 14 | OKeyListViewItem( const Opie::Core::OKeyConfigItem& item, |
15 | Opie::Core::OKeyConfigManager*, | ||
16 | Opie::Ui::OListViewItem* parent); | ||
15 | ~OKeyListViewItem(); | 17 | ~OKeyListViewItem(); |
16 | 18 | ||
17 | void setDefault(); | 19 | void setDefault(); |
18 | 20 | ||
19 | OKeyConfigItem& item(); | 21 | Opie::Core::OKeyConfigItem& item(); |
20 | OKeyConfigItem origItem()const; | 22 | Opie::Core::OKeyConfigItem origItem()const; |
21 | void setItem( const OKeyConfigItem& item ); | 23 | void setItem( const Opie::Core::OKeyConfigItem& item ); |
22 | void updateText(); | 24 | void updateText(); |
23 | 25 | ||
24 | OKeyConfigManager *manager(); | 26 | Opie::Core::OKeyConfigManager *manager(); |
25 | private: | 27 | private: |
26 | OKeyConfigItem m_item; | 28 | Opie::Core::OKeyConfigItem m_item; |
27 | OKeyConfigItem m_origItem; | 29 | Opie::Core::OKeyConfigItem m_origItem; |
28 | OKeyConfigManager* m_manager; | 30 | Opie::Core::OKeyConfigManager* m_manager; |
29 | 31 | ||
30 | }; | 32 | }; |
31 | } | 33 | } |
32 | } | 34 | } |
33 | } | 35 | } |
diff --git a/noncore/graphics/opie-eye/gui/iconview.cpp b/noncore/graphics/opie-eye/gui/iconview.cpp index 7e4164b..2a49786 100644 --- a/noncore/graphics/opie-eye/gui/iconview.cpp +++ b/noncore/graphics/opie-eye/gui/iconview.cpp | |||
@@ -1,448 +1,448 @@ | |||
1 | /* | 1 | /* |
2 | * GPLv2 zecke@handhelds.org | 2 | * GPLv2 zecke@handhelds.org |
3 | * No WArranty... | 3 | * No WArranty... |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include "iconview.h" | 6 | #include "iconview.h" |
7 | 7 | ||
8 | #include <lib/imagecache.h> | 8 | #include <lib/imagecache.h> |
9 | #include <gui/imageinfoui.h> | 9 | #include <gui/imageinfoui.h> |
10 | #include <gui/imagescrollview.h> | 10 | #include <gui/imagescrollview.h> |
11 | 11 | ||
12 | #include <iface/dirview.h> | 12 | #include <iface/dirview.h> |
13 | #include <iface/dirlister.h> | 13 | #include <iface/dirlister.h> |
14 | 14 | ||
15 | #include <opie2/oconfig.h> | 15 | #include <opie2/oconfig.h> |
16 | #include <opie2/okeyconfigwidget.h> | 16 | #include <opie2/okeyconfigwidget.h> |
17 | #include <opie2/odebug.h> | 17 | #include <opie2/odebug.h> |
18 | 18 | ||
19 | #include <qpe/resource.h> | 19 | #include <qpe/resource.h> |
20 | #include <qpe/qpemessagebox.h> | 20 | #include <qpe/qpemessagebox.h> |
21 | #include <qpe/ir.h> | 21 | #include <qpe/ir.h> |
22 | #include <qpe/qcopenvelope_qws.h> | 22 | #include <qpe/qcopenvelope_qws.h> |
23 | #include <qpe/qpeapplication.h> | 23 | #include <qpe/qpeapplication.h> |
24 | 24 | ||
25 | #include <qiconview.h> | 25 | #include <qiconview.h> |
26 | #include <qlabel.h> | 26 | #include <qlabel.h> |
27 | #include <qhbox.h> | 27 | #include <qhbox.h> |
28 | #include <qcombobox.h> | 28 | #include <qcombobox.h> |
29 | #include <qdir.h> | 29 | #include <qdir.h> |
30 | #include <qapplication.h> | 30 | #include <qapplication.h> |
31 | #include <qmainwindow.h> | 31 | #include <qmainwindow.h> |
32 | #include <qtimer.h> | 32 | #include <qtimer.h> |
33 | #include <qstyle.h> | 33 | #include <qstyle.h> |
34 | 34 | ||
35 | 35 | ||
36 | using Opie::Ui::OKeyConfigItem; | 36 | using Opie::Core::OKeyConfigItem; |
37 | 37 | ||
38 | /* | 38 | /* |
39 | * The Icons, Request Cache and IconViewItem for the IconView | 39 | * The Icons, Request Cache and IconViewItem for the IconView |
40 | */ | 40 | */ |
41 | namespace { | 41 | namespace { |
42 | static QPixmap* _dirPix = 0; | 42 | static QPixmap* _dirPix = 0; |
43 | static QPixmap* _unkPix = 0; | 43 | static QPixmap* _unkPix = 0; |
44 | class IconViewItem : public QIconViewItem { | 44 | class IconViewItem : public QIconViewItem { |
45 | public: | 45 | public: |
46 | IconViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false); | 46 | IconViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false); |
47 | QPixmap* pixmap()const; | 47 | QPixmap* pixmap()const; |
48 | QString path()const { return m_path; } | 48 | QString path()const { return m_path; } |
49 | bool isDir()const { return m_isDir; } | 49 | bool isDir()const { return m_isDir; } |
50 | void setText( const QString& ); | 50 | void setText( const QString& ); |
51 | 51 | ||
52 | 52 | ||
53 | private: | 53 | private: |
54 | mutable QPixmap* m_pix; | 54 | mutable QPixmap* m_pix; |
55 | QString m_path; | 55 | QString m_path; |
56 | bool m_isDir : 1; | 56 | bool m_isDir : 1; |
57 | bool m_noInfo :1; | 57 | bool m_noInfo :1; |
58 | }; | 58 | }; |
59 | 59 | ||
60 | 60 | ||
61 | /* | 61 | /* |
62 | * If we request an Image or String | 62 | * If we request an Image or String |
63 | * we add it to the map | 63 | * we add it to the map |
64 | */ | 64 | */ |
65 | static QMap<QString, IconViewItem*> g_stringInf; | 65 | static QMap<QString, IconViewItem*> g_stringInf; |
66 | static QMap<QString, IconViewItem*> g_stringPix; | 66 | static QMap<QString, IconViewItem*> g_stringPix; |
67 | 67 | ||
68 | IconViewItem::IconViewItem( QIconView* view,const QString& path, | 68 | IconViewItem::IconViewItem( QIconView* view,const QString& path, |
69 | const QString& name, bool isDir ) | 69 | const QString& name, bool isDir ) |
70 | : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ), | 70 | : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ), |
71 | m_noInfo( false ) | 71 | m_noInfo( false ) |
72 | { | 72 | { |
73 | if ( isDir && !_dirPix ) | 73 | if ( isDir && !_dirPix ) |
74 | _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser")); | 74 | _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser")); |
75 | else if ( !isDir && !_unkPix ) | 75 | else if ( !isDir && !_unkPix ) |
76 | _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) ); | 76 | _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) ); |
77 | } | 77 | } |
78 | inline QPixmap* IconViewItem::pixmap()const { | 78 | inline QPixmap* IconViewItem::pixmap()const { |
79 | // qWarning( "Name is " + m_path.right( 15 ) + " rect is %d %d %d %d | %d %d", | 79 | // qWarning( "Name is " + m_path.right( 15 ) + " rect is %d %d %d %d | %d %d", |
80 | // rect().x(),rect().y(),rect().width(),rect().height(), | 80 | // rect().x(),rect().y(),rect().width(),rect().height(), |
81 | // iconView()->contentsX(), iconView()->contentsY()); | 81 | // iconView()->contentsX(), iconView()->contentsY()); |
82 | 82 | ||
83 | if ( m_isDir ) | 83 | if ( m_isDir ) |
84 | return _dirPix; | 84 | return _dirPix; |
85 | else{ | 85 | else{ |
86 | if (!m_noInfo && !g_stringInf.contains( m_path ) ) { | 86 | if (!m_noInfo && !g_stringInf.contains( m_path ) ) { |
87 | currentView()->dirLister()->imageInfo( m_path ); | 87 | currentView()->dirLister()->imageInfo( m_path ); |
88 | g_stringInf.insert( m_path, const_cast<IconViewItem*>(this)); | 88 | g_stringInf.insert( m_path, const_cast<IconViewItem*>(this)); |
89 | } | 89 | } |
90 | 90 | ||
91 | m_pix = PPixmapCache::self()->cachedImage( m_path, 64, 64 ); | 91 | m_pix = PPixmapCache::self()->cachedImage( m_path, 64, 64 ); |
92 | if ( !m_pix && !g_stringPix.contains( m_path )) { | 92 | if ( !m_pix && !g_stringPix.contains( m_path )) { |
93 | currentView()->dirLister()->thumbNail( m_path, 64, 64 ); | 93 | currentView()->dirLister()->thumbNail( m_path, 64, 64 ); |
94 | g_stringPix.insert( m_path, const_cast<IconViewItem*>(this)); | 94 | g_stringPix.insert( m_path, const_cast<IconViewItem*>(this)); |
95 | } | 95 | } |
96 | return m_pix ? m_pix : _unkPix; | 96 | return m_pix ? m_pix : _unkPix; |
97 | } | 97 | } |
98 | } | 98 | } |
99 | inline void IconViewItem::setText( const QString& str ) { | 99 | inline void IconViewItem::setText( const QString& str ) { |
100 | QString text = QIconViewItem::text()+"\n"+str; | 100 | QString text = QIconViewItem::text()+"\n"+str; |
101 | m_noInfo = true; | 101 | m_noInfo = true; |
102 | QIconViewItem::setText( text ); | 102 | QIconViewItem::setText( text ); |
103 | } | 103 | } |
104 | } | 104 | } |
105 | 105 | ||
106 | 106 | ||
107 | /* | 107 | /* |
108 | * Set up the GUI.. initialize the slave set up gui | 108 | * Set up the GUI.. initialize the slave set up gui |
109 | * and also load a dir | 109 | * and also load a dir |
110 | */ | 110 | */ |
111 | PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg ) | 111 | PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg ) |
112 | : QVBox( wid ), m_cfg( cfg ), m_updatet( false ) | 112 | : QVBox( wid ), m_cfg( cfg ), m_updatet( false ) |
113 | { | 113 | { |
114 | { | 114 | { |
115 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" ); | 115 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" ); |
116 | } | 116 | } |
117 | m_path = QDir::homeDirPath(); | 117 | m_path = QDir::homeDirPath(); |
118 | 118 | ||
119 | QHBox *hbox = new QHBox( this ); | 119 | QHBox *hbox = new QHBox( this ); |
120 | QLabel* lbl = new QLabel( hbox ); | 120 | QLabel* lbl = new QLabel( hbox ); |
121 | lbl->setText( tr("View as" ) ); | 121 | lbl->setText( tr("View as" ) ); |
122 | 122 | ||
123 | m_views = new QComboBox( hbox, "View As" ); | 123 | m_views = new QComboBox( hbox, "View As" ); |
124 | connect( m_views, SIGNAL(activated(int)), | 124 | connect( m_views, SIGNAL(activated(int)), |
125 | this, SLOT(slotViewChanged(int)) ); | 125 | this, SLOT(slotViewChanged(int)) ); |
126 | 126 | ||
127 | m_view= new QIconView( this ); | 127 | m_view= new QIconView( this ); |
128 | connect(m_view, SIGNAL(clicked(QIconViewItem*) ), | 128 | connect(m_view, SIGNAL(clicked(QIconViewItem*) ), |
129 | this, SLOT(slotClicked(QIconViewItem*)) ); | 129 | this, SLOT(slotClicked(QIconViewItem*)) ); |
130 | connect(m_view, SIGNAL(returnPressed(QIconViewItem*)), | 130 | connect(m_view, SIGNAL(returnPressed(QIconViewItem*)), |
131 | this, SLOT(slotClicked(QIconViewItem*)) ); | 131 | this, SLOT(slotClicked(QIconViewItem*)) ); |
132 | 132 | ||
133 | m_view->setArrangement( QIconView::LeftToRight ); | 133 | m_view->setArrangement( QIconView::LeftToRight ); |
134 | m_view->setItemTextPos( QIconView::Right ); | 134 | m_view->setItemTextPos( QIconView::Right ); |
135 | 135 | ||
136 | int dw = QApplication::desktop()->width(); | 136 | int dw = QApplication::desktop()->width(); |
137 | int viewerWidth = dw-style().scrollBarExtent().width(); | 137 | int viewerWidth = dw-style().scrollBarExtent().width(); |
138 | m_view->setGridX( viewerWidth-3*m_view->spacing()); | 138 | m_view->setGridX( viewerWidth-3*m_view->spacing()); |
139 | m_view->setGridY( fontMetrics().height()*2+40 ); | 139 | m_view->setGridY( fontMetrics().height()*2+40 ); |
140 | 140 | ||
141 | 141 | ||
142 | initKeys(); | 142 | initKeys(); |
143 | 143 | ||
144 | loadViews(); | 144 | loadViews(); |
145 | slotViewChanged( m_views->currentItem() ); | 145 | slotViewChanged( m_views->currentItem() ); |
146 | } | 146 | } |
147 | 147 | ||
148 | /* | 148 | /* |
149 | * Unref the slave and save the keyboard manager | 149 | * Unref the slave and save the keyboard manager |
150 | */ | 150 | */ |
151 | PIconView::~PIconView() { | 151 | PIconView::~PIconView() { |
152 | { | 152 | { |
153 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" ); | 153 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" ); |
154 | } | 154 | } |
155 | m_viewManager->save(); | 155 | m_viewManager->save(); |
156 | delete m_viewManager; | 156 | delete m_viewManager; |
157 | } | 157 | } |
158 | 158 | ||
159 | Opie::Ui::OKeyConfigManager* PIconView::manager() { | 159 | Opie::Core::OKeyConfigManager* PIconView::manager() { |
160 | return m_viewManager; | 160 | return m_viewManager; |
161 | } | 161 | } |
162 | 162 | ||
163 | 163 | ||
164 | /* | 164 | /* |
165 | * init the KeyBoard Shortcuts | 165 | * init the KeyBoard Shortcuts |
166 | * called from the c'tor | 166 | * called from the c'tor |
167 | */ | 167 | */ |
168 | void PIconView::initKeys() { | 168 | void PIconView::initKeys() { |
169 | Opie::Ui::OKeyPair::List lst; | 169 | Opie::Core::OKeyPair::List lst; |
170 | lst.append( Opie::Ui::OKeyPair::upArrowKey() ); | 170 | lst.append( Opie::Core::OKeyPair::upArrowKey() ); |
171 | lst.append( Opie::Ui::OKeyPair::downArrowKey() ); | 171 | lst.append( Opie::Core::OKeyPair::downArrowKey() ); |
172 | lst.append( Opie::Ui::OKeyPair::leftArrowKey() ); | 172 | lst.append( Opie::Core::OKeyPair::leftArrowKey() ); |
173 | lst.append( Opie::Ui::OKeyPair::rightArrowKey() ); | 173 | lst.append( Opie::Core::OKeyPair::rightArrowKey() ); |
174 | lst.append( Opie::Ui::OKeyPair::returnKey() ); | 174 | lst.append( Opie::Core::OKeyPair::returnKey() ); |
175 | 175 | ||
176 | m_viewManager = new Opie::Ui::OKeyConfigManager(m_cfg, "View-KeyBoard-Config", | 176 | m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "View-KeyBoard-Config", |
177 | lst, false,this, "keyconfig name" ); | 177 | lst, false,this, "keyconfig name" ); |
178 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Beam Current Item") , "beam", | 178 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Beam Current Item") , "beam", |
179 | Resource::loadPixmap("beam"), BeamItem, | 179 | Resource::loadPixmap("beam"), BeamItem, |
180 | Opie::Ui::OKeyPair(Qt::Key_B, Qt::ShiftButton), | 180 | Opie::Core::OKeyPair(Qt::Key_B, Qt::ShiftButton), |
181 | this, SLOT(slotBeam())) ); | 181 | this, SLOT(slotBeam())) ); |
182 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Delete Current Item"), "delete", | 182 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Delete Current Item"), "delete", |
183 | Resource::loadPixmap("trash"), DeleteItem, | 183 | Resource::loadPixmap("trash"), DeleteItem, |
184 | Opie::Ui::OKeyPair(Qt::Key_D, Qt::ShiftButton), | 184 | Opie::Core::OKeyPair(Qt::Key_D, Qt::ShiftButton), |
185 | this, SLOT(slotTrash())) ); | 185 | this, SLOT(slotTrash())) ); |
186 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("View Current Item"), "view", | 186 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("View Current Item"), "view", |
187 | Resource::loadPixmap("1to1"), ViewItem, | 187 | Resource::loadPixmap("1to1"), ViewItem, |
188 | Opie::Ui::OKeyPair(Qt::Key_V, Qt::ShiftButton), | 188 | Opie::Core::OKeyPair(Qt::Key_V, Qt::ShiftButton), |
189 | this, SLOT(slotShowImage()))); | 189 | this, SLOT(slotShowImage()))); |
190 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Show Image Info") , "info", | 190 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Show Image Info") , "info", |
191 | Resource::loadPixmap("DocumentTypeWord"), InfoItem, | 191 | Resource::loadPixmap("DocumentTypeWord"), InfoItem, |
192 | Opie::Ui::OKeyPair(Qt::Key_I, Qt::ShiftButton ), | 192 | Opie::Core::OKeyPair(Qt::Key_I, Qt::ShiftButton ), |
193 | this, SLOT(slotImageInfo()) ) ); | 193 | this, SLOT(slotImageInfo()) ) ); |
194 | m_viewManager->load(); | 194 | m_viewManager->load(); |
195 | m_viewManager->handleWidget( m_view ); | 195 | m_viewManager->handleWidget( m_view ); |
196 | } | 196 | } |
197 | 197 | ||
198 | 198 | ||
199 | /* | 199 | /* |
200 | * change one dir up | 200 | * change one dir up |
201 | */ | 201 | */ |
202 | void PIconView::slotDirUp() { | 202 | void PIconView::slotDirUp() { |
203 | QDir dir( m_path ); | 203 | QDir dir( m_path ); |
204 | dir.cdUp(); | 204 | dir.cdUp(); |
205 | slotChangeDir( dir.absPath() ); | 205 | slotChangeDir( dir.absPath() ); |
206 | } | 206 | } |
207 | 207 | ||
208 | /* | 208 | /* |
209 | * change the dir | 209 | * change the dir |
210 | */ | 210 | */ |
211 | void PIconView::slotChangeDir(const QString& path) { | 211 | void PIconView::slotChangeDir(const QString& path) { |
212 | if ( !currentView() ) | 212 | if ( !currentView() ) |
213 | return; | 213 | return; |
214 | 214 | ||
215 | PDirLister *lister = currentView()->dirLister(); | 215 | PDirLister *lister = currentView()->dirLister(); |
216 | if (!lister ) | 216 | if (!lister ) |
217 | return; | 217 | return; |
218 | 218 | ||
219 | /* | 219 | /* |
220 | * Say what we want and take what we get | 220 | * Say what we want and take what we get |
221 | */ | 221 | */ |
222 | lister->setStartPath( path ); | 222 | lister->setStartPath( path ); |
223 | m_path = lister->currentPath(); | 223 | m_path = lister->currentPath(); |
224 | 224 | ||
225 | m_view->viewport()->setUpdatesEnabled( false ); | 225 | m_view->viewport()->setUpdatesEnabled( false ); |
226 | m_view->clear(); | 226 | m_view->clear(); |
227 | 227 | ||
228 | /* | 228 | /* |
229 | * add files and folders | 229 | * add files and folders |
230 | */ | 230 | */ |
231 | addFolders( lister->folders() ); | 231 | addFolders( lister->folders() ); |
232 | addFiles( lister->files() ); | 232 | addFiles( lister->files() ); |
233 | m_view->viewport()->setUpdatesEnabled( true ); | 233 | m_view->viewport()->setUpdatesEnabled( true ); |
234 | 234 | ||
235 | // Also invalidate the cache. We can't cancel the operations anyway | 235 | // Also invalidate the cache. We can't cancel the operations anyway |
236 | g_stringPix.clear(); | 236 | g_stringPix.clear(); |
237 | g_stringInf.clear(); | 237 | g_stringInf.clear(); |
238 | 238 | ||
239 | // looks ugly | 239 | // looks ugly |
240 | static_cast<QMainWindow*>(parent())->setCaption( QObject::tr("%1 - O View", "Name of the dir").arg( m_path ) ); | 240 | static_cast<QMainWindow*>(parent())->setCaption( QObject::tr("%1 - O View", "Name of the dir").arg( m_path ) ); |
241 | } | 241 | } |
242 | 242 | ||
243 | /** | 243 | /** |
244 | * get the current file name | 244 | * get the current file name |
245 | * @param isDir see if this is a dir or real file | 245 | * @param isDir see if this is a dir or real file |
246 | */ | 246 | */ |
247 | QString PIconView::currentFileName(bool &isDir)const { | 247 | QString PIconView::currentFileName(bool &isDir)const { |
248 | isDir = false; | 248 | isDir = false; |
249 | QIconViewItem* _it = m_view->currentItem(); | 249 | QIconViewItem* _it = m_view->currentItem(); |
250 | if ( !_it ) | 250 | if ( !_it ) |
251 | return QString::null; | 251 | return QString::null; |
252 | 252 | ||
253 | IconViewItem* it = static_cast<IconViewItem*>( _it ); | 253 | IconViewItem* it = static_cast<IconViewItem*>( _it ); |
254 | isDir = it->isDir(); | 254 | isDir = it->isDir(); |
255 | return it->path(); | 255 | return it->path(); |
256 | } | 256 | } |
257 | 257 | ||
258 | void PIconView::slotTrash() { | 258 | void PIconView::slotTrash() { |
259 | bool isDir; | 259 | bool isDir; |
260 | QString pa = currentFileName( isDir ); | 260 | QString pa = currentFileName( isDir ); |
261 | if ( isDir && pa.isEmpty() ) | 261 | if ( isDir && pa.isEmpty() ) |
262 | return; | 262 | return; |
263 | 263 | ||
264 | if (!QPEMessageBox::confirmDelete( this, | 264 | if (!QPEMessageBox::confirmDelete( this, |
265 | tr("Delete Image" ), | 265 | tr("Delete Image" ), |
266 | tr("the Image %1" ).arg(pa))) | 266 | tr("the Image %1" ).arg(pa))) |
267 | return | 267 | return |
268 | 268 | ||
269 | 269 | ||
270 | currentView()->dirLister()->deleteImage( pa ); | 270 | currentView()->dirLister()->deleteImage( pa ); |
271 | delete m_view->currentItem(); | 271 | delete m_view->currentItem(); |
272 | } | 272 | } |
273 | 273 | ||
274 | /* | 274 | /* |
275 | * see what views are available | 275 | * see what views are available |
276 | */ | 276 | */ |
277 | void PIconView::loadViews() { | 277 | void PIconView::loadViews() { |
278 | ViewMap::Iterator it; | 278 | ViewMap::Iterator it; |
279 | ViewMap* map = viewMap(); | 279 | ViewMap* map = viewMap(); |
280 | for ( it = map->begin(); it != map->end(); ++it ) | 280 | for ( it = map->begin(); it != map->end(); ++it ) |
281 | m_views->insertItem( QObject::tr(it.key() ) ); | 281 | m_views->insertItem( QObject::tr(it.key() ) ); |
282 | } | 282 | } |
283 | 283 | ||
284 | void PIconView::resetView() { | 284 | void PIconView::resetView() { |
285 | slotViewChanged(m_views->currentItem()); | 285 | slotViewChanged(m_views->currentItem()); |
286 | } | 286 | } |
287 | 287 | ||
288 | /* | 288 | /* |
289 | *swicth view reloadDir and connect signals | 289 | *swicth view reloadDir and connect signals |
290 | */ | 290 | */ |
291 | void PIconView::slotViewChanged( int i) { | 291 | void PIconView::slotViewChanged( int i) { |
292 | if (!m_views->count() ) { | 292 | if (!m_views->count() ) { |
293 | setCurrentView( 0l); | 293 | setCurrentView( 0l); |
294 | return; | 294 | return; |
295 | } | 295 | } |
296 | 296 | ||
297 | PDirView* cur = currentView(); | 297 | PDirView* cur = currentView(); |
298 | delete cur; | 298 | delete cur; |
299 | QString str = m_views->text(i); | 299 | QString str = m_views->text(i); |
300 | cur = (*(*viewMap())[str])(*m_cfg); | 300 | cur = (*(*viewMap())[str])(*m_cfg); |
301 | setCurrentView( cur ); | 301 | setCurrentView( cur ); |
302 | 302 | ||
303 | /* connect to the signals of the lister */ | 303 | /* connect to the signals of the lister */ |
304 | PDirLister* lis = cur->dirLister(); | 304 | PDirLister* lis = cur->dirLister(); |
305 | connect(lis, SIGNAL(sig_thumbInfo(const QString&, const QString& )), | 305 | connect(lis, SIGNAL(sig_thumbInfo(const QString&, const QString& )), |
306 | this, SLOT( slotThumbInfo(const QString&, const QString&))); | 306 | this, SLOT( slotThumbInfo(const QString&, const QString&))); |
307 | connect(lis, SIGNAL( sig_thumbNail(const QString&, const QPixmap&)), | 307 | connect(lis, SIGNAL( sig_thumbNail(const QString&, const QPixmap&)), |
308 | this, SLOT(slotThumbNail(const QString&, const QPixmap&))); | 308 | this, SLOT(slotThumbNail(const QString&, const QPixmap&))); |
309 | connect(lis, SIGNAL(sig_start()), | 309 | connect(lis, SIGNAL(sig_start()), |
310 | this, SLOT(slotStart())); | 310 | this, SLOT(slotStart())); |
311 | connect(lis, SIGNAL(sig_end()) , | 311 | connect(lis, SIGNAL(sig_end()) , |
312 | this, SLOT(slotEnd()) ); | 312 | this, SLOT(slotEnd()) ); |
313 | 313 | ||
314 | 314 | ||
315 | /* reload now */ | 315 | /* reload now */ |
316 | QTimer::singleShot( 0, this, SLOT(slotReloadDir())); | 316 | QTimer::singleShot( 0, this, SLOT(slotReloadDir())); |
317 | } | 317 | } |
318 | 318 | ||
319 | 319 | ||
320 | void PIconView::slotReloadDir() { | 320 | void PIconView::slotReloadDir() { |
321 | slotChangeDir( m_path ); | 321 | slotChangeDir( m_path ); |
322 | } | 322 | } |
323 | 323 | ||
324 | 324 | ||
325 | /* | 325 | /* |
326 | * add files and folders | 326 | * add files and folders |
327 | */ | 327 | */ |
328 | void PIconView::addFolders( const QStringList& lst) { | 328 | void PIconView::addFolders( const QStringList& lst) { |
329 | QStringList::ConstIterator it; | 329 | QStringList::ConstIterator it; |
330 | 330 | ||
331 | for(it=lst.begin(); it != lst.end(); ++it ) | 331 | for(it=lst.begin(); it != lst.end(); ++it ) |
332 | (void)new IconViewItem( m_view, m_path+"/"+(*it), (*it), true ); | 332 | (void)new IconViewItem( m_view, m_path+"/"+(*it), (*it), true ); |
333 | 333 | ||
334 | 334 | ||
335 | } | 335 | } |
336 | 336 | ||
337 | void PIconView::addFiles( const QStringList& lst) { | 337 | void PIconView::addFiles( const QStringList& lst) { |
338 | QStringList::ConstIterator it; | 338 | QStringList::ConstIterator it; |
339 | for (it=lst.begin(); it!= lst.end(); ++it ) | 339 | for (it=lst.begin(); it!= lst.end(); ++it ) |
340 | (void)new IconViewItem( m_view, m_path+"/"+(*it), (*it) ); | 340 | (void)new IconViewItem( m_view, m_path+"/"+(*it), (*it) ); |
341 | 341 | ||
342 | } | 342 | } |
343 | 343 | ||
344 | /* | 344 | /* |
345 | * user clicked on the item. Change dir or view | 345 | * user clicked on the item. Change dir or view |
346 | */ | 346 | */ |
347 | void PIconView::slotClicked(QIconViewItem* _it) { | 347 | void PIconView::slotClicked(QIconViewItem* _it) { |
348 | if(!_it ) | 348 | if(!_it ) |
349 | return; | 349 | return; |
350 | 350 | ||
351 | IconViewItem* it = static_cast<IconViewItem*>(_it); | 351 | IconViewItem* it = static_cast<IconViewItem*>(_it); |
352 | if( it->isDir() ) | 352 | if( it->isDir() ) |
353 | slotChangeDir( it->path() ); | 353 | slotChangeDir( it->path() ); |
354 | else // view image | 354 | else // view image |
355 | slotShowImage(); | 355 | slotShowImage(); |
356 | } | 356 | } |
357 | 357 | ||
358 | /* | 358 | /* |
359 | * got thumb info add to the cache if items is visible | 359 | * got thumb info add to the cache if items is visible |
360 | * we later need update after processing of slave is done | 360 | * we later need update after processing of slave is done |
361 | */ | 361 | */ |
362 | void PIconView::slotThumbInfo( const QString& _path, const QString& str ) { | 362 | void PIconView::slotThumbInfo( const QString& _path, const QString& str ) { |
363 | IconViewItem* item = g_stringInf[_path]; | 363 | IconViewItem* item = g_stringInf[_path]; |
364 | if (!item ) | 364 | if (!item ) |
365 | return; | 365 | return; |
366 | 366 | ||
367 | if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(), | 367 | if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(), |
368 | m_view->contentsWidth(), m_view->contentsHeight() ) ) ) | 368 | m_view->contentsWidth(), m_view->contentsHeight() ) ) ) |
369 | m_updatet = true; | 369 | m_updatet = true; |
370 | 370 | ||
371 | item->setText( str ); | 371 | item->setText( str ); |
372 | g_stringInf.remove( _path ); | 372 | g_stringInf.remove( _path ); |
373 | } | 373 | } |
374 | 374 | ||
375 | /* | 375 | /* |
376 | * got thumbnail and see if it is visible so we need to update later | 376 | * got thumbnail and see if it is visible so we need to update later |
377 | */ | 377 | */ |
378 | void PIconView::slotThumbNail(const QString& _path, const QPixmap &pix) { | 378 | void PIconView::slotThumbNail(const QString& _path, const QPixmap &pix) { |
379 | IconViewItem* item = g_stringPix[_path]; | 379 | IconViewItem* item = g_stringPix[_path]; |
380 | if (!item ) | 380 | if (!item ) |
381 | return; | 381 | return; |
382 | 382 | ||
383 | if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(), | 383 | if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(), |
384 | m_view->contentsWidth(), m_view->contentsHeight() ) ) ) | 384 | m_view->contentsWidth(), m_view->contentsHeight() ) ) ) |
385 | m_updatet = true; | 385 | m_updatet = true; |
386 | 386 | ||
387 | if (pix.width()>0) | 387 | if (pix.width()>0) |
388 | PPixmapCache::self()->insertImage( _path, pix, 64, 64 ); | 388 | PPixmapCache::self()->insertImage( _path, pix, 64, 64 ); |
389 | 389 | ||
390 | 390 | ||
391 | g_stringPix.remove( _path ); | 391 | g_stringPix.remove( _path ); |
392 | } | 392 | } |
393 | 393 | ||
394 | 394 | ||
395 | /* | 395 | /* |
396 | * FIXME rename | 396 | * FIXME rename |
397 | */ | 397 | */ |
398 | void PIconView::slotRename() { | 398 | void PIconView::slotRename() { |
399 | 399 | ||
400 | } | 400 | } |
401 | 401 | ||
402 | 402 | ||
403 | /* | 403 | /* |
404 | * BEAM the current file | 404 | * BEAM the current file |
405 | */ | 405 | */ |
406 | void PIconView::slotBeam() { | 406 | void PIconView::slotBeam() { |
407 | bool isDir; | 407 | bool isDir; |
408 | QString pa = currentFileName( isDir ); | 408 | QString pa = currentFileName( isDir ); |
409 | if ( isDir && pa.isEmpty() ) | 409 | if ( isDir && pa.isEmpty() ) |
410 | return; | 410 | return; |
411 | 411 | ||
412 | Ir* ir = new Ir( this ); | 412 | Ir* ir = new Ir( this ); |
413 | connect( ir, SIGNAL(done(Ir*)), | 413 | connect( ir, SIGNAL(done(Ir*)), |
414 | this, SLOT(slotBeamDone(Ir*))); | 414 | this, SLOT(slotBeamDone(Ir*))); |
415 | ir->send(pa, tr( "Image" ) ); | 415 | ir->send(pa, tr( "Image" ) ); |
416 | } | 416 | } |
417 | 417 | ||
418 | /* | 418 | /* |
419 | * BEAM done clean up | 419 | * BEAM done clean up |
420 | */ | 420 | */ |
421 | void PIconView::slotBeamDone( Ir* ir) { | 421 | void PIconView::slotBeamDone( Ir* ir) { |
422 | delete ir; | 422 | delete ir; |
423 | } | 423 | } |
424 | 424 | ||
425 | void PIconView::slotStart() { | 425 | void PIconView::slotStart() { |
426 | m_view->viewport()->setUpdatesEnabled( false ); | 426 | m_view->viewport()->setUpdatesEnabled( false ); |
427 | } | 427 | } |
428 | 428 | ||
429 | void PIconView::slotEnd() { | 429 | void PIconView::slotEnd() { |
430 | if ( m_updatet ) | 430 | if ( m_updatet ) |
431 | m_view->arrangeItemsInGrid( ); | 431 | m_view->arrangeItemsInGrid( ); |
432 | m_view->viewport()->setUpdatesEnabled( true ); | 432 | m_view->viewport()->setUpdatesEnabled( true ); |
433 | m_updatet = false; | 433 | m_updatet = false; |
434 | } | 434 | } |
435 | 435 | ||
436 | void PIconView::slotShowImage() | 436 | void PIconView::slotShowImage() |
437 | { | 437 | { |
438 | bool isDir = false; | 438 | bool isDir = false; |
439 | QString name = currentFileName(isDir); | 439 | QString name = currentFileName(isDir); |
440 | if (isDir) return; | 440 | if (isDir) return; |
441 | 441 | ||
442 | slotShowImage( name ); | 442 | slotShowImage( name ); |
443 | } | 443 | } |
444 | void PIconView::slotShowImage( const QString& name) { | 444 | void PIconView::slotShowImage( const QString& name) { |
445 | emit sig_display( name ); | 445 | emit sig_display( name ); |
446 | } | 446 | } |
447 | void PIconView::slotImageInfo() { | 447 | void PIconView::slotImageInfo() { |
448 | bool isDir = false; | 448 | bool isDir = false; |
diff --git a/noncore/graphics/opie-eye/gui/iconview.h b/noncore/graphics/opie-eye/gui/iconview.h index a4ca0bc..9cf7b3e 100644 --- a/noncore/graphics/opie-eye/gui/iconview.h +++ b/noncore/graphics/opie-eye/gui/iconview.h | |||
@@ -1,84 +1,82 @@ | |||
1 | /* | 1 | /* |
2 | * GPLv2 zecke@handhelds.org | 2 | * GPLv2 zecke@handhelds.org |
3 | * No WArranty... | 3 | * No WArranty... |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #ifndef PHUNK_ICON_VIEW_H | 6 | #ifndef PHUNK_ICON_VIEW_H |
7 | #define PHUNK_ICON_VIEW_H | 7 | #define PHUNK_ICON_VIEW_H |
8 | 8 | ||
9 | #include <qvbox.h> | 9 | #include <qvbox.h> |
10 | 10 | ||
11 | 11 | ||
12 | class QIconView; | 12 | class QIconView; |
13 | class QIconViewItem; | 13 | class QIconViewItem; |
14 | class QComboBox; | 14 | class QComboBox; |
15 | class PIconViewItem; | 15 | class PIconViewItem; |
16 | class PDirLister; | 16 | class PDirLister; |
17 | class Ir; | 17 | class Ir; |
18 | 18 | ||
19 | namespace Opie { | 19 | namespace Opie { |
20 | namespace Core{ | 20 | namespace Core{ |
21 | class OConfig; | 21 | class OConfig; |
22 | } | ||
23 | namespace Ui { | ||
24 | class OKeyConfigManager; | 22 | class OKeyConfigManager; |
25 | } | 23 | } |
26 | } | 24 | } |
27 | 25 | ||
28 | class PIconView : public QVBox { | 26 | class PIconView : public QVBox { |
29 | Q_OBJECT | 27 | Q_OBJECT |
30 | friend class PIconViewItem; | 28 | friend class PIconViewItem; |
31 | enum ActionIds { | 29 | enum ActionIds { |
32 | BeamItem, DeleteItem, ViewItem, InfoItem | 30 | BeamItem, DeleteItem, ViewItem, InfoItem |
33 | }; | 31 | }; |
34 | public: | 32 | public: |
35 | PIconView( QWidget* wid, Opie::Core::OConfig *cfg ); | 33 | PIconView( QWidget* wid, Opie::Core::OConfig *cfg ); |
36 | ~PIconView(); | 34 | ~PIconView(); |
37 | void resetView(); | 35 | void resetView(); |
38 | Opie::Ui::OKeyConfigManager* manager(); | 36 | Opie::Core::OKeyConfigManager* manager(); |
39 | 37 | ||
40 | signals: | 38 | signals: |
41 | void sig_showInfo( const QString& ); | 39 | void sig_showInfo( const QString& ); |
42 | void sig_display( const QString& ); | 40 | void sig_display( const QString& ); |
43 | 41 | ||
44 | private: | 42 | private: |
45 | void initKeys(); | 43 | void initKeys(); |
46 | QString currentFileName(bool &isDir)const; | 44 | QString currentFileName(bool &isDir)const; |
47 | void loadViews(); | 45 | void loadViews(); |
48 | 46 | ||
49 | private slots: | 47 | private slots: |
50 | void slotDirUp(); | 48 | void slotDirUp(); |
51 | void slotChangeDir(const QString&); | 49 | void slotChangeDir(const QString&); |
52 | void slotTrash(); | 50 | void slotTrash(); |
53 | void slotViewChanged( int ); | 51 | void slotViewChanged( int ); |
54 | void slotReloadDir(); | 52 | void slotReloadDir(); |
55 | void slotRename(); | 53 | void slotRename(); |
56 | void slotBeam(); | 54 | void slotBeam(); |
57 | void slotBeamDone( Ir* ); | 55 | void slotBeamDone( Ir* ); |
58 | 56 | ||
59 | void slotShowImage(); | 57 | void slotShowImage(); |
60 | void slotShowImage( const QString& ); | 58 | void slotShowImage( const QString& ); |
61 | void slotImageInfo(); | 59 | void slotImageInfo(); |
62 | void slotImageInfo( const QString& ); | 60 | void slotImageInfo( const QString& ); |
63 | 61 | ||
64 | void slotStart(); | 62 | void slotStart(); |
65 | void slotEnd(); | 63 | void slotEnd(); |
66 | 64 | ||
67 | /* for performance reasons make it inline in the future */ | 65 | /* for performance reasons make it inline in the future */ |
68 | void addFolders( const QStringList& ); | 66 | void addFolders( const QStringList& ); |
69 | void addFiles( const QStringList& ); | 67 | void addFiles( const QStringList& ); |
70 | void slotClicked(QIconViewItem* ); | 68 | void slotClicked(QIconViewItem* ); |
71 | 69 | ||
72 | /**/ | 70 | /**/ |
73 | void slotThumbInfo(const QString&, const QString&); | 71 | void slotThumbInfo(const QString&, const QString&); |
74 | void slotThumbNail(const QString&, const QPixmap&); | 72 | void slotThumbNail(const QString&, const QPixmap&); |
75 | private: | 73 | private: |
76 | Opie::Ui::OKeyConfigManager *m_viewManager; | 74 | Opie::Core::OKeyConfigManager *m_viewManager; |
77 | Opie::Core::OConfig *m_cfg; | 75 | Opie::Core::OConfig *m_cfg; |
78 | QComboBox* m_views; | 76 | QComboBox* m_views; |
79 | QIconView* m_view; | 77 | QIconView* m_view; |
80 | QString m_path; | 78 | QString m_path; |
81 | bool m_updatet : 1; | 79 | bool m_updatet : 1; |
82 | }; | 80 | }; |
83 | 81 | ||
84 | #endif | 82 | #endif |
diff --git a/noncore/graphics/opie-eye/gui/imageinfoui.cpp b/noncore/graphics/opie-eye/gui/imageinfoui.cpp index 0b3250c..27a67a6 100644 --- a/noncore/graphics/opie-eye/gui/imageinfoui.cpp +++ b/noncore/graphics/opie-eye/gui/imageinfoui.cpp | |||
@@ -1,205 +1,205 @@ | |||
1 | #include "imageinfoui.h" | 1 | #include "imageinfoui.h" |
2 | 2 | ||
3 | #include <qframe.h> | 3 | #include <qframe.h> |
4 | #include <qlabel.h> | 4 | #include <qlabel.h> |
5 | #include <qpushbutton.h> | 5 | #include <qpushbutton.h> |
6 | #include <qtextview.h> | 6 | #include <qtextview.h> |
7 | #include <qlayout.h> | 7 | #include <qlayout.h> |
8 | #include <qvariant.h> | 8 | #include <qvariant.h> |
9 | #include <qtooltip.h> | 9 | #include <qtooltip.h> |
10 | #include <qwhatsthis.h> | 10 | #include <qwhatsthis.h> |
11 | #include <qimage.h> | 11 | #include <qimage.h> |
12 | #include <qpixmap.h> | 12 | #include <qpixmap.h> |
13 | #include <qstring.h> | 13 | #include <qstring.h> |
14 | #include <qfileinfo.h> | 14 | #include <qfileinfo.h> |
15 | 15 | ||
16 | #include "lib/slavemaster.h" | 16 | #include "lib/slavemaster.h" |
17 | #include "lib/imagecache.h" | 17 | #include "lib/imagecache.h" |
18 | 18 | ||
19 | #include <opie2/oconfig.h> | 19 | #include <opie2/oconfig.h> |
20 | #include <opie2/okeyconfigwidget.h> | 20 | #include <opie2/okeyconfigwidget.h> |
21 | #include <opie2/odebug.h> | 21 | #include <opie2/odebug.h> |
22 | 22 | ||
23 | #include <qpe/qcopenvelope_qws.h> | 23 | #include <qpe/qcopenvelope_qws.h> |
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
25 | 25 | ||
26 | static const int THUMBSIZE = 128; | 26 | static const int THUMBSIZE = 128; |
27 | 27 | ||
28 | using namespace Opie::Core; | 28 | using namespace Opie::Core; |
29 | 29 | ||
30 | imageinfo::imageinfo(Opie::Core::OConfig *cfg,QWidget* parent, const char* name, WFlags fl ) | 30 | imageinfo::imageinfo(Opie::Core::OConfig *cfg,QWidget* parent, const char* name, WFlags fl ) |
31 | : QWidget( parent, name, fl ) | 31 | : QWidget( parent, name, fl ) |
32 | { | 32 | { |
33 | m_viewManager = 0; | 33 | m_viewManager = 0; |
34 | m_cfg = cfg; | 34 | m_cfg = cfg; |
35 | init(name); | 35 | init(name); |
36 | initKeys(); | 36 | initKeys(); |
37 | } | 37 | } |
38 | 38 | ||
39 | imageinfo::imageinfo(const QString&_path, QWidget* parent, const char* name, WFlags fl ) | 39 | imageinfo::imageinfo(const QString&_path, QWidget* parent, const char* name, WFlags fl ) |
40 | : QWidget( parent, name, fl ),currentFile(_path) | 40 | : QWidget( parent, name, fl ),currentFile(_path) |
41 | { | 41 | { |
42 | m_viewManager = 0; | 42 | m_viewManager = 0; |
43 | m_cfg = 0; | 43 | m_cfg = 0; |
44 | init(name); | 44 | init(name); |
45 | initKeys(); | 45 | initKeys(); |
46 | slotChangeName(_path); | 46 | slotChangeName(_path); |
47 | } | 47 | } |
48 | 48 | ||
49 | Opie::Ui::OKeyConfigManager* imageinfo::manager() | 49 | Opie::Core::OKeyConfigManager* imageinfo::manager() |
50 | { | 50 | { |
51 | if (!m_viewManager) { | 51 | if (!m_viewManager) { |
52 | initKeys(); | 52 | initKeys(); |
53 | } | 53 | } |
54 | return m_viewManager; | 54 | return m_viewManager; |
55 | } | 55 | } |
56 | 56 | ||
57 | void imageinfo::initKeys() | 57 | void imageinfo::initKeys() |
58 | { | 58 | { |
59 | odebug << "init imageinfo keys" << oendl; | 59 | odebug << "init imageinfo keys" << oendl; |
60 | #if 0 | 60 | #if 0 |
61 | if (!m_cfg) { | 61 | if (!m_cfg) { |
62 | m_cfg = new Opie::Core::OConfig("phunkview"); | 62 | m_cfg = new Opie::Core::OConfig("phunkview"); |
63 | m_cfg->setGroup("imageinfo_keys" ); | 63 | m_cfg->setGroup("imageinfo_keys" ); |
64 | } | 64 | } |
65 | #endif | 65 | #endif |
66 | Opie::Ui::OKeyPair::List lst; | 66 | Opie::Core::OKeyPair::List lst; |
67 | lst.append( Opie::Ui::OKeyPair::upArrowKey() ); | 67 | lst.append( Opie::Core::OKeyPair::upArrowKey() ); |
68 | lst.append( Opie::Ui::OKeyPair::downArrowKey() ); | 68 | lst.append( Opie::Core::OKeyPair::downArrowKey() ); |
69 | lst.append( Opie::Ui::OKeyPair::leftArrowKey() ); | 69 | lst.append( Opie::Core::OKeyPair::leftArrowKey() ); |
70 | lst.append( Opie::Ui::OKeyPair::rightArrowKey() ); | 70 | lst.append( Opie::Core::OKeyPair::rightArrowKey() ); |
71 | lst.append( Opie::Ui::OKeyPair::returnKey() ); | 71 | lst.append( Opie::Core::OKeyPair::returnKey() ); |
72 | 72 | ||
73 | m_viewManager = new Opie::Ui::OKeyConfigManager(m_cfg, "imageinfo_keys", | 73 | m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "imageinfo_keys", |
74 | lst, false,this, "keyconfig name" ); | 74 | lst, false,this, "keyconfig name" ); |
75 | m_viewManager->addKeyConfig( Opie::Ui::OKeyConfigItem(tr("View Full Image"), "infoview", | 75 | m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("View Full Image"), "infoview", |
76 | Resource::loadPixmap("1to1"), ViewItem, | 76 | Resource::loadPixmap("1to1"), ViewItem, |
77 | Opie::Ui::OKeyPair(Qt::Key_V, Qt::ShiftButton), | 77 | Opie::Core::OKeyPair(Qt::Key_V, Qt::ShiftButton), |
78 | this, SLOT(slotShowImage()))); | 78 | this, SLOT(slotShowImage()))); |
79 | m_viewManager->load(); | 79 | m_viewManager->load(); |
80 | m_viewManager->handleWidget( this ); | 80 | m_viewManager->handleWidget( this ); |
81 | m_viewManager->handleWidget( TextView1 ); | 81 | m_viewManager->handleWidget( TextView1 ); |
82 | } | 82 | } |
83 | 83 | ||
84 | void imageinfo::slotShowImage() | 84 | void imageinfo::slotShowImage() |
85 | { | 85 | { |
86 | emit dispImage(currentFile); | 86 | emit dispImage(currentFile); |
87 | } | 87 | } |
88 | 88 | ||
89 | void imageinfo::init(const char* name) { | 89 | void imageinfo::init(const char* name) { |
90 | { | 90 | { |
91 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" ); | 91 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" ); |
92 | } | 92 | } |
93 | if ( !name ) | 93 | if ( !name ) |
94 | setName( "imageinfo" ); | 94 | setName( "imageinfo" ); |
95 | resize( 289, 335 ); | 95 | resize( 289, 335 ); |
96 | setCaption( tr( "Image info" ) ); | 96 | setCaption( tr( "Image info" ) ); |
97 | imageinfoLayout = new QVBoxLayout( this ); | 97 | imageinfoLayout = new QVBoxLayout( this ); |
98 | imageinfoLayout->setSpacing(2); | 98 | imageinfoLayout->setSpacing(2); |
99 | imageinfoLayout->setMargin(4); | 99 | imageinfoLayout->setMargin(4); |
100 | 100 | ||
101 | PixmapLabel1 = new QLabel( this, "PixmapLabel1" ); | 101 | PixmapLabel1 = new QLabel( this, "PixmapLabel1" ); |
102 | PixmapLabel1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)5, PixmapLabel1->sizePolicy().hasHeightForWidth() ) ); | 102 | PixmapLabel1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)5, PixmapLabel1->sizePolicy().hasHeightForWidth() ) ); |
103 | QWhatsThis::add( PixmapLabel1, tr("Displays an thumbnail of the image") ); | 103 | QWhatsThis::add( PixmapLabel1, tr("Displays an thumbnail of the image") ); |
104 | 104 | ||
105 | imageinfoLayout->addWidget( PixmapLabel1 ); | 105 | imageinfoLayout->addWidget( PixmapLabel1 ); |
106 | 106 | ||
107 | Line1 = new QFrame( this, "Line1" ); | 107 | Line1 = new QFrame( this, "Line1" ); |
108 | Line1->setFrameStyle( QFrame::HLine | QFrame::Sunken ); | 108 | Line1->setFrameStyle( QFrame::HLine | QFrame::Sunken ); |
109 | imageinfoLayout->addWidget( Line1 ); | 109 | imageinfoLayout->addWidget( Line1 ); |
110 | 110 | ||
111 | fnameLabel = new QLabel( this, "FnameLabel" ); | 111 | fnameLabel = new QLabel( this, "FnameLabel" ); |
112 | imageinfoLayout->addWidget( fnameLabel); | 112 | imageinfoLayout->addWidget( fnameLabel); |
113 | 113 | ||
114 | TextView1 = new QTextView( this, "TextView1" ); | 114 | TextView1 = new QTextView( this, "TextView1" ); |
115 | TextView1->setFrameShadow( QTextView::Sunken ); | 115 | TextView1->setFrameShadow( QTextView::Sunken ); |
116 | TextView1->setResizePolicy( QTextView::AutoOneFit ); | 116 | TextView1->setResizePolicy( QTextView::AutoOneFit ); |
117 | TextView1->setBackgroundOrigin( QTextView::ParentOrigin ); | 117 | TextView1->setBackgroundOrigin( QTextView::ParentOrigin ); |
118 | TextView1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)3, TextView1->sizePolicy().hasHeightForWidth() ) ); | 118 | TextView1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)3, TextView1->sizePolicy().hasHeightForWidth() ) ); |
119 | // TextView1->setVScrollBarMode(QScrollView::AlwaysOn); | 119 | // TextView1->setVScrollBarMode(QScrollView::AlwaysOn); |
120 | QWhatsThis::add( TextView1, tr("Displays info of selected image") ); | 120 | QWhatsThis::add( TextView1, tr("Displays info of selected image") ); |
121 | imageinfoLayout->addWidget( TextView1 ); | 121 | imageinfoLayout->addWidget( TextView1 ); |
122 | 122 | ||
123 | SlaveMaster* master = SlaveMaster::self(); | 123 | SlaveMaster* master = SlaveMaster::self(); |
124 | connect( master, SIGNAL(sig_fullInfo(const QString&, const QString&)), | 124 | connect( master, SIGNAL(sig_fullInfo(const QString&, const QString&)), |
125 | this, SLOT(slot_fullInfo(const QString&, const QString&)) ); | 125 | this, SLOT(slot_fullInfo(const QString&, const QString&)) ); |
126 | connect(master, SIGNAL( sig_thumbNail(const QString&, const QPixmap&)), | 126 | connect(master, SIGNAL( sig_thumbNail(const QString&, const QPixmap&)), |
127 | this, SLOT(slotThumbNail(const QString&, const QPixmap&))); | 127 | this, SLOT(slotThumbNail(const QString&, const QPixmap&))); |
128 | } | 128 | } |
129 | 129 | ||
130 | void imageinfo::slotChangeName(const QString&_path) | 130 | void imageinfo::slotChangeName(const QString&_path) |
131 | { | 131 | { |
132 | currentFile=_path; | 132 | currentFile=_path; |
133 | QFileInfo fi(_path); | 133 | QFileInfo fi(_path); |
134 | fnameLabel->setText("<qt><center><b>"+fi.fileName()+"</b></center></qt>"); | 134 | fnameLabel->setText("<qt><center><b>"+fi.fileName()+"</b></center></qt>"); |
135 | SlaveMaster::self()->imageInfo( currentFile ); | 135 | SlaveMaster::self()->imageInfo( currentFile ); |
136 | 136 | ||
137 | QPixmap*m_pix = PPixmapCache::self()->cachedImage( _path, THUMBSIZE,THUMBSIZE ); | 137 | QPixmap*m_pix = PPixmapCache::self()->cachedImage( _path, THUMBSIZE,THUMBSIZE ); |
138 | if (!m_pix) { | 138 | if (!m_pix) { |
139 | PixmapLabel1->setPixmap(QPixmap( Resource::loadPixmap( "UnknownDocument" ))); | 139 | PixmapLabel1->setPixmap(QPixmap( Resource::loadPixmap( "UnknownDocument" ))); |
140 | SlaveMaster::self()->thumbNail(currentFile,THUMBSIZE,THUMBSIZE); | 140 | SlaveMaster::self()->thumbNail(currentFile,THUMBSIZE,THUMBSIZE); |
141 | } else { | 141 | } else { |
142 | PixmapLabel1->setPixmap(*m_pix); | 142 | PixmapLabel1->setPixmap(*m_pix); |
143 | } | 143 | } |
144 | } | 144 | } |
145 | 145 | ||
146 | imageinfo::~imageinfo() | 146 | imageinfo::~imageinfo() |
147 | { | 147 | { |
148 | { | 148 | { |
149 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" ); | 149 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" ); |
150 | } | 150 | } |
151 | if (m_viewManager) { | 151 | if (m_viewManager) { |
152 | delete m_viewManager; | 152 | delete m_viewManager; |
153 | } | 153 | } |
154 | } | 154 | } |
155 | 155 | ||
156 | void imageinfo::slot_fullInfo(const QString&_path, const QString&_t) | 156 | void imageinfo::slot_fullInfo(const QString&_path, const QString&_t) |
157 | { | 157 | { |
158 | if (_path == currentFile) { | 158 | if (_path == currentFile) { |
159 | qDebug(_t); | 159 | qDebug(_t); |
160 | QString t = _t; | 160 | QString t = _t; |
161 | t.replace(QRegExp("\n"),"<br>"); | 161 | t.replace(QRegExp("\n"),"<br>"); |
162 | TextView1->setText(t); | 162 | TextView1->setText(t); |
163 | } | 163 | } |
164 | } | 164 | } |
165 | 165 | ||
166 | void imageinfo::slotThumbNail(const QString&_path, const QPixmap&_pix) | 166 | void imageinfo::slotThumbNail(const QString&_path, const QPixmap&_pix) |
167 | { | 167 | { |
168 | if (_path == currentFile) { | 168 | if (_path == currentFile) { |
169 | if (_pix.width()>0) { | 169 | if (_pix.width()>0) { |
170 | PPixmapCache::self()->insertImage( _path, _pix, THUMBSIZE, THUMBSIZE ); | 170 | PPixmapCache::self()->insertImage( _path, _pix, THUMBSIZE, THUMBSIZE ); |
171 | PixmapLabel1->setPixmap( _pix ); | 171 | PixmapLabel1->setPixmap( _pix ); |
172 | PixmapLabel1->resize(QSize(_pix.width(),_pix.height())); | 172 | PixmapLabel1->resize(QSize(_pix.width(),_pix.height())); |
173 | } | 173 | } |
174 | } | 174 | } |
175 | } | 175 | } |
176 | 176 | ||
177 | void imageinfo::setPath( const QString& str ) { | 177 | void imageinfo::setPath( const QString& str ) { |
178 | slotChangeName( str ); | 178 | slotChangeName( str ); |
179 | } | 179 | } |
180 | 180 | ||
181 | void imageinfo::setDestructiveClose() { | 181 | void imageinfo::setDestructiveClose() { |
182 | WFlags fl = getWFlags(); | 182 | WFlags fl = getWFlags(); |
183 | /* clear it just in case */ | 183 | /* clear it just in case */ |
184 | fl &= ~WDestructiveClose; | 184 | fl &= ~WDestructiveClose; |
185 | fl |= WDestructiveClose; | 185 | fl |= WDestructiveClose; |
186 | setWFlags( fl ); | 186 | setWFlags( fl ); |
187 | } | 187 | } |
188 | 188 | ||
189 | 189 | ||
190 | /* for testing */ | 190 | /* for testing */ |
191 | infoDlg::infoDlg(const QString&fname,QWidget * parent, const char * name) | 191 | infoDlg::infoDlg(const QString&fname,QWidget * parent, const char * name) |
192 | :QDialog(parent,name,true,WStyle_ContextHelp) | 192 | :QDialog(parent,name,true,WStyle_ContextHelp) |
193 | { | 193 | { |
194 | QVBoxLayout*dlglayout = new QVBoxLayout(this); | 194 | QVBoxLayout*dlglayout = new QVBoxLayout(this); |
195 | dlglayout->setSpacing(2); | 195 | dlglayout->setSpacing(2); |
196 | dlglayout->setMargin(1); | 196 | dlglayout->setMargin(1); |
197 | imageinfo*inf = new imageinfo(fname,this); | 197 | imageinfo*inf = new imageinfo(fname,this); |
198 | dlglayout->addWidget(inf); | 198 | dlglayout->addWidget(inf); |
199 | } | 199 | } |
200 | 200 | ||
201 | infoDlg::~infoDlg() | 201 | infoDlg::~infoDlg() |
202 | { | 202 | { |
203 | } | 203 | } |
204 | 204 | ||
205 | 205 | ||
diff --git a/noncore/graphics/opie-eye/gui/imageinfoui.h b/noncore/graphics/opie-eye/gui/imageinfoui.h index c9b83a1..bc99bf9 100644 --- a/noncore/graphics/opie-eye/gui/imageinfoui.h +++ b/noncore/graphics/opie-eye/gui/imageinfoui.h | |||
@@ -1,78 +1,76 @@ | |||
1 | #ifndef IMAGEINFO_H | 1 | #ifndef IMAGEINFO_H |
2 | #define IMAGEINFO_H | 2 | #define IMAGEINFO_H |
3 | 3 | ||
4 | #include <qvariant.h> | 4 | #include <qvariant.h> |
5 | #include <qwidget.h> | 5 | #include <qwidget.h> |
6 | #include <qdialog.h> | 6 | #include <qdialog.h> |
7 | 7 | ||
8 | class QVBoxLayout; | 8 | class QVBoxLayout; |
9 | class QHBoxLayout; | 9 | class QHBoxLayout; |
10 | class QGridLayout; | 10 | class QGridLayout; |
11 | class QFrame; | 11 | class QFrame; |
12 | class QLabel; | 12 | class QLabel; |
13 | class QTextView; | 13 | class QTextView; |
14 | 14 | ||
15 | namespace Opie { | 15 | namespace Opie { |
16 | namespace Core { | 16 | namespace Core { |
17 | class OConfig; | 17 | class OConfig; |
18 | } | ||
19 | namespace Ui { | ||
20 | class OKeyConfigManager; | 18 | class OKeyConfigManager; |
21 | } | 19 | } |
22 | } | 20 | } |
23 | 21 | ||
24 | class imageinfo : public QWidget | 22 | class imageinfo : public QWidget |
25 | { | 23 | { |
26 | Q_OBJECT | 24 | Q_OBJECT |
27 | enum ActionIds { | 25 | enum ActionIds { |
28 | ViewItem | 26 | ViewItem |
29 | }; | 27 | }; |
30 | 28 | ||
31 | public: | 29 | public: |
32 | imageinfo(Opie::Core::OConfig *cfg, QWidget* parent = 0, const char* name = 0, WFlags fl =0); | 30 | imageinfo(Opie::Core::OConfig *cfg, QWidget* parent = 0, const char* name = 0, WFlags fl =0); |
33 | imageinfo(const QString&_path, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | 31 | imageinfo(const QString&_path, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); |
34 | virtual ~imageinfo(); | 32 | virtual ~imageinfo(); |
35 | 33 | ||
36 | void setDestructiveClose(); | 34 | void setDestructiveClose(); |
37 | Opie::Ui::OKeyConfigManager* manager(); | 35 | Opie::Core::OKeyConfigManager* manager(); |
38 | 36 | ||
39 | signals: | 37 | signals: |
40 | void dispImage(const QString&); | 38 | void dispImage(const QString&); |
41 | void sig_return(); | 39 | void sig_return(); |
42 | 40 | ||
43 | public slots: | 41 | public slots: |
44 | virtual void setPath( const QString& path ); | 42 | virtual void setPath( const QString& path ); |
45 | virtual void slotShowImage(); | 43 | virtual void slotShowImage(); |
46 | 44 | ||
47 | private: | 45 | private: |
48 | void init(const char* name); | 46 | void init(const char* name); |
49 | 47 | ||
50 | protected: | 48 | protected: |
51 | QLabel* PixmapLabel1; | 49 | QLabel* PixmapLabel1; |
52 | QLabel* fnameLabel; | 50 | QLabel* fnameLabel; |
53 | QFrame* Line1; | 51 | QFrame* Line1; |
54 | QTextView* TextView1; | 52 | QTextView* TextView1; |
55 | QVBoxLayout* imageinfoLayout; | 53 | QVBoxLayout* imageinfoLayout; |
56 | QString currentFile; | 54 | QString currentFile; |
57 | 55 | ||
58 | Opie::Core::OConfig * m_cfg; | 56 | Opie::Core::OConfig * m_cfg; |
59 | Opie::Ui::OKeyConfigManager*m_viewManager; | 57 | Opie::Core::OKeyConfigManager*m_viewManager; |
60 | void initKeys(); | 58 | void initKeys(); |
61 | 59 | ||
62 | protected slots: | 60 | protected slots: |
63 | virtual void slot_fullInfo(const QString&, const QString&); | 61 | virtual void slot_fullInfo(const QString&, const QString&); |
64 | virtual void slotThumbNail(const QString&, const QPixmap&); | 62 | virtual void slotThumbNail(const QString&, const QPixmap&); |
65 | 63 | ||
66 | virtual void slotChangeName(const QString&); | 64 | virtual void slotChangeName(const QString&); |
67 | }; | 65 | }; |
68 | 66 | ||
69 | /* for testing purpose */ | 67 | /* for testing purpose */ |
70 | class infoDlg:public QDialog | 68 | class infoDlg:public QDialog |
71 | { | 69 | { |
72 | Q_OBJECT | 70 | Q_OBJECT |
73 | public: | 71 | public: |
74 | infoDlg(const QString&,QWidget * parent=0, const char * name=0); | 72 | infoDlg(const QString&,QWidget * parent=0, const char * name=0); |
75 | virtual ~infoDlg(); | 73 | virtual ~infoDlg(); |
76 | }; | 74 | }; |
77 | 75 | ||
78 | #endif // IMAGEINFO_H | 76 | #endif // IMAGEINFO_H |
diff --git a/noncore/graphics/opie-eye/gui/imageview.cpp b/noncore/graphics/opie-eye/gui/imageview.cpp index e43bbff..2078b19 100644 --- a/noncore/graphics/opie-eye/gui/imageview.cpp +++ b/noncore/graphics/opie-eye/gui/imageview.cpp | |||
@@ -1,61 +1,61 @@ | |||
1 | #include "imageview.h" | 1 | #include "imageview.h" |
2 | 2 | ||
3 | #include <opie2/odebug.h> | 3 | #include <opie2/odebug.h> |
4 | #include <opie2/oconfig.h> | 4 | #include <opie2/oconfig.h> |
5 | #include <opie2/okeyconfigwidget.h> | 5 | #include <opie2/okeyconfigwidget.h> |
6 | 6 | ||
7 | #include <qpe/resource.h> | 7 | #include <qpe/resource.h> |
8 | 8 | ||
9 | using namespace Opie::Core; | 9 | using namespace Opie::Core; |
10 | 10 | ||
11 | ImageView::ImageView(Opie::Core::OConfig *cfg, QWidget* parent, const char* name, WFlags fl ) | 11 | ImageView::ImageView(Opie::Core::OConfig *cfg, QWidget* parent, const char* name, WFlags fl ) |
12 | : ImageScrollView(parent,name,fl) | 12 | : ImageScrollView(parent,name,fl) |
13 | { | 13 | { |
14 | m_viewManager = 0; | 14 | m_viewManager = 0; |
15 | m_cfg = cfg; | 15 | m_cfg = cfg; |
16 | initKeys(); | 16 | initKeys(); |
17 | } | 17 | } |
18 | 18 | ||
19 | ImageView::~ImageView() | 19 | ImageView::~ImageView() |
20 | { | 20 | { |
21 | if (m_viewManager) { | 21 | if (m_viewManager) { |
22 | delete m_viewManager; | 22 | delete m_viewManager; |
23 | } | 23 | } |
24 | } | 24 | } |
25 | 25 | ||
26 | Opie::Ui::OKeyConfigManager* ImageView::manager() | 26 | Opie::Core::OKeyConfigManager* ImageView::manager() |
27 | { | 27 | { |
28 | if (!m_viewManager) { | 28 | if (!m_viewManager) { |
29 | initKeys(); | 29 | initKeys(); |
30 | } | 30 | } |
31 | return m_viewManager; | 31 | return m_viewManager; |
32 | } | 32 | } |
33 | 33 | ||
34 | void ImageView::initKeys() | 34 | void ImageView::initKeys() |
35 | { | 35 | { |
36 | odebug << "init imageview keys" << oendl; | 36 | odebug << "init imageview keys" << oendl; |
37 | if (!m_cfg) { | 37 | if (!m_cfg) { |
38 | m_cfg = new Opie::Core::OConfig("phunkview"); | 38 | m_cfg = new Opie::Core::OConfig("phunkview"); |
39 | m_cfg->setGroup("image_view_keys" ); | 39 | m_cfg->setGroup("image_view_keys" ); |
40 | } | 40 | } |
41 | Opie::Ui::OKeyPair::List lst; | 41 | Opie::Core::OKeyPair::List lst; |
42 | lst.append( Opie::Ui::OKeyPair::upArrowKey() ); | 42 | lst.append( Opie::Core::OKeyPair::upArrowKey() ); |
43 | lst.append( Opie::Ui::OKeyPair::downArrowKey() ); | 43 | lst.append( Opie::Core::OKeyPair::downArrowKey() ); |
44 | lst.append( Opie::Ui::OKeyPair::leftArrowKey() ); | 44 | lst.append( Opie::Core::OKeyPair::leftArrowKey() ); |
45 | lst.append( Opie::Ui::OKeyPair::rightArrowKey() ); | 45 | lst.append( Opie::Core::OKeyPair::rightArrowKey() ); |
46 | lst.append( Opie::Ui::OKeyPair::returnKey() ); | 46 | lst.append( Opie::Core::OKeyPair::returnKey() ); |
47 | 47 | ||
48 | m_viewManager = new Opie::Ui::OKeyConfigManager(m_cfg, "image_view_keys", | 48 | m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "image_view_keys", |
49 | lst, false,this, "image_view_keys" ); | 49 | lst, false,this, "image_view_keys" ); |
50 | m_viewManager->addKeyConfig( Opie::Ui::OKeyConfigItem(tr("View Image Info"), "imageviewinfo", | 50 | m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("View Image Info"), "imageviewinfo", |
51 | Resource::loadPixmap("1to1"), ViewInfo, | 51 | Resource::loadPixmap("1to1"), ViewInfo, |
52 | Opie::Ui::OKeyPair(Qt::Key_I,Qt::ShiftButton), | 52 | Opie::Core::OKeyPair(Qt::Key_I,Qt::ShiftButton), |
53 | this, SLOT(slotShowImageInfo()))); | 53 | this, SLOT(slotShowImageInfo()))); |
54 | m_viewManager->handleWidget( this ); | 54 | m_viewManager->handleWidget( this ); |
55 | m_viewManager->load(); | 55 | m_viewManager->load(); |
56 | } | 56 | } |
57 | 57 | ||
58 | void ImageView::slotShowImageInfo() | 58 | void ImageView::slotShowImageInfo() |
59 | { | 59 | { |
60 | emit dispImageInfo(m_lastName); | 60 | emit dispImageInfo(m_lastName); |
61 | } | 61 | } |
diff --git a/noncore/graphics/opie-eye/gui/imageview.h b/noncore/graphics/opie-eye/gui/imageview.h index f61c93f..87e2b32 100644 --- a/noncore/graphics/opie-eye/gui/imageview.h +++ b/noncore/graphics/opie-eye/gui/imageview.h | |||
@@ -1,40 +1,38 @@ | |||
1 | #ifndef _IMAGE_VIEW_H | 1 | #ifndef _IMAGE_VIEW_H |
2 | #define _IMAGE_VIEW_H | 2 | #define _IMAGE_VIEW_H |
3 | 3 | ||
4 | /* must be changed when it will moved to Opie::MM */ | 4 | /* must be changed when it will moved to Opie::MM */ |
5 | #include "imagescrollview.h" | 5 | #include "imagescrollview.h" |
6 | 6 | ||
7 | namespace Opie { | 7 | namespace Opie { |
8 | namespace Core { | 8 | namespace Core { |
9 | class OConfig; | 9 | class OConfig; |
10 | } | ||
11 | namespace Ui { | ||
12 | class OKeyConfigManager; | 10 | class OKeyConfigManager; |
13 | } | 11 | } |
14 | } | 12 | } |
15 | 13 | ||
16 | class ImageView:public ImageScrollView | 14 | class ImageView:public ImageScrollView |
17 | { | 15 | { |
18 | Q_OBJECT | 16 | Q_OBJECT |
19 | 17 | ||
20 | enum ActionIds { | 18 | enum ActionIds { |
21 | ViewInfo | 19 | ViewInfo |
22 | }; | 20 | }; |
23 | 21 | ||
24 | public: | 22 | public: |
25 | ImageView(Opie::Core::OConfig *cfg, QWidget* parent, const char* name = 0, WFlags fl = 0 ); | 23 | ImageView(Opie::Core::OConfig *cfg, QWidget* parent, const char* name = 0, WFlags fl = 0 ); |
26 | virtual ~ImageView(); | 24 | virtual ~ImageView(); |
27 | Opie::Ui::OKeyConfigManager* manager(); | 25 | Opie::Core::OKeyConfigManager* manager(); |
28 | 26 | ||
29 | signals: | 27 | signals: |
30 | void dispImageInfo(const QString&); | 28 | void dispImageInfo(const QString&); |
31 | void sig_return(); | 29 | void sig_return(); |
32 | 30 | ||
33 | protected: | 31 | protected: |
34 | Opie::Core::OConfig * m_cfg; | 32 | Opie::Core::OConfig * m_cfg; |
35 | Opie::Ui::OKeyConfigManager*m_viewManager; | 33 | Opie::Core::OKeyConfigManager*m_viewManager; |
36 | void initKeys(); | 34 | void initKeys(); |
37 | protected slots: | 35 | protected slots: |
38 | virtual void slotShowImageInfo(); | 36 | virtual void slotShowImageInfo(); |
39 | }; | 37 | }; |
40 | #endif | 38 | #endif |
diff --git a/noncore/graphics/opie-eye/gui/mainwindow.h b/noncore/graphics/opie-eye/gui/mainwindow.h index 042d568..59dba30 100644 --- a/noncore/graphics/opie-eye/gui/mainwindow.h +++ b/noncore/graphics/opie-eye/gui/mainwindow.h | |||
@@ -1,68 +1,70 @@ | |||
1 | /* | 1 | /* |
2 | * GPLv2 zecke@handhelds.org | 2 | * GPLv2 zecke@handhelds.org |
3 | * No WArranty... | 3 | * No WArranty... |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #ifndef PHUNK_MAIN_WINDOW_H | 6 | #ifndef PHUNK_MAIN_WINDOW_H |
7 | #define PHUNK_MAIN_WINDOW_H | 7 | #define PHUNK_MAIN_WINDOW_H |
8 | 8 | ||
9 | #include <opie2/oconfig.h> | 9 | #include <opie2/oconfig.h> |
10 | 10 | ||
11 | #include <qmainwindow.h> | 11 | #include <qmainwindow.h> |
12 | 12 | ||
13 | 13 | ||
14 | 14 | ||
15 | namespace Opie { | 15 | namespace Opie { |
16 | namespace Ui{ | 16 | namespace Ui{ |
17 | class OKeyConfigManager; | ||
18 | class OWidgetStack; | 17 | class OWidgetStack; |
19 | } | 18 | } |
19 | namespace Core{ | ||
20 | class OKeyConfigManager; | ||
21 | } | ||
20 | } | 22 | } |
21 | 23 | ||
22 | class PIconView; | 24 | class PIconView; |
23 | class imageinfo; | 25 | class imageinfo; |
24 | class ImageView; | 26 | class ImageView; |
25 | class PMainWindow : public QMainWindow { | 27 | class PMainWindow : public QMainWindow { |
26 | Q_OBJECT | 28 | Q_OBJECT |
27 | enum Views { IconView, ImageInfo, ImageDisplay }; | 29 | enum Views { IconView, ImageInfo, ImageDisplay }; |
28 | public: | 30 | public: |
29 | static QString appName() { return QString::fromLatin1("opie-eye" ); } | 31 | static QString appName() { return QString::fromLatin1("opie-eye" ); } |
30 | PMainWindow(QWidget*, const char*, WFlags ); | 32 | PMainWindow(QWidget*, const char*, WFlags ); |
31 | ~PMainWindow(); | 33 | ~PMainWindow(); |
32 | 34 | ||
33 | signals: | 35 | signals: |
34 | void configChanged(); | 36 | void configChanged(); |
35 | 37 | ||
36 | public slots: | 38 | public slots: |
37 | void slotShowInfo( const QString& inf ); | 39 | void slotShowInfo( const QString& inf ); |
38 | void slotDisplay( const QString& inf ); | 40 | void slotDisplay( const QString& inf ); |
39 | void slotReturn(); | 41 | void slotReturn(); |
40 | void slotRotateToggled(bool); | 42 | void slotRotateToggled(bool); |
41 | void slotScaleToggled(bool); | 43 | void slotScaleToggled(bool); |
42 | void setDocument( const QString& ); | 44 | void setDocument( const QString& ); |
43 | 45 | ||
44 | protected: | 46 | protected: |
45 | void raiseIconView(); | 47 | void raiseIconView(); |
46 | void closeEvent( QCloseEvent* ); | 48 | void closeEvent( QCloseEvent* ); |
47 | 49 | ||
48 | private: | 50 | private: |
49 | template<class T> void initT( const char* name, T**, int ); | 51 | template<class T> void initT( const char* name, T**, int ); |
50 | void initInfo(); | 52 | void initInfo(); |
51 | void initDisp(); | 53 | void initDisp(); |
52 | 54 | ||
53 | private: | 55 | private: |
54 | Opie::Core::OConfig *m_cfg; | 56 | Opie::Core::OConfig *m_cfg; |
55 | Opie::Ui::OWidgetStack *m_stack; | 57 | Opie::Ui::OWidgetStack *m_stack; |
56 | PIconView* m_view; | 58 | PIconView* m_view; |
57 | imageinfo *m_info; | 59 | imageinfo *m_info; |
58 | ImageView *m_disp; | 60 | ImageView *m_disp; |
59 | bool autoRotate; | 61 | bool autoRotate; |
60 | bool autoScale; | 62 | bool autoScale; |
61 | QToolButton*rotateButton; | 63 | QToolButton*rotateButton; |
62 | 64 | ||
63 | 65 | ||
64 | private slots: | 66 | private slots: |
65 | void slotConfig(); | 67 | void slotConfig(); |
66 | }; | 68 | }; |
67 | 69 | ||
68 | #endif | 70 | #endif |