Skip to content

Commit

Permalink
Add PDF orientation and page size (#5679)
Browse files Browse the repository at this point in the history
* Add PDF orientation and page size

* Use a boolean for lansscape/portrait setting
  • Loading branch information
boutinb authored and JorisGoosen committed Sep 30, 2024
1 parent 22ed321 commit a900fd1
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 20 deletions.
46 changes: 44 additions & 2 deletions Desktop/components/JASP/Widgets/FileMenu/PrefsResults.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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.pdfLandscape
onCheckedChanged: if (checked) preferencesModel.pdfLandscape = false

KeyNavigation.tab: pdfOrientationLandscape
}

RadioButton
{
id: pdfOrientationLandscape
label: qsTr("Landscape")
checked: preferencesModel.pdfLandscape
onCheckedChanged: if (checked) preferencesModel.pdfLandscape = true

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")
Expand All @@ -165,7 +208,6 @@ ScrollView
}
}


Item
{
id: extraSpaceForScrolling
Expand Down
2 changes: 1 addition & 1 deletion Desktop/components/JASP/Widgets/MainPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ Item

function onExportToPDF(pdfPath)
{
resultsView.printToPdf(pdfPath);
resultsView.printToPdf(pdfPath, preferencesModel.pdfPageSize, preferencesModel.pdfLandscape ? WebEngineView.Landscape : WebEngineView.Portrait);
}

function onPrepForExport()
Expand Down
2 changes: 2 additions & 0 deletions Desktop/gui/pdfdefinition.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#define ENUM_DECLARATION_CPP
#include "pdfdefinition.h"
7 changes: 7 additions & 0 deletions Desktop/gui/pdfdefinition.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef PDFDEFINITION_H
#define PDFDEFINITION_H
#include "enumutilities.h"

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
24 changes: 15 additions & 9 deletions Desktop/gui/preferencesmodel.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ PreferencesModel::PreferencesModel(QObject *parent) :

_loadDatabaseFont();

for(auto pdfPageSizeElt : pdfPageSizeToVector())
{
QMap<QString, QVariant> map =
{
std::make_pair("value", int(pdfPageSizeElt)),
std::make_pair("label", pdfPageSizeToQString(pdfPageSizeElt)),
};

_pdfPageSizeModel.append(map);
}

dataLabelNAChangedSlot(dataLabelNA());
}

Expand Down Expand Up @@ -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_BOOL( pdfLandscape, Settings::PDF_LANDSCAPE )
GET_PREF_FUNC_INT( pdfPageSize, Settings::PDF_PAGESIZE )

int PreferencesModel::maxEngines() const
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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( bool, setPdfLandscape, pdfLandscape, pdfLandscapeChanged, Settings::PDF_LANDSCAPE )
SET_PREF_FUNCTION( int, setPdfPageSize, pdfPageSize, pdfPageSizeChanged, Settings::PDF_PAGESIZE )

void PreferencesModel::setGithubPatCustom(QString newPat)
{
Expand Down
19 changes: 17 additions & 2 deletions Desktop/gui/preferencesmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

#include <QObject>
#include <QFont>
#include <QVariantList>
#include "preferencesmodelbase.h"
#include "pdfdefinition.h"

class JaspTheme;

Expand Down Expand Up @@ -70,9 +72,14 @@ 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(bool pdfLandscape READ pdfLandscape WRITE setPdfLandscape NOTIFY pdfLandscapeChanged )


public:


explicit PreferencesModel(QObject *parent = 0);

static PreferencesModel * prefs() { return qobject_cast<PreferencesModel*>(_singleton); }
Expand Down Expand Up @@ -136,7 +143,10 @@ class PreferencesModel : public PreferencesModelBase
bool ALTNavModeActive() const;
bool orderByValueByDefault() const;
int maxScaleLevels() const override;

QVariantList pdfPageSizeModel() const { return _pdfPageSizeModel; }
int pdfPageSize() const;
bool pdfLandscape() const;

bool checkUpdatesAskUser() const;
void setCheckUpdatesAskUser(bool newCheckUpdatesAskUser);

Expand Down Expand Up @@ -201,6 +211,8 @@ public slots:
void setALTNavModeActive( bool ALTNavModeActive);
void setOrderByValueByDefault( bool orderByValueByDefault);
void setMaxScaleLevels( int maxScaleLevels);
void setPdfPageSize( int pdfPageSize);
void setPdfLandscape( bool pdfLandscape);

signals:
void fixedDecimalsChanged( bool fixedDecimals);
Expand Down Expand Up @@ -254,7 +266,9 @@ public slots:
void checkUpdatesAskUserChanged( bool checkAsk);
void checkUpdatesChanged( bool check);
void maxScaleLevelsChanged( int maxScaleLevels);

void pdfPageSizeChanged( int pdfPageSize);
void pdfLandscapeChanged( bool pdfLandscape);

private slots:
void dataLabelNAChangedSlot(QString label);

Expand All @@ -265,6 +279,7 @@ private slots:
_allInterfaceFonts,
_allResultFonts,
_allCodeFonts;
QVariantList _pdfPageSizeModel;
bool _githubPatCustom; //Should be initialized on prefs construction

void _loadDatabaseFont();
Expand Down
9 changes: 5 additions & 4 deletions Desktop/html/css/printing.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion Desktop/utilities/settings.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "settings.h"
#include "resultstesting/compareresults.h"
#include "gui/pdfdefinition.h"

QSettings* Settings::_settings = nullptr;

Expand Down Expand Up @@ -92,7 +93,9 @@ const Settings::Setting Settings::Values[] = {
{"checkUpdatesAskUser", true },
{"checkUpdates", false },
{"checkUpdatesLastTime", -1 },
{"maxScaleLevels", 100 }
{"maxScaleLevels", 100 },
{"pdfLandscape", false },
{"pdfPageSize", int(pdfPageSize::A4) }

};

Expand Down
4 changes: 3 additions & 1 deletion Desktop/utilities/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ class Settings {
CHECK_UPDATES_ASK_USER,
CHECK_UPDATES,
LAST_CHECK,
MAX_SCALE_LEVELS
MAX_SCALE_LEVELS,
PDF_LANDSCAPE,
PDF_PAGESIZE
};

static QVariant value(Settings::Type key);
Expand Down

0 comments on commit a900fd1

Please sign in to comment.