Add overlay support to Plasma IconItem.

By default Plasma IconItem renders the icon without an overlay even when an overlay is required.
This fixes this.

REVIEW:128573
This commit is contained in:
Chinmoy Ranjan Pradhan 2016-08-02 21:43:30 +05:30
parent fbfcc4e914
commit 0abc67a99f
2 changed files with 44 additions and 1 deletions

View File

@ -19,7 +19,6 @@
*/
#include "iconitem.h"
#include <QDebug>
#include <QPaintEngine>
#include <QPainter>
@ -74,6 +73,9 @@ IconItem::IconItem(QQuickItem *parent)
connect(this, &QQuickItem::windowChanged,
this, &IconItem::schedulePixmapUpdate);
connect(this, SIGNAL(overlaysChanged()),
this, SLOT(schedulePixmapUpdate()));
//initialize implicit size to the Dialog size
setImplicitWidth(KIconLoader::global()->currentSize(KIconLoader::Dialog));
setImplicitHeight(KIconLoader::global()->currentSize(KIconLoader::Dialog));
@ -212,6 +214,22 @@ Plasma::Theme::ColorGroup IconItem::colorGroup() const
return m_colorGroup;
}
void IconItem::setOverlays(const QStringList &overlays)
{
if (overlays == m_overlays) {
return;
}
m_overlays = overlays;
emit overlaysChanged();
}
QStringList IconItem::overlays() const
{
return m_overlays;
}
bool IconItem::isActive() const
{
return m_active;
@ -451,6 +469,20 @@ void IconItem::loadPixmap()
return;
}
// Strangely KFileItem::overlays() returns empty string-values, so
// we need to check first whether an overlay must be drawn at all.
// It is more efficient to do it here, as KIconLoader::drawOverlays()
// assumes that an overlay will be drawn and has some additional
// setup time.
foreach (const QString& overlay, m_overlays) {
if (!overlay.isEmpty()) {
// There is at least one overlay, draw all overlays above m_pixmap
// and cancel the check
KIconLoader::global()->drawOverlays(m_overlays, result, KIconLoader::Desktop);
break;
}
}
if (!isEnabled()) {
result = KIconLoader::global()->iconEffect()->apply(result, KIconLoader::Desktop, KIconLoader::DisabledState);
} else if (m_active) {

View File

@ -60,6 +60,11 @@ class IconItem : public QQuickItem
*/
Q_PROPERTY(Plasma::Theme::ColorGroup colorGroup READ colorGroup WRITE setColorGroup NOTIFY colorGroupChanged)
/**
* Specifies the overlay(s) for this icon
*/
Q_PROPERTY(QStringList overlays READ overlays WRITE setOverlays NOTIFY overlaysChanged)
/**
* See QQuickItem::smooth
*/
@ -119,6 +124,9 @@ public:
void setColorGroup(Plasma::Theme::ColorGroup group);
Plasma::Theme::ColorGroup colorGroup() const;
void setOverlays(const QStringList &overlays);
QStringList overlays() const;
bool isActive() const;
void setActive(bool active);
@ -149,6 +157,7 @@ public:
void componentComplete() Q_DECL_OVERRIDE;
Q_SIGNALS:
void overlaysChanged();
void activeChanged();
void sourceChanged();
void smoothChanged();
@ -193,6 +202,8 @@ private:
QPixmap m_iconPixmap;
QPixmap m_oldIconPixmap;
QStringList m_overlays;
Plasma::Theme::ColorGroup m_colorGroup;
//animation on pixmap change