MythTV  master
standardsettings.h
Go to the documentation of this file.
1 #ifndef STANDARDSETTINGS_H_
2 #define STANDARDSETTINGS_H_
3 
4 #include <initializer_list>
5 #include <utility>
6 
7 #include <QMap>
8 #include <QObject>
9 
10 #include "mythexp.h"
11 #include "mythuibuttonlist.h"
12 #include "mythdialogbox.h"
13 #include "mythstorage.h"
14 
15 class StandardSetting;
16 
17 class MythUIButtonListItemSetting : public QObject, public MythUIButtonListItem
18 {
19  Q_OBJECT
20 
21  public:
22  MythUIButtonListItemSetting (MythUIButtonList *lbtype, const QString &text)
23  : MythUIButtonListItem(lbtype, text) {}
24 
25  public slots:
26  void ShouldUpdate(StandardSetting *setting);
27 };
28 
29 class MPUBLIC StandardSetting : public QObject, public StorageUser
30 {
31  Q_OBJECT
32 
33  public:
34  virtual void setLabel(QString str) { m_label = std::move(str); }
35  QString getLabel(void) const { return m_label; }
36 
37  virtual void setHelpText(const QString &str) { m_helptext = str; emit helpTextChanged(m_helptext); }
38  QString getHelpText(void) const { return m_helptext; }
39 
40  virtual void setName(const QString &name);
41  QString getName(void) const { return m_name; }
42  StandardSetting * byName(const QString &name);
43 
44  bool isVisible(void) const { return m_visible; }
45  bool isEnabled() const { return m_enabled; }
46  bool haveChanged();
47  void setChanged(bool changed);
48  StandardSetting *getParent() const {return m_parent;}
49 
50  // Gets
51  virtual QString getValue(void) const {return m_settingValue;}
52 
53  virtual void updateButton(MythUIButtonListItem *item);
54 
55  // StorageUser
56  void SetDBValue(const QString &val) override { setValue(val); } // StorageUser
57  QString GetDBValue(void) const override { return getValue(); } // StorageUser
58 
59  MythUIButtonListItem *createButton(MythUIButtonList *list);
60 
61  //subsettings
62  virtual void addChild(StandardSetting *child);
63  virtual void removeChild(StandardSetting *child);
64  virtual QList<StandardSetting *> *getSubSettings();
65  virtual bool haveSubSettings();
66  virtual void clearSettings();
67  void clearTargetedSettings(const QString &value);
68 
69  virtual void edit(MythScreenType *screen) = 0;
70  virtual void resultEdit(DialogCompletionEvent *dce) = 0;
71 
72  virtual void Load(void);
73  virtual void Save(void);
74 
75  virtual void Open(void) {}
76  virtual void Close(void) {}
77 
78  Storage *GetStorage(void) const { return m_storage; }
79 
80  void addTargetedChild(const QString &value, StandardSetting *setting);
81  void addTargetedChildren(const QString &value,
82  std::initializer_list<StandardSetting *> settings);
83  void removeTargetedChild(const QString &value, StandardSetting *child);
84 
85  virtual bool keyPressEvent(QKeyEvent *event);
86 
87  void MoveToThread(QThread *thread);
88 
89  public slots:
90  virtual void setEnabled(bool enabled);
91  void setVisible(bool visible);
92  virtual void setValue(const QString &newValue);
93  virtual void setValue(int newValue);
94  virtual void childChanged(StandardSetting */*child*/) {}
95 
96  signals:
97  void valueChanged(const QString &newValue);
98  void valueChanged(StandardSetting *setting);
99  void ShouldRedraw(StandardSetting *setting);
100  void settingsChanged(StandardSetting *selectedSetting = nullptr);
101  void ChangeSaved();
102  void helpTextChanged(const QString &newValue);
103 
104  protected:
105  explicit StandardSetting(Storage *_storage = nullptr)
106  : m_storage(_storage) {}
107  ~StandardSetting() override;
108  void setParent(StandardSetting *parent);
109  QString m_settingValue;
110  bool m_enabled {true};
111  QString m_label;
112  QString m_helptext;
113  QString m_name;
114  bool m_visible {true};
115 
116  private:
117  bool m_haveChanged {false};
118  Storage *m_storage {nullptr};
119  StandardSetting *m_parent {nullptr};
120  QList<StandardSetting *> m_children;
121  QMap<QString, QList<StandardSetting *> > m_targets;
122 };
123 
125 {
126  public:
127  AutoIncrementSetting(QString _table, QString _column);
128 
129  void Save(void) override; // StandardSetting
130  void edit(MythScreenType * /*screen*/) override { } // StandardSetting
131  void resultEdit(DialogCompletionEvent * /*dce*/) override { } // StandardSetting
132 
133  protected:
134  QString m_table;
135  QString m_column;
136 };
137 
138 /*******************************************************************************
139 * TextEdit Setting *
140 *******************************************************************************/
141 
142 
144 {
145  public:
146  void resultEdit(DialogCompletionEvent *dce) override; // StandardSetting
147  void edit(MythScreenType *screen) override; // StandardSetting
148  void updateButton(MythUIButtonListItem *item) override; // StandardSetting
149  void SetPasswordEcho(bool b);
150 
151  protected:
152  explicit MythUITextEditSetting(Storage *_storage = nullptr)
153  : StandardSetting(_storage) {}
154  bool m_passwordEcho {false};
155 };
156 
157 
159 {
160  public:
161  TransTextEditSetting() = default;
162 };
163 
164 
166 {
167  public:
168  explicit HostTextEditSetting(const QString &name) :
169  MythUITextEditSetting(new HostDBStorage(this, name)) { }
170 };
171 
173 {
174  public:
175  explicit GlobalTextEditSetting(const QString &name) :
176  MythUITextEditSetting(new GlobalDBStorage(this, name)) { }
177 };
178 
179 /*******************************************************************************
180 * Directory Setting *
181 *******************************************************************************/
182 
183 
185 {
186  public:
187  void resultEdit(DialogCompletionEvent *dce) override; // StandardSetting
188  void edit(MythScreenType *screen) override; // StandardSetting
189  void updateButton(MythUIButtonListItem *item) override; // StandardSetting
190  void SetTypeFilter(QDir::Filters filter) { m_typeFilter = filter; };
191  void SetNameFilter(QStringList filter) { m_nameFilter = std::move(filter); };
192 
193  protected:
194  explicit MythUIFileBrowserSetting(Storage *_storage)
195  : StandardSetting(_storage) {}
196  QDir::Filters m_typeFilter {QDir::AllDirs | QDir::Drives |
197  QDir::Files | QDir::Readable |
198  QDir::Writable | QDir::Executable};
199  QStringList m_nameFilter {"*"};
200 };
201 
202 
204 {
205  public:
206  explicit HostFileBrowserSetting(const QString &name) :
207  MythUIFileBrowserSetting(new HostDBStorage(this, name)) { }
208 };
209 
210 
211 /*******************************************************************************
212 * ComboBox Setting *
213 *******************************************************************************/
214 //TODO implement rw=true
216 {
217  Q_OBJECT
218  public:
219  void setValue(int value) override; // StandardSetting
220  int getValueIndex(const QString &value) const;
221  QString getValueLabel(void) const;
222  void resultEdit(DialogCompletionEvent *dce) override; // StandardSetting
223  void edit(MythScreenType *screen) override; // StandardSetting
224  void addSelection(const QString &label, QString value = QString(),
225  bool select = false);
226  void clearSelections();
227  void fillSelectionsFromDir(const QDir &dir, bool absPath = true);
228  void updateButton(MythUIButtonListItem *item) override; // StandardSetting
229  virtual int size(void) const;
230 
231  public slots:
232  void setValue(const QString &newValue) override; // StandardSetting
233 
234  protected:
242  explicit MythUIComboBoxSetting(Storage *_storage = nullptr, bool rw = false)
243  : StandardSetting(_storage), m_rewrite(rw) {}
244  ~MythUIComboBoxSetting() override;
245  QVector<QString> m_labels;
246  QVector<QString> m_values;
247 
248  private:
249  bool m_rewrite;
250  bool m_isSet {false};
251 
252 };
253 
255 {
256  public:
257  explicit HostComboBoxSetting(const QString &name, bool rw = false) :
258  MythUIComboBoxSetting(new HostDBStorage(this, name), rw) { }
259 };
260 
261 
263 {
264  public:
265  explicit GlobalComboBoxSetting(const QString &name, bool rw = false) :
266  MythUIComboBoxSetting(new GlobalDBStorage(this, name), rw) { }
267 };
268 
270 {
271  public:
272  explicit TransMythUIComboBoxSetting(bool rw = false) :
273  MythUIComboBoxSetting(nullptr, rw) { }
274 };
275 
277 {
278  public:
279  explicit HostTimeBoxSetting(const QString &name,
280  const QString &defaultTime = "00:00",
281  const int interval = 1) :
283  {
284  for (int hour = 0; hour < 24; hour++)
285  {
286  for (int minute = 0; minute < 60; minute += interval)
287  {
288  QString timeStr = QString("%1:%2")
289  .arg(hour, 2,10,QChar('0'))
290  .arg(minute,2,10,QChar('0'));
291  addSelection(timeStr, timeStr,
292  timeStr == defaultTime);
293  }
294  }
295  }
296 };
297 
299 {
300  public:
301  explicit GlobalTimeBoxSetting(const QString &name,
302  const QString &defaultTime = "00:00",
303  const int interval = 1) :
305  {
306  for (int hour = 0; hour < 24; hour++)
307  {
308  for (int minute = 0; minute < 60; minute += interval)
309  {
310  QString timeStr = QString("%1:%2")
311  .arg(hour, 2,10,QChar('0'))
312  .arg(minute,2,10,QChar('0'));
313  addSelection(timeStr, timeStr,
314  timeStr == defaultTime);
315  }
316  }
317  }
318 };
319 
320 /*******************************************************************************
321 * SpinBox Setting *
322 *******************************************************************************/
323 
324 
326 {
327  public:
328  //void setValue(int value);
329  int intValue();
330  void resultEdit(DialogCompletionEvent *dce) override; // StandardSetting
331  void edit(MythScreenType *screen) override; // StandardSetting
332  void updateButton(MythUIButtonListItem *item) override; // StandardSetting
333 
334  protected:
335  // MythUISpinBoxSetting(Storage *_storage, int min, int max, int step,
336  // bool allow_single_step = false,
337  // const QString &special_value_text = QString());
338 
339  MythUISpinBoxSetting(Storage *_storage, int min, int max, int step,
340  int pageMultiple = 8,
341  QString special_value_text = QString());
342  private:
343  int m_min;
344  int m_max;
345  int m_step;
348 };
349 
351 {
352  public:
353  TransMythUISpinBoxSetting(int min, int max, int step,
354  int pageMultiple = 5,
355  const QString &special_value_text = QString()) :
356  MythUISpinBoxSetting(nullptr, min, max, step, pageMultiple,
357  special_value_text)
358  { }
359 };
360 
362 {
363  public:
364  HostSpinBoxSetting(const QString &name, int min, int max, int step,
365  int pageMultiple = 8,
366  const QString &special_value_text = QString()) :
367  MythUISpinBoxSetting(new HostDBStorage(this, name), min, max, step,
368  pageMultiple, special_value_text)
369  { }
370 };
371 
373 {
374  public:
375  GlobalSpinBoxSetting(const QString &name, int min, int max, int step,
376  int pageMultiple = 8,
377  const QString &special_value_text = QString()) :
378  MythUISpinBoxSetting(new GlobalDBStorage(this, name), min, max, step,
379  pageMultiple, special_value_text)
380  { }
381 };
382 
383 /*******************************************************************************
384 * CheckBox Setting *
385 *******************************************************************************/
386 
388 {
389  Q_OBJECT
390 
391  public:
392  void resultEdit(DialogCompletionEvent *dce) override; // StandardSetting
393  void edit(MythScreenType *screen) override; // StandardSetting
394  void updateButton(MythUIButtonListItem *item) override; // StandardSetting
395  void setValue(const QString &newValue) override; // StandardSetting
396  virtual void setValue(bool value);
398  bool boolValue() { return m_settingValue == "1"; }
399 
400  signals:
401  void valueChanged(bool);
402 
403  protected:
404  explicit MythUICheckBoxSetting(Storage *_storage = nullptr);
405 
406 };
407 
409 {
410  public:
411  TransMythUICheckBoxSetting() = default;
412 };
413 
415 {
416  public:
417  explicit HostCheckBoxSetting(const QString &name) :
418  MythUICheckBoxSetting(new HostDBStorage(this, name)) { }
419 };
420 
422 {
423  public:
424  explicit GlobalCheckBoxSetting(const QString &name) :
425  MythUICheckBoxSetting(new GlobalDBStorage(this, name)) { }
426 };
427 
428 /*******************************************************************************
429 * Group Setting *
430 *******************************************************************************/
431 
433 {
434  Q_OBJECT
435 
436  public:
437  GroupSetting() = default;
438 
439  void edit(MythScreenType *screen) override; // StandardSetting
440  void resultEdit(DialogCompletionEvent */*dce*/) override {} // StandardSetting
441  virtual void applyChange() {}
442  void updateButton(MythUIButtonListItem *item) override; // StandardSetting
443  virtual bool canDelete(void) {return false;}
444  virtual void deleteEntry(void) {}
445 };
446 
448 {
449  Q_OBJECT
450 
451  public:
452  explicit ButtonStandardSetting(const QString &label);
453 
454  void edit(MythScreenType *screen) override; // StandardSetting
455  void resultEdit(DialogCompletionEvent */*dce*/) override {}; // StandardSetting
456 
457  signals:
458  void clicked();
459 };
460 
461 /*******************************************************************************
462 * Standard Dialog Setting *
463 *******************************************************************************/
464 
466 {
467  Q_OBJECT
468 
469  public:
470 
471  StandardSettingDialog(MythScreenStack *parent, const char *name,
472  GroupSetting *groupSettings = nullptr)
473  : MythScreenType(parent, name), m_settingsTree(groupSettings) {}
474  ~StandardSettingDialog() override;
475  bool Create(void) override; // MythScreenType
476  void customEvent(QEvent *event) override; // MythUIType
477  bool keyPressEvent(QKeyEvent *event) override; // MythScreenType
478  void ShowMenu(void) override; // MythScreenType
479  void deleteEntry(void);
480 
481  public slots:
482  void Close(void) override; // MythScreenType
483  void updateSettings(StandardSetting *selectedSetting = nullptr);
484  void editEntry(void);
485  void deleteSelected(void);
486  void deleteEntryConfirmed(bool ok);
487 
488  protected:
489  void Load(void) override; // MythScreenType
490  void Init(void) override; // MythScreenType
491  GroupSetting *GetGroupSettings(void) const;
492  MythUIButtonList *m_buttonList {nullptr};
493 
494  private slots:
495  void settingSelected(MythUIButtonListItem *item);
496  void settingClicked(MythUIButtonListItem *item);
497 
498  private:
499  void LevelUp();
500  void LevelDown();
501  void setCurrentGroupSetting(StandardSetting *groupSettings,
502  StandardSetting *selectedSetting = nullptr);
503  void Save();
504 
505  MythUIText *m_title {nullptr};
506  MythUIText *m_groupHelp {nullptr};
507  MythUIText *m_selectedSettingHelp {nullptr};
508  MythDialogBox *m_menuPopup {nullptr};
509  GroupSetting *m_settingsTree {nullptr};
510  StandardSetting *m_currentGroupSetting {nullptr};
511  bool m_loaded {false};
512 };
513 
515 
516 
517 #endif
MythUITextEditSetting(Storage *_storage=nullptr)
HostTextEditSetting(const QString &name)
void resultEdit(DialogCompletionEvent *) override
MythUIFileBrowserSetting(Storage *_storage)
HostCheckBoxSetting(const QString &name)
unsigned int slots[4]
Definition: element.c:38
virtual bool canDelete(void)
virtual void ShowMenu(void)
#define MPUBLIC
Definition: mythexp.h:10
All purpose text widget, displays a text string.
Definition: mythuitext.h:28
void customEvent(QEvent *event) override
Definition: mythuitype.cpp:978
Storage * GetStorage(void) const
StandardSetting * getParent() const
void SetNameFilter(QStringList filter)
virtual bool Create(void)
Basic menu dialog, message and a list of options.
void addSelection(const QString &label, QString value=QString(), bool select=false)
QVector< QString > m_labels
virtual void setHelpText(const QString &str)
QVector< QString > m_values
QString getLabel(void) const
void resultEdit(DialogCompletionEvent *) override
void resultEdit(DialogCompletionEvent *) override
StandardSetting(Storage *_storage=nullptr)
MythUIButtonListItemSetting(MythUIButtonList *lbtype, const QString &text)
TransMythUIComboBoxSetting(bool rw=false)
virtual void Open(void)
QString getName(void) const
StandardSettingDialog(MythScreenStack *parent, const char *name, GroupSetting *groupSettings=nullptr)
virtual void updateButton(MythUIButtonListItem *item)
This method is called whenever the UI need to reflect a change Reimplement this If you widget need a ...
MythUIComboBoxSetting(Storage *_storage=nullptr, bool rw=false)
Create a Setting Widget to select the value from a list.
void SetDBValue(const QString &val) override
virtual QString getValue(void) const
GlobalTextEditSetting(const QString &name)
HostTimeBoxSetting(const QString &name, const QString &defaultTime="00:00", const int interval=1)
virtual void Close()
HostSpinBoxSetting(const QString &name, int min, int max, int step, int pageMultiple=8, const QString &special_value_text=QString())
Q_DECLARE_METATYPE(StandardSetting *)
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:85
QString GetDBValue(void) const override
virtual void setLabel(QString str)
void ShouldUpdate(StandardSetting *setting)
virtual void edit(MythScreenType *screen)=0
void valueChanged(const QString &newValue)
HostFileBrowserSetting(const QString &name)
GlobalTimeBoxSetting(const QString &name, const QString &defaultTime="00:00", const int interval=1)
HostComboBoxSetting(const QString &name, bool rw=false)
virtual void applyChange()
GlobalSpinBoxSetting(const QString &name, int min, int max, int step, int pageMultiple=8, const QString &special_value_text=QString())
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
bool isEnabled() const
QList< StandardSetting * > m_children
const char * m_name
Definition: ParseText.cpp:328
virtual void childChanged(StandardSetting *)
virtual void Save(void)
void edit(MythScreenType *) override
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
virtual void resultEdit(DialogCompletionEvent *dce)=0
TransMythUISpinBoxSetting(int min, int max, int step, int pageMultiple=5, const QString &special_value_text=QString())
void SetTypeFilter(QDir::Filters filter)
virtual void Close(void)
virtual void Init(void)
Used after calling Load() to assign data to widgets and other UI initilisation which is prohibited in...
virtual void Load(void)
Load data which will ultimately be displayed on-screen or used to determine what appears on-screen (S...
QMap< QString, QList< StandardSetting * > > m_targets
Screen in which all other widgets are contained and rendered.
virtual void deleteEntry(void)
GlobalCheckBoxSetting(const QString &name)
bool isVisible(void) const
Event dispatched from MythUI modal dialogs to a listening class containing a result of some form.
Definition: mythdialogbox.h:41
virtual void setValue(const QString &newValue)
GlobalComboBoxSetting(const QString &name, bool rw=false)
QString getHelpText(void) const
static void fillSelectionsFromDir(const QDir &dir, AudioOutput::ADCVect *list)