Permalink
Browse files

Add a couple of jump points to show each widgets bounding rect and name.

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...
1 parent e887abe commit 7c0a23815b0cdc47b80aa9eb90909218118b4ee5 Paul Harrison committed Mar 5, 2011
@@ -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;
@@ -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);
@@ -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
@@ -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()
@@ -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)
@@ -6,6 +6,7 @@
#include <QMap>
#include <QList>
#include <QFont>
+#include <QColor>
#include "xmlparsebase.h"
#include "mythrect.h"
@@ -227,6 +228,8 @@ class MUI_PUBLIC MythUIType : public QObject, public XMLParseBase
bool m_deferload;
+ QColor m_BorderColor;
+
friend class XMLParseBase;
};
@@ -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"),
@@ -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);

0 comments on commit 7c0a238

Please sign in to comment.