forked from openlp/openlp
Add Image cache
This commit is contained in:
parent
f62ac45a29
commit
8f98ae9d2e
@ -81,6 +81,9 @@ html_expands.append({u'desc':u'Italics', u'start tag':u'{it}',
|
|||||||
u'start html':u'<em>', u'end tag':u'{/it}', u'end html':u'</em>',
|
u'start html':u'<em>', u'end tag':u'{/it}', u'end html':u'</em>',
|
||||||
u'protected':True})
|
u'protected':True})
|
||||||
|
|
||||||
|
# Image cache to stop regualar image resizing
|
||||||
|
cache = {}
|
||||||
|
|
||||||
def translate(context, text, comment=None):
|
def translate(context, text, comment=None):
|
||||||
"""
|
"""
|
||||||
A special shortcut method to wrap around the Qt4 translation functions.
|
A special shortcut method to wrap around the Qt4 translation functions.
|
||||||
@ -258,6 +261,9 @@ def resize_image(image, width, height, background=QtCore.Qt.black):
|
|||||||
return preview
|
return preview
|
||||||
preview = preview.scaled(width, height, QtCore.Qt.KeepAspectRatio,
|
preview = preview.scaled(width, height, QtCore.Qt.KeepAspectRatio,
|
||||||
QtCore.Qt.SmoothTransformation)
|
QtCore.Qt.SmoothTransformation)
|
||||||
|
cache_key = u'%s%s%s' % (image, unicode(width), unicode(height))
|
||||||
|
if cache_key in cache:
|
||||||
|
return cache[cache_key]
|
||||||
realw = preview.width()
|
realw = preview.width()
|
||||||
realh = preview.height()
|
realh = preview.height()
|
||||||
# and move it to the centre of the preview space
|
# and move it to the centre of the preview space
|
||||||
@ -266,6 +272,8 @@ def resize_image(image, width, height, background=QtCore.Qt.black):
|
|||||||
new_image.fill(background)
|
new_image.fill(background)
|
||||||
painter = QtGui.QPainter(new_image)
|
painter = QtGui.QPainter(new_image)
|
||||||
painter.drawImage((width - realw) / 2, (height - realh) / 2, preview)
|
painter.drawImage((width - realw) / 2, (height - realh) / 2, preview)
|
||||||
|
cache[cache_key] = new_image
|
||||||
|
print cache
|
||||||
return new_image
|
return new_image
|
||||||
|
|
||||||
def check_item_selected(list_widget, message):
|
def check_item_selected(list_widget, message):
|
||||||
|
@ -188,7 +188,7 @@ class ImageMediaItem(MediaManagerItem):
|
|||||||
bitem = self.listView.item(item.row())
|
bitem = self.listView.item(item.row())
|
||||||
filename = unicode(bitem.data(QtCore.Qt.UserRole).toString())
|
filename = unicode(bitem.data(QtCore.Qt.UserRole).toString())
|
||||||
frame = QtGui.QImage(unicode(filename))
|
frame = QtGui.QImage(unicode(filename))
|
||||||
self.parent.liveController.display.image(frame)
|
self.parent.liveController.display.image(filename)
|
||||||
self.resetButton.setVisible(True)
|
self.resetButton.setVisible(True)
|
||||||
|
|
||||||
def onPreviewClick(self):
|
def onPreviewClick(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user