From e613662ab57efe44f7ee138a9e0849e80c108595 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Tue, 22 Jul 2014 03:14:26 +0200 Subject: [PATCH] Make framesvg unit test pass Revert the changes in contentsRect, it was clearly not the best place to put the code that contains the code that computes the content size. Instead move the code in FrameSvgItem, duplicates data and code but works. --- autotests/framesvgtest.cpp | 2 - src/declarativeimports/core/framesvgitem.cpp | 41 ++++++++++++++++++-- src/plasma/framesvg.cpp | 7 ++-- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/autotests/framesvgtest.cpp b/autotests/framesvgtest.cpp index e6beb3653..b3b7b0a41 100644 --- a/autotests/framesvgtest.cpp +++ b/autotests/framesvgtest.cpp @@ -45,9 +45,7 @@ void FrameSvgTest::margins() void FrameSvgTest::contentsRect() { m_frameSvg->resizeFrame(QSize(100,100)); - QEXPECT_FAIL("", "contentsRect() is broken in master right now.", Continue); QCOMPARE(m_frameSvg->contentsRect(), QRectF(26, 26, 48, 48)); } QTEST_MAIN(FrameSvgTest) - diff --git a/src/declarativeimports/core/framesvgitem.cpp b/src/declarativeimports/core/framesvgitem.cpp index 8cd8edb91..9e9277ec0 100644 --- a/src/declarativeimports/core/framesvgitem.cpp +++ b/src/declarativeimports/core/framesvgitem.cpp @@ -37,6 +37,40 @@ namespace Plasma { +class FrameNode : public QSGNode +{ +public: + FrameNode(const QString& prefix, FrameSvg* svg) + : QSGNode() + , leftWidth(0) + , rightWidth(0) + , topHeight(0) + , bottomHeight(0) + { + if (svg->enabledBorders() & FrameSvg::LeftBorder) + leftWidth = svg->elementSize(prefix % "left").width(); + if (svg->enabledBorders() & FrameSvg::RightBorder) + rightWidth = svg->elementSize(prefix % "right").width(); + if (svg->enabledBorders() & FrameSvg::TopBorder) + topHeight = svg->elementSize(prefix % "top").height(); + if (svg->enabledBorders() & FrameSvg::BottomBorder) + bottomHeight = svg->elementSize(prefix % "bottom").height(); + } + + QRect contentsRect(const QSize& size) + { + const QSize contentSize(size.width() - leftWidth - rightWidth, size.height() - topHeight - bottomHeight); + + return QRect(QPoint(leftWidth, topHeight), contentSize); + } + +private: + int leftWidth; + int rightWidth; + int topHeight; + int bottomHeight; +}; + class FrameItemNode : public SVGTextureNode { public: @@ -399,9 +433,9 @@ QSGNode *FrameSvgItem::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaint } if (!oldNode) { - oldNode = new QSGNode; - QString prefix = m_frameSvg->actualPrefix(); + oldNode = new FrameNode(prefix, m_frameSvg); + bool tileCenter = (m_frameSvg->hasElement("hint-tile-center") || m_frameSvg->hasElement(prefix % "hint-tile-center")); bool stretchBorders = (m_frameSvg->hasElement("hint-stretch-borders") || m_frameSvg->hasElement(prefix % "hint-stretch-borders")); FrameItemNode::FitMode borderFitMode = stretchBorders ? FrameItemNode::Stretch : FrameItemNode::Tile; @@ -422,8 +456,9 @@ QSGNode *FrameSvgItem::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaint } if (m_sizeChanged) { + FrameNode* frameNode = static_cast(oldNode); QSize frameSize(width(), height()); - QRect geometry = m_frameSvg->contentsRect().toRect(); + QRect geometry = frameNode->contentsRect(frameSize); for(int i = 0; ichildCount(); ++i) { FrameItemNode* it = static_cast(oldNode->childAtIndex(i)); it->reposition(geometry, frameSize); diff --git a/src/plasma/framesvg.cpp b/src/plasma/framesvg.cpp index 3e1b9373d..1bb3510bb 100644 --- a/src/plasma/framesvg.cpp +++ b/src/plasma/framesvg.cpp @@ -475,9 +475,10 @@ void FrameSvg::getFixedMargins(qreal &left, qreal &top, qreal &right, qreal &bot QRectF FrameSvg::contentsRect() const { - QHash::const_iterator it = d->frames.constFind(d->prefix); - if (it != d->frames.constEnd()) { - return d->contentGeometry(*it, (*it)->frameSize); + FrameData* frame = d->frames.value(d->prefix); + if (frame) { + QRectF rect(QPoint(0,0), frame->frameSize); + return rect.adjusted(frame->leftMargin, frame->topMargin, -frame->rightMargin, -frame->bottomMargin); } else { return QRectF(); }