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 
24 ScreenWizard::ScreenWizard(MythScreenStack *parent, const char *name) :
25  MythScreenType(parent, name),
26  m_xSize(GetMythMainWindow()->GetUIScreenRect().width()),
27  m_ySize(GetMythMainWindow()->GetUIScreenRect().height())
28 {
29 }
30 
31 void ScreenWizard::SetInitialSettings(int _x, int _y, int _w, int _h)
32 {
33  m_xOffset = _x;
34  m_yOffset = _y;
35 
36  m_screenWidth = _w ? _w : m_xSize;
37  m_screenHeight = _h ? _h : m_ySize;
38 }
39 
41 {
42  // Load the theme for this screen
43  bool foundtheme = LoadWindowFromXML("appear-ui.xml", "appearance", this);
44  if (!foundtheme)
45  return false;
46 
47  m_blackout = dynamic_cast<MythUIShape *> (GetChild("blackout"));
48  m_preview = dynamic_cast<MythUIImage *> (GetChild("preview"));
49  m_size = dynamic_cast<MythUIText *> (GetChild("size"));
50  m_offsets = dynamic_cast<MythUIText *> (GetChild("offsets"));
51  m_changeAmount = dynamic_cast<MythUIText *> (GetChild("changeamount"));
52 
53  if (!m_blackout || !m_preview || !m_size || !m_offsets || !m_changeAmount)
54  {
55  LOG(VB_GENERAL, LOG_ERR, "ScreenWizard, Error: "
56  "Could not instantiate, please check appear-ui.xml for errors");
57  return false;
58  }
59 
61 
62  // work out origin co-ordinates for preview corners
67 
68  updateScreen();
69 
70  return true;
71 }
72 
73 bool ScreenWizard::keyPressEvent(QKeyEvent *event)
74 {
75  if (GetFocusWidget() && GetFocusWidget()->keyPressEvent(event))
76  return true;
77 
78  QStringList actions;
79  bool handled = GetMythMainWindow()->TranslateKeyPress("Global", event, actions);
80 
81  for (int i = 0; i < actions.size() && !handled; i++)
82  {
83  QString action = actions[i];
84  handled = true;
85  bool refresh = false;
86 
87  if (action == "SELECT")
88  {
90  refresh = true;
91  }
92  else if (action == "UP")
93  {
94  if (m_whichCorner)
95  refresh = moveTLUp();
96  else
97  refresh = moveBRUp();
98  }
99  else if (action == "DOWN")
100  {
101  if (m_whichCorner)
102  refresh = moveTLDown();
103  else
104  refresh = moveBRDown();
105  }
106  else if (action == "LEFT")
107  {
108  if (m_whichCorner)
109  refresh = moveTLLeft();
110  else
111  refresh = moveBRLeft();
112  }
113  else if (action == "RIGHT")
114  {
115  if (m_whichCorner)
116  refresh = moveTLRight();
117  else
118  refresh = moveBRRight();
119  }
120  else if (action == "MENU")
121  doMenu();
122  else if (action == "ESCAPE")
123  {
124  if (anythingChanged())
125  doExit();
126  else
127  qApp->quit();
128  }
129  else
130  handled = false;
131 
132  if (refresh)
133  updateScreen();
134  }
135 
136  if (!handled && MythScreenType::keyPressEvent(event))
137  handled = true;
138 
139  return handled;
140 }
141 
143 {
144  if (m_topLeftY < (0 + m_change))
145  return false;
146 
147  m_topLeftY -= m_change;
148  return true;
149 }
150 
152 {
154  if (!moveBRDown())
155  return false;
156 
157  m_topLeftY += m_change;
158  return true;
159 }
160 
162 {
163  if (m_topLeftX < (0 + m_change))
164  return false;
165 
166  m_topLeftX -= m_change;
167  return true;
168 }
169 
171 {
173  if (!moveBRRight())
174  return false;
175 
176  m_topLeftX += m_change;
177  return true;
178 }
179 
181 {
183  if (!moveTLUp())
184  return false;
185 
187  return true;
188 }
189 
191 {
192  if (m_bottomRightY > (m_ySize - m_change))
193  return false;
194 
196  return true;
197 }
198 
200 {
202  if (!moveTLLeft())
203  return false;
204 
206  return true;
207 }
208 
210 {
211  if (m_bottomRightX > (m_xSize - m_change))
212  return false;
213 
215  return true;
216 }
217 
219 {
220  int width = m_bottomRightX - m_topLeftX;
221  int height = m_bottomRightY - m_topLeftY;
222 
223  m_preview->SetArea(MythRect(m_topLeftX, m_topLeftY, width, height));
224  m_size->SetText(tr("Size: %1 x %2").arg(width).arg(height));
225  m_offsets->SetText(tr("Offset: %1 x %2").arg(m_topLeftX).arg(m_topLeftY));
226  m_changeAmount->SetText(tr("Change amount: %n pixel(s)", "", m_change));
227 
228 }
229 
231 {
232  if (m_menuPopup)
233  return;
234 
235  QString label = tr("Options");
236 
237  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
238 
239  m_menuPopup = new MythDialogBox(label, popupStack, "menuPopup");
240 
241  if (m_menuPopup->Create())
242  {
243  if (anythingChanged())
244  {
245  m_menuPopup->SetReturnEvent(this, "save");
246  m_menuPopup->AddButton(tr("Save and Quit"));
247  }
248  else
249  m_menuPopup->SetReturnEvent(this, "nosave");
250 
251  m_menuPopup->AddButton(tr("Reset Changes and Quit"));
252  m_menuPopup->AddButton(tr("Coarse/Fine adjustment"));
253  m_menuPopup->AddButton(tr("Close Menu"));
254 
255  popupStack->AddScreen(m_menuPopup);
256  }
257  else
258  {
259  delete m_menuPopup;
260  }
261 }
262 
264 {
265  if (m_menuPopup)
266  return;
267 
268  QString label = tr("Exit Options");
269 
270  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
271 
272  m_menuPopup = new MythDialogBox(label, popupStack, "menuPopup");
273 
274  if (m_menuPopup->Create())
275  {
276  m_menuPopup->SetReturnEvent(this, "quit");
277  m_menuPopup->AddButton(tr("Save and Quit"));
278  m_menuPopup->AddButton(tr("Discard and Quit"));
279  m_menuPopup->AddButton(tr("Reset and Quit"));
280  m_menuPopup->AddButton(tr("Close Menu"));
281 
282  popupStack->AddScreen(m_menuPopup);
283  }
284  else
285  {
286  delete m_menuPopup;
287  }
288 }
289 
291 {
292  if (m_coarseFine)
293  {
294  m_coarseFine = false;
295  m_change = m_fine;
296  }
297  else
298  {
299  m_coarseFine = true;
300  m_change = m_coarse;
301  }
302 
303  updateScreen();
304 }
305 
307 {
308  LOG(VB_GENERAL, LOG_ERR, "Updating screen size settings");
309  gCoreContext->SaveSetting("GuiOffsetX", m_topLeftX);
310  gCoreContext->SaveSetting("GuiOffsetY", m_topLeftY);
313  qApp->quit();
314 }
315 
317 {
318  gCoreContext->SaveSetting("GuiOffsetX", 0);
319  gCoreContext->SaveSetting("GuiOffsetY", 0);
320  gCoreContext->SaveSetting("GuiWidth", 0);
321  gCoreContext->SaveSetting("GuiHeight", 0);
322  qApp->quit();
323 }
324 
326 {
328  return true;
329  if (m_xOffset != m_topLeftX)
330  return true;
332  return true;
333  if (m_yOffset != m_topLeftY)
334  return true;
335  return false;
336 }
337 
338 void ScreenWizard::customEvent(QEvent *event)
339 {
340 
341  if (event->type() == DialogCompletionEvent::kEventType)
342  {
343  auto *dce = (DialogCompletionEvent*)(event);
344 
345  QString resultid = dce->GetId();
346  int buttonnum = dce->GetResult();
347 
348  if (resultid == "save")
349  {
350  if (buttonnum == 0)
352  else if (buttonnum == 1)
354  else if (buttonnum == 2)
356  }
357  else if (resultid == "nosave")
358  {
359  if (buttonnum == 0)
361  if (buttonnum == 1)
363  }
364  else if (resultid == "quit")
365  {
366  if (buttonnum == 0)
368  if (buttonnum == 1)
369  qApp->quit();
370  if (buttonnum == 2)
372  }
373 
374  m_menuPopup = nullptr;
375  }
376 
377 }
bool Create(void) override
bool m_coarseFine
Definition: screenwizard.h:35
bool moveTLDown(void)
void customEvent(QEvent *event) override
bool moveTLLeft(void)
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:135
#define kMinWidth
MythScreenStack * GetStack(const QString &stackname)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
int m_bottomRightX
Definition: screenwizard.h:42
int m_bottomRightY
Definition: screenwizard.h:43
static Type kEventType
Definition: mythdialogbox.h:56
int m_screenHeight
Definition: screenwizard.h:45
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)
bool m_whichCorner
Definition: screenwizard.h:34
MythUIText * m_offsets
Definition: screenwizard.h:57
void slotChangeCoarseFine()
Wrapper around QRect allowing us to handle percentage and other relative values for areas in mythui.
Definition: mythrect.h:17
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)
MythUIText * m_changeAmount
Definition: screenwizard.h:58
MythUIImage * m_preview
Definition: screenwizard.h:55
virtual void SetArea(const MythRect &rect)
Definition: mythuitype.cpp:589
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
void SetReturnEvent(QObject *retobject, const QString &resultid)
bool moveBRUp(void)
void updateScreen()
bool anythingChanged()
MythUIShape * m_blackout
Definition: screenwizard.h:54
static void slotResetSettings()
Screen in which all other widgets are contained and rendered.
bool moveTLUp(void)
Event dispatched from MythUI modal dialogs to a listening class containing a result of some form.
Definition: mythdialogbox.h:41
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:130
bool Create(void) override
#define kMinHeight