From 26f22626114f0c254947e711282563fdedb04aa4 Mon Sep 17 00:00:00 2001 From: boutinb Date: Thu, 26 Sep 2024 15:05:25 +0200 Subject: [PATCH 1/2] Add PDF orientation and page size --- .../JASP/Widgets/FileMenu/PrefsResults.qml | 46 ++++++++++++++++++- Desktop/components/JASP/Widgets/MainPage.qml | 2 +- Desktop/gui/pdfdefinition.cpp | 2 + Desktop/gui/pdfdefinition.h | 8 ++++ Desktop/gui/preferencesmodel.cpp.in | 24 ++++++---- Desktop/gui/preferencesmodel.h | 23 +++++++++- Desktop/html/css/printing.css | 9 ++-- Desktop/utilities/settings.cpp | 5 +- Desktop/utilities/settings.h | 4 +- 9 files changed, 103 insertions(+), 20 deletions(-) create mode 100644 Desktop/gui/pdfdefinition.cpp create mode 100644 Desktop/gui/pdfdefinition.h diff --git a/Desktop/components/JASP/Widgets/FileMenu/PrefsResults.qml b/Desktop/components/JASP/Widgets/FileMenu/PrefsResults.qml index c5601c1681..b265dc6dc0 100644 --- a/Desktop/components/JASP/Widgets/FileMenu/PrefsResults.qml +++ b/Desktop/components/JASP/Widgets/FileMenu/PrefsResults.qml @@ -142,11 +142,54 @@ ScrollView onCheckedChanged: preferencesModel.whiteBackground = !checked toolTip: qsTr("This makes the background of all plots transparent, quite useful if you want to use it seamlessly on any background that isn't white.") - KeyNavigation.tab: showRSyntaxInResults + KeyNavigation.tab: pdfOrientationLandscape } } } + PrefsGroupRect + { + title: qsTr("PDF Settings") + + RadioButtonGroup + { + id: pdfOrientation + title: qsTr("Orientation") + + RadioButton + { + id: pdfOrientationPortrait + label: qsTr("Portrait") + checked: preferencesModel.pdfOrientation === preferencesModel.pdfPortrait + onCheckedChanged: if (checked) preferencesModel.pdfOrientation = preferencesModel.pdfPortrait + + KeyNavigation.tab: pdfOrientationLandscape + } + + RadioButton + { + id: pdfOrientationLandscape + label: qsTr("Landsacpe") + checked: preferencesModel.pdfOrientation === preferencesModel.pdfLandscape + onCheckedChanged: if (checked) preferencesModel.pdfOrientation = preferencesModel.pdfLandscape + + KeyNavigation.tab: pdfPageSize + } + } + + DropDown + { + id: pdfPageSize + label: qsTr("Page size") + values: preferencesModel.pdfPageSizeModel + startValue: preferencesModel.pdfPageSize + onValueChanged: preferencesModel.pdfPageSize = value + + KeyNavigation.tab: showRSyntaxInResults + } + + } + PrefsGroupRect { title: qsTr("Miscellaneous options") @@ -165,7 +208,6 @@ ScrollView } } - Item { id: extraSpaceForScrolling diff --git a/Desktop/components/JASP/Widgets/MainPage.qml b/Desktop/components/JASP/Widgets/MainPage.qml index dbd98d3e96..448cdc2abf 100644 --- a/Desktop/components/JASP/Widgets/MainPage.qml +++ b/Desktop/components/JASP/Widgets/MainPage.qml @@ -403,7 +403,7 @@ Item function onExportToPDF(pdfPath) { - resultsView.printToPdf(pdfPath); + resultsView.printToPdf(pdfPath, preferencesModel.pdfPageSize, preferencesModel.pdfOrientation); } function onPrepForExport() diff --git a/Desktop/gui/pdfdefinition.cpp b/Desktop/gui/pdfdefinition.cpp new file mode 100644 index 0000000000..4e5f210e2c --- /dev/null +++ b/Desktop/gui/pdfdefinition.cpp @@ -0,0 +1,2 @@ +#define ENUM_DECLARATION_CPP +#include "pdfdefinition.h" diff --git a/Desktop/gui/pdfdefinition.h b/Desktop/gui/pdfdefinition.h new file mode 100644 index 0000000000..c46255434b --- /dev/null +++ b/Desktop/gui/pdfdefinition.h @@ -0,0 +1,8 @@ +#ifndef PDFDEFINITION_H +#define PDFDEFINITION_H +#include "enumutilities.h" + +DECLARE_ENUM(pdfOrientation, portrait = 0, landscape); // Cf https://doc.qt.io/qt-6/qpagelayout.html#Orientation-enum +DECLARE_ENUM(pdfPageSize, letter = 0, legal, executive, A0, A1, A2, A3, A4, A5, A6); // Cf https://doc.qt.io/qt-6/qpagesize.html#PageSizeId-enum + +#endif // PDFDEFINITION_H diff --git a/Desktop/gui/preferencesmodel.cpp.in b/Desktop/gui/preferencesmodel.cpp.in index b9d36d3897..664b120a79 100644 --- a/Desktop/gui/preferencesmodel.cpp.in +++ b/Desktop/gui/preferencesmodel.cpp.in @@ -35,6 +35,17 @@ PreferencesModel::PreferencesModel(QObject *parent) : _loadDatabaseFont(); + for(auto pdfPageSizeElt : pdfPageSizeToVector()) + { + QMap map = + { + std::make_pair("value", int(pdfPageSizeElt)), + std::make_pair("label", pdfPageSizeToQString(pdfPageSizeElt)), + }; + + _pdfPageSizeModel.append(map); + } + dataLabelNAChangedSlot(dataLabelNA()); } @@ -125,6 +136,8 @@ GET_PREF_FUNC_BOOL( orderByValueByDefault, Settings::ORDER_BY_VALUE_BY_DEFAULT GET_PREF_FUNC_BOOL( checkUpdatesAskUser, Settings::CHECK_UPDATES_ASK_USER ) GET_PREF_FUNC_BOOL( checkUpdates, Settings::CHECK_UPDATES ) GET_PREF_FUNC_INT( maxScaleLevels, Settings::MAX_SCALE_LEVELS ) +GET_PREF_FUNC_INT( pdfOrientation, Settings::PDF_ORIENTATION ) +GET_PREF_FUNC_INT( pdfPageSize, Settings::PDF_PAGESIZE ) int PreferencesModel::maxEngines() const { @@ -253,14 +266,6 @@ void PreferencesModel::FUNC_NAME(TYPE newVal) \ emit NOTIFY(); \ } -#define SET_PREF_FUNCTION_EMIT_NO_ARG(TYPE, FUNC_NAME, GET_FUNC, NOTIFY, SETTING) \ -void PreferencesModel::FUNC_NAME(TYPE newVal) \ -{ \ - if(GET_FUNC() == newVal) return; \ - Settings::setValue(SETTING, newVal); \ - emit NOTIFY(); \ -} - void PreferencesModel::setCurrentThemeName(QString _currentThemeName) { if (currentThemeName() == _currentThemeName) return; @@ -307,7 +312,8 @@ SET_PREF_FUNCTION( bool, setOrderByValueByDefault, orderByValueByDefault, o SET_PREF_FUNCTION( bool, setCheckUpdatesAskUser, checkUpdatesAskUser, checkUpdatesAskUserChanged, Settings::CHECK_UPDATES_ASK_USER ) SET_PREF_FUNCTION( bool, setCheckUpdates, checkUpdates, checkUpdatesChanged, Settings::CHECK_UPDATES ) SET_PREF_FUNCTION( int, setMaxScaleLevels, maxScaleLevels, maxScaleLevelsChanged, Settings::MAX_SCALE_LEVELS ) - +SET_PREF_FUNCTION( int, setPdfOrientation, pdfOrientation, pdfOrientationChanged, Settings::PDF_ORIENTATION ) +SET_PREF_FUNCTION( int, setPdfPageSize, pdfPageSize, pdfPageSizeChanged, Settings::PDF_PAGESIZE ) void PreferencesModel::setGithubPatCustom(QString newPat) { diff --git a/Desktop/gui/preferencesmodel.h b/Desktop/gui/preferencesmodel.h index f87f2ed508..5b5b2caea8 100644 --- a/Desktop/gui/preferencesmodel.h +++ b/Desktop/gui/preferencesmodel.h @@ -3,7 +3,9 @@ #include #include +#include #include "preferencesmodelbase.h" +#include "pdfdefinition.h" class JaspTheme; @@ -70,9 +72,16 @@ class PreferencesModel : public PreferencesModelBase Q_PROPERTY(bool checkUpdatesAskUser READ checkUpdatesAskUser WRITE setCheckUpdatesAskUser NOTIFY checkUpdatesAskUserChanged ) Q_PROPERTY(bool checkUpdates READ checkUpdates WRITE setCheckUpdates NOTIFY checkUpdatesChanged ) Q_PROPERTY(int maxScaleLevels READ maxScaleLevels WRITE setMaxScaleLevels NOTIFY maxScaleLevelsChanged ) + Q_PROPERTY(QVariantList pdfPageSizeModel READ pdfPageSizeModel CONSTANT ) + Q_PROPERTY(int pdfPageSize READ pdfPageSize WRITE setPdfPageSize NOTIFY pdfPageSizeChanged ) + Q_PROPERTY(int pdfOrientation READ pdfOrientation WRITE setPdfOrientation NOTIFY pdfOrientationChanged ) + Q_PROPERTY(int pdfLandscape READ pdfLandscape CONSTANT ) + Q_PROPERTY(int pdfPortrait READ pdfPortrait CONSTANT ) public: + + explicit PreferencesModel(QObject *parent = 0); static PreferencesModel * prefs() { return qobject_cast(_singleton); } @@ -136,7 +145,12 @@ class PreferencesModel : public PreferencesModelBase bool ALTNavModeActive() const; bool orderByValueByDefault() const; int maxScaleLevels() const override; - + QVariantList pdfPageSizeModel() const { return _pdfPageSizeModel; } + int pdfPageSize() const; + int pdfOrientation() const; + int pdfPortrait() const { return int(pdfOrientation::portrait); } + int pdfLandscape() const { return int(pdfOrientation::landscape); } + bool checkUpdatesAskUser() const; void setCheckUpdatesAskUser(bool newCheckUpdatesAskUser); @@ -201,6 +215,8 @@ public slots: void setALTNavModeActive( bool ALTNavModeActive); void setOrderByValueByDefault( bool orderByValueByDefault); void setMaxScaleLevels( int maxScaleLevels); + void setPdfPageSize( int pdfPageSize); + void setPdfOrientation( int pdfOrientation); signals: void fixedDecimalsChanged( bool fixedDecimals); @@ -254,7 +270,9 @@ public slots: void checkUpdatesAskUserChanged( bool checkAsk); void checkUpdatesChanged( bool check); void maxScaleLevelsChanged( int maxScaleLevels); - + void pdfPageSizeChanged( int pdfPageSize); + void pdfOrientationChanged( int pdfOrientation); + private slots: void dataLabelNAChangedSlot(QString label); @@ -265,6 +283,7 @@ private slots: _allInterfaceFonts, _allResultFonts, _allCodeFonts; + QVariantList _pdfPageSizeModel; bool _githubPatCustom; //Should be initialized on prefs construction void _loadDatabaseFont(); diff --git a/Desktop/html/css/printing.css b/Desktop/html/css/printing.css index 4ed695b310..4501601070 100644 --- a/Desktop/html/css/printing.css +++ b/Desktop/html/css/printing.css @@ -51,16 +51,17 @@ .jasp-table-primitive { page-break-inside: avoid; } - .jasp-table table { + /* .jasp-table table { table-layout:fixed !important; - width: 20cm !important; - } + width: 100% !important; + } */ + .jasp-table table td { white-space: pre-wrap !important; word-wrap: break-all !important; } .jasp-rsyntax-container { - max-width: 20cm !important; + max-width: 95% !important; } } @page { diff --git a/Desktop/utilities/settings.cpp b/Desktop/utilities/settings.cpp index 5791e67358..c9f2e49d15 100644 --- a/Desktop/utilities/settings.cpp +++ b/Desktop/utilities/settings.cpp @@ -1,5 +1,6 @@ #include "settings.h" #include "resultstesting/compareresults.h" +#include "gui/pdfdefinition.h" QSettings* Settings::_settings = nullptr; @@ -92,7 +93,9 @@ const Settings::Setting Settings::Values[] = { {"checkUpdatesAskUser", true }, {"checkUpdates", false }, {"checkUpdatesLastTime", -1 }, - {"maxScaleLevels", 100 } + {"maxScaleLevels", 100 }, + {"pdfOrientation", int(pdfOrientation::landscape) }, + {"pdfPageSize", int(pdfPageSize::A4) } }; diff --git a/Desktop/utilities/settings.h b/Desktop/utilities/settings.h index 9f8cfe83cb..f80665e910 100644 --- a/Desktop/utilities/settings.h +++ b/Desktop/utilities/settings.h @@ -77,7 +77,9 @@ class Settings { CHECK_UPDATES_ASK_USER, CHECK_UPDATES, LAST_CHECK, - MAX_SCALE_LEVELS + MAX_SCALE_LEVELS, + PDF_ORIENTATION, + PDF_PAGESIZE }; static QVariant value(Settings::Type key); From edf6da56cc7648942708c097913ad5605bcb116d Mon Sep 17 00:00:00 2001 From: boutinb Date: Mon, 30 Sep 2024 11:44:21 +0200 Subject: [PATCH 2/2] Use a boolean for lansscape/portrait setting --- .../JASP/Widgets/FileMenu/PrefsResults.qml | 10 +++++----- Desktop/components/JASP/Widgets/MainPage.qml | 2 +- Desktop/gui/pdfdefinition.h | 1 - Desktop/gui/preferencesmodel.cpp.in | 4 ++-- Desktop/gui/preferencesmodel.h | 12 ++++-------- Desktop/utilities/settings.cpp | 2 +- Desktop/utilities/settings.h | 2 +- 7 files changed, 14 insertions(+), 19 deletions(-) diff --git a/Desktop/components/JASP/Widgets/FileMenu/PrefsResults.qml b/Desktop/components/JASP/Widgets/FileMenu/PrefsResults.qml index b265dc6dc0..f9698486d9 100644 --- a/Desktop/components/JASP/Widgets/FileMenu/PrefsResults.qml +++ b/Desktop/components/JASP/Widgets/FileMenu/PrefsResults.qml @@ -160,8 +160,8 @@ ScrollView { id: pdfOrientationPortrait label: qsTr("Portrait") - checked: preferencesModel.pdfOrientation === preferencesModel.pdfPortrait - onCheckedChanged: if (checked) preferencesModel.pdfOrientation = preferencesModel.pdfPortrait + checked: !preferencesModel.pdfLandscape + onCheckedChanged: if (checked) preferencesModel.pdfLandscape = false KeyNavigation.tab: pdfOrientationLandscape } @@ -169,9 +169,9 @@ ScrollView RadioButton { id: pdfOrientationLandscape - label: qsTr("Landsacpe") - checked: preferencesModel.pdfOrientation === preferencesModel.pdfLandscape - onCheckedChanged: if (checked) preferencesModel.pdfOrientation = preferencesModel.pdfLandscape + label: qsTr("Landscape") + checked: preferencesModel.pdfLandscape + onCheckedChanged: if (checked) preferencesModel.pdfLandscape = true KeyNavigation.tab: pdfPageSize } diff --git a/Desktop/components/JASP/Widgets/MainPage.qml b/Desktop/components/JASP/Widgets/MainPage.qml index 448cdc2abf..68ac065c4a 100644 --- a/Desktop/components/JASP/Widgets/MainPage.qml +++ b/Desktop/components/JASP/Widgets/MainPage.qml @@ -403,7 +403,7 @@ Item function onExportToPDF(pdfPath) { - resultsView.printToPdf(pdfPath, preferencesModel.pdfPageSize, preferencesModel.pdfOrientation); + resultsView.printToPdf(pdfPath, preferencesModel.pdfPageSize, preferencesModel.pdfLandscape ? WebEngineView.Landscape : WebEngineView.Portrait); } function onPrepForExport() diff --git a/Desktop/gui/pdfdefinition.h b/Desktop/gui/pdfdefinition.h index c46255434b..5c1eb37fc7 100644 --- a/Desktop/gui/pdfdefinition.h +++ b/Desktop/gui/pdfdefinition.h @@ -2,7 +2,6 @@ #define PDFDEFINITION_H #include "enumutilities.h" -DECLARE_ENUM(pdfOrientation, portrait = 0, landscape); // Cf https://doc.qt.io/qt-6/qpagelayout.html#Orientation-enum DECLARE_ENUM(pdfPageSize, letter = 0, legal, executive, A0, A1, A2, A3, A4, A5, A6); // Cf https://doc.qt.io/qt-6/qpagesize.html#PageSizeId-enum #endif // PDFDEFINITION_H diff --git a/Desktop/gui/preferencesmodel.cpp.in b/Desktop/gui/preferencesmodel.cpp.in index 664b120a79..2ee6fcc3c1 100644 --- a/Desktop/gui/preferencesmodel.cpp.in +++ b/Desktop/gui/preferencesmodel.cpp.in @@ -136,7 +136,7 @@ GET_PREF_FUNC_BOOL( orderByValueByDefault, Settings::ORDER_BY_VALUE_BY_DEFAULT GET_PREF_FUNC_BOOL( checkUpdatesAskUser, Settings::CHECK_UPDATES_ASK_USER ) GET_PREF_FUNC_BOOL( checkUpdates, Settings::CHECK_UPDATES ) GET_PREF_FUNC_INT( maxScaleLevels, Settings::MAX_SCALE_LEVELS ) -GET_PREF_FUNC_INT( pdfOrientation, Settings::PDF_ORIENTATION ) +GET_PREF_FUNC_BOOL( pdfLandscape, Settings::PDF_LANDSCAPE ) GET_PREF_FUNC_INT( pdfPageSize, Settings::PDF_PAGESIZE ) int PreferencesModel::maxEngines() const @@ -312,7 +312,7 @@ SET_PREF_FUNCTION( bool, setOrderByValueByDefault, orderByValueByDefault, o SET_PREF_FUNCTION( bool, setCheckUpdatesAskUser, checkUpdatesAskUser, checkUpdatesAskUserChanged, Settings::CHECK_UPDATES_ASK_USER ) SET_PREF_FUNCTION( bool, setCheckUpdates, checkUpdates, checkUpdatesChanged, Settings::CHECK_UPDATES ) SET_PREF_FUNCTION( int, setMaxScaleLevels, maxScaleLevels, maxScaleLevelsChanged, Settings::MAX_SCALE_LEVELS ) -SET_PREF_FUNCTION( int, setPdfOrientation, pdfOrientation, pdfOrientationChanged, Settings::PDF_ORIENTATION ) +SET_PREF_FUNCTION( bool, setPdfLandscape, pdfLandscape, pdfLandscapeChanged, Settings::PDF_LANDSCAPE ) SET_PREF_FUNCTION( int, setPdfPageSize, pdfPageSize, pdfPageSizeChanged, Settings::PDF_PAGESIZE ) void PreferencesModel::setGithubPatCustom(QString newPat) diff --git a/Desktop/gui/preferencesmodel.h b/Desktop/gui/preferencesmodel.h index 5b5b2caea8..472dcba94b 100644 --- a/Desktop/gui/preferencesmodel.h +++ b/Desktop/gui/preferencesmodel.h @@ -74,9 +74,7 @@ class PreferencesModel : public PreferencesModelBase Q_PROPERTY(int maxScaleLevels READ maxScaleLevels WRITE setMaxScaleLevels NOTIFY maxScaleLevelsChanged ) Q_PROPERTY(QVariantList pdfPageSizeModel READ pdfPageSizeModel CONSTANT ) Q_PROPERTY(int pdfPageSize READ pdfPageSize WRITE setPdfPageSize NOTIFY pdfPageSizeChanged ) - Q_PROPERTY(int pdfOrientation READ pdfOrientation WRITE setPdfOrientation NOTIFY pdfOrientationChanged ) - Q_PROPERTY(int pdfLandscape READ pdfLandscape CONSTANT ) - Q_PROPERTY(int pdfPortrait READ pdfPortrait CONSTANT ) + Q_PROPERTY(bool pdfLandscape READ pdfLandscape WRITE setPdfLandscape NOTIFY pdfLandscapeChanged ) public: @@ -147,9 +145,7 @@ class PreferencesModel : public PreferencesModelBase int maxScaleLevels() const override; QVariantList pdfPageSizeModel() const { return _pdfPageSizeModel; } int pdfPageSize() const; - int pdfOrientation() const; - int pdfPortrait() const { return int(pdfOrientation::portrait); } - int pdfLandscape() const { return int(pdfOrientation::landscape); } + bool pdfLandscape() const; bool checkUpdatesAskUser() const; void setCheckUpdatesAskUser(bool newCheckUpdatesAskUser); @@ -216,7 +212,7 @@ public slots: void setOrderByValueByDefault( bool orderByValueByDefault); void setMaxScaleLevels( int maxScaleLevels); void setPdfPageSize( int pdfPageSize); - void setPdfOrientation( int pdfOrientation); + void setPdfLandscape( bool pdfLandscape); signals: void fixedDecimalsChanged( bool fixedDecimals); @@ -271,7 +267,7 @@ public slots: void checkUpdatesChanged( bool check); void maxScaleLevelsChanged( int maxScaleLevels); void pdfPageSizeChanged( int pdfPageSize); - void pdfOrientationChanged( int pdfOrientation); + void pdfLandscapeChanged( bool pdfLandscape); private slots: void dataLabelNAChangedSlot(QString label); diff --git a/Desktop/utilities/settings.cpp b/Desktop/utilities/settings.cpp index c9f2e49d15..d267d65511 100644 --- a/Desktop/utilities/settings.cpp +++ b/Desktop/utilities/settings.cpp @@ -94,7 +94,7 @@ const Settings::Setting Settings::Values[] = { {"checkUpdates", false }, {"checkUpdatesLastTime", -1 }, {"maxScaleLevels", 100 }, - {"pdfOrientation", int(pdfOrientation::landscape) }, + {"pdfLandscape", false }, {"pdfPageSize", int(pdfPageSize::A4) } }; diff --git a/Desktop/utilities/settings.h b/Desktop/utilities/settings.h index f80665e910..4adbdf1598 100644 --- a/Desktop/utilities/settings.h +++ b/Desktop/utilities/settings.h @@ -78,7 +78,7 @@ class Settings { CHECK_UPDATES, LAST_CHECK, MAX_SCALE_LEVELS, - PDF_ORIENTATION, + PDF_LANDSCAPE, PDF_PAGESIZE };