From 435074064b20a997f14d055fbdfbef49bb50062b Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Mon, 11 Dec 2017 16:48:00 +0300 Subject: [PATCH] Dark theme has been added --- designer/designer.pro | 2 ++ include/lrglobal.h | 1 + .../editors/lrtextalignmenteditorwidget.cpp | 2 +- limereport/lrbasedesignintf.cpp | 10 +++++++++- limereport/lrdatasourcemanager.cpp | 2 +- limereport/lrglobal.h | 1 + limereport/lrreportdesignwidget.cpp | 19 ++++++++++++++++--- limereport/lrreportdesignwidget.h | 3 ++- limereport/lrreportengine.cpp | 14 ++++++++++++-- limereport/lrreportengine_p.h | 9 ++++++--- limereport/lrsettingdialog.cpp | 15 +++++++++++++++ limereport/lrsettingdialog.h | 2 ++ limereport/lrsettingdialog.ui | 7 +++++++ limereport/lrvariablesholder.h | 2 +- 14 files changed, 76 insertions(+), 13 deletions(-) diff --git a/designer/designer.pro b/designer/designer.pro index f8a22c3..4062e6f 100644 --- a/designer/designer.pro +++ b/designer/designer.pro @@ -13,6 +13,8 @@ SOURCES += main.cpp INCLUDEPATH += $$PWD/../include DEPENDPATH += $$PWD/../include +RESOURCES += $$PWD/../3rdparty/dark_style_sheet/qdarkstyle/style.qrc + DEST_DIR = $${DEST_BINS} REPORTS_DIR = $${DEST_DIR} diff --git a/include/lrglobal.h b/include/lrglobal.h index 74eeb00..13d8851 100644 --- a/include/lrglobal.h +++ b/include/lrglobal.h @@ -161,6 +161,7 @@ namespace Const{ Enums(){} Q_GADGET }; + typedef Enums::VariableDataType VariableDataType; } // namespace LimeReport diff --git a/limereport/items/editors/lrtextalignmenteditorwidget.cpp b/limereport/items/editors/lrtextalignmenteditorwidget.cpp index 6fd833b..8eb424b 100644 --- a/limereport/items/editors/lrtextalignmenteditorwidget.cpp +++ b/limereport/items/editors/lrtextalignmenteditorwidget.cpp @@ -95,7 +95,7 @@ void TextAlignmentEditorWidget::initEditor() void TextAlignmentEditorWidget::updateValues(const Qt::Alignment &align) { - m_textAttibutesIsChanging=true; + m_textAttibutesIsChanging=true; m_textAliginLeft->setChecked((align & Qt::AlignLeft)==Qt::AlignLeft); m_textAliginRight->setChecked((align & Qt::AlignRight)==Qt::AlignRight); m_textAliginHCenter->setChecked((align & Qt::AlignHCenter)==Qt::AlignHCenter); diff --git a/limereport/lrbasedesignintf.cpp b/limereport/lrbasedesignintf.cpp index 0f2a8fd..0b41b05 100644 --- a/limereport/lrbasedesignintf.cpp +++ b/limereport/lrbasedesignintf.cpp @@ -1139,8 +1139,16 @@ void BaseDesignIntf::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) } } +QWidget* findRootWidget(QWidget* widget){ + while (widget->parentWidget()) { + widget = widget->parentWidget(); + } + return widget; +} + void BaseDesignIntf::showEditorDialog(){ - QWidget *editor = defaultEditor(); + QWidget *editor = defaultEditor(); + editor->setStyleSheet(findRootWidget(scene()->views().at(0))->styleSheet()); if (editor) { #ifdef Q_OS_WIN diff --git a/limereport/lrdatasourcemanager.cpp b/limereport/lrdatasourcemanager.cpp index 786ef14..6890b3e 100644 --- a/limereport/lrdatasourcemanager.cpp +++ b/limereport/lrdatasourcemanager.cpp @@ -1503,7 +1503,7 @@ VariableDataType DataSourceManager::variableDataType(const QString& name) { if (m_reportVariables.containsVariable(name)) return m_reportVariables.variableByName(name)->dataType(); - return VariableDataType::Undefined; + return Enums::Undefined; } void DataSourceManager::setVariableDataType(const QString& name, VariableDataType value) diff --git a/limereport/lrglobal.h b/limereport/lrglobal.h index 74eeb00..13d8851 100644 --- a/limereport/lrglobal.h +++ b/limereport/lrglobal.h @@ -161,6 +161,7 @@ namespace Const{ Enums(){} Q_GADGET }; + typedef Enums::VariableDataType VariableDataType; } // namespace LimeReport diff --git a/limereport/lrreportdesignwidget.cpp b/limereport/lrreportdesignwidget.cpp index 2af7de9..b336429 100644 --- a/limereport/lrreportdesignwidget.cpp +++ b/limereport/lrreportdesignwidget.cpp @@ -56,7 +56,7 @@ ReportDesignWidget::ReportDesignWidget(ReportEnginePrivateInterface* report, QMa #ifdef HAVE_QTDESIGNER_INTEGRATION m_dialogDesignerManager(new DialogDesignerManager(this)), #endif - m_mainWindow(mainWindow), m_verticalGridStep(10), m_horizontalGridStep(10), m_useGrid(false), m_dialogChanged(false) + m_mainWindow(mainWindow), m_verticalGridStep(10), m_horizontalGridStep(10), m_useGrid(false), m_dialogChanged(false), m_useDarkTheme(false) { #ifdef HAVE_QT4 m_tabWidget = new LimeReportTabWidget(this); @@ -189,6 +189,7 @@ void ReportDesignWidget::saveState(QSettings* settings) settings->setValue("vGridStep",m_verticalGridStep); settings->setValue("defaultFont",m_defaultFont); settings->setValue("useGrid",m_useGrid); + settings->setValue("useDarkTheme",m_useDarkTheme); settings->setValue("ScriptEditorState", m_scriptEditor->saveState()); settings->endGroup(); } @@ -199,6 +200,13 @@ void ReportDesignWidget::applySettings() m_report->pageAt(i)->pageItem()->setFont(m_defaultFont); } applyUseGrid(); + if (m_useDarkTheme) { + QFile theme(":/qdarkstyle/style.qss"); + theme.open(QIODevice::ReadOnly); + QString styleSheet = theme.readAll(); + parentWidget()->setStyleSheet(styleSheet); + m_report->setStyleSheet(styleSheet); + } else parentWidget()->setStyleSheet(""); } void ReportDesignWidget::loadState(QSettings* settings) @@ -223,6 +231,11 @@ void ReportDesignWidget::loadState(QSettings* settings) m_useGrid = v.toBool(); } + v = settings->value("useDarkTheme"); + if (v.isValid()){ + m_useDarkTheme = v.toBool(); + } + v = settings->value("ScriptEditorState"); if (v.isValid()){ m_scriptEditor->restoreState(v.toByteArray()); @@ -369,8 +382,6 @@ PageDesignIntf * ReportDesignWidget::activePage() return 0; } - - QList ReportDesignWidget::selectedItems(){ return activePage()->selectedItems(); } @@ -697,11 +708,13 @@ void ReportDesignWidget::editSetting() setting.setHorizontalGridStep(m_horizontalGridStep); setting.setDefaultFont(m_defaultFont); setting.setSuppressAbsentFieldsAndVarsWarnings(m_report->suppressFieldAndVarError()); + setting.setUseDarkTheme(m_useDarkTheme); if (setting.exec()){ m_horizontalGridStep = setting.horizontalGridStep(); m_verticalGridStep = setting.verticalGridStep(); m_defaultFont = setting.defaultFont(); + m_useDarkTheme = setting.userDarkTheme(); m_report->setSuppressFieldAndVarError(setting.suppressAbsentFieldsAndVarsWarnings()); applySettings(); } diff --git a/limereport/lrreportdesignwidget.h b/limereport/lrreportdesignwidget.h index e38338b..2887621 100644 --- a/limereport/lrreportdesignwidget.h +++ b/limereport/lrreportdesignwidget.h @@ -199,6 +199,7 @@ protected: #endif private: bool eventFilter(QObject *target, QEvent *event); + void prepareReport(); private: ReportEnginePrivateInterface* m_report; QGraphicsView *m_view; @@ -221,7 +222,7 @@ private: bool m_useGrid; bool m_useMagnet; bool m_dialogChanged; - void prepareReport(); + bool m_useDarkTheme; }; } // namespace LimeReport diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index 59f5de2..d3646f8 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -502,7 +502,7 @@ void ReportEnginePrivate::previewReport(PreviewHints hints) } w->setHideResultEditButton(resultIsEditable()); - + w->setStyleSheet(m_styleSheet); m_activePreview = w; connect(w,SIGNAL(destroyed(QObject*)), this, SLOT(slotPreviewWindowDestroyed(QObject*))); w->exec(); @@ -932,10 +932,20 @@ void ReportEnginePrivate::activateLanguage(QLocale::Language language) } } +QString ReportEnginePrivate::styleSheet() const +{ + return m_styleSheet; +} + +void ReportEnginePrivate::setStyleSheet(const QString &styleSheet) +{ + m_styleSheet = styleSheet; +} + bool ReportEnginePrivate::setReportLanguage(QLocale::Language language){ m_reportLanguage = language; if (!m_translations.keys().contains(language)) return false; -// activateLanguage(language); + // activateLanguage(language); return true; } diff --git a/limereport/lrreportengine_p.h b/limereport/lrreportengine_p.h index 4bf57cd..9dde434 100644 --- a/limereport/lrreportengine_p.h +++ b/limereport/lrreportengine_p.h @@ -53,8 +53,6 @@ class PageDesignIntf; class PrintRange; class ReportDesignWindow; -//TODO: Add on render callback - class ReportEnginePrivateInterface { public: virtual PageDesignIntf* appendPage(const QString& pageName="") = 0; @@ -84,7 +82,8 @@ public: virtual QString currentReportsDir() = 0; virtual bool suppressFieldAndVarError() const = 0; virtual void setSuppressFieldAndVarError(bool suppressFieldAndVarError) = 0; - + virtual void setStyleSheet(const QString& styleSheet) = 0; + virtual QString styleSheet() const = 0; }; class ReportEnginePrivate : public QObject, public ICollectionContainer, public ITranslationContainer, @@ -179,6 +178,9 @@ public: void clearSelection(); Qt::LayoutDirection previewLayoutDirection(); void setPreviewLayoutDirection(const Qt::LayoutDirection& previewLayoutDirection); + QString styleSheet() const; + void setStyleSheet(const QString &styleSheet); + signals: void pagesLoadFinished(); void datasourceCollectionLoadFinished(const QString& collectionName); @@ -243,6 +245,7 @@ private: void activateLanguage(QLocale::Language language); Qt::LayoutDirection m_previewLayoutDirection; LimeReportPluginInterface* m_designerFactory; + QString m_styleSheet; }; } diff --git a/limereport/lrsettingdialog.cpp b/limereport/lrsettingdialog.cpp index 0b929be..ee34440 100644 --- a/limereport/lrsettingdialog.cpp +++ b/limereport/lrsettingdialog.cpp @@ -1,5 +1,6 @@ #include "lrsettingdialog.h" #include "ui_lrsettingdialog.h" +#include namespace LimeReport{ @@ -8,6 +9,10 @@ SettingDialog::SettingDialog(QWidget *parent) : ui(new Ui::SettingDialog) { ui->setupUi(this); + QFile theme(":/qdarkstyle/style.qss"); + if (!theme.exists()){ + ui->cbbUseDarkTheme->setVisible(false); + } } SettingDialog::~SettingDialog() @@ -32,6 +37,11 @@ QFont SettingDialog::defaultFont() return result; } +bool SettingDialog::userDarkTheme() +{ + return ui->cbbUseDarkTheme->isChecked(); +} + bool SettingDialog::suppressAbsentFieldsAndVarsWarnings() { return ui->cbSuppressWarnings->isChecked(); @@ -57,4 +67,9 @@ void SettingDialog::setDefaultFont(const QFont &value) ui->defaultFontSize->setValue(value.pointSize()); } +void SettingDialog::setUseDarkTheme(bool value) +{ + ui->cbbUseDarkTheme->setChecked(value); +} + } // namespace LimeReport diff --git a/limereport/lrsettingdialog.h b/limereport/lrsettingdialog.h index e9a740d..db908f9 100644 --- a/limereport/lrsettingdialog.h +++ b/limereport/lrsettingdialog.h @@ -19,11 +19,13 @@ public: int verticalGridStep(); int horizontalGridStep(); QFont defaultFont(); + bool userDarkTheme(); bool suppressAbsentFieldsAndVarsWarnings(); void setSuppressAbsentFieldsAndVarsWarnings(bool value); void setHorizontalGridStep(int value); void setVerticalGridStep(int value); void setDefaultFont(const QFont& value); + void setUseDarkTheme(bool value); private: Ui::SettingDialog *ui; }; diff --git a/limereport/lrsettingdialog.ui b/limereport/lrsettingdialog.ui index d3a143a..b0dd1ed 100644 --- a/limereport/lrsettingdialog.ui +++ b/limereport/lrsettingdialog.ui @@ -108,6 +108,13 @@ + + + + Use dark theme + + + diff --git a/limereport/lrvariablesholder.h b/limereport/lrvariablesholder.h index 6756240..76446b5 100644 --- a/limereport/lrvariablesholder.h +++ b/limereport/lrvariablesholder.h @@ -45,7 +45,7 @@ class VarDesc : public QObject{ Q_PROPERTY(bool isMandatory READ isMandatory WRITE setMandatory) Q_PROPERTY(int dataType READ readDataTypeProperty WRITE setDataTypeProperty) public: - VarDesc() : m_dataType(VariableDataType::Undefined), m_mandatory(false){} + VarDesc() : m_dataType(Enums::Undefined), m_mandatory(false){} enum VarType {System, User, Report}; void setVarType(VarType value){m_varType=value;} VarType varType(){return m_varType;}