From bfe37da9028890dc0a93bffd0323ba9b8f81c58e Mon Sep 17 00:00:00 2001 From: Siraj Razick Date: Mon, 5 Mar 2007 12:54:54 +0000 Subject: [PATCH] icon support svn path=/trunk/KDE/kdebase/workspace/plasma/lib/; revision=639602 --- widgets/pushbutton.cpp | 22 +++++++++++++++++++++- widgets/pushbutton.h | 5 +++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/widgets/pushbutton.cpp b/widgets/pushbutton.cpp index 6ddb24db6..bb24f3568 100644 --- a/widgets/pushbutton.cpp +++ b/widgets/pushbutton.cpp @@ -37,6 +37,9 @@ class PushButton::Private QString labelText; QString labelIcon; QColor labelTextColor; + QIcon icon; + QSize iconSize; + bool hasIcon; int labelTextOpacity; int height; int width; @@ -61,6 +64,8 @@ PushButton::PushButton(QGraphicsItem *parent) d->state= PushButton::NONE; d->labelText=tr("Plasma"); d->labelTextColor= QColor(201,201,255); + d->hasIcon = false; + d->iconSize=QSize(32,32); } @@ -81,7 +86,11 @@ void PushButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *option options.state = option->state; options.rect = boundingRect().toRect(); options.text = text(); - + if (d->hasIcon){ + options.icon= d->icon; + options.iconSize = d->iconSize; + } + widget->style()->drawPrimitive(QStyle::PE_PanelButtonCommand, &options, painter, widget); widget->style()->drawPrimitive(QStyle::PE_FrameFocusRect, &options, painter, widget); widget-> style()->drawControl(QStyle::CE_PushButton, &options, painter, widget); @@ -136,6 +145,17 @@ void PushButton::setWidth(int w) } } +void PushButton::setIcon(const QString& path) +{ + QPixmap _iconPixmap (path); + if (!path.isNull()) { + d->icon = QIcon(_iconPixmap); + d->iconSize = _iconPixmap.size(); + d->hasIcon=true; + }else { + d->hasIcon = false; + } +} QSize PushButton::size() { return QSize(d->width,d->height); diff --git a/widgets/pushbutton.h b/widgets/pushbutton.h index c2b0673b9..6d6f5cd0a 100644 --- a/widgets/pushbutton.h +++ b/widgets/pushbutton.h @@ -47,12 +47,13 @@ class KDE_EXPORT PushButton : public DataVisualization,public QGraphicsItem void setText(const QString&) ; QString text(); QSize size(); + int height(); + int width(); + void setIcon(const QString& path); void setSize(QSize size); void setWidth(int width); void setHeight(int height); void setMaximumWidth(int maxwidth); - int width(); - int height(); public slots: void data(const DataSource::Data&);