eric6/E5Gui/E5ModelMenu.py

changeset 8143
2c730d5fd177
parent 7923
91e843545d9a
child 8218
7c09585bd960
equal deleted inserted replaced
8141:27f636beebad 8143:2c730d5fd177
39 self.__root = QModelIndex() 39 self.__root = QModelIndex()
40 self.__dragStartPosition = QPoint() 40 self.__dragStartPosition = QPoint()
41 41
42 self.setAcceptDrops(True) 42 self.setAcceptDrops(True)
43 43
44 self._mouseButton = Qt.NoButton 44 self._mouseButton = Qt.MouseButton.NoButton
45 self._keyboardModifiers = Qt.KeyboardModifiers(Qt.NoModifier) 45 self._keyboardModifiers = Qt.KeyboardModifiers(
46 Qt.KeyboardModifier.NoModifier)
46 self.__dropRow = -1 47 self.__dropRow = -1
47 self.__dropIndex = None 48 self.__dropIndex = None
48 49
49 # This is to ensure it will be shown on Mac OS X 50 # This is to ensure it will be shown on Mac OS X
50 self.addAction("--not populated--") 51 self.addAction("--not populated--")
201 modelMenu = self.createBaseMenu() 202 modelMenu = self.createBaseMenu()
202 # triggered goes all the way up the menu structure 203 # triggered goes all the way up the menu structure
203 modelMenu.triggered.disconnect(modelMenu.__actionTriggered) 204 modelMenu.triggered.disconnect(modelMenu.__actionTriggered)
204 modelMenu.setTitle(title) 205 modelMenu.setTitle(title)
205 206
206 icon = parent.data(Qt.DecorationRole) 207 icon = parent.data(Qt.ItemDataRole.DecorationRole)
207 if icon == NotImplemented or icon is None: 208 if icon == NotImplemented or icon is None:
208 icon = UI.PixmapCache.getIcon("defaultIcon") 209 icon = UI.PixmapCache.getIcon("defaultIcon")
209 modelMenu.setIcon(icon) 210 modelMenu.setIcon(icon)
210 if parentMenu is not None: 211 if parentMenu is not None:
211 parentMenu.addMenu(modelMenu).setData(v) 212 parentMenu.addMenu(modelMenu).setData(v)
241 Private method to create an action. 242 Private method to create an action.
242 243
243 @param idx index of the item to create an action for (QModelIndex) 244 @param idx index of the item to create an action for (QModelIndex)
244 @return reference to the created action (QAction) 245 @return reference to the created action (QAction)
245 """ 246 """
246 icon = idx.data(Qt.DecorationRole) 247 icon = idx.data(Qt.ItemDataRole.DecorationRole)
247 if icon == NotImplemented or icon is None: 248 if icon == NotImplemented or icon is None:
248 icon = UI.PixmapCache.getIcon("defaultIcon") 249 icon = UI.PixmapCache.getIcon("defaultIcon")
249 action = self.makeAction(icon, idx.data(), self) 250 action = self.makeAction(icon, idx.data(), self)
250 action.setStatusTip(idx.data(self.__statusBarTextRole)) 251 action.setStatusTip(idx.data(self.__statusBarTextRole))
251 252
267 if self.__maxWidth == -1: 268 if self.__maxWidth == -1:
268 try: 269 try:
269 self.__maxWidth = fm.horizontalAdvance("m") * 30 270 self.__maxWidth = fm.horizontalAdvance("m") * 30
270 except AttributeError: 271 except AttributeError:
271 self.__maxWidth = fm.width('m') * 30 272 self.__maxWidth = fm.width('m') * 30
272 smallText = fm.elidedText(text, Qt.ElideMiddle, self.__maxWidth) 273 smallText = fm.elidedText(text, Qt.TextElideMode.ElideMiddle,
274 self.__maxWidth)
273 275
274 return QAction(icon, smallText, parent) 276 return QAction(icon, smallText, parent)
275 277
276 def __actionTriggered(self, action): 278 def __actionTriggered(self, action):
277 """ 279 """
352 """ 354 """
353 Protected method handling mouse press events. 355 Protected method handling mouse press events.
354 356
355 @param evt reference to the event object (QMouseEvent) 357 @param evt reference to the event object (QMouseEvent)
356 """ 358 """
357 if evt.button() == Qt.LeftButton: 359 if evt.button() == Qt.MouseButton.LeftButton:
358 self.__dragStartPosition = evt.pos() 360 self.__dragStartPosition = evt.pos()
359 super(E5ModelMenu, self).mousePressEvent(evt) 361 super(E5ModelMenu, self).mousePressEvent(evt)
360 362
361 def mouseMoveEvent(self, evt): 363 def mouseMoveEvent(self, evt):
362 """ 364 """
366 """ 368 """
367 if self.__model is None: 369 if self.__model is None:
368 super(E5ModelMenu, self).mouseMoveEvent(evt) 370 super(E5ModelMenu, self).mouseMoveEvent(evt)
369 return 371 return
370 372
371 if not (evt.buttons() & Qt.LeftButton): 373 if not (evt.buttons() & Qt.MouseButton.LeftButton):
372 super(E5ModelMenu, self).mouseMoveEvent(evt) 374 super(E5ModelMenu, self).mouseMoveEvent(evt)
373 return 375 return
374 376
375 if self.__dragStartPosition.isNull(): 377 if self.__dragStartPosition.isNull():
376 super(E5ModelMenu, self).mouseMoveEvent(evt) 378 super(E5ModelMenu, self).mouseMoveEvent(evt)
395 drag = QDrag(self) 397 drag = QDrag(self)
396 drag.setMimeData(self.__model.mimeData([idx])) 398 drag.setMimeData(self.__model.mimeData([idx]))
397 actionRect = self.actionGeometry(act) 399 actionRect = self.actionGeometry(act)
398 drag.setPixmap(self.grab(actionRect)) 400 drag.setPixmap(self.grab(actionRect))
399 401
400 if drag.exec() == Qt.MoveAction: 402 if drag.exec() == Qt.DropAction.MoveAction:
401 row = idx.row() 403 row = idx.row()
402 if self.__dropIndex == idx.parent() and self.__dropRow <= row: 404 if self.__dropIndex == idx.parent() and self.__dropRow <= row:
403 row += 1 405 row += 1
404 self.__model.removeRow(row, self.__root) 406 self.__model.removeRow(row, self.__root)
405 407
415 @param evt reference to the event object (QMouseEvent) 417 @param evt reference to the event object (QMouseEvent)
416 """ 418 """
417 self._mouseButton = evt.button() 419 self._mouseButton = evt.button()
418 self._keyboardModifiers = evt.modifiers() 420 self._keyboardModifiers = evt.modifiers()
419 421
420 if evt.button() == Qt.LeftButton: 422 if evt.button() == Qt.MouseButton.LeftButton:
421 self.__dragStartPosition = QPoint() 423 self.__dragStartPosition = QPoint()
422 424
423 super(E5ModelMenu, self).mouseReleaseEvent(evt) 425 super(E5ModelMenu, self).mouseReleaseEvent(evt)
424 426
425 def resetFlags(self): 427 def resetFlags(self):
426 """ 428 """
427 Public method to reset the saved internal state. 429 Public method to reset the saved internal state.
428 """ 430 """
429 self._mouseButton = Qt.NoButton 431 self._mouseButton = Qt.MouseButton.NoButton
430 self._keyboardModifiers = Qt.KeyboardModifiers(Qt.NoModifier) 432 self._keyboardModifiers = Qt.KeyboardModifiers(
433 Qt.KeyboardModifier.NoModifier)
431 434
432 def removeEntry(self, idx): 435 def removeEntry(self, idx):
433 """ 436 """
434 Public method to remove a menu entry. 437 Public method to remove a menu entry.
435 438

eric ide

mercurial