forked from openlp/openlp
Added smart scaling when manually resized, integrated with settings dialog, fixed some pep8 errors
This commit is contained in:
parent
1e94cd92e9
commit
68460f5e3f
@ -121,6 +121,7 @@ class Settings(QtCore.QSettings):
|
|||||||
'advanced/double click live': False,
|
'advanced/double click live': False,
|
||||||
'advanced/enable exit confirmation': True,
|
'advanced/enable exit confirmation': True,
|
||||||
'advanced/expand service item': False,
|
'advanced/expand service item': False,
|
||||||
|
'advanced/slide max height': 0,
|
||||||
'advanced/hide mouse': True,
|
'advanced/hide mouse': True,
|
||||||
'advanced/is portable': False,
|
'advanced/is portable': False,
|
||||||
'advanced/max recent files': 20,
|
'advanced/max recent files': 20,
|
||||||
|
@ -80,6 +80,13 @@ class AdvancedTab(SettingsTab):
|
|||||||
self.expand_service_item_check_box = QtWidgets.QCheckBox(self.ui_group_box)
|
self.expand_service_item_check_box = QtWidgets.QCheckBox(self.ui_group_box)
|
||||||
self.expand_service_item_check_box.setObjectName('expand_service_item_check_box')
|
self.expand_service_item_check_box.setObjectName('expand_service_item_check_box')
|
||||||
self.ui_layout.addRow(self.expand_service_item_check_box)
|
self.ui_layout.addRow(self.expand_service_item_check_box)
|
||||||
|
self.slide_max_height_label = QtWidgets.QLabel(self.ui_group_box)
|
||||||
|
self.slide_max_height_label.setObjectName('slide_max_height_label')
|
||||||
|
self.slide_max_height_spin_box = QtWidgets.QSpinBox(self.ui_group_box)
|
||||||
|
self.slide_max_height_spin_box.setObjectName('slide_max_height_spin_box')
|
||||||
|
self.slide_max_height_spin_box.setRange(0,1000)
|
||||||
|
self.slide_max_height_spin_box.setSingleStep(20)
|
||||||
|
self.ui_layout.addRow(self.slide_max_height_label,self.slide_max_height_spin_box)
|
||||||
self.search_as_type_check_box = QtWidgets.QCheckBox(self.ui_group_box)
|
self.search_as_type_check_box = QtWidgets.QCheckBox(self.ui_group_box)
|
||||||
self.search_as_type_check_box.setObjectName('SearchAsType_check_box')
|
self.search_as_type_check_box.setObjectName('SearchAsType_check_box')
|
||||||
self.ui_layout.addRow(self.search_as_type_check_box)
|
self.ui_layout.addRow(self.search_as_type_check_box)
|
||||||
@ -272,6 +279,9 @@ class AdvancedTab(SettingsTab):
|
|||||||
'Preview items when clicked in Media Manager'))
|
'Preview items when clicked in Media Manager'))
|
||||||
self.expand_service_item_check_box.setText(translate('OpenLP.AdvancedTab',
|
self.expand_service_item_check_box.setText(translate('OpenLP.AdvancedTab',
|
||||||
'Expand new service items on creation'))
|
'Expand new service items on creation'))
|
||||||
|
self.slide_max_height_label.setText(translate('OpenLP.AdvancedTab',
|
||||||
|
'Max height for non-text slides\nin slide controller:'))
|
||||||
|
self.slide_max_height_spin_box.setSpecialValueText(translate('OpenLP.AdvancedTab', 'Disabled'))
|
||||||
self.enable_auto_close_check_box.setText(translate('OpenLP.AdvancedTab',
|
self.enable_auto_close_check_box.setText(translate('OpenLP.AdvancedTab',
|
||||||
'Enable application exit confirmation'))
|
'Enable application exit confirmation'))
|
||||||
self.service_name_group_box.setTitle(translate('OpenLP.AdvancedTab', 'Default Service Name'))
|
self.service_name_group_box.setTitle(translate('OpenLP.AdvancedTab', 'Default Service Name'))
|
||||||
@ -340,6 +350,7 @@ class AdvancedTab(SettingsTab):
|
|||||||
self.double_click_live_check_box.setChecked(settings.value('double click live'))
|
self.double_click_live_check_box.setChecked(settings.value('double click live'))
|
||||||
self.single_click_preview_check_box.setChecked(settings.value('single click preview'))
|
self.single_click_preview_check_box.setChecked(settings.value('single click preview'))
|
||||||
self.expand_service_item_check_box.setChecked(settings.value('expand service item'))
|
self.expand_service_item_check_box.setChecked(settings.value('expand service item'))
|
||||||
|
self.slide_max_height_spin_box.setValue(settings.value('slide max height'))
|
||||||
self.enable_auto_close_check_box.setChecked(settings.value('enable exit confirmation'))
|
self.enable_auto_close_check_box.setChecked(settings.value('enable exit confirmation'))
|
||||||
self.hide_mouse_check_box.setChecked(settings.value('hide mouse'))
|
self.hide_mouse_check_box.setChecked(settings.value('hide mouse'))
|
||||||
self.service_name_day.setCurrentIndex(settings.value('default service day'))
|
self.service_name_day.setCurrentIndex(settings.value('default service day'))
|
||||||
@ -421,6 +432,7 @@ class AdvancedTab(SettingsTab):
|
|||||||
settings.setValue('double click live', self.double_click_live_check_box.isChecked())
|
settings.setValue('double click live', self.double_click_live_check_box.isChecked())
|
||||||
settings.setValue('single click preview', self.single_click_preview_check_box.isChecked())
|
settings.setValue('single click preview', self.single_click_preview_check_box.isChecked())
|
||||||
settings.setValue('expand service item', self.expand_service_item_check_box.isChecked())
|
settings.setValue('expand service item', self.expand_service_item_check_box.isChecked())
|
||||||
|
settings.setValue('slide max height', self.slide_max_height_spin_box.value())
|
||||||
settings.setValue('enable exit confirmation', self.enable_auto_close_check_box.isChecked())
|
settings.setValue('enable exit confirmation', self.enable_auto_close_check_box.isChecked())
|
||||||
settings.setValue('hide mouse', self.hide_mouse_check_box.isChecked())
|
settings.setValue('hide mouse', self.hide_mouse_check_box.isChecked())
|
||||||
settings.setValue('alternate rows', self.alternate_rows_check_box.isChecked())
|
settings.setValue('alternate rows', self.alternate_rows_check_box.isChecked())
|
||||||
|
@ -26,7 +26,7 @@ It is based on a QTableWidget but represents its contents in list form.
|
|||||||
|
|
||||||
from PyQt5 import QtCore, QtGui, QtWidgets
|
from PyQt5 import QtCore, QtGui, QtWidgets
|
||||||
|
|
||||||
from openlp.core.common import RegistryProperties
|
from openlp.core.common import RegistryProperties, Settings
|
||||||
from openlp.core.lib import ImageSource, ServiceItem
|
from openlp.core.lib import ImageSource, ServiceItem
|
||||||
|
|
||||||
|
|
||||||
@ -48,9 +48,6 @@ class ListPreviewWidget(QtWidgets.QTableWidget, RegistryProperties):
|
|||||||
super(QtWidgets.QTableWidget, self).__init__(parent)
|
super(QtWidgets.QTableWidget, self).__init__(parent)
|
||||||
self._setup(screen_ratio)
|
self._setup(screen_ratio)
|
||||||
|
|
||||||
# max row height for non-text slides in pixels. If <= 0, will disable max row height.
|
|
||||||
self.max_img_row_height = 200
|
|
||||||
|
|
||||||
def _setup(self, screen_ratio):
|
def _setup(self, screen_ratio):
|
||||||
"""
|
"""
|
||||||
Set up the widget
|
Set up the widget
|
||||||
@ -66,6 +63,8 @@ class ListPreviewWidget(QtWidgets.QTableWidget, RegistryProperties):
|
|||||||
# Initialize variables.
|
# Initialize variables.
|
||||||
self.service_item = ServiceItem()
|
self.service_item = ServiceItem()
|
||||||
self.screen_ratio = screen_ratio
|
self.screen_ratio = screen_ratio
|
||||||
|
# Connect signals
|
||||||
|
self.verticalHeader().sectionResized.connect(self.row_resized)
|
||||||
|
|
||||||
def resizeEvent(self, event):
|
def resizeEvent(self, event):
|
||||||
"""
|
"""
|
||||||
@ -83,14 +82,30 @@ class ListPreviewWidget(QtWidgets.QTableWidget, RegistryProperties):
|
|||||||
# Sort out songs, bibles, etc.
|
# Sort out songs, bibles, etc.
|
||||||
if self.service_item.is_text():
|
if self.service_item.is_text():
|
||||||
self.resizeRowsToContents()
|
self.resizeRowsToContents()
|
||||||
else:
|
|
||||||
# Sort out image heights.
|
# Sort out image heights.
|
||||||
height = self.viewport().width() // self.screen_ratio ### Moved out of loop as only needs to run once
|
else:
|
||||||
if self.max_img_row_height > 0 and height > self.max_img_row_height: ### Apply row height cap.
|
height = self.viewport().width() // self.screen_ratio
|
||||||
height = self.max_img_row_height
|
max_img_row_height = Settings().value('advanced/slide max height')
|
||||||
|
# Adjust for row height cap if in use.
|
||||||
|
if max_img_row_height > 0 and height > max_img_row_height:
|
||||||
|
height = max_img_row_height
|
||||||
|
# Apply new height to slides
|
||||||
for frame_number in range(len(self.service_item.get_frames())):
|
for frame_number in range(len(self.service_item.get_frames())):
|
||||||
self.setRowHeight(frame_number, height)
|
self.setRowHeight(frame_number, height)
|
||||||
|
|
||||||
|
def row_resized(self, row, old_height, new_height):
|
||||||
|
"""
|
||||||
|
Will scale non-image slides.
|
||||||
|
"""
|
||||||
|
# Only for non-text slides when row height cap in use
|
||||||
|
if self.service_item.is_text() or Settings().value('advanced/slide max height') <= 0:
|
||||||
|
return
|
||||||
|
# Get and validate label widget containing slide & adjust max width
|
||||||
|
try:
|
||||||
|
self.cellWidget(row, 0).children()[1].setMaximumWidth(new_height * self.screen_ratio)
|
||||||
|
except:
|
||||||
|
return
|
||||||
|
|
||||||
def screen_size_changed(self, screen_ratio):
|
def screen_size_changed(self, screen_ratio):
|
||||||
"""
|
"""
|
||||||
This method is called whenever the live screen size changes, which then makes a layout recalculation necessary
|
This method is called whenever the live screen size changes, which then makes a layout recalculation necessary
|
||||||
@ -144,21 +159,26 @@ class ListPreviewWidget(QtWidgets.QTableWidget, RegistryProperties):
|
|||||||
pixmap = QtGui.QPixmap.fromImage(image)
|
pixmap = QtGui.QPixmap.fromImage(image)
|
||||||
pixmap.setDevicePixelRatio(label.devicePixelRatio())
|
pixmap.setDevicePixelRatio(label.devicePixelRatio())
|
||||||
label.setPixmap(pixmap)
|
label.setPixmap(pixmap)
|
||||||
### begin added/modified content
|
|
||||||
if self.max_img_row_height > 0:
|
|
||||||
label.setMaximumWidth(self.max_img_row_height * self.screen_ratio) ### set max width based on max height
|
|
||||||
label.resize(self.max_img_row_height * self.screen_ratio,self.max_img_row_height) ### resize to max width and max height; may be adjusted when setRowHeight called.
|
|
||||||
container = QtWidgets.QWidget() ### container widget
|
|
||||||
hbox = QtWidgets.QHBoxLayout() ### hbox to allow for horizonal stretch padding
|
|
||||||
hbox.setContentsMargins(0, 0, 0, 0) ### 0 contents margins to avoid extra padding
|
|
||||||
hbox.addWidget(label,stretch=1) ### add slide, stretch allows growing to max-width
|
|
||||||
hbox.addStretch(0) ### add strech padding with lowest priority; will only grow when slide has hit max-width
|
|
||||||
container.setLayout(hbox) ### populate container widget
|
|
||||||
self.setCellWidget(frame_number, 0, container) ### populate cell with container
|
|
||||||
else:
|
|
||||||
self.setCellWidget(frame_number, 0, label) ### populate cell with slide
|
|
||||||
### end added/modified content
|
|
||||||
slide_height = width // self.screen_ratio
|
slide_height = width // self.screen_ratio
|
||||||
|
# Setup row height cap if in use.
|
||||||
|
max_img_row_height = Settings().value('advanced/slide max height')
|
||||||
|
if max_img_row_height > 0:
|
||||||
|
if slide_height > max_img_row_height:
|
||||||
|
slide_height = max_img_row_height
|
||||||
|
label.setMaximumWidth(max_img_row_height * self.screen_ratio)
|
||||||
|
label.resize(max_img_row_height * self.screen_ratio, max_img_row_height)
|
||||||
|
# Build widget with stretch padding
|
||||||
|
container = QtWidgets.QWidget()
|
||||||
|
hbox = QtWidgets.QHBoxLayout()
|
||||||
|
hbox.setContentsMargins(0, 0, 0, 0)
|
||||||
|
hbox.addWidget(label, stretch=1)
|
||||||
|
hbox.addStretch(0)
|
||||||
|
container.setLayout(hbox)
|
||||||
|
# Add to table
|
||||||
|
self.setCellWidget(frame_number, 0, container)
|
||||||
|
else:
|
||||||
|
# Add to table
|
||||||
|
self.setCellWidget(frame_number, 0, label)
|
||||||
row += 1
|
row += 1
|
||||||
text.append(str(row))
|
text.append(str(row))
|
||||||
self.setItem(frame_number, 0, item)
|
self.setItem(frame_number, 0, item)
|
||||||
|
@ -23,9 +23,11 @@
|
|||||||
Package to test the openlp.core.ui.listpreviewwidget package.
|
Package to test the openlp.core.ui.listpreviewwidget package.
|
||||||
"""
|
"""
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
|
from openlp.core.common import Settings
|
||||||
from openlp.core.ui.listpreviewwidget import ListPreviewWidget
|
from openlp.core.ui.listpreviewwidget import ListPreviewWidget
|
||||||
|
|
||||||
from tests.functional import patch
|
from tests.functional import MagicMock, patch
|
||||||
|
|
||||||
|
|
||||||
class TestListPreviewWidget(TestCase):
|
class TestListPreviewWidget(TestCase):
|
||||||
|
Loading…
Reference in New Issue
Block a user