From 5b867900439c92e8ffbeeb8c5cbe580012abaa39 Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Thu, 18 Dec 2014 09:32:21 +0100 Subject: [PATCH] Rebased TeX printing Signed-off-by: Robert C. Helling --- logbookstyle.tex | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ qt-ui/divelistview.cpp | 48 +++++++++++++++++++++++++++++++++++++++ qt-ui/divelistview.h | 1 + subsurfacestartup.c | 10 +++++++++ subsurfacestartup.h | 1 + 5 files changed, 121 insertions(+) create mode 100644 logbookstyle.tex diff --git a/logbookstyle.tex b/logbookstyle.tex new file mode 100644 index 0000000..32d2f4e --- /dev/null +++ b/logbookstyle.tex @@ -0,0 +1,61 @@ +\input graphicx +\nopagenumbers +\font\breit=cmr10 scaled \magstep3 +\font\klein=cmr9 +\font\winzig=cmr5 +\def\slinie{\hrulefill\hskip 3em} +\overfullrule=0pt +\def\p{\hskip 0.5cm} % typical horizontal room +\parindent=1cm +%\offinterlineskip +$$\vbox{\hrule % upper cutting line +\vskip 2.0cm % upper whitespace +\vrule % left cutting line +$\vbox to 15cm{ % height of box +\vss\hbox to 3mm{\hrulefill}\vss}$ % middle line +\hskip 4.0cm % left white space +\vrule\vbox to 15cm{ % again height of box +\hrule depth 2pt % upper box boundary +\hbox to 10cm{ % width of box +\strut\p\date\slinie\vrule$\vcenter to 1.5cm{\vfil\hbox to +1.5cm{\hss\breit\strut\number\hss}\vfil\hrule}\vrule$} +% +\hbox{\p{\breit\strut\place} \country\hrulefill} +\medskip +\hbox{\p{\breit\strut\spot}\hrulefill} +\medskip +\hbox{\p\strut Entrance:\entrance\slinie} +\bigskip +\hbox to 10cm{\hss\breit\strut \time \p@\p\hbox to 1.5cm{\hss\depth}\hss} +\bigskip +\hbox to 10cm{\klein\p $\Delta p$:\hbox to 1cm{\hrulefill\gasuse}\hss +SAC:\hbox to 1.5cm{\hrulefill\sac}\hss +Type:\hbox to 1.2cm{\hrulefill\type}\hss Viz.: +\hbox to 0.8cm{\hrulefill\viz}\p} +\bigskip +\hbox{\p\hsize = 9cm +\vbox{\noindent +\comment +}\p\hss} +\leaders\vbox to 0.55cm{\vss\hbox to 10cm{\p\hrulefill\p}}\vfill +\hbox to 10cm{\hss\plot\hss} +\vskip 0.5cm +\hbox to 10cm{\p\breit Buddy: \buddy\hrulefill\p} + +\vskip 1ex % room above end of box +\hrule depth 2pt % lower boundary +}\vrule % right boundary +\hskip 1.0cm\vrule % right white space +\par +\hbox{\hskip 6cm +\winzig Subsurface dive log.} +\vskip 2.0cm % lower white space +\hrule}$$ +\bye + + + + + + + diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index c5ffaaa..229380a 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -28,6 +28,7 @@ #include #include #include "../qthelper.h" +#include "../subsurfacestartup.h" // # Date Rtg Dpth Dur Tmp Wght Suit Cyl Gas SAC OTU CNS Loc static int defaultWidth[] = { 70, 140, 90, 50, 50, 50, 50, 70, 50, 50, 70, 50, 50, 500}; @@ -758,6 +759,51 @@ void DiveListView::deleteDive() fixMessyQtModelBehaviour(); } + +void DiveListView::exportTeX() +{ + int nr; + struct dive *dive = (struct dive *) contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value(); + if (dive) { + + ProfileWidget2 *profile = MainWindow::instance()->graphics(); + profile->replot(); + QString fileName = "profile.png"; + QPixmap pixMap = QPixmap::grabWidget(profile); + pixMap.save(fileName); + + FILE *f = fopen("dive.tex","w"); + if (!f) + return; + + struct tm tm; + + utc_mkdate(dive->when, &tm); + + fprintf(f, "\\def\\date{%04u-%02u-%02u}\n", + tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday); + fprintf(f, "\\def\\number{%d}\n", dive->number); + fprintf(f, "\\def\\place{%s}\n", dive->location); + fputs("\\def\\spot{}\n", f); + fputs("\\def\\country{}\n", f); + fputs("\\def\\entrance{}\n", f); + fprintf(f, "\\def\\time{%u:%02u}\n", FRACTION(dive->duration.seconds, 60)); + fprintf(f, "\\def\\depth{%u.%01um}\n", FRACTION(dive->maxdepth.mm/100, 10)); + fputs("\\def\\gasuse{}\n",f); + fprintf(f, "\\def\\sac{%u.%01u l/min}\n", FRACTION(dive->sac/100,10)); + fputs("\\def\\type{}\n",f); + fprintf(f, "\\def\\viz{%d}\n", dive->visibility); + fputs("\\def\\plot{\\includegraphics[width=9cm,height=4cm]{profile}}\n",f); + fprintf(f, "\\def\\comment{%s}\n", dive->notes); + fprintf(f, "\\def\\buddy{%s}\n", dive->buddy); + fputs("\\input logbookstyle\n", f); + + fclose(f); + system("pdftex dive.tex"); + system("open dive.pdf"); + } +} + void DiveListView::testSlot() { struct dive *d = (struct dive *)contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value(); @@ -805,6 +851,8 @@ void DiveListView::contextMenuEvent(QContextMenuEvent *event) if (is_trip_before_after(bottom, (currentOrder == Qt::DescendingOrder))) popup.addAction(tr("Add dive(s) to trip immediately below"), this, SLOT(addToTripBelow())); } + if(has_pdftex) + popup.addAction(tr("export as TeX"), this, SLOT(exportTeX())); } if (trip) { popup.addAction(tr("Merge trip with trip above"), this, SLOT(mergeTripAbove())); diff --git a/qt-ui/divelistview.h b/qt-ui/divelistview.h index a6522fa..68f6be7 100644 --- a/qt-ui/divelistview.h +++ b/qt-ui/divelistview.h @@ -39,6 +39,7 @@ slots: void headerClicked(int); void removeFromTrip(); void deleteDive(); + void exportTeX(); void markDiveInvalid(); void testSlot(); void fixMessyQtModelBehaviour(); diff --git a/subsurfacestartup.c b/subsurfacestartup.c index 8847ab3..7f4b4e6 100644 --- a/subsurfacestartup.c +++ b/subsurfacestartup.c @@ -3,6 +3,8 @@ #include #include #include "gettext.h" +#include + struct preferences prefs; struct preferences default_prefs = { .units = SI_UNITS, @@ -184,6 +186,8 @@ void renumber_dives(int start_nr, bool selected_only) mark_divelist_changed(true); } +bool has_pdftex = false; + /* * Under a POSIX setup, the locale string should have a format * like [language[_territory][.codeset][@modifier]]. @@ -197,6 +201,12 @@ void renumber_dives(int start_nr, bool selected_only) void setup_system_prefs(void) { const char *env; + + /* determine if a pdftex binary is in the PATH */ + FILE *tex = popen("which pdftex","r"); + getc(tex); + if(!feof(tex)) + has_pdftex = true; subsurface_OS_pref_setup(); default_prefs.divelist_font = strdup(system_divelist_default_font); diff --git a/subsurfacestartup.h b/subsurfacestartup.h index 8eaaaa0..e19b76d 100644 --- a/subsurfacestartup.h +++ b/subsurfacestartup.h @@ -12,6 +12,7 @@ extern "C" { #endif extern bool imported; + extern bool has_pdftex; void setup_system_prefs(void); void parse_argument(const char *arg); -- 1.9.3 (Apple Git-50)