E5Gui/E5ModelMenu.py

changeset 2990
583beaf0b4b8
parent 2953
703452a2876f
child 3034
7ce719013078
child 3057
10516539f238
equal deleted inserted replaced
2989:7efa8b8b6903 2990:583beaf0b4b8
6 """ 6 """
7 Module implementing a menu populated from a QAbstractItemModel. 7 Module implementing a menu populated from a QAbstractItemModel.
8 """ 8 """
9 9
10 from PyQt4.QtCore import pyqtSignal, qVersion, Qt, QModelIndex, QPoint 10 from PyQt4.QtCore import pyqtSignal, qVersion, Qt, QModelIndex, QPoint
11 from PyQt4.QtGui import QMenu, QFontMetrics, QAction, QApplication, QDrag, QPixmap 11 from PyQt4.QtGui import QMenu, QFontMetrics, QAction, QApplication, QDrag, \
12 QPixmap
12 13
13 import UI.PixmapCache 14 import UI.PixmapCache
14 15
15 16
16 class E5ModelMenu(QMenu): 17 class E5ModelMenu(QMenu):
180 """ 181 """
181 return E5ModelMenu(self) 182 return E5ModelMenu(self)
182 183
183 def createMenu(self, parent, max_, parentMenu=None, menu=None): 184 def createMenu(self, parent, max_, parentMenu=None, menu=None):
184 """ 185 """
185 Public method to put all the children of a parent into a menu of a given length. 186 Public method to put all the children of a parent into a menu of a
187 given length.
186 188
187 @param parent index of the parent item (QModelIndex) 189 @param parent index of the parent item (QModelIndex)
188 @param max_ maximum number of entries (integer) 190 @param max_ maximum number of entries (integer)
189 @param parentMenu reference to the parent menu (QMenu) 191 @param parentMenu reference to the parent menu (QMenu)
190 @param menu reference to the menu to be populated (QMenu) 192 @param menu reference to the menu to be populated (QMenu)
218 for i in range(end): 220 for i in range(end):
219 idx = self.__model.index(i, 0, parent) 221 idx = self.__model.index(i, 0, parent)
220 if self.__model.hasChildren(idx): 222 if self.__model.hasChildren(idx):
221 self.createMenu(idx, -1, menu) 223 self.createMenu(idx, -1, menu)
222 else: 224 else:
223 if self.__separatorRole != 0 and idx.data(self.__separatorRole): 225 if self.__separatorRole != 0 and \
226 idx.data(self.__separatorRole):
224 self.addSeparator() 227 self.addSeparator()
225 else: 228 else:
226 menu.addAction(self.__makeAction(idx)) 229 menu.addAction(self.__makeAction(idx))
227 230
228 if menu == self and i == self.__firstSeparator - 1: 231 if menu == self and i == self.__firstSeparator - 1:
358 361
359 if not (evt.buttons() & Qt.LeftButton): 362 if not (evt.buttons() & Qt.LeftButton):
360 super().mouseMoveEvent(evt) 363 super().mouseMoveEvent(evt)
361 return 364 return
362 365
363 manhattanLength = (evt.pos() - self.__dragStartPosition).manhattanLength() 366 manhattanLength = (evt.pos() -
367 self.__dragStartPosition).manhattanLength()
364 if manhattanLength <= QApplication.startDragDistance(): 368 if manhattanLength <= QApplication.startDragDistance():
365 super().mouseMoveEvent(evt) 369 super().mouseMoveEvent(evt)
366 return 370 return
367 371
368 act = self.actionAt(self.__dragStartPosition) 372 act = self.actionAt(self.__dragStartPosition)

eric ide

mercurial