Skip to content

Commit 8dd7581

Browse files
committed
MythUI: Make buttonitem 'relative' offsets/sizes, relative to the buttonarea,
instead of the "full" area. This has no impact if absolute offset/sizes are used. Any existing theme that uses 'relative' offset/sizes for a button item, will need tweaked.
1 parent bf6ed42 commit 8dd7581

File tree

5 files changed

+59
-13
lines changed

5 files changed

+59
-13
lines changed

mythtv/libs/libmythui/mythuibuttonlist.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1565,6 +1565,13 @@ QVariant MythUIButtonList::GetDataValue() const
15651565
return QVariant();
15661566
}
15671567

1568+
MythRect MythUIButtonList::GetButtonArea(void) const
1569+
{
1570+
if (m_contentsRect.isValid())
1571+
return m_contentsRect;
1572+
return m_Area;
1573+
}
1574+
15681575
MythUIButtonListItem *MythUIButtonList::GetItemFirst() const
15691576
{
15701577
if (!m_itemList.empty())
@@ -2500,14 +2507,29 @@ void MythUIButtonList::CalculateVisibleItems(void)
25002507
m_itemsVisible = m_columns * m_rows;
25012508
}
25022509

2510+
void MythUIButtonList::SetButtonArea(const MythRect &rect)
2511+
{
2512+
if (rect == m_contentsRect)
2513+
return;
2514+
2515+
m_contentsRect = rect;
2516+
2517+
if (m_Area.isValid())
2518+
m_contentsRect.CalculateArea(m_Area);
2519+
else if (m_Parent)
2520+
m_contentsRect.CalculateArea(m_Parent->GetFullArea());
2521+
else
2522+
m_contentsRect.CalculateArea(GetMythMainWindow()->GetUIScreenRect());
2523+
}
2524+
25032525
/**
25042526
* \copydoc MythUIType::ParseElement()
25052527
*/
25062528
bool MythUIButtonList::ParseElement(
25072529
const QString &filename, QDomElement &element, bool showWarnings)
25082530
{
25092531
if (element.tagName() == "buttonarea")
2510-
m_contentsRect = parseRect(element);
2532+
SetButtonArea(parseRect(element));
25112533
else if (element.tagName() == "layout")
25122534
{
25132535
QString layout = getFirstText(element).toLower();

mythtv/libs/libmythui/mythuibuttonlist.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class MUI_PUBLIC MythUIButtonList : public MythUIType
142142
virtual int GetIntValue() const;
143143
virtual QString GetValue() const;
144144
QVariant GetDataValue() const;
145+
MythRect GetButtonArea(void) const;
145146

146147
void SetItemCurrent(MythUIButtonListItem* item);
147148
void SetItemCurrent(int pos, int topPos = -1);
@@ -239,6 +240,7 @@ class MUI_PUBLIC MythUIButtonList : public MythUIType
239240
virtual void CalculateVisibleItems(void);
240241
virtual QPoint GetButtonPosition(int column, int row) const;
241242

243+
void SetButtonArea(const MythRect &rect);
242244
virtual bool ParseElement(
243245
const QString &filename, QDomElement &element, bool showWarnings);
244246
virtual void CopyFrom(MythUIType *base);

mythtv/libs/libmythui/mythuistatetype.cpp

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
21
// Own header
32
#include "mythuistatetype.h"
3+
#include "mythuibuttonlist.h"
44

55
// Qt headers
66
#include <QDomDocument>
@@ -48,11 +48,7 @@ bool MythUIStateType::AddObject(const QString &name, MythUIType *object)
4848
m_ObjectsByName[key] = object;
4949

5050
MythRect objectArea = object->GetArea();
51-
52-
if (m_Parent)
53-
objectArea.CalculateArea(m_Parent->GetFullArea());
54-
else
55-
objectArea.CalculateArea(GetMythMainWindow()->GetUIScreenRect());
51+
objectArea.CalculateArea(m_ParentArea);
5652

5753
ExpandArea(objectArea);
5854

@@ -81,11 +77,7 @@ bool MythUIStateType::AddObject(StateType type, MythUIType *object)
8177
m_ObjectsByState[(int)type] = object;
8278

8379
MythRect objectArea = object->GetArea();
84-
85-
if (m_Parent)
86-
objectArea.CalculateArea(m_Parent->GetFullArea());
87-
else
88-
objectArea.CalculateArea(GetMythMainWindow()->GetUIScreenRect());
80+
objectArea.CalculateArea(m_ParentArea);
8981

9082
ExpandArea(objectArea);
9183

@@ -342,3 +334,31 @@ void MythUIStateType::LoadNow(void)
342334
MythUIType::LoadNow();
343335
}
344336

337+
void MythUIStateType::RecalculateArea(bool recurse)
338+
{
339+
if (m_Parent)
340+
{
341+
if (objectName().startsWith("buttonlist button"))
342+
{
343+
MythUIButtonList *list = dynamic_cast<MythUIButtonList *>(m_Parent);
344+
m_ParentArea = list->GetButtonArea();
345+
}
346+
else
347+
m_ParentArea = m_Parent->GetFullArea();
348+
}
349+
else
350+
m_ParentArea = GetMythMainWindow()->GetUIScreenRect();
351+
352+
m_Area.CalculateArea(m_ParentArea);
353+
354+
if (recurse)
355+
{
356+
QList<MythUIType *>::iterator it;
357+
358+
for (it = m_ChildrenList.begin(); it != m_ChildrenList.end(); ++it)
359+
{
360+
(*it)->RecalculateArea(recurse);
361+
}
362+
}
363+
}
364+

mythtv/libs/libmythui/mythuistatetype.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class MUI_PUBLIC MythUIStateType : public MythUIType
4848
void EnsureStateLoaded(StateType type);
4949

5050
virtual void LoadNow(void);
51+
virtual void RecalculateArea(bool recurse = true);
5152

5253
protected:
5354
virtual bool ParseElement(
@@ -60,6 +61,7 @@ class MUI_PUBLIC MythUIStateType : public MythUIType
6061
QMap<int, MythUIType *> m_ObjectsByState;
6162

6263
MythUIType *m_CurrentState;
64+
MythRect m_ParentArea;
6365

6466
bool m_ShowEmpty;
6567

mythtv/themes/MythCenter-wide/base.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@
494494
<statetype name="buttonitem">
495495
<area>0,0,100%,100%</area>
496496
<state name="active">
497-
<area>0,0,-20,100%</area>
497+
<area>0,0,100%,100%</area>
498498
<shape name="background" from="basewidgetshape" />
499499
<textarea name="buttontext">
500500
<area>10,4,-40,-4</area>

0 commit comments

Comments
 (0)