[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdebase/workspace/libs/plasma
From: Kevin Ottens <ervin () kde ! org>
Date: 2007-11-12 19:27:25
Message-ID: 1194895645.824689.13686.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 735845 by ervin:
Add support for applet handles in plasma containments.
Still a couple of issues to flesh out, but that's usable already.
M +1 -0 CMakeLists.txt
M +2 -3 applet.cpp
A applethandle.cpp [License: LGPL]
A applethandle_p.h [License: LGPL]
M +42 -50 containment.cpp
M +6 -2 containment.h
M +0 -3 corona.cpp
--- trunk/KDE/kdebase/workspace/libs/plasma/CMakeLists.txt #735844:735845
@@ -24,6 +24,7 @@
appletbrowser/kcategorizeditemsviewmodels.cpp
appletbrowser/plasmaappletitemmodel.cpp
appletbrowser/customdragtreeview.cpp
+ applethandle.cpp
configxml.cpp
containment.cpp
corona.cpp
--- trunk/KDE/kdebase/workspace/libs/plasma/applet.cpp #735844:735845
@@ -110,6 +110,7 @@
void init(Applet* applet)
{
+ applet->setAcceptsHoverEvents(true);
applet->setZValue(100);
kioskImmutable = applet->globalConfig().isImmutable() ||
applet->config().isImmutable();
@@ -218,7 +219,7 @@
p.setRenderHint(QPainter::SmoothPixmapTransform);
//FIXME: This is a hack to fix a drawing problems with svg files where a \
thin transparent border is drawn around the svg image.
- // the transparent border around the svg seems to vary in size \
depending on the size of the svg and as a result increasing the + // \
the transparent border around the svg seems to vary in size depending on the size of \
the svg and as a result increasing the
// svn image by 2 all around didn't resolve the issue. For now it resizes \
based on the border size.
background->resize(contentWidth, contentHeight);
@@ -574,8 +575,6 @@
void Applet::setImmutable(bool immutable)
{
d->immutable = immutable;
- setFlag(QGraphicsItem::ItemIsMovable, d->immutable || d->kioskImmutable ||
- !scene() || \
!static_cast<Corona*>(scene())->isImmutable()); }
bool Applet::drawStandardBackground()
--- trunk/KDE/kdebase/workspace/libs/plasma/containment.cpp #735844:735845
@@ -36,6 +36,7 @@
#include <KServiceTypeTrader>
#include <KStandardDirs>
+#include "applethandle_p.h"
#include "corona.h"
#include "phase.h"
#include "svg.h"
@@ -68,6 +69,7 @@
FormFactor formFactor;
Location location;
Applet::List applets;
+ QMap<Applet*, AppletHandle*> handles;
int screen;
bool immutable;
};
@@ -102,7 +104,7 @@
//TODO: would be nice to not do this on init, as it causes Phase to init
connect(Phase::self(), \
SIGNAL(animationComplete(QGraphicsItem*,Plasma::Phase::Animation)),
- this, SLOT(appletDisappearComplete(QGraphicsItem*,Plasma::Phase::Animation)));
+ this, SLOT(appletAnimationComplete(QGraphicsItem*,Plasma::Phase::Animation)));
}
void Containment::initConstraints(KConfigGroup* group)
@@ -182,45 +184,10 @@
foreach(QAction* action, actions) {
desktopMenu.addAction(action);
}
- } else if (applet->isImmutable()) {
+ } else {
kDebug() << "immutable applet";
QGraphicsItem::contextMenuEvent(event);
return;
- } else {
- bool hasEntries = false;
- if (applet->hasConfigurationInterface()) {
- QAction* configureApplet = new QAction(i18n("%1 Settings...", \
applet->name()), &desktopMenu);
- connect(configureApplet, SIGNAL(triggered(bool)),
- applet, SLOT(showConfigurationInterface()));
- desktopMenu.addAction(configureApplet);
- hasEntries = true;
- }
-
- if (scene() && !static_cast<Corona*>(scene())->isImmutable()) {
- QAction* closeApplet = new QAction(i18n("Remove this %1", \
applet->name()), &desktopMenu);
- QVariant appletV;
- appletV.setValue((QObject*)applet);
- closeApplet->setData(appletV);
- connect(closeApplet, SIGNAL(triggered(bool)),
- this, SLOT(destroyApplet()));
- desktopMenu.addAction(closeApplet);
- hasEntries = true;
- }
-
- QList<QAction*> actions = applet->contextActions();
- if (!actions.isEmpty()) {
- desktopMenu.addSeparator();
- foreach(QAction* action, actions) {
- desktopMenu.addAction(action);
- }
- hasEntries = true;
- }
-
- if (!hasEntries) {
- QGraphicsItem::contextMenuEvent(event);
- kDebug() << "no entries";
- return;
- }
}
event->accept();
@@ -375,20 +342,8 @@
}
}
-void Containment::destroyApplet()
+void Containment::appletAnimationComplete(QGraphicsItem *item, \
Plasma::Phase::Animation anim) {
- QAction *action = qobject_cast<QAction*>(sender());
-
- if (!action) {
- return;
- }
-
- Applet *applet = qobject_cast<Applet*>(action->data().value<QObject*>());
- Phase::self()->animateItem(applet, Phase::Disappear);
-}
-
-void Containment::appletDisappearComplete(QGraphicsItem *item, \
Plasma::Phase::Animation anim)
-{
if (anim == Phase::Disappear) {
if (item->parentItem() == this) {
Applet *applet = qgraphicsitem_cast<Applet*>(item);
@@ -397,6 +352,10 @@
applet->destroy();
}
}
+ } else if (anim == Phase::Appear) {
+ if (type()==DesktopContainment) {
+ item->installSceneEventFilter(this);
+ }
}
}
@@ -550,6 +509,39 @@
Q_UNUSED(event)
}
+bool Containment::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
+{
+ Applet *applet = qgraphicsitem_cast<Applet*>(watched);
+ //QEvent::GraphicsSceneHoverEnter
+
+ // Otherwise we're watching something we shouldn't be...
+ Q_ASSERT(applet!=0);
+ Q_ASSERT(d->applets.contains(applet));
+
+ switch (event->type())
+ {
+ case QEvent::GraphicsSceneHoverEnter:
+ if (!d->immutable && !applet->isImmutable()
+ && !d->handles.contains(applet)) {
+ AppletHandle *handle = new AppletHandle(this, applet);
+ d->handles[applet] = handle;
+ connect(handle, SIGNAL(disappearDone(AppletHandle*)),
+ this, SLOT(handleDisappeared(AppletHandle*)));
+ }
+ break;
+ default:
+ break;
+ }
+
+ return false;
}
+void Containment::handleDisappeared(AppletHandle *handle)
+{
+ d->handles.remove(handle->applet());
+ handle->deleteLater();
+}
+
+}
+
#include "containment.moc"
--- trunk/KDE/kdebase/workspace/libs/plasma/containment.h #735844:735845
@@ -33,6 +33,7 @@
namespace Plasma
{
+class AppletHandle;
class DataEngine;
class Package;
class Corona;
@@ -226,16 +227,19 @@
void contextMenuEvent(QGraphicsSceneContextMenuEvent * event);
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
+ bool sceneEventFilter(QGraphicsItem *watched, QEvent *event);
protected Q_SLOTS:
/**
* @internal
*/
void appletDestroyed(QObject*);
- void destroyApplet();
- void appletDisappearComplete(QGraphicsItem *item, Plasma::Phase::Animation \
anim); + void appletAnimationComplete(QGraphicsItem *item, \
Plasma::Phase::Animation anim); void dropEvent(QGraphicsSceneDragDropEvent* event);
+ private Q_SLOTS:
+ void handleDisappeared(AppletHandle *handle);
+
private:
Q_DISABLE_COPY(Containment)
--- trunk/KDE/kdebase/workspace/libs/plasma/corona.cpp #735844:735845
@@ -415,9 +415,6 @@
}
d->immutable = immutable;
- foreach (QGraphicsItem* item, items()) {
- item->setFlag(QGraphicsItem::ItemIsMovable, immutable);
- }
}
} // namespace Plasma
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic