new method 'getAxpectRatio' with code taken from 'setAspectLocked' (#392)
Co-authored-by: Ogi Moore <ognyan.moore@gmail.com>
This commit is contained in:
parent
983cc1695e
commit
ca9b0c7910
@ -233,6 +233,17 @@ class ViewBox(GraphicsWidget):
|
|||||||
if name is None:
|
if name is None:
|
||||||
self.updateViewLists()
|
self.updateViewLists()
|
||||||
|
|
||||||
|
def getAspectRatio(self):
|
||||||
|
'''return the current aspect ratio'''
|
||||||
|
rect = self.rect()
|
||||||
|
vr = self.viewRect()
|
||||||
|
if rect.height() == 0 or vr.width() == 0 or vr.height() == 0:
|
||||||
|
currentRatio = 1.0
|
||||||
|
else:
|
||||||
|
currentRatio = (rect.width()/float(rect.height())) / (
|
||||||
|
vr.width()/vr.height())
|
||||||
|
return currentRatio
|
||||||
|
|
||||||
def register(self, name):
|
def register(self, name):
|
||||||
"""
|
"""
|
||||||
Add this ViewBox to the registered list of views.
|
Add this ViewBox to the registered list of views.
|
||||||
@ -1134,12 +1145,7 @@ class ViewBox(GraphicsWidget):
|
|||||||
return
|
return
|
||||||
self.state['aspectLocked'] = False
|
self.state['aspectLocked'] = False
|
||||||
else:
|
else:
|
||||||
rect = self.rect()
|
currentRatio = self.getAspectRatio()
|
||||||
vr = self.viewRect()
|
|
||||||
if rect.height() == 0 or vr.width() == 0 or vr.height() == 0:
|
|
||||||
currentRatio = 1.0
|
|
||||||
else:
|
|
||||||
currentRatio = (rect.width()/float(rect.height())) / (vr.width()/vr.height())
|
|
||||||
if ratio is None:
|
if ratio is None:
|
||||||
ratio = currentRatio
|
ratio = currentRatio
|
||||||
if self.state['aspectLocked'] == ratio: # nothing to change
|
if self.state['aspectLocked'] == ratio: # nothing to change
|
||||||
|
Loading…
Reference in New Issue
Block a user