2019-04-18 15:03:01 +02:00
|
|
|
/*
|
|
|
|
* Strawberry Music Player
|
|
|
|
* This file was part of Clementine.
|
|
|
|
* Copyright 2012, David Sansome <me@davidsansome.com>
|
2021-03-20 21:14:47 +01:00
|
|
|
* Copyright 2019-2021, Jonas Kvinge <jonas@jkvinge.net>
|
2019-04-18 15:03:01 +02:00
|
|
|
*
|
|
|
|
* Strawberry 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.
|
|
|
|
*
|
|
|
|
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <QIODevice>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QSettings>
|
2020-02-09 02:29:35 +01:00
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QSize>
|
2019-04-18 15:03:01 +02:00
|
|
|
|
|
|
|
#include "core/iconloader.h"
|
|
|
|
#include "core/logging.h"
|
|
|
|
|
|
|
|
#include "settingsdialog.h"
|
2020-02-09 02:29:35 +01:00
|
|
|
#include "settingspage.h"
|
2019-04-18 15:03:01 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_MOODBAR
|
|
|
|
# include "moodbar/moodbarrenderer.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "moodbarsettingspage.h"
|
|
|
|
#include "ui_moodbarsettingspage.h"
|
|
|
|
|
|
|
|
const char *MoodbarSettingsPage::kSettingsGroup = "Moodbar";
|
|
|
|
const int MoodbarSettingsPage::kMoodbarPreviewWidth = 150;
|
|
|
|
const int MoodbarSettingsPage::kMoodbarPreviewHeight = 18;
|
|
|
|
|
2021-06-20 19:04:08 +02:00
|
|
|
MoodbarSettingsPage::MoodbarSettingsPage(SettingsDialog *dialog, QWidget *parent)
|
|
|
|
: SettingsPage(dialog, parent),
|
2019-04-18 15:03:01 +02:00
|
|
|
ui_(new Ui_MoodbarSettingsPage),
|
2021-07-11 07:40:57 +02:00
|
|
|
initialized_(false) {
|
2019-04-18 15:03:01 +02:00
|
|
|
|
|
|
|
ui_->setupUi(this);
|
2023-01-04 21:24:57 +01:00
|
|
|
setWindowIcon(IconLoader::Load("moodbar", true, 0, 32));
|
2019-04-18 15:03:01 +02:00
|
|
|
|
2021-03-21 04:47:11 +01:00
|
|
|
MoodbarSettingsPage::Load();
|
2021-07-11 07:40:57 +02:00
|
|
|
|
2019-04-18 15:03:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MoodbarSettingsPage::~MoodbarSettingsPage() { delete ui_; }
|
|
|
|
|
|
|
|
void MoodbarSettingsPage::Load() {
|
|
|
|
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(kSettingsGroup);
|
|
|
|
ui_->moodbar_enabled->setChecked(s.value("enabled", false).toBool());
|
|
|
|
ui_->moodbar_show->setChecked(s.value("show", false).toBool());
|
|
|
|
ui_->moodbar_style->setCurrentIndex(s.value("style", 0).toInt());
|
|
|
|
ui_->moodbar_save->setChecked(s.value("save", false).toBool());
|
|
|
|
s.endGroup();
|
|
|
|
|
|
|
|
InitMoodbarPreviews();
|
|
|
|
|
2020-05-25 23:56:54 +02:00
|
|
|
Init(ui_->layout_moodbarsettingspage->parentWidget());
|
|
|
|
|
2020-10-12 17:20:18 +02:00
|
|
|
if (!QSettings().childGroups().contains(kSettingsGroup)) set_changed();
|
|
|
|
|
2019-04-18 15:03:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MoodbarSettingsPage::Save() {
|
|
|
|
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(kSettingsGroup);
|
|
|
|
s.setValue("enabled", ui_->moodbar_enabled->isChecked());
|
|
|
|
s.setValue("show", ui_->moodbar_show->isChecked());
|
|
|
|
s.setValue("style", ui_->moodbar_style->currentIndex());
|
|
|
|
s.setValue("save", ui_->moodbar_save->isChecked());
|
|
|
|
s.endGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MoodbarSettingsPage::Cancel() {}
|
|
|
|
|
|
|
|
void MoodbarSettingsPage::InitMoodbarPreviews() {
|
|
|
|
|
2020-10-17 17:29:09 +02:00
|
|
|
if (initialized_) return;
|
|
|
|
initialized_ = true;
|
2019-04-18 15:03:01 +02:00
|
|
|
|
|
|
|
const QSize preview_size(kMoodbarPreviewWidth, kMoodbarPreviewHeight);
|
|
|
|
ui_->moodbar_style->setIconSize(preview_size);
|
|
|
|
|
|
|
|
// Read the sample data
|
|
|
|
QFile file(":/mood/sample.mood");
|
|
|
|
if (!file.open(QIODevice::ReadOnly)) {
|
2021-08-09 23:32:26 +02:00
|
|
|
qLog(Warning) << "Failed to open moodbar sample file" << file.fileName() << "for reading:" << file.errorString();
|
2019-04-18 15:03:01 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-04-23 21:08:28 +02:00
|
|
|
QByteArray file_data = file.readAll();
|
2021-02-02 21:08:58 +01:00
|
|
|
file.close();
|
2019-04-18 15:03:01 +02:00
|
|
|
|
|
|
|
// Render and set each preview
|
2023-02-18 14:09:27 +01:00
|
|
|
for (int i = 0; i < static_cast<int>(MoodbarRenderer::MoodbarStyle::StyleCount); ++i) {
|
2019-04-18 15:03:01 +02:00
|
|
|
|
2022-06-13 00:23:42 +02:00
|
|
|
const MoodbarRenderer::MoodbarStyle style = static_cast<MoodbarRenderer::MoodbarStyle>(i);
|
2020-04-23 21:08:28 +02:00
|
|
|
const ColorVector colors = MoodbarRenderer::Colors(file_data, style, palette());
|
2019-04-18 15:03:01 +02:00
|
|
|
|
|
|
|
QPixmap pixmap(preview_size);
|
|
|
|
QPainter p(&pixmap);
|
|
|
|
MoodbarRenderer::Render(colors, &p, pixmap.rect());
|
|
|
|
p.end();
|
|
|
|
|
|
|
|
ui_->moodbar_style->addItem(MoodbarRenderer::StyleName(style));
|
|
|
|
ui_->moodbar_style->setItemData(i, pixmap, Qt::DecorationRole);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|