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  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  doMenu();
120  else if (action == "ESCAPE")
121  {
122  if (anythingChanged())
123  doExit();
124  else
125  qApp->quit();
126  }
127  else
128  handled = false;
129 
130  if (refresh)
131  updateScreen();
132  }
133 
134  if (!handled && MythScreenType::keyPressEvent(event))
135  handled = true;
136 
137  return handled;
138 }
139 
141 {
142  if (m_topLeftY < (0 + m_change))
143  return false;
144 
145  m_topLeftY -= m_change;
146  return true;
147 }
148 
150 {
152  if (!moveBRDown())
153  return false;
154 
155  m_topLeftY += m_change;
156  return true;
157 }
158 
160 {
161  if (m_topLeftX < (0 + m_change))
162  return false;
163 
164  m_topLeftX -= m_change;
165  return true;
166 }
167 
169 {
171  if (!moveBRRight())
172  return false;
173 
174  m_topLeftX += m_change;
175  return true;
176 }
177 
179 {
181  if (!moveTLUp())
182  return false;
183 
185  return true;
186 }
187 
189 {
190  if (m_bottomRightY > (m_ySize - m_change))
191  return false;
192 
194  return true;
195 }
196 
198 {
200  if (!moveTLLeft())
201  return false;
202 
204  return true;
205 }
206 
208 {
209  if (m_bottomRightX > (m_xSize - m_change))
210  return false;
211 
213  return true;
214 }
215 
217 {
218  int width = m_bottomRightX - m_topLeftX;
219  int height = m_bottomRightY - m_topLeftY;
220 
221  m_preview->SetArea(MythRect(m_topLeftX, m_topLeftY, width, height));
222  m_size->SetText(tr("Size: %1 x %2").arg(width).arg(height));
223  m_offsets->SetText(tr("Offset: %1 x %2").arg(m_topLeftX).arg(m_topLeftY));
224  m_changeAmount->SetText(tr("Change amount: %n pixel(s)", "", m_change));
225 
226 }
227 
229 {
230  if (m_menuPopup)
231  return;
232 
233  QString label = tr("Options");
234 
235  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
236 
237  m_menuPopup = new MythDialogBox(label, popupStack, "menuPopup");
238 
239  if (m_menuPopup->Create())
240  {
241  if (anythingChanged())
242  {
243  m_menuPopup->SetReturnEvent(this, "save");
244  m_menuPopup->AddButton(tr("Save and Quit"));
245  }
246  else
247  m_menuPopup->SetReturnEvent(this, "nosave");
248 
249  m_menuPopup->AddButton(tr("Reset Changes and Quit"));
250  m_menuPopup->AddButton(tr("Coarse/Fine adjustment"));
251  m_menuPopup->AddButton(tr("Close Menu"));
252 
253  popupStack->AddScreen(m_menuPopup);
254  }
255  else
256  {
257  delete m_menuPopup;
258  }
259 }
260 
262 {
263  if (m_menuPopup)
264  return;
265 
266  QString label = tr("Exit Options");
267 
268  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
269 
270  m_menuPopup = new MythDialogBox(label, popupStack, "menuPopup");
271 
272  if (m_menuPopup->Create())
273  {
274  m_menuPopup->SetReturnEvent(this, "quit");
275  m_menuPopup->AddButton(tr("Save and Quit"));
276  m_menuPopup->AddButton(tr("Discard and Quit"));
277  m_menuPopup->AddButton(tr("Reset and Quit"));
278  m_menuPopup->AddButton(tr("Close Menu"));
279 
280  popupStack->AddScreen(m_menuPopup);
281  }
282  else
283  {
284  delete m_menuPopup;
285  }
286 }
287 
289 {
290  if (m_coarseFine)
291  {
292  m_coarseFine = false;
293  m_change = m_fine;
294  }
295  else
296  {
297  m_coarseFine = true;
298  m_change = m_coarse;
299  }
300 
301  updateScreen();
302 }
303 
305 {
306  LOG(VB_GENERAL, LOG_ERR, "Updating screen size settings");
307  gCoreContext->SaveSetting("GuiOffsetX", m_topLeftX);
308  gCoreContext->SaveSetting("GuiOffsetY", m_topLeftY);
311  qApp->quit();
312 }
313 
315 {
316  gCoreContext->SaveSetting("GuiOffsetX", 0);
317  gCoreContext->SaveSetting("GuiOffsetY", 0);
318  gCoreContext->SaveSetting("GuiWidth", 0);
319  gCoreContext->SaveSetting("GuiHeight", 0);
320  qApp->quit();
321 }
322 
324 {
326  return true;
327  if (m_xOffset != m_topLeftX)
328  return true;
330  return true;
331  if (m_yOffset != m_topLeftY)
332  return true;
333  return false;
334 }
335 
336 void ScreenWizard::customEvent(QEvent *event)
337 {
338 
339  if (event->type() == DialogCompletionEvent::kEventType)
340  {
341  auto *dce = (DialogCompletionEvent*)(event);
342 
343  QString resultid = dce->GetId();
344  int buttonnum = dce->GetResult();
345 
346  if (resultid == "save")
347  {
348  if (buttonnum == 0)
350  else if (buttonnum == 1)
352  else if (buttonnum == 2)
354  }
355  else if (resultid == "nosave")
356  {
357  if (buttonnum == 0)
359  if (buttonnum == 1)
361  }
362  else if (resultid == "quit")
363  {
364  if (buttonnum == 0)
366  if (buttonnum == 1)
367  qApp->quit();
368  if (buttonnum == 2)
370  }
371 
372  m_menuPopup = nullptr;
373  }
374 
375 }
ScreenWizard::moveTLLeft
bool moveTLLeft(void)
Definition: screenwizard.cpp:159
mythrect.h
ScreenWizard::m_coarseFine
bool m_coarseFine
Definition: screenwizard.h:37
MythDialogBox::SetReturnEvent
void SetReturnEvent(QObject *retobject, const QString &resultid)
Definition: mythdialogbox.cpp:301
ScreenWizard::doExit
void doExit()
Definition: screenwizard.cpp:261
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:197
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:323
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:133
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:609
ScreenWizard::moveTLUp
bool moveTLUp(void)
Definition: screenwizard.cpp:140
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:113
ScreenWizard::m_screenWidth
int m_screenWidth
Definition: screenwizard.h:46
ScreenWizard::updateScreen
void updateScreen()
Definition: screenwizard.cpp:216
ScreenWizard::slotResetSettings
static void slotResetSettings()
Definition: screenwizard.cpp:314
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:198
MythDialogBox
Basic menu dialog, message and a list of options.
Definition: mythdialogbox.h:166
ScreenWizard::doMenu
void doMenu()
Definition: screenwizard.cpp:228
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:149
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:55
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:288
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:404
mythcorecontext.h
XMLParseBase::LoadWindowFromXML
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
Definition: xmlparsebase.cpp:695
ScreenWizard::moveBRDown
bool moveBRDown(void)
Definition: screenwizard.cpp:188
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:41
MythUIText::SetText
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:132
ScreenWizard::moveBRUp
bool moveBRUp(void)
Definition: screenwizard.cpp:178
ScreenWizard::moveTLRight
bool moveTLRight(void)
Definition: screenwizard.cpp:168
DialogCompletionEvent::kEventType
static const Type kEventType
Definition: mythdialogbox.h:57
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:323
screenwizard.h
MythCoreContext::SaveSetting
void SaveSetting(const QString &key, int newValue)
Definition: mythcorecontext.cpp:880
ScreenWizard::customEvent
void customEvent(QEvent *event) override
Definition: screenwizard.cpp:336
ScreenWizard::slotSaveSettings
void slotSaveSettings() const
Definition: screenwizard.cpp:304
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:207