Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start working on UI customization. Allow user to change global backgr…
…ound/foreground colors. Some work still required to update all components' colors Update issue 219 Started!
- Loading branch information
1 parent
483c367
commit 710536a
Showing
6 changed files
with
5,159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.