mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
Add ScreenMask for icon drop outside
This commit is contained in:
parent
880b38ea00
commit
1a3ba913d2
@ -1,6 +1,7 @@
|
||||
#include "panel.h"
|
||||
|
||||
Panel::Panel(QWidget *parent) : QWidget(parent)
|
||||
Panel::Panel(QWidget *parent)
|
||||
: QWidget(parent),parentWidget(parent)
|
||||
{
|
||||
leftLayout = new DockLayout(this);
|
||||
leftLayout->resize(1024,50);
|
||||
@ -17,6 +18,9 @@ Panel::Panel(QWidget *parent) : QWidget(parent)
|
||||
leftLayout->addItem(b3);
|
||||
leftLayout->addItem(b4);
|
||||
leftLayout->addItem(b5);
|
||||
|
||||
connect(leftLayout,SIGNAL(dragStarted()),this,SLOT(slotDragStarted()));
|
||||
connect(leftLayout,SIGNAL(itemDropped()),this,SLOT(slotItemDropped()));
|
||||
}
|
||||
|
||||
void Panel::resize(const QSize &size)
|
||||
@ -31,6 +35,36 @@ void Panel::resize(int width, int height)
|
||||
leftLayout->resize(this->width() * 2 / 3,this->height());
|
||||
}
|
||||
|
||||
void Panel::showScreenMask()
|
||||
{
|
||||
qWarning() << "[Info:]" << "Show Screen Mask.";
|
||||
maskWidget = new ScreenMask();
|
||||
connect(maskWidget,SIGNAL(itemDropped(QPoint)),this,SLOT(slotItemDropped()));
|
||||
|
||||
//TODO change to Other ways to do this,it will hide the drag icon
|
||||
parentWidget->hide();
|
||||
parentWidget->show();
|
||||
}
|
||||
|
||||
void Panel::hideScreenMask()
|
||||
{
|
||||
qWarning() << "[Info:]" << "Hide Screen Mask.";
|
||||
disconnect(maskWidget,SIGNAL(itemDropped(QPoint)),this,SLOT(slotItemDropped()));
|
||||
maskWidget->hide();
|
||||
maskWidget->deleteLater();
|
||||
maskWidget = NULL;
|
||||
}
|
||||
|
||||
void Panel::slotDragStarted()
|
||||
{
|
||||
showScreenMask();
|
||||
}
|
||||
|
||||
void Panel::slotItemDropped()
|
||||
{
|
||||
hideScreenMask();
|
||||
}
|
||||
|
||||
Panel::~Panel()
|
||||
{
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <QDebug>
|
||||
#include "Widgets/appitem.h"
|
||||
#include "Widgets/docklayout.h"
|
||||
#include "Widgets/screenmask.h"
|
||||
|
||||
class Panel : public QWidget
|
||||
{
|
||||
@ -17,11 +18,19 @@ public:
|
||||
void resize(const QSize &size);
|
||||
void resize(int width,int height);
|
||||
|
||||
void showScreenMask();
|
||||
void hideScreenMask();
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
void slotDragStarted();
|
||||
void slotItemDropped();
|
||||
|
||||
private:
|
||||
DockLayout * leftLayout;
|
||||
QWidget * parentWidget = NULL;
|
||||
ScreenMask * maskWidget = NULL;
|
||||
};
|
||||
|
||||
#endif // PANEL_H
|
||||
|
@ -106,6 +106,8 @@ void AppItem::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
QDrag* drag = new QDrag(this);
|
||||
QMimeData* data = new QMimeData();
|
||||
QImage dataImg(this->itemIconPath);
|
||||
data->setImageData(QVariant(dataImg));
|
||||
drag->setMimeData(data);
|
||||
|
||||
QPixmap pixmap(this->itemIconPath);
|
||||
@ -130,8 +132,18 @@ void AppItem::leaveEvent(QEvent *event)
|
||||
void AppItem::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
emit dragEntered(event,this);
|
||||
// event->setDropAction(Qt::MoveAction);
|
||||
// event->accept();
|
||||
|
||||
AppItem *tmpItem = NULL;
|
||||
tmpItem = dynamic_cast<AppItem *>(event->source());
|
||||
if (tmpItem)
|
||||
{
|
||||
// qWarning()<< "[Info:]" << "Brother Item.";
|
||||
}
|
||||
else
|
||||
{
|
||||
event->setDropAction(Qt::MoveAction);
|
||||
event->accept();
|
||||
}
|
||||
|
||||
// if (event->mimeData()->hasFormat("application/x-dnditemdata")){
|
||||
// if (event->source() == this){
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <QDrag>
|
||||
#include <QMimeData>
|
||||
#include <QPixmap>
|
||||
#include <QImage>
|
||||
#include <QDebug>
|
||||
#include "dockitem.h"
|
||||
#include "dockconstants.h"
|
||||
|
@ -199,6 +199,8 @@ void DockLayout::dropEvent(QDropEvent *event)
|
||||
{
|
||||
insertItem(tmpItem,lastHoverIndex);
|
||||
}
|
||||
|
||||
emit itemDropped();
|
||||
}
|
||||
|
||||
void DockLayout::slotItemDrag(AppItem *item)
|
||||
@ -208,6 +210,8 @@ void DockLayout::slotItemDrag(AppItem *item)
|
||||
if (tmpIndex != -1)
|
||||
{
|
||||
dragoutFromLayout(tmpIndex);
|
||||
|
||||
emit dragStarted();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,10 @@ public:
|
||||
int indexOf(AppItem * item);
|
||||
int indexOf(int x,int y);
|
||||
|
||||
signals:
|
||||
void dragStarted();
|
||||
void itemDropped();
|
||||
|
||||
protected:
|
||||
void dragEnterEvent(QDragEnterEvent *event);
|
||||
void dropEvent(QDropEvent *event);
|
||||
|
40
dde-dock/Widgets/screenmask.cpp
Normal file
40
dde-dock/Widgets/screenmask.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include "screenmask.h"
|
||||
|
||||
ScreenMask::ScreenMask(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
QRect rec = QApplication::desktop()->screenGeometry();
|
||||
this->resize(rec.width(),rec.height());
|
||||
this->setWindowFlags(Qt::ToolTip);
|
||||
this->setWindowOpacity(0);
|
||||
|
||||
setAcceptDrops(true);
|
||||
|
||||
this->show();
|
||||
}
|
||||
|
||||
void ScreenMask::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
event->setDropAction(Qt::MoveAction);
|
||||
event->accept();
|
||||
}
|
||||
|
||||
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())
|
||||
{
|
||||
TransformLabel * imgLabel = new TransformLabel();
|
||||
imgLabel->setAttribute(Qt::WA_TranslucentBackground);
|
||||
imgLabel->setWindowFlags(Qt::ToolTip);
|
||||
imgLabel->setPixmap(QPixmap::fromImage(image));
|
||||
imgLabel->move(event->pos());
|
||||
imgLabel->show();
|
||||
|
||||
//TODO add animation here
|
||||
QTimer::singleShot(1000,imgLabel,SLOT(deleteLater()));
|
||||
|
||||
emit itemDropped(event->pos());
|
||||
}
|
||||
|
||||
}
|
52
dde-dock/Widgets/screenmask.h
Normal file
52
dde-dock/Widgets/screenmask.h
Normal file
@ -0,0 +1,52 @@
|
||||
#ifndef SCREENMASK_H
|
||||
#define SCREENMASK_H
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
#include <QPixmap>
|
||||
#include <QTransform>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QDragMoveEvent>
|
||||
#include <QDropEvent>
|
||||
#include <QMimeData>
|
||||
#include <QTimer>
|
||||
#include <QDebug>
|
||||
|
||||
class TransformLabel : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QTransform transform READ getTransform WRITE setTransform)
|
||||
public:
|
||||
explicit TransformLabel(QWidget *parent=0) : QLabel(parent){}
|
||||
|
||||
QTransform getTransform(){return this->pixTransform;}
|
||||
void setTransform(const QTransform &value)
|
||||
{
|
||||
this->pixTransform = value;
|
||||
this->setPixmap(this->pixmap()->transformed(value));
|
||||
}
|
||||
|
||||
private:
|
||||
QTransform pixTransform;
|
||||
};
|
||||
|
||||
class ScreenMask : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ScreenMask(QWidget *parent = 0);
|
||||
|
||||
protected:
|
||||
void dragEnterEvent(QDragEnterEvent *event);
|
||||
void dropEvent(QDropEvent *event);
|
||||
|
||||
signals:
|
||||
void itemDropped(QPoint pos);
|
||||
|
||||
public slots:
|
||||
};
|
||||
|
||||
#endif // SCREENMASK_H
|
@ -24,7 +24,8 @@ SOURCES += main.cpp\
|
||||
Widgets/appitem.cpp \
|
||||
Widgets/docklayout.cpp \
|
||||
Widgets/windowpreview.cpp \
|
||||
Widgets/dockitem.cpp
|
||||
Widgets/dockitem.cpp \
|
||||
Widgets/screenmask.cpp
|
||||
|
||||
HEADERS += mainwidget.h \
|
||||
Panel/panel.h \
|
||||
@ -37,7 +38,8 @@ HEADERS += mainwidget.h \
|
||||
Widgets/appitem.h \
|
||||
Widgets/docklayout.h \
|
||||
Widgets/windowpreview.h \
|
||||
Widgets/dockitem.h
|
||||
Widgets/dockitem.h \
|
||||
Widgets/screenmask.h
|
||||
|
||||
RESOURCES += \
|
||||
images.qrc
|
||||
|
Loading…
x
Reference in New Issue
Block a user