* position applets due to drops properly
* if we get a matching mimetype, create that applet (not that applet + a button too ;) svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=696783
This commit is contained in:
parent
c68077c56e
commit
05d103abfa
52
corona.cpp
52
corona.cpp
@ -175,9 +175,13 @@ QString Corona::appletMimeType()
|
|||||||
void Corona::saveApplets(const QString &config) const
|
void Corona::saveApplets(const QString &config) const
|
||||||
{
|
{
|
||||||
KConfig appletConfig(config);
|
KConfig appletConfig(config);
|
||||||
|
foreach (const QString& group, appletConfig.groupList()) {
|
||||||
|
appletConfig.deleteGroup(group);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (Applet *applet, d->applets) {
|
foreach (Applet *applet, d->applets) {
|
||||||
KConfigGroup cg(&appletConfig, QString::number(applet->id()));
|
KConfigGroup cg(&appletConfig, QString::number(applet->id()));
|
||||||
kDebug() << "saving applet " << applet->name();
|
//kDebug() << "saving applet " << applet->name();
|
||||||
cg.writeEntry("plugin", applet->pluginName());
|
cg.writeEntry("plugin", applet->pluginName());
|
||||||
cg.writeEntry("geometry", QRect(applet->pos().toPoint(), applet->boundingRect().size().toSize()));
|
cg.writeEntry("geometry", QRect(applet->pos().toPoint(), applet->boundingRect().size().toSize()));
|
||||||
}
|
}
|
||||||
@ -214,10 +218,14 @@ Applet* Corona::addApplet(const QString& name, const QStringList& args, uint id,
|
|||||||
qreal appHeight = applet->boundingRect().height();
|
qreal appHeight = applet->boundingRect().height();
|
||||||
if (geometry.isValid()) {
|
if (geometry.isValid()) {
|
||||||
applet->setGeometry(geometry);
|
applet->setGeometry(geometry);
|
||||||
|
} else if (geometry.x() != -1 && geometry.y() != -1) {
|
||||||
|
// yes, this means we can't have items start -1, -1
|
||||||
|
applet->setPos(geometry.topLeft() - QPoint(applet->boundingRect().width()/2,
|
||||||
|
applet->boundingRect().height()/2));
|
||||||
} else {
|
} else {
|
||||||
//TODO: Make sure new applets don't overlap with existing ones
|
//TODO: Make sure new applets don't overlap with existing ones
|
||||||
// Center exactly:
|
// Center exactly:
|
||||||
applet->setPos((width() / 2) - (appWidth / 2),(height() / 2) - (appHeight / 2));
|
applet->setPos((width() / 2) - (appWidth / 2), (height() / 2) - (appHeight / 2));
|
||||||
}
|
}
|
||||||
addItem(applet);
|
addItem(applet);
|
||||||
applet->updateConstraints();
|
applet->updateConstraints();
|
||||||
@ -245,7 +253,7 @@ void Corona::addKaramba(const KUrl& path)
|
|||||||
void Corona::dragEnterEvent( QGraphicsSceneDragDropEvent *event)
|
void Corona::dragEnterEvent( QGraphicsSceneDragDropEvent *event)
|
||||||
{
|
{
|
||||||
kDebug() << "Corona::dragEnterEvent(QGraphicsSceneDragDropEvent* event)";
|
kDebug() << "Corona::dragEnterEvent(QGraphicsSceneDragDropEvent* event)";
|
||||||
if (event->mimeData()->hasFormat("text/x-plasmoidservicename") ||
|
if (event->mimeData()->hasFormat(d->mimetype) ||
|
||||||
KUrl::List::canDecode(event->mimeData())) {
|
KUrl::List::canDecode(event->mimeData())) {
|
||||||
event->acceptProposedAction();
|
event->acceptProposedAction();
|
||||||
//TODO Create the applet, move to mouse position then send the
|
//TODO Create the applet, move to mouse position then send the
|
||||||
@ -277,41 +285,31 @@ void Corona::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
|
|||||||
void Corona::dropEvent(QGraphicsSceneDragDropEvent *event)
|
void Corona::dropEvent(QGraphicsSceneDragDropEvent *event)
|
||||||
{
|
{
|
||||||
//kDebug() << "Corona::dropEvent(QDropEvent* event)";
|
//kDebug() << "Corona::dropEvent(QDropEvent* event)";
|
||||||
if (event->mimeData()->hasFormat("text/x-plasmoidservicename")) {
|
if (event->mimeData()->hasFormat(d->mimetype)) {
|
||||||
//TODO This will pretty much move into dragEnterEvent()
|
|
||||||
QString plasmoidName;
|
QString plasmoidName;
|
||||||
plasmoidName = event->mimeData()->data("text/x-plasmoidservicename");
|
plasmoidName = event->mimeData()->data(d->mimetype);
|
||||||
addApplet(plasmoidName);
|
QRectF geom(event->scenePos(), QSize(0, 0));
|
||||||
Applet *applet = d->applets.last();
|
addApplet(plasmoidName, QStringList(), 0, geom);
|
||||||
// TODO: should we place it centered on the mouse cursor? If so, the
|
|
||||||
// default "zoom in" animation needs changing to zoom in from the same
|
|
||||||
// point, or it just looks odd
|
|
||||||
applet->setPos(event->scenePos()); // -
|
|
||||||
// QPoint(applet->boundingRect().width()/2,applet->boundingRect().height()/2));
|
|
||||||
|
|
||||||
event->acceptProposedAction();
|
event->acceptProposedAction();
|
||||||
} else if (KUrl::List::canDecode(event->mimeData())) {
|
} else if (KUrl::List::canDecode(event->mimeData())) {
|
||||||
KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
|
KUrl::List urls = KUrl::List::fromMimeData(event->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->scenePos(), QSize(0, 0));
|
||||||
|
QStringList args;
|
||||||
|
args << url.url();
|
||||||
// kDebug() << mimeName;
|
// kDebug() << mimeName;
|
||||||
KPluginInfo::List appletList = Applet::knownAppletsForMimetype(mimeName);
|
KPluginInfo::List appletList = Applet::knownAppletsForMimetype(mimeName);
|
||||||
|
|
||||||
|
if (appletList.isEmpty()) {
|
||||||
//FIXME: we should probably show a dialog here to choose which plasmoid load.
|
// no special applet associated with this mimetype, let's
|
||||||
addApplet(appletList.first().pluginName());
|
addApplet("url", args, 0, geom);
|
||||||
|
} else {
|
||||||
QStringList args;
|
//TODO: should we show a dialog here to choose which plasmoid load if
|
||||||
args << url.url();
|
//appletList.count() > 0?
|
||||||
Applet* button = addApplet("url", args);
|
addApplet(appletList.first().pluginName(), args, 0, geom);
|
||||||
if (button) {
|
|
||||||
// button->setSize(128,128);
|
|
||||||
button->setPos(event->scenePos() - QPoint(button->boundingRect().width()/2,
|
|
||||||
button->boundingRect().height()/2));
|
|
||||||
}
|
}
|
||||||
addItem(button);
|
|
||||||
button->updateConstraints();
|
|
||||||
}
|
}
|
||||||
event->acceptProposedAction();
|
event->acceptProposedAction();
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user