78
57
setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
79
58
setFocusPolicy(Qt::NoFocus);
80
59
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
60
setBackgroundHints(Plasma::Applet::TranslucentBackground);
82
62
Helpers::buildUp();
84
isAlternative = false;
86
m_layout = new QGraphicsGridLayout(this);
90
tooltip = new Tooltip("");
92
switcher = new Plasma::Label(this);
94
m_layout->addItem(switcher, 0, 0, 1, 10, Qt::AlignRight);
95
m_layout->setRowMinimumHeight ( 0, 10 );
96
m_layout->setRowPreferredHeight ( 0, 10 );
97
m_layout->setRowMaximumHeight ( 0, 15 );
98
QObject::connect(switcher, SIGNAL( linkActivated(QString) ), parent, SLOT( toggleMode() ) );
100
engine = dataEngine("keystate");
102
engine -> connectAllSources(this);
107
PlasmaboardWidget::~PlasmaboardWidget(){
112
void PlasmaboardWidget::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data){
64
m_isAlternative = false;
66
m_isRepeating = false;
68
m_tooltip = new Tooltip("");
70
m_frame = new Plasma::FrameSvg();
71
m_frame->setCacheAllRenderedFrames(false);
72
m_frame->setImagePath("widgets/button");
73
m_frame->setElementPrefix("normal");
75
m_activeFrame = new Plasma::FrameSvg();
76
m_activeFrame->setCacheAllRenderedFrames(false);
77
m_activeFrame->setImagePath("widgets/button");
78
m_activeFrame->setElementPrefix("pressed");
80
m_engine = dataEngine("keystate");
82
m_engine -> connectAllSources(this);
85
m_repeatTimer = new QTimer(this);
86
connect(m_repeatTimer, SIGNAL(timeout()), this, SLOT(repeatKeys()));
87
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(themeChanged()));
92
PlasmaboardWidget::~PlasmaboardWidget()
99
qDeleteAll(m_activeFrames);
102
void PlasmaboardWidget::change(FuncKey *key, bool state)
110
void PlasmaboardWidget::clear()
112
Q_FOREACH(BoardKey* key, m_pressedList){
119
void PlasmaboardWidget::clearTooltip()
124
FuncKey* PlasmaboardWidget::createFunctionKey(QPoint &point, QSize &size, QString action)
128
StickyKey *k = new StickyKey(point, size, Helpers::keysymToKeycode(XK_Alt_L), QString(i18n("Alt")));
132
else if(action == "ALTGR"){
133
StickyKey *k = new StickyKey(point, size, Helpers::keysymToKeycode(XK_ISO_Level3_Shift), QString( i18nc("The Alt Gr key on a keyboard", "Alt Gr")));
137
else if(action == "BACKSPACE")
138
return new BackspaceKey(point, size);
139
else if(action == "CAPSLOCK"){
140
CapsKey *k = new CapsKey(point, size);
144
else if(action == "CONTROLLEFT"){
145
StickyKey *k = new StickyKey(point, size, Helpers::keysymToKeycode(XK_Control_L), QString(i18nc("The Ctrl key on a keyboard", "Ctrl")));
149
else if(action == "CONTROLRIGHT"){
150
StickyKey *k = new StickyKey(point, size, Helpers::keysymToKeycode(XK_Control_R), QString(i18nc("The Ctrl key on a keyboard", "Ctrl")));
154
else if(action == "ENTER")
155
return new EnterKey(point, size);
156
else if(action == "SHIFT") {
157
ShiftKey *k = new ShiftKey(point, size);
161
else if(action == "SPACE")
162
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_space), QString());
163
else if(action == "SUPERLEFT"){
164
StickyKey *k = new StickyKey(point, size, Helpers::keysymToKeycode(XK_Super_L), QString( i18nc("The super (windows) key on a keyboard", "Super")));
168
else if(action == "TAB")
169
return new TabKey(point, size);
170
else if(action == "ESCAPE")
171
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_Escape), QString(i18nc("The escape key on a keyboard", "Esc")));
172
else if(action == "F1")
173
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_F1), QString(i18n("F1")));
174
else if(action == "F2")
175
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_F2), QString(i18n("F2")));
176
else if(action == "F3")
177
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_F3), QString(i18n("F3")));
178
else if(action == "F4")
179
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_F4), QString(i18n("F4")));
180
else if(action == "F5")
181
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_F5), QString(i18n("F5")));
182
else if(action == "F6")
183
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_F6), QString(i18n("F6")));
184
else if(action == "F7")
185
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_F7), QString(i18n("F7")));
186
else if(action == "F8")
187
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_F8), QString(i18n("F8")));
188
else if(action == "F9")
189
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_F9), QString(i18n("F9")));
190
else if(action == "F10")
191
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_F10), QString(i18n("F10")));
192
else if(action == "F11")
193
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_F11), QString(i18n("F11")));
194
else if(action == "F12")
195
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_F12), QString(i18n("F12")));
196
else if(action == "PRINT")
197
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_Print), QString(i18nc("The print key on a keyboard", "Print")));
198
else if(action == "NUM")
199
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_Num_Lock), QString(i18nc("The num key on a keyboard", "Num")));
200
else if(action == "PAUSE")
201
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_Pause), QString(i18nc("The pause key on a keyboard", "Pause")));
202
else if(action == "HOME")
203
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_Home), QString(i18nc("The home key on a keyboard", "Home")));
204
else if(action == "DEL")
205
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_Delete), QString(i18nc("The delete key on a keyboard", "Del")));
206
else if(action == "END")
207
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_End), QString(i18nc("The end key on a keyboard", "End")));
208
else if(action == "PAGEUP")
209
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_Page_Up), QString(i18nc("The page up key on a keyboard", "PgUp")));
210
else if(action == "INSERT")
211
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_Insert), QString(i18nc("The insert key on a keyboard", "Ins")));
212
else if(action == "PAGEDOWN")
213
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_Page_Down), QString(i18nc("The page down key on a keyboard", "PgDn")));
214
else if(action == "ARROWUP")
215
return new ArrowTopKey(point, size);
216
else if(action == "ARROWDOWN")
217
return new ArrowBottomKey(point, size);
218
else if(action == "ARROWLEFT")
219
return new ArrowLeftKey(point, size);
220
else if(action == "ARROWRIGHT")
221
return new ArrowRightKey(point, size);
222
else if(action == "KEYPADDIVIDE")
223
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_KP_Divide), QString(i18nc("Divider on the keypad", "/")));
224
else if(action == "KEYPADMULTIPLY")
225
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_KP_Multiply), QString(i18nc("Multiplier on keypad", "*")));
226
else if(action == "KEYPADADD")
227
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_KP_Add), QString(i18nc("Plus sign Divider on the keypad", "+")));
228
else if(action == "KEYPADSUBTRACT")
229
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_KP_Subtract), QString(i18nc("Plus sign Divider on the keypad", "+")));
230
else if(action == "KEYPADENTER")
231
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_KP_Enter), QString(i18nc("Enter key on the keypad", "Enter")));
232
else if(action == "KEYPADSEPARATOR")
233
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_KP_Separator), QString(i18nc("Seperator key on the keypad", ".")));
234
else if(action == "KEYPAD1")
235
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_KP_1), QString(i18nc("1 key on the keypad", "1")));
236
else if(action == "KEYPAD2")
237
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_KP_2), QString(i18nc("2 key on the keypad", "2")));
238
else if(action == "KEYPAD3")
239
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_KP_3), QString(i18nc("3 key on the keypad", "3")));
240
else if(action == "KEYPAD4")
241
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_KP_4), QString(i18nc("4 key on the keypad", "4")));
242
else if(action == "KEYPAD5")
243
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_KP_5), QString(i18nc("5 key on the keypad", "5")));
244
else if(action == "KEYPAD6")
245
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_KP_6), QString(i18nc("6 key on the keypad", "6")));
246
else if(action == "KEYPAD7")
247
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_KP_7), QString(i18nc("7 key on the keypad", "7")));
248
else if(action == "KEYPAD8")
249
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_KP_8), QString(i18nc("8 key on the keypad", "8")));
250
else if(action == "KEYPAD9")
251
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_KP_9), QString(i18nc("9 key on the keypad", "9")));
252
else if(action == "KEYPAD0")
253
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_KP_0), QString(i18nc("0 key on the keypad", "0")));
254
else if(action == "SWITCH")
255
return new SwitchKey(point, size, Helpers::keysymToKeycode(XK_VoidSymbol), this);
257
return new FuncKey(point, size, Helpers::keysymToKeycode(XK_space), QString("Unkown"));
260
void PlasmaboardWidget::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data)
262
bool state = data["Pressed"].toBool();
114
264
if ( sourceName == "Shift" ){
115
if ( data["Pressed"].toBool() ){
120
emit shiftKey(false);
265
Q_FOREACH(FuncKey* key, m_shiftKeys){
125
272
else if ( sourceName == "Caps Lock" ) {
126
if ( data["Pressed"].toBool() )
273
Q_FOREACH(FuncKey* key, m_capsKeys){
132
280
else if ( sourceName == "AltGr" ) {
133
if ( data["Pressed"].toBool() ){
134
isAlternative = true;
138
isAlternative = false;
139
emit altGrKey(false);
281
Q_FOREACH(FuncKey* key, m_altgrKeys){
284
m_isAlternative = state;
143
288
else if ( sourceName == "Alt" ) {
144
if ( data["Pressed"].toBool() )
289
Q_FOREACH(FuncKey* key, m_altKeys){
150
294
else if ( sourceName == "Super" ) {
151
if ( data["Pressed"].toBool() )
154
emit superKey(false);
295
Q_FOREACH(FuncKey* key, m_superKeys){
157
300
else if ( sourceName == "Ctrl" ) {
158
if ( data["Pressed"].toBool() )
159
emit controlKey(true);
161
emit controlKey(false);
301
Q_FOREACH(FuncKey* key, m_ctlKeys){
163
305
else if ( sourceName == "Menu" ) {
164
if ( data["Pressed"].toBool() )
310
void PlasmaboardWidget::deleteKeys()
312
qDeleteAll(m_funcKeys);
315
qDeleteAll(m_alphaKeys);
328
QPixmap *PlasmaboardWidget::getActiveFrame(const QSize &size)
331
if(!m_activeFrames.contains(size)){
332
m_activeFrame->resizeFrame(size);
333
pixmap = new QPixmap(m_activeFrame->framePixmap());
334
m_activeFrames[size] = pixmap;
337
pixmap = m_activeFrames[size];
343
QPixmap *PlasmaboardWidget::getFrame(const QSize &size)
346
if(!m_frames.contains(size)){
347
m_frame->resizeFrame(size);
348
pixmap = new QPixmap(m_frame->framePixmap());
349
m_frames[size] = pixmap;
352
pixmap = m_frames[size];
357
void PlasmaboardWidget::initKeyboard(const QString &file)
362
QPoint currentPoint = QPoint(0,0);
363
QSize currentSize = QSize(100,100);
364
int currentWidth = 100;
367
QFile* fileP = new QFile(file);
368
fileP->open(QIODevice::ReadOnly | QIODevice::Text);
370
m_xmlReader.setDevice(fileP);
372
// reading in header information
373
if (m_xmlReader.readNextStartElement()) {
374
if (m_xmlReader.name() == "keyboard"){
375
spacing = QVariant(m_xmlReader.attributes().value("spacing").toString()).toInt();
379
m_xmlReader.raiseError(i18n("Missing keyboard tag"));
383
// building up layout
384
while(!m_xmlReader.atEnd()) {
385
m_xmlReader.readNextStartElement();
387
if (m_xmlReader.name() == "row"){
388
rowHeight = QVariant(m_xmlReader.attributes().value("height").toString()).toInt();
389
rowWidth = QVariant(m_xmlReader.attributes().value("width").toString()).toInt();
391
while(m_xmlReader.readNextStartElement()){
393
currentPoint += QPoint(spacing, 0);
395
if(m_xmlReader.attributes().hasAttribute("width")){
396
currentWidth = QVariant(m_xmlReader.attributes().value("width").toString()).toInt();
399
currentWidth = rowWidth;
402
if(m_xmlReader.attributes().hasAttribute("height")){
403
currentHeight = QVariant(m_xmlReader.attributes().value("height").toString()).toInt();
406
currentHeight = rowHeight;
409
currentSize = QSize(currentWidth, currentHeight);
411
if(m_xmlReader.name() == "key"){
412
if(m_xmlReader.attributes().hasAttribute("alt")){
413
DualKey* key = new DualKey(currentPoint, currentSize, QVariant(m_xmlReader.attributes().value("code").toString()).toInt(), m_xmlReader.attributes().value("alt").toString());
418
m_alphaKeys << new AlphaNumKey(currentPoint, currentSize, QVariant(m_xmlReader.attributes().value("code").toString()).toInt());
421
else if(m_xmlReader.name() == "fkey"){
422
m_funcKeys << createFunctionKey(currentPoint, currentSize, m_xmlReader.attributes().value("action").toString());
425
m_xmlReader.skipCurrentElement();
426
currentPoint += QPoint(currentWidth, 0);
430
currentPoint = QPoint(0, currentPoint.y() + rowHeight + spacing);
435
Q_FOREACH(BoardKey* key, m_alphaKeys){
438
Q_FOREACH(BoardKey* key, m_funcKeys){
445
void PlasmaboardWidget::mouseMoveEvent ( QGraphicsSceneMouseEvent * event )
447
if(m_pressedList.count() > 0){ // as long no key is pressed, we don't care about mouse moves
448
QPoint click = event->pos().toPoint();
450
if(!boundingRect().contains(click)){ // if mouse is moved outside the widget...
451
Q_FOREACH(BoardKey* clickedKey, m_pressedList){ // ... we unpress all pressed keys
457
Q_FOREACH(BoardKey* key, m_pressedList){
458
if(key->contains(click)){
459
return; // if mouse move is inside an already clicked button, we do nothing
463
Q_FOREACH(BoardKey* key, m_keys){
465
Q_FOREACH(BoardKey* clickedKey, m_pressedList){ // release all pressed keys
466
clickedKey->released();
468
m_isRepeating = false;
471
if(key->contains(click)){
472
Q_FOREACH(BoardKey* clickedKey, m_pressedList){ // release all pressed keys
481
Plasma::Applet::mouseMoveEvent(event);
484
void PlasmaboardWidget::mousePressEvent ( QGraphicsSceneMouseEvent * event )
486
QPoint click = event->pos().toPoint();
487
Q_FOREACH(BoardKey* key, m_keys){
488
if(key->contains(click)){
493
Plasma::Applet::mousePressEvent(event);
496
void PlasmaboardWidget::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
498
QPoint click = event->pos().toPoint();
499
Q_FOREACH(BoardKey* key, m_pressedList){
500
if(key->contains(click)){
505
Plasma::Applet::mouseReleaseEvent(event);
508
/*bool PlasmaboardWidget::event ( QEvent * event )
510
qDebug() << event->type();
511
return QGraphicsWidget::event(event);
514
void PlasmaboardWidget::paint(QPainter *p,
515
const QStyleOptionGraphicsItem *option,
519
//Plasma::Containment::paint(p, option, widget);
521
p->setBrush(Plasma::Theme::defaultTheme()->color(Plasma::Theme::ButtonTextColor));
523
QRectF rect = option->exposedRect;
524
Q_FOREACH(BoardKey *key, m_keys){
525
if(key->intersects(rect)){
531
void PlasmaboardWidget::press(BoardKey *key)
534
key->setPixmap(getActiveFrame(key->size()));
535
m_pressedList << key;
538
m_repeatTimer->start(1500);
541
void PlasmaboardWidget::press(FuncKey *key)
543
key->setPixmap(getActiveFrame(key->size()));
544
m_pressedList << key;
548
void PlasmaboardWidget::refreshKeys()
550
double factor_x = size().width() / 10048;
551
double factor_y = size().height() / 10002;
553
Q_FOREACH(BoardKey* key, m_keys){
554
key->updateDimensions(factor_x, factor_y);
555
key->setPixmap(getFrame(key->size()));
560
void PlasmaboardWidget::relabelKeys()
562
qDebug() << "Relabeling";
563
foreach (AlphaNumKey* key, m_alphaKeys){
564
key->switchKey(m_isLevel2, m_isAlternative, m_isLocked);
569
void PlasmaboardWidget::release(BoardKey *key)
572
key->setPixmap(getFrame(key->size()));
573
m_pressedList.removeAll(key);
577
if(m_alphaKeys.contains((AlphaNumKey*) key)){
581
m_repeatTimer->stop();
584
void PlasmaboardWidget::repeatKeys()
586
Q_FOREACH(BoardKey* key, m_pressedList){
587
key->pressRepeated();
589
m_isRepeating = true;
592
void PlasmaboardWidget::resizeEvent(QGraphicsSceneResizeEvent* event)
598
void PlasmaboardWidget::reset(){
600
Q_FOREACH(BoardKey* key, m_pressedList){
604
Q_FOREACH(StickyKey* key, m_altKeys){
608
Q_FOREACH(StickyKey* key, m_altgrKeys){
612
Q_FOREACH(StickyKey* key, m_ctlKeys){
616
Q_FOREACH(StickyKey* key, m_shiftKeys){
620
Q_FOREACH(StickyKey* key, m_superKeys){
626
void PlasmaboardWidget::setTooltip(BoardKey* key)
628
QString label = key->label();
629
if(label.size() > 0) {
630
m_tooltip -> setText( key->label() );
631
m_tooltip -> move( popupPosition( key->size()*2 ) + key->position() - QPoint(key->size().width()/2, 0) );
632
m_tooltip -> resize( key->size()*2 );
637
void PlasmaboardWidget::switchAlternative(bool alt){
638
Q_FOREACH(DualKey* key, m_dualKeys){
639
key->setAlternative(alt);
172
void PlasmaboardWidget::resetKeyboard(){
175
int i = m_layout->count() - 1;
177
m_layout->removeAt(i--);
180
qDeleteAll(funcKeys);
183
qDeleteAll(alphaKeys);
192
extendedKeys = false;
196
void PlasmaboardWidget::initExtendedKeyboard(){
201
extKeys << new FuncKey(this);
202
QObject::connect(extKeys[i], SIGNAL( clicked() ), this, SLOT( clear() ) );
206
delete extKeys[ARROWTOPKEY];
207
delete extKeys[ARROWLEFTKEY];
208
delete extKeys[ARROWBOTTOMKEY];
209
delete extKeys[ARROWRIGHTKEY];
210
extKeys[ARROWTOPKEY] = new ArrowTopKey(this);
211
extKeys[ARROWLEFTKEY] = new ArrowLeftKey(this);
212
extKeys[ARROWBOTTOMKEY] = new ArrowBottomKey(this);
213
extKeys[ARROWRIGHTKEY] = new ArrowRightKey(this);
215
m_layout->addItem(extKeys[0], FIRST_ROW, 0, 1, 2);
217
for(i = 1; i < 5; i++){
218
m_layout->addItem(extKeys[i], FIRST_ROW, (i*2)+1, 1, 2);
220
for(i = 5; i < 9; i++){
221
m_layout->addItem(extKeys[i], FIRST_ROW, (i*2)+2, 1, 2);
223
for(i = 9; i < 13; i++){
224
m_layout->addItem(extKeys[i], FIRST_ROW, (i*2)+3, 1, 2);
227
for(i = 13; i < 16; i++){
228
m_layout->addItem(extKeys[i], FIRST_ROW, (i*2)+4, 1, 2);
231
extKeys[0]->setKey(XK_Escape, true, i18nc("The escape key on a keyboard", "Esc"));
232
extKeys[1]->setKey(XK_F1, true, i18n("F1"));
233
extKeys[2]->setKey(XK_F2, true, i18n("F2"));
234
extKeys[3]->setKey(XK_F3, true, i18n("F3"));
235
extKeys[4]->setKey(XK_F4, true, i18n("F4"));
236
extKeys[5]->setKey(XK_F5, true, i18n("F5"));
237
extKeys[6]->setKey(XK_F6, true, i18n("F6"));
238
extKeys[7]->setKey(XK_F7, true, i18n("F7"));
239
extKeys[8]->setKey(XK_F8, true, i18n("F8"));
240
extKeys[9]->setKey(XK_F9, true, i18n("F9"));
241
extKeys[10]->setKey(XK_F10, true, i18n("F10"));
242
extKeys[11]->setKey(XK_F11, true, i18n("F11"));
243
extKeys[12]->setKey(XK_F12, true, i18n("F12"));
244
extKeys[13]->setKey(XK_Print, true, i18nc("The print key on a keyboard", "Print"));
245
extKeys[14]->setKey(XK_Num_Lock, true, i18nc("The num key on a keyboard", "Num"));
246
extKeys[15]->setKey(XK_Pause, true, i18nc("The pause key on a keyboard", "Pause"));
248
m_layout->addItem(extKeys[ARROWLEFTKEY], FIRST_ROW + 5, 29, 1, 2);
252
m_layout->addItem(extKeys[HOMEKEY], FIRST_ROW + 1, col, 1, 2);
253
extKeys[HOMEKEY]->setKey(XK_Home, true, i18nc("The home key on a keyboard", "Home"));
255
m_layout->addItem(extKeys[ENDKEY], FIRST_ROW + 2, col, 1, 2);
256
extKeys[ENDKEY]->setKey(XK_End, true, i18nc("The end key on a keyboard", "End"));
258
m_layout->addItem(extKeys[INSKEY], FIRST_ROW + 3, col, 1, 2);
259
extKeys[INSKEY]->setKey(XK_Insert, true, i18nc("The insert key on a keyboard", "Ins"));
261
m_layout->addItem(extKeys[ARROWTOPKEY], FIRST_ROW + 4, col, 1, 2);
262
m_layout->addItem(extKeys[ARROWBOTTOMKEY], FIRST_ROW + 5, col, 1, 2);
266
m_layout->addItem(extKeys[ARROWRIGHTKEY], FIRST_ROW + 5, col, 1, 2);
267
m_layout->addItem(extKeys[DELKEY], FIRST_ROW + 1, col, 1, 2);
268
extKeys[DELKEY]->setKey(XK_Delete, true, i18nc("The delete key on a keyboard", "Del"));
269
m_layout->addItem(extKeys[PGUPKEY], FIRST_ROW + 2, col, 1, 2);
270
extKeys[PGUPKEY]->setKey(XK_Page_Up, true, i18nc("The page up key on a keyboard", "PgUp"));
271
m_layout->addItem(extKeys[PGDOWNKEY], FIRST_ROW + 3, col, 1, 2);
272
extKeys[PGDOWNKEY]->setKey(XK_Page_Down, true, i18nc("The page down key on a keyboard", "PgDn"));
276
m_layout->addItem(extKeys[26], FIRST_ROW + 2, col, 1, 2);
277
extKeys[26]->setKey(XK_KP_7, true, i18n("7"));
278
m_layout->addItem(extKeys[27], FIRST_ROW + 3, col, 1, 2);
279
extKeys[27]->setKey(XK_KP_4, true, i18n("4"));
280
m_layout->addItem(extKeys[28], FIRST_ROW + 4, col, 1, 2);
281
extKeys[28]->setKey(XK_KP_1, true, i18n("1"));
282
m_layout->addItem(extKeys[29], FIRST_ROW + 5, col, 1, 4);
283
extKeys[29]->setKey(XK_KP_0, true, i18n("0"));
287
m_layout->addItem(extKeys[30], FIRST_ROW + 1, col, 1, 2);
288
extKeys[30]->setKey(XK_KP_Divide, true, i18n("/"));
289
m_layout->addItem(extKeys[31], FIRST_ROW + 2, col, 1, 2);
290
extKeys[31]->setKey(XK_KP_8, true, i18n("8"));
291
m_layout->addItem(extKeys[32], FIRST_ROW + 3, col, 1, 2);
292
extKeys[32]->setKey(XK_KP_5, true, i18n("5"));
293
m_layout->addItem(extKeys[33], FIRST_ROW + 4, col, 1, 2);
294
extKeys[33]->setKey(XK_KP_2, true, i18n("2"));
298
m_layout->addItem(extKeys[34], FIRST_ROW + 1, col, 1, 2);
299
extKeys[34]->setKey(XK_KP_Multiply, true, i18n("*"));
300
m_layout->addItem(extKeys[35], FIRST_ROW + 2, col, 1, 2);
301
extKeys[35]->setKey(XK_KP_9, true, i18n("9"));
302
m_layout->addItem(extKeys[36], FIRST_ROW + 3, col, 1, 2);
303
extKeys[36]->setKey(XK_KP_6, true, i18n("6"));
304
m_layout->addItem(extKeys[37], FIRST_ROW + 4, col, 1, 2);
305
extKeys[37]->setKey(XK_KP_3, true, i18n("3"));
306
m_layout->addItem(extKeys[38], FIRST_ROW + 5, col, 1, 2);
307
extKeys[38]->setKey(XK_KP_Separator, true, i18n("."));
311
m_layout->addItem(extKeys[39], FIRST_ROW + 1, col, 1, 2);
312
extKeys[39]->setKey(XK_KP_Subtract, true, i18n("-"));
313
m_layout->addItem(extKeys[40], FIRST_ROW + 2, col, 2, 2);
314
extKeys[40]->setKey(XK_KP_Add, true, i18n("+"));
315
m_layout->addItem(extKeys[41], FIRST_ROW + 4, col, 2, 2);
316
extKeys[41]->setKey(XK_KP_Enter, true, i18nc("The enter key on a keyboard", "Enter"));
318
initBasicKeyboard(1);
322
int t_width = size().width() / 30;
323
for(int i = 30; i < 44; i++){
324
m_layout->setColumnPreferredWidth(i,t_width);
328
void PlasmaboardWidget::initBasicKeyboard(int offset){
335
funcKeys.append( new BackspaceKey(this) );
336
funcKeys << new TabKey(this);
337
funcKeys << new EnterKey(this);
338
funcKeys << new CapsKey(this);
339
funcKeys << new ShiftKey(this);
340
funcKeys << new ShiftKey(this);
344
funcKeys << new FuncKey(this);
348
funcKeys[CTLKEY]->setKey(XK_Control_L, false, i18nc("The Ctrl key on a keyboard", "Ctrl"));
349
QObject::connect(this, SIGNAL( controlKey(bool) ), funcKeys[CTLKEY], SLOT( toggle(bool) ) );
350
funcKeys[SUPER_L_KEY]->setKey(XK_Super_L, false, i18nc("The meta (windows) key on a keyboard", "Super"));
351
QObject::connect(this, SIGNAL( superKey(bool) ), funcKeys[SUPER_L_KEY], SLOT( toggle(bool) ) );
352
funcKeys[ALT_L_KEY]->setKey(XK_Alt_L, false, i18nc("The alt key on a keyboard", "Alt"));
353
QObject::connect(this, SIGNAL( altKey(bool) ), funcKeys[ALT_L_KEY], SLOT( toggle(bool) ) );
354
funcKeys[SPACE]->setKeycode(XK_space, true);
355
funcKeys[ALTGRKEY]->setKey(XK_ISO_Level3_Shift, false, i18nc("The Alt Gr key on a keyboard", "Alt Gr"));
356
QObject::connect(this, SIGNAL( altGrKey(bool) ), funcKeys[ALTGRKEY], SLOT( toggle(bool) ) );
357
funcKeys[SUPER_R_KEY]->setKey(XK_Super_L, false, i18n("Super"));
358
QObject::connect(this, SIGNAL( superKey(bool) ), funcKeys[SUPER_R_KEY], SLOT( toggle(bool) ) );
359
funcKeys[MENU]->setKey(XK_Menu, true, i18nc("The menu key on a keyboard", "Menu"));
360
QObject::connect(this, SIGNAL( menuKey(bool) ), funcKeys[MENU], SLOT( toggle(bool) ) );
361
funcKeys[CONTROL_LEFT]->setKey(XK_Control_L, false, i18nc("The Ctrl key on a keyboard", "Ctrl"));
362
QObject::connect(this, SIGNAL( controlKey(bool) ), funcKeys[CONTROL_LEFT], SLOT( toggle(bool) ) );
366
alphaKeys << new AlphaNumKey(this, 49);
368
for ( i = 10; i < 22; i++ ){
369
alphaKeys << new AlphaNumKey(this, i);
372
for ( i = 24; i < 36; i++ ){
373
alphaKeys << new AlphaNumKey(this, i);
376
for ( i = 38; i < 49; i++ ){
377
alphaKeys << new AlphaNumKey(this, i);
380
alphaKeys << new AlphaNumKey(this, 51);
381
alphaKeys << new AlphaNumKey(this, 94);
383
for ( i = 52; i < 62; i++ ){
384
alphaKeys << new AlphaNumKey(this, i);
390
int numberOfCols = 30;
394
for(x = 0; x<=12; x++){
395
m_layout->addItem(alphaKeys[x], row, x*2, 1, 2);
397
m_layout->addItem(funcKeys[BACKSPACEKEY], row, x*2, 1, 4);
401
m_layout->addItem(funcKeys[TABKEY], row, 0, 1, 3);
403
for(x = 13; x<=24; x++){
404
m_layout->addItem(alphaKeys[x], row, t, 1, 2);
407
m_layout->addItem(funcKeys[ENTERKEY], row, t+1, 2, 2);
411
m_layout->addItem(funcKeys[CAPSKEY], row, 0, 1, 4);
413
for(x = 25; x<=36; x++){
414
m_layout->addItem(alphaKeys[x], row, t, 1, 2);
420
m_layout->addItem(funcKeys[SHIFT_L_KEY], row, 0, 1, 3);
422
for(x = 37; x<=47; x++){
423
m_layout->addItem(alphaKeys[x], row, t, 1, 2);
426
m_layout->addItem(funcKeys[SHIFT_R_KEY], row, t, 1, 5);
430
m_layout->addItem(funcKeys[CTLKEY], row, 0, 1, 2);
431
m_layout->addItem(funcKeys[SUPER_L_KEY], row, 2, 1, 2);
432
m_layout->addItem(funcKeys[ALT_L_KEY], row, 4, 1, 2);
433
m_layout->addItem(funcKeys[SPACE], row, 6, 1, 14);
434
m_layout->addItem(funcKeys[ALTGRKEY], row, 20, 1, 2);
435
m_layout->addItem(funcKeys[SUPER_R_KEY], row, 22, 1, 2);
436
m_layout->addItem(funcKeys[MENU], row, 24, 1, 2);
437
m_layout->addItem(funcKeys[CONTROL_LEFT], row, 26, 1, 3);
439
for(int i = 0; i<numberOfCols; i++){
440
m_layout->setColumnPreferredWidth(i,size().width()/numberOfCols);
443
for(int i = 30; i < 44; i++){
444
m_layout->setColumnPreferredWidth(i, 0);
447
m_layout->setSpacing(0);
448
m_layout->setContentsMargins(0,0,0,0);
453
void PlasmaboardWidget::paint(QPainter *p,
454
const QStyleOptionGraphicsItem *option,
644
void PlasmaboardWidget::themeChanged()
457
p->setRenderHint(QPainter::SmoothPixmapTransform);
458
p->setRenderHint(QPainter::Antialiasing);
461
void PlasmaboardWidget::relabelKeys() {
462
foreach (AlphaNumKey* key, alphaKeys){
463
key->switchKey(isLevel2, isAlternative, isLocked);
467
void PlasmaboardWidget::clearAnything(){
469
funcKeys[CAPSKEY]->sendKeycodePress();
470
funcKeys[CAPSKEY]->sendKeycodeRelease();
475
void PlasmaboardWidget::clear(){
478
if( funcKeys[SHIFT_L_KEY]->toggled() || funcKeys[SHIFT_R_KEY]->toggled() ){
479
Helpers::fakeKeyRelease(Helpers::keysymToKeycode(XK_Shift_L));
480
funcKeys[SHIFT_L_KEY]->toggleOff();
481
funcKeys[SHIFT_R_KEY]->toggleOff();
485
if( funcKeys[ALTGRKEY]->toggled() ){
486
Helpers::fakeKeyRelease(Helpers::keysymToKeycode(XK_ISO_Level3_Shift));
487
funcKeys[ALTGRKEY]->toggleOff();
488
isAlternative = false;
496
Helpers::fakeKeyRelease(Helpers::keysymToKeycode(XK_Control_L));
497
funcKeys[CTLKEY]->toggleOff();
498
funcKeys[CONTROL_LEFT]->toggleOff();
499
Helpers::fakeKeyRelease(Helpers::keysymToKeycode(XK_Meta_L));
500
funcKeys[SUPER_L_KEY]->toggleOff();
501
funcKeys[SUPER_R_KEY]->toggleOff();
502
Helpers::fakeKeyRelease(Helpers::keysymToKeycode(XK_Alt_L));
503
funcKeys[ALT_L_KEY]->toggleOff();
509
void PlasmaboardWidget::setTooltip(QString text, QSizeF buttonSize, QPointF position){
510
tooltip -> setText( text );
511
tooltip -> move( popupPosition(buttonSize.toSize()) + QPoint(position.x() - buttonSize.width() / 2 , position.y() - buttonSize.height()) );
512
tooltip -> resize( (buttonSize * 2).toSize() );
515
//tooltipTimer->start(300);
518
void PlasmaboardWidget::clearTooltip(){
646
qDeleteAll(m_frames);
648
qDeleteAll(m_activeFrames);
649
m_activeFrames.clear();
654
void PlasmaboardWidget::unpress(BoardKey *key)
658
key->setPixmap(getFrame(key->size()));
660
m_pressedList.removeAll(key);
661
m_repeatTimer->stop();