api to add an existing applet and position mapping

This commit is contained in:
Marco Martin 2014-05-13 12:46:17 +02:00
parent cdb9c8c1cc
commit 64cff59a31
2 changed files with 54 additions and 8 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
@ -245,7 +245,7 @@ QObject *ContainmentInterface::containmentAt(int x, int y)
return 0;
}
void ContainmentInterface::addApplet(AppletInterface *applet)
void ContainmentInterface::addApplet(AppletInterface *applet, int x, int y)
{
if (!applet || applet->applet()->containment() == containment()) {
return;
@ -254,7 +254,35 @@ void ContainmentInterface::addApplet(AppletInterface *applet)
blockSignals(true);
containment()->addApplet(applet->applet());
blockSignals(false);
emit appletAdded(applet, QCursor::pos().x(), QCursor::pos().y());
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)
@ -353,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]));
}
@ -490,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());
}
@ -499,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,9 +115,27 @@ 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);
Q_INVOKABLE void addApplet(AppletInterface *applet);
/**
* 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)
{
@ -167,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);