Permalink
Browse files

Add the beginnings of a general purpose video widget.

At the moment it just allows you to pass a MythImage or QPixmap to display for
each frame and isn't very efficient but I'm sure it can be improved by someone
more familiar with the painters. It's what I've been using to test the
MythUI friendly visualisers in MythMusic.

Refs ticket 5763.
  • Loading branch information...
Paul Harrison
Paul Harrison committed Dec 19, 2010
1 parent 66defe9 commit 6fd38760e169222be2c38c9947e52758f36822e3
@@ -29,7 +29,7 @@ HEADERS += themeinfo.h mythxdisplay.h DisplayRes.h DisplayResScreen.h
HEADERS += mythgenerictree.h mythuibuttontree.h mythuiutils.h
HEADERS += mythvirtualkeyboard.h mythuishape.h mythuiguidegrid.h
HEADERS += mythrender_base.h mythfontmanager.h mythuieditbar.h
-HEADERS += mythdisplay.h
+HEADERS += mythdisplay.h mythuivideo.h
SOURCES = mythmainwindow.cpp mythpainter.cpp mythimage.cpp mythrect.cpp
SOURCES += myththemebase.cpp mythpainter_qimage.cpp mythpainter_yuva.cpp
@@ -46,7 +46,8 @@ SOURCES += themeinfo.cpp mythxdisplay.cpp DisplayRes.cpp DisplayResScreen.cpp
SOURCES += mythgenerictree.cpp mythuibuttontree.cpp mythuiutils.cpp
SOURCES += mythvirtualkeyboard.cpp mythuishape.cpp mythuiguidegrid.cpp
SOURCES += mythfontmanager.cpp mythuieditbar.cpp
-SOURCES += mythdisplay.cpp
+SOURCES += mythdisplay.cpp mythuivideo.cpp
+
inc.path = $${PREFIX}/include/mythtv/libmythui/
@@ -60,8 +61,9 @@ inc.files += mythuiclock.h mythgesture.h mythuitextedit.h mythprogressdialog.h
inc.files += mythuispinbox.h mythuicheckbox.h mythuibuttonlist.h mythuigroup.h
inc.files += mythuiprogressbar.h mythuiwebbrowser.h mythuiutils.h
inc.files += x11colors.h mythgenerictree.h mythuibuttontree.h
-inc.files += mythvirtualkeyboard.h mythuishape.h mythuiguidegrid.h
+inc.files += mythvirtualkeyboard.h mythuishape.h mythuiguidegrid.h
inc.files += mythuieditbar.h
+inc.files += mythuivideo.h
INSTALLS += inc
@@ -0,0 +1,131 @@
+// C/C++
+#include <cstdlib>
+
+// QT
+#include <QRect>
+#include <QDomDocument>
+
+// Libmythdb
+#include "mythverbose.h"
+
+// Mythui
+#include "mythpainter.h"
+#include "mythmainwindow.h"
+#include "mythuihelper.h"
+#include "mythscreentype.h"
+#include "mythuivideo.h"
+#include "mythimage.h"
+
+#define LOC QString("MythUIVideo(%1): ").arg((long long)this)
+#define LOC_ERR QString("MythUIVideo(%1) ERROR: ").arg((long long)this)
+#define LOC_WARN QString("MythUIVideo(%1) WARNING: ").arg((long long)this)
+
+MythUIVideo::MythUIVideo(MythUIType *parent, const QString &name)
+ : MythUIType(parent, name)
+{
+ m_image = NULL;
+ m_backgroundColor = QColor(Qt::black);
+}
+
+MythUIVideo::~MythUIVideo()
+{
+ if (m_image)
+ {
+ m_image->DownRef();
+ m_image = NULL;
+ }
+}
+
+/**
+ * \brief Reset the video back to the default defined in the theme
+ */
+void MythUIVideo::Reset(void)
+{
+ if (m_image)
+ {
+ m_image->DownRef();
+ m_image = NULL;
+ }
+ MythUIType::Reset();
+}
+
+void MythUIVideo::UpdateFrame(MythImage *image)
+{
+ if (m_image)
+ m_image->DownRef();
+
+ m_image = image;
+ m_image->UpRef();
+
+ SetRedraw();
+}
+
+void MythUIVideo::UpdateFrame(QPixmap *pixmap)
+{
+ if (m_image)
+ m_image->DownRef();
+
+ m_image = GetMythPainter()->GetFormatImage();
+ m_image->Assign(*pixmap);
+ m_image->UpRef();
+
+ SetRedraw();
+}
+
+/**
+ * \copydoc MythUIType::Pulse()
+ */
+void MythUIVideo::Pulse(void)
+{
+
+ MythUIType::Pulse();
+}
+
+/**
+ * \copydoc MythUIType::DrawSelf()
+ */
+void MythUIVideo::DrawSelf(MythPainter *p, int xoffset, int yoffset,
+ int alphaMod, QRect clipRect)
+{
+ QRect area = GetArea();
+ area.translate(xoffset, yoffset);
+
+ if (!m_image || m_image->isNull())
+ return;
+
+ if (m_image)
+ p->DrawImage(area.x(), area.y(), m_image, alphaMod);
+}
+
+/**
+ * \copydoc MythUIType::ParseElement()
+ */
+bool MythUIVideo::ParseElement(
+ const QString &filename, QDomElement &element, bool showWarnings)
+{
+ if (element.tagName() == "backgroundcolor")
+ {
+ m_backgroundColor = QColor(getFirstText(element));
+ }
+ else
+ return MythUIType::ParseElement(filename, element, showWarnings);
+
+ return true;
+}
+
+/**
+ * \copydoc MythUIType::CopyFrom()
+ */
+void MythUIVideo::CopyFrom(MythUIType *base)
+{
+ MythUIType::CopyFrom(base);
+}
+
+/**
+ * \copydoc MythUIType::CreateCopy()
+ */
+void MythUIVideo::CreateCopy(MythUIType *parent)
+{
+ MythUIVideo *im = new MythUIVideo(parent, objectName());
+ im->CopyFrom(this);
+}
@@ -0,0 +1,41 @@
+#ifndef MYTHUI_VIDEO_H_
+#define MYTHUI_VIDEO_H_
+
+#include <QString>
+#include <QColor>
+
+#include "mythuitype.h"
+
+/**
+ * \class MythUIVideo
+ *
+ * \brief Video widget, displays raw image data
+ */
+class MPUBLIC MythUIVideo : public MythUIType
+{
+ public:
+ MythUIVideo(MythUIType *parent, const QString &name);
+ ~MythUIVideo();
+
+ void UpdateFrame(MythImage *image);
+ void UpdateFrame(QPixmap *pixmap);
+
+ QColor GetBackgroundColor(void) { return m_backgroundColor; }
+
+ void Reset(void);
+ virtual void Pulse(void);
+
+ protected:
+ virtual void DrawSelf(MythPainter *p, int xoffset, int yoffset,
+ int alphaMod, QRect clipRect);
+
+ virtual bool ParseElement(
+ const QString &filename, QDomElement &element, bool showWarnings);
+ virtual void CopyFrom(MythUIType *base);
+ virtual void CreateCopy(MythUIType *parent);
+
+ MythImage *m_image;
+ QColor m_backgroundColor;
+};
+
+#endif
@@ -35,6 +35,7 @@
#include "mythuiguidegrid.h"
#include "mythuishape.h"
#include "mythuibuttontree.h"
+#include "mythuivideo.h"
#include "mythuieditbar.h"
#include "mythfontproperties.h"
@@ -352,7 +353,8 @@ void XMLParseBase::ParseChildren(const QString &filename,
type == "webbrowser" ||
type == "guidegrid" ||
type == "shape" ||
- type == "editbar")
+ type == "editbar" ||
+ type == "video")
{
ParseUIType(filename, info, type, parent, NULL, showWarnings);
}
@@ -452,6 +454,8 @@ MythUIType *XMLParseBase::ParseUIType(
uitype = new MythUIShape(parent, name);
else if (type == "editbar")
uitype = new MythUIEditBar(parent, name);
+ else if (type == "video")
+ uitype = new MythUIVideo(parent, name);
else if (type == "window" && parent == GetGlobalObjectStore())
uitype = new MythScreenType(parent, name);
else
@@ -538,7 +542,8 @@ MythUIType *XMLParseBase::ParseUIType(
info.tagName() == "webbrowser" ||
info.tagName() == "guidegrid" ||
info.tagName() == "shape" ||
- info.tagName() == "editbar")
+ info.tagName() == "editbar" ||
+ info.tagName() == "video")
{
ParseUIType(filename, info, info.tagName(),
uitype, screen, showWarnings);
@@ -724,7 +729,8 @@ bool XMLParseBase::doLoad(const QString &windowname,
type == "webbrowser" ||
type == "guidegrid" ||
type == "shape" ||
- type == "editbar")
+ type == "editbar" ||
+ type == "video")
{
ParseUIType(filename, e, type, parent, NULL, showWarnings);
}

0 comments on commit 6fd3876

Please sign in to comment.