MythTV  master
mythmediaoverlay.cpp
Go to the documentation of this file.
1 // MythTV
2 #include "mythlogging.h"
3 #include "mythmainwindow.h"
4 #include "mythscreentype.h"
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 {
42  m_player = Player;
43 }
44 
46 {
47  for (MythScreenType * screen : qAsConst(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 
62 bool 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 
74 void 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 
87 bool 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")
144  .arg(m_savedFontStretch).arg(m_fontStretch));
145  }
146  m_uiScaleOverride = true;
147 
148  // Apply new
150  m_mainWindow->SetScalingFactors(wmult, mult);
152 }
153 
155 {
156  if (m_uiScaleOverride)
157  {
161  }
162  m_uiScaleOverride = false;
163 }
MythOverlayWindow::m_themed
bool m_themed
Definition: mythmediaoverlay.h:27
MythMediaOverlay::RevertUIScale
void RevertUIScale()
Definition: mythmediaoverlay.cpp:154
MythUIScreenBounds::GetUIScreenRect
QRect GetUIScreenRect()
Definition: mythuiscreenbounds.cpp:195
MythMediaOverlay::InitWindow
MythScreenType * InitWindow(const QString &Window, MythScreenType *Screen)
Definition: mythmediaoverlay.cpp:100
MythMediaOverlay::m_uiScaleOverride
bool m_uiScaleOverride
Definition: mythmediaoverlay.h:55
MythUIScreenBounds::SetScalingFactors
void SetScalingFactors(float Horizontal, float Vertical)
Definition: mythuiscreenbounds.cpp:240
MythUIScreenBounds::SetFontStretch
void SetFontStretch(int Stretch)
Definition: mythuiscreenbounds.cpp:256
MythScreenType::Close
virtual void Close()
Definition: mythscreentype.cpp:385
MythMediaOverlay::m_savedWMult
float m_savedWMult
Definition: mythmediaoverlay.h:56
MythScreenStack
Definition: mythscreenstack.h:16
MythScreenType::Create
virtual bool Create(void)
Definition: mythscreentype.cpp:265
MythMediaOverlay::Bounds
QRect Bounds() const
Definition: mythmediaoverlay.cpp:52
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MythMediaOverlay::HideWindow
virtual void HideWindow(const QString &Window)
Definition: mythmediaoverlay.cpp:74
MythScreenType
Screen in which all other widgets are contained and rendered.
Definition: mythscreentype.h:44
MythMediaOverlay::m_player
MythPlayerUI * m_player
Definition: mythmediaoverlay.h:52
MythMediaOverlay::~MythMediaOverlay
~MythMediaOverlay() override
Definition: mythmediaoverlay.cpp:35
MythMediaOverlay::m_savedFontStretch
int m_savedFontStretch
Definition: mythmediaoverlay.h:60
MythOverlayWindow
Definition: mythmediaoverlay.h:18
true
VERBOSE_PREAMBLE Most true
Definition: verbosedefs.h:91
LOC
#define LOC
Definition: mythmediaoverlay.cpp:10
MythPlayerUI
Definition: mythplayerui.h:10
MythMediaOverlay::m_rect
QRect m_rect
Definition: mythmediaoverlay.h:54
MythMediaOverlay::HasWindow
bool HasWindow(const QString &Window)
Definition: mythmediaoverlay.cpp:87
MythMediaOverlay::m_painter
MythPainter * m_painter
Definition: mythmediaoverlay.h:53
MythMediaOverlay::m_fontStretch
int m_fontStretch
Definition: mythmediaoverlay.h:59
mythlogging.h
mythmediaoverlay.h
MythUIScreenBounds::GetFontStretch
int GetFontStretch() const
Definition: mythuiscreenbounds.cpp:251
MythUIScreenBounds::SetUIScreenRect
void SetUIScreenRect(QRect Rect)
Definition: mythuiscreenbounds.cpp:200
MythMediaOverlay::MythMediaOverlay
MythMediaOverlay(MythMainWindow *MainWindow, TV *Tv, MythPlayerUI *Player, MythPainter *Painter)
Definition: mythmediaoverlay.cpp:27
MythMediaOverlay::m_savedHMult
float m_savedHMult
Definition: mythmediaoverlay.h:57
MythMediaOverlay::m_children
QMap< QString, MythScreenType * > m_children
Definition: mythmediaoverlay.h:61
MythMediaOverlay::SetPlayer
void SetPlayer(MythPlayerUI *Player)
Definition: mythmediaoverlay.cpp:40
MythMediaOverlay::m_savedUIRect
QRect m_savedUIRect
Definition: mythmediaoverlay.h:58
MythMediaOverlay::Init
virtual bool Init(QRect Rect, float FontAspect)
Definition: mythmediaoverlay.cpp:62
MythMediaOverlay::GetWindow
virtual MythScreenType * GetWindow(const QString &Window)
Definition: mythmediaoverlay.cpp:92
XMLParseBase::LoadWindowFromXML
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
Definition: xmlparsebase.cpp:692
MythPainter
Definition: mythpainter.h:32
Name
Definition: channelsettings.cpp:46
MythMediaOverlay::m_mainWindow
MythMainWindow * m_mainWindow
Definition: mythmediaoverlay.h:50
MythUIType::SetVisible
virtual void SetVisible(bool visible)
Definition: mythuitype.cpp:1086
MythUIType::m_painter
MythPainter * m_painter
Definition: mythuitype.h:292
MythOverlayWindow::MythOverlayWindow
MythOverlayWindow(MythScreenStack *Parent, MythPainter *Painter, const QString &Name, bool Themed)
Definition: mythmediaoverlay.cpp:12
MythMediaOverlay::GetFontStretch
int GetFontStretch() const
Definition: mythmediaoverlay.cpp:57
MThread::objectName
QString objectName(void) const
Definition: mthread.cpp:246
MythOverlayWindow::Create
bool Create() override
Definition: mythmediaoverlay.cpp:20
Player
Definition: zmliveplayer.h:34
MythMediaOverlay::TearDown
virtual void TearDown()
Definition: mythmediaoverlay.cpp:45
MythUIScreenBounds::GetScalingFactors
void GetScalingFactors(float &Horizontal, float &Vertical) const
Definition: mythuiscreenbounds.cpp:234
mythmainwindow.h
MythMediaOverlay::OverrideUIScale
void OverrideUIScale(bool Log=true)
Definition: mythmediaoverlay.cpp:121
MythMainWindow
Definition: mythmainwindow.h:35
mythscreentype.h
MythUIScreenBounds::GetThemeSize
QSize GetThemeSize()
Definition: mythuiscreenbounds.cpp:246
TV
Control TV playback.
Definition: tv_play.h:154