2008-09-07 23:33:02 +02:00
|
|
|
/*
|
2008-09-08 19:32:25 +02:00
|
|
|
* Copyright 2008 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
|
2008-09-07 23:33:02 +02:00
|
|
|
*
|
2008-09-08 19:32:25 +02:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2008-09-07 23:33:02 +02:00
|
|
|
*
|
2008-09-08 19:32:25 +02:00
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
2008-09-07 23:33:02 +02:00
|
|
|
*
|
2008-09-08 19:32:25 +02:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301 USA
|
2008-09-07 23:33:02 +02:00
|
|
|
*/
|
2008-08-02 13:48:56 +02:00
|
|
|
|
2008-08-06 11:19:29 +02:00
|
|
|
#ifndef PLASMA_EXTENDER_H
|
|
|
|
#define PLASMA_EXTENDER_H
|
2008-08-02 13:48:56 +02:00
|
|
|
|
2008-08-02 21:36:54 +02:00
|
|
|
#include <QtGui/QGraphicsWidget>
|
2008-08-02 13:48:56 +02:00
|
|
|
|
2008-10-20 12:58:37 +02:00
|
|
|
#include "plasma/panelsvg.h"
|
2008-08-02 13:48:56 +02:00
|
|
|
#include "plasma/plasma_export.h"
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
class ExtenderPrivate;
|
|
|
|
class ExtenderItem;
|
|
|
|
class Applet;
|
|
|
|
|
|
|
|
/**
|
2008-08-25 19:47:48 +02:00
|
|
|
* @class Extender plasma/extender.h <Plasma/Extender>
|
|
|
|
*
|
|
|
|
* @short Extends applets to allow detachable parts
|
|
|
|
*
|
2008-08-02 19:46:32 +02:00
|
|
|
* An Extender is a widget that visually extends the normal contents of an applet with
|
|
|
|
* additional dynamic widgets called ExtenderItems. These ExtenderItems can be
|
|
|
|
* detached by the user and dropped either on another Extender or on the canvas directly.
|
|
|
|
*
|
|
|
|
* This widget allows using ExtenderItems in your applet. Extender takes care of the presentation
|
|
|
|
* of a collection of ExtenderItems and keeps track of ExtenderItems that originate in it.
|
|
|
|
*
|
|
|
|
* The default Extender implementation displays extender items in a vertical layout with
|
|
|
|
* spacers that appear when dropping an ExtenderItem over it.
|
|
|
|
*
|
2008-08-02 13:48:56 +02:00
|
|
|
* If you wish to have a different presentation of extender items, you can choose to subclass
|
2008-08-02 19:46:32 +02:00
|
|
|
* Extender and reimplement the extenderItem* events and, optionally, the saveState function.
|
2008-10-24 16:49:32 +02:00
|
|
|
*
|
|
|
|
* To use an Extender in you applet, you'll have to instantiate one. A call to extender() in your
|
|
|
|
* applet will create an extender on your applet if you haven't got one already. Every applet can
|
|
|
|
* contain only one extender. Think of it as a decorator that adds some functionality to applets
|
|
|
|
* that require it. Never instantiate an Extender before init() in your applet. This won't work
|
|
|
|
* correctly since a scene is required when an Extender is instantiated.
|
|
|
|
*
|
|
|
|
* As soon as an Extender is instantiated, ExtenderItems contained previously in this Extender are
|
|
|
|
* restored using the initExtenderItem function from the applet the items originally came from. For
|
|
|
|
* more information on how this works and how to use ExtenderItems in general, see the ExtenderItem
|
|
|
|
* API documentation.
|
2008-08-02 13:48:56 +02:00
|
|
|
*/
|
|
|
|
class PLASMA_EXPORT Extender : public QGraphicsWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2008-10-11 18:19:04 +02:00
|
|
|
Q_PROPERTY(QString emptyExtenderMessage READ emptyExtenderMessage WRITE setEmptyExtenderMessage)
|
2008-08-02 13:48:56 +02:00
|
|
|
|
|
|
|
public:
|
2008-10-20 12:58:37 +02:00
|
|
|
/**
|
|
|
|
* Description on how to render the extender's items.
|
|
|
|
*/
|
|
|
|
enum Appearance {
|
2008-10-24 16:49:32 +02:00
|
|
|
NoBorders = 0, /**< Draws no borders on the extender's items. When placed in an applet
|
|
|
|
on the desktop, use this setting and use the standard margins of
|
|
|
|
the applet containing this extender. */
|
|
|
|
BottomUpStacked = 1, /**< Draws no borders on the topmost extenderitem, but draws the
|
|
|
|
left, top and right border on subsequent items. When margins
|
|
|
|
of the containing dialog are set to 0, except for the top
|
|
|
|
margin, this leads to the 'stacked' look, recommended for
|
|
|
|
extenders of applet's contained in a panel at the bottom of
|
|
|
|
the screen. */
|
|
|
|
TopDownStacked = 2 /**< Draws no borders on the bottom extenderitem, but draws the
|
|
|
|
left, bottom and right border on subsequent items. When margins
|
|
|
|
of the containing dialog are set to 0, except for the bottom
|
|
|
|
margin, this leads to the 'stacked' look, recommended for
|
|
|
|
extenders of applet's contained in a panel at the top of
|
|
|
|
the screen. */
|
2008-10-20 12:58:37 +02:00
|
|
|
};
|
|
|
|
|
2008-08-02 13:48:56 +02:00
|
|
|
/**
|
|
|
|
* Creates an extender. Note that extender expects applet to have a config(), and needs a
|
|
|
|
* scene because of that. So you should only instantiate an extender in init() or later, not
|
|
|
|
* in an applet's constructor.
|
2008-10-24 16:49:32 +02:00
|
|
|
* The constructor also takes care of restoring ExtenderItems that were contained in this
|
|
|
|
* extender before, so ExtenderItems are persistent between sessions.
|
2008-08-02 13:48:56 +02:00
|
|
|
* @param applet The applet this extender is part of. Null is not allowed here.
|
|
|
|
*/
|
|
|
|
explicit Extender(Applet *applet);
|
|
|
|
|
|
|
|
~Extender();
|
|
|
|
|
|
|
|
/**
|
2008-10-24 16:49:32 +02:00
|
|
|
* @param message The text to be shown whenever the applet's extender is empty.
|
2008-08-02 13:48:56 +02:00
|
|
|
* Defaults to i18n'ed "no items".
|
|
|
|
*/
|
|
|
|
void setEmptyExtenderMessage(const QString &message);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return The text to be shown whenever the applet's layout is empty.
|
|
|
|
*/
|
|
|
|
QString emptyExtenderMessage() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns a list of all extender items (attached AND detached) where the source applet is
|
|
|
|
* this applet.
|
|
|
|
*/
|
|
|
|
QList<ExtenderItem*> items() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns a list of all attached extender items.
|
|
|
|
*/
|
|
|
|
QList<ExtenderItem*> attachedItems() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns a list of all detached extender items.
|
|
|
|
*/
|
|
|
|
QList<ExtenderItem*> detachedItems() const;
|
|
|
|
|
|
|
|
/**
|
2008-10-12 13:12:24 +02:00
|
|
|
* This function can be used for easily determining if a certain item is already displayed
|
2008-08-02 13:48:56 +02:00
|
|
|
* in a extender item somewhere, so your applet doesn't duplicate this item. Say the applet
|
|
|
|
* displays 'jobs', from an engine which add's a source for every job. In sourceAdded you
|
|
|
|
* could do something like:
|
2008-10-07 18:15:33 +02:00
|
|
|
* if (!item(source)) {
|
2008-08-02 13:48:56 +02:00
|
|
|
* //add an extender item monitoring this source.
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
ExtenderItem *item(const QString &name) const;
|
|
|
|
|
2008-10-20 12:58:37 +02:00
|
|
|
/**
|
|
|
|
* Use this function to instruct the extender on how to render it's items. Usually you will
|
|
|
|
* want to call this function in your applet's constraintsEvent, allthough this is already
|
|
|
|
* done for you when using PopupApplet at base class for your applet. Defaults to NoBorders.
|
|
|
|
*/
|
|
|
|
void setExtenderAppearance(Appearance appearance);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the current way of rendering extender items that is used.
|
|
|
|
*/
|
|
|
|
Appearance extenderAppearance() const;
|
|
|
|
|
2008-08-02 13:48:56 +02:00
|
|
|
protected:
|
|
|
|
/**
|
2008-10-12 13:12:24 +02:00
|
|
|
* Get's called after an item has been added to this extender. The bookkeeping has already
|
2008-08-02 13:48:56 +02:00
|
|
|
* been done when this function get's called. The only thing left to do is put it somewhere
|
|
|
|
* appropriate. The default implementation adds the extenderItem to the appropriate place in
|
|
|
|
* a QGraphicsLinearLayout.
|
|
|
|
* @param item The item that has just been added.
|
|
|
|
* @param pos The location the item has been dropped in local coordinates.
|
|
|
|
*/
|
|
|
|
virtual void itemAddedEvent(ExtenderItem *item, const QPointF &pos);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get's called after an item has been removed from this extender. All bookkeeping has
|
2008-10-12 13:12:24 +02:00
|
|
|
* already been done when this function get's called.
|
2008-08-02 13:48:56 +02:00
|
|
|
* @param item The item that has just been removed.
|
|
|
|
*/
|
|
|
|
virtual void itemRemovedEvent(ExtenderItem *item);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get's called when an ExtenderItem that get's dragged enters this extender. Default
|
|
|
|
* implementation does nothing.
|
|
|
|
*/
|
|
|
|
virtual void itemHoverEnterEvent(ExtenderItem *item);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets called when an ExtenderItem is hovering over this extender. Implement this function
|
|
|
|
* to give some visual feedback about what will happen when the mouse button is released at
|
|
|
|
* that position. The default implementation shows a spacer at the appropriate location in
|
|
|
|
* the layout.
|
2008-10-12 13:12:24 +02:00
|
|
|
* @param item The item that's hovering over this extender. Most useful for obtaining the
|
2008-08-02 13:48:56 +02:00
|
|
|
* size of the spacer.
|
|
|
|
* @param pos The location the item is hovering.
|
|
|
|
*/
|
|
|
|
virtual void itemHoverMoveEvent(ExtenderItem *item, const QPointF &pos);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get's called when an ExtenderItem that was previously hovering over this extender moves
|
|
|
|
* away from this extender. The default implementation removes any spacer from the layout.
|
|
|
|
*/
|
|
|
|
virtual void itemHoverLeaveEvent(ExtenderItem *item);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function get's called for every extender when plasma exits. Implement this function
|
|
|
|
* to store the current state of this extender (position in a layout for example), so this
|
|
|
|
* can be restored when applet starts again. The default implementation stores the y
|
|
|
|
* coordinate of every extender item in the config field extenderItemPos.
|
|
|
|
*/
|
|
|
|
virtual void saveState();
|
|
|
|
|
2008-10-20 12:58:37 +02:00
|
|
|
/**
|
|
|
|
* This function get's called on every item to determine which background border's to
|
|
|
|
* render.
|
|
|
|
* @param item the item for which it's position or extender has changed.
|
|
|
|
* @return the borders that have to be enabled on it's background.
|
|
|
|
*/
|
|
|
|
virtual PanelSvg::EnabledBorders enabledBordersForItem(ExtenderItem *item) const;
|
|
|
|
|
2008-08-05 19:28:58 +02:00
|
|
|
/**
|
2008-10-24 16:49:32 +02:00
|
|
|
* Reimplemented from QGraphicsWidget
|
2008-08-05 19:28:58 +02:00
|
|
|
*/
|
|
|
|
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
|
|
|
|
|
|
|
/**
|
2008-10-24 16:49:32 +02:00
|
|
|
* Reimplemented from QGraphicsWidget
|
2008-08-05 19:28:58 +02:00
|
|
|
*/
|
|
|
|
void resizeEvent(QGraphicsSceneResizeEvent *event);
|
|
|
|
|
2008-08-02 13:48:56 +02:00
|
|
|
Q_SIGNALS:
|
|
|
|
/**
|
|
|
|
* Fires when an extender item is added to this extender.
|
|
|
|
*/
|
|
|
|
void itemAttached(Plasma::ExtenderItem *);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fires when an extender item is removed from this extender.
|
|
|
|
*/
|
|
|
|
void itemDetached(Plasma::ExtenderItem *);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fires when an extender's preferred size changes.
|
|
|
|
*/
|
|
|
|
void geometryChanged();
|
|
|
|
|
|
|
|
private:
|
2008-10-11 18:19:04 +02:00
|
|
|
ExtenderPrivate *const d;
|
2008-08-02 13:48:56 +02:00
|
|
|
|
|
|
|
friend class ExtenderPrivate;
|
|
|
|
friend class ExtenderItem;
|
|
|
|
friend class ExtenderItemPrivate;
|
2008-10-20 12:58:37 +02:00
|
|
|
//dialog needs access to the extender's applet location.
|
|
|
|
friend class DialogPrivate;
|
2008-08-02 13:48:56 +02:00
|
|
|
//applet should be able to call saveState();
|
|
|
|
friend class Applet;
|
|
|
|
|
|
|
|
};
|
|
|
|
} // Plasma namespace
|
|
|
|
|
2008-08-06 11:19:29 +02:00
|
|
|
#endif //PLASMA_EXTENDER_H
|
2008-08-02 19:46:32 +02:00
|
|
|
|