1
- """
1
+ """
2
2
@file
3
3
@brief This file contains the transitions file treeview, used by the main window
4
4
@author Jonathan Thomas <[email protected] >
5
-
5
+
6
6
@section LICENSE
7
-
7
+
8
8
Copyright (c) 2008-2018 OpenShot Studios, LLC
9
9
(http://www.openshotstudios.com). This file is part of
10
10
OpenShot Video Editor (http://www.openshot.org), an open-source project
11
11
dedicated to delivering high quality video editing and animation solutions
12
12
to the world.
13
-
13
+
14
14
OpenShot Video Editor is free software: you can redistribute it and/or modify
15
15
it under the terms of the GNU General Public License as published by
16
16
the Free Software Foundation, either version 3 of the License, or
17
17
(at your option) any later version.
18
-
18
+
19
19
OpenShot Video Editor is distributed in the hope that it will be useful,
20
20
but WITHOUT ANY WARRANTY; without even the implied warranty of
21
21
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
22
GNU General Public License for more details.
23
-
23
+
24
24
You should have received a copy of the GNU General Public License
25
25
along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
26
26
"""
27
27
28
- from PyQt5 .QtCore import QSize , QPoint , Qt
28
+ from PyQt5 .QtCore import QSize , QPoint , Qt , QRegExp
29
29
from PyQt5 .QtGui import *
30
30
from PyQt5 .QtWidgets import QListView , QMenu
31
31
32
32
from classes .app import get_app
33
- from windows .models .transition_model import TransitionsModel
33
+ from windows .models .transition_model import TransitionsModel , TransitionFilterProxyModel
34
34
35
35
import json
36
36
@@ -54,12 +54,12 @@ def startDrag(self, event):
54
54
""" Override startDrag method to display custom icon """
55
55
56
56
# Get image of selected item
57
- selected_row = self .transition_model .model .itemFromIndex (self .selectionModel ().selectedIndexes ()[0 ]).row ()
57
+ selected_row = self .transition_model .model .itemFromIndex (self .proxy_model . mapToSource ( self . selectionModel ().selectedIndexes ()[0 ]) ).row ()
58
58
icon = self .transition_model .model .item (selected_row , 0 ).icon ()
59
59
60
60
# Start drag operation
61
61
drag = QDrag (self )
62
- drag .setMimeData (self .transition_model . model .mimeData (self .selectionModel ().selectedIndexes ()))
62
+ drag .setMimeData (self .proxy_model .mimeData (self .selectionModel ().selectedIndexes ()))
63
63
# drag.setPixmap(QIcon.fromTheme('document-new').pixmap(QSize(self.drag_item_size,self.drag_item_size)))
64
64
drag .setPixmap (icon .pixmap (QSize (self .drag_item_size , self .drag_item_size )))
65
65
drag .setHotSpot (QPoint (self .drag_item_size / 2 , self .drag_item_size / 2 ))
@@ -69,25 +69,36 @@ def filter_changed(self):
69
69
self .refresh_view ()
70
70
71
71
def refresh_view (self ):
72
- self .transition_model .update_model ()
72
+ """Filter transitions with proxy class"""
73
+ filter_text = self .win .transitionsFilter .text ()
74
+ self .proxy_model .setFilterRegExp (QRegExp (filter_text .replace (' ' , '.*' )))
75
+ self .proxy_model .setFilterCaseSensitivity (Qt .CaseInsensitive )
76
+ self .proxy_model .sort (Qt .AscendingOrder )
73
77
74
- def __init__ (self , * args ):
78
+ def __init__ (self , model ):
75
79
# Invoke parent init
76
- QListView .__init__ (self , * args )
80
+ QListView .__init__ (self )
77
81
78
82
# Get a reference to the window object
79
83
self .win = get_app ().window
80
84
81
85
# Get Model data
82
- self .transition_model = TransitionsModel ()
86
+ self .transition_model = model
87
+
88
+ # Create proxy model (for sorting and filtering)
89
+ self .proxy_model = TransitionFilterProxyModel (self )
90
+ self .proxy_model .setDynamicSortFilter (True )
91
+ self .proxy_model .setFilterCaseSensitivity (Qt .CaseInsensitive )
92
+ self .proxy_model .setSortCaseSensitivity (Qt .CaseSensitive )
93
+ self .proxy_model .setSourceModel (self .transition_model .model )
83
94
84
95
# Keep track of mouse press start position to determine when to start drag
85
96
self .setAcceptDrops (True )
86
97
self .setDragEnabled (True )
87
98
self .setDropIndicatorShown (True )
88
99
89
100
# Setup header columns
90
- self .setModel (self .transition_model . model )
101
+ self .setModel (self .proxy_model )
91
102
self .setIconSize (QSize (131 , 108 ))
92
103
self .setGridSize (QSize (102 , 92 ))
93
104
self .setViewMode (QListView .IconMode )
@@ -97,8 +108,8 @@ def __init__(self, *args):
97
108
self .setTextElideMode (Qt .ElideRight )
98
109
self .setStyleSheet ('QListView::item { padding-top: 2px; }' )
99
110
100
- # Refresh view
101
- self .refresh_view ()
111
+ # Load initial transition model data
112
+ self .transition_model . update_model ()
102
113
103
114
# setup filter events
104
115
app = get_app ()
0 commit comments