Merge branch 'mart/plasmoidMove'

This commit is contained in:
Marco Martin 2014-05-13 12:47:49 +02:00
commit 55514d28c7
2 changed files with 82 additions and 5 deletions

View File

@ -198,7 +198,7 @@ QRect ContainmentInterface::availableScreenRect() const
return rect;
}
Plasma::Applet *ContainmentInterface::addApplet(const QString &plugin, const QVariantList &args, const QPoint &pos)
Plasma::Applet *ContainmentInterface::createApplet(const QString &plugin, const QVariantList &args, const QPoint &pos)
{
//HACK
//This is necessary to delay the appletAdded signal (of containmentInterface) AFTER the applet graphics object has been created
@ -230,6 +230,61 @@ void ContainmentInterface::setAppletArgs(Plasma::Applet *applet, const QString &
}
}
QObject *ContainmentInterface::containmentAt(int x, int y)
{
foreach (Plasma::Containment *c, containment()->corona()->containments()) {
ContainmentInterface *contInterface = c->property("_plasma_graphicObject").value<ContainmentInterface *>();
if (contInterface) {
QWindow *w = contInterface->window();
if (w && w->geometry().contains(QPoint(window()->x(), window()->y()) + QPoint(x, y))) {
return contInterface;
}
}
}
return 0;
}
void ContainmentInterface::addApplet(AppletInterface *applet, int x, int y)
{
if (!applet || applet->applet()->containment() == containment()) {
return;
}
blockSignals(true);
containment()->addApplet(applet->applet());
blockSignals(false);
emit appletAdded(applet, x, y);
}
QPointF ContainmentInterface::mapFromApplet(AppletInterface *applet, int x, int y)
{
if (!applet->window() || !window()) {
return QPointF();
}
//x,y in absolute screen coordinates of current view
QPointF pos = applet->mapToScene(QPointF(x, y));
pos = QPointF(pos + applet->window()->geometry().topLeft());
//return the coordinate in the relative view's coords
return pos - window()->geometry().topLeft();
}
QPointF ContainmentInterface::mapToApplet(AppletInterface *applet, int x, int y)
{
if (!applet->window() || !window()) {
return QPointF();
}
//x,y in absolute screen coordinates of current view
QPointF pos(x, y);
pos = QPointF(pos + window()->geometry().topLeft());
//the coordinate in the relative view's coords
pos = pos - applet->window()->geometry().topLeft();
//make it relative to applet coords
return pos - applet->mapToScene(QPointF(0, 0));
}
void ContainmentInterface::processMimeData(QMimeData *mimeData, int x, int y)
{
if (!mimeData) {
@ -326,7 +381,7 @@ void ContainmentInterface::processMimeData(QMimeData *mimeData, int x, int y)
if (!selectedPlugin.isEmpty()) {
Plasma::Applet *applet = addApplet(selectedPlugin, QVariantList(), QPoint(x, y));
Plasma::Applet *applet = createApplet(selectedPlugin, QVariantList(), QPoint(x, y));
setAppletArgs(applet, pluginFormats[selectedPlugin], mimeData->data(pluginFormats[selectedPlugin]));
}
@ -463,7 +518,7 @@ void ContainmentInterface::mimeTypeRetrieved(KIO::Job *job, const QString &mimet
m_wallpaperInterface->setUrl(tjob->url());
}
} else {
Plasma::Applet *applet = addApplet(actionsToApplets[choice], QVariantList(), posi);
Plasma::Applet *applet = createApplet(actionsToApplets[choice], QVariantList(), posi);
setAppletArgs(applet, mimetype, tjob->url().toString());
}
@ -472,7 +527,7 @@ void ContainmentInterface::mimeTypeRetrieved(KIO::Job *job, const QString &mimet
}
} else {
// we can at least create an icon as a link to the URL
Plasma::Applet *applet = addApplet("org.kde.plasma.icon", QVariantList(), posi);
Plasma::Applet *applet = createApplet("org.kde.plasma.icon", QVariantList(), posi);
setAppletArgs(applet, mimetype, tjob->url().toString());
}
}

View File

@ -115,6 +115,28 @@ public:
*/
Q_INVOKABLE void processMimeData(QMimeData *data, int x, int y);
/**
* Search for a containment at those coordinates.
* the coordinates are passed as local coordinates of *this* containment
*/
Q_INVOKABLE QObject *containmentAt(int x, int y);
/**
* Add an existing applet to this containment.
* The coordinates are passed as local coordinates of this containment
*/
Q_INVOKABLE void addApplet(AppletInterface *applet, int x, int y);
/**
* Map coordinates from relative to the given applet to relative to this containment
*/
Q_INVOKABLE QPointF mapFromApplet(AppletInterface *applet, int x, int y);
/**
*Map coordinates from relative to this containment to relative to the given applet
*/
Q_INVOKABLE QPointF mapToApplet(AppletInterface *applet, int x, int y);
static ContainmentInterface *qmlAttachedProperties(QObject *object)
{
return qobject_cast<ContainmentInterface *>(AppletQuickItem::qmlAttachedProperties(object));
@ -163,7 +185,7 @@ protected Q_SLOTS:
void mimeTypeRetrieved(KIO::Job *job, const QString &mimetype);
private Q_SLOTS:
Plasma::Applet *addApplet(const QString &plugin, const QVariantList &args, const QPoint &pos);
Plasma::Applet *createApplet(const QString &plugin, const QVariantList &args, const QPoint &pos);
private:
void clearDataForMimeJob(KIO::Job *job);