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 
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  LOG(VB_GENERAL, LOG_ERR,
30  QString("Checkbox %1 is missing required elements")
31  .arg(objectName()));
32 
33  if (m_CheckState)
35 
38 }
39 
40 
42 {
43  bool onOff = false;
44 
46  {
48  onOff = true;
49  }
50  else
51  {
53  onOff = false;
54  }
55 
56  if (m_CheckState)
58 
59  emit DependChanged(!onOff);
60  emit toggled(onOff);
61  emit valueChanged();
62 }
63 
65 {
66  m_currentCheckState = state;
67  if (m_CheckState)
68  m_CheckState->DisplayState(state);
69 
70  if (state == MythUIStateType::Off)
71  emit DependChanged(true);
72  else
73  emit DependChanged(false);
74  emit valueChanged();
75 }
76 
78 {
79  if (onOff)
80  {
82  }
83  else
84  {
86  }
87 
88  if (m_CheckState)
90 
91  emit toggled(onOff);
92  emit DependChanged(!onOff);
93  emit valueChanged();
94 }
95 
97 {
98  return m_currentCheckState;
99 }
100 
102 {
104 }
105 
107 {
108  if (!IsEnabled())
109  return;
110 
111  m_state = "selected";
112  if (m_BackgroundState)
114 }
115 
117 {
118  if (IsEnabled())
119  m_state = "active";
120  else
121  m_state = "disabled";
122 
123  if (m_BackgroundState)
125 }
126 
128 {
129  m_state = "active";
130  if (m_BackgroundState)
132 }
133 
135 {
136  m_state = "disabled";
137  if (m_BackgroundState)
139 }
140 
147 {
148  if (event->gesture() == MythGestureEvent::Click)
149  {
150  if (IsEnabled())
151  {
153  return true;
154  }
155  }
156 
157  return false;
158 }
159 
164 bool MythUICheckBox::keyPressEvent(QKeyEvent *event)
165 {
166  QStringList actions;
167  bool handled = false;
168  handled = GetMythMainWindow()->TranslateKeyPress("Global", event, actions);
169 
170  for (int i = 0; i < actions.size() && !handled; i++)
171  {
172  QString action = actions[i];
173  handled = true;
174 
175  if (action == "SELECT")
177  else
178  handled = false;
179  }
180 
181  return handled;
182 }
183 
188 {
189  MythUICheckBox *checkbox = new MythUICheckBox(parent, objectName());
190  checkbox->CopyFrom(this);
191 }
192 
197 {
198  MythUICheckBox *button = dynamic_cast<MythUICheckBox *>(base);
199 
200  if (!button)
201  {
202  LOG(VB_GENERAL, LOG_ERR, "Dynamic cast of base failed");
203  return;
204  }
205 
206  MythUIType::CopyFrom(base);
207 
209 }
210 
215 {
217 }
bool keyPressEvent(QKeyEvent *) override
Key event handler.
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)
A checkbox widget supporting three check states - on,off,half and two conditions - selected and unsel...
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
const char * name
Definition: ParseText.cpp:328
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()
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:132
void SetCanTakeFocus(bool set=true)
Set whether this widget can take focus.
Definition: mythuitype.cpp:344
MythUIStateType * m_BackgroundState