mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-17 20:09:50 +01:00
Merge commit '710536ad506d' into appearance
This commit is contained in:
commit
b08567b697
79
src/core/appearance.cpp
Normal file
79
src/core/appearance.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/* 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 "appearance.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
|
const char* Appearance::kSettingsGroup = "Appearance";
|
||||||
|
const char* Appearance::kUseCustomColorSet = "use-custom-set";
|
||||||
|
const char* Appearance::kForegroundColor = "foreground-color";
|
||||||
|
const char* Appearance::kBackgroundColor = "background-color";
|
||||||
|
|
||||||
|
Appearance::Appearance(QObject* parent)
|
||||||
|
: QObject(parent)
|
||||||
|
{
|
||||||
|
QSettings s;
|
||||||
|
s.beginGroup(kSettingsGroup);
|
||||||
|
QPalette p = QApplication::palette();
|
||||||
|
background_color_ = s.value(kBackgroundColor,
|
||||||
|
p.color(QPalette::WindowText)).value<QColor>();
|
||||||
|
foreground_color_ = s.value(kForegroundColor,
|
||||||
|
p.color(QPalette::Window)).value<QColor>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Appearance::LoadUserTheme() {
|
||||||
|
QSettings s;
|
||||||
|
s.beginGroup(kSettingsGroup);
|
||||||
|
bool use_a_custom_color_set = s.value(kUseCustomColorSet).toBool();
|
||||||
|
if (!use_a_custom_color_set)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ChangeForegroundColor(foreground_color_);
|
||||||
|
ChangeBackgroundColor(background_color_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Appearance::ResetToSystemDefaultTheme() {
|
||||||
|
QApplication::setPalette(QPalette());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Appearance::ChangeForegroundColor(const QColor& color) {
|
||||||
|
// Get the application palette
|
||||||
|
QPalette p = QApplication::palette();
|
||||||
|
|
||||||
|
// Modify the palette
|
||||||
|
p.setColor(QPalette::WindowText, color);
|
||||||
|
p.setColor(QPalette::Text, color);
|
||||||
|
|
||||||
|
// Make the modified palette the new application's palette
|
||||||
|
QApplication::setPalette(p);
|
||||||
|
foreground_color_ = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Appearance::ChangeBackgroundColor(const QColor& color) {
|
||||||
|
// Get the application palette
|
||||||
|
QPalette p = QApplication::palette();
|
||||||
|
|
||||||
|
// Modify the palette
|
||||||
|
p.setColor(QPalette::Window, color);
|
||||||
|
p.setColor(QPalette::Base, color);
|
||||||
|
|
||||||
|
// Make the modified palette the new application's palette
|
||||||
|
QApplication::setPalette(p);
|
||||||
|
background_color_ = color;
|
||||||
|
}
|
43
src/core/appearance.h
Normal file
43
src/core/appearance.h
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef APPEARANCE_H
|
||||||
|
#define APPEARANCE_H
|
||||||
|
|
||||||
|
#include <QColor>
|
||||||
|
#include <QPalette>
|
||||||
|
|
||||||
|
class Appearance : public QObject {
|
||||||
|
public:
|
||||||
|
Appearance(QObject* parent = NULL);
|
||||||
|
// Load the user preferred theme, which could the default system theme or a
|
||||||
|
// custom set of colors that user has chosen
|
||||||
|
void LoadUserTheme();
|
||||||
|
void ResetToSystemDefaultTheme();
|
||||||
|
void ChangeForegroundColor(const QColor& color);
|
||||||
|
void ChangeBackgroundColor(const QColor& color);
|
||||||
|
|
||||||
|
static const char* kSettingsGroup;
|
||||||
|
static const char* kUseCustomColorSet;
|
||||||
|
static const char* kForegroundColor;
|
||||||
|
static const char* kBackgroundColor;
|
||||||
|
private:
|
||||||
|
QColor foreground_color_;
|
||||||
|
QColor background_color_;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // APPEARANCE_H
|
4674
src/translations/translations.pot
Normal file
4674
src/translations/translations.pot
Normal file
File diff suppressed because it is too large
Load Diff
136
src/ui/appearancesettingspage.cpp
Normal file
136
src/ui/appearancesettingspage.cpp
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
/* 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>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
|
#include "iconloader.h"
|
||||||
|
#include "settingsdialog.h"
|
||||||
|
#include "ui_appearancesettingspage.h"
|
||||||
|
#include "core/appearance.h"
|
||||||
|
#include "core/logging.h"
|
||||||
|
|
||||||
|
AppearanceSettingsPage::AppearanceSettingsPage(SettingsDialog* dialog)
|
||||||
|
: SettingsPage(dialog),
|
||||||
|
ui_(new Ui_AppearanceSettingsPage),
|
||||||
|
original_use_a_custom_color_set_(false)
|
||||||
|
{
|
||||||
|
ui_->setupUi(this);
|
||||||
|
setWindowIcon(IconLoader::Load("view-media-visualization"));
|
||||||
|
|
||||||
|
Load();
|
||||||
|
|
||||||
|
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_);
|
||||||
|
|
||||||
|
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)));
|
||||||
|
}
|
||||||
|
|
||||||
|
AppearanceSettingsPage::~AppearanceSettingsPage() {
|
||||||
|
delete ui_;
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
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_;
|
||||||
|
|
||||||
|
InitColorSelectorsColors();
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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_);
|
||||||
|
if (!color_selected.isValid())
|
||||||
|
return;
|
||||||
|
|
||||||
|
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_);
|
||||||
|
if (!color_selected.isValid())
|
||||||
|
return;
|
||||||
|
|
||||||
|
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() {
|
||||||
|
UpdateColorSelectorColor(ui_->select_foreground_color, current_foreground_color_);
|
||||||
|
UpdateColorSelectorColor(ui_->select_background_color, current_background_color_);
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
color_selector->setStyleSheet(css);
|
||||||
|
}
|
57
src/ui/appearancesettingspage.h
Normal file
57
src/ui/appearancesettingspage.h
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef APPEARANCESETTINGSPAGE_H
|
||||||
|
#define APPEARANCESETTINGSPAGE_H
|
||||||
|
|
||||||
|
#include "settingspage.h"
|
||||||
|
|
||||||
|
class QWidget;
|
||||||
|
|
||||||
|
class Ui_AppearanceSettingsPage;
|
||||||
|
|
||||||
|
class AppearanceSettingsPage : public SettingsPage {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
AppearanceSettingsPage(SettingsDialog* dialog);
|
||||||
|
~AppearanceSettingsPage();
|
||||||
|
|
||||||
|
void Load();
|
||||||
|
void Save();
|
||||||
|
void Cancel();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void SelectForegroundColor();
|
||||||
|
void SelectBackgroundColor();
|
||||||
|
void UseCustomColorSetOptionChanged(bool);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Set the widget's background to new_color
|
||||||
|
void UpdateColorSelectorColor(QWidget* color_selector, const QColor& new_color);
|
||||||
|
// Init (or refresh) the colorSelectors colors
|
||||||
|
void InitColorSelectorsColors();
|
||||||
|
|
||||||
|
Ui_AppearanceSettingsPage* ui_;
|
||||||
|
bool original_use_a_custom_color_set_;
|
||||||
|
QColor original_foreground_color_;
|
||||||
|
QColor original_background_color_;
|
||||||
|
QColor current_foreground_color_;
|
||||||
|
QColor current_background_color_;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // APPEARANCESETTINGSPAGE_H
|
170
src/ui/appearancesettingspage.ui
Normal file
170
src/ui/appearancesettingspage.ui
Normal file
@ -0,0 +1,170 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>AppearanceSettingsPage</class>
|
||||||
|
<widget class="QWidget" name="AppearanceSettingsPage">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>596</width>
|
||||||
|
<height>199</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Appearance</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="groupBox">
|
||||||
|
<property name="title">
|
||||||
|
<string>Colors</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="use_system_color_set">
|
||||||
|
<property name="text">
|
||||||
|
<string>Use the system default color set</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="use_a_custom_color_set">
|
||||||
|
<property name="text">
|
||||||
|
<string>Use a custom color set</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="select_foreground_color_label">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Select foreground color:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="select_foreground_color">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="select_background_color_label">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Select background color:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="select_background_color">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>use_a_custom_color_set</sender>
|
||||||
|
<signal>toggled(bool)</signal>
|
||||||
|
<receiver>select_background_color</receiver>
|
||||||
|
<slot>setEnabled(bool)</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>301</x>
|
||||||
|
<y>72</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>440</x>
|
||||||
|
<y>139</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>use_a_custom_color_set</sender>
|
||||||
|
<signal>toggled(bool)</signal>
|
||||||
|
<receiver>select_background_color_label</receiver>
|
||||||
|
<slot>setEnabled(bool)</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>301</x>
|
||||||
|
<y>72</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>162</x>
|
||||||
|
<y>139</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>use_a_custom_color_set</sender>
|
||||||
|
<signal>toggled(bool)</signal>
|
||||||
|
<receiver>select_foreground_color</receiver>
|
||||||
|
<slot>setEnabled(bool)</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>301</x>
|
||||||
|
<y>72</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>440</x>
|
||||||
|
<y>104</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>use_a_custom_color_set</sender>
|
||||||
|
<signal>toggled(bool)</signal>
|
||||||
|
<receiver>select_foreground_color_label</receiver>
|
||||||
|
<slot>setEnabled(bool)</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>301</x>
|
||||||
|
<y>72</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>162</x>
|
||||||
|
<y>104</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
Loading…
Reference in New Issue
Block a user