cmds: use version.check_git(...) in OpenParent
[git-cola.git] / cola / qtcompat.py
blob29221d4a19646567d3e6faccb66bfff96bb7d161
1 from __future__ import division, absolute_import, unicode_literals
3 from qtpy import PYQT4
4 from qtpy import QtCore
5 from qtpy import QtGui
6 from qtpy import QtWidgets
7 from qtpy.QtCore import Qt
9 from . import hotkeys
12 def patch(obj, attr, value):
13 if not hasattr(obj, attr):
14 setattr(obj, attr, value)
17 def install():
18 patch(QtWidgets.QGraphicsItem, 'mapRectToScene', _map_rect_to_scene)
19 patch(QtGui.QKeySequence, 'Preferences', hotkeys.PREFERENCES)
22 def add_search_path(prefix, path):
23 if hasattr(QtCore.QDir, 'addSearchPath'):
24 QtCore.QDir.addSearchPath(prefix, path)
27 def set_common_dock_options(window):
28 if not hasattr(window, 'setDockOptions'):
29 return
30 nested = QtWidgets.QMainWindow.AllowNestedDocks
31 tabbed = QtWidgets.QMainWindow.AllowTabbedDocks
32 animated = QtWidgets.QMainWindow.AnimatedDocks
33 window.setDockOptions(nested | tabbed | animated)
36 def _map_rect_to_scene(self, rect):
37 """Only available in newer PyQt4 versions"""
38 return self.sceneTransform().mapRect(rect)
41 def wheel_translation(event):
42 """Return the Tx Ty translation delta for a pan"""
43 if PYQT4:
44 tx = event.delta()
45 ty = 0.0
46 if event.orientation() == Qt.Vertical:
47 (tx, ty) = (ty, tx)
48 else:
49 angle = event.angleDelta()
50 tx = angle.x()
51 ty = angle.y()
52 return (tx, ty)
55 def wheel_delta(event):
56 """Return a single wheel delta"""
57 if PYQT4:
58 delta = event.delta()
59 else:
60 angle = event.angleDelta()
61 x = angle.x()
62 y = angle.y()
63 if abs(x) > abs(y):
64 delta = x
65 else:
66 delta = y
67 return delta