forked from OpenShot/openshot-qt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheffects_listview.py
120 lines (93 loc) · 4.25 KB
/
effects_listview.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
"""
@file
@brief This file contains the effects file listview, used by the main window
@author Jonathan Thomas <[email protected]>
@section LICENSE
Copyright (c) 2008-2018 OpenShot Studios, LLC
(http://www.openshotstudios.com). This file is part of
OpenShot Video Editor (http://www.openshot.org), an open-source project
dedicated to delivering high quality video editing and animation solutions
to the world.
OpenShot Video Editor is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenShot Video Editor is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
"""
from PyQt5.QtCore import QSize, QPoint, Qt, QRegExp
from PyQt5.QtGui import QDrag
from PyQt5.QtWidgets import QListView, QMenu, QAbstractItemView
from classes.app import get_app
from classes.logger import log
class EffectsListView(QListView):
""" A TreeView QWidget used on the main window """
drag_item_size = 48
def contextMenuEvent(self, event):
# Set context menu mode
app = get_app()
app.context_menu_object = "effects"
menu = QMenu(self)
menu.addAction(self.win.actionDetailsView)
menu.exec_(event.globalPos())
def startDrag(self, event):
""" Override startDrag method to display custom icon """
# Get first column indexes for all selected rows
selected = self.selectionModel().selectedRows(0)
# Get image of current item
current = self.selectionModel().currentIndex()
if not current.isValid() and selected:
current = selected[0]
if not current.isValid():
# We can't find anything to drag
log.warning("No draggable items found in model!")
return False
# Get icon from column 0 on same row as current item
icon = current.sibling(current.row(), 0).data(Qt.DecorationRole)
# Start drag operation
drag = QDrag(self)
drag.setMimeData(self.model().mimeData(selected))
drag.setPixmap(icon.pixmap(QSize(self.drag_item_size, self.drag_item_size)))
drag.setHotSpot(QPoint(self.drag_item_size / 2, self.drag_item_size / 2))
drag.exec_()
def filter_changed(self):
self.refresh_view()
def refresh_view(self):
"""Filter transitions with proxy class"""
filter_text = self.win.effectsFilter.text()
self.model().setFilterRegExp(QRegExp(filter_text.replace(' ', '.*')))
self.model().setFilterCaseSensitivity(Qt.CaseInsensitive)
self.model().sort(Qt.AscendingOrder)
def __init__(self, model):
# Invoke parent init
QListView.__init__(self)
# Get a reference to the window object
self.win = get_app().window
# Get Model data
self.effects_model = model
# Keep track of mouse press start position to determine when to start drag
self.setAcceptDrops(True)
self.setDragEnabled(True)
self.setDropIndicatorShown(True)
self.setModel(self.effects_model.proxy_model)
# Remove the default selection model and wire up to the shared one
self.selectionModel().deleteLater()
self.setSelectionMode(QAbstractItemView.SingleSelection)
self.setSelectionBehavior(QAbstractItemView.SelectRows)
self.setSelectionModel(self.effects_model.selection_model)
# Setup header columns
self.setIconSize(QSize(131, 108))
self.setGridSize(QSize(102, 92))
self.setViewMode(QListView.IconMode)
self.setResizeMode(QListView.Adjust)
self.setUniformItemSizes(True)
self.setWordWrap(False)
self.setTextElideMode(Qt.ElideRight)
self.setStyleSheet('QListView::item { padding-top: 2px; }')
# setup filter events
app = get_app()
app.window.effectsFilter.textChanged.connect(self.filter_changed)