aboutsummaryrefslogtreecommitdiff
path: root/libLumina
diff options
context:
space:
mode:
Diffstat (limited to 'libLumina')
-rw-r--r--libLumina/LuminaThemes.cpp74
-rw-r--r--libLumina/LuminaThemes.h12
-rw-r--r--libLumina/LuminaUtils.cpp4
-rw-r--r--libLumina/colors/SampleColors.qss.colors1
-rw-r--r--libLumina/libLumina.pro2
-rw-r--r--libLumina/themes/SampleTheme.qss.template64
6 files changed, 69 insertions, 88 deletions
diff --git a/libLumina/LuminaThemes.cpp b/libLumina/LuminaThemes.cpp
index 5100a084..0b328502 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;
@@ -124,8 +154,11 @@ QString LTHEME::assembleStyleSheet(QString themepath, QString colorpath){
else if(colors[i].startsWith("BASECOLOR=")){ stylesheet = stylesheet.replace("%%BASECOLOR%%", colors[i].section("=",1,1).simplified()); }
else if(colors[i].startsWith("ALTBASECOLOR=")){ stylesheet = stylesheet.replace("%%ALTBASECOLOR%%", colors[i].section("=",1,1).simplified()); }
else if(colors[i].startsWith("TEXTCOLOR=")){ stylesheet = stylesheet.replace("%%TEXTCOLOR%%", colors[i].section("=",1,1).simplified()); }
+ else if(colors[i].startsWith("TEXTDISABLECOLOR=")){ stylesheet = stylesheet.replace("%%TEXTDISABLECOLOR%%", 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 +168,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 +188,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];
}
diff --git a/libLumina/LuminaThemes.h b/libLumina/LuminaThemes.h
index 1026622b..e4bbd208 100644
--- a/libLumina/LuminaThemes.h
+++ b/libLumina/LuminaThemes.h
@@ -26,14 +26,18 @@ public:
static QStringList availableLocalColors(); //returns: [name::::path] for each item
static QStringList availableSystemIcons(); //returns: [name] for each item
+ //Save a new theme/color file
+ static bool saveLocalTheme(QString name, QStringList contents);
+ static bool saveLocalColors(QString name, QStringList contents);
+
//Return the currently selected Theme/Colors/Icons
- static QStringList currentSettings(); //returns [theme path, colorspath, iconsname]
+ static QStringList currentSettings(); //returns [theme path, colorspath, iconsname, font, fontsize]
//Change the current Theme/Colors/Icons
- static bool setCurrentSettings(QString themepath, QString colorpath, QString iconname);
+ static bool setCurrentSettings(QString themepath, QString colorpath, QString iconname, QString font, QString fontsize);
//Return the complete stylesheet for a given theme/colors
- static QString assembleStyleSheet(QString themepath, QString colorpath);
+ static QString assembleStyleSheet(QString themepath, QString colorpath, QString font, QString fontsize);
};
@@ -58,7 +62,7 @@ public:
private:
QApplication *application;
QFileSystemWatcher *watcher;
- QString theme,colors,icons; //current settings
+ QString theme,colors,icons, font, fontsize; //current settings
private slots:
void watcherChange();
diff --git a/libLumina/LuminaUtils.cpp b/libLumina/LuminaUtils.cpp
index 46c2e26c..6f91082c 100644
--- a/libLumina/LuminaUtils.cpp
+++ b/libLumina/LuminaUtils.cpp
@@ -54,9 +54,9 @@ QStringList LUtils::readFile(QString filepath){
bool LUtils::writeFile(QString filepath, QStringList contents, bool overwrite){
QFile file(filepath);
- QFile::OpenMode mode = overwrite ? (QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate) : (QIODevice::WriteOnly | QIODevice::Text);
+ if(file.exists() && !overwrite){ return false; }
bool ok = false;
- if(file.open( mode ) ){
+ if( file.open(QIODevice::WriteOnly | QIODevice::Truncate) ){
QTextStream out(&file);
out << contents.join("\n");
file.close();
diff --git a/libLumina/colors/SampleColors.qss.colors b/libLumina/colors/SampleColors.qss.colors
index fa770fa2..19f27ff5 100644
--- a/libLumina/colors/SampleColors.qss.colors
+++ b/libLumina/colors/SampleColors.qss.colors
@@ -9,4 +9,5 @@ ACCENTDISABLECOLOR=#f5f0e7
BASECOLOR=#f4f0e8
ALTBASECOLOR=white
TEXTCOLOR=black
+TEXTDISABLECOLOR=grey
TEXTHIGHLIGHTCOLOR=black \ No newline at end of file
diff --git a/libLumina/libLumina.pro b/libLumina/libLumina.pro
index 97ebb799..cb89e7ca 100644
--- a/libLumina/libLumina.pro
+++ b/libLumina/libLumina.pro
@@ -52,7 +52,7 @@ colors.path=$$PREFIX/share/Lumina-DE/colors/
colors.files=colors/SampleColors.qss.colors
themes.path=$$PREFIX/share/Lumina-DE/themes/
-themes.files=themes/SampleTheme.qss.template
+themes.files=themes/Lumina-default.qss.template
INSTALLS += target include colors themes
diff --git a/libLumina/themes/SampleTheme.qss.template b/libLumina/themes/SampleTheme.qss.template
deleted file mode 100644
index b60fbf5a..00000000
--- a/libLumina/themes/SampleTheme.qss.template
+++ /dev/null
@@ -1,64 +0,0 @@
-QWidget{ color: %%TEXTCOLOR%%; }
-QWidget#page_browser,#page_audioPlayer,#page_zfs,#page_image_view{background:
-qradialgradient(cx: 0.5, cy: -1.8, fx: 0.5, fy: 0, radius: 2,
-stop: 0 %%ACCENTCOLOR%%,
-stop: 1 %%PRIMARYCOLOR%%);
-}
-QMainWindow, QMenu{ background: %%BASECOLOR%%; }
-QMenuBar, QMenuBar::item, QToolBar{ background: transparent; }
-QMenuBar::item:selected, QMenuBar::item:pressed, QMenu::item:selected{ background: qradialgradient(cx: 0.5, cy: -1.8, fx: 0.5, fy: 0, radius: 2,
-stop: 0 %%ACCENTCOLOR%%,
-stop: 1 %%HIGHLIGHTCOLOR%%);
-color: %%TEXTHIGHLIGHTCOLOR%%;
-}
-QMenu::item{ background: transparent; border: none; color: %%TEXTCOLOR%%; padding: 2px 25px 2px 20px;}
-QMenu::indicator{ width: 14px; height: 14px; }
-
- QMenu::indicator:non-exclusive:unchecked {
- image: url(:/trolltech/styles/commonstyle/images/standardbutton-no-16.png);
- }
-
- QMenu::indicator:non-exclusive:unchecked:selected {
- image: url(:/trolltech/styles/commonstyle/images/standardbutton-no-16.png);
- }
-
- QMenu::indicator:non-exclusive:checked {
- image: url(:/trolltech/styles/commonstyle/images/standardbutton-yes-16.png);
- }
-
- QMenu::indicator:non-exclusive:checked:selected {
- image: url(:/trolltech/styles/commonstyle/images/standardbutton-yes-16.png);
- }
-
- QTabBar::tab {
- background: qradialgradient(cx: 0.5, cy: -1.8, fx: 0.5, fy: 0, radius: 2,
-stop: 0 %%SECONDARYDISABLECOLOR%%,
-stop: 1 %%SECONDARYCOLOR%%);
- border-top-left-radius: 4px;
- border-top-right-radius: 4px;
- min-width: 8ex;
- padding: 2px;
- }
-
- QTabBar::tab:selected{
- background: qradialgradient(cx: 0.5, cy: -1.8, fx: 0.5, fy: 0, radius: 2,
-stop: 0 %%ACCENTDISABLECOLOR%%,
-stop: 1 %%HIGHLIGHTCOLOR%%);
- }
-QTabBar::tab:hover {
- background: qradialgradient(cx: 0.5, cy: -1.8, fx: 0.5, fy: 0, radius: 2,
-stop: 0 %%ACCENTDISABLECOLOR%%,
-stop: 1 %%HIGHLIGHTDISABLECOLOR%%);
- }
-
- QTabBar::tab:!selected {
- margin-top: 2px; /* make non-selected tabs look smaller */
- }
-
-QToolTip{
- background: %%BASECOLOR%%;
- border: 1px solid %%PRIMARYDISABLECOLOR%%;
- border-radius: 2px;
- padding: 1px;
- color: %%TEXTCOLOR%%;
-} \ No newline at end of file
bgstack15