From 88050e04f0fe04eb70aec087f4b612b84be934de Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 6 Dec 2017 15:25:20 -0500 Subject: Start trying to get stylesheet validation into the qss editor. Not quite working yet - still not picking up on the error message from Qt itself from the new lthemeengine-sstest process. --- .../lthemeengine-sstest/lthemeengine-sstest.pro | 11 ++++++ .../src/lthemeengine-sstest/main.cpp | 18 ++++++++++ .../src/lthemeengine/qsseditordialog.cpp | 39 ++++++++++++++++++++++ .../src/lthemeengine/qsseditordialog.h | 4 +++ .../src/lthemeengine/qsseditordialog.ui | 36 ++++++++++++++++++-- 5 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 src-qt5/core/lumina-theme-engine/src/lthemeengine-sstest/lthemeengine-sstest.pro create mode 100644 src-qt5/core/lumina-theme-engine/src/lthemeengine-sstest/main.cpp (limited to 'src-qt5/core/lumina-theme-engine/src') diff --git a/src-qt5/core/lumina-theme-engine/src/lthemeengine-sstest/lthemeengine-sstest.pro b/src-qt5/core/lumina-theme-engine/src/lthemeengine-sstest/lthemeengine-sstest.pro new file mode 100644 index 00000000..fadc6fcb --- /dev/null +++ b/src-qt5/core/lumina-theme-engine/src/lthemeengine-sstest/lthemeengine-sstest.pro @@ -0,0 +1,11 @@ +include(../../lthemeengine.pri) +TEMPLATE = app +QT *= widgets + +SOURCES += \ + main.cpp + +TARGET = lthemeengine-sstest +target.path = $${L_BINDIR} + +INSTALLS += target diff --git a/src-qt5/core/lumina-theme-engine/src/lthemeengine-sstest/main.cpp b/src-qt5/core/lumina-theme-engine/src/lthemeengine-sstest/main.cpp new file mode 100644 index 00000000..bdab0a30 --- /dev/null +++ b/src-qt5/core/lumina-theme-engine/src/lthemeengine-sstest/main.cpp @@ -0,0 +1,18 @@ +#include +//#include +#include + +#include + +int main(int argc, char **argv){ + if(argc<2){ return 1; } //error + unsetenv("QT_QPA_PLATFORMTHEME"); //Make sure we are not testing anything related to the current theme engine + QString stylesheet = LUtils::readFile(argv[1]).join("\n"); + //qDebug() << "Found Stylesheet:" << stylesheet; + QApplication app(argc, argv); + app.setStyleSheet(stylesheet); + //qDebug() << " Using Stylesheet:" << app.styleSheet(); + QWidget tmp(0,Qt::SplashScreen | Qt::BypassWindowManagerHint); + tmp.show(); //needed to actually run the parser on the stylesheet (unused/unchecked otherwise) + return 0; +} diff --git a/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsseditordialog.cpp b/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsseditordialog.cpp index ac891a80..56289931 100644 --- a/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsseditordialog.cpp +++ b/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsseditordialog.cpp @@ -4,6 +4,12 @@ #include "qsseditordialog.h" #include "ui_qsseditordialog.h" +#include +#include + +#include +#include + QSSEditorDialog::QSSEditorDialog(const QString &filePath, QWidget *parent) : QDialog(parent), m_ui(new Ui::QSSEditorDialog){ m_ui->setupUi(this); m_filePath = filePath; @@ -37,6 +43,11 @@ QSSEditorDialog::QSSEditorDialog(const QString &filePath, QWidget *parent) : QDi for(int i=0; iaddAction( colors[i].section("::::",0,0) )->setWhatsThis(colors[i].section("::::",1,1) ); } m_ui->tool_color->setMenu(colorMenu); connect(colorMenu, SIGNAL(triggered(QAction*)), this, SLOT(colorPicked(QAction*)) ); + validateTimer = new QTimer(this); + validateTimer->setInterval(500); //1/2 second after finish typing + validateTimer->setSingleShot(true); + connect(validateTimer, SIGNAL(timeout()), this, SLOT(validateStyleSheet()) ); + connect(m_ui->textEdit, SIGNAL(textChanged()), validateTimer, SLOT(start()) ); } QSSEditorDialog::~QSSEditorDialog(){ @@ -69,3 +80,31 @@ void QSSEditorDialog::colorPicked(QAction* act){ if(id.isEmpty()){ return; } m_ui->textEdit->insertPlainText( QString("palette(%1)").arg(id) ); } + +bool QSSEditorDialog::isStyleSheetValid(const QString &styleSheet){ + QTemporaryFile tempfile; + if(tempfile.open()){ + QTextStream out(&tempfile); + out << styleSheet; + out.flush(); + tempfile.close(); + } + QStringList log = LUtils::getCmdOutput("lthemeengine-sstest", QStringList() << tempfile.fileName()); + qDebug() << "Got Validation Log:" << log; + return log.join("").simplified().isEmpty(); +} + +void QSSEditorDialog::validateStyleSheet(){ + qDebug() << "Validating StyleSheet:"; + bool ok = isStyleSheetValid(m_ui->textEdit->toPlainText()); + + //Now update the button/label as needed + int sz = this->fontMetrics().height(); + if(ok){ + m_ui->label_status_icon->setPixmap(LXDG::findIcon("dialog-ok","").pixmap(sz,sz) ); + m_ui->label_status_icon->setToolTip(tr("Valid StyleSheet")); + }else{ + m_ui->label_status_icon->setPixmap(LXDG::findIcon("dialog-cancel","").pixmap(sz,sz) ); + m_ui->label_status_icon->setToolTip(tr("Invalid StyleSheet")); + } +} diff --git a/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsseditordialog.h b/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsseditordialog.h index 114611fe..f51434e9 100644 --- a/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsseditordialog.h +++ b/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsseditordialog.h @@ -5,6 +5,7 @@ #include #include #include +#include namespace Ui { class QSSEditorDialog; @@ -23,6 +24,8 @@ public: private slots: void on_buttonBox_clicked(QAbstractButton *button); void colorPicked(QAction*); + bool isStyleSheetValid(const QString&); + void validateStyleSheet(); private: void save(); @@ -30,6 +33,7 @@ private: Ui::QSSEditorDialog *m_ui; QString m_filePath; QMenu *colorMenu; + QTimer *validateTimer; }; diff --git a/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsseditordialog.ui b/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsseditordialog.ui index f75a21c6..68a14fb1 100644 --- a/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsseditordialog.ui +++ b/src-qt5/core/lumina-theme-engine/src/lthemeengine/qsseditordialog.ui @@ -6,8 +6,8 @@ 0 0 - 643 - 499 + 808 + 512 @@ -52,6 +52,38 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 16 + 16 + + + + + + + false + + + Qt::AlignCenter + + + -- cgit