Permalink
Browse files

Add multiple UI display dependencies support.

Operators supported are & (AND) and | (OR); priority are strictly from left to right. If a dependee doesn't exist, it's considered as in unvisible state rather than just ignored
  • Loading branch information...
jyavenard committed Jul 15, 2013
1 parent c95619a commit 640da5a98241fe4210b545cbb9e28f6942f8b638
Showing with 98 additions and 24 deletions.
  1. +89 −22 mythtv/libs/libmythui/mythuitype.cpp
  2. +9 −2 mythtv/libs/libmythui/mythuitype.h
@@ -47,7 +47,6 @@ MythUIType::MythUIType(QObject *parent, const QString &name)
m_XYSpeed = QPoint(0, 0);
m_deferload = false;
m_IsDependDefault = false;
m_ReverseDepend = false;
m_Parent = NULL;
@@ -1037,13 +1036,52 @@ void MythUIType::Refresh(void)
SetRedraw();
}
void MythUIType::UpdateDependState(bool isDefault)
void MythUIType::UpdateDependState(MythUIType *dependee, bool isDefault)
{
m_IsDependDefault = m_ReverseDepend ? !isDefault : isDefault;
bool visible;
if (dependee)
{
bool reverse = m_ReverseDepend[dependee];
visible = reverse ? !isDefault : isDefault;
for (int i = 0; i < m_dependsValue.size(); i++)
{
if (m_dependsValue[i].first != dependee)
continue;
m_dependsValue[i].second = visible;
break;
}
}
visible = m_dependsValue[0].second;
for (int i = 1; i < m_dependsValue.size(); i++)
{
bool v = m_dependsValue[i].second;
if (m_dependOperator[i-1] == 1)
{
// OR operator
visible = visible && v;
}
else
{
// AND operator
visible = visible || v;
}
}
m_IsDependDefault = visible;
SetVisible(!m_IsDependDefault);
}
void MythUIType::UpdateDependState(bool isDefault)
{
MythUIType *dependee = static_cast<MythUIType*>(sender());
UpdateDependState(dependee, isDefault);
}
void MythUIType::SetVisible(bool visible)
{
if (visible == m_Visible)
@@ -1159,7 +1197,6 @@ void MythUIType::CopyFrom(MythUIType *base)
}
m_dependsMap = base->m_dependsMap;
m_ReverseDepend = base->m_ReverseDepend;
SetMinArea(base->m_MinArea);
}
@@ -1372,34 +1409,64 @@ void MythUIType::SetDependsMap(QMap<QString, QString> dependsMap)
m_dependsMap = dependsMap;
}
void MythUIType::SetReverseDependence(bool reverse)
void MythUIType::SetReverseDependence(MythUIType *dependee, bool reverse)
{
m_ReverseDepend = reverse;
m_ReverseDepend.insert(dependee, reverse);
}
void MythUIType::ConnectDependants(bool recurse)
{
QMapIterator<QString, QString> i(m_dependsMap);
while(i.hasNext())
QMapIterator<QString, QString> it(m_dependsMap);
while(it.hasNext())
{
i.next();
QString dependeeName = i.value();
bool reverse = false;
if (dependeeName.startsWith('!'))
it.next();
// build list of operators and dependeees.
QStringList dependees;
QList<int> operators;
QString name = it.value();
QStringList tmp1 = name.split("&");
for (int i = 0; i < tmp1.size(); i++)
{
reverse = true;
dependeeName.remove(0,1);
QStringList tmp2 = tmp1[i].split("|");
dependees.append(tmp2[0]);
for (int j = 1; j < tmp2.size(); j++)
{
dependees.append(tmp2[j]);
operators.append(1); // 1 is OR
}
operators.append(2); // 2 is AND
}
MythUIType *dependee = GetChild(dependeeName);
MythUIType *dependant = GetChild(i.key());
if (dependee && dependant)
MythUIType *dependant = GetChild(it.key());
if (dependant)
{
QObject::connect(dependee, SIGNAL(DependChanged(bool)),
dependant, SLOT(UpdateDependState(bool)));
dependant->SetReverseDependence(reverse);
dependant->UpdateDependState(true);
dependant->m_dependOperator = operators;
foreach (QString dependeeName, dependees)
{
bool reverse = false;
if (dependeeName.startsWith('!'))
{
reverse = true;
dependeeName.remove(0,1);
}
MythUIType *dependee = GetChild(dependeeName);
if (dependee)
{
QObject::connect(dependee, SIGNAL(DependChanged(bool)),
dependant, SLOT(UpdateDependState(bool)));
dependant->SetReverseDependence(dependee, reverse);
dependant->m_dependsValue.append(QPair<MythUIType *, bool>(dependee, false));
dependant->UpdateDependState(dependee, true);
}
else
{
dependant->m_dependsValue.append(QPair<MythUIType *, bool>(dependee, !reverse));
dependant->UpdateDependState(dependee, reverse);
}
}
}
}
@@ -6,6 +6,7 @@
#include <QMap>
#include <QHash>
#include <QList>
#include <QPair>
#include <QFont>
#include <QColor>
@@ -174,7 +175,7 @@ class MUI_PUBLIC MythUIType : public QObject, public XMLParseBase
void SetVerticalZoom(float zoom);
void SetAngle(float angle);
void SetDependIsDefault(bool isDefault);
void SetReverseDependence(bool reverse);
void SetReverseDependence(MythUIType *dependee, bool reverse);
void SetDependsMap(QMap<QString, QString> dependsMap);
QMap<QString, QString> GetDependsMap() const { return m_dependsMap; }
@@ -190,6 +191,7 @@ class MUI_PUBLIC MythUIType : public QObject, public XMLParseBase
void Show(void);
void Refresh(void);
void UpdateDependState(bool isDefault);
void UpdateDependState(MythUIType *dependee, bool isDefault);
signals:
void RequestUpdate();
@@ -228,6 +230,11 @@ class MUI_PUBLIC MythUIType : public QObject, public XMLParseBase
QList<MythUIType *> m_ChildrenList;
QMap<QString, QString> m_dependsMap;
// the number of dependencies is assumed to be small (1 or 2 elements on average)
// so we use a QList as we want the element ordered in the order they were defined
// and speed isn't going to be a factor
QList< QPair<MythUIType *, bool> >m_dependsValue;
QList<int> m_dependOperator;
bool m_Visible;
bool m_HasFocus;
@@ -238,7 +245,7 @@ class MUI_PUBLIC MythUIType : public QObject, public XMLParseBase
bool m_Vanish;
bool m_Vanished;
bool m_IsDependDefault;
bool m_ReverseDepend;
QMap<MythUIType *, bool> m_ReverseDepend;
int m_focusOrder;

0 comments on commit 640da5a

Please sign in to comment.