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.
This commit is contained in:
Aleix Pol 2014-07-22 03:14:26 +02:00
parent 963a900e0e
commit e613662ab5
3 changed files with 42 additions and 8 deletions

View File

@ -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)

View File

@ -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<FrameNode*>(oldNode);
QSize frameSize(width(), height());
QRect geometry = m_frameSvg->contentsRect().toRect();
QRect geometry = frameNode->contentsRect(frameSize);
for(int i = 0; i<oldNode->childCount(); ++i) {
FrameItemNode* it = static_cast<FrameItemNode*>(oldNode->childAtIndex(i));
it->reposition(geometry, frameSize);

View File

@ -475,9 +475,10 @@ void FrameSvg::getFixedMargins(qreal &left, qreal &top, qreal &right, qreal &bot
QRectF FrameSvg::contentsRect() const
{
QHash<QString, FrameData *>::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();
}