diff --git a/applet.cpp b/applet.cpp index 86807b016..86598ee85 100644 --- a/applet.cpp +++ b/applet.cpp @@ -315,18 +315,16 @@ uint Applet::Private::s_maxAppletId = 0; Applet::Applet(QGraphicsItem *parent, const QString& serviceID, uint appletId) - : QObject(0), - Widget(parent), - d(new Private(KService::serviceByStorageId(serviceID), appletId)) + : Widget(parent), + d(new Private(KService::serviceByStorageId(serviceID), appletId)) { d->init(this); } Applet::Applet(QObject* parent, const QStringList& args) - : QObject(parent), - Widget(0), - d(new Private(KService::serviceByStorageId(args.count() > 0 ? args[0] : QString()), - args.count() > 1 ? args[1].toInt() : 0)) + : Widget(0), + d(new Private(KService::serviceByStorageId(args.count() > 0 ? args[0] : QString()), + args.count() > 1 ? args[1].toInt() : 0)) { d->init(this); // the brain damage seen in the initialization list is due to the diff --git a/applet.h b/applet.h index 094cd022d..27fd8cabf 100644 --- a/applet.h +++ b/applet.h @@ -53,7 +53,7 @@ class Package; * * See techbase.kde.org for tutorial on writing Applets using this class. */ -class PLASMA_EXPORT Applet : public QObject, public Widget +class PLASMA_EXPORT Applet : public Widget { Q_OBJECT // Q_PROPERTY( QRectF maxSizeHint READ maxSizeHint ) diff --git a/widgets/checkbox.cpp b/widgets/checkbox.cpp index de367c319..da5d2c4f3 100644 --- a/widgets/checkbox.cpp +++ b/widgets/checkbox.cpp @@ -51,31 +51,43 @@ class CheckBox::Private }; CheckBox::CheckBox(QGraphicsItem *parent) - : QObject(), - QGraphicsItem(parent), + : Plasma::Widget(parent), d(new Private) +{ + init(); +} + + +CheckBox::CheckBox(const QString &text, QGraphicsItem *parent) + : Plasma::Widget(parent), + d(new Private) +{ + init(); + setText(text); +} + +void CheckBox::init() { setAcceptedMouseButtons(Qt::LeftButton); setAcceptsHoverEvents(true); setAcceptDrops(true); setEnabled(true); + + setPos(QPointF(0.0,0.0)); + d->height = 40; d->width = 100 ; d->maxWidth = 600; - setPos(QPointF(0.0,0.0)); d->state= Qt::Unchecked; - d->labelText=QString("Plasma"); - d->labelTextColor= QColor(201,201,255); + d->hasIcon = false; - d->iconSize=QSize(32,32); + d->iconSize = QSize(32,32); d->hasMouse = false; d->down = false; d->hovering = false; d->down = false; - } - CheckBox::~CheckBox() { delete d; @@ -83,16 +95,17 @@ CheckBox::~CheckBox() QRectF CheckBox::boundingRect() const { - return QRectF(0,0,d->width,d->height); + return QRectF(0, 0, d->width, d->height); } -void CheckBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +void CheckBox::paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option) + QStyleOptionButton options; options.rect = boundingRect().toRect(); options.text = text(); - options.state |= (d->state == Qt::Checked)? QStyle::State_On : QStyle::State_Off; + options.state |= (d->state == Qt::Checked) ? QStyle::State_On : QStyle::State_Off; //if (d->down) { // options.state |= QStyle::State_Sunken; @@ -105,6 +118,7 @@ void CheckBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, options.state |= QStyle::State_Raised; options.state |= QStyle::State_On; } + widget-> style()->drawControl(QStyle::CE_CheckBox, &options, painter, widget); } diff --git a/widgets/checkbox.h b/widgets/checkbox.h index 97e2273dd..4690c3b39 100644 --- a/widgets/checkbox.h +++ b/widgets/checkbox.h @@ -23,8 +23,9 @@ #include #include - #include +#include + //TODO //Please Document this class @@ -34,45 +35,54 @@ namespace Plasma /** * Class that emulates a QCheckBox inside plasma */ -class PLASMA_EXPORT CheckBox : public QObject, public QGraphicsItem +class PLASMA_EXPORT CheckBox : public Plasma::Widget { Q_OBJECT - public: +public: + explicit CheckBox(QGraphicsItem *parent = 0); + explicit CheckBox(const QString &text, QGraphicsItem *parent = 0); + virtual ~CheckBox(); - CheckBox(QGraphicsItem *parent = 0); - virtual ~CheckBox(); + void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + QRectF boundingRect() const; - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); - QRectF boundingRect() const; - void setText(const QString&) ; - QString text() const; - QSize size() const; - int height() const; - int width() const; - void setSize(const QSize &size); - void setWidth(int width); - void setHeight(int height); - void setMaximumWidth(int maxwidth); - Qt::CheckState checkState() const; - void setChecked(bool checked); - void setCheckState(Qt::CheckState state); + Qt::CheckState checkState() const; + void setChecked(bool checked); + void setCheckState(Qt::CheckState state); + void setText(const QString&) ; + QString text() const; - public Q_SLOTS: - void updated(const QString&, const DataEngine::Data&); - Q_SIGNALS: - void clicked(); - protected: - //bool isDown(); - void mousePressEvent ( QGraphicsSceneMouseEvent * event ); - void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); - void mouseMoveEvent (QGraphicsSceneMouseEvent * event); - void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); - void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); - void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ); - private: - class Private ; - Private * const d; + QSize size() const; + void setSize(const QSize &size); + + int height() const; + void setHeight(int height); + + int width() const; + void setWidth(int width); + void setMaximumWidth(int maxwidth); + +public Q_SLOTS: + void updated(const QString&, const DataEngine::Data&); + +Q_SIGNALS: + void clicked(); + +protected: + //bool isDown(); + void mousePressEvent ( QGraphicsSceneMouseEvent * event ); + void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + void mouseMoveEvent (QGraphicsSceneMouseEvent * event); + void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ); + +private: + void init(); + + class Private ; + Private * const d; }; diff --git a/widgets/flash.cpp b/widgets/flash.cpp index 9e3fd65fa..d715da465 100644 --- a/widgets/flash.cpp +++ b/widgets/flash.cpp @@ -62,8 +62,7 @@ class Flash::Private Flash::Flash(QGraphicsItem *parent) - : QObject(), - QGraphicsItem(parent), + : Plasma::Widget(parent), d(new Private) { d->defaultDuration = 3000; @@ -212,7 +211,7 @@ QPixmap Flash::renderPixmap() return pm; } -void Flash::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +void Flash::paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option) Q_UNUSED(widget) diff --git a/widgets/flash.h b/widgets/flash.h index 8882bb72a..9555a3e32 100644 --- a/widgets/flash.h +++ b/widgets/flash.h @@ -24,6 +24,7 @@ #include #include +#include namespace Plasma { @@ -31,14 +32,14 @@ namespace Plasma /** * Class that allows to flash text or icons inside plasma */ -class PLASMA_EXPORT Flash : public QObject, public QGraphicsItem +class PLASMA_EXPORT Flash : public Plasma::Widget { Q_OBJECT public: Flash(QGraphicsItem *parent = 0); virtual ~Flash(); - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); QRectF boundingRect() const; QSize size() const; int height() const; diff --git a/widgets/label.cpp b/widgets/label.cpp index 7290d50eb..d318ba0bb 100644 --- a/widgets/label.cpp +++ b/widgets/label.cpp @@ -16,7 +16,7 @@ class Label::Private }; Label::Label(Widget *parent) - : Widget(parent), + : Plasma::Widget(parent), d(new Private) { setAlignment(Qt::AlignHCenter); diff --git a/widgets/pushbutton.cpp b/widgets/pushbutton.cpp index c2d2a29b1..ea102992f 100644 --- a/widgets/pushbutton.cpp +++ b/widgets/pushbutton.cpp @@ -51,8 +51,7 @@ class PushButton::Private }; PushButton::PushButton(Widget *parent) - : QObject(), - Widget(parent), + : Plasma::Widget(parent), d(new Private) { setAcceptedMouseButtons(Qt::LeftButton); diff --git a/widgets/pushbutton.h b/widgets/pushbutton.h index 5d67bb52b..466f99ea0 100644 --- a/widgets/pushbutton.h +++ b/widgets/pushbutton.h @@ -38,8 +38,7 @@ namespace Plasma * * */ -class PLASMA_EXPORT PushButton : public QObject, - public Plasma::Widget +class PLASMA_EXPORT PushButton : public Plasma::Widget { Q_OBJECT diff --git a/widgets/radiobutton.cpp b/widgets/radiobutton.cpp index 22852035f..cdd2615d1 100644 --- a/widgets/radiobutton.cpp +++ b/widgets/radiobutton.cpp @@ -61,8 +61,7 @@ RadioButton::Private::~Private() RadioButton::RadioButton(QGraphicsItem *parent) - : QObject(), - QGraphicsItem(parent), + : Plasma::Widget(parent), d(new Private) { setAcceptedMouseButtons(Qt::LeftButton); @@ -79,7 +78,7 @@ QRectF RadioButton::boundingRect() const return QRectF(0, 0, 150, 30); // FIXME: this is obviously wrong } -void RadioButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +void RadioButton::paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { QStyle *style = widget ? widget->style() : QApplication::style(); diff --git a/widgets/radiobutton.h b/widgets/radiobutton.h index 014e48d65..b3935feac 100644 --- a/widgets/radiobutton.h +++ b/widgets/radiobutton.h @@ -25,7 +25,7 @@ // KDE includes #include - +#include #include namespace Plasma @@ -47,17 +47,16 @@ namespace Plasma */ -class PLASMA_EXPORT RadioButton : public QObject, public QGraphicsItem +class PLASMA_EXPORT RadioButton : public Plasma::Widget { Q_OBJECT - public: RadioButton(QGraphicsItem *parent = 0); virtual ~RadioButton(); // QGraphicsItem overridden virtual methods QRectF boundingRect() const; - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); // Getters bool isChecked() const; diff --git a/widgets/widget.h b/widgets/widget.h index 958316d56..d4e2224aa 100644 --- a/widgets/widget.h +++ b/widgets/widget.h @@ -36,7 +36,8 @@ class Layout; /** * Base class for all Widgets in Plasma. * - * @author Alexander Wiedenbruch and Matias Valdenegro. + * @author Alexander Wiedenbruch + * @author Matias Valdenegro * * Widgets are the basis for User Interfaces inside Plasma. * Widgets are rectangular, but can be in any visible shape by just using transparency to mask @@ -44,147 +45,149 @@ class Layout; * * To implement a Widget, just subclass Plasma::Widget and implement at minimum, sizeHint() and paint() */ -class PLASMA_EXPORT Widget : public QGraphicsItem, - public LayoutItem +class PLASMA_EXPORT Widget : public QObject, + public QGraphicsItem, + public LayoutItem { - public: + Q_OBJECT +public: - /** - * Constructor. - */ - explicit Widget(QGraphicsItem *parent = 0); + /** + * Constructor. + */ + explicit Widget(QGraphicsItem *parent = 0); - /** - * Virtual Destructor. - */ - virtual ~Widget(); + /** + * Virtual Destructor. + */ + virtual ~Widget(); - /** - * Returns a bitmask with the directions that this Widget can be expanded. - */ - virtual Qt::Orientations expandingDirections() const; + /** + * Returns a bitmask with the directions that this Widget can be expanded. + */ + virtual Qt::Orientations expandingDirections() const; - /** - * Sets the minimum size of this Widget. - */ - void setMinimumSize(const QSizeF& size); + /** + * Sets the minimum size of this Widget. + */ + void setMinimumSize(const QSizeF& size); - /** - * Returns the minimum size of this Widget. - */ - QSizeF minimumSize() const; + /** + * Returns the minimum size of this Widget. + */ + QSizeF minimumSize() const; - /** - * Sets the maximum size of this Widget. - */ - void setMaximumSize(const QSizeF& size); + /** + * Sets the maximum size of this Widget. + */ + void setMaximumSize(const QSizeF& size); - /** - * Returns the maximum size of this Widget. - */ - QSizeF maximumSize() const; + /** + * Returns the maximum size of this Widget. + */ + QSizeF maximumSize() const; - /** - * Returns true whatever this Widget can use height-for-width layout management, - * false otherwise. - */ - virtual bool hasHeightForWidth() const; + /** + * Returns true whatever this Widget can use height-for-width layout management, + * false otherwise. + */ + virtual bool hasHeightForWidth() const; - /** - * Returns the corresponding height for a given width. - * @param w Width - */ - virtual qreal heightForWidth(qreal w) const; + /** + * Returns the corresponding height for a given width. + * @param w Width + */ + virtual qreal heightForWidth(qreal w) const; - /** - * Returns true whatever this Widget can use width-for-height layout management, - * false otherwise. - */ - virtual bool hasWidthForHeight() const; + /** + * Returns true whatever this Widget can use width-for-height layout management, + * false otherwise. + */ + virtual bool hasWidthForHeight() const; - /** - * Returns the corresponding width for a given height. - * @param h Height - */ - virtual qreal widthForHeight(qreal h) const; + /** + * Returns the corresponding width for a given height. + * @param h Height + */ + virtual qreal widthForHeight(qreal h) const; - /** - * Returns the geometry of this Widget, in parent coordinates. - */ - QRectF geometry() const; + /** + * Returns the geometry of this Widget, in parent coordinates. + */ + QRectF geometry() const; - /** - * Returns the geometry of this Widget, in local coordinates. - */ - QRectF localGeometry() const; + /** + * Returns the geometry of this Widget, in local coordinates. + */ + QRectF localGeometry() const; - /** - * Sets the geometry of this Widget. - */ - void setGeometry(const QRectF &geometry); + /** + * Sets the geometry of this Widget. + */ + void setGeometry(const QRectF &geometry); - /** - * Propagates the geometry information to associated layouts and other Widgets. - */ - void updateGeometry(); + /** + * Propagates the geometry information to associated layouts and other Widgets. + */ + void updateGeometry(); - /** - * Invalidates the geometry information. - */ - virtual void invalidate(); + /** + * Invalidates the geometry information. + */ + virtual void invalidate(); - /** - * Returns the most appropriate size of this Widget to hold it's contents. - */ - virtual QSizeF sizeHint() const; + /** + * Returns the most appropriate size of this Widget to hold it's contents. + */ + virtual QSizeF sizeHint() const; - /** - * Returns the size of this Widget. - */ - QSizeF size() const; + /** + * Returns the size of this Widget. + */ + QSizeF size() const; - /** - * Returns the bounding rectangle of this Widget. - */ - virtual QRectF boundingRect() const; + /** + * Returns the bounding rectangle of this Widget. + */ + virtual QRectF boundingRect() const; - /** - * Resizes this Widget. - * @param size New size - */ - void resize(const QSizeF &size); + /** + * Resizes this Widget. + * @param size New size + */ + void resize(const QSizeF &size); - /** - * Resizes this Widget. - * @param w New width - * @param h New height - */ - void resize(qreal w, qreal h); + /** + * Resizes this Widget. + * @param w New width + * @param h New height + */ + void resize(qreal w, qreal h); - /** - * Returns the parent of this Widget. - */ - Widget *parent() const; + /** + * Returns the parent of this Widget. + */ + Widget *parent() const; - /** - * Changes the parent of this Widget. - */ - void reparent(Widget *w); + /** + * Changes the parent of this Widget. + */ + void reparent(Widget *w); - /** - * Appends a child Widget to this Widget. - */ - void addChild(Widget *w); + /** + * Appends a child Widget to this Widget. + */ + void addChild(Widget *w); - /** - * Paint function. - */ - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + /** + * Paint function. + */ + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); - /** - * Paints the widget. Called by the paint function under correct conditions. - */ - virtual void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + /** + * Paints the widget. Called by the paint function under correct conditions. + */ + virtual void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); private: class Private;