MythTV  master
mythdialogbox.h
Go to the documentation of this file.
1 #ifndef MYTHDIALOGBOX_H_
2 #define MYTHDIALOGBOX_H_
3 
4 #include <functional>
5 #include <utility>
6 
7 // Qt headers
8 #include <QDir>
9 #include <QEvent>
10 #include <QString>
11 #include <QStringList>
12 
13 // MythTV headers
14 #include "mythscreentype.h"
15 #include "mythuitextedit.h"
16 #include "mythmainwindow.h"
17 #include "mythlogging.h"
18 
19 
20 class QTimer;
21 
23 class MythUIButtonList;
24 class MythUIButton;
25 class MythUITextEdit;
26 class MythUISpinBox;
27 class MythUIImage;
28 class MythUIStateType;
29 class MythMenu;
30 
31 
41 class MUI_PUBLIC DialogCompletionEvent : public QEvent
42 {
43  public:
44  DialogCompletionEvent(QString id, int result, QString text,
45  QVariant data)
46  : QEvent(kEventType),
47  m_id(std::move(id)), m_result(result),
48  m_resultText(std::move(text)),
49  m_resultData(std::move(data)) { }
50 
51  QString GetId() { return m_id; }
52  int GetResult() { return m_result; }
53  QString GetResultText() { return m_resultText; }
54  QVariant GetData() { return m_resultData; }
55 
56  static Type kEventType;
57 
58  private:
59  QString m_id;
60  int m_result;
61  QString m_resultText;
62  QVariant m_resultData;
63 };
64 
65 
66 using MythUIButtonCallback = std::function<void(void)>;
67 
69 {
70  public:
71  explicit MythMenuItem(QString text, QVariant data = 0, bool checked = false, MythMenu *subMenu = nullptr) :
72  m_text(std::move(text)), m_data(std::move(data)),
73  m_checked(checked), m_subMenu(subMenu), m_useSlot(false) { Init(); }
74  MythMenuItem(QString text, const char *slot, bool checked = false, MythMenu *subMenu = nullptr) :
75  m_text(std::move(text)), m_data(QVariant::fromValue(slot)),
76  m_checked(checked), m_subMenu(subMenu) { Init(); }
77  MythMenuItem(QString text, const MythUIButtonCallback &slot, bool checked = false, MythMenu *subMenu = nullptr) :
78  m_text(std::move(text)), m_data(QVariant::fromValue(slot)),
79  m_checked(checked), m_subMenu(subMenu) { Init(); }
80 
81  QString m_text;
82  QVariant m_data {0};
83  bool m_checked {false};
84  MythMenu *m_subMenu {nullptr};
85  bool m_useSlot {true};
86 
87  private:
88  void Init(void) {}
89 };
90 
92 {
93  friend class MythDialogBox;
94 
95  public:
96  MythMenu(QString text, QObject *retobject, QString resultid);
97  MythMenu(QString title, QString text, QObject *retobject, QString resultid);
98  ~MythMenu(void);
99 
100  void AddItem(const QString &title, QVariant data = 0, MythMenu *subMenu = nullptr,
101  bool selected = false, bool checked = false);
102  void AddItem(const QString &title, const char *slot, MythMenu *subMenu = nullptr,
103  bool selected = false, bool checked = false);
104  void AddItem(const QString &title, const MythUIButtonCallback &slot,
105  MythMenu *subMenu = nullptr, bool selected = false,
106  bool checked = false);
107 
108  void SetSelectedByTitle(const QString &title);
109  void SetSelectedByData(const QVariant& data);
110 
111  void SetParent(MythMenu *parent) { m_parentMenu = parent; }
112 
113  bool IsEmpty() { return m_menuItems.isEmpty(); }
114 
115  private:
116  void Init(void) {}
117  void AddItem(MythMenuItem *item, bool selected, MythMenu *subMenu);
118 
119  MythMenu *m_parentMenu {nullptr};
120  QString m_title;
121  QString m_text;
122  QString m_resultid;
123  QObject *m_retObject {nullptr};
124  QList<MythMenuItem*> m_menuItems;
125  int m_selectedItem {0};
126 };
127 
137 {
138  Q_OBJECT
139  public:
140  MythDialogBox(QString text,
141  MythScreenStack *parent, const char *name,
142  bool fullscreen = false, bool osd = false)
143  : MythScreenType(parent, name, false), m_fullscreen(fullscreen),
144  m_osdDialog(osd), m_text(std::move(text)) {}
145  MythDialogBox(QString title, QString text,
146  MythScreenStack *parent, const char *name,
147  bool fullscreen = false, bool osd = false)
148  : MythScreenType(parent, name, false), m_fullscreen(fullscreen),
149  m_osdDialog(osd), m_title(std::move(title)),m_text(std::move(text)) {}
150  MythDialogBox(MythMenu* menu, MythScreenStack *parent, const char *name,
151  bool fullscreen = false, bool osd = false)
152  : MythScreenType(parent, name, false), m_fullscreen(fullscreen),
153  m_osdDialog(osd), m_menu(menu), m_currentMenu(menu) {}
154  ~MythDialogBox(void) override;
155 
156  bool Create(void) override; // MythScreenType
157 
158  void SetMenuItems(MythMenu *menu);
159 
160  void SetReturnEvent(QObject *retobject, const QString &resultid);
161  void SetBackAction(const QString &text, QVariant data);
162  void SetExitAction(const QString &text, QVariant data);
163  void SetText(const QString &text);
164 
165  void AddButton(const QString &title, QVariant data = 0,
166  bool newMenu = false, bool setCurrent = false);
167  void AddButton(const QString &title, const char *slot,
168  bool newMenu = false, bool setCurrent = false);
169  void AddButton(const QString &title, const MythUIButtonCallback &slot,
170  bool newMenu = false, bool setCurrent = false)
171  {
172  AddButton(title, QVariant::fromValue(slot), newMenu, setCurrent);
173  m_useSlots = true;
174  }
175 
176  bool keyPressEvent(QKeyEvent *event) override; // MythScreenType
177  bool gestureEvent(MythGestureEvent *event) override; // MythScreenType
178 
179  public slots:
180  void Select(MythUIButtonListItem* item);
181 
182  signals:
183  void Selected();
184  void Closed(QString, int);
185 
186  protected:
187  void SendEvent(int res, const QString& text = "", const QVariant& data = 0);
188  void updateMenu(void);
189 
190  MythUIText *m_titlearea {nullptr};
191  MythUIText *m_textarea {nullptr};
192  MythUIButtonList *m_buttonList {nullptr};
193  QObject *m_retObject {nullptr};
194  QString m_id;
195  bool m_useSlots {false};
196 
197  bool m_fullscreen {false};
198  bool m_osdDialog {false};
199  QString m_title;
200  QString m_text;
201 
202  QString m_backtext;
203  QVariant m_backdata {0};
204  QString m_exittext;
205  QVariant m_exitdata {0};
206 
207  MythMenu *m_menu {nullptr};
208  MythMenu *m_currentMenu {nullptr};
209 };
210 
211 
221 {
222  Q_OBJECT
223 
224  public:
225  MythConfirmationDialog(MythScreenStack *parent, QString message,
226  bool showCancel = true)
227  : MythScreenType(parent, "mythconfirmpopup"),
228  m_message(std::move(message)), m_showCancel(showCancel) {}
229 
230  bool Create(void) override; // MythScreenType
231  void SetReturnEvent(QObject *retobject, const QString &resultid);
232  void SetData(QVariant data) { m_resultData = std::move(data); }
233  void SetMessage(const QString &message);
234 
235  bool keyPressEvent(QKeyEvent *event) override; // MythScreenType
236 
237  signals:
238  void haveResult(bool);
239 
240  private:
241  void sendResult(bool ok);
242  MythUIText *m_messageText {nullptr};
243  QString m_message;
244  bool m_showCancel {true};
245  QObject *m_retObject {nullptr};
246  QString m_id;
247  QVariant m_resultData;
248 
249  private slots:
250  void Confirm(void);
251  void Cancel();
252 };
253 
263 {
264  Q_OBJECT
265 
266  public:
267  MythTextInputDialog(MythScreenStack *parent, QString message,
268  InputFilter filter = FilterNone,
269  bool isPassword = false,
270  QString defaultValue = "")
271  : MythScreenType(parent, "mythtextinputpopup"),
272  m_message(std::move(message)), m_defaultValue(std::move(defaultValue)),
273  m_filter(filter), m_isPassword(isPassword) {}
274 
275  bool Create(void) override; // MythScreenType
276  void SetReturnEvent(QObject *retobject, const QString &resultid);
277 
278  signals:
279  void haveResult(QString);
280 
281  protected:
282  MythUITextEdit *m_textEdit {nullptr};
283  QString m_message;
284  QString m_defaultValue;
286  bool m_isPassword {false};
287  QObject *m_retObject {nullptr};
288  QString m_id;
289 
290  protected slots:
291  void sendResult();
292 };
293 
294 
304 {
305  Q_OBJECT
306 
307  public:
308  MythSpinBoxDialog(MythScreenStack *parent, QString message);
309 
310  bool Create(void) override; // MythScreenType
311  void SetReturnEvent(QObject *retobject, const QString &resultid);
312 
313  void SetRange(int low, int high, int step, uint pageMultiple=5);
314  void AddSelection(const QString& label, int value);
315  void SetValue(const QString & value);
316  void SetValue(int value);
317 
318  signals:
319  void haveResult(QString);
320 
321  protected:
323  QString m_message;
324  QString m_defaultValue;
325  QObject *m_retObject;
326  QString m_id;
327 
328  protected slots:
329  void sendResult();
330 };
331 
332 
348 {
349  Q_OBJECT
350 
351  public:
353  const QString &title,
354  const QStringList &list,
355  bool matchAnywhere = false,
356  const QString &defaultValue = "");
357 
358  bool Create(void) override; // MythScreenType
359  void SetReturnEvent(QObject *retobject, const QString &resultid);
360 
361  signals:
362  void haveResult(QString);
363 
364  private:
369 
370  QString m_title;
371  QString m_defaultValue;
372  QStringList m_list;
374 
375  QObject *m_retObject;
376  QString m_id;
377 
378  private slots:
379  void slotSendResult(void);
380  void slotUpdateList(void);
381 };
382 
392 {
393  Q_OBJECT
394 
395  public:
396  // FIXME Not sure about this enum
398  // Date Resolution
399  kNoDate = 0x01,
400  kYear = 0x02,
401  kMonth = 0x04,
402  kDay = 0x08,
403 
404  // Time Resolution
405  kNoTime = 0x10,
406  kHours = 0x20,
407  kMinutes = 0x40,
408 
409  // Work forward/backwards or backwards and fowards from start time
410  kFutureDates = 0x100,
411  kPastDates = 0x200,
412  kAllDates = 0x300
413  };
414 
415  MythTimeInputDialog(MythScreenStack *parent, QString message,
416  int resolutionFlags,
417  QDateTime startTime = QDateTime::currentDateTime(),
418  int rangeLimit = 14);
419 
420  bool Create() override; // MythScreenType
421  void SetReturnEvent(QObject *retobject, const QString &resultid);
422 
423  signals:
424  void haveResult(QDateTime time);
425 
426  private slots:
427  void okClicked(void);
428 
429  private:
430  QString m_message;
431  QDateTime m_startTime;
434  QStringList m_list;
435  QString m_currentValue;
436 
439 
440  QObject *m_retObject;
441  QString m_id;
442 };
443 
444 MUI_PUBLIC MythConfirmationDialog *ShowOkPopup(const QString &message, QObject *parent = nullptr,
445  const char *slot = nullptr, bool showCancel = false);
446 template <typename Func>
447 MUI_PUBLIC MythConfirmationDialog *ShowOkPopup(const QString &message, QObject *parent,
448  Func slot, bool showCancel = false)
449 {
450  QString LOC = "ShowOkPopup('" + message + "') - ";
451  MythScreenStack *stk = nullptr;
452 
454 
455  if (win)
456  stk = win->GetStack("popup stack");
457  else
458  {
459  LOG(VB_GENERAL, LOG_ERR, LOC + "no main window?");
460  return nullptr;
461  }
462 
463  if (!stk)
464  {
465  LOG(VB_GENERAL, LOG_ERR, LOC + "no popup stack? "
466  "Is there a MythThemeBase?");
467  return nullptr;
468  }
469 
470  auto *pop = new MythConfirmationDialog(stk, message, showCancel);
471  if (pop->Create())
472  {
473  stk->AddScreen(pop);
474  if (parent)
475  QObject::connect(pop, &MythConfirmationDialog::haveResult, parent, slot,
476  Qt::QueuedConnection);
477  }
478  else
479  {
480  delete pop;
481  pop = nullptr;
482  LOG(VB_GENERAL, LOG_ERR, LOC + "Couldn't Create() Dialog");
483  }
484 
485  return pop;
486 }
487 
490 
492 Q_DECLARE_METATYPE(const char*)
494 
495 #endif
This widget is used for grouping other widgets for display when a particular named state is called.
bool IsEmpty()
MythUIText * m_titleText
static int SendEvent(const MythUtilCommandLineParser &cmdline)
MythDialogBox(QString text, MythScreenStack *parent, const char *name, bool fullscreen=false, bool osd=false)
void AddButton(const QString &title, const MythUIButtonCallback &slot, bool newMenu=false, bool setCurrent=false)
MythDialogBox(MythMenu *menu, MythScreenStack *parent, const char *name, bool fullscreen=false, bool osd=false)
QObject * m_retObject
unsigned int slots[4]
Definition: element.c:38
Dialog asking for user confirmation.
A widget for offering a range of numerical values where only the the bounding values and interval are...
Definition: mythuispinbox.h:16
All purpose text widget, displays a text string.
Definition: mythuitext.h:28
MythUIButtonList * m_itemList
MythUIButtonList * m_timeList
#define LOC
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:97
virtual bool Create(void)
Basic menu dialog, message and a list of options.
void SetParent(MythMenu *parent)
MythScreenStack * GetStack(const QString &stackname)
QString m_text
MythDialogBox(QString title, QString text, MythScreenStack *parent, const char *name, bool fullscreen=false, bool osd=false)
QString m_title
QList< MythMenuItem * > m_menuItems
Q_DECLARE_METATYPE(GrabberScript *)
static MythThemedMenu * menu
QObject * m_retObject
InputFilter
static Type kEventType
Definition: mythdialogbox.h:56
bool MUI_PUBLIC WaitFor(MythConfirmationDialog *dialog)
Blocks until confirmation dialog exits.
MythUISpinBox * m_spinBox
MythTextInputDialog(MythScreenStack *parent, QString message, InputFilter filter=FilterNone, bool isPassword=false, QString defaultValue="")
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
QString m_exittext
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:85
void Init(void)
Definition: mythdialogbox.h:88
A text entry and edit widget.
MythMenuItem(QString text, const MythUIButtonCallback &slot, bool checked=false, MythMenu *subMenu=nullptr)
Definition: mythdialogbox.h:77
MythConfirmationDialog(MythScreenStack *parent, QString message, bool showCancel=true)
QString m_backtext
unsigned int uint
Definition: compat.h:140
void Init(void)
A custom event that represents a mouse gesture.
Definition: mythgesture.h:39
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
DialogCompletionEvent(QString id, int result, QString text, QVariant data)
Definition: mythdialogbox.h:44
A single button widget.
Definition: mythuibutton.h:21
MythMainWindow * GetMythMainWindow(void)
MythUIButtonList * m_dateList
bool gestureEvent(MythGestureEvent *event) override
Mouse click/movement handler, receives mouse gesture events from the QCoreApplication event loop.
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
MythMenuItem(QString text, QVariant data=0, bool checked=false, MythMenu *subMenu=nullptr)
Definition: mythdialogbox.h:71
Dialog prompting the user to enter a text string.
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
QStringList m_list
MythMenuItem(QString text, const char *slot, bool checked=false, MythMenu *subMenu=nullptr)
Definition: mythdialogbox.h:74
#define MUI_PUBLIC
Definition: mythuiexp.h:9
Dialog prompting the user to enter a number using a spin box.
Screen in which all other widgets are contained and rendered.
MythUITextEdit * m_textEdit
QString m_resultid
MythUIText * m_matchesText
Event dispatched from MythUI modal dialogs to a listening class containing a result of some form.
Definition: mythdialogbox.h:41
std::function< void(void)> MythUIButtonCallback
Definition: mythdialogbox.h:66
MUI_PUBLIC MythConfirmationDialog * ShowOkPopup(const QString &message, QObject *parent=nullptr, const char *slot=nullptr, bool showCancel=false)
Non-blocking version of MythPopupBox::showOkPopup()
void SetData(QVariant data)
Provide a dialog to quickly find an entry in a list.
QString m_text
Definition: mythdialogbox.h:81