Path image improvements

This commit is contained in:
Tim Bentley 2010-10-15 16:33:06 +01:00
parent 4f04bba5e6
commit cef92476ad
3 changed files with 33 additions and 24 deletions

View File

@ -223,16 +223,20 @@ def image_to_byte(image):
``image`` ``image``
The image to converted. The image to converted.
""" """
log.debug(u'image_to_byte') log.debug(u'image_to_byte - start')
byte_array = QtCore.QByteArray() byte_array = QtCore.QByteArray()
# use buffer to store pixmap into byteArray # use buffer to store pixmap into byteArray
buffie = QtCore.QBuffer(byte_array) buffie = QtCore.QBuffer(byte_array)
buffie.open(QtCore.QIODevice.WriteOnly) buffie.open(QtCore.QIODevice.WriteOnly)
if isinstance(image, QtGui.QImage): # if isinstance(image, QtGui.QImage):
pixmap = QtGui.QPixmap.fromImage(image) # log.debug(u'image_to_byte - image')
else: # #pixmap = QtGui.QPixmap.fromImage(image)
pixmap = QtGui.QPixmap(image) # pixmap = image
pixmap.save(buffie, "PNG") # else:
# log.debug(u'image_to_byte - pixmap')
# pixmap = QtGui.QPixmap(image)
image.save(buffie, "PNG")
log.debug(u'image_to_byte - end')
# convert to base64 encoding so does not get missed! # convert to base64 encoding so does not get missed!
return byte_array.toBase64() return byte_array.toBase64()
@ -253,8 +257,11 @@ def resize_image(image, width, height, background=QtCore.Qt.black):
The background colour defaults to black. The background colour defaults to black.
""" """
log.debug(u'resize_image') log.debug(u'resize_image - start')
preview = QtGui.QImage(image) if isinstance(image, QtGui.QImage):
preview = image
else:
preview = QtGui.QImage(image)
if not preview.isNull(): if not preview.isNull():
# Only resize if different size # Only resize if different size
if preview.width() == width and preview.height == height: if preview.width() == width and preview.height == height:
@ -263,6 +270,7 @@ def resize_image(image, width, height, background=QtCore.Qt.black):
QtCore.Qt.SmoothTransformation) QtCore.Qt.SmoothTransformation)
image_cache_key = u'%s%s%s' % (image, unicode(width), unicode(height)) image_cache_key = u'%s%s%s' % (image, unicode(width), unicode(height))
if image_cache_key in image_cache: if image_cache_key in image_cache:
log.debug(u'resize_image - end cache')
return image_cache[image_cache_key] return image_cache[image_cache_key]
realw = preview.width() realw = preview.width()
realh = preview.height() realh = preview.height()
@ -273,6 +281,7 @@ def resize_image(image, width, height, background=QtCore.Qt.black):
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)
image_cache[image_cache_key] = new_image image_cache[image_cache_key] = new_image
log.debug(u'resize_image - end')
return new_image return new_image
def check_item_selected(list_widget, message): def check_item_selected(list_widget, message):

View File

@ -184,7 +184,7 @@ class MainDisplay(DisplayWidget):
`slide` `slide`
The slide text to be displayed The slide text to be displayed
""" """
log.debug(u'text') log.debug(u'text to display')
# Wait for the webview to update before displayiong text. # Wait for the webview to update before displayiong text.
while not self.loaded: while not self.loaded:
Receiver.send_message(u'openlp_process_events') Receiver.send_message(u'openlp_process_events')
@ -199,7 +199,7 @@ class MainDisplay(DisplayWidget):
`slide` `slide`
The slide text to be displayed The slide text to be displayed
""" """
log.debug(u'alert') log.debug(u'alert to display')
if self.height() != self.screen[u'size'].height() \ if self.height() != self.screen[u'size'].height() \
or not self.isVisible() or self.videoWidget.isVisible(): or not self.isVisible() or self.videoWidget.isVisible():
shrink = True shrink = True
@ -219,7 +219,7 @@ class MainDisplay(DisplayWidget):
shrinkItem.setVisible(True) shrinkItem.setVisible(True)
else: else:
shrinkItem.setVisible(False) shrinkItem.setVisible(False)
shrinkItem.resize(self.screen[u'size'].width(), shrinkItem.resize(self.screen[u'size'].width(),
self.screen[u'size'].height()) self.screen[u'size'].height())
def image(self, image): def image(self, image):
@ -230,7 +230,7 @@ class MainDisplay(DisplayWidget):
`Image` `Image`
The Image to be displayed can be QImage or QPixmap The Image to be displayed can be QImage or QPixmap
""" """
log.debug(u'image') log.debug(u'image to display')
image = resize_image(image, self.screen[u'size'].width(), image = resize_image(image, self.screen[u'size'].width(),
self.screen[u'size'].height()) self.screen[u'size'].height())
self.resetVideo() self.resetVideo()

View File

@ -179,23 +179,23 @@ class SlideController(QtGui.QWidget):
self.HideMenu.setMenu(QtGui.QMenu( self.HideMenu.setMenu(QtGui.QMenu(
translate('OpenLP.SlideController', 'Hide'), self.Toolbar)) translate('OpenLP.SlideController', 'Hide'), self.Toolbar))
self.BlankScreen = QtGui.QAction(QtGui.QIcon( self.BlankScreen = QtGui.QAction(QtGui.QIcon(
u':/slides/slide_blank.png'), u':/slides/slide_blank.png'),
translate('OpenLP.SlideController', translate('OpenLP.SlideController',
'Blank Screen'), self.HideMenu) 'Blank Screen'), self.HideMenu)
self.BlankScreen.setCheckable(True) self.BlankScreen.setCheckable(True)
QtCore.QObject.connect(self.BlankScreen, QtCore.QObject.connect(self.BlankScreen,
QtCore.SIGNAL("triggered(bool)"), self.onBlankDisplay) QtCore.SIGNAL("triggered(bool)"), self.onBlankDisplay)
self.ThemeScreen = QtGui.QAction(QtGui.QIcon( self.ThemeScreen = QtGui.QAction(QtGui.QIcon(
u':/slides/slide_theme.png'), u':/slides/slide_theme.png'),
translate('OpenLP.SlideController', translate('OpenLP.SlideController',
'Blank to Theme'), self.HideMenu) 'Blank to Theme'), self.HideMenu)
self.ThemeScreen.setCheckable(True) self.ThemeScreen.setCheckable(True)
QtCore.QObject.connect(self.ThemeScreen, QtCore.QObject.connect(self.ThemeScreen,
QtCore.SIGNAL("triggered(bool)"), self.onThemeDisplay) QtCore.SIGNAL("triggered(bool)"), self.onThemeDisplay)
if self.screens.display_count > 1: if self.screens.display_count > 1:
self.DesktopScreen = QtGui.QAction(QtGui.QIcon( self.DesktopScreen = QtGui.QAction(QtGui.QIcon(
u':/slides/slide_desktop.png'), u':/slides/slide_desktop.png'),
translate('OpenLP.SlideController', translate('OpenLP.SlideController',
'Show Desktop'), self.HideMenu) 'Show Desktop'), self.HideMenu)
self.DesktopScreen.setCheckable(True) self.DesktopScreen.setCheckable(True)
QtCore.QObject.connect(self.DesktopScreen, QtCore.QObject.connect(self.DesktopScreen,
@ -214,7 +214,7 @@ class SlideController(QtGui.QWidget):
self.Toolbar.addToolbarSeparator(u'Close Separator') self.Toolbar.addToolbarSeparator(u'Close Separator')
self.Toolbar.addToolbarButton( self.Toolbar.addToolbarButton(
u'Edit Song', u':/general/general_edit.png', u'Edit Song', u':/general/general_edit.png',
translate('OpenLP.SlideController', translate('OpenLP.SlideController',
'Edit and reload song preview'), 'Edit and reload song preview'),
self.onEditSong) self.onEditSong)
if isLive: if isLive:
@ -584,11 +584,11 @@ class SlideController(QtGui.QWidget):
else: else:
label = QtGui.QLabel() label = QtGui.QLabel()
label.setMargin(4) label.setMargin(4)
pixmap = resize_image(frame[u'image'], # pixmap = resize_image(frame[u'image'],
self.parent.RenderManager.width, # self.parent.RenderManager.width,
self.parent.RenderManager.height) # self.parent.RenderManager.height)
label.setScaledContents(True) label.setScaledContents(True)
label.setPixmap(QtGui.QPixmap.fromImage(pixmap)) label.setPixmap(QtGui.QPixmap.fromImage(frame[u'image']))
self.PreviewListWidget.setCellWidget(framenumber, 0, label) self.PreviewListWidget.setCellWidget(framenumber, 0, label)
slideHeight = width * self.parent.RenderManager.screen_ratio slideHeight = width * self.parent.RenderManager.screen_ratio
row += 1 row += 1
@ -985,7 +985,7 @@ class SlideController(QtGui.QWidget):
self.video.hide() self.video.hide()
self.SlidePreview.clear() self.SlidePreview.clear()
self.SlidePreview.show() self.SlidePreview.show()
def onMediaClose(self): def onMediaClose(self):
""" """
Respond to a request to close the Video Respond to a request to close the Video