MythTV master
mythuicheckbox.cpp
Go to the documentation of this file.
1
2// Own header
3#include "mythuicheckbox.h"
4
5// Myth headers
7
8// MythUI headers
9#include "mythmainwindow.h"
10#include "mythgesture.h"
11
12MythUICheckBox::MythUICheckBox(MythUIType *parent, const QString &name)
13 : MythUIType(parent, name)
14{
15 connect(this, &MythUIType::TakingFocus, this, &MythUICheckBox::Select);
17 connect(this, &MythUIType::Enabling, this, &MythUICheckBox::Enable);
18 connect(this, &MythUIType::Disabling, this, &MythUICheckBox::Disable);
19
20 SetCanTakeFocus(true);
21}
22
24{
25 m_backgroundState = dynamic_cast<MythUIStateType *>(GetChild("background"));
26 m_checkState = dynamic_cast<MythUIStateType *>(GetChild("checkstate"));
27
29 {
30 LOG(VB_GENERAL, LOG_ERR,
31 QString("Checkbox %1 is missing required elements")
32 .arg(objectName()));
33 }
34
35 if (m_checkState)
37
40}
41
42
44{
45 bool onOff = false;
46
48 {
50 onOff = true;
51 }
52 else
53 {
55 onOff = false;
56 }
57
58 if (m_checkState)
60
61 emit DependChanged(!onOff);
62 emit toggled(onOff);
63 emit valueChanged();
64}
65
67{
68 m_currentCheckState = state;
69 if (m_checkState)
71
72 if (state == MythUIStateType::Off)
73 emit DependChanged(true);
74 else
75 emit DependChanged(false);
76 emit valueChanged();
77}
78
80{
81 if (onOff)
82 {
84 }
85 else
86 {
88 }
89
90 if (m_checkState)
92
93 emit toggled(onOff);
94 emit DependChanged(!onOff);
95 emit valueChanged();
96}
97
99{
100 return m_currentCheckState;
101}
102
104{
106}
107
109{
110 if (!IsEnabled())
111 return;
112
113 m_state = "selected";
116}
117
119{
120 if (IsEnabled())
121 m_state = "active";
122 else
123 m_state = "disabled";
124
127}
128
130{
131 m_state = "active";
134}
135
137{
138 m_state = "disabled";
141}
142
149{
150 if (event->GetGesture() == MythGestureEvent::Click)
151 {
152 if (IsEnabled())
153 {
155 return true;
156 }
157 }
158
159 return false;
160}
161
166bool 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")
179 else
180 handled = false;
181 }
182
183 return handled;
184}
185
190{
191 auto *checkbox = new MythUICheckBox(parent, objectName());
192 checkbox->CopyFrom(this);
193}
194
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
209
211}
212
217{
219}
A custom event that represents a mouse gesture.
Definition: mythgesture.h:40
Gesture GetGesture() const
Definition: mythgesture.h:85
bool TranslateKeyPress(const QString &Context, QKeyEvent *Event, QStringList &Actions, bool AllowJumps=true)
Get a list of actions for a keypress in the given context.
A checkbox widget supporting three check states - on,off,half and two conditions - selected and unsel...
void SetCheckState(MythUIStateType::StateType state)
void toggleCheckState(void)
MythUIStateType * m_backgroundState
bool gestureEvent(MythGestureEvent *event) override
Mouse click/movement handler, receives mouse gesture events from the QCoreApplication event loop.
void toggled(bool)
MythUIStateType::StateType GetCheckState() const
void CreateCopy(MythUIType *parent) override
Copy the state of this widget to the one given, it must be of the same type.
void Finalize(void) override
Perform any post-xml parsing initialisation tasks.
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
void CopyFrom(MythUIType *base) override
Copy this widgets state from another.
MythUIStateType * m_checkState
bool GetBooleanCheckState(void) const
MythUIStateType::StateType m_currentCheckState
MythUICheckBox(MythUIType *parent, const QString &name)
void SetInitialStates(void)
void valueChanged()
This widget is used for grouping other widgets for display when a particular named state is called.
bool DisplayState(const QString &name)
The base class on which all widgets and screens are based.
Definition: mythuitype.h:86
bool IsEnabled(void) const
Definition: mythuitype.h:119
void SetCanTakeFocus(bool set=true)
Set whether this widget can take focus.
Definition: mythuitype.cpp:362
void TakingFocus(void)
void Disabling(void)
virtual void CopyFrom(MythUIType *base)
Copy this widgets state from another.
void Enabling(void)
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:138
void DependChanged(bool isDefault)
void LosingFocus(void)
A C++ ripoff of the stroke library for MythTV.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythMainWindow * GetMythMainWindow(void)