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 }
MythUICheckBox::m_currentCheckState
MythUIStateType::StateType m_currentCheckState
Definition: mythuicheckbox.h:57
MythUICheckBox::m_backgroundState
MythUIStateType * m_backgroundState
Definition: mythuicheckbox.h:54
MythUICheckBox::m_checkState
MythUIStateType * m_checkState
Definition: mythuicheckbox.h:55
MythUIType::Enabling
void Enabling()
MythMainWindow::TranslateKeyPress
bool TranslateKeyPress(const QString &context, QKeyEvent *e, QStringList &actions, bool allowJumps=true)
Get a list of actions for a keypress in the given context.
Definition: mythmainwindow.cpp:1106
MythUIType::GetChild
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:130
MythUICheckBox::GetBooleanCheckState
bool GetBooleanCheckState(void) const
Definition: mythuicheckbox.cpp:103
MythUICheckBox::Deselect
void Deselect()
Definition: mythuicheckbox.cpp:118
arg
arg(title).arg(filename).arg(doDelete))
MythUIType::SetCanTakeFocus
void SetCanTakeFocus(bool set=true)
Set whether this widget can take focus.
Definition: mythuitype.cpp:342
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MythUICheckBox::m_state
QString m_state
Definition: mythuicheckbox.h:58
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
MythUIType::DependChanged
void DependChanged(bool isDefault)
MythUIType::IsEnabled
bool IsEnabled(void) const
Definition: mythuitype.h:94
MythUIType::Disabling
void Disabling()
MythGestureEvent::gesture
Gesture gesture(void) const
Get the gesture type.
Definition: mythgesture.h:109
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
MythGestureEvent::Click
@ Click
Definition: mythgesture.h:75
MythUIType::CopyFrom
virtual void CopyFrom(MythUIType *base)
Copy this widgets state from another.
Definition: mythuitype.cpp:1152
MythUIStateType::Full
@ Full
Definition: mythuistatetype.h:25
MythUICheckBox
A checkbox widget supporting three check states - on,off,half and two conditions - selected and unsel...
Definition: mythuicheckbox.h:16
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:64
MythUIStateType::Off
@ Off
Definition: mythuistatetype.h:25
MythUIStateType::StateType
StateType
Definition: mythuistatetype.h:25
MythUICheckBox::SetCheckState
void SetCheckState(MythUIStateType::StateType state)
Definition: mythuicheckbox.cpp:66
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:107
build_compdb.action
action
Definition: build_compdb.py:9
MythUICheckBox::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: mythuicheckbox.cpp:166
MythGestureEvent
A custom event that represents a mouse gesture.
Definition: mythgesture.h:40
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:23
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