Renderer replacement started

This commit is contained in:
Tim Bentley 2010-07-11 08:45:49 +01:00
parent 1a2dfc863d
commit 02c0fe9e89
4 changed files with 637 additions and 455 deletions

View File

@ -165,12 +165,51 @@ def context_menu_separator(base):
action.setSeparator(True)
return action
def resize_image(image, width, height):
def resize_image_for_web(image, width, height, background=QtCore.Qt.black):
"""
Resize an image to fit on the current screen for the web and retuns
it as a byte stream.
``image``
The image to resize.
``width``
The new image width.
``height``
The new image height.
``background ``
The background colour defaults to black.
"""
new_image = resize_image(image, width, height, background)
return image_to_byte(image)
def image_to_byte(image):
"""
Resize an image to fit on the current screen for the web and retuns
it as a byte stream.
``image``
The image to converted.
"""
byte_array = QtCore.QByteArray()
buffer = QtCore.QBuffer(byte_array) #// use buffer to store pixmap into byteArray
buffer.open(QtCore.QIODevice.WriteOnly)
pixmap = QtGui.QPixmap(image)
pixmap.save(buffer, "PNG")
#convert to base64 encoding so does not get missed!
return byte_array
def resize_image(image, width, height, background=QtCore.Qt.black):
"""
Resize an image to fit on the current screen.
``image``
The image to resize.
``width``
The new image width.
``height``
The new image height.
``background ``
The background colour defaults to black.
"""
preview = QtGui.QImage(image)
if not preview.isNull():
@ -186,7 +225,7 @@ def resize_image(image, width, height):
# and move it to the centre of the preview space
new_image = QtGui.QImage(width, height,
QtGui.QImage.Format_ARGB32_Premultiplied)
new_image.fill(QtCore.Qt.black)
new_image.fill(background)
painter = QtGui.QPainter(new_image)
painter.drawImage((width - realw) / 2, (height - realh) / 2, preview)
return new_image
@ -215,6 +254,7 @@ from settingstab import SettingsTab
from serviceitem import ServiceItem
from serviceitem import ServiceItemType
from serviceitem import ItemCapabilities
from htmlbuilder import build_html
from toolbar import OpenLPToolbar
from dockwidget import OpenLPDockWidget
from theme import ThemeLevel, ThemeXML

View File

@ -167,21 +167,25 @@ class Renderer(object):
shell = "<p>%s</p>"
temp_text = u''
old_html_text = u''
page = []
for line in text:
#do we need a <br> here?
temp_text = temp_text + line
# mark line ends
temp_text = temp_text + line + u'<br>'
html_text = shell % temp_text
doc.setHtml(html_text)
#Text too long so gone to next mage
if layout.pageCount() != 1:
formatted.append(old_html_text)
page.append(shell % old_html_text)
formatted.append(page)
temp_text = line
old_html_text = temp_text
formatted.append(old_html_text)
for f in formatted:
print "f", f
page.append(shell % old_html_text)
formatted.append(page)
print "ft", formatted
print "st", split_text
log.debug(u'format_slide - End')
return split_text
#return split_text
return formatted
def pre_render_text(self, text):
metrics = QtGui.QFontMetrics(self.main_font)

View File

@ -40,8 +40,6 @@ from slidecontroller import HideMode
from servicenoteform import ServiceNoteForm
from serviceitemeditform import ServiceItemEditForm
from screen import ScreenList
from maindisplay import MainDisplay
from maindisplay import VideoDisplay
from maindisplay import DisplayManager
from amendthemeform import AmendThemeForm
from slidecontroller import SlideController

File diff suppressed because it is too large Load Diff