MythTV  master
mythdialogbox.cpp
Go to the documentation of this file.
1 
2 #include "mythdialogbox.h"
3 
4 #include <QCoreApplication>
5 #include <QFileInfo>
6 #include <QString>
7 #include <QStringList>
8 #include <QDateTime>
9 #include <QDate>
10 #include <QTime>
11 
12 #include "mythlogging.h"
13 #include "mythdate.h"
14 
15 #include "mythmainwindow.h"
16 #include "mythfontproperties.h"
17 #include "mythuiutils.h"
18 #include "mythuitext.h"
19 #include "mythuiimage.h"
20 #include "mythuibuttonlist.h"
21 #include "mythuibutton.h"
22 #include "mythuistatetype.h"
23 #include "mythuispinbox.h"
24 #include "mythgesture.h"
25 
27  (QEvent::Type) QEvent::registerEventType();
28 
29 
30 MythMenu::MythMenu(const QString &text, QObject *retobject, const QString &resultid) :
31  m_parentMenu(nullptr), m_title(""), m_text(text), m_resultid(resultid), m_retObject(retobject), m_selectedItem(0)
32 {
33  Init();
34 }
35 
36 MythMenu::MythMenu(const QString &title, const QString &text, QObject *retobject, const QString &resultid) :
37  m_parentMenu(nullptr), m_title(title), m_text(text), m_resultid(resultid), m_retObject(retobject), m_selectedItem(0)
38 {
39  Init();
40 }
41 
43 {
44  while (!m_menuItems.isEmpty())
45  {
46  MythMenuItem *item = m_menuItems.takeFirst();
47 
48  if (item->SubMenu)
49  delete item->SubMenu;
50 
51  delete item;
52  }
53 }
54 
55 void MythMenu::AddItem(const QString& title, const char* slot, MythMenu *subMenu, bool selected, bool checked)
56 {
57  MythMenuItem *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  MythMenuItem *item = new MythMenuItem(title, 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  MythMenuItem *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->Text == title)
95  {
96  m_selectedItem = m_menuItems.indexOf(item);
97  break;
98  }
99  }
100 }
101 
102 void MythMenu::SetSelectedByData(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->Data == data)
112  {
113  m_selectedItem = m_menuItems.indexOf(item);
114  break;
115  }
116  }
117 }
118 
120 
121 MythDialogBox::MythDialogBox(const QString &text,
122  MythScreenStack *parent, const char *name,
123  bool fullscreen, bool osd)
124  : MythScreenType(parent, name, false)
125 {
126  m_menu = nullptr;
127  m_currentMenu = nullptr;
128  m_retObject = nullptr;
129  m_titlearea = nullptr;
130  m_text = text;
131  m_textarea = nullptr;
132  m_buttonList = nullptr;
133 
134  m_fullscreen = fullscreen;
135  m_osdDialog = osd;
136  m_useSlots = false;
137 
138  m_backtext = "";
139  m_backdata = 0;
140  m_exittext = "";
141  m_exitdata = 0;
142 }
143 
144 MythDialogBox::MythDialogBox(const QString &title, const QString &text,
145  MythScreenStack *parent, const char *name,
146  bool fullscreen, bool osd)
147  : MythScreenType(parent, name, false)
148 {
149  m_menu = nullptr;
150  m_currentMenu = nullptr;
151  m_id = "";
152  m_retObject = nullptr;
153  m_title = title;
154  m_titlearea = nullptr;
155  m_text = text;
156  m_textarea = nullptr;
157  m_buttonList = nullptr;
158 
159  m_fullscreen = fullscreen;
160  m_osdDialog = osd;
161  m_useSlots = false;
162 
163  m_backtext = "";
164  m_backdata = 0;
165  m_exittext = "";
166  m_exitdata = 0;
167 }
168 
170  bool fullscreen, bool osd)
171  : MythScreenType(parent, name, false)
172 {
173  m_menu = menu;
175  m_id = "";
176  m_retObject = nullptr;
177  m_title = "";
178  m_titlearea = nullptr;
179  m_textarea = nullptr;
180  m_buttonList = nullptr;
181 
182  m_fullscreen = fullscreen;
183  m_osdDialog = osd;
184  m_useSlots = false;
185 
186  m_backtext = "";
187  m_backdata = 0;
188  m_exittext = "";
189  m_exitdata = 0;
190 }
191 
193 {
194  if (m_menu)
195  {
196  delete m_menu;
197  m_menu = nullptr;
198  }
199 }
200 
202 {
203  QString windowName = (m_fullscreen ? "MythDialogBox" : "MythPopupBox");
204 
205  if (m_osdDialog)
206  {
207  if (!XMLParseBase::LoadWindowFromXML("osd.xml", windowName, this))
208  return false;
209  }
210  else if (!CopyWindowFromBase(windowName, this))
211  return false;
212 
213  bool err = false;
214  UIUtilW::Assign(this, m_titlearea, "title");
215  UIUtilE::Assign(this, m_textarea, "messagearea", &err);
216  UIUtilE::Assign(this, m_buttonList, "list", &err);
217 
218  if (err)
219  {
220  LOG(VB_GENERAL, LOG_ERR, QString("Cannot load screen '%1'")
221  .arg(windowName));
222  return false;
223  }
224 
225  if (m_titlearea)
228 
229  BuildFocusList();
230 
231  if (m_menu)
232  updateMenu();
233 
234  connect(m_buttonList, SIGNAL(itemClicked(MythUIButtonListItem*)),
235  SLOT(Select(MythUIButtonListItem*)));
236 
237  return true;
238 }
239 
241 {
242  m_menu = menu;
244  updateMenu();
245 }
246 
248 {
249  if (!m_buttonList)
250  {
251  LOG(VB_GENERAL, LOG_ERR, "UpdateMenu() called before we have a button list to update!");
252  return;
253  }
254 
255  if (!m_currentMenu)
256  return;
257 
258  if (m_titlearea)
260 
262 
263  m_buttonList->Reset();
264 
265  for (int x = 0; x < m_currentMenu->m_menuItems.count(); x++)
266  {
267  MythMenuItem *menuItem = m_currentMenu->m_menuItems.at(x);
269  button->SetData(qVariantFromValue(menuItem));
270  button->setDrawArrow((menuItem->SubMenu != nullptr));
271 
272  if (m_currentMenu->m_selectedItem == x)
273  m_buttonList->SetItemCurrent(button);
274  }
275  // GetVisibleCount here makes sure that the dialog size is
276  // calculated correctly
279 }
280 
282 {
283  if (!item)
284  return;
285 
286  if (m_currentMenu)
287  {
288  MythMenuItem *menuItem = item->GetData().value< MythMenuItem * >();
289 
290  if (menuItem->SubMenu)
291  {
293  m_currentMenu = menuItem->SubMenu;
294  updateMenu();
295  return;
296  }
297 
298  if (menuItem->UseSlot)
299  {
300  const char *slot = menuItem->Data.value < const char * >();
301  if (slot)
302  {
303  connect(this, SIGNAL(Selected()), m_currentMenu->m_retObject, slot,
304  Qt::QueuedConnection);
305  emit Selected();
306  }
307  else if (menuItem->Data.value<MythUIButtonCallback>())
308  {
310  menuItem->Data.value<MythUIButtonCallback>(),
311  Qt::QueuedConnection);
312  emit Selected();
313  }
314  }
315 
316  SendEvent(m_buttonList->GetItemPos(item), item->GetText(), menuItem->Data);
317  }
318  else
319  {
320  if (m_useSlots)
321  {
322  const char *slot = item->GetData().value<const char *>();
323  if (slot)
324  {
325  connect(this, SIGNAL(Selected()), m_retObject, slot,
326  Qt::QueuedConnection);
327  emit Selected();
328  }
329  else if (item->GetData().value<MythUIButtonCallback>())
330  {
331  connect(this, &MythDialogBox::Selected, m_retObject,
332  item->GetData().value<MythUIButtonCallback>(),
333  Qt::QueuedConnection);
334  emit Selected();
335  }
336  }
337 
338  SendEvent(m_buttonList->GetItemPos(item), item->GetText(), item->GetData());
339  }
340 
341  if (m_ScreenStack)
342  m_ScreenStack->PopScreen(nullptr, false);
343 }
344 
345 void MythDialogBox::SetReturnEvent(QObject *retobject,
346  const QString &resultid)
347 {
348  m_retObject = retobject;
349  m_id = resultid;
350 }
351 
352 void MythDialogBox::SetBackAction(const QString &text, QVariant data)
353 {
354  m_backtext = text;
355  m_backdata = data;
356 }
357 
358 void MythDialogBox::SetExitAction(const QString &text, QVariant data)
359 {
360  m_exittext = text;
361  m_exitdata = data;
362 }
363 
364 void MythDialogBox::SetText(const QString &text)
365 {
366  if (m_textarea)
367  m_textarea->SetText(text);
368 }
369 
370 void MythDialogBox::AddButton(const QString &title, QVariant data, bool newMenu,
371  bool setCurrent)
372 {
374  button->SetData(data);
375  button->setDrawArrow(newMenu);
376 
377  if (setCurrent)
378  m_buttonList->SetItemCurrent(button);
379  // GetVisibleCount here makes sure that the dialog size is
380  // calculated correctly
382 }
383 
384 void MythDialogBox::AddButton(const QString &title, const char *slot,
385  bool newMenu, bool setCurrent)
386 {
388 
389  m_useSlots = true;
390 
391  if (slot)
392  button->SetData(qVariantFromValue(slot));
393  button->setDrawArrow(newMenu);
394 
395  if (setCurrent)
396  m_buttonList->SetItemCurrent(button);
397  // GetVisibleCount here makes sure that the dialog size is
398  // calculated correctly
400 }
401 
402 bool MythDialogBox::keyPressEvent(QKeyEvent *event)
403 {
404  if (GetFocusWidget()->keyPressEvent(event))
405  return true;
406 
407  bool handled = false;
408  QStringList actions;
409  handled = GetMythMainWindow()->TranslateKeyPress("qt", event, actions);
410 
411  for (int i = 0; i < actions.size() && !handled; i++)
412  {
413  QString action = actions[i];
414  handled = true;
415 
416  if (action == "ESCAPE")
417  {
419  if (m_exitdata == 0 && m_exittext.isEmpty())
420  Close();
421  }
422  else if ((action == "LEFT" &&
424  (action == "UP" &&
426  {
428  {
430  updateMenu();
431  return true;
432  }
433 
435  Close();
436  }
437  else if (action == "MENU")
438  {
439  SendEvent(-2);
440  Close();
441  }
442  else if ((action == "RIGHT" &&
444  (action == "DOWN" &&
446  {
448  }
449  else
450  handled = false;
451  }
452 
453  if (!handled && MythScreenType::keyPressEvent(event))
454  handled = true;
455 
456  return handled;
457 }
458 
460 {
461  bool handled = false;
462  if (event->gesture() == MythGestureEvent::Click)
463  {
464  switch (event->GetButton())
465  {
467  SendEvent(-2);
468  Close();
469  handled = true;
470  break;
471  default :
472  break;
473  }
474 
475  }
476 
477  if (!handled && MythScreenType::gestureEvent(event))
478  handled = true;
479 
480  return handled;
481 }
482 
483 void MythDialogBox::SendEvent(int res, QString text, QVariant data)
484 {
485  if (m_currentMenu)
486  {
487  emit Closed(m_currentMenu->m_resultid, res);
488 
490  return;
491 
493  QCoreApplication::postEvent(m_currentMenu->m_retObject, dce);
494  }
495  else
496  {
497  emit Closed(m_id, res);
498 
499  if (!m_retObject)
500  return;
501 
502  DialogCompletionEvent *dce = new DialogCompletionEvent(m_id, res, text, data);
503  QCoreApplication::postEvent(m_retObject, dce);
504  }
505 }
506 
508 
510  const QString &message,
511  bool showCancel)
512  : MythScreenType(parent, "mythconfirmpopup")
513 {
514  m_messageText = nullptr;
515  m_message = message;
516  m_showCancel = showCancel;
517 
518  m_id = "";
519  m_retObject = nullptr;
520 }
521 
523 {
524  if (!CopyWindowFromBase("MythConfirmationDialog", this))
525  return false;
526 
527  MythUIButton *okButton = nullptr;
528  MythUIButton *cancelButton = nullptr;
529 
530  bool err = false;
531  UIUtilE::Assign(this, m_messageText, "message", &err);
532  UIUtilE::Assign(this, okButton, "ok", &err);
533  UIUtilE::Assign(this, cancelButton, "cancel", &err);
534 
535  if (err)
536  {
537  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythConfirmationDialog'");
538  return false;
539  }
540 
541  if (m_showCancel)
542  {
543  connect(cancelButton, SIGNAL(Clicked()), SLOT(Cancel()));
544  }
545  else
546  cancelButton->SetVisible(false);
547 
548  connect(okButton, SIGNAL(Clicked()), SLOT(Confirm()));
549 
551 
552  BuildFocusList();
553 
554  if (m_showCancel)
555  SetFocusWidget(cancelButton);
556  else
557  SetFocusWidget(okButton);
558 
559  return true;
560 }
561 
563 {
564  if (GetFocusWidget()->keyPressEvent(event))
565  return true;
566 
567  bool handled = false;
568  QStringList actions;
569  handled = GetMythMainWindow()->TranslateKeyPress("qt", event, actions);
570 
571  for (int i = 0; i < actions.size() && !handled; i++)
572  {
573  QString action = actions[i];
574  handled = true;
575 
576  if (action == "ESCAPE")
577  sendResult(false);
578  else
579  handled = false;
580  }
581 
582  if (!handled && MythScreenType::keyPressEvent(event))
583  handled = true;
584 
585  return handled;
586 }
587 
588 void MythConfirmationDialog::SetMessage(const QString &message)
589 {
590  m_message = message;
591  if (m_messageText)
593 }
594 
596  const QString &resultid)
597 {
598  m_retObject = retobject;
599  m_id = resultid;
600 }
601 
603 {
604  sendResult(true);
605 }
606 
608 {
609  sendResult(false);
610 }
611 
613 {
614  emit haveResult(ok);
615 
616  if (m_retObject)
617  {
618  int res = 0;
619  if (ok)
620  res = 1;
621 
623  m_resultData);
624  QCoreApplication::postEvent(m_retObject, dce);
625  m_retObject = nullptr;
626  }
627 
628  Close();
629 }
630 
634 MythConfirmationDialog *ShowOkPopup(const QString &message, QObject *parent,
635  const char *slot, bool showCancel)
636 {
637  QString LOC = "ShowOkPopup('" + message + "') - ";
639  MythScreenStack *stk = nullptr;
640 
642 
643  if (win)
644  stk = win->GetStack("popup stack");
645  else
646  {
647  LOG(VB_GENERAL, LOG_ERR, LOC + "no main window?");
648  return nullptr;
649  }
650 
651  if (!stk)
652  {
653  LOG(VB_GENERAL, LOG_ERR, LOC + "no popup stack? "
654  "Is there a MythThemeBase?");
655  return nullptr;
656  }
657 
658  pop = new MythConfirmationDialog(stk, message, showCancel);
659  if (pop->Create())
660  {
661  stk->AddScreen(pop);
662  if (parent && slot)
663  QObject::connect(pop, SIGNAL(haveResult(bool)), parent, slot,
664  Qt::QueuedConnection);
665  }
666  else
667  {
668  delete pop;
669  pop = nullptr;
670  LOG(VB_GENERAL, LOG_ERR, LOC + "Couldn't Create() Dialog");
671  }
672 
673  return pop;
674 }
675 
677 
679  const QString &message,
680  InputFilter filter,
681  bool isPassword,
682  const QString &defaultValue)
683  : MythScreenType(parent, "mythtextinputpopup")
684 {
685  m_filter = filter;
686  m_isPassword = isPassword;
687  m_message = message;
688  m_defaultValue = defaultValue;
689  m_textEdit = nullptr;
690 
691  m_id = "";
692  m_retObject = nullptr;
693 }
694 
696 {
697  if (!CopyWindowFromBase("MythTextInputDialog", this))
698  return false;
699 
700  MythUIText *messageText = nullptr;
701  MythUIButton *okButton = nullptr;
702  MythUIButton *cancelButton = nullptr;
703 
704  bool err = false;
705  UIUtilE::Assign(this, m_textEdit, "input", &err);
706  UIUtilE::Assign(this, messageText, "message", &err);
707  UIUtilE::Assign(this, okButton, "ok", &err);
708  UIUtilW::Assign(this, cancelButton, "cancel");
709 
710  if (err)
711  {
712  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythTextInputDialog'");
713  return false;
714  }
715 
716  if (cancelButton)
717  connect(cancelButton, SIGNAL(Clicked()), SLOT(Close()));
718  connect(okButton, SIGNAL(Clicked()), SLOT(sendResult()));
719 
723 
724  messageText->SetText(m_message);
725 
726  BuildFocusList();
727 
728  return true;
729 }
730 
731 void MythTextInputDialog::SetReturnEvent(QObject *retobject,
732  const QString &resultid)
733 {
734  m_retObject = retobject;
735  m_id = resultid;
736 }
737 
739 {
740  QString inputString = m_textEdit->GetText();
741  emit haveResult(inputString);
742 
743  if (m_retObject)
744  {
746  inputString, "");
747  QCoreApplication::postEvent(m_retObject, dce);
748  }
749 
750  Close();
751 }
752 
754 
756  const QString &message)
757  : MythScreenType(parent, "mythspinboxpopup"),
758  m_spinBox(nullptr),
759  m_message(message),
760  m_retObject(nullptr),
761  m_id("")
762 {
763 }
764 
766 {
767  if (!CopyWindowFromBase("MythSpinBoxDialog", this))
768  return false;
769 
770  MythUIText *messageText = nullptr;
771  MythUIButton *okButton = nullptr;
772  MythUIButton *cancelButton = nullptr;
773 
774  bool err = false;
775  UIUtilE::Assign(this, m_spinBox, "input", &err);
776  UIUtilE::Assign(this, messageText, "message", &err);
777  UIUtilE::Assign(this, okButton, "ok", &err);
778  UIUtilW::Assign(this, cancelButton, "cancel");
779 
780  if (err)
781  {
782  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythSpinBoxDialog'");
783  return false;
784  }
785 
786  if (cancelButton)
787  connect(cancelButton, SIGNAL(Clicked()), SLOT(Close()));
788  connect(okButton, SIGNAL(Clicked()), SLOT(sendResult()));
789 
790  messageText->SetText(m_message);
791  BuildFocusList();
792 
793  return true;
794 }
795 
800 void MythSpinBoxDialog::SetRange(int low, int high, int step, uint pageMultiple)
801 {
802  m_spinBox->SetRange(low, high, step, pageMultiple);
803 }
804 
808 void MythSpinBoxDialog::AddSelection(QString label, int value)
809 {
810  m_spinBox->AddSelection(value, label);
811 }
812 
817 void MythSpinBoxDialog::SetValue (const QString & value)
818 {
819  m_spinBox->SetValue(value);
820 }
821 
826 {
827  m_spinBox->SetValue(value);
828 }
829 
830 void MythSpinBoxDialog::SetReturnEvent(QObject *retobject,
831  const QString &resultid)
832 {
833  m_retObject = retobject;
834  m_id = resultid;
835 }
836 
838 {
839  QString inputString = m_spinBox->GetValue();
840  emit haveResult(inputString);
841 
842  if (m_retObject)
843  {
845  inputString, "");
846  QCoreApplication::postEvent(m_retObject, dce);
847  }
848 
849  Close();
850 }
851 
853 
854 
870  const QString &title,
871  const QStringList &list,
872  bool matchAnywhere,
873  const QString &defaultValue)
874  : MythScreenType(parent, "mythsearchdialogpopup")
875 {
876  m_list = list;
877  m_matchAnywhere = matchAnywhere;
878  m_title = title;
879  m_defaultValue = defaultValue;
880 
881  m_titleText = nullptr;
882  m_matchesText = nullptr;
883  m_textEdit = nullptr;
884  m_itemList = nullptr;
885 
886  m_id = "";
887  m_retObject = nullptr;
888 }
889 
891 {
892  if (!CopyWindowFromBase("MythSearchDialog", this))
893  return false;
894 
895  MythUIButton *okButton = nullptr;
896  MythUIButton *cancelButton = nullptr;
897 
898  bool err = false;
899  UIUtilE::Assign(this, m_textEdit, "input", &err);
900  UIUtilE::Assign(this, m_titleText, "title", &err);
901  UIUtilW::Assign(this, m_matchesText, "matches");
902  UIUtilE::Assign(this, m_itemList, "itemlist", &err);
903  UIUtilE::Assign(this, okButton, "ok", &err);
904  UIUtilW::Assign(this, cancelButton, "cancel");
905 
906  if (err)
907  {
908  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythSearchDialog'");
909  return false;
910  }
911 
912  if (cancelButton)
913  connect(cancelButton, SIGNAL(Clicked()), SLOT(Close()));
914 
915  connect(okButton, SIGNAL(Clicked()), SLOT(slotSendResult()));
916 
917  connect(m_itemList, SIGNAL(itemClicked(MythUIButtonListItem*)),
918  SLOT(slotSendResult()));
919 
921  connect(m_textEdit, SIGNAL(valueChanged()), SLOT(slotUpdateList()));
922 
924  if (m_matchesText)
925  m_matchesText->SetText(tr("%n match(es)", "", 0));
926 
927  BuildFocusList();
928 
929  slotUpdateList();
930 
931  return true;
932 }
933 
934 void MythUISearchDialog::SetReturnEvent(QObject *retobject,
935  const QString &resultid)
936 {
937  m_retObject = retobject;
938  m_id = resultid;
939 }
940 
942 {
943  if (!m_itemList->GetItemCurrent())
944  return;
945 
946  QString result = m_itemList->GetValue();
947 
948  emit haveResult(result);
949 
950  if (m_retObject)
951  {
953  result, "");
954  QCoreApplication::postEvent(m_retObject, dce);
955  }
956 
957  Close();
958 }
959 
961 {
962  m_itemList->Reset();
963 
964  for (int x = 0; x < m_list.size(); x++)
965  {
966  QString item = m_list.at(x);
967 
968  if (m_matchAnywhere)
969  {
970  if (!item.contains(m_textEdit->GetText(), Qt::CaseInsensitive))
971  continue;
972  }
973  else
974  {
975  if (!item.startsWith(m_textEdit->GetText(), Qt::CaseInsensitive))
976  continue;
977  }
978 
979  // add item to list
980  new MythUIButtonListItem(m_itemList, item, nullptr, false);
981  }
982 
984 
985  if (m_matchesText)
986  m_matchesText->SetText(tr("%n match(es)", "", 0));
987 }
988 
990 
992  const QString &message,
993  int resolutionFlags,
994  QDateTime startTime,
995  int rangeLimit)
996  : MythScreenType(parent, "timepopup"),
997  m_message(message), m_startTime(startTime),
998  m_resolution(resolutionFlags), m_rangeLimit(rangeLimit),
999  m_dateList(nullptr), m_timeList(nullptr), m_retObject(nullptr)
1000 {
1001 }
1002 
1004 {
1005  if (!CopyWindowFromBase("MythTimeInputDialog", this))
1006  return false;
1007 
1008  MythUIText *messageText = nullptr;
1009  MythUIButton *okButton = nullptr;
1010 
1011  bool err = false;
1012  UIUtilE::Assign(this, messageText, "message", &err);
1013  UIUtilE::Assign(this, m_dateList, "dates", &err);
1014  UIUtilE::Assign(this, m_timeList, "times", &err);
1015  UIUtilE::Assign(this, okButton, "ok", &err);
1016 
1017  if (err)
1018  {
1019  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythTimeInputDialog'");
1020  return false;
1021  }
1022 
1023  m_dateList->SetVisible(false);
1024  m_timeList->SetVisible(false);
1025 
1026  MythUIButtonListItem *item;
1027  // Date
1028  if (kNoDate != (m_resolution & 0xF))
1029  {
1030  const QDate startdate(m_startTime.toLocalTime().date());
1031  QDate date(startdate);
1032 
1033  int limit = 0;
1034  if (m_resolution & kFutureDates)
1035  {
1036  limit += m_rangeLimit;
1037  }
1038  if (m_resolution & kPastDates)
1039  {
1040  limit += m_rangeLimit;
1041  date = date.addDays(0-m_rangeLimit);
1042  }
1043 
1044  QString text;
1045  int flags;
1046  bool selected = false;
1047  for (int x = 0; x <= limit; x++)
1048  {
1049  selected = false;
1050  if (m_resolution & kDay)
1051  {
1052  date = date.addDays(1);
1054  if (m_rangeLimit >= 356)
1055  flags |= MythDate::kAddYear;
1056  text = MythDate::toString(date, flags);
1057 
1058  if (date == startdate)
1059  selected = true;
1060  }
1061  else if (m_resolution & kMonth)
1062  {
1063  date = date.addMonths(1);
1064  text = date.toString("MMM yyyy");
1065 
1066  if ((date.month() == startdate.month()) &&
1067  (date.year() == startdate.year()))
1068  selected = true;
1069  }
1070  else if (m_resolution & kYear)
1071  {
1072  date = date.addYears(1);
1073  text = date.toString("yyyy");
1074  if (date.year() == startdate.year())
1075  selected = true;
1076  }
1077 
1078  item = new MythUIButtonListItem(m_dateList, text, nullptr, false);
1079  item->SetData(QVariant(date));
1080 
1081  if (selected)
1082  m_dateList->SetItemCurrent(item);
1083  }
1084  m_dateList->SetVisible(true);
1085  }
1086 
1087  // Time
1088  if (kNoTime != (m_resolution & 0xF0))
1089  {
1090  QDate startdate(m_startTime.toLocalTime().date());
1091  QTime starttime(m_startTime.toLocalTime().time());
1092  QTime time(0,0,0);
1093  QString text;
1094  bool selected = false;
1095 
1096  int limit = (m_resolution & kMinutes) ? (60 * 24) : 24;
1097 
1098  for (int x = 0; x < limit; x++)
1099  {
1100  selected = false;
1101  if (m_resolution & kMinutes)
1102  {
1103  time = time.addSecs(60);
1104  QDateTime dt = QDateTime(startdate, time, Qt::LocalTime);
1105  text = MythDate::toString(dt, MythDate::kTime);
1106 
1107  if (time == starttime)
1108  selected = true;
1109  }
1110  else if (m_resolution & kHours)
1111  {
1112  time = time.addSecs(60*60);
1113  text = time.toString("hh:00");
1114 
1115  if (time.hour() == starttime.hour())
1116  selected = true;
1117  }
1118 
1119  item = new MythUIButtonListItem(m_timeList, text, nullptr, false);
1120  item->SetData(QVariant(time));
1121 
1122  if (selected)
1123  m_timeList->SetItemCurrent(item);
1124  }
1125  m_timeList->SetVisible(true);
1126  }
1127 
1128  if (messageText && !m_message.isEmpty())
1129  messageText->SetText(m_message);
1130 
1131  connect(okButton, SIGNAL(Clicked()), SLOT(okClicked()));
1132 
1133  BuildFocusList();
1134 
1135  return true;
1136 }
1137 
1138 void MythTimeInputDialog::SetReturnEvent(QObject* retobject,
1139  const QString& resultid)
1140 {
1141  m_retObject = retobject;
1142  m_id = resultid;
1143 }
1144 
1146 {
1147  QDate date = m_dateList->GetDataValue().toDate();
1148  QTime time = m_timeList->GetDataValue().toTime();
1149 
1150  QDateTime dateTime = QDateTime(date, time, Qt::LocalTime).toUTC();
1151 
1152  emit haveResult(dateTime);
1153 
1154  if (m_retObject)
1155  {
1156  QVariant data(dateTime);
1158  data);
1159  QCoreApplication::postEvent(m_retObject, dce);
1160  }
1161 
1162  Close();
1163 }
void haveResult(QString)
InputFilter m_filter
MythUIText * m_titleText
MythConfirmationDialog(MythScreenStack *parent, const QString &message, bool showCancel=true)
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
void SetMessage(const QString &message)
MythUIText * m_textarea
void AddSelection(QString label, int value)
Dialog asking for user confirmation.
void haveResult(QString)
MythMenu * m_menu
void SetBackAction(const QString &text, QVariant data)
MythTextInputDialog(MythScreenStack *parent, const QString &message, InputFilter filter=FilterNone, bool isPassword=false, const QString &defaultValue="")
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:30
void SetRedraw(void)
Definition: mythuitype.cpp:318
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:168
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:25
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
InputFilter
QString Text
Definition: mythdialogbox.h:72
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)
MythDialogBox(const QString &text, MythScreenStack *parent, const char *name, bool fullscreen=false, bool osd=false)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
QString m_exittext
void haveResult(QString)
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:85
~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)
MythTimeInputDialog(MythScreenStack *parent, const QString &message, int resolutionFlags, QDateTime startTime=QDateTime::currentDateTime(), int dayLimit=14)
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)
A custom event that represents a mouse gesture.
Definition: mythgesture.h:39
const char * name
Definition: ParseText.cpp:339
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
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
QVariant Data
Definition: mythdialogbox.h:73
bool Create(void) override
void SetSelectedByData(QVariant data)
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.
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
void SendEvent(int res, QString text="", QVariant data=0)
MythUIButtonListItem * GetItemCurrent() const
bool Create(void) override
MythUITextEdit * m_textEdit
MythMenu * SubMenu
Definition: mythdialogbox.h:75