aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libLumina/LuminaThemes.cpp117
-rw-r--r--libLumina/LuminaThemes.h17
-rw-r--r--lumina-config/mainUI.cpp26
-rw-r--r--lumina-config/mainUI.h1
-rw-r--r--lumina-config/mainUI.ui53
5 files changed, 196 insertions, 18 deletions
diff --git a/libLumina/LuminaThemes.cpp b/libLumina/LuminaThemes.cpp
index e4c13ae7..cf31e5fd 100644
--- a/libLumina/LuminaThemes.cpp
+++ b/libLumina/LuminaThemes.cpp
@@ -1,6 +1,6 @@
//===========================================
// Lumina-DE source code
-// Copyright (c) 2014, Ken Moore
+// Copyright (c) 2014-2015, Ken Moore
// Available under the 3-clause BSD license
// See the LICENSE file for full details
//===========================================
@@ -13,6 +13,10 @@
#include <QDebug>
#include <QObject>
+//Stuff necesary for Qt Cursor Reloads
+//#include "qxcbcursor.h" //needed to prod Qt to refresh the mouse cursor theme
+//#include <QCursor>
+
QStringList LTHEME::availableSystemThemes(){
//returns: [name::::path] for each item
QDir dir(LOS::LuminaShare()+"themes");
@@ -82,6 +86,22 @@ QStringList LTHEME::availableSystemIcons(){ //returns: [name] for each item
return themes;
}
+QStringList LTHEME::availableSystemCursors(){ //returns: [name] for each item
+ QStringList paths; paths << LOS::SysPrefix()+"lib/X11/icons/" << LOS::AppPrefix()+"lib/X11/icons/";
+ QStringList out;
+ for(int i=0; i<paths.length(); i++){
+ if( !QFile::exists(paths[i]) ){ continue; }
+ QDir dir(paths[i]);
+ QStringList tmp = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
+ for(int j=0; j<tmp.length(); j++){
+ if(QFile::exists(paths[i]+tmp[j]+"/cursors")){
+ out << tmp[j]; //good theme - save it to the output list
+ }
+ }
+ }
+ return out;
+}
+
//Save a new theme/color file
bool LTHEME::saveLocalTheme(QString name, QStringList contents){
QString localdir = QDir::homePath()+"/.lumina/themes/";
@@ -119,7 +139,25 @@ QStringList LTHEME::currentSettings(){ //returns [theme path, colorspath, iconsn
return out;
}
-
+
+//Return the currently-selected Cursor theme
+QString LTHEME::currentCursor(){
+ //qDebug() << "Reading Current Cursor Theme:";
+ QStringList info = LUtils::readFile(QDir::homePath()+"/.icons/default/index.theme");
+ if(info.isEmpty()){ return ""; }
+ QString cursor;
+ bool insection = false;
+ for(int i=0; i<info.length(); i++){
+ if(info[i]=="[Icon Theme]"){ insection = true; continue;}
+ else if(insection && info[i].startsWith("Inherits=")){
+ cursor = info[i].section("=",1,1).simplified();
+ break;
+ }
+ }
+ //qDebug() << " - found theme:" << cursor;
+ return cursor;
+}
+
//Change the current Theme/Colors/Icons
bool LTHEME::setCurrentSettings(QString themepath, QString colorpath, QString iconname, QString font, QString fontsize){
QIcon::setThemeName(iconname);
@@ -134,7 +172,37 @@ bool LTHEME::setCurrentSettings(QString themepath, QString colorpath, QString ic
return ok;
}
-
+
+//Change the current Cursor Theme
+bool LTHEME::setCursorTheme(QString cursorname){
+//qDebug() << "Set Cursor Theme:" << cursorname;
+ QStringList info = LUtils::readFile(QDir::homePath()+"/.icons/default/index.theme");
+ bool insection = false;
+ bool changed = false;
+ QString newval = "Inherits="+cursorname;
+ for(int i=0; i<info.length() && !changed; i++){
+ if(info[i]=="[Icon Theme]"){
+ insection = true;
+ }else if( info[i].startsWith("[") && insection){
+ //Section does not have the setting - add it
+ info.insert(i, newval);
+ changed =true;
+ }else if( info[i].startsWith("[") ){
+ insection = false;
+ }else if(insection && info[i].startsWith("Inherits=")){
+ info[i] = newval; //replace the current setting
+ changed = true;
+ }
+ } //end loop over file contents
+ if(!changed){ //Could not change the file contents for some reason
+ if(insection){ info << newval; } //end of file while in the section
+ else{ info << "[Icon Theme]" << newval; } //entire section missing from file
+ }
+ //Now save the file
+ //qDebug() << "Done saving the cursor:" << info;
+ return LUtils::writeFile(QDir::homePath()+"/.icons/default/index.theme", info, true);
+}
+
//Return the complete stylesheet for a given theme/colors
QString LTHEME::assembleStyleSheet(QString themepath, QString colorpath, QString font, QString fontsize){
QString stylesheet = LUtils::readFile(themepath).join("\n");
@@ -162,6 +230,25 @@ QString LTHEME::assembleStyleSheet(QString themepath, QString colorpath, QString
//qDebug() << "Assembled Style Sheet:\n" << stylesheet;
return stylesheet;
}
+// Extra information about a cursor theme
+QStringList LTHEME::cursorInformation(QString name){
+ //returns: [Name, Comment, Sample Image File]
+ QStringList out; out << "" << "" << ""; //ensure consistent output structure
+ QStringList paths; paths << LOS::SysPrefix()+"lib/X11/icons/" << LOS::AppPrefix()+"lib/X11/icons/";
+ for(int i=0; i<paths.length(); i++){
+ if(QFile::exists(paths[i]+name)){
+ if(QFile::exists(paths[i]+name+"/cursors/arrow")){ out[2] = paths[i]+name+"/cursors/arrow"; }
+ QStringList info = LUtils::readFile(paths[i]+name+"/index.theme");
+ for(int j=info.indexOf("[Icon Theme]"); j<info.length(); j++){
+ if(j<0){continue; } //just in case the index function errors out
+ if(info[j].startsWith("Name") && info[j].contains("=")){ out[0] = info[j].section("=",1,1).simplified(); }
+ else if(info[j].startsWith("Comment") && info[j].contains("=")){ out[1] = info[j].section("=",1,1).simplified(); }
+ }
+ break; //found the cursor
+ }
+ }
+ return out;
+}
//==================
// THEME ENGINE CLASS
@@ -175,14 +262,19 @@ LuminaThemeEngine::LuminaThemeEngine(QApplication *app){
// Now load the theme stylesheet
QStringList current = LTHEME::currentSettings();
theme = current[0]; colors=current[1]; icons=current[2]; font=current[3]; fontsize=current[4];
+ cursors = LTHEME::currentCursor();
application->setStyleSheet( LTHEME::assembleStyleSheet(theme, colors, font, fontsize) );
QIcon::setThemeName(icons); //make sure this sets set within this environment
syncTimer = new QTimer(this);
syncTimer->setSingleShot(true);
syncTimer->setInterval(500); //wait 1/2 second before re-loading the files
+ if(cursors.isEmpty()){
+ LTHEME::setCursorTheme("default"); //X11 fallback (always installed?)
+ cursors = "default";
+ }
watcher = new QFileSystemWatcher(this);
watcher->addPath( QDir::homePath()+"/.lumina/themesettings.cfg" );
- watcher->addPaths( QStringList() << theme << colors ); //also watch these files for changes
+ watcher->addPaths( QStringList() << theme << colors << QDir::homePath()+"/.icons/default/index.theme" ); //also watch these files for changes
connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT(watcherChange()) );
connect(syncTimer, SIGNAL(timeout()), this, SLOT(reloadFiles()) );
}
@@ -204,8 +296,21 @@ void LuminaThemeEngine::reloadFiles(){
QIcon::setThemeName(current[2]); //make sure this sets set within this environment
emit updateIcons();
}
+ QString ccurs = LTHEME::currentCursor();
+ if(cursors != ccurs){
+ emit updateCursors();
+ //Might be something we can do automatically here as well - since we have the QApplication handy
+ // - Note: setting/unsetting an override cursor does not update the current cursor bitmap
+ // Qt created a background database/hash/mapping of the theme pixmaps on startup
+ // So Qt itself needs to be prodded to update that mapping
+ /*QXcbCursor::cursorThemePropertyChanged( \
+ new QXcbVirtualDesktop(QX11Info::connection(), application->screen()->handle(), QX11Info::appScreen()),
+ ccurs.toData(), QVariant("Inherits"), NULL);*/
+
+ }
//Now save this for later checking
- watcher->removePaths( QStringList() << theme << colors );
+ watcher->removePaths( QStringList() << theme << colors << QDir::homePath()+"/.icons/default/index.theme");
theme = current[0]; colors=current[1]; icons=current[2]; font=current[3]; fontsize=current[4];
- watcher->addPaths( QStringList() << theme << colors );
+ cursors = ccurs;
+ watcher->addPaths( QStringList() << theme << colors << QDir::homePath()+"/.icons/default/index.theme");
}
diff --git a/libLumina/LuminaThemes.h b/libLumina/LuminaThemes.h
index 9b5ad5bc..3767eb7a 100644
--- a/libLumina/LuminaThemes.h
+++ b/libLumina/LuminaThemes.h
@@ -1,6 +1,6 @@
//===========================================
// Lumina-DE source code
-// Copyright (c) 2014, Ken Moore
+// Copyright (c) 2014-2015, Ken Moore
// Available under the 3-clause BSD license
// See the LICENSE file for full details
//===========================================
@@ -26,20 +26,26 @@ public:
static QStringList availableSystemColors(); //returns: [name::::path] for each item
static QStringList availableLocalColors(); //returns: [name::::path] for each item
static QStringList availableSystemIcons(); //returns: [name] for each item
-
+ static QStringList availableSystemCursors(); //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, font, fontsize]
+ static QString currentCursor(); //returns: current cursor theme name
//Change the current Theme/Colors/Icons
static bool setCurrentSettings(QString themepath, QString colorpath, QString iconname, QString font, QString fontsize);
-
+ static bool setCursorTheme(QString cursorname);
+
//Return the complete stylesheet for a given theme/colors
static QString assembleStyleSheet(QString themepath, QString colorpath, QString font, QString fontsize);
+ //Additional info for a cursor theme
+ static QStringList cursorInformation(QString name); //returns: [Name, Comment, Sample Image File]
+
};
@@ -63,7 +69,7 @@ public:
private:
QApplication *application;
QFileSystemWatcher *watcher;
- QString theme,colors,icons, font, fontsize; //current settings
+ QString theme,colors,icons, font, fontsize, cursors; //current settings
QTimer *syncTimer;
private slots:
@@ -72,6 +78,7 @@ private slots:
signals:
void updateIcons();
+ void updateCursors();
};
diff --git a/lumina-config/mainUI.cpp b/lumina-config/mainUI.cpp
index 5b111cf1..6bd6ba07 100644
--- a/lumina-config/mainUI.cpp
+++ b/lumina-config/mainUI.cpp
@@ -181,6 +181,7 @@ void MainUI::setupConnections(){
connect(ui->combo_session_wfocus, SIGNAL(currentIndexChanged(int)), this, SLOT(sessionoptchanged()) );
connect(ui->combo_session_wloc, SIGNAL(currentIndexChanged(int)), this, SLOT(sessionoptchanged()) );
connect(ui->combo_session_wtheme, SIGNAL(currentIndexChanged(int)), this, SLOT(sessionthemechanged()) );
+ connect(ui->combo_session_cursortheme, SIGNAL(currentIndexChanged(int)), this, SLOT(sessionCursorChanged()) );
connect(ui->check_session_numlock, SIGNAL(stateChanged(int)), this, SLOT(sessionoptchanged()) );
connect(ui->check_session_playloginaudio, SIGNAL(stateChanged(int)), this, SLOT(sessionoptchanged()) );
connect(ui->check_session_playlogoutaudio, SIGNAL(stateChanged(int)), this, SLOT(sessionoptchanged()) );
@@ -238,6 +239,12 @@ void MainUI::setupMenus(){
ui->combo_session_datetimeorder->addItem( tr("Time first then Date"), "timedate");
ui->combo_session_datetimeorder->addItem( tr("Date first then Time"), "datetime");
+ //Available Cursor Themes
+ ui->combo_session_cursortheme->clear();
+ ui->combo_session_cursortheme->addItems( LTHEME::availableSystemCursors() );
+ //int cur = ui->combo_session_cursortheme->findText( LTHEME::currentCursor() );
+ //if(cur>=0){ ui->combo_session_cursortheme->setCurrentIndex(cur); }
+
//Available Time zones
ui->combo_session_timezone->clear();
QList<QByteArray> TZList = QTimeZone::availableTimeZoneIds();
@@ -1664,9 +1671,13 @@ void MainUI::loadSessionSettings(){
// - Font Size
ui->spin_session_fontsize->setValue( current[4].section("p",0,0).toInt() );
+ int cur = ui->combo_session_cursortheme->findText( LTHEME::currentCursor() );
+ if(cur>=0){ ui->combo_session_cursortheme->setCurrentIndex(cur); }
+
//sessionstartchanged(); //make sure to update buttons
sessionLoadTimeSample();
sessionLoadDateSample();
+ sessionCursorChanged();
}
void MainUI::saveSessionSettings(){
@@ -1771,7 +1782,6 @@ void MainUI::saveSessionSettings(){
sessionsettings->setValue("InitLocale/LC_CTYPE", ui->combo_locale_ctype->currentData().toString() );
-
//Now do the theme options
QString themefile = ui->combo_session_themefile->itemData( ui->combo_session_themefile->currentIndex() ).toString();
QString colorfile = ui->combo_session_colorfile->itemData( ui->combo_session_colorfile->currentIndex() ).toString();
@@ -1780,6 +1790,7 @@ void MainUI::saveSessionSettings(){
QString fontsize = QString::number(ui->spin_session_fontsize->value())+"pt";
//qDebug() << "Saving theme options:" << themefile << colorfile << iconset << font << fontsize;
LTHEME::setCurrentSettings( themefile, colorfile, iconset, font, fontsize);
+ LTHEME::setCursorTheme(ui->combo_session_cursortheme->currentText());
if(newstartapps){ loadSessionSettings(); } //make sure to re-load the session settings to catch the new files
}
@@ -1853,6 +1864,18 @@ void MainUI::sessionthemechanged(){
sessionoptchanged();
}
+void MainUI::sessionCursorChanged(){
+ //Update the Cursor Theme preview
+ QStringList info = LTHEME::cursorInformation(ui->combo_session_cursortheme->currentText());
+ // - info format: [name, comment. sample file]
+ qDebug() << "Cursor Information:" << ui->combo_session_cursortheme->currentText() << info;
+ QPixmap img(info[2]);
+ qDebug() << "Image Data:" << img.isNull() << img.size();
+ ui->label_cursor_sample->setPixmap( img.scaledToHeight(ui->label_cursor_sample->height(), Qt::SmoothTransformation) );
+ ui->label_cursor_sample->setToolTip(info[1]);
+ ui->combo_session_cursortheme->setToolTip(info[1]);
+ sessionoptchanged();
+}
/*void MainUI::sessionstartchanged(){
ui->tool_session_rmapp->setEnabled( ui->list_session_start->currentRow()>=0 );
}*/
@@ -2006,4 +2029,3 @@ void MainUI::sessionShowDateCodes(){
msg << tr("Text may be contained within single-quotes to ignore replacements");
QMessageBox::information(this, tr("Date Codes"), msg.join("\n") );
}
-
diff --git a/lumina-config/mainUI.h b/lumina-config/mainUI.h
index ee5b5feb..1810c7b6 100644
--- a/lumina-config/mainUI.h
+++ b/lumina-config/mainUI.h
@@ -151,6 +151,7 @@ private slots:
void addsessionstartfile();
void sessionoptchanged();
void sessionthemechanged();
+ void sessionCursorChanged();
//void sessionstartchanged();
void sessionEditColor();
void sessionEditTheme();
diff --git a/lumina-config/mainUI.ui b/lumina-config/mainUI.ui
index eee44aa5..aa7024d3 100644
--- a/lumina-config/mainUI.ui
+++ b/lumina-config/mainUI.ui
@@ -109,7 +109,7 @@
<enum>QFrame::StyledPanel</enum>
</property>
<property name="currentIndex">
- <number>4</number>
+ <number>0</number>
</property>
<widget class="QWidget" name="page_desktop">
<layout class="QVBoxLayout" name="verticalLayout_3">
@@ -370,6 +370,49 @@
<item row="4" column="1">
<widget class="QComboBox" name="combo_session_icontheme"/>
</item>
+ <item row="5" column="0">
+ <widget class="QLabel" name="label_31">
+ <property name="text">
+ <string>Mouse Cursors:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="1">
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="QComboBox" name="combo_session_cursortheme">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_cursor_sample">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="toolTip">
+ <string notr="true"/>
+ </property>
+ <property name="text">
+ <string notr="true"/>
+ </property>
+ <property name="scaledContents">
+ <bool>true</bool>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
</layout>
</widget>
</widget>
@@ -570,8 +613,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>27</width>
- <height>16</height>
+ <width>98</width>
+ <height>28</height>
</rect>
</property>
</widget>
@@ -1447,8 +1490,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>518</width>
- <height>139</height>
+ <width>117</width>
+ <height>28</height>
</rect>
</property>
<property name="sizePolicy">
bgstack15