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
18
19
20class QTimer;
21
22class MythUIButton;
23class MythUITextEdit;
24class MythUISpinBox;
25class MythUIImage;
26class MythUIStateType;
27class MythMenu;
28
29
39class MUI_PUBLIC DialogCompletionEvent : public QEvent
40{
41 public:
42 DialogCompletionEvent(QString id, int result, QString text,
43 QVariant data)
44 : QEvent(kEventType),
45 m_id(std::move(id)), m_result(result),
46 m_resultText(std::move(text)),
47 m_resultData(std::move(data)) { }
48 ~DialogCompletionEvent() override;
49
50 QString GetId() { return m_id; }
51 int GetResult() const { return m_result; }
52 QString GetResultText() { return m_resultText; }
53 QVariant GetData() { return m_resultData; }
54
55 static const Type kEventType;
56
57 private:
58 QString m_id;
60 QString m_resultText;
61 QVariant m_resultData;
62};
63
64
66{
67 public:
68 MythMenuItem(QString text, bool checked = false, MythMenu *subMenu = nullptr) :
69 m_text(std::move(text)), m_checked(checked), m_subMenu(subMenu) { Init(); }
70 // For non-class, static class, or lambda functions.
71 MythMenuItem(QString text, const MythUICallbackNMF &slot,
72 bool checked = false, MythMenu *subMenu = nullptr) :
73 m_text(std::move(text)), m_data(QVariant::fromValue(slot)),
74 m_checked(checked), m_subMenu(subMenu) { Init(); }
75 // For class member functions.
76 MythMenuItem(QString text, MythUICallbackMF slot,
77 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 // For const class member functions.
81 MythMenuItem(QString text, MythUICallbackMFc slot,
82 bool checked = false, MythMenu *subMenu = nullptr) :
83 m_text(std::move(text)), m_data(QVariant::fromValue(slot)),
84 m_checked(checked), m_subMenu(subMenu) { Init(); }
85 void SetData(QVariant data) { m_data = std::move(data); }
86
87 QString m_text;
88 QVariant m_data {0};
89 bool m_checked {false};
90 MythMenu *m_subMenu {nullptr};
91 bool m_useSlot {true};
92
93 private:
94 void Init(void) {}
95};
96
98{
99 friend class MythDialogBox;
100
101 public:
102 MythMenu(QString text, QObject *retobject, QString resultid);
103 MythMenu(QString title, QString text, QObject *retobject, QString resultid);
104 ~MythMenu(void);
105
106 void AddItemV(const QString &title, QVariant data = 0, MythMenu *subMenu = nullptr,
107 bool selected = false, bool checked = false);
108 void AddItem(const QString &title) { AddItemV(title); };
109 // For non-class, static class, or lambda functions.
110 void AddItem(const QString &title, const MythUICallbackNMF &slot,
111 MythMenu *subMenu = nullptr, bool selected = false,
112 bool checked = false);
113 // For class member non-const functions.
114 template <typename SLOT>
115 void AddItem(const QString &title, const SLOT &slot,
116 MythMenu *subMenu = nullptr, bool selected = false,
117 bool checked = false)
118 requires is_nonconst_member_func_v<SLOT>
119 {
120 auto slot2 = static_cast<MythUICallbackMF>(slot);
121 auto *item = new MythMenuItem(title, slot2, checked, subMenu);
122 AddItem(item, selected, subMenu);
123 }
124 // For class member const functions.
125 template <typename SLOT>
126 void AddItem(const QString &title, const SLOT &slot,
127 MythMenu *subMenu = nullptr, bool selected = false,
128 bool checked = false)
129 requires is_const_member_func_v<SLOT>
130 {
131 auto slot2 = static_cast<MythUICallbackMFc>(slot);
132 auto *item = new MythMenuItem(title, slot2, checked, subMenu);
133 AddItem(item, selected, subMenu);
134 }
135
136 void SetSelectedByTitle(const QString &title);
137 void SetSelectedByData(const QVariant& data);
138
139 void SetParent(MythMenu *parent) { m_parentMenu = parent; }
140
141 bool IsEmpty() { return m_menuItems.isEmpty(); }
142
143 private:
144 void Init(void) {}
145 void AddItem(MythMenuItem *item, bool selected, MythMenu *subMenu);
146
147 MythMenu *m_parentMenu {nullptr};
148 QString m_title;
149 QString m_text;
150 QString m_resultid;
151 QObject *m_retObject {nullptr};
152 QList<MythMenuItem*> m_menuItems;
153 int m_selectedItem {0};
154};
155
165{
166 Q_OBJECT
167 public:
168 MythDialogBox(QString text,
169 MythScreenStack *parent, const char *name,
170 bool fullscreen = false, bool osd = false)
171 : MythScreenType(parent, name, false), m_fullscreen(fullscreen),
172 m_osdDialog(osd), m_text(std::move(text)) {}
173 MythDialogBox(QString title, QString text,
174 MythScreenStack *parent, const char *name,
175 bool fullscreen = false, bool osd = false)
176 : MythScreenType(parent, name, false), m_fullscreen(fullscreen),
177 m_osdDialog(osd), m_title(std::move(title)),m_text(std::move(text)) {}
178 MythDialogBox(MythMenu* menu, MythScreenStack *parent, const char *name,
179 bool fullscreen = false, bool osd = false)
180 : MythScreenType(parent, name, false), m_fullscreen(fullscreen),
181 m_osdDialog(osd), m_menu(menu), m_currentMenu(menu) {}
182 ~MythDialogBox(void) override;
183
184 bool Create(void) override; // MythScreenType
185
186 void SetMenuItems(MythMenu *menu);
187
188 void SetReturnEvent(QObject *retobject, const QString &resultid);
189 void SetBackAction(const QString &text, QVariant data);
190 void SetExitAction(const QString &text, QVariant data);
191 void SetText(const QString &text);
192
193 void AddButtonV(const QString &title, QVariant data = 0,
194 bool newMenu = false, bool setCurrent = false);
195 void AddButtonD(const QString &title, bool setCurrent) { AddButtonV(title, 0,false, setCurrent); }
196 void AddButton(const QString &title) { AddButtonV(title, 0,false, false); }
197 // For non-class, static class, or lambda functions.
198 void AddButton(const QString &title, const MythUICallbackNMF &slot,
199 bool newMenu = false, bool setCurrent = false)
200 {
201 AddButtonV(title, QVariant::fromValue(slot), newMenu, setCurrent);
202 m_useSlots = true;
203 }
204 // For class member non-const functions.
205 template <typename SLOT>
206 void AddButton(const QString &title, const SLOT &slot,
207 bool newMenu = false, bool setCurrent = false)
208 requires is_nonconst_member_func_v<SLOT>
209 {
210 auto slot2 = static_cast<MythUICallbackMF>(slot);
211 AddButtonV(title, QVariant::fromValue(slot2), newMenu, setCurrent);
212 m_useSlots = true;
213 }
214 // For class member const functions.
215 template <typename SLOT>
216 void AddButton(const QString &title, const SLOT &slot,
217 bool newMenu = false, bool setCurrent = false)
218 requires is_const_member_func_v<SLOT>
219 {
220 auto slot2 = static_cast<MythUICallbackMFc>(slot);
221 AddButtonV(title, QVariant::fromValue(slot2), newMenu, setCurrent);
222 m_useSlots = true;
223 }
224
225 bool keyPressEvent(QKeyEvent *event) override; // MythScreenType
226 bool inputMethodEvent(QInputMethodEvent *event) override;// MythScreenType
227 bool gestureEvent(MythGestureEvent *event) override; // MythScreenType
228
229 public slots:
230 void Select(MythUIButtonListItem* item);
231
232 signals:
233 void Selected();
234 void Closed(QString, int);
235
236 protected:
237 void SendEvent(int res, const QString& text = "", const QVariant& data = 0);
238 void updateMenu(void);
239
240 MythUIText *m_titlearea {nullptr};
241 MythUIText *m_textarea {nullptr};
242 MythUIButtonList *m_buttonList {nullptr};
243 QObject *m_retObject {nullptr};
244 QString m_id;
245 bool m_useSlots {false};
246
247 bool m_fullscreen {false};
248 bool m_osdDialog {false};
249 QString m_title;
250 QString m_text;
251
252 QString m_backtext;
253 QVariant m_backdata {0};
254 QString m_exittext;
255 QVariant m_exitdata {0};
256
257 MythMenu *m_menu {nullptr};
258 MythMenu *m_currentMenu {nullptr};
259};
260
261
271{
272 Q_OBJECT
273
274 public:
275 MythConfirmationDialog(MythScreenStack *parent, QString message,
276 bool showCancel = true)
277 : MythScreenType(parent, "mythconfirmpopup"),
278 m_message(std::move(message)), m_showCancel(showCancel) {}
279
280 bool Create(void) override; // MythScreenType
281 void SetReturnEvent(QObject *retobject, const QString &resultid);
282 void SetData(QVariant data) { m_resultData = std::move(data); }
283 void SetMessage(const QString &message);
284
285 bool keyPressEvent(QKeyEvent *event) override; // MythScreenType
286
287 signals:
288 void haveResult(bool);
289
290 private:
291 void sendResult(bool ok);
292 MythUIText *m_messageText {nullptr};
293 QString m_message;
294 bool m_showCancel {true};
295 QObject *m_retObject {nullptr};
296 QString m_id;
297 QVariant m_resultData;
298
299 private slots:
300 void Confirm(void);
301 void Cancel();
302};
303
313{
314 Q_OBJECT
315
316 public:
317 MythTextInputDialog(MythScreenStack *parent, QString message,
318 InputFilter filter = FilterNone,
319 bool isPassword = false,
320 QString defaultValue = "")
321 : MythScreenType(parent, "mythtextinputpopup"),
322 m_message(std::move(message)), m_defaultValue(std::move(defaultValue)),
323 m_filter(filter), m_isPassword(isPassword) {}
324
325 bool Create(void) override; // MythScreenType
326 void SetReturnEvent(QObject *retobject, const QString &resultid);
327
328 signals:
329 void haveResult(QString);
330
331 protected:
332 MythUITextEdit *m_textEdit {nullptr};
333 QString m_message;
336 bool m_isPassword {false};
337 QObject *m_retObject {nullptr};
338 QString m_id;
339
340 protected slots:
341 void sendResult();
342};
343
344
354{
355 Q_OBJECT
356
357 public:
358 MythSpinBoxDialog(MythScreenStack *parent, QString message);
359
360 bool Create(void) override; // MythScreenType
361 void SetReturnEvent(QObject *retobject, const QString &resultid);
362
363 void SetRange(int low, int high, int step, uint pageMultiple=5);
364 void AddSelection(const QString& label, int value);
365 void SetValue(const QString & value);
366 void SetValue(int value);
367
368 signals:
369 void haveResult(QString);
370
371 protected:
372 MythUISpinBox *m_spinBox { nullptr };
373 QString m_message;
375 QObject *m_retObject { nullptr };
376 QString m_id;
377
378 protected slots:
379 void sendResult();
380};
381
382
398{
399 Q_OBJECT
400
401 public:
412 QString title,
413 QStringList list,
414 bool matchAnywhere = false,
415 QString defaultValue = "")
416 : MythScreenType(parent, "mythsearchdialogpopup"),
417 m_title(std::move(title)),
418 m_defaultValue(std::move(defaultValue)),
419 m_list(std::move(list)),
420 m_matchAnywhere(matchAnywhere),
421 m_id("") {};
422
423 bool Create(void) override; // MythScreenType
424 void SetReturnEvent(QObject *retobject, const QString &resultid);
425
426 signals:
427 void haveResult(QString);
428
429 private:
430 MythUIButtonList *m_itemList { nullptr };
431 MythUITextEdit *m_textEdit { nullptr };
432 MythUIText *m_titleText { nullptr };
433 MythUIText *m_matchesText { nullptr };
434
435 QString m_title;
437 QStringList m_list;
438 bool m_matchAnywhere { false };
439
440 QObject *m_retObject { nullptr };
441 QString m_id;
442
443 private slots:
444 void slotSendResult(void);
445 void slotUpdateList(void);
446};
447
457{
458 Q_OBJECT
459
460 public:
461 // FIXME Not sure about this enum
463 // Date Resolution
464 kNoDate = 0x01,
465 kYear = 0x02,
466 kMonth = 0x04,
467 kDay = 0x08,
468
469 // Time Resolution
470 kNoTime = 0x10,
471 kHours = 0x20,
472 kMinutes = 0x40,
473
474 // Work forward/backwards or backwards and fowards from start time
475 kFutureDates = 0x100,
476 kPastDates = 0x200,
477 kAllDates = 0x300
478 };
479
480 MythTimeInputDialog(MythScreenStack *parent, QString message,
481 int resolutionFlags,
482 QDateTime startTime = QDateTime::currentDateTime(),
483 int rangeLimit = 14);
484
485 bool Create() override; // MythScreenType
486 void SetReturnEvent(QObject *retobject, const QString &resultid);
487
488 signals:
489 void haveResult(QDateTime time);
490
491 private slots:
492 void okClicked(void);
493
494 private:
495 QString m_message;
496 QDateTime m_startTime;
499 QStringList m_list;
501
502 MythUIButtonList *m_dateList { nullptr };
503 MythUIButtonList *m_timeList { nullptr };
504
505 QObject *m_retObject { nullptr };
506 QString m_id;
507};
508
509MUI_PUBLIC MythConfirmationDialog *ShowOkPopup(const QString &message, bool showCancel = false);
510template <class OBJ, typename FUNC>
511MythConfirmationDialog *ShowOkPopup(const QString &message, const OBJ *parent,
512 FUNC slot, bool showCancel = false)
513{
514 auto* pop = ShowOkPopup(message, showCancel);
515 if (pop != nullptr && parent != nullptr)
516 {
517 QObject::connect(pop, &MythConfirmationDialog::haveResult, parent, slot,
518 Qt::QueuedConnection);
519 }
520
521 return pop;
522}
523
526
528Q_DECLARE_METATYPE(const char*)
529
530#endif
static int SendEvent(const MythUtilCommandLineParser &cmdline)
Event dispatched from MythUI modal dialogs to a listening class containing a result of some form.
Definition: mythdialogbox.h:40
static const Type kEventType
Definition: mythdialogbox.h:55
DialogCompletionEvent(QString id, int result, QString text, QVariant data)
Definition: mythdialogbox.h:42
Dialog asking for user confirmation.
MythConfirmationDialog(MythScreenStack *parent, QString message, bool showCancel=true)
void SetData(QVariant data)
Basic menu dialog, message and a list of options.
MythDialogBox(QString title, QString text, MythScreenStack *parent, const char *name, bool fullscreen=false, bool osd=false)
QString m_backtext
void AddButton(const QString &title)
MythDialogBox(MythMenu *menu, MythScreenStack *parent, const char *name, bool fullscreen=false, bool osd=false)
void AddButton(const QString &title, const MythUICallbackNMF &slot, bool newMenu=false, bool setCurrent=false)
QString m_exittext
void AddButton(const QString &title, const SLOT &slot, bool newMenu=false, bool setCurrent=false)
void AddButtonD(const QString &title, bool setCurrent)
QObject * m_retObject
void Closed(QString, int)
void AddButton(const QString &title, const SLOT &slot, bool newMenu=false, bool setCurrent=false)
MythDialogBox(QString text, MythScreenStack *parent, const char *name, bool fullscreen=false, bool osd=false)
A custom event that represents a mouse gesture.
Definition: mythgesture.h:40
void SetData(QVariant data)
Definition: mythdialogbox.h:85
MythMenuItem(QString text, MythUICallbackMFc slot, bool checked=false, MythMenu *subMenu=nullptr)
Definition: mythdialogbox.h:81
void Init(void)
Definition: mythdialogbox.h:94
QString m_text
Definition: mythdialogbox.h:87
MythMenuItem(QString text, bool checked=false, MythMenu *subMenu=nullptr)
Definition: mythdialogbox.h:68
MythMenuItem(QString text, const MythUICallbackNMF &slot, bool checked=false, MythMenu *subMenu=nullptr)
Definition: mythdialogbox.h:71
MythMenuItem(QString text, MythUICallbackMF slot, bool checked=false, MythMenu *subMenu=nullptr)
Definition: mythdialogbox.h:76
bool IsEmpty()
QString m_title
void AddItem(const QString &title, const SLOT &slot, MythMenu *subMenu=nullptr, bool selected=false, bool checked=false)
void Init(void)
void AddItem(const QString &title, const SLOT &slot, MythMenu *subMenu=nullptr, bool selected=false, bool checked=false)
void AddItem(const QString &title)
QString m_text
void SetParent(MythMenu *parent)
QList< MythMenuItem * > m_menuItems
QString m_resultid
Screen in which all other widgets are contained and rendered.
Dialog prompting the user to enter a number using a spin box.
void haveResult(QString)
Dialog prompting the user to enter a text string.
MythTextInputDialog(MythScreenStack *parent, QString message, InputFilter filter=FilterNone, bool isPassword=false, QString defaultValue="")
void haveResult(QString)
void haveResult(QDateTime time)
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
A single button widget.
Definition: mythuibutton.h:22
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:98
Provide a dialog to quickly find an entry in a list.
MythUISearchDialog(MythScreenStack *parent, QString title, QStringList list, bool matchAnywhere=false, QString defaultValue="")
the classes constructor
QStringList m_list
void haveResult(QString)
A widget for offering a range of numerical values where only the the bounding values and interval are...
Definition: mythuispinbox.h:19
This widget is used for grouping other widgets for display when a particular named state is called.
A text entry and edit widget.
All purpose text widget, displays a text string.
Definition: mythuitext.h:29
unsigned int uint
Definition: compat.h:60
unsigned short uint16_t
Definition: iso6937tables.h:3
Q_DECLARE_METATYPE(std::chrono::seconds)
bool MUI_PUBLIC WaitFor(MythConfirmationDialog *dialog)
Blocks until confirmation dialog exits.
MUI_PUBLIC MythConfirmationDialog * ShowOkPopup(const QString &message, bool showCancel=false)
Non-blocking version of MythPopupBox::showOkPopup()
static MythThemedMenu * menu
#define MUI_PUBLIC
Definition: mythuiexp.h:9
InputFilter
@ FilterNone
void(QObject::*)(void) const MythUICallbackMFc
Definition: mythuitype.h:45
void(QObject::*)(void) MythUICallbackMF
Definition: mythuitype.h:44
constexpr bool is_nonconst_member_func_v
Definition: mythuitype.h:67
constexpr bool is_const_member_func_v
Definition: mythuitype.h:64
std::function< void(void)> MythUICallbackNMF
Definition: mythuitype.h:42
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:80