MythTV  master
mythuicheckbox.cpp
Go to the documentation of this file.
1 
2 // Own header
3 #include "mythuicheckbox.h"
4 
5 // Myth headers
6 #include "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, SIGNAL(TakingFocus()), this, SLOT(Select()));
16  connect(this, SIGNAL(LosingFocus()), this, SLOT(Deselect()));
17  connect(this, SIGNAL(Enabling()), this, SLOT(Enable()));
18  connect(this, SIGNAL(Disabling()), this, SLOT(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)
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 
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";
114  if (m_BackgroundState)
116 }
117 
119 {
120  if (IsEnabled())
121  m_state = "active";
122  else
123  m_state = "disabled";
124 
125  if (m_BackgroundState)
127 }
128 
130 {
131  m_state = "active";
132  if (m_BackgroundState)
134 }
135 
137 {
138  m_state = "disabled";
139  if (m_BackgroundState)
141 }
142 
149 {
150  if (event->gesture() == MythGestureEvent::Click)
151  {
152  if (IsEnabled())
153  {
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  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 
208  MythUIType::CopyFrom(base);
209 
211 }
212 
217 {
219 }
MythUIStateType::StateType GetCheckState() const
void Finalize(void) override
Perform any post-xml parsing initialisation tasks.
bool TranslateKeyPress(const QString &context, QKeyEvent *e, QStringList &actions, bool allowJumps=true)
Get a list of actions for a keypress in the given context.
void LosingFocus()
MythUICheckBox(MythUIType *parent, const QString &name)
void CopyFrom(MythUIType *base) override
Copy this widgets state from another.
bool gestureEvent(MythGestureEvent *event) override
Mouse click/movement handler, receives mouse gesture events from the QCoreApplication event loop.
void toggled(bool)
void Enabling()
MythUIStateType::StateType m_currentCheckState
Gesture gesture(void) const
Get the gesture type.
Definition: mythgesture.h:107
The base class on which all widgets and screens are based.
Definition: mythuitype.h:63
MythUIStateType * m_CheckState
bool GetBooleanCheckState(void) const
void TakingFocus()
A C++ ripoff of the stroke library for MythTV.
void DependChanged(bool isDefault)
void SetInitialStates(void)
A custom event that represents a mouse gesture.
Definition: mythgesture.h:39
MythMainWindow * GetMythMainWindow(void)
void CreateCopy(MythUIType *parent) override
Copy the state of this widget to the one given, it must be of the same type.
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
void valueChanged()
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
virtual void CopyFrom(MythUIType *base)
Copy this widgets state from another.
bool IsEnabled(void) const
Definition: mythuitype.h:94
bool DisplayState(const QString &name)
void SetCheckState(MythUIStateType::StateType state)
void toggleCheckState(void)
void Disabling()
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:130
void SetCanTakeFocus(bool set=true)
Set whether this widget can take focus.
Definition: mythuitype.cpp:342
MythUIStateType * m_BackgroundState