MythTV  master
screenwizard.cpp
Go to the documentation of this file.
1 
2 #include "screenwizard.h"
3 
4 /* QT includes */
5 #include <QStringList>
6 #include <QCoreApplication>
7 #include <QString>
8 #include <QBrush>
9 #include <QColor>
10 
11 /* MythTV includes */
12 #include "mythcorecontext.h"
13 #include "mythmainwindow.h"
14 #include "mythuihelper.h"
15 #include "mythlogging.h"
16 #include "themeinfo.h"
17 #include "mythrect.h"
18 
19 using namespace std;
20 
21 #define kMinWidth 160
22 #define kMinHeight 160
23 
25  MythScreenType(parent, name),
26  m_whichcorner(true),
27  m_coarsefine(false), // fine adjustments by default
28  m_changed(false),
29  m_fine(1), // fine moves corners by one pixel
30  m_coarse(10), // coarse moves corners by ten pixels
31  m_change(m_fine),
32  m_topleft_x(0), m_topleft_y(0),
33  m_bottomright_x(0), m_bottomright_y(0),
34  m_screenwidth(0), m_screenheight(0),
35  m_xsize(GetMythMainWindow()->GetUIScreenRect().width()),
36  m_ysize(GetMythMainWindow()->GetUIScreenRect().height()),
37  m_xoffset(0), m_yoffset(0),
38  m_blackout(nullptr), m_preview(nullptr),
39  m_size(nullptr), m_offsets(nullptr),
40  m_changeamount(nullptr), m_menuPopup(nullptr)
41 {
42 }
43 
44 void ScreenWizard::SetInitialSettings(int _x, int _y, int _w, int _h)
45 {
46  m_xoffset = _x;
47  m_yoffset = _y;
48 
49  m_screenwidth = _w ? _w : m_xsize;
50  m_screenheight = _h ? _h : m_ysize;
51 }
52 
54 {
55  // Load the theme for this screen
56  bool foundtheme = LoadWindowFromXML("appear-ui.xml", "appearance", this);
57  if (!foundtheme)
58  return false;
59 
60  m_blackout = dynamic_cast<MythUIShape *> (GetChild("blackout"));
61  m_preview = dynamic_cast<MythUIImage *> (GetChild("preview"));
62  m_size = dynamic_cast<MythUIText *> (GetChild("size"));
63  m_offsets = dynamic_cast<MythUIText *> (GetChild("offsets"));
64  m_changeamount = dynamic_cast<MythUIText *> (GetChild("changeamount"));
65 
66  if (!m_blackout || !m_preview || !m_size || !m_offsets || !m_changeamount)
67  {
68  LOG(VB_GENERAL, LOG_ERR, "ScreenWizard, Error: "
69  "Could not instantiate, please check appear-ui.xml for errors");
70  return false;
71  }
72 
74 
75  // work out origin co-ordinates for preview corners
80 
81  updateScreen();
82 
83  return true;
84 }
85 
86 bool ScreenWizard::keyPressEvent(QKeyEvent *event)
87 {
88  if (GetFocusWidget() && GetFocusWidget()->keyPressEvent(event))
89  return true;
90 
91  QStringList actions;
92  bool handled = GetMythMainWindow()->TranslateKeyPress("Global", event, actions);
93 
94  for (int i = 0; i < actions.size() && !handled; i++)
95  {
96  QString action = actions[i];
97  handled = true;
98  bool refresh = false;
99 
100  if (action == "SELECT")
101  {
103  refresh = true;
104  }
105  else if (action == "UP")
106  {
107  if (m_whichcorner)
108  refresh = moveTLUp();
109  else
110  refresh = moveBRUp();
111  }
112  else if (action == "DOWN")
113  {
114  if (m_whichcorner)
115  refresh = moveTLDown();
116  else
117  refresh = moveBRDown();
118  }
119  else if (action == "LEFT")
120  {
121  if (m_whichcorner)
122  refresh = moveTLLeft();
123  else
124  refresh = moveBRLeft();
125  }
126  else if (action == "RIGHT")
127  {
128  if (m_whichcorner)
129  refresh = moveTLRight();
130  else
131  refresh = moveBRRight();
132  }
133  else if (action == "MENU")
134  doMenu();
135  else if (action == "ESCAPE")
136  {
137  if (anythingChanged())
138  doExit();
139  else
140  qApp->quit();
141  }
142  else
143  handled = false;
144 
145  if (refresh)
146  updateScreen();
147  }
148 
149  if (!handled && MythScreenType::keyPressEvent(event))
150  handled = true;
151 
152  return handled;
153 }
154 
156 {
157  if (m_topleft_y < (0 + m_change))
158  return false;
159 
161  return true;
162 }
163 
165 {
167  if (!moveBRDown())
168  return false;
169 
171  return true;
172 }
173 
175 {
176  if (m_topleft_x < (0 + m_change))
177  return false;
178 
180  return true;
181 }
182 
184 {
186  if (!moveBRRight())
187  return false;
188 
190  return true;
191 }
192 
194 {
196  if (!moveTLUp())
197  return false;
198 
200  return true;
201 }
202 
204 {
205  if (m_bottomright_y > (m_ysize - m_change))
206  return false;
207 
209  return true;
210 }
211 
213 {
215  if (!moveTLLeft())
216  return false;
217 
219  return true;
220 }
221 
223 {
224  if (m_bottomright_x > (m_xsize - m_change))
225  return false;
226 
228  return true;
229 }
230 
232 {
233  int width = m_bottomright_x - m_topleft_x;
234  int height = m_bottomright_y - m_topleft_y;
235 
236  m_preview->SetArea(MythRect(m_topleft_x, m_topleft_y, width, height));
237  m_size->SetText(tr("Size: %1 x %2").arg(width).arg(height));
238  m_offsets->SetText(tr("Offset: %1 x %2").arg(m_topleft_x).arg(m_topleft_y));
239  m_changeamount->SetText(tr("Change amount: %n pixel(s)", "", m_change));
240 
241 }
242 
244 {
245  if (m_menuPopup)
246  return;
247 
248  QString label = tr("Options");
249 
250  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
251 
252  m_menuPopup = new MythDialogBox(label, popupStack, "menuPopup");
253 
254  if (m_menuPopup->Create())
255  {
256  if (anythingChanged())
257  {
258  m_menuPopup->SetReturnEvent(this, "save");
259  m_menuPopup->AddButton(tr("Save and Quit"));
260  }
261  else
262  m_menuPopup->SetReturnEvent(this, "nosave");
263 
264  m_menuPopup->AddButton(tr("Reset Changes and Quit"));
265  m_menuPopup->AddButton(tr("Coarse/Fine adjustment"));
266  m_menuPopup->AddButton(tr("Close Menu"));
267 
268  popupStack->AddScreen(m_menuPopup);
269  }
270  else
271  {
272  delete m_menuPopup;
273  }
274 }
275 
277 {
278  if (m_menuPopup)
279  return;
280 
281  QString label = tr("Exit Options");
282 
283  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
284 
285  m_menuPopup = new MythDialogBox(label, popupStack, "menuPopup");
286 
287  if (m_menuPopup->Create())
288  {
289  m_menuPopup->SetReturnEvent(this, "quit");
290  m_menuPopup->AddButton(tr("Save and Quit"));
291  m_menuPopup->AddButton(tr("Discard and Quit"));
292  m_menuPopup->AddButton(tr("Reset and Quit"));
293  m_menuPopup->AddButton(tr("Close Menu"));
294 
295  popupStack->AddScreen(m_menuPopup);
296  }
297  else
298  {
299  delete m_menuPopup;
300  }
301 }
302 
304 {
305  if (m_coarsefine)
306  {
307  m_coarsefine = false;
308  m_change = m_fine;
309  }
310  else
311  {
312  m_coarsefine = true;
313  m_change = m_coarse;
314  }
315 
316  updateScreen();
317 }
318 
320 {
321  LOG(VB_GENERAL, LOG_ERR, "Updating screen size settings");
322  gCoreContext->SaveSetting("GuiOffsetX", m_topleft_x);
323  gCoreContext->SaveSetting("GuiOffsetY", m_topleft_y);
326  qApp->quit();
327 }
328 
330 {
331  gCoreContext->SaveSetting("GuiOffsetX", 0);
332  gCoreContext->SaveSetting("GuiOffsetY", 0);
333  gCoreContext->SaveSetting("GuiWidth", 0);
334  gCoreContext->SaveSetting("GuiHeight", 0);
335  qApp->quit();
336 }
337 
339 {
341  return true;
342  if (m_xoffset != m_topleft_x)
343  return true;
345  return true;
346  if (m_yoffset != m_topleft_y)
347  return true;
348  return false;
349 }
350 
351 void ScreenWizard::customEvent(QEvent *event)
352 {
353 
354  if (event->type() == DialogCompletionEvent::kEventType)
355  {
357 
358  QString resultid = dce->GetId();
359  int buttonnum = dce->GetResult();
360 
361  if (resultid == "save")
362  {
363  if (buttonnum == 0)
365  else if (buttonnum == 1)
367  else if (buttonnum == 2)
369  }
370  else if (resultid == "nosave")
371  {
372  if (buttonnum == 0)
374  if (buttonnum == 1)
376  }
377  else if (resultid == "quit")
378  {
379  if (buttonnum == 0)
381  if (buttonnum == 1)
382  qApp->quit();
383  if (buttonnum == 2)
385  }
386 
387  m_menuPopup = nullptr;
388  }
389 
390 }
bool Create(void) override
bool moveTLDown(void)
void customEvent(QEvent *event) override
bool moveTLLeft(void)
VERBOSE_PREAMBLE Most true
Definition: verbosedefs.h:91
bool TranslateKeyPress(const QString &context, QKeyEvent *e, QStringList &actions, bool allowJumps=true)
Get a list of actions for a keypress in the given context.
bool moveBRRight(void)
MythDialogBox * m_menuPopup
Definition: screenwizard.h:59
void SaveSetting(const QString &key, int newValue)
Basic menu dialog, message and a list of options.
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:136
MythUIText * m_changeamount
Definition: screenwizard.h:58
#define kMinWidth
MythScreenStack * GetStack(const QString &stackname)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
int m_bottomright_x
Definition: screenwizard.h:42
static Type kEventType
Definition: mythdialogbox.h:50
ScreenWizard(MythScreenStack *parent, const char *name)
void AddButton(const QString &title, QVariant data=0, bool newMenu=false, bool setCurrent=false)
void slotSaveSettings()
bool moveBRDown(void)
bool moveBRLeft(void)
MythUIText * m_size
Definition: screenwizard.h:56
bool moveTLRight(void)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
int m_screenheight
Definition: screenwizard.h:45
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:85
bool m_whichcorner
Definition: screenwizard.h:34
bool m_coarsefine
Definition: screenwizard.h:35
MythUIText * m_offsets
Definition: screenwizard.h:57
void slotChangeCoarseFine()
bool keyPressEvent(QKeyEvent *) override
Key event handler.
Wrapper around QRect allowing us to handle percentage and other relative values for areas in mythui.
Definition: mythrect.h:17
const char * name
Definition: ParseText.cpp:328
void SetInitialSettings(int _x, int _y, int _w, int _h)
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
MythUIType * GetFocusWidget(void) const
MythMainWindow * GetMythMainWindow(void)
MythUIImage * m_preview
Definition: screenwizard.h:55
virtual void SetArea(const MythRect &rect)
Definition: mythuitype.cpp:591
bool keyPressEvent(QKeyEvent *) override
Key event handler.
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
void SetReturnEvent(QObject *retobject, const QString &resultid)
bool moveBRUp(void)
void updateScreen()
bool anythingChanged()
MythUIShape * m_blackout
Definition: screenwizard.h:54
void slotResetSettings()
Screen in which all other widgets are contained and rendered.
int m_bottomright_y
Definition: screenwizard.h:43
bool moveTLUp(void)
Event dispatched from MythUI modal dialogs to a listening class containing a result of some form.
Definition: mythdialogbox.h:37
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:132
bool Create(void) override
#define kMinHeight