Skip to content

Commit

Permalink
MythUIHelper/MythMainWindow: Simplify API
Browse files Browse the repository at this point in the history
- by using QRect instead of four integer vars.
- pre-cursor to fixing screen rect state for QScreen switching
  • Loading branch information
mark-kendall committed Jan 2, 2020
1 parent 428e8fd commit 27188d9
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 113 deletions.
5 changes: 1 addition & 4 deletions mythtv/libs/libmythtv/osd.cpp
Expand Up @@ -196,10 +196,7 @@ void OSD::OverrideUIScale(bool Log)

m_savedFontStretch = GetMythUI()->GetFontStretch();
GetMythUI()->SetFontStretch(m_fontStretch);

int width;
int height;
GetMythUI()->GetScreenSettings(width, m_savedWMult, height, m_savedHMult);
GetMythUI()->GetScreenSettings(m_savedWMult, m_savedHMult);
QSize theme_size = GetMythUI()->GetBaseSize();
m_savedUIRect = uirect;
float tmp_wmult = static_cast<float>(m_rect.size().width()) / static_cast<float>(theme_size.width());
Expand Down
21 changes: 8 additions & 13 deletions mythtv/libs/libmythtv/tv_play.cpp
Expand Up @@ -1176,19 +1176,14 @@ bool TV::Init(bool createWindow)
GetMythMainWindow()->size());

// adjust for window manager wierdness.
int xbase;
int width;
int ybase;
int height;
float wmult;
float hmult;
GetMythUI()->GetScreenSettings(xbase, width, wmult,
ybase, height, hmult);
if ((abs(m_savedGuiBounds.x()-xbase) < 3) &&
(abs(m_savedGuiBounds.y()-ybase) < 3))
{
m_savedGuiBounds = QRect(QPoint(xbase, ybase),
mainwindow->size());
float dummy1 = 0.0F;
float dummy2 = 0.0F;
QRect screen;
GetMythUI()->GetScreenSettings(screen, dummy1, dummy2);
if ((abs(m_savedGuiBounds.x() - screen.left()) < 3) &&
(abs(m_savedGuiBounds.y() - screen.top()) < 3))
{
m_savedGuiBounds = QRect(screen.topLeft(), mainwindow->size());
}

// if width && height are zero users expect fullscreen playback
Expand Down
18 changes: 4 additions & 14 deletions mythtv/libs/libmythui/mythmainwindow.cpp
Expand Up @@ -134,14 +134,8 @@ class MythMainWindowPrivate

float m_wmult {1.0F};
float m_hmult {1.0F};
int m_screenwidth {0};
int m_screenheight {0};

QRect m_screenRect;
QRect m_uiScreenRect;

int m_xbase {0};
int m_ybase {0};
bool m_doesFillScreen {false};

bool m_ignoreLircKeys {false};
Expand Down Expand Up @@ -979,8 +973,7 @@ void MythMainWindow::Init(bool mayReInit)
if ( !(mayReInit || d->m_firstinit) )
return;

GetMythUI()->GetScreenSettings(d->m_xbase, d->m_screenwidth, d->m_wmult,
d->m_ybase, d->m_screenheight, d->m_hmult);
GetMythUI()->GetScreenSettings(d->m_screenRect, d->m_wmult, d->m_hmult);

d->m_doesFillScreen =
(GetMythDB()->GetNumSetting("GuiOffsetX") == 0 &&
Expand Down Expand Up @@ -1046,12 +1039,9 @@ void MythMainWindow::Init(bool mayReInit)

QTimer::singleShot(1000, this, SLOT(DelayedAction()));

d->m_screenRect = QRect(d->m_xbase, d->m_ybase, d->m_screenwidth, d->m_screenheight);
d->m_uiScreenRect = QRect(0, 0, d->m_screenwidth, d->m_screenheight);

d->m_uiScreenRect = QRect(QPoint(0, 0), d->m_screenRect.size());
LOG(VB_GENERAL, LOG_INFO, QString("UI Screen Resolution: %1 x %2")
.arg(d->m_screenwidth).arg(d->m_screenheight));

.arg(d->m_screenRect.width()).arg(d->m_screenRect.height()));
MoveResize(d->m_screenRect);
Show();

Expand All @@ -1060,7 +1050,7 @@ void MythMainWindow::Init(bool mayReInit)
// Set cursor call must come after Show() to work on some systems.
ShowMouseCursor(false);

move(d->m_xbase, d->m_ybase);
move(d->m_screenRect.topLeft());

if (d->m_paintwin)
{
Expand Down
98 changes: 35 additions & 63 deletions mythtv/libs/libmythui/mythuihelper.cpp
Expand Up @@ -110,8 +110,7 @@ class MythUIHelperPrivate
float m_hmult {1.0F};

// Dimensions of the theme
int m_baseWidth {800};
int m_baseHeight {600};
QSize m_baseSize { 800, 600 };
bool m_isWide {false};

QMap<QString, MythImage *> m_imageCache;
Expand All @@ -133,14 +132,8 @@ class MythUIHelperPrivate
#endif

// The part of the screen(s) allocated for the GUI. Unless
// overridden by the user, defaults to drawable area above.
int m_screenxbase {0};
int m_screenybase {0};

// The part of the screen(s) allocated for the GUI. Unless
// overridden by the user, defaults to drawable area above.
int m_screenwidth {0};
int m_screenheight {0};
// overridden by the user, defaults to the full drawable area.
QRect m_screenRect { 0, 0, 0, 0};

// Command-line GUI size, which overrides both the above sets of sizes
static int x_override;
Expand Down Expand Up @@ -229,32 +222,23 @@ void MythUIHelperPrivate::StoreGUIsettings()
GetMythDB()->OverrideSettingForSession("GuiHeight", QString::number(h_override));
}

m_screenxbase = GetMythDB()->GetNumSetting("GuiOffsetX");
m_screenybase = GetMythDB()->GetNumSetting("GuiOffsetY");

m_screenwidth = m_screenheight = 0;
GetMythDB()->GetResolutionSetting("Gui", m_screenwidth, m_screenheight);
int x = GetMythDB()->GetNumSetting("GuiOffsetX");
int y = GetMythDB()->GetNumSetting("GuiOffsetY");
int width = 0;
int height = 0;
GetMythDB()->GetResolutionSetting("Gui", width, height);

if (!m_display)
m_display = MythDisplay::AcquireRelease();
QRect screenbounds = m_display->GetScreenBounds();

// If any of these was _not_ set by the user,
// (i.e. they are 0) use the whole-screen defaults

if (!m_screenxbase)
m_screenxbase = screenbounds.left();

if (!m_screenybase)
m_screenybase = screenbounds.top();

if (!m_screenwidth)
m_screenwidth = screenbounds.width();

if (!m_screenheight)
m_screenheight = screenbounds.height();
// As per MythMainWindow::Init, fullscreen is indicated by all zero's in settings
if (x == 0 && y == 0 && width == 0 && height == 0)
m_screenRect = screenbounds;
else
m_screenRect = QRect(x, y, width, height);

if (m_screenheight < 160 || m_screenwidth < 160)
if (m_screenRect.width() < 160 || m_screenRect.height() < 160)
{
LOG(VB_GENERAL, LOG_ERR, LOC +
"Somehow, your screen size settings are bad.\n\t\t\t" +
Expand All @@ -264,16 +248,14 @@ void MythUIHelperPrivate::StoreGUIsettings()
.arg(GetMythDB()->GetNumSetting("GuiWidth")) +
QString(" old GuiHeight: %1\n\t\t\t")
.arg(GetMythDB()->GetNumSetting("GuiHeight")) +
QString("width: %1").arg(screenbounds.width()) +
QString("height: %1\n\t\t\t").arg(screenbounds.height()) +
QString("width: %1 ").arg(m_screenRect.width()) +
QString("height: %1\n\t\t\t").arg(m_screenRect.height()) +
"Falling back to 640x480");

m_screenwidth = 640;
m_screenheight = 480;
m_screenRect.setSize(QSize(640, 480));
}

m_wmult = m_screenwidth / static_cast<float>(m_baseWidth);
m_hmult = m_screenheight / static_cast<float>(m_baseHeight);
m_wmult = m_screenRect.width() / static_cast<float>(m_baseSize.width());
m_hmult = m_screenRect.height() / static_cast<float>(m_baseSize.height());

// Default font, _ALL_ fonts inherit from this!
// e.g All fonts will be 19 pixels unless a new size is explicitly defined.
Expand Down Expand Up @@ -361,12 +343,11 @@ void MythUIHelper::LoadQtConfig(void)
if (themeinfo)
{
d->m_isWide = themeinfo->IsWide();
d->m_baseWidth = themeinfo->GetBaseRes()->width();
d->m_baseHeight = themeinfo->GetBaseRes()->height();
d->m_baseSize = themeinfo->GetBaseRes();
d->m_themename = themeinfo->GetName();
LOG(VB_GUI, LOG_INFO, LOC +
QString("Using theme base resolution of %1x%2")
.arg(d->m_baseWidth).arg(d->m_baseHeight));
.arg(d->m_baseSize.width()).arg(d->m_baseSize.height()));
delete themeinfo;
}

Expand Down Expand Up @@ -654,8 +635,8 @@ QString MythUIHelper::GetThemeCacheDir(void)
static QString s_oldcachedir;
QString tmpcachedir = GetThemeBaseCacheDir() + "/" +
GetMythDB()->GetSetting("Theme", DEFAULT_UI_THEME) +
"." + QString::number(d->m_screenwidth) +
"." + QString::number(d->m_screenheight);
"." + QString::number(d->m_screenRect.width()) +
"." + QString::number(d->m_screenRect.height());

if (tmpcachedir != s_oldcachedir)
{
Expand Down Expand Up @@ -846,33 +827,24 @@ void MythUIHelper::PruneCacheDir(const QString& dirname)
.arg(kept).arg(deleted).arg(errcnt));
}

void MythUIHelper::GetScreenSettings(float &wmult, float &hmult)
void MythUIHelper::GetScreenSettings(float &XFactor, float &YFactor)
{
wmult = d->m_wmult;
hmult = d->m_hmult;
XFactor = d->m_wmult;
YFactor = d->m_hmult;
}

void MythUIHelper::GetScreenSettings(int &width, float &wmult,
int &height, float &hmult)
void MythUIHelper::GetScreenSettings(QSize &Size, float &XFactor, float &YFactor)
{
height = d->m_screenheight;
width = d->m_screenwidth;

wmult = d->m_wmult;
hmult = d->m_hmult;
XFactor = d->m_wmult;
YFactor = d->m_hmult;
Size = d->m_screenRect.size();
}

void MythUIHelper::GetScreenSettings(int &xbase, int &width, float &wmult,
int &ybase, int &height, float &hmult)
void MythUIHelper::GetScreenSettings(QRect &Rect, float &XFactor, float &YFactor)
{
xbase = d->m_screenxbase;
ybase = d->m_screenybase;

height = d->m_screenheight;
width = d->m_screenwidth;

wmult = d->m_wmult;
hmult = d->m_hmult;
XFactor = d->m_wmult;
YFactor = d->m_hmult;
Rect = d->m_screenRect;
}

/**
Expand Down Expand Up @@ -1564,7 +1536,7 @@ MThreadPool *MythUIHelper::GetImageThreadPool(void)

QSize MythUIHelper::GetBaseSize(void) const
{
return {d->m_baseWidth, d->m_baseHeight};
return d->m_baseSize;
}

void MythUIHelper::SetFontStretch(int stretch)
Expand Down
8 changes: 3 additions & 5 deletions mythtv/libs/libmythui/mythuihelper.h
Expand Up @@ -67,11 +67,9 @@ class MUI_PUBLIC MythUIHelper
static bool IsTopScreenInitialized(void);

// which the user may have set to be different from the raw screen size
void GetScreenSettings(float &wmult, float &hmult);
void GetScreenSettings(int &width, float &wmult,
int &height, float &hmult);
void GetScreenSettings(int &xbase, int &width, float &wmult,
int &ybase, int &height, float &hmult);
void GetScreenSettings(QRect &Rect, float &XFactor, float &YFactor);
void GetScreenSettings(QSize &Size, float &XFactor, float &YFactor);
void GetScreenSettings(float &XFactor, float &YFactor);

// Parse an X11 style command line (-geometry) string
static void ParseGeometryOverride(const QString &geometry);
Expand Down
25 changes: 12 additions & 13 deletions mythtv/libs/libmythui/mythvirtualkeyboard.cpp
Expand Up @@ -102,11 +102,10 @@ bool MythUIVirtualKeyboard::Create()
loadKeyDefinitions(gCoreContext->GetLanguageAndVariant());
updateKeys(true);

int screenWidth = 0;
int screenHeight = 0;
float xmult = 0;
float ymult = 0;
GetMythUI()->GetScreenSettings(screenWidth, xmult, screenHeight, ymult);
QSize screensize;
float dummy1 = 0;
float dummy2 = 0;
GetMythUI()->GetScreenSettings(screensize, dummy1, dummy2);
MythRect editArea = m_parentEdit->GetArea();
MythRect area = GetArea();
MythPoint newPos;
Expand Down Expand Up @@ -136,20 +135,20 @@ bool MythUIVirtualKeyboard::Create()
break;

case VK_POSTOPDIALOG:
newPos = QPoint(screenWidth / 2 - area.width() / 2, 5);
newPos = QPoint(screensize.width() / 2 - area.width() / 2, 5);
break;

case VK_POSBOTTOMDIALOG:
newPos = QPoint(screenWidth / 2 - area.width() / 2, screenHeight - 5 - area.height());
newPos = QPoint(screensize.width() / 2 - area.width() / 2, screensize.height() - 5 - area.height());
break;

case VK_POSCENTERDIALOG:
newPos = QPoint(screenWidth / 2 - area.width() / 2, screenHeight / 2 - area.height() / 2);
newPos = QPoint(screensize.width() / 2 - area.width() / 2, screensize.height() / 2 - area.height() / 2);
break;

default:
// VK_POSBELOWEDIT
if (editArea.y() + editArea.height() + area.height() + 5 < screenHeight)
if (editArea.y() + editArea.height() + area.height() + 5 < screensize.height())
{
newPos = QPoint(editArea.x() + editArea.width() / 2 - area.width() / 2,
editArea.y() + editArea.height() + 5);
Expand All @@ -165,12 +164,12 @@ bool MythUIVirtualKeyboard::Create()
// make sure the popup doesn't go off screen
if (newPos.x() < 5)
newPos.setX(5);
if (newPos.x() + area.width() + 5 > screenWidth)
newPos.setX(screenWidth - area.width() - 5);
if (newPos.x() + area.width() + 5 > screensize.width())
newPos.setX(screensize.width() - area.width() - 5);
if (newPos.y() < 5)
newPos.setY(5);
if (newPos.y() + area.height() + 5 > screenHeight)
newPos.setY(screenHeight - area.height() - 5);
if (newPos.y() + area.height() + 5 > screensize.width())
newPos.setY(screensize.width() - area.height() - 5);

SetPosition(newPos);

Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythui/themeinfo.h
Expand Up @@ -26,7 +26,7 @@ class MUI_PUBLIC ThemeInfo : public XMLParseBase

bool IsWide() const;
QString GetAspect() const { return m_aspect; }
const QSize *GetBaseRes() const { return &m_baseres; }
const QSize GetBaseRes() const { return m_baseres; }
QString GetName() const { return m_name; }
QString GetBaseTheme() const { return m_baseTheme; }
QString GetDescription() const { return m_description; }
Expand Down

0 comments on commit 27188d9

Please sign in to comment.