diff --git a/backend-shared/exportfuncs.cpp b/backend-shared/exportfuncs.cpp index 2b33acf51..35586b2dd 100644 --- a/backend-shared/exportfuncs.cpp +++ b/backend-shared/exportfuncs.cpp @@ -52,9 +52,8 @@ static void exportProfile(ProfileWidget2 *profile, const struct dive *dive, cons static std::unique_ptr getPrintProfile() { - auto profile = std::make_unique(nullptr, nullptr); + auto profile = std::make_unique(nullptr, (double)profileScale, nullptr); profile->setPrintMode(true); - profile->setFontPrintScale((double)profileScale); return profile; } diff --git a/desktop-widgets/diveplanner.cpp b/desktop-widgets/diveplanner.cpp index ad1b9a276..83aced4bb 100644 --- a/desktop-widgets/diveplanner.cpp +++ b/desktop-widgets/diveplanner.cpp @@ -609,7 +609,7 @@ void PlannerWidgets::printDecoPlan() painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::SmoothPixmapTransform); - auto profile = std::make_unique(DivePlannerPointsModel::instance(), nullptr); + auto profile = std::make_unique(DivePlannerPointsModel::instance(), 1.0, nullptr); profile->setPlanState(&displayed_dive, 0); profile->plotDive(&displayed_dive, 0, true, true); profile->setPrintMode(true); diff --git a/desktop-widgets/printer.cpp b/desktop-widgets/printer.cpp index 7b083bb21..269867d9a 100644 --- a/desktop-widgets/printer.cpp +++ b/desktop-widgets/printer.cpp @@ -102,8 +102,14 @@ void Printer::flowRender() void Printer::render(int pages) { - auto profile = std::make_unique(nullptr, nullptr); - double printFontScale = 1.0; + // get all refereces to diveprofile class in the Html template + QWebElementCollection collection = webView->page()->mainFrame()->findAllElements(".diveprofile"); + + // A "standard" profile has about 600 pixels in height. + // Scale the fonts in the printed profile accordingly. + // This is arbitrary, but it seems to work reasonably well. + double printFontScale = collection.count() > 0 ? collection[0].geometry().size().height() / 600.0 : 1.0; + auto profile = std::make_unique(nullptr, printFontScale, nullptr); // apply printing settings to profile profile->setFrameStyle(QFrame::NoFrame); @@ -116,18 +122,6 @@ void Printer::render(int pages) painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::SmoothPixmapTransform); - // get all refereces to diveprofile class in the Html template - QWebElementCollection collection = webView->page()->mainFrame()->findAllElements(".diveprofile"); - - if (collection.count() > 0) { - // A "standard" profile has about 600 pixels in height. - // Scale the fonts in the printed profile accordingly. - // This is arbitrary, but it seems to work reasonably. - QSize size = collection[0].geometry().size(); - printFontScale = size.height() / 600.0; - } - profile->setFontPrintScale(printFontScale); - int elemNo = 0; for (int i = 0; i < pages; i++) { // render the base Html template diff --git a/desktop-widgets/profilewidget.cpp b/desktop-widgets/profilewidget.cpp index 96335790a..2b1b28c83 100644 --- a/desktop-widgets/profilewidget.cpp +++ b/desktop-widgets/profilewidget.cpp @@ -26,7 +26,7 @@ ProfileWidget::ProfileWidget() ui.profHR, // very few dive computers support this ui.profTissues }; // maybe less frequently used - view.reset(new ProfileWidget2(DivePlannerPointsModel::instance(), this)); + view.reset(new ProfileWidget2(DivePlannerPointsModel::instance(), 1.0, this)); QToolBar *toolBar = new QToolBar(this); for (QAction *a: toolbarActions) toolBar->addAction(a); diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 519f58e33..7bded1de3 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -95,7 +95,7 @@ T *ProfileWidget2::createItem(const DiveCartesianAxis &vAxis, int vColumn, int z return res; } -ProfileWidget2::ProfileWidget2(DivePlannerPointsModel *plannerModelIn, QWidget *parent) : QGraphicsView(parent), +ProfileWidget2::ProfileWidget2(DivePlannerPointsModel *plannerModelIn, double fontPrintScale, QWidget *parent) : QGraphicsView(parent), currentState(INVALID), dataModel(new DivePlotDataModel(this)), plannerModel(plannerModelIn), @@ -139,7 +139,7 @@ ProfileWidget2::ProfileWidget2(DivePlannerPointsModel *plannerModelIn, QWidget * #endif tankItem(new TankItem(*timeAxis)), shouldCalculateMax(true), - fontPrintScale(1.0) + fontPrintScale(fontPrintScale) { init_plot_info(&plotInfo); diff --git a/profile-widget/profilewidget2.h b/profile-widget/profilewidget2.h index 8af7f8dad..3d2eea781 100644 --- a/profile-widget/profilewidget2.h +++ b/profile-widget/profilewidget2.h @@ -66,7 +66,7 @@ public: }; // Pass null as plannerModel if no support for planning required - ProfileWidget2(DivePlannerPointsModel *plannerModel, QWidget *parent = 0); + ProfileWidget2(DivePlannerPointsModel *plannerModel, double fontPrintScale, QWidget *parent = 0); ~ProfileWidget2(); void resetZoom(); void scale(qreal sx, qreal sy); diff --git a/profile-widget/qmlprofile.cpp b/profile-widget/qmlprofile.cpp index 3d664c9a3..24c57caa7 100644 --- a/profile-widget/qmlprofile.cpp +++ b/profile-widget/qmlprofile.cpp @@ -28,10 +28,9 @@ QMLProfile::QMLProfile(QQuickItem *parent) : void QMLProfile::createProfileView() { - m_profileWidget.reset(new ProfileWidget2(nullptr, nullptr)); + m_profileWidget.reset(new ProfileWidget2(nullptr, fontScale * m_devicePixelRatio, nullptr)); m_profileWidget->setProfileState(nullptr, 0); m_profileWidget->setPrintMode(true); - m_profileWidget->setFontPrintScale(fontScale * m_devicePixelRatio); } // we need this so we can connect update() to the scaleChanged() signal - which the connect above cannot do