Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PDF orientation and page size #5679

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok pagesize has more options then I thought. But the question still stands for portrait and landscape...


#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;
Copy link
Contributor

@shun2wang shun2wang Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why comment this out, now jasp-table will be cut-off while printing a multiple cols table. I think overlap is better than cut off because cut off cannot be noticed easily by users.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This css obliged the table to be 20 cm wide (even if the table is self much smaller). This allows table that are wider than 20 cm to fit in a A4 format, but most of the time it is not a valid solution since the table is squeezed, and the columns overlapped each other.
To set it explicitly to 20cm does not work anyway for landscape print (or for other page size).
If I set the the width to 100% (with the table-layout fixed), then it fits the landscape size, but then all tables are as wide as the whole width of the page.
Unfortunately, the max-width does not work with table-layout fixed, this would be in fact what we are looking for.
As I cannot see a right solution here, I prefer to remove this setting.
I find the argument that the cut-off might not be noticed by users, a bit poor compared to the problems this setting generate. I find we see quite easily that a part of a table misses when it is too big.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, set 20cm explicitly is only for A4.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could set the exact size for each different combination of pagesize + orientation. But I wouldnt want to hold up the PR for that :p

} */

.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
Loading