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
|
2007-09-14 22:17:11 +02:00
|
|
|
* it under the terms of the GNU Library General Public License as
|
2007-09-14 21:06:18 +02:00
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
2007-03-01 20:58:19 +01:00
|
|
|
*
|
|
|
|
* 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-12-23 20:20:22 +01:00
|
|
|
#include <QtGui/QPixmap>
|
2007-03-01 20:58:19 +01:00
|
|
|
|
2007-05-22 18:48:34 +02:00
|
|
|
#include <QtCore/QRectF>
|
|
|
|
#include <QtCore/QSizeF>
|
2007-12-21 06:33:17 +01:00
|
|
|
#include <QtCore/QString>
|
2007-05-22 18:48:34 +02:00
|
|
|
|
2007-11-20 00:40:03 +01:00
|
|
|
#include <plasma/layouts/layoutitem.h>
|
2007-06-02 19:29:39 +02:00
|
|
|
#include <plasma/plasma_export.h>
|
2007-03-02 15:34:41 +01:00
|
|
|
|
2007-12-08 04:35:11 +01:00
|
|
|
class QGraphicsView;
|
2007-12-21 06:33:17 +01:00
|
|
|
class QGraphicsSceneHoverEvent;
|
2007-12-08 04:35:11 +01:00
|
|
|
|
2007-03-02 06:27:33 +01:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2007-12-21 06:33:17 +01:00
|
|
|
struct PLASMA_EXPORT ToolTipData
|
|
|
|
{
|
2008-01-03 12:35:42 +01:00
|
|
|
ToolTipData() : windowToPreview( 0 ) {}
|
2007-12-21 06:33:17 +01:00
|
|
|
QString mainText; //Important information
|
|
|
|
QString subText; //Elaborates on the Main Text
|
|
|
|
QPixmap image; // Icon to show;
|
2008-01-03 12:35:42 +01:00
|
|
|
WId windowToPreview; // Id of window to show preview
|
2007-12-21 06:33:17 +01:00
|
|
|
};
|
|
|
|
|
2007-05-22 18:48:34 +02:00
|
|
|
class Layout;
|
|
|
|
|
2007-12-21 06:33:17 +01:00
|
|
|
|
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.
|
|
|
|
*
|
2007-10-11 21:16:01 +02:00
|
|
|
* To implement a Widget, just subclass Plasma::Widget and implement at minimum,
|
|
|
|
* sizeHint() and paintWidget()
|
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-09-28 07:45:10 +02:00
|
|
|
Q_PROPERTY( QSizeF size READ size WRITE resize )
|
|
|
|
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-10-01 07:06:51 +02:00
|
|
|
virtual void setGeometry(const QRectF &geometry);
|
2007-08-03 18:00:10 +02:00
|
|
|
|
|
|
|
/**
|
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-09-13 21:33:44 +02:00
|
|
|
/**
|
|
|
|
* @return the font currently set for this widget
|
|
|
|
**/
|
|
|
|
QFont font() const;
|
|
|
|
|
2007-08-03 18:00:10 +02:00
|
|
|
/**
|
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
|
|
|
|
2008-01-23 00:39:15 +01:00
|
|
|
/**
|
|
|
|
* @return the Plasma::Widget parent for a given QGraphicsItem
|
|
|
|
*/
|
|
|
|
static Widget *parent(const QGraphicsItem *item);
|
|
|
|
|
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-12-08 04:35:11 +01:00
|
|
|
/**
|
|
|
|
* Returns the view this widget is visible on
|
|
|
|
*/
|
|
|
|
QGraphicsView *view() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps a QRect from a view's coordinates to local coordinates.
|
|
|
|
* @param view the view from which rect should be mapped
|
|
|
|
* @param rect the rect to be mapped
|
|
|
|
*/
|
|
|
|
QRectF mapFromView(const QGraphicsView *view, const QRect &rect) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps a QRectF from local coordinates to a view's coordinates.
|
|
|
|
* @param view the view to which rect should be mapped
|
|
|
|
* @param rect the rect to be mapped
|
|
|
|
*/
|
|
|
|
QRect mapToView(const QGraphicsView *view, const QRectF &rect) const;
|
|
|
|
|
2007-12-21 06:33:17 +01:00
|
|
|
/**
|
|
|
|
* The Data from the tooltip
|
|
|
|
* @returns A ToolTip::Data object with current information
|
|
|
|
*/
|
2008-02-05 19:26:17 +01:00
|
|
|
const ToolTipData* toolTip() const;
|
2007-12-21 06:33:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Setter for data shown in tooltip
|
|
|
|
* @param data a ToolTip::Data object containing icon and text
|
|
|
|
*/
|
|
|
|
void setToolTip( const ToolTipData &dt );
|
2007-12-25 06:34:43 +01:00
|
|
|
|
2008-01-21 12:42:08 +01:00
|
|
|
/**
|
|
|
|
* Recomended position for a popup window like a menu or a tooltip
|
|
|
|
* given its size
|
|
|
|
* @param s size of the popup
|
|
|
|
* @returns recomended position
|
|
|
|
*/
|
|
|
|
QPoint popupPosition(const QSize s) const;
|
|
|
|
|
2008-01-23 00:39:15 +01:00
|
|
|
/**
|
|
|
|
* Reimplemented from QGraphicsItem
|
|
|
|
*/
|
|
|
|
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
|
|
|
|
|
2007-12-25 06:34:43 +01:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
*/
|
|
|
|
virtual void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
|
|
|
|
2007-10-30 00:10:45 +01:00
|
|
|
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
2007-10-24 08:54:26 +02:00
|
|
|
void managingLayoutChanged();
|
2007-12-30 11:45:21 +01:00
|
|
|
|
|
|
|
virtual bool sceneEvent(QEvent *event);
|
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
|