summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--desktop-widgets/mainwindow.cpp29
-rw-r--r--profile-widget/profilewidget2.cpp1
2 files changed, 30 insertions, 0 deletions
diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp
index 5e80a345b..356196dad 100644
--- a/desktop-widgets/mainwindow.cpp
+++ b/desktop-widgets/mainwindow.cpp
@@ -28,6 +28,7 @@
#include "diveplanner.h"
#ifndef NO_PRINTING
#include <QPrintDialog>
+#include <QBuffer>
#include "printdialog.h"
#endif
#include "tankinfomodel.h"
@@ -768,6 +769,34 @@ void MainWindow::printPlan()
if (dialog->exec() != QDialog::Accepted)
return;
+ /* render the profile as a pixmap that is inserted as base64 data into a HTML <img> tag
+ * make it fit a page width defined by 2 cm margins via QTextDocument->print() (cannot be changed?)
+ * the height of the profile is 40% of the page height.
+ */
+ QSizeF renderSize = printer.pageRect(QPrinter::Inch).size();
+ const qreal marginsInch = 1.57480315; // = (2 x 2cm) / 2.45cm/inch
+ renderSize.setWidth((renderSize.width() - marginsInch) * printer.resolution());
+ renderSize.setHeight(((renderSize.height() - marginsInch) * printer.resolution()) / 2.5);
+
+ QPixmap pixmap(renderSize.toSize());
+ QPainter painter(&pixmap);
+ painter.setRenderHint(QPainter::Antialiasing);
+ painter.setRenderHint(QPainter::SmoothPixmapTransform);
+
+ ProfileWidget2 *profile = graphics();
+ QSize origSize = profile->size();
+ profile->resize(renderSize.toSize());
+ profile->setPrintMode(true);
+ profile->render(&painter);
+ profile->resize(origSize);
+ profile->setPrintMode(false);
+
+ QByteArray byteArray;
+ QBuffer buffer(&byteArray);
+ pixmap.save(&buffer, "PNG");
+ QString profileImage = QString("<img src=\"data:image/png;base64,") + byteArray.toBase64() + "\"/><br><br>";
+ withDisclaimer = profileImage + withDisclaimer;
+
plannerDetails()->divePlanOutput()->setHtml(withDisclaimer);
plannerDetails()->divePlanOutput()->print(&printer);
plannerDetails()->divePlanOutput()->setHtml(diveplan);
diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp
index eae4b3f21..b44bdfc99 100644
--- a/profile-widget/profilewidget2.cpp
+++ b/profile-widget/profilewidget2.cpp
@@ -1527,6 +1527,7 @@ void ProfileWidget2::setPrintMode(bool mode, bool grayscale)
isGrayscale = mode ? grayscale : false;
mouseFollowerHorizontal->setVisible(!mode);
mouseFollowerVertical->setVisible(!mode);
+ toolTipItem->setVisible(!mode);
}
void ProfileWidget2::setFontPrintScale(double scale)