5 |
5 |
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 __future__ import unicode_literals # __IGNORE_WARNING__ |
|
11 |
10 from PyQt4.QtCore import pyqtSignal, qVersion, Qt, QModelIndex, QPoint |
12 from PyQt4.QtCore import pyqtSignal, qVersion, Qt, QModelIndex, QPoint |
11 from PyQt4.QtGui import QMenu, QFontMetrics, QAction, QApplication, QDrag, QPixmap |
13 from PyQt4.QtGui import QMenu, QFontMetrics, QAction, QApplication, QDrag, QPixmap |
12 |
14 |
13 import UI.PixmapCache |
15 import UI.PixmapCache |
14 |
16 |
301 mimeTypes = self.__model.mimeTypes() |
303 mimeTypes = self.__model.mimeTypes() |
302 for mimeType in mimeTypes: |
304 for mimeType in mimeTypes: |
303 if evt.mimeData().hasFormat(mimeType): |
305 if evt.mimeData().hasFormat(mimeType): |
304 evt.acceptProposedAction() |
306 evt.acceptProposedAction() |
305 |
307 |
306 super().dragEnterEvent(evt) |
308 super(E5ModelMenu, self).dragEnterEvent(evt) |
307 |
309 |
308 def dropEvent(self, evt): |
310 def dropEvent(self, evt): |
309 """ |
311 """ |
310 Protected method to handle drop events. |
312 Protected method to handle drop events. |
311 |
313 |
332 evt.acceptProposedAction() |
334 evt.acceptProposedAction() |
333 self.__model.dropMimeData(evt.mimeData(), evt.dropAction(), |
335 self.__model.dropMimeData(evt.mimeData(), evt.dropAction(), |
334 row, 0, parentIndex) |
336 row, 0, parentIndex) |
335 self.close() |
337 self.close() |
336 |
338 |
337 super().dropEvent(evt) |
339 super(E5ModelMenu, self).dropEvent(evt) |
338 |
340 |
339 def mousePressEvent(self, evt): |
341 def mousePressEvent(self, evt): |
340 """ |
342 """ |
341 Protected method handling mouse press events. |
343 Protected method handling mouse press events. |
342 |
344 |
343 @param evt reference to the event object (QMouseEvent) |
345 @param evt reference to the event object (QMouseEvent) |
344 """ |
346 """ |
345 if evt.button() == Qt.LeftButton: |
347 if evt.button() == Qt.LeftButton: |
346 self.__dragStartPosition = evt.pos() |
348 self.__dragStartPosition = evt.pos() |
347 super().mousePressEvent(evt) |
349 super(E5ModelMenu, self).mousePressEvent(evt) |
348 |
350 |
349 def mouseMoveEvent(self, evt): |
351 def mouseMoveEvent(self, evt): |
350 """ |
352 """ |
351 Protected method to handle mouse move events. |
353 Protected method to handle mouse move events. |
352 |
354 |
353 @param evt reference to the event (QMouseEvent) |
355 @param evt reference to the event (QMouseEvent) |
354 """ |
356 """ |
355 if self.__model is None: |
357 if self.__model is None: |
356 super().mouseMoveEvent(evt) |
358 super(E5ModelMenu, self).mouseMoveEvent(evt) |
357 return |
359 return |
358 |
360 |
359 if not (evt.buttons() & Qt.LeftButton): |
361 if not (evt.buttons() & Qt.LeftButton): |
360 super().mouseMoveEvent(evt) |
362 super(E5ModelMenu, self).mouseMoveEvent(evt) |
361 return |
363 return |
362 |
364 |
363 manhattanLength = (evt.pos() - self.__dragStartPosition).manhattanLength() |
365 manhattanLength = (evt.pos() - self.__dragStartPosition).manhattanLength() |
364 if manhattanLength <= QApplication.startDragDistance(): |
366 if manhattanLength <= QApplication.startDragDistance(): |
365 super().mouseMoveEvent(evt) |
367 super(E5ModelMenu, self).mouseMoveEvent(evt) |
366 return |
368 return |
367 |
369 |
368 act = self.actionAt(self.__dragStartPosition) |
370 act = self.actionAt(self.__dragStartPosition) |
369 if act is None: |
371 if act is None: |
370 super().mouseMoveEvent(evt) |
372 super(E5ModelMenu, self).mouseMoveEvent(evt) |
371 return |
373 return |
372 |
374 |
373 idx = self.index(act) |
375 idx = self.index(act) |
374 if not idx.isValid(): |
376 if not idx.isValid(): |
375 super().mouseMoveEvent(evt) |
377 super(E5ModelMenu, self).mouseMoveEvent(evt) |
376 return |
378 return |
377 |
379 |
378 drag = QDrag(self) |
380 drag = QDrag(self) |
379 drag.setMimeData(self.__model.mimeData([idx])) |
381 drag.setMimeData(self.__model.mimeData([idx])) |
380 actionRect = self.actionGeometry(act) |
382 actionRect = self.actionGeometry(act) |
400 |
402 |
401 @param evt reference to the event object (QMouseEvent) |
403 @param evt reference to the event object (QMouseEvent) |
402 """ |
404 """ |
403 self._mouseButton = evt.button() |
405 self._mouseButton = evt.button() |
404 self._keyboardModifiers = evt.modifiers() |
406 self._keyboardModifiers = evt.modifiers() |
405 super().mouseReleaseEvent(evt) |
407 super(E5ModelMenu, self).mouseReleaseEvent(evt) |
406 |
408 |
407 def resetFlags(self): |
409 def resetFlags(self): |
408 """ |
410 """ |
409 Public method to reset the saved internal state. |
411 Public method to reset the saved internal state. |
410 """ |
412 """ |