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