MythTV
master
mythtv
libs
libmythui
mythuicheckbox.cpp
Go to the documentation of this file.
1
2
// Own header
3
#include "
mythuicheckbox.h
"
4
5
// Myth headers
6
#include "
libmythbase/mythlogging.h
"
7
8
// MythUI headers
9
#include "
mythmainwindow.h
"
10
#include "
mythgesture.h
"
11
12
MythUICheckBox::MythUICheckBox
(
MythUIType
*parent,
const
QString &name)
13
:
MythUIType
(parent, name)
14
{
15
connect(
this
, &
MythUIType::TakingFocus
,
this
, &
MythUICheckBox::Select
);
16
connect(
this
, &
MythUIType::LosingFocus
,
this
, &
MythUICheckBox::Deselect
);
17
connect(
this
, &
MythUIType::Enabling
,
this
, &
MythUICheckBox::Enable
);
18
connect(
this
, &
MythUIType::Disabling
,
this
, &
MythUICheckBox::Disable
);
19
20
SetCanTakeFocus
(
true
);
21
}
22
23
void
MythUICheckBox::SetInitialStates
()
24
{
25
m_backgroundState
=
dynamic_cast<
MythUIStateType
*
>
(
GetChild
(
"background"
));
26
m_checkState
=
dynamic_cast<
MythUIStateType
*
>
(
GetChild
(
"checkstate"
));
27
28
if
(!
m_checkState
|| !
m_backgroundState
)
29
{
30
LOG
(VB_GENERAL, LOG_ERR,
31
QString(
"Checkbox %1 is missing required elements"
)
32
.arg(objectName()));
33
}
34
35
if
(
m_checkState
)
36
m_checkState
->
DisplayState
(
m_currentCheckState
);
37
38
if
(
m_backgroundState
)
39
m_backgroundState
->
DisplayState
(
m_state
);
40
}
41
42
43
void
MythUICheckBox::toggleCheckState
()
44
{
45
bool
onOff =
false
;
46
47
if
(
m_currentCheckState
!=
MythUIStateType::Full
)
48
{
49
m_currentCheckState
=
MythUIStateType::Full
;
50
onOff =
true
;
51
}
52
else
53
{
54
m_currentCheckState
=
MythUIStateType::Off
;
55
onOff =
false
;
56
}
57
58
if
(
m_checkState
)
59
m_checkState
->
DisplayState
(
m_currentCheckState
);
60
61
emit
DependChanged
(!onOff);
62
emit
toggled
(onOff);
63
emit
valueChanged
();
64
}
65
66
void
MythUICheckBox::SetCheckState
(
MythUIStateType::StateType
state)
67
{
68
m_currentCheckState
= state;
69
if
(
m_checkState
)
70
m_checkState
->
DisplayState
(state);
71
72
if
(state ==
MythUIStateType::Off
)
73
emit
DependChanged
(
true
);
74
else
75
emit
DependChanged
(
false
);
76
emit
valueChanged
();
77
}
78
79
void
MythUICheckBox::SetCheckState
(
bool
onOff)
80
{
81
if
(onOff)
82
{
83
m_currentCheckState
=
MythUIStateType::Full
;
84
}
85
else
86
{
87
m_currentCheckState
=
MythUIStateType::Off
;
88
}
89
90
if
(
m_checkState
)
91
m_checkState
->
DisplayState
(
m_currentCheckState
);
92
93
emit
toggled
(onOff);
94
emit
DependChanged
(!onOff);
95
emit
valueChanged
();
96
}
97
98
MythUIStateType::StateType
MythUICheckBox::GetCheckState
()
const
99
{
100
return
m_currentCheckState
;
101
}
102
103
bool
MythUICheckBox::GetBooleanCheckState
()
const
104
{
105
return
m_currentCheckState
==
MythUIStateType::Full
;
106
}
107
108
void
MythUICheckBox::Select
()
109
{
110
if
(!
IsEnabled
())
111
return
;
112
113
m_state
=
"selected"
;
114
if
(
m_backgroundState
)
115
m_backgroundState
->
DisplayState
(
m_state
);
116
}
117
118
void
MythUICheckBox::Deselect
()
119
{
120
if
(
IsEnabled
())
121
m_state
=
"active"
;
122
else
123
m_state
=
"disabled"
;
124
125
if
(
m_backgroundState
)
126
m_backgroundState
->
DisplayState
(
m_state
);
127
}
128
129
void
MythUICheckBox::Enable
()
130
{
131
m_state
=
"active"
;
132
if
(
m_backgroundState
)
133
m_backgroundState
->
DisplayState
(
m_state
);
134
}
135
136
void
MythUICheckBox::Disable
()
137
{
138
m_state
=
"disabled"
;
139
if
(
m_backgroundState
)
140
m_backgroundState
->
DisplayState
(
m_state
);
141
}
142
148
bool
MythUICheckBox::gestureEvent
(
MythGestureEvent
*event)
149
{
150
if
(event->
GetGesture
() ==
MythGestureEvent::Click
)
151
{
152
if
(
IsEnabled
())
153
{
154
toggleCheckState
();
155
return
true
;
156
}
157
}
158
159
return
false
;
160
}
161
166
bool
MythUICheckBox::keyPressEvent
(QKeyEvent *event)
167
{
168
QStringList actions;
169
bool
handled =
false
;
170
handled =
GetMythMainWindow
()->
TranslateKeyPress
(
"Global"
, event, actions);
171
172
for
(
int
i = 0; i < actions.size() && !handled; i++)
173
{
174
const
QString&
action
= actions[i];
175
handled =
true
;
176
177
if
(
action
==
"SELECT"
)
178
toggleCheckState
();
179
else
180
handled =
false
;
181
}
182
183
return
handled;
184
}
185
189
void
MythUICheckBox::CreateCopy
(
MythUIType
*parent)
190
{
191
auto
*checkbox =
new
MythUICheckBox
(parent, objectName());
192
checkbox->CopyFrom(
this
);
193
}
194
198
void
MythUICheckBox::CopyFrom
(
MythUIType
*base)
199
{
200
auto
*button =
dynamic_cast<
MythUICheckBox
*
>
(base);
201
202
if
(!button)
203
{
204
LOG
(VB_GENERAL, LOG_ERR,
"Dynamic cast of base failed"
);
205
return
;
206
}
207
208
MythUIType::CopyFrom
(base);
209
210
SetInitialStates
();
211
}
212
216
void
MythUICheckBox::Finalize
()
217
{
218
SetInitialStates
();
219
}
MythGestureEvent::Click
@ Click
Definition:
mythgesture.h:77
MythUICheckBox::m_currentCheckState
MythUIStateType::StateType m_currentCheckState
Definition:
mythuicheckbox.h:58
MythUICheckBox::m_backgroundState
MythUIStateType * m_backgroundState
Definition:
mythuicheckbox.h:55
MythGestureEvent::GetGesture
Gesture GetGesture() const
Definition:
mythgesture.h:85
MythUICheckBox::m_checkState
MythUIStateType * m_checkState
Definition:
mythuicheckbox.h:56
MythUIType::Enabling
void Enabling()
MythUIType::GetChild
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition:
mythuitype.cpp:138
MythUICheckBox::GetBooleanCheckState
bool GetBooleanCheckState(void) const
Definition:
mythuicheckbox.cpp:103
MythUICheckBox::Deselect
void Deselect()
Definition:
mythuicheckbox.cpp:118
MythUIType::SetCanTakeFocus
void SetCanTakeFocus(bool set=true)
Set whether this widget can take focus.
Definition:
mythuitype.cpp:362
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition:
mythlogging.h:39
MythUICheckBox::m_state
QString m_state
Definition:
mythuicheckbox.h:59
MythUICheckBox::Disable
void Disable()
Definition:
mythuicheckbox.cpp:136
MythUICheckBox::Finalize
void Finalize(void) override
Perform any post-xml parsing initialisation tasks.
Definition:
mythuicheckbox.cpp:216
MythUICheckBox::Select
void Select()
Definition:
mythuicheckbox.cpp:108
MythUIType::TakingFocus
void TakingFocus()
MythUICheckBox::toggled
void toggled(bool)
MythUICheckBox::CopyFrom
void CopyFrom(MythUIType *base) override
Copy this widgets state from another.
Definition:
mythuicheckbox.cpp:198
MythUICheckBox::valueChanged
void valueChanged()
mythlogging.h
MythMainWindow::TranslateKeyPress
bool TranslateKeyPress(const QString &Context, QKeyEvent *Event, QStringList &Actions, bool AllowJumps=true)
Get a list of actions for a keypress in the given context.
Definition:
mythmainwindow.cpp:1111
MythUIType::DependChanged
void DependChanged(bool isDefault)
MythUIType::IsEnabled
bool IsEnabled(void) const
Definition:
mythuitype.h:117
MythUIType::Disabling
void Disabling()
MythUICheckBox::MythUICheckBox
MythUICheckBox(MythUIType *parent, const QString &name)
Definition:
mythuicheckbox.cpp:12
MythUICheckBox::SetInitialStates
void SetInitialStates(void)
Definition:
mythuicheckbox.cpp:23
MythUICheckBox::CreateCopy
void CreateCopy(MythUIType *parent) override
Copy the state of this widget to the one given, it must be of the same type.
Definition:
mythuicheckbox.cpp:189
MythUIStateType::Off
@ Off
Definition:
mythuistatetype.h:27
MythUIType::CopyFrom
virtual void CopyFrom(MythUIType *base)
Copy this widgets state from another.
Definition:
mythuitype.cpp:1171
MythUICheckBox
A checkbox widget supporting three check states - on,off,half and two conditions - selected and unsel...
Definition:
mythuicheckbox.h:15
MythUICheckBox::Enable
void Enable()
Definition:
mythuicheckbox.cpp:129
mythgesture.h
A C++ ripoff of the stroke library for MythTV.
MythUICheckBox::toggleCheckState
void toggleCheckState(void)
Definition:
mythuicheckbox.cpp:43
MythUIType
The base class on which all widgets and screens are based.
Definition:
mythuitype.h:85
MythUICheckBox::SetCheckState
void SetCheckState(MythUIStateType::StateType state)
Definition:
mythuicheckbox.cpp:66
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition:
mythmainwindow.cpp:104
build_compdb.action
action
Definition:
build_compdb.py:9
MythUICheckBox::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition:
mythuicheckbox.cpp:166
MythUIStateType::StateType
StateType
Definition:
mythuistatetype.h:26
MythUIStateType::Full
@ Full
Definition:
mythuistatetype.h:27
MythGestureEvent
A custom event that represents a mouse gesture.
Definition:
mythgesture.h:39
mythuicheckbox.h
MythUICheckBox::GetCheckState
MythUIStateType::StateType GetCheckState() const
Definition:
mythuicheckbox.cpp:98
MythUIType::LosingFocus
void LosingFocus()
mythmainwindow.h
MythUIStateType
This widget is used for grouping other widgets for display when a particular named state is called....
Definition:
mythuistatetype.h:22
MythUIStateType::DisplayState
bool DisplayState(const QString &name)
Definition:
mythuistatetype.cpp:84
MythUICheckBox::gestureEvent
bool gestureEvent(MythGestureEvent *event) override
Mouse click/movement handler, receives mouse gesture events from the QCoreApplication event loop.
Definition:
mythuicheckbox.cpp:148
Generated on Sun Jan 19 2025 03:16:57 for MythTV by
1.8.17