Debian Codegraph @

src/album/albumview/leftlistwidget.cpp

raw
1 /*
2 * Copyright (C) 2020 ~ 2021 Uniontech Software Technology Co., Ltd.
3 *
4 * Author: ZhangYong <[email protected]>
5 *
6 * Maintainer: ZhangYong <[email protected]>
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21 #include "leftlistwidget.h"
22
23 #include <QDebug>
24 #include <QDrag>
25 #include <QMimeData>
26 #include <QMouseEvent>
27 #include <QAbstractItemView>
28 #include "widgets/albumlefttabitem.h"
29
30 LeftListWidget::LeftListWidget()
31 {
32 setViewportMargins(8, 0, 8, 0);
33 setAcceptDrops(true);
34 }
35
36 void LeftListWidget::dragMoveEvent(QDragMoveEvent *event)
37 {
38 QModelIndex index = this->indexAt(event->pos());
39 if (index.isValid()) {
40 AlbumLeftTabItem *item = dynamic_cast<AlbumLeftTabItem *>(this->itemWidget(this->item(index.row())));
41 QString leftTabListName = item->m_albumNameStr;
42 QString leftTabListType = item->m_albumTypeStr;
43 //只支持拖拽到自定义相册
44 if (leftTabListType == COMMON_STR_CREATEALBUM) {
45 return event->accept();
46 } else {
47 qDebug() << "Can not drop!";
48 return event->ignore();
49 }
50 }
51 }
52
53 void LeftListWidget::dropEvent(QDropEvent *event)
54 {
55 QModelIndex index = this->indexAt(event->pos());
56 if (index.isValid()) {
57 qDebug() << "emit signalDropEvent:" << index;
58 emit signalDropEvent(index);
59 } else {
60 DListWidget::dropEvent(event);
61 }
62
63 }
64
65 void LeftListWidget::dragEnterEvent(QDragEnterEvent *event)
66 {
67 if (event->mimeData()->hasFormat("TestListView/text-icon-icon_hover")) {
68 event->acceptProposedAction();
69 } else {
70 QListWidget::dragEnterEvent(event);
71 }
72 }
73
74 void LeftListWidget::mousePressEvent(QMouseEvent *e)
75 {
76 QModelIndex index = indexAt(e->pos());
77 if (!index.isValid()) {
78 emit sigMousePressIsNoValid();
79 }
80 DListWidget::mousePressEvent(e);
81 }
82
83 void LeftListWidget::keyPressEvent(QKeyEvent *event)
84 {
85 DListWidget::keyPressEvent(event);
86 }
87
88 void LeftListWidget::keyReleaseEvent(QKeyEvent *event)
89 {
90 DListWidget::keyReleaseEvent(event);
91 }
92
93 QStyleOptionViewItem LeftListWidget::viewOptions() const
94 {
95 QStyleOptionViewItem option = QAbstractItemView::viewOptions();
96
97 if (this->viewMode() == QListView::IconMode) {
98 option.showDecorationSelected = false;
99 option.decorationPosition = QStyleOptionViewItem::Top;
100 option.displayAlignment = Qt::AlignCenter;
101 } else {
102 option.decorationPosition = QStyleOptionViewItem::Left;
103 }
104
105 if (this->gridSize().isValid()) {
106 option.rect.setSize(this->gridSize());
107 }
108
109 return option;
110 }
111
112 //QModelIndex LeftListWidget::getModelIndex(QListWidgetItem *pItem)
113 //{
114 // return indexFromItem(pItem);
115 //}