Diffstat (limited to 'core/settings/button/remapdlg.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/settings/button/remapdlg.cpp | 72 |
1 files changed, 39 insertions, 33 deletions
diff --git a/core/settings/button/remapdlg.cpp b/core/settings/button/remapdlg.cpp index 4effebc..cadb955 100644 --- a/core/settings/button/remapdlg.cpp +++ b/core/settings/button/remapdlg.cpp | |||
@@ -1,136 +1,142 @@ | |||
1 | |||
2 | #include "remapdlg.h" | ||
3 | #include "buttonutils.h" | ||
4 | |||
5 | /* OPIE */ | ||
6 | #include <opie2/odebug.h> | ||
7 | |||
8 | /* QT */ | ||
1 | #include <qlistview.h> | 9 | #include <qlistview.h> |
2 | #include <qcombobox.h> | 10 | #include <qcombobox.h> |
3 | #include <qtimer.h> | 11 | #include <qtimer.h> |
4 | 12 | ||
5 | #include "remapdlg.h" | ||
6 | #include "buttonutils.h" | ||
7 | 13 | ||
8 | 14 | ||
9 | using namespace Opie::Core; | 15 | using namespace Opie::Core; |
10 | class NoSortItem : public QListViewItem { | 16 | class NoSortItem : public QListViewItem { |
11 | public: | 17 | public: |
12 | NoSortItem ( QListView *lv, uint pos, const QString &str, const QCString &s1 = 0, const QCString &s2 = 0 ) | 18 | NoSortItem ( QListView *lv, uint pos, const QString &str, const QCString &s1 = 0, const QCString &s2 = 0 ) |
13 | : QListViewItem ( lv, str, s1, s2 ) | 19 | : QListViewItem ( lv, str, s1, s2 ) |
14 | { | 20 | { |
15 | m_key = QString ( QChar ( 'a' + pos )); | 21 | m_key = QString ( QChar ( 'a' + pos )); |
16 | m_def = false; | 22 | m_def = false; |
17 | } | 23 | } |
18 | 24 | ||
19 | void setDefault ( bool b ) | 25 | void setDefault ( bool b ) |
20 | { | 26 | { |
21 | m_def = b; | 27 | m_def = b; |
22 | } | 28 | } |
23 | 29 | ||
24 | virtual QString key ( int /*column*/, bool /*ascending*/ ) const | 30 | virtual QString key ( int /*column*/, bool /*ascending*/ ) const |
25 | { | 31 | { |
26 | return m_key; | 32 | return m_key; |
27 | } | 33 | } |
28 | 34 | ||
29 | virtual void paintCell ( QPainter * p, const QColorGroup & cg, int column, int width, int align ) | 35 | virtual void paintCell ( QPainter * p, const QColorGroup & cg, int column, int width, int align ) |
30 | { | 36 | { |
31 | if ( m_def ) { | 37 | if ( m_def ) { |
32 | QFont f ( listView ( )-> font ( )); | 38 | QFont f ( listView ( )-> font ( )); |
33 | f. setBold ( true ); | 39 | f. setBold ( true ); |
34 | p-> setFont ( f ); | 40 | p-> setFont ( f ); |
35 | } | 41 | } |
36 | QListViewItem::paintCell ( p, cg, column, width, align ); | 42 | QListViewItem::paintCell ( p, cg, column, width, align ); |
37 | } | 43 | } |
38 | 44 | ||
39 | private: | 45 | private: |
40 | QString m_key; | 46 | QString m_key; |
41 | bool m_def; | 47 | bool m_def; |
42 | }; | 48 | }; |
43 | 49 | ||
44 | 50 | ||
45 | RemapDlg::RemapDlg ( const Opie::Core::ODeviceButton *b, bool hold, QWidget *parent, const char *name ) | 51 | RemapDlg::RemapDlg ( const Opie::Core::ODeviceButton *b, bool hold, QWidget *parent, const char *name ) |
46 | : RemapDlgBase ( parent, name, true, WStyle_ContextHelp ) | 52 | : RemapDlgBase ( parent, name, true, WStyle_ContextHelp ) |
47 | { | 53 | { |
48 | setCaption ( tr( "%1 %2", "(hold|press) buttoname" ). arg( hold ? tr( "Held" ) : tr( "Pressed" )). arg ( b-> userText ( ))); | 54 | setCaption ( tr( "%1 %2", "(hold|press) buttoname" ). arg( hold ? tr( "Held" ) : tr( "Pressed" )). arg ( b-> userText ( ))); |
49 | 55 | ||
50 | m_current = 0; | 56 | m_current = 0; |
51 | 57 | ||
52 | static const char * const def_channels [] = { "QPE/Application/", "QPE/Launcher", "QPE/System", "QPE/TaskBar", "QPE/", 0 }; | 58 | static const char * const def_channels [] = { "QPE/Application/", "QPE/Launcher", "QPE/System", "QPE/TaskBar", "QPE/", 0 }; |
53 | w_channel-> insertStrList ((const char **) def_channels ); | 59 | w_channel-> insertStrList ((const char **) def_channels ); |
54 | 60 | ||
55 | m_msg = hold ? b-> heldAction ( ) : b-> pressedAction ( ); | 61 | m_msg = hold ? b-> heldAction ( ) : b-> pressedAction ( ); |
56 | m_msg_preset = hold ? b-> factoryPresetHeldAction ( ) : b-> factoryPresetPressedAction ( ); | 62 | m_msg_preset = hold ? b-> factoryPresetHeldAction ( ) : b-> factoryPresetPressedAction ( ); |
57 | 63 | ||
58 | m_map_none = new NoSortItem ( w_list, 0, tr( "No mapping" )); | 64 | m_map_none = new NoSortItem ( w_list, 0, tr( "No mapping" )); |
59 | m_map_preset = new NoSortItem ( w_list, 1, tr( "Default" ), m_msg_preset. channel ( ), m_msg_preset. message ( )); | 65 | m_map_preset = new NoSortItem ( w_list, 1, tr( "Default" ), m_msg_preset. channel ( ), m_msg_preset. message ( )); |
60 | ((NoSortItem *) m_map_preset )-> setDefault ( true ); | 66 | ((NoSortItem *) m_map_preset )-> setDefault ( true ); |
61 | 67 | ||
62 | if (m_msg. channel ( ) == "ignore") | 68 | if (m_msg. channel ( ) == "ignore") |
63 | { | 69 | { |
64 | m_map_custom = new NoSortItem ( w_list, 2, tr( "Custom" ), m_msg_preset. channel ( ), m_msg_preset. message ( )); | 70 | m_map_custom = new NoSortItem ( w_list, 2, tr( "Custom" ), m_msg_preset. channel ( ), m_msg_preset. message ( )); |
65 | 71 | ||
66 | m_current = m_map_none; | 72 | m_current = m_map_none; |
67 | } | 73 | } |
68 | else | 74 | else |
69 | { | 75 | { |
70 | m_map_custom = new NoSortItem ( w_list, 2, tr( "Custom" ), m_msg. channel ( ), m_msg. message ( )); | 76 | m_map_custom = new NoSortItem ( w_list, 2, tr( "Custom" ), m_msg. channel ( ), m_msg. message ( )); |
71 | m_current = m_map_custom; | 77 | m_current = m_map_custom; |
72 | } | 78 | } |
73 | 79 | ||
74 | QListViewItem *it = new NoSortItem ( w_list, 3, tr( "Actions" )); | 80 | QListViewItem *it = new NoSortItem ( w_list, 3, tr( "Actions" )); |
75 | ButtonUtils::inst ( )-> insertActions ( it ); | 81 | ButtonUtils::inst ( )-> insertActions ( it ); |
76 | it-> setOpen ( true ); | 82 | it-> setOpen ( true ); |
77 | 83 | ||
78 | m_map_show = new NoSortItem ( w_list, 4, tr( "Show" )); | 84 | m_map_show = new NoSortItem ( w_list, 4, tr( "Show" )); |
79 | 85 | ||
80 | w_list-> setCurrentItem ( m_current ); | 86 | w_list-> setCurrentItem ( m_current ); |
81 | 87 | ||
82 | QTimer::singleShot ( 0, this, SLOT( delayedInit())); | 88 | QTimer::singleShot ( 0, this, SLOT( delayedInit())); |
83 | } | 89 | } |
84 | 90 | ||
85 | RemapDlg::~RemapDlg ( ) | 91 | RemapDlg::~RemapDlg ( ) |
86 | { | 92 | { |
87 | } | 93 | } |
88 | 94 | ||
89 | void RemapDlg::delayedInit ( ) | 95 | void RemapDlg::delayedInit ( ) |
90 | { | 96 | { |
91 | bool b = w_list-> viewport ( )-> isUpdatesEnabled ( ); | 97 | bool b = w_list-> viewport ( )-> isUpdatesEnabled ( ); |
92 | w_list-> viewport ( )-> setUpdatesEnabled ( false ); | 98 | w_list-> viewport ( )-> setUpdatesEnabled ( false ); |
93 | 99 | ||
94 | ButtonUtils::inst ( )-> insertAppLnks ( m_map_show ); | 100 | ButtonUtils::inst ( )-> insertAppLnks ( m_map_show ); |
95 | 101 | ||
96 | w_list-> viewport ( )-> setUpdatesEnabled ( b ); | 102 | w_list-> viewport ( )-> setUpdatesEnabled ( b ); |
97 | 103 | ||
98 | m_map_show-> repaint ( ); | 104 | m_map_show-> repaint ( ); |
99 | } | 105 | } |
100 | 106 | ||
101 | void RemapDlg::itemChanged ( QListViewItem *it ) | 107 | void RemapDlg::itemChanged ( QListViewItem *it ) |
102 | { | 108 | { |
103 | bool enabled = false; | 109 | bool enabled = false; |
104 | OQCopMessage m; | 110 | OQCopMessage m; |
105 | 111 | ||
106 | m_current = it; | 112 | m_current = it; |
107 | 113 | ||
108 | if ( it == m_map_none ) | 114 | if ( it == m_map_none ) |
109 | { | 115 | { |
110 | m_msg = m = OQCopMessage ( "ignore", 0 ); | 116 | m_msg = m = OQCopMessage ( "ignore", 0 ); |
111 | qDebug ("***ignoring"); | 117 | odebug << "***ignoring" << oendl; |
112 | } | 118 | } |
113 | else if ( it == m_map_preset ) | 119 | else if ( it == m_map_preset ) |
114 | { | 120 | { |
115 | m_msg = m = m_msg_preset; | 121 | m_msg = m = m_msg_preset; |
116 | qDebug ("***Preset"); | 122 | odebug << "***Preset" << oendl; |
117 | } | 123 | } |
118 | else if ( it && !it-> childCount ( ) ) | 124 | else if ( it && !it-> childCount ( ) ) |
119 | { | 125 | { |
120 | qDebug ("***Custom: %s %s ",it-> text ( 1 ). latin1 ( ), it-> text ( 2 ). latin1 ( )); | 126 | odebug << "***Custom: " << it-> text ( 1 ). latin1 ( ) << " " << it-> text ( 2 ). latin1 ( ) << oendl; |
121 | enabled = ( it == m_map_custom ); | 127 | enabled = ( it == m_map_custom ); |
122 | m_msg = m = OQCopMessage ( it-> text ( 1 ). latin1 ( ), it-> text ( 2 ). latin1 ( )); | 128 | m_msg = m = OQCopMessage ( it-> text ( 1 ). latin1 ( ), it-> text ( 2 ). latin1 ( )); |
123 | } | 129 | } |
124 | 130 | ||
125 | w_channel-> setEnabled ( enabled ); | 131 | w_channel-> setEnabled ( enabled ); |
126 | w_message-> setEnabled ( enabled ); | 132 | w_message-> setEnabled ( enabled ); |
127 | 133 | ||
128 | w_channel-> setEditText ( m. channel ( )); | 134 | w_channel-> setEditText ( m. channel ( )); |
129 | //hack for if user has typed in a message, such as 'suspend()' | 135 | //hack for if user has typed in a message, such as 'suspend()' |
130 | //so raise() is always present | 136 | //so raise() is always present |
131 | if(m. message ( ) != "raise()") | 137 | if(m. message ( ) != "raise()") |
132 | w_message->insertItem("raise()"); | 138 | w_message->insertItem("raise()"); |
133 | w_message-> setEditText ( m. message ( )); | 139 | w_message-> setEditText ( m. message ( )); |
134 | } | 140 | } |
135 | 141 | ||
136 | void RemapDlg::textChanged ( const QString &str ) | 142 | void RemapDlg::textChanged ( const QString &str ) |
@@ -146,10 +152,10 @@ void RemapDlg::textChanged ( const QString &str ) | |||
146 | m_current-> setText ( 2, str ); | 152 | m_current-> setText ( 2, str ); |
147 | } | 153 | } |
148 | 154 | ||
149 | OQCopMessage RemapDlg::message ( ) | 155 | OQCopMessage RemapDlg::message ( ) |
150 | { | 156 | { |
151 | //make sure to update message if typed in | 157 | //make sure to update message if typed in |
152 | itemChanged(w_list->currentItem()); | 158 | itemChanged(w_list->currentItem()); |
153 | return m_msg; | 159 | return m_msg; |
154 | } | 160 | } |
155 | 161 | ||