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 return XMLParseBase::LoadWindowFromXML("osd.xml", objectName(), this);
24 return false;
25}
26
28 : m_mainWindow(MainWindow),
29 m_tv(Tv),
30 m_player(Player),
31 m_painter(Painter)
32{
33}
34
36{
38}
39
41{
43}
44
46{
47 for (MythScreenType * screen : std::as_const(m_children))
48 delete screen;
49 m_children.clear();
50}
51
53{
54 return m_rect;
55}
56
58{
59 return m_fontStretch;
60}
61
62bool MythMediaOverlay::Init(QRect Rect, float FontAspect)
63{
64 int newstretch = static_cast<int>(lroundf(FontAspect * 100));
65 if (!(Rect == m_rect) || (newstretch != m_fontStretch))
66 {
67 TearDown();
68 m_rect = Rect;
69 m_fontStretch = newstretch;
70 }
71 return true;
72}
73
74void MythMediaOverlay::HideWindow(const QString& Window)
75{
76 if (!m_children.contains(Window))
77 return;
78
79 MythScreenType *screen = m_children.value(Window);
80 if (screen != nullptr)
81 {
82 screen->SetVisible(false);
83 screen->Close(); // for InteractiveScreen
84 }
85}
86
87bool MythMediaOverlay::HasWindow(const QString& Window)
88{
89 return m_children.contains(Window);
90}
91
93{
94 if (m_children.contains(Window))
95 return m_children.value(Window);
96
97 return InitWindow(Window, new MythOverlayWindow(nullptr, m_painter, Window, false));
98}
99
101{
102 if (Screen)
103 {
104 if (Screen->Create())
105 {
106 m_children.insert(Window, Screen);
107 LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("Created window %1").arg(Window));
108 }
109 else
110 {
111 delete Screen;
112 Screen = nullptr;
113 }
114 }
115
116 if (!Screen)
117 LOG(VB_GENERAL, LOG_ERR, LOC + QString("Failed to create window %1").arg(Window));
118 return Screen;
119}
120
122{
123 // Avoid unnecessary switches
124 QRect uirect = m_mainWindow->GetUIScreenRect();
125 if (uirect == m_rect)
126 return;
127
128 // Save current data
129 m_savedUIRect = uirect;
132
133 // Calculate new
134 QSize themesize = m_mainWindow->GetThemeSize();
135 float wmult = static_cast<float>(m_rect.size().width()) / static_cast<float>(themesize.width());
136 float mult = static_cast<float>(m_rect.size().height()) / static_cast<float>(themesize.height());
137 if (Log)
138 {
139 LOG(VB_GENERAL, LOG_INFO, LOC + QString("Base theme size: %1x%2")
140 .arg(themesize.width()).arg(themesize.height()));
141 LOG(VB_GENERAL, LOG_INFO, LOC + QString("Scaling factors: %1x%2")
142 .arg(static_cast<double>(wmult)).arg(static_cast<double>(mult)));
143 LOG(VB_GENERAL, LOG_INFO, LOC + QString("Font stretch: saved %1 new %2")
145 }
146 m_uiScaleOverride = true;
147
148 // Apply new
150 m_mainWindow->SetScalingFactors(wmult, mult);
152}
153
155{
157 {
161 }
162 m_uiScaleOverride = false;
163}
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:298
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:95