MythTV  master
screenwizard.cpp
Go to the documentation of this file.
1 // Qt
2 #include <QBrush>
3 #include <QColor>
4 #include <QCoreApplication>
5 #include <QString>
6 #include <QStringList>
7 
8 // MythTV
12 #include "libmythui/mythrect.h"
13 #include "libmythui/mythuihelper.h"
14 #include "libmythui/themeinfo.h"
15 
16 // MythScreenWizard
17 #include "screenwizard.h"
18 
19 static constexpr int kMinWidth { 160 };
20 static constexpr int kMinHeight { 160 };
21 
22 ScreenWizard::ScreenWizard(MythScreenStack *parent, const char *name) :
23  MythScreenType(parent, name),
24  m_xSize(GetMythMainWindow()->GetUIScreenRect().width()),
25  m_ySize(GetMythMainWindow()->GetUIScreenRect().height())
26 {
27 }
28 
29 void ScreenWizard::SetInitialSettings(int _x, int _y, int _w, int _h)
30 {
31  m_xOffset = _x;
32  m_yOffset = _y;
33 
34  m_screenWidth = _w ? _w : m_xSize;
35  m_screenHeight = _h ? _h : m_ySize;
36 }
37 
39 {
40  // Load the theme for this screen
41  bool foundtheme = LoadWindowFromXML("appear-ui.xml", "appearance", this);
42  if (!foundtheme)
43  return false;
44 
45  m_blackout = dynamic_cast<MythUIShape *> (GetChild("blackout"));
46  m_preview = dynamic_cast<MythUIImage *> (GetChild("preview"));
47  m_size = dynamic_cast<MythUIText *> (GetChild("size"));
48  m_offsets = dynamic_cast<MythUIText *> (GetChild("offsets"));
49  m_changeAmount = dynamic_cast<MythUIText *> (GetChild("changeamount"));
50 
51  if (!m_blackout || !m_preview || !m_size || !m_offsets || !m_changeAmount)
52  {
53  LOG(VB_GENERAL, LOG_ERR, "ScreenWizard, Error: "
54  "Could not instantiate, please check appear-ui.xml for errors");
55  return false;
56  }
57 
59 
60  // work out origin co-ordinates for preview corners
65 
66  updateScreen();
67 
68  return true;
69 }
70 
71 bool ScreenWizard::keyPressEvent(QKeyEvent *event)
72 {
73  if (GetFocusWidget() && GetFocusWidget()->keyPressEvent(event))
74  return true;
75 
76  QStringList actions;
77  bool handled = GetMythMainWindow()->TranslateKeyPress("Global", event, actions);
78 
79  for (int i = 0; i < actions.size() && !handled; i++)
80  {
81  const QString& action = actions[i];
82  handled = true;
83  bool refresh = false;
84 
85  if (action == "SELECT")
86  {
88  refresh = true;
89  }
90  else if (action == "UP")
91  {
92  if (m_whichCorner)
93  refresh = moveTLUp();
94  else
95  refresh = moveBRUp();
96  }
97  else if (action == "DOWN")
98  {
99  if (m_whichCorner)
100  refresh = moveTLDown();
101  else
102  refresh = moveBRDown();
103  }
104  else if (action == "LEFT")
105  {
106  if (m_whichCorner)
107  refresh = moveTLLeft();
108  else
109  refresh = moveBRLeft();
110  }
111  else if (action == "RIGHT")
112  {
113  if (m_whichCorner)
114  refresh = moveTLRight();
115  else
116  refresh = moveBRRight();
117  }
118  else if (action == "MENU")
119  {
120  doMenu();
121  }
122  else if (action == "ESCAPE")
123  {
124  if (anythingChanged())
125  doExit();
126  else
127  qApp->quit();
128  }
129  else
130  {
131  handled = false;
132  }
133 
134  if (refresh)
135  updateScreen();
136  }
137 
138  if (!handled && MythScreenType::keyPressEvent(event))
139  handled = true;
140 
141  return handled;
142 }
143 
145 {
146  if (m_topLeftY < (0 + m_change))
147  return false;
148 
149  m_topLeftY -= m_change;
150  return true;
151 }
152 
154 {
156  if (!moveBRDown())
157  return false;
158 
159  m_topLeftY += m_change;
160  return true;
161 }
162 
164 {
165  if (m_topLeftX < (0 + m_change))
166  return false;
167 
168  m_topLeftX -= m_change;
169  return true;
170 }
171 
173 {
175  if (!moveBRRight())
176  return false;
177 
178  m_topLeftX += m_change;
179  return true;
180 }
181 
183 {
185  if (!moveTLUp())
186  return false;
187 
189  return true;
190 }
191 
193 {
194  if (m_bottomRightY > (m_ySize - m_change))
195  return false;
196 
198  return true;
199 }
200 
202 {
204  if (!moveTLLeft())
205  return false;
206 
208  return true;
209 }
210 
212 {
213  if (m_bottomRightX > (m_xSize - m_change))
214  return false;
215 
217  return true;
218 }
219 
221 {
222  int width = m_bottomRightX - m_topLeftX;
223  int height = m_bottomRightY - m_topLeftY;
224 
225  m_preview->SetArea(MythRect(m_topLeftX, m_topLeftY, width, height));
226  m_size->SetText(tr("Size: %1 x %2").arg(width).arg(height));
227  m_offsets->SetText(tr("Offset: %1 x %2").arg(m_topLeftX).arg(m_topLeftY));
228  m_changeAmount->SetText(tr("Change amount: %n pixel(s)", "", m_change));
229 
230 }
231 
233 {
234  if (m_menuPopup)
235  return;
236 
237  QString label = tr("Options");
238 
239  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
240 
241  m_menuPopup = new MythDialogBox(label, popupStack, "menuPopup");
242 
243  if (m_menuPopup->Create())
244  {
245  if (anythingChanged())
246  {
247  m_menuPopup->SetReturnEvent(this, "save");
248  m_menuPopup->AddButton(tr("Save and Quit"));
249  }
250  else
251  {
252  m_menuPopup->SetReturnEvent(this, "nosave");
253  }
254 
255  m_menuPopup->AddButton(tr("Reset Changes and Quit"));
256  m_menuPopup->AddButton(tr("Coarse/Fine adjustment"));
257  m_menuPopup->AddButton(tr("Close Menu"));
258 
259  popupStack->AddScreen(m_menuPopup);
260  }
261  else
262  {
263  delete m_menuPopup;
264  }
265 }
266 
268 {
269  if (m_menuPopup)
270  return;
271 
272  QString label = tr("Exit Options");
273 
274  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
275 
276  m_menuPopup = new MythDialogBox(label, popupStack, "menuPopup");
277 
278  if (m_menuPopup->Create())
279  {
280  m_menuPopup->SetReturnEvent(this, "quit");
281  m_menuPopup->AddButton(tr("Save and Quit"));
282  m_menuPopup->AddButton(tr("Discard and Quit"));
283  m_menuPopup->AddButton(tr("Reset and Quit"));
284  m_menuPopup->AddButton(tr("Close Menu"));
285 
286  popupStack->AddScreen(m_menuPopup);
287  }
288  else
289  {
290  delete m_menuPopup;
291  }
292 }
293 
295 {
296  if (m_coarseFine)
297  {
298  m_coarseFine = false;
299  m_change = m_fine;
300  }
301  else
302  {
303  m_coarseFine = true;
304  m_change = m_coarse;
305  }
306 
307  updateScreen();
308 }
309 
311 {
312  LOG(VB_GENERAL, LOG_ERR, "Updating screen size settings");
313  gCoreContext->SaveSetting("GuiOffsetX", m_topLeftX);
314  gCoreContext->SaveSetting("GuiOffsetY", m_topLeftY);
317  qApp->quit();
318 }
319 
321 {
322  gCoreContext->SaveSetting("GuiOffsetX", 0);
323  gCoreContext->SaveSetting("GuiOffsetY", 0);
324  gCoreContext->SaveSetting("GuiWidth", 0);
325  gCoreContext->SaveSetting("GuiHeight", 0);
326  qApp->quit();
327 }
328 
330 {
332  return true;
333  if (m_xOffset != m_topLeftX)
334  return true;
336  return true;
337  if (m_yOffset != m_topLeftY)
338  return true;
339  return false;
340 }
341 
342 void ScreenWizard::customEvent(QEvent *event)
343 {
344 
345  if (event->type() == DialogCompletionEvent::kEventType)
346  {
347  auto *dce = (DialogCompletionEvent*)(event);
348 
349  QString resultid = dce->GetId();
350  int buttonnum = dce->GetResult();
351 
352  if (resultid == "save")
353  {
354  if (buttonnum == 0)
356  else if (buttonnum == 1)
358  else if (buttonnum == 2)
360  }
361  else if (resultid == "nosave")
362  {
363  if (buttonnum == 0)
365  if (buttonnum == 1)
367  }
368  else if (resultid == "quit")
369  {
370  if (buttonnum == 0)
372  if (buttonnum == 1)
373  qApp->quit();
374  if (buttonnum == 2)
376  }
377 
378  m_menuPopup = nullptr;
379  }
380 
381 }
ScreenWizard::moveTLLeft
bool moveTLLeft(void)
Definition: screenwizard.cpp:163
mythrect.h
ScreenWizard::m_coarseFine
bool m_coarseFine
Definition: screenwizard.h:37
MythDialogBox::SetReturnEvent
void SetReturnEvent(QObject *retobject, const QString &resultid)
Definition: mythdialogbox.cpp:303
ScreenWizard::doExit
void doExit()
Definition: screenwizard.cpp:267
ScreenWizard::m_menuPopup
MythDialogBox * m_menuPopup
Definition: screenwizard.h:61
ScreenWizard::m_preview
MythUIImage * m_preview
Definition: screenwizard.h:57
ScreenWizard::moveBRLeft
bool moveBRLeft(void)
Definition: screenwizard.cpp:201
MythUIImage
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:97
ScreenWizard::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: screenwizard.cpp:71
ScreenWizard::m_xSize
int m_xSize
Definition: screenwizard.h:48
kMinHeight
static constexpr int kMinHeight
Definition: screenwizard.cpp:20
ScreenWizard::anythingChanged
bool anythingChanged() const
Definition: screenwizard.cpp:329
ScreenWizard::m_offsets
MythUIText * m_offsets
Definition: screenwizard.h:59
MythUIType::GetChild
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:138
ScreenWizard::m_yOffset
int m_yOffset
Definition: screenwizard.h:51
ScreenWizard::m_ySize
int m_ySize
Definition: screenwizard.h:49
MythScreenStack
Definition: mythscreenstack.h:16
MythUIType::SetArea
virtual void SetArea(const MythRect &rect)
Definition: mythuitype.cpp:610
ScreenWizard::moveTLUp
bool moveTLUp(void)
Definition: screenwizard.cpp:144
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythScreenType
Screen in which all other widgets are contained and rendered.
Definition: mythscreentype.h:45
ScreenWizard::m_coarse
int m_coarse
Definition: screenwizard.h:40
MythRect
Wrapper around QRect allowing us to handle percentage and other relative values for areas in mythui.
Definition: mythrect.h:17
ScreenWizard::m_size
MythUIText * m_size
Definition: screenwizard.h:58
ScreenWizard::m_bottomRightX
int m_bottomRightX
Definition: screenwizard.h:44
ScreenWizard::ScreenWizard
ScreenWizard(MythScreenStack *parent, const char *name)
Definition: screenwizard.cpp:22
ScreenWizard::m_bottomRightY
int m_bottomRightY
Definition: screenwizard.h:45
MythScreenType::GetFocusWidget
MythUIType * GetFocusWidget(void) const
Definition: mythscreentype.cpp:111
ScreenWizard::m_screenWidth
int m_screenWidth
Definition: screenwizard.h:46
ScreenWizard::updateScreen
void updateScreen()
Definition: screenwizard.cpp:220
ScreenWizard::slotResetSettings
static void slotResetSettings()
Definition: screenwizard.cpp:320
mythlogging.h
ScreenWizard::m_change
int m_change
Definition: screenwizard.h:41
themeinfo.h
ScreenWizard::m_whichCorner
bool m_whichCorner
Definition: screenwizard.h:36
MythMainWindow::TranslateKeyPress
bool TranslateKeyPress(const QString &Context, QKeyEvent *Event, QStringList &Actions, bool AllowJumps=true)
Get a list of actions for a keypress in the given context.
Definition: mythmainwindow.cpp:1111
ScreenWizard::m_screenHeight
int m_screenHeight
Definition: screenwizard.h:47
MythDialogBox::AddButton
void AddButton(const QString &title)
Definition: mythdialogbox.h:197
MythDialogBox
Basic menu dialog, message and a list of options.
Definition: mythdialogbox.h:165
ScreenWizard::doMenu
void doMenu()
Definition: screenwizard.cpp:232
MythDialogBox::Create
bool Create(void) override
Definition: mythdialogbox.cpp:127
ScreenWizard::m_blackout
MythUIShape * m_blackout
Definition: screenwizard.h:56
ScreenWizard::m_topLeftX
int m_topLeftX
Definition: screenwizard.h:42
ScreenWizard::Create
bool Create(void) override
Definition: screenwizard.cpp:38
ScreenWizard::moveTLDown
bool moveTLDown(void)
Definition: screenwizard.cpp:153
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:57
ScreenWizard::m_topLeftY
int m_topLeftY
Definition: screenwizard.h:43
kMinWidth
static constexpr int kMinWidth
Definition: screenwizard.cpp:19
ScreenWizard::SetInitialSettings
void SetInitialSettings(int _x, int _y, int _w, int _h)
Definition: screenwizard.cpp:29
MythUIShape
A widget for rendering primitive shapes and lines.
Definition: mythuishape.h:21
mythuihelper.h
ScreenWizard::slotChangeCoarseFine
void slotChangeCoarseFine()
Definition: screenwizard.cpp:294
MythUIText
All purpose text widget, displays a text string.
Definition: mythuitext.h:28
MythScreenType::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: mythscreentype.cpp:402
mythcorecontext.h
XMLParseBase::LoadWindowFromXML
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
Definition: xmlparsebase.cpp:701
ScreenWizard::moveBRDown
bool moveBRDown(void)
Definition: screenwizard.cpp:192
ScreenWizard::m_xOffset
int m_xOffset
Definition: screenwizard.h:50
DialogCompletionEvent
Event dispatched from MythUI modal dialogs to a listening class containing a result of some form.
Definition: mythdialogbox.h:40
MythUIText::SetText
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:115
ScreenWizard::moveBRUp
bool moveBRUp(void)
Definition: screenwizard.cpp:182
ScreenWizard::moveTLRight
bool moveTLRight(void)
Definition: screenwizard.cpp:172
DialogCompletionEvent::kEventType
static const Type kEventType
Definition: mythdialogbox.h:56
ScreenWizard::m_fine
int m_fine
Definition: screenwizard.h:39
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:104
build_compdb.action
action
Definition: build_compdb.py:9
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &Stackname)
Definition: mythmainwindow.cpp:322
screenwizard.h
MythCoreContext::SaveSetting
void SaveSetting(const QString &key, int newValue)
Definition: mythcorecontext.cpp:887
ScreenWizard::customEvent
void customEvent(QEvent *event) override
Definition: screenwizard.cpp:342
ScreenWizard::slotSaveSettings
void slotSaveSettings() const
Definition: screenwizard.cpp:310
mythmainwindow.h
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:52
ScreenWizard::m_changeAmount
MythUIText * m_changeAmount
Definition: screenwizard.h:60
ScreenWizard::moveBRRight
bool moveBRRight(void)
Definition: screenwizard.cpp:211