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,16 +315,14 @@ 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))
{ {

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,35 +35,41 @@ 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);
CheckBox(QGraphicsItem *parent = 0); explicit CheckBox(const QString &text, QGraphicsItem *parent = 0);
virtual ~CheckBox(); virtual ~CheckBox();
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;
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; Qt::CheckState checkState() const;
void setChecked(bool checked); void setChecked(bool checked);
void setCheckState(Qt::CheckState state); void setCheckState(Qt::CheckState state);
void setText(const QString&) ;
QString text() const;
public Q_SLOTS: 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&); void updated(const QString&, const DataEngine::Data&);
Q_SIGNALS:
Q_SIGNALS:
void clicked(); void clicked();
protected:
protected:
//bool isDown(); //bool isDown();
void mousePressEvent ( QGraphicsSceneMouseEvent * event ); void mousePressEvent ( QGraphicsSceneMouseEvent * event );
void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event );
@ -70,7 +77,10 @@ class PLASMA_EXPORT CheckBox : public QObject, public QGraphicsItem
void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); void hoverMoveEvent ( QGraphicsSceneHoverEvent * event );
void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event );
void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ); void hoverEnterEvent ( QGraphicsSceneHoverEvent * event );
private:
private:
void init();
class Private ; class Private ;
Private * const d; 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,10 +45,12 @@ 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 QGraphicsItem,
public LayoutItem public LayoutItem
{ {
public: Q_OBJECT
public:
/** /**
* Constructor. * Constructor.