SvgItem, IconItem: drop "smooth" property override, update node on change

Summary:
QQuickItem already has a "smooth" property, which was shadowed by the
custom ones with the same name. As the property was not part of public
symbols, but instead is dynamically looked up without the class name part
of the property, we just remove the custom versions and instead switch
all custom code to use the inherited property.

While doing that the code is also fixed to properly update the
textureNodes to the current value of the "smooth" property.
As well as not set the filtering only on the texture, when it is passed
to a texturenode which will set its own filtering state to the texture
right before the bind call and thus wipe any previous direct setting
of the filter mode on the texture.

This also changed the default to smooth=true for SvgItem, though
effectively smooth was always true, as the texturenode was hardcoded
to get a QSGTexture::Linear filtering (which, as said above, is forced
onto its texture, no matter what was otherwise set before).

Reviewers: #plasma, davidedmundson, mart

Reviewed By: #plasma, davidedmundson

Subscribers: kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D20510
This commit is contained in:
Friedrich W. H. Kossebau 2019-04-13 17:23:20 +02:00
parent 66063f7c94
commit 18a2ca50ab
4 changed files with 5 additions and 56 deletions

View File

@ -39,7 +39,6 @@ IconItem::IconItem(QQuickItem *parent)
: QQuickItem(parent), : QQuickItem(parent),
m_svgIcon(nullptr), m_svgIcon(nullptr),
m_status(Plasma::Svg::Normal), m_status(Plasma::Svg::Normal),
m_smooth(true),
m_active(false), m_active(false),
m_animated(true), m_animated(true),
m_usesPlasmaTheme(true), m_usesPlasmaTheme(true),
@ -320,20 +319,6 @@ void IconItem::setActive(bool active)
emit activeChanged(); emit activeChanged();
} }
void IconItem::setSmooth(const bool smooth)
{
if (smooth == m_smooth) {
return;
}
m_smooth = smooth;
update();
}
bool IconItem::smooth() const
{
return m_smooth;
}
bool IconItem::isAnimated() const bool IconItem::isAnimated() const
{ {
return m_animated; return m_animated;
@ -492,9 +477,9 @@ QSGNode* IconItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *update
delete oldNode; delete oldNode;
QSGTexture *source = window()->createTextureFromImage(m_oldIconPixmap.toImage(), QQuickWindow::TextureCanUseAtlas); QSGTexture *source = window()->createTextureFromImage(m_oldIconPixmap.toImage(), QQuickWindow::TextureCanUseAtlas);
source->setFiltering(m_smooth ? QSGTexture::Linear : QSGTexture::Nearest); source->setFiltering(smooth() ? QSGTexture::Linear : QSGTexture::Nearest);
QSGTexture *target = window()->createTextureFromImage(m_iconPixmap.toImage(), QQuickWindow::TextureCanUseAtlas); QSGTexture *target = window()->createTextureFromImage(m_iconPixmap.toImage(), QQuickWindow::TextureCanUseAtlas);
target->setFiltering(m_smooth ? QSGTexture::Linear : QSGTexture::Nearest); target->setFiltering(smooth() ? QSGTexture::Linear : QSGTexture::Nearest);
animatingNode = new FadingNode(source, target); animatingNode = new FadingNode(source, target);
m_sizeChanged = true; m_sizeChanged = true;
m_textureChanged = false; m_textureChanged = false;
@ -516,11 +501,11 @@ QSGNode* IconItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *update
if (!textureNode || m_textureChanged) { if (!textureNode || m_textureChanged) {
delete oldNode; delete oldNode;
textureNode = new ManagedTextureNode; textureNode = new ManagedTextureNode;
textureNode->setFiltering(m_smooth ? QSGTexture::Linear : QSGTexture::Nearest);
textureNode->setTexture(QSharedPointer<QSGTexture>(window()->createTextureFromImage(m_iconPixmap.toImage(), QQuickWindow::TextureCanUseAtlas))); textureNode->setTexture(QSharedPointer<QSGTexture>(window()->createTextureFromImage(m_iconPixmap.toImage(), QQuickWindow::TextureCanUseAtlas)));
m_sizeChanged = true; m_sizeChanged = true;
m_textureChanged = false; m_textureChanged = false;
} }
textureNode->setFiltering(smooth() ? QSGTexture::Linear : QSGTexture::Nearest);
if (m_sizeChanged) { if (m_sizeChanged) {
const QSize newSize = paintedSize(); const QSize newSize = paintedSize();

View File

@ -66,12 +66,6 @@ class IconItem : public QQuickItem
*/ */
Q_PROPERTY(QStringList overlays READ overlays WRITE setOverlays NOTIFY overlaysChanged) Q_PROPERTY(QStringList overlays READ overlays WRITE setOverlays NOTIFY overlaysChanged)
/**
* See QQuickItem::smooth
*/
//KF6 Remove, this just shadows QQuickItem::smooth
Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged)
/** /**
* Apply a visual indication that this icon is active. * Apply a visual indication that this icon is active.
* Typically used to indicate that it is hovered * Typically used to indicate that it is hovered
@ -141,9 +135,6 @@ public:
bool isActive() const; bool isActive() const;
void setActive(bool active); void setActive(bool active);
void setSmooth(const bool smooth);
bool smooth() const;
bool isAnimated() const; bool isAnimated() const;
void setAnimated(bool animated); void setAnimated(bool animated);

View File

@ -36,7 +36,6 @@ namespace Plasma
SvgItem::SvgItem(QQuickItem *parent) SvgItem::SvgItem(QQuickItem *parent)
: QQuickItem(parent), : QQuickItem(parent),
m_smooth(false),
m_textureChanged(false) m_textureChanged(false)
{ {
setFlag(QQuickItem::ItemHasContents, true); setFlag(QQuickItem::ItemHasContents, true);
@ -115,20 +114,6 @@ Plasma::Svg *SvgItem::svg() const
return m_svg.data(); return m_svg.data();
} }
void SvgItem::setSmooth(const bool smooth)
{
if (smooth == m_smooth) {
return;
}
m_smooth = smooth;
emit smoothChanged();
}
bool SvgItem::smooth() const
{
return m_smooth;
}
QSGNode *SvgItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) QSGNode *SvgItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData)
{ {
Q_UNUSED(updatePaintNodeData); Q_UNUSED(updatePaintNodeData);
@ -146,7 +131,6 @@ QSGNode *SvgItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updateP
ManagedTextureNode *textureNode = static_cast<ManagedTextureNode *>(oldNode); ManagedTextureNode *textureNode = static_cast<ManagedTextureNode *>(oldNode);
if (!textureNode) { if (!textureNode) {
textureNode = new ManagedTextureNode; textureNode = new ManagedTextureNode;
textureNode->setFiltering(QSGTexture::Linear);
m_textureChanged = true; m_textureChanged = true;
} }
@ -164,15 +148,14 @@ QSGNode *SvgItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updateP
} }
QSharedPointer<QSGTexture> texture(window()->createTextureFromImage(m_image, QQuickWindow::TextureCanUseAtlas)); QSharedPointer<QSGTexture> texture(window()->createTextureFromImage(m_image, QQuickWindow::TextureCanUseAtlas));
if (m_smooth) {
texture->setFiltering(QSGTexture::Linear);
}
textureNode->setTexture(texture); textureNode->setTexture(texture);
m_textureChanged = false; m_textureChanged = false;
textureNode->setRect(0, 0, width(), height()); textureNode->setRect(0, 0, width(), height());
} }
textureNode->setFiltering(smooth() ? QSGTexture::Linear : QSGTexture::Nearest);
return textureNode; return textureNode;
} }

View File

@ -60,11 +60,6 @@ class SvgItem : public QQuickItem
*/ */
Q_PROPERTY(QSizeF naturalSize READ naturalSize NOTIFY naturalSizeChanged) Q_PROPERTY(QSizeF naturalSize READ naturalSize NOTIFY naturalSizeChanged)
/**
* If true enable antialiasing in paint: default off, better quality but less performance.
*/
Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged)
public: public:
/// @cond INTERNAL_DOCS /// @cond INTERNAL_DOCS
@ -77,9 +72,6 @@ public:
void setSvg(Plasma::Svg *svg); void setSvg(Plasma::Svg *svg);
Plasma::Svg *svg() const; Plasma::Svg *svg() const;
void setSmooth(const bool smooth);
bool smooth() const;
QSizeF naturalSize() const; QSizeF naturalSize() const;
QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) override; QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) override;
@ -89,7 +81,6 @@ Q_SIGNALS:
void elementIdChanged(); void elementIdChanged();
void svgChanged(); void svgChanged();
void naturalSizeChanged(); void naturalSizeChanged();
void smoothChanged();
protected Q_SLOTS: protected Q_SLOTS:
/// @cond INTERNAL_DOCS /// @cond INTERNAL_DOCS
@ -104,7 +95,6 @@ private:
QPointer<Plasma::Svg> m_svg; QPointer<Plasma::Svg> m_svg;
QString m_elementID; QString m_elementID;
bool m_smooth;
bool m_textureChanged; bool m_textureChanged;
QImage m_image; QImage m_image;
}; };