diff --git a/3rdparty/dark_style_sheet/qdarkstyle/style.qss b/3rdparty/dark_style_sheet/qdarkstyle/style.qss index 59941f4..fd9d694 100644 --- a/3rdparty/dark_style_sheet/qdarkstyle/style.qss +++ b/3rdparty/dark_style_sheet/qdarkstyle/style.qss @@ -952,6 +952,7 @@ QDockWidget { QDockWidget::title{ background: #383838; padding-left: 5px; + margin-top: 4px; } diff --git a/designer/designer.pro b/designer/designer.pro index 4062e6f..d5abd1b 100644 --- a/designer/designer.pro +++ b/designer/designer.pro @@ -8,7 +8,8 @@ contains(CONFIG,release) { } TEMPLATE = app -SOURCES += main.cpp +SOURCES += main.cpp \ + designersettingmanager.cpp INCLUDEPATH += $$PWD/../include DEPENDPATH += $$PWD/../include @@ -61,3 +62,6 @@ win32 { } } +HEADERS += \ + designersettingmanager.h + diff --git a/designer/designersettingmanager.cpp b/designer/designersettingmanager.cpp new file mode 100644 index 0000000..925143f --- /dev/null +++ b/designer/designersettingmanager.cpp @@ -0,0 +1,37 @@ +#include "designersettingmanager.h" + +DesignerSettingManager::DesignerSettingManager(QObject *parent) : QObject(parent) +{ + m_setting = new QSettings("LimeReport",QCoreApplication::applicationName()); +} + +DesignerSettingManager::~DesignerSettingManager() +{ + delete m_setting; +} + +void DesignerSettingManager::getAviableLanguages(QList* languages) +{ + languages->append(QLocale::Russian); + languages->append(QLocale::English); + languages->append(QLocale::Arabic); +} + +QLocale::Language DesignerSettingManager::getCurrentDefaultLanguage() +{ + m_setting->beginGroup("ReportDesigner"); + QVariant v = m_setting->value("DesignerLanguage"); + m_setting->endGroup(); + if (v.isValid()){ + return static_cast(v.toInt()) ; + } else { + return QLocale::system().language(); + } +} + +void DesignerSettingManager::currentDefaulLanguageChanged(QLocale::Language language) +{ + m_setting->beginGroup("ReportDesigner"); + m_setting->setValue("DesignerLanguage", (int)language); + m_setting->endGroup(); +} diff --git a/designer/designersettingmanager.h b/designer/designersettingmanager.h new file mode 100644 index 0000000..2f07d79 --- /dev/null +++ b/designer/designersettingmanager.h @@ -0,0 +1,27 @@ +#ifndef DESIGNERSETTINGMANAGER_H +#define DESIGNERSETTINGMANAGER_H + +#include +#include +#include +#include + +class DesignerSettingManager : public QObject +{ + Q_OBJECT +public: + explicit DesignerSettingManager(QObject *parent = 0); + ~DesignerSettingManager(); + void setApplicationInstance(QApplication* application); +signals: + +public slots: + void getAviableLanguages(QList* languages); + QLocale::Language getCurrentDefaultLanguage(); + void currentDefaulLanguageChanged(QLocale::Language language); +private: + QApplication* m_app; + QSettings* m_setting; +}; + +#endif // DESIGNERSETTINGMANAGER_H diff --git a/designer/main.cpp b/designer/main.cpp index 9132b47..eeadf9b 100644 --- a/designer/main.cpp +++ b/designer/main.cpp @@ -1,25 +1,46 @@ #include #include #include +#include +#include "designersettingmanager.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); + DesignerSettingManager manager; QTranslator limeReportTranslator; QString translationPath = QApplication::applicationDirPath(); translationPath.append("/languages"); - limeReportTranslator.load("limereport_"+QLocale::system().name(),translationPath); + + QString designerTranslation = QLocale(manager.getCurrentDefaultLanguage()).name(); + + limeReportTranslator.load("limereport_"+designerTranslation, translationPath); a.installTranslator(&limeReportTranslator); QTranslator qtTranslator; - qtTranslator.load("qt_" + QLocale::system().name(),translationPath); + qtTranslator.load("qt_" + designerTranslation, translationPath); a.installTranslator(&qtTranslator); + Qt::LayoutDirection layoutDirection = QLocale(manager.getCurrentDefaultLanguage()).textDirection(); + LimeReport::ReportEngine report; + a.setLayoutDirection(layoutDirection); + report.setPreviewLayoutDirection(layoutDirection); + if (a.arguments().count()>1){ report.loadFromFile(a.arguments().at(1)); } + QObject::connect(&report, SIGNAL(getAviableLanguages(QList*)), + &manager, SLOT(getAviableLanguages(QList*))); + + QObject::connect(&report, SIGNAL(getCurrentDefaultLanguage()), + &manager, SLOT(getCurrentDefaultLanguage())); + + QObject::connect(&report, SIGNAL(currentDefaulLanguageChanged(QLocale::Language)), + &manager, SLOT(currentDefaulLanguageChanged(QLocale::Language))); + report.designReport(); return a.exec(); } + diff --git a/include/lrreportengine.h b/include/lrreportengine.h index 589e359..e6db8d0 100644 --- a/include/lrreportengine.h +++ b/include/lrreportengine.h @@ -113,6 +113,8 @@ public: bool setReportLanguage(QLocale::Language language); Qt::LayoutDirection previewLayoutDirection(); void setPreviewLayoutDirection(const Qt::LayoutDirection& previewLayoutDirection); + QList designerLanguages(); + QLocale::Language currentDesignerLanguage(); signals: void renderStarted(); void renderFinished(); @@ -120,6 +122,9 @@ signals: void onLoad(bool& loaded); void onSave(); void saveFinished(); + void getAviableLanguages(QList* languages); + void currentDefaulLanguageChanged(QLocale::Language); + QLocale::Language getCurrentDefaultLanguage(); public slots: void cancelRender(); protected: diff --git a/limereport/lrreportdesignwidget.cpp b/limereport/lrreportdesignwidget.cpp index b5585d8..96cd9eb 100644 --- a/limereport/lrreportdesignwidget.cpp +++ b/limereport/lrreportdesignwidget.cpp @@ -707,6 +707,7 @@ void ReportDesignWidget::editSetting() setting.setDefaultFont(m_defaultFont); setting.setSuppressAbsentFieldsAndVarsWarnings(m_report->suppressFieldAndVarError()); setting.setUseDarkTheme(m_useDarkTheme); + setting.setDesignerLanguages(m_report->designerLanguages(), m_report->currentDesignerLanguage()); if (setting.exec()){ m_horizontalGridStep = setting.horizontalGridStep(); @@ -714,6 +715,9 @@ void ReportDesignWidget::editSetting() m_defaultFont = setting.defaultFont(); m_useDarkTheme = setting.userDarkTheme(); m_report->setSuppressFieldAndVarError(setting.suppressAbsentFieldsAndVarsWarnings()); + if (m_report->currentDesignerLanguage() != setting.designerLanguage() ){ + m_report->setCurrentDesignerLanguage(setting.designerLanguage()); + } applySettings(); } } diff --git a/limereport/lrreportdesignwindow.h b/limereport/lrreportdesignwindow.h index 6f3dba6..1beb45a 100644 --- a/limereport/lrreportdesignwindow.h +++ b/limereport/lrreportdesignwindow.h @@ -71,7 +71,6 @@ public: QSettings* settings(); void restoreSetting(); void setShowProgressDialog(bool value){m_showProgressDialog = value;} - private slots: void slotNewReport(); void slotNewPage(); diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index e699459..53056db 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -957,6 +957,27 @@ void ReportEnginePrivate::activateLanguage(QLocale::Language language) } } +QList ReportEnginePrivate::designerLanguages() +{ + + QList result; + emit getAviableLanguages(&result); + return result; +} + +QLocale::Language ReportEnginePrivate::currentDesignerLanguage() +{ + QLocale::Language result = emit getCurrentDefaultLanguage(); + return result; +} + +void ReportEnginePrivate::setCurrentDesignerLanguage(QLocale::Language language) +{ + m_currentDesignerLanguage = language; + QMessageBox::information(m_designerWindow, tr("Warning") ,tr("The language will change after the application is restarted")); + emit currentDefaulLanguageChanged(language); +} + QString ReportEnginePrivate::styleSheet() const { return m_styleSheet; @@ -1138,7 +1159,15 @@ ReportEngine::ReportEngine(QObject *parent) connect(d, SIGNAL(onSave()), this, SIGNAL(onSave())); connect(d, SIGNAL(onLoad(bool&)), this, SIGNAL(onLoad(bool&))); connect(d, SIGNAL(saveFinished()), this, SIGNAL(saveFinished())); - connect(d, SIGNAL(loaded()), this, SIGNAL(loaded())); + connect(d, SIGNAL(loaded()), this, SIGNAL(loaded())); + + connect(d, SIGNAL(getAviableLanguages(QList*)), + this, SIGNAL(getAviableLanguages(QList*))); + connect(d, SIGNAL(currentDefaulLanguageChanged(QLocale::Language)), + this, SIGNAL(currentDefaulLanguageChanged(QLocale::Language))); + connect(d, SIGNAL(getCurrentDefaultLanguage()), + this, SIGNAL(getCurrentDefaultLanguage())); + } ReportEngine::~ReportEngine() @@ -1245,6 +1274,30 @@ bool ReportEngine::setReportLanguage(QLocale::Language language) return d->setReportLanguage(language); } +Qt::LayoutDirection ReportEngine::previewLayoutDirection() +{ + Q_D(ReportEngine); + return d->previewLayoutDirection(); +} + +void ReportEngine::setPreviewLayoutDirection(const Qt::LayoutDirection& previewLayoutDirection) +{ + Q_D(ReportEngine); + d->setPreviewLayoutDirection(previewLayoutDirection); +} + +QList ReportEngine::designerLanguages() +{ + Q_D(ReportEngine); + return d->designerLanguages(); +} + +QLocale::Language ReportEngine::currentDesignerLanguage() +{ + Q_D(ReportEngine); + return d->currentDesignerLanguage(); +} + void ReportEngine::setShowProgressDialog(bool value) { Q_D(ReportEngine); diff --git a/limereport/lrreportengine.h b/limereport/lrreportengine.h index bed2d88..6eed25a 100644 --- a/limereport/lrreportengine.h +++ b/limereport/lrreportengine.h @@ -113,6 +113,8 @@ public: bool setReportLanguage(QLocale::Language language); Qt::LayoutDirection previewLayoutDirection(); void setPreviewLayoutDirection(const Qt::LayoutDirection& previewLayoutDirection); + QList designerLanguages(); + QLocale::Language currentDesignerLanguage(); signals: void renderStarted(); void renderFinished(); @@ -120,7 +122,10 @@ signals: void onLoad(bool& loaded); void onSave(); void saveFinished(); - void loaded(); + void loaded(); + void getAviableLanguages(QList* languages); + void currentDefaulLanguageChanged(QLocale::Language); + QLocale::Language getCurrentDefaultLanguage(); public slots: void cancelRender(); protected: diff --git a/limereport/lrreportengine_p.h b/limereport/lrreportengine_p.h index d0bc16f..b3280d8 100644 --- a/limereport/lrreportengine_p.h +++ b/limereport/lrreportengine_p.h @@ -33,6 +33,7 @@ #include #include #include +#include #include "lrreportengine.h" #include "lrcollection.h" #include "lrglobal.h" @@ -83,6 +84,9 @@ public: virtual void setSuppressFieldAndVarError(bool suppressFieldAndVarError) = 0; virtual void setStyleSheet(const QString& styleSheet) = 0; virtual QString styleSheet() const = 0; + virtual QList designerLanguages() = 0; + virtual QLocale::Language currentDesignerLanguage() = 0; + virtual void setCurrentDesignerLanguage(QLocale::Language language) = 0; }; class ReportEnginePrivate : public QObject, public ICollectionContainer, public ITranslationContainer, @@ -178,7 +182,9 @@ public: void setPreviewLayoutDirection(const Qt::LayoutDirection& previewLayoutDirection); QString styleSheet() const; void setStyleSheet(const QString &styleSheet); - + QList designerLanguages(); + QLocale::Language currentDesignerLanguage(); + void setCurrentDesignerLanguage(QLocale::Language language); signals: void pagesLoadFinished(); void datasourceCollectionLoadFinished(const QString& collectionName); @@ -189,7 +195,10 @@ signals: void onLoad(bool& loaded); void onSave(); void saveFinished(); - void loaded(); + void loaded(); + void getAviableLanguages(QList* languages); + void currentDefaulLanguageChanged(QLocale::Language); + QLocale::Language getCurrentDefaultLanguage(); public slots: bool slotLoadFromFile(const QString& fileName); void cancelRender(); @@ -248,6 +257,7 @@ private: Qt::LayoutDirection m_previewLayoutDirection; LimeReportPluginInterface* m_designerFactory; QString m_styleSheet; + QLocale::Language m_currentDesignerLanguage; }; } diff --git a/limereport/lrsettingdialog.cpp b/limereport/lrsettingdialog.cpp index ee34440..b05fa74 100644 --- a/limereport/lrsettingdialog.cpp +++ b/limereport/lrsettingdialog.cpp @@ -47,6 +47,15 @@ bool SettingDialog::suppressAbsentFieldsAndVarsWarnings() return ui->cbSuppressWarnings->isChecked(); } +QLocale::Language SettingDialog::designerLanguage() +{ + foreach (QLocale::Language language, m_aviableLanguages) { + if (ui->designerLanguage->currentText().compare(QLocale::languageToString(language)) == 0) + return language; + } + return QLocale().language(); +} + void SettingDialog::setSuppressAbsentFieldsAndVarsWarnings(bool value){ ui->cbSuppressWarnings->setChecked(value); } @@ -72,4 +81,22 @@ void SettingDialog::setUseDarkTheme(bool value) ui->cbbUseDarkTheme->setChecked(value); } +void SettingDialog::setDesignerLanguages(QList languages, QLocale::Language currentLanguage) +{ + m_aviableLanguages = languages; + m_currentLanguage = currentLanguage; + + if (languages.isEmpty()) { + ui->designerLanguage->setVisible(false); + ui->lblLanguage->setVisible(false); + return; + } + ui->designerLanguage->addItem(QLocale::languageToString(currentLanguage)); + foreach (QLocale::Language language, languages) { + if (language != currentLanguage) + ui->designerLanguage->addItem(QLocale::languageToString(language)); + } + ui->designerLanguage->setCurrentText(QLocale::languageToString(currentLanguage)); +} + } // namespace LimeReport diff --git a/limereport/lrsettingdialog.h b/limereport/lrsettingdialog.h index db908f9..d4c89e3 100644 --- a/limereport/lrsettingdialog.h +++ b/limereport/lrsettingdialog.h @@ -2,6 +2,7 @@ #define LRSETTINGDIALOG_H #include +#include namespace LimeReport{ @@ -21,13 +22,17 @@ public: QFont defaultFont(); bool userDarkTheme(); bool suppressAbsentFieldsAndVarsWarnings(); + QLocale::Language designerLanguage(); void setSuppressAbsentFieldsAndVarsWarnings(bool value); void setHorizontalGridStep(int value); void setVerticalGridStep(int value); void setDefaultFont(const QFont& value); void setUseDarkTheme(bool value); + void setDesignerLanguages(QList languages, QLocale::Language currentLanguage); private: Ui::SettingDialog *ui; + QList m_aviableLanguages; + QLocale::Language m_currentLanguage; }; } // namespace LimeReport diff --git a/limereport/lrsettingdialog.ui b/limereport/lrsettingdialog.ui index b0dd1ed..fa7da68 100644 --- a/limereport/lrsettingdialog.ui +++ b/limereport/lrsettingdialog.ui @@ -6,10 +6,16 @@ 0 0 - 351 - 318 + 397 + 378 + + + 0 + 0 + + Designer setting @@ -108,6 +114,27 @@ + + + + + + Language + + + + + + + + 0 + 0 + + + + + +