MythTV  master
mythdialogs.cpp
Go to the documentation of this file.
1 
2 #include <iostream>
3 #include <algorithm>
4 using namespace std;
5 
6 #include <QApplication>
7 #include <QCursor>
8 #include <QDialog>
9 #include <QDir>
10 #include <QLayout>
11 #include <QRegExp>
12 #include <QPixmap>
13 #include <QKeyEvent>
14 #include <QFrame>
15 #include <QPaintEvent>
16 #include <QPainter>
17 #include <QProgressBar>
18 #include <QAbstractButton>
19 
20 #ifdef QWS
21 #include <qwindowsystem_qws.h>
22 #endif
23 
24 #include "mythdialogs.h"
25 #include "lcddevice.h"
26 #include "mythdbcon.h"
27 #include "mythfontproperties.h"
28 #include "mythuihelper.h"
29 #include "mythlogging.h"
30 #include "mythcorecontext.h"
31 #include "mythmainwindow.h"
32 
33 #ifdef _WIN32
34 #undef LoadImage
35 #endif
36 
37 static bool inline IsEGLFS()
38 {
39  return qApp->platformName().contains("egl");
40 }
41 
46 MythDialog::MythDialog(MythMainWindow *parent, const char *name, bool setsize)
47  : QFrame(IsEGLFS() ? nullptr : parent)
48 {
49  setObjectName(name);
50  if (!parent)
51  {
52  LOG(VB_GENERAL, LOG_ALERT,
53  "Trying to create a dialog without a parent.");
54  return;
55  }
56 
57  MythUIHelper *ui = GetMythUI();
58 
61 
65 
66  setFont(m_defaultMediumFont);
67 
68  if (setsize)
69  {
70  move(0, 0);
71  setFixedSize(QSize(m_screenwidth, m_screenheight));
72  }
73 
74  setAutoFillBackground(true);
75 
76  parent->attach(this);
77  m_parent = parent;
78 }
79 
81 {
82  TeardownAll();
83 }
84 
86 {
87  hide();
88  TeardownAll();
89  QFrame::deleteLater();
90 }
91 
93 {
94  if (m_parent)
95  {
96  m_parent->detach(this);
97  m_parent = nullptr;
98  }
99 }
100 
102 {
103 }
104 
106 {
107  return false;
108 }
109 
110 
111 
113 {
114  show();
115 }
116 
118 {
119  if ((r < kDialogCodeRejected) ||
121  {
122  LOG(VB_GENERAL, LOG_ALERT,
123  QString("MythDialog::setResult(%1) "
124  "called with invalid DialogCode").arg(r));
125  }
126 
127  m_rescode = r;
128 }
129 
131 {
132  hide();
134  close();
135 }
136 
138 {
139  if (i < 0)
140  {
141  LOG(VB_GENERAL, LOG_ALERT,
142  QString("MythDialog::AcceptItem(%1) "
143  "called with negative index").arg(i));
144  reject();
145  return;
146  }
147 
148  done((DialogCode)((int)kDialogCodeListStart + i));
149 }
150 
152 {
153  return (int)code - (int)kDialogCodeListStart;
154 }
155 
157 {
158  done(Accepted);
159 }
160 
162 {
163  done(Rejected);
164 }
165 
167 {
168  if (m_in_loop)
169  {
170  LOG(VB_GENERAL, LOG_ALERT,
171  "MythDialog::exec: Recursive call detected.");
172  return kDialogCodeRejected;
173  }
174 
176 
177  Show();
178 
179  m_in_loop = true;
180 
181  QEventLoop eventLoop;
182  connect(this, SIGNAL(leaveModality()), &eventLoop, SLOT(quit()));
183  eventLoop.exec();
184 
185  DialogCode res = result();
186 
187  return res;
188 }
189 
191 {
192  if (isHidden())
193  return;
194 
195  // Reimplemented to exit a modal when the dialog is hidden.
196  QWidget::hide();
197  if (m_in_loop)
198  {
199  m_in_loop = false;
200  emit leaveModality();
201  }
202 }
203 
204 void MythDialog::keyPressEvent( QKeyEvent *e )
205 {
206  bool handled = false;
207  QStringList actions;
208 
209  handled = GetMythMainWindow()->TranslateKeyPress("qt", e, actions);
210 
211  for (int i = 0; i < actions.size() && !handled; i++)
212  {
213  QString action = actions[i];
214  handled = true;
215 
216  if (action == "ESCAPE")
217  reject();
218  else if (action == "UP" || action == "LEFT")
219  {
220  if (focusWidget() &&
221  (focusWidget()->focusPolicy() == Qt::StrongFocus ||
222  focusWidget()->focusPolicy() == Qt::WheelFocus))
223  {
224  }
225  else
226  focusNextPrevChild(false);
227  }
228  else if (action == "DOWN" || action == "RIGHT")
229  {
230  if (focusWidget() &&
231  (focusWidget()->focusPolicy() == Qt::StrongFocus ||
232  focusWidget()->focusPolicy() == Qt::WheelFocus))
233  {
234  }
235  else
236  focusNextPrevChild(true);
237  }
238  else if (action == "MENU")
239  emit menuButtonPressed();
240  else
241  handled = false;
242  }
243 }
virtual bool onMediaEvent(MythMediaDevice *mediadevice)
int m_screenwidth
Definition: mythdialogs.h:92
bool TranslateKeyPress(const QString &context, QKeyEvent *e, QStringList &actions, bool allowJumps=true)
Get a list of actions for a keypress in the given context.
QFont GetMediumFont(void)
static int CalcItemIndex(DialogCode code)
DialogCode m_rescode
Definition: mythdialogs.h:99
MythDialog(MythMainWindow *parent, const char *name="MythDialog", bool setsize=true)
Definition: mythdialogs.cpp:46
void setResult(DialogCode r)
bool m_in_loop
Definition: mythdialogs.h:101
void setNoErase(void)
QFont GetSmallFont(void)
DialogCode result(void) const
Definition: mythdialogs.h:53
static bool IsEGLFS()
Definition: mythdialogs.cpp:37
int m_screenheight
Definition: mythdialogs.h:93
static const DialogCode Accepted
Definition: mythdialogs.h:50
unsigned char r
Definition: ParseText.cpp:329
QFont m_defaultMediumFont
Definition: mythdialogs.h:103
float m_dlghmult
Definition: mythdialogs.h:91
void TeardownAll(void)
Definition: mythdialogs.cpp:92
DialogCode
Definition: mythdialogs.h:21
#define close
Definition: compat.h:16
static void show(uint8_t *buf, int length)
Definition: ringbuffer.c:335
void menuButtonPressed()
virtual void deleteLater(void)
Definition: mythdialogs.cpp:85
virtual void reject()
virtual void done(int)
virtual void accept()
const char * name
Definition: ParseText.cpp:328
QFont GetBigFont(void)
DialogCode exec(void)
MythUIHelper * GetMythUI()
MythMainWindow * GetMythMainWindow(void)
QFont m_defaultBigFont
Definition: mythdialogs.h:103
virtual void AcceptItem(int)
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
float m_dlgwmult
Definition: mythdialogs.h:90
QFont m_defaultSmallFont
Definition: mythdialogs.h:103
void hide(void)
void detach(QWidget *child)
void leaveModality()
void keyPressEvent(QKeyEvent *e) override
virtual void Show(void)
void attach(QWidget *child)
MythMainWindow * m_parent
Definition: mythdialogs.h:97
void GetScreenSettings(float &wmult, float &hmult)
static const DialogCode Rejected
Definition: mythdialogs.h:49