Skip to content

Commit

Permalink
Add some explicit functions for manipulating a MythRect/QRect.
Browse files Browse the repository at this point in the history
Some issues show up when changing MythRect to have an explicit
constructor.  Add some specific functions to handle a QRect being
passed to a function where a MythRect was expected.  These new
functions simplify the necessary processing by eliminating QRect ->
MythRect ->QRect conversions.  Add a handful of explicit conversions
from QRect to MythRect.

Future work could include writing news MythUIType::SetArea and
MythUIType::SetMinArea functions that operate on a QRect. Adding these
will require adding similar override functions to every subclass that
redefines SetArea or SetMinArea. At this time it was simpler to add
the explicit conversions mentioned before.
  • Loading branch information
linuxdude42 committed Jul 22, 2020
1 parent 822a4f5 commit d6eb860
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 20 deletions.
2 changes: 1 addition & 1 deletion mythplugins/mythbrowser/mythbrowser/mythflashplayer.cpp
Expand Up @@ -51,7 +51,7 @@ bool MythFlashPlayer::Create(void)
{
if (!m_browser)
m_browser = new MythUIWebBrowser(this, "mythflashplayer");
m_browser->SetArea(GetMythMainWindow()->GetUIScreenRect());
m_browser->SetArea(MythRect(GetMythMainWindow()->GetUIScreenRect()));
m_browser->Init();
m_browser->SetActive(true);
m_browser->Show();
Expand Down
2 changes: 1 addition & 1 deletion mythplugins/mythbrowser/mythbrowser/webpage.cpp
Expand Up @@ -23,7 +23,7 @@ WebPage::WebPage(MythBrowser *parent, QRect area, const char* name)
MythUIButtonListItem::CantCheck, false);

m_browser = new MythUIWebBrowser(parent, name);
m_browser->SetArea(area);
m_browser->SetArea(MythRect(area));
m_browser->Init();

connect(m_browser, SIGNAL(loadStarted()),
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/captions/subtitlescreen.cpp
Expand Up @@ -50,7 +50,7 @@ class SubSimpleText : public MythUISimpleText, public SubWrapper
MythUIType *parent, const QString &name,
int whichImageCache, long long expireTime) :
MythUISimpleText(text, font, rect, align, parent, name),
SubWrapper(rect, expireTime, whichImageCache) {}
SubWrapper(MythRect(rect), expireTime, whichImageCache) {}
};

class SubShape : public MythUIShape, public SubWrapper
Expand Down Expand Up @@ -1821,7 +1821,7 @@ void SubtitleScreen::OptimiseDisplayedArea(void)
MythUIType *img = i.next();
auto *wrapper = dynamic_cast<SubWrapper *>(img);
if (wrapper && img->IsVisible())
img->SetArea(wrapper->GetOrigArea().translated(left, top));
img->SetArea(MythRect(wrapper->GetOrigArea().translated(left, top)));
}
}

Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/captions/teletextscreen.cpp
Expand Up @@ -138,7 +138,7 @@ void TeletextScreen::OptimiseDisplayedArea(void)
while (i.hasNext())
{
MythUIType *img = i.next();
img->SetArea(img->GetArea().translated(left, top));
img->SetArea(MythRect(img->GetArea().translated(left, top)));
}
}

Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/mheg/interactivescreen.cpp
Expand Up @@ -55,6 +55,6 @@ void InteractiveScreen::OptimiseDisplayedArea(void)
while (i.hasNext())
{
MythUIType *img = i.next();
img->SetArea(img->GetArea().translated(left, top));
img->SetArea(MythRect(img->GetArea().translated(left, top)));
}
}
56 changes: 48 additions & 8 deletions mythtv/libs/libmythui/mythrect.cpp
Expand Up @@ -11,6 +11,38 @@ MythRect::MythRect(const QString &sX, const QString &sY, const QString &sWidth,
setRect(sX,sY,sWidth,sHeight,baseRes);
}

/*
* An explicit assignment operator from QRect to MythRect. This
* takes the place of an implicitly converting from a QRect to a
* MythRect and then calling the compiler generated default
* assignment operator.
*/
MythRect& MythRect::operator= (const QRect& other)
{
if (this == &other)
return *this;

// Set coords from the point.
QRect::setX(other.x());
QRect::setY(other.y());
QRect::setWidth(other.width());
QRect::setHeight(other.height());

// Restore everything else to default.
m_percentWidth = 0.0F;
m_percentHeight = 0.0F;
m_percentX = 0.0F;
m_percentY = 0.0F;
m_offsetWidth = 0;
m_offsetHeight = 0;
m_offsetX = 0;
m_offsetY = 0;
m_needsUpdate = true;
m_parentArea = {0,0,0,0};

return *this;
};

bool MythRect::operator== (const MythRect &other) const
{
return ((m_percentWidth == other.m_percentWidth) &&
Expand All @@ -29,13 +61,12 @@ void MythRect::Reset(void)
m_parentArea.setRect(0, 0, 0, 0);
}

void MythRect::CalculateArea(const MythRect & parentArea)
void MythRect::CalculateArea(const QRect & parentArea)
{
QRect area = parentArea.toQRect();
if ((m_parentArea == area && !m_needsUpdate) || !parentArea.isValid())
if ((m_parentArea == parentArea && !m_needsUpdate) || !parentArea.isValid())
return;

m_parentArea = area;
m_parentArea = parentArea;

int w = width();
int h = height();
Expand Down Expand Up @@ -70,6 +101,11 @@ void MythRect::CalculateArea(const MythRect & parentArea)
m_needsUpdate = false;
}

void MythRect::CalculateArea(const MythRect & parentArea)
{
CalculateArea(parentArea.toQRect());
}

void MythRect::NormRect(void)
{

Expand Down Expand Up @@ -406,13 +442,12 @@ MythPoint& MythPoint::operator= (const QPoint& other)
return *this;
};

void MythPoint::CalculatePoint(const MythRect & parentArea)
void MythPoint::CalculatePoint(const QRect & parentArea)
{
QRect area = parentArea.toQRect();
if ((m_parentArea == area && !m_needsUpdate) || !parentArea.isValid())
if ((m_parentArea == parentArea && !m_needsUpdate) || !parentArea.isValid())
return;

m_parentArea = area;
m_parentArea = parentArea;

int X = x();
int Y = y();
Expand All @@ -429,6 +464,11 @@ void MythPoint::CalculatePoint(const MythRect & parentArea)
m_valid = true;
}

void MythPoint::CalculatePoint(const MythRect & parentArea)
{
CalculatePoint(parentArea.toQRect());
}

void MythPoint::NormPoint(void)
{
if (m_percentX == 0.0F)
Expand Down
5 changes: 4 additions & 1 deletion mythtv/libs/libmythui/mythrect.h
Expand Up @@ -23,11 +23,13 @@ class MUI_PUBLIC MythRect : public QRect
: QRect(x, y, width, height) {}
MythRect(const QString &sX, const QString &sY, const QString &sWidth,
const QString &sHeight, const QString &baseRes = QString());
MythRect(QRect rect)
explicit MythRect(QRect rect)
: QRect(rect) {}
MythRect& operator= (const QRect& other);
bool operator== (const MythRect &other) const;

void Reset(void);
void CalculateArea(const QRect & parentArea);
void CalculateArea(const MythRect & parentArea);

void NormRect(void);
Expand Down Expand Up @@ -98,6 +100,7 @@ class MUI_PUBLIC MythPoint : public QPoint
MythPoint& operator= (const QPoint& other);

bool isValid(void) const { return m_valid; }
void CalculatePoint(const QRect & parentArea);
void CalculatePoint(const MythRect & parentArea);

void NormPoint(void);
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythui/mythuisimpletext.cpp
Expand Up @@ -26,7 +26,7 @@ MythUISimpleText::MythUISimpleText(const QString &text,
m_Font(font),
m_Message(text.trimmed())
{
SetArea(rect);
SetArea(MythRect(rect));
m_Font = font;
}

Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythui/mythuitext.cpp
Expand Up @@ -67,7 +67,7 @@ MythUIText::MythUIText(const QString &text, const MythFontProperties &font,
m_textCursor = -1;
m_EnableInitiator = true;

MythUIText::SetArea(displayRect);
MythUIText::SetArea(MythRect(displayRect));
m_FontStates.insert("default", font);
*m_Font = m_FontStates["default"];
}
Expand Down Expand Up @@ -1022,7 +1022,7 @@ void MythUIText::FillCutMessage(void)
if (m_MinSize.isValid())
{
// Record the minimal area needed for the message.
SetMinArea(min_rect.toRect());
SetMinArea(MythRect(min_rect.toRect()));
}
}

Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythui/mythuitype.cpp
Expand Up @@ -850,7 +850,7 @@ void MythUIType::SetMinArea(const MythRect &rect)
m_Parent->SetMinAreaParent(m_MinArea, m_Area, this);
}

void MythUIType::ExpandArea(const MythRect &rect)
void MythUIType::ExpandArea(const QRect &rect)
{
QSize childSize = rect.size();
QSize size = m_Area.size();
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythui/mythuitype.h
Expand Up @@ -125,7 +125,7 @@ class MUI_PUBLIC MythUIType : public QObject, public XMLParseBase
virtual MythRect GetArea(void) const;
virtual MythRect GetFullArea(void) const;
virtual void RecalculateArea(bool recurse = true);
void ExpandArea(const MythRect &rect);
void ExpandArea(const QRect &rect);

virtual QRegion GetDirtyArea(void) const;

Expand Down

0 comments on commit d6eb860

Please sign in to comment.