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
40void 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
219QSize 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
237void MythUIScreenBounds::GetScalingFactors(float& Horizontal, float& Vertical) const
238{
241}
242
243void 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}
void OverrideSettingForSession(const QString &key, const QString &value)
int GetNumSetting(const QString &key, int defaultval=0)
bool GetBoolSetting(const QString &key, bool defaultval=false)
void GetResolutionSetting(const QString &type, int &width, int &height, double &forced_aspect, double &refresh_rate, int index=-1)
double GetPixelAspectRatio()
QRect GetScreenBounds()
void SetScalingFactors(float Horizontal, float Vertical)
void SetFontStretch(int Stretch)
static QRect GetGeometryOverride()
QSize NormSize(QSize Size) const
static bool WindowIsAlwaysFullscreen()
Return true if the current platform only supports fullscreen windows.
void UpdateScreenSettings(MythDisplay *mDisplay)
void GetScalingFactors(float &Horizontal, float &Vertical) const
int NormX(int X) const
static void ParseGeometryOverride(const QString &Geometry)
Parse an X11 style command line geometry string.
void UIScreenRectChanged(const QRect &Rect)
static bool GeometryIsOverridden()
void SetUIScreenRect(QRect Rect)
int NormY(int Y) const
void SetScreenSize(QSize Size)
QSize GetBaseSize() const
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythUIHelper * GetMythUI()
#define LOC