~ubuntu-branches/ubuntu/trusty/kdeplasma-addons/trusty

« back to all changes in this revision

Viewing changes to applets/plasmaboard/widget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas
  • Date: 2010-05-25 09:50:14 UTC
  • mfrom: (1.1.28 upstream)
  • Revision ID: james.westby@ubuntu.com-20100525095014-6mlrm9z9bkws0zkt
Tags: 4:4.4.80-0ubuntu1
* New upstream beta release:
  - Bump kde-sc-dev-latest build-dep version to 4.4.80
  - Refresh kubuntu_04_kimpanel_disable_scim.diff
  - Update various .install files
  - Drop liblancelot0a and liblancelot-dev packages; Upstream has broken ABI
    without an .so version bump, and after discussion with Debian it was
    decided it was not worth it to ship an unstable library.
  - Add liblancelot files to plasma-widget-lancelot, adding appropriate
    Replaces: entries
* Switch to source format 3.0 (quilt):
  - Bump debhelper build-depend version to 7.3.16 or greater

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
 
21
21
#include "widget.h"
22
 
#include "BoardKey.h"
 
22
 
23
23
#include "AlphaNumKey.h"
24
 
#include "FuncKey.h"
25
 
#include "EnterKey.h"
26
 
#include "BackspaceKey.h"
27
 
#include "TabKey.h"
28
 
#include "ShiftKey.h"
29
 
#include "CapsKey.h"
30
 
#include "ArrowTopKey.h"
31
24
#include "ArrowBottomKey.h"
32
25
#include "ArrowLeftKey.h"
33
26
#include "ArrowRightKey.h"
 
27
#include "ArrowTopKey.h"
 
28
#include "BackspaceKey.h"
 
29
#include "BoardKey.h"
 
30
#include "CapsKey.h"
 
31
#include "DualKey.h"
 
32
#include "EnterKey.h"
 
33
#include "FuncKey.h"
 
34
#include "ShiftKey.h"
 
35
#include "StickyKey.h"
 
36
#include "SwitchKey.h"
 
37
#include "TabKey.h"
 
38
 
 
39
#include <QFile>
 
40
#include <QStyleOptionGraphicsItem>
 
41
#include <QGraphicsSceneResizeEvent>
 
42
#include <QTimer>
34
43
#include <QPainter>
35
 
#include <QGraphicsGridLayout>
 
44
#include <plasma/theme.h>
36
45
 
37
46
#include "Helpers.h"
38
47
 
39
 
#define BACKSPACEKEY 0
40
 
#define TABKEY 1
41
 
#define ENTERKEY 2
42
 
#define CAPSKEY 3
43
 
#define SHIFT_L_KEY 4
44
 
#define SHIFT_R_KEY 5
45
 
#define CTLKEY 6
46
 
#define SUPER_L_KEY 7
47
 
#define ALT_L_KEY 8
48
 
#define SPACE 9
49
 
#define ALTGRKEY 10
50
 
#define SUPER_R_KEY 11
51
 
 
52
 
#define MENU 12
53
 
#define CONTROL_LEFT 13
54
 
 
55
 
#define HOMEKEY 16
56
 
#define ENDKEY 17
57
 
#define INSKEY 18
58
 
#define DELKEY 19
59
 
#define PGUPKEY 20
60
 
#define PGDOWNKEY 21
61
 
 
62
 
#define ARROWTOPKEY     22
63
 
#define ARROWLEFTKEY    23
64
 
#define ARROWBOTTOMKEY  24
65
 
#define ARROWRIGHTKEY   25
66
 
 
67
 
#define FIRST_ROW 1
68
 
 
69
 
 
70
48
QChar Helpers::mapXtoUTF8[0xffff+1];
 
49
int Helpers::keysymsPerKeycode;
71
50
 
72
51
PlasmaboardWidget::PlasmaboardWidget(QGraphicsWidget *parent)
73
 
    : Plasma::Containment(parent)
 
52
    : Plasma::Applet(parent)
74
53
{
75
54
    setPreferredSize(500, 200);
76
55
    setMinimumSize(200,100);
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);
81
61
 
82
62
    Helpers::buildUp();
83
 
    isLevel2 = false;
84
 
    isAlternative = false;
85
 
    isLocked = false;
86
 
    m_layout = new QGraphicsGridLayout(this);
87
 
    extendedKeys = false;
88
 
    basicKeys = false;
89
 
 
90
 
    tooltip = new Tooltip("");
91
 
 
92
 
    switcher = new Plasma::Label(this);
93
 
 
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() ) );
99
 
 
100
 
    engine = dataEngine("keystate");
101
 
    if(engine){
102
 
        engine -> connectAllSources(this);
103
 
    }
104
 
}
105
 
 
106
 
 
107
 
PlasmaboardWidget::~PlasmaboardWidget(){
108
 
    delete switcher;
109
 
    delete tooltip;
110
 
}
111
 
 
112
 
void PlasmaboardWidget::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data){
 
63
    m_isLevel2 = false;
 
64
    m_isAlternative = false;
 
65
    m_isLocked = false;
 
66
    m_isRepeating = false;
 
67
 
 
68
    m_tooltip = new Tooltip("");
 
69
 
 
70
    m_frame = new Plasma::FrameSvg();
 
71
    m_frame->setCacheAllRenderedFrames(false);
 
72
    m_frame->setImagePath("widgets/button");
 
73
    m_frame->setElementPrefix("normal");
 
74
 
 
75
    m_activeFrame = new Plasma::FrameSvg();
 
76
    m_activeFrame->setCacheAllRenderedFrames(false);
 
77
    m_activeFrame->setImagePath("widgets/button");
 
78
    m_activeFrame->setElementPrefix("pressed");
 
79
 
 
80
    m_engine = dataEngine("keystate");
 
81
    if(m_engine){
 
82
        m_engine -> connectAllSources(this);
 
83
    }
 
84
 
 
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()));
 
88
 
 
89
}
 
90
 
 
91
 
 
92
PlasmaboardWidget::~PlasmaboardWidget()
 
93
{
 
94
    delete m_frame;
 
95
    delete m_activeFrame;
 
96
    delete m_tooltip;
 
97
    qDeleteAll(m_keys);
 
98
    qDeleteAll(m_frames);
 
99
    qDeleteAll(m_activeFrames);
 
100
}
 
101
 
 
102
void PlasmaboardWidget::change(FuncKey *key, bool state)
 
103
{
 
104
    if(state)
 
105
        press(key);
 
106
    else
 
107
        unpress(key);
 
108
}
 
109
 
 
110
void PlasmaboardWidget::clear()
 
111
{
 
112
    Q_FOREACH(BoardKey* key, m_pressedList){
 
113
        key->unpressed();
 
114
    }
 
115
 
 
116
    clearTooltip();
 
117
}
 
118
 
 
119
void PlasmaboardWidget::clearTooltip()
 
120
{
 
121
    m_tooltip->hide();
 
122
}
 
123
 
 
124
FuncKey* PlasmaboardWidget::createFunctionKey(QPoint &point, QSize &size, QString action)
 
125
{
 
126
 
 
127
    if(action == "ALT"){
 
128
        StickyKey *k = new StickyKey(point, size, Helpers::keysymToKeycode(XK_Alt_L), QString(i18n("Alt")));
 
129
        m_altKeys << k;
 
130
        return k;
 
131
    }
 
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")));
 
134
        m_altgrKeys << k;
 
135
        return k;
 
136
    }
 
137
    else if(action == "BACKSPACE")
 
138
        return new BackspaceKey(point, size);
 
139
    else if(action == "CAPSLOCK"){
 
140
        CapsKey *k = new CapsKey(point, size);
 
141
        m_capsKeys << k;
 
142
        return k;
 
143
    }
 
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")));
 
146
        m_ctlKeys << k;
 
147
        return k;
 
148
    }
 
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")));
 
151
        m_ctlKeys << k;
 
152
        return k;
 
153
    }
 
154
    else if(action == "ENTER")
 
155
        return new EnterKey(point, size);
 
156
    else if(action == "SHIFT") {
 
157
        ShiftKey *k = new ShiftKey(point, size);
 
158
        m_shiftKeys << k;
 
159
        return k;
 
160
    }
 
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")));
 
165
        m_superKeys << k;
 
166
        return k;
 
167
    }
 
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);
 
256
    else
 
257
        return new FuncKey(point, size, Helpers::keysymToKeycode(XK_space), QString("Unkown"));
 
258
}
 
259
 
 
260
void PlasmaboardWidget::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data)
 
261
{
 
262
    bool state = data["Pressed"].toBool();
113
263
 
114
264
    if ( sourceName == "Shift" ){
115
 
        if ( data["Pressed"].toBool() ){
116
 
            emit shiftKey(true);
117
 
            isLevel2 = true;
118
 
        }
119
 
        else{
120
 
            emit shiftKey(false);
121
 
            isLevel2 = false;
122
 
        }
 
265
        Q_FOREACH(FuncKey* key, m_shiftKeys){
 
266
            change(key, state);
 
267
        }
 
268
        m_isLevel2 = state;
 
269
        relabelKeys();
123
270
    }
124
271
    
125
272
    else if ( sourceName == "Caps Lock" ) {
126
 
        if ( data["Pressed"].toBool() )
127
 
            isLocked = true;
128
 
        else
129
 
            isLocked = false;
 
273
        Q_FOREACH(FuncKey* key, m_capsKeys){
 
274
            change(key, state);
 
275
        }
 
276
        m_isLocked = state;
 
277
        relabelKeys();
130
278
    }
131
279
 
132
280
    else if ( sourceName == "AltGr" ) {
133
 
        if ( data["Pressed"].toBool() ){
134
 
            isAlternative = true;
135
 
            emit altGrKey(true);
136
 
        }
137
 
        else{
138
 
            isAlternative = false;
139
 
            emit altGrKey(false);
140
 
        }
 
281
        Q_FOREACH(FuncKey* key, m_altgrKeys){
 
282
            change(key, state);
 
283
        }
 
284
        m_isAlternative = state;
 
285
        relabelKeys();
141
286
    }
142
287
 
143
288
    else if ( sourceName == "Alt" ) {
144
 
        if ( data["Pressed"].toBool() )
145
 
            emit altKey(true);
146
 
        else
147
 
            emit altKey(false);
 
289
        Q_FOREACH(FuncKey* key, m_altKeys){
 
290
            change(key, state);
 
291
        }
148
292
    }
149
293
 
150
294
    else if ( sourceName == "Super" ) {
151
 
        if ( data["Pressed"].toBool() )
152
 
            emit superKey(true);
153
 
        else
154
 
            emit superKey(false);
 
295
        Q_FOREACH(FuncKey* key, m_superKeys){
 
296
            change(key, state);
 
297
        }
155
298
    }
156
299
 
157
300
    else if ( sourceName == "Ctrl" ) {
158
 
        if ( data["Pressed"].toBool() )
159
 
            emit controlKey(true);
160
 
        else
161
 
            emit controlKey(false);
 
301
        Q_FOREACH(FuncKey* key, m_ctlKeys){
 
302
            change(key, state);
 
303
        }
162
304
    }
163
305
    else if ( sourceName == "Menu" ) {
164
 
        if ( data["Pressed"].toBool() )
165
 
            emit menuKey(true);
166
 
        else
167
 
            emit menuKey(false);
 
306
 
 
307
    }    
 
308
}
 
309
 
 
310
void PlasmaboardWidget::deleteKeys()
 
311
{
 
312
    qDeleteAll(m_funcKeys);
 
313
    m_funcKeys.clear();
 
314
 
 
315
    qDeleteAll(m_alphaKeys);
 
316
    m_alphaKeys.clear();
 
317
 
 
318
    m_keys.clear();
 
319
    m_altKeys.clear();
 
320
    m_altgrKeys.clear();
 
321
    m_capsKeys.clear();
 
322
    m_ctlKeys.clear();
 
323
    m_dualKeys.clear();
 
324
    m_shiftKeys.clear();
 
325
    m_superKeys.clear();
 
326
}
 
327
 
 
328
QPixmap *PlasmaboardWidget::getActiveFrame(const QSize &size)
 
329
{
 
330
    QPixmap *pixmap;
 
331
    if(!m_activeFrames.contains(size)){
 
332
        m_activeFrame->resizeFrame(size);
 
333
        pixmap = new QPixmap(m_activeFrame->framePixmap());
 
334
        m_activeFrames[size] = pixmap;
 
335
    }
 
336
    else{
 
337
        pixmap = m_activeFrames[size];
 
338
    }
 
339
    return pixmap;
 
340
 
 
341
}
 
342
 
 
343
QPixmap *PlasmaboardWidget::getFrame(const QSize &size)
 
344
{
 
345
    QPixmap *pixmap;
 
346
    if(!m_frames.contains(size)){
 
347
        m_frame->resizeFrame(size);
 
348
        pixmap = new QPixmap(m_frame->framePixmap());
 
349
        m_frames[size] = pixmap;
 
350
    }
 
351
    else{
 
352
        pixmap = m_frames[size];
 
353
    }
 
354
    return pixmap;
 
355
}
 
356
 
 
357
void PlasmaboardWidget::initKeyboard(const QString &file)
 
358
{
 
359
    int spacing = 100;
 
360
    int rowHeight = 100;
 
361
    int rowWidth = 100;
 
362
    QPoint currentPoint = QPoint(0,0);
 
363
    QSize currentSize = QSize(100,100);
 
364
    int currentWidth = 100;
 
365
    int currentHeight;
 
366
 
 
367
    QFile* fileP = new QFile(file);
 
368
    fileP->open(QIODevice::ReadOnly | QIODevice::Text);
 
369
 
 
370
    m_xmlReader.setDevice(fileP);
 
371
 
 
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();
 
376
 
 
377
        }
 
378
        else {
 
379
            m_xmlReader.raiseError(i18n("Missing keyboard tag"));
 
380
        }
 
381
    }
 
382
 
 
383
    // building up layout
 
384
    while(!m_xmlReader.atEnd()) {
 
385
        m_xmlReader.readNextStartElement();
 
386
 
 
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();
 
390
 
 
391
            while(m_xmlReader.readNextStartElement()){
 
392
 
 
393
                currentPoint += QPoint(spacing, 0);
 
394
 
 
395
                if(m_xmlReader.attributes().hasAttribute("width")){
 
396
                    currentWidth = QVariant(m_xmlReader.attributes().value("width").toString()).toInt();
 
397
                }
 
398
                else {
 
399
                    currentWidth = rowWidth;
 
400
                }
 
401
 
 
402
                if(m_xmlReader.attributes().hasAttribute("height")){
 
403
                    currentHeight = QVariant(m_xmlReader.attributes().value("height").toString()).toInt();
 
404
                }
 
405
                else {
 
406
                    currentHeight = rowHeight;
 
407
                }
 
408
 
 
409
                currentSize = QSize(currentWidth, currentHeight);
 
410
 
 
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());
 
414
                        m_alphaKeys << key;
 
415
                        m_dualKeys << key;
 
416
                    }
 
417
                    else {
 
418
                        m_alphaKeys << new AlphaNumKey(currentPoint, currentSize, QVariant(m_xmlReader.attributes().value("code").toString()).toInt());
 
419
                    }
 
420
                }
 
421
                else if(m_xmlReader.name() == "fkey"){
 
422
                    m_funcKeys << createFunctionKey(currentPoint, currentSize, m_xmlReader.attributes().value("action").toString());
 
423
                }
 
424
 
 
425
                m_xmlReader.skipCurrentElement();
 
426
                currentPoint += QPoint(currentWidth, 0);
 
427
 
 
428
            }
 
429
 
 
430
            currentPoint = QPoint(0, currentPoint.y() + rowHeight + spacing);
 
431
        }
 
432
 
 
433
    }
 
434
 
 
435
    Q_FOREACH(BoardKey* key, m_alphaKeys){
 
436
        m_keys << key;
 
437
    }
 
438
    Q_FOREACH(BoardKey* key, m_funcKeys){
 
439
        m_keys << key;
 
440
    }
 
441
 
 
442
    delete fileP;
 
443
}
 
444
 
 
445
void PlasmaboardWidget::mouseMoveEvent ( QGraphicsSceneMouseEvent * event )
 
446
{    
 
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();
 
449
 
 
450
        if(!boundingRect().contains(click)){ // if mouse is moved outside the widget...
 
451
            Q_FOREACH(BoardKey* clickedKey, m_pressedList){  // ... we unpress all pressed keys
 
452
                unpress(clickedKey);
 
453
            }            
 
454
            return;
 
455
        }
 
456
 
 
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
 
460
            }
 
461
        }
 
462
 
 
463
        Q_FOREACH(BoardKey* key, m_keys){
 
464
            if(m_isRepeating){
 
465
                Q_FOREACH(BoardKey* clickedKey, m_pressedList){ // release all pressed keys
 
466
                    clickedKey->released();
 
467
                }
 
468
                m_isRepeating = false;
 
469
            }
 
470
 
 
471
            if(key->contains(click)){
 
472
                Q_FOREACH(BoardKey* clickedKey, m_pressedList){ // release all pressed keys
 
473
                    unpress(clickedKey);
 
474
                }                
 
475
                press(key);
 
476
                return;
 
477
            }
 
478
        }
 
479
    }
 
480
 
 
481
    Plasma::Applet::mouseMoveEvent(event);
 
482
}
 
483
 
 
484
void PlasmaboardWidget::mousePressEvent ( QGraphicsSceneMouseEvent * event )
 
485
{
 
486
    QPoint click = event->pos().toPoint();
 
487
    Q_FOREACH(BoardKey* key, m_keys){
 
488
        if(key->contains(click)){
 
489
            press(key);
 
490
            return;
 
491
        }
 
492
    }
 
493
    Plasma::Applet::mousePressEvent(event);
 
494
}
 
495
 
 
496
void PlasmaboardWidget::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
 
497
{
 
498
    QPoint click = event->pos().toPoint();
 
499
    Q_FOREACH(BoardKey* key, m_pressedList){
 
500
        if(key->contains(click)){
 
501
            release(key);
 
502
            return;
 
503
        }
 
504
    }
 
505
    Plasma::Applet::mouseReleaseEvent(event);
 
506
}
 
507
 
 
508
/*bool PlasmaboardWidget::event ( QEvent * event )
 
509
{
 
510
    qDebug() << event->type();
 
511
    return QGraphicsWidget::event(event);
 
512
}*/
 
513
 
 
514
void PlasmaboardWidget::paint(QPainter *p,
 
515
                              const QStyleOptionGraphicsItem *option,
 
516
                              QWidget* widget)
 
517
{
 
518
    Q_UNUSED(widget);
 
519
    //Plasma::Containment::paint(p, option, widget);
 
520
 
 
521
    p->setBrush(Plasma::Theme::defaultTheme()->color(Plasma::Theme::ButtonTextColor));
 
522
 
 
523
    QRectF rect = option->exposedRect;
 
524
    Q_FOREACH(BoardKey *key, m_keys){
 
525
        if(key->intersects(rect)){
 
526
            key->paint(p);
 
527
        }
 
528
    }
 
529
}
 
530
 
 
531
void PlasmaboardWidget::press(BoardKey *key)
 
532
{
 
533
    key->pressed();
 
534
    key->setPixmap(getActiveFrame(key->size()));
 
535
    m_pressedList << key;    
 
536
    update(key->rect());
 
537
    setTooltip(key);
 
538
    m_repeatTimer->start(1500);
 
539
}
 
540
 
 
541
void PlasmaboardWidget::press(FuncKey *key)
 
542
{
 
543
    key->setPixmap(getActiveFrame(key->size()));
 
544
    m_pressedList << key;
 
545
    update(key->rect());
 
546
}
 
547
 
 
548
void PlasmaboardWidget::refreshKeys()
 
549
{
 
550
    double factor_x = size().width() / 10048;
 
551
    double factor_y = size().height() / 10002;
 
552
 
 
553
    Q_FOREACH(BoardKey* key, m_keys){
 
554
        key->updateDimensions(factor_x, factor_y);
 
555
        key->setPixmap(getFrame(key->size()));
 
556
    }
 
557
 
 
558
}
 
559
 
 
560
void PlasmaboardWidget::relabelKeys()
 
561
{
 
562
    qDebug() << "Relabeling";
 
563
    foreach (AlphaNumKey* key, m_alphaKeys){
 
564
        key->switchKey(m_isLevel2, m_isAlternative, m_isLocked);
 
565
        update(key->rect());
 
566
    }
 
567
}
 
568
 
 
569
void PlasmaboardWidget::release(BoardKey *key)
 
570
{    
 
571
    key->released();
 
572
    key->setPixmap(getFrame(key->size()));
 
573
    m_pressedList.removeAll(key);
 
574
    update(key->rect());
 
575
    clearTooltip();
 
576
 
 
577
    if(m_alphaKeys.contains((AlphaNumKey*) key)){
 
578
        reset();
 
579
    }
 
580
 
 
581
    m_repeatTimer->stop();
 
582
}
 
583
 
 
584
void PlasmaboardWidget::repeatKeys()
 
585
{
 
586
    Q_FOREACH(BoardKey* key, m_pressedList){
 
587
        key->pressRepeated();
 
588
    }
 
589
    m_isRepeating = true;
 
590
}
 
591
 
 
592
void PlasmaboardWidget::resizeEvent(QGraphicsSceneResizeEvent* event)
 
593
{
 
594
    Q_UNUSED(event);
 
595
    refreshKeys();
 
596
}
 
597
 
 
598
void PlasmaboardWidget::reset(){
 
599
 
 
600
    Q_FOREACH(BoardKey* key, m_pressedList){
 
601
        unpress(key);
 
602
    }
 
603
 
 
604
    Q_FOREACH(StickyKey* key, m_altKeys){
 
605
        key->reset();
 
606
    }
 
607
 
 
608
    Q_FOREACH(StickyKey* key, m_altgrKeys){
 
609
        key->reset();
 
610
    }
 
611
 
 
612
    Q_FOREACH(StickyKey* key, m_ctlKeys){
 
613
        key->reset();
 
614
    }
 
615
 
 
616
    Q_FOREACH(StickyKey* key, m_shiftKeys){
 
617
        key->reset();
 
618
    }
 
619
 
 
620
    Q_FOREACH(StickyKey* key, m_superKeys){
 
621
        key->reset();
 
622
    }
 
623
 
 
624
}
 
625
 
 
626
void PlasmaboardWidget::setTooltip(BoardKey* key)
 
627
{
 
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 );
 
633
        m_tooltip -> show();
 
634
    }
 
635
}
 
636
 
 
637
void PlasmaboardWidget::switchAlternative(bool alt){
 
638
    Q_FOREACH(DualKey* key, m_dualKeys){
 
639
        key->setAlternative(alt);
168
640
    }
169
641
    relabelKeys();
170
642
}
171
643
 
172
 
void PlasmaboardWidget::resetKeyboard(){
173
 
 
174
 
        if( basicKeys ){
175
 
                int i = m_layout->count() - 1;
176
 
                while(i >= 0){
177
 
                        m_layout->removeAt(i--);
178
 
                }
179
 
 
180
 
                qDeleteAll(funcKeys);
181
 
                funcKeys.clear();
182
 
 
183
 
                qDeleteAll(alphaKeys);
184
 
                alphaKeys.clear();
185
 
 
186
 
                basicKeys = false;
187
 
        }
188
 
 
189
 
        if( extendedKeys ) {
190
 
                qDeleteAll(extKeys);
191
 
                extKeys.clear();
192
 
                extendedKeys = false;
193
 
        }
194
 
}
195
 
 
196
 
void PlasmaboardWidget::initExtendedKeyboard(){
197
 
        extendedKeys = true;
198
 
 
199
 
        int i = 0;
200
 
        while ( i < 42 ) {
201
 
                extKeys << new FuncKey(this);
202
 
                QObject::connect(extKeys[i], SIGNAL( clicked() ), this, SLOT( clear() ) );
203
 
                i++;
204
 
        }
205
 
 
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);
214
 
 
215
 
        m_layout->addItem(extKeys[0], FIRST_ROW, 0, 1, 2);
216
 
        i = 1;
217
 
        for(i = 1; i < 5; i++){
218
 
                m_layout->addItem(extKeys[i], FIRST_ROW, (i*2)+1, 1, 2);
219
 
        }
220
 
        for(i = 5; i < 9; i++){
221
 
                m_layout->addItem(extKeys[i], FIRST_ROW, (i*2)+2, 1, 2);
222
 
        }
223
 
        for(i = 9; i < 13; i++){
224
 
                m_layout->addItem(extKeys[i], FIRST_ROW, (i*2)+3, 1, 2);
225
 
        }
226
 
 
227
 
        for(i = 13; i < 16; i++){
228
 
                m_layout->addItem(extKeys[i], FIRST_ROW, (i*2)+4, 1, 2);
229
 
        }
230
 
 
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"));
247
 
        
248
 
        m_layout->addItem(extKeys[ARROWLEFTKEY], FIRST_ROW + 5, 29, 1, 2);
249
 
 
250
 
        int col = 31;
251
 
 
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"));
254
 
 
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"));
257
 
 
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"));
260
 
 
261
 
        m_layout->addItem(extKeys[ARROWTOPKEY], FIRST_ROW + 4, col, 1, 2);
262
 
        m_layout->addItem(extKeys[ARROWBOTTOMKEY], FIRST_ROW + 5, col, 1, 2);
263
 
 
264
 
        col+=2;
265
 
 
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"));
273
 
 
274
 
        col+=3;
275
 
 
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"));
284
 
 
285
 
        col+=2;
286
 
 
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"));
295
 
 
296
 
        col+=2;
297
 
 
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("."));
308
 
 
309
 
        col+=2;
310
 
 
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"));
317
 
 
318
 
        initBasicKeyboard(1);
319
 
 
320
 
 
321
 
 
322
 
        int t_width = size().width() / 30;
323
 
        for(int i = 30; i < 44; i++){
324
 
                m_layout->setColumnPreferredWidth(i,t_width);
325
 
        }
326
 
}
327
 
 
328
 
void PlasmaboardWidget::initBasicKeyboard(int offset){
329
 
 
330
 
        basicKeys = true;
331
 
        offset += FIRST_ROW;
332
 
 
333
 
        // create objects
334
 
 
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);
341
 
 
342
 
        int i = 6;
343
 
        while ( i < 14 ) {
344
 
                funcKeys << new FuncKey(this);
345
 
                i++;
346
 
        }
347
 
 
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) ) );
363
 
 
364
 
        // set Keymap
365
 
 
366
 
        alphaKeys << new AlphaNumKey(this, 49);
367
 
 
368
 
        for ( i = 10; i < 22; i++ ){
369
 
               alphaKeys << new AlphaNumKey(this, i);
370
 
        }
371
 
 
372
 
        for ( i = 24; i < 36; i++ ){
373
 
               alphaKeys << new AlphaNumKey(this, i);
374
 
        }
375
 
 
376
 
        for ( i = 38; i < 49; i++ ){
377
 
               alphaKeys << new AlphaNumKey(this, i);
378
 
        }
379
 
 
380
 
        alphaKeys << new AlphaNumKey(this, 51);
381
 
        alphaKeys << new AlphaNumKey(this, 94);
382
 
 
383
 
        for ( i = 52; i < 62; i++ ){
384
 
               alphaKeys << new AlphaNumKey(this, i);
385
 
        }
386
 
 
387
 
 
388
 
        // create layout
389
 
 
390
 
        int numberOfCols = 30;
391
 
 
392
 
        int x;
393
 
        int row = offset;
394
 
        for(x = 0; x<=12; x++){
395
 
                m_layout->addItem(alphaKeys[x], row, x*2, 1, 2);
396
 
        }
397
 
        m_layout->addItem(funcKeys[BACKSPACEKEY], row, x*2, 1, 4);
398
 
 
399
 
        row++;
400
 
 
401
 
        m_layout->addItem(funcKeys[TABKEY], row, 0, 1, 3);
402
 
        int t = 3;
403
 
        for(x = 13; x<=24; x++){
404
 
                m_layout->addItem(alphaKeys[x], row, t, 1, 2);
405
 
                t+=2;
406
 
        }
407
 
        m_layout->addItem(funcKeys[ENTERKEY], row, t+1, 2, 2);
408
 
 
409
 
        row++;
410
 
 
411
 
        m_layout->addItem(funcKeys[CAPSKEY], row, 0, 1, 4);
412
 
        t = 4;
413
 
        for(x = 25; x<=36; x++){
414
 
                m_layout->addItem(alphaKeys[x], row, t, 1, 2);
415
 
                t+=2;
416
 
        }
417
 
 
418
 
        row++;
419
 
 
420
 
        m_layout->addItem(funcKeys[SHIFT_L_KEY], row, 0, 1, 3);
421
 
        t = 3;
422
 
        for(x = 37; x<=47; x++){
423
 
                m_layout->addItem(alphaKeys[x], row, t, 1, 2);
424
 
                t+=2;
425
 
        }
426
 
        m_layout->addItem(funcKeys[SHIFT_R_KEY], row, t, 1, 5);
427
 
 
428
 
        row++;
429
 
 
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);
438
 
 
439
 
        for(int i = 0; i<numberOfCols; i++){
440
 
                m_layout->setColumnPreferredWidth(i,size().width()/numberOfCols);
441
 
        }
442
 
 
443
 
        for(int i = 30; i < 44; i++){
444
 
                m_layout->setColumnPreferredWidth(i, 0);
445
 
        }
446
 
 
447
 
        m_layout->setSpacing(0);
448
 
        m_layout->setContentsMargins(0,0,0,0);
449
 
 
450
 
 
451
 
}
452
 
 
453
 
void PlasmaboardWidget::paint(QPainter *p,
454
 
                const QStyleOptionGraphicsItem *option,
455
 
                 QWidget*)
 
644
void PlasmaboardWidget::themeChanged()
456
645
{
457
 
    p->setRenderHint(QPainter::SmoothPixmapTransform);
458
 
    p->setRenderHint(QPainter::Antialiasing);
459
 
}
460
 
 
461
 
void PlasmaboardWidget::relabelKeys() {
462
 
        foreach (AlphaNumKey* key, alphaKeys){
463
 
            key->switchKey(isLevel2, isAlternative, isLocked);
464
 
        }
465
 
}
466
 
 
467
 
void PlasmaboardWidget::clearAnything(){
468
 
        if ( isLocked ) {
469
 
                funcKeys[CAPSKEY]->sendKeycodePress();
470
 
                funcKeys[CAPSKEY]->sendKeycodeRelease();
471
 
        }
472
 
        clear();
473
 
}
474
 
 
475
 
void PlasmaboardWidget::clear(){
476
 
 
477
 
        bool change = false;
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();
482
 
                isLevel2 = false;
483
 
                change = true;
484
 
        }
485
 
        if( funcKeys[ALTGRKEY]->toggled() ){
486
 
                Helpers::fakeKeyRelease(Helpers::keysymToKeycode(XK_ISO_Level3_Shift));
487
 
                funcKeys[ALTGRKEY]->toggleOff();
488
 
                isAlternative = false;
489
 
                change = true;
490
 
        }
491
 
 
492
 
        if(change){
493
 
                relabelKeys();
494
 
        }
495
 
 
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();
504
 
 
505
 
        clearTooltip();
506
 
}
507
 
 
508
 
 
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() );
513
 
    tooltip -> show();
514
 
 
515
 
    //tooltipTimer->start(300);
516
 
}
517
 
 
518
 
void PlasmaboardWidget::clearTooltip(){
519
 
 
520
 
    tooltip->hide();
 
646
    qDeleteAll(m_frames);
 
647
    m_frames.clear();
 
648
    qDeleteAll(m_activeFrames);
 
649
    m_activeFrames.clear();
 
650
 
 
651
    refreshKeys();
 
652
}
 
653
 
 
654
void PlasmaboardWidget::unpress(BoardKey *key)
 
655
{    
 
656
    clearTooltip();
 
657
    key->unpressed();
 
658
    key->setPixmap(getFrame(key->size()));
 
659
    update(key->rect());
 
660
    m_pressedList.removeAll(key);
 
661
    m_repeatTimer->stop();
521
662
}
522
663