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