Add moodbar
This commit is contained in:
122
src/settings/moodbarsettingspage.cpp
Normal file
122
src/settings/moodbarsettingspage.cpp
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2012, David Sansome <me@davidsansome.com>
|
||||
*
|
||||
* 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>
|
||||
|
||||
#include "core/application.h"
|
||||
#include "core/mainwindow.h"
|
||||
#include "core/iconloader.h"
|
||||
#include "core/logging.h"
|
||||
|
||||
#include "settingsdialog.h"
|
||||
|
||||
#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;
|
||||
|
||||
MoodbarSettingsPage::MoodbarSettingsPage(SettingsDialog* dialog)
|
||||
: SettingsPage(dialog),
|
||||
ui_(new Ui_MoodbarSettingsPage),
|
||||
initialised_(false)
|
||||
{
|
||||
|
||||
ui_->setupUi(this);
|
||||
setWindowIcon(IconLoader::Load("moodbar"));
|
||||
|
||||
Load();
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
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() {
|
||||
|
||||
if (initialised_) return;
|
||||
initialised_ = true;
|
||||
|
||||
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)) {
|
||||
qLog(Warning) << "Unable to open moodbar sample file";
|
||||
return;
|
||||
}
|
||||
QByteArray data(file.readAll());
|
||||
|
||||
// Render and set each preview
|
||||
for (int i = 0; i < MoodbarRenderer::StyleCount; ++i) {
|
||||
|
||||
const MoodbarRenderer::MoodbarStyle style = MoodbarRenderer::MoodbarStyle(i);
|
||||
const ColorVector colors = MoodbarRenderer::Colors(data, style, palette());
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
54
src/settings/moodbarsettingspage.h
Normal file
54
src/settings/moodbarsettingspage.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2012, David Sansome <me@davidsansome.com>
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MOODBARSETTINGSPAGE_H
|
||||
#define MOODBARSETTINGSPAGE_H
|
||||
|
||||
#include "settingspage.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class Ui_MoodbarSettingsPage;
|
||||
|
||||
class MoodbarSettingsPage : public SettingsPage {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MoodbarSettingsPage(SettingsDialog* dialog);
|
||||
~MoodbarSettingsPage();
|
||||
|
||||
static const char *kSettingsGroup;
|
||||
|
||||
void Load();
|
||||
void Save();
|
||||
void Cancel();
|
||||
|
||||
private:
|
||||
static const int kMoodbarPreviewWidth;
|
||||
static const int kMoodbarPreviewHeight;
|
||||
|
||||
void InitMoodbarPreviews();
|
||||
|
||||
Ui_MoodbarSettingsPage* ui_;
|
||||
|
||||
bool initialised_;
|
||||
};
|
||||
|
||||
#endif // MOODBARSETTINGSPAGE_H
|
||||
61
src/settings/moodbarsettingspage.ui
Normal file
61
src/settings/moodbarsettingspage.ui
Normal file
@@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MoodbarSettingsPage</class>
|
||||
<widget class="QWidget" name="MoodbarSettingsPage">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>596</width>
|
||||
<height>666</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Moodbar</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="layout_moodbarsettingspage">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="moodbar_group">
|
||||
<property name="title">
|
||||
<string>Moodbar</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="layout_moodbar">
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="moodbar_show">
|
||||
<property name="text">
|
||||
<string>Show a moodbar in the track progress bar</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_moodbar_style">
|
||||
<property name="text">
|
||||
<string>Moodbar style</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="moodbar_style"/>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="moodbar_save">
|
||||
<property name="text">
|
||||
<string>Save the .mood files directly in the songs folders</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="moodbar_enabled">
|
||||
<property name="text">
|
||||
<string>Enabled</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -65,6 +65,9 @@
|
||||
#ifdef HAVE_TIDAL
|
||||
# include "tidalsettingspage.h"
|
||||
#endif
|
||||
#ifdef HAVE_MOODBAR
|
||||
# include "moodbarsettingspage.h"
|
||||
#endif
|
||||
|
||||
#include "ui_settingsdialog.h"
|
||||
|
||||
@@ -133,6 +136,10 @@ SettingsDialog::SettingsDialog(Application *app, QWidget *parent)
|
||||
AddPage(Page_GlobalShortcuts, new GlobalShortcutsSettingsPage(this), iface);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MOODBAR
|
||||
AddPage(Page_Moodbar, new MoodbarSettingsPage(this), iface);
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_TIDAL)
|
||||
QTreeWidgetItem *streaming = AddCategory(tr("Streaming"));
|
||||
#endif
|
||||
|
||||
@@ -83,6 +83,7 @@ class SettingsDialog : public QDialog {
|
||||
Page_Proxy,
|
||||
Page_Scrobbler,
|
||||
Page_Tidal,
|
||||
Page_Moodbar,
|
||||
};
|
||||
|
||||
enum Role {
|
||||
|
||||
Reference in New Issue
Block a user