MythTV  master
mythdialogbox.cpp
Go to the documentation of this file.
1 
2 #include "mythdialogbox.h"
3 
4 #include <QCoreApplication>
5 #include <QDate>
6 #include <QDateTime>
7 #include <QFileInfo>
8 #include <QString>
9 #include <QStringList>
10 #include <QTime>
11 #include <utility>
12 
13 #include "mythlogging.h"
14 #include "mythdate.h"
15 
16 #include "mythmainwindow.h"
17 #include "mythfontproperties.h"
18 #include "mythuiutils.h"
19 #include "mythuitext.h"
20 #include "mythuiimage.h"
21 #include "mythuibuttonlist.h"
22 #include "mythuibutton.h"
23 #include "mythuistatetype.h"
24 #include "mythuispinbox.h"
25 #include "mythgesture.h"
26 
28  (QEvent::Type) QEvent::registerEventType();
29 
31 {
32 }
33 
34 MythMenu::MythMenu(QString text, QObject *retobject, QString resultid) :
35  m_text(std::move(text)), m_resultid(std::move(resultid)), m_retObject(retobject)
36 {
37  Init();
38 }
39 
40 MythMenu::MythMenu(QString title, QString text, QObject *retobject, QString resultid) :
41  m_title(std::move(title)), m_text(std::move(text)), m_resultid(std::move(resultid)),
42  m_retObject(retobject)
43 {
44  Init();
45 }
46 
48 {
49  while (!m_menuItems.isEmpty())
50  {
51  MythMenuItem *item = m_menuItems.takeFirst();
52 
53  delete item->m_subMenu;
54  delete item;
55  }
56 }
57 
58 void MythMenu::AddItem(const QString& title, const char* slot, MythMenu *subMenu, bool selected, bool checked)
59 {
60  auto *item = new MythMenuItem(title, slot, checked, subMenu);
61  AddItem(item, selected, subMenu);
62 }
63 
64 void MythMenu::AddItem(const QString &title, QVariant data, MythMenu *subMenu, bool selected, bool checked)
65 {
66  auto *item = new MythMenuItem(title, std::move(data), checked, subMenu);
67  AddItem(item, selected, subMenu);
68 }
69 
70 void MythMenu::AddItem(const QString &title, const MythUIButtonCallback &slot,
71  MythMenu *subMenu, bool selected, bool checked)
72 {
73  auto *item = new MythMenuItem(title, slot, checked, subMenu);
74  AddItem(item, selected, subMenu);
75 }
76 
77 void MythMenu::AddItem(MythMenuItem *item, bool selected, MythMenu *subMenu)
78 {
79  m_menuItems.append(item);
80 
81  if (selected)
82  m_selectedItem = m_menuItems.indexOf(item);
83 
84  if (subMenu)
85  subMenu->SetParent(this);
86 }
87 
88 void MythMenu::SetSelectedByTitle(const QString& title)
89 {
90  foreach (auto & item, m_menuItems)
91  {
92  if (!item)
93  continue;
94 
95  if (item->m_text == title)
96  {
97  m_selectedItem = m_menuItems.indexOf(item);
98  break;
99  }
100  }
101 }
102 
103 void MythMenu::SetSelectedByData(const QVariant& data)
104 {
105  foreach (auto & item, m_menuItems)
106  {
107  if (!item)
108  continue;
109 
110  if (item->m_data == data)
111  {
112  m_selectedItem = m_menuItems.indexOf(item);
113  break;
114  }
115  }
116 }
117 
119 
121 {
122  if (m_menu)
123  {
124  delete m_menu;
125  m_menu = nullptr;
126  }
127 }
128 
130 {
131  QString windowName = (m_fullscreen ? "MythDialogBox" : "MythPopupBox");
132 
133  if (m_osdDialog)
134  {
135  if (!XMLParseBase::LoadWindowFromXML("osd.xml", windowName, this))
136  return false;
137  }
138  else if (!CopyWindowFromBase(windowName, this))
139  return false;
140 
141  bool err = false;
142  UIUtilW::Assign(this, m_titlearea, "title");
143  UIUtilE::Assign(this, m_textarea, "messagearea", &err);
144  UIUtilE::Assign(this, m_buttonList, "list", &err);
145 
146  if (err)
147  {
148  LOG(VB_GENERAL, LOG_ERR, QString("Cannot load screen '%1'")
149  .arg(windowName));
150  return false;
151  }
152 
153  if (m_titlearea)
156 
157  BuildFocusList();
158 
159  if (m_menu)
160  updateMenu();
161 
162  connect(m_buttonList, SIGNAL(itemClicked(MythUIButtonListItem*)),
163  SLOT(Select(MythUIButtonListItem*)));
164 
165  return true;
166 }
167 
169 {
170  m_menu = menu;
172  updateMenu();
173 }
174 
176 {
177  if (!m_buttonList)
178  {
179  LOG(VB_GENERAL, LOG_ERR, "UpdateMenu() called before we have a button list to update!");
180  return;
181  }
182 
183  if (!m_currentMenu)
184  return;
185 
186  if (m_titlearea)
188 
190 
191  m_buttonList->Reset();
192 
193  for (int x = 0; x < m_currentMenu->m_menuItems.count(); x++)
194  {
195  MythMenuItem *menuItem = m_currentMenu->m_menuItems.at(x);
196  auto *button = new MythUIButtonListItem(m_buttonList, menuItem->m_text);
197  button->SetData(QVariant::fromValue(menuItem));
198  button->setDrawArrow((menuItem->m_subMenu != nullptr));
199 
200  if (m_currentMenu->m_selectedItem == x)
201  m_buttonList->SetItemCurrent(button);
202  }
203  // GetVisibleCount here makes sure that the dialog size is
204  // calculated correctly
207 }
208 
210 {
211  if (!item)
212  return;
213 
214  if (m_currentMenu)
215  {
216  auto *menuItem = item->GetData().value< MythMenuItem * >();
217 
218  if (menuItem->m_subMenu)
219  {
221  m_currentMenu = menuItem->m_subMenu;
222  updateMenu();
223  return;
224  }
225 
226  if (menuItem->m_useSlot)
227  {
228  const char *slot = menuItem->m_data.value < const char * >();
229  if (slot)
230  {
231  connect(this, SIGNAL(Selected()), m_currentMenu->m_retObject, slot,
232  Qt::QueuedConnection);
233  emit Selected();
234  }
235  else if (menuItem->m_data.value<MythUIButtonCallback>())
236  {
238  menuItem->m_data.value<MythUIButtonCallback>(),
239  Qt::QueuedConnection);
240  emit Selected();
241  }
242  }
243 
244  SendEvent(m_buttonList->GetItemPos(item), item->GetText(), menuItem->m_data);
245  }
246  else
247  {
248  if (m_useSlots)
249  {
250  const char *slot = item->GetData().value<const char *>();
251  if (slot)
252  {
253  connect(this, SIGNAL(Selected()), m_retObject, slot,
254  Qt::QueuedConnection);
255  emit Selected();
256  }
257  else if (item->GetData().value<MythUIButtonCallback>())
258  {
259  connect(this, &MythDialogBox::Selected, m_retObject,
260  item->GetData().value<MythUIButtonCallback>(),
261  Qt::QueuedConnection);
262  emit Selected();
263  }
264  }
265 
266  SendEvent(m_buttonList->GetItemPos(item), item->GetText(), item->GetData());
267  }
268 
269  if (m_ScreenStack)
270  m_ScreenStack->PopScreen(nullptr, false);
271 }
272 
273 void MythDialogBox::SetReturnEvent(QObject *retobject,
274  const QString &resultid)
275 {
276  m_retObject = retobject;
277  m_id = resultid;
278 }
279 
280 void MythDialogBox::SetBackAction(const QString &text, QVariant data)
281 {
282  m_backtext = text;
283  m_backdata = std::move(data);
284 }
285 
286 void MythDialogBox::SetExitAction(const QString &text, QVariant data)
287 {
288  m_exittext = text;
289  m_exitdata = std::move(data);
290 }
291 
292 void MythDialogBox::SetText(const QString &text)
293 {
294  if (m_textarea)
295  m_textarea->SetText(text);
296 }
297 
298 void MythDialogBox::AddButton(const QString &title, QVariant data, bool newMenu,
299  bool setCurrent)
300 {
301  auto *button = new MythUIButtonListItem(m_buttonList, title);
302  button->SetData(std::move(data));
303  button->setDrawArrow(newMenu);
304 
305  if (setCurrent)
306  m_buttonList->SetItemCurrent(button);
307  // GetVisibleCount here makes sure that the dialog size is
308  // calculated correctly
310 }
311 
312 void MythDialogBox::AddButton(const QString &title, const char *slot,
313  bool newMenu, bool setCurrent)
314 {
315  auto *button = new MythUIButtonListItem(m_buttonList, title);
316 
317  m_useSlots = true;
318 
319  if (slot)
320  button->SetData(QVariant::fromValue(slot));
321  button->setDrawArrow(newMenu);
322 
323  if (setCurrent)
324  m_buttonList->SetItemCurrent(button);
325  // GetVisibleCount here makes sure that the dialog size is
326  // calculated correctly
328 }
329 
330 bool MythDialogBox::keyPressEvent(QKeyEvent *event)
331 {
332  if (GetFocusWidget()->keyPressEvent(event))
333  return true;
334 
335  bool handled = false;
336  QStringList actions;
337  handled = GetMythMainWindow()->TranslateKeyPress("qt", event, actions);
338 
339  for (int i = 0; i < actions.size() && !handled; i++)
340  {
341  QString action = actions[i];
342  handled = true;
343 
344  if (action == "ESCAPE")
345  {
347  if (m_exitdata == 0 && m_exittext.isEmpty())
348  Close();
349  }
350  else if ((action == "LEFT" &&
352  (action == "UP" &&
354  {
356  {
358  updateMenu();
359  return true;
360  }
361 
363  Close();
364  }
365  else if (action == "MENU")
366  {
367  SendEvent(-2);
368  Close();
369  }
370  else if ((action == "RIGHT" &&
372  (action == "DOWN" &&
374  {
376  }
377  else
378  handled = false;
379  }
380 
381  if (!handled && MythScreenType::keyPressEvent(event))
382  handled = true;
383 
384  return handled;
385 }
386 
388 {
389  bool handled = false;
390  if (event->gesture() == MythGestureEvent::Click)
391  {
392  switch (event->GetButton())
393  {
395  SendEvent(-2);
396  Close();
397  handled = true;
398  break;
399  default :
400  break;
401  }
402 
403  }
404 
405  if (!handled && MythScreenType::gestureEvent(event))
406  handled = true;
407 
408  return handled;
409 }
410 
411 void MythDialogBox::SendEvent(int res, const QString& text, const QVariant& data)
412 {
413  if (m_currentMenu)
414  {
415  emit Closed(m_currentMenu->m_resultid, res);
416 
418  return;
419 
420  auto *dce = new DialogCompletionEvent(m_currentMenu->m_resultid, res, text, data);
421  QCoreApplication::postEvent(m_currentMenu->m_retObject, dce);
422  }
423  else
424  {
425  emit Closed(m_id, res);
426 
427  if (!m_retObject)
428  return;
429 
430  auto *dce = new DialogCompletionEvent(m_id, res, text, data);
431  QCoreApplication::postEvent(m_retObject, dce);
432  }
433 }
434 
436 
438 {
439  if (!CopyWindowFromBase("MythConfirmationDialog", this))
440  return false;
441 
442  MythUIButton *okButton = nullptr;
443  MythUIButton *cancelButton = nullptr;
444 
445  bool err = false;
446  UIUtilE::Assign(this, m_messageText, "message", &err);
447  UIUtilE::Assign(this, okButton, "ok", &err);
448  UIUtilE::Assign(this, cancelButton, "cancel", &err);
449 
450  if (err)
451  {
452  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythConfirmationDialog'");
453  return false;
454  }
455 
456  if (m_showCancel)
457  {
458  connect(cancelButton, SIGNAL(Clicked()), SLOT(Cancel()));
459  }
460  else
461  cancelButton->SetVisible(false);
462 
463  connect(okButton, SIGNAL(Clicked()), SLOT(Confirm()));
464 
466 
467  BuildFocusList();
468 
469  if (m_showCancel)
470  SetFocusWidget(cancelButton);
471  else
472  SetFocusWidget(okButton);
473 
474  return true;
475 }
476 
478 {
479  if (GetFocusWidget()->keyPressEvent(event))
480  return true;
481 
482  bool handled = false;
483  QStringList actions;
484  handled = GetMythMainWindow()->TranslateKeyPress("qt", event, actions);
485 
486  for (int i = 0; i < actions.size() && !handled; i++)
487  {
488  QString action = actions[i];
489  handled = true;
490 
491  if (action == "ESCAPE")
492  sendResult(false);
493  else
494  handled = false;
495  }
496 
497  if (!handled && MythScreenType::keyPressEvent(event))
498  handled = true;
499 
500  return handled;
501 }
502 
503 void MythConfirmationDialog::SetMessage(const QString &message)
504 {
505  m_message = message;
506  if (m_messageText)
508 }
509 
511  const QString &resultid)
512 {
513  m_retObject = retobject;
514  m_id = resultid;
515 }
516 
518 {
519  sendResult(true);
520 }
521 
523 {
524  sendResult(false);
525 }
526 
528 {
529  emit haveResult(ok);
530 
531  if (m_retObject)
532  {
533  int res = 0;
534  if (ok)
535  res = 1;
536 
537  auto *dce = new DialogCompletionEvent(m_id, res, "", m_resultData);
538  QCoreApplication::postEvent(m_retObject, dce);
539  m_retObject = nullptr;
540  }
541 
542  Close();
543 }
544 
548 MythConfirmationDialog *ShowOkPopup(const QString &message, QObject *parent,
549  const char *slot, bool showCancel)
550 {
551  QString LOC = "ShowOkPopup('" + message + "') - ";
552  MythScreenStack *stk = nullptr;
553 
555 
556  if (win)
557  stk = win->GetStack("popup stack");
558  else
559  {
560  LOG(VB_GENERAL, LOG_ERR, LOC + "no main window?");
561  return nullptr;
562  }
563 
564  if (!stk)
565  {
566  LOG(VB_GENERAL, LOG_ERR, LOC + "no popup stack? "
567  "Is there a MythThemeBase?");
568  return nullptr;
569  }
570 
571  auto *pop = new MythConfirmationDialog(stk, message, showCancel);
572  if (pop->Create())
573  {
574  stk->AddScreen(pop);
575  if (parent && slot)
576  QObject::connect(pop, SIGNAL(haveResult(bool)), parent, slot,
577  Qt::QueuedConnection);
578  }
579  else
580  {
581  delete pop;
582  pop = nullptr;
583  LOG(VB_GENERAL, LOG_ERR, LOC + "Couldn't Create() Dialog");
584  }
585 
586  return pop;
587 }
588 
590 {
591  if (!dialog)
592  return true; // No dialog is treated as user pressing OK
593 
594  // Local event loop processes events whilst we wait
595  QEventLoop block;
596 
597  // Quit when dialog exits
598  QObject::connect(dialog, &MythConfirmationDialog::haveResult,
599  &block, [&block](bool result)
600  { block.exit(result ? 1 : 0); });
601 
602  // Block and return dialog result
603  return block.exec() != 0;
604 }
605 
607 
609 {
610  if (!CopyWindowFromBase("MythTextInputDialog", this))
611  return false;
612 
613  MythUIText *messageText = nullptr;
614  MythUIButton *okButton = nullptr;
615  MythUIButton *cancelButton = nullptr;
616 
617  bool err = false;
618  UIUtilE::Assign(this, m_textEdit, "input", &err);
619  UIUtilE::Assign(this, messageText, "message", &err);
620  UIUtilE::Assign(this, okButton, "ok", &err);
621  UIUtilW::Assign(this, cancelButton, "cancel");
622 
623  if (err)
624  {
625  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythTextInputDialog'");
626  return false;
627  }
628 
629  if (cancelButton)
630  connect(cancelButton, SIGNAL(Clicked()), SLOT(Close()));
631  connect(okButton, SIGNAL(Clicked()), SLOT(sendResult()));
632 
636 
637  messageText->SetText(m_message);
638 
639  BuildFocusList();
640 
641  return true;
642 }
643 
644 void MythTextInputDialog::SetReturnEvent(QObject *retobject,
645  const QString &resultid)
646 {
647  m_retObject = retobject;
648  m_id = resultid;
649 }
650 
652 {
653  QString inputString = m_textEdit->GetText();
654  emit haveResult(inputString);
655 
656  if (m_retObject)
657  {
658  auto *dce = new DialogCompletionEvent(m_id, 0, inputString, "");
659  QCoreApplication::postEvent(m_retObject, dce);
660  }
661 
662  Close();
663 }
664 
666 
668  QString message)
669  : MythScreenType(parent, "mythspinboxpopup"),
670  m_spinBox(nullptr),
671  m_message(std::move(message)),
672  m_retObject(nullptr),
673  m_id("")
674 {
675 }
676 
678 {
679  if (!CopyWindowFromBase("MythSpinBoxDialog", this))
680  return false;
681 
682  MythUIText *messageText = nullptr;
683  MythUIButton *okButton = nullptr;
684  MythUIButton *cancelButton = nullptr;
685 
686  bool err = false;
687  UIUtilE::Assign(this, m_spinBox, "input", &err);
688  UIUtilE::Assign(this, messageText, "message", &err);
689  UIUtilE::Assign(this, okButton, "ok", &err);
690  UIUtilW::Assign(this, cancelButton, "cancel");
691 
692  if (err)
693  {
694  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythSpinBoxDialog'");
695  return false;
696  }
697 
698  if (cancelButton)
699  connect(cancelButton, SIGNAL(Clicked()), SLOT(Close()));
700  connect(okButton, SIGNAL(Clicked()), SLOT(sendResult()));
701 
702  messageText->SetText(m_message);
703  BuildFocusList();
704 
705  return true;
706 }
707 
712 void MythSpinBoxDialog::SetRange(int low, int high, int step, uint pageMultiple)
713 {
714  m_spinBox->SetRange(low, high, step, pageMultiple);
715 }
716 
720 void MythSpinBoxDialog::AddSelection(const QString& label, int value)
721 {
722  m_spinBox->AddSelection(value, label);
723 }
724 
729 void MythSpinBoxDialog::SetValue (const QString & value)
730 {
731  m_spinBox->SetValue(value);
732 }
733 
738 {
739  m_spinBox->SetValue(value);
740 }
741 
742 void MythSpinBoxDialog::SetReturnEvent(QObject *retobject,
743  const QString &resultid)
744 {
745  m_retObject = retobject;
746  m_id = resultid;
747 }
748 
750 {
751  QString inputString = m_spinBox->GetValue();
752  emit haveResult(inputString);
753 
754  if (m_retObject)
755  {
756  auto *dce = new DialogCompletionEvent(m_id, 0, inputString, "");
757  QCoreApplication::postEvent(m_retObject, dce);
758  }
759 
760  Close();
761 }
762 
764 
765 
781  const QString &title,
782  const QStringList &list,
783  bool matchAnywhere,
784  const QString &defaultValue)
785  : MythScreenType(parent, "mythsearchdialogpopup")
786 {
787  m_list = list;
788  m_matchAnywhere = matchAnywhere;
789  m_title = title;
790  m_defaultValue = defaultValue;
791 
792  m_titleText = nullptr;
793  m_matchesText = nullptr;
794  m_textEdit = nullptr;
795  m_itemList = nullptr;
796 
797  m_id = "";
798  m_retObject = nullptr;
799 }
800 
802 {
803  if (!CopyWindowFromBase("MythSearchDialog", this))
804  return false;
805 
806  MythUIButton *okButton = nullptr;
807  MythUIButton *cancelButton = nullptr;
808 
809  bool err = false;
810  UIUtilE::Assign(this, m_textEdit, "input", &err);
811  UIUtilE::Assign(this, m_titleText, "title", &err);
812  UIUtilW::Assign(this, m_matchesText, "matches");
813  UIUtilE::Assign(this, m_itemList, "itemlist", &err);
814  UIUtilE::Assign(this, okButton, "ok", &err);
815  UIUtilW::Assign(this, cancelButton, "cancel");
816 
817  if (err)
818  {
819  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythSearchDialog'");
820  return false;
821  }
822 
823  if (cancelButton)
824  connect(cancelButton, SIGNAL(Clicked()), SLOT(Close()));
825 
826  connect(okButton, SIGNAL(Clicked()), SLOT(slotSendResult()));
827 
828  connect(m_itemList, SIGNAL(itemClicked(MythUIButtonListItem*)),
829  SLOT(slotSendResult()));
830 
832  connect(m_textEdit, SIGNAL(valueChanged()), SLOT(slotUpdateList()));
833 
835  if (m_matchesText)
836  m_matchesText->SetText(tr("%n match(es)", "", 0));
837 
838  BuildFocusList();
839 
840  slotUpdateList();
841 
842  return true;
843 }
844 
845 void MythUISearchDialog::SetReturnEvent(QObject *retobject,
846  const QString &resultid)
847 {
848  m_retObject = retobject;
849  m_id = resultid;
850 }
851 
853 {
854  if (!m_itemList->GetItemCurrent())
855  return;
856 
857  QString result = m_itemList->GetValue();
858 
859  emit haveResult(result);
860 
861  if (m_retObject)
862  {
863  auto *dce = new DialogCompletionEvent(m_id, 0, result, "");
864  QCoreApplication::postEvent(m_retObject, dce);
865  }
866 
867  Close();
868 }
869 
871 {
872  m_itemList->Reset();
873 
874  for (int x = 0; x < m_list.size(); x++)
875  {
876  QString item = m_list.at(x);
877 
878  if (m_matchAnywhere)
879  {
880  if (!item.contains(m_textEdit->GetText(), Qt::CaseInsensitive))
881  continue;
882  }
883  else
884  {
885  if (!item.startsWith(m_textEdit->GetText(), Qt::CaseInsensitive))
886  continue;
887  }
888 
889  // add item to list
890  new MythUIButtonListItem(m_itemList, item, nullptr, false);
891  }
892 
894 
895  if (m_matchesText)
896  m_matchesText->SetText(tr("%n match(es)", "", 0));
897 }
898 
900 
902  QString message,
903  int resolutionFlags,
904  QDateTime startTime,
905  int rangeLimit)
906  : MythScreenType(parent, "timepopup"),
907  m_message(std::move(message)), m_startTime(std::move(startTime)),
908  m_resolution(resolutionFlags), m_rangeLimit(rangeLimit),
909  m_dateList(nullptr), m_timeList(nullptr), m_retObject(nullptr)
910 {
911 }
912 
914 {
915  if (!CopyWindowFromBase("MythTimeInputDialog", this))
916  return false;
917 
918  MythUIText *messageText = nullptr;
919  MythUIButton *okButton = nullptr;
920 
921  bool err = false;
922  UIUtilE::Assign(this, messageText, "message", &err);
923  UIUtilE::Assign(this, m_dateList, "dates", &err);
924  UIUtilE::Assign(this, m_timeList, "times", &err);
925  UIUtilE::Assign(this, okButton, "ok", &err);
926 
927  if (err)
928  {
929  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythTimeInputDialog'");
930  return false;
931  }
932 
933  m_dateList->SetVisible(false);
934  m_timeList->SetVisible(false);
935 
936  // Date
937  if (kNoDate != (m_resolution & 0xF))
938  {
939  const QDate startdate(m_startTime.toLocalTime().date());
940  QDate date(startdate);
941 
942  int limit = 0;
944  {
945  limit += m_rangeLimit;
946  }
947  if (m_resolution & kPastDates)
948  {
949  limit += m_rangeLimit;
950  date = date.addDays(0-m_rangeLimit);
951  }
952 
953  QString text;
954  bool selected = false;
955  for (int x = 0; x <= limit; x++)
956  {
957  selected = false;
958  if (m_resolution & kDay)
959  {
960  date = date.addDays(1);
962  if (m_rangeLimit >= 356)
963  flags |= MythDate::kAddYear;
964  text = MythDate::toString(date, flags);
965 
966  if (date == startdate)
967  selected = true;
968  }
969  else if (m_resolution & kMonth)
970  {
971  date = date.addMonths(1);
972  text = date.toString("MMM yyyy");
973 
974  if ((date.month() == startdate.month()) &&
975  (date.year() == startdate.year()))
976  selected = true;
977  }
978  else if (m_resolution & kYear)
979  {
980  date = date.addYears(1);
981  text = date.toString("yyyy");
982  if (date.year() == startdate.year())
983  selected = true;
984  }
985 
986  auto *item = new MythUIButtonListItem(m_dateList, text, nullptr, false);
987  item->SetData(QVariant(date));
988 
989  if (selected)
990  m_dateList->SetItemCurrent(item);
991  }
992  m_dateList->SetVisible(true);
993  }
994 
995  // Time
996  if (kNoTime != (m_resolution & 0xF0))
997  {
998  QDate startdate(m_startTime.toLocalTime().date());
999  QTime starttime(m_startTime.toLocalTime().time());
1000  QTime time(0,0,0);
1001  QString text;
1002  bool selected = false;
1003 
1004  int limit = (m_resolution & kMinutes) ? (60 * 24) : 24;
1005 
1006  for (int x = 0; x < limit; x++)
1007  {
1008  selected = false;
1009  if (m_resolution & kMinutes)
1010  {
1011  time = time.addSecs(60);
1012  QDateTime dt = QDateTime(startdate, time, Qt::LocalTime);
1013  text = MythDate::toString(dt, MythDate::kTime);
1014 
1015  if (time == starttime)
1016  selected = true;
1017  }
1018  else if (m_resolution & kHours)
1019  {
1020  time = time.addSecs(60*60);
1021  text = time.toString("hh:00");
1022 
1023  if (time.hour() == starttime.hour())
1024  selected = true;
1025  }
1026 
1027  auto *item = new MythUIButtonListItem(m_timeList, text, nullptr, false);
1028  item->SetData(QVariant(time));
1029 
1030  if (selected)
1031  m_timeList->SetItemCurrent(item);
1032  }
1033  m_timeList->SetVisible(true);
1034  }
1035 
1036  if (messageText && !m_message.isEmpty())
1037  messageText->SetText(m_message);
1038 
1039  connect(okButton, SIGNAL(Clicked()), SLOT(okClicked()));
1040 
1041  BuildFocusList();
1042 
1043  return true;
1044 }
1045 
1046 void MythTimeInputDialog::SetReturnEvent(QObject* retobject,
1047  const QString& resultid)
1048 {
1049  m_retObject = retobject;
1050  m_id = resultid;
1051 }
1052 
1054 {
1055  QDate date = m_dateList->GetDataValue().toDate();
1056  QTime time = m_timeList->GetDataValue().toTime();
1057 
1058  QDateTime dateTime = QDateTime(date, time, Qt::LocalTime).toUTC();
1059 
1060  emit haveResult(dateTime);
1061 
1062  if (m_retObject)
1063  {
1064  QVariant data(dateTime);
1065  auto *dce = new DialogCompletionEvent(m_id, 0, "", data);
1066  QCoreApplication::postEvent(m_retObject, dce);
1067  }
1068 
1069  Close();
1070 }
void haveResult(QString)
void AddSelection(const QString &label, int value)
InputFilter m_filter
MythUIText * m_titleText
void SendEvent(int res, const QString &text="", const QVariant &data=0)
void AddSelection(int value, const QString &label="")
Add a special label for a value of the spinbox, it does not need to be in the range.
QObject * m_retObject
bool WaitFor(MythConfirmationDialog *dialog)
Blocks until confirmation dialog exits.
void SetMessage(const QString &message)
MythUIText * m_textarea
Dialog asking for user confirmation.
void haveResult(QString)
MythMenu * m_menu
void SetBackAction(const QString &text, QVariant data)
bool TranslateKeyPress(const QString &context, QKeyEvent *e, QStringList &actions, bool allowJumps=true)
Get a list of actions for a keypress in the given context.
MythMenu * m_parentMenu
MythUIText * m_messageText
MythConfirmationDialog * ShowOkPopup(const QString &message, QObject *parent, const char *slot, bool showCancel)
Non-blocking version of MythPopupBox::showOkPopup()
All purpose text widget, displays a text string.
Definition: mythuitext.h:28
MythUIButtonList * m_itemList
QString GetValue(void) const override
Definition: mythuispinbox.h:31
void SetRedraw(void)
Definition: mythuitype.cpp:293
MythUIButtonList * m_timeList
#define LOC
void slotSendResult(void)
void Select(MythUIButtonListItem *item)
void SetFilter(InputFilter filter)
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:135
int GetItemPos(MythUIButtonListItem *item) const
void SetParent(MythMenu *parent)
MythScreenStack * GetStack(const QString &stackname)
QString m_text
void SetValue(int val) override
Definition: mythuispinbox.h:26
MythScreenStack * GetMainStack()
Do Today/Yesterday/Tomorrow transform.
Definition: mythdate.h:23
Gesture gesture(void) const
Get the gesture type.
Definition: mythgesture.h:109
QString m_title
QList< MythMenuItem * > m_menuItems
static MythThemedMenu * menu
MythSpinBoxDialog(MythScreenStack *parent, QString message)
QObject * m_retObject
void BuildFocusList(void)
static Type kEventType
Definition: mythdialogbox.h:57
QObject * m_retObject
MythUISpinBox * m_spinBox
virtual void Close()
void AddButton(const QString &title, QVariant data=0, bool newMenu=false, bool setCurrent=false)
void SetRange(int low, int high, int step, uint pageMultiple=5)
Set the lower and upper bounds of the spinbox, the interval and page amount.
bool Create(void) override
virtual void SetVisible(bool visible)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
QString m_exittext
void haveResult(QString)
~MythMenu(void)
bool Create() override
virtual MythScreenType * GetTopScreen(void) const
A C++ ripoff of the stroke library for MythTV.
static bool CopyWindowFromBase(const QString &windowname, MythScreenType *win)
void SetReturnEvent(QObject *retobject, const QString &resultid)
Default local time.
Definition: mythdate.h:16
void SetReturnEvent(QObject *retobject, const QString &resultid)
MythUIButtonList * m_buttonList
QString m_backtext
QVariant GetDataValue() const
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27
Add year to string if not included.
Definition: mythdate.h:22
unsigned int uint
Definition: compat.h:140
void Init(void)
A custom event that represents a mouse gesture.
Definition: mythgesture.h:39
MythMenu * m_currentMenu
QString toString(const QDateTime &raw_dt, uint format)
Returns formatted string representing the time.
Definition: mythdate.cpp:101
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
void AddItem(const QString &title, QVariant data=0, MythMenu *subMenu=nullptr, bool selected=false, bool checked=false)
void SetText(const QString &text, bool moveCursor=true)
void SetReturnEvent(QObject *retobject, const QString &resultid)
MythUIType * GetFocusWidget(void) const
void SetSelectedByData(const QVariant &data)
A single button widget.
Definition: mythuibutton.h:21
void Reset() override
Reset the widget to it's original state, should not reset changes made by the theme.
MythMainWindow * GetMythMainWindow(void)
QString GetText(const QString &name="") const
virtual QString GetValue() const
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.
void haveResult(QDateTime time)
void SetMenuItems(MythMenu *menu)
Button GetButton(void) const
Definition: mythgesture.h:121
QStringList m_list
void SetExitAction(const QString &text, QVariant data)
virtual void PopScreen(MythScreenType *screen=nullptr, bool allowFade=true, bool deleteScreen=true)
MythScreenStack * m_ScreenStack
bool Create(void) override
bool Create(void) override
void slotUpdateList(void)
void SetReturnEvent(QObject *retobject, const QString &resultid)
void SetText(const QString &text)
~DialogCompletionEvent() override
void updateMenu(void)
void SetPassword(bool isPassword)
bool gestureEvent(MythGestureEvent *event) override
Mouse click/movement handler, receives mouse gesture events from the QCoreApplication event loop.
int m_selectedItem
LayoutType GetLayout() const
void SetItemCurrent(MythUIButtonListItem *item)
MythUIText * m_titlearea
MythMenu(QString text, QObject *retobject, QString resultid)
bool SetFocusWidget(MythUIType *widget=nullptr)
void SetValue(const QString &value)
Can be called only after MythSpinBoxDialog::Create() return successfully The range need to be set bef...
MythUISearchDialog(MythScreenStack *parent, const QString &title, const QStringList &list, bool matchAnywhere=false, const QString &defaultValue="")
the classes constructor
Screen in which all other widgets are contained and rendered.
int GetCurrentPos() const
MythUITextEdit * m_textEdit
MythTimeInputDialog(MythScreenStack *parent, QString message, int resolutionFlags, QDateTime startTime=QDateTime::currentDateTime(), int rangeLimit=14)
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
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
void SetSelectedByTitle(const QString &title)
QVariant m_backdata
void SetRange(int low, int high, int step, uint pageMultiple=5)
Set the lower and upper bounds of the spinbox, the interval and page amount.
MythMenu * m_subMenu
Definition: mythdialogbox.h:85
QVariant m_exitdata
~MythDialogBox(void) override
bool Create(void) override
std::function< void(void)> MythUIButtonCallback
Definition: mythdialogbox.h:67
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
void SetReturnEvent(QObject *retobject, const QString &resultid)
void Closed(QString, int)
void SetReturnEvent(QObject *retobject, const QString &resultid)
QString GetText(void) const
QString m_text
Definition: mythdialogbox.h:82
MythUIButtonListItem * GetItemCurrent() const
bool Create(void) override
MythUITextEdit * m_textEdit
Default local time.
Definition: mythdate.h:19
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:41