2007-03-01 20:58:19 +01:00
|
|
|
/*
|
2007-08-06 13:20:02 +02:00
|
|
|
* Copyright 2007 by Alexander Wiedenbruch <mail@wiedenbruch.de>
|
2007-05-22 18:48:34 +02:00
|
|
|
* and Matias Valdenegro <mvaldenegro@informatica.utem.cl>
|
2007-03-01 20:58:19 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef WIDGET_H_
|
|
|
|
#define WIDGET_H_
|
|
|
|
|
2007-04-22 11:35:04 +02:00
|
|
|
#include <QtGui/QGraphicsItem>
|
2007-03-01 20:58:19 +01:00
|
|
|
|
2007-05-22 18:48:34 +02:00
|
|
|
#include <QtCore/QRectF>
|
|
|
|
#include <QtCore/QSizeF>
|
|
|
|
|
2007-06-02 19:29:39 +02:00
|
|
|
#include <plasma/widgets/layoutitem.h>
|
|
|
|
#include <plasma/plasma_export.h>
|
2007-03-02 15:34:41 +01:00
|
|
|
|
2007-03-02 06:27:33 +01:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2007-05-22 18:48:34 +02:00
|
|
|
class Layout;
|
|
|
|
|
2007-05-20 18:25:07 +02:00
|
|
|
/**
|
2007-07-23 00:16:40 +02:00
|
|
|
* Base class for all Widgets in Plasma.
|
|
|
|
*
|
2007-08-03 18:00:10 +02:00
|
|
|
* @author Alexander Wiedenbruch
|
|
|
|
* @author Matias Valdenegro
|
2007-07-23 00:16:40 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* out non-rectangular areas.
|
|
|
|
*
|
|
|
|
* To implement a Widget, just subclass Plasma::Widget and implement at minimum, sizeHint() and paint()
|
2007-05-20 18:25:07 +02:00
|
|
|
*/
|
2007-08-03 18:00:10 +02:00
|
|
|
class PLASMA_EXPORT Widget : public QObject,
|
|
|
|
public QGraphicsItem,
|
|
|
|
public LayoutItem
|
2007-03-01 20:58:19 +01:00
|
|
|
{
|
2007-08-03 18:00:10 +02:00
|
|
|
Q_OBJECT
|
2007-08-04 14:37:59 +02:00
|
|
|
Q_PROPERTY( Qt::Orientations expandingDirections READ expandingDirections )
|
|
|
|
Q_PROPERTY( QSizeF minimumSize READ minimumSize WRITE setMinimumSize )
|
|
|
|
Q_PROPERTY( QSizeF maximumSize READ maximumSize WRITE setMaximumSize )
|
|
|
|
Q_PROPERTY( QRectF geometry READ geometry WRITE setGeometry )
|
|
|
|
Q_PROPERTY( QSizeF sizeHint READ sizeHint )
|
2007-08-17 17:05:01 +02:00
|
|
|
Q_PROPERTY( QSizeF size READ size WRITE resize )
|
2007-09-02 19:41:05 +02:00
|
|
|
Q_PROPERTY( qreal opacity READ opacity WRITE setOpacity )
|
2007-08-04 14:37:59 +02:00
|
|
|
|
2007-08-03 18:00:10 +02:00
|
|
|
public:
|
2007-09-10 21:06:58 +02:00
|
|
|
enum CachePaintMode {
|
|
|
|
NoCacheMode,
|
2007-09-13 07:34:11 +02:00
|
|
|
ItemCoordinateCacheMode,
|
|
|
|
DeviceCoordinateCacheMode
|
2007-09-10 21:06:58 +02:00
|
|
|
};
|
2007-08-03 18:00:10 +02:00
|
|
|
|
2007-08-03 20:56:14 +02:00
|
|
|
|
2007-08-03 18:00:10 +02:00
|
|
|
/**
|
2007-08-03 20:56:14 +02:00
|
|
|
* Creates a new Plasma::Widget.
|
|
|
|
* @param parent the QGraphicsItem this icon is parented to.
|
|
|
|
*/
|
2007-08-17 17:05:01 +02:00
|
|
|
explicit Widget(QGraphicsItem *parent = 0 , QObject *parentObject = 0);
|
2007-08-03 18:00:10 +02:00
|
|
|
|
|
|
|
/**
|
2007-08-03 20:56:14 +02:00
|
|
|
* Destroys a Plasma::Widget.
|
|
|
|
*/
|
2007-08-03 18:00:10 +02:00
|
|
|
virtual ~Widget();
|
|
|
|
|
|
|
|
/**
|
2007-08-03 20:56:14 +02:00
|
|
|
* This method is used by Plasma::Layout to determine which directions the
|
|
|
|
* widget naturally expands.
|
|
|
|
* @return bitmask with the directions that this Widget can be expanded.
|
|
|
|
*/
|
2007-08-03 18:00:10 +02:00
|
|
|
virtual Qt::Orientations expandingDirections() const;
|
|
|
|
|
|
|
|
/**
|
2007-08-03 20:56:14 +02:00
|
|
|
* Sets the minimum size of the Widget.
|
|
|
|
* @param size the size to set as the minimum size.
|
|
|
|
*/
|
2007-08-03 18:00:10 +02:00
|
|
|
void setMinimumSize(const QSizeF& size);
|
|
|
|
|
|
|
|
/**
|
2007-08-03 20:56:14 +02:00
|
|
|
* @return minimum size of the Widget.
|
|
|
|
*/
|
2007-08-03 18:00:10 +02:00
|
|
|
QSizeF minimumSize() const;
|
|
|
|
|
|
|
|
/**
|
2007-08-03 20:56:14 +02:00
|
|
|
* Sets the maximum size of the Widget.
|
|
|
|
* @param size the size to set as the maximum size.
|
|
|
|
*/
|
2007-08-03 18:00:10 +02:00
|
|
|
void setMaximumSize(const QSizeF& size);
|
|
|
|
|
|
|
|
/**
|
2007-08-03 20:56:14 +02:00
|
|
|
* @return maximum size of the Widget.
|
|
|
|
*/
|
2007-08-03 18:00:10 +02:00
|
|
|
QSizeF maximumSize() const;
|
|
|
|
|
|
|
|
/**
|
2007-08-03 20:56:14 +02:00
|
|
|
* This method is used by Plasma::Layout to determine whether this widget
|
|
|
|
* can provide a height value given a width value.
|
|
|
|
* @return whether or not this Widget has heightForWidth.
|
|
|
|
*/
|
2007-08-03 18:00:10 +02:00
|
|
|
virtual bool hasHeightForWidth() const;
|
|
|
|
|
|
|
|
/**
|
2007-08-03 20:56:14 +02:00
|
|
|
* This method is used by Plasma::Layout to determine a height value
|
|
|
|
* given a width value.
|
|
|
|
* @param width the width to use to determine height.
|
|
|
|
* @return height calculated using width given.
|
|
|
|
*/
|
|
|
|
virtual qreal heightForWidth(qreal width) const;
|
2007-08-03 18:00:10 +02:00
|
|
|
|
|
|
|
/**
|
2007-08-03 20:56:14 +02:00
|
|
|
* This method is used by Plasma::Layout to determine whether this widget
|
|
|
|
* can provide a width value given a height value.
|
|
|
|
* @return whether or not this Widget has widthForHeight.
|
|
|
|
*/
|
2007-08-03 18:00:10 +02:00
|
|
|
virtual bool hasWidthForHeight() const;
|
|
|
|
|
|
|
|
/**
|
2007-08-03 20:56:14 +02:00
|
|
|
* This method is used by Plasma::Layout to determine a width value
|
|
|
|
* given a height value.
|
|
|
|
* @param height the width to use to determine width.
|
|
|
|
* @return width calculated using height given.
|
|
|
|
*/
|
2007-08-03 18:00:10 +02:00
|
|
|
virtual qreal widthForHeight(qreal h) const;
|
|
|
|
|
|
|
|
/**
|
2007-08-03 20:56:14 +02:00
|
|
|
* @return geometry of this widget.
|
|
|
|
*/
|
2007-08-03 18:00:10 +02:00
|
|
|
QRectF geometry() const;
|
|
|
|
|
|
|
|
/**
|
2007-08-03 20:56:14 +02:00
|
|
|
* Sets the geometry of this Widget.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* Sets the geometry of this Plasma::Widget
|
|
|
|
* @param geometry the geometry to apply to this Plasma::Widget.
|
|
|
|
*/
|
2007-08-03 18:00:10 +02:00
|
|
|
void setGeometry(const QRectF &geometry);
|
|
|
|
|
|
|
|
/**
|
2007-08-03 20:56:14 +02:00
|
|
|
* This method is used to notify any containing Plasma::Layout that it should
|
|
|
|
* reset its geometry.
|
|
|
|
*/
|
|
|
|
// NOTE: this is a completely broken concept -MB
|
2007-08-04 14:37:59 +02:00
|
|
|
Q_INVOKABLE void updateGeometry();
|
2007-08-03 18:00:10 +02:00
|
|
|
|
|
|
|
/**
|
2007-08-03 20:56:14 +02:00
|
|
|
* Returns the recommended size for this widget. Note that this size is not
|
|
|
|
* necessarily only the size for the widget, but might also include margins etc.
|
|
|
|
* @return recommended size for this Plasma::Widget.
|
|
|
|
*/
|
2007-08-03 18:00:10 +02:00
|
|
|
virtual QSizeF sizeHint() const;
|
|
|
|
|
2007-08-03 20:56:14 +02:00
|
|
|
/**
|
|
|
|
* @return the size of this Plasma::Widget
|
|
|
|
*/
|
2007-08-03 18:00:10 +02:00
|
|
|
QSizeF size() const;
|
|
|
|
|
|
|
|
/**
|
2007-08-03 20:56:14 +02:00
|
|
|
* Reimplemented from QGraphicsItem
|
|
|
|
* @return the bounding rectangle for this Plasma::Widget
|
|
|
|
*/
|
2007-08-03 18:00:10 +02:00
|
|
|
virtual QRectF boundingRect() const;
|
|
|
|
|
|
|
|
/**
|
2007-08-03 20:56:14 +02:00
|
|
|
* Resizes this Plasma::Widget.
|
|
|
|
* @param size the new size of this Plasma::Widget.
|
|
|
|
*/
|
2007-08-04 14:37:59 +02:00
|
|
|
Q_INVOKABLE void resize(const QSizeF &size);
|
2007-08-03 18:00:10 +02:00
|
|
|
|
|
|
|
/**
|
2007-08-03 20:56:14 +02:00
|
|
|
* Convenience method for resizing this Plasma::Widget
|
|
|
|
* @param width the new width.
|
|
|
|
* @param height the new height.
|
|
|
|
*/
|
2007-08-04 14:37:59 +02:00
|
|
|
Q_INVOKABLE void resize(qreal width, qreal height);
|
2007-08-03 18:00:10 +02:00
|
|
|
|
|
|
|
/**
|
2007-08-03 20:56:14 +02:00
|
|
|
* @return this Plasma::Widget's parent, returns a null pointer if
|
|
|
|
* none exist.
|
|
|
|
*/
|
2007-08-04 14:37:59 +02:00
|
|
|
Q_INVOKABLE Widget *parent() const;
|
2007-08-03 18:00:10 +02:00
|
|
|
|
|
|
|
/**
|
2007-08-03 20:56:14 +02:00
|
|
|
* Sets the parent of this Plasma::Widget;
|
|
|
|
* @param widget the widget to reparent to.
|
|
|
|
*/
|
2007-08-04 14:37:59 +02:00
|
|
|
Q_INVOKABLE void reparent(Widget *widget);
|
2007-08-03 18:00:10 +02:00
|
|
|
|
|
|
|
/**
|
2007-08-03 20:56:14 +02:00
|
|
|
* Add another Plasma::Widget as a child of this one.
|
|
|
|
* @param widget the widget to reparent to this Plasma::Widget.
|
|
|
|
*/
|
2007-08-04 14:37:59 +02:00
|
|
|
Q_INVOKABLE void addChild(Widget *widget);
|
2007-08-03 18:00:10 +02:00
|
|
|
|
2007-08-13 11:01:00 +02:00
|
|
|
void setOpacity(qreal opacity);
|
2007-08-16 17:56:00 +02:00
|
|
|
qreal opacity() const;
|
2007-08-13 11:01:00 +02:00
|
|
|
|
2007-09-10 21:06:58 +02:00
|
|
|
/**
|
|
|
|
* Sets the widget's cache paint mode and cache size.
|
|
|
|
* @param mode the new cache paint mode
|
|
|
|
* @param mode the new cache size, only applies to ItemCoordinateCacheMode
|
|
|
|
*/
|
|
|
|
void setCachePaintMode(CachePaintMode mode, const QSize &size = QSize());
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The current cache paint mode.
|
|
|
|
*/
|
|
|
|
CachePaintMode cachePaintMode() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invalidates the widget's cache paint mode for a given item rectangle.
|
|
|
|
* @param rect the optional invalidated rectangle; if null, defaults to boundingRect().
|
|
|
|
*/
|
2007-09-10 22:44:24 +02:00
|
|
|
void update(const QRectF &rect = QRectF());
|
|
|
|
inline void update(qreal _x, qreal _y, qreal w, qreal h)
|
|
|
|
{ update(QRectF(_x, _y, w, h)); }
|
2007-09-10 21:06:58 +02:00
|
|
|
|
2007-08-13 11:01:00 +02:00
|
|
|
virtual QGraphicsItem* graphicsItem();
|
|
|
|
|
2007-08-03 20:56:14 +02:00
|
|
|
protected:
|
2007-08-03 18:00:10 +02:00
|
|
|
/**
|
2007-08-03 20:56:14 +02:00
|
|
|
* Paints the widget
|
|
|
|
* @param painter the QPainter to use to paint.
|
|
|
|
* @param option the style option used to give specific info on the item being dawn.
|
|
|
|
* @param widget the parent QWidget (most likely the Corona)
|
|
|
|
*/
|
2007-08-03 18:00:10 +02:00
|
|
|
virtual void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
2007-05-22 18:48:34 +02:00
|
|
|
|
2007-07-12 19:54:58 +02:00
|
|
|
private:
|
2007-08-03 20:56:14 +02:00
|
|
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
|
|
|
|
2007-07-12 19:54:58 +02:00
|
|
|
class Private;
|
|
|
|
Private *const d;
|
2007-03-01 20:58:19 +01:00
|
|
|
};
|
|
|
|
|
2007-03-02 06:27:33 +01:00
|
|
|
} // Plasma namespace
|
|
|
|
|
2007-03-01 20:58:19 +01:00
|
|
|
#endif
|