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 
30 
31 MythMenu::MythMenu(const QString &text, QObject *retobject, const QString &resultid) :
32  m_text(text), m_resultid(resultid), m_retObject(retobject)
33 {
34  Init();
35 }
36 
37 MythMenu::MythMenu(const QString &title, const QString &text, QObject *retobject, const QString &resultid) :
38  m_title(title), m_text(text), m_resultid(resultid), m_retObject(retobject)
39 {
40  Init();
41 }
42 
44 {
45  while (!m_menuItems.isEmpty())
46  {
47  MythMenuItem *item = m_menuItems.takeFirst();
48 
49  delete item->m_subMenu;
50  delete item;
51  }
52 }
53 
54 void MythMenu::AddItem(const QString& title, const char* slot, MythMenu *subMenu, bool selected, bool checked)
55 {
56  MythMenuItem *item = new MythMenuItem(title, slot, checked, subMenu);
57  AddItem(item, selected, subMenu);
58 }
59 
60 void MythMenu::AddItem(const QString &title, QVariant data, MythMenu *subMenu, bool selected, bool checked)
61 {
62  MythMenuItem *item = new MythMenuItem(title, std::move(data), checked, subMenu);
63  AddItem(item, selected, subMenu);
64 }
65 
66 void MythMenu::AddItem(const QString &title, const MythUIButtonCallback &slot,
67  MythMenu *subMenu, bool selected, bool checked)
68 {
69  MythMenuItem *item = new MythMenuItem(title, slot, checked, subMenu);
70  AddItem(item, selected, subMenu);
71 }
72 
73 void MythMenu::AddItem(MythMenuItem *item, bool selected, MythMenu *subMenu)
74 {
75  m_menuItems.append(item);
76 
77  if (selected)
78  m_selectedItem = m_menuItems.indexOf(item);
79 
80  if (subMenu)
81  subMenu->SetParent(this);
82 }
83 
84 void MythMenu::SetSelectedByTitle(const QString& title)
85 {
86  QList<MythMenuItem*>::iterator it = m_menuItems.begin();
87  for ( ; it < m_menuItems.end(); ++it)
88  {
89  MythMenuItem *item = (*it);
90  if (!item)
91  continue;
92 
93  if (item->m_text == title)
94  {
95  m_selectedItem = m_menuItems.indexOf(item);
96  break;
97  }
98  }
99 }
100 
101 void MythMenu::SetSelectedByData(const QVariant& data)
102 {
103  QList<MythMenuItem*>::iterator it = m_menuItems.begin();
104  for ( ; it < m_menuItems.end(); ++it)
105  {
106  MythMenuItem *item = (*it);
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);
197  button->SetData(qVariantFromValue(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  MythMenuItem *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 {
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 {
316 
317  m_useSlots = true;
318 
319  if (slot)
320  button->SetData(qVariantFromValue(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 
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  DialogCompletionEvent *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 
538  m_resultData);
539  QCoreApplication::postEvent(m_retObject, dce);
540  m_retObject = nullptr;
541  }
542 
543  Close();
544 }
545 
549 MythConfirmationDialog *ShowOkPopup(const QString &message, QObject *parent,
550  const char *slot, bool showCancel)
551 {
552  QString LOC = "ShowOkPopup('" + message + "') - ";
554  MythScreenStack *stk = nullptr;
555 
557 
558  if (win)
559  stk = win->GetStack("popup stack");
560  else
561  {
562  LOG(VB_GENERAL, LOG_ERR, LOC + "no main window?");
563  return nullptr;
564  }
565 
566  if (!stk)
567  {
568  LOG(VB_GENERAL, LOG_ERR, LOC + "no popup stack? "
569  "Is there a MythThemeBase?");
570  return nullptr;
571  }
572 
573  pop = new MythConfirmationDialog(stk, message, showCancel);
574  if (pop->Create())
575  {
576  stk->AddScreen(pop);
577  if (parent && slot)
578  QObject::connect(pop, SIGNAL(haveResult(bool)), parent, slot,
579  Qt::QueuedConnection);
580  }
581  else
582  {
583  delete pop;
584  pop = nullptr;
585  LOG(VB_GENERAL, LOG_ERR, LOC + "Couldn't Create() Dialog");
586  }
587 
588  return pop;
589 }
590 
592 {
593  if (!dialog)
594  return true; // No dialog is treated as user pressing OK
595 
596  // Local event loop processes events whilst we wait
597  QEventLoop block;
598 
599  // Quit when dialog exits
600  QObject::connect(dialog, &MythConfirmationDialog::haveResult,
601  &block, [&block](bool result)
602  { block.exit(result ? 1 : 0); });
603 
604  // Block and return dialog result
605  return block.exec() != 0;
606 }
607 
609 
611 {
612  if (!CopyWindowFromBase("MythTextInputDialog", this))
613  return false;
614 
615  MythUIText *messageText = nullptr;
616  MythUIButton *okButton = nullptr;
617  MythUIButton *cancelButton = nullptr;
618 
619  bool err = false;
620  UIUtilE::Assign(this, m_textEdit, "input", &err);
621  UIUtilE::Assign(this, messageText, "message", &err);
622  UIUtilE::Assign(this, okButton, "ok", &err);
623  UIUtilW::Assign(this, cancelButton, "cancel");
624 
625  if (err)
626  {
627  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythTextInputDialog'");
628  return false;
629  }
630 
631  if (cancelButton)
632  connect(cancelButton, SIGNAL(Clicked()), SLOT(Close()));
633  connect(okButton, SIGNAL(Clicked()), SLOT(sendResult()));
634 
638 
639  messageText->SetText(m_message);
640 
641  BuildFocusList();
642 
643  return true;
644 }
645 
646 void MythTextInputDialog::SetReturnEvent(QObject *retobject,
647  const QString &resultid)
648 {
649  m_retObject = retobject;
650  m_id = resultid;
651 }
652 
654 {
655  QString inputString = m_textEdit->GetText();
656  emit haveResult(inputString);
657 
658  if (m_retObject)
659  {
661  inputString, "");
662  QCoreApplication::postEvent(m_retObject, dce);
663  }
664 
665  Close();
666 }
667 
669 
671  const QString &message)
672  : MythScreenType(parent, "mythspinboxpopup"),
673  m_spinBox(nullptr),
674  m_message(message),
675  m_retObject(nullptr),
676  m_id("")
677 {
678 }
679 
681 {
682  if (!CopyWindowFromBase("MythSpinBoxDialog", this))
683  return false;
684 
685  MythUIText *messageText = nullptr;
686  MythUIButton *okButton = nullptr;
687  MythUIButton *cancelButton = nullptr;
688 
689  bool err = false;
690  UIUtilE::Assign(this, m_spinBox, "input", &err);
691  UIUtilE::Assign(this, messageText, "message", &err);
692  UIUtilE::Assign(this, okButton, "ok", &err);
693  UIUtilW::Assign(this, cancelButton, "cancel");
694 
695  if (err)
696  {
697  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythSpinBoxDialog'");
698  return false;
699  }
700 
701  if (cancelButton)
702  connect(cancelButton, SIGNAL(Clicked()), SLOT(Close()));
703  connect(okButton, SIGNAL(Clicked()), SLOT(sendResult()));
704 
705  messageText->SetText(m_message);
706  BuildFocusList();
707 
708  return true;
709 }
710 
715 void MythSpinBoxDialog::SetRange(int low, int high, int step, uint pageMultiple)
716 {
717  m_spinBox->SetRange(low, high, step, pageMultiple);
718 }
719 
723 void MythSpinBoxDialog::AddSelection(const QString& label, int value)
724 {
725  m_spinBox->AddSelection(value, label);
726 }
727 
732 void MythSpinBoxDialog::SetValue (const QString & value)
733 {
734  m_spinBox->SetValue(value);
735 }
736 
741 {
742  m_spinBox->SetValue(value);
743 }
744 
745 void MythSpinBoxDialog::SetReturnEvent(QObject *retobject,
746  const QString &resultid)
747 {
748  m_retObject = retobject;
749  m_id = resultid;
750 }
751 
753 {
754  QString inputString = m_spinBox->GetValue();
755  emit haveResult(inputString);
756 
757  if (m_retObject)
758  {
760  inputString, "");
761  QCoreApplication::postEvent(m_retObject, dce);
762  }
763 
764  Close();
765 }
766 
768 
769 
785  const QString &title,
786  const QStringList &list,
787  bool matchAnywhere,
788  const QString &defaultValue)
789  : MythScreenType(parent, "mythsearchdialogpopup")
790 {
791  m_list = list;
792  m_matchAnywhere = matchAnywhere;
793  m_title = title;
794  m_defaultValue = defaultValue;
795 
796  m_titleText = nullptr;
797  m_matchesText = nullptr;
798  m_textEdit = nullptr;
799  m_itemList = nullptr;
800 
801  m_id = "";
802  m_retObject = nullptr;
803 }
804 
806 {
807  if (!CopyWindowFromBase("MythSearchDialog", this))
808  return false;
809 
810  MythUIButton *okButton = nullptr;
811  MythUIButton *cancelButton = nullptr;
812 
813  bool err = false;
814  UIUtilE::Assign(this, m_textEdit, "input", &err);
815  UIUtilE::Assign(this, m_titleText, "title", &err);
816  UIUtilW::Assign(this, m_matchesText, "matches");
817  UIUtilE::Assign(this, m_itemList, "itemlist", &err);
818  UIUtilE::Assign(this, okButton, "ok", &err);
819  UIUtilW::Assign(this, cancelButton, "cancel");
820 
821  if (err)
822  {
823  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythSearchDialog'");
824  return false;
825  }
826 
827  if (cancelButton)
828  connect(cancelButton, SIGNAL(Clicked()), SLOT(Close()));
829 
830  connect(okButton, SIGNAL(Clicked()), SLOT(slotSendResult()));
831 
832  connect(m_itemList, SIGNAL(itemClicked(MythUIButtonListItem*)),
833  SLOT(slotSendResult()));
834 
836  connect(m_textEdit, SIGNAL(valueChanged()), SLOT(slotUpdateList()));
837 
839  if (m_matchesText)
840  m_matchesText->SetText(tr("%n match(es)", "", 0));
841 
842  BuildFocusList();
843 
844  slotUpdateList();
845 
846  return true;
847 }
848 
849 void MythUISearchDialog::SetReturnEvent(QObject *retobject,
850  const QString &resultid)
851 {
852  m_retObject = retobject;
853  m_id = resultid;
854 }
855 
857 {
858  if (!m_itemList->GetItemCurrent())
859  return;
860 
861  QString result = m_itemList->GetValue();
862 
863  emit haveResult(result);
864 
865  if (m_retObject)
866  {
868  result, "");
869  QCoreApplication::postEvent(m_retObject, dce);
870  }
871 
872  Close();
873 }
874 
876 {
877  m_itemList->Reset();
878 
879  for (int x = 0; x < m_list.size(); x++)
880  {
881  QString item = m_list.at(x);
882 
883  if (m_matchAnywhere)
884  {
885  if (!item.contains(m_textEdit->GetText(), Qt::CaseInsensitive))
886  continue;
887  }
888  else
889  {
890  if (!item.startsWith(m_textEdit->GetText(), Qt::CaseInsensitive))
891  continue;
892  }
893 
894  // add item to list
895  new MythUIButtonListItem(m_itemList, item, nullptr, false);
896  }
897 
899 
900  if (m_matchesText)
901  m_matchesText->SetText(tr("%n match(es)", "", 0));
902 }
903 
905 
907  const QString &message,
908  int resolutionFlags,
909  QDateTime startTime,
910  int rangeLimit)
911  : MythScreenType(parent, "timepopup"),
912  m_message(message), m_startTime(std::move(startTime)),
913  m_resolution(resolutionFlags), m_rangeLimit(rangeLimit),
914  m_dateList(nullptr), m_timeList(nullptr), m_retObject(nullptr)
915 {
916 }
917 
919 {
920  if (!CopyWindowFromBase("MythTimeInputDialog", this))
921  return false;
922 
923  MythUIText *messageText = nullptr;
924  MythUIButton *okButton = nullptr;
925 
926  bool err = false;
927  UIUtilE::Assign(this, messageText, "message", &err);
928  UIUtilE::Assign(this, m_dateList, "dates", &err);
929  UIUtilE::Assign(this, m_timeList, "times", &err);
930  UIUtilE::Assign(this, okButton, "ok", &err);
931 
932  if (err)
933  {
934  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythTimeInputDialog'");
935  return false;
936  }
937 
938  m_dateList->SetVisible(false);
939  m_timeList->SetVisible(false);
940 
941  MythUIButtonListItem *item;
942  // Date
943  if (kNoDate != (m_resolution & 0xF))
944  {
945  const QDate startdate(m_startTime.toLocalTime().date());
946  QDate date(startdate);
947 
948  int limit = 0;
950  {
951  limit += m_rangeLimit;
952  }
953  if (m_resolution & kPastDates)
954  {
955  limit += m_rangeLimit;
956  date = date.addDays(0-m_rangeLimit);
957  }
958 
959  QString text;
960  int flags;
961  bool selected = false;
962  for (int x = 0; x <= limit; x++)
963  {
964  selected = false;
965  if (m_resolution & kDay)
966  {
967  date = date.addDays(1);
969  if (m_rangeLimit >= 356)
970  flags |= MythDate::kAddYear;
971  text = MythDate::toString(date, flags);
972 
973  if (date == startdate)
974  selected = true;
975  }
976  else if (m_resolution & kMonth)
977  {
978  date = date.addMonths(1);
979  text = date.toString("MMM yyyy");
980 
981  if ((date.month() == startdate.month()) &&
982  (date.year() == startdate.year()))
983  selected = true;
984  }
985  else if (m_resolution & kYear)
986  {
987  date = date.addYears(1);
988  text = date.toString("yyyy");
989  if (date.year() == startdate.year())
990  selected = true;
991  }
992 
993  item = new MythUIButtonListItem(m_dateList, text, nullptr, false);
994  item->SetData(QVariant(date));
995 
996  if (selected)
997  m_dateList->SetItemCurrent(item);
998  }
999  m_dateList->SetVisible(true);
1000  }
1001 
1002  // Time
1003  if (kNoTime != (m_resolution & 0xF0))
1004  {
1005  QDate startdate(m_startTime.toLocalTime().date());
1006  QTime starttime(m_startTime.toLocalTime().time());
1007  QTime time(0,0,0);
1008  QString text;
1009  bool selected = false;
1010 
1011  int limit = (m_resolution & kMinutes) ? (60 * 24) : 24;
1012 
1013  for (int x = 0; x < limit; x++)
1014  {
1015  selected = false;
1016  if (m_resolution & kMinutes)
1017  {
1018  time = time.addSecs(60);
1019  QDateTime dt = QDateTime(startdate, time, Qt::LocalTime);
1020  text = MythDate::toString(dt, MythDate::kTime);
1021 
1022  if (time == starttime)
1023  selected = true;
1024  }
1025  else if (m_resolution & kHours)
1026  {
1027  time = time.addSecs(60*60);
1028  text = time.toString("hh:00");
1029 
1030  if (time.hour() == starttime.hour())
1031  selected = true;
1032  }
1033 
1034  item = new MythUIButtonListItem(m_timeList, text, nullptr, false);
1035  item->SetData(QVariant(time));
1036 
1037  if (selected)
1038  m_timeList->SetItemCurrent(item);
1039  }
1040  m_timeList->SetVisible(true);
1041  }
1042 
1043  if (messageText && !m_message.isEmpty())
1044  messageText->SetText(m_message);
1045 
1046  connect(okButton, SIGNAL(Clicked()), SLOT(okClicked()));
1047 
1048  BuildFocusList();
1049 
1050  return true;
1051 }
1052 
1053 void MythTimeInputDialog::SetReturnEvent(QObject* retobject,
1054  const QString& resultid)
1055 {
1056  m_retObject = retobject;
1057  m_id = resultid;
1058 }
1059 
1061 {
1062  QDate date = m_dateList->GetDataValue().toDate();
1063  QTime time = m_timeList->GetDataValue().toTime();
1064 
1065  QDateTime dateTime = QDateTime(date, time, Qt::LocalTime).toUTC();
1066 
1067  emit haveResult(dateTime);
1068 
1069  if (m_retObject)
1070  {
1071  QVariant data(dateTime);
1073  data);
1074  QCoreApplication::postEvent(m_retObject, dce);
1075  }
1076 
1077  Close();
1078 }
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
MythTimeInputDialog(MythScreenStack *parent, const QString &message, int resolutionFlags, QDateTime startTime=QDateTime::currentDateTime(), int rangeLimit=14)
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
void SetData(QVariant data)
QString GetValue(void) const override
Definition: mythuispinbox.h:31
void SetRedraw(void)
Definition: mythuitype.cpp:295
MythUIButtonList * m_timeList
#define LOC
void slotSendResult(void)
void Select(MythUIButtonListItem *item)
MythSpinBoxDialog(MythScreenStack *parent, const QString &message)
void SetFilter(InputFilter filter)
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:136
int GetItemPos(MythUIButtonListItem *item) const
void SetParent(MythMenu *parent)
MythScreenStack * GetStack(const QString &stackname)
QString m_text
void setDrawArrow(bool flag)
unsigned int uint
Definition: compat.h:140
void SetValue(int val) override
Definition: mythuispinbox.h:26
MythScreenStack * GetMainStack()
Gesture gesture(void) const
Get the gesture type.
Definition: mythgesture.h:107
QString m_title
QList< MythMenuItem * > m_menuItems
static MythThemedMenu * menu
QObject * m_retObject
void BuildFocusList(void)
static Type kEventType
Definition: mythdialogbox.h:50
QObject * m_retObject
bool gestureEvent(MythGestureEvent *) override
Mouse click/movement handler, receives mouse gesture events from the QCoreApplication event loop.
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
Default local time.
Definition: mythdate.h:19
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
Do Today/Yesterday/Tomorrow transform.
Definition: mythdate.h:23
void Init(void)
QVariant m_data
Definition: mythdialogbox.h:73
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
void haveResult(QDateTime time)
bool keyPressEvent(QKeyEvent *) override
Key event handler.
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
void SetMenuItems(MythMenu *menu)
Button GetButton(void) const
Definition: mythgesture.h:119
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)
void updateMenu(void)
MythMenu(const QString &text, QObject *retobject, const QString &resultid)
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
bool SetFocusWidget(MythUIType *widget=nullptr)
Add year to string if not included.
Definition: mythdate.h:22
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
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
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:75
QVariant m_exitdata
bool Create(void) override
std::function< void(void)> MythUIButtonCallback
Definition: mythdialogbox.h:60
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:72
MythUIButtonListItem * GetItemCurrent() const
bool Create(void) override
MythUITextEdit * m_textEdit