OpenShot Video Editor  2.0.0
transitions_treeview.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
30 from PyQt5.QtGui import *
31 from PyQt5.QtWidgets import QTreeView, QAbstractItemView, QMenu, QSizePolicy
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 TreeView QWidget used on the main window
44 class TransitionsTreeView(QTreeView):
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.actionThumbnailView)
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.transition_model.model.itemFromIndex(self.selectionModel().selectedIndexes()[0]).row()
62  icon = self.transition_model.model.item(selected_row, 0).icon()
63 
64  # Start drag operation
65  drag = QDrag(self)
66  drag.setMimeData(self.transition_model.model.mimeData(self.selectionModel().selectedIndexes()))
67  # drag.setPixmap(QIcon.fromTheme('document-new').pixmap(QSize(self.drag_item_size,self.drag_item_size)))
68  drag.setPixmap(icon.pixmap(QSize(self.drag_item_size, self.drag_item_size)))
69  drag.setHotSpot(QPoint(self.drag_item_size / 2, self.drag_item_size / 2))
70  drag.exec_()
71 
72  def clear_filter(self):
73  get_app().window.transitionsFilter.setText("")
74 
75  def filter_changed(self):
76  if self.win.transitionsFilter.text() == "":
77  self.win.actionTransitionsClear.setEnabled(False)
78  else:
79  self.win.actionTransitionsClear.setEnabled(True)
80  self.refresh_view()
81 
82  def refresh_view(self):
83  self.transition_model.update_model()
84  self.hideColumn(2)
85  self.hideColumn(3)
86 
87  def __init__(self, *args):
88  # Invoke parent init
89  QTreeView.__init__(self, *args)
90 
91  # Get a reference to the window object
92  self.win = get_app().window
93 
94  # Get Model data
95  self.transition_model = TransitionsModel()
96 
97  # Keep track of mouse press start position to determine when to start drag
98  self.setAcceptDrops(True)
99  self.setDragEnabled(True)
100  self.setDropIndicatorShown(True)
101 
102  # Setup header columns
103  self.setModel(self.transition_model.model)
104  self.setIconSize(QSize(75, 62))
105  self.setIndentation(0)
106  self.setSelectionBehavior(QTreeView.SelectRows)
107  self.setSelectionBehavior(QAbstractItemView.SelectRows)
108  self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
109  self.setWordWrap(True)
110  self.setStyleSheet('QTreeView::item { padding-top: 2px; }')
111 
112  # Refresh view
113  self.refresh_view()
114 
115  # setup filter events
116  app = get_app()
117  app.window.transitionsFilter.textChanged.connect(self.filter_changed)
118  app.window.actionTransitionsClear.triggered.connect(self.clear_filter)
def get_app
Returns the current QApplication instance of OpenShot.
Definition: app.py:55
A TreeView QWidget used on the main window.
def startDrag
Override startDrag method to display custom icon.