diff options
-rw-r--r-- | src/skin/skincontext.cpp | 33 | ||||
-rw-r--r-- | src/skin/skincontext.h | 1 | ||||
-rw-r--r-- | src/skin/svgparser.cpp | 12 | ||||
-rw-r--r-- | src/skin/svgparser.h | 3 | ||||
-rw-r--r-- | src/widget/wpixmapstore.cpp | 26 | ||||
-rw-r--r-- | src/widget/wpixmapstore.h | 2 | ||||
-rw-r--r-- | src/widget/wpushbutton.cpp | 9 |
7 files changed, 79 insertions, 7 deletions
diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 64e4f2e754..c7024cfff9 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -233,3 +233,36 @@ QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { return pixmapPath; } + +QByteArray SkinContext::getPixmapBundle(const QDomNode& pixmapNode) const { + /**/ + QString pixmapPath, pixmapName; + const SvgParser* pSvgParser = new SvgParser(*this); + + if (!pixmapNode.isNull()) { + QDomNode svgNode = selectNode(pixmapNode, "svg"); + if (!svgNode.isNull()) { + // inline svg + pixmapPath = pSvgParser->saveToTempFile( + pSvgParser->parseSvgTree(svgNode) ); + } else { + // filename + pixmapName = nodeToString(pixmapNode); + if (!pixmapName.isEmpty()) { + pixmapName = getSkinPath(pixmapName); + if (pixmapName.endsWith(".svg", Qt::CaseInsensitive)) { + pixmapPath = pSvgParser->parseAsQByteArray(pixmapName); + } else { + pixmapPath = pixmapName; + } + } + } + } + + /**/ + QByteArray tmp; + return tmp; +} + + + diff --git a/src/skin/skincontext.h b/src/skin/skincontext.h index a6d3fb8805..0ef83dbb2b 100644 --- a/src/skin/skincontext.h +++ b/src/skin/skincontext.h @@ -61,6 +61,7 @@ class SkinContext { QString defaultValue) const; QString nodeToString(const QDomNode& node) const; QString getPixmapPath(const QDomNode& pixmapNode) const; + QByteArray getPixmapBundle(const QDomNode& pixmapNode) const; private: QString variableNodeToText(const QDomElement& element) const; diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 6953e93fc8..84d9548961 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -51,7 +51,7 @@ QString SvgParser::parseSvgFile(const QString& svgFileName) const { } } -QString SvgParser::parseSvgTree(const QDomNode& svgSkinNode) const { +QDomNode SvgParser::parseSvgTree(const QDomNode& svgSkinNode) const { // clone svg to don't alter xml input QDomNode svgNode = svgSkinNode.cloneNode(true); @@ -60,7 +60,8 @@ QString SvgParser::parseSvgTree(const QDomNode& svgSkinNode) const { parseScriptElements(svgNode); scanTree(svgNode, &SvgParser::parseAttributes); - return saveToTempFile(svgNode); + // return saveToTempFile(svgNode); + return svgNode; } QString SvgParser::saveToTempFile(const QDomNode& svgNode) const { @@ -86,6 +87,13 @@ QString SvgParser::saveToTempFile(const QDomNode& svgNode) const { return svgTempFileName; } +QByteArray SvgParser::saveToQByteArray(const QDomNode& svgNode) const { + QByteArray out; + QTextStream textStream(&out); + svgNode.save(textStream, 2); + return out; +} + // replaces Variables nodes in an svg dom tree void SvgParser::parseVariableElements(const QDomNode& svgNode) const { diff --git a/src/skin/svgparser.h b/src/skin/svgparser.h index 8a006fc225..bfef437b87 100644 --- a/src/skin/svgparser.h +++ b/src/skin/svgparser.h @@ -37,9 +37,10 @@ class SvgParser { void scanTree(const QDomNode& node, void (SvgParser::*callback)(const QDomNode& node)const) const; - QString parseSvgTree(const QDomNode& svgSkinNode) const; + QDomNode parseSvgTree(const QDomNode& svgSkinNode) const; QString parseSvgFile(const QString& svgFileName) const; QString saveToTempFile(const QDomNode& svgNode) const; + QByteArray parseToQByteArray(const QDomNode& svgNode) const; void parseVariableElements(const QDomNode& svgNode) const; diff --git a/src/widget/wpixmapstore.cpp b/src/widget/wpixmapstore.cpp index 5c4ad0acff..b354773340 100644 --- a/src/widget/wpixmapstore.cpp +++ b/src/widget/wpixmapstore.cpp @@ -68,6 +68,32 @@ Paintable::Paintable(const QString& fileName, DrawMode mode) } } +Paintable::Paintable(const QByteArray& pixmapData, DrawMode mode) + : m_draw_mode(mode) { + if (fileName.endsWith(".svg", Qt::CaseInsensitive)) { + if (mode == STRETCH) { + m_pSvg.reset(new QSvgRenderer(pixmapData)); + } else if (mode == TILE) { + // The SVG renderer doesn't directly support tiling, so we render + // it to a pixmap which will then get tiled. + QSvgRenderer renderer(pixmap); + QImage copy_buffer(renderer.defaultSize(), QImage::Format_ARGB32); + copy_buffer.fill(0x00000000); // Transparent black. + m_pPixmap.reset(new QPixmap(renderer.defaultSize())); + QPainter painter(©_buffer); + renderer.render(&painter); + m_pPixmap->convertFromImage(copy_buffer); + } else { + qWarning() << "Error, unknown drawing mode!"; + } + } else { + QPixmap * pPixmap = new QPixmap(); + pPixmap.loadFromData(pixmapData); + m_pPixmap.reset(pPixmap); + } +} + + bool Paintable::isNull() const { if (!m_pPixmap.isNull()) { return m_pPixmap->isNull(); diff --git a/src/widget/wpixmapstore.h b/src/widget/wpixmapstore.h index 6744a307b2..88d08c5b61 100644 --- a/src/widget/wpixmapstore.h +++ b/src/widget/wpixmapstore.h @@ -73,6 +73,8 @@ class WPixmapStore { public: static PaintablePointer getPaintable(const QString& fileName, Paintable::DrawMode mode); + static PaintablePointer getPaintable(const QByteArray& fileName, + Paintable::DrawMode mode); static QPixmap* getPixmapNoCache(const QString& fileName); static void setLoader(QSharedPointer<ImgSource> ld); diff --git a/src/widget/wpushbutton.cpp b/src/widget/wpushbutton.cpp index cccb6baab9..bac14aef5f 100644 --- a/src/widget/wpushbutton.cpp +++ b/src/widget/wpushbutton.cpp @@ -202,7 +202,8 @@ void WPushButton::setStates(int iStates) { m_align.resize(iStates); } -void WPushButton::setPixmap(int iState, bool bPressed, const QString& filename) { +// void WPushButton::setPixmap(int iState, bool bPressed, const QString& filename) { +template<typename pixmapBundle> void WPushButton::setPixmap(int iState, bool bPressed, const pixmapBundle sPixmapBundle) { QVector<PaintablePointer>& pixmaps = bPressed ? m_pressedPixmaps : m_unpressedPixmaps; @@ -210,13 +211,13 @@ void WPushButton::setPixmap(int iState, bool bPressed, const QString& filename) return; } - PaintablePointer pPixmap = WPixmapStore::getPaintable(filename, + PaintablePointer pPixmap = WPixmapStore::getPaintable(sPixmapBundle, Paintable::STRETCH); if (pPixmap.isNull() || pPixmap->isNull()) { // Only log if it looks like the user tried to specify a pixmap. - if (!filename.isEmpty()) { - qDebug() << "WPushButton: Error loading pixmap:" << filename; + if (!sPixmapBundle.isEmpty()) { + qDebug() << "WPushButton: Error loading pixmap:" << sPixmapBundle; } } else { // Set size of widget equal to pixmap size |