openlp/openlp/core/ui/themestab.py

225 lines
12 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2019-04-13 13:00:22 +00:00
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
2022-02-01 10:10:57 +00:00
# Copyright (c) 2008-2022 OpenLP Developers #
2019-04-13 13:00:22 +00:00
# ---------------------------------------------------------------------- #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
##########################################################################
2013-02-01 21:34:23 +00:00
"""
The Themes configuration tab
"""
2015-11-07 00:49:40 +00:00
from PyQt5 import QtCore, QtGui, QtWidgets
2017-10-07 07:05:07 +00:00
from openlp.core.common import ThemeLevel
from openlp.core.common.i18n import UiStrings, translate
from openlp.core.common.registry import Registry
from openlp.core.lib.settingstab import SettingsTab
from openlp.core.lib.ui import find_and_set_in_combo_box
2018-06-24 06:56:50 +00:00
from openlp.core.ui.icons import UiIcons
class ThemesTab(SettingsTab):
"""
ThemesTab is the theme settings tab in the settings dialog.
"""
2013-03-16 21:18:05 +00:00
def __init__(self, parent):
2013-02-01 21:34:23 +00:00
"""
Constructor
"""
2018-06-24 06:56:50 +00:00
self.icon_path = UiIcons().theme
2013-03-16 16:59:10 +00:00
theme_translated = translate('OpenLP.ThemesTab', 'Themes')
2013-08-31 18:17:38 +00:00
super(ThemesTab, self).__init__(parent, 'Themes', theme_translated)
def setup_ui(self):
2013-02-01 21:34:23 +00:00
"""
Set up the UI
"""
2013-08-31 18:17:38 +00:00
self.setObjectName('ThemesTab')
super(ThemesTab, self).setup_ui()
2015-11-07 00:49:40 +00:00
self.global_group_box = QtWidgets.QGroupBox(self.left_column)
2013-08-31 18:17:38 +00:00
self.global_group_box.setObjectName('global_group_box')
2015-11-07 00:49:40 +00:00
self.global_group_box_layout = QtWidgets.QVBoxLayout(self.global_group_box)
2013-08-31 18:17:38 +00:00
self.global_group_box_layout.setObjectName('global_group_box_layout')
2015-11-07 00:49:40 +00:00
self.default_combo_box = QtWidgets.QComboBox(self.global_group_box)
self.default_combo_box.setSizeAdjustPolicy(QtWidgets.QComboBox.AdjustToMinimumContentsLength)
self.default_combo_box.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
2013-08-31 18:17:38 +00:00
self.default_combo_box.setObjectName('default_combo_box')
2013-03-16 16:59:10 +00:00
self.global_group_box_layout.addWidget(self.default_combo_box)
2015-11-07 00:49:40 +00:00
self.default_list_view = QtWidgets.QLabel(self.global_group_box)
2013-08-31 18:17:38 +00:00
self.default_list_view.setObjectName('default_list_view')
2013-03-16 16:59:10 +00:00
self.global_group_box_layout.addWidget(self.default_list_view)
self.left_layout.addWidget(self.global_group_box)
2015-11-07 00:49:40 +00:00
self.universal_group_box = QtWidgets.QGroupBox(self.left_column)
2014-07-21 06:37:41 +00:00
self.universal_group_box.setObjectName('universal_group_box')
2015-11-07 00:49:40 +00:00
self.universal_group_box_layout = QtWidgets.QVBoxLayout(self.universal_group_box)
2014-07-21 06:37:41 +00:00
self.universal_group_box_layout.setObjectName('universal_group_box_layout')
self.item_transitions_check_box = QtWidgets.QCheckBox(self.universal_group_box)
self.item_transitions_check_box.setObjectName('item_transitions_check_box')
self.universal_group_box_layout.addWidget(self.item_transitions_check_box)
self.theme_hot_reload = QtWidgets.QCheckBox(self.universal_group_box)
self.theme_hot_reload.setObjectName('theme_hot_reload')
self.universal_group_box_layout.addWidget(self.theme_hot_reload)
2014-07-21 06:37:41 +00:00
self.left_layout.addWidget(self.universal_group_box)
2013-03-16 16:59:10 +00:00
self.left_layout.addStretch()
2015-11-07 00:49:40 +00:00
self.level_group_box = QtWidgets.QGroupBox(self.right_column)
2013-08-31 18:17:38 +00:00
self.level_group_box.setObjectName('level_group_box')
2015-11-07 00:49:40 +00:00
self.level_layout = QtWidgets.QFormLayout(self.level_group_box)
2013-03-16 21:18:05 +00:00
self.level_layout.setLabelAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)
2013-03-16 16:59:10 +00:00
self.level_layout.setFormAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)
2013-08-31 18:17:38 +00:00
self.level_layout.setObjectName('level_layout')
2015-11-07 00:49:40 +00:00
self.song_level_radio_button = QtWidgets.QRadioButton(self.level_group_box)
2013-08-31 18:17:38 +00:00
self.song_level_radio_button.setObjectName('song_level_radio_button')
2015-11-07 00:49:40 +00:00
self.song_level_label = QtWidgets.QLabel(self.level_group_box)
2013-08-31 18:17:38 +00:00
self.song_level_label.setObjectName('song_level_label')
2013-03-16 16:59:10 +00:00
self.level_layout.addRow(self.song_level_radio_button, self.song_level_label)
2015-11-07 00:49:40 +00:00
self.service_level_radio_button = QtWidgets.QRadioButton(self.level_group_box)
2013-08-31 18:17:38 +00:00
self.service_level_radio_button.setObjectName('service_level_radio_button')
2015-11-07 00:49:40 +00:00
self.service_level_label = QtWidgets.QLabel(self.level_group_box)
2013-08-31 18:17:38 +00:00
self.service_level_label.setObjectName('service_level_label')
2013-03-16 16:59:10 +00:00
self.level_layout.addRow(self.service_level_radio_button, self.service_level_label)
2015-11-07 00:49:40 +00:00
self.global_level_radio_button = QtWidgets.QRadioButton(self.level_group_box)
2013-08-31 18:17:38 +00:00
self.global_level_radio_button.setObjectName('global_level_radio_button')
2015-11-07 00:49:40 +00:00
self.global_level_label = QtWidgets.QLabel(self.level_group_box)
2013-08-31 18:17:38 +00:00
self.global_level_label.setObjectName('global_level_label')
2013-03-16 16:59:10 +00:00
self.level_layout.addRow(self.global_level_radio_button, self.global_level_label)
label_top_margin = (self.song_level_radio_button.sizeHint().height() -
2013-12-26 17:36:00 +00:00
self.song_level_label.sizeHint().height()) // 2
2013-03-16 16:59:10 +00:00
for label in [self.song_level_label, self.service_level_label, self.global_level_label]:
rect = label.rect()
rect.setTop(rect.top() + label_top_margin)
label.setFrameRect(rect)
label.setWordWrap(True)
2013-03-16 16:59:10 +00:00
self.right_layout.addWidget(self.level_group_box)
self.right_layout.addStretch()
self.song_level_radio_button.clicked.connect(self.on_song_level_button_clicked)
2013-03-16 21:18:05 +00:00
self.service_level_radio_button.clicked.connect(self.on_service_level_button_clicked)
self.global_level_radio_button.clicked.connect(self.on_global_level_button_clicked)
2013-03-16 16:59:10 +00:00
self.default_combo_box.activated.connect(self.on_default_combo_box_changed)
2013-08-31 18:17:38 +00:00
Registry().register_function('theme_update_list', self.update_theme_list)
def retranslate_ui(self):
2013-02-01 21:34:23 +00:00
"""
Translate the UI on the fly
"""
2013-03-16 16:59:10 +00:00
self.tab_title_visible = UiStrings().Themes
self.global_group_box.setTitle(translate('OpenLP.ThemesTab', 'Global Theme'))
2014-07-21 06:37:41 +00:00
self.universal_group_box.setTitle(translate('OpenLP.ThemesTab', 'Universal Settings'))
self.item_transitions_check_box.setText(translate('OpenLP.ThemesTab', '&Transition between service items'))
self.theme_hot_reload.setText(translate('OpenLP.ThemesTab', '&Reload live theme when changed'))
2013-03-16 16:59:10 +00:00
self.level_group_box.setTitle(translate('OpenLP.ThemesTab', 'Theme Level'))
self.song_level_radio_button.setText(translate('OpenLP.ThemesTab', 'S&ong Level'))
2014-04-12 20:19:22 +00:00
self.song_level_label.setText(
translate('OpenLP.ThemesTab', 'Use the theme from each song in the database. If a song doesn\'t have a '
'theme associated with it, then use the service\'s theme. If the service '
'doesn\'t have a theme, then use the global theme.'))
2013-03-16 16:59:10 +00:00
self.service_level_radio_button.setText(translate('OpenLP.ThemesTab', '&Service Level'))
2014-04-12 20:19:22 +00:00
self.service_level_label.setText(
translate('OpenLP.ThemesTab', 'Use the theme from the service, overriding any of the individual '
'songs\' themes. If the service doesn\'t have a theme, then use the global '
'theme.'))
2013-03-16 16:59:10 +00:00
self.global_level_radio_button.setText(translate('OpenLP.ThemesTab', '&Global Level'))
2014-04-12 20:19:22 +00:00
self.global_level_label.setText(translate('OpenLP.ThemesTab', 'Use the global theme, overriding any themes '
'associated with either the service or the '
'songs.'))
2009-05-16 16:38:03 +00:00
def load(self):
2013-02-01 21:34:23 +00:00
"""
Load the theme settings into the tab
"""
2020-06-06 16:05:36 +00:00
self.theme_level = self.settings.value('themes/theme level')
self.global_theme = self.settings.value('themes/global theme')
self.item_transitions_check_box.setChecked(self.settings.value('themes/item transitions'))
self.theme_hot_reload.setChecked(self.settings.value('themes/hot reload'))
if self.theme_level == ThemeLevel.Global:
2013-03-16 16:59:10 +00:00
self.global_level_radio_button.setChecked(True)
elif self.theme_level == ThemeLevel.Service:
2013-03-16 16:59:10 +00:00
self.service_level_radio_button.setChecked(True)
else:
2013-03-16 16:59:10 +00:00
self.song_level_radio_button.setChecked(True)
def save(self):
2013-02-01 21:34:23 +00:00
"""
Save the settings
"""
2022-01-16 13:15:09 +00:00
theme_level = self.settings.value('themes/theme level')
global_theme = self.settings.value('themes/global theme')
2020-06-06 16:05:36 +00:00
self.settings.setValue('themes/theme level', self.theme_level)
self.settings.setValue('themes/global theme', self.global_theme)
self.settings.setValue('themes/item transitions', self.item_transitions_check_box.isChecked())
self.settings.setValue('themes/hot reload', self.theme_hot_reload.isChecked())
2019-02-13 19:41:10 +00:00
self.renderer.set_theme_level(self.theme_level)
2022-01-16 13:15:09 +00:00
if theme_level != self.theme_level:
self.settings_form.register_post_process('theme_level_changed')
if global_theme != self.global_theme:
self.settings_form.register_post_process('reload_global_theme')
2013-03-17 09:21:18 +00:00
if self.tab_visited:
2022-01-16 13:15:09 +00:00
self.settings_form.register_post_process('theme_update_list')
2013-03-17 09:21:18 +00:00
self.tab_visited = False
2009-08-29 07:17:56 +00:00
2013-03-16 21:18:05 +00:00
def on_song_level_button_clicked(self):
2013-02-01 21:34:23 +00:00
"""
Set the theme level
"""
self.theme_level = ThemeLevel.Song
2013-03-16 21:18:05 +00:00
def on_service_level_button_clicked(self):
2013-02-01 21:34:23 +00:00
"""
Set the theme level
"""
self.theme_level = ThemeLevel.Service
2013-03-16 21:18:05 +00:00
def on_global_level_button_clicked(self):
2013-02-01 21:34:23 +00:00
"""
Set the theme level
"""
self.theme_level = ThemeLevel.Global
2013-03-16 16:59:10 +00:00
def on_default_combo_box_changed(self, value):
2013-02-01 21:34:23 +00:00
"""
Set the global default theme
"""
2013-03-16 16:59:10 +00:00
self.global_theme = self.default_combo_box.currentText()
2018-11-06 18:55:34 +00:00
# self.renderer.set_global_theme()
2013-03-25 07:27:54 +00:00
self._preview_global_theme()
2013-02-07 11:33:47 +00:00
def update_theme_list(self, theme_list):
2009-05-16 16:38:03 +00:00
"""
Called from ThemeManager when the Themes have changed.
2014-03-17 19:05:55 +00:00
:param theme_list: The list of available themes::
2014-05-02 06:42:17 +00:00
['Bible Theme', 'Song Theme']
2009-05-16 16:38:03 +00:00
"""
# Reload as may have been triggered by the ThemeManager.
self.global_theme = self.settings.value('themes/global theme')
2013-03-16 16:59:10 +00:00
self.default_combo_box.clear()
self.default_combo_box.addItems(theme_list)
find_and_set_in_combo_box(self.default_combo_box, self.global_theme)
# self.renderer.set_global_theme()
2019-02-13 19:41:10 +00:00
self.renderer.set_theme_level(self.theme_level)
2019-03-09 03:53:20 +00:00
if self.global_theme != '':
2013-03-16 16:59:10 +00:00
self._preview_global_theme()
2011-02-01 00:33:50 +00:00
2013-03-16 16:59:10 +00:00
def _preview_global_theme(self):
2011-02-01 00:33:50 +00:00
"""
Utility method to update the global theme preview image.
"""
2017-09-26 16:39:13 +00:00
image_path = self.theme_manager.theme_path / '{file_name}.png'.format(file_name=self.global_theme)
preview = QtGui.QPixmap(str(image_path))
2011-02-01 00:33:50 +00:00
if not preview.isNull():
2012-12-29 15:25:29 +00:00
preview = preview.scaled(300, 255, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)
2013-03-16 16:59:10 +00:00
self.default_list_view.setPixmap(preview)