~scarlettmoore/kde-blinken-snap/trunk

« back to all changes in this revision

Viewing changes to src/button.cpp

  • Committer: Scarlett Moore
  • Date: 2023-08-22 14:44:27 UTC
  • Revision ID: scarlettmoore@ubuntu.com-20230822144427-z182y98hsrtcq8f2
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    SPDX-FileCopyrightText: 2005-2006 Albert Astals Cid <aacid@kde.org>
 
3
 
 
4
    SPDX-License-Identifier: GPL-2.0-or-later
 
5
*/
 
6
 
 
7
#include "button.h"
 
8
 
 
9
#include <KConfig>
 
10
#include <KSharedConfig>
 
11
#include <KConfigGroup>
 
12
 
 
13
#include <QKeySequence>
 
14
 
 
15
button::button(blinkenGame::color c) : m_selected(false), m_color(c)
 
16
{
 
17
        KConfigGroup kc(KSharedConfig::openConfig(), "General");
 
18
        QString cs = getColorString();
 
19
        
 
20
        switch (c)
 
21
        {
 
22
                case blinkenGame::blue:
 
23
                        m_key = kc.readEntry(cs, int(Qt::Key_3));
 
24
                break;
 
25
                
 
26
                case blinkenGame::yellow:
 
27
                        m_key = kc.readEntry(cs, int(Qt::Key_1));
 
28
                break;
 
29
                
 
30
                case blinkenGame::red:
 
31
                        m_key =kc.readEntry(cs, int(Qt::Key_2));
 
32
                break;
 
33
                
 
34
                case blinkenGame::green:
 
35
                        m_key = kc.readEntry(cs, int(Qt::Key_4));
 
36
                break;
 
37
                
 
38
                default:
 
39
                        // never happens
 
40
                break;
 
41
        }
 
42
}
 
43
 
 
44
button::~button()
 
45
{
 
46
}
 
47
 
 
48
void button::setShortcut(int key)
 
49
{
 
50
        m_key = key;
 
51
        m_selected = false;
 
52
        
 
53
        KConfigGroup kc(KSharedConfig::openConfig(), "General");
 
54
        kc.writeEntry(getColorString(), key);
 
55
        kc.sync();
 
56
}
 
57
 
 
58
QString button::shortcut() const
 
59
{
 
60
        return QKeySequence(m_key).toString();
 
61
}
 
62
 
 
63
int button::key() const
 
64
{
 
65
        return m_key;
 
66
}
 
67
 
 
68
void button::setSelected(bool b)
 
69
{
 
70
        m_selected = b;
 
71
}
 
72
 
 
73
bool button::selected() const
 
74
{
 
75
        return m_selected;
 
76
}
 
77
 
 
78
QString button::getColorString() const
 
79
{
 
80
        switch (m_color)
 
81
        {
 
82
                case blinkenGame::blue:
 
83
                        return QStringLiteral("blue");
 
84
                
 
85
                case blinkenGame::yellow:
 
86
                        return QStringLiteral("yellow");
 
87
                
 
88
                case blinkenGame::red:
 
89
                        return QStringLiteral("red");
 
90
                
 
91
                case blinkenGame::green:
 
92
                        return QStringLiteral("green");
 
93
                
 
94
                default:
 
95
                        // never happens
 
96
                break;
 
97
        }
 
98
        
 
99
        // never happens
 
100
        return QString();
 
101
}