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(QString text, QObject *retobject, QString resultid) :
32  m_text(std::move(text)), m_resultid(std::move(resultid)), m_retObject(retobject)
33 {
34  Init();
35 }
36 
37 MythMenu::MythMenu(QString title, QString text, QObject *retobject, QString resultid) :
38  m_title(std::move(title)), m_text(std::move(text)), m_resultid(std::move(resultid)),
39  m_retObject(retobject)
40 {
41  Init();
42 }
43 
45 {
46  while (!m_menuItems.isEmpty())
47  {
48  MythMenuItem *item = m_menuItems.takeFirst();
49 
50  delete item->m_subMenu;
51  delete item;
52  }
53 }
54 
55 void MythMenu::AddItem(const QString& title, const char* slot, MythMenu *subMenu, bool selected, bool checked)
56 {
57  auto *item = new MythMenuItem(title, slot, checked, subMenu);
58  AddItem(item, selected, subMenu);
59 }
60 
61 void MythMenu::AddItem(const QString &title, QVariant data, MythMenu *subMenu, bool selected, bool checked)
62 {
63  auto *item = new MythMenuItem(title, std::move(data), checked, subMenu);
64  AddItem(item, selected, subMenu);
65 }
66 
67 void MythMenu::AddItem(const QString &title, const MythUIButtonCallback &slot,
68  MythMenu *subMenu, bool selected, bool checked)
69 {
70  auto *item = new MythMenuItem(title, slot, checked, subMenu);
71  AddItem(item, selected, subMenu);
72 }
73 
74 void MythMenu::AddItem(MythMenuItem *item, bool selected, MythMenu *subMenu)
75 {
76  m_menuItems.append(item);
77 
78  if (selected)
79  m_selectedItem = m_menuItems.indexOf(item);
80 
81  if (subMenu)
82  subMenu->SetParent(this);
83 }
84 
85 void MythMenu::SetSelectedByTitle(const QString& title)
86 {
87  QList<MythMenuItem*>::iterator it = m_menuItems.begin();
88  for ( ; it < m_menuItems.end(); ++it)
89  {
90  MythMenuItem *item = (*it);
91  if (!item)
92  continue;
93 
94  if (item->m_text == title)
95  {
96  m_selectedItem = m_menuItems.indexOf(item);
97  break;
98  }
99  }
100 }
101 
102 void MythMenu::SetSelectedByData(const QVariant& data)
103 {
104  QList<MythMenuItem*>::iterator it = m_menuItems.begin();
105  for ( ; it < m_menuItems.end(); ++it)
106  {
107  MythMenuItem *item = (*it);
108  if (!item)
109  continue;
110 
111  if (item->m_data == data)
112  {
113  m_selectedItem = m_menuItems.indexOf(item);
114  break;
115  }
116  }
117 }
118 
120 
122 {
123  if (m_menu)
124  {
125  delete m_menu;
126  m_menu = nullptr;
127  }
128 }
129 
131 {
132  QString windowName = (m_fullscreen ? "MythDialogBox" : "MythPopupBox");
133 
134  if (m_osdDialog)
135  {
136  if (!XMLParseBase::LoadWindowFromXML("osd.xml", windowName, this))
137  return false;
138  }
139  else if (!CopyWindowFromBase(windowName, this))
140  return false;
141 
142  bool err = false;
143  UIUtilW::Assign(this, m_titlearea, "title");
144  UIUtilE::Assign(this, m_textarea, "messagearea", &err);
145  UIUtilE::Assign(this, m_buttonList, "list", &err);
146 
147  if (err)
148  {
149  LOG(VB_GENERAL, LOG_ERR, QString("Cannot load screen '%1'")
150  .arg(windowName));
151  return false;
152  }
153 
154  if (m_titlearea)
157 
158  BuildFocusList();
159 
160  if (m_menu)
161  updateMenu();
162 
163  connect(m_buttonList, SIGNAL(itemClicked(MythUIButtonListItem*)),
164  SLOT(Select(MythUIButtonListItem*)));
165 
166  return true;
167 }
168 
170 {
171  m_menu = menu;
173  updateMenu();
174 }
175 
177 {
178  if (!m_buttonList)
179  {
180  LOG(VB_GENERAL, LOG_ERR, "UpdateMenu() called before we have a button list to update!");
181  return;
182  }
183 
184  if (!m_currentMenu)
185  return;
186 
187  if (m_titlearea)
189 
191 
192  m_buttonList->Reset();
193 
194  for (int x = 0; x < m_currentMenu->m_menuItems.count(); x++)
195  {
196  MythMenuItem *menuItem = m_currentMenu->m_menuItems.at(x);
197  auto *button = new MythUIButtonListItem(m_buttonList, menuItem->m_text);
198  button->SetData(qVariantFromValue(menuItem));
199  button->setDrawArrow((menuItem->m_subMenu != nullptr));
200 
201  if (m_currentMenu->m_selectedItem == x)
202  m_buttonList->SetItemCurrent(button);
203  }
204  // GetVisibleCount here makes sure that the dialog size is
205  // calculated correctly
208 }
209 
211 {
212  if (!item)
213  return;
214 
215  if (m_currentMenu)
216  {
217  auto *menuItem = item->GetData().value< MythMenuItem * >();
218 
219  if (menuItem->m_subMenu)
220  {
222  m_currentMenu = menuItem->m_subMenu;
223  updateMenu();
224  return;
225  }
226 
227  if (menuItem->m_useSlot)
228  {
229  const char *slot = menuItem->m_data.value < const char * >();
230  if (slot)
231  {
232  connect(this, SIGNAL(Selected()), m_currentMenu->m_retObject, slot,
233  Qt::QueuedConnection);
234  emit Selected();
235  }
236  else if (menuItem->m_data.value<MythUIButtonCallback>())
237  {
239  menuItem->m_data.value<MythUIButtonCallback>(),
240  Qt::QueuedConnection);
241  emit Selected();
242  }
243  }
244 
245  SendEvent(m_buttonList->GetItemPos(item), item->GetText(), menuItem->m_data);
246  }
247  else
248  {
249  if (m_useSlots)
250  {
251  const char *slot = item->GetData().value<const char *>();
252  if (slot)
253  {
254  connect(this, SIGNAL(Selected()), m_retObject, slot,
255  Qt::QueuedConnection);
256  emit Selected();
257  }
258  else if (item->GetData().value<MythUIButtonCallback>())
259  {
260  connect(this, &MythDialogBox::Selected, m_retObject,
261  item->GetData().value<MythUIButtonCallback>(),
262  Qt::QueuedConnection);
263  emit Selected();
264  }
265  }
266 
267  SendEvent(m_buttonList->GetItemPos(item), item->GetText(), item->GetData());
268  }
269 
270  if (m_ScreenStack)
271  m_ScreenStack->PopScreen(nullptr, false);
272 }
273 
274 void MythDialogBox::SetReturnEvent(QObject *retobject,
275  const QString &resultid)
276 {
277  m_retObject = retobject;
278  m_id = resultid;
279 }
280 
281 void MythDialogBox::SetBackAction(const QString &text, QVariant data)
282 {
283  m_backtext = text;
284  m_backdata = std::move(data);
285 }
286 
287 void MythDialogBox::SetExitAction(const QString &text, QVariant data)
288 {
289  m_exittext = text;
290  m_exitdata = std::move(data);
291 }
292 
293 void MythDialogBox::SetText(const QString &text)
294 {
295  if (m_textarea)
296  m_textarea->SetText(text);
297 }
298 
299 void MythDialogBox::AddButton(const QString &title, QVariant data, bool newMenu,
300  bool setCurrent)
301 {
302  auto *button = new MythUIButtonListItem(m_buttonList, title);
303  button->SetData(std::move(data));
304  button->setDrawArrow(newMenu);
305 
306  if (setCurrent)
307  m_buttonList->SetItemCurrent(button);
308  // GetVisibleCount here makes sure that the dialog size is
309  // calculated correctly
311 }
312 
313 void MythDialogBox::AddButton(const QString &title, const char *slot,
314  bool newMenu, bool setCurrent)
315 {
316  auto *button = new MythUIButtonListItem(m_buttonList, title);
317 
318  m_useSlots = true;
319 
320  if (slot)
321  button->SetData(qVariantFromValue(slot));
322  button->setDrawArrow(newMenu);
323 
324  if (setCurrent)
325  m_buttonList->SetItemCurrent(button);
326  // GetVisibleCount here makes sure that the dialog size is
327  // calculated correctly
329 }
330 
331 bool MythDialogBox::keyPressEvent(QKeyEvent *event)
332 {
333  if (GetFocusWidget()->keyPressEvent(event))
334  return true;
335 
336  bool handled = false;
337  QStringList actions;
338  handled = GetMythMainWindow()->TranslateKeyPress("qt", event, actions);
339 
340  for (int i = 0; i < actions.size() && !handled; i++)
341  {
342  QString action = actions[i];
343  handled = true;
344 
345  if (action == "ESCAPE")
346  {
348  if (m_exitdata == 0 && m_exittext.isEmpty())
349  Close();
350  }
351  else if ((action == "LEFT" &&
353  (action == "UP" &&
355  {
357  {
359  updateMenu();
360  return true;
361  }
362 
364  Close();
365  }
366  else if (action == "MENU")
367  {
368  SendEvent(-2);
369  Close();
370  }
371  else if ((action == "RIGHT" &&
373  (action == "DOWN" &&
375  {
377  }
378  else
379  handled = false;
380  }
381 
382  if (!handled && MythScreenType::keyPressEvent(event))
383  handled = true;
384 
385  return handled;
386 }
387 
389 {
390  bool handled = false;
391  if (event->gesture() == MythGestureEvent::Click)
392  {
393  switch (event->GetButton())
394  {
396  SendEvent(-2);
397  Close();
398  handled = true;
399  break;
400  default :
401  break;
402  }
403 
404  }
405 
406  if (!handled && MythScreenType::gestureEvent(event))
407  handled = true;
408 
409  return handled;
410 }
411 
412 void MythDialogBox::SendEvent(int res, const QString& text, const QVariant& data)
413 {
414  if (m_currentMenu)
415  {
416  emit Closed(m_currentMenu->m_resultid, res);
417 
419  return;
420 
421  auto *dce = new DialogCompletionEvent(m_currentMenu->m_resultid, res, text, data);
422  QCoreApplication::postEvent(m_currentMenu->m_retObject, dce);
423  }
424  else
425  {
426  emit Closed(m_id, res);
427 
428  if (!m_retObject)
429  return;
430 
431  auto *dce = new DialogCompletionEvent(m_id, res, text, data);
432  QCoreApplication::postEvent(m_retObject, dce);
433  }
434 }
435 
437 
439 {
440  if (!CopyWindowFromBase("MythConfirmationDialog", this))
441  return false;
442 
443  MythUIButton *okButton = nullptr;
444  MythUIButton *cancelButton = nullptr;
445 
446  bool err = false;
447  UIUtilE::Assign(this, m_messageText, "message", &err);
448  UIUtilE::Assign(this, okButton, "ok", &err);
449  UIUtilE::Assign(this, cancelButton, "cancel", &err);
450 
451  if (err)
452  {
453  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythConfirmationDialog'");
454  return false;
455  }
456 
457  if (m_showCancel)
458  {
459  connect(cancelButton, SIGNAL(Clicked()), SLOT(Cancel()));
460  }
461  else
462  cancelButton->SetVisible(false);
463 
464  connect(okButton, SIGNAL(Clicked()), SLOT(Confirm()));
465 
467 
468  BuildFocusList();
469 
470  if (m_showCancel)
471  SetFocusWidget(cancelButton);
472  else
473  SetFocusWidget(okButton);
474 
475  return true;
476 }
477 
479 {
480  if (GetFocusWidget()->keyPressEvent(event))
481  return true;
482 
483  bool handled = false;
484  QStringList actions;
485  handled = GetMythMainWindow()->TranslateKeyPress("qt", event, actions);
486 
487  for (int i = 0; i < actions.size() && !handled; i++)
488  {
489  QString action = actions[i];
490  handled = true;
491 
492  if (action == "ESCAPE")
493  sendResult(false);
494  else
495  handled = false;
496  }
497 
498  if (!handled && MythScreenType::keyPressEvent(event))
499  handled = true;
500 
501  return handled;
502 }
503 
504 void MythConfirmationDialog::SetMessage(const QString &message)
505 {
506  m_message = message;
507  if (m_messageText)
509 }
510 
512  const QString &resultid)
513 {
514  m_retObject = retobject;
515  m_id = resultid;
516 }
517 
519 {
520  sendResult(true);
521 }
522 
524 {
525  sendResult(false);
526 }
527 
529 {
530  emit haveResult(ok);
531 
532  if (m_retObject)
533  {
534  int res = 0;
535  if (ok)
536  res = 1;
537 
538  auto *dce = new DialogCompletionEvent(m_id, res, "", 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 + "') - ";
553  MythScreenStack *stk = nullptr;
554 
556 
557  if (win)
558  stk = win->GetStack("popup stack");
559  else
560  {
561  LOG(VB_GENERAL, LOG_ERR, LOC + "no main window?");
562  return nullptr;
563  }
564 
565  if (!stk)
566  {
567  LOG(VB_GENERAL, LOG_ERR, LOC + "no popup stack? "
568  "Is there a MythThemeBase?");
569  return nullptr;
570  }
571 
572  auto pop = new MythConfirmationDialog(stk, message, showCancel);
573  if (pop->Create())
574  {
575  stk->AddScreen(pop);
576  if (parent && slot)
577  QObject::connect(pop, SIGNAL(haveResult(bool)), parent, slot,
578  Qt::QueuedConnection);
579  }
580  else
581  {
582  delete pop;
583  pop = nullptr;
584  LOG(VB_GENERAL, LOG_ERR, LOC + "Couldn't Create() Dialog");
585  }
586 
587  return pop;
588 }
589 
591 {
592  if (!dialog)
593  return true; // No dialog is treated as user pressing OK
594 
595  // Local event loop processes events whilst we wait
596  QEventLoop block;
597 
598  // Quit when dialog exits
599  QObject::connect(dialog, &MythConfirmationDialog::haveResult,
600  &block, [&block](bool result)
601  { block.exit(result ? 1 : 0); });
602 
603  // Block and return dialog result
604  return block.exec() != 0;
605 }
606 
608 
610 {
611  if (!CopyWindowFromBase("MythTextInputDialog", this))
612  return false;
613 
614  MythUIText *messageText = nullptr;
615  MythUIButton *okButton = nullptr;
616  MythUIButton *cancelButton = nullptr;
617 
618  bool err = false;
619  UIUtilE::Assign(this, m_textEdit, "input", &err);
620  UIUtilE::Assign(this, messageText, "message", &err);
621  UIUtilE::Assign(this, okButton, "ok", &err);
622  UIUtilW::Assign(this, cancelButton, "cancel");
623 
624  if (err)
625  {
626  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythTextInputDialog'");
627  return false;
628  }
629 
630  if (cancelButton)
631  connect(cancelButton, SIGNAL(Clicked()), SLOT(Close()));
632  connect(okButton, SIGNAL(Clicked()), SLOT(sendResult()));
633 
637 
638  messageText->SetText(m_message);
639 
640  BuildFocusList();
641 
642  return true;
643 }
644 
645 void MythTextInputDialog::SetReturnEvent(QObject *retobject,
646  const QString &resultid)
647 {
648  m_retObject = retobject;
649  m_id = resultid;
650 }
651 
653 {
654  QString inputString = m_textEdit->GetText();
655  emit haveResult(inputString);
656 
657  if (m_retObject)
658  {
659  auto *dce = new DialogCompletionEvent(m_id, 0, inputString, "");
660  QCoreApplication::postEvent(m_retObject, dce);
661  }
662 
663  Close();
664 }
665 
667 
669  QString message)
670  : MythScreenType(parent, "mythspinboxpopup"),
671  m_spinBox(nullptr),
672  m_message(std::move(message)),
673  m_retObject(nullptr),
674  m_id("")
675 {
676 }
677 
679 {
680  if (!CopyWindowFromBase("MythSpinBoxDialog", this))
681  return false;
682 
683  MythUIText *messageText = nullptr;
684  MythUIButton *okButton = nullptr;
685  MythUIButton *cancelButton = nullptr;
686 
687  bool err = false;
688  UIUtilE::Assign(this, m_spinBox, "input", &err);
689  UIUtilE::Assign(this, messageText, "message", &err);
690  UIUtilE::Assign(this, okButton, "ok", &err);
691  UIUtilW::Assign(this, cancelButton, "cancel");
692 
693  if (err)
694  {
695  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythSpinBoxDialog'");
696  return false;
697  }
698 
699  if (cancelButton)
700  connect(cancelButton, SIGNAL(Clicked()), SLOT(Close()));
701  connect(okButton, SIGNAL(Clicked()), SLOT(sendResult()));
702 
703  messageText->SetText(m_message);
704  BuildFocusList();
705 
706  return true;
707 }
708 
713 void MythSpinBoxDialog::SetRange(int low, int high, int step, uint pageMultiple)
714 {
715  m_spinBox->SetRange(low, high, step, pageMultiple);
716 }
717 
721 void MythSpinBoxDialog::AddSelection(const QString& label, int value)
722 {
723  m_spinBox->AddSelection(value, label);
724 }
725 
730 void MythSpinBoxDialog::SetValue (const QString & value)
731 {
732  m_spinBox->SetValue(value);
733 }
734 
739 {
740  m_spinBox->SetValue(value);
741 }
742 
743 void MythSpinBoxDialog::SetReturnEvent(QObject *retobject,
744  const QString &resultid)
745 {
746  m_retObject = retobject;
747  m_id = resultid;
748 }
749 
751 {
752  QString inputString = m_spinBox->GetValue();
753  emit haveResult(inputString);
754 
755  if (m_retObject)
756  {
757  auto *dce = new DialogCompletionEvent(m_id, 0, inputString, "");
758  QCoreApplication::postEvent(m_retObject, dce);
759  }
760 
761  Close();
762 }
763 
765 
766 
782  const QString &title,
783  const QStringList &list,
784  bool matchAnywhere,
785  const QString &defaultValue)
786  : MythScreenType(parent, "mythsearchdialogpopup")
787 {
788  m_list = list;
789  m_matchAnywhere = matchAnywhere;
790  m_title = title;
791  m_defaultValue = defaultValue;
792 
793  m_titleText = nullptr;
794  m_matchesText = nullptr;
795  m_textEdit = nullptr;
796  m_itemList = nullptr;
797 
798  m_id = "";
799  m_retObject = nullptr;
800 }
801 
803 {
804  if (!CopyWindowFromBase("MythSearchDialog", this))
805  return false;
806 
807  MythUIButton *okButton = nullptr;
808  MythUIButton *cancelButton = nullptr;
809 
810  bool err = false;
811  UIUtilE::Assign(this, m_textEdit, "input", &err);
812  UIUtilE::Assign(this, m_titleText, "title", &err);
813  UIUtilW::Assign(this, m_matchesText, "matches");
814  UIUtilE::Assign(this, m_itemList, "itemlist", &err);
815  UIUtilE::Assign(this, okButton, "ok", &err);
816  UIUtilW::Assign(this, cancelButton, "cancel");
817 
818  if (err)
819  {
820  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythSearchDialog'");
821  return false;
822  }
823 
824  if (cancelButton)
825  connect(cancelButton, SIGNAL(Clicked()), SLOT(Close()));
826 
827  connect(okButton, SIGNAL(Clicked()), SLOT(slotSendResult()));
828 
829  connect(m_itemList, SIGNAL(itemClicked(MythUIButtonListItem*)),
830  SLOT(slotSendResult()));
831 
833  connect(m_textEdit, SIGNAL(valueChanged()), SLOT(slotUpdateList()));
834 
836  if (m_matchesText)
837  m_matchesText->SetText(tr("%n match(es)", "", 0));
838 
839  BuildFocusList();
840 
841  slotUpdateList();
842 
843  return true;
844 }
845 
846 void MythUISearchDialog::SetReturnEvent(QObject *retobject,
847  const QString &resultid)
848 {
849  m_retObject = retobject;
850  m_id = resultid;
851 }
852 
854 {
855  if (!m_itemList->GetItemCurrent())
856  return;
857 
858  QString result = m_itemList->GetValue();
859 
860  emit haveResult(result);
861 
862  if (m_retObject)
863  {
864  auto *dce = new DialogCompletionEvent(m_id, 0, result, "");
865  QCoreApplication::postEvent(m_retObject, dce);
866  }
867 
868  Close();
869 }
870 
872 {
873  m_itemList->Reset();
874 
875  for (int x = 0; x < m_list.size(); x++)
876  {
877  QString item = m_list.at(x);
878 
879  if (m_matchAnywhere)
880  {
881  if (!item.contains(m_textEdit->GetText(), Qt::CaseInsensitive))
882  continue;
883  }
884  else
885  {
886  if (!item.startsWith(m_textEdit->GetText(), Qt::CaseInsensitive))
887  continue;
888  }
889 
890  // add item to list
891  new MythUIButtonListItem(m_itemList, item, nullptr, false);
892  }
893 
895 
896  if (m_matchesText)
897  m_matchesText->SetText(tr("%n match(es)", "", 0));
898 }
899 
901 
903  QString message,
904  int resolutionFlags,
905  QDateTime startTime,
906  int rangeLimit)
907  : MythScreenType(parent, "timepopup"),
908  m_message(std::move(message)), m_startTime(std::move(startTime)),
909  m_resolution(resolutionFlags), m_rangeLimit(rangeLimit),
910  m_dateList(nullptr), m_timeList(nullptr), m_retObject(nullptr)
911 {
912 }
913 
915 {
916  if (!CopyWindowFromBase("MythTimeInputDialog", this))
917  return false;
918 
919  MythUIText *messageText = nullptr;
920  MythUIButton *okButton = nullptr;
921 
922  bool err = false;
923  UIUtilE::Assign(this, messageText, "message", &err);
924  UIUtilE::Assign(this, m_dateList, "dates", &err);
925  UIUtilE::Assign(this, m_timeList, "times", &err);
926  UIUtilE::Assign(this, okButton, "ok", &err);
927 
928  if (err)
929  {
930  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythTimeInputDialog'");
931  return false;
932  }
933 
934  m_dateList->SetVisible(false);
935  m_timeList->SetVisible(false);
936 
937  // Date
938  if (kNoDate != (m_resolution & 0xF))
939  {
940  const QDate startdate(m_startTime.toLocalTime().date());
941  QDate date(startdate);
942 
943  int limit = 0;
945  {
946  limit += m_rangeLimit;
947  }
948  if (m_resolution & kPastDates)
949  {
950  limit += m_rangeLimit;
951  date = date.addDays(0-m_rangeLimit);
952  }
953 
954  QString text;
955  bool selected = false;
956  for (int x = 0; x <= limit; x++)
957  {
958  selected = false;
959  if (m_resolution & kDay)
960  {
961  date = date.addDays(1);
963  if (m_rangeLimit >= 356)
964  flags |= MythDate::kAddYear;
965  text = MythDate::toString(date, flags);
966 
967  if (date == startdate)
968  selected = true;
969  }
970  else if (m_resolution & kMonth)
971  {
972  date = date.addMonths(1);
973  text = date.toString("MMM yyyy");
974 
975  if ((date.month() == startdate.month()) &&
976  (date.year() == startdate.year()))
977  selected = true;
978  }
979  else if (m_resolution & kYear)
980  {
981  date = date.addYears(1);
982  text = date.toString("yyyy");
983  if (date.year() == startdate.year())
984  selected = true;
985  }
986 
987  auto item = new MythUIButtonListItem(m_dateList, text, nullptr, false);
988  item->SetData(QVariant(date));
989 
990  if (selected)
991  m_dateList->SetItemCurrent(item);
992  }
993  m_dateList->SetVisible(true);
994  }
995 
996  // Time
997  if (kNoTime != (m_resolution & 0xF0))
998  {
999  QDate startdate(m_startTime.toLocalTime().date());
1000  QTime starttime(m_startTime.toLocalTime().time());
1001  QTime time(0,0,0);
1002  QString text;
1003  bool selected = false;
1004 
1005  int limit = (m_resolution & kMinutes) ? (60 * 24) : 24;
1006 
1007  for (int x = 0; x < limit; x++)
1008  {
1009  selected = false;
1010  if (m_resolution & kMinutes)
1011  {
1012  time = time.addSecs(60);
1013  QDateTime dt = QDateTime(startdate, time, Qt::LocalTime);
1014  text = MythDate::toString(dt, MythDate::kTime);
1015 
1016  if (time == starttime)
1017  selected = true;
1018  }
1019  else if (m_resolution & kHours)
1020  {
1021  time = time.addSecs(60*60);
1022  text = time.toString("hh:00");
1023 
1024  if (time.hour() == starttime.hour())
1025  selected = true;
1026  }
1027 
1028  auto item = new MythUIButtonListItem(m_timeList, text, nullptr, false);
1029  item->SetData(QVariant(time));
1030 
1031  if (selected)
1032  m_timeList->SetItemCurrent(item);
1033  }
1034  m_timeList->SetVisible(true);
1035  }
1036 
1037  if (messageText && !m_message.isEmpty())
1038  messageText->SetText(m_message);
1039 
1040  connect(okButton, SIGNAL(Clicked()), SLOT(okClicked()));
1041 
1042  BuildFocusList();
1043 
1044  return true;
1045 }
1046 
1047 void MythTimeInputDialog::SetReturnEvent(QObject* retobject,
1048  const QString& resultid)
1049 {
1050  m_retObject = retobject;
1051  m_id = resultid;
1052 }
1053 
1055 {
1056  QDate date = m_dateList->GetDataValue().toDate();
1057  QTime time = m_timeList->GetDataValue().toTime();
1058 
1059  QDateTime dateTime = QDateTime(date, time, Qt::LocalTime).toUTC();
1060 
1061  emit haveResult(dateTime);
1062 
1063  if (m_retObject)
1064  {
1065  QVariant data(dateTime);
1066  auto *dce = new DialogCompletionEvent(m_id, 0, "", data);
1067  QCoreApplication::postEvent(m_retObject, dce);
1068  }
1069 
1070  Close();
1071 }
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:295
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:107
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: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
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)
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)
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: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
Default local time.
Definition: mythdate.h:19