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-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 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.actionDetailsView)
54  menu.addAction(self.win.actionThumbnailView)
55  menu.exec_(QCursor.pos())
56 
57  ##
58  # Override startDrag method to display custom icon
59  def startDrag(self, event):
60 
61  # Get image of selected item
62  selected_row = self.transition_model.model.itemFromIndex(self.selectionModel().selectedIndexes()[0]).row()
63  icon = self.transition_model.model.item(selected_row, 0).icon()
64 
65  # Start drag operation
66  drag = QDrag(self)
67  drag.setMimeData(self.transition_model.model.mimeData(self.selectionModel().selectedIndexes()))
68  # drag.setPixmap(QIcon.fromTheme('document-new').pixmap(QSize(self.drag_item_size,self.drag_item_size)))
69  drag.setPixmap(icon.pixmap(QSize(self.drag_item_size, self.drag_item_size)))
70  drag.setHotSpot(QPoint(self.drag_item_size / 2, self.drag_item_size / 2))
71  drag.exec_()
72 
73  def clear_filter(self):
74  get_app().window.transitionsFilter.setText("")
75 
76  def filter_changed(self):
77  if self.win.transitionsFilter.text() == "":
78  self.win.actionTransitionsClear.setEnabled(False)
79  else:
80  self.win.actionTransitionsClear.setEnabled(True)
81  self.refresh_view()
82 
83  def refresh_view(self):
84  self.transition_model.update_model()
85  self.hideColumn(2)
86  self.hideColumn(3)
87 
88  def __init__(self, *args):
89  # Invoke parent init
90  QTreeView.__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(75, 62))
106  self.setIndentation(0)
107  self.setSelectionBehavior(QTreeView.SelectRows)
108  self.setSelectionBehavior(QAbstractItemView.SelectRows)
109  self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
110  self.setWordWrap(True)
111  self.setStyleSheet('QTreeView::item { padding-top: 2px; }')
112 
113  # Refresh view
114  self.refresh_view()
115 
116  # setup filter events
117  app = get_app()
118  app.window.transitionsFilter.textChanged.connect(self.filter_changed)
119  app.window.actionTransitionsClear.triggered.connect(self.clear_filter)
def get_app()
Returns the current QApplication instance of OpenShot.
Definition: app.py:54
A TreeView QWidget used on the main window.
def startDrag(self, event)
Override startDrag method to display custom icon.