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
|
#include "VButton.h"
#include <tqvbox.h>
#include <tqfont.h>
#include <tdeconfig.h>
#include <tdeapplication.h>
double VButton::pw=552.0;
double VButton::ph=235.0;
VButton::VButton(TQWidget *parent, const char *name): TQPushButton (parent,name)
{
TDEConfig *cfg = TDEApplication::kApplication()->config();
TQString keysC = cfg->readEntry("keysColor", "#f0f0f0");
setColor(TQColor(keysC));
setFocusPolicy(TQ_NoFocus);
resize(30,30);
press=false;
}
VButton::~VButton()
{
}
void VButton::shiftCapsPressed(bool shift, bool caps)
{
if (isAlpha)
{
// Alpha button, both shift and caps affect its state
if (caps && shift)
{
TQPushButton::setText(capsShiftText);
}
else if (caps)
{
TQPushButton::setText(capsText);
}
else if (shift)
{
TQPushButton::setText(shiftText);
}
else
{
TQPushButton::setText(normalText);
}
}
else
{
// Non alpha button, only shift affects its state
if (shift)
{
TQPushButton::setText(shiftText);
}
else
{
TQPushButton::setText(normalText);
}
}
}
void VButton::setText(const TQString& text)
{
// Need to set the pushbutton text to correctly handle those buttons which usually
// don't change (tab, shift, caps, Fn, ...)
TQPushButton::setText(text);
normalText = text;
capsText = text.upper();
isAlpha = text.length() == 1 && capsText != normalText;
}
void VButton::setShiftText(const TQString& text)
{
shiftText = text;
// 'text' is normally uppercase here, so in most cases we need to set capsShiftText
// to text.lower() to handle caps+shift correctly. Special cases like ç and Ç are
// handled by using text.upper()
if (text.lower() != text)
{
capsShiftText = text.lower();
}
else
{
capsShiftText = text.upper();
}
}
void VButton::setColor(const TQColor &color)
{
setPaletteBackgroundColor(color);
// Need to set TQColorGroup::Button color as well, otherwise the actual
// color of the key does not change until the next restart of the application.
TQPalette plt = palette();
plt.setColor(TQPalette::Active, TQColorGroup::Button, color);
plt.setColor(TQPalette::Inactive, TQColorGroup::Button, color);
plt.setColor(TQPalette::Disabled, TQColorGroup::Button, color);
setPalette(plt);
}
void VButton::setKeyCode(unsigned int keycode)
{
this->keycode=keycode;
}
unsigned int VButton::getKeyCode()
{
return this->keycode;
}
void VButton::sendKey()
{
emit keyClick(keycode);
}
void VButton::reposition(int width, int height)
{
double dx=pw/orig_size.x();
double dy=ph/orig_size.y();
double sdx=pw/orig_size.width();
double sdy=ph/orig_size.height();
move((int)(width/dx),(int)(height/dy));
resize((int)(width/sdx), (int)(height/sdy));
}
void VButton::res()
{
orig_size=geometry();
}
void VButton::enterEvent(TQEvent *e)
{
TQPushButton::enterEvent(e);
inside = true;
}
void VButton::leaveEvent(TQEvent *e)
{
TQPushButton::leaveEvent(e);
inside = false;
}
void VButton::mousePressEvent(TQMouseEvent *e)
{
press=true;
TQPushButton::mousePressEvent(e);
if (!isToggleButton())
{
// non toggle buttons need to send the key here
sendKey();
startTimer(500);
}
}
void VButton::mouseReleaseEvent(TQMouseEvent *e)
{
press=false;
TQPushButton::mouseReleaseEvent(e);
if (hitButton(e->pos()) && isToggleButton())
{
// toggle buttons need to send the key here because the underlying pushbutton state
// is only updated on mouse release
sendKey();
}
killTimers();
inrpt=false;
}
void VButton::timerEvent(TQTimerEvent *)
{
if (!press)
{
inrpt=false;
return;
}
if (press && !inrpt)
{
inrpt=true;
startTimer(120);
return;
}
if (inside)
{
// Send key only if the mouse is still inside the button rectangle
sendKey();
}
}
#include "VButton.moc"
|