middle-click pastes data onto containments now :)
svn path=/trunk/KDE/kdelibs/; revision=963659
This commit is contained in:
parent
13dd4280f7
commit
571367cec2
102
containment.cpp
102
containment.cpp
@ -21,6 +21,7 @@
|
|||||||
#include "containment.h"
|
#include "containment.h"
|
||||||
#include "private/containment_p.h"
|
#include "private/containment_p.h"
|
||||||
|
|
||||||
|
#include <QClipboard>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QGraphicsSceneContextMenuEvent>
|
#include <QGraphicsSceneContextMenuEvent>
|
||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
@ -448,6 +449,9 @@ void Containment::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
|
|
||||||
if (event->isAccepted()) {
|
if (event->isAccepted()) {
|
||||||
setFocus(Qt::MouseFocusReason);
|
setFocus(Qt::MouseFocusReason);
|
||||||
|
} else if (event->button() == Qt::MidButton) {
|
||||||
|
//middle-click = paste
|
||||||
|
event->accept();
|
||||||
} else {
|
} else {
|
||||||
event->accept();
|
event->accept();
|
||||||
Applet::mousePressEvent(event);
|
Applet::mousePressEvent(event);
|
||||||
@ -464,7 +468,13 @@ void Containment::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!event->isAccepted()) {
|
if (event->isAccepted()) {
|
||||||
|
//do nothing
|
||||||
|
} else if (event->button() == Qt::MidButton) {
|
||||||
|
//middle-click = paste
|
||||||
|
event->accept();
|
||||||
|
d->dropData(event);
|
||||||
|
} else {
|
||||||
event->accept();
|
event->accept();
|
||||||
Applet::mouseReleaseEvent(event);
|
Applet::mouseReleaseEvent(event);
|
||||||
}
|
}
|
||||||
@ -1002,43 +1012,79 @@ void Containment::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
|
|||||||
|
|
||||||
void Containment::dropEvent(QGraphicsSceneDragDropEvent *event)
|
void Containment::dropEvent(QGraphicsSceneDragDropEvent *event)
|
||||||
{
|
{
|
||||||
//kDebug() << event->mimeData()->text();
|
if (isContainment()) {
|
||||||
if (!isContainment()) {
|
d->dropData(event);
|
||||||
|
} else {
|
||||||
Applet::dropEvent(event);
|
Applet::dropEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContainmentPrivate::dropData(QGraphicsSceneEvent *event)
|
||||||
|
{
|
||||||
|
if (q->immutability() != Mutable) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString appletMimetype(corona() ? corona()->appletMimeType() : QString());
|
QGraphicsSceneDragDropEvent *dropEvent = dynamic_cast<QGraphicsSceneDragDropEvent*>(event);
|
||||||
|
QGraphicsSceneMouseEvent *mouseEvent = dynamic_cast<QGraphicsSceneMouseEvent*>(event);
|
||||||
|
|
||||||
if (!appletMimetype.isEmpty() && event->mimeData()->hasFormat(appletMimetype)) {
|
QPointF pos;
|
||||||
QString data = event->mimeData()->data(appletMimetype);
|
QPointF scenePos;
|
||||||
|
QPoint screenPos;
|
||||||
|
const QMimeData *mimeData;
|
||||||
|
|
||||||
|
if (dropEvent) {
|
||||||
|
pos = dropEvent->pos();
|
||||||
|
scenePos = dropEvent->scenePos();
|
||||||
|
screenPos = dropEvent->screenPos();
|
||||||
|
mimeData = dropEvent->mimeData();
|
||||||
|
} else if (mouseEvent) {
|
||||||
|
pos = mouseEvent->pos();
|
||||||
|
scenePos = mouseEvent->scenePos();
|
||||||
|
screenPos = mouseEvent->screenPos();
|
||||||
|
QClipboard *clipboard = QApplication::clipboard();
|
||||||
|
mimeData = clipboard->mimeData(QClipboard::Selection);
|
||||||
|
//TODO if that's not supported (ie non-linux) should we try clipboard instead of selection?
|
||||||
|
} else {
|
||||||
|
kDebug() << "unexpected event";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//kDebug() << event->mimeData()->text();
|
||||||
|
|
||||||
|
QString appletMimetype(q->corona() ? q->corona()->appletMimeType() : QString());
|
||||||
|
|
||||||
|
if (!appletMimetype.isEmpty() && mimeData->hasFormat(appletMimetype)) {
|
||||||
|
QString data = mimeData->data(appletMimetype);
|
||||||
QStringList appletNames = data.split('\n', QString::SkipEmptyParts);
|
QStringList appletNames = data.split('\n', QString::SkipEmptyParts);
|
||||||
|
|
||||||
foreach (const QString &appletName, appletNames) {
|
foreach (const QString &appletName, appletNames) {
|
||||||
//kDebug() << "doing" << appletName;
|
//kDebug() << "doing" << appletName;
|
||||||
QRectF geom(mapFromScene(event->scenePos()), QSize(0, 0));
|
QRectF geom(q->mapFromScene(scenePos), QSize(0, 0));
|
||||||
addApplet(appletName, QVariantList(), geom);
|
q->addApplet(appletName, QVariantList(), geom);
|
||||||
}
|
}
|
||||||
event->acceptProposedAction();
|
if (dropEvent) {
|
||||||
} else if (event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())) {
|
dropEvent->acceptProposedAction();
|
||||||
|
}
|
||||||
|
} else if (mimeData->hasFormat(ExtenderItemMimeData::mimeType())) {
|
||||||
kDebug() << "mimetype plasma/extenderitem is dropped, creating internal:extender";
|
kDebug() << "mimetype plasma/extenderitem is dropped, creating internal:extender";
|
||||||
//Handle dropping extenderitems.
|
//Handle dropping extenderitems.
|
||||||
const ExtenderItemMimeData *mimeData = qobject_cast<const ExtenderItemMimeData*>(event->mimeData());
|
const ExtenderItemMimeData *extenderData = qobject_cast<const ExtenderItemMimeData*>(mimeData);
|
||||||
if (mimeData) {
|
if (extenderData) {
|
||||||
ExtenderItem *item = mimeData->extenderItem();
|
ExtenderItem *item = extenderData->extenderItem();
|
||||||
QRectF geometry(event->pos(), item->size());
|
QRectF geometry(pos, item->size());
|
||||||
kDebug() << "desired geometry: " << geometry;
|
kDebug() << "desired geometry: " << geometry;
|
||||||
Applet *applet = addApplet("internal:extender", QVariantList(), geometry);
|
Applet *applet = q->addApplet("internal:extender", QVariantList(), geometry);
|
||||||
item->setExtender(applet->extender());
|
item->setExtender(applet->extender());
|
||||||
}
|
}
|
||||||
} else if (KUrl::List::canDecode(event->mimeData())) {
|
} else if (KUrl::List::canDecode(mimeData)) {
|
||||||
//TODO: collect the mimetypes of available script engines and offer
|
//TODO: collect the mimetypes of available script engines and offer
|
||||||
// to create widgets out of the matching URLs, if any
|
// to create widgets out of the matching URLs, if any
|
||||||
KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
|
KUrl::List urls = KUrl::List::fromMimeData(mimeData);
|
||||||
foreach (const KUrl &url, urls) {
|
foreach (const KUrl &url, urls) {
|
||||||
KMimeType::Ptr mime = KMimeType::findByUrl(url);
|
KMimeType::Ptr mime = KMimeType::findByUrl(url);
|
||||||
QString mimeName = mime->name();
|
QString mimeName = mime->name();
|
||||||
QRectF geom(event->pos(), QSize());
|
QRectF geom(pos, QSize());
|
||||||
QVariantList args;
|
QVariantList args;
|
||||||
args << url.url();
|
args << url.url();
|
||||||
// kDebug() << mimeName;
|
// kDebug() << mimeName;
|
||||||
@ -1061,19 +1107,21 @@ void Containment::dropEvent(QGraphicsSceneDragDropEvent *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
actionsToPlugins.insert(choices.addAction(i18n("Icon")), "icon");
|
actionsToPlugins.insert(choices.addAction(i18n("Icon")), "icon");
|
||||||
QAction *choice = choices.exec(event->screenPos());
|
QAction *choice = choices.exec(screenPos);
|
||||||
if (choice) {
|
if (choice) {
|
||||||
addApplet(actionsToPlugins[choice], args, geom);
|
q->addApplet(actionsToPlugins[choice], args, geom);
|
||||||
}
|
}
|
||||||
} else if (url.protocol() != "data") {
|
} else if (url.protocol() != "data") {
|
||||||
// We don't try to do anything with data: URIs
|
// We don't try to do anything with data: URIs
|
||||||
// no special applet associated with this mimetype, let's
|
// no special applet associated with this mimetype, let's
|
||||||
addApplet("icon", args, geom);
|
q->addApplet("icon", args, geom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
event->acceptProposedAction();
|
if (dropEvent) {
|
||||||
|
dropEvent->acceptProposedAction();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
QStringList formats = event->mimeData()->formats();
|
QStringList formats = mimeData->formats();
|
||||||
QHash<QString, KPluginInfo> seenPlugins;
|
QHash<QString, KPluginInfo> seenPlugins;
|
||||||
QHash<QString, QString> pluginFormats;
|
QHash<QString, QString> pluginFormats;
|
||||||
|
|
||||||
@ -1112,7 +1160,7 @@ void Containment::dropEvent(QGraphicsSceneDragDropEvent *event)
|
|||||||
actionsToPlugins.insert(action, info.pluginName());
|
actionsToPlugins.insert(action, info.pluginName());
|
||||||
}
|
}
|
||||||
|
|
||||||
QAction *choice = choices.exec(event->screenPos());
|
QAction *choice = choices.exec(screenPos);
|
||||||
if (choice) {
|
if (choice) {
|
||||||
selectedPlugin = actionsToPlugins[choice];
|
selectedPlugin = actionsToPlugins[choice];
|
||||||
}
|
}
|
||||||
@ -1126,17 +1174,17 @@ void Containment::dropEvent(QGraphicsSceneDragDropEvent *event)
|
|||||||
|
|
||||||
{
|
{
|
||||||
QDataStream stream(&tempFile);
|
QDataStream stream(&tempFile);
|
||||||
QByteArray data = event->mimeData()->data(pluginFormats[selectedPlugin]);
|
QByteArray data = mimeData->data(pluginFormats[selectedPlugin]);
|
||||||
stream.writeRawData(data, data.size());
|
stream.writeRawData(data, data.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF geom(event->pos(), QSize());
|
QRectF geom(pos, QSize());
|
||||||
QVariantList args;
|
QVariantList args;
|
||||||
args << tempFile.fileName();
|
args << tempFile.fileName();
|
||||||
kDebug() << args;
|
kDebug() << args;
|
||||||
tempFile.close();
|
tempFile.close();
|
||||||
|
|
||||||
addApplet(selectedPlugin, args, geom);
|
q->addApplet(selectedPlugin, args, geom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,6 +106,12 @@ public:
|
|||||||
*/
|
*/
|
||||||
Context *context();
|
Context *context();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles dropped/pasted mimetype data
|
||||||
|
* @param event the drop or mouse event
|
||||||
|
*/
|
||||||
|
void dropData(QGraphicsSceneEvent *event);
|
||||||
|
|
||||||
Containment *q;
|
Containment *q;
|
||||||
FormFactor formFactor;
|
FormFactor formFactor;
|
||||||
Location location;
|
Location location;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user