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); PushButton *configWidget = new PushButton(d->messageOverlay);
if (!qobject_cast<Plasma::PopupApplet *>(this) && (formFactor() == Plasma::Horizontal || formFactor() == Plasma::Vertical)) { 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->setMaximumSize(24,24);
configWidget->setMinimumSize(24,24); configWidget->setMinimumSize(24,24);
} else { } else {

View file

@ -20,14 +20,8 @@
#include "checkbox.h" #include "checkbox.h"
#include <QCheckBox> #include <QCheckBox>
#include <QPainter>
#include <QDir>
#include <kmimetype.h>
#include "private/themedwidgetinterface_p.h" #include "private/themedwidgetinterface_p.h"
#include "svg.h"
#include "theme.h"
namespace Plasma namespace Plasma
{ {
@ -36,49 +30,9 @@ class CheckBoxPrivate : public ThemedWidgetInterface<CheckBox>
{ {
public: public:
CheckBoxPrivate(CheckBox *c) CheckBoxPrivate(CheckBox *c)
: ThemedWidgetInterface<CheckBox>(c), : ThemedWidgetInterface<CheckBox>(c)
svg(nullptr)
{ {
} }
~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) CheckBox::CheckBox(QGraphicsWidget *parent)
@ -101,37 +55,12 @@ CheckBox::~CheckBox()
void CheckBox::setText(const QString &text) void CheckBox::setText(const QString &text)
{ {
static_cast<QCheckBox*>(widget())->setText(text); nativeWidget()->setText(text);
} }
QString CheckBox::text() const QString CheckBox::text() const
{ {
return static_cast<QCheckBox*>(widget())->text(); return nativeWidget()->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;
} }
QCheckBox *CheckBox::nativeWidget() const QCheckBox *CheckBox::nativeWidget() const
@ -139,20 +68,14 @@ QCheckBox *CheckBox::nativeWidget() const
return static_cast<QCheckBox*>(widget()); return static_cast<QCheckBox*>(widget());
} }
void CheckBox::resizeEvent(QGraphicsSceneResizeEvent *event)
{
d->setPixmap();
QGraphicsProxyWidget::resizeEvent(event);
}
void CheckBox::setChecked(bool checked) void CheckBox::setChecked(bool checked)
{ {
static_cast<QCheckBox*>(widget())->setChecked(checked); nativeWidget()->setChecked(checked);
} }
bool CheckBox::isChecked() const bool CheckBox::isChecked() const
{ {
return static_cast<QCheckBox*>(widget())->isChecked(); return nativeWidget()->isChecked();
} }
void CheckBox::changeEvent(QEvent *event) void CheckBox::changeEvent(QEvent *event)

View file

@ -40,7 +40,6 @@ class PLASMA_EXPORT CheckBox : public QGraphicsProxyWidget
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString text READ text WRITE setText) 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) Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggled)
public: public:
@ -59,18 +58,6 @@ public:
*/ */
QString text() const; 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 * @return the native widget wrapped by this CheckBox
*/ */
@ -92,12 +79,10 @@ Q_SIGNALS:
void toggled(bool); void toggled(bool);
protected: protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
void changeEvent(QEvent *event); void changeEvent(QEvent *event);
private: private:
Q_PRIVATE_SLOT(d, void setPalette()) Q_PRIVATE_SLOT(d, void setPalette())
Q_PRIVATE_SLOT(d, void setPixmap())
CheckBoxPrivate * const d; CheckBoxPrivate * const d;
}; };

View file

@ -20,20 +20,11 @@
#include "label.h" #include "label.h"
#include <QApplication> #include <QApplication>
#include <QDir> #include <QGraphicsSceneContextMenuEvent>
#include <QtGui/qgraphicssceneevent.h>
#include <QLabel> #include <QLabel>
#include <QMenu> #include <QIcon>
#include <QPainter>
#include <QtGui/qstyleoption.h>
#include <kcolorscheme.h>
#include <kglobalsettings.h>
#include <kmimetype.h>
#include "private/themedwidgetinterface_p.h" #include "private/themedwidgetinterface_p.h"
#include "svg.h"
#include "theme.h"
namespace Plasma namespace Plasma
{ {
@ -42,49 +33,9 @@ class LabelPrivate : public ThemedWidgetInterface<Label>
{ {
public: public:
LabelPrivate(Label *label) LabelPrivate(Label *label)
: ThemedWidgetInterface<Label>(label), : ThemedWidgetInterface<Label>(label)
svg(nullptr)
{ {
} }
~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) Label::Label(QGraphicsWidget *parent)
@ -121,31 +72,6 @@ QString Label::text() const
return nativeWidget()->text(); 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) void Label::setScaledContents(bool scaled)
{ {
nativeWidget()->setScaledContents(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) void Label::changeEvent(QEvent *event)
{ {
d->changeEvent(event); d->changeEvent(event);

View file

@ -40,7 +40,6 @@ class PLASMA_EXPORT Label : public QGraphicsProxyWidget
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString text READ text WRITE setText) 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(Qt::Alignment alignment READ alignment WRITE setAlignment)
Q_PROPERTY(bool hasScaledContents READ hasScaledContents WRITE setScaledContents) Q_PROPERTY(bool hasScaledContents READ hasScaledContents WRITE setScaledContents)
Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap) Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap)
@ -66,18 +65,6 @@ public:
*/ */
QString text() const; 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 * Sets the alignment for the text
* *
@ -140,7 +127,6 @@ Q_SIGNALS:
void linkHovered(const QString &link); void linkHovered(const QString &link);
protected: protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
void changeEvent(QEvent *event); void changeEvent(QEvent *event);
bool event(QEvent *event); bool event(QEvent *event);
QVariant itemChange(GraphicsItemChange change, const QVariant & value); QVariant itemChange(GraphicsItemChange change, const QVariant & value);
@ -149,7 +135,6 @@ protected:
private: private:
Q_PRIVATE_SLOT(d, void setPalette()) Q_PRIVATE_SLOT(d, void setPalette())
Q_PRIVATE_SLOT(d, void setPixmap())
LabelPrivate * const d; LabelPrivate * const d;
}; };

View file

@ -19,23 +19,10 @@
*/ */
#include "pushbutton.h" #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/actionwidgetinterface_p.h"
#include "private/themedwidgetinterface_p.h" #include "private/themedwidgetinterface_p.h"
#include "theme.h"
#include <kpushbutton.h>
namespace Plasma namespace Plasma
{ {
@ -44,64 +31,9 @@ class PushButtonPrivate : public ActionWidgetInterface<PushButton>
{ {
public: public:
PushButtonPrivate(PushButton *pushButton) PushButtonPrivate(PushButton *pushButton)
: ActionWidgetInterface<PushButton>(pushButton), : ActionWidgetInterface<PushButton>(pushButton)
svg(nullptr)
{ {
} }
~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) void PushButton::setText(const QString &text)
{ {
static_cast<KPushButton*>(widget())->setText(text); nativeWidget()->setText(text);
updateGeometry(); updateGeometry();
} }
QString PushButton::text() const QString PushButton::text() const
{ {
return static_cast<KPushButton*>(widget())->text(); return nativeWidget()->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;
} }
void PushButton::setAction(QAction *action) void PushButton::setAction(QAction *action)
@ -231,12 +132,6 @@ KPushButton *PushButton::nativeWidget() const
return static_cast<KPushButton*>(widget()); return static_cast<KPushButton*>(widget());
} }
void PushButton::resizeEvent(QGraphicsSceneResizeEvent *event)
{
d->setPixmap();
QGraphicsProxyWidget::resizeEvent(event);
}
void PushButton::changeEvent(QEvent *event) void PushButton::changeEvent(QEvent *event)
{ {
d->changeEvent(event); d->changeEvent(event);

View file

@ -22,12 +22,11 @@
#include <QtGui/QGraphicsProxyWidget> #include <QtGui/QGraphicsProxyWidget>
#include <plasma/plasma_export.h>
#include <kicon.h> #include <kicon.h>
class KPushButton; class KPushButton;
#include <plasma/plasma_export.h>
namespace Plasma namespace Plasma
{ {
@ -42,7 +41,6 @@ class PLASMA_EXPORT PushButton : public QGraphicsProxyWidget
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString text READ text WRITE setText) 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(QAction *action READ action WRITE setAction)
Q_PROPERTY(QIcon icon READ icon WRITE setIcon) Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable) Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable)
@ -65,28 +63,6 @@ public:
*/ */
QString text() const; 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 * Associate an action with this PushButton
* this makes the button follow the state of the action, using its icon, text, etc. * 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); void setChecked(bool checked);
protected: protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
void changeEvent(QEvent *event); void changeEvent(QEvent *event);
private: private:
Q_PRIVATE_SLOT(d, void setPixmap())
Q_PRIVATE_SLOT(d, void syncToAction()) Q_PRIVATE_SLOT(d, void syncToAction())
Q_PRIVATE_SLOT(d, void clearAction()) Q_PRIVATE_SLOT(d, void clearAction())
Q_PRIVATE_SLOT(d, void setPalette()) Q_PRIVATE_SLOT(d, void setPalette())

View file

@ -18,16 +18,10 @@
*/ */
#include "radiobutton.h" #include "radiobutton.h"
#include <QDir>
#include <QPainter>
#include <QRadioButton>
#include <kmimetype.h>
#include "private/themedwidgetinterface_p.h" #include "private/themedwidgetinterface_p.h"
#include "svg.h" #include "svg.h"
#include "theme.h"
#include <QRadioButton>
namespace Plasma namespace Plasma
{ {
@ -36,39 +30,9 @@ class RadioButtonPrivate : public ThemedWidgetInterface<RadioButton>
{ {
public: public:
RadioButtonPrivate(RadioButton *radio) RadioButtonPrivate(RadioButton *radio)
: ThemedWidgetInterface<RadioButton>(radio), : ThemedWidgetInterface<RadioButton>(radio)
svg(nullptr)
{ {
} }
~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) RadioButton::RadioButton(QGraphicsWidget *parent)
@ -90,37 +54,12 @@ RadioButton::~RadioButton()
void RadioButton::setText(const QString &text) void RadioButton::setText(const QString &text)
{ {
static_cast<QRadioButton*>(widget())->setText(text); nativeWidget()->setText(text);
} }
QString RadioButton::text() const QString RadioButton::text() const
{ {
return static_cast<QRadioButton*>(widget())->text(); return nativeWidget()->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;
} }
QRadioButton *RadioButton::nativeWidget() const QRadioButton *RadioButton::nativeWidget() const
@ -128,20 +67,14 @@ QRadioButton *RadioButton::nativeWidget() const
return static_cast<QRadioButton*>(widget()); return static_cast<QRadioButton*>(widget());
} }
void RadioButton::resizeEvent(QGraphicsSceneResizeEvent *event)
{
d->setPixmap(this);
QGraphicsProxyWidget::resizeEvent(event);
}
void RadioButton::setChecked(bool checked) void RadioButton::setChecked(bool checked)
{ {
static_cast<QRadioButton*>(widget())->setChecked(checked); nativeWidget()->setChecked(checked);
} }
bool RadioButton::isChecked() const bool RadioButton::isChecked() const
{ {
return static_cast<QRadioButton*>(widget())->isChecked(); return nativeWidget()->isChecked();
} }
void RadioButton::changeEvent(QEvent *event) void RadioButton::changeEvent(QEvent *event)

View file

@ -40,11 +40,10 @@ class PLASMA_EXPORT RadioButton : public QGraphicsProxyWidget
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString text READ text WRITE setText) 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) Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggled)
public: public:
explicit RadioButton(QGraphicsWidget *parent = 0); explicit RadioButton(QGraphicsWidget *parent = nullptr);
~RadioButton(); ~RadioButton();
/** /**
@ -59,18 +58,6 @@ public:
*/ */
QString text() const; 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 * @return the native widget wrapped by this RadioButton
*/ */
@ -92,12 +79,9 @@ Q_SIGNALS:
void toggled(bool); void toggled(bool);
protected: protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
void changeEvent(QEvent *event); void changeEvent(QEvent *event);
private: private:
Q_PRIVATE_SLOT(d, void setPixmap(RadioButton *))
RadioButtonPrivate * const d; RadioButtonPrivate * const d;
Q_PRIVATE_SLOT(d, void setPalette()) Q_PRIVATE_SLOT(d, void setPalette())
}; };

View file

@ -18,24 +18,16 @@
*/ */
#include "toolbutton.h" #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 <QPropertyAnimation>
#include <QtGui/qstyleoption.h> #include <QStyleOptionToolButton>
#include <QToolButton> #include <QToolButton>
#include <kcolorutils.h> #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 namespace Plasma
{ {
@ -48,58 +40,10 @@ public:
background(nullptr), background(nullptr),
animation(nullptr), animation(nullptr),
opacity(1.0), opacity(1.0),
svg(nullptr),
underMouse(false) 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 syncActiveRect();
void syncBorders(); void syncBorders();
void animationUpdate(qreal progress); void animationUpdate(qreal progress);
@ -109,10 +53,6 @@ public:
qreal opacity; qreal opacity;
QRectF activeRect; QRectF activeRect;
QString imagePath;
QString absImagePath;
Svg *svg;
QString svgElement;
bool underMouse; bool underMouse;
}; };
@ -227,43 +167,13 @@ bool ToolButton::autoRaise() const
void ToolButton::setText(const QString &text) void ToolButton::setText(const QString &text)
{ {
static_cast<QToolButton*>(widget())->setText(text); nativeWidget()->setText(text);
updateGeometry(); updateGeometry();
} }
QString ToolButton::text() const QString ToolButton::text() const
{ {
return static_cast<QToolButton*>(widget())->text(); return nativeWidget()->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);
} }
void ToolButton::setIcon(const QIcon &icon) void ToolButton::setIcon(const QIcon &icon)
@ -276,11 +186,6 @@ QIcon ToolButton::icon() const
return nativeWidget()->icon(); return nativeWidget()->icon();
} }
QString ToolButton::image() const
{
return d->imagePath;
}
void ToolButton::setDown(bool down) void ToolButton::setDown(bool down)
{ {
nativeWidget()->setDown(down); nativeWidget()->setDown(down);
@ -298,8 +203,6 @@ QToolButton *ToolButton::nativeWidget() const
void ToolButton::resizeEvent(QGraphicsSceneResizeEvent *event) void ToolButton::resizeEvent(QGraphicsSceneResizeEvent *event)
{ {
d->setPixmap();
if (d->background) { if (d->background) {
// resize all four panels // resize all four panels
d->background->setElementPrefix("pressed"); d->background->setElementPrefix("pressed");

View file

@ -41,7 +41,6 @@ class PLASMA_EXPORT ToolButton : public QGraphicsProxyWidget
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString text READ text WRITE setText) Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(bool autoRaise READ autoRaise WRITE setAutoRaise) Q_PROPERTY(bool autoRaise READ autoRaise WRITE setAutoRaise)
Q_PROPERTY(QString image READ image WRITE setImage)
Q_PROPERTY(QToolButton *nativeWidget READ nativeWidget) Q_PROPERTY(QToolButton *nativeWidget READ nativeWidget)
Q_PROPERTY(QAction *action READ action WRITE setAction) Q_PROPERTY(QAction *action READ action WRITE setAction)
Q_PROPERTY(bool down READ isDown WRITE setDown) Q_PROPERTY(bool down READ isDown WRITE setDown)
@ -76,28 +75,6 @@ public:
*/ */
QString text() const; 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 * Sets the status of the button to pressed
* *
@ -178,7 +155,6 @@ private:
Q_PRIVATE_SLOT(d, void syncBorders()) Q_PRIVATE_SLOT(d, void syncBorders())
Q_PRIVATE_SLOT(d, void syncToAction()) Q_PRIVATE_SLOT(d, void syncToAction())
Q_PRIVATE_SLOT(d, void clearAction()) Q_PRIVATE_SLOT(d, void clearAction())
Q_PRIVATE_SLOT(d, void setPixmap())
Q_PRIVATE_SLOT(d, void setPalette()) Q_PRIVATE_SLOT(d, void setPalette())
friend class ToolButtonPrivate; friend class ToolButtonPrivate;

View file

@ -20,11 +20,7 @@
#include "<name>.h" #include "<name>.h"
#include <<Native>> #include <<Native>>
#include <QPainter>
#include <kmimetype.h>
#include "theme.h"
#include "svg.h" #include "svg.h"
namespace Plasma 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; <Name> *q;
QString imagePath;
QString absImagePath;
Svg *svg;
}; };
<Name>::<Name>(QGraphicsWidget *parent) <Name>::<Name>(QGraphicsWidget *parent)
@ -100,37 +56,12 @@ public:
void <Name>::setText(const QString &text) void <Name>::setText(const QString &text)
{ {
static_cast<<Native>*>(widget())->setText(text); nativeWidget()->setText(text);
} }
QString <Name>::text() const QString <Name>::text() const
{ {
return static_cast<<Native>*>(widget())->text(); return nativeWidget()->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;
} }
<Native>* <Name>::nativeWidget() const <Native>* <Name>::nativeWidget() const
@ -138,12 +69,6 @@ QString <Name>::image() const
return static_cast<<Native>*>(widget()); return static_cast<<Native>*>(widget());
} }
void <Name>::resizeEvent(QGraphicsSceneResizeEvent *event)
{
d->setPixmap(this);
QGraphicsProxyWidget::resizeEvent(event);
}
} // namespace Plasma } // namespace Plasma
#include <<name>.moc> #include <<name>.moc>

View file

@ -42,11 +42,10 @@ class PLASMA_EXPORT <Name> : public QGraphicsProxyWidget
Q_PROPERTY(QGraphicsWidget *parentWidget READ parentWidget) Q_PROPERTY(QGraphicsWidget *parentWidget READ parentWidget)
Q_PROPERTY(QString text READ text WRITE setText) Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(QString image READ image WRITE setImage)
Q_PROPERTY(<Native>* nativeWidget READ nativeWidget) Q_PROPERTY(<Native>* nativeWidget READ nativeWidget)
public: public:
explicit <Name>(QGraphicsWidget *parent = 0); explicit <Name>(QGraphicsWidget *parent = nullptr);
~<Name>(); ~<Name>();
/** /**
@ -61,18 +60,6 @@ public:
*/ */
QString text() const; 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> * @return the native widget wrapped by this <Name>
*/ */
@ -80,12 +67,7 @@ public:
Q_SIGNALS: Q_SIGNALS:
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
private: private:
Q_PRIVATE_SLOT(d, void setPixmap())
<Name>Private * const d; <Name>Private * const d;
}; };