aboutsummaryrefslogtreecommitdiff
path: root/libLumina/LuminaThemes.cpp
diff options
context:
space:
mode:
authorKen Moore <ken@pcbsd.org>2014-10-10 15:10:19 -0400
committerKen Moore <ken@pcbsd.org>2014-10-10 15:10:19 -0400
commitf936d7d555972bb0f60d4f217356d7e43f231580 (patch)
tree87b602ce714d18b3230398b28d2f1b8def43512b /libLumina/LuminaThemes.cpp
parentMake sure the directory catch for running lumina-fm happens at the end (in ca... (diff)
downloadlumina-f936d7d555972bb0f60d4f217356d7e43f231580.tar.gz
lumina-f936d7d555972bb0f60d4f217356d7e43f231580.tar.bz2
lumina-f936d7d555972bb0f60d4f217356d7e43f231580.zip
Large update to the Lumina project: provide full theming capabilities.
1) New libLumina classes: LuminaThemes.h 2) Single-line usage to add lumina theme usage to an application (already added to all the Lumina utilities) 3) Include a Lumina-default theme template, as well as a single color scheme (will add more later) 4) Will create a global Qt style for "lumina" so that this theme engine can be automatically applied to all Qt applications at a later date (want to make sure to beat this up and get it working reliably before turning it on for everything). Major Features: 1) Full Qt theme capabilities through Qt stylesheets (so they can be modified and applied on the fly). 2) Stylesheets are broken into a couple pieces: an "incomplete" stylesheet file (the theme template) with variables in place of colors, font size, and font family. A "color" file which variable->value definitions for the different colors. And a themesettings.cfg files which keeps track of the files/font settings. 3) Along with this, add the ability to specify the icon theme that is used as well, and make that automatically re-loaded as necessary. 4) Add the ability to read/set thes values in lumina-config. The lumina-config usage is still a bit rough: working on cleaning it up right now.
Diffstat (limited to 'libLumina/LuminaThemes.cpp')
-rw-r--r--libLumina/LuminaThemes.cpp73
1 files changed, 56 insertions, 17 deletions
diff --git a/libLumina/LuminaThemes.cpp b/libLumina/LuminaThemes.cpp
index 5100a084..8548f739 100644
--- a/libLumina/LuminaThemes.cpp
+++ b/libLumina/LuminaThemes.cpp
@@ -9,6 +9,7 @@
#include "LuminaUtils.h"
#include "LuminaOS.h"
#include <QIcon>
+#include <QFont>
#include <QDebug>
@@ -65,11 +66,15 @@ QStringList LTHEME::availableSystemIcons(){ //returns: [name] for each item
}
}
//Now get all the icon themes in these directories
- QStringList themes;
+ QStringList themes, tmpthemes;
QDir dir;
for(int i=0; i<paths.length(); i++){
if(dir.cd(paths[i])){
- themes << dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
+ tmpthemes = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
+ for(int j=0; j<tmpthemes.length(); j++){
+ if(tmpthemes[j].startsWith("default")){ continue; }
+ if(QFile::exists(dir.absoluteFilePath(tmpthemes[j]+"/index.theme")) ){ themes << tmpthemes[j]; }
+ }
}
}
themes.removeDuplicates();
@@ -77,36 +82,61 @@ QStringList LTHEME::availableSystemIcons(){ //returns: [name] for each item
return themes;
}
- //Return the currently selected Theme/Colors/Icons
-QStringList LTHEME::currentSettings(){ //returns [theme path, colorspath, iconsname]
- QStringList out; out << "" << "" << "";
+//Save a new theme/color file
+bool LTHEME::saveLocalTheme(QString name, QStringList contents){
+ QString localdir = QDir::homePath()+"/.lumina/themes/";
+ if(!QFile::exists(localdir)){ QDir dir(); dir.mkpath(localdir); }
+ return LUtils::writeFile(localdir+name+".qss.template", contents, true);
+}
+
+bool LTHEME::saveLocalColors(QString name, QStringList contents){
+ QString localdir = QDir::homePath()+"/.lumina/colors/";
+ if(!QFile::exists(localdir)){ QDir dir(); dir.mkpath(localdir); }
+ return LUtils::writeFile(localdir+name+".qss.colors", contents, true);
+}
+
+//Return the currently selected Theme/Colors/Icons
+QStringList LTHEME::currentSettings(){ //returns [theme path, colorspath, iconsname, font, fontsize]
+ QStringList out; out << "" << "" << "" << "" << "";
QStringList settings = LUtils::readFile(QDir::homePath()+"/.lumina/themesettings.cfg");
for(int i=0; i<settings.length(); i++){
if(settings[i].startsWith("THEMEFILE=")){ out[0] = settings[i].section("=",1,1).simplified(); }
else if(settings[i].startsWith("COLORFILE=")){ out[1] = settings[i].section("=",1,1).simplified(); }
+ else if(settings[i].startsWith("ICONTHEME=")){ out[2] = settings[i].section("=",1,1).simplified(); }
+ else if(settings[i].startsWith("FONTFAMILY=")){ out[3] = settings[i].section("=",1,1).simplified(); }
+ else if(settings[i].startsWith("FONTSIZE=")){ out[4] = settings[i].section("=",1,1).simplified(); }
}
- out[2] = QIcon::themeName();
bool nofile = settings.isEmpty();
- if(out[0].isEmpty()){ out[0] = LOS::LuminaShare()+"themes/SampleTheme.qss.template"; }
+ if(out[0].isEmpty()){ out[0] = LOS::LuminaShare()+"themes/Lumina-default.qss.template"; }
if(out[1].isEmpty()){ out[1] = LOS::LuminaShare()+"colors/SampleColors.qss.colors"; }
- if(nofile){ setCurrentSettings(out[0], out[1], out[2]); }
+ if(out[3].isEmpty()){ out[3] = QFont().defaultFamily(); }
+ if(out[4].isEmpty()){
+ int num = QFont().pointSize(); out[4] = QString::number(num)+"pt"; //Check point size first
+ if(num<0){ num = QFont().pixelSize(); out[4] = QString::number(num)+"px";} //Now check pixel size
+ if(num<0){ out[4] = "9pt"; } //Now hard-code a fallback (just in case)
+ }
+ if(nofile){ setCurrentSettings(out[0], out[1], out[2], out[3], out[4]); }
return out;
}
//Change the current Theme/Colors/Icons
-bool LTHEME::setCurrentSettings(QString themepath, QString colorpath, QString iconname){
+bool LTHEME::setCurrentSettings(QString themepath, QString colorpath, QString iconname, QString font, QString fontsize){
+ QIcon::setThemeName(iconname);
+ //Now save the theme settings file
QStringList contents;
contents << "THEMEFILE="+themepath;
contents << "COLORFILE="+colorpath;
contents << "ICONTHEME="+iconname;
+ contents << "FONTFAMILY="+font;
+ contents << "FONTSIZE="+fontsize;
bool ok = LUtils::writeFile(QDir::homePath()+"/.lumina/themesettings.cfg", contents, true);
- QIcon::setThemeName(iconname);
+
return ok;
}
//Return the complete stylesheet for a given theme/colors
-QString LTHEME::assembleStyleSheet(QString themepath, QString colorpath){
+QString LTHEME::assembleStyleSheet(QString themepath, QString colorpath, QString font, QString fontsize){
QString stylesheet = LUtils::readFile(themepath).join("\n");
QStringList colors = LUtils::readFile(colorpath);
//qDebug() << "Found Theme:" << themepath << stylesheet;
@@ -126,6 +156,8 @@ QString LTHEME::assembleStyleSheet(QString themepath, QString colorpath){
else if(colors[i].startsWith("TEXTCOLOR=")){ stylesheet = stylesheet.replace("%%TEXTCOLOR%%", colors[i].section("=",1,1).simplified()); }
else if(colors[i].startsWith("TEXTHIGHLIGHTCOLOR=")){ stylesheet = stylesheet.replace("%%TEXTHIGHLIGHTCOLOR%%", colors[i].section("=",1,1).simplified()); }
}
+ stylesheet = stylesheet.replace("%%FONT%%", font);
+ stylesheet = stylesheet.replace("%%FONTSIZE%%", fontsize);
//qDebug() << "Assembled Style Sheet:\n" << stylesheet;
return stylesheet;
}
@@ -135,9 +167,15 @@ QString LTHEME::assembleStyleSheet(QString themepath, QString colorpath){
//==================
LuminaThemeEngine::LuminaThemeEngine(QApplication *app){
application=app; //save this pointer for later
+ //Make sure to prefer font antialiasing on the application
+ QFont tmp = application->font();
+ tmp.setStyleStrategy(QFont::PreferAntialias);
+ application->setFont(tmp);
+ // Now load the theme stylesheet
QStringList current = LTHEME::currentSettings();
- theme = current[0]; colors=current[1]; icons=current[2];
- application->setStyleSheet( LTHEME::assembleStyleSheet(theme, colors) );
+ theme = current[0]; colors=current[1]; icons=current[2]; font=current[3]; fontsize=current[4];
+ application->setStyleSheet( LTHEME::assembleStyleSheet(theme, colors, font, fontsize) );
+ QIcon::setThemeName(icons); //make sure this sets set within this environment
watcher = new QFileSystemWatcher(this);
watcher->addPath( QDir::homePath()+"/.lumina/themesettings.cfg" );
connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT(watcherChange()) );
@@ -149,12 +187,13 @@ LuminaThemeEngine::~LuminaThemeEngine(){
void LuminaThemeEngine::watcherChange(){
QStringList current = LTHEME::currentSettings();
- if(theme!=current[0] || colors!=current[1]){
- application->setStyleSheet( LTHEME::assembleStyleSheet(current[0], current[1]) );
+ if(theme!=current[0] || colors!=current[1] || font!=current[3] || fontsize!=current[4]){
+ application->setStyleSheet( LTHEME::assembleStyleSheet(current[0], current[1], current[3], current[4]) );
}
- if(icons!=current[3]){
+ if(icons!=current[2]){
+ QIcon::setThemeName(current[2]); //make sure this sets set within this environment
emit updateIcons();
}
//Now save this for later checking
- theme = current[0]; colors=current[1]; icons=current[2];
+ theme = current[0]; colors=current[1]; icons=current[2]; font=current[3]; fontsize=current[4];
}
bgstack15