Skip to content

Commit

Permalink
Add a couple of jump points to show each widgets bounding rect and name.
Browse files Browse the repository at this point in the history
This is really only useful for developers or theme creators to help see
exactly the area a widget is occupying. It makes it easier to set out text
areas so they don't overlap other widgets for example.

The jump points are 'Toggle Show Widget Borders' and 'Toggle Show Widget Names'
and both are unbound by default.

The show names jump point will show the widgets name in the top left of the
widgets bounding box but only when show borders is turned on.
  • Loading branch information
Paul Harrison committed Mar 5, 2011
1 parent e887abe commit 7c0a238
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
15 changes: 14 additions & 1 deletion mythtv/libs/libmythui/mythpainter.h
Expand Up @@ -23,7 +23,8 @@ class MythImage;
class MUI_PUBLIC MythPainter
{
public:
MythPainter() : m_Parent(0), m_CacheSize(0) { }
MythPainter() : m_Parent(0), m_CacheSize(0),
m_showBorders(false), m_showNames(false) { }
virtual ~MythPainter();

virtual QString GetName(void) = 0;
Expand Down Expand Up @@ -62,6 +63,15 @@ class MUI_PUBLIC MythPainter
// make friend so only callable from image
virtual void DeleteFormatImage(MythImage *im);

void SetDebugMode(bool showBorders, bool showNames)
{
m_showBorders = showBorders;
m_showNames = showNames;
}

bool ShowBorders(void) { return m_showBorders; }
bool ShowTypeNames(void) { return m_showNames; }

protected:
virtual void DeleteFormatImagePriv(MythImage *im) { (void) im; }
void CheckFormatImage(MythImage *im);
Expand All @@ -73,6 +83,9 @@ class MUI_PUBLIC MythPainter
static int m_MaxCacheSize;
QList<MythImage*> m_allocatedImages;
QMutex m_allocationLock;

bool m_showBorders;
bool m_showNames;
};

#endif
16 changes: 16 additions & 0 deletions mythtv/libs/libmythui/mythuitype.cpp
Expand Up @@ -58,6 +58,8 @@ MythUIType::MythUIType(QObject *parent, const QString &name)
m_Fonts = new FontMap();
m_focusOrder = 0;
m_Painter = NULL;

m_BorderColor = QColor(rand() % 255, rand() % 255, rand() % 255);
}

MythUIType::~MythUIType()
Expand Down Expand Up @@ -452,6 +454,20 @@ void MythUIType::Draw(MythPainter *p, int xoffset, int yoffset, int alphaMod,
(*it)->Draw(p, xoffset + m_Area.x(), yoffset + m_Area.y(),
CalcAlpha(alphaMod), clipRect);
}

if (p->ShowBorders())
{
p->DrawRect(realArea, false, QColor(), true, 1, m_BorderColor);

if (p->ShowTypeNames())
{
MythFontProperties font;
font.SetFace(QFont("Droid Sans"));
font.SetColor(m_BorderColor);
font.SetPointSize(8);
p->DrawText(realArea, objectName(), 0, font, 255, realArea);
}
}
}

void MythUIType::SetPosition(int x, int y)
Expand Down
3 changes: 3 additions & 0 deletions mythtv/libs/libmythui/mythuitype.h
Expand Up @@ -6,6 +6,7 @@
#include <QMap>
#include <QList>
#include <QFont>
#include <QColor>

#include "xmlparsebase.h"
#include "mythrect.h"
Expand Down Expand Up @@ -227,6 +228,8 @@ class MUI_PUBLIC MythUIType : public QObject, public XMLParseBase

bool m_deferload;

QColor m_BorderColor;

friend class XMLParseBase;
};

Expand Down
23 changes: 23 additions & 0 deletions mythtv/programs/mythfrontend/main.cpp
Expand Up @@ -926,6 +926,24 @@ static void getScreenShot(void)
(void) GetMythMainWindow()->screenShot();
}

static void setDebugShowBorders(void)
{
MythPainter *p = GetMythPainter();
p->SetDebugMode(!p->ShowBorders(), p->ShowTypeNames());

if (GetMythMainWindow()->GetMainStack()->GetTopScreen())
GetMythMainWindow()->GetMainStack()->GetTopScreen()->SetRedraw();
}

static void setDebugShowNames(void)
{
MythPainter *p = GetMythPainter();
p->SetDebugMode(p->ShowBorders(), !p->ShowTypeNames());

if (GetMythMainWindow()->GetMainStack()->GetTopScreen())
GetMythMainWindow()->GetMainStack()->GetTopScreen()->SetRedraw();
}

static void InitJumpPoints(void)
{
REG_JUMP(QT_TRANSLATE_NOOP("MythControls", "Reload Theme"),
Expand Down Expand Up @@ -961,6 +979,11 @@ static void InitJumpPoints(void)
REG_JUMPEX(QT_TRANSLATE_NOOP("MythControls", "ScreenShot"),
"", "", getScreenShot, false);

REG_JUMPEX(QT_TRANSLATE_NOOP("MythControls", "Toggle Show Widget Borders"),
"", "", setDebugShowBorders, false);
REG_JUMPEX(QT_TRANSLATE_NOOP("MythControls", "Toggle Show Widget Names"),
"", "", setDebugShowNames, false);

TV::InitKeys();

TV::SetFuncPtr("playbackbox", (void *)PlaybackBox::RunPlaybackBox);
Expand Down

0 comments on commit 7c0a238

Please sign in to comment.