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