aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/core-utils/lumina-config/pages/page_theme.cpp
blob: 52579ec2a7a9182cf49bceddfc98a4f4d98ac087 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
//===========================================
//  Lumina-DE source code
//  Copyright (c) 2016, Ken Moore
//  Available under the 3-clause BSD license
//  See the LICENSE file for full details
//===========================================
#include "page_theme.h"
#include "ui_page_theme.h"

#include "../ColorDialog.h"
#include "../ThemeDialog.h"
//==========
//    PUBLIC
//==========
page_theme::page_theme(QWidget *parent) : PageWidget(parent), ui(new Ui::page_theme()){
  ui->setupUi(this);
  findQt5Themes();
  loading = false;
  PINFO = new LPlugins(); //load the info class
  connect(ui->spin_session_fontsize, SIGNAL(valueChanged(int)), this, SLOT(settingsChanged()) );
  connect(ui->combo_session_themefile, SIGNAL(currentIndexChanged(int)), this, SLOT(settingsChanged()) );
  connect(ui->combo_session_colorfile, SIGNAL(currentIndexChanged(int)), this, SLOT(settingsChanged()) );
  connect(ui->combo_session_icontheme, SIGNAL(currentIndexChanged(int)), this, SLOT(settingsChanged()) );
  connect(ui->font_session_theme, SIGNAL(currentIndexChanged(int)), this, SLOT(settingsChanged()) );
  connect(ui->tool_session_newcolor, SIGNAL(clicked()), this, SLOT(sessionEditColor()) );
  connect(ui->tool_session_newtheme, SIGNAL(clicked()), this, SLOT(sessionEditTheme()) );
  connect(ui->combo_session_cursortheme, SIGNAL(currentIndexChanged(int)), this, SLOT(settingsChanged()) );
  connect(ui->combo_qt5_theme, SIGNAL(currentIndexChanged(int)), this, SLOT(checkQt5Theme()) );
  updateIcons();
}

page_theme::~page_theme(){

}

//================
//    PUBLIC SLOTS
//================
void page_theme::SaveSettings(){
  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();
  QString iconset = ui->combo_session_icontheme->currentText();
  QString font = ui->font_session_theme->currentFont().family();
  QString fontsize = QString::number(ui->spin_session_fontsize->value())+"pt";
  QString qt5theme = ui->combo_qt5_theme->currentData().toString();
   if(qt5theme=="internal_custom"){ qt5theme = ui->line_qt5_custom_theme->text(); }
   QSettings sessionsettings("lumina-desktop","sessionsettings");
    sessionsettings.setValue("Qt5_theme_engine", qt5theme);

  //qDebug() << "Saving theme options:" << themefile << colorfile << iconset << font << fontsize;
  LTHEME::setCurrentSettings( themefile, colorfile, iconset, font, fontsize);
  LTHEME::setCursorTheme(ui->combo_session_cursortheme->currentText());
  emit HasPendingChanges(false);
}

void page_theme::LoadSettings(int){
  emit HasPendingChanges(false);
  emit ChangePageTitle( tr("Theme Settings") );

  loading = true;
  //Load the available settings
  ui->combo_session_cursortheme->clear();
  ui->combo_session_cursortheme->addItems( LTHEME::availableSystemCursors() );

ui->combo_session_themefile->clear();
  ui->combo_session_colorfile->clear();
  ui->combo_session_icontheme->clear();
  QStringList current = LTHEME::currentSettings();
  // - local theme templates
  QStringList tmp = LTHEME::availableLocalThemes();
  tmp.sort();
  for(int i=0; i<tmp.length(); i++){ 
    ui->combo_session_themefile->addItem(tmp[i].section("::::",0,0)+" ("+tr("Local")+")", tmp[i].section("::::",1,1));
    if(tmp[i].section("::::",1,1)==current[0]){ ui->combo_session_themefile->setCurrentIndex(ui->combo_session_themefile->count()-1); }
  }
  // - system theme templates
  tmp = LTHEME::availableSystemThemes();
  tmp.sort();
  for(int i=0; i<tmp.length(); i++){ 
    ui->combo_session_themefile->addItem(tmp[i].section("::::",0,0)+" ("+tr("System")+")", tmp[i].section("::::",1,1));
    if(tmp[i].section("::::",1,1)==current[0]){ ui->combo_session_themefile->setCurrentIndex(ui->combo_session_themefile->count()-1); }
  }
  // - local color schemes
  tmp = LTHEME::availableLocalColors();
  tmp.sort();
  for(int i=0; i<tmp.length(); i++){ 
    ui->combo_session_colorfile->addItem(tmp[i].section("::::",0,0)+" ("+tr("Local")+")", tmp[i].section("::::",1,1));
    if(tmp[i].section("::::",1,1)==current[1]){ ui->combo_session_colorfile->setCurrentIndex(ui->combo_session_colorfile->count()-1); }
  }
  // - system color schemes
  tmp = LTHEME::availableSystemColors();
  tmp.sort();
  for(int i=0; i<tmp.length(); i++){ 
    ui->combo_session_colorfile->addItem(tmp[i].section("::::",0,0)+" ("+tr("System")+")", tmp[i].section("::::",1,1));
    if(tmp[i].section("::::",1,1)==current[1]){ ui->combo_session_colorfile->setCurrentIndex(ui->combo_session_colorfile->count()-1); }
  }
  // - icon themes
  tmp = LTHEME::availableSystemIcons();
  tmp.sort();
  for(int i=0; i<tmp.length(); i++){ 
    ui->combo_session_icontheme->addItem(tmp[i]);
    if(tmp[i]==current[2]){ ui->combo_session_icontheme->setCurrentIndex(i); }
  }
  // - Font
  ui->font_session_theme->setCurrentFont( QFont(current[3]) );
  // - 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); }

   QSettings sessionsettings("lumina-desktop","sessionsettings");
    QString qt5theme = sessionsettings.value("Qt5_theme_engine", "").toString();
  int index = ui->combo_qt5_theme->findData(qt5theme);
  if(index <0){ 
    ui->line_qt5_custom_theme->setText(qt5theme);
    index = ui->combo_qt5_theme->findData("internal_custom");
  }
  if(index>=0){ ui->combo_qt5_theme->setCurrentIndex(index); }
  checkQt5Theme(); //update item visibility
  QApplication::processEvents();
  loading = false;
}

void page_theme::updateIcons(){
  ui->tool_session_newtheme->setIcon( LXDG::findIcon("preferences-desktop-theme","") );
  ui->tool_session_newcolor->setIcon( LXDG::findIcon("preferences-desktop-color","") );
  ui->tabWidget->setTabIcon(0, LXDG::findIcon("user-desktop","desktop") );
  ui->tabWidget->setTabIcon(1, LXDG::findIcon("preferences-system-windows","") );
}

//=================
//       PRIVATE 
//=================
void page_theme::findQt5Themes(){
  ui->combo_qt5_theme->clear();
  ui->combo_qt5_theme->addItem( tr("None"), "");
  ui->combo_qt5_theme->addItem( tr("Manual Setting"), "internal_custom");
  //Now probe the system and list any themes that are found
  QStringList paths = QCoreApplication::libraryPaths();
  qDebug() << "Known Library Paths:" << paths;
  QStringList engines;
  for(int i=0; i<paths.length(); i++){
    if(QFile::exists(paths[i]+"/platformthemes")){
      QDir dir(paths[i]+"/platformthemes");
      QStringList libs = dir.entryList(QStringList("lib*.so*"), QDir::Files, QDir::NoSort) ;
      for(int j=0; j<libs.length(); j++){ engines << libs[j].section("lib",1,-1).section(".",0,-2).simplified(); }
    }
  }
  engines.sort();
  for(int i=0; i<engines.length(); i++){
    if(i==0){ ui->combo_qt5_theme->insertSeparator(2); }
    ui->combo_qt5_theme->addItem( engines[i], engines[i] );
  }
}
//=================
//    PRIVATE SLOTS
//=================
void page_theme::sessionEditColor(){
  //Get the current color file
  QString file = ui->combo_session_colorfile->itemData( ui->combo_session_colorfile->currentIndex() ).toString();
  //Open the color edit dialog
  ColorDialog dlg(this, PINFO, file);
  dlg.exec();
  //Check whether the file got saved/changed
  if(dlg.colorname.isEmpty() || dlg.colorpath.isEmpty() ){ return; } //cancelled
  //Reload the color list and activate the new color
  // - local color schemes
  ui->combo_session_colorfile->clear();
  QStringList tmp = LTHEME::availableLocalColors();
  tmp.sort();
  for(int i=0; i<tmp.length(); i++){ 
    ui->combo_session_colorfile->addItem(tmp[i].section("::::",0,0)+" ("+tr("Local")+")", tmp[i].section("::::",1,1));
    if(tmp[i].section("::::",1,1)==dlg.colorpath){ ui->combo_session_colorfile->setCurrentIndex(ui->combo_session_colorfile->count()-1); }
  }
  // - system color schemes
  tmp = LTHEME::availableSystemColors();
  tmp.sort();
  for(int i=0; i<tmp.length(); i++){ 
    ui->combo_session_colorfile->addItem(tmp[i].section("::::",0,0)+" ("+tr("System")+")", tmp[i].section("::::",1,1));
    if(tmp[i].section("::::",1,1)==dlg.colorpath){ ui->combo_session_colorfile->setCurrentIndex(ui->combo_session_colorfile->count()-1); }
  }
  emit HasPendingChanges(true);
}

void page_theme::sessionEditTheme(){
  QString file = ui->combo_session_themefile->itemData( ui->combo_session_themefile->currentIndex() ).toString();
  //Open the theme editor dialog
  ThemeDialog dlg(this, PINFO, file);
  dlg.exec();
  //Check for file change/save
  if(dlg.themename.isEmpty() || dlg.themepath.isEmpty()){ return; } //cancelled
  //Reload the theme list and activate the new theme
  ui->combo_session_themefile->clear();
  // - local theme templates
  QStringList tmp = LTHEME::availableLocalThemes();
  tmp.sort();
  for(int i=0; i<tmp.length(); i++){ 
    ui->combo_session_themefile->addItem(tmp[i].section("::::",0,0)+" ("+tr("Local")+")", tmp[i].section("::::",1,1));
    if(tmp[i].section("::::",1,1)==dlg.themepath){ ui->combo_session_themefile->setCurrentIndex(ui->combo_session_themefile->count()-1); }
  }
  // - system theme templates
  tmp = LTHEME::availableSystemThemes();
  tmp.sort();
  for(int i=0; i<tmp.length(); i++){ 
    ui->combo_session_themefile->addItem(tmp[i].section("::::",0,0)+" ("+tr("System")+")", tmp[i].section("::::",1,1));
    if(tmp[i].section("::::",1,1)==dlg.themepath){ ui->combo_session_themefile->setCurrentIndex(ui->combo_session_themefile->count()-1); }
  }
  emit HasPendingChanges(true);
}

void page_theme::checkQt5Theme(){
  ui->line_qt5_custom_theme->setVisible( ui->combo_qt5_theme->currentData().toString()=="internal_custom");
  settingsChanged();
}
bgstack15