2
* Copyright 2007 by Alexander Wiedenbruch <mail@wiedenbruch.de>
3
* and Matias Valdenegro <mvaldenegro@informatica.utem.cl>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU Library General Public License version 2 as
7
* published by the Free Software Foundation
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details
14
* You should have received a copy of the GNU Library General Public
15
* License along with this program; if not, write to the
16
* Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
#include <QtGui/QGraphicsItem>
25
#include <QtCore/QRectF>
26
#include <QtCore/QSizeF>
28
#include <plasma/widgets/layoutitem.h>
29
#include <plasma/plasma_export.h>
37
* Base class for all Widgets in Plasma.
39
* @author Alexander Wiedenbruch
40
* @author Matias Valdenegro
42
* Widgets are the basis for User Interfaces inside Plasma.
43
* Widgets are rectangular, but can be in any visible shape by just using transparency to mask
44
* out non-rectangular areas.
46
* To implement a Widget, just subclass Plasma::Widget and implement at minimum, sizeHint() and paint()
48
class PLASMA_EXPORT Widget : public QObject,
53
Q_PROPERTY( Qt::Orientations expandingDirections READ expandingDirections )
54
Q_PROPERTY( QSizeF minimumSize READ minimumSize WRITE setMinimumSize )
55
Q_PROPERTY( QSizeF maximumSize READ maximumSize WRITE setMaximumSize )
56
Q_PROPERTY( QRectF geometry READ geometry WRITE setGeometry )
57
Q_PROPERTY( QSizeF sizeHint READ sizeHint )
58
Q_PROPERTY( QSizeF size READ size WRITE resize )
64
* Creates a new Plasma::Widget.
65
* @param parent the QGraphicsItem this icon is parented to.
67
explicit Widget(QGraphicsItem *parent = 0 , QObject *parentObject = 0);
70
* Destroys a Plasma::Widget.
75
* This method is used by Plasma::Layout to determine which directions the
76
* widget naturally expands.
77
* @return bitmask with the directions that this Widget can be expanded.
79
virtual Qt::Orientations expandingDirections() const;
82
* Sets the minimum size of the Widget.
83
* @param size the size to set as the minimum size.
85
void setMinimumSize(const QSizeF& size);
88
* @return minimum size of the Widget.
90
QSizeF minimumSize() const;
93
* Sets the maximum size of the Widget.
94
* @param size the size to set as the maximum size.
96
void setMaximumSize(const QSizeF& size);
99
* @return maximum size of the Widget.
101
QSizeF maximumSize() const;
104
* This method is used by Plasma::Layout to determine whether this widget
105
* can provide a height value given a width value.
106
* @return whether or not this Widget has heightForWidth.
108
virtual bool hasHeightForWidth() const;
111
* This method is used by Plasma::Layout to determine a height value
112
* given a width value.
113
* @param width the width to use to determine height.
114
* @return height calculated using width given.
116
virtual qreal heightForWidth(qreal width) const;
119
* This method is used by Plasma::Layout to determine whether this widget
120
* can provide a width value given a height value.
121
* @return whether or not this Widget has widthForHeight.
123
virtual bool hasWidthForHeight() const;
126
* This method is used by Plasma::Layout to determine a width value
127
* given a height value.
128
* @param height the width to use to determine width.
129
* @return width calculated using height given.
131
virtual qreal widthForHeight(qreal h) const;
134
* @return geometry of this widget.
136
QRectF geometry() const;
139
* Sets the geometry of this Widget.
142
* Sets the geometry of this Plasma::Widget
143
* @param geometry the geometry to apply to this Plasma::Widget.
145
void setGeometry(const QRectF &geometry);
148
* This method is used to notify any containing Plasma::Layout that it should
149
* reset its geometry.
151
// NOTE: this is a completely broken concept -MB
152
Q_INVOKABLE void updateGeometry();
155
* Invalidate current geometry of this Plasma::Widget as well as its
156
* parent if it exists.
158
Q_INVOKABLE virtual void invalidate();
161
* Returns the recommended size for this widget. Note that this size is not
162
* necessarily only the size for the widget, but might also include margins etc.
163
* @return recommended size for this Plasma::Widget.
165
virtual QSizeF sizeHint() const;
168
* @return the size of this Plasma::Widget
173
* Reimplemented from QGraphicsItem
174
* @return the bounding rectangle for this Plasma::Widget
176
virtual QRectF boundingRect() const;
179
* Resizes this Plasma::Widget.
180
* @param size the new size of this Plasma::Widget.
182
Q_INVOKABLE void resize(const QSizeF &size);
185
* Convenience method for resizing this Plasma::Widget
186
* @param width the new width.
187
* @param height the new height.
189
Q_INVOKABLE void resize(qreal width, qreal height);
192
* @return this Plasma::Widget's parent, returns a null pointer if
195
Q_INVOKABLE Widget *parent() const;
198
* Sets the parent of this Plasma::Widget;
199
* @param widget the widget to reparent to.
201
Q_INVOKABLE void reparent(Widget *widget);
204
* Add another Plasma::Widget as a child of this one.
205
* @param widget the widget to reparent to this Plasma::Widget.
207
Q_INVOKABLE void addChild(Widget *widget);
209
void setOpacity(qreal opacity);
210
qreal opacity() const;
212
virtual QGraphicsItem* graphicsItem();
217
* @param painter the QPainter to use to paint.
218
* @param option the style option used to give specific info on the item being dawn.
219
* @param widget the parent QWidget (most likely the Corona)
221
virtual void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
224
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
230
} // Plasma namespace