From 42a09e95fd93f344a1c96ecbf24f4234a5549be5 Mon Sep 17 00:00:00 2001 From: lixueman Date: Mon, 21 Nov 2022 09:01:12 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=BC=80=E5=A7=8B=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=88=97=E8=A1=A8=E5=A2=9E=E5=8A=A0=E6=8B=96?= =?UTF-8?q?=E6=8B=BD=E5=88=B0=E4=BB=BB=E5=8A=A1=E6=A0=8F=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/UserInterface/ListView/listview.cpp | 32 +++++++++++++++++++++++++ src/UserInterface/ListView/listview.h | 3 +++ 2 files changed, 35 insertions(+) diff --git a/src/UserInterface/ListView/listview.cpp b/src/UserInterface/ListView/listview.cpp index 89be87b..3ec9cd7 100755 --- a/src/UserInterface/ListView/listview.cpp +++ b/src/UserInterface/ListView/listview.cpp @@ -18,9 +18,11 @@ #include "listview.h" #include "function_button_widget.h" #include "utility.h" +#include "thumbnail.h" #include #include #include +#include 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); @@ -47,6 +50,7 @@ ListView::~ListView() void ListView::initWidget() { setAttribute(Qt::WA_TranslucentBackground); + this->setAcceptDrops(true); viewport()->setAttribute(Qt::WA_TranslucentBackground); viewport()->setAutoFillBackground(false); this->setSelectionMode(QAbstractItemView::SingleSelection); @@ -70,6 +74,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().at(0); + QMimeData *mimeData = new QMimeData; + ThumbNail *dragImage = new ThumbNail; + QDrag *drag = new QDrag(this); + QList 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 data, int module) { this->module = module; diff --git a/src/UserInterface/ListView/listview.h b/src/UserInterface/ListView/listview.h index f9125e8..6a26210 100755 --- a/src/UserInterface/ListView/listview.h +++ b/src/UserInterface/ListView/listview.h @@ -50,11 +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; + QPoint m_pressPos; private Q_SLOTS: From 90157f6306da90820183f1ca6ff73fb087d975ed Mon Sep 17 00:00:00 2001 From: lixueman Date: Mon, 21 Nov 2022 17:14:05 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9pressPos=E6=9C=AA?= =?UTF-8?q?=E8=B5=8B=E5=80=BC=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/UserInterface/ListView/klistview.cpp | 5 +++-- src/UserInterface/ListView/klistview.h | 1 + src/UserInterface/ListView/listview.cpp | 1 - src/UserInterface/ListView/listview.h | 2 -- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/UserInterface/ListView/klistview.cpp b/src/UserInterface/ListView/klistview.cpp index 91fbe08..28c83c2 100755 --- a/src/UserInterface/ListView/klistview.cpp +++ b/src/UserInterface/ListView/klistview.cpp @@ -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); } diff --git a/src/UserInterface/ListView/klistview.h b/src/UserInterface/ListView/klistview.h index 503997b..2ac6f3d 100755 --- a/src/UserInterface/ListView/klistview.h +++ b/src/UserInterface/ListView/klistview.h @@ -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); diff --git a/src/UserInterface/ListView/listview.cpp b/src/UserInterface/ListView/listview.cpp index 3ec9cd7..a9a9ed2 100755 --- a/src/UserInterface/ListView/listview.cpp +++ b/src/UserInterface/ListView/listview.cpp @@ -50,7 +50,6 @@ ListView::~ListView() void ListView::initWidget() { setAttribute(Qt::WA_TranslucentBackground); - this->setAcceptDrops(true); viewport()->setAttribute(Qt::WA_TranslucentBackground); viewport()->setAutoFillBackground(false); this->setSelectionMode(QAbstractItemView::SingleSelection); diff --git a/src/UserInterface/ListView/listview.h b/src/UserInterface/ListView/listview.h index 6a26210..cfcfbf8 100755 --- a/src/UserInterface/ListView/listview.h +++ b/src/UserInterface/ListView/listview.h @@ -57,8 +57,6 @@ private: int h = 0; int m_preRowCount; bool m_scrollbarState = true; - QPoint m_pressPos; - private Q_SLOTS: void onClicked(QModelIndex index);//点击item