1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
#include <kapp.h>
#include <kconfig.h>
#include <klocale.h>
#include <kstddirs.h>
#include <keys.h>
#include <kaccel.h>
#include <ntqpushbt.h>
#include <ntqlabel.h>
#include <ntqframe.h>
#include <ntqkeycode.h>
#include <ntqpixmap.h>
#include <ntqstring.h>
Keys::Keys( TQWidget *parent, const char *name)
: TQDialog( parent, name, TRUE )
{
KStandardDirs *dirs = KGlobal::dirs();
TQPushButton *okButton = new TQPushButton(this);
okButton->setText(i18n("Ok"));
okButton->setFixedSize(okButton->size());
connect( okButton, SIGNAL(clicked()),this, SLOT(ok()) );
okButton->move(20,210);
TQPushButton *defaultButton = new TQPushButton(this);
defaultButton->setText(i18n("Defaults"));
defaultButton->setFixedSize(defaultButton->size());
connect( defaultButton, SIGNAL(clicked()),this, SLOT(defaults()) );
defaultButton->move(140,210);
TQPushButton *cancelButton = new TQPushButton(this);
cancelButton->setText(i18n("Cancel"));
cancelButton->setFixedSize(cancelButton->size());
connect( cancelButton, SIGNAL(clicked()),this, SLOT(reject()) );
cancelButton->move(260,210);
TQFrame *separator = new TQFrame(this);
separator->setFrameStyle( TQFrame::HLine | TQFrame::Sunken );
separator->setGeometry( 20, 190, 340, 4 );
for ( int x = 0; x < 4; x++) {
TQLabel *l = new TQLabel(this);
l->setAlignment(AlignCenter);
labels[x] = l;
}
labels[0]->setGeometry(120, 20, 140, 20 );
labels[1]->setGeometry(120,160, 140, 20 );
labels[2]->setGeometry( 20, 92, 100, 20 );
labels[3]->setGeometry(265, 92, 100, 20 );
TQString pixPath;
TQPushButton *up = new TQPushButton(this);
pixPath = dirs->findResource("appdata", "pics/up.xpm");
up->setPixmap( TQPixmap(pixPath));
up->setFixedSize(up->pixmap()->size());
connect( up, SIGNAL(clicked()),this, SLOT(butUp()) );
up->move(180, 50);
TQPushButton *down = new TQPushButton(this);
pixPath = dirs->findResource("appdata", "pics/down.xpm");
down->setPixmap( TQPixmap(pixPath));
down->setFixedSize(down->pixmap()->size());
connect( down, SIGNAL(clicked()),this, SLOT(butDown()) );
down->move(180, 130);
TQPushButton *left = new TQPushButton(this);
pixPath = dirs->findResource("appdata", "pics/left.xpm");
left->setPixmap( TQPixmap(pixPath));
left->setFixedSize(left->pixmap()->size());
connect( left, SIGNAL(clicked()),this, SLOT(butLeft()) );
left->move(140, 90);
TQPushButton *right = new TQPushButton(this);
pixPath = dirs->findResource("appdata", "pics/right.xpm");
right->setPixmap( TQPixmap(pixPath));
right->setFixedSize(right->pixmap()->size());
connect( right, SIGNAL(clicked()),this, SLOT(butRight()) );
right->move(220, 90);
setCaption(i18n("Change Direction Keys"));
setFixedSize(380, 260);
lab = 0;
init();
}
void Keys::keyPressEvent( TQKeyEvent *e )
{
uint kCode = e->key() & ~(SHIFT | CTRL | ALT);
TQString string = KAccel::keyToString(kCode);
if (lab != 0) {
if ( string.isNull() )
lab->setText(i18n("Undefined key"));
else
lab->setText(string);
}
else if ( lab == 0 && e->key() == Key_Escape)
reject();
}
void Keys::butUp()
{
getKey(0);
}
void Keys::butDown()
{
getKey(1);
}
void Keys::butLeft()
{
getKey(2);
}
void Keys::butRight()
{
getKey(3);
}
void Keys::getKey(int i)
{
if ( lab != 0)
focusOut(lab);
focusIn(labels[i]);
}
void Keys::focusOut(TQLabel *l)
{
l->setFrameStyle( TQFrame::NoFrame );
l->setBackgroundColor(backgroundColor());
l->repaint();
}
void Keys::focusIn(TQLabel *l)
{
lab = l;
lab->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
lab->setBackgroundColor(white);
lab->repaint();
}
void Keys::defaults()
{
if ( lab != 0)
focusOut(lab);
lab = 0;
labels[0]->setText("Up");
labels[1]->setText("Down");
labels[2]->setText("Left");
labels[3]->setText("Right");
}
void Keys::init()
{
TQString up("Up");
up = kapp->config()->readEntry("upKey", (const char*) up);
labels[0]->setText(up);
TQString down("Down");
down = kapp->config()->readEntry("downKey", (const char*) down);
labels[1]->setText(down);
TQString left("Left");
left = kapp->config()->readEntry("leftKey", (const char*) left);
labels[2]->setText(left);
TQString right("Right");
right = kapp->config()->readEntry("rightKey", (const char*) right);
labels[3]->setText(right);
}
void Keys::ok()
{
kapp->config()->writeEntry("upKey", (const char*) labels[0]->text() );
kapp->config()->writeEntry("downKey", (const char*) labels[1]->text() );
kapp->config()->writeEntry("leftKey", (const char*) labels[2]->text() );
kapp->config()->writeEntry("rightKey",(const char*) labels[3]->text() );
kapp->config()->sync();
accept();
}
|