Construct full frame image using nodes inside FrameSVGItem

This commit is contained in:
David Edmundson 2014-07-14 18:44:33 +02:00
parent 9fc470089b
commit dcbcb8a490
2 changed files with 79 additions and 13 deletions

View File

@ -271,6 +271,15 @@ Plasma::FrameSvg *FrameSvgItem::frameSvg() const
return m_frameSvg; return m_frameSvg;
} }
SVGTextureNode* FrameSvgItem::createNode(QImage image)
{
auto node = new SVGTextureNode;
auto texture = window()->createTextureFromImage(image);
texture->setFiltering(QSGTexture::Nearest);
node->setTexture(texture);
return node;
}
QSGNode *FrameSvgItem::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) QSGNode *FrameSvgItem::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *)
{ {
if (!window() || !m_frameSvg || !m_frameSvg->hasElementPrefix(m_prefix)) { if (!window() || !m_frameSvg || !m_frameSvg->hasElementPrefix(m_prefix)) {
@ -278,23 +287,77 @@ QSGNode *FrameSvgItem::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaint
return Q_NULLPTR; return Q_NULLPTR;
} }
SVGTextureNode *textureNode = static_cast<SVGTextureNode *>(oldNode); if(!oldNode) { //FIXME or theme changed or enabled borders changed
if (!textureNode) { delete oldNode;
textureNode = new SVGTextureNode; oldNode = new QSGNode;
textureNode->setFiltering(QSGTexture::Nearest); //we're abusing transformOrigin enum here to get access to values
m_textureChanged = true; //force updating the texture on our newly created node //these MUST be uploaded in the same order
auto topLeft = createNode(m_frameSvg->image(QSize(5,5), "topleft"));
oldNode->appendChildNode(topLeft);
auto top = createNode(m_frameSvg->image(QSize(5,5), "top"));
oldNode->appendChildNode(top);
auto topRight = createNode(m_frameSvg->image(QSize(5,5), "topright"));
oldNode->appendChildNode(topRight);
auto left = createNode(m_frameSvg->image(QSize(5,5), "left"));
oldNode->appendChildNode(left);
auto center = createNode(m_frameSvg->image(QSize(5,5), "center"));
oldNode->appendChildNode(center);
auto right = createNode(m_frameSvg->image(QSize(5,5), "right"));
oldNode->appendChildNode(right);
auto bottomLeft = createNode(m_frameSvg->image(QSize(5,5), "bottomleft"));
oldNode->appendChildNode(bottomLeft);
auto bottom = createNode(m_frameSvg->image(QSize(5,5), "bottom"));
oldNode->appendChildNode(bottom);
auto bottomRight = createNode(m_frameSvg->image(QSize(5,5), "bottomright"));
oldNode->appendChildNode(bottomRight);
//set sizeDirty=true
} }
if (m_textureChanged || textureNode->texture()->textureSize() != m_frameSvg->size()) {
const QImage image = m_frameSvg->framePixmap().toImage(); //FIXME if (m_sizeDirty)
QSGTexture *texture = window()->createTextureFromImage(image); {
texture->setFiltering(QSGTexture::Nearest); //TODO cast root node add a convenience method on it?
textureNode->setTexture(texture);
m_textureChanged = false; static_cast<SVGTextureNode*>(oldNode->childAtIndex(Top))->setRect(5,0,width()-10, 5);
textureNode->setRect(0, 0, width(), height()); static_cast<SVGTextureNode*>(oldNode->childAtIndex(Left))->setRect(0,5, 5,height()-10);
static_cast<SVGTextureNode*>(oldNode->childAtIndex(Right))->setRect(width()-5,5,5,height()-10);
static_cast<SVGTextureNode*>(oldNode->childAtIndex(Bottom))->setRect(5,height()-5,width()-10,5);
static_cast<SVGTextureNode*>(oldNode->childAtIndex(TopLeft))->setRect(0,0,5,5);
static_cast<SVGTextureNode*>(oldNode->childAtIndex(TopRight))->setRect(width()-5,0,5,5);
static_cast<SVGTextureNode*>(oldNode->childAtIndex(BottomLeft))->setRect(0,height()-5, 5,5);
static_cast<SVGTextureNode*>(oldNode->childAtIndex(BottomRight))->setRect(width()-5,height()-5, 5, 5);
static_cast<SVGTextureNode*>(oldNode->childAtIndex(Center))->setRect(5,5, width()-10, height()-10);
//TODO sizeDirty = false
} }
return textureNode; // SVGTextureNode *textureNode = static_cast<SVGTextureNode *>(oldNode);
// if (!textureNode) {
// textureNode = new SVGTextureNode;
// textureNode->setFiltering(QSGTexture::Nearest);
// m_textureChanged = true; //force updating the texture on our newly created node
// }
//
// if (m_textureChanged || textureNode->texture()->textureSize() != m_frameSvg->size()) {
// const QImage image = m_frameSvg->framePixmap().toImage();
// QSGTexture *texture = window()->createTextureFromImage(image);
// texture->setFiltering(QSGTexture::Nearest);
// textureNode->setTexture(texture);
// m_textureChanged = false;
// textureNode->setRect(0, 0, width(), height());
// }
return oldNode;
} }
void FrameSvgItem::componentComplete() void FrameSvgItem::componentComplete()

View File

@ -31,6 +31,7 @@ namespace Plasma
{ {
class FrameSvg; class FrameSvg;
class SVGTextureNode;
class FrameSvgItemMargins : public QObject class FrameSvgItemMargins : public QObject
{ {
@ -182,6 +183,8 @@ private Q_SLOTS:
void updateDevicePixelRatio(); void updateDevicePixelRatio();
private: private:
SVGTextureNode *createNode(QImage image);
Plasma::FrameSvg *m_frameSvg; Plasma::FrameSvg *m_frameSvg;
FrameSvgItemMargins *m_margins; FrameSvgItemMargins *m_margins;
FrameSvgItemMargins *m_fixedMargins; FrameSvgItemMargins *m_fixedMargins;