E5Gui/E5ModelToolBar.py

branch
Py2 comp.
changeset 2525
8b507a9a2d40
parent 2467
33f1bcfdd65e
child 3057
10516539f238
equal deleted inserted replaced
2523:139f182b72f6 2525:8b507a9a2d40
5 5
6 """ 6 """
7 Module implementing a tool bar populated from a QAbstractItemModel. 7 Module implementing a tool bar 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, QEvent 12 from PyQt4.QtCore import pyqtSignal, qVersion, Qt, QModelIndex, QPoint, QEvent
11 from PyQt4.QtGui import QApplication, QDrag, QPixmap, QToolBar, QIcon, QToolButton 13 from PyQt4.QtGui import QApplication, QDrag, QPixmap, QToolBar, QIcon, QToolButton
12 14
13 15
14 class E5ModelToolBar(QToolBar): 16 class E5ModelToolBar(QToolBar):
25 27
26 @param title title for the tool bar (string) 28 @param title title for the tool bar (string)
27 @param parent reference to the parent widget (QWidget) 29 @param parent reference to the parent widget (QWidget)
28 """ 30 """
29 if title is not None: 31 if title is not None:
30 super().__init__(title, parent) 32 super(E5ModelToolBar, self).__init__(title, parent)
31 else: 33 else:
32 super().__init__(parent) 34 super(E5ModelToolBar, self).__init__(parent)
33 35
34 self.__model = None 36 self.__model = None
35 37
36 self.__root = QModelIndex() 38 self.__root = QModelIndex()
37 self.__dragStartPosition = QPoint() 39 self.__dragStartPosition = QPoint()
180 mimeTypes = self.__model.mimeTypes() 182 mimeTypes = self.__model.mimeTypes()
181 for mimeType in mimeTypes: 183 for mimeType in mimeTypes:
182 if evt.mimeData().hasFormat(mimeType): 184 if evt.mimeData().hasFormat(mimeType):
183 evt.acceptProposedAction() 185 evt.acceptProposedAction()
184 186
185 super().dragEnterEvent(evt) 187 super(E5ModelToolBar, self).dragEnterEvent(evt)
186 188
187 def dropEvent(self, evt): 189 def dropEvent(self, evt):
188 """ 190 """
189 Protected method to handle drop events. 191 Protected method to handle drop events.
190 192
207 self.__dropIndex = parentIndex 209 self.__dropIndex = parentIndex
208 evt.acceptProposedAction() 210 evt.acceptProposedAction()
209 self.__model.dropMimeData(evt.mimeData(), evt.dropAction(), 211 self.__model.dropMimeData(evt.mimeData(), evt.dropAction(),
210 row, 0, parentIndex) 212 row, 0, parentIndex)
211 213
212 super().dropEvent(evt) 214 super(E5ModelToolBar, self).dropEvent(evt)
213 215
214 def mouseMoveEvent(self, evt): 216 def mouseMoveEvent(self, evt):
215 """ 217 """
216 Protected method to handle mouse move events. 218 Protected method to handle mouse move events.
217 219
218 @param evt reference to the event (QMouseEvent) 220 @param evt reference to the event (QMouseEvent)
219 """ 221 """
220 if self.__model is None: 222 if self.__model is None:
221 super().mouseMoveEvent(evt) 223 super(E5ModelToolBar, self).mouseMoveEvent(evt)
222 return 224 return
223 225
224 if not (evt.buttons() & Qt.LeftButton): 226 if not (evt.buttons() & Qt.LeftButton):
225 super().mouseMoveEvent(evt) 227 super(E5ModelToolBar, self).mouseMoveEvent(evt)
226 return 228 return
227 229
228 manhattanLength = (evt.pos() - self.__dragStartPosition).manhattanLength() 230 manhattanLength = (evt.pos() - self.__dragStartPosition).manhattanLength()
229 if manhattanLength <= QApplication.startDragDistance(): 231 if manhattanLength <= QApplication.startDragDistance():
230 super().mouseMoveEvent(evt) 232 super(E5ModelToolBar, self).mouseMoveEvent(evt)
231 return 233 return
232 234
233 act = self.actionAt(self.__dragStartPosition) 235 act = self.actionAt(self.__dragStartPosition)
234 if act is None: 236 if act is None:
235 super().mouseMoveEvent(evt) 237 super(E5ModelToolBar, self).mouseMoveEvent(evt)
236 return 238 return
237 239
238 idx = self.index(act) 240 idx = self.index(act)
239 assert idx.isValid() 241 assert idx.isValid()
240 242
257 Protected method to handle hide events. 259 Protected method to handle hide events.
258 260
259 @param evt reference to the hide event (QHideEvent) 261 @param evt reference to the hide event (QHideEvent)
260 """ 262 """
261 self.clear() 263 self.clear()
262 super().hideEvent(evt) 264 super(E5ModelToolBar, self).hideEvent(evt)
263 265
264 def showEvent(self, evt): 266 def showEvent(self, evt):
265 """ 267 """
266 Protected method to handle show events. 268 Protected method to handle show events.
267 269
268 @param evt reference to the hide event (QHideEvent) 270 @param evt reference to the hide event (QHideEvent)
269 """ 271 """
270 if len(self.actions()) == 0: 272 if len(self.actions()) == 0:
271 self._build() 273 self._build()
272 super().showEvent(evt) 274 super(E5ModelToolBar, self).showEvent(evt)
273 275
274 def resetFlags(self): 276 def resetFlags(self):
275 """ 277 """
276 Public method to reset the saved internal state. 278 Public method to reset the saved internal state.
277 """ 279 """

eric ide

mercurial