!30 开始菜单应用列表增加拖拽到任务栏功能

Merge pull request !30 from lixueman/upstream
This commit is contained in:
lixueman 2022-11-22 08:32:01 +00:00 committed by Gitee
commit 88486df649
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 37 additions and 3 deletions

View File

@ -92,8 +92,9 @@ void KListView::mouseMoveEvent(QMouseEvent *e)
void KListView::mousePressEvent(QMouseEvent *event)
{
if ((this->indexAt(event->pos()).isValid()) && event->button() == Qt::LeftButton) {
m_pressApp = m_listmodel->data(this->indexAt(event->pos()), Qt::DisplayRole);
m_pressPos = event->pos();
if ((this->indexAt(m_pressPos).isValid()) && event->button() == Qt::LeftButton) {
m_pressApp = m_listmodel->data(this->indexAt(m_pressPos), Qt::DisplayRole);
}
return QListView::mousePressEvent(event);
}

View File

@ -36,6 +36,7 @@ public:
int module = 0;
double m_transparency;
QVariant m_pressApp;
QPoint m_pressPos;
UkuiMenuInterface *m_ukuiMenuInterface = nullptr;
protected:
void paintEvent(QPaintEvent *e);

View File

@ -18,9 +18,11 @@
#include "listview.h"
#include "function_button_widget.h"
#include "utility.h"
#include "thumbnail.h"
#include <QDebug>
#include <QDesktopServices>
#include <QtConcurrent/QtConcurrent>
#include <QDrag>
ListView::ListView(QWidget *parent/*, int width, int height, int module*/):
KListView(parent)
@ -29,6 +31,7 @@ ListView::ListView(QWidget *parent/*, int width, int height, int module*/):
this->h = 540;
this->module = 1;
initWidget();
setDragEnabled(true);
setAttribute(Qt::WA_AcceptTouchEvents);
m_listmodel = new QStandardItemModel(this);
this->setModel(m_listmodel);
@ -70,6 +73,34 @@ void ListView::initWidget()
connect(this, &ListView::clicked, this, &ListView::onClicked);
}
void ListView::mouseMoveEvent(QMouseEvent *e)
{
if (e->buttons() & Qt::LeftButton) {
if ((e->pos() - m_pressPos).manhattanLength() >= QApplication::startDragDistance()) {
myDebug() << "进入拖拽事件";
QString desktopfp = m_pressApp.value<QStringList>().at(0);
QMimeData *mimeData = new QMimeData;
ThumbNail *dragImage = new ThumbNail;
QDrag *drag = new QDrag(this);
QList<QUrl> desktopUrlList;
desktopUrlList.append(QUrl(desktopfp));
myDebug() << desktopUrlList;
mimeData->setUrls(desktopUrlList);
//设置拖拽时的缩略图
dragImage->setupthumbnail(desktopfp);
QPixmap pixmap = dragImage->grab();
pixmap = pixmap.scaled(QSize(32, 32), Qt::KeepAspectRatio);
myDebug() << mimeData;
drag->setMimeData(mimeData);
drag->setPixmap(pixmap);
drag->setHotSpot(QPoint(pixmap.width(), pixmap.height()));
drag->exec(Qt::MoveAction);
delete dragImage;
dragImage = nullptr;
}
}
}
void ListView::addData(QVector<QStringList> data, int module)
{
this->module = module;

View File

@ -50,13 +50,14 @@ protected:
void paintEvent(QPaintEvent *e) override;
void keyPressEvent(QKeyEvent *e);
bool event(QEvent *e);
void mouseMoveEvent(QMouseEvent *e);
private:
int w = 0;
int h = 0;
int m_preRowCount;
bool m_scrollbarState = true;
private Q_SLOTS:
void onClicked(QModelIndex index);//点击item
// void rightClickedSlot(const QPoint &pos);//右键菜单