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
17
18
19class QTimer;
20
23class MythUIButton;
24class MythUITextEdit;
25class MythUISpinBox;
26class MythUIImage;
27class MythUIStateType;
28class MythMenu;
29
30
40class MUI_PUBLIC DialogCompletionEvent : public QEvent
41{
42 public:
43 DialogCompletionEvent(QString id, int result, QString text,
44 QVariant data)
45 : QEvent(kEventType),
46 m_id(std::move(id)), m_result(result),
47 m_resultText(std::move(text)),
48 m_resultData(std::move(data)) { }
49 ~DialogCompletionEvent() override;
50
51 QString GetId() { return m_id; }
52 int GetResult() const { return m_result; }
53 QString GetResultText() { return m_resultText; }
54 QVariant GetData() { return m_resultData; }
55
56 static const Type kEventType;
57
58 private:
59 QString m_id;
61 QString m_resultText;
62 QVariant m_resultData;
63};
64
65
67{
68 public:
69 MythMenuItem(QString text, bool checked = false, MythMenu *subMenu = nullptr) :
70 m_text(std::move(text)), m_checked(checked), m_subMenu(subMenu) { Init(); }
71 // For non-class, static class, or lambda functions.
72 MythMenuItem(QString text, const MythUICallbackNMF &slot,
73 bool checked = false, MythMenu *subMenu = nullptr) :
74 m_text(std::move(text)), m_data(QVariant::fromValue(slot)),
75 m_checked(checked), m_subMenu(subMenu) { Init(); }
76 // For class member functions.
77 MythMenuItem(QString text, MythUICallbackMF slot,
78 bool checked = false, MythMenu *subMenu = nullptr) :
79 m_text(std::move(text)), m_data(QVariant::fromValue(slot)),
80 m_checked(checked), m_subMenu(subMenu) { Init(); }
81 // For const class member functions.
82 MythMenuItem(QString text, MythUICallbackMFc slot,
83 bool checked = false, MythMenu *subMenu = nullptr) :
84 m_text(std::move(text)), m_data(QVariant::fromValue(slot)),
85 m_checked(checked), m_subMenu(subMenu) { Init(); }
86 void SetData(QVariant data) { m_data = std::move(data); }
87
88 QString m_text;
89 QVariant m_data {0};
90 bool m_checked {false};
91 MythMenu *m_subMenu {nullptr};
92 bool m_useSlot {true};
93
94 private:
95 void Init(void) {}
96};
97
99{
100 friend class MythDialogBox;
101
102 public:
103 MythMenu(QString text, QObject *retobject, QString resultid);
104 MythMenu(QString title, QString text, QObject *retobject, QString resultid);
105 ~MythMenu(void);
106
107 void AddItemV(const QString &title, QVariant data = 0, MythMenu *subMenu = nullptr,
108 bool selected = false, bool checked = false);
109 void AddItem(const QString &title) { AddItemV(title); };
110 // For non-class, static class, or lambda functions.
111 void AddItem(const QString &title, const MythUICallbackNMF &slot,
112 MythMenu *subMenu = nullptr, bool selected = false,
113 bool checked = false);
114 // For class member non-const functions.
115 template <typename SLOT>
116 typename std::enable_if_t<FunctionPointerTest<SLOT>::MemberFunction>
117 AddItem(const QString &title, const SLOT &slot,
118 MythMenu *subMenu = nullptr, bool selected = false,
119 bool checked = false)
120 {
121 auto slot2 = static_cast<MythUICallbackMF>(slot);
122 auto *item = new MythMenuItem(title, slot2, checked, subMenu);
123 AddItem(item, selected, subMenu);
124 }
125 // For class member const functions.
126 template <typename SLOT>
127 typename std::enable_if_t<FunctionPointerTest<SLOT>::MemberConstFunction>
128 AddItem(const QString &title, const SLOT &slot,
129 MythMenu *subMenu = nullptr, bool selected = false,
130 bool checked = false)
131 {
132 auto slot2 = static_cast<MythUICallbackMFc>(slot);
133 auto *item = new MythMenuItem(title, slot2, checked, subMenu);
134 AddItem(item, selected, subMenu);
135 }
136
137 void SetSelectedByTitle(const QString &title);
138 void SetSelectedByData(const QVariant& data);
139
140 void SetParent(MythMenu *parent) { m_parentMenu = parent; }
141
142 bool IsEmpty() { return m_menuItems.isEmpty(); }
143
144 private:
145 void Init(void) {}
146 void AddItem(MythMenuItem *item, bool selected, MythMenu *subMenu);
147
148 MythMenu *m_parentMenu {nullptr};
149 QString m_title;
150 QString m_text;
151 QString m_resultid;
152 QObject *m_retObject {nullptr};
153 QList<MythMenuItem*> m_menuItems;
154 int m_selectedItem {0};
155};
156
166{
167 Q_OBJECT
168 public:
169 MythDialogBox(QString text,
170 MythScreenStack *parent, const char *name,
171 bool fullscreen = false, bool osd = false)
172 : MythScreenType(parent, name, false), m_fullscreen(fullscreen),
173 m_osdDialog(osd), m_text(std::move(text)) {}
174 MythDialogBox(QString title, QString text,
175 MythScreenStack *parent, const char *name,
176 bool fullscreen = false, bool osd = false)
177 : MythScreenType(parent, name, false), m_fullscreen(fullscreen),
178 m_osdDialog(osd), m_title(std::move(title)),m_text(std::move(text)) {}
179 MythDialogBox(MythMenu* menu, MythScreenStack *parent, const char *name,
180 bool fullscreen = false, bool osd = false)
181 : MythScreenType(parent, name, false), m_fullscreen(fullscreen),
182 m_osdDialog(osd), m_menu(menu), m_currentMenu(menu) {}
183 ~MythDialogBox(void) override;
184
185 bool Create(void) override; // MythScreenType
186
187 void SetMenuItems(MythMenu *menu);
188
189 void SetReturnEvent(QObject *retobject, const QString &resultid);
190 void SetBackAction(const QString &text, QVariant data);
191 void SetExitAction(const QString &text, QVariant data);
192 void SetText(const QString &text);
193
194 void AddButtonV(const QString &title, QVariant data = 0,
195 bool newMenu = false, bool setCurrent = false);
196 void AddButtonD(const QString &title, bool setCurrent) { AddButtonV(title, 0,false, setCurrent); }
197 void AddButton(const QString &title) { AddButtonV(title, 0,false, false); }
198 // For non-class, static class, or lambda functions.
199 void AddButton(const QString &title, const MythUICallbackNMF &slot,
200 bool newMenu = false, bool setCurrent = false)
201 {
202 AddButtonV(title, QVariant::fromValue(slot), newMenu, setCurrent);
203 m_useSlots = true;
204 }
205 // For class member non-const functions.
206 template <typename SLOT>
207 typename std::enable_if_t<FunctionPointerTest<SLOT>::MemberFunction>
208 AddButton(const QString &title, const SLOT &slot,
209 bool newMenu = false, bool setCurrent = false)
210 {
211 auto slot2 = static_cast<MythUICallbackMF>(slot);
212 AddButtonV(title, QVariant::fromValue(slot2), newMenu, setCurrent);
213 m_useSlots = true;
214 }
215 // For class member const functions.
216 template <typename SLOT>
217 typename std::enable_if_t<FunctionPointerTest<SLOT>::MemberConstFunction>
218 AddButton(const QString &title, const SLOT &slot,
219 bool newMenu = false, bool setCurrent = false)
220 {
221 auto slot2 = static_cast<MythUICallbackMFc>(slot);
222 AddButtonV(title, QVariant::fromValue(slot2), newMenu, setCurrent);
223 m_useSlots = true;
224 }
225
226 bool keyPressEvent(QKeyEvent *event) override; // MythScreenType
227 bool inputMethodEvent(QInputMethodEvent *event) override;// MythScreenType
228 bool gestureEvent(MythGestureEvent *event) override; // MythScreenType
229
230 public slots:
231 void Select(MythUIButtonListItem* item);
232
233 signals:
234 void Selected();
235 void Closed(QString, int);
236
237 protected:
238 void SendEvent(int res, const QString& text = "", const QVariant& data = 0);
239 void updateMenu(void);
240
241 MythUIText *m_titlearea {nullptr};
242 MythUIText *m_textarea {nullptr};
243 MythUIButtonList *m_buttonList {nullptr};
244 QObject *m_retObject {nullptr};
245 QString m_id;
246 bool m_useSlots {false};
247
248 bool m_fullscreen {false};
249 bool m_osdDialog {false};
250 QString m_title;
251 QString m_text;
252
253 QString m_backtext;
254 QVariant m_backdata {0};
255 QString m_exittext;
256 QVariant m_exitdata {0};
257
258 MythMenu *m_menu {nullptr};
259 MythMenu *m_currentMenu {nullptr};
260};
261
262
272{
273 Q_OBJECT
274
275 public:
276 MythConfirmationDialog(MythScreenStack *parent, QString message,
277 bool showCancel = true)
278 : MythScreenType(parent, "mythconfirmpopup"),
279 m_message(std::move(message)), m_showCancel(showCancel) {}
280
281 bool Create(void) override; // MythScreenType
282 void SetReturnEvent(QObject *retobject, const QString &resultid);
283 void SetData(QVariant data) { m_resultData = std::move(data); }
284 void SetMessage(const QString &message);
285
286 bool keyPressEvent(QKeyEvent *event) override; // MythScreenType
287
288 signals:
289 void haveResult(bool);
290
291 private:
292 void sendResult(bool ok);
293 MythUIText *m_messageText {nullptr};
294 QString m_message;
295 bool m_showCancel {true};
296 QObject *m_retObject {nullptr};
297 QString m_id;
298 QVariant m_resultData;
299
300 private slots:
301 void Confirm(void);
302 void Cancel();
303};
304
314{
315 Q_OBJECT
316
317 public:
318 MythTextInputDialog(MythScreenStack *parent, QString message,
319 InputFilter filter = FilterNone,
320 bool isPassword = false,
321 QString defaultValue = "")
322 : MythScreenType(parent, "mythtextinputpopup"),
323 m_message(std::move(message)), m_defaultValue(std::move(defaultValue)),
324 m_filter(filter), m_isPassword(isPassword) {}
325
326 bool Create(void) override; // MythScreenType
327 void SetReturnEvent(QObject *retobject, const QString &resultid);
328
329 signals:
330 void haveResult(QString);
331
332 protected:
333 MythUITextEdit *m_textEdit {nullptr};
334 QString m_message;
337 bool m_isPassword {false};
338 QObject *m_retObject {nullptr};
339 QString m_id;
340
341 protected slots:
342 void sendResult();
343};
344
345
355{
356 Q_OBJECT
357
358 public:
359 MythSpinBoxDialog(MythScreenStack *parent, QString message);
360
361 bool Create(void) override; // MythScreenType
362 void SetReturnEvent(QObject *retobject, const QString &resultid);
363
364 void SetRange(int low, int high, int step, uint pageMultiple=5);
365 void AddSelection(const QString& label, int value);
366 void SetValue(const QString & value);
367 void SetValue(int value);
368
369 signals:
370 void haveResult(QString);
371
372 protected:
373 MythUISpinBox *m_spinBox { nullptr };
374 QString m_message;
376 QObject *m_retObject { nullptr };
377 QString m_id;
378
379 protected slots:
380 void sendResult();
381};
382
383
399{
400 Q_OBJECT
401
402 public:
413 QString title,
414 QStringList list,
415 bool matchAnywhere = false,
416 QString defaultValue = "")
417 : MythScreenType(parent, "mythsearchdialogpopup"),
418 m_title(std::move(title)),
419 m_defaultValue(std::move(defaultValue)),
420 m_list(std::move(list)),
421 m_matchAnywhere(matchAnywhere),
422 m_id("") {};
423
424 bool Create(void) override; // MythScreenType
425 void SetReturnEvent(QObject *retobject, const QString &resultid);
426
427 signals:
428 void haveResult(QString);
429
430 private:
431 MythUIButtonList *m_itemList { nullptr };
432 MythUITextEdit *m_textEdit { nullptr };
433 MythUIText *m_titleText { nullptr };
434 MythUIText *m_matchesText { nullptr };
435
436 QString m_title;
438 QStringList m_list;
439 bool m_matchAnywhere { false };
440
441 QObject *m_retObject { nullptr };
442 QString m_id;
443
444 private slots:
445 void slotSendResult(void);
446 void slotUpdateList(void);
447};
448
458{
459 Q_OBJECT
460
461 public:
462 // FIXME Not sure about this enum
464 // Date Resolution
465 kNoDate = 0x01,
466 kYear = 0x02,
467 kMonth = 0x04,
468 kDay = 0x08,
469
470 // Time Resolution
471 kNoTime = 0x10,
472 kHours = 0x20,
473 kMinutes = 0x40,
474
475 // Work forward/backwards or backwards and fowards from start time
476 kFutureDates = 0x100,
477 kPastDates = 0x200,
478 kAllDates = 0x300
479 };
480
481 MythTimeInputDialog(MythScreenStack *parent, QString message,
482 int resolutionFlags,
483 QDateTime startTime = QDateTime::currentDateTime(),
484 int rangeLimit = 14);
485
486 bool Create() override; // MythScreenType
487 void SetReturnEvent(QObject *retobject, const QString &resultid);
488
489 signals:
490 void haveResult(QDateTime time);
491
492 private slots:
493 void okClicked(void);
494
495 private:
496 QString m_message;
497 QDateTime m_startTime;
500 QStringList m_list;
502
503 MythUIButtonList *m_dateList { nullptr };
504 MythUIButtonList *m_timeList { nullptr };
505
506 QObject *m_retObject { nullptr };
507 QString m_id;
508};
509
510MUI_PUBLIC MythConfirmationDialog *ShowOkPopup(const QString &message, bool showCancel = false);
511template <class OBJ, typename FUNC>
512MythConfirmationDialog *ShowOkPopup(const QString &message, const OBJ *parent,
513 FUNC slot, bool showCancel = false)
514{
515 auto* pop = ShowOkPopup(message, showCancel);
516 if (pop != nullptr && parent != nullptr)
517 {
518 QObject::connect(pop, &MythConfirmationDialog::haveResult, parent, slot,
519 Qt::QueuedConnection);
520 }
521
522 return pop;
523}
524
527
529Q_DECLARE_METATYPE(const char*)
530
531#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:41
static const Type kEventType
Definition: mythdialogbox.h:56
DialogCompletionEvent(QString id, int result, QString text, QVariant data)
Definition: mythdialogbox.h:43
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
std::enable_if_t< FunctionPointerTest< SLOT >::MemberConstFunction > AddButton(const QString &title, const SLOT &slot, bool newMenu=false, bool setCurrent=false)
void AddButton(const QString &title)
MythDialogBox(MythMenu *menu, MythScreenStack *parent, const char *name, bool fullscreen=false, bool osd=false)
std::enable_if_t< FunctionPointerTest< SLOT >::MemberFunction > AddButton(const QString &title, const SLOT &slot, bool newMenu=false, bool setCurrent=false)
void AddButton(const QString &title, const MythUICallbackNMF &slot, bool newMenu=false, bool setCurrent=false)
QString m_exittext
void AddButtonD(const QString &title, bool setCurrent)
QObject * m_retObject
void Closed(QString, int)
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:86
MythMenuItem(QString text, MythUICallbackMFc slot, bool checked=false, MythMenu *subMenu=nullptr)
Definition: mythdialogbox.h:82
void Init(void)
Definition: mythdialogbox.h:95
QString m_text
Definition: mythdialogbox.h:88
MythMenuItem(QString text, bool checked=false, MythMenu *subMenu=nullptr)
Definition: mythdialogbox.h:69
MythMenuItem(QString text, const MythUICallbackNMF &slot, bool checked=false, MythMenu *subMenu=nullptr)
Definition: mythdialogbox.h:72
MythMenuItem(QString text, MythUICallbackMF slot, bool checked=false, MythMenu *subMenu=nullptr)
Definition: mythdialogbox.h:77
bool IsEmpty()
std::enable_if_t< FunctionPointerTest< SLOT >::MemberFunction > AddItem(const QString &title, const SLOT &slot, MythMenu *subMenu=nullptr, bool selected=false, bool checked=false)
std::enable_if_t< FunctionPointerTest< SLOT >::MemberConstFunction > AddItem(const QString &title, const SLOT &slot, MythMenu *subMenu=nullptr, bool selected=false, bool checked=false)
QString m_title
void Init(void)
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:23
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:68
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
std::function< void(void)> MythUICallbackNMF
Definition: mythuitype.h:42
STL namespace.
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:89