Add function to provide elided text

Fixes: https://launchpad.net/bugs/1405260
This commit is contained in:
Phill Ridout 2014-12-30 08:48:46 +00:00
parent 36417083ce
commit 5d1eac9ded
2 changed files with 15 additions and 1 deletions

View File

@ -43,6 +43,7 @@ from openlp.core.lib import OpenLPToolbar, ItemCapabilities, ServiceItem, ImageS
ScreenList, build_icon, build_html
from openlp.core.ui import HideMode, MainDisplay, Display, DisplayControllerType
from openlp.core.lib.ui import create_action
from openlp.core.utils import elide_text
from openlp.core.utils.actions import ActionList, CategoryOrder
from openlp.core.ui.listpreviewwidget import ListPreviewWidget
@ -161,6 +162,7 @@ class SlideController(DisplayController, RegistryProperties):
# Info label for the title of the current item, at the top of the slide controller
self.info_label = QtGui.QLabel(self.panel)
self.info_label.setAlignment(QtCore.Qt.AlignCenter)
self.info_label.setSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Preferred)
self.panel_layout.addWidget(self.info_label)
# Splitter
self.splitter = QtGui.QSplitter(self.panel)
@ -808,7 +810,8 @@ class SlideController(DisplayController, RegistryProperties):
if service_item.is_command():
Registry().execute(
'%s_start' % service_item.name.lower(), [self.service_item, self.is_live, self.hide_mode(), slide_no])
self.info_label.setText(self.service_item.title)
self.info_label.setText(elide_text(self.service_item.title, self.info_label.font(), self.info_label.width()))
self.info_label.setToolTip(self.service_item.title)
self.slide_list = {}
if self.is_live:
self.song_menu.menu().clear()

View File

@ -506,6 +506,17 @@ def get_natural_key(string):
return [b''] + key
return key
def elide_text(text, font, width):
"""
Add an ellipsis to text if it is wider than width.
:param text: The string to elide
:param font: The font that the text is being desplayed in
:param width: The width that the elided text string needs to fill
:return: The elided string or just text
"""
font_metrics = QtGui.QFontMetrics(font)
return font_metrics.elidedText(text, QtCore.Qt.ElideRight, width)
from .languagemanager import LanguageManager
from .actions import ActionList