1 /*
2 * Cantata
3 *
4 * Copyright (c) 2011-2020 Craig Drummond <craig.p.drummond@gmail.com>
5 *
6 * ----
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; see the file COPYING. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 */
23
24 #include "othersettings.h"
25 #include "gui/settings.h"
26 #include "support/pathrequester.h"
27 #include "widgets/playqueueview.h"
28
29 static const char *constValueProperty="value";
30
OtherSettings(QWidget * p)31 OtherSettings::OtherSettings(QWidget *p)
32 : QWidget(p)
33 {
34 setupUi(this);
35 connect(wikipediaIntroOnly, SIGNAL(toggled(bool)), SLOT(toggleWikiNote()));
36
37 contextBackdrop_none->setProperty(constValueProperty, PlayQueueView::BI_None);
38 contextBackdrop_artist->setProperty(constValueProperty, PlayQueueView::BI_Cover);
39 contextBackdrop_custom->setProperty(constValueProperty, PlayQueueView::BI_Custom);
40 contextBackdropFile->setDirMode(false);
41 contextBackdropFile->setFilter(tr("Images (*.png *.jpg)"));
42 int labelWidth=qMax(fontMetrics().horizontalAdvance(QLatin1String("100%")), fontMetrics().horizontalAdvance(tr("10px", "pixels")));
43 contextBackdropOpacityLabel->setFixedWidth(labelWidth);
44 contextBackdropBlurLabel->setFixedWidth(labelWidth);
45 connect(contextBackdropOpacity, SIGNAL(valueChanged(int)), SLOT(setContextBackdropOpacityLabel()));
46 connect(contextBackdropBlur, SIGNAL(valueChanged(int)), SLOT(setContextBackdropBlurLabel()));
47 connect(contextBackdrop_none, SIGNAL(toggled(bool)), SLOT(enableContextBackdropOptions()));
48 connect(contextBackdrop_artist, SIGNAL(toggled(bool)), SLOT(enableContextBackdropOptions()));
49 connect(contextBackdrop_custom, SIGNAL(toggled(bool)), SLOT(enableContextBackdropOptions()));
50 }
51
load()52 void OtherSettings::load()
53 {
54 wikipediaIntroOnly->setChecked(Settings::self()->wikipediaIntroOnly());
55 contextDarkBackground->setChecked(Settings::self()->contextDarkBackground());
56 contextAlwaysCollapsed->setChecked(Settings::self()->contextAlwaysCollapsed());
57 storeLyricsInMpdDir->setChecked(Settings::self()->storeLyricsInMpdDir());
58
59 int bgnd=Settings::self()->contextBackdrop();
60 contextBackdrop_none->setChecked(bgnd==contextBackdrop_none->property(constValueProperty).toInt());
61 contextBackdrop_artist->setChecked(bgnd==contextBackdrop_artist->property(constValueProperty).toInt());
62 contextBackdrop_custom->setChecked(bgnd==contextBackdrop_custom->property(constValueProperty).toInt());
63 contextBackdropOpacity->setValue(Settings::self()->contextBackdropOpacity());
64 contextBackdropBlur->setValue(Settings::self()->contextBackdropBlur());
65 contextBackdropFile->setText(Utils::convertPathForDisplay(Settings::self()->contextBackdropFile(), false));
66 contextSwitchTime->setValue(Settings::self()->contextSwitchTime());
67
68 toggleWikiNote();
69 setContextBackdropOpacityLabel();
70 setContextBackdropBlurLabel();
71 enableContextBackdropOptions();
72 }
73
save()74 void OtherSettings::save()
75 {
76 Settings::self()->saveWikipediaIntroOnly(wikipediaIntroOnly->isChecked());
77 Settings::self()->saveContextDarkBackground(contextDarkBackground->isChecked());
78 Settings::self()->saveContextAlwaysCollapsed(contextAlwaysCollapsed->isChecked());
79 Settings::self()->saveStoreLyricsInMpdDir(storeLyricsInMpdDir->isChecked());
80
81 if (contextBackdrop_none->isChecked()) {
82 Settings::self()->saveContextBackdrop(contextBackdrop_none->property(constValueProperty).toInt());
83 } else if (contextBackdrop_artist->isChecked()) {
84 Settings::self()->saveContextBackdrop(contextBackdrop_artist->property(constValueProperty).toInt());
85 } else if (contextBackdrop_custom->isChecked()) {
86 Settings::self()->saveContextBackdrop(contextBackdrop_custom->property(constValueProperty).toInt());
87 }
88 Settings::self()->saveContextBackdropOpacity(contextBackdropOpacity->value());
89 Settings::self()->saveContextBackdropBlur(contextBackdropBlur->value());
90 Settings::self()->saveContextBackdropFile(Utils::convertPathFromDisplay(contextBackdropFile->text(), false));
91 Settings::self()->saveContextSwitchTime(contextSwitchTime->value());
92 }
93
toggleWikiNote()94 void OtherSettings::toggleWikiNote()
95 {
96 wikipediaIntroOnlyNote->setOn(!wikipediaIntroOnly->isChecked());
97 }
98
setContextBackdropOpacityLabel()99 void OtherSettings::setContextBackdropOpacityLabel()
100 {
101 contextBackdropOpacityLabel->setText(tr("%1%", "value%").arg(contextBackdropOpacity->value()));
102 }
103
setContextBackdropBlurLabel()104 void OtherSettings::setContextBackdropBlurLabel()
105 {
106 contextBackdropBlurLabel->setText(tr("%1 px", "pixels").arg(contextBackdropBlur->value()));
107 }
108
enableContextBackdropOptions()109 void OtherSettings::enableContextBackdropOptions()
110 {
111 contextBackdropOpacity->setEnabled(!contextBackdrop_none->isChecked());
112 contextBackdropOpacityLabel->setEnabled(contextBackdropOpacity->isEnabled());
113 contextBackdropBlur->setEnabled(contextBackdropOpacity->isEnabled());
114 contextBackdropBlurLabel->setEnabled(contextBackdropOpacity->isEnabled());
115 }
116
117 #include "moc_othersettings.cpp"
118