Skip to content

Commit

Permalink
Create MythUIComposite class.
Browse files Browse the repository at this point in the history
MythUIScreenType, MythUIGroup and MythUIStateType all inherit from it. It allows to use SetTextFromMap and templates on all those composite elements and their children objects.

Fixes #11680
  • Loading branch information
jyavenard committed Jul 14, 2013
1 parent 4633f01 commit c97bd58
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 71 deletions.
5 changes: 3 additions & 2 deletions mythtv/libs/libmythui/libmythui.pro
Expand Up @@ -42,7 +42,7 @@ HEADERS += mythdisplay.h mythuivideo.h mythudplistener.h
HEADERS += mythuiexp.h mythuisimpletext.h mythuistatetracker.h
HEADERS += mythuianimation.h mythuiscrollbar.h
HEADERS += mythuinotificationcenter.h mythuinotificationcenter_private.h
HEADERS += mythnotification.h
HEADERS += mythuicomposite.h mythnotification.h

SOURCES = mythmainwindow.cpp mythpainter.cpp mythimage.cpp mythrect.cpp
SOURCES += myththemebase.cpp mythpainter_qimage.cpp mythpainter_yuva.cpp
Expand All @@ -63,6 +63,7 @@ SOURCES += mythdisplay.cpp mythuivideo.cpp mythudplistener.cpp
SOURCES += mythuisimpletext.cpp mythuistatetracker.cpp
SOURCES += mythuianimation.cpp mythuiscrollbar.cpp
SOURCES += mythuinotificationcenter.cpp mythnotification.cpp
SOURCES += mythuicomposite.cpp

contains(QT_VERSION, ^4\\.[0-9]\\..*) {
SOURCES += mythuiwebbrowser.cpp
Expand All @@ -84,7 +85,7 @@ inc.files += mythvirtualkeyboard.h mythuishape.h mythuiguidegrid.h
inc.files += mythuieditbar.h mythuifilebrowser.h mythuivideo.h
inc.files += mythuiexp.h mythuisimpletext.h mythuiactions.h
inc.files += mythuistatetracker.h mythuianimation.h mythuiscrollbar.h
inc.files += mythuinotificationcenter.h mythnotification.h
inc.files += mythuinotificationcenter.h mythnotification.h mythuicomposite.h

INSTALLS += inc

Expand Down
61 changes: 3 additions & 58 deletions mythtv/libs/libmythui/mythscreentype.cpp
Expand Up @@ -14,6 +14,7 @@
#include "mythuihelper.h"
#include "mythprogressdialog.h"
#include "mythuigroup.h"
#include "mythuistatetype.h"
#include "mythlogging.h"

class SemaphoreLocker
Expand Down Expand Up @@ -55,7 +56,7 @@ class ScreenLoadTask : public QRunnable

MythScreenType::MythScreenType(
MythScreenStack *parent, const QString &name, bool fullscreen) :
MythUIType(parent, name), m_LoadLock(1)
MythUIComposite(parent, name), m_LoadLock(1)
{
m_FullScreen = fullscreen;
m_CurrentFocusWidget = NULL;
Expand All @@ -77,7 +78,7 @@ MythScreenType::MythScreenType(

MythScreenType::MythScreenType(
MythUIType *parent, const QString &name, bool fullscreen) :
MythUIType(parent, name), m_LoadLock(1)
MythUIComposite(parent, name), m_LoadLock(1)
{
m_FullScreen = fullscreen;
m_CurrentFocusWidget = NULL;
Expand Down Expand Up @@ -429,62 +430,6 @@ void MythScreenType::ShowMenu(void)
// Virtual
}

static void DoSetTextFromMap(MythUIType *UItype, InfoMap &infoMap)
{
QList<MythUIType *> *children = UItype->GetAllChildren();

MythUIText *textType;

QMutableListIterator<MythUIType *> i(*children);
while (i.hasNext())
{
MythUIType *type = i.next();

textType = dynamic_cast<MythUIText *> (type);
if (textType)
textType->SetTextFromMap(infoMap);

MythUIGroup *group = dynamic_cast<MythUIGroup *> (type);
if (group)
DoSetTextFromMap(type, infoMap);
}
}

void MythScreenType::SetTextFromMap(InfoMap &infoMap)
{
DoSetTextFromMap((MythUIType*) this, infoMap);
}

static void DoResetMap(MythUIType *UItype, InfoMap &infoMap)
{
if (infoMap.isEmpty())
return;

QList<MythUIType *> *children = UItype->GetAllChildren();

MythUIText *textType;
QMutableListIterator<MythUIType *> i(*children);
while (i.hasNext())
{
MythUIType *type = i.next();
if (!type->IsVisible())
continue;

textType = dynamic_cast<MythUIText *> (type);
if (textType && infoMap.contains(textType->objectName()))
textType->Reset();

MythUIGroup *group = dynamic_cast<MythUIGroup *> (type);
if (group)
DoResetMap(type, infoMap);
}
}

void MythScreenType::ResetMap(InfoMap &infoMap)
{
DoResetMap(this, infoMap);
}

bool MythScreenType::keyPressEvent(QKeyEvent *event)
{
if (m_CurrentFocusWidget && m_CurrentFocusWidget->keyPressEvent(event))
Expand Down
7 changes: 2 additions & 5 deletions mythtv/libs/libmythui/mythscreentype.h
@@ -1,7 +1,7 @@
#ifndef MYTHSCREEN_TYPE_H_
#define MYTHSCREEN_TYPE_H_

#include "mythuitype.h"
#include "mythuicomposite.h"
#include "mythuitext.h"
#include "mythuiutils.h"

Expand Down Expand Up @@ -37,7 +37,7 @@ class MUI_PUBLIC ScreenLoadCompletionEvent : public QEvent
*
* \ingroup MythUI_Widgets
*/
class MUI_PUBLIC MythScreenType : public MythUIType
class MUI_PUBLIC MythScreenType : public MythUIComposite
{
Q_OBJECT

Expand Down Expand Up @@ -77,9 +77,6 @@ class MUI_PUBLIC MythScreenType : public MythUIType
bool IsLoading(void) { return m_IsLoading; }
bool IsLoaded(void) { return m_IsLoaded; }

void SetTextFromMap(InfoMap &infoMap);
void ResetMap(InfoMap &infoMap);

virtual MythPainter *GetPainter(void);

public slots:
Expand Down
48 changes: 48 additions & 0 deletions mythtv/libs/libmythui/mythuicomposite.cpp
@@ -0,0 +1,48 @@
#include "mythuicomposite.h"
#include "mythuitext.h"

MythUIComposite::MythUIComposite(QObject *parent, const QString &name) :
MythUIType(parent, name)
{
}

void MythUIComposite::SetTextFromMap(InfoMap &infoMap)
{
QList<MythUIType *> *children = GetAllChildren();
QMutableListIterator<MythUIType *> i(*children);

while (i.hasNext())
{
MythUIType *type = i.next();

MythUIText *textType = dynamic_cast<MythUIText *> (type);
if (textType)
textType->SetTextFromMap(infoMap);

MythUIComposite *group = dynamic_cast<MythUIComposite *> (type);
if (group)
group->SetTextFromMap(infoMap);
}
}

void MythUIComposite::ResetMap(InfoMap &infoMap)
{
if (infoMap.isEmpty())
return;

QList<MythUIType *> *children = GetAllChildren();
QMutableListIterator<MythUIType *> i(*children);

while (i.hasNext())
{
MythUIType *type = i.next();

MythUIText *textType = dynamic_cast<MythUIText *> (type);
if (textType && infoMap.contains(textType->objectName()))
textType->Reset();

MythUIComposite *group = dynamic_cast<MythUIComposite *> (type);
if (group)
group->ResetMap(infoMap);
}
}
16 changes: 16 additions & 0 deletions mythtv/libs/libmythui/mythuicomposite.h
@@ -0,0 +1,16 @@
#ifndef __MythTV__mythuicomposite__
#define __MythTV__mythuicomposite__

#include "mythuitype.h"

class MUI_PUBLIC MythUIComposite : public MythUIType
{
public:
MythUIComposite(QObject *parent, const QString &name);
virtual ~MythUIComposite() { }

virtual void SetTextFromMap(InfoMap &infoMap);
virtual void ResetMap(InfoMap &infoMap);
};

#endif /* defined(__MythTV__mythuicomposite__) */
2 changes: 1 addition & 1 deletion mythtv/libs/libmythui/mythuigroup.cpp
Expand Up @@ -2,7 +2,7 @@
#include "mythuigroup.h"

MythUIGroup::MythUIGroup(MythUIType *parent, const QString &name)
: MythUIType(parent, name)
: MythUIComposite(parent, name)
{
}

Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythui/mythuigroup.h
@@ -1,14 +1,14 @@
#ifndef MYTHUI_GROUP_H_
#define MYTHUI_GROUP_H_

#include "mythuitype.h"
#include "mythuicomposite.h"

/** \class MythUIGroup
*
* \brief Create a group of widgets.
* \ingroup MythUI_Widgets
*/
class MUI_PUBLIC MythUIGroup : public MythUIType
class MUI_PUBLIC MythUIGroup : public MythUIComposite
{

public:
Expand Down
38 changes: 37 additions & 1 deletion mythtv/libs/libmythui/mythuistatetype.cpp
Expand Up @@ -12,7 +12,7 @@
#include "mythmainwindow.h"

MythUIStateType::MythUIStateType(MythUIType *parent, const QString &name)
: MythUIType(parent, name)
: MythUIComposite(parent, name)
{
m_CurrentState = NULL;
m_ShowEmpty = true;
Expand Down Expand Up @@ -387,3 +387,39 @@ void MythUIStateType::AdjustDependence(void)
}
emit DependChanged(true);
}

void MythUIStateType::SetTextFromMap(InfoMap &infoMap)
{
if (m_ObjectsByName.isEmpty() && m_ObjectsByState.isEmpty())
return;

QMap<QString, MythUIType *>::Iterator i;

for (i = m_ObjectsByName.begin(); i != m_ObjectsByName.end(); ++i)
{
MythUIType *type = i.value();

MythUIText *textType = dynamic_cast<MythUIText *> (type);
if (textType)
textType->SetTextFromMap(infoMap);

MythUIComposite *group = dynamic_cast<MythUIComposite *> (type);
if (group)
group->SetTextFromMap(infoMap);
}

QMap<int, MythUIType *>::Iterator j;

for (j = m_ObjectsByState.begin(); j != m_ObjectsByState.end(); ++j)
{
MythUIType *type = j.value();

MythUIText *textType = dynamic_cast<MythUIText *> (type);
if (textType)
textType->SetTextFromMap(infoMap);

MythUIComposite *group = dynamic_cast<MythUIComposite *> (type);
if (group)
group->SetTextFromMap(infoMap);
}
}
6 changes: 4 additions & 2 deletions mythtv/libs/libmythui/mythuistatetype.h
Expand Up @@ -4,7 +4,7 @@
#include <QString>
#include <QMap>

#include "mythuitype.h"
#include "mythuicomposite.h"
#include "mythimage.h"

/** \class MythUIStateType
Expand All @@ -18,7 +18,7 @@
*
* \ingroup MythUI_Widgets
*/
class MUI_PUBLIC MythUIStateType : public MythUIType
class MUI_PUBLIC MythUIStateType : public MythUIComposite
{
public:
enum StateType { None = 0, Off, Half, Full }; // Can be used for tri-state checks, two state toggles, etc.
Expand Down Expand Up @@ -50,6 +50,8 @@ class MUI_PUBLIC MythUIStateType : public MythUIType
virtual void LoadNow(void);
virtual void RecalculateArea(bool recurse = true);

virtual void SetTextFromMap(InfoMap &infoMap);

protected:
virtual bool ParseElement(
const QString &filename, QDomElement &element, bool showWarnings);
Expand Down

0 comments on commit c97bd58

Please sign in to comment.