From 91b49f991eaa2c2c6ba50ec129db9f7c0405c14d Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Mon, 11 Sep 2017 14:53:32 -0400 Subject: Rename the "stylesheets" tab and split it up into two tabs: "Application Theme" and "Desktop Theme". Also re-work the qsspage class a bit to understand whether it is running in "desktop" or "application" mode. --- .../lumina-theme-engine/src/lthemeengine/qsspage.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src-qt5/core/lumina-theme-engine/src/lthemeengine/qsspage.cpp') diff --git a/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsspage.cpp b/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsspage.cpp index 2cf0f221..681de6c9 100644 --- a/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsspage.cpp +++ b/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsspage.cpp @@ -12,8 +12,9 @@ #define QSS_FULL_PATH_ROLE (Qt::ItemDataRole(Qt::UserRole)) #define QSS_WRITABLE_ROLE (Qt::ItemDataRole(Qt::UserRole + 1)) -QSSPage::QSSPage(QWidget *parent) : TabPage(parent), m_ui(new Ui::QSSPage){ +QSSPage::QSSPage(QWidget *parent, bool desktop) : TabPage(parent), m_ui(new Ui::QSSPage){ m_ui->setupUi(this); + desktop_qss = desktop; QDir("/").mkpath(lthemeengine::userStyleSheetPath()); m_menu = new QMenu(this); m_menu->addAction(QIcon::fromTheme("accessories-text-editor"), tr("Edit"), this, SLOT(on_editButton_clicked())); @@ -37,7 +38,8 @@ void QSSPage::writeSettings(){ for(int i = 0; i < m_ui->qssListWidget->count(); ++i){ QListWidgetItem *item = m_ui->qssListWidget->item(i); if(item->checkState() == Qt::Checked){ styleSheets << item->data(QSS_FULL_PATH_ROLE).toString(); } - settings.setValue("Interface/stylesheets", styleSheets); + if(desktop_qss){ settings.setValue("Interface/desktop_stylesheets", styleSheets); } + else{ settings.setValue("Interface/stylesheets", styleSheets); } } } @@ -58,7 +60,9 @@ void QSSPage::on_createButton_clicked(){ QString name = QInputDialog::getText(this, tr("Enter Style Sheet Name"), tr("File name:")); if(name.isEmpty()){ return; } if(!name.endsWith(".qss", Qt::CaseInsensitive)){ name.append(".qss"); } - QString filePath = lthemeengine::userStyleSheetPath() + name; + QString filePath; + if(desktop_qss){ filePath = lthemeengine::userDesktopStyleSheetPath() + name; } + else{ filePath = lthemeengine::userStyleSheetPath() + name; } if(QFile::exists(filePath)){ QMessageBox::warning(this, tr("Error"), tr("The file \"%1\" already exists").arg(filePath)); return; @@ -95,9 +99,13 @@ void QSSPage::on_removeButton_clicked(){ void QSSPage::readSettings(){ //load stylesheets m_ui->qssListWidget->clear(); - findStyleSheets(QStringList() << lthemeengine::userStyleSheetPath() << lthemeengine::sharedStyleSheetPath()); + if(desktop_qss){ findStyleSheets(QStringList() << lthemeengine::userStyleSheetPath() << lthemeengine::sharedStyleSheetPath()); } + else{findStyleSheets(QStringList() << lthemeengine::userStyleSheetPath() << lthemeengine::sharedStyleSheetPath()); } QSettings settings(lthemeengine::configFile(), QSettings::IniFormat); - QStringList styleSheets = settings.value("Interface/stylesheets").toStringList(); + QStringList styleSheets; + if(desktop_qss){ styleSheets = settings.value("Interface/desktop_stylesheets").toStringList(); } + else{ styleSheets = settings.value("Interface/stylesheets").toStringList(); } + for(int i = 0; i < m_ui->qssListWidget->count(); ++i){ QListWidgetItem *item = m_ui->qssListWidget->item(i); if(styleSheets.contains(item->data(QSS_FULL_PATH_ROLE).toString())){ item->setCheckState(Qt::Checked); } -- cgit From 94b2980985d668172a6760ea3e6855be36cce336 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 13 Sep 2017 13:11:52 -0400 Subject: Fix up some of the qss theme page --- src-qt5/core/lumina-theme-engine/src/lthemeengine/qsspage.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src-qt5/core/lumina-theme-engine/src/lthemeengine/qsspage.cpp') diff --git a/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsspage.cpp b/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsspage.cpp index 681de6c9..2e906d9e 100644 --- a/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsspage.cpp +++ b/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsspage.cpp @@ -4,6 +4,8 @@ #include #include #include +#include + #include "lthemeengine.h" #include "qsseditordialog.h" #include "qsspage.h" @@ -44,6 +46,7 @@ void QSSPage::writeSettings(){ } void QSSPage::on_qssListWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *){ + //qDebug() << "Got Current Item Changed"; if(current){ m_ui->editButton->setEnabled(current->data(QSS_WRITABLE_ROLE).toBool()); m_ui->removeButton->setEnabled(current->data(QSS_WRITABLE_ROLE).toBool()); @@ -67,6 +70,12 @@ void QSSPage::on_createButton_clicked(){ QMessageBox::warning(this, tr("Error"), tr("The file \"%1\" already exists").arg(filePath)); return; } + // Make sure the directory exists + QString dir = filePath.section("/",0,-2); + if(!QFile::exists(dir)){ + QDir D(dir); + D.mkpath(dir); + } //creating empty file QFile file(filePath); file.open(QIODevice::WriteOnly); @@ -99,7 +108,7 @@ void QSSPage::on_removeButton_clicked(){ void QSSPage::readSettings(){ //load stylesheets m_ui->qssListWidget->clear(); - if(desktop_qss){ findStyleSheets(QStringList() << lthemeengine::userStyleSheetPath() << lthemeengine::sharedStyleSheetPath()); } + if(desktop_qss){ findStyleSheets(QStringList() << lthemeengine::userDesktopStyleSheetPath() << lthemeengine::sharedDesktopStyleSheetPath()); } else{findStyleSheets(QStringList() << lthemeengine::userStyleSheetPath() << lthemeengine::sharedStyleSheetPath()); } QSettings settings(lthemeengine::configFile(), QSettings::IniFormat); QStringList styleSheets; -- cgit From 5f82ff57aded0bdea93a1e825070538c4f928275 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Thu, 14 Sep 2017 10:52:20 -0400 Subject: Cleanup the QSS page quite a bit so that items can now be sorted, ordered by priority and more. --- .../src/lthemeengine/qsspage.cpp | 119 ++++++++++++++++++--- 1 file changed, 102 insertions(+), 17 deletions(-) (limited to 'src-qt5/core/lumina-theme-engine/src/lthemeengine/qsspage.cpp') diff --git a/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsspage.cpp b/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsspage.cpp index 2e906d9e..ae5350ab 100644 --- a/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsspage.cpp +++ b/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsspage.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "lthemeengine.h" #include "qsseditordialog.h" @@ -37,15 +38,37 @@ QSSPage::~QSSPage(){ void QSSPage::writeSettings(){ QStringList styleSheets; QSettings settings(lthemeengine::configFile(), QSettings::IniFormat); - for(int i = 0; i < m_ui->qssListWidget->count(); ++i){ + for(int i = m_ui->qssListWidget->count()-1; i>=0; i--){ QListWidgetItem *item = m_ui->qssListWidget->item(i); - if(item->checkState() == Qt::Checked){ styleSheets << item->data(QSS_FULL_PATH_ROLE).toString(); } + styleSheets << item->data(QSS_FULL_PATH_ROLE).toString(); + } if(desktop_qss){ settings.setValue("Interface/desktop_stylesheets", styleSheets); } else{ settings.setValue("Interface/stylesheets", styleSheets); } - } } void QSSPage::on_qssListWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *){ + if(current!=0){ + m_ui->list_disabled->clearSelection(); //clear any current selection on the other widget + m_ui->list_disabled->setCurrentRow(-1); + } + //qDebug() << "Got Current Item Changed"; + if(current){ + m_ui->editButton->setEnabled(current->data(QSS_WRITABLE_ROLE).toBool()); + m_ui->removeButton->setEnabled(current->data(QSS_WRITABLE_ROLE).toBool()); + m_ui->renameButton->setEnabled(current->data(QSS_WRITABLE_ROLE).toBool()); + } + else{ + m_ui->editButton->setEnabled(false); + m_ui->removeButton->setEnabled(false); + m_ui->renameButton->setEnabled(false); + } +} + +void QSSPage::on_list_disabled_currentItemChanged(QListWidgetItem *current, QListWidgetItem *){ + if(current!=0){ + m_ui->qssListWidget->clearSelection(); //clear any current selection on the other widget + m_ui->qssListWidget->setCurrentRow(-1); + } //qDebug() << "Got Current Item Changed"; if(current){ m_ui->editButton->setEnabled(current->data(QSS_WRITABLE_ROLE).toBool()); @@ -86,11 +109,12 @@ void QSSPage::on_createButton_clicked(){ item->setToolTip(info.filePath()); item->setData(QSS_FULL_PATH_ROLE, info.filePath()); item->setData(QSS_WRITABLE_ROLE, info.isWritable()); - item->setCheckState(Qt::Unchecked); + m_ui->qssListWidget->setCurrentRow(m_ui->qssListWidget->count()-1); + QTimer::singleShot(10, this, SLOT(on_editButton_clicked()) ); } void QSSPage::on_editButton_clicked(){ - QListWidgetItem *item = m_ui->qssListWidget->currentItem(); + QListWidgetItem *item = currentSelection(); if(item){ QSSEditorDialog dialog(item->data(QSS_FULL_PATH_ROLE).toString(), this); dialog.exec(); @@ -98,31 +122,76 @@ void QSSPage::on_editButton_clicked(){ } void QSSPage::on_removeButton_clicked(){ - QListWidgetItem *item = m_ui->qssListWidget->currentItem(); + QListWidgetItem *item = currentSelection(); if(!item){ return; } int button = QMessageBox::question(this, tr("Confirm Remove"),tr("Are you sure you want to remove style sheet \"%1\"?").arg(item->text()), QMessageBox::Yes | QMessageBox::No); if(button == QMessageBox::Yes){ QFile::remove(item->data(QSS_FULL_PATH_ROLE).toString()); } delete item; } +void QSSPage::on_tool_enable_clicked(){ + QList sel = m_ui->list_disabled->selectedItems(); + //qDebug() << "Got Selection:" << sel.count(); + for(int i=0; iqssListWidget->addItem(sel[i]->clone()); + delete sel[i]; + //QCoreApplication::processEvents(); + m_ui->qssListWidget->setCurrentRow(m_ui->qssListWidget->count()-1); + } + +} + +void QSSPage::on_tool_disable_clicked(){ + QList sel = m_ui->qssListWidget->selectedItems(); + //qDebug() << "Got Selection:" << sel.count(); + for(int i=0; ilist_disabled->addItem(sel[i]->clone()); + delete sel[i]; + //QCoreApplication::processEvents(); + m_ui->list_disabled->setCurrentRow(m_ui->list_disabled->count()-1); + } +} + +void QSSPage::on_tool_priority_up_clicked(){ + QList sel = m_ui->qssListWidget->selectedItems(); + for(int i=0; iqssListWidget->row(sel[i]); + //qDebug() << "Move Item Up:" << index; + if(index>0){ + m_ui->qssListWidget->insertItem(index-1, m_ui->qssListWidget->takeItem(index)); + m_ui->qssListWidget->setCurrentRow(index-1); + } + } +} + +void QSSPage::on_tool_priority_down_clicked(){ + QList sel = m_ui->qssListWidget->selectedItems(); + for(int i=0; iqssListWidget->row(sel[i]); + //qDebug() << "Move Item Down:" << index; + if(index<(m_ui->qssListWidget->count()-1) ){ + m_ui->qssListWidget->insertItem(index+1, m_ui->qssListWidget->takeItem(index)); + m_ui->qssListWidget->setCurrentRow(index+1); + } + } +} + void QSSPage::readSettings(){ //load stylesheets m_ui->qssListWidget->clear(); - if(desktop_qss){ findStyleSheets(QStringList() << lthemeengine::userDesktopStyleSheetPath() << lthemeengine::sharedDesktopStyleSheetPath()); } - else{findStyleSheets(QStringList() << lthemeengine::userStyleSheetPath() << lthemeengine::sharedStyleSheetPath()); } + m_ui->list_disabled->clear(); + //Read the currently-enabled settings QSettings settings(lthemeengine::configFile(), QSettings::IniFormat); QStringList styleSheets; if(desktop_qss){ styleSheets = settings.value("Interface/desktop_stylesheets").toStringList(); } else{ styleSheets = settings.value("Interface/stylesheets").toStringList(); } + //Now load the items into list widgets + if(desktop_qss){ findStyleSheets(QStringList() << lthemeengine::userDesktopStyleSheetPath() << lthemeengine::sharedDesktopStyleSheetPath(), styleSheets); } + else{findStyleSheets(QStringList() << lthemeengine::userStyleSheetPath() << lthemeengine::sharedStyleSheetPath(), styleSheets); } - for(int i = 0; i < m_ui->qssListWidget->count(); ++i){ - QListWidgetItem *item = m_ui->qssListWidget->item(i); - if(styleSheets.contains(item->data(QSS_FULL_PATH_ROLE).toString())){ item->setCheckState(Qt::Checked); } - else { item->setCheckState(Qt::Unchecked); } - } } -void QSSPage::findStyleSheets(QStringList paths){ +void QSSPage::findStyleSheets(QStringList paths, QStringList enabled){ paths.removeDuplicates(); for(int i=0; iqssListWidget); + QListWidgetItem *item = new QListWidgetItem(info.fileName()); item->setToolTip(info.filePath()); item->setData(QSS_FULL_PATH_ROLE, info.filePath()); item->setData(QSS_WRITABLE_ROLE, info.isWritable()); + if( enabled.contains(info.filePath()) ){ m_ui->qssListWidget->addItem(item); } + else{ m_ui->list_disabled->addItem(item); } } } + //Now ensure the priority of the items in the active list is correct + for(int i = 0; i < m_ui->qssListWidget->count(); ++i){ + QListWidgetItem *item = m_ui->qssListWidget->item(i); + int index = enabled.indexOf( item->data(QSS_FULL_PATH_ROLE).toString() ); + if(index>=0){ m_ui->qssListWidget->insertItem(index, item); }// item->move(m_ui->qssListWidget->count() - 1 - index); } + } + m_ui->list_disabled->sortItems(Qt::AscendingOrder); + } void QSSPage::on_renameButton_clicked(){ - QListWidgetItem *item = m_ui->qssListWidget->currentItem(); + QListWidgetItem *item = currentSelection(); if(!item){ return; } QString name = QInputDialog::getText(this, tr("Rename Style Sheet"), tr("Style sheet name:"), QLineEdit::Normal, item->text(), 0); if(name.isEmpty()){ return; } - if(!m_ui->qssListWidget->findItems(name, Qt::MatchExactly).isEmpty()){ + if(!m_ui->qssListWidget->findItems(name, Qt::MatchExactly).isEmpty() || !m_ui->list_disabled->findItems(name, Qt::MatchExactly).isEmpty()){ QMessageBox::warning(this, tr("Error"), tr("The style sheet \"%1\" already exists").arg(name)); return; } @@ -162,3 +241,9 @@ void QSSPage::on_qssListWidget_customContextMenuRequested(const QPoint &pos){ QListWidgetItem *item = m_ui->qssListWidget->currentItem(); if(item && item->data(QSS_WRITABLE_ROLE).toBool()){ m_menu->exec(m_ui->qssListWidget->viewport()->mapToGlobal(pos)); } } + +QListWidgetItem* QSSPage::currentSelection(){ + QListWidgetItem *item = m_ui->qssListWidget->currentItem(); + if(item==0){ item = m_ui->list_disabled->currentItem(); } + return item; +} -- cgit From 49d7b64794cb5c645f0093d18a207ea1c9fe2121 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Thu, 14 Sep 2017 12:22:31 -0400 Subject: Turn off the custom theme engine for the 1.x desktop itself, and use the lthemeengine styles for everything now. Also commit a few simple fixes for the lthemeengine styles page and a couple other random tweaks. --- src-qt5/core/lumina-theme-engine/src/lthemeengine/qsspage.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src-qt5/core/lumina-theme-engine/src/lthemeengine/qsspage.cpp') diff --git a/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsspage.cpp b/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsspage.cpp index ae5350ab..cd88fb56 100644 --- a/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsspage.cpp +++ b/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsspage.cpp @@ -29,6 +29,8 @@ QSSPage::QSSPage(QWidget *parent, bool desktop) : TabPage(parent), m_ui(new Ui:: m_ui->createButton->setIcon(QIcon::fromTheme("document-new")); m_ui->editButton->setIcon(QIcon::fromTheme("accessories-text-editor")); m_ui->removeButton->setIcon(QIcon::fromTheme("edit-delete")); + m_ui->tool_enable->setEnabled(false); + m_ui->tool_disable->setEnabled(false); } QSSPage::~QSSPage(){ @@ -50,8 +52,10 @@ void QSSPage::on_qssListWidget_currentItemChanged(QListWidgetItem *current, QLis if(current!=0){ m_ui->list_disabled->clearSelection(); //clear any current selection on the other widget m_ui->list_disabled->setCurrentRow(-1); + m_ui->tool_enable->setEnabled(false); } //qDebug() << "Got Current Item Changed"; + m_ui->tool_disable->setEnabled(current!=0); if(current){ m_ui->editButton->setEnabled(current->data(QSS_WRITABLE_ROLE).toBool()); m_ui->removeButton->setEnabled(current->data(QSS_WRITABLE_ROLE).toBool()); @@ -68,8 +72,10 @@ void QSSPage::on_list_disabled_currentItemChanged(QListWidgetItem *current, QLis if(current!=0){ m_ui->qssListWidget->clearSelection(); //clear any current selection on the other widget m_ui->qssListWidget->setCurrentRow(-1); + m_ui->tool_disable->setEnabled(false); } //qDebug() << "Got Current Item Changed"; + m_ui->tool_enable->setEnabled(current!=0); if(current){ m_ui->editButton->setEnabled(current->data(QSS_WRITABLE_ROLE).toBool()); m_ui->removeButton->setEnabled(current->data(QSS_WRITABLE_ROLE).toBool()); @@ -105,11 +111,11 @@ void QSSPage::on_createButton_clicked(){ file.close(); //creating item QFileInfo info(filePath); - QListWidgetItem *item = new QListWidgetItem(info.fileName(), m_ui->qssListWidget); + QListWidgetItem *item = new QListWidgetItem(info.fileName(), m_ui->list_disabled); item->setToolTip(info.filePath()); item->setData(QSS_FULL_PATH_ROLE, info.filePath()); item->setData(QSS_WRITABLE_ROLE, info.isWritable()); - m_ui->qssListWidget->setCurrentRow(m_ui->qssListWidget->count()-1); + m_ui->list_disabled->setCurrentRow(m_ui->list_disabled->count()-1); QTimer::singleShot(10, this, SLOT(on_editButton_clicked()) ); } -- cgit