Skip to content

Commit b2bd1bc

Browse files
committed
Show dive information in profile export
This was requested for social media posting. Signed-off-by: Robert C. Helling <helling@atdotde.de>
1 parent 2d3f73c commit b2bd1bc

File tree

4 files changed

+56
-11
lines changed

4 files changed

+56
-11
lines changed

backend-shared/exportfuncs.cpp

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
#include "core/selection.h"
1919
#include "core/taxonomy.h"
2020
#include "core/sample.h"
21+
#include "core/string-format.h"
2122
#include "profile-widget/profilescene.h"
23+
#include "core/qthelper.h"
2224
#include <QDir>
2325
#include <QFileInfo>
2426
#include <QtConcurrent>
@@ -41,21 +43,51 @@ static constexpr int profileScale = 4;
4143
static constexpr int profileWidth = 800 * profileScale;
4244
static constexpr int profileHeight = 600 * profileScale;
4345

44-
static void exportProfile(ProfileScene &profile, const struct dive &dive, const QString &filename)
46+
static QString profileText(const struct dive &dive)
47+
{
48+
QString text;
49+
50+
if (dive.dive_site->name.length() > 0)
51+
text += "🗺 " + QString::fromStdString(dive.dive_site->name) + " \n";
52+
if (dive.when) {
53+
text += "🗓️ " + formatDiveDateTime(&dive) + "\n";
54+
}
55+
text += "⏱️: " + formatDiveDuration(&dive) + "\n";
56+
text += "⭳: " + get_depth_string(dive.maxdepth, true) + " \n";
57+
if (dive.watertemp.mkelvin)
58+
text += "🌡️: " + get_temperature_string(dive.watertemp, true) + " \n";
59+
if (dive.visibility)
60+
text += "👁: " + QString("").repeated(dive.visibility) + " \n";
61+
text += formatGas(&dive);
62+
63+
return text;
64+
}
65+
66+
static void exportProfile(ProfileScene &profile, const struct dive &dive, const QString &filename, bool diveinfo)
4567
{
4668
QImage image = QImage(QSize(profileWidth, profileHeight), QImage::Format_RGB32);
4769
QPainter paint;
48-
paint.begin(&image);
49-
profile.draw(&paint, QRect(0, 0, profileWidth, profileHeight), &dive, 0, nullptr, false);
50-
image.save(filename);
70+
paint.begin(&image);
71+
profile.draw(&paint, QRect(0, 0, profileWidth, profileHeight), &dive, 0, nullptr, false);
72+
if (diveinfo) {
73+
QPixmap logo(":poster-icon");
74+
paint.drawPixmap(profileWidth - 210, profileHeight * 0.9 - 200, 200, 200, logo);
75+
QString text = profileText(dive);
76+
QPen pen = QPen(Qt::darkBlue);
77+
paint.setPen(pen);
78+
QFont textfont("Courier", 60, QFont::Bold);
79+
paint.setFont(textfont);
80+
paint.drawText(QRect(0.05 * profileWidth, 0, profileWidth, profileHeight * 0.9), text, Qt::AlignBottom | Qt::AlignLeft);
81+
}
82+
image.save(filename);
5183
}
5284

5385
static std::unique_ptr<ProfileScene> getPrintProfile()
5486
{
5587
return std::make_unique<ProfileScene>((double)profileScale, true, false);
5688
}
5789

58-
void exportProfile(QString filename, bool selected_only, ExportCallback &cb)
90+
void exportProfile(QString filename, bool selected_only, ExportCallback &cb, bool diveinfo)
5991
{
6092
int count = 0;
6193
if (!filename.endsWith(".png", Qt::CaseInsensitive))
@@ -73,7 +105,7 @@ void exportProfile(QString filename, bool selected_only, ExportCallback &cb)
73105
cb.setProgress(done++ * 1000 / todo);
74106
QString fn = count ? fi.path() + QDir::separator() + fi.completeBaseName().append(QString("-%1.").arg(count)) + fi.suffix()
75107
: filename;
76-
exportProfile(*profile, *dive, fn);
108+
exportProfile(*profile, *dive, fn, diveinfo);
77109
++count;
78110
}
79111
}
@@ -138,7 +170,7 @@ void export_TeX(const char *filename, bool selected_only, bool plain, ExportCall
138170
if (selected_only && !dive->selected)
139171
continue;
140172
cb.setProgress(done++ * 1000 / todo);
141-
exportProfile(*profile, *dive, texdir.filePath(QString("profile%1.png").arg(dive->number)));
173+
exportProfile(*profile, *dive, texdir.filePath(QString("profile%1.png").arg(dive->number)), false);
142174
struct tm tm;
143175
utc_mkdate(dive->when, &tm);
144176

backend-shared/exportfuncs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct ExportCallback {
1313
virtual bool canceled() const;
1414
};
1515

16-
void exportProfile(QString filename, bool selected_only, ExportCallback &cb);
16+
void exportProfile(QString filename, bool selected_only, ExportCallback &cb, bool diveinfo);
1717
void export_TeX(const char *filename, bool selected_only, bool plain, ExportCallback &cb);
1818
void export_depths(const char *filename, bool selected_only);
1919
std::vector<const dive_site *> getDiveSitesToExport(bool selectedOnly);

desktop-widgets/divelogexportdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ void DiveLogExportDialog::on_buttonBox_accepted()
224224
filename = QFileDialog::getSaveFileName(this, tr("Save profile image"), lastDir);
225225
if (!filename.isEmpty()) {
226226
ProgressDialogCallback cb;
227-
exportProfile(qPrintable(filename), ui->exportSelected->isChecked(), cb);
227+
exportProfile(qPrintable(filename), ui->exportSelected->isChecked(), cb, ui->diveinfo->isChecked());
228228
}
229229
} else if (ui->exportProfileData->isChecked()) {
230230
filename = QFileDialog::getSaveFileName(this, tr("Save profile data"), lastDir);

desktop-widgets/divelogexportdialog.ui

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>507</width>
10-
<height>423</height>
10+
<height>556</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -175,6 +175,19 @@
175175
<string>Anonymize</string>
176176
</property>
177177
</widget>
178+
<widget class="QCheckBox" name="diveinfo">
179+
<property name="geometry">
180+
<rect>
181+
<x>10</x>
182+
<y>90</y>
183+
<width>181</width>
184+
<height>23</height>
185+
</rect>
186+
</property>
187+
<property name="text">
188+
<string>Dive info in profle</string>
189+
</property>
190+
</widget>
178191
</widget>
179192
</item>
180193
</layout>
@@ -666,7 +679,7 @@
666679
</connection>
667680
</connections>
668681
<buttongroups>
669-
<buttongroup name="buttonGroup"/>
670682
<buttongroup name="exportGroup"/>
683+
<buttongroup name="buttonGroup"/>
671684
</buttongroups>
672685
</ui>

0 commit comments

Comments
 (0)