summaryrefslogtreecommitdiffstats
path: root/blinken/src/button.cpp
blob: 16d5d91ed0dc8d995c5b70355d022665d89f496d (plain)
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
/***************************************************************************
 *   Copyright (C) 2005 by Albert Astals Cid <[email protected]>            *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

#include <kaction.h>
#include <kapplication.h>
#include <tdeconfig.h>
#include <kstandarddirs.h>
#include <kdebug.h>

#include "button.h"

button::button(blinkenGame::color c) : m_selected(false), m_color(c)
{
	TDEConfig *kc = kapp->config();
	kc->setGroup("General");
	TQString cs = getColorString();
	TQString pixmap = TQString("images/%1h.png").arg(cs);
	
	switch (c)
	{
		case blinkenGame::blue:
			m_key = kc->readNumEntry(cs, TQt::Key_3);
		break;
		
		case blinkenGame::yellow:
			m_key = kc->readNumEntry(cs, TQt::Key_1);
		break;
		
		case blinkenGame::red:
			m_key = kc->readNumEntry(cs, TQt::Key_2);
		break;
		
		case blinkenGame::green:
			m_key = kc->readNumEntry(cs, TQt::Key_4);
		break;
		
		default:
			// never happens
		break;
	}
	
	m_highlighted = new TQPixmap(locate("appdata", pixmap));
}

button::~button()
{
	delete m_highlighted;
}

void button::setShortcut(int key)
{
	m_key = key;
	m_selected = false;
	
	TDEConfig *kc = kapp->config();
	kc->setGroup("General");
	kc->writeEntry(getColorString(), key);
	kc->sync();
}

TQString button::shortcut() const
{
	return KShortcut(m_key).toString();
}

int button::key() const
{
	return m_key;
}

void button::setSelected(bool b)
{
	m_selected = b;
}

bool button::selected() const
{
	return m_selected;
}

TQPixmap *button::pixmap() const
{
	return m_highlighted;
}

TQString button::getColorString() const
{
	switch (m_color)
	{
		case blinkenGame::blue:
			return "blue";
		break;
		
		case blinkenGame::yellow:
			return "yellow";
		break;
		
		case blinkenGame::red:
			return "red";
		break;
		
		case blinkenGame::green:
			return "green";
		break;
		
		default:
			// never happens
		break;
	}
	
	// never happens
	return TQString();
}