aboutsummaryrefslogtreecommitdiff
path: root/src-qt5
diff options
context:
space:
mode:
authorKen Moore <ken@ixsystems.com>2017-12-06 15:25:20 -0500
committerKen Moore <ken@ixsystems.com>2017-12-06 15:25:20 -0500
commit88050e04f0fe04eb70aec087f4b612b84be934de (patch)
tree3206e6b5376268a16c1f8104e27563115c72eca9 /src-qt5
parentFix the LUtils.pri file: Forgot to remove a couple unused files from the incl... (diff)
downloadlumina-88050e04f0fe04eb70aec087f4b612b84be934de.tar.gz
lumina-88050e04f0fe04eb70aec087f4b612b84be934de.tar.bz2
lumina-88050e04f0fe04eb70aec087f4b612b84be934de.zip
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.
Diffstat (limited to 'src-qt5')
-rw-r--r--src-qt5/core/lumina-theme-engine/lumina-theme-engine.pro3
-rw-r--r--src-qt5/core/lumina-theme-engine/src/lthemeengine-sstest/lthemeengine-sstest.pro11
-rw-r--r--src-qt5/core/lumina-theme-engine/src/lthemeengine-sstest/main.cpp18
-rw-r--r--src-qt5/core/lumina-theme-engine/src/lthemeengine/qsseditordialog.cpp39
-rw-r--r--src-qt5/core/lumina-theme-engine/src/lthemeengine/qsseditordialog.h4
-rw-r--r--src-qt5/core/lumina-theme-engine/src/lthemeengine/qsseditordialog.ui36
6 files changed, 108 insertions, 3 deletions
diff --git a/src-qt5/core/lumina-theme-engine/lumina-theme-engine.pro b/src-qt5/core/lumina-theme-engine/lumina-theme-engine.pro
index e1023752..1e8b2ca4 100644
--- a/src-qt5/core/lumina-theme-engine/lumina-theme-engine.pro
+++ b/src-qt5/core/lumina-theme-engine/lumina-theme-engine.pro
@@ -3,7 +3,8 @@ include(../../OS-detect.pri)
TEMPLATE = subdirs
SUBDIRS += src/lthemeengine-qtplugin \
src/lthemeengine-style \
- src/lthemeengine
+ src/lthemeengine \
+ src/lthemeengine-sstest
colors.files = colors/*.conf
colors.path = $${L_SHAREDIR}/lthemeengine/colors
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 <QApplication>
+//#include <QDebug>
+#include <QWidget>
+
+#include <LUtils.h>
+
+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 <QTemporaryFile>
+#include <QTextStream>
+
+#include <LuminaXDG.h>
+#include <LUtils.h>
+
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; i<colors.length(); i++){ colorMenu->addAction( 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 <QString>
#include <QMenu>
#include <QAction>
+#include <QTimer>
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 @@
<rect>
<x>0</x>
<y>0</y>
- <width>643</width>
- <height>499</height>
+ <width>808</width>
+ <height>512</height>
</rect>
</property>
<property name="windowTitle">
@@ -53,6 +53,38 @@
</widget>
</item>
<item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_status_icon">
+ <property name="minimumSize">
+ <size>
+ <width>16</width>
+ <height>16</height>
+ </size>
+ </property>
+ <property name="text">
+ <string notr="true"/>
+ </property>
+ <property name="scaledContents">
+ <bool>false</bool>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
bgstack15