Merge pull request #488 from AndiDog/feature/status-context-menu-view-history
[git-cola.git] / cola / qtcompat.py
blob106481af13b4acbb345bf5a856f3b153b2e505b4
1 from __future__ import division, absolute_import, unicode_literals
3 from PyQt4 import QtGui
4 from PyQt4 import QtCore
7 def patch(obj, attr, value):
8 if not hasattr(obj, attr):
9 setattr(obj, attr, value)
12 def install():
13 set_contents_margins = lambda self, *args: self.setMargin(max(args))
14 patch(QtGui.QHBoxLayout, 'setContentsMargins', set_contents_margins)
15 patch(QtGui.QVBoxLayout, 'setContentsMargins', set_contents_margins)
17 set_margin = lambda self, x: self.setContentsMargins(x, x, x, x)
18 patch(QtGui.QHBoxLayout, 'setMargin', set_margin)
19 patch(QtGui.QVBoxLayout, 'setMargin', set_margin)
21 patch(QtGui.QKeySequence, 'Preferences', 'Ctrl+,')
22 patch(QtGui.QGraphicsItem, 'mapRectToScene', _map_rect_to_scene)
25 def add_search_path(prefix, path):
26 if hasattr(QtCore.QDir, 'addSearchPath'):
27 QtCore.QDir.addSearchPath(prefix, path)
29 def set_common_dock_options(window):
30 if not hasattr(window, 'setDockOptions'):
31 return
32 nested = QtGui.QMainWindow.AllowNestedDocks
33 tabbed = QtGui.QMainWindow.AllowTabbedDocks
34 animated = QtGui.QMainWindow.AnimatedDocks
35 window.setDockOptions(nested | tabbed | animated)
38 def _map_rect_to_scene(self, rect):
39 """Only available in newer PyQt4 versions"""
40 return self.sceneTransform().mapRect(rect)