8 """ |
8 """ |
9 |
9 |
10 from __future__ import unicode_literals # __IGNORE_WARNING__ |
10 from __future__ import unicode_literals # __IGNORE_WARNING__ |
11 |
11 |
12 from PyQt4.QtCore import pyqtSignal, qVersion, Qt, QModelIndex, QPoint |
12 from PyQt4.QtCore import pyqtSignal, qVersion, Qt, QModelIndex, QPoint |
13 from PyQt4.QtGui import QMenu, QFontMetrics, QAction, QApplication, QDrag, QPixmap |
13 from PyQt4.QtGui import QMenu, QFontMetrics, QAction, QApplication, QDrag, \ |
|
14 QPixmap |
14 |
15 |
15 import UI.PixmapCache |
16 import UI.PixmapCache |
16 |
17 |
17 |
18 |
18 class E5ModelMenu(QMenu): |
19 class E5ModelMenu(QMenu): |
182 """ |
183 """ |
183 return E5ModelMenu(self) |
184 return E5ModelMenu(self) |
184 |
185 |
185 def createMenu(self, parent, max_, parentMenu=None, menu=None): |
186 def createMenu(self, parent, max_, parentMenu=None, menu=None): |
186 """ |
187 """ |
187 Public method to put all the children of a parent into a menu of a given length. |
188 Public method to put all the children of a parent into a menu of a |
|
189 given length. |
188 |
190 |
189 @param parent index of the parent item (QModelIndex) |
191 @param parent index of the parent item (QModelIndex) |
190 @param max_ maximum number of entries (integer) |
192 @param max_ maximum number of entries (integer) |
191 @param parentMenu reference to the parent menu (QMenu) |
193 @param parentMenu reference to the parent menu (QMenu) |
192 @param menu reference to the menu to be populated (QMenu) |
194 @param menu reference to the menu to be populated (QMenu) |
220 for i in range(end): |
222 for i in range(end): |
221 idx = self.__model.index(i, 0, parent) |
223 idx = self.__model.index(i, 0, parent) |
222 if self.__model.hasChildren(idx): |
224 if self.__model.hasChildren(idx): |
223 self.createMenu(idx, -1, menu) |
225 self.createMenu(idx, -1, menu) |
224 else: |
226 else: |
225 if self.__separatorRole != 0 and idx.data(self.__separatorRole): |
227 if self.__separatorRole != 0 and \ |
|
228 idx.data(self.__separatorRole): |
226 self.addSeparator() |
229 self.addSeparator() |
227 else: |
230 else: |
228 menu.addAction(self.__makeAction(idx)) |
231 menu.addAction(self.__makeAction(idx)) |
229 |
232 |
230 if menu == self and i == self.__firstSeparator - 1: |
233 if menu == self and i == self.__firstSeparator - 1: |
252 """ |
255 """ |
253 Public method to create an action. |
256 Public method to create an action. |
254 |
257 |
255 @param icon icon of the action (QIcon) |
258 @param icon icon of the action (QIcon) |
256 @param text text of the action (string) |
259 @param text text of the action (string) |
257 @param reference to the parent object (QObject) |
260 @param parent reference to the parent object (QObject) |
258 @return reference to the created action (QAction) |
261 @return reference to the created action (QAction) |
259 """ |
262 """ |
260 fm = QFontMetrics(self.font()) |
263 fm = QFontMetrics(self.font()) |
261 if self.__maxWidth == -1: |
264 if self.__maxWidth == -1: |
262 self.__maxWidth = fm.width('m') * 30 |
265 self.__maxWidth = fm.width('m') * 30 |
360 |
363 |
361 if not (evt.buttons() & Qt.LeftButton): |
364 if not (evt.buttons() & Qt.LeftButton): |
362 super(E5ModelMenu, self).mouseMoveEvent(evt) |
365 super(E5ModelMenu, self).mouseMoveEvent(evt) |
363 return |
366 return |
364 |
367 |
365 manhattanLength = (evt.pos() - self.__dragStartPosition).manhattanLength() |
368 manhattanLength = (evt.pos() - |
|
369 self.__dragStartPosition).manhattanLength() |
366 if manhattanLength <= QApplication.startDragDistance(): |
370 if manhattanLength <= QApplication.startDragDistance(): |
367 super(E5ModelMenu, self).mouseMoveEvent(evt) |
371 super(E5ModelMenu, self).mouseMoveEvent(evt) |
368 return |
372 return |
369 |
373 |
370 act = self.actionAt(self.__dragStartPosition) |
374 act = self.actionAt(self.__dragStartPosition) |