Diffstat (limited to 'noncore/games/kpacman/keys.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/kpacman/keys.cpp | 203 |
1 files changed, 203 insertions, 0 deletions
diff --git a/noncore/games/kpacman/keys.cpp b/noncore/games/kpacman/keys.cpp new file mode 100644 index 0000000..c609373 --- a/dev/null +++ b/noncore/games/kpacman/keys.cpp | |||
@@ -0,0 +1,203 @@ | |||
1 | |||
2 | #include "portable.h" | ||
3 | |||
4 | #if defined( KDE2_PORT ) | ||
5 | #include <kapp.h> | ||
6 | #include <kconfig.h> | ||
7 | #include <klocale.h> | ||
8 | #include <kstddirs.h> | ||
9 | #include <kaccel.h> | ||
10 | |||
11 | #include <keys.h> | ||
12 | #include <keys.moc> | ||
13 | #elif defined( QPE_PORT ) | ||
14 | #include <qaccel.h> | ||
15 | #include <qpe/qpeapplication.h> | ||
16 | #include "config.h" | ||
17 | #include "keys.h" | ||
18 | #endif | ||
19 | |||
20 | #include <qpushbt.h> | ||
21 | #include <qlabel.h> | ||
22 | #include <qframe.h> | ||
23 | #include <qkeycode.h> | ||
24 | #include <qpixmap.h> | ||
25 | #include <qstring.h> | ||
26 | |||
27 | Keys::Keys( QWidget *parent, const char *name) | ||
28 | : QDialog( parent, name, TRUE ) | ||
29 | { | ||
30 | //KStandardDirs *dirs = KGlobal::dirs(); | ||
31 | |||
32 | QPushButton *okButton = new QPushButton(this); | ||
33 | okButton->setText(i18n("Ok")); | ||
34 | okButton->setFixedSize(okButton->size()); | ||
35 | connect( okButton, SIGNAL(clicked()),this, SLOT(ok()) ); | ||
36 | okButton->move(20,210); | ||
37 | |||
38 | QPushButton *defaultButton = new QPushButton(this); | ||
39 | defaultButton->setText(i18n("Defaults")); | ||
40 | defaultButton->setFixedSize(defaultButton->size()); | ||
41 | connect( defaultButton, SIGNAL(clicked()),this, SLOT(defaults()) ); | ||
42 | defaultButton->move(140,210); | ||
43 | |||
44 | QPushButton *cancelButton = new QPushButton(this); | ||
45 | cancelButton->setText(i18n("Cancel")); | ||
46 | cancelButton->setFixedSize(cancelButton->size()); | ||
47 | connect( cancelButton, SIGNAL(clicked()),this, SLOT(reject()) ); | ||
48 | cancelButton->move(260,210); | ||
49 | |||
50 | QFrame *separator = new QFrame(this); | ||
51 | separator->setFrameStyle( QFrame::HLine | QFrame::Sunken ); | ||
52 | separator->setGeometry( 20, 190, 340, 4 ); | ||
53 | |||
54 | for ( int x = 0; x < 4; x++) { | ||
55 | QLabel *l = new QLabel(this); | ||
56 | l->setAlignment(AlignCenter); | ||
57 | labels[x] = l; | ||
58 | } | ||
59 | |||
60 | labels[0]->setGeometry(120, 20, 140, 20 ); | ||
61 | labels[1]->setGeometry(120,160, 140, 20 ); | ||
62 | labels[2]->setGeometry( 20, 92, 100, 20 ); | ||
63 | labels[3]->setGeometry(265, 92, 100, 20 ); | ||
64 | |||
65 | QString pixPath; | ||
66 | |||
67 | QPushButton *up = new QPushButton(this); | ||
68 | pixPath = FIND_APP_DATA( "pics/up.xpm" ); | ||
69 | up->setPixmap( QPixmap(pixPath)); | ||
70 | up->setFixedSize(up->pixmap()->size()); | ||
71 | connect( up, SIGNAL(clicked()),this, SLOT(butUp()) ); | ||
72 | up->move(180, 50); | ||
73 | |||
74 | QPushButton *down = new QPushButton(this); | ||
75 | pixPath = FIND_APP_DATA( "pics/down.xpm"); | ||
76 | down->setPixmap( QPixmap(pixPath)); | ||
77 | down->setFixedSize(down->pixmap()->size()); | ||
78 | connect( down, SIGNAL(clicked()),this, SLOT(butDown()) ); | ||
79 | down->move(180, 130); | ||
80 | |||
81 | QPushButton *left = new QPushButton(this); | ||
82 | pixPath = FIND_APP_DATA( "pics/left.xpm"); | ||
83 | left->setPixmap( QPixmap(pixPath)); | ||
84 | left->setFixedSize(left->pixmap()->size()); | ||
85 | connect( left, SIGNAL(clicked()),this, SLOT(butLeft()) ); | ||
86 | left->move(140, 90); | ||
87 | |||
88 | QPushButton *right = new QPushButton(this); | ||
89 | pixPath = FIND_APP_DATA( "pics/right.xpm"); | ||
90 | right->setPixmap( QPixmap(pixPath)); | ||
91 | right->setFixedSize(right->pixmap()->size()); | ||
92 | connect( right, SIGNAL(clicked()),this, SLOT(butRight()) ); | ||
93 | right->move(220, 90); | ||
94 | |||
95 | |||
96 | setCaption(i18n("Change Direction Keys")); | ||
97 | setFixedSize(380, 260); | ||
98 | lab = 0; | ||
99 | init(); | ||
100 | } | ||
101 | |||
102 | void Keys::keyPressEvent( QKeyEvent *e ) | ||
103 | { | ||
104 | uint kCode = e->key() & ~(SHIFT | CTRL | ALT); | ||
105 | QString string = KAccel::keyToString(kCode); | ||
106 | |||
107 | if (lab != 0) { | ||
108 | if ( string.isNull() ) | ||
109 | lab->setText(i18n("Undefined key")); | ||
110 | else | ||
111 | lab->setText(string); | ||
112 | } | ||
113 | else if ( lab == 0 && e->key() == Key_Escape) | ||
114 | reject(); | ||
115 | } | ||
116 | |||
117 | void Keys::butUp() | ||
118 | { | ||
119 | getKey(0); | ||
120 | } | ||
121 | |||
122 | void Keys::butDown() | ||
123 | { | ||
124 | getKey(1); | ||
125 | } | ||
126 | |||
127 | void Keys::butLeft() | ||
128 | { | ||
129 | getKey(2); | ||
130 | } | ||
131 | |||
132 | void Keys::butRight() | ||
133 | { | ||
134 | getKey(3); | ||
135 | } | ||
136 | |||
137 | void Keys::getKey(int i) | ||
138 | { | ||
139 | if ( lab != 0) | ||
140 | focusOut(lab); | ||
141 | |||
142 | focusIn(labels[i]); | ||
143 | } | ||
144 | |||
145 | void Keys::focusOut(QLabel *l) | ||
146 | { | ||
147 | l->setFrameStyle( QFrame::NoFrame ); | ||
148 | l->setBackgroundColor(backgroundColor()); | ||
149 | l->repaint(); | ||
150 | } | ||
151 | |||
152 | void Keys::focusIn(QLabel *l) | ||
153 | { | ||
154 | lab = l; | ||
155 | lab->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | ||
156 | lab->setBackgroundColor(white); | ||
157 | lab->repaint(); | ||
158 | } | ||
159 | |||
160 | void Keys::defaults() | ||
161 | { | ||
162 | if ( lab != 0) | ||
163 | focusOut(lab); | ||
164 | |||
165 | lab = 0; | ||
166 | |||
167 | labels[0]->setText("Up"); | ||
168 | labels[1]->setText("Down"); | ||
169 | labels[2]->setText("Left"); | ||
170 | labels[3]->setText("Right"); | ||
171 | } | ||
172 | |||
173 | void Keys::init() | ||
174 | { | ||
175 | APP_CONFIG_BEGIN( cfg ); | ||
176 | QString up("Up"); | ||
177 | up = cfg->readEntry("upKey", (const char*) up); | ||
178 | labels[0]->setText(up); | ||
179 | |||
180 | QString down("Down"); | ||
181 | down = cfg->readEntry("downKey", (const char*) down); | ||
182 | labels[1]->setText(down); | ||
183 | |||
184 | QString left("Left"); | ||
185 | left = cfg->readEntry("leftKey", (const char*) left); | ||
186 | labels[2]->setText(left); | ||
187 | |||
188 | QString right("Right"); | ||
189 | right = cfg->readEntry("rightKey", (const char*) right); | ||
190 | labels[3]->setText(right); | ||
191 | APP_CONFIG_END( cfg ); | ||
192 | } | ||
193 | |||
194 | void Keys::ok() | ||
195 | { | ||
196 | APP_CONFIG_BEGIN( cfg ); | ||
197 | cfg->writeEntry("upKey", (const char*) labels[0]->text() ); | ||
198 | cfg->writeEntry("downKey", (const char*) labels[1]->text() ); | ||
199 | cfg->writeEntry("leftKey", (const char*) labels[2]->text() ); | ||
200 | cfg->writeEntry("rightKey",(const char*) labels[3]->text() ); | ||
201 | APP_CONFIG_END( cfg ); | ||
202 | accept(); | ||
203 | } | ||