eric6/E5Gui/E5ModelToolBar.py

changeset 8143
2c730d5fd177
parent 7923
91e843545d9a
child 8218
7c09585bd960
equal deleted inserted replaced
8141:27f636beebad 8143:2c730d5fd177
40 if self.isVisible(): 40 if self.isVisible():
41 self._build() 41 self._build()
42 42
43 self.setAcceptDrops(True) 43 self.setAcceptDrops(True)
44 44
45 self._mouseButton = Qt.NoButton 45 self._mouseButton = Qt.MouseButton.NoButton
46 self._keyboardModifiers = Qt.KeyboardModifiers(Qt.NoModifier) 46 self._keyboardModifiers = Qt.KeyboardModifiers(
47 Qt.KeyboardModifier.NoModifier)
47 self.__dropRow = -1 48 self.__dropRow = -1
48 self.__dropIndex = None 49 self.__dropIndex = None
49 50
50 def setModel(self, model): 51 def setModel(self, model):
51 """ 52 """
107 self.clear() 108 self.clear()
108 109
109 for i in range(self.__model.rowCount(self.__root)): 110 for i in range(self.__model.rowCount(self.__root)):
110 idx = self.__model.index(i, 0, self.__root) 111 idx = self.__model.index(i, 0, self.__root)
111 112
112 title = idx.data(Qt.DisplayRole) 113 title = idx.data(Qt.ItemDataRole.DisplayRole)
113 icon = idx.data(Qt.DecorationRole) 114 icon = idx.data(Qt.ItemDataRole.DecorationRole)
114 if icon == NotImplemented or icon is None: 115 if icon == NotImplemented or icon is None:
115 icon = QIcon() 116 icon = QIcon()
116 folder = self.__model.hasChildren(idx) 117 folder = self.__model.hasChildren(idx)
117 118
118 act = self.addAction(icon, title) 119 act = self.addAction(icon, title)
124 if folder: 125 if folder:
125 menu = self._createMenu() 126 menu = self._createMenu()
126 menu.setModel(self.__model) 127 menu.setModel(self.__model)
127 menu.setRootIndex(idx) 128 menu.setRootIndex(idx)
128 act.setMenu(menu) 129 act.setMenu(menu)
129 button.setPopupMode(QToolButton.InstantPopup) 130 button.setPopupMode(
130 button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) 131 QToolButton.ToolButtonPopupMode.InstantPopup)
132 button.setToolButtonStyle(
133 Qt.ToolButtonStyle.ToolButtonTextBesideIcon)
131 134
132 def index(self, action): 135 def index(self, action):
133 """ 136 """
134 Public method to get the index of an action. 137 Public method to get the index of an action.
135 138
163 166
164 @param obj reference to the object (QObject) 167 @param obj reference to the object (QObject)
165 @param evt reference to the event (QEvent) 168 @param evt reference to the event (QEvent)
166 @return flag indicating that the event should be filtered out (boolean) 169 @return flag indicating that the event should be filtered out (boolean)
167 """ 170 """
168 if evt.type() == QEvent.MouseButtonRelease: 171 if evt.type() == QEvent.Type.MouseButtonRelease:
169 self._mouseButton = evt.button() 172 self._mouseButton = evt.button()
170 self._keyboardModifiers = evt.modifiers() 173 self._keyboardModifiers = evt.modifiers()
171 act = obj.defaultAction() 174 act = obj.defaultAction()
172 idx = self.index(act) 175 idx = self.index(act)
173 if idx.isValid(): 176 if idx.isValid():
174 self.activated[QModelIndex].emit(idx) 177 self.activated[QModelIndex].emit(idx)
175 elif evt.type() == QEvent.MouseButtonPress: 178 elif evt.type() == QEvent.Type.MouseButtonPress:
176 if evt.buttons() & Qt.LeftButton: 179 if evt.buttons() & Qt.MouseButton.LeftButton:
177 self.__dragStartPosition = self.mapFromGlobal(evt.globalPos()) 180 self.__dragStartPosition = self.mapFromGlobal(evt.globalPos())
178 181
179 return False 182 return False
180 183
181 def dragEnterEvent(self, evt): 184 def dragEnterEvent(self, evt):
230 """ 233 """
231 if self.__model is None: 234 if self.__model is None:
232 super(E5ModelToolBar, self).mouseMoveEvent(evt) 235 super(E5ModelToolBar, self).mouseMoveEvent(evt)
233 return 236 return
234 237
235 if not (evt.buttons() & Qt.LeftButton): 238 if not (evt.buttons() & Qt.MouseButton.LeftButton):
236 super(E5ModelToolBar, self).mouseMoveEvent(evt) 239 super(E5ModelToolBar, self).mouseMoveEvent(evt)
237 return 240 return
238 241
239 manhattanLength = (evt.pos() - 242 manhattanLength = (evt.pos() -
240 self.__dragStartPosition).manhattanLength() 243 self.__dragStartPosition).manhattanLength()
254 drag = QDrag(self) 257 drag = QDrag(self)
255 drag.setMimeData(self.__model.mimeData([idx])) 258 drag.setMimeData(self.__model.mimeData([idx]))
256 actionRect = self.actionGeometry(act) 259 actionRect = self.actionGeometry(act)
257 drag.setPixmap(self.grab(actionRect)) 260 drag.setPixmap(self.grab(actionRect))
258 261
259 if drag.exec() == Qt.MoveAction: 262 if drag.exec() == Qt.DropAction.MoveAction:
260 row = idx.row() 263 row = idx.row()
261 if self.__dropIndex == idx.parent() and self.__dropRow <= row: 264 if self.__dropIndex == idx.parent() and self.__dropRow <= row:
262 row += 1 265 row += 1
263 self.__model.removeRow(row, self.__root) 266 self.__model.removeRow(row, self.__root)
264 267
283 286
284 def resetFlags(self): 287 def resetFlags(self):
285 """ 288 """
286 Public method to reset the saved internal state. 289 Public method to reset the saved internal state.
287 """ 290 """
288 self._mouseButton = Qt.NoButton 291 self._mouseButton = Qt.MouseButton.NoButton
289 self._keyboardModifiers = Qt.KeyboardModifiers(Qt.NoModifier) 292 self._keyboardModifiers = Qt.KeyboardModifiers(
293 Qt.KeyboardModifier.NoModifier)

eric ide

mercurial