MythTV  master
mythuiscreenbounds.cpp
Go to the documentation of this file.
1 // Qt
2 #include <QApplication>
3 
4 // MythTV
5 #include "mythcorecontext.h"
6 #include "mythlogging.h"
7 #include "mythuihelper.h"
8 #include "mythdisplay.h"
9 #include "mythuiscreenbounds.h"
10 
15 
16 #define LOC QString("UIBounds: ")
17 
19 {
20  return (s_XOverride >= 0 || s_YOverride >= 0 || s_WOverride >= 0 || s_HOverride >= 0);
21 }
22 
24 {
25  // NB Call GeometryIsOverridden first to ensure this is valid
27 }
28 
38 void MythUIScreenBounds::ParseGeometryOverride(const QString& Geometry)
39 {
40  QRegExp sre("^(\\d+)x(\\d+)$");
41  QRegExp lre(R"(^(\d+)x(\d+)([+-]\d+)([+-]\d+)$)");
42  QStringList geometry;
43  bool longform = false;
44 
45  if (sre.exactMatch(Geometry))
46  {
47  geometry = sre.capturedTexts();
48  }
49  else if (lre.exactMatch(Geometry))
50  {
51  geometry = lre.capturedTexts();
52  longform = true;
53  }
54  else
55  {
56  LOG(VB_GENERAL, LOG_ERR, LOC + "Geometry does not match either form - "
57  "WIDTHxHEIGHT or WIDTHxHEIGHT+XOFF+YOFF");
58  return;
59  }
60 
61  bool parsed = false;
62  int height = 0;
63  int width = geometry[1].toInt(&parsed);
64  if (!parsed)
65  LOG(VB_GENERAL, LOG_ERR, LOC + "Could not parse width of geometry override");
66 
67  if (parsed)
68  {
69  height = geometry[2].toInt(&parsed);
70  if (!parsed)
71  LOG(VB_GENERAL, LOG_ERR, LOC + "Could not parse height of geometry override");
72  }
73 
74  if (parsed)
75  {
76  s_WOverride = width;
77  s_HOverride = height;
78  LOG(VB_GENERAL, LOG_INFO, LOC + QString("Overriding GUI size: %1x%2")
79  .arg(width).arg(height));
80  }
81  else
82  {
83  LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to override GUI size.");
84  }
85 
86  if (longform)
87  {
88  int x = geometry[3].toInt(&parsed);
89  if (!parsed)
90  {
91  LOG(VB_GENERAL, LOG_ERR, LOC + "Could not parse horizontal offset of geometry override");
92  LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to override GUI offset.");
93  return;
94  }
95 
96  int y = geometry[4].toInt(&parsed);
97  if (!parsed)
98  {
99  LOG(VB_GENERAL, LOG_ERR, LOC + "Could not parse vertical offset of geometry override");
100  LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to override GUI offset.");
101  return;
102  }
103 
104  s_XOverride = x;
105  s_YOverride = y;
106  LOG(VB_GENERAL, LOG_INFO, LOC + QString("Overriding GUI offset: %1+%2").arg(x).arg(y));
107  }
108 }
109 
112 {
113 #ifdef Q_OS_ANDROID
114  return true;
115 #else
116  // this may need to cover other platform plugins
117  return QGuiApplication::platformName().toLower().contains("eglfs");
118 #endif
119 }
120 
122 {
124 }
125 
127 {
128  m_wantFullScreen = (gCoreContext->GetNumSetting("GuiOffsetX") == 0 &&
129  gCoreContext->GetNumSetting("GuiWidth") == 0 &&
130  gCoreContext->GetNumSetting("GuiOffsetY") == 0 &&
131  gCoreContext->GetNumSetting("GuiHeight") == 0);
132  m_wantWindow = gCoreContext->GetBoolSetting("RunFrontendInWindow", false);
134  m_alwaysOnTop = gCoreContext->GetBoolSetting("AlwaysOnTop", false);
136 }
137 
139 {
140  if (s_XOverride >= 0 && s_YOverride >= 0)
141  {
142  gCoreContext->OverrideSettingForSession("GuiOffsetX", QString::number(s_XOverride));
143  gCoreContext->OverrideSettingForSession("GuiOffsetY", QString::number(s_YOverride));
144  }
145 
146  if (s_WOverride > 0 && s_HOverride > 0)
147  {
148  gCoreContext->OverrideSettingForSession("GuiWidth", QString::number(s_WOverride));
149  gCoreContext->OverrideSettingForSession("GuiHeight", QString::number(s_HOverride));
150  }
151 
152  int x = gCoreContext->GetNumSetting("GuiOffsetX");
153  int y = gCoreContext->GetNumSetting("GuiOffsetY");
154  int width = 0;
155  int height = 0;
156  gCoreContext->GetResolutionSetting("Gui", width, height);
157 
158  QRect screenbounds = mDisplay->GetScreenBounds();
159 
160  // As per MythMainWindow::Init, fullscreen is indicated by all zero's in settings
161  if (x == 0 && y == 0 && width == 0 && height == 0)
162  m_screenRect = screenbounds;
163  else
164  m_screenRect = QRect(x, y, width, height);
165 
166  if (m_screenRect.width() < 160 || m_screenRect.height() < 160)
167  {
168  LOG(VB_GENERAL, LOG_ERR, LOC + QString("Strange screen size: %1x%2 - forcing 640x480")
169  .arg(m_screenRect.width()).arg(m_screenRect.height()));
170  m_screenRect.setSize(QSize(640, 480));
171  }
172 
173  m_screenHorizScale = m_screenRect.width() / static_cast<float>(m_themeSize.width());
174  m_screenVertScale = m_screenRect.height() / static_cast<float>(m_themeSize.height());
175 
177 
178  // Default font, _ALL_ fonts inherit from this!
179  // e.g All fonts will be 19 pixels unless a new size is explicitly defined.
180  QFont font = QFont("Arial");
181  if (!font.exactMatch())
182  font = QFont();
183 
184  font.setStyleHint(QFont::SansSerif, QFont::PreferAntialias);
185  font.setPixelSize(static_cast<int>(lroundf(19.0F * m_screenHorizScale)));
186  int stretch = static_cast<int>(lround(100.0 / mDisplay->GetPixelAspectRatio()));
187  font.setStretch(stretch); // QT
188  m_fontStretch = stretch; // MythUI
189  QApplication::setFont(font);
190 }
191 
193 {
194  return m_uiScreenRect;
195 }
196 
198 {
199  if (Rect == m_uiScreenRect)
200  return;
201  m_uiScreenRect = Rect;
202  LOG(VB_GENERAL, LOG_INFO, LOC + QString("New UI bounds: %1x%2+%3+%4")
203  .arg(m_uiScreenRect.width()).arg(m_uiScreenRect.height())
204  .arg(m_uiScreenRect.left()).arg(m_uiScreenRect.top()));
206 }
207 
209 {
210  return m_screenRect;
211 }
212 
213 QSize MythUIScreenBounds::NormSize(const QSize Size) const
214 {
215  QSize result;
216  result.setWidth(static_cast<int>(Size.width() * m_screenHorizScale));
217  result.setHeight(static_cast<int>(Size.height() * m_screenVertScale));
218  return result;
219 }
220 
222 {
223  return qRound(X * m_screenHorizScale);
224 }
225 
227 {
228  return qRound(Y * m_screenVertScale);
229 }
230 
231 void MythUIScreenBounds::GetScalingFactors(float& Horizontal, float& Vertical) const
232 {
233  Horizontal = m_screenHorizScale;
235 }
236 
237 void MythUIScreenBounds::SetScalingFactors(float Horizontal, float Vertical)
238 {
239  m_screenHorizScale = Horizontal;
241 }
242 
244 {
245  return m_themeSize;
246 }
247 
249 {
250  return m_fontStretch;
251 }
252 
254 {
255  m_fontStretch = Stretch;
256 }
MythUIScreenBounds::m_alwaysOnTop
bool m_alwaysOnTop
Definition: mythuiscreenbounds.h:50
MythUIThemeHelper::GetBaseSize
QSize GetBaseSize() const
Definition: mythuithemehelper.cpp:268
MythDisplay::GetScreenBounds
QRect GetScreenBounds()
Definition: mythdisplay.cpp:263
MythUIScreenBounds::ParseGeometryOverride
static void ParseGeometryOverride(const QString &Geometry)
Parse an X11 style command line geometry string.
Definition: mythuiscreenbounds.cpp:38
MythUIScreenBounds::GetUIScreenRect
QRect GetUIScreenRect()
Definition: mythuiscreenbounds.cpp:192
MythUIScreenBounds::SetScalingFactors
void SetScalingFactors(float Horizontal, float Vertical)
Definition: mythuiscreenbounds.cpp:237
MythUIScreenBounds::SetFontStretch
void SetFontStretch(int Stretch)
Definition: mythuiscreenbounds.cpp:253
MythUIScreenBounds::UpdateScreenSettings
void UpdateScreenSettings(MythDisplay *mDisplay)
Definition: mythuiscreenbounds.cpp:138
MythUIScreenBounds::m_wantFullScreen
bool m_wantFullScreen
Definition: mythuiscreenbounds.h:48
MythCoreContext::OverrideSettingForSession
void OverrideSettingForSession(const QString &key, const QString &value)
Definition: mythcorecontext.cpp:1346
MythUIScreenBounds::m_qtFullScreen
bool m_qtFullScreen
Definition: mythuiscreenbounds.h:49
arg
arg(title).arg(filename).arg(doDelete))
MythUIScreenBounds::s_WOverride
static int s_WOverride
Definition: mythuiscreenbounds.h:56
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MythDisplay::GetPixelAspectRatio
double GetPixelAspectRatio()
Definition: mythdisplay.cpp:249
MythUIThemeCache::SetScreenSize
void SetScreenSize(QSize Size)
Definition: mythuithemecache.cpp:50
MythUIScreenBounds::s_HOverride
static int s_HOverride
Definition: mythuiscreenbounds.h:57
mythuiscreenbounds.h
ReflectAxis::Horizontal
@ Horizontal
mythdisplay.h
mythlogging.h
LOC
#define LOC
Definition: mythuiscreenbounds.cpp:16
MythUIScreenBounds::GetFontStretch
int GetFontStretch() const
Definition: mythuiscreenbounds.cpp:248
MythUIScreenBounds::m_screenRect
QRect m_screenRect
Definition: mythuiscreenbounds.h:44
MythUIScreenBounds::SetUIScreenRect
void SetUIScreenRect(QRect Rect)
Definition: mythuiscreenbounds.cpp:197
MythCoreContext::GetResolutionSetting
void GetResolutionSetting(const QString &type, int &width, int &height, double &forced_aspect, double &refresh_rate, int index=-1)
Definition: mythcorecontext.cpp:870
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:60
MythDisplay
Definition: mythdisplay.h:19
MythCoreContext::GetNumSetting
int GetNumSetting(const QString &key, int defaultval=0)
Definition: mythcorecontext.cpp:933
MythCoreContext::GetBoolSetting
bool GetBoolSetting(const QString &key, bool defaultval=false)
Definition: mythcorecontext.cpp:927
MythUIScreenBounds::NormX
int NormX(int X) const
Definition: mythuiscreenbounds.cpp:221
mythuihelper.h
MythUIScreenBounds::InitScreenBounds
void InitScreenBounds()
Definition: mythuiscreenbounds.cpp:126
MythUIScreenBounds::m_wantWindow
bool m_wantWindow
Definition: mythuiscreenbounds.h:47
MythUIScreenBounds::WindowIsAlwaysFullscreen
static bool WindowIsAlwaysFullscreen()
Return true if the current platform only supports fullscreen windows.
Definition: mythuiscreenbounds.cpp:111
mythcorecontext.h
MythUIScreenBounds::GetScreenRect
QRect GetScreenRect()
Definition: mythuiscreenbounds.cpp:208
MythUIScreenBounds::UIScreenRectChanged
void UIScreenRectChanged(const QRect &Rect)
MythUIScreenBounds::GetGeometryOverride
static QRect GetGeometryOverride()
Definition: mythuiscreenbounds.cpp:23
MythUIScreenBounds::s_XOverride
static int s_XOverride
Definition: mythuiscreenbounds.h:54
MythUIScreenBounds::MythUIScreenBounds
MythUIScreenBounds()
Definition: mythuiscreenbounds.cpp:121
MythUIScreenBounds::m_fontStretch
int m_fontStretch
Definition: mythuiscreenbounds.h:51
MythUIScreenBounds::m_screenVertScale
float m_screenVertScale
Definition: mythuiscreenbounds.h:46
MythUIScreenBounds::m_screenHorizScale
float m_screenHorizScale
Definition: mythuiscreenbounds.h:45
GetMythUI
MythUIHelper * GetMythUI()
Definition: mythuihelper.cpp:66
MythUIScreenBounds::GetScalingFactors
void GetScalingFactors(float &Horizontal, float &Vertical) const
Definition: mythuiscreenbounds.cpp:231
MythUIScreenBounds::NormY
int NormY(int Y) const
Definition: mythuiscreenbounds.cpp:226
MythUIScreenBounds::s_YOverride
static int s_YOverride
Definition: mythuiscreenbounds.h:55
MythUIScreenBounds::GetThemeSize
QSize GetThemeSize()
Definition: mythuiscreenbounds.cpp:243
MythUIScreenBounds::GeometryIsOverridden
static bool GeometryIsOverridden()
Definition: mythuiscreenbounds.cpp:18
MythUIScreenBounds::m_themeSize
QSize m_themeSize
Definition: mythuiscreenbounds.h:42
MythUIScreenBounds::m_uiScreenRect
QRect m_uiScreenRect
Definition: mythuiscreenbounds.h:43
MythUIScreenBounds::NormSize
QSize NormSize(QSize Size) const
Definition: mythuiscreenbounds.cpp:213