openlp/openlp/core/ui/themestab.py

208 lines
10 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2010-12-26 11:04:47 +00:00
# Copyright (c) 2008-2011 Raoul Snyman #
# Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael #
2010-07-24 22:10:47 +00:00
# Gorven, Scott Guerrieri, Meinert Jordan, Andreas Preikschat, Christian #
# Richter, Philip Ridout, Maikel Stuivenberg, Martin Thompson, Jon Tibble, #
# Carsten Tinggaard, Frode Woldsund #
# --------------------------------------------------------------------------- #
# 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; version 2 of the License. #
# #
# 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, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
from PyQt4 import QtCore, QtGui
from openlp.core.lib import SettingsTab, Receiver, ThemeLevel, translate
class ThemesTab(SettingsTab):
"""
ThemesTab is the theme settings tab in the settings dialog.
"""
def __init__(self, parent):
self.parent = parent
2009-10-30 17:44:16 +00:00
SettingsTab.__init__(self, u'Themes')
def setupUi(self):
self.setObjectName(u'ThemesTab')
SettingsTab.setupUi(self)
self.GlobalGroupBox = QtGui.QGroupBox(self.leftColumn)
self.GlobalGroupBox.setObjectName(u'GlobalGroupBox')
self.GlobalGroupBoxLayout = QtGui.QVBoxLayout(self.GlobalGroupBox)
self.GlobalGroupBoxLayout.setObjectName(u'GlobalGroupBoxLayout')
self.DefaultComboBox = QtGui.QComboBox(self.GlobalGroupBox)
self.DefaultComboBox.setSizeAdjustPolicy(
QtGui.QComboBox.AdjustToMinimumContentsLength)
self.DefaultComboBox.setSizePolicy(
QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)
self.DefaultComboBox.setObjectName(u'DefaultComboBox')
self.GlobalGroupBoxLayout.addWidget(self.DefaultComboBox)
self.DefaultListView = QtGui.QLabel(self.GlobalGroupBox)
self.DefaultListView.setObjectName(u'DefaultListView')
self.GlobalGroupBoxLayout.addWidget(self.DefaultListView)
self.leftLayout.addWidget(self.GlobalGroupBox)
self.leftLayout.addStretch()
self.LevelGroupBox = QtGui.QGroupBox(self.rightColumn)
self.LevelGroupBox.setObjectName(u'LevelGroupBox')
self.LevelLayout = QtGui.QFormLayout(self.LevelGroupBox)
self.LevelLayout.setLabelAlignment(
QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)
self.LevelLayout.setFormAlignment(
QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)
self.LevelLayout.setObjectName(u'LevelLayout')
self.SongLevelRadioButton = QtGui.QRadioButton(self.LevelGroupBox)
self.SongLevelRadioButton.setObjectName(u'SongLevelRadioButton')
self.SongLevelLabel = QtGui.QLabel(self.LevelGroupBox)
self.SongLevelLabel.setWordWrap(True)
self.SongLevelLabel.setObjectName(u'SongLevelLabel')
self.LevelLayout.addRow(self.SongLevelRadioButton, self.SongLevelLabel)
self.ServiceLevelRadioButton = QtGui.QRadioButton(self.LevelGroupBox)
self.ServiceLevelRadioButton.setObjectName(u'ServiceLevelRadioButton')
self.ServiceLevelLabel = QtGui.QLabel(self.LevelGroupBox)
self.ServiceLevelLabel.setWordWrap(True)
self.ServiceLevelLabel.setObjectName(u'ServiceLevelLabel')
self.LevelLayout.addRow(self.ServiceLevelRadioButton,
self.ServiceLevelLabel)
self.GlobalLevelRadioButton = QtGui.QRadioButton(self.LevelGroupBox)
self.GlobalLevelRadioButton.setChecked(True)
self.GlobalLevelRadioButton.setObjectName(u'GlobalLevelRadioButton')
self.GlobalLevelLabel = QtGui.QLabel(self.LevelGroupBox)
self.GlobalLevelLabel.setWordWrap(True)
self.GlobalLevelLabel.setObjectName(u'GlobalLevelLabel')
self.LevelLayout.addRow(self.GlobalLevelRadioButton,
self.GlobalLevelLabel)
self.rightLayout.addWidget(self.LevelGroupBox)
self.rightLayout.addStretch()
QtCore.QObject.connect(self.SongLevelRadioButton,
QtCore.SIGNAL(u'pressed()'), self.onSongLevelButtonPressed)
QtCore.QObject.connect(self.ServiceLevelRadioButton,
QtCore.SIGNAL(u'pressed()'), self.onServiceLevelButtonPressed)
QtCore.QObject.connect(self.GlobalLevelRadioButton,
QtCore.SIGNAL(u'pressed()'), self.onGlobalLevelButtonPressed)
QtCore.QObject.connect(self.DefaultComboBox,
QtCore.SIGNAL(u'activated(int)'), self.onDefaultComboBoxChanged)
2009-08-25 05:18:09 +00:00
QtCore.QObject.connect(Receiver.get_receiver(),
2010-04-16 07:31:01 +00:00
QtCore.SIGNAL(u'theme_update_list'), self.updateThemeList)
def retranslateUi(self):
self.tabTitleVisible = translate('OpenLP.ThemesTab', 'Themes')
self.GlobalGroupBox.setTitle(
translate('OpenLP.ThemesTab', 'Global Theme'))
self.LevelGroupBox.setTitle(
translate('OpenLP.ThemesTab', 'Theme Level'))
self.SongLevelRadioButton.setText(
translate('OpenLP.ThemesTab', 'S&ong Level'))
self.SongLevelLabel.setText(
translate('OpenLP.ThemesTab', 'Use the theme from each song '
2010-06-18 23:18:08 +00:00
'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.'))
self.ServiceLevelRadioButton.setText(
translate('OpenLP.ThemesTab', '&Service Level'))
self.ServiceLevelLabel.setText(
translate('OpenLP.ThemesTab', 'Use the theme from the service, '
2010-06-18 23:18:08 +00:00
'overriding any of the individual songs\' themes. If the '
'service doesn\'t have a theme, then use the global theme.'))
self.GlobalLevelRadioButton.setText(
translate('OpenLP.ThemesTab', '&Global Level'))
self.GlobalLevelLabel.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):
2010-04-27 16:27:57 +00:00
settings = QtCore.QSettings()
settings.beginGroup(self.settingsSection)
2010-04-27 16:27:57 +00:00
self.theme_level = settings.value(
2010-04-28 14:17:42 +00:00
u'theme level', QtCore.QVariant(ThemeLevel.Global)).toInt()[0]
2010-04-27 16:27:57 +00:00
self.global_theme = unicode(settings.value(
2010-04-28 14:17:42 +00:00
u'global theme', QtCore.QVariant(u'')).toString())
settings.endGroup()
if self.theme_level == ThemeLevel.Global:
self.GlobalLevelRadioButton.setChecked(True)
elif self.theme_level == ThemeLevel.Service:
self.ServiceLevelRadioButton.setChecked(True)
else:
self.SongLevelRadioButton.setChecked(True)
def save(self):
2010-04-27 16:27:57 +00:00
settings = QtCore.QSettings()
settings.beginGroup(self.settingsSection)
2010-04-28 14:17:42 +00:00
settings.setValue(u'theme level',
2010-04-27 16:27:57 +00:00
QtCore.QVariant(self.theme_level))
2010-04-28 14:17:42 +00:00
settings.setValue(u'global theme',
2010-04-27 16:27:57 +00:00
QtCore.QVariant(self.global_theme))
2010-04-28 14:17:42 +00:00
settings.endGroup()
2010-12-03 18:56:12 +00:00
self.parent.renderManager.set_global_theme(
self.global_theme, self.theme_level)
Receiver.send_message(u'theme_update_global', self.global_theme)
2009-08-29 07:17:56 +00:00
def postSetUp(self):
2010-04-16 07:31:01 +00:00
Receiver.send_message(u'theme_update_global', self.global_theme)
def onSongLevelButtonPressed(self):
self.theme_level = ThemeLevel.Song
def onServiceLevelButtonPressed(self):
self.theme_level = ThemeLevel.Service
def onGlobalLevelButtonPressed(self):
self.theme_level = ThemeLevel.Global
def onDefaultComboBoxChanged(self, value):
self.global_theme = unicode(self.DefaultComboBox.currentText())
2010-12-03 18:56:12 +00:00
self.parent.renderManager.set_global_theme(
self.global_theme, self.theme_level)
2009-09-21 17:56:36 +00:00
image = self.parent.ThemeManagerContents.getPreviewImage(
self.global_theme)
preview = QtGui.QPixmap(unicode(image))
if not preview.isNull():
preview = preview.scaled(300, 255, QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation)
self.DefaultListView.setPixmap(preview)
2009-05-16 16:38:03 +00:00
def updateThemeList(self, theme_list):
"""
Called from ThemeManager when the Themes have changed.
``theme_list``
The list of available themes::
2010-11-13 20:13:24 +00:00
[u'Bible Theme', u'Song Theme']
2009-05-16 16:38:03 +00:00
"""
# Reload as may have been triggered by the ThemeManager.
2010-04-27 16:27:57 +00:00
self.global_theme = unicode(QtCore.QSettings().value(
self.settingsSection + u'/global theme',
2010-04-28 14:17:42 +00:00
QtCore.QVariant(u'')).toString())
2009-05-16 16:38:03 +00:00
self.DefaultComboBox.clear()
for theme in theme_list:
self.DefaultComboBox.addItem(theme)
2009-09-21 17:56:36 +00:00
id = self.DefaultComboBox.findText(
self.global_theme, QtCore.Qt.MatchExactly)
if id == -1:
id = 0 # Not Found
self.global_theme = u''
self.DefaultComboBox.setCurrentIndex(id)
2010-12-03 18:56:12 +00:00
self.parent.renderManager.set_global_theme(
self.global_theme, self.theme_level)
2009-05-18 19:47:18 +00:00
if self.global_theme is not u'':
2009-09-21 17:56:36 +00:00
image = self.parent.ThemeManagerContents.getPreviewImage(
self.global_theme)
preview = QtGui.QPixmap(unicode(image))
if not preview.isNull():
preview = preview.scaled(300, 255, QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation)
self.DefaultListView.setPixmap(preview)