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,
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

View File

@ -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 )

View File

@ -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);
}

View File

@ -23,8 +23,9 @@
#include <QtGui/QGraphicsItem>
#include <plasma/plasma_export.h>
#include <plasma/dataengine.h>
#include <plasma/widgets/widget.h>
//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;
};

View File

@ -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)

View File

@ -24,6 +24,7 @@
#include <QtGui/QTextOption>
#include <plasma/plasma_export.h>
#include <plasma/widgets/widget.h>
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;

View File

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

View File

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

View File

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

View File

@ -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();

View File

@ -25,7 +25,7 @@
// KDE includes
#include <plasma/plasma_export.h>
#include <plasma/widgets/widget.h>
#include <plasma/dataengine.h>
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;

View File

@ -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;