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"
14#include "libmythui/themeinfo.h"
15
16// MythScreenWizard
17#include "screenwizard.h"
18
19static constexpr int kMinWidth { 160 };
20static constexpr int kMinHeight { 160 };
21
22ScreenWizard::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
29void 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
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
67
68 return true;
69}
70
71bool ScreenWizard::keyPressEvent(QKeyEvent *event)
72{
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
150 return true;
151}
152
154{
156 if (!moveBRDown())
157 return false;
158
160 return true;
161}
162
164{
165 if (m_topLeftX < (0 + m_change))
166 return false;
167
169 return true;
170}
171
173{
175 if (!moveBRRight())
176 return false;
177
179 return true;
180}
181
183{
185 if (!moveTLUp())
186 return false;
187
189 return true;
190}
191
193{
195 return false;
196
198 return true;
199}
200
202{
204 if (!moveTLLeft())
205 return false;
206
208 return true;
209}
210
212{
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
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;
300 }
301 else
302 {
303 m_coarseFine = true;
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
342void 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}
Event dispatched from MythUI modal dialogs to a listening class containing a result of some form.
Definition: mythdialogbox.h:41
static const Type kEventType
Definition: mythdialogbox.h:56
void SaveSetting(const QString &key, int newValue)
Basic menu dialog, message and a list of options.
void AddButton(const QString &title)
void SetReturnEvent(QObject *retobject, const QString &resultid)
bool Create(void) override
bool TranslateKeyPress(const QString &Context, QKeyEvent *Event, QStringList &Actions, bool AllowJumps=true)
Get a list of actions for a keypress in the given context.
MythScreenStack * GetStack(const QString &Stackname)
Wrapper around QRect allowing us to handle percentage and other relative values for areas in mythui.
Definition: mythrect.h:18
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Screen in which all other widgets are contained and rendered.
MythUIType * GetFocusWidget(void) const
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:98
A widget for rendering primitive shapes and lines.
Definition: mythuishape.h:22
All purpose text widget, displays a text string.
Definition: mythuitext.h:29
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:115
virtual void SetArea(const MythRect &rect)
Definition: mythuitype.cpp:610
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:138
bool moveTLUp(void)
bool moveBRDown(void)
bool m_whichCorner
Definition: screenwizard.h:36
void slotChangeCoarseFine()
int m_bottomRightX
Definition: screenwizard.h:44
int m_bottomRightY
Definition: screenwizard.h:45
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
void updateScreen()
static void slotResetSettings()
bool moveBRUp(void)
bool m_coarseFine
Definition: screenwizard.h:37
bool moveBRRight(void)
bool Create(void) override
bool moveTLLeft(void)
void slotSaveSettings() const
ScreenWizard(MythScreenStack *parent, const char *name)
bool moveBRLeft(void)
MythUIShape * m_blackout
Definition: screenwizard.h:56
bool moveTLDown(void)
bool anythingChanged() const
MythUIText * m_changeAmount
Definition: screenwizard.h:60
int m_screenHeight
Definition: screenwizard.h:47
MythDialogBox * m_menuPopup
Definition: screenwizard.h:61
MythUIText * m_offsets
Definition: screenwizard.h:59
bool moveTLRight(void)
MythUIText * m_size
Definition: screenwizard.h:58
void customEvent(QEvent *event) override
void SetInitialSettings(int _x, int _y, int _w, int _h)
MythUIImage * m_preview
Definition: screenwizard.h:57
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythMainWindow * GetMythMainWindow(void)
static constexpr int kMinWidth
static constexpr int kMinHeight