Subversion Repositories public

Rev

Rev 276 | Rev 283 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 276 Rev 280
Line 46... Line 46...
46
#include <qregexp.h>
46
#include <qregexp.h>
47
#include <QMouseEvent>
47
#include <QMouseEvent>
48
#include <QRect>
48
#include <QRect>
49
#include <QRegion>
49
#include <QRegion>
50
#include <KIcon>
50
#include <KIcon>
-
 
51
#include <QPrintDialog>
-
 
52
#include <QPrinter>
51
 
53
 
52
#if defined HAVE_GDAL
54
#if defined HAVE_GDAL
53
   #include <gdal/ogr_spatialref.h>
55
   #include <gdal/ogr_spatialref.h>
54
   #include <gdal/ogrsf_frmts.h>
56
   #include <gdal/ogrsf_frmts.h>
55
   #include <gdal/gdalwarper.h>
57
   #include <gdal/gdalwarper.h>
Line 57... Line 59...
57
#endif
59
#endif
58
 
60
 
59
#include "garmin.h"
61
#include "garmin.h"
60
#include "transform.h"
62
#include "transform.h"
61
#include "import.h"
63
#include "import.h"
62
#include "render.h"
-
 
63
 
64
 
64
//#define DEBUG	1
65
#if defined HAVE_MAPNIK
-
 
66
   #include "render.h"
-
 
67
#endif
65
 
68
 
66
using std::cout;
69
using std::cout;
67
using std::cerr;
70
using std::cerr;
68
using std::clog;
71
using std::clog;
69
using std::endl;
72
using std::endl;
Line 94... Line 97...
94
	oldTransX = oldTransY = 0.0;
97
	oldTransX = oldTransY = 0.0;
95
	lmbPressed = 0;
98
	lmbPressed = 0;
96
	DIRTY = true;
99
	DIRTY = true;
97
	curTab = ui_sportwatcherWidgetBase.tabView->currentIndex();
100
	curTab = ui_sportwatcherWidgetBase.tabView->currentIndex();
98
	tabDirt0 = tabDirt1 = tabDirt2 = tabDirt3 = true;
101
	tabDirt0 = tabDirt1 = tabDirt2 = tabDirt3 = true;
-
 
102
	ActivePrint = false;	// true if we are printing on paper
99
	kl = new KLocale(QString("kdesktop"), 0);
103
	kl = new KLocale(QString("kdesktop"), 0);
100
 
104
 
101
	// Load the config parameters
105
	// Load the config parameters
102
	KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig);
106
	KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig);
103
	KConfigGroup ic (&cfg, "SportWatcher");
107
	KConfigGroup ic (&cfg, "SportWatcher");
Line 621... Line 625...
621
	}
625
	}
622
 
626
 
623
	DIRTY = false;
627
	DIRTY = false;
624
}
628
}
625
 
629
 
-
 
630
/*
-
 
631
 * The following function is called, when the user clicks the print button.
-
 
632
 * It then prints the currently loaded activity. First the laps and on a
-
 
633
 * seperate page the map, heart rate, elevation and speed.
-
 
634
 *
-
 
635
 * The function uses the already existing function showTrack() to draw an
-
 
636
 * optional map and the track on it. It uses the function showThreeCurve()
-
 
637
 * to draw the heart rate, elevation and speed. Only the laps are drawn
-
 
638
 * directly in this function.
-
 
639
 */
626
void sportwatcherWidget::filePrint()
640
void sportwatcherWidget::filePrint()
627
{
641
{
-
 
642
QPrinter printer(QPrinter::HighResolution);
-
 
643
QDateTime dt;
-
 
644
QTime t, st;
-
 
645
QDateTime *qt;
-
 
646
QRectF rect;
-
 
647
QString qs_name, qs_distance, qs_etime, qs_avgpace, qs_avgspeed, qs_maxspeed;
-
 
648
QString qs_calories, qs_avghr, qs_maxhr, qs_avgcadence, qs_ascent, qs_descent;
-
 
649
QString qs_totdist, hv0;
-
 
650
LAP *lap;
-
 
651
POINT *point;
-
 
652
RUN_NODE *rakt, *rn;
-
 
653
int laps, i, anz, cad, page, firstPage, lastPage;
-
 
654
qreal extMil[4];
-
 
655
double sum_asc, sum_dsc, old_asc, old_dsc;
-
 
656
double totdist, lineH, aktLine;
-
 
657
bool printed = false;
-
 
658
 
-
 
659
	if (!gmn)
-
 
660
	{
-
 
661
	   KMessageBox::error(this, i18n("You must select an activity first!"));
-
 
662
	   return;
-
 
663
	}
-
 
664
 
-
 
665
	printer.setCreator(QString("SportWatcher"));
-
 
666
	printer.setDocName(QString("SportWatcher_%1").arg(QString(VERSION)));
-
 
667
	QPrintDialog printDialog(&printer, this);
-
 
668
 
-
 
669
	if (!printDialog.exec() == QDialog::Accepted)
-
 
670
	   return;
-
 
671
 
-
 
672
	if (!(rn = ds.getRunNode()))
-
 
673
	   return;
-
 
674
 
-
 
675
	// We dont care about page margins of a printer. Instead we assume
-
 
676
	// a frame from about 20mm arround the page. European paper size is
-
 
677
	// A4 (210x297mm) and the output is optimized for this.
-
 
678
	extMil[0] = 20.0;
-
 
679
	extMil[1] = 20.0;
-
 
680
	extMil[2] = 210.0 - 20.0;
-
 
681
	extMil[3] = 279.0 - 20.0;
-
 
682
	lineH = 4.5;	// The height of a line with 10pt letters
-
 
683
	page = 1;	// The page number
-
 
684
	firstPage = printer.fromPage();
-
 
685
	lastPage = printer.toPage();
-
 
686
 
-
 
687
	if (!printArea.begin(&printer))
-
 
688
	{
628
	KMessageBox::information(this, i18n("This function is currently not implemented!"));
689
	   KMessageBox::error(this, i18n("Error initializing printer! Printing is currently not available!"));
-
 
690
	   return;
-
 
691
	}
-
 
692
 
-
 
693
	ActivePrint = true;
-
 
694
	rakt = rn;
-
 
695
	QApplication::setOverrideCursor (QCursor(Qt::WaitCursor));
-
 
696
 
-
 
697
	while (rakt)
-
 
698
	{
-
 
699
	   // Check for a supported run type
-
 
700
	   if (rakt->run->type == data_D1000 || rakt->run->type == data_D1009 ||
-
 
701
	   	rakt->run->type == data_D1010)
-
 
702
	   {
-
 
703
	   int ahr;
-
 
704
	   double distance, speed, mspeed;
-
 
705
	   QDate dat;
-
 
706
 
-
 
707
	      printArea.setFont(QFont(QString("Helvetica"), 12, QFont::Bold, false));
-
 
708
	      rect.setCoords(milToPixel(extMil[0], printer),
-
 
709
			milToPixel(extMil[1], printer, true),
-
 
710
			milToPixel(extMil[0]+170, printer),
-
 
711
			milToPixel(extMil[1] + 7.0, printer, true));
-
 
712
	      printArea.setPen(QPen(QBrush(QColor("black")), (qreal)milToPixel(0.5, printer, false)));
-
 
713
 
-
 
714
	      if ((lastPage > 0 && page >= firstPage && page <= lastPage) ||
-
 
715
		  (lastPage == 0 && firstPage == 0))
-
 
716
	      {
-
 
717
		 printArea.drawRect(rect);
-
 
718
		 printed = true;
-
 
719
	      }
-
 
720
 
-
 
721
	      if (!(lap = ds.getLap(rakt->run->first_lap_index)))
-
 
722
	      {
-
 
723
		 ActivePrint = false;
-
 
724
		 QApplication::restoreOverrideCursor();
-
 
725
		 return;
-
 
726
	      }
-
 
727
 
-
 
728
	      if (strlen (rn->run->workout.name) > 1 && strlen (rn->run->workout.name) < 16 && isalpha (rn->run->workout.name[0]))
-
 
729
		 hv0 = QString(rakt->run->workout.name);
-
 
730
	      else
-
 
731
	      {
-
 
732
		 qt = garmin_dtime(lap->start_time);
-
 
733
		 hv0 = kl->formatDate(qt->date(), KLocale::ShortDate) + " ";
-
 
734
		 hv0.append(qt->toString("hh:mm:ss"));
-
 
735
		 delete qt;
-
 
736
	      }
-
 
737
 
-
 
738
	      // Set the name depending on the sport type
-
 
739
	      // This is used on the tab "Summary"
-
 
740
	      switch (rakt->run->sport_type)
-
 
741
	      {
-
 
742
		 case D1000_running: qs_name = i18n("Running: "); break;
-
 
743
		 case D1000_biking:  qs_name = i18n("Biking: "); break;
-
 
744
		 case D1000_other:   qs_name = i18n("Other: "); break;
-
 
745
		 default:
-
 
746
		    qs_name = i18n("Unknown: ");
-
 
747
	      }
-
 
748
 
-
 
749
	      // Print the headline inside the frame
-
 
750
	      if ((lastPage > 0 && page >= firstPage && page <= lastPage) ||
-
 
751
		  (lastPage == 0 && firstPage == 0))
-
 
752
	      {
-
 
753
		 printArea.drawText(rect, Qt::AlignHCenter, QString("%1%2").arg(qs_name).arg(hv0));
-
 
754
		 // Print the headline of the table
-
 
755
		 printArea.setFont(QFont(QString("Helvetica"), 10, QFont::Bold, false));
-
 
756
		 rect.setCoords(milToPixel(extMil[0], printer), milToPixel(extMil[1]+10, printer, true), milToPixel(extMil[0]+35, printer), milToPixel(extMil[0]+10+lineH, printer, true));
-
 
757
		 printArea.drawText(rect, Qt::AlignHCenter, i18n("Lap"));
-
 
758
		 rect.setCoords(milToPixel(extMil[0]+35, printer), milToPixel(extMil[1]+10, printer, true), milToPixel(extMil[0]+60, printer), milToPixel(extMil[0]+10+lineH, printer, true));
-
 
759
		 printArea.drawText(rect, Qt::AlignHCenter, i18n("Distance"));
-
 
760
		 rect.setCoords(milToPixel(extMil[0]+60, printer), milToPixel(extMil[1]+10, printer, true), milToPixel(extMil[0]+85, printer), milToPixel(extMil[0]+10+lineH, printer, true));
-
 
761
		 printArea.drawText(rect, Qt::AlignHCenter, i18n("Time"));
-
 
762
		 rect.setCoords(milToPixel(extMil[0]+85, printer), milToPixel(extMil[1]+10, printer, true), milToPixel(extMil[0]+122, printer), milToPixel(extMil[0]+10+lineH, printer, true));
-
 
763
		 printArea.drawText(rect, Qt::AlignHCenter, i18n("Speed"));
-
 
764
		 rect.setCoords(milToPixel(extMil[0]+122, printer), milToPixel(extMil[1]+10, printer, true), milToPixel(extMil[0]+147, printer), milToPixel(extMil[0]+10+lineH, printer, true));
-
 
765
		 printArea.drawText(rect, Qt::AlignHCenter, i18n("Heart rate"));
-
 
766
		 rect.setCoords(milToPixel(extMil[0]+147, printer), milToPixel(extMil[1]+10, printer, true), milToPixel(extMil[0]+170, printer), milToPixel(extMil[0]+10+lineH, printer, true));
-
 
767
		 printArea.drawText(rect, Qt::AlignHCenter, i18n("Cadence"));
-
 
768
		 aktLine = extMil[1] + 10.0 + lineH;
-
 
769
		 printArea.drawLine(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 170, printer), milToPixel(aktLine, printer, true));
-
 
770
		 aktLine += 1.0;
-
 
771
		 printed = true;
-
 
772
	      }
-
 
773
	      else
-
 
774
	      {
-
 
775
		 aktLine = extMil[1] + 10.0 + lineH;
-
 
776
		 aktLine += 1.0;
-
 
777
	      }
-
 
778
 
-
 
779
	      // Prepare to print the first line
-
 
780
	      qt = garmin_dtime (lap->start_time);
-
 
781
	      StartTime = *qt;
-
 
782
	      st = qt->time();
-
 
783
	      dat = qt->date();
-
 
784
	      delete qt;
-
 
785
	      qt = 0;
-
 
786
	      // Find the last track
-
 
787
	      if (!(point = ds.getLastPoint()))
-
 
788
	      {
-
 
789
		 QApplication::restoreOverrideCursor();
-
 
790
		 KMessageBox::error(this, i18n("Error getting the last messure point!"));
-
 
791
		 ActivePrint = false;
-
 
792
		 return;
-
 
793
	      }
-
 
794
 
-
 
795
	      qt = garmin_dtime(point->time);
-
 
796
	      t = qt->time();
-
 
797
	      t.setHMS(0, 0, 0);
-
 
798
	      t = t.addSecs(ds.getTotalTime());
-
 
799
	      qt->setDate(dat);
-
 
800
	      qt->setTime(t);
-
 
801
	      qs_name = kl->formatDate(dat, KLocale::ShortDate);
-
 
802
	      qs_name.append(" ");
-
 
803
	      qs_name.append(kl->formatTime(st, true));
-
 
804
	      max_time = ds.getTotalTime();
-
 
805
	      qs_etime = QString(qt->toString("hh:mm:ss.zzz"));
-
 
806
 
-
 
807
	      distance = 0.0;
-
 
808
	      mspeed = 0;
-
 
809
	      ahr = 0;
-
 
810
	      anz = 0;
-
 
811
	      cad = 0;
-
 
812
	      sum_asc = sum_dsc = old_asc = old_dsc = 0;
-
 
813
 
-
 
814
	      // Find out the total distance, calories, maximum speed,
-
 
815
	      // maximum heart rate and the average heart rate. Get this
-
 
816
	      // values from the lap summary the watch made.
-
 
817
	      for (i = rakt->run->first_lap_index; (unsigned int)i <= rakt->run->last_lap_index; i++)
-
 
818
	      {
-
 
819
		 if ((lap = ds.getLap(i)) == NULL)
-
 
820
		    continue;
-
 
821
 
-
 
822
		 distance += lap->total_distance;
-
 
823
 
-
 
824
		 if (lap->avg_cadence != 0xff)
-
 
825
		    cad += lap->avg_cadence;
-
 
826
 
-
 
827
		 ahr += lap->avg_heart_rate;
-
 
828
		 anz++;
-
 
829
 
-
 
830
		 if (lap->max_speed > mspeed)
-
 
831
		    mspeed = lap->max_speed;
-
 
832
	      }
-
 
833
 
-
 
834
	      total_distance = distance = ds.getTotalDistance();
-
 
835
 
-
 
836
	      if (Units == 1)		// Statute?
-
 
837
		 qs_distance.sprintf("%.2f ft", distance / 0.304);
-
 
838
	      else
-
 
839
	         qs_distance.sprintf("%.2f m", distance);
-
 
840
 
-
 
841
	      if (distance > 0)
-
 
842
	      {
-
 
843
		 QTime tt = qt->time();
-
 
844
		 long secs = (double)(tt.hour() * 3600 + tt.minute() * 60 + tt.second()) / 100.0;
-
 
845
 
-
 
846
		 if (Units == 0)
-
 
847
		    secs = secs * (1000.0 / distance * 100.0);
-
 
848
		 else
-
 
849
		    secs = secs * (1609.344 / distance * 100.0);
-
 
850
 
-
 
851
		 int h = secs / 3600;
-
 
852
		 int m = (secs - (h * 3600)) / 60;
-
 
853
		 int s = secs - ((h * 3600) + (m * 60));
-
 
854
		 t = QTime(h, m, s, 0);
-
 
855
		 qs_avgpace = QString("  ") + kl->formatTime(t, true);
-
 
856
 
-
 
857
		 if (Units == 0)
-
 
858
		    qs_avgpace.append(QString(" /km"));
-
 
859
		 else
-
 
860
		    qs_avgpace.append(QString(" /mi"));
-
 
861
	      }
-
 
862
 
-
 
863
	      if (Units == 1)		// Statute?
-
 
864
		 speed = distance / ds.getTotalTime() * 3.6 / 1.609344;
-
 
865
	      else
-
 
866
		 speed = distance / ds.getTotalTime() * 3.6;
-
 
867
 
-
 
868
	      qs_avgspeed.sprintf("%.2f %s", speed, (Units == 1) ? "mph" : "km/h");
-
 
869
	      qs_maxspeed.sprintf("%.2f %s", (Units == 1) ? mspeed * 3.6 / 1.609344 : mspeed * 3.6, (Units == 1) ? "mph" : "km/h");
-
 
870
	      qs_avghr.sprintf("%d bpm", ahr / anz);
-
 
871
 
-
 
872
	      if (cad > 0)
-
 
873
		 qs_avgcadence.sprintf("%d", cad / anz);
-
 
874
 
-
 
875
	      // Print out the summary line and draw twi thin lines underneath
-
 
876
	      if ((lastPage > 0 && page >= firstPage && page <= lastPage) ||
-
 
877
		  (lastPage == 0 && firstPage == 0))
-
 
878
	      {
-
 
879
		 printArea.setFont(QFont(QString("Helvetica"), 10, QFont::Normal, false));
-
 
880
		 rect.setCoords(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+35, printer), milToPixel(aktLine+lineH, printer, true));
-
 
881
		 printArea.drawText(rect, Qt::AlignLeft, qs_name);
-
 
882
		 rect.setCoords(milToPixel(extMil[0]+35, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+60, printer), milToPixel(aktLine+lineH, printer, true));
-
 
883
		 printArea.drawText(rect, Qt::AlignRight, kl->formatNumber(qs_distance, false));
-
 
884
		 rect.setCoords(milToPixel(extMil[0]+60, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+85, printer), milToPixel(aktLine+lineH, printer, true));
-
 
885
		 printArea.drawText(rect, Qt::AlignRight, qs_etime);
-
 
886
		 rect.setCoords(milToPixel(extMil[0]+85, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+122, printer), milToPixel(aktLine+lineH, printer, true));
-
 
887
		 printArea.drawText(rect, Qt::AlignRight, kl->formatNumber(qs_avgspeed, false));
-
 
888
		 rect.setCoords(milToPixel(extMil[0]+122, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+147, printer), milToPixel(aktLine+lineH, printer, true));
-
 
889
		 printArea.drawText(rect, Qt::AlignRight, qs_avghr);
-
 
890
		 rect.setCoords(milToPixel(extMil[0]+147, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+170, printer), milToPixel(aktLine+lineH, printer, true));
-
 
891
		 printArea.drawText(rect, Qt::AlignRight, qs_avgcadence);
-
 
892
		 aktLine += (lineH + (lineH / 3.0));
-
 
893
		 printArea.setPen(QPen(QBrush(QColor("black")), milToPixel(0.1, printer, false)));
-
 
894
		 printArea.drawLine(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 170, printer), milToPixel(aktLine, printer, true));
-
 
895
		 printArea.drawLine(milToPixel(extMil[0], printer), milToPixel(aktLine+0.5, printer, true), milToPixel(extMil[0] + 170, printer), milToPixel(aktLine+0.5, printer, true));
-
 
896
		 aktLine += (lineH / 3.0);
-
 
897
		 printed = true;
-
 
898
	      }
-
 
899
	      else
-
 
900
	      {
-
 
901
		 aktLine += (lineH + (lineH / 3.0));
-
 
902
		 aktLine += (lineH / 3.0);
-
 
903
	      }
-
 
904
 
-
 
905
	      delete qt;
-
 
906
	      /* Get the laps. */
-
 
907
	      laps = 1;
-
 
908
 
-
 
909
	      for (i = rakt->run->first_lap_index; (unsigned int)i <= rakt->run->last_lap_index; i++)
-
 
910
	      {
-
 
911
		 double spd;
-
 
912
		 char *un;
-
 
913
 
-
 
914
		 if ((lap = ds.getLap(i)) == NULL)
-
 
915
		    continue;
-
 
916
 
-
 
917
		 qt = garmin_dtime (lap->start_time);
-
 
918
		 qs_name.sprintf("Lap %03d - ", laps);
-
 
919
		 qs_name.append(kl->formatTime(qt->time(), true));
-
 
920
		 qs_distance.sprintf("%.2f %s", (Units == 1) ? lap->total_distance / 0.304 : lap->total_distance, (Units == 1) ? "ft" : "m");
-
 
921
		 totdist += (Units == 1) ? lap->total_distance / 0.304 : lap->total_distance;
-
 
922
		 qs_totdist.sprintf("%2.f %s", totdist, (Units == 1) ? "ft" : "m");
-
 
923
		 t = QTime(0, 0, 0, 0);
-
 
924
		 t = t.addMSecs(lap->total_time * 10);
-
 
925
		 qs_etime = t.toString("hh:mm:ss.zzz");
-
 
926
		 spd = lap->total_distance / (lap->total_time / 100.0);
-
 
927
		 delete qt;
-
 
928
		 qt = 0;
-
 
929
 
-
 
930
		 if (Units == 0)
-
 
931
		 {
-
 
932
		    un = (char *)"km/h";
-
 
933
		    spd *= 3.6;
-
 
934
		 }
-
 
935
		 else
-
 
936
		 {
-
 
937
		    spd *= 3.6 / 1.609344;
-
 
938
		    un = (char *)"mph";
-
 
939
		 }
-
 
940
 
-
 
941
		 qs_avgspeed.sprintf("%.2f %s", spd, un);
-
 
942
 
-
 
943
		 if (lap->total_distance > 0 && lap->total_time != 0)
-
 
944
		 {
-
 
945
		    double fact;
-
 
946
 
-
 
947
		    if (Units == 0)
-
 
948
		       fact = 1000.0;		// 1 km
-
 
949
		    else
-
 
950
		       fact = 1609.344;		// 1 mile in meters
-
 
951
 
-
 
952
		    long secs = (double)lap->total_time / 10000.0 * (fact / lap->total_distance * 100.0);
-
 
953
		    int h = secs / 3600;
-
 
954
		    int m = (secs - (h * 3600)) / 60;
-
 
955
		    int s = secs - ((h * 3600) + (m * 60));
-
 
956
		    t = QTime(h, m, s, 0);
-
 
957
		    qs_avgpace = kl->formatTime(t, true);
-
 
958
 
-
 
959
		    if (Units == 0)
-
 
960
		       qs_avgpace.append(QString(" /km"));
-
 
961
		    else
-
 
962
		       qs_avgpace.append(QString(" /mi"));
-
 
963
		 }
-
 
964
 
-
 
965
		 qs_avghr.sprintf("%d bpm", lap->avg_heart_rate);
-
 
966
 
-
 
967
		 if (lap->avg_cadence != 0xff)
-
 
968
		    qs_avgcadence.sprintf("%d", lap->avg_cadence);
-
 
969
		 // Draw a new detail line
-
 
970
		 if ((lastPage > 0 && page >= firstPage && page <= lastPage) ||
-
 
971
		     (lastPage == 0 && firstPage == 0))
-
 
972
		 {
-
 
973
		    rect.setCoords(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+35, printer), milToPixel(aktLine+lineH, printer, true));
-
 
974
		    printArea.drawText(rect, Qt::AlignLeft, qs_name);
-
 
975
		    rect.setCoords(milToPixel(extMil[0]+35, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+60, printer), milToPixel(aktLine+lineH, printer, true));
-
 
976
		    printArea.drawText(rect, Qt::AlignRight, kl->formatNumber(qs_distance, false));
-
 
977
		    rect.setCoords(milToPixel(extMil[0]+60, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+85, printer), milToPixel(aktLine+lineH, printer, true));
-
 
978
		    printArea.drawText(rect, Qt::AlignRight, qs_etime);
-
 
979
		    rect.setCoords(milToPixel(extMil[0]+85, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+122, printer), milToPixel(aktLine+lineH, printer, true));
-
 
980
		    printArea.drawText(rect, Qt::AlignRight, kl->formatNumber(qs_avgspeed, false));
-
 
981
		    rect.setCoords(milToPixel(extMil[0]+122, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+147, printer), milToPixel(aktLine+lineH, printer, true));
-
 
982
		    printArea.drawText(rect, Qt::AlignRight, qs_avghr);
-
 
983
		    rect.setCoords(milToPixel(extMil[0]+147, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+170, printer), milToPixel(aktLine+lineH, printer, true));
-
 
984
		    printArea.drawText(rect, Qt::AlignRight, qs_avgcadence);
-
 
985
		    printed = true;
-
 
986
		 }
-
 
987
 
-
 
988
		 aktLine += lineH;
-
 
989
 
-
 
990
		 if (aktLine >= extMil[3])	// Print on the next page
-
 
991
		 {
-
 
992
		    aktLine = extMil[3] + 10.0;
-
 
993
 
-
 
994
		    if ((lastPage > 0 && page >= firstPage && page <= lastPage) ||
-
 
995
		        (lastPage == 0 && firstPage == 0))
-
 
996
		    {
-
 
997
		       printArea.setFont(QFont(QString("Helvetica"), 8, QFont::Normal, false));
-
 
998
		       rect.setCoords(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+170, printer), milToPixel(aktLine+lineH, printer, true));
-
 
999
		       printArea.drawText(rect, Qt::AlignRight, i18n("Page %1").arg(page));
-
 
1000
		       aktLine = extMil[1];
-
 
1001
		       printed = true;
-
 
1002
		    }
-
 
1003
		    else
-
 
1004
		       aktLine = extMil[1];
-
 
1005
 
-
 
1006
		    if (printed)
-
 
1007
		       printer.newPage();
-
 
1008
 
-
 
1009
		    page++;
-
 
1010
		    // Print the headline of the table
-
 
1011
		    if ((lastPage > 0 && page >= firstPage && page <= lastPage) ||
-
 
1012
		        (lastPage == 0 && firstPage == 0))
-
 
1013
		    {
-
 
1014
		       printArea.setFont(QFont(QString("Helvetica"), 10, QFont::Bold, false));
-
 
1015
		       rect.setCoords(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+35, printer), milToPixel(aktLine+lineH, printer, true));
-
 
1016
		       printArea.drawText(rect, Qt::AlignHCenter, i18n("Lap"));
-
 
1017
		       rect.setCoords(milToPixel(extMil[0]+35, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+60, printer), milToPixel(aktLine+lineH, printer, true));
-
 
1018
		       printArea.drawText(rect, Qt::AlignHCenter, i18n("Distance"));
-
 
1019
		       rect.setCoords(milToPixel(extMil[0]+60, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+85, printer), milToPixel(aktLine+lineH, printer, true));
-
 
1020
		       printArea.drawText(rect, Qt::AlignHCenter, i18n("Time"));
-
 
1021
		       rect.setCoords(milToPixel(extMil[0]+85, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+122, printer), milToPixel(aktLine+lineH, printer, true));
-
 
1022
		       printArea.drawText(rect, Qt::AlignHCenter, i18n("Speed"));
-
 
1023
		       rect.setCoords(milToPixel(extMil[0]+122, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+147, printer), milToPixel(aktLine+lineH, printer, true));
-
 
1024
		       printArea.drawText(rect, Qt::AlignHCenter, i18n("Heart rate"));
-
 
1025
		       rect.setCoords(milToPixel(extMil[0]+147, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+170, printer), milToPixel(aktLine+lineH, printer, true));
-
 
1026
		       printArea.drawText(rect, Qt::AlignHCenter, i18n("Cadence"));
-
 
1027
		       aktLine += lineH;
-
 
1028
		       printArea.setPen(QPen(QBrush(QColor("black")), milToPixel(0.5, printer, false)));
-
 
1029
		       printArea.drawLine(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 170, printer), milToPixel(aktLine, printer, true));
-
 
1030
		       aktLine += 1.0;
-
 
1031
		       printed = true;
-
 
1032
		    }
-
 
1033
		    else
-
 
1034
		    {
-
 
1035
		       aktLine += lineH;
-
 
1036
		       aktLine += 1.0;
-
 
1037
		    }
-
 
1038
 
-
 
1039
		    printArea.setFont(QFont(QString("Helvetica"), 10, QFont::Normal, false));
-
 
1040
		 }
-
 
1041
 
-
 
1042
		 delete qt;
-
 
1043
		 laps++;
-
 
1044
	      }
-
 
1045
 
-
 
1046
	      aktLine = extMil[3] + 10.0;
-
 
1047
	      if ((lastPage > 0 && page >= firstPage && page <= lastPage) ||
-
 
1048
		  (lastPage == 0 && firstPage == 0))
-
 
1049
	      {
-
 
1050
		 printArea.setFont(QFont(QString("Helvetica"), 8, QFont::Normal, false));
-
 
1051
		 rect.setCoords(milToPixel(extMil[0], printer),
-
 
1052
				milToPixel(aktLine, printer, true),
-
 
1053
				milToPixel(extMil[0]+170, printer),
-
 
1054
				milToPixel(aktLine+lineH, printer, true));
-
 
1055
		 printArea.drawText(rect, Qt::AlignRight, i18n("Page %1").arg(page));
-
 
1056
		 printed = true;
-
 
1057
	      }
-
 
1058
 
-
 
1059
	      aktLine = extMil[1];
-
 
1060
	      page++;
-
 
1061
 
-
 
1062
	      if (printed && (page <= lastPage || lastPage == 0))
-
 
1063
		 printer.newPage();
-
 
1064
 
-
 
1065
	      if ((lastPage > 0 && (page < firstPage || page > lastPage)))
-
 
1066
		 break;
-
 
1067
 
-
 
1068
	      // Draw the map on top of a new page
-
 
1069
	      // Use 1/3 of the available height for the map
-
 
1070
	      qreal resFact = 8;	// The factor to calculate the resolution for pixmaps
-
 
1071
	      int width = (int)(milToPixel(170, printer) / resFact);
-
 
1072
	      int height = (int)(milToPixel(extMil[3] - extMil[1], printer, true) / resFact);
-
 
1073
	      pmPrMap = QPixmap(width, height / 3);	// 1/3 of page height
-
 
1074
	      DIRTY = true;
-
 
1075
	      int ct = curTab;
-
 
1076
	      curTab = 1;
-
 
1077
	      QApplication::restoreOverrideCursor();
-
 
1078
	      showTrack();
-
 
1079
	      QApplication::setOverrideCursor (QCursor(Qt::WaitCursor));
-
 
1080
	      DIRTY = false;
-
 
1081
	      curTab = ct;
-
 
1082
	      printArea.drawPixmap(milToPixel(extMil[0], printer),
-
 
1083
				milToPixel(extMil[1], printer),
-
 
1084
				pmPrMap.scaled((int)milToPixel(170, printer),
-
 
1085
				(int)milToPixel(extMil[3] - extMil[1], printer, true) / 3,
-
 
1086
				Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
-
 
1087
	      // Put a frame around the map
-
 
1088
	      rect.setCoords(milToPixel(extMil[0], printer), milToPixel(extMil[1], printer, true),
-
 
1089
				milToPixel(extMil[0] + 170, printer),
-
 
1090
				milToPixel(extMil[1], printer, true) + (milToPixel(extMil[3] - extMil[1], printer, true) / 3));
-
 
1091
	      printArea.setPen(QPen(QBrush(QColor("black")), milToPixel(0.2, printer)));
-
 
1092
	      printArea.drawRect(rect);
-
 
1093
	      aktLine = (extMil[3] - extMil[1]) / 3.0 + extMil[1] + lineH;
-
 
1094
 
-
 
1095
	      // Draw the heart rate diagram
-
 
1096
	      rect.setCoords(milToPixel(extMil[0], printer),
-
 
1097
				milToPixel(aktLine, printer, true),
-
 
1098
				milToPixel(extMil[2], printer),
-
 
1099
				milToPixel(aktLine + lineH, printer, true));
-
 
1100
	      printArea.drawText(rect, Qt::AlignLeft, i18n("Heart rate:"));
-
 
1101
	      aktLine += lineH;
-
 
1102
	      qreal pixHeight = (extMil[3] - aktLine) / 3.0 - lineH * 2.0;
-
 
1103
	      int realH = (int)milToPixel(pixHeight, printer, true);
-
 
1104
	      height = realH / (int)resFact;
-
 
1105
	      showThreeCurve(width, height);	// Calculate the curves
-
 
1106
	      printArea.drawPixmap(milToPixel(extMil[0], printer),
-
 
1107
				milToPixel(aktLine, printer, true),
-
 
1108
				prHR.scaled((int)milToPixel(170, printer),
-
 
1109
				realH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
-
 
1110
	      rect.setCoords(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true),
-
 
1111
				milToPixel(extMil[0] + 170, printer),
-
 
1112
				milToPixel(aktLine + pixHeight, printer, true));
-
 
1113
	      printArea.drawRect(rect);
-
 
1114
	      aktLine += pixHeight + lineH;
-
 
1115
 
-
 
1116
	      // Draw the elevation diagram
-
 
1117
	      rect.setCoords(milToPixel(extMil[0], printer),
-
 
1118
				milToPixel(aktLine, printer, true),
-
 
1119
				milToPixel(extMil[2], printer),
-
 
1120
				milToPixel(aktLine + lineH, printer, true));
-
 
1121
	      printArea.drawText(rect, Qt::AlignLeft, i18n("Elevation:"));
-
 
1122
	      aktLine += lineH;
-
 
1123
	      printArea.drawPixmap(milToPixel(extMil[0], printer),
-
 
1124
				milToPixel(aktLine, printer, true),
-
 
1125
				prElevation.scaled((int)milToPixel(170, printer),
-
 
1126
				realH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
-
 
1127
	      rect.setCoords(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true),
-
 
1128
				milToPixel(extMil[0] + 170, printer),
-
 
1129
				milToPixel(aktLine + pixHeight, printer, true));
-
 
1130
	      printArea.drawRect(rect);
-
 
1131
	      aktLine += pixHeight + lineH;
-
 
1132
 
-
 
1133
	      // Draw the speed diagram
-
 
1134
	      rect.setCoords(milToPixel(extMil[0], printer),
-
 
1135
				milToPixel(aktLine, printer, true),
-
 
1136
				milToPixel(extMil[2], printer),
-
 
1137
				milToPixel(aktLine + lineH, printer, true));
-
 
1138
	      printArea.drawText(rect, Qt::AlignLeft, i18n("Speed:"));
-
 
1139
	      aktLine += lineH;
-
 
1140
	      printArea.drawPixmap(milToPixel(extMil[0], printer),
-
 
1141
				milToPixel(aktLine, printer, true),
-
 
1142
				prSpeed.scaled((int)milToPixel(170, printer),
-
 
1143
				realH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
-
 
1144
	      rect.setCoords(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true),
-
 
1145
				milToPixel(extMil[0] + 170, printer),
-
 
1146
				milToPixel(aktLine + pixHeight, printer, true));
-
 
1147
	      printArea.drawRect(rect);
-
 
1148
 
-
 
1149
	      // Print the page number at the right bottom of the page
-
 
1150
	      aktLine = extMil[3] + 10.0;
-
 
1151
	      printArea.setFont(QFont(QString("Helvetica"), 8, QFont::Normal, false));
-
 
1152
	      rect.setCoords(milToPixel(extMil[0], printer),
-
 
1153
				milToPixel(aktLine, printer, true),
-
 
1154
				milToPixel(extMil[0]+170, printer),
-
 
1155
				milToPixel(aktLine+lineH, printer, true));
-
 
1156
	      printArea.drawText(rect, Qt::AlignRight, i18n("Page %1").arg(page));
-
 
1157
	   }
-
 
1158
 
-
 
1159
	   rakt = rakt->next;
-
 
1160
	}
-
 
1161
 
-
 
1162
	printArea.end();
-
 
1163
	// Mark printing as done
-
 
1164
	ActivePrint = false;
-
 
1165
	QApplication::restoreOverrideCursor();
-
 
1166
}
-
 
1167
 
-
 
1168
qreal sportwatcherWidget::milToPixel(qreal dist, QPrinter &pr, bool dir)
-
 
1169
{
-
 
1170
	QSizeF r = pr.paperSize(QPrinter::DevicePixel);
-
 
1171
	QSizeF m = pr.paperSize(QPrinter::Millimeter);
-
 
1172
 
-
 
1173
	if (!dir)	// width
-
 
1174
	   return r.width() / m.width() * dist;
-
 
1175
	else
-
 
1176
	   return r.height() / m.height() * dist;
629
}
1177
}
630
 
1178
 
631
/*
1179
/*
632
 * This function allows the user to choose a file name, where we save the
1180
 * This function allows the user to choose a file name, where we save the
633
 * actual lap in Garmins own TCX format. This format is simply a XML-file.
1181
 * actual lap in Garmins own TCX format. This format is simply a XML-file.
Line 1747... Line 2295...
1747
	{
2295
	{
1748
	   wmsbase *dlg = new wmsbase(this);
2296
	   wmsbase *dlg = new wmsbase(this);
1749
	   dlg->exec();
2297
	   dlg->exec();
1750
	   delete dlg;
2298
	   delete dlg;
1751
	}
2299
	}
1752
 
-
 
-
 
2300
#if defined HAVE_MAPNIK
1753
	if (MapType == MPT_SHP || MapType == MPT_OSM)
2301
	if (MapType == MPT_SHP || MapType == MPT_OSM)
1754
	{
2302
	{
1755
	   shapeWidget *dlg = new shapeWidget(this);
2303
	   shapeWidget *dlg = new shapeWidget(this);
1756
 
2304
 
1757
	   if (MapType == MPT_SHP)
2305
	   if (MapType == MPT_SHP)
Line 1760... Line 2308...
1760
	      dlg->setMapType(shapeWidget::MAP_OSM);
2308
	      dlg->setMapType(shapeWidget::MAP_OSM);
1761
 
2309
 
1762
	   dlg->exec();
2310
	   dlg->exec();
1763
	   delete dlg;
2311
	   delete dlg;
1764
	}
2312
	}
1765
 
2313
#else
-
 
2314
	KMessageBox::detailedSorry(this,
-
 
2315
	   i18n("This function was disabled at compile time because of missing Mapnik!"),
-
 
2316
	   i18n("SportWatcher needs Mapnik 0.6 or newer, to enable this function.\n") +
-
 
2317
	   i18n("If you like this to be working, install Mapnik and recompile the source."));
-
 
2318
#endif
1766
	if (MapType != MPT_WMS && MapType != MPT_SHP && MapType != MPT_OSM)
2319
	if (MapType != MPT_WMS && MapType != MPT_SHP && MapType != MPT_OSM)
1767
	{
2320
	{
1768
	   KMessageBox::detailedSorry(this,
2321
	   KMessageBox::detailedSorry(this,
1769
	      i18n("You have not choosen a WMS tag file or shape file directory!"),
2322
	      i18n("You have not choosen a WMS tag file or shape file directory!"),
1770
	      i18n("This dialog is especialy to set map specific parameters. ") +
2323
	      i18n("This dialog is especialy to set map specific parameters. ") +
Line 1773... Line 2326...
1773
	      i18n("Shape file as your map type."));
2326
	      i18n("Shape file as your map type."));
1774
	      return;
2327
	      return;
1775
	}
2328
	}
1776
#else
2329
#else
1777
	KMessageBox::detailedSorry(this,
2330
	KMessageBox::detailedSorry(this,
1778
	   i18n("This function was disabled at compile time because of missing GDAL v1.5.x!"),
2331
	   i18n("This function was disabled at compile time because of missing GDAL v1.x.x!"),
1779
	   i18n("Sportwatcher needs GDAL v1.5.x to enable this function.\n") +
2332
	   i18n("Sportwatcher needs GDAL v1.5.x or newer, to enable this function.\n") +
1780
	   i18n("If you like this to be working, install GDAL version 1.5.x and recompile the source!"));
2333
	   i18n("If you like this to be working, install GDAL and recompile the source!"));
1781
#endif
2334
#endif
1782
}
2335
}
1783
 
2336
 
1784
/*
2337
/*
1785
 * Functions to fill in the boxes of the main mask.
2338
 * Functions to fill in the boxes of the main mask.
Line 1802... Line 2355...
1802
 
2355
 
1803
	if (!DIRTY)
2356
	if (!DIRTY)
1804
	   return;
2357
	   return;
1805
 
2358
 
1806
	if (!gmn)
2359
	if (!gmn)
1807
	{
-
 
1808
//	   KMessageBox::error(this, i18n("No data were loaded!"));
-
 
1809
	   return;
2360
	   return;
1810
	}
-
 
1811
 
2361
 
1812
	if (gmn->type == data_Dnil)
2362
	if (gmn->type == data_Dnil)
1813
	{
2363
	{
1814
	   KMessageBox::error(0, i18n("No data found!"));
2364
	   KMessageBox::error(this, i18n("No data found!"));
1815
	   return;
2365
	   return;
1816
	}
2366
	}
1817
 
2367
 
1818
	if (gmn->type != data_Dlist)     /* List of data */
2368
	if (gmn->type != data_Dlist)     /* List of data */
1819
	{
2369
	{
1820
	   KMessageBox::error(0, i18n("Found unexpected data type %1!").arg(gmn->type));
2370
	   KMessageBox::error(this, i18n("Found unexpected data type %1!").arg(gmn->type));
1821
	   return;
2371
	   return;
1822
	}
2372
	}
1823
 
2373
 
1824
	ds.destroy();
2374
	ds.destroy();
1825
	min_hr = max_hr = avg_hr = 0;
2375
	min_hr = max_hr = avg_hr = 0;
Line 1869... Line 2419...
1869
 
2419
 
1870
	      // Set the name depending on the sport type
2420
	      // Set the name depending on the sport type
1871
	      // This is used on the tab "Summary"
2421
	      // This is used on the tab "Summary"
1872
	      switch (rakt->run->sport_type)
2422
	      switch (rakt->run->sport_type)
1873
	      {
2423
	      {
1874
		 case D1000_running: qs_name = QString("Running: "); break;
2424
		 case D1000_running: qs_name = i18n("Running: "); break;
1875
		 case D1000_biking:  qs_name = QString("Biking: "); break;
2425
		 case D1000_biking:  qs_name = i18n("Biking: "); break;
1876
		 case D1000_other:   qs_name = QString("Other: "); break;
2426
		 case D1000_other:   qs_name = i18n("Other: "); break;
1877
		 default:
2427
		 default:
1878
		    qs_name = QString("Unknown: ");
2428
		    qs_name = i18n("Unknown: ");
1879
	      }
2429
	      }
1880
 
2430
 
1881
	      if (!(lap = ds.getLap(rakt->run->first_lap_index)))
2431
	      if (!(lap = ds.getLap(rakt->run->first_lap_index)))
1882
		 return;
2432
		 return;
1883
 
2433
 
Line 2375... Line 2925...
2375
	oriLeftLat = ic.readEntry("LeftLat", 0.0);
2925
	oriLeftLat = ic.readEntry("LeftLat", 0.0);
2376
	oriRightLon = ic.readEntry("RightLon", 0.0);
2926
	oriRightLon = ic.readEntry("RightLon", 0.0);
2377
	oriRightLat = ic.readEntry("RightLat", 0.0);
2927
	oriRightLat = ic.readEntry("RightLat", 0.0);
2378
//	int isrs = ic.readEntry("SRS", 0);
2928
//	int isrs = ic.readEntry("SRS", 0);
2379
#endif
2929
#endif
2380
	if (curTab == 0)
2930
	if (curTab == 0 && !ActivePrint)
2381
	{
2931
	{
2382
	   width = ui_sportwatcherWidgetBase.imgMap->width() - 2;
2932
	   width = ui_sportwatcherWidgetBase.imgMap->width() - 2;
2383
	   height = ui_sportwatcherWidgetBase.imgMap->height();
2933
	   height = ui_sportwatcherWidgetBase.imgMap->height();
2384
	}
2934
	}
-
 
2935
	else if (ActivePrint)
-
 
2936
	{
-
 
2937
	   width = pmPrMap.width();
-
 
2938
	   height = pmPrMap.height();
-
 
2939
	}
2385
	else
2940
	else
2386
	{
2941
	{
2387
	   width = ui_sportwatcherWidgetBase.grMap->width() - 2;
2942
	   width = ui_sportwatcherWidgetBase.grMap->width() - 2;
2388
	   height = ui_sportwatcherWidgetBase.grMap->height();
2943
	   height = ui_sportwatcherWidgetBase.grMap->height();
2389
	}
2944
	}
Line 2747... Line 3302...
2747
		 poDataset = 0;
3302
		 poDataset = 0;
2748
 
3303
 
2749
		 if (MAP != fName)
3304
		 if (MAP != fName)
2750
		    unlink (fName.toAscii().data());
3305
		    unlink (fName.toAscii().data());
2751
	      }
3306
	      }
-
 
3307
#if defined HAVE_MAPNIK
2752
	      else if (MapType == MPT_SHP)
3308
	      else if (MapType == MPT_SHP)
2753
	      {
3309
	      {
2754
		 QDir shpd(MAP, QString("*.shp"));
3310
		 QDir shpd(MAP, QString("*.shp"));
2755
 
3311
 
2756
		 if (shpd.count() < 1)
3312
		 if (shpd.count() < 1)
Line 2761... Line 3317...
2761
		 else
3317
		 else
2762
		 {
3318
		 {
2763
		 SRender rd;
3319
		 SRender rd;
2764
		 QColor bg(220, 220, 220);		// background color
3320
		 QColor bg(220, 220, 220);		// background color
2765
 
3321
 
2766
		    if (curTab == 0)
3322
		    if (curTab == 0 && !ActivePrint)
2767
		       rd.setDrawArea(*ui_sportwatcherWidgetBase.imgMap);
3323
		       rd.setDrawArea(ui_sportwatcherWidgetBase.imgMap->width(), ui_sportwatcherWidgetBase.imgMap->height());
-
 
3324
		    else if (!ActivePrint)
-
 
3325
		       rd.setDrawArea(ui_sportwatcherWidgetBase.grMap->width(), ui_sportwatcherWidgetBase.grMap->height());
2768
		    else
3326
		    else if (ActivePrint)
2769
		       rd.setDrawArea(*ui_sportwatcherWidgetBase.grMap);
3327
		       rd.setDrawArea(pmPrMap.width(), pmPrMap.height());
2770
 
3328
 
2771
		    rd.setMapType(SRender::MAP_SHAPE);
3329
		    rd.setMapType(SRender::MAP_SHAPE);
2772
 
3330
 
2773
		    if (rd.getMap(posLXY.lon, posLXY.lat, posRXY.lon, posRXY.lat))
3331
		    if (rd.getMap(posLXY.lon, posLXY.lat, posRXY.lon, posRXY.lat))
2774
		    {
3332
		    {
2775
		       paint.fillRect(0, 0, width+2, height+2, bg);
3333
		       paint.fillRect(0, 0, width+2, height+2, bg);
2776
 
-
 
2777
		       if (curTab == 0)
-
 
2778
			  paint.drawPixmap(0, 0, *ui_sportwatcherWidgetBase.imgMap->pixmap());
-
 
2779
		       else
-
 
2780
			  paint.drawPixmap(0, 0, *ui_sportwatcherWidgetBase.grMap->pixmap());
3334
		       paint.drawPixmap(0, 0, rd.pixmap());
2781
 
-
 
2782
		       Fgeo = true;
3335
		       Fgeo = true;
2783
		    }
3336
		    }
2784
		    else
3337
		    else
2785
		       Fgeo = false;
3338
		       Fgeo = false;
2786
		 }
3339
		 }
Line 2797... Line 3350...
2797
		 else
3350
		 else
2798
		 {
3351
		 {
2799
		 SRender rd;
3352
		 SRender rd;
2800
		 QColor bg(220, 220, 220);		// background color
3353
		 QColor bg(220, 220, 220);		// background color
2801
 
3354
 
2802
		    if (curTab == 0)
3355
		    if (curTab == 0 && !ActivePrint)
2803
		       rd.setDrawArea(*ui_sportwatcherWidgetBase.imgMap);
3356
		       rd.setDrawArea(ui_sportwatcherWidgetBase.imgMap->width(), ui_sportwatcherWidgetBase.imgMap->height());
-
 
3357
		    else if (!ActivePrint)
-
 
3358
		       rd.setDrawArea(ui_sportwatcherWidgetBase.grMap->width(), ui_sportwatcherWidgetBase.grMap->height());
2804
		    else
3359
		    else if (ActivePrint)
2805
		       rd.setDrawArea(*ui_sportwatcherWidgetBase.grMap);
3360
		       rd.setDrawArea(pmPrMap.width(), pmPrMap.height());
2806
 
3361
 
2807
		    rd.setMapType(SRender::MAP_OSM);
3362
		    rd.setMapType(SRender::MAP_OSM);
2808
 
3363
 
2809
		    if (rd.getMap(posLXY.lon, posLXY.lat, posRXY.lon, posRXY.lat))
3364
		    if (rd.getMap(posLXY.lon, posLXY.lat, posRXY.lon, posRXY.lat))
2810
		    {
3365
		    {
2811
		       paint.fillRect(0, 0, width+2, height+2, bg);
3366
		       paint.fillRect(0, 0, width+2, height+2, bg);
2812
 
-
 
2813
		       if (curTab == 0)
-
 
2814
			  paint.drawPixmap(0, 0, *ui_sportwatcherWidgetBase.imgMap->pixmap());
-
 
2815
		       else
-
 
2816
			  paint.drawPixmap(0, 0, *ui_sportwatcherWidgetBase.grMap->pixmap());
3367
		       paint.drawPixmap(0, 0, rd.pixmap());
2817
 
-
 
2818
		       Fgeo = true;
3368
		       Fgeo = true;
2819
		    }
3369
		    }
2820
		    else
3370
		    else
2821
		       Fgeo = false;
3371
		       Fgeo = false;
2822
		 }
3372
		 }
2823
	      }
3373
	      }
-
 
3374
#endif	// HAVE_MAPNIK
2824
	      else
3375
	      else
2825
	      {
3376
	      {
2826
		 KMessageBox::error(this, i18n("Error opening map file!"));
3377
		 KMessageBox::error(this, i18n("Error opening map file!"));
2827
		 Fgeo = false;
3378
		 Fgeo = false;
2828
	      }
3379
	      }
2829
	   }
3380
	   }
2830
	}
3381
	}
2831
#endif
3382
#endif	// HAVE_GDAL
2832
	/*
3383
	/*
2833
	 * Here we come to draw the track. It will be drawn over the previous
3384
	 * Here we come to draw the track. It will be drawn over the previous
2834
	 * created map image.
3385
	 * created map image.
2835
	 */
3386
	 */
2836
	// Colors and fonts
3387
	// Colors and fonts
Line 2958... Line 3509...
2958
	   paint.drawPixmap (x2, y2 - 16, qpx);
3509
	   paint.drawPixmap (x2, y2 - 16, qpx);
2959
	}
3510
	}
2960
 
3511
 
2961
	paint.end();
3512
	paint.end();
2962
 
3513
 
2963
	if (curTab == 0)
3514
	if (curTab == 0 && !ActivePrint)
2964
	   ui_sportwatcherWidgetBase.imgMap->setPixmap(pmMap);
3515
	   ui_sportwatcherWidgetBase.imgMap->setPixmap(pmMap);
-
 
3516
	else if (ActivePrint)
-
 
3517
	   pmPrMap = pmMap;
2965
	else
3518
	else
2966
	   ui_sportwatcherWidgetBase.grMap->setPixmap(pmMap);
3519
	   ui_sportwatcherWidgetBase.grMap->setPixmap(pmMap);
2967
 
3520
 
2968
	QApplication::restoreOverrideCursor();
3521
	QApplication::restoreOverrideCursor();
2969
}
3522
}
Line 3719... Line 4272...
3719
	}
4272
	}
3720
 
4273
 
3721
	DIRTY = false;
4274
	DIRTY = false;
3722
}
4275
}
3723
 
4276
 
3724
void sportwatcherWidget::showThreeCurve()
4277
void sportwatcherWidget::showThreeCurve(int pw, int ph)
3725
{
4278
{
3726
QPainter ptHR, ptElevation, ptSpeed;
4279
QPainter ptHR, ptElevation, ptSpeed;
3727
int width, height, wdHR, htHR, wdElev, htElev, wdSpeed, htSpeed;
4280
int width, height, wdHR, htHR, wdElev, htElev, wdSpeed, htSpeed;
3728
int i, secs, cuType;
4281
int i, secs, cuType;
3729
int lineHeight, margin_left, margin_right, margin_bottom;
4282
int lineHeight, margin_left, margin_right, margin_bottom;
Line 3742... Line 4295...
3742
	// values detected in the function showLap(). In case
4295
	// values detected in the function showLap(). In case
3743
	// all values are 0, we exit here.
4296
	// all values are 0, we exit here.
3744
	if (min_hr == 0 && max_hr == 0 && min_height == 0.0 && max_height == 0.0)
4297
	if (min_hr == 0 && max_hr == 0 && min_height == 0.0 && max_height == 0.0)
3745
	   return;
4298
	   return;
3746
 
4299
 
3747
	if (!DIRTY || curTab != 2)
4300
	if (!ActivePrint && (!DIRTY || curTab != 2))
3748
	   return;
4301
	   return;
3749
 
4302
 
3750
	// Get the dimensions of the available draw area
4303
	// Get the dimensions of the available draw area
3751
	// First for heart rate
4304
	// First for heart rate
-
 
4305
	if (!ActivePrint)
-
 
4306
	{
3752
	wdHR = ui_sportwatcherWidgetBase.grHR->width() - 2;
4307
	   wdHR = ui_sportwatcherWidgetBase.grHR->width() - 2;
3753
	htHR = ui_sportwatcherWidgetBase.grHR->height();
4308
	   htHR = ui_sportwatcherWidgetBase.grHR->height();
3754
	pmHR = QPixmap(wdHR, htHR);
4309
	   pmHR = QPixmap(wdHR, htHR);
3755
	// Then for elevation
4310
	   // Then for elevation
3756
	wdElev = ui_sportwatcherWidgetBase.grElevation->width() - 2;
4311
	   wdElev = ui_sportwatcherWidgetBase.grElevation->width() - 2;
3757
	htElev = ui_sportwatcherWidgetBase.grElevation->height();
4312
	   htElev = ui_sportwatcherWidgetBase.grElevation->height();
3758
	pmElevation = QPixmap(wdElev, htElev);
4313
	   pmElevation = QPixmap(wdElev, htElev);
3759
	// And at last for speed
4314
	   // And at last for speed
3760
	wdSpeed = ui_sportwatcherWidgetBase.grSpeed->width() - 2;
4315
	   wdSpeed = ui_sportwatcherWidgetBase.grSpeed->width() - 2;
3761
	htSpeed = ui_sportwatcherWidgetBase.grSpeed->height();
4316
	   htSpeed = ui_sportwatcherWidgetBase.grSpeed->height();
3762
	pmSpeed = QPixmap(wdSpeed, htSpeed);
4317
	   pmSpeed = QPixmap(wdSpeed, htSpeed);
3763
	// Initialize QPainter
4318
	   // Initialize QPainter
3764
	ptHR.begin(&pmHR);
4319
	   ptHR.begin(&pmHR);
3765
	ptElevation.begin(&pmElevation);
4320
	   ptElevation.begin(&pmElevation);
3766
	ptSpeed.begin(&pmSpeed);
4321
	   ptSpeed.begin(&pmSpeed);
-
 
4322
	}
-
 
4323
	else if (ActivePrint && pw > 0 && ph > 0)
-
 
4324
	{
-
 
4325
	   wdHR = wdElev = wdSpeed = pw;
-
 
4326
	   htHR = htElev = htSpeed = ph;
-
 
4327
	   prHR = prElevation = prSpeed = QPixmap(pw, ph);
-
 
4328
	   ptHR.begin(&prHR);
-
 
4329
	   ptElevation.begin(&prElevation);
-
 
4330
	   ptSpeed.begin(&prSpeed);
-
 
4331
	}
-
 
4332
	else
-
 
4333
	   return;
3767
 
4334
 
3768
	// we need a somewhat bigger area to draw our curves than
4335
	// we need a somewhat bigger area to draw our curves than
3769
	// we have with the real min and max values.
4336
	// we have with the real min and max values.
3770
	if (max_height > 0.0)
4337
	if (max_height > 0.0)
3771
	{
4338
	{
Line 4450... Line 5017...
4450
	}
5017
	}
4451
 
5018
 
4452
	ptHR.end();
5019
	ptHR.end();
4453
	ptElevation.end();
5020
	ptElevation.end();
4454
	ptSpeed.end();
5021
	ptSpeed.end();
4455
	ui_sportwatcherWidgetBase.grHR->setPixmap(pmHR);
-
 
4456
	ui_sportwatcherWidgetBase.grElevation->setPixmap(pmElevation);
-
 
4457
	ui_sportwatcherWidgetBase.grSpeed->setPixmap(pmSpeed);
-
 
4458
 
5022
 
-
 
5023
	if (!ActivePrint)
-
 
5024
	{
-
 
5025
	   ui_sportwatcherWidgetBase.grHR->setPixmap(pmHR);
-
 
5026
	   ui_sportwatcherWidgetBase.grElevation->setPixmap(pmElevation);
-
 
5027
	   ui_sportwatcherWidgetBase.grSpeed->setPixmap(pmSpeed);
-
 
5028
	}
4459
	// free the chain of altitudes
5029
	// free the chain of altitudes
4460
	avgHakt = avgHfirst;
5030
	avgHakt = avgHfirst;
4461
 
5031
 
4462
	while (avgHakt)
5032
	while (avgHakt)
4463
	{
5033
	{