OpenShot Video Editor  2.0.0
effects_listview.py
Go to the documentation of this file.
1 ##
2 #
3 # @file
4 # @brief This file contains the effects file listview, used by the main window
5 # @author Jonathan Thomas <jonathan@openshot.org>
6 #
7 # @section LICENSE
8 #
9 # Copyright (c) 2008-2018 OpenShot Studios, LLC
10 # (http://www.openshotstudios.com). This file is part of
11 # OpenShot Video Editor (http://www.openshot.org), an open-source project
12 # dedicated to delivering high quality video editing and animation solutions
13 # to the world.
14 #
15 # OpenShot Video Editor is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU General Public License as published by
17 # the Free Software Foundation, either version 3 of the License, or
18 # (at your option) any later version.
19 #
20 # OpenShot Video Editor is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
27 #
28 
29 from PyQt5.QtCore import QSize, QPoint, Qt
30 from PyQt5.QtGui import *
31 from PyQt5.QtWidgets import QListView, QMenu
32 
33 from classes.app import get_app
34 from windows.models.effects_model import EffectsModel
35 
36 try:
37  import json
38 except ImportError:
39  import simplejson as json
40 
41 
42 ##
43 # A TreeView QWidget used on the main window
44 class EffectsListView(QListView):
45  drag_item_size = 48
46 
47  def contextMenuEvent(self, event):
48  # Set context menu mode
49  app = get_app()
50  app.context_menu_object = "effects"
51 
52  menu = QMenu(self)
53  menu.addAction(self.win.actionDetailsView)
54  menu.exec_(QCursor.pos())
55 
56  ##
57  # Override startDrag method to display custom icon
58  def startDrag(self, event):
59 
60  # Get image of selected item
61  selected_row = self.effects_model.model.itemFromIndex(self.selectionModel().selectedIndexes()[0]).row()
62  icon = self.effects_model.model.item(selected_row, 0).icon()
63 
64  # Start drag operation
65  drag = QDrag(self)
66  drag.setMimeData(self.effects_model.model.mimeData(self.selectionModel().selectedIndexes()))
67  drag.setPixmap(icon.pixmap(QSize(self.drag_item_size, self.drag_item_size)))
68  drag.setHotSpot(QPoint(self.drag_item_size / 2, self.drag_item_size / 2))
69  drag.exec_()
70 
71  def clear_filter(self):
72  get_app().window.effectsFilter.setText("")
73 
74  def filter_changed(self):
75  if self.win.effectsFilter.text() == "":
76  self.win.actionEffectsClear.setEnabled(False)
77  else:
78  self.win.actionEffectsClear.setEnabled(True)
79  self.refresh_view()
80 
81  def refresh_view(self):
82  self.effects_model.update_model()
83 
84  def __init__(self, *args):
85  # Invoke parent init
86  QListView.__init__(self, *args)
87 
88  # Get a reference to the window object
89  self.win = get_app().window
90 
91  # Get Model data
92  self.effects_model = EffectsModel()
93 
94  # Keep track of mouse press start position to determine when to start drag
95  self.setAcceptDrops(True)
96  self.setDragEnabled(True)
97  self.setDropIndicatorShown(True)
98 
99  # Setup header columns
100  self.setModel(self.effects_model.model)
101  self.setIconSize(QSize(131, 108))
102  self.setGridSize(QSize(102, 92))
103  self.setViewMode(QListView.IconMode)
104  self.setResizeMode(QListView.Adjust)
105  self.setUniformItemSizes(True)
106  self.setWordWrap(False)
107  self.setTextElideMode(Qt.ElideRight)
108  self.setStyleSheet('QListView::item { padding-top: 2px; }')
109 
110  # Refresh view
111  self.refresh_view()
112 
113  # setup filter events
114  app = get_app()
115  app.window.effectsFilter.textChanged.connect(self.filter_changed)
116  app.window.actionEffectsClear.triggered.connect(self.clear_filter)
A TreeView QWidget used on the main window.
def get_app
Returns the current QApplication instance of OpenShot.
Definition: app.py:55
def startDrag
Override startDrag method to display custom icon.