-
Notifications
You must be signed in to change notification settings - Fork 341
/
mythuicheckbox.cpp
227 lines (185 loc) · 4.8 KB
/
mythuicheckbox.cpp
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
// Own header
#include "mythuicheckbox.h"
// Myth headers
#include "mythlogging.h"
// MythUI headers
#include "mythmainwindow.h"
#include "mythgesture.h"
MythUICheckBox::MythUICheckBox(MythUIType *parent, const QString &name)
: MythUIType(parent, name)
{
m_currentCheckState = MythUIStateType::Off;
m_state = "active";
m_BackgroundState = m_CheckState = NULL;
connect(this, SIGNAL(TakingFocus()), this, SLOT(Select()));
connect(this, SIGNAL(LosingFocus()), this, SLOT(Deselect()));
connect(this, SIGNAL(Enabling()), this, SLOT(Enable()));
connect(this, SIGNAL(Disabling()), this, SLOT(Disable()));
SetCanTakeFocus(true);
}
MythUICheckBox::~MythUICheckBox()
{
}
void MythUICheckBox::SetInitialStates()
{
m_BackgroundState = dynamic_cast<MythUIStateType *>(GetChild("background"));
m_CheckState = dynamic_cast<MythUIStateType *>(GetChild("checkstate"));
if (!m_CheckState || !m_BackgroundState)
LOG(VB_GENERAL, LOG_ERR,
QString("Checkbox %1 is missing required elements")
.arg(objectName()));
if (m_CheckState)
m_CheckState->DisplayState(m_currentCheckState);
if (m_BackgroundState)
m_BackgroundState->DisplayState(m_state);
}
void MythUICheckBox::toggleCheckState()
{
bool onOff = false;
if (m_currentCheckState != MythUIStateType::Full)
{
m_currentCheckState = MythUIStateType::Full;
onOff = true;
}
else
{
m_currentCheckState = MythUIStateType::Off;
onOff = false;
}
if (m_CheckState)
m_CheckState->DisplayState(m_currentCheckState);
emit DependChanged(!onOff);
emit toggled(onOff);
emit valueChanged();
}
void MythUICheckBox::SetCheckState(MythUIStateType::StateType state)
{
m_currentCheckState = state;
if (m_CheckState)
m_CheckState->DisplayState(state);
if (state == MythUIStateType::Off)
emit DependChanged(true);
else
emit DependChanged(false);
emit valueChanged();
}
void MythUICheckBox::SetCheckState(bool onOff)
{
if (onOff)
{
m_currentCheckState = MythUIStateType::Full;
}
else
{
m_currentCheckState = MythUIStateType::Off;
}
if (m_CheckState)
m_CheckState->DisplayState(m_currentCheckState);
emit toggled(onOff);
emit DependChanged(!onOff);
emit valueChanged();
}
MythUIStateType::StateType MythUICheckBox::GetCheckState() const
{
return m_currentCheckState;
}
bool MythUICheckBox::GetBooleanCheckState() const
{
return m_currentCheckState == MythUIStateType::Full;
}
void MythUICheckBox::Select()
{
if (!IsEnabled())
return;
m_state = "selected";
if (m_BackgroundState)
m_BackgroundState->DisplayState(m_state);
}
void MythUICheckBox::Deselect()
{
if (IsEnabled())
m_state = "active";
else
m_state = "disabled";
if (m_BackgroundState)
m_BackgroundState->DisplayState(m_state);
}
void MythUICheckBox::Enable()
{
m_state = "active";
if (m_BackgroundState)
m_BackgroundState->DisplayState(m_state);
}
void MythUICheckBox::Disable()
{
m_state = "disabled";
if (m_BackgroundState)
m_BackgroundState->DisplayState(m_state);
}
/** \brief Mouse click/movement handler, receives mouse gesture events from the
* QCoreApplication event loop. Should not be used directly.
*
* \param uitype The mythuitype receiving the event
* \param event Mouse event
*/
bool MythUICheckBox::gestureEvent(MythGestureEvent *event)
{
if (event->gesture() == MythGestureEvent::Click)
{
if (IsEnabled())
{
toggleCheckState();
return true;
}
}
return false;
}
/** \brief Key event handler
*
* \param event Keypress event
*/
bool MythUICheckBox::keyPressEvent(QKeyEvent *event)
{
QStringList actions;
bool handled = false;
handled = GetMythMainWindow()->TranslateKeyPress("Global", event, actions);
for (int i = 0; i < actions.size() && !handled; i++)
{
QString action = actions[i];
handled = true;
if (action == "SELECT")
toggleCheckState();
else
handled = false;
}
return handled;
}
/**
* \copydoc MythUIType::CreateCopy()
*/
void MythUICheckBox::CreateCopy(MythUIType *parent)
{
MythUICheckBox *checkbox = new MythUICheckBox(parent, objectName());
checkbox->CopyFrom(this);
}
/**
* \copydoc MythUIType::CopyFrom()
*/
void MythUICheckBox::CopyFrom(MythUIType *base)
{
MythUICheckBox *button = dynamic_cast<MythUICheckBox *>(base);
if (!button)
{
LOG(VB_GENERAL, LOG_ERR, "Dynamic cast of base failed");
return;
}
MythUIType::CopyFrom(base);
SetInitialStates();
}
/**
* \copydoc MythUIType::Finalize()
*/
void MythUICheckBox::Finalize()
{
SetInitialStates();
}