mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
support plugins item drag & drop
Change-Id: Iaee1b8023cbfeb1d03705f8729639732d5a0dbd6
This commit is contained in:
parent
c981babb53
commit
e53b4577bd
@ -37,6 +37,11 @@ void DockItemController::itemMove(DockItem * const moveItem, DockItem * const re
|
||||
if (replaceType != DockItem::App && replaceType != DockItem::Placeholder)
|
||||
return;
|
||||
|
||||
// plugins move
|
||||
if (moveType == DockItem::Plugins)
|
||||
if (replaceType != DockItem::Plugins)
|
||||
return;
|
||||
|
||||
const int moveIndex = m_itemList.indexOf(moveItem);
|
||||
const int replaceIndex = replaceItem->itemType() == DockItem::Placeholder ?
|
||||
// disable insert after placeholder item
|
||||
|
@ -31,7 +31,6 @@ private:
|
||||
const QString contextMenu() const;
|
||||
|
||||
void startDrag();
|
||||
void initClientManager();
|
||||
|
||||
private slots:
|
||||
void updateTitle();
|
||||
|
@ -4,23 +4,36 @@
|
||||
|
||||
#include <QPainter>
|
||||
#include <QBoxLayout>
|
||||
#include <QMouseEvent>
|
||||
#include <QDrag>
|
||||
#include <QMimeData>
|
||||
|
||||
#define PLUGIN_ITEM_DRAG_THRESHOLD 20
|
||||
|
||||
QPoint PluginsItem::MousePressPoint = QPoint();
|
||||
|
||||
PluginsItem::PluginsItem(PluginsItemInterface* const pluginInter, const QString &itemKey, QWidget *parent)
|
||||
: DockItem(Plugins, parent),
|
||||
m_pluginInter(pluginInter),
|
||||
m_itemKey(itemKey)
|
||||
m_itemKey(itemKey),
|
||||
m_draging(false)
|
||||
{
|
||||
m_type = pluginInter->pluginType(itemKey);
|
||||
m_pluginType = pluginInter->pluginType(itemKey);
|
||||
|
||||
if (m_type == PluginsItemInterface::Simple)
|
||||
if (m_pluginType == PluginsItemInterface::Simple)
|
||||
return;
|
||||
|
||||
// construct complex widget layout
|
||||
QWidget *centeralWidget = m_pluginInter->itemWidget(itemKey);
|
||||
centeralWidget->installEventFilter(this);
|
||||
|
||||
QBoxLayout *layout = new QHBoxLayout;
|
||||
layout->addWidget(m_pluginInter->itemWidget(itemKey));
|
||||
layout->addWidget(centeralWidget);
|
||||
layout->setSpacing(0);
|
||||
layout->setMargin(0);
|
||||
|
||||
setLayout(layout);
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
}
|
||||
|
||||
int PluginsItem::itemSortKey() const
|
||||
@ -28,9 +41,50 @@ int PluginsItem::itemSortKey() const
|
||||
return m_pluginInter->itemSortKey(m_itemKey);
|
||||
}
|
||||
|
||||
void PluginsItem::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
if (e->button() == Qt::LeftButton)
|
||||
{
|
||||
MousePressPoint = e->pos();
|
||||
}
|
||||
else if (e->button() == Qt::RightButton)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
DockItem::mousePressEvent(e);
|
||||
}
|
||||
|
||||
void PluginsItem::mouseMoveEvent(QMouseEvent *e)
|
||||
{
|
||||
if (e->buttons() != Qt::LeftButton)
|
||||
return DockItem::mouseMoveEvent(e);
|
||||
|
||||
e->accept();
|
||||
|
||||
const QPoint distance = e->pos() - MousePressPoint;
|
||||
if (distance.manhattanLength() > PLUGIN_ITEM_DRAG_THRESHOLD)
|
||||
startDrag();
|
||||
}
|
||||
|
||||
void PluginsItem::mouseReleaseEvent(QMouseEvent *e)
|
||||
{
|
||||
if (e->button() != Qt::LeftButton)
|
||||
return DockItem::mouseReleaseEvent(e);
|
||||
|
||||
e->accept();
|
||||
|
||||
const QPoint distance = e->pos() - MousePressPoint;
|
||||
if (distance.manhattanLength() < PLUGIN_ITEM_DRAG_THRESHOLD)
|
||||
mouseClicked();
|
||||
}
|
||||
|
||||
void PluginsItem::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
if (m_type == PluginsItemInterface::Complex)
|
||||
if (m_draging)
|
||||
return;
|
||||
|
||||
if (m_pluginType == PluginsItemInterface::Complex)
|
||||
return DockItem::paintEvent(e);
|
||||
|
||||
QPainter painter(this);
|
||||
@ -41,11 +95,50 @@ void PluginsItem::paintEvent(QPaintEvent *e)
|
||||
painter.drawPixmap(iconRect, pixmap);
|
||||
}
|
||||
|
||||
bool PluginsItem::eventFilter(QObject *o, QEvent *e)
|
||||
{
|
||||
if (m_draging)
|
||||
if (o->parent() == this && e->type() == QEvent::Paint)
|
||||
return true;
|
||||
|
||||
return DockItem::eventFilter(o, e);
|
||||
}
|
||||
|
||||
QSize PluginsItem::sizeHint() const
|
||||
{
|
||||
if (m_type == PluginsItemInterface::Complex)
|
||||
if (m_pluginType == PluginsItemInterface::Complex)
|
||||
return DockItem::sizeHint();
|
||||
|
||||
// TODO: icon size on efficient mode
|
||||
return QSize(48, 48);
|
||||
}
|
||||
|
||||
void PluginsItem::startDrag()
|
||||
{
|
||||
QPixmap pixmap;
|
||||
if (m_pluginType == PluginsItemInterface::Simple)
|
||||
pixmap = m_pluginInter->itemIcon(m_itemKey).pixmap(perfectIconRect().size());
|
||||
else
|
||||
pixmap = grab();
|
||||
|
||||
m_draging = true;
|
||||
update();
|
||||
|
||||
QDrag *drag = new QDrag(this);
|
||||
drag->setPixmap(pixmap);
|
||||
drag->setHotSpot(pixmap.rect().center());
|
||||
drag->setMimeData(new QMimeData);
|
||||
|
||||
emit dragStarted();
|
||||
const Qt::DropAction result = drag->exec(Qt::MoveAction);
|
||||
Q_UNUSED(result);
|
||||
|
||||
m_draging = false;
|
||||
setVisible(true);
|
||||
update();
|
||||
}
|
||||
|
||||
void PluginsItem::mouseClicked()
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -14,14 +14,25 @@ public:
|
||||
int itemSortKey() const;
|
||||
|
||||
private:
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
void mouseMoveEvent(QMouseEvent *e);
|
||||
void mouseReleaseEvent(QMouseEvent *e);
|
||||
void paintEvent(QPaintEvent *e);
|
||||
bool eventFilter(QObject *o, QEvent *e);
|
||||
QSize sizeHint() const;
|
||||
|
||||
private:
|
||||
void startDrag();
|
||||
void mouseClicked();
|
||||
|
||||
private:
|
||||
PluginsItemInterface * const m_pluginInter;
|
||||
const QString m_itemKey;
|
||||
PluginsItemInterface::PluginType m_pluginType;
|
||||
|
||||
PluginsItemInterface::PluginType m_type;
|
||||
bool m_draging;
|
||||
|
||||
static QPoint MousePressPoint;
|
||||
};
|
||||
|
||||
#endif // PLUGINSITEM_H
|
||||
|
@ -165,7 +165,8 @@ void MainPanel::adjustItemSize()
|
||||
const QList<DockItem *> itemList = m_itemController->itemList();
|
||||
for (auto item : itemList)
|
||||
{
|
||||
item->setVisible(true);
|
||||
// item->setVisible(true);
|
||||
QMetaObject::invokeMethod(item, "setVisible", Qt::QueuedConnection, Q_ARG(bool, true));
|
||||
|
||||
switch (item->itemType())
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user