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_wantFullScreen = (gCoreContext->GetNumSetting("GuiOffsetX") == 0 &&
133  gCoreContext->GetNumSetting("GuiWidth") == 0 &&
134  gCoreContext->GetNumSetting("GuiOffsetY") == 0 &&
135  gCoreContext->GetNumSetting("GuiHeight") == 0);
136  m_wantWindow = gCoreContext->GetBoolSetting("RunFrontendInWindow", false);
138  m_alwaysOnTop = gCoreContext->GetBoolSetting("AlwaysOnTop", false);
140 }
141 
143 {
144  if (s_XOverride >= 0 && s_YOverride >= 0)
145  {
146  gCoreContext->OverrideSettingForSession("GuiOffsetX", QString::number(s_XOverride));
147  gCoreContext->OverrideSettingForSession("GuiOffsetY", QString::number(s_YOverride));
148  }
149 
150  if (s_WOverride > 0 && s_HOverride > 0)
151  {
152  gCoreContext->OverrideSettingForSession("GuiWidth", QString::number(s_WOverride));
153  gCoreContext->OverrideSettingForSession("GuiHeight", QString::number(s_HOverride));
154  }
155 
156  int x = gCoreContext->GetNumSetting("GuiOffsetX");
157  int y = gCoreContext->GetNumSetting("GuiOffsetY");
158  int width = 0;
159  int height = 0;
160  gCoreContext->GetResolutionSetting("Gui", width, height);
161 
162  QRect screenbounds = mDisplay->GetScreenBounds();
163 
164  // As per MythMainWindow::Init, fullscreen is indicated by all zero's in settings
165  if (x == 0 && y == 0 && width == 0 && height == 0)
166  m_screenRect = screenbounds;
167  else
168  m_screenRect = QRect(x, y, width, height);
169 
170  if (m_screenRect.width() < 160 || m_screenRect.height() < 160)
171  {
172  LOG(VB_GENERAL, LOG_ERR, LOC + QString("Strange screen size: %1x%2 - forcing 640x480")
173  .arg(m_screenRect.width()).arg(m_screenRect.height()));
174  m_screenRect.setSize(QSize(640, 480));
175  }
176 
177  m_screenHorizScale = m_screenRect.width() / static_cast<float>(m_themeSize.width());
178  m_screenVertScale = m_screenRect.height() / static_cast<float>(m_themeSize.height());
179 
181 
182  // Default font, _ALL_ fonts inherit from this!
183  // e.g All fonts will be 19 pixels unless a new size is explicitly defined.
184  QFont font = QFont("Arial");
185  if (!font.exactMatch())
186  font = QFont();
187 
188  font.setStyleHint(QFont::SansSerif, QFont::PreferAntialias);
189  font.setPixelSize(static_cast<int>(lroundf(19.0F * m_screenHorizScale)));
190  int stretch = static_cast<int>(lround(100.0 / mDisplay->GetPixelAspectRatio()));
191  font.setStretch(stretch); // QT
192  m_fontStretch = stretch; // MythUI
193  QApplication::setFont(font);
194 }
195 
197 {
198  return m_uiScreenRect;
199 }
200 
202 {
203  if (Rect == m_uiScreenRect)
204  return;
205  m_uiScreenRect = Rect;
206  LOG(VB_GENERAL, LOG_INFO, LOC + QString("New UI bounds: %1x%2+%3+%4")
207  .arg(m_uiScreenRect.width()).arg(m_uiScreenRect.height())
208  .arg(m_uiScreenRect.left()).arg(m_uiScreenRect.top()));
210 }
211 
213 {
214  return m_screenRect;
215 }
216 
217 QSize MythUIScreenBounds::NormSize(const QSize Size) const
218 {
219  QSize result;
220  result.setWidth(static_cast<int>(Size.width() * m_screenHorizScale));
221  result.setHeight(static_cast<int>(Size.height() * m_screenVertScale));
222  return result;
223 }
224 
226 {
227  return qRound(X * m_screenHorizScale);
228 }
229 
231 {
232  return qRound(Y * m_screenVertScale);
233 }
234 
235 void MythUIScreenBounds::GetScalingFactors(float& Horizontal, float& Vertical) const
236 {
239 }
240 
241 void MythUIScreenBounds::SetScalingFactors(float Horizontal, float Vertical)
242 {
245 }
246 
248 {
249  return m_themeSize;
250 }
251 
253 {
254  return m_fontStretch;
255 }
256 
258 {
259  m_fontStretch = Stretch;
260 }
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:309
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:196
MythUIScreenBounds::SetScalingFactors
void SetScalingFactors(float Horizontal, float Vertical)
Definition: mythuiscreenbounds.cpp:241
MythUIScreenBounds::SetFontStretch
void SetFontStretch(int Stretch)
Definition: mythuiscreenbounds.cpp:257
MythUIScreenBounds::UpdateScreenSettings
void UpdateScreenSettings(MythDisplay *mDisplay)
Definition: mythuiscreenbounds.cpp:142
MythUIScreenBounds::m_wantFullScreen
bool m_wantFullScreen
Definition: mythuiscreenbounds.h:48
MythCoreContext::OverrideSettingForSession
void OverrideSettingForSession(const QString &key, const QString &value)
Definition: mythcorecontext.cpp:1337
MythUIScreenBounds::m_qtFullScreen
bool m_qtFullScreen
Definition: mythuiscreenbounds.h:49
MythUIScreenBounds::s_WOverride
static int s_WOverride
Definition: mythuiscreenbounds.h:56
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythDisplay::GetPixelAspectRatio
double GetPixelAspectRatio()
Definition: mythdisplay.cpp:295
MythUIThemeCache::SetScreenSize
void SetScreenSize(QSize Size)
Definition: mythuithemecache.cpp:51
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:18
MythUIScreenBounds::GetFontStretch
int GetFontStretch() const
Definition: mythuiscreenbounds.cpp:252
MythUIScreenBounds::m_screenRect
QRect m_screenRect
Definition: mythuiscreenbounds.h:44
MythUIScreenBounds::SetUIScreenRect
void SetUIScreenRect(QRect Rect)
Definition: mythuiscreenbounds.cpp:201
MythCoreContext::GetResolutionSetting
void GetResolutionSetting(const QString &type, int &width, int &height, double &forced_aspect, double &refresh_rate, int index=-1)
Definition: mythcorecontext.cpp:849
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:55
MythDisplay
Definition: mythdisplay.h:22
MythCoreContext::GetNumSetting
int GetNumSetting(const QString &key, int defaultval=0)
Definition: mythcorecontext.cpp:912
MythCoreContext::GetBoolSetting
bool GetBoolSetting(const QString &key, bool defaultval=false)
Definition: mythcorecontext.cpp:906
MythUIScreenBounds::NormX
int NormX(int X) const
Definition: mythuiscreenbounds.cpp:225
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:212
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:54
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
ReflectAxis::Vertical
@ Vertical
GetMythUI
MythUIHelper * GetMythUI()
Definition: mythuihelper.cpp:66
MythUIScreenBounds::GetScalingFactors
void GetScalingFactors(float &Horizontal, float &Vertical) const
Definition: mythuiscreenbounds.cpp:235
MythUIScreenBounds::NormY
int NormY(int Y) const
Definition: mythuiscreenbounds.cpp:230
MythUIScreenBounds::s_YOverride
static int s_YOverride
Definition: mythuiscreenbounds.h:55
MythUIScreenBounds::GetThemeSize
QSize GetThemeSize()
Definition: mythuiscreenbounds.cpp:247
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:217