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-2016 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
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.addAction(self.win.actionThumbnailView)
55  menu.exec_(QCursor.pos())
56 
57  # Ignore event, propagate to parent
58  event.ignore()
59  super().mouseMoveEvent(event)
60 
61  ##
62  # Override startDrag method to display custom icon
63  def startDrag(self, event):
64 
65  # Get image of selected item
66  selected_row = self.transition_model.model.itemFromIndex(self.selectionModel().selectedIndexes()[0]).row()
67  icon = self.transition_model.model.item(selected_row, 0).icon()
68 
69  # Start drag operation
70  drag = QDrag(self)
71  drag.setMimeData(self.transition_model.model.mimeData(self.selectionModel().selectedIndexes()))
72  # drag.setPixmap(QIcon.fromTheme('document-new').pixmap(QSize(self.drag_item_size,self.drag_item_size)))
73  drag.setPixmap(icon.pixmap(QSize(self.drag_item_size, self.drag_item_size)))
74  drag.setHotSpot(QPoint(self.drag_item_size / 2, self.drag_item_size / 2))
75  drag.exec_()
76 
77  def clear_filter(self):
78  get_app().window.transitionsFilter.setText("")
79 
80  def filter_changed(self):
81  if self.win.transitionsFilter.text() == "":
82  self.win.actionTransitionsClear.setEnabled(False)
83  else:
84  self.win.actionTransitionsClear.setEnabled(True)
85  self.refresh_view()
86 
87  def refresh_view(self):
88  self.transition_model.update_model()
89 
90  def __init__(self, *args):
91  # Invoke parent init
92  QListView.__init__(self, *args)
93 
94  # Get a reference to the window object
95  self.win = get_app().window
96 
97  # Get Model data
98  self.transition_model = TransitionsModel()
99 
100  # Keep track of mouse press start position to determine when to start drag
101  self.setAcceptDrops(True)
102  self.setDragEnabled(True)
103  self.setDropIndicatorShown(True)
104 
105  # Setup header columns
106  self.setModel(self.transition_model.model)
107  self.setIconSize(QSize(131, 108))
108  self.setViewMode(QListView.IconMode)
109  self.setResizeMode(QListView.Adjust)
110  self.setUniformItemSizes(True)
111  self.setWordWrap(True)
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:54
A QListView QWidget used on the main window.