MythTV  master
mythdialogbox.h
Go to the documentation of this file.
1 #ifndef MYTHDIALOGBOX_H_
2 #define MYTHDIALOGBOX_H_
3 
4 #include <QDir>
5 #include <QEvent>
6 #include <QString>
7 #include <QStringList>
8 
9 #include "mythscreentype.h"
10 #include "mythuitextedit.h"
11 #include "mythmainwindow.h"
12 #include "mythlogging.h"
13 
14 #include <functional>
15 
16 class QTimer;
17 
19 class MythUIButtonList;
20 class MythUIButton;
21 class MythUITextEdit;
22 class MythUISpinBox;
23 class MythUIImage;
24 class MythUIStateType;
25 class MythMenu;
26 
27 
37 class MUI_PUBLIC DialogCompletionEvent : public QEvent
38 {
39  public:
40  DialogCompletionEvent(const QString &id, int result, QString text,
41  QVariant data)
42  : QEvent(kEventType),
43  m_id(id), m_result(result), m_resultText(text), m_resultData(data) { }
44 
45  QString GetId() { return m_id; }
46  int GetResult() { return m_result; }
47  QString GetResultText() { return m_resultText; }
48  QVariant GetData() { return m_resultData; }
49 
50  static Type kEventType;
51 
52  private:
53  QString m_id;
54  int m_result;
55  QString m_resultText;
56  QVariant m_resultData;
57 };
58 
59 
60 using MythUIButtonCallback = std::function<void(void)>;
61 
63 {
64  public:
65  MythMenuItem(const QString &text, QVariant data = 0, bool checked = false, MythMenu *subMenu = nullptr) :
66  m_text(text), m_data(data), m_checked(checked), m_subMenu(subMenu), m_useSlot(false) { Init(); }
67  MythMenuItem(const QString &text, const char *slot, bool checked = false, MythMenu *subMenu = nullptr) :
68  m_text(text), m_data(qVariantFromValue(slot)), m_checked(checked), m_subMenu(subMenu) { Init(); }
69  MythMenuItem(const QString &text, const MythUIButtonCallback &slot, bool checked = false, MythMenu *subMenu = nullptr) :
70  m_text(text), m_data(qVariantFromValue(slot)), m_checked(checked), m_subMenu(subMenu) { Init(); }
71 
72  QString m_text;
73  QVariant m_data {0};
74  bool m_checked {false};
75  MythMenu *m_subMenu {nullptr};
76  bool m_useSlot {true};
77 
78  private:
79  void Init(void) {}
80 };
81 
83 {
84  friend class MythDialogBox;
85 
86  public:
87  MythMenu(QString text, QObject *retobject, QString resultid);
88  MythMenu(QString title, QString text, QObject *retobject, QString resultid);
89  ~MythMenu(void);
90 
91  void AddItem(const QString &title, QVariant data = 0, MythMenu *subMenu = nullptr,
92  bool selected = false, bool checked = false);
93  void AddItem(const QString &title, const char *slot, MythMenu *subMenu = nullptr,
94  bool selected = false, bool checked = false);
95  void AddItem(const QString &title, const MythUIButtonCallback &slot,
96  MythMenu *subMenu = nullptr, bool selected = false,
97  bool checked = false);
98 
99  void SetSelectedByTitle(const QString &title);
100  void SetSelectedByData(const QVariant& data);
101 
102  void SetParent(MythMenu *parent) { m_parentMenu = parent; }
103 
104  bool IsEmpty() { return m_menuItems.isEmpty(); }
105 
106  private:
107  void Init(void) {}
108  void AddItem(MythMenuItem *, bool selected, MythMenu *subMenu);
109 
110  MythMenu *m_parentMenu {nullptr};
111  QString m_title;
112  QString m_text;
113  QString m_resultid;
114  QObject *m_retObject {nullptr};
115  QList<MythMenuItem*> m_menuItems;
116  int m_selectedItem {0};
117 };
118 
128 {
129  Q_OBJECT
130  public:
131  MythDialogBox(const QString &text,
132  MythScreenStack *parent, const char *name,
133  bool fullscreen = false, bool osd = false)
134  : MythScreenType(parent, name, false), m_fullscreen(fullscreen),
135  m_osdDialog(osd), m_text(text) {}
136  MythDialogBox(const QString &title, const QString &text,
137  MythScreenStack *parent, const char *name,
138  bool fullscreen = false, bool osd = false)
139  : MythScreenType(parent, name, false), m_fullscreen(fullscreen),
140  m_osdDialog(osd), m_title(title),m_text(text) {}
141  MythDialogBox(MythMenu* menu, 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_menu(menu), m_currentMenu(menu) {}
145  ~MythDialogBox(void);
146 
147  bool Create(void) override; // MythScreenType
148 
149  void SetMenuItems(MythMenu *menu);
150 
151  void SetReturnEvent(QObject *retobject, const QString &resultid);
152  void SetBackAction(const QString &text, QVariant data);
153  void SetExitAction(const QString &text, QVariant data);
154  void SetText(const QString &text);
155 
156  void AddButton(const QString &title, QVariant data = 0,
157  bool newMenu = false, bool setCurrent = false);
158  void AddButton(const QString &title, const char *slot,
159  bool newMenu = false, bool setCurrent = false);
160  void AddButton(const QString &title, const MythUIButtonCallback &slot,
161  bool newMenu = false, bool setCurrent = false)
162  {
163  AddButton(title, QVariant::fromValue(slot), newMenu, setCurrent);
164  m_useSlots = true;
165  }
166 
167  bool keyPressEvent(QKeyEvent *event) override; // MythScreenType
168  bool gestureEvent(MythGestureEvent *event) override; // MythScreenType
169 
170  public slots:
171  void Select(MythUIButtonListItem* item);
172 
173  signals:
174  void Selected();
175  void Closed(QString, int);
176 
177  protected:
178  void SendEvent(int res, const QString& text = "", const QVariant& data = 0);
179  void updateMenu(void);
180 
181  MythUIText *m_titlearea {nullptr};
182  MythUIText *m_textarea {nullptr};
183  MythUIButtonList *m_buttonList {nullptr};
184  QObject *m_retObject {nullptr};
185  QString m_id;
186  bool m_useSlots {false};
187 
188  bool m_fullscreen {false};
189  bool m_osdDialog {false};
190  QString m_title;
191  QString m_text;
192 
193  QString m_backtext;
194  QVariant m_backdata {0};
195  QString m_exittext;
196  QVariant m_exitdata {0};
197 
198  MythMenu *m_menu {nullptr};
199  MythMenu *m_currentMenu {nullptr};
200 };
201 
202 
212 {
213  Q_OBJECT
214 
215  public:
216  MythConfirmationDialog(MythScreenStack *parent, const QString &message,
217  bool showCancel = true)
218  : MythScreenType(parent, "mythconfirmpopup"),
219  m_message(message), m_showCancel(showCancel) {}
220 
221  bool Create(void) override; // MythScreenType
222  void SetReturnEvent(QObject *retobject, const QString &resultid);
223  void SetData(QVariant data) { m_resultData = data; }
224  void SetMessage(const QString &message);
225 
226  bool keyPressEvent(QKeyEvent *event) override; // MythScreenType
227 
228  signals:
229  void haveResult(bool);
230 
231  private:
232  void sendResult(bool);
233  MythUIText *m_messageText {nullptr};
234  QString m_message;
235  bool m_showCancel {true};
236  QObject *m_retObject {nullptr};
237  QString m_id;
238  QVariant m_resultData;
239 
240  private slots:
241  void Confirm(void);
242  void Cancel();
243 };
244 
254 {
255  Q_OBJECT
256 
257  public:
258  MythTextInputDialog(MythScreenStack *parent, const QString &message,
259  InputFilter filter = FilterNone,
260  bool isPassword = false,
261  const QString &defaultValue = "")
262  : MythScreenType(parent, "mythtextinputpopup"),
263  m_message(message), m_defaultValue(defaultValue),
264  m_filter(filter), m_isPassword(isPassword) {}
265 
266  bool Create(void) override; // MythScreenType
267  void SetReturnEvent(QObject *retobject, const QString &resultid);
268 
269  signals:
270  void haveResult(QString);
271 
272  protected:
273  MythUITextEdit *m_textEdit {nullptr};
274  QString m_message;
275  QString m_defaultValue;
277  bool m_isPassword {false};
278  QObject *m_retObject {nullptr};
279  QString m_id;
280 
281  protected slots:
282  void sendResult();
283 };
284 
285 
295 {
296  Q_OBJECT
297 
298  public:
299  MythSpinBoxDialog(MythScreenStack *parent, QString message);
300 
301  bool Create(void) override; // MythScreenType
302  void SetReturnEvent(QObject *retobject, const QString &resultid);
303 
304  void SetRange(int low, int high, int step, uint pageMultiple=5);
305  void AddSelection(const QString& label, int value);
306  void SetValue(const QString & value);
307  void SetValue(int value);
308 
309  signals:
310  void haveResult(QString);
311 
312  protected:
314  QString m_message;
315  QString m_defaultValue;
316  QObject *m_retObject;
317  QString m_id;
318 
319  protected slots:
320  void sendResult();
321 };
322 
323 
339 {
340  Q_OBJECT
341 
342  public:
344  const QString &title,
345  const QStringList &list,
346  bool matchAnywhere = false,
347  const QString &defaultValue = "");
348 
349  bool Create(void) override; // MythScreenType
350  void SetReturnEvent(QObject *retobject, const QString &resultid);
351 
352  signals:
353  void haveResult(QString);
354 
355  private:
360 
361  QString m_title;
362  QString m_defaultValue;
363  QStringList m_list;
365 
366  QObject *m_retObject;
367  QString m_id;
368 
369  private slots:
370  void slotSendResult(void);
371  void slotUpdateList(void);
372 };
373 
383 {
384  Q_OBJECT
385 
386  public:
387  // FIXME Not sure about this enum
389  // Date Resolution
390  kNoDate = 0x01,
391  kYear = 0x02,
392  kMonth = 0x04,
393  kDay = 0x08,
394 
395  // Time Resolution
396  kNoTime = 0x10,
397  kHours = 0x20,
398  kMinutes = 0x40,
399 
400  // Work forward/backwards or backwards and fowards from start time
401  kFutureDates = 0x100,
402  kPastDates = 0x200,
403  kAllDates = 0x300
404  };
405 
406  MythTimeInputDialog(MythScreenStack *parent, QString message,
407  int resolutionFlags,
408  QDateTime startTime = QDateTime::currentDateTime(),
409  int rangeLimit = 14);
410 
411  bool Create() override; // MythScreenType
412  void SetReturnEvent(QObject *retobject, const QString &resultid);
413 
414  signals:
415  void haveResult(QDateTime time);
416 
417  private slots:
418  void okClicked(void);
419 
420  private:
421  QString m_message;
422  QDateTime m_startTime;
425  QStringList m_list;
426  QString m_currentValue;
427 
430 
431  QObject *m_retObject;
432  QString m_id;
433 };
434 
435 MUI_PUBLIC MythConfirmationDialog *ShowOkPopup(const QString &message, QObject *parent = nullptr,
436  const char *slot = nullptr, bool showCancel = false);
437 template <typename Func>
438 MUI_PUBLIC MythConfirmationDialog *ShowOkPopup(const QString &message, QObject *parent,
439  Func slot, bool showCancel = false)
440 {
441  QString LOC = "ShowOkPopup('" + message + "') - ";
443  MythScreenStack *stk = nullptr;
444 
446 
447  if (win)
448  stk = win->GetStack("popup stack");
449  else
450  {
451  LOG(VB_GENERAL, LOG_ERR, LOC + "no main window?");
452  return nullptr;
453  }
454 
455  if (!stk)
456  {
457  LOG(VB_GENERAL, LOG_ERR, LOC + "no popup stack? "
458  "Is there a MythThemeBase?");
459  return nullptr;
460  }
461 
462  pop = new MythConfirmationDialog(stk, message, showCancel);
463  if (pop->Create())
464  {
465  stk->AddScreen(pop);
466  if (parent)
467  QObject::connect(pop, &MythConfirmationDialog::haveResult, parent, slot,
468  Qt::QueuedConnection);
469  }
470  else
471  {
472  delete pop;
473  pop = nullptr;
474  LOG(VB_GENERAL, LOG_ERR, LOC + "Couldn't Create() Dialog");
475  }
476 
477  return pop;
478 }
479 
482 
484 Q_DECLARE_METATYPE(const char*)
486 
487 #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)
MythConfirmationDialog(MythScreenStack *parent, const QString &message, bool showCancel=true)
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.
MythTextInputDialog(MythScreenStack *parent, const QString &message, InputFilter filter=FilterNone, bool isPassword=false, const QString &defaultValue="")
DialogCompletionEvent(const QString &id, int result, QString text, QVariant data)
Definition: mythdialogbox.h:40
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
QString m_title
QList< MythMenuItem * > m_menuItems
Q_DECLARE_METATYPE(GrabberScript *)
static MythThemedMenu * menu
QObject * m_retObject
InputFilter
static Type kEventType
Definition: mythdialogbox.h:50
bool MUI_PUBLIC WaitFor(MythConfirmationDialog *dialog)
Blocks until confirmation dialog exits.
bool gestureEvent(MythGestureEvent *) override
Mouse click/movement handler, receives mouse gesture events from the QCoreApplication event loop.
MythUISpinBox * m_spinBox
MythMenuItem(const QString &text, const MythUIButtonCallback &slot, bool checked=false, MythMenu *subMenu=nullptr)
Definition: mythdialogbox.h:69
MythDialogBox(const QString &text, MythScreenStack *parent, const char *name, bool fullscreen=false, bool osd=false)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
QString m_exittext
MythDialogBox(const QString &title, const QString &text, MythScreenStack *parent, const char *name, bool fullscreen=false, bool osd=false)
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:85
void Init(void)
Definition: mythdialogbox.h:79
A text entry and edit widget.
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 ...
A single button widget.
Definition: mythuibutton.h:21
MythMainWindow * GetMythMainWindow(void)
MythUIButtonList * m_dateList
Dialog prompting the user to enter a text string.
bool keyPressEvent(QKeyEvent *) override
Key event handler.
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
QStringList m_list
bool Create(void) override
MythMenuItem(const QString &text, QVariant data=0, bool checked=false, MythMenu *subMenu=nullptr)
Definition: mythdialogbox.h:65
#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.
MythMenuItem(const QString &text, const char *slot, bool checked=false, MythMenu *subMenu=nullptr)
Definition: mythdialogbox.h:67
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:37
std::function< void(void)> MythUIButtonCallback
Definition: mythdialogbox.h:60
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:72