~ubuntu-branches/ubuntu/gutsy/kdebase-workspace/gutsy-backports

« back to all changes in this revision

Viewing changes to libs/plasma/widgets/widget.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-09-05 20:45:14 UTC
  • Revision ID: james.westby@ubuntu.com-20070905204514-632hhspl0nvrc84i
Tags: upstream-3.93.0
ImportĀ upstreamĀ versionĀ 3.93.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright 2007 by Alexander Wiedenbruch <mail@wiedenbruch.de>
 
3
 *                      and Matias Valdenegro <mvaldenegro@informatica.utem.cl>
 
4
 *
 
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
 
8
 *
 
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
 
13
 *
 
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.
 
18
 */
 
19
 
 
20
#ifndef WIDGET_H_
 
21
#define WIDGET_H_
 
22
 
 
23
#include <QtGui/QGraphicsItem>
 
24
 
 
25
#include <QtCore/QRectF>
 
26
#include <QtCore/QSizeF>
 
27
 
 
28
#include <plasma/widgets/layoutitem.h>
 
29
#include <plasma/plasma_export.h>
 
30
 
 
31
namespace Plasma
 
32
{
 
33
 
 
34
class Layout;
 
35
 
 
36
/**
 
37
 * Base class for all Widgets in Plasma.
 
38
 *
 
39
 * @author Alexander Wiedenbruch
 
40
 * @author Matias Valdenegro
 
41
 *
 
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.
 
45
 *
 
46
 * To implement a Widget, just subclass Plasma::Widget and implement at minimum, sizeHint() and paint()
 
47
 */
 
48
class PLASMA_EXPORT Widget  : public QObject,
 
49
                              public QGraphicsItem,
 
50
                              public LayoutItem
 
51
{
 
52
    Q_OBJECT
 
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 ) 
 
59
 
 
60
public:
 
61
 
 
62
 
 
63
    /**
 
64
     * Creates a new Plasma::Widget.
 
65
     * @param parent the QGraphicsItem this icon is parented to.
 
66
     */
 
67
    explicit Widget(QGraphicsItem *parent = 0 , QObject *parentObject = 0);
 
68
 
 
69
    /**
 
70
     * Destroys a Plasma::Widget.
 
71
     */
 
72
    virtual ~Widget();
 
73
 
 
74
    /**
 
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.
 
78
     */
 
79
    virtual Qt::Orientations expandingDirections() const;
 
80
 
 
81
    /**
 
82
     * Sets the minimum size of the Widget.
 
83
     * @param size the size to set as the minimum size.
 
84
     */
 
85
    void setMinimumSize(const QSizeF& size);
 
86
 
 
87
    /**
 
88
     * @return minimum size of the Widget.
 
89
     */
 
90
    QSizeF minimumSize() const;
 
91
 
 
92
    /**
 
93
     * Sets the maximum size of the Widget.
 
94
     * @param size the size to set as the maximum size.
 
95
     */
 
96
    void setMaximumSize(const QSizeF& size);
 
97
 
 
98
    /**
 
99
     * @return maximum size of the Widget.
 
100
     */
 
101
    QSizeF maximumSize() const;
 
102
 
 
103
    /**
 
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.
 
107
     */
 
108
    virtual bool hasHeightForWidth() const;
 
109
 
 
110
    /**
 
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.
 
115
     */
 
116
    virtual qreal heightForWidth(qreal width) const;
 
117
 
 
118
    /**
 
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.
 
122
     */
 
123
    virtual bool hasWidthForHeight() const;
 
124
 
 
125
    /**
 
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.
 
130
     */
 
131
    virtual qreal widthForHeight(qreal h) const;
 
132
 
 
133
    /**
 
134
     * @return geometry of this widget.
 
135
     */
 
136
    QRectF geometry() const;
 
137
 
 
138
    /**
 
139
    * Sets the geometry of this Widget.
 
140
    */
 
141
    /**
 
142
     * Sets the geometry of this Plasma::Widget
 
143
     * @param geometry the geometry to apply to this Plasma::Widget.
 
144
     */
 
145
    void setGeometry(const QRectF &geometry);
 
146
 
 
147
    /**
 
148
     * This method is used to notify any containing Plasma::Layout that it should
 
149
     * reset its geometry.
 
150
     */
 
151
    // NOTE: this is a completely broken concept -MB
 
152
    Q_INVOKABLE void updateGeometry();
 
153
 
 
154
    /**
 
155
     * Invalidate current geometry of this Plasma::Widget as well as its
 
156
     * parent if it exists.
 
157
     */
 
158
    Q_INVOKABLE virtual void invalidate();
 
159
 
 
160
    /**
 
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.
 
164
     */
 
165
    virtual QSizeF sizeHint() const;
 
166
 
 
167
    /**
 
168
     * @return the size of this Plasma::Widget
 
169
     */
 
170
    QSizeF size() const;
 
171
 
 
172
    /**
 
173
     * Reimplemented from QGraphicsItem
 
174
     * @return the bounding rectangle for this Plasma::Widget
 
175
     */
 
176
    virtual QRectF boundingRect() const;
 
177
 
 
178
    /**
 
179
     * Resizes this Plasma::Widget.
 
180
     * @param size the new size of this Plasma::Widget.
 
181
     */
 
182
    Q_INVOKABLE void resize(const QSizeF &size);
 
183
 
 
184
    /**
 
185
     * Convenience method for resizing this Plasma::Widget
 
186
     * @param width the new width.
 
187
     * @param height the new height.
 
188
     */
 
189
    Q_INVOKABLE void resize(qreal width, qreal height);
 
190
 
 
191
    /**
 
192
     * @return this Plasma::Widget's parent, returns a null pointer if
 
193
     *         none exist.
 
194
     */
 
195
    Q_INVOKABLE Widget *parent() const;
 
196
 
 
197
    /**
 
198
     * Sets the parent of this Plasma::Widget;
 
199
     * @param widget the widget to reparent to.
 
200
     */
 
201
    Q_INVOKABLE void reparent(Widget *widget);
 
202
 
 
203
    /**
 
204
     * Add another Plasma::Widget as a child of this one.
 
205
     * @param widget the widget to reparent to this Plasma::Widget.
 
206
     */
 
207
    Q_INVOKABLE void addChild(Widget *widget);
 
208
 
 
209
    void setOpacity(qreal opacity);
 
210
    qreal opacity() const;
 
211
 
 
212
    virtual QGraphicsItem* graphicsItem();
 
213
 
 
214
protected:
 
215
    /**
 
216
     * Paints the widget
 
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)
 
220
     */
 
221
    virtual void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
 
222
 
 
223
private:
 
224
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
 
225
 
 
226
    class Private;
 
227
    Private *const d;
 
228
};
 
229
 
 
230
} // Plasma namespace
 
231
 
 
232
#endif