plasma: drop support for setting image instead of icon for widgets

mixing the usual icons with svg icons makes things look different, does it
not?

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-05-23 10:10:13 +03:00
parent 2ee9256d1a
commit b8325fec7e
13 changed files with 35 additions and 650 deletions

View file

@ -882,7 +882,7 @@ void Applet::setConfigurationRequired(bool needsConfig, const QString &reason)
PushButton *configWidget = new PushButton(d->messageOverlay);
if (!qobject_cast<Plasma::PopupApplet *>(this) && (formFactor() == Plasma::Horizontal || formFactor() == Plasma::Vertical)) {
configWidget->setImage("widgets/configuration-icons", "configure");
configWidget->setIcon(KIcon("configure"));
configWidget->setMaximumSize(24,24);
configWidget->setMinimumSize(24,24);
} else {

View file

@ -20,14 +20,8 @@
#include "checkbox.h"
#include <QCheckBox>
#include <QPainter>
#include <QDir>
#include <kmimetype.h>
#include "private/themedwidgetinterface_p.h"
#include "svg.h"
#include "theme.h"
namespace Plasma
{
@ -36,49 +30,9 @@ class CheckBoxPrivate : public ThemedWidgetInterface<CheckBox>
{
public:
CheckBoxPrivate(CheckBox *c)
: ThemedWidgetInterface<CheckBox>(c),
svg(nullptr)
: ThemedWidgetInterface<CheckBox>(c)
{
}
~CheckBoxPrivate()
{
delete svg;
}
void setPixmap()
{
if (imagePath.isEmpty()) {
delete svg;
svg = nullptr;
return;
}
KMimeType::Ptr mime = KMimeType::findByUrl(KUrl(absImagePath));
QPixmap pm(q->size().toSize());
if (mime->is("image/svg+xml") || mime->is("image/svg+xml-compressed")) {
if (!svg || svg->imagePath() != imagePath) {
delete svg;
svg = new Svg();
svg->setImagePath(imagePath);
QObject::connect(svg, SIGNAL(repaintNeeded()), q, SLOT(setPixmap()));
}
QPainter p(&pm);
svg->paint(&p, pm.rect());
} else {
delete svg;
svg = nullptr;
pm = QPixmap(absImagePath);
}
static_cast<QCheckBox*>(q->widget())->setIcon(QIcon(pm));
}
QString imagePath;
QString absImagePath;
Svg *svg;
};
CheckBox::CheckBox(QGraphicsWidget *parent)
@ -101,37 +55,12 @@ CheckBox::~CheckBox()
void CheckBox::setText(const QString &text)
{
static_cast<QCheckBox*>(widget())->setText(text);
nativeWidget()->setText(text);
}
QString CheckBox::text() const
{
return static_cast<QCheckBox*>(widget())->text();
}
void CheckBox::setImage(const QString &path)
{
if (d->imagePath == path) {
return;
}
delete d->svg;
d->svg = nullptr;
d->imagePath = path;
const bool absolutePath = (!path.isEmpty() && path[0] == '/');
if (absolutePath) {
d->absImagePath = path;
} else {
d->absImagePath = Theme::defaultTheme()->imagePath(path);
}
d->setPixmap();
}
QString CheckBox::image() const
{
return d->imagePath;
return nativeWidget()->text();
}
QCheckBox *CheckBox::nativeWidget() const
@ -139,20 +68,14 @@ QCheckBox *CheckBox::nativeWidget() const
return static_cast<QCheckBox*>(widget());
}
void CheckBox::resizeEvent(QGraphicsSceneResizeEvent *event)
{
d->setPixmap();
QGraphicsProxyWidget::resizeEvent(event);
}
void CheckBox::setChecked(bool checked)
{
static_cast<QCheckBox*>(widget())->setChecked(checked);
nativeWidget()->setChecked(checked);
}
bool CheckBox::isChecked() const
{
return static_cast<QCheckBox*>(widget())->isChecked();
return nativeWidget()->isChecked();
}
void CheckBox::changeEvent(QEvent *event)

View file

@ -40,7 +40,6 @@ class PLASMA_EXPORT CheckBox : public QGraphicsProxyWidget
{
Q_OBJECT
Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(QString image READ image WRITE setImage)
Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggled)
public:
@ -59,18 +58,6 @@ public:
*/
QString text() const;
/**
* Sets the path to an image to display.
*
* @param path the path to the image; if a relative path, then a themed image will be loaded.
*/
void setImage(const QString &path);
/**
* @return the image path being displayed currently, or an empty string if none.
*/
QString image() const;
/**
* @return the native widget wrapped by this CheckBox
*/
@ -92,12 +79,10 @@ Q_SIGNALS:
void toggled(bool);
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
void changeEvent(QEvent *event);
private:
Q_PRIVATE_SLOT(d, void setPalette())
Q_PRIVATE_SLOT(d, void setPixmap())
CheckBoxPrivate * const d;
};

View file

@ -20,20 +20,11 @@
#include "label.h"
#include <QApplication>
#include <QDir>
#include <QtGui/qgraphicssceneevent.h>
#include <QGraphicsSceneContextMenuEvent>
#include <QLabel>
#include <QMenu>
#include <QPainter>
#include <QtGui/qstyleoption.h>
#include <kcolorscheme.h>
#include <kglobalsettings.h>
#include <kmimetype.h>
#include <QIcon>
#include "private/themedwidgetinterface_p.h"
#include "svg.h"
#include "theme.h"
namespace Plasma
{
@ -42,49 +33,9 @@ class LabelPrivate : public ThemedWidgetInterface<Label>
{
public:
LabelPrivate(Label *label)
: ThemedWidgetInterface<Label>(label),
svg(nullptr)
: ThemedWidgetInterface<Label>(label)
{
}
~LabelPrivate()
{
delete svg;
}
void setPixmap()
{
if (imagePath.isEmpty()) {
delete svg;
svg = nullptr;
return;
}
KMimeType::Ptr mime = KMimeType::findByUrl(KUrl(absImagePath));
QPixmap pm(q->size().toSize());
if (mime->is("image/svg+xml") || mime->is("image/svg+xml-compressed")) {
if (!svg || svg->imagePath() != absImagePath) {
delete svg;
svg = new Svg();
svg->setImagePath(imagePath);
QObject::connect(svg, SIGNAL(repaintNeeded()), q, SLOT(setPixmap()));
}
QPainter p(&pm);
svg->paint(&p, pm.rect());
} else {
delete svg;
svg = nullptr;
pm = QPixmap(absImagePath);
}
q->nativeWidget()->setPixmap(pm);
}
QString imagePath;
QString absImagePath;
Svg *svg;
};
Label::Label(QGraphicsWidget *parent)
@ -121,31 +72,6 @@ QString Label::text() const
return nativeWidget()->text();
}
void Label::setImage(const QString &path)
{
if (d->imagePath == path) {
return;
}
delete d->svg;
d->svg = nullptr;
d->imagePath = path;
const bool absolutePath = (!path.isEmpty() && path[0] == '/');
if (absolutePath) {
d->absImagePath = path;
} else {
d->absImagePath = Theme::defaultTheme()->imagePath(path);
}
d->setPixmap();
}
QString Label::image() const
{
return d->imagePath;
}
void Label::setScaledContents(bool scaled)
{
nativeWidget()->setScaledContents(scaled);
@ -195,12 +121,6 @@ void Label::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
}
}
void Label::resizeEvent(QGraphicsSceneResizeEvent *event)
{
d->setPixmap();
QGraphicsProxyWidget::resizeEvent(event);
}
void Label::changeEvent(QEvent *event)
{
d->changeEvent(event);

View file

@ -40,7 +40,6 @@ class PLASMA_EXPORT Label : public QGraphicsProxyWidget
{
Q_OBJECT
Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(QString image READ image WRITE setImage)
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
Q_PROPERTY(bool hasScaledContents READ hasScaledContents WRITE setScaledContents)
Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap)
@ -66,18 +65,6 @@ public:
*/
QString text() const;
/**
* Sets the path to an image to display.
*
* @param path the path to the image; if a relative path, then a themed image will be loaded.
*/
void setImage(const QString &path);
/**
* @return the image path being displayed currently, or an empty string if none.
*/
QString image() const;
/**
* Sets the alignment for the text
*
@ -140,7 +127,6 @@ Q_SIGNALS:
void linkHovered(const QString &link);
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
void changeEvent(QEvent *event);
bool event(QEvent *event);
QVariant itemChange(GraphicsItemChange change, const QVariant & value);
@ -149,7 +135,6 @@ protected:
private:
Q_PRIVATE_SLOT(d, void setPalette())
Q_PRIVATE_SLOT(d, void setPixmap())
LabelPrivate * const d;
};

View file

@ -19,23 +19,10 @@
*/
#include "pushbutton.h"
#include <QDir>
#include <QPainter>
#include <QtGui/qstyleoption.h>
#include <QtCore/qsharedpointer.h>
#include <kicon.h>
#include <kiconeffect.h>
#include <kmimetype.h>
#include <kpushbutton.h>
#include "animator.h"
#include "framesvg.h"
#include "paintutils.h"
#include "private/actionwidgetinterface_p.h"
#include "private/themedwidgetinterface_p.h"
#include "theme.h"
#include <kpushbutton.h>
namespace Plasma
{
@ -44,64 +31,9 @@ class PushButtonPrivate : public ActionWidgetInterface<PushButton>
{
public:
PushButtonPrivate(PushButton *pushButton)
: ActionWidgetInterface<PushButton>(pushButton),
svg(nullptr)
: ActionWidgetInterface<PushButton>(pushButton)
{
}
~PushButtonPrivate()
{
delete svg;
}
void setPixmap()
{
if (imagePath.isEmpty()) {
delete svg;
svg = nullptr;
return;
}
KMimeType::Ptr mime = KMimeType::findByUrl(KUrl(absImagePath));
QPixmap pm;
if (mime->is("image/svg+xml") || mime->is("image/svg+xml-compressed")) {
if (!svg || svg->imagePath() != absImagePath) {
delete svg;
svg = new Svg();
svg->setImagePath(imagePath);
QObject::connect(svg, SIGNAL(repaintNeeded()), q, SLOT(setPixmap()));
if (!svgElement.isNull()) {
svg->setContainsMultipleImages(true);
}
}
//QPainter p(&pm);
if (!svgElement.isEmpty() && svg->hasElement(svgElement)) {
svg->resize();
QSizeF elementSize = svg->elementSize(svgElement);
float scale = q->nativeWidget()->iconSize().width() / qMax(elementSize.width(), elementSize.height());
svg->resize(elementSize * scale);
pm = svg->pixmap(svgElement);
} else {
svg->resize(q->nativeWidget()->iconSize());
pm = svg->pixmap();
}
} else {
delete svg;
svg = nullptr;
pm = QPixmap(absImagePath);
}
static_cast<KPushButton*>(q->widget())->setIcon(KIcon(pm));
}
QString imagePath;
QString absImagePath;
Svg *svg;
QString svgElement;
};
@ -131,44 +63,13 @@ PushButton::~PushButton()
void PushButton::setText(const QString &text)
{
static_cast<KPushButton*>(widget())->setText(text);
nativeWidget()->setText(text);
updateGeometry();
}
QString PushButton::text() const
{
return static_cast<KPushButton*>(widget())->text();
}
void PushButton::setImage(const QString &path)
{
if (d->imagePath == path) {
return;
}
delete d->svg;
d->svg = nullptr;
d->imagePath = path;
const bool absolutePath = (!path.isEmpty() && path[0] == '/');
if (absolutePath) {
d->absImagePath = path;
} else {
d->absImagePath = Theme::defaultTheme()->imagePath(path);
}
d->setPixmap();
}
void PushButton::setImage(const QString &path, const QString &elementid)
{
d->svgElement = elementid;
setImage(path);
}
QString PushButton::image() const
{
return d->imagePath;
return nativeWidget()->text();
}
void PushButton::setAction(QAction *action)
@ -231,12 +132,6 @@ KPushButton *PushButton::nativeWidget() const
return static_cast<KPushButton*>(widget());
}
void PushButton::resizeEvent(QGraphicsSceneResizeEvent *event)
{
d->setPixmap();
QGraphicsProxyWidget::resizeEvent(event);
}
void PushButton::changeEvent(QEvent *event)
{
d->changeEvent(event);

View file

@ -22,12 +22,11 @@
#include <QtGui/QGraphicsProxyWidget>
#include <plasma/plasma_export.h>
#include <kicon.h>
class KPushButton;
#include <plasma/plasma_export.h>
namespace Plasma
{
@ -42,7 +41,6 @@ class PLASMA_EXPORT PushButton : public QGraphicsProxyWidget
{
Q_OBJECT
Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(QString image READ image WRITE setImage)
Q_PROPERTY(QAction *action READ action WRITE setAction)
Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable)
@ -65,28 +63,6 @@ public:
*/
QString text() const;
/**
* Sets the path to an image to display.
*
* @param path the path to the image; if a relative path, then a themed image will be loaded.
*/
void setImage(const QString &path);
/**
* Sets the path to an svg image to display and the id of the used svg element, if necessary.
*
* @param path the path to the image; if a relative path, then a themed image will be loaded.
* @param elementid the id of a svg element.
*
* @since 4.4
*/
void setImage(const QString &path, const QString &elementid);
/**
* @return the image path being displayed currently, or an empty string if none.
*/
QString image() const;
/**
* Associate an action with this PushButton
* this makes the button follow the state of the action, using its icon, text, etc.
@ -201,11 +177,9 @@ public Q_SLOTS:
void setChecked(bool checked);
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
void changeEvent(QEvent *event);
private:
Q_PRIVATE_SLOT(d, void setPixmap())
Q_PRIVATE_SLOT(d, void syncToAction())
Q_PRIVATE_SLOT(d, void clearAction())
Q_PRIVATE_SLOT(d, void setPalette())

View file

@ -18,16 +18,10 @@
*/
#include "radiobutton.h"
#include <QDir>
#include <QPainter>
#include <QRadioButton>
#include <kmimetype.h>
#include "private/themedwidgetinterface_p.h"
#include "svg.h"
#include "theme.h"
#include <QRadioButton>
namespace Plasma
{
@ -36,44 +30,14 @@ class RadioButtonPrivate : public ThemedWidgetInterface<RadioButton>
{
public:
RadioButtonPrivate(RadioButton *radio)
: ThemedWidgetInterface<RadioButton>(radio),
svg(nullptr)
: ThemedWidgetInterface<RadioButton>(radio)
{
}
~RadioButtonPrivate()
{
delete svg;
}
void setPixmap(RadioButton *q)
{
if (imagePath.isEmpty()) {
return;
}
KMimeType::Ptr mime = KMimeType::findByUrl(KUrl(absImagePath));
QPixmap pm(q->size().toSize());
if (mime->is("image/svg+xml")) {
svg = new Svg();
QPainter p(&pm);
svg->paint(&p, pm.rect());
} else {
pm = QPixmap(absImagePath);
}
static_cast<QRadioButton*>(q->widget())->setIcon(QIcon(pm));
}
QString imagePath;
QString absImagePath;
Svg *svg;
};
RadioButton::RadioButton(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new RadioButtonPrivate(this))
d(new RadioButtonPrivate(this))
{
QRadioButton *native = new QRadioButton();
connect(native, SIGNAL(toggled(bool)), this, SIGNAL(toggled(bool)));
@ -90,37 +54,12 @@ RadioButton::~RadioButton()
void RadioButton::setText(const QString &text)
{
static_cast<QRadioButton*>(widget())->setText(text);
nativeWidget()->setText(text);
}
QString RadioButton::text() const
{
return static_cast<QRadioButton*>(widget())->text();
}
void RadioButton::setImage(const QString &path)
{
if (d->imagePath == path) {
return;
}
delete d->svg;
d->svg = nullptr;
d->imagePath = path;
const bool absolutePath = (!path.isEmpty() && path[0] == '/');
if (absolutePath) {
d->absImagePath = path;
} else {
d->absImagePath = Theme::defaultTheme()->imagePath(path);
}
d->setPixmap(this);
}
QString RadioButton::image() const
{
return d->imagePath;
return nativeWidget()->text();
}
QRadioButton *RadioButton::nativeWidget() const
@ -128,20 +67,14 @@ QRadioButton *RadioButton::nativeWidget() const
return static_cast<QRadioButton*>(widget());
}
void RadioButton::resizeEvent(QGraphicsSceneResizeEvent *event)
{
d->setPixmap(this);
QGraphicsProxyWidget::resizeEvent(event);
}
void RadioButton::setChecked(bool checked)
{
static_cast<QRadioButton*>(widget())->setChecked(checked);
nativeWidget()->setChecked(checked);
}
bool RadioButton::isChecked() const
{
return static_cast<QRadioButton*>(widget())->isChecked();
return nativeWidget()->isChecked();
}
void RadioButton::changeEvent(QEvent *event)

View file

@ -40,11 +40,10 @@ class PLASMA_EXPORT RadioButton : public QGraphicsProxyWidget
{
Q_OBJECT
Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(QString image READ image WRITE setImage)
Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggled)
public:
explicit RadioButton(QGraphicsWidget *parent = 0);
explicit RadioButton(QGraphicsWidget *parent = nullptr);
~RadioButton();
/**
@ -59,18 +58,6 @@ public:
*/
QString text() const;
/**
* Sets the path to an image to display.
*
* @param path the path to the image; if a relative path, then a themed image will be loaded.
*/
void setImage(const QString &path);
/**
* @return the image path being displayed currently, or an empty string if none.
*/
QString image() const;
/**
* @return the native widget wrapped by this RadioButton
*/
@ -92,12 +79,9 @@ Q_SIGNALS:
void toggled(bool);
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
void changeEvent(QEvent *event);
private:
Q_PRIVATE_SLOT(d, void setPixmap(RadioButton *))
RadioButtonPrivate * const d;
Q_PRIVATE_SLOT(d, void setPalette())
};

View file

@ -18,24 +18,16 @@
*/
#include "toolbutton.h"
#include "animator.h"
#include "framesvg.h"
#include "private/actionwidgetinterface_p.h"
#include "private/themedwidgetinterface_p.h"
#include <QDir>
#include <QPainter>
#include <QPropertyAnimation>
#include <QtGui/qstyleoption.h>
#include <QStyleOptionToolButton>
#include <QToolButton>
#include <kcolorutils.h>
#include <kicon.h>
#include <kiconeffect.h>
#include <kmimetype.h>
#include "animator.h"
#include "framesvg.h"
#include "paintutils.h"
#include "private/actionwidgetinterface_p.h"
#include "private/themedwidgetinterface_p.h"
#include "theme.h"
namespace Plasma
{
@ -48,58 +40,10 @@ public:
background(nullptr),
animation(nullptr),
opacity(1.0),
svg(nullptr),
underMouse(false)
{
}
~ToolButtonPrivate()
{
delete svg;
}
void setPixmap()
{
if (imagePath.isEmpty()) {
delete svg;
svg = nullptr;
return;
}
KMimeType::Ptr mime = KMimeType::findByUrl(KUrl(absImagePath));
QPixmap pm;
if (mime->is("image/svg+xml") || mime->is("image/svg+xml-compressed")) {
if (!svg || svg->imagePath() != absImagePath) {
delete svg;
svg = new Svg();
svg->setImagePath(imagePath);
QObject::connect(svg, SIGNAL(repaintNeeded()), q, SLOT(setPixmap()));
if (!svgElement.isNull()) {
svg->setContainsMultipleImages(true);
}
}
//QPainter p(&pm);
if (!svgElement.isNull() && svg->hasElement(svgElement)) {
QSizeF elementSize = svg->elementSize(svgElement);
float scale = pm.width() / qMax(elementSize.width(), elementSize.height());
svg->resize(svg->size() * scale);
pm = svg->pixmap(svgElement);
} else {
svg->resize(pm.size());
pm = svg->pixmap();
}
} else {
delete svg;
svg = nullptr;
pm = QPixmap(absImagePath);
}
static_cast<QToolButton*>(q->widget())->setIcon(KIcon(pm));
}
void syncActiveRect();
void syncBorders();
void animationUpdate(qreal progress);
@ -109,10 +53,6 @@ public:
qreal opacity;
QRectF activeRect;
QString imagePath;
QString absImagePath;
Svg *svg;
QString svgElement;
bool underMouse;
};
@ -162,7 +102,7 @@ void ToolButtonPrivate::animationUpdate(qreal progress)
ToolButton::ToolButton(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new ToolButtonPrivate(this))
d(new ToolButtonPrivate(this))
{
d->background = new FrameSvg(this);
d->background->setImagePath("widgets/button");
@ -227,43 +167,13 @@ bool ToolButton::autoRaise() const
void ToolButton::setText(const QString &text)
{
static_cast<QToolButton*>(widget())->setText(text);
nativeWidget()->setText(text);
updateGeometry();
}
QString ToolButton::text() const
{
return static_cast<QToolButton*>(widget())->text();
}
void ToolButton::setImage(const QString &path)
{
if (d->imagePath == path) {
return;
}
delete d->svg;
d->svg = nullptr;
d->imagePath = path;
const bool absolutePath = (!path.isEmpty() && path[0] == '/');
if (absolutePath) {
d->absImagePath = path;
} else {
d->absImagePath = Theme::defaultTheme()->imagePath(path);
}
d->setPixmap();
}
void ToolButton::setImage(const QString &path, const QString &elementid)
{
if (d->imagePath == path && d->svgElement == elementid) {
return;
}
d->imagePath.clear();
d->svgElement = elementid;
setImage(path);
return nativeWidget()->text();
}
void ToolButton::setIcon(const QIcon &icon)
@ -276,11 +186,6 @@ QIcon ToolButton::icon() const
return nativeWidget()->icon();
}
QString ToolButton::image() const
{
return d->imagePath;
}
void ToolButton::setDown(bool down)
{
nativeWidget()->setDown(down);
@ -298,8 +203,6 @@ QToolButton *ToolButton::nativeWidget() const
void ToolButton::resizeEvent(QGraphicsSceneResizeEvent *event)
{
d->setPixmap();
if (d->background) {
// resize all four panels
d->background->setElementPrefix("pressed");

View file

@ -41,7 +41,6 @@ class PLASMA_EXPORT ToolButton : public QGraphicsProxyWidget
Q_OBJECT
Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(bool autoRaise READ autoRaise WRITE setAutoRaise)
Q_PROPERTY(QString image READ image WRITE setImage)
Q_PROPERTY(QToolButton *nativeWidget READ nativeWidget)
Q_PROPERTY(QAction *action READ action WRITE setAction)
Q_PROPERTY(bool down READ isDown WRITE setDown)
@ -76,28 +75,6 @@ public:
*/
QString text() const;
/**
* Sets the path to an image to display.
*
* @param path the path to the image; if a relative path, then a themed image will be loaded.
*/
void setImage(const QString &path);
/**
* Sets the path to an svg image to display and the id of the used svg element, if necessary.
*
* @param path the path to the image; if a relative path, then a themed image will be loaded.
* @param elementid the id of a svg element.
*
* @since 4.4
*/
void setImage(const QString &path, const QString &elementid);
/**
* @return the image path being displayed currently, or an empty string if none.
*/
QString image() const;
/**
* Sets the status of the button to pressed
*
@ -178,7 +155,6 @@ private:
Q_PRIVATE_SLOT(d, void syncBorders())
Q_PRIVATE_SLOT(d, void syncToAction())
Q_PRIVATE_SLOT(d, void clearAction())
Q_PRIVATE_SLOT(d, void setPixmap())
Q_PRIVATE_SLOT(d, void setPalette())
friend class ToolButtonPrivate;

View file

@ -20,11 +20,7 @@
#include "<name>.h"
#include <<Native>>
#include <QPainter>
#include <kmimetype.h>
#include "theme.h"
#include "svg.h"
namespace Plasma
@ -39,47 +35,7 @@ public:
{
}
~<Name>Private()
{
delete svg;
}
void setPixmap(<Name> *q)
{
if (imagePath.isEmpty()) {
delete svg;
svg = nullptr;
return;
}
KMimeType::Ptr mime = KMimeType::findByUrl(KUrl(absImagePath));
QPixmap pm(q->size().toSize());
if (mime->is("image/svg+xml")) {
if (!svg || svg->imagePath() != imagePath) {
delete svg;
svg = new Svg();
svg->setImagePath(imagePath);
QObject::connect(svg, SIGNAL(repaintNeeded()), q, SLOT(setPixmap()));
}
QPainter p(&pm);
svg->paint(&p, pm.rect());
} else {
delete svg;
svg = nullptr;
pm = QPixmap(absImagePath);
}
//TODO: load image into widget
//static_cast<<Native>*>(q->widget())->setPixmappm(pm);
//static_cast<<Native>*>(q->widget())->setIcon(QIcon(pm));
}
<Name> *q;
QString imagePath;
QString absImagePath;
Svg *svg;
};
<Name>::<Name>(QGraphicsWidget *parent)
@ -100,37 +56,12 @@ public:
void <Name>::setText(const QString &text)
{
static_cast<<Native>*>(widget())->setText(text);
nativeWidget()->setText(text);
}
QString <Name>::text() const
{
return static_cast<<Native>*>(widget())->text();
}
void <Name>::setImage(const QString &path)
{
if (d->imagePath == path) {
return;
}
delete d->svg;
d->svg = nullptr;
d->imagePath = path;
const bool absolutePath = (!path.isEmpty() && path[0] == '/');
if (absolutePath) {
d->absImagePath = path;
} else {
d->absImagePath = Theme::defaultTheme()->imagePath(path);
}
d->setPixmap(this);
}
QString <Name>::image() const
{
return d->imagePath;
return nativeWidget()->text();
}
<Native>* <Name>::nativeWidget() const
@ -138,12 +69,6 @@ QString <Name>::image() const
return static_cast<<Native>*>(widget());
}
void <Name>::resizeEvent(QGraphicsSceneResizeEvent *event)
{
d->setPixmap(this);
QGraphicsProxyWidget::resizeEvent(event);
}
} // namespace Plasma
#include <<name>.moc>

View file

@ -42,11 +42,10 @@ class PLASMA_EXPORT <Name> : public QGraphicsProxyWidget
Q_PROPERTY(QGraphicsWidget *parentWidget READ parentWidget)
Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(QString image READ image WRITE setImage)
Q_PROPERTY(<Native>* nativeWidget READ nativeWidget)
public:
explicit <Name>(QGraphicsWidget *parent = 0);
explicit <Name>(QGraphicsWidget *parent = nullptr);
~<Name>();
/**
@ -61,18 +60,6 @@ public:
*/
QString text() const;
/**
* Sets the path to an image to display.
*
* @arg path the path to the image; if a relative path, then a themed image will be loaded.
*/
void setImage(const QString &path);
/**
* @return the image path being displayed currently, or an empty string if none.
*/
QString image() const;
/**
* @return the native widget wrapped by this <Name>
*/
@ -80,12 +67,7 @@ public:
Q_SIGNALS:
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
private:
Q_PRIVATE_SLOT(d, void setPixmap())
<Name>Private * const d;
};