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:
parent
fbfcc4e914
commit
0abc67a99f
@ -19,7 +19,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "iconitem.h"
|
#include "iconitem.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QPaintEngine>
|
#include <QPaintEngine>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
@ -74,6 +73,9 @@ IconItem::IconItem(QQuickItem *parent)
|
|||||||
connect(this, &QQuickItem::windowChanged,
|
connect(this, &QQuickItem::windowChanged,
|
||||||
this, &IconItem::schedulePixmapUpdate);
|
this, &IconItem::schedulePixmapUpdate);
|
||||||
|
|
||||||
|
connect(this, SIGNAL(overlaysChanged()),
|
||||||
|
this, SLOT(schedulePixmapUpdate()));
|
||||||
|
|
||||||
//initialize implicit size to the Dialog size
|
//initialize implicit size to the Dialog size
|
||||||
setImplicitWidth(KIconLoader::global()->currentSize(KIconLoader::Dialog));
|
setImplicitWidth(KIconLoader::global()->currentSize(KIconLoader::Dialog));
|
||||||
setImplicitHeight(KIconLoader::global()->currentSize(KIconLoader::Dialog));
|
setImplicitHeight(KIconLoader::global()->currentSize(KIconLoader::Dialog));
|
||||||
@ -212,6 +214,22 @@ Plasma::Theme::ColorGroup IconItem::colorGroup() const
|
|||||||
return m_colorGroup;
|
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
|
bool IconItem::isActive() const
|
||||||
{
|
{
|
||||||
return m_active;
|
return m_active;
|
||||||
@ -451,6 +469,20 @@ void IconItem::loadPixmap()
|
|||||||
return;
|
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()) {
|
if (!isEnabled()) {
|
||||||
result = KIconLoader::global()->iconEffect()->apply(result, KIconLoader::Desktop, KIconLoader::DisabledState);
|
result = KIconLoader::global()->iconEffect()->apply(result, KIconLoader::Desktop, KIconLoader::DisabledState);
|
||||||
} else if (m_active) {
|
} else if (m_active) {
|
||||||
|
@ -60,6 +60,11 @@ class IconItem : public QQuickItem
|
|||||||
*/
|
*/
|
||||||
Q_PROPERTY(Plasma::Theme::ColorGroup colorGroup READ colorGroup WRITE setColorGroup NOTIFY colorGroupChanged)
|
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
|
* See QQuickItem::smooth
|
||||||
*/
|
*/
|
||||||
@ -119,6 +124,9 @@ public:
|
|||||||
void setColorGroup(Plasma::Theme::ColorGroup group);
|
void setColorGroup(Plasma::Theme::ColorGroup group);
|
||||||
Plasma::Theme::ColorGroup colorGroup() const;
|
Plasma::Theme::ColorGroup colorGroup() const;
|
||||||
|
|
||||||
|
void setOverlays(const QStringList &overlays);
|
||||||
|
QStringList overlays() const;
|
||||||
|
|
||||||
bool isActive() const;
|
bool isActive() const;
|
||||||
void setActive(bool active);
|
void setActive(bool active);
|
||||||
|
|
||||||
@ -149,6 +157,7 @@ public:
|
|||||||
void componentComplete() Q_DECL_OVERRIDE;
|
void componentComplete() Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
|
void overlaysChanged();
|
||||||
void activeChanged();
|
void activeChanged();
|
||||||
void sourceChanged();
|
void sourceChanged();
|
||||||
void smoothChanged();
|
void smoothChanged();
|
||||||
@ -193,6 +202,8 @@ private:
|
|||||||
QPixmap m_iconPixmap;
|
QPixmap m_iconPixmap;
|
||||||
QPixmap m_oldIconPixmap;
|
QPixmap m_oldIconPixmap;
|
||||||
|
|
||||||
|
QStringList m_overlays;
|
||||||
|
|
||||||
Plasma::Theme::ColorGroup m_colorGroup;
|
Plasma::Theme::ColorGroup m_colorGroup;
|
||||||
|
|
||||||
//animation on pixmap change
|
//animation on pixmap change
|
||||||
|
Loading…
Reference in New Issue
Block a user