Added single click preview for service manager (see attached blueprint)

- Checkbox appears in advanced settings tab.
- When enabled, items will be sent to preview when clicked in service manager, but NOT if double-clicked.

bzr-revno: 2629
Fixes: https://launchpad.net/bugs/1536809
This commit is contained in:
ian@knightly.xyz 2016-03-15 22:34:58 +01:00 committed by Tomas Groth
commit dc6a9b6d86
4 changed files with 117 additions and 4 deletions

View File

@ -131,6 +131,7 @@ class Settings(QtCore.QSettings):
'advanced/save current plugin': False,
'advanced/slide limits': SlideLimits.End,
'advanced/single click preview': False,
'advanced/single click service preview': False,
'advanced/x11 bypass wm': X11_BYPASS_DEFAULT,
'advanced/search as type': True,
'crashreport/last directory': '',

View File

@ -77,6 +77,9 @@ class AdvancedTab(SettingsTab):
self.single_click_preview_check_box = QtWidgets.QCheckBox(self.ui_group_box)
self.single_click_preview_check_box.setObjectName('single_click_preview_check_box')
self.ui_layout.addRow(self.single_click_preview_check_box)
self.single_click_service_preview_check_box = QtWidgets.QCheckBox(self.ui_group_box)
self.single_click_service_preview_check_box.setObjectName('single_click_service_preview_check_box')
self.ui_layout.addRow(self.single_click_service_preview_check_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.ui_layout.addRow(self.expand_service_item_check_box)
@ -270,6 +273,8 @@ class AdvancedTab(SettingsTab):
'Double-click to send items straight to live'))
self.single_click_preview_check_box.setText(translate('OpenLP.AdvancedTab',
'Preview items when clicked in Media Manager'))
self.single_click_service_preview_check_box.setText(translate('OpenLP.AdvancedTab',
'Preview items when clicked in Service Manager'))
self.expand_service_item_check_box.setText(translate('OpenLP.AdvancedTab',
'Expand new service items on creation'))
self.enable_auto_close_check_box.setText(translate('OpenLP.AdvancedTab',
@ -339,6 +344,7 @@ class AdvancedTab(SettingsTab):
self.media_plugin_check_box.setChecked(settings.value('save current plugin'))
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_service_preview_check_box.setChecked(settings.value('single click service preview'))
self.expand_service_item_check_box.setChecked(settings.value('expand service item'))
self.enable_auto_close_check_box.setChecked(settings.value('enable exit confirmation'))
self.hide_mouse_check_box.setChecked(settings.value('hide mouse'))
@ -420,6 +426,7 @@ class AdvancedTab(SettingsTab):
settings.setValue('save current plugin', self.media_plugin_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 service preview', self.single_click_service_preview_check_box.isChecked())
settings.setValue('expand service item', self.expand_service_item_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())

View File

@ -211,7 +211,8 @@ class Ui_ServiceManager(object):
self.layout.addWidget(self.order_toolbar)
# Connect up our signals and slots
self.theme_combo_box.activated.connect(self.on_theme_combo_box_selected)
self.service_manager_list.doubleClicked.connect(self.on_make_live)
self.service_manager_list.doubleClicked.connect(self.on_double_click_live)
self.service_manager_list.clicked.connect(self.on_single_click_preview)
self.service_manager_list.itemCollapsed.connect(self.collapsed)
self.service_manager_list.itemExpanded.connect(self.expanded)
# Last little bits of setting up
@ -319,6 +320,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ServiceMa
self._modified = False
self._file_name = ''
self.service_has_all_original_files = True
self.list_double_clicked = False
def bootstrap_initialise(self):
"""
@ -1454,13 +1456,38 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ServiceMa
else:
return self.service_items[item]['service_item']
def on_make_live(self, field=None):
def on_double_click_live(self, field=None):
"""
Send the current item to the Live slide controller but triggered by a tablewidget click event.
:param field:
"""
self.list_double_clicked = True
self.make_live()
def on_single_click_preview(self, field=None):
"""
If single click previewing is enabled, and triggered by a tablewidget click event,
start a timeout to verify a double-click hasn't triggered.
:param field:
"""
if Settings().value('advanced/single click service preview'):
if not self.list_double_clicked:
# If a double click has not registered start a timer, otherwise wait for the existing timer to finish.
QtCore.QTimer.singleShot(QtWidgets.QApplication.instance().doubleClickInterval(),
self.on_single_click_preview_timeout)
def on_single_click_preview_timeout(self):
"""
If a single click ok, but double click not triggered, send the current item to the Preview slide controller.
:param field:
"""
if self.list_double_clicked:
# If a double click has registered, clear it.
self.list_double_clicked = False
else:
# Otherwise preview the item.
self.make_preview()
def make_live(self, row=-1):
"""
Send the current item to the Live slide controller

View File

@ -22,13 +22,14 @@
"""
Package to test the openlp.core.ui.slidecontroller package.
"""
import PyQt5
from unittest import TestCase
from openlp.core.common import Registry, ThemeLevel
from openlp.core.common import Registry, ThemeLevel, Settings
from openlp.core.lib import ServiceItem, ServiceItemType, ItemCapabilities
from openlp.core.ui import ServiceManager
from tests.functional import MagicMock
from tests.functional import MagicMock, patch
class TestServiceManager(TestCase):
@ -540,3 +541,80 @@ class TestServiceManager(TestCase):
self.assertEquals(service_manager.timed_slide_interval.setChecked.call_count, 0, 'Should not be called')
self.assertEquals(service_manager.theme_menu.menuAction().setVisible.call_count, 1,
'Should have be called once')
@patch(u'openlp.core.ui.servicemanager.Settings')
@patch(u'PyQt5.QtCore.QTimer.singleShot')
def single_click_preview_test_true(self, mocked_singleShot, MockedSettings):
"""
Test that when "Preview items when clicked in Service Manager" enabled the preview timer starts
"""
# GIVEN: A setting to enable "Preview items when clicked in Service Manager" and a service manager.
mocked_settings = MagicMock()
mocked_settings.value.return_value = True
MockedSettings.return_value = mocked_settings
service_manager = ServiceManager(None)
# WHEN: on_single_click_preview() is called
service_manager.on_single_click_preview()
# THEN: timer should have been started
mocked_singleShot.assert_called_with(PyQt5.QtWidgets.QApplication.instance().doubleClickInterval(),
service_manager.on_single_click_preview_timeout)
@patch(u'openlp.core.ui.servicemanager.Settings')
@patch(u'PyQt5.QtCore.QTimer.singleShot')
def single_click_preview_test_false(self, mocked_singleShot, MockedSettings):
"""
Test that when "Preview items when clicked in Service Manager" disabled the preview timer doesn't start
"""
# GIVEN: A setting to enable "Preview items when clicked in Service Manager" and a service manager.
mocked_settings = MagicMock()
mocked_settings.value.return_value = False
MockedSettings.return_value = mocked_settings
service_manager = ServiceManager(None)
# WHEN: on_single_click_preview() is called
service_manager.on_single_click_preview()
# THEN: timer should not be started
self.assertEquals(mocked_singleShot.call_count, 0, 'Should not be called')
@patch(u'openlp.core.ui.servicemanager.Settings')
@patch(u'PyQt5.QtCore.QTimer.singleShot')
@patch(u'openlp.core.ui.servicemanager.ServiceManager.make_live')
def single_click_preview_test_double(self, mocked_make_live, mocked_singleShot, MockedSettings):
"""
Test that when a double click has registered the preview timer doesn't start
"""
# GIVEN: A setting to enable "Preview items when clicked in Service Manager" and a service manager.
mocked_settings = MagicMock()
mocked_settings.value.return_value = True
MockedSettings.return_value = mocked_settings
service_manager = ServiceManager(None)
# WHEN: on_single_click_preview() is called following a double click
service_manager.on_double_click_live()
service_manager.on_single_click_preview()
# THEN: timer should not be started
self.assertEquals(mocked_singleShot.call_count, 0, 'Should not be called')
@patch(u'openlp.core.ui.servicemanager.ServiceManager.make_preview')
def single_click_timeout_test_single(self, mocked_make_preview):
"""
Test that when a single click has been registered, the item is sent to preview
"""
# GIVEN: A service manager.
service_manager = ServiceManager(None)
# WHEN: on_single_click_preview() is called
service_manager.on_single_click_preview_timeout()
# THEN: make_preview() should have been called
self.assertEquals(mocked_make_preview.call_count, 1, 'Should have been called once')
@patch(u'openlp.core.ui.servicemanager.ServiceManager.make_preview')
@patch(u'openlp.core.ui.servicemanager.ServiceManager.make_live')
def single_click_timeout_test_double(self, mocked_make_live, mocked_make_preview):
"""
Test that when a double click has been registered, the item does not goes to preview
"""
# GIVEN: A service manager.
service_manager = ServiceManager(None)
# WHEN: on_single_click_preview() is called after a double click
service_manager.on_double_click_live()
service_manager.on_single_click_preview_timeout()
# THEN: make_preview() should have been called
self.assertEquals(mocked_make_preview.call_count, 0, 'Should not be called')