summaryrefslogtreecommitdiff
path: root/core/settings/button/remapdlg.cpp
authorsandman <sandman>2002-12-22 23:46:02 (UTC)
committer sandman <sandman>2002-12-22 23:46:02 (UTC)
commit92fb302dd801e7f568cd9d66025431e79dad9771 (patch) (unidiff)
tree1303acdd800fd01d221a1aa261f2ee730ada4ec1 /core/settings/button/remapdlg.cpp
parentc5de1fcc13b32e7c1f893dc3f8a1385b8698ebaf (diff)
downloadopie-92fb302dd801e7f568cd9d66025431e79dad9771.zip
opie-92fb302dd801e7f568cd9d66025431e79dad9771.tar.gz
opie-92fb302dd801e7f568cd9d66025431e79dad9771.tar.bz2
New button settings -- replaces AppsKey, which does not work anymore with
the new device button framework
Diffstat (limited to 'core/settings/button/remapdlg.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/settings/button/remapdlg.cpp119
1 files changed, 119 insertions, 0 deletions
diff --git a/core/settings/button/remapdlg.cpp b/core/settings/button/remapdlg.cpp
new file mode 100644
index 0000000..511d0e7
--- a/dev/null
+++ b/core/settings/button/remapdlg.cpp
@@ -0,0 +1,119 @@
1#include <qlistview.h>
2#include <qlabel.h>
3#include <qcombobox.h>
4
5#include "remapdlg.h"
6#include "buttonutils.h"
7
8using namespace Opie;
9
10class NoSortItem : public QListViewItem {
11public:
12 NoSortItem ( QListView *lv, uint pos, const QString &str, const QCString &s1 = 0, const QCString &s2 = 0 )
13 : QListViewItem ( lv, str, s1, s2 )
14 {
15 m_key = QString ( QChar ( 'a' + pos ));
16 m_def = false;
17 }
18
19 void setDefault ( bool b )
20 {
21 m_def = b;
22 }
23
24 virtual QString key ( int /*column*/, bool /*ascending*/ ) const
25 {
26 return m_key;
27 }
28
29 virtual void paintCell ( QPainter * p, const QColorGroup & cg, int column, int width, int align )
30 {
31 if ( m_def ) {
32 QFont f ( listView ( )-> font ( ));
33 f. setBold ( true );
34 p-> setFont ( f );
35 }
36 QListViewItem::paintCell ( p, cg, column, width, align );
37 }
38
39private:
40 QString m_key;
41 bool m_def;
42};
43
44
45RemapDlg::RemapDlg ( const Opie::ODeviceButton *b, bool hold, QWidget *parent, const char *name )
46 : RemapDlgBase ( parent, name, true, WStyle_ContextHelp )
47{
48 setCaption ( tr( "%1 %2", "(hold|press) buttoname" ). arg( hold ? tr( "Held" ) : tr( "Pressed" )). arg ( b-> userText ( )));
49
50 m_msg = hold ? b-> heldAction ( ) : b-> pressedAction ( );
51 m_msg_preset = hold ? b-> factoryPresetHeldAction ( ) : b-> factoryPresetPressedAction ( );
52
53 m_map_none = new NoSortItem ( w_list, 0, tr( "No mapping" ));
54 m_map_preset = new NoSortItem ( w_list, 1, tr( "Default" ), m_msg_preset. channel ( ), m_msg_preset. message ( ));
55 ((NoSortItem *) m_map_preset )-> setDefault ( true );
56 m_map_custom = new NoSortItem ( w_list, 2, tr( "Custom" ), m_msg. channel ( ), m_msg. message ( ));
57
58 QListViewItem *it = new NoSortItem ( w_list, 3, tr( "Actions" ));
59 ButtonUtils::inst ( )-> insertActions ( it );
60 it-> setOpen ( true );
61
62 it = new NoSortItem ( w_list, 4, tr( "Show" ));
63 ButtonUtils::inst ( )-> insertAppLnks ( it );
64
65 m_current = m_map_custom;
66 w_list-> setCurrentItem ( m_current );
67
68 static const char * const def_channels [] = {
69 "QPE/Application/", "QPE/Launcher", "QPE/System", "QPE/TaskBar", "QPE/", 0
70 };
71
72 w_channel-> insertStrList ((const char **) def_channels );
73}
74
75RemapDlg::~RemapDlg ( )
76{
77}
78
79void RemapDlg::itemChanged ( QListViewItem *it )
80{
81 bool enabled = false;
82 OQCopMessage m;
83
84 m_current = it;
85
86 if ( it == m_map_none )
87 m_msg = m = OQCopMessage ( 0, 0 );
88 else if ( it == m_map_preset )
89 m_msg = m = m_msg_preset;
90 else if ( it && !it-> childCount ( )) {
91 enabled = ( it == m_map_custom );
92 m_msg = m = OQCopMessage ( it-> text ( 1 ). latin1 ( ), it-> text ( 2 ). latin1 ( ));
93 }
94
95 w_channel-> setEnabled ( enabled );
96 w_message-> setEnabled ( enabled );
97
98 w_channel-> setEditText ( m. channel ( ));
99 w_message-> setEditText ( m. message ( ));
100}
101
102void RemapDlg::textChanged ( const QString &str )
103{
104 if ( !m_current )
105 return;
106
107 QComboBox *which = (QComboBox *) sender ( );
108
109 if ( which == w_channel )
110 m_current-> setText ( 1, str );
111 else if ( which == w_message )
112 m_current-> setText ( 2, str );
113}
114
115OQCopMessage RemapDlg::message ( )
116{
117 return m_msg;
118}
119