OpenShot Video Editor  2.0.0
transitions_listview.py
Go to the documentation of this file.
1 ##
2 #
3 # @file
4 # @brief This file contains the transitions file treeview, 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.transition_model import TransitionsModel
35 
36 try:
37  import json
38 except ImportError:
39  import simplejson as json
40 
41 
42 ##
43 # A QListView QWidget used on the main window
44 class TransitionsListView(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 = "transitions"
51 
52  menu = QMenu(self)
53  menu.addAction(self.win.actionDetailsView)
54  menu.exec_(QCursor.pos())
55 
56  # Ignore event, propagate to parent
57  event.ignore()
58 
59  ##
60  # Override startDrag method to display custom icon
61  def startDrag(self, event):
62 
63  # Get image of selected item
64  selected_row = self.transition_model.model.itemFromIndex(self.selectionModel().selectedIndexes()[0]).row()
65  icon = self.transition_model.model.item(selected_row, 0).icon()
66 
67  # Start drag operation
68  drag = QDrag(self)
69  drag.setMimeData(self.transition_model.model.mimeData(self.selectionModel().selectedIndexes()))
70  # drag.setPixmap(QIcon.fromTheme('document-new').pixmap(QSize(self.drag_item_size,self.drag_item_size)))
71  drag.setPixmap(icon.pixmap(QSize(self.drag_item_size, self.drag_item_size)))
72  drag.setHotSpot(QPoint(self.drag_item_size / 2, self.drag_item_size / 2))
73  drag.exec_()
74 
75  def clear_filter(self):
76  get_app().window.transitionsFilter.setText("")
77 
78  def filter_changed(self):
79  if self.win.transitionsFilter.text() == "":
80  self.win.actionTransitionsClear.setEnabled(False)
81  else:
82  self.win.actionTransitionsClear.setEnabled(True)
83  self.refresh_view()
84 
85  def refresh_view(self):
86  self.transition_model.update_model()
87 
88  def __init__(self, *args):
89  # Invoke parent init
90  QListView.__init__(self, *args)
91 
92  # Get a reference to the window object
93  self.win = get_app().window
94 
95  # Get Model data
96  self.transition_model = TransitionsModel()
97 
98  # Keep track of mouse press start position to determine when to start drag
99  self.setAcceptDrops(True)
100  self.setDragEnabled(True)
101  self.setDropIndicatorShown(True)
102 
103  # Setup header columns
104  self.setModel(self.transition_model.model)
105  self.setIconSize(QSize(131, 108))
106  self.setGridSize(QSize(102, 92))
107  self.setViewMode(QListView.IconMode)
108  self.setResizeMode(QListView.Adjust)
109  self.setUniformItemSizes(True)
110  self.setWordWrap(False)
111  self.setTextElideMode(Qt.ElideRight)
112  self.setStyleSheet('QListView::item { padding-top: 2px; }')
113 
114  # Refresh view
115  self.refresh_view()
116 
117  # setup filter events
118  app = get_app()
119  app.window.transitionsFilter.textChanged.connect(self.filter_changed)
120  app.window.actionTransitionsClear.triggered.connect(self.clear_filter)
def startDrag(self, event)
Override startDrag method to display custom icon.
def get_app()
Returns the current QApplication instance of OpenShot.
Definition: app.py:55
A QListView QWidget used on the main window.