Make all plasma/widgets inherit Plasma::Widget now. Holding off on committing change for icon as I have a massive patch for the new text drawing

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=696028
This commit is contained in:
Matt Broadstone 2007-08-03 16:00:10 +00:00
parent 8fce372a7c
commit be3c212374
12 changed files with 206 additions and 185 deletions

View File

@ -315,18 +315,16 @@ uint Applet::Private::s_maxAppletId = 0;
Applet::Applet(QGraphicsItem *parent, Applet::Applet(QGraphicsItem *parent,
const QString& serviceID, const QString& serviceID,
uint appletId) uint appletId)
: QObject(0), : Widget(parent),
Widget(parent), d(new Private(KService::serviceByStorageId(serviceID), appletId))
d(new Private(KService::serviceByStorageId(serviceID), appletId))
{ {
d->init(this); d->init(this);
} }
Applet::Applet(QObject* parent, const QStringList& args) Applet::Applet(QObject* parent, const QStringList& args)
: QObject(parent), : Widget(0),
Widget(0), d(new Private(KService::serviceByStorageId(args.count() > 0 ? args[0] : QString()),
d(new Private(KService::serviceByStorageId(args.count() > 0 ? args[0] : QString()), args.count() > 1 ? args[1].toInt() : 0))
args.count() > 1 ? args[1].toInt() : 0))
{ {
d->init(this); d->init(this);
// the brain damage seen in the initialization list is due to the // the brain damage seen in the initialization list is due to the

View File

@ -53,7 +53,7 @@ class Package;
* *
* See techbase.kde.org for tutorial on writing Applets using this class. * 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_OBJECT
// Q_PROPERTY( QRectF maxSizeHint READ maxSizeHint ) // Q_PROPERTY( QRectF maxSizeHint READ maxSizeHint )

View File

@ -51,31 +51,43 @@ class CheckBox::Private
}; };
CheckBox::CheckBox(QGraphicsItem *parent) CheckBox::CheckBox(QGraphicsItem *parent)
: QObject(), : Plasma::Widget(parent),
QGraphicsItem(parent),
d(new Private) 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); setAcceptedMouseButtons(Qt::LeftButton);
setAcceptsHoverEvents(true); setAcceptsHoverEvents(true);
setAcceptDrops(true); setAcceptDrops(true);
setEnabled(true); setEnabled(true);
setPos(QPointF(0.0,0.0));
d->height = 40; d->height = 40;
d->width = 100 ; d->width = 100 ;
d->maxWidth = 600; d->maxWidth = 600;
setPos(QPointF(0.0,0.0));
d->state= Qt::Unchecked; d->state= Qt::Unchecked;
d->labelText=QString("Plasma");
d->labelTextColor= QColor(201,201,255);
d->hasIcon = false; d->hasIcon = false;
d->iconSize=QSize(32,32); d->iconSize = QSize(32,32);
d->hasMouse = false; d->hasMouse = false;
d->down = false; d->down = false;
d->hovering = false; d->hovering = false;
d->down = false; d->down = false;
} }
CheckBox::~CheckBox() CheckBox::~CheckBox()
{ {
delete d; delete d;
@ -83,16 +95,17 @@ CheckBox::~CheckBox()
QRectF CheckBox::boundingRect() const 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) Q_UNUSED(option)
QStyleOptionButton options; QStyleOptionButton options;
options.rect = boundingRect().toRect(); options.rect = boundingRect().toRect();
options.text = text(); 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) { //if (d->down) {
// options.state |= QStyle::State_Sunken; // 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_Raised;
options.state |= QStyle::State_On; options.state |= QStyle::State_On;
} }
widget-> style()->drawControl(QStyle::CE_CheckBox, &options, painter, widget); widget-> style()->drawControl(QStyle::CE_CheckBox, &options, painter, widget);
} }

View File

@ -23,8 +23,9 @@
#include <QtGui/QGraphicsItem> #include <QtGui/QGraphicsItem>
#include <plasma/plasma_export.h> #include <plasma/plasma_export.h>
#include <plasma/dataengine.h> #include <plasma/dataengine.h>
#include <plasma/widgets/widget.h>
//TODO //TODO
//Please Document this class //Please Document this class
@ -34,45 +35,54 @@ namespace Plasma
/** /**
* Class that emulates a QCheckBox inside 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 Q_OBJECT
public: public:
explicit CheckBox(QGraphicsItem *parent = 0);
explicit CheckBox(const QString &text, QGraphicsItem *parent = 0);
virtual ~CheckBox();
CheckBox(QGraphicsItem *parent = 0); void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
virtual ~CheckBox(); QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); Qt::CheckState checkState() const;
QRectF boundingRect() const; void setChecked(bool checked);
void setText(const QString&) ; void setCheckState(Qt::CheckState state);
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);
void setText(const QString&) ;
QString text() const;
public Q_SLOTS: QSize size() const;
void updated(const QString&, const DataEngine::Data&); void setSize(const QSize &size);
Q_SIGNALS:
void clicked(); int height() const;
protected: void setHeight(int height);
//bool isDown();
void mousePressEvent ( QGraphicsSceneMouseEvent * event ); int width() const;
void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); void setWidth(int width);
void mouseMoveEvent (QGraphicsSceneMouseEvent * event); void setMaximumWidth(int maxwidth);
void hoverMoveEvent ( QGraphicsSceneHoverEvent * event );
void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); public Q_SLOTS:
void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ); void updated(const QString&, const DataEngine::Data&);
private:
class Private ; Q_SIGNALS:
Private * const d; 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;
}; };

View File

@ -62,8 +62,7 @@ class Flash::Private
Flash::Flash(QGraphicsItem *parent) Flash::Flash(QGraphicsItem *parent)
: QObject(), : Plasma::Widget(parent),
QGraphicsItem(parent),
d(new Private) d(new Private)
{ {
d->defaultDuration = 3000; d->defaultDuration = 3000;
@ -212,7 +211,7 @@ QPixmap Flash::renderPixmap()
return pm; 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(option)
Q_UNUSED(widget) Q_UNUSED(widget)

View File

@ -24,6 +24,7 @@
#include <QtGui/QTextOption> #include <QtGui/QTextOption>
#include <plasma/plasma_export.h> #include <plasma/plasma_export.h>
#include <plasma/widgets/widget.h>
namespace Plasma namespace Plasma
{ {
@ -31,14 +32,14 @@ namespace Plasma
/** /**
* Class that allows to flash text or icons inside 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 Q_OBJECT
public: public:
Flash(QGraphicsItem *parent = 0); Flash(QGraphicsItem *parent = 0);
virtual ~Flash(); 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; QRectF boundingRect() const;
QSize size() const; QSize size() const;
int height() const; int height() const;

View File

@ -16,7 +16,7 @@ class Label::Private
}; };
Label::Label(Widget *parent) Label::Label(Widget *parent)
: Widget(parent), : Plasma::Widget(parent),
d(new Private) d(new Private)
{ {
setAlignment(Qt::AlignHCenter); setAlignment(Qt::AlignHCenter);

View File

@ -51,8 +51,7 @@ class PushButton::Private
}; };
PushButton::PushButton(Widget *parent) PushButton::PushButton(Widget *parent)
: QObject(), : Plasma::Widget(parent),
Widget(parent),
d(new Private) d(new Private)
{ {
setAcceptedMouseButtons(Qt::LeftButton); setAcceptedMouseButtons(Qt::LeftButton);

View File

@ -38,8 +38,7 @@ namespace Plasma
* *
* *
*/ */
class PLASMA_EXPORT PushButton : public QObject, class PLASMA_EXPORT PushButton : public Plasma::Widget
public Plasma::Widget
{ {
Q_OBJECT Q_OBJECT

View File

@ -61,8 +61,7 @@ RadioButton::Private::~Private()
RadioButton::RadioButton(QGraphicsItem *parent) RadioButton::RadioButton(QGraphicsItem *parent)
: QObject(), : Plasma::Widget(parent),
QGraphicsItem(parent),
d(new Private) d(new Private)
{ {
setAcceptedMouseButtons(Qt::LeftButton); setAcceptedMouseButtons(Qt::LeftButton);
@ -79,7 +78,7 @@ QRectF RadioButton::boundingRect() const
return QRectF(0, 0, 150, 30); // FIXME: this is obviously wrong 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(); QStyle *style = widget ? widget->style() : QApplication::style();

View File

@ -25,7 +25,7 @@
// KDE includes // KDE includes
#include <plasma/plasma_export.h> #include <plasma/plasma_export.h>
#include <plasma/widgets/widget.h>
#include <plasma/dataengine.h> #include <plasma/dataengine.h>
namespace Plasma 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 Q_OBJECT
public: public:
RadioButton(QGraphicsItem *parent = 0); RadioButton(QGraphicsItem *parent = 0);
virtual ~RadioButton(); virtual ~RadioButton();
// QGraphicsItem overridden virtual methods // QGraphicsItem overridden virtual methods
QRectF boundingRect() const; QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
// Getters // Getters
bool isChecked() const; bool isChecked() const;

View File

@ -36,7 +36,8 @@ class Layout;
/** /**
* Base class for all Widgets in Plasma. * 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 the basis for User Interfaces inside Plasma.
* Widgets are rectangular, but can be in any visible shape by just using transparency to mask * 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() * To implement a Widget, just subclass Plasma::Widget and implement at minimum, sizeHint() and paint()
*/ */
class PLASMA_EXPORT Widget : public QGraphicsItem, class PLASMA_EXPORT Widget : public QObject,
public LayoutItem public QGraphicsItem,
public LayoutItem
{ {
public: Q_OBJECT
public:
/** /**
* Constructor. * Constructor.
*/ */
explicit Widget(QGraphicsItem *parent = 0); explicit Widget(QGraphicsItem *parent = 0);
/** /**
* Virtual Destructor. * Virtual Destructor.
*/ */
virtual ~Widget(); virtual ~Widget();
/** /**
* Returns a bitmask with the directions that this Widget can be expanded. * Returns a bitmask with the directions that this Widget can be expanded.
*/ */
virtual Qt::Orientations expandingDirections() const; virtual Qt::Orientations expandingDirections() const;
/** /**
* Sets the minimum size of this Widget. * Sets the minimum size of this Widget.
*/ */
void setMinimumSize(const QSizeF& size); void setMinimumSize(const QSizeF& size);
/** /**
* Returns the minimum size of this Widget. * Returns the minimum size of this Widget.
*/ */
QSizeF minimumSize() const; QSizeF minimumSize() const;
/** /**
* Sets the maximum size of this Widget. * Sets the maximum size of this Widget.
*/ */
void setMaximumSize(const QSizeF& size); void setMaximumSize(const QSizeF& size);
/** /**
* Returns the maximum size of this Widget. * Returns the maximum size of this Widget.
*/ */
QSizeF maximumSize() const; QSizeF maximumSize() const;
/** /**
* Returns true whatever this Widget can use height-for-width layout management, * Returns true whatever this Widget can use height-for-width layout management,
* false otherwise. * false otherwise.
*/ */
virtual bool hasHeightForWidth() const; virtual bool hasHeightForWidth() const;
/** /**
* Returns the corresponding height for a given width. * Returns the corresponding height for a given width.
* @param w Width * @param w Width
*/ */
virtual qreal heightForWidth(qreal w) const; virtual qreal heightForWidth(qreal w) const;
/** /**
* Returns true whatever this Widget can use width-for-height layout management, * Returns true whatever this Widget can use width-for-height layout management,
* false otherwise. * false otherwise.
*/ */
virtual bool hasWidthForHeight() const; virtual bool hasWidthForHeight() const;
/** /**
* Returns the corresponding width for a given height. * Returns the corresponding width for a given height.
* @param h Height * @param h Height
*/ */
virtual qreal widthForHeight(qreal h) const; virtual qreal widthForHeight(qreal h) const;
/** /**
* Returns the geometry of this Widget, in parent coordinates. * Returns the geometry of this Widget, in parent coordinates.
*/ */
QRectF geometry() const; QRectF geometry() const;
/** /**
* Returns the geometry of this Widget, in local coordinates. * Returns the geometry of this Widget, in local coordinates.
*/ */
QRectF localGeometry() const; QRectF localGeometry() const;
/** /**
* Sets the geometry of this Widget. * Sets the geometry of this Widget.
*/ */
void setGeometry(const QRectF &geometry); void setGeometry(const QRectF &geometry);
/** /**
* Propagates the geometry information to associated layouts and other Widgets. * Propagates the geometry information to associated layouts and other Widgets.
*/ */
void updateGeometry(); void updateGeometry();
/** /**
* Invalidates the geometry information. * Invalidates the geometry information.
*/ */
virtual void invalidate(); virtual void invalidate();
/** /**
* Returns the most appropriate size of this Widget to hold it's contents. * Returns the most appropriate size of this Widget to hold it's contents.
*/ */
virtual QSizeF sizeHint() const; virtual QSizeF sizeHint() const;
/** /**
* Returns the size of this Widget. * Returns the size of this Widget.
*/ */
QSizeF size() const; QSizeF size() const;
/** /**
* Returns the bounding rectangle of this Widget. * Returns the bounding rectangle of this Widget.
*/ */
virtual QRectF boundingRect() const; virtual QRectF boundingRect() const;
/** /**
* Resizes this Widget. * Resizes this Widget.
* @param size New size * @param size New size
*/ */
void resize(const QSizeF &size); void resize(const QSizeF &size);
/** /**
* Resizes this Widget. * Resizes this Widget.
* @param w New width * @param w New width
* @param h New height * @param h New height
*/ */
void resize(qreal w, qreal h); void resize(qreal w, qreal h);
/** /**
* Returns the parent of this Widget. * Returns the parent of this Widget.
*/ */
Widget *parent() const; Widget *parent() const;
/** /**
* Changes the parent of this Widget. * Changes the parent of this Widget.
*/ */
void reparent(Widget *w); void reparent(Widget *w);
/** /**
* Appends a child Widget to this Widget. * Appends a child Widget to this Widget.
*/ */
void addChild(Widget *w); void addChild(Widget *w);
/** /**
* Paint function. * Paint function.
*/ */
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
/** /**
* Paints the widget. Called by the paint function under correct conditions. * Paints the widget. Called by the paint function under correct conditions.
*/ */
virtual void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); virtual void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
private: private:
class Private; class Private;