MythTV master
mythmediaoverlay.cpp
Go to the documentation of this file.
1// MythTV
5#include "mythmediaoverlay.h"
6
7// Std
8#include <cmath>
9
10#define LOC QString("Overlay: ")
11
13 const QString& Name, bool Themed)
14 : MythScreenType(Parent, Name, true),
15 m_themed(Themed)
16{
17 m_painter = Painter;
18}
19
21{
22 if (m_themed)
23 {
24 bool result = XMLParseBase::LoadWindowFromXML("osd.xml", objectName(), this);
25 if (!result)
26 {
27 LOG(VB_GENERAL, LOG_ERR, LOC + QString("Failed to create window %1")
28 .arg(objectName()));
29 }
30 return result;
31 }
32 return false;
33}
34
36 : m_mainWindow(MainWindow),
37 m_tv(Tv),
38 m_player(Player),
39 m_painter(Painter)
40{
41}
42
44{
46}
47
49{
51}
52
54{
55 for (MythScreenType * screen : std::as_const(m_children))
56 delete screen;
57 m_children.clear();
58}
59
61{
62 return m_rect;
63}
64
66{
67 return m_fontStretch;
68}
69
70bool MythMediaOverlay::Init(QRect Rect, float FontAspect)
71{
72 int newstretch = static_cast<int>(lroundf(FontAspect * 100));
73 if (!(Rect == m_rect) || (newstretch != m_fontStretch))
74 {
75 TearDown();
76 m_rect = Rect;
77 m_fontStretch = newstretch;
78 }
79 return true;
80}
81
82void MythMediaOverlay::HideWindow(const QString& Window)
83{
84 if (!m_children.contains(Window))
85 return;
86
87 MythScreenType *screen = m_children.value(Window);
88 if (screen != nullptr)
89 {
90 screen->SetVisible(false);
91 screen->Close(); // for InteractiveScreen
92 }
93}
94
95bool MythMediaOverlay::HasWindow(const QString& Window)
96{
97 return m_children.contains(Window);
98}
99
101{
102 if (m_children.contains(Window))
103 return m_children.value(Window);
104
105 return InitWindow(Window, new MythOverlayWindow(nullptr, m_painter, Window, false));
106}
107
109{
110 if (Screen)
111 {
112 if (Screen->Create())
113 {
114 m_children.insert(Window, Screen);
115 LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("Created window %1").arg(Window));
116 }
117 else
118 {
119 delete Screen;
120 Screen = nullptr;
121 }
122 }
123
124 return Screen;
125}
126
128{
129 // Avoid unnecessary switches
130 QRect uirect = m_mainWindow->GetUIScreenRect();
131 if (uirect == m_rect)
132 return;
133
134 // Save current data
135 m_savedUIRect = uirect;
138
139 // Calculate new
140 QSize themesize = m_mainWindow->GetThemeSize();
141 float wmult = static_cast<float>(m_rect.size().width()) / static_cast<float>(themesize.width());
142 float mult = static_cast<float>(m_rect.size().height()) / static_cast<float>(themesize.height());
143 if (Log)
144 {
145 LOG(VB_GENERAL, LOG_INFO, LOC + QString("Base theme size: %1x%2")
146 .arg(themesize.width()).arg(themesize.height()));
147 LOG(VB_GENERAL, LOG_INFO, LOC + QString("Scaling factors: %1x%2")
148 .arg(static_cast<double>(wmult)).arg(static_cast<double>(mult)));
149 LOG(VB_GENERAL, LOG_INFO, LOC + QString("Font stretch: saved %1 new %2")
151 }
152 m_uiScaleOverride = true;
153
154 // Apply new
156 m_mainWindow->SetScalingFactors(wmult, mult);
158}
159
161{
163 {
167 }
168 m_uiScaleOverride = false;
169}
MythPlayerUI * m_player
virtual void TearDown()
~MythMediaOverlay() override
MythPainter * m_painter
QMap< QString, MythScreenType * > m_children
virtual bool Init(QRect Rect, float FontAspect)
virtual MythScreenType * GetWindow(const QString &Window)
MythMediaOverlay(MythMainWindow *MainWindow, TV *Tv, MythPlayerUI *Player, MythPainter *Painter)
QRect Bounds() const
MythMainWindow * m_mainWindow
void OverrideUIScale(bool Log=true)
void SetPlayer(MythPlayerUI *Player)
MythScreenType * InitWindow(const QString &Window, MythScreenType *Screen)
int GetFontStretch() const
virtual void HideWindow(const QString &Window)
bool HasWindow(const QString &Window)
bool Create() override
MythOverlayWindow(MythScreenStack *Parent, MythPainter *Painter, const QString &Name, bool Themed)
Screen in which all other widgets are contained and rendered.
virtual bool Create(void)
virtual void Close()
void SetScalingFactors(float Horizontal, float Vertical)
void SetFontStretch(int Stretch)
void GetScalingFactors(float &Horizontal, float &Vertical) const
void SetUIScreenRect(QRect Rect)
virtual void SetVisible(bool visible)
MythPainter * m_painter
Definition: mythuitype.h:309
Control TV playback.
Definition: tv_play.h:156
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
#define LOC
VERBOSE_PREAMBLE Most true
Definition: verbosedefs.h:86