mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
Drag launcher app to dock and request undock app when drag out of dock
This commit is contained in:
parent
4952571605
commit
9ca0418b97
@ -8,8 +8,8 @@
|
||||
* Do not edit! All changes made to it will be lost.
|
||||
*/
|
||||
|
||||
#ifndef DBUSDOCKEDAPPMANAGER_H_1435837249
|
||||
#define DBUSDOCKEDAPPMANAGER_H_1435837249
|
||||
#ifndef DBUSDOCKEDAPPMANAGER_H_1436925098
|
||||
#define DBUSDOCKEDAPPMANAGER_H_1436925098
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QByteArray>
|
||||
@ -60,6 +60,20 @@ public Q_SLOTS: // METHODS
|
||||
return asyncCallWithArgumentList(QStringLiteral("IsDocked"), argumentList);
|
||||
}
|
||||
|
||||
inline QDBusPendingReply<bool> ReqeustDock(const QString &in0, const QString &in1, const QString &in2, const QString &in3)
|
||||
{
|
||||
QList<QVariant> argumentList;
|
||||
argumentList << QVariant::fromValue(in0) << QVariant::fromValue(in1) << QVariant::fromValue(in2) << QVariant::fromValue(in3);
|
||||
return asyncCallWithArgumentList(QStringLiteral("ReqeustDock"), argumentList);
|
||||
}
|
||||
|
||||
inline QDBusPendingReply<bool> RequestUndock(const QString &in0)
|
||||
{
|
||||
QList<QVariant> argumentList;
|
||||
argumentList << QVariant::fromValue(in0);
|
||||
return asyncCallWithArgumentList(QStringLiteral("RequestUndock"), argumentList);
|
||||
}
|
||||
|
||||
inline QDBusPendingReply<> Sort(const QStringList &in0)
|
||||
{
|
||||
QList<QVariant> argumentList;
|
||||
|
@ -122,18 +122,25 @@ int DockLayout::spacingItemIndex()
|
||||
|
||||
void DockLayout::moveWithSpacingItem(int hoverIndex)
|
||||
{
|
||||
int itemWidth = 0;
|
||||
if (tmpAppMap.isEmpty())
|
||||
itemWidth = DockModeData::instance()->getNormalItemWidth();
|
||||
else
|
||||
itemWidth = tmpAppMap.firstKey()->width();
|
||||
|
||||
if (sortDirection == LeftToRight)
|
||||
{
|
||||
int spacintIndex = spacingItemIndex();
|
||||
if (spacintIndex == -1)
|
||||
return;
|
||||
|
||||
if (spacintIndex > hoverIndex)
|
||||
{
|
||||
for (int i = hoverIndex; i < spacintIndex; i ++)
|
||||
{
|
||||
AbstractDockItem *targetItem = appList.at(i);
|
||||
|
||||
targetItem->setNextPos(QPoint(targetItem->x() + tmpAppMap.firstKey()->width() + itemSpacing,0));
|
||||
targetItem->setNextPos(QPoint(targetItem->x() + itemWidth + itemSpacing,0));
|
||||
|
||||
QPropertyAnimation *animation = new QPropertyAnimation(targetItem, "pos");
|
||||
animation->setStartValue(targetItem->pos());
|
||||
@ -153,7 +160,7 @@ void DockLayout::moveWithSpacingItem(int hoverIndex)
|
||||
{
|
||||
AbstractDockItem *targetItem = appList.at(i);
|
||||
|
||||
targetItem->setNextPos(QPoint(targetItem->x() - tmpAppMap.firstKey()->width() - itemSpacing,0));
|
||||
targetItem->setNextPos(QPoint(targetItem->x() - itemWidth - itemSpacing,0));
|
||||
|
||||
QPropertyAnimation *animation = new QPropertyAnimation(targetItem, "pos");
|
||||
animation->setStartValue(targetItem->pos());
|
||||
@ -201,14 +208,19 @@ void DockLayout::relayout()
|
||||
|
||||
void DockLayout::addSpacingItem()
|
||||
{
|
||||
int spacingValue = 0;
|
||||
if (tmpAppMap.isEmpty())
|
||||
return;
|
||||
spacingValue = DockModeData::instance()->getNormalItemWidth();
|
||||
else
|
||||
{
|
||||
AbstractDockItem *tmpItem = tmpAppMap.firstKey();
|
||||
spacingValue = tmpItem->width();
|
||||
}
|
||||
|
||||
AbstractDockItem *tmpItem = tmpAppMap.firstKey();
|
||||
for (int i = appList.count() -1;i >= lastHoverIndex; i-- )
|
||||
{
|
||||
AbstractDockItem *targetItem = appList.at(i);
|
||||
targetItem->setNextPos(targetItem->x() + tmpItem->width() + itemSpacing,0);
|
||||
targetItem->setNextPos(targetItem->x() + spacingValue + itemSpacing,0);
|
||||
|
||||
QPropertyAnimation *animation = new QPropertyAnimation(targetItem, "pos");
|
||||
animation->setStartValue(targetItem->pos());
|
||||
@ -264,19 +276,42 @@ void DockLayout::dragEnterEvent(QDragEnterEvent *event)
|
||||
|
||||
void DockLayout::dropEvent(QDropEvent *event)
|
||||
{
|
||||
AbstractDockItem * tmpItem = tmpAppMap.firstKey();
|
||||
tmpAppMap.remove(tmpItem);
|
||||
tmpItem->setVisible(true);
|
||||
if (indexOf(tmpItem) == -1)
|
||||
{
|
||||
if (movingForward)
|
||||
insertItem(tmpItem,lastHoverIndex);
|
||||
else
|
||||
insertItem(tmpItem,lastHoverIndex + 1);
|
||||
}
|
||||
//("text/plain", "COMPOUND_TEXT", "text/plain;charset=utf-8", "_DEEPIN_DND", "text/uri-list")
|
||||
AbstractDockItem *sourceItem = NULL;
|
||||
sourceItem = dynamic_cast<AbstractDockItem *>(event->source());
|
||||
|
||||
emit itemDropped();
|
||||
m_animationItemCount = 0;
|
||||
if (event->mimeData()->formats().indexOf("_DEEPIN_DND") != -1 && !sourceItem)
|
||||
{
|
||||
QString jsonStr = QString(event->mimeData()->data("_DEEPIN_DND")).split("uninstall").last().trimmed();
|
||||
|
||||
//Tim at both ends of the string is added to a character SOH (start of heading)
|
||||
jsonStr = jsonStr.mid(1,jsonStr.length() - 2);
|
||||
QJsonObject dataObj = QJsonDocument::fromJson(jsonStr.trimmed().toUtf8()).object();
|
||||
if (dataObj.isEmpty() || m_ddam->IsDocked(dataObj.value("id").toString()))
|
||||
{
|
||||
relayout();
|
||||
return;
|
||||
}
|
||||
|
||||
m_ddam->ReqeustDock(dataObj.value("id").toString(),dataObj.value("name").toString(),dataObj.value("icon").toString(),"");
|
||||
|
||||
}
|
||||
else if (event->mimeData()->formats().indexOf("_DEEPIN_DND") == -1 && sourceItem)
|
||||
{
|
||||
AbstractDockItem * tmpItem = tmpAppMap.firstKey();
|
||||
tmpAppMap.remove(tmpItem);
|
||||
tmpItem->setVisible(true);
|
||||
if (indexOf(tmpItem) == -1)
|
||||
{
|
||||
if (movingForward)
|
||||
insertItem(tmpItem,lastHoverIndex);
|
||||
else
|
||||
insertItem(tmpItem,lastHoverIndex + 1);
|
||||
}
|
||||
|
||||
emit itemDropped();
|
||||
m_animationItemCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void DockLayout::slotItemDrag()
|
||||
@ -348,10 +383,7 @@ void DockLayout::slotItemEntered(QDragEnterEvent *)
|
||||
|
||||
m_lastPost = tmpPos;
|
||||
|
||||
if (!tmpAppMap.isEmpty())
|
||||
{
|
||||
moveWithSpacingItem(tmpIndex);
|
||||
}
|
||||
moveWithSpacingItem(tmpIndex);
|
||||
}
|
||||
|
||||
void DockLayout::slotItemExited(QDragLeaveEvent *)
|
||||
|
@ -6,6 +6,10 @@
|
||||
#include <QMap>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QCursor>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include "Controller/dockmodedata.h"
|
||||
#include "DBus/dbusdockedappmanager.h"
|
||||
#include "appitem.h"
|
||||
|
||||
class DockLayout : public QWidget
|
||||
@ -62,6 +66,7 @@ private:
|
||||
private:
|
||||
QList<AbstractDockItem *> appList;
|
||||
QMap<AbstractDockItem *,int> tmpAppMap;//only one item inside
|
||||
DBusDockedAppManager *m_ddam = new DBusDockedAppManager(this);
|
||||
|
||||
DockLayout::Direction sortDirection = DockLayout::LeftToRight;
|
||||
qreal itemSpacing = 10;
|
||||
|
@ -27,25 +27,34 @@ void ScreenMask::dragLeaveEvent(QDragLeaveEvent *event)
|
||||
|
||||
void ScreenMask::dropEvent(QDropEvent *event)
|
||||
{
|
||||
qWarning() << "Item drop here:" << event->pos() << event->mimeData()->hasImage();
|
||||
QImage image = qvariant_cast<QImage>(event->mimeData()->imageData());
|
||||
if (!image.isNull())
|
||||
AppItem *sourceItem = NULL;
|
||||
sourceItem = dynamic_cast<AppItem *>(event->source());
|
||||
if (sourceItem)
|
||||
{
|
||||
TransformLabel * imgLabel = new TransformLabel();
|
||||
imgLabel->setAttribute(Qt::WA_TranslucentBackground);
|
||||
imgLabel->setWindowFlags(Qt::ToolTip);
|
||||
imgLabel->setPixmap(QPixmap::fromImage(image));
|
||||
imgLabel->move(event->pos());
|
||||
imgLabel->show();
|
||||
DBusDockedAppManager dda;
|
||||
if (dda.IsDocked(sourceItem->itemData().id))
|
||||
dda.RequestUndock(sourceItem->itemData().id);
|
||||
|
||||
//TODO add animation here
|
||||
QTimer::singleShot(1000,imgLabel,SLOT(deleteLater()));
|
||||
qWarning() << "Item drop here:" << event->pos() << event->mimeData()->hasImage();
|
||||
QImage image = qvariant_cast<QImage>(event->mimeData()->imageData());
|
||||
if (!image.isNull())
|
||||
{
|
||||
TransformLabel * imgLabel = new TransformLabel();
|
||||
imgLabel->setAttribute(Qt::WA_TranslucentBackground);
|
||||
imgLabel->setWindowFlags(Qt::ToolTip);
|
||||
imgLabel->setPixmap(QPixmap::fromImage(image));
|
||||
imgLabel->move(event->pos());
|
||||
imgLabel->show();
|
||||
|
||||
emit itemDropped(event->pos());
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << "Image is NULL!";
|
||||
//TODO add animation here
|
||||
QTimer::singleShot(1000,imgLabel,SLOT(deleteLater()));
|
||||
|
||||
emit itemDropped(event->pos());
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << "Image is NULL!";
|
||||
}
|
||||
}
|
||||
|
||||
this->close();
|
||||
|
@ -14,6 +14,8 @@
|
||||
#include <QMimeData>
|
||||
#include <QTimer>
|
||||
#include <QDebug>
|
||||
#include "DBus/dbusdockedappmanager.h"
|
||||
#include "appitem.h"
|
||||
|
||||
class TransformLabel : public QLabel
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user