API REVIEW:

* watchForMouseMove() -> registerAsDragHandle() / unregisterDragHandle()
* Added isRegisteredAsDragHandle() (I'm not really sure If it's a good idea to add this method).

ping me if you find better names for registerAsDragHandle() / unregisterDragHandle().

CCMAIL: panel-devel@kde.org

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=802774
This commit is contained in:
Davide Bettio 2008-04-30 15:04:49 +00:00
parent 2621c6c07f
commit 0916889c58
2 changed files with 43 additions and 18 deletions

View File

@ -351,7 +351,7 @@ public:
KPluginInfo appletDescription;
Package* package;
OverlayWidget *needsConfigOverlay;
QList<QGraphicsItem*> watchedForMouseMove;
QList<QGraphicsItem*> registeredAsDragHandle;
QStringList loadedEngines;
Plasma::PanelSvg *background;
AppletScript *script;
@ -1069,24 +1069,37 @@ void Applet::setAspectRatioMode(Plasma::AspectRatio mode)
d->aspectRatioMode = mode;
}
void Applet::watchForMouseMove( QGraphicsItem * watched, bool watch )
void Applet::registerAsDragHandle( QGraphicsItem * item )
{
if (!watched) {
if (!item) {
return;
}
int index = d->watchedForMouseMove.indexOf(watched);
if (watch) {
if (index == -1) {
d->watchedForMouseMove.append(watched);
watched->installSceneEventFilter(this);
}
} else if (index != -1) {
d->watchedForMouseMove.removeAt(index);
watched->removeSceneEventFilter(this);
int index = d->registeredAsDragHandle.indexOf(item);
if (index == -1) {
d->registeredAsDragHandle.append(item);
item->installSceneEventFilter(this);
}
}
void Applet::unregisterDragHandle( QGraphicsItem * item )
{
if (!item) {
return;
}
int index = d->registeredAsDragHandle.indexOf(item);
if (index != -1) {
d->registeredAsDragHandle.removeAt(index);
item->removeSceneEventFilter(this);
}
}
bool Applet::isRegisteredAsDragHandle( QGraphicsItem * item )
{
return (d->registeredAsDragHandle.indexOf(item) != -1);
}
bool Applet::hasConfigurationInterface() const
{
return d->hasConfigurationInterface;
@ -1106,7 +1119,7 @@ bool Applet::sceneEventFilter( QGraphicsItem * watched, QEvent * event )
{
switch (event->type()) {
case QEvent::GraphicsSceneMouseMove: {
if (d->watchedForMouseMove.contains( watched )) {
if (d->registeredAsDragHandle.contains( watched )) {
mouseMoveEvent(static_cast<QGraphicsSceneMouseEvent*>(event));
return true;
}

View File

@ -608,16 +608,28 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
void setBackgroundHints(const BackgroundHints hints);
/**
* Register the widgets that manages mouse clicks but you still want
* Register the widgets that manage mouse clicks but you still want
* to be able to drag the applet around when holding the mouse pointer
* on that widgets.
* on that widget.
*
* Calling this results in an eventFilter being places on the widget.
*
* @param widget the widget to watch for mouse move
* @param watch whether to start watching the widget, or to stop doing so
* @param item the item to watch for mouse move
*/
void watchForMouseMove(QGraphicsItem *widget, bool watch);
void registerAsDragHandle( QGraphicsItem * item );
/**
* Unregister a widget registered with registerAsDragHandle.
*
* @param item the item to unregister
*/
void unregisterDragHandle( QGraphicsItem * item );
/**
* @param item the item to look for if it is registered or not
* @return true if it is registered, false otherwise
*/
bool isRegisteredAsDragHandle( QGraphicsItem * item );
/**
* @internal event filter; used for focus watching