2012-01-08 23:56:17 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2012, David Sansome <me@davidsansome.com>
|
|
|
|
|
|
|
|
Clementine 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.
|
|
|
|
|
|
|
|
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "appearancesettingspage.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QColorDialog>
|
2012-02-18 19:57:36 +01:00
|
|
|
#include <QFileDialog>
|
2012-05-28 00:44:49 +02:00
|
|
|
#include <QPainter>
|
2012-01-08 23:56:17 +01:00
|
|
|
#include <QSettings>
|
|
|
|
|
2012-05-28 00:44:49 +02:00
|
|
|
#include "config.h"
|
2012-01-08 23:56:17 +01:00
|
|
|
#include "iconloader.h"
|
2012-02-18 19:57:36 +01:00
|
|
|
#include "mainwindow.h"
|
2012-01-08 23:56:17 +01:00
|
|
|
#include "settingsdialog.h"
|
|
|
|
#include "ui_appearancesettingspage.h"
|
|
|
|
#include "core/appearance.h"
|
2012-05-28 00:44:49 +02:00
|
|
|
#include "core/application.h"
|
2012-01-08 23:56:17 +01:00
|
|
|
#include "core/logging.h"
|
2012-02-18 19:57:36 +01:00
|
|
|
#include "playlist/playlistview.h"
|
|
|
|
#include "ui/albumcoverchoicecontroller.h"
|
2012-01-08 23:56:17 +01:00
|
|
|
|
2012-05-28 00:44:49 +02:00
|
|
|
#ifdef HAVE_MOODBAR
|
2014-02-07 16:34:20 +01:00
|
|
|
#include "moodbar/moodbarrenderer.h"
|
2012-05-28 00:44:49 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
const int AppearanceSettingsPage::kMoodbarPreviewWidth = 150;
|
|
|
|
const int AppearanceSettingsPage::kMoodbarPreviewHeight = 18;
|
|
|
|
|
2012-01-08 23:56:17 +01:00
|
|
|
AppearanceSettingsPage::AppearanceSettingsPage(SettingsDialog* dialog)
|
2014-02-07 16:34:20 +01:00
|
|
|
: SettingsPage(dialog),
|
|
|
|
ui_(new Ui_AppearanceSettingsPage),
|
|
|
|
original_use_a_custom_color_set_(false),
|
|
|
|
playlist_view_background_image_type_(PlaylistView::Default),
|
|
|
|
initialised_moodbar_previews_(false) {
|
2012-01-08 23:56:17 +01:00
|
|
|
ui_->setupUi(this);
|
2015-10-14 03:01:08 +02:00
|
|
|
setWindowIcon(IconLoader::Load("view-media-visualization", IconLoader::Base));
|
2012-01-08 23:56:17 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
connect(ui_->blur_slider, SIGNAL(valueChanged(int)),
|
|
|
|
SLOT(BlurLevelChanged(int)));
|
|
|
|
connect(ui_->opacity_slider, SIGNAL(valueChanged(int)),
|
|
|
|
SLOT(OpacityLevelChanged(int)));
|
2013-02-17 03:55:54 +01:00
|
|
|
|
2012-01-08 23:56:17 +01:00
|
|
|
Load();
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
connect(ui_->select_foreground_color, SIGNAL(pressed()),
|
|
|
|
SLOT(SelectForegroundColor()));
|
|
|
|
connect(ui_->select_background_color, SIGNAL(pressed()),
|
|
|
|
SLOT(SelectBackgroundColor()));
|
|
|
|
connect(ui_->use_a_custom_color_set, SIGNAL(toggled(bool)),
|
|
|
|
SLOT(UseCustomColorSetOptionChanged(bool)));
|
2012-02-18 19:57:36 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
connect(ui_->select_background_image_filename_button, SIGNAL(pressed()),
|
|
|
|
SLOT(SelectBackgroundImage()));
|
2012-02-18 19:57:36 +01:00
|
|
|
connect(ui_->use_custom_background_image, SIGNAL(toggled(bool)),
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->background_image_filename, SLOT(setEnabled(bool)));
|
2012-02-18 19:57:36 +01:00
|
|
|
connect(ui_->use_custom_background_image, SIGNAL(toggled(bool)),
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->select_background_image_filename_button, SLOT(setEnabled(bool)));
|
2012-11-09 20:22:39 +01:00
|
|
|
|
|
|
|
connect(ui_->use_custom_background_image, SIGNAL(toggled(bool)),
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->blur_slider, SLOT(setEnabled(bool)));
|
2012-11-09 20:22:39 +01:00
|
|
|
connect(ui_->use_album_cover_background, SIGNAL(toggled(bool)),
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->blur_slider, SLOT(setEnabled(bool)));
|
2012-11-09 20:22:39 +01:00
|
|
|
|
|
|
|
connect(ui_->use_default_background, SIGNAL(toggled(bool)),
|
2014-02-07 16:34:20 +01:00
|
|
|
SLOT(DisableBlurAndOpacitySliders(bool)));
|
2012-11-09 20:22:39 +01:00
|
|
|
connect(ui_->use_no_background, SIGNAL(toggled(bool)),
|
2014-02-07 16:34:20 +01:00
|
|
|
SLOT(DisableBlurAndOpacitySliders(bool)));
|
2017-05-30 22:25:24 +02:00
|
|
|
#if !defined (Q_OS_UNIX) || defined (Q_OS_MACOS)
|
2017-08-16 16:09:55 +02:00
|
|
|
ui_->b_use_sys_icons->setDisabled(true);
|
2017-05-30 22:25:24 +02:00
|
|
|
#endif
|
2012-01-08 23:56:17 +01:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
AppearanceSettingsPage::~AppearanceSettingsPage() { delete ui_; }
|
2012-01-08 23:56:17 +01:00
|
|
|
|
|
|
|
void AppearanceSettingsPage::Load() {
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(Appearance::kSettingsGroup);
|
|
|
|
|
|
|
|
QPalette p = QApplication::palette();
|
|
|
|
|
|
|
|
// Keep in mind originals colors, in case the user clicks on Cancel, to be
|
|
|
|
// able to restore colors
|
2014-02-07 16:34:20 +01:00
|
|
|
original_use_a_custom_color_set_ =
|
|
|
|
s.value(Appearance::kUseCustomColorSet, false).toBool();
|
|
|
|
|
|
|
|
original_foreground_color_ =
|
|
|
|
s.value(Appearance::kForegroundColor, p.color(QPalette::WindowText))
|
|
|
|
.value<QColor>();
|
|
|
|
current_foreground_color_ = original_foreground_color_;
|
|
|
|
original_background_color_ =
|
|
|
|
s.value(Appearance::kBackgroundColor, p.color(QPalette::Window))
|
|
|
|
.value<QColor>();
|
|
|
|
current_background_color_ = original_background_color_;
|
2012-01-08 23:56:17 +01:00
|
|
|
|
|
|
|
InitColorSelectorsColors();
|
2017-05-30 22:25:24 +02:00
|
|
|
ui_->b_use_sys_icons->setChecked(s.value("b_use_sys_icons", false).toBool());
|
2012-05-28 00:44:49 +02:00
|
|
|
s.endGroup();
|
2012-02-18 19:57:36 +01:00
|
|
|
|
2012-05-28 00:44:49 +02:00
|
|
|
// Playlist settings
|
|
|
|
s.beginGroup(Playlist::kSettingsGroup);
|
2012-02-18 19:57:36 +01:00
|
|
|
playlist_view_background_image_type_ =
|
|
|
|
static_cast<PlaylistView::BackgroundImageType>(
|
2012-05-28 00:44:49 +02:00
|
|
|
s.value(PlaylistView::kSettingBackgroundImageType).toInt());
|
2014-02-07 16:34:20 +01:00
|
|
|
playlist_view_background_image_filename_ =
|
2012-05-28 00:44:49 +02:00
|
|
|
s.value(PlaylistView::kSettingBackgroundImageFilename).toString();
|
2012-03-19 20:06:29 +01:00
|
|
|
|
|
|
|
ui_->use_system_color_set->setChecked(!original_use_a_custom_color_set_);
|
|
|
|
ui_->use_a_custom_color_set->setChecked(original_use_a_custom_color_set_);
|
|
|
|
|
|
|
|
switch (playlist_view_background_image_type_) {
|
|
|
|
case PlaylistView::None:
|
|
|
|
ui_->use_no_background->setChecked(true);
|
2013-02-17 18:20:24 +01:00
|
|
|
DisableBlurAndOpacitySliders(true);
|
2012-03-19 20:06:29 +01:00
|
|
|
break;
|
|
|
|
case PlaylistView::AlbumCover:
|
|
|
|
ui_->use_album_cover_background->setChecked(true);
|
|
|
|
break;
|
|
|
|
case PlaylistView::Custom:
|
|
|
|
ui_->use_custom_background_image->setChecked(true);
|
|
|
|
break;
|
|
|
|
case PlaylistView::Default:
|
|
|
|
default:
|
|
|
|
ui_->use_default_background->setChecked(true);
|
2013-02-17 18:20:24 +01:00
|
|
|
DisableBlurAndOpacitySliders(true);
|
2012-03-19 20:06:29 +01:00
|
|
|
}
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->background_image_filename->setText(
|
|
|
|
playlist_view_background_image_filename_);
|
2013-02-17 04:03:39 +01:00
|
|
|
ui_->blur_slider->setValue(
|
|
|
|
s.value("blur_radius", PlaylistView::kDefaultBlurRadius).toInt());
|
|
|
|
ui_->opacity_slider->setValue(
|
|
|
|
s.value("opacity_level", PlaylistView::kDefaultOpacityLevel).toInt());
|
2012-11-19 14:32:39 +01:00
|
|
|
|
2012-05-28 00:44:49 +02:00
|
|
|
s.endGroup();
|
|
|
|
|
|
|
|
// Moodbar settings
|
|
|
|
s.beginGroup("Moodbar");
|
|
|
|
ui_->moodbar_show->setChecked(s.value("show", true).toBool());
|
|
|
|
ui_->moodbar_style->setCurrentIndex(s.value("style", 0).toInt());
|
2012-11-19 14:32:39 +01:00
|
|
|
ui_->moodbar_calculate->setChecked(!s.value("calculate", true).toBool());
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->moodbar_save->setChecked(
|
|
|
|
s.value("save_alongside_originals", false).toBool());
|
2012-05-28 00:44:49 +02:00
|
|
|
s.endGroup();
|
|
|
|
|
|
|
|
InitMoodbarPreviews();
|
2012-01-08 23:56:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AppearanceSettingsPage::Save() {
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(Appearance::kSettingsGroup);
|
|
|
|
bool use_a_custom_color_set = ui_->use_a_custom_color_set->isChecked();
|
|
|
|
s.setValue(Appearance::kUseCustomColorSet, use_a_custom_color_set);
|
|
|
|
if (use_a_custom_color_set) {
|
|
|
|
s.setValue(Appearance::kBackgroundColor, current_background_color_);
|
|
|
|
s.setValue(Appearance::kForegroundColor, current_foreground_color_);
|
|
|
|
} else {
|
|
|
|
dialog()->appearance()->ResetToSystemDefaultTheme();
|
|
|
|
}
|
2017-05-30 22:25:24 +02:00
|
|
|
s.setValue("b_use_sys_icons", ui_->b_use_sys_icons->isChecked());
|
2012-05-28 00:44:49 +02:00
|
|
|
s.endGroup();
|
2012-02-18 19:57:36 +01:00
|
|
|
|
2012-05-28 00:44:49 +02:00
|
|
|
// Playlist settings
|
|
|
|
s.beginGroup(Playlist::kSettingsGroup);
|
2014-02-07 16:34:20 +01:00
|
|
|
playlist_view_background_image_filename_ =
|
|
|
|
ui_->background_image_filename->text();
|
2012-02-18 19:57:36 +01:00
|
|
|
if (ui_->use_no_background->isChecked()) {
|
|
|
|
playlist_view_background_image_type_ = PlaylistView::None;
|
2012-03-03 01:20:37 +01:00
|
|
|
} else if (ui_->use_album_cover_background->isChecked()) {
|
|
|
|
playlist_view_background_image_type_ = PlaylistView::AlbumCover;
|
2012-02-18 19:57:36 +01:00
|
|
|
} else if (ui_->use_default_background->isChecked()) {
|
|
|
|
playlist_view_background_image_type_ = PlaylistView::Default;
|
|
|
|
} else if (ui_->use_custom_background_image->isChecked()) {
|
|
|
|
playlist_view_background_image_type_ = PlaylistView::Custom;
|
2012-05-28 00:44:49 +02:00
|
|
|
s.setValue(PlaylistView::kSettingBackgroundImageFilename,
|
2014-02-07 16:34:20 +01:00
|
|
|
playlist_view_background_image_filename_);
|
2012-02-18 19:57:36 +01:00
|
|
|
}
|
2012-05-28 00:44:49 +02:00
|
|
|
s.setValue(PlaylistView::kSettingBackgroundImageType,
|
2012-11-19 14:32:39 +01:00
|
|
|
playlist_view_background_image_type_);
|
2012-11-09 20:17:26 +01:00
|
|
|
s.setValue("blur_radius", ui_->blur_slider->value());
|
2013-02-15 13:41:56 +01:00
|
|
|
s.setValue("opacity_level", ui_->opacity_slider->value());
|
2012-05-28 00:44:49 +02:00
|
|
|
s.endGroup();
|
|
|
|
|
|
|
|
// Moodbar settings
|
|
|
|
s.beginGroup("Moodbar");
|
2012-11-19 14:32:39 +01:00
|
|
|
s.setValue("calculate", !ui_->moodbar_calculate->isChecked());
|
2012-05-28 00:44:49 +02:00
|
|
|
s.setValue("show", ui_->moodbar_show->isChecked());
|
|
|
|
s.setValue("style", ui_->moodbar_style->currentIndex());
|
|
|
|
s.setValue("save_alongside_originals", ui_->moodbar_save->isChecked());
|
|
|
|
s.endGroup();
|
2012-01-08 23:56:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AppearanceSettingsPage::Cancel() {
|
|
|
|
if (original_use_a_custom_color_set_) {
|
|
|
|
dialog()->appearance()->ChangeForegroundColor(original_foreground_color_);
|
|
|
|
dialog()->appearance()->ChangeBackgroundColor(original_background_color_);
|
|
|
|
} else {
|
|
|
|
dialog()->appearance()->ResetToSystemDefaultTheme();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppearanceSettingsPage::SelectForegroundColor() {
|
|
|
|
QColor color_selected = QColorDialog::getColor(current_foreground_color_);
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!color_selected.isValid()) return;
|
2012-11-19 14:32:39 +01:00
|
|
|
|
2012-01-08 23:56:17 +01:00
|
|
|
current_foreground_color_ = color_selected;
|
|
|
|
dialog()->appearance()->ChangeForegroundColor(color_selected);
|
|
|
|
|
|
|
|
UpdateColorSelectorColor(ui_->select_foreground_color, color_selected);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppearanceSettingsPage::SelectBackgroundColor() {
|
|
|
|
QColor color_selected = QColorDialog::getColor(current_background_color_);
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!color_selected.isValid()) return;
|
2012-11-19 14:32:39 +01:00
|
|
|
|
2012-01-08 23:56:17 +01:00
|
|
|
current_background_color_ = color_selected;
|
|
|
|
dialog()->appearance()->ChangeBackgroundColor(color_selected);
|
|
|
|
|
|
|
|
UpdateColorSelectorColor(ui_->select_background_color, color_selected);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppearanceSettingsPage::UseCustomColorSetOptionChanged(bool checked) {
|
|
|
|
if (checked) {
|
|
|
|
dialog()->appearance()->ChangeForegroundColor(current_foreground_color_);
|
|
|
|
dialog()->appearance()->ChangeBackgroundColor(current_background_color_);
|
|
|
|
} else {
|
|
|
|
dialog()->appearance()->ResetToSystemDefaultTheme();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppearanceSettingsPage::InitColorSelectorsColors() {
|
2014-02-07 16:34:20 +01:00
|
|
|
UpdateColorSelectorColor(ui_->select_foreground_color,
|
|
|
|
current_foreground_color_);
|
|
|
|
UpdateColorSelectorColor(ui_->select_background_color,
|
|
|
|
current_background_color_);
|
2012-01-08 23:56:17 +01:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void AppearanceSettingsPage::UpdateColorSelectorColor(QWidget* color_selector,
|
|
|
|
const QColor& color) {
|
|
|
|
QString css =
|
|
|
|
QString("background-color: rgb(%1, %2, %3); color: rgb(255, 255, 255)")
|
|
|
|
.arg(color.red())
|
|
|
|
.arg(color.green())
|
|
|
|
.arg(color.blue());
|
2012-01-08 23:56:17 +01:00
|
|
|
color_selector->setStyleSheet(css);
|
|
|
|
}
|
2012-02-18 19:57:36 +01:00
|
|
|
|
|
|
|
void AppearanceSettingsPage::SelectBackgroundImage() {
|
2014-02-07 16:34:20 +01:00
|
|
|
QString selected_filename = QFileDialog::getOpenFileName(
|
|
|
|
this, tr("Select background image"),
|
2012-02-18 19:57:36 +01:00
|
|
|
playlist_view_background_image_filename_,
|
|
|
|
tr(AlbumCoverChoiceController::kLoadImageFileFilter) + ";;" +
|
2014-02-07 16:34:20 +01:00
|
|
|
tr(AlbumCoverChoiceController::kAllFilesFilter));
|
|
|
|
if (selected_filename.isEmpty()) return;
|
2012-02-18 19:57:36 +01:00
|
|
|
playlist_view_background_image_filename_ = selected_filename;
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->background_image_filename->setText(
|
|
|
|
playlist_view_background_image_filename_);
|
2012-02-18 19:57:36 +01:00
|
|
|
}
|
2012-05-28 00:44:49 +02:00
|
|
|
|
2012-11-09 20:17:26 +01:00
|
|
|
void AppearanceSettingsPage::BlurLevelChanged(int value) {
|
|
|
|
ui_->background_blur_radius_label->setText(QString("%1px").arg(value));
|
|
|
|
}
|
|
|
|
|
2013-02-15 13:41:56 +01:00
|
|
|
void AppearanceSettingsPage::OpacityLevelChanged(int percent) {
|
|
|
|
ui_->background_opacity_label->setText(QString("%1\%").arg(percent));
|
|
|
|
}
|
|
|
|
|
2012-05-28 00:44:49 +02:00
|
|
|
void AppearanceSettingsPage::InitMoodbarPreviews() {
|
|
|
|
#ifdef HAVE_MOODBAR
|
2014-02-07 16:34:20 +01:00
|
|
|
if (initialised_moodbar_previews_) return;
|
2012-05-28 00:44:49 +02:00
|
|
|
initialised_moodbar_previews_ = true;
|
|
|
|
|
|
|
|
const QSize preview_size(kMoodbarPreviewWidth, kMoodbarPreviewHeight);
|
|
|
|
ui_->moodbar_style->setIconSize(preview_size);
|
|
|
|
|
|
|
|
// Read the sample data
|
|
|
|
QFile file(":sample.mood");
|
|
|
|
if (!file.open(QIODevice::ReadOnly)) {
|
|
|
|
qLog(Warning) << "Unable to open moodbar sample file";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QByteArray data(file.readAll());
|
|
|
|
|
|
|
|
// Render and set each preview
|
2014-02-07 16:34:20 +01:00
|
|
|
for (int i = 0; i < MoodbarRenderer::StyleCount; ++i) {
|
2012-05-28 13:50:07 +02:00
|
|
|
const MoodbarRenderer::MoodbarStyle style =
|
|
|
|
MoodbarRenderer::MoodbarStyle(i);
|
|
|
|
const ColorVector colors = MoodbarRenderer::Colors(data, style, palette());
|
2012-05-28 00:44:49 +02:00
|
|
|
|
|
|
|
QPixmap pixmap(preview_size);
|
|
|
|
QPainter p(&pixmap);
|
|
|
|
MoodbarRenderer::Render(colors, &p, pixmap.rect());
|
|
|
|
p.end();
|
|
|
|
|
2012-05-28 13:50:07 +02:00
|
|
|
ui_->moodbar_style->addItem(MoodbarRenderer::StyleName(style));
|
2012-05-28 00:44:49 +02:00
|
|
|
ui_->moodbar_style->setItemData(i, pixmap, Qt::DecorationRole);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
ui_->moodbar_group->hide();
|
|
|
|
#endif
|
|
|
|
}
|
2012-11-09 20:22:39 +01:00
|
|
|
|
2013-02-17 18:20:24 +01:00
|
|
|
void AppearanceSettingsPage::DisableBlurAndOpacitySliders(bool checked) {
|
|
|
|
// Blur slider
|
2012-11-09 20:22:39 +01:00
|
|
|
ui_->blur_slider->setDisabled(checked);
|
|
|
|
ui_->background_blur_radius_label->setDisabled(checked);
|
|
|
|
ui_->select_background_blur_label->setDisabled(checked);
|
2013-02-17 18:20:24 +01:00
|
|
|
|
|
|
|
// Opacity slider
|
|
|
|
ui_->opacity_slider->setDisabled(checked);
|
|
|
|
ui_->background_opacity_label->setDisabled(checked);
|
2013-02-17 19:02:07 +01:00
|
|
|
ui_->select_opacity_level_label->setDisabled(checked);
|
2012-11-09 20:22:39 +01:00
|
|
|
}
|