aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/core/lumina-theme-engine/src/lthemeengine/appearancepage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src-qt5/core/lumina-theme-engine/src/lthemeengine/appearancepage.cpp')
-rw-r--r--src-qt5/core/lumina-theme-engine/src/lthemeengine/appearancepage.cpp210
1 files changed, 100 insertions, 110 deletions
diff --git a/src-qt5/core/lumina-theme-engine/src/lthemeengine/appearancepage.cpp b/src-qt5/core/lumina-theme-engine/src/lthemeengine/appearancepage.cpp
index 95f2c9b7..04ca6a0b 100644
--- a/src-qt5/core/lumina-theme-engine/src/lthemeengine/appearancepage.cpp
+++ b/src-qt5/core/lumina-theme-engine/src/lthemeengine/appearancepage.cpp
@@ -42,8 +42,7 @@ AppearancePage::AppearancePage(QWidget *parent) : TabPage(parent), m_ui(new Ui::
}
AppearancePage::~AppearancePage(){
- if(m_selectedStyle)
- delete m_selectedStyle;
+ if(m_selectedStyle){ delete m_selectedStyle; }
delete m_ui;
delete m_previewUi;
}
@@ -59,13 +58,11 @@ void AppearancePage::writeSettings(){
void AppearancePage::on_styleComboBox_activated(const QString &text){
QStyle *style = QStyleFactory::create(text);
- if(!style)
- return;
- setStyle(m_previewWidget, style);
- if(m_selectedStyle)
- delete m_selectedStyle;
- m_selectedStyle = style;
- updatePalette();
+ if(!style){ return; }
+ setStyle(m_previewWidget, style);
+ if(m_selectedStyle){ delete m_selectedStyle; }
+ m_selectedStyle = style;
+ updatePalette();
}
void AppearancePage::on_colorSchemeComboBox_activated(int){
@@ -75,94 +72,84 @@ void AppearancePage::on_colorSchemeComboBox_activated(int){
void AppearancePage::createColorScheme(){
QString name = QInputDialog::getText(this, tr("Enter Color Scheme Name"), tr("File name:"));
- if(name.isEmpty())
+ if(name.isEmpty()){ return; }
+ if(!name.endsWith(".conf", Qt::CaseInsensitive)){ name.append(".conf"); }
+ if(m_ui->colorSchemeComboBox->findText(name.section('.',0,0)) != -1){
+ QMessageBox::warning(this, tr("Error"), tr("The color scheme \"%1\" already exists").arg(name.section('.',0,0)));
return;
- if(!name.endsWith(".conf", Qt::CaseInsensitive))
- name.append(".conf");
- if(m_ui->colorSchemeComboBox->findText(name.section('.',0,0)) != -1){
- QMessageBox::warning(this, tr("Error"), tr("The color scheme \"%1\" already exists").arg(name.section('.',0,0)));
- return;
- }
- QString schemePath = lthemeengine::userColorSchemePath() + "/" + name;
- createColorScheme(schemePath, palette());
- m_ui->colorSchemeComboBox->addItem(name.section('.',0,0), schemePath);
+ }
+ QString schemePath = lthemeengine::userColorSchemePath() + "/" + name;
+ createColorScheme(schemePath, palette());
+ m_ui->colorSchemeComboBox->addItem(name.section('.',0,0), schemePath);
}
void AppearancePage::changeColorScheme(){
- if(m_ui->colorSchemeComboBox->currentIndex() < 0)
+ if(m_ui->colorSchemeComboBox->currentIndex() < 0){ return; }
+ if(!QFileInfo(m_ui->colorSchemeComboBox->currentData().toString()).isWritable()){
+ QMessageBox::information(this, tr("Warning"), tr("The color scheme \"%1\" is read only").arg(m_ui->colorSchemeComboBox->currentText()));
return;
- if(!QFileInfo(m_ui->colorSchemeComboBox->currentData().toString()).isWritable()){
- QMessageBox::information(this, tr("Warning"), tr("The color scheme \"%1\" is read only").arg(m_ui->colorSchemeComboBox->currentText()));
- return;
}
- PaletteEditDialog d(m_customPalette, m_selectedStyle, this);
- connect(&d, SIGNAL(paletteChanged(QPalette)), SLOT(setPreviewPalette(QPalette)));
- if(d.exec() == QDialog::Accepted){
- m_customPalette = d.selectedPalette();
- createColorScheme(m_ui->colorSchemeComboBox->currentData().toString(), m_customPalette);
+ PaletteEditDialog d(m_customPalette, m_selectedStyle, this);
+ connect(&d, SIGNAL(paletteChanged(QPalette)), SLOT(setPreviewPalette(QPalette)));
+ if(d.exec() == QDialog::Accepted){
+ m_customPalette = d.selectedPalette();
+ createColorScheme(m_ui->colorSchemeComboBox->currentData().toString(), m_customPalette);
}
- updatePalette();
+ updatePalette();
}
void AppearancePage::removeColorScheme(){
int index = m_ui->colorSchemeComboBox->currentIndex();
- if(index < 0 || m_ui->colorSchemeComboBox->count() <= 1)
+ if(index < 0 || m_ui->colorSchemeComboBox->count() <= 1){ return; }
+ if(!QFileInfo(m_ui->colorSchemeComboBox->currentData().toString()).isWritable()){
+ QMessageBox::information(this, tr("Warning"), tr("The color scheme \"%1\" is read only").arg(m_ui->colorSchemeComboBox->currentText()));
return;
- if(!QFileInfo(m_ui->colorSchemeComboBox->currentData().toString()).isWritable()){
- QMessageBox::information(this, tr("Warning"), tr("The color scheme \"%1\" is read only").arg(m_ui->colorSchemeComboBox->currentText()));
- return;
}
- int button = QMessageBox::question(this, tr("Confirm Remove"),tr("Are you sure you want to remove color scheme \"%1\"?").arg(m_ui->colorSchemeComboBox->currentText()), QMessageBox::Yes | QMessageBox::No);
- if(button != QMessageBox::Yes)
- return;
- if(QFile::remove(m_ui->colorSchemeComboBox->currentData().toString())){
- m_ui->colorSchemeComboBox->removeItem(index);
- on_colorSchemeComboBox_activated(0);
- }
+ int button = QMessageBox::question(this, tr("Confirm Remove"),tr("Are you sure you want to remove color scheme \"%1\"?").arg(m_ui->colorSchemeComboBox->currentText()), QMessageBox::Yes | QMessageBox::No);
+ if(button != QMessageBox::Yes){ return; }
+ if(QFile::remove(m_ui->colorSchemeComboBox->currentData().toString())){
+ m_ui->colorSchemeComboBox->removeItem(index);
+ on_colorSchemeComboBox_activated(0);
+ }
}
void AppearancePage::copyColorScheme(){
- if(m_ui->colorSchemeComboBox->currentIndex() < 0)
+ if(m_ui->colorSchemeComboBox->currentIndex() < 0) { return; }
+ QString name = QInputDialog::getText(this, tr("Enter Color Scheme Name"), tr("File name:"),QLineEdit::Normal, tr("%1 (copy)").arg(m_ui->colorSchemeComboBox->currentText()));
+ if(name.isEmpty() || name == m_ui->colorSchemeComboBox->currentText()){ return; }
+ if(!name.endsWith(".conf", Qt::CaseInsensitive)) { name.append(".conf"); }
+ if(m_ui->colorSchemeComboBox->findText(name.section('.',0,0)) != -1){
+ QMessageBox::warning(this, tr("Error"), tr("The color scheme \"%1\" already exists").arg(name.section('.',0,0)));
return;
- QString name = QInputDialog::getText(this, tr("Enter Color Scheme Name"), tr("File name:"),QLineEdit::Normal, tr("%1 (copy)").arg(m_ui->colorSchemeComboBox->currentText()));
- if(name.isEmpty() || name == m_ui->colorSchemeComboBox->currentText())
- return;
- if(!name.endsWith(".conf", Qt::CaseInsensitive))name.append(".conf");
- if(m_ui->colorSchemeComboBox->findText(name.section('.',0,0)) != -1){
- QMessageBox::warning(this, tr("Error"), tr("The color scheme \"%1\" already exists").arg(name.section('.',0,0)));
- return;
- }
- QString newPath = lthemeengine::userColorSchemePath() + "/" + name;
- QFile::copy(m_ui->colorSchemeComboBox->currentData().toString(), newPath);
- m_ui->colorSchemeComboBox->addItem(name.section('.',0,0), newPath);
+ }
+ QString newPath = lthemeengine::userColorSchemePath() + "/" + name;
+ QFile::copy(m_ui->colorSchemeComboBox->currentData().toString(), newPath);
+ m_ui->colorSchemeComboBox->addItem(name.section('.',0,0), newPath);
}
void AppearancePage::renameColorScheme(){
int index = m_ui->colorSchemeComboBox->currentIndex();
- if(index < 0)
- return;
- if(!QFileInfo(m_ui->colorSchemeComboBox->currentData().toString()).isWritable()){
- QMessageBox::information(this, tr("Warning"), tr("The color scheme \"%1\" is read only").arg(m_ui->colorSchemeComboBox->currentText()));
- return;
- }
- QString name = QInputDialog::getText(this, tr("Enter Color Scheme Name"), tr("File name:"), QLineEdit::Normal, m_ui->colorSchemeComboBox->currentText());
- if(name.isEmpty() || name == m_ui->colorSchemeComboBox->currentText())
- return;
- if(!name.endsWith(".conf", Qt::CaseInsensitive))name.append(".conf");
- if(m_ui->colorSchemeComboBox->findText(name.section('.',0,0)) != -1){
- QMessageBox::warning(this, tr("Error"), tr("The color scheme \"%1\" already exists").arg(name.section('.',0,0)));
- return;
- }
- QString newPath = lthemeengine::userColorSchemePath() + "/" + name;
- QFile::rename(m_ui->colorSchemeComboBox->currentData().toString(), newPath);
- m_ui->colorSchemeComboBox->setItemText(index, name.section('.',0,0));
- m_ui->colorSchemeComboBox->setItemData(index, newPath);
+ if(index < 0){ return; }
+ if(!QFileInfo(m_ui->colorSchemeComboBox->currentData().toString()).isWritable()){
+ QMessageBox::information(this, tr("Warning"), tr("The color scheme \"%1\" is read only").arg(m_ui->colorSchemeComboBox->currentText()));
+ return;
+ }
+ QString name = QInputDialog::getText(this, tr("Enter Color Scheme Name"), tr("File name:"), QLineEdit::Normal, m_ui->colorSchemeComboBox->currentText());
+ if(name.isEmpty() || name == m_ui->colorSchemeComboBox->currentText()){ return; }
+ if(!name.endsWith(".conf", Qt::CaseInsensitive)){ name.append(".conf"); }
+ if(m_ui->colorSchemeComboBox->findText(name.section('.',0,0)) != -1){
+ QMessageBox::warning(this, tr("Error"), tr("The color scheme \"%1\" already exists").arg(name.section('.',0,0)));
+ return;
+ }
+ QString newPath = lthemeengine::userColorSchemePath() + "/" + name;
+ QFile::rename(m_ui->colorSchemeComboBox->currentData().toString(), newPath);
+ m_ui->colorSchemeComboBox->setItemText(index, name.section('.',0,0));
+ m_ui->colorSchemeComboBox->setItemData(index, newPath);
}
void AppearancePage::updatePalette(){
- if(!m_selectedStyle)
- return;
- setPreviewPalette(m_ui->customPaletteButton->isChecked() ? m_customPalette : m_selectedStyle->standardPalette());
+ if(!m_selectedStyle){ return; }
+ setPreviewPalette(m_ui->customPaletteButton->isChecked() ? m_customPalette : m_selectedStyle->standardPalette());
}
void AppearancePage::setPreviewPalette(const QPalette &p){
@@ -171,15 +158,15 @@ void AppearancePage::setPreviewPalette(const QPalette &p){
if(m_ui->paletteComboBox->currentIndex() == 0){
colorGroup = QPalette::Active;
}
- else if(m_ui->paletteComboBox->currentIndex() == 1){
- colorGroup = QPalette::Inactive;
- }
- for (int i = 0; i < QPalette::NColorRoles; i++){
- QPalette::ColorRole role = QPalette::ColorRole(i);
- previewPalette.setColor(QPalette::Active, role, p.color(colorGroup, role));
- previewPalette.setColor(QPalette::Inactive, role, p.color(colorGroup, role));
- }
- setPalette(m_ui->mdiArea, previewPalette);
+ else if(m_ui->paletteComboBox->currentIndex() == 1){
+ colorGroup = QPalette::Inactive;
+ }
+ for (int i = 0; i < QPalette::NColorRoles; i++){
+ QPalette::ColorRole role = QPalette::ColorRole(i);
+ previewPalette.setColor(QPalette::Active, role, p.color(colorGroup, role));
+ previewPalette.setColor(QPalette::Inactive, role, p.color(colorGroup, role));
+ }
+ setPalette(m_ui->mdiArea, previewPalette);
}
void AppearancePage::updateActions(){
@@ -188,11 +175,11 @@ void AppearancePage::updateActions(){
m_renameColorSchemeAction->setVisible(false);
m_removeColorSchemeAction->setVisible(false);
}
- else{
- m_changeColorSchemeAction->setVisible(true);
- m_renameColorSchemeAction->setVisible(true);
- m_removeColorSchemeAction->setVisible(m_ui->colorSchemeComboBox->count() > 1);
- }
+ else{
+ m_changeColorSchemeAction->setVisible(true);
+ m_renameColorSchemeAction->setVisible(true);
+ m_removeColorSchemeAction->setVisible(m_ui->colorSchemeComboBox->count() > 1);
+ }
}
void AppearancePage::readSettings(){
@@ -203,27 +190,26 @@ void AppearancePage::readSettings(){
m_ui->customPaletteButton->setChecked(settings.value("custom_palette", false).toBool());
QString colorSchemePath = settings.value("color_scheme_path").toString();
QDir("/").mkpath(lthemeengine::userColorSchemePath());
- findColorSchemes(lthemeengine::userColorSchemePath());
- findColorSchemes(lthemeengine::sharedColorSchemePath().join(", "));
+ findColorSchemes( QStringList() << lthemeengine::userColorSchemePath() << lthemeengine::sharedColorSchemePath());
if(m_ui->colorSchemeComboBox->count() == 0){
m_customPalette = palette(); //load fallback palette
}
- else{
- int index = m_ui->colorSchemeComboBox->findData(colorSchemePath);
- if(index >= 0)
- m_ui->colorSchemeComboBox->setCurrentIndex(index);
- m_customPalette = loadColorScheme(m_ui->colorSchemeComboBox->currentData().toString());
- }
- on_styleComboBox_activated(m_ui->styleComboBox->currentText());
- settings.endGroup();
+ else{
+ int index = m_ui->colorSchemeComboBox->findData(colorSchemePath);
+ if(index >= 0)
+ m_ui->colorSchemeComboBox->setCurrentIndex(index);
+ m_customPalette = loadColorScheme(m_ui->colorSchemeComboBox->currentData().toString());
+ }
+ on_styleComboBox_activated(m_ui->styleComboBox->currentText());
+ settings.endGroup();
}
void AppearancePage::setStyle(QWidget *w, QStyle *s){
foreach (QObject *o, w->children()){
- if(o->isWidgetType()){
- setStyle(qobject_cast<QWidget *>(o), s);
+ if(o->isWidgetType()){
+ setStyle(qobject_cast<QWidget *>(o), s);
+ }
}
- }
w->setStyle(s);
}
@@ -236,12 +222,16 @@ void AppearancePage::setPalette(QWidget *w, QPalette p){
w->setPalette(p);
}
-void AppearancePage::findColorSchemes(const QString &path){
- QDir dir(path);
- dir.setFilter(QDir::Files);
- dir.setNameFilters(QStringList() << "*.conf");
- foreach (QFileInfo info, dir.entryInfoList()){
- m_ui->colorSchemeComboBox->addItem(info.baseName(), info.filePath());
+void AppearancePage::findColorSchemes(QStringList paths){
+ paths.removeDuplicates();
+ for(int i=0; i<paths.length(); i++){
+ if( !QFile::exists(paths[i])){ continue; }
+ QDir dir(paths[i]);
+ dir.setFilter(QDir::Files);
+ dir.setNameFilters(QStringList() << "*.conf");
+ foreach (QFileInfo info, dir.entryInfoList()){
+ m_ui->colorSchemeComboBox->addItem(info.baseName(), info.filePath());
+ }
}
}
@@ -261,10 +251,10 @@ QPalette AppearancePage::loadColorScheme(const QString &filePath){
customPalette.setColor(QPalette::Disabled, role, QColor(disabledColors.at(i)));
}
}
- else{
- customPalette = palette(); //load fallback palette
- }
- return customPalette;
+ else{
+ customPalette = palette(); //load fallback palette
+ }
+ return customPalette;
}
void AppearancePage::createColorScheme(const QString &name, const QPalette &palette){
bgstack15