Subversion Repositories public

Rev

Rev 299 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 299 Rev 314
Line 1... Line 1...
1
/***************************************************************************
1
/***************************************************************************
2
 *   Copyright (C) 2007 - 2009 by Andreas Theofilu                         *
2
 *   Copyright (C) 2007 - 2013 by Andreas Theofilu                         *
3
 *   andreas@theosys.at                                                    *
3
 *   andreas@theosys.at                                                    *
4
 *                                                                         *
4
 *                                                                         *
5
 *   This program is free software; you can redistribute it and/or modify  *
5
 *   This program is free software; you can redistribute it and/or modify  *
6
 *   it under the terms of the GNU General Public License as published by  *
6
 *   it under the terms of the GNU General Public License as published by  *
7
 *   the Free Software Foundation version 3 of the License.                *
7
 *   the Free Software Foundation version 3 of the License.                *
Line 50... Line 50...
50
#include <KIcon>
50
#include <KIcon>
51
#include <QPrintDialog>
51
#include <QPrintDialog>
52
#include <QPrinter>
52
#include <QPrinter>
53
 
53
 
54
#if defined HAVE_GDAL
54
#if defined HAVE_GDAL
55
   #include <gdal/ogr_spatialref.h>
55
#include <gdal/ogr_spatialref.h>
56
   #include <gdal/ogrsf_frmts.h>
56
#include <gdal/ogrsf_frmts.h>
57
   #include <gdal/gdalwarper.h>
57
#include <gdal/gdalwarper.h>
58
   #include <gdal/ogrsf_frmts.h>
58
#include <gdal/ogrsf_frmts.h>
59
   #include "GDALError.h"
59
#include "GDALError.h"
60
#endif
60
#endif
61
 
61
 
62
#include "garmin.h"
62
#include "garmin.h"
63
#include "transform.h"
63
#include "transform.h"
64
#include "import.h"
-
 
65
 
64
 
66
#if defined HAVE_MAPNIK
65
#if defined HAVE_MAPNIK
67
   #include "render.h"
66
#include "render.h"
68
#endif
67
#endif
69
 
68
 
70
using std::cout;
69
using std::cout;
71
using std::cerr;
70
using std::cerr;
72
using std::clog;
71
using std::clog;
Line 82... Line 81...
82
#if defined HAVE_GDAL
81
#if defined HAVE_GDAL
83
typedef struct ERRMSG
82
typedef struct ERRMSG
84
{
83
{
85
	char msg[4096];
84
	char msg[4096];
86
	ERRMSG *next;
85
	ERRMSG *next;
87
}ERRMSG;
86
} ERRMSG;
88
 
87
 
89
ERRMSG *firstError;
88
ERRMSG *firstError;
90
#endif
89
#endif
91
 
90
 
92
sportwatcherWidget::sportwatcherWidget(QWidget *parent)
91
sportwatcherWidget::sportwatcherWidget(QWidget *parent)
Line 113... Line 112...
113
	tabDirt0 = tabDirt1 = tabDirt2 = tabDirt3 = true;
112
	tabDirt0 = tabDirt1 = tabDirt2 = tabDirt3 = true;
114
	ActivePrint = false;	// true if we are printing on paper
113
	ActivePrint = false;	// true if we are printing on paper
115
	kl = new KLocale(QString("kdesktop"), 0);
114
	kl = new KLocale(QString("kdesktop"), 0);
116
 
115
 
117
	// Load the config parameters
116
	// Load the config parameters
118
	KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig);
117
	KConfig cfg(QString("sportwatcher.rc"), KConfig::SimpleConfig);
119
	KConfigGroup ic (&cfg, "SportWatcher");
118
	KConfigGroup ic(&cfg, "SportWatcher");
120
	lower1 = ic.readEntry("lower1", 0);
119
	lower1 = ic.readEntry("lower1", 0);
121
	lower2 = ic.readEntry("lower2", 0);
120
	lower2 = ic.readEntry("lower2", 0);
122
	lower3 = ic.readEntry("lower3", 0);
121
	lower3 = ic.readEntry("lower3", 0);
123
	upper1 = ic.readEntry("upper1", 0);
122
	upper1 = ic.readEntry("upper1", 0);
124
	upper2 = ic.readEntry("upper2", 0);
123
	upper2 = ic.readEntry("upper2", 0);
Line 154... Line 153...
154
#endif
153
#endif
155
}
154
}
156
 
155
 
157
void sportwatcherWidget::destroy()
156
void sportwatcherWidget::destroy()
158
{
157
{
159
	if (gmn)
158
	if(gmn)
160
	   garmin_free_data (gmn);
159
		garmin_free_data(gmn);
161
 
160
 
162
	gmn = 0;
161
	gmn = 0;
163
	oldTransX = oldTransY = 0.0;
162
	oldTransX = oldTransY = 0.0;
164
}
163
}
165
 
164
 
Line 171... Line 170...
171
	ui_sportwatcherWidgetBase.btGlasMinus->setIcon(KIcon("glas_minus"));
170
	ui_sportwatcherWidgetBase.btGlasMinus->setIcon(KIcon("glas_minus"));
172
	ui_sportwatcherWidgetBase.btGlasPlus->setIcon(KIcon("glas_plus"));
171
	ui_sportwatcherWidgetBase.btGlasPlus->setIcon(KIcon("glas_plus"));
173
	ui_sportwatcherWidgetBase.btFlag->setIcon(KIcon("flag"));
172
	ui_sportwatcherWidgetBase.btFlag->setIcon(KIcon("flag"));
174
	ui_sportwatcherWidgetBase.btFullscreen->setIcon(KIcon("fullscreen"));
173
	ui_sportwatcherWidgetBase.btFullscreen->setIcon(KIcon("fullscreen"));
175
 
174
 
176
	if (curTab != 0)
175
	if(curTab != 0)
177
	{
176
	{
178
	   ui_sportwatcherWidgetBase.tabView->setCurrentIndex(0);
177
		ui_sportwatcherWidgetBase.tabView->setCurrentIndex(0);
179
	   curTab = ui_sportwatcherWidgetBase.tabView->currentIndex();
178
		curTab = ui_sportwatcherWidgetBase.tabView->currentIndex();
180
	}
179
	}
181
 
180
 
182
//	btHand->setToggleButton(true);
181
//	btHand->setToggleButton(true);
183
//	btGlas->setToggleButton(true);
182
//	btGlas->setToggleButton(true);
184
	// Fill the activities
183
	// Fill the activities
Line 190... Line 189...
190
#endif
189
#endif
191
}
190
}
192
 
191
 
193
QTreeWidgetItem *sportwatcherWidget::findElement(QTreeWidget *wdg, const QString &val)
192
QTreeWidgetItem *sportwatcherWidget::findElement(QTreeWidget *wdg, const QString &val)
194
{
193
{
195
QTreeWidgetItem *item, *child, *subchild;
194
	QTreeWidgetItem *item, *child, *subchild;
196
 
195
 
197
	if (!wdg)
196
	if(!wdg)
198
	   return 0;
197
		return 0;
199
 
198
 
200
	for (int a = 0; a < wdg->topLevelItemCount(); a++)
199
	for(int a = 0; a < wdg->topLevelItemCount(); a++)
201
	{
200
	{
202
	   if (!(item = wdg->topLevelItem(a)))
201
		if(!(item = wdg->topLevelItem(a)))
203
	      continue;
202
			continue;
204
 
203
 
205
	   for (int j = 0; j < item->childCount(); j++)
204
		for(int j = 0; j < item->childCount(); j++)
206
	   {
205
		{
207
	      if (!(child = item->child(j)))
206
			if(!(child = item->child(j)))
208
		 continue;
207
				continue;
209
 
208
 
210
	      if (child->data(0, Qt::UserRole).toString() == val)
209
			if(child->data(0, Qt::UserRole).toString() == val)
211
		 return child;
210
				return child;
212
 
211
 
213
	      for (int i = 0; i < child->childCount(); i++)
212
			for(int i = 0; i < child->childCount(); i++)
214
	      {
213
			{
215
		 if (!(subchild = child->child(i)))
214
				if(!(subchild = child->child(i)))
216
		    continue;
215
					continue;
217
 
216
 
218
		 if (subchild->data(0, Qt::UserRole).toString() == val)
217
				if(subchild->data(0, Qt::UserRole).toString() == val)
219
		    return subchild;
218
					return subchild;
220
	      }
219
			}
221
	   }
220
		}
222
	}
221
	}
223
 
222
 
224
	return 0;
223
	return 0;
225
}
224
}
226
 
225
 
Line 230... Line 229...
230
 * to find the basic data of activities. Then add the information into
229
 * to find the basic data of activities. Then add the information into
231
 * the activities KListView.
230
 * the activities KListView.
232
 */
231
 */
233
void sportwatcherWidget::getActivities()
232
void sportwatcherWidget::getActivities()
234
{
233
{
235
QString path, txt;
234
	QString path, txt;
236
QDir mdir, dir = QDir::home();
235
	QDir mdir, dir = QDir::home();
237
QStringList years, months;
236
	QStringList years, months;
238
QTreeWidgetItem *running, *biking, *other, *year_run, *year_bike, *year_other;
237
	QTreeWidgetItem *running, *biking, *other, *year_run, *year_bike, *year_other;
239
QTreeWidgetItem *el;
238
	QTreeWidgetItem *el;
240
QList<QTreeWidgetItem *> item;
239
	QList<QTreeWidgetItem *> item;
241
int i, j;
240
	int i, j;
242
int y_run, y_bike, y_other;
241
	int y_run, y_bike, y_other;
243
RUN_NODE *rn;
242
	RUN_NODE *rn;
244
LAP *lap;
243
	LAP *lap;
245
 
244
 
246
	if (Data.isEmpty())
245
	if(Data.isEmpty())
247
	{
246
	{
248
	   path = dir.homePath();
247
		path = dir.homePath();
249
	   path.append("/.sportwatcher");
248
		path.append("/.sportwatcher");
250
	}
249
	}
251
	else
250
	else
252
	   path = Data;
251
		path = Data;
253
 
252
 
254
	dir.setPath(path);
253
	dir.setPath(path);
255
	dir.refresh();
254
	dir.refresh();
256
 
255
 
257
	if (!dir.exists())
256
	if(!dir.exists())
258
	{
257
	{
259
	   dir.mkdir(path);
258
		dir.mkdir(path);
260
	   return;
259
		return;
261
	}
260
	}
262
 
261
 
263
	destroy();
262
	destroy();
264
 
263
 
265
	if (!ui_sportwatcherWidgetBase.liActivities)
264
	if(!ui_sportwatcherWidgetBase.liActivities)
266
	{
265
	{
267
	   KMessageBox::error(this, i18n("Error initializing some widgets of main window!"));
266
		KMessageBox::error(this, i18n("Error initializing some widgets of main window!"));
268
	   return;
267
		return;
269
	}
268
	}
270
 
269
 
271
	ui_sportwatcherWidgetBase.liActivities->clear();
270
	ui_sportwatcherWidgetBase.liActivities->clear();
272
	ui_sportwatcherWidgetBase.liActivities->setSortingEnabled(false);
271
	ui_sportwatcherWidgetBase.liActivities->setSortingEnabled(false);
273
	ui_sportwatcherWidgetBase.liActivities->setColumnCount(1);
272
	ui_sportwatcherWidgetBase.liActivities->setColumnCount(1);
274
 
273
 
275
	running = new QTreeWidgetItem(ui_sportwatcherWidgetBase.liActivities);
274
	running = new QTreeWidgetItem(ui_sportwatcherWidgetBase.liActivities);
276
	biking = new QTreeWidgetItem(ui_sportwatcherWidgetBase.liActivities);
275
	biking = new QTreeWidgetItem(ui_sportwatcherWidgetBase.liActivities);
277
	other = new QTreeWidgetItem(ui_sportwatcherWidgetBase.liActivities);
276
	other = new QTreeWidgetItem(ui_sportwatcherWidgetBase.liActivities);
278
 
277
 
279
	if (!other || !biking || !running)
278
	if(!other || !biking || !running)
280
	{
279
	{
281
	   KMessageBox::error(this, i18n("Not enough memory to initilize application!"));
280
		KMessageBox::error(this, i18n("Not enough memory to initilize application!"));
282
	   return;
281
		return;
283
	}
282
	}
284
 
283
 
285
	running->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
284
	running->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
286
	biking->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
285
	biking->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
287
	other->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
286
	other->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
Line 303... Line 302...
303
	dir.setFilter(QDir::Dirs | QDir::NoSymLinks);
302
	dir.setFilter(QDir::Dirs | QDir::NoSymLinks);
304
	dir.setSorting(QDir::Name);
303
	dir.setSorting(QDir::Name);
305
	dir.refresh();
304
	dir.refresh();
306
	QFileInfoList list = dir.entryInfoList();
305
	QFileInfoList list = dir.entryInfoList();
307
 
306
 
308
	if (!list.size())
307
	if(!list.size())
309
	   return;
308
		return;
310
 
309
 
311
	for (i = 0; i < list.size(); i++)		// Years
310
	for(i = 0; i < list.size(); i++)		// Years
312
	{
311
	{
313
	QFileInfo fileInfo = list.at(i);
312
		QFileInfo fileInfo = list.at(i);
314
 
313
 
315
	   if (fileInfo.fileName() == QString(".") || fileInfo.fileName() == QString(".."))
314
		if(fileInfo.fileName() == QString(".") || fileInfo.fileName() == QString(".."))
316
	      continue;
315
			continue;
317
 
316
 
318
	   years += fileInfo.absoluteFilePath();
317
		years += fileInfo.absoluteFilePath();
319
	}
318
	}
320
 
319
 
321
	for (i = 0; i < years.size(); ++i)
320
	for(i = 0; i < years.size(); ++i)
322
	{
321
	{
323
	   if (months.size() > 0)
322
		if(months.size() > 0)
324
	      months.clear();
323
			months.clear();
325
 
-
 
326
	   dir.setPath(years.at(i));
-
 
327
	   dir.refresh();
-
 
328
	   list = dir.entryInfoList();
-
 
329
 
-
 
330
	   if (!list.size())
-
 
331
	      continue;
-
 
332
 
324
 
333
	   for (j = 0; j < list.size(); j++)		// Months
325
		dir.setPath(years.at(i));
334
	   {
326
		dir.refresh();
335
	   QFileInfo fileInfo = list.at(j);
327
		list = dir.entryInfoList();
336
 
328
 
337
	      if (fileInfo.fileName() == QString(".") || fileInfo.fileName() == QString(".."))
329
		if(!list.size())
338
		 continue;
330
			continue;
339
 
331
 
340
	      months += fileInfo.absoluteFilePath();
332
		for(j = 0; j < list.size(); j++)		// Months
341
	   }
333
		{
-
 
334
			QFileInfo fileInfo = list.at(j);
342
 
335
 
343
	   for (j = 0; j < months.size(); ++j)
-
 
344
	   {
-
 
345
	      mdir.setPath(months.at(j));
-
 
346
	      mdir.cd(months.at(j));
-
 
347
	      mdir.setFilter(QDir::Files | QDir::NoSymLinks);
-
 
348
	      mdir.setSorting(QDir::Name);
-
 
349
	      mdir.setNameFilters(QStringList("*.gmn"));
336
			if(fileInfo.fileName() == QString(".") || fileInfo.fileName() == QString(".."))
350
	      mdir.refresh();
337
				continue;
351
	      list = mdir.entryInfoList();
-
 
352
 
338
 
353
	      if (!list.size())
339
			months += fileInfo.absoluteFilePath();
354
		 continue;
340
		}
355
 
341
 
-
 
342
		for(j = 0; j < months.size(); ++j)
-
 
343
		{
-
 
344
			mdir.setPath(months.at(j));
-
 
345
			mdir.cd(months.at(j));
-
 
346
			mdir.setFilter(QDir::Files | QDir::NoSymLinks);
-
 
347
			mdir.setSorting(QDir::Name);
-
 
348
			mdir.setNameFilters(QStringList("*.gmn"));
-
 
349
			mdir.refresh();
-
 
350
			list = mdir.entryInfoList();
-
 
351
 
-
 
352
			if(!list.size())
-
 
353
				continue;
-
 
354
 
356
	      for (int a = 0; a < list.size(); a++)		// Files
355
			for(int a = 0; a < list.size(); a++)		// Files
357
	      {
356
			{
358
	      QFileInfo fileInfo = list.at(a);
357
				QFileInfo fileInfo = list.at(a);
359
 
358
 
360
		 files += fileInfo.absoluteFilePath();
359
				files += fileInfo.absoluteFilePath();
361
	      }
360
			}
362
	   }
361
		}
363
	}
362
	}
364
 
363
 
365
	y_run = y_bike = y_other = 0;
364
	y_run = y_bike = y_other = 0;
366
	year_run = year_bike = year_other = 0;
365
	year_run = year_bike = year_other = 0;
-
 
366
 
367
	// Open every file and read its head
367
	// Open every file and read its head
368
	for (i = 0; i < files.size(); ++i)
368
	for(i = 0; i < files.size(); ++i)
369
	{
369
	{
370
	QTreeWidgetItem *yr, *yb, *yo;
370
		QTreeWidgetItem *yr, *yb, *yo;
371
 
371
 
372
	   if (findElement(ui_sportwatcherWidgetBase.liActivities, files.at(i)))
372
		if(findElement(ui_sportwatcherWidgetBase.liActivities, files.at(i)))
373
	      continue;
373
			continue;
374
 
374
 
375
	   spw.destroy();
375
		spw.destroy();
376
 
376
 
377
	   if (spw.setFileName(files.at(i).toAscii().constData()) == -1)
377
		if(spw.setFileName(files.at(i).toAscii().constData()) == -1)
378
	      return;
-
 
379
 
-
 
380
	   if (gmn)
-
 
381
	   {
-
 
382
	      garmin_free_data (gmn);
-
 
383
	      gmn = 0;
-
 
384
	   }
-
 
385
 
-
 
386
	   if (!(gmn = spw.readFile()))
-
 
387
	      continue;
-
 
388
 
-
 
389
	   ds.destroy();
-
 
390
	   ds.garmin_print_data(gmn);
-
 
391
	   rn = ds.getRunNode();
-
 
392
 
-
 
393
	   if (!rn)
-
 
394
	      return;
-
 
395
 
-
 
396
	   lap = ds.getLap(rn->run->first_lap_index);
-
 
397
 
-
 
398
	   if (!lap)
-
 
399
	      return;
378
			return;
400
 
-
 
401
	   const QDateTime *qt = garmin_dtime (lap->start_time);
-
 
402
	   // By default set the name of the session to the date and time
-
 
403
	   // it was recorded.
-
 
404
	   QString idx = kl->formatDateTime (*qt, KLocale::ShortDate, true);
-
 
405
	   QString stTip = kl->formatDateTime (*qt, KLocale::LongDate, true);
-
 
406
 
-
 
407
	   // If we have a custom name for this session, set it.
-
 
408
	   if (strlen (rn->run->workout.name) > 1 && strlen (rn->run->workout.name) < 16 && isalpha (rn->run->workout.name[0]))
-
 
409
	      idx = QString (rn->run->workout.name);
-
 
410
 
-
 
411
	   switch (rn->run->sport_type)
-
 
412
	   {
-
 
413
	      case D1000_running:
-
 
414
		 yr = findElement(ui_sportwatcherWidgetBase.liActivities, QString("run_%1").arg(qt->date().year()));
-
 
415
 
-
 
416
		 if (!yr && qt->date().year() != y_run)
-
 
417
		 {
-
 
418
		    year_run = new QTreeWidgetItem(running, running, QTreeWidgetItem::Type);
-
 
419
		    y_run = qt->date().year();
-
 
420
		    year_run->setText(0, QString("%1").arg(y_run));
-
 
421
		    year_run->setData(0, Qt::UserRole, QString("run_%1").arg(y_run));
-
 
422
		    year_run->setIcon(0, KIcon(QString("today")));
-
 
423
		    year_run->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
-
 
424
		 }
-
 
425
		 else
-
 
426
		    year_run = yr;
-
 
427
 
-
 
428
		 el = new QTreeWidgetItem(year_run, year_run, QTreeWidgetItem::Type);
-
 
429
		 el->setText(0, idx);
-
 
430
		 el->setData(0, Qt::UserRole, files.at(i));
-
 
431
		 el->setIcon(0, KIcon(QString("spw-running")));
-
 
432
		 el->setStatusTip(0, stTip);
-
 
433
		 el->setToolTip(0, stTip);
-
 
434
		 el->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
-
 
435
	      break;
-
 
436
 
-
 
437
	      case D1000_biking:
-
 
438
		 yb = findElement(ui_sportwatcherWidgetBase.liActivities, QString("bike_%1").arg(qt->date().year()));
-
 
439
 
-
 
440
		 if (!yb && qt->date().year() != y_bike)
-
 
441
		 {
-
 
442
		    year_bike = new QTreeWidgetItem(biking, biking, QTreeWidgetItem::Type);
-
 
443
		    y_bike = qt->date().year();
-
 
444
		    year_bike->setText(0, QString("%1").arg(y_bike));
-
 
445
		    year_bike->setData(0, Qt::UserRole, QString("bike_%1").arg(y_bike));
-
 
446
		    year_bike->setIcon(0, KIcon(QString("today")));
-
 
447
		    year_bike->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
-
 
448
		 }
-
 
449
		 else
-
 
450
		    year_bike = yb;
-
 
451
 
-
 
452
		 el = new QTreeWidgetItem(year_bike, year_bike, QTreeWidgetItem::Type);
-
 
453
		 el->setText(0, idx);
-
 
454
		 el->setData(0, Qt::UserRole, files.at(i));
-
 
455
		 el->setStatusTip(0, stTip);
-
 
456
		 el->setToolTip(0, stTip);
-
 
457
		 el->setIcon(0, KIcon(QString("bike")));
-
 
458
		 el->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
-
 
459
	      break;
-
 
460
 
-
 
461
	      case D1000_other:
-
 
462
	      default:
-
 
463
		 yo = findElement(ui_sportwatcherWidgetBase.liActivities, QString("other_%1").arg(qt->date().year()));
-
 
464
 
-
 
465
		 if (!yo && qt->date().year() != y_other)
-
 
466
		 {
-
 
467
		    year_other = new QTreeWidgetItem(other, other, QTreeWidgetItem::Type);
-
 
468
		    y_other = qt->date().year();
-
 
469
		    year_other->setText(0, QString("%1").arg(y_other));
-
 
470
		    year_other->setData(0, Qt::UserRole, QString("other_%1").arg(y_other));
-
 
471
		    year_other->setIcon(0, KIcon(QString("today")));
-
 
472
		    year_other->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
-
 
473
		 }
-
 
474
		 else
-
 
475
		    year_other = yo;
-
 
476
 
-
 
477
		 el = new QTreeWidgetItem(year_other, year_other, QTreeWidgetItem::Type);
-
 
478
		 el->setText(0, idx);
-
 
479
		 el->setData(0, Qt::UserRole, files.at(i));
-
 
480
		 el->setStatusTip(0, stTip);
-
 
481
		 el->setToolTip(0, stTip);
-
 
482
		 el->setIcon(0, KIcon(QString("other")));
-
 
483
		 el->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
-
 
484
	   }
-
 
485
 
379
 
-
 
380
		if(gmn)
-
 
381
		{
-
 
382
			garmin_free_data(gmn);
-
 
383
			gmn = 0;
-
 
384
		}
-
 
385
 
-
 
386
		if(!(gmn = spw.readFile()))
-
 
387
			continue;
-
 
388
 
-
 
389
		ds.destroy();
-
 
390
		ds.garmin_print_data(gmn);
-
 
391
		rn = ds.getRunNode();
-
 
392
 
-
 
393
		if(!rn)
-
 
394
			return;
-
 
395
 
-
 
396
		lap = ds.getLap(rn->run->first_lap_index);
-
 
397
 
-
 
398
		if(!lap)
-
 
399
			return;
-
 
400
 
-
 
401
		const QDateTime *qt = garmin_dtime(lap->start_time);
-
 
402
		// By default set the name of the session to the date and time
-
 
403
		// it was recorded.
-
 
404
		QString idx = kl->formatDateTime(*qt, KLocale::ShortDate, true);
-
 
405
		QString stTip = kl->formatDateTime(*qt, KLocale::LongDate, true);
-
 
406
 
-
 
407
		// If we have a custom name for this session, set it.
-
 
408
		if(strlen(rn->run->workout.name) > 1 && strlen(rn->run->workout.name) < 16 && isalpha(rn->run->workout.name[0]))
-
 
409
			idx = QString(rn->run->workout.name);
-
 
410
 
-
 
411
		switch(rn->run->sport_type)
-
 
412
		{
-
 
413
			case D1000_running:
-
 
414
				yr = findElement(ui_sportwatcherWidgetBase.liActivities, QString("run_%1").arg(qt->date().year()));
-
 
415
 
-
 
416
				if(!yr && qt->date().year() != y_run)
-
 
417
				{
-
 
418
					year_run = new QTreeWidgetItem(running, running, QTreeWidgetItem::Type);
-
 
419
					y_run = qt->date().year();
-
 
420
					year_run->setText(0, QString("%1").arg(y_run));
-
 
421
					year_run->setData(0, Qt::UserRole, QString("run_%1").arg(y_run));
-
 
422
					year_run->setIcon(0, KIcon(QString("today")));
-
 
423
					year_run->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
-
 
424
				}
-
 
425
				else
-
 
426
					year_run = yr;
-
 
427
 
-
 
428
				el = new QTreeWidgetItem(year_run, year_run, QTreeWidgetItem::Type);
-
 
429
				el->setText(0, idx);
-
 
430
				el->setData(0, Qt::UserRole, files.at(i));
-
 
431
				el->setIcon(0, KIcon(QString("spw-running")));
-
 
432
				el->setStatusTip(0, stTip);
-
 
433
				el->setToolTip(0, stTip);
-
 
434
				el->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
-
 
435
				break;
-
 
436
 
-
 
437
			case D1000_biking:
-
 
438
				yb = findElement(ui_sportwatcherWidgetBase.liActivities, QString("bike_%1").arg(qt->date().year()));
-
 
439
 
-
 
440
				if(!yb && qt->date().year() != y_bike)
-
 
441
				{
-
 
442
					year_bike = new QTreeWidgetItem(biking, biking, QTreeWidgetItem::Type);
-
 
443
					y_bike = qt->date().year();
-
 
444
					year_bike->setText(0, QString("%1").arg(y_bike));
-
 
445
					year_bike->setData(0, Qt::UserRole, QString("bike_%1").arg(y_bike));
-
 
446
					year_bike->setIcon(0, KIcon(QString("today")));
-
 
447
					year_bike->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
-
 
448
				}
-
 
449
				else
-
 
450
					year_bike = yb;
-
 
451
 
-
 
452
				el = new QTreeWidgetItem(year_bike, year_bike, QTreeWidgetItem::Type);
-
 
453
				el->setText(0, idx);
-
 
454
				el->setData(0, Qt::UserRole, files.at(i));
-
 
455
				el->setStatusTip(0, stTip);
-
 
456
				el->setToolTip(0, stTip);
-
 
457
				el->setIcon(0, KIcon(QString("bike")));
-
 
458
				el->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
-
 
459
				break;
-
 
460
 
-
 
461
			case D1000_other:
-
 
462
			default:
-
 
463
				yo = findElement(ui_sportwatcherWidgetBase.liActivities, QString("other_%1").arg(qt->date().year()));
-
 
464
 
-
 
465
				if(!yo && qt->date().year() != y_other)
-
 
466
				{
-
 
467
					year_other = new QTreeWidgetItem(other, other, QTreeWidgetItem::Type);
-
 
468
					y_other = qt->date().year();
-
 
469
					year_other->setText(0, QString("%1").arg(y_other));
-
 
470
					year_other->setData(0, Qt::UserRole, QString("other_%1").arg(y_other));
-
 
471
					year_other->setIcon(0, KIcon(QString("today")));
-
 
472
					year_other->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
-
 
473
				}
-
 
474
				else
-
 
475
					year_other = yo;
-
 
476
 
-
 
477
				el = new QTreeWidgetItem(year_other, year_other, QTreeWidgetItem::Type);
-
 
478
				el->setText(0, idx);
-
 
479
				el->setData(0, Qt::UserRole, files.at(i));
-
 
480
				el->setStatusTip(0, stTip);
-
 
481
				el->setToolTip(0, stTip);
-
 
482
				el->setIcon(0, KIcon(QString("other")));
-
 
483
				el->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
-
 
484
		}
-
 
485
 
486
	   delete qt;
486
		delete qt;
487
	}
487
	}
488
 
488
 
489
	ui_sportwatcherWidgetBase.liActivities->setItemExpanded(running, true);
489
	ui_sportwatcherWidgetBase.liActivities->setItemExpanded(running, true);
490
 
490
 
491
	if (year_run)
491
	if(year_run)
492
	   ui_sportwatcherWidgetBase.liActivities->setItemExpanded(year_run, true);
492
		ui_sportwatcherWidgetBase.liActivities->setItemExpanded(year_run, true);
493
 
493
 
494
	if (gmn)
494
	if(gmn)
495
	   garmin_free_data (gmn);
495
		garmin_free_data(gmn);
496
 
496
 
497
	gmn = 0;
497
	gmn = 0;
498
}
498
}
499
 
499
 
500
/*$SPECIALIZATION$*/
500
/*$SPECIALIZATION$*/
Line 507... Line 507...
507
	DIRTY = false;
507
	DIRTY = false;
508
}
508
}
509
 
509
 
510
void sportwatcherWidget::btGlasMinusSlot()
510
void sportwatcherWidget::btGlasMinusSlot()
511
{
511
{
512
bool sh = stateHand;
512
	bool sh = stateHand;
513
 
513
 
514
	stateHand = false;
514
	stateHand = false;
515
	DIRTY = true;
515
	DIRTY = true;
516
	showTrack(zfactor - 1000);
516
	showTrack(zfactor - 1000);
517
	DIRTY = false;
517
	DIRTY = false;
518
	stateHand = sh;
518
	stateHand = sh;
519
}
519
}
520
 
520
 
521
void sportwatcherWidget::btGlasPlusSlot()
521
void sportwatcherWidget::btGlasPlusSlot()
522
{
522
{
523
bool sh = stateHand;
523
	bool sh = stateHand;
524
 
524
 
525
	stateHand = false;
525
	stateHand = false;
526
	DIRTY = true;
526
	DIRTY = true;
527
	showTrack(zfactor + 1000);
527
	showTrack(zfactor + 1000);
528
	DIRTY = false;
528
	DIRTY = false;
529
	stateHand = sh;
529
	stateHand = sh;
530
}
530
}
531
 
531
 
532
void sportwatcherWidget::btHandSlot()
532
void sportwatcherWidget::btHandSlot()
533
{
533
{
534
QCursor cs;
534
	QCursor cs;
535
 
535
 
536
	if (stateGlas)
536
	if(stateGlas)
537
	{
537
	{
538
	   stateGlas = false;
538
		stateGlas = false;
539
	   ui_sportwatcherWidgetBase.btGlas->toggle();
539
		ui_sportwatcherWidgetBase.btGlas->toggle();
540
	}
540
	}
541
	
541
 
542
	stateHand = (stateHand) ? false : true;
542
	stateHand = (stateHand) ? false : true;
543
 
543
 
544
	if (stateHand)
544
	if(stateHand)
545
	   cs.setShape(Qt::PointingHandCursor);
545
		cs.setShape(Qt::PointingHandCursor);
546
	else
546
	else
547
	   cs.setShape(Qt::ArrowCursor);
547
		cs.setShape(Qt::ArrowCursor);
548
 
548
 
549
	ui_sportwatcherWidgetBase.imgMap->setCursor(cs);
549
	ui_sportwatcherWidgetBase.imgMap->setCursor(cs);
550
}
550
}
551
 
551
 
552
void sportwatcherWidget::btGlasSlot()
552
void sportwatcherWidget::btGlasSlot()
553
{
553
{
554
QCursor cs;
554
	QCursor cs;
555
 
555
 
556
	if (stateHand)
556
	if(stateHand)
557
	{
557
	{
558
	   stateHand = false;
558
		stateHand = false;
559
	   ui_sportwatcherWidgetBase.btHand->toggle();
559
		ui_sportwatcherWidgetBase.btHand->toggle();
560
	}
560
	}
561
 
561
 
562
	stateGlas = (stateGlas) ? false : true;
562
	stateGlas = (stateGlas) ? false : true;
563
 
563
 
564
	if (stateGlas)
564
	if(stateGlas)
565
	   cs.setShape(Qt::ForbiddenCursor);
565
		cs.setShape(Qt::ForbiddenCursor);
566
	else
566
	else
567
	   cs.setShape(Qt::ArrowCursor);
567
		cs.setShape(Qt::ArrowCursor);
568
 
568
 
569
	ui_sportwatcherWidgetBase.imgMap->setCursor(cs);
569
	ui_sportwatcherWidgetBase.imgMap->setCursor(cs);
570
}
570
}
571
 
571
 
572
void sportwatcherWidget::btFlagSlot()
572
void sportwatcherWidget::btFlagSlot()
573
{
573
{
574
}
574
}
575
 
575
 
576
void sportwatcherWidget::liLapsSlot(Q3ListViewItem *item)
576
void sportwatcherWidget::liLapsSlot(Q3ListViewItem *item)
577
{
577
{
578
QString sl;
578
	QString sl;
579
int l;
579
	int l;
580
int idx;
580
	int idx;
581
RUN_NODE *rn;
581
	RUN_NODE *rn;
582
LAP *lap;
582
	LAP *lap;
583
 
583
 
584
	if (!item)
584
	if(!item)
585
	   return;
585
		return;
586
 
586
 
587
	DIRTY = true;
587
	DIRTY = true;
588
	sl = item->text(0).mid(4, 3);
588
	sl = item->text(0).mid(4, 3);
589
	l = sl.toInt();
589
	l = sl.toInt();
590
 
590
 
591
	if (l <= 0)
591
	if(l <= 0)
592
	{
592
	{
593
	   // Show the whole map and track
593
		// Show the whole map and track
594
	   showTrack(zfactor, mapPan, 0);
594
		showTrack(zfactor, mapPan, 0);
595
	   // Don't mark any lap. Just display normal.
595
		// Don't mark any lap. Just display normal.
596
	   showCurves(0);
596
		showCurves(0);
597
	   return;
597
		return;
598
	}
598
	}
599
 
599
 
600
	rn = ds.getRunNode();
600
	rn = ds.getRunNode();
601
	idx = rn->run->first_lap_index;
601
	idx = rn->run->first_lap_index;
602
	lap = ds.getLap(idx + l - 1);
602
	lap = ds.getLap(idx + l - 1);
Line 607... Line 607...
607
	DIRTY = false;
607
	DIRTY = false;
608
}
608
}
609
 
609
 
610
void sportwatcherWidget::liActivitiesSlot(QTreeWidgetItem *item, int)
610
void sportwatcherWidget::liActivitiesSlot(QTreeWidgetItem *item, int)
611
{
611
{
612
	if (!item)
612
	if(!item)
613
	   return;
613
		return;
614
 
614
 
615
	spw.destroy();
615
	spw.destroy();
616
 
616
 
617
	if (spw.setFileName(item->data(0, Qt::UserRole).toString().toAscii().constData()) == -1)
617
	if(spw.setFileName(item->data(0, Qt::UserRole).toString().toAscii().constData()) == -1)
618
	   return;
618
		return;
619
 
619
 
620
	if (gmn)
620
	if(gmn)
621
	   garmin_free_data (gmn);
621
		garmin_free_data(gmn);
622
 
622
 
623
	gmn = spw.readFile();
623
	gmn = spw.readFile();
624
	zfactor = 0;
624
	zfactor = 0;
625
 
625
 
626
	// Make sure, the currently not visible tabs will be redrawn as soon
626
	// Make sure, the currently not visible tabs will be redrawn as soon
627
	// as they are visible.
627
	// as they are visible.
628
	switch (curTab)
628
	switch(curTab)
629
	{
629
	{
630
	   case 0: tabDirt1 = tabDirt2 = tabDirt3 = true; break;
630
		case 0: tabDirt1 = tabDirt2 = tabDirt3 = true; break;
631
	   case 1: tabDirt0 = tabDirt2 = tabDirt3 = true; break;
631
		case 1: tabDirt0 = tabDirt2 = tabDirt3 = true; break;
632
	   case 2: tabDirt0 = tabDirt1 = tabDirt3 = true; break;
632
		case 2: tabDirt0 = tabDirt1 = tabDirt3 = true; break;
633
	   case 3: tabDirt0 = tabDirt1 = tabDirt2 = true; break;
633
		case 3: tabDirt0 = tabDirt1 = tabDirt2 = true; break;
634
	}
634
	}
635
 
635
 
636
	// Display the just loaded sport session
636
	// Display the just loaded sport session
637
	DIRTY = true;
637
	DIRTY = true;
638
	showLaps();
638
	showLaps();
639
	showTrack();
639
	showTrack();
640
	showCurves();
640
	showCurves();
641
 
641
 
642
	if (curTab == 2)
642
	if(curTab == 2)
643
	{
643
	{
644
	   showThreeCurve();
644
		showThreeCurve();
645
	   tabDirt2 = false;
645
		tabDirt2 = false;
646
	}
646
	}
647
 
647
 
648
	DIRTY = false;
648
	DIRTY = false;
649
}
649
}
650
 
650
 
Line 658... Line 658...
658
 * to draw the heart rate, elevation and speed. Only the laps are drawn
658
 * to draw the heart rate, elevation and speed. Only the laps are drawn
659
 * directly in this function.
659
 * directly in this function.
660
 */
660
 */
661
void sportwatcherWidget::filePrint()
661
void sportwatcherWidget::filePrint()
662
{
662
{
663
QPrinter printer(QPrinter::HighResolution);
663
	QPrinter printer(QPrinter::HighResolution);
664
QDateTime dt;
664
	QDateTime dt;
665
QTime t, st;
665
	QTime t, st;
666
QDateTime *qt;
666
	QDateTime *qt;
667
QRectF rect;
667
	QRectF rect;
668
QString qs_name, qs_distance, qs_etime, qs_avgpace, qs_avgspeed, qs_maxspeed;
668
	QString qs_name, qs_distance, qs_etime, qs_avgpace, qs_avgspeed, qs_maxspeed;
669
QString qs_calories, qs_avghr, qs_maxhr, qs_avgcadence, qs_ascent, qs_descent;
669
	QString qs_calories, qs_avghr, qs_maxhr, qs_avgcadence, qs_ascent, qs_descent;
670
QString qs_totdist, hv0;
670
	QString qs_totdist, hv0;
671
LAP *lap;
671
	LAP *lap;
672
POINT *point;
672
	POINT *point;
673
RUN_NODE *rakt, *rn;
673
	RUN_NODE *rakt, *rn;
674
int laps, i, anz, cad, page, firstPage, lastPage;
674
	int laps, i, anz, cad, page, firstPage, lastPage;
675
qreal extMil[4];
675
	qreal extMil[4];
676
double sum_asc, sum_dsc, old_asc, old_dsc;
676
	double sum_dsc, old_asc, old_dsc;
677
double totdist, lineH, aktLine;
677
	double totdist, lineH, aktLine;
678
bool printed = false;
678
	bool printed = false;
679
 
679
 
680
	if (!gmn)
680
	if(!gmn)
681
	{
681
	{
682
	   KMessageBox::error(this, i18n("You must select an activity first!"));
682
		KMessageBox::error(this, i18n("You must select an activity first!"));
683
	   return;
683
		return;
684
	}
684
	}
685
 
685
 
686
	printer.setCreator(QString("SportWatcher"));
686
	printer.setCreator(QString("SportWatcher"));
687
	printer.setDocName(QString("SportWatcher_%1").arg(QString(VERSION)));
687
	printer.setDocName(QString("SportWatcher_%1").arg(QString(VERSION)));
688
	QPrintDialog printDialog(&printer, this);
688
	QPrintDialog printDialog(&printer, this);
689
 
689
 
690
	if (!printDialog.exec() == QDialog::Accepted)
690
	if(!printDialog.exec() == QDialog::Accepted)
691
	   return;
691
		return;
692
 
692
 
693
	if (!(rn = ds.getRunNode()))
693
	if(!(rn = ds.getRunNode()))
694
	   return;
694
		return;
695
 
695
 
696
	// We dont care about page margins of a printer. Instead we assume
696
	// We dont care about page margins of a printer. Instead we assume
697
	// a frame from about 20mm arround the page. European paper size is
697
	// a frame from about 20mm arround the page. European paper size is
698
	// A4 (210x297mm) and the output is optimized for this.
698
	// A4 (210x297mm) and the output is optimized for this.
699
	totdist = 0;
699
	totdist = 0;
Line 704... Line 704...
704
	lineH = 4.5;	// The height of a line with 10pt letters
704
	lineH = 4.5;	// The height of a line with 10pt letters
705
	page = 1;	// The page number
705
	page = 1;	// The page number
706
	firstPage = printer.fromPage();
706
	firstPage = printer.fromPage();
707
	lastPage = printer.toPage();
707
	lastPage = printer.toPage();
708
 
708
 
709
	if (!printArea.begin(&printer))
709
	if(!printArea.begin(&printer))
710
	{
710
	{
711
	   KMessageBox::error(this, i18n("Error initializing printer! Printing is currently not available!"));
711
		KMessageBox::error(this, i18n("Error initializing printer! Printing is currently not available!"));
712
	   return;
712
		return;
713
	}
713
	}
714
 
714
 
715
	ActivePrint = true;
715
	ActivePrint = true;
716
	rakt = rn;
716
	rakt = rn;
717
	QApplication::setOverrideCursor (QCursor(Qt::WaitCursor));
717
	QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
718
 
718
 
719
	while (rakt)
719
	while(rakt)
720
	{
720
	{
721
	   // Check for a supported run type
721
		// Check for a supported run type
722
	   if (rakt->run->type == data_D1000 || rakt->run->type == data_D1009 ||
722
		if(rakt->run->type == data_D1000 || rakt->run->type == data_D1009 ||
723
	   	rakt->run->type == data_D1010)
723
		                  rakt->run->type == data_D1010)
724
	   {
724
		{
725
	   int ahr;
725
			int ahr;
726
	   double distance, speed, mspeed;
726
			double distance, speed, mspeed;
727
	   QDate dat;
727
			QDate dat;
728
 
728
 
729
	      printArea.setFont(QFont(QString("Helvetica"), 12, QFont::Bold, false));
729
			printArea.setFont(QFont(QString("Helvetica"), 12, QFont::Bold, false));
730
	      rect.setCoords(milToPixel(extMil[0], printer),
730
			rect.setCoords(milToPixel(extMil[0], printer),
731
			milToPixel(extMil[1], printer, true),
731
			               milToPixel(extMil[1], printer, true),
732
			milToPixel(extMil[0]+170, printer),
732
			               milToPixel(extMil[0] + 170, printer),
733
			milToPixel(extMil[1] + 7.0, printer, true));
733
			               milToPixel(extMil[1] + 7.0, printer, true));
734
	      printArea.setPen(QPen(QBrush(QColor("black")), (qreal)milToPixel(0.5, printer, false)));
734
			printArea.setPen(QPen(QBrush(QColor("black")), (qreal)milToPixel(0.5, printer, false)));
735
 
735
 
736
	      if ((lastPage > 0 && page >= firstPage && page <= lastPage) ||
736
			if((lastPage > 0 && page >= firstPage && page <= lastPage) ||
737
		  (lastPage == 0 && firstPage == 0))
737
			                  (lastPage == 0 && firstPage == 0))
738
	      {
738
			{
739
		 printArea.drawRect(rect);
739
				printArea.drawRect(rect);
740
		 printed = true;
740
				printed = true;
741
	      }
741
			}
742
 
742
 
743
	      if (!(lap = ds.getLap(rakt->run->first_lap_index)))
743
			if(!(lap = ds.getLap(rakt->run->first_lap_index)))
744
	      {
744
			{
745
		 ActivePrint = false;
745
				ActivePrint = false;
746
		 QApplication::restoreOverrideCursor();
746
				QApplication::restoreOverrideCursor();
747
		 return;
747
				return;
748
	      }
748
			}
749
 
749
 
750
	      if (strlen (rn->run->workout.name) > 1 && strlen (rn->run->workout.name) < 16 && isalpha (rn->run->workout.name[0]))
750
			if(strlen(rn->run->workout.name) > 1 && strlen(rn->run->workout.name) < 16 && isalpha(rn->run->workout.name[0]))
751
		 hv0 = QString(rakt->run->workout.name);
751
				hv0 = QString(rakt->run->workout.name);
752
	      else
752
			else
753
	      {
753
			{
754
		 qt = garmin_dtime(lap->start_time);
754
				qt = garmin_dtime(lap->start_time);
755
		 hv0 = kl->formatDate(qt->date(), KLocale::ShortDate) + " ";
755
				hv0 = kl->formatDate(qt->date(), KLocale::ShortDate) + " ";
756
		 hv0.append(qt->toString("hh:mm:ss"));
756
				hv0.append(qt->toString("hh:mm:ss"));
757
		 delete qt;
757
				delete qt;
758
	      }
758
			}
759
 
759
 
760
	      // Set the name depending on the sport type
760
			// Set the name depending on the sport type
761
	      // This is used on the tab "Summary"
761
			// This is used on the tab "Summary"
762
	      switch (rakt->run->sport_type)
762
			switch(rakt->run->sport_type)
763
	      {
763
			{
764
		 case D1000_running: qs_name = i18n("Running: "); break;
764
				case D1000_running: qs_name = i18n("Running: "); break;
765
		 case D1000_biking:  qs_name = i18n("Biking: "); break;
765
				case D1000_biking:  qs_name = i18n("Biking: "); break;
766
		 case D1000_other:   qs_name = i18n("Other: "); break;
766
				case D1000_other:   qs_name = i18n("Other: "); break;
767
		 default:
767
				default:
768
		    qs_name = i18n("Unknown: ");
768
					qs_name = i18n("Unknown: ");
769
	      }
769
			}
770
 
770
 
771
	      // Print the headline inside the frame
771
			// Print the headline inside the frame
772
	      if ((lastPage > 0 && page >= firstPage && page <= lastPage) ||
772
			if((lastPage > 0 && page >= firstPage && page <= lastPage) ||
773
		  (lastPage == 0 && firstPage == 0))
773
			                  (lastPage == 0 && firstPage == 0))
774
	      {
774
			{
775
		 printArea.drawText(rect, Qt::AlignHCenter, QString("%1%2").arg(qs_name).arg(hv0));
775
				printArea.drawText(rect, Qt::AlignHCenter, QString("%1%2").arg(qs_name).arg(hv0));
776
		 // Print the headline of the table
776
				// Print the headline of the table
777
		 printArea.setFont(QFont(QString("Helvetica"), 10, QFont::Bold, false));
777
				printArea.setFont(QFont(QString("Helvetica"), 10, QFont::Bold, false));
778
		 rect.setCoords(milToPixel(extMil[0], printer), milToPixel(extMil[1]+10, printer, true), milToPixel(extMil[0]+35, printer), milToPixel(extMil[0]+10+lineH, printer, true));
778
				rect.setCoords(milToPixel(extMil[0], printer), milToPixel(extMil[1] + 10, printer, true), milToPixel(extMil[0] + 35, printer), milToPixel(extMil[0] + 10 + lineH, printer, true));
779
		 printArea.drawText(rect, Qt::AlignHCenter, i18n("Lap"));
779
				printArea.drawText(rect, Qt::AlignHCenter, i18n("Lap"));
780
		 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));
780
				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));
781
		 printArea.drawText(rect, Qt::AlignHCenter, i18n("Distance"));
781
				printArea.drawText(rect, Qt::AlignHCenter, i18n("Distance"));
782
		 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));
782
				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));
783
		 printArea.drawText(rect, Qt::AlignHCenter, i18n("Time"));
783
				printArea.drawText(rect, Qt::AlignHCenter, i18n("Time"));
784
		 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));
784
				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));
785
		 printArea.drawText(rect, Qt::AlignHCenter, i18n("Speed"));
785
				printArea.drawText(rect, Qt::AlignHCenter, i18n("Speed"));
786
		 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));
786
				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));
787
		 printArea.drawText(rect, Qt::AlignHCenter, i18n("Heart rate"));
787
				printArea.drawText(rect, Qt::AlignHCenter, i18n("Heart rate"));
788
		 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));
788
				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));
789
		 printArea.drawText(rect, Qt::AlignHCenter, i18n("Cadence"));
789
				printArea.drawText(rect, Qt::AlignHCenter, i18n("Cadence"));
790
		 aktLine = extMil[1] + 10.0 + lineH;
790
				aktLine = extMil[1] + 10.0 + lineH;
791
		 printArea.drawLine(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 170, printer), milToPixel(aktLine, printer, true));
791
				printArea.drawLine(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 170, printer), milToPixel(aktLine, printer, true));
792
		 aktLine += 1.0;
792
				aktLine += 1.0;
793
		 printed = true;
793
				printed = true;
794
	      }
794
			}
795
	      else
795
			else
796
	      {
796
			{
797
		 aktLine = extMil[1] + 10.0 + lineH;
797
				aktLine = extMil[1] + 10.0 + lineH;
798
		 aktLine += 1.0;
798
				aktLine += 1.0;
799
	      }
799
			}
800
 
800
 
801
	      // Prepare to print the first line
801
			// Prepare to print the first line
802
	      qt = garmin_dtime (lap->start_time);
802
			qt = garmin_dtime(lap->start_time);
803
	      StartTime = *qt;
803
			StartTime = *qt;
804
	      st = qt->time();
804
			st = qt->time();
805
	      dat = qt->date();
805
			dat = qt->date();
806
	      delete qt;
806
			delete qt;
807
	      qt = 0;
807
			qt = 0;
808
	      // Find the last track
808
 
809
	      if (!(point = ds.getLastPoint()))
809
			// Find the last track
810
	      {
810
			if(!(point = ds.getLastPoint()))
811
		 QApplication::restoreOverrideCursor();
811
			{
812
		 KMessageBox::error(this, i18n("Error getting the last messure point!"));
812
				QApplication::restoreOverrideCursor();
813
		 ActivePrint = false;
813
				KMessageBox::error(this, i18n("Error getting the last messure point!"));
814
		 return;
814
				ActivePrint = false;
815
	      }
815
				return;
816
 
816
			}
817
	      qt = garmin_dtime(point->time);
817
 
818
	      t = qt->time();
818
			qt = garmin_dtime(point->time);
819
	      t.setHMS(0, 0, 0);
819
			t = qt->time();
820
	      t = t.addSecs(ds.getTotalTime());
820
			t.setHMS(0, 0, 0);
821
	      qt->setDate(dat);
821
			t = t.addSecs(ds.getTotalTime());
822
	      qt->setTime(t);
822
			qt->setDate(dat);
823
	      qs_name = kl->formatDate(dat, KLocale::ShortDate);
823
			qt->setTime(t);
824
	      qs_name.append(" ");
824
			qs_name = kl->formatDate(dat, KLocale::ShortDate);
825
	      qs_name.append(kl->formatTime(st, true));
825
			qs_name.append(" ");
826
	      max_time = ds.getTotalTime();
826
			qs_name.append(kl->formatTime(st, true));
827
	      qs_etime = QString(qt->toString("hh:mm:ss.zzz"));
827
			max_time = ds.getTotalTime();
828
 
828
			qs_etime = QString(qt->toString("hh:mm:ss.zzz"));
829
	      distance = 0.0;
829
 
830
	      mspeed = 0;
830
			distance = 0.0;
831
	      ahr = 0;
831
			mspeed = 0;
832
	      anz = 0;
832
			ahr = 0;
833
	      cad = 0;
833
			anz = 0;
834
	      sum_asc = sum_dsc = old_asc = old_dsc = 0;
834
			cad = 0;
835
 
835
			sum_dsc = old_asc = old_dsc = 0;
836
	      // Find out the total distance, calories, maximum speed,
836
 
837
	      // maximum heart rate and the average heart rate. Get this
837
			// Find out the total distance, calories, maximum speed,
838
	      // values from the lap summary the watch made.
838
			// maximum heart rate and the average heart rate. Get this
839
	      for (i = rakt->run->first_lap_index; (unsigned int)i <= rakt->run->last_lap_index; i++)
839
			// values from the lap summary the watch made.
840
	      {
840
			for(i = rakt->run->first_lap_index; (unsigned int)i <= rakt->run->last_lap_index; i++)
841
		 if ((lap = ds.getLap(i)) == NULL)
841
			{
842
		    continue;
842
				if((lap = ds.getLap(i)) == NULL)
843
 
843
					continue;
844
		 distance += lap->total_distance;
844
 
845
 
845
				distance += lap->total_distance;
846
		 if (lap->avg_cadence != 0xff)
846
 
847
		    cad += lap->avg_cadence;
847
				if(lap->avg_cadence != 0xff)
848
 
848
					cad += lap->avg_cadence;
849
		 ahr += lap->avg_heart_rate;
849
 
850
		 anz++;
850
				ahr += lap->avg_heart_rate;
851
 
851
				anz++;
852
		 if (lap->max_speed > mspeed)
852
 
853
		    mspeed = lap->max_speed;
853
				if(lap->max_speed > mspeed)
854
	      }
854
					mspeed = lap->max_speed;
855
 
855
			}
856
	      total_distance = distance = ds.getTotalDistance();
856
 
857
 
857
			total_distance = distance = ds.getTotalDistance();
858
	      if (Units == 1)		// Statute?
858
 
859
		 qs_distance.sprintf("%.2f ft", distance / 0.304);
859
			if(Units == 1)		// Statute?
860
	      else
860
				qs_distance.sprintf("%.2f ft", distance / 0.304);
861
	         qs_distance.sprintf("%.2f m", distance);
861
			else
862
 
862
				qs_distance.sprintf("%.2f m", distance);
863
	      if (distance > 0)
863
 
864
	      {
864
			if(distance > 0)
865
		 QTime tt = qt->time();
865
			{
866
		 long secs = (double)(tt.hour() * 3600 + tt.minute() * 60 + tt.second()) / 100.0;
866
				QTime tt = qt->time();
867
 
867
				long secs = (double)(tt.hour() * 3600 + tt.minute() * 60 + tt.second()) / 100.0;
868
		 if (Units == 0)
868
 
869
		    secs = secs * (1000.0 / distance * 100.0);
869
				if(Units == 0)
870
		 else
870
					secs = secs * (1000.0 / distance * 100.0);
871
		    secs = secs * (1609.344 / distance * 100.0);
871
				else
872
 
872
					secs = secs * (1609.344 / distance * 100.0);
873
		 int h = secs / 3600;
873
 
874
		 int m = (secs - (h * 3600)) / 60;
874
				int h = secs / 3600;
875
		 int s = secs - ((h * 3600) + (m * 60));
875
				int m = (secs - (h * 3600)) / 60;
876
		 t = QTime(h, m, s, 0);
876
				int s = secs - ((h * 3600) + (m * 60));
877
		 qs_avgpace = QString("  ") + kl->formatTime(t, true);
877
				t = QTime(h, m, s, 0);
878
 
878
				qs_avgpace = QString("  ") + kl->formatTime(t, true);
879
		 if (Units == 0)
879
 
880
		    qs_avgpace.append(QString(" /km"));
880
				if(Units == 0)
881
		 else
881
					qs_avgpace.append(QString(" /km"));
882
		    qs_avgpace.append(QString(" /mi"));
882
				else
883
	      }
883
					qs_avgpace.append(QString(" /mi"));
884
 
884
			}
885
	      if (Units == 1)		// Statute?
885
 
886
		 speed = distance / ds.getTotalTime() * 3.6 / 1.609344;
886
			if(Units == 1)		// Statute?
887
	      else
887
				speed = distance / ds.getTotalTime() * 3.6 / 1.609344;
888
		 speed = distance / ds.getTotalTime() * 3.6;
888
			else
889
 
889
				speed = distance / ds.getTotalTime() * 3.6;
890
	      qs_avgspeed.sprintf("%.2f %s", speed, (Units == 1) ? "mph" : "km/h");
890
 
891
	      qs_maxspeed.sprintf("%.2f %s", (Units == 1) ? mspeed * 3.6 / 1.609344 : mspeed * 3.6, (Units == 1) ? "mph" : "km/h");
891
			qs_avgspeed.sprintf("%.2f %s", speed, (Units == 1) ? "mph" : "km/h");
892
	      qs_avghr.sprintf("%d bpm", ahr / anz);
892
			qs_maxspeed.sprintf("%.2f %s", (Units == 1) ? mspeed * 3.6 / 1.609344 : mspeed * 3.6, (Units == 1) ? "mph" : "km/h");
893
 
893
			qs_avghr.sprintf("%d bpm", ahr / anz);
894
	      if (cad > 0)
894
 
895
		 qs_avgcadence.sprintf("%d", cad / anz);
895
			if(cad > 0)
896
 
896
				qs_avgcadence.sprintf("%d", cad / anz);
897
	      // Print out the summary line and draw twi thin lines underneath
897
 
898
	      if ((lastPage > 0 && page >= firstPage && page <= lastPage) ||
898
			// Print out the summary line and draw twi thin lines underneath
899
		  (lastPage == 0 && firstPage == 0))
899
			if((lastPage > 0 && page >= firstPage && page <= lastPage) ||
900
	      {
900
			                  (lastPage == 0 && firstPage == 0))
901
		 printArea.setFont(QFont(QString("Helvetica"), 10, QFont::Normal, false));
901
			{
902
		 rect.setCoords(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+35, printer), milToPixel(aktLine+lineH, printer, true));
902
				printArea.setFont(QFont(QString("Helvetica"), 10, QFont::Normal, false));
903
		 printArea.drawText(rect, Qt::AlignLeft, qs_name);
903
				rect.setCoords(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 35, printer), milToPixel(aktLine + lineH, printer, true));
904
		 rect.setCoords(milToPixel(extMil[0]+35, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+60, printer), milToPixel(aktLine+lineH, printer, true));
904
				printArea.drawText(rect, Qt::AlignLeft, qs_name);
905
		 printArea.drawText(rect, Qt::AlignRight, kl->formatNumber(qs_distance, false));
905
				rect.setCoords(milToPixel(extMil[0] + 35, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 60, printer), milToPixel(aktLine + lineH, printer, true));
906
		 rect.setCoords(milToPixel(extMil[0]+60, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+85, printer), milToPixel(aktLine+lineH, printer, true));
906
				printArea.drawText(rect, Qt::AlignRight, kl->formatNumber(qs_distance, false));
907
		 printArea.drawText(rect, Qt::AlignRight, qs_etime);
907
				rect.setCoords(milToPixel(extMil[0] + 60, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 85, printer), milToPixel(aktLine + lineH, printer, true));
908
		 rect.setCoords(milToPixel(extMil[0]+85, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+122, printer), milToPixel(aktLine+lineH, printer, true));
908
				printArea.drawText(rect, Qt::AlignRight, qs_etime);
909
		 printArea.drawText(rect, Qt::AlignRight, kl->formatNumber(qs_avgspeed, false));
909
				rect.setCoords(milToPixel(extMil[0] + 85, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 122, printer), milToPixel(aktLine + lineH, printer, true));
910
		 rect.setCoords(milToPixel(extMil[0]+122, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+147, printer), milToPixel(aktLine+lineH, printer, true));
910
				printArea.drawText(rect, Qt::AlignRight, kl->formatNumber(qs_avgspeed, false));
911
		 printArea.drawText(rect, Qt::AlignRight, qs_avghr);
911
				rect.setCoords(milToPixel(extMil[0] + 122, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 147, printer), milToPixel(aktLine + lineH, printer, true));
912
		 rect.setCoords(milToPixel(extMil[0]+147, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+170, printer), milToPixel(aktLine+lineH, printer, true));
912
				printArea.drawText(rect, Qt::AlignRight, qs_avghr);
913
		 printArea.drawText(rect, Qt::AlignRight, qs_avgcadence);
913
				rect.setCoords(milToPixel(extMil[0] + 147, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 170, printer), milToPixel(aktLine + lineH, printer, true));
914
		 aktLine += (lineH + (lineH / 3.0));
914
				printArea.drawText(rect, Qt::AlignRight, qs_avgcadence);
915
		 printArea.setPen(QPen(QBrush(QColor("black")), milToPixel(0.1, printer, false)));
915
				aktLine += (lineH + (lineH / 3.0));
916
		 printArea.drawLine(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 170, printer), milToPixel(aktLine, printer, true));
916
				printArea.setPen(QPen(QBrush(QColor("black")), milToPixel(0.1, printer, false)));
917
		 printArea.drawLine(milToPixel(extMil[0], printer), milToPixel(aktLine+0.5, printer, true), milToPixel(extMil[0] + 170, printer), milToPixel(aktLine+0.5, printer, true));
917
				printArea.drawLine(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 170, printer), milToPixel(aktLine, printer, true));
918
		 aktLine += (lineH / 3.0);
918
				printArea.drawLine(milToPixel(extMil[0], printer), milToPixel(aktLine + 0.5, printer, true), milToPixel(extMil[0] + 170, printer), milToPixel(aktLine + 0.5, printer, true));
919
		 printed = true;
919
				aktLine += (lineH / 3.0);
920
	      }
920
				printed = true;
921
	      else
921
			}
922
	      {
922
			else
923
		 aktLine += (lineH + (lineH / 3.0));
923
			{
924
		 aktLine += (lineH / 3.0);
924
				aktLine += (lineH + (lineH / 3.0));
925
	      }
925
				aktLine += (lineH / 3.0);
926
 
926
			}
927
	      delete qt;
927
 
928
	      /* Get the laps. */
928
			delete qt;
929
	      laps = 1;
929
			/* Get the laps. */
930
 
930
			laps = 1;
931
	      for (i = rakt->run->first_lap_index; (unsigned int)i <= rakt->run->last_lap_index; i++)
931
 
932
	      {
932
			for(i = rakt->run->first_lap_index; (unsigned int)i <= rakt->run->last_lap_index; i++)
933
		 double spd;
933
			{
934
		 char *un;
934
				double spd;
935
 
935
				char *un;
936
		 if ((lap = ds.getLap(i)) == NULL)
936
 
937
		    continue;
937
				if((lap = ds.getLap(i)) == NULL)
938
 
938
					continue;
939
		 qt = garmin_dtime (lap->start_time);
939
 
940
		 qs_name.sprintf("Lap %03d - ", laps);
940
				qt = garmin_dtime(lap->start_time);
941
		 qs_name.append(kl->formatTime(qt->time(), true));
941
				qs_name.sprintf("Lap %03d - ", laps);
942
		 qs_distance.sprintf("%.2f %s", (Units == 1) ? lap->total_distance / 0.304 : lap->total_distance, (Units == 1) ? "ft" : "m");
942
				qs_name.append(kl->formatTime(qt->time(), true));
943
		 totdist += (Units == 1) ? lap->total_distance / 0.304 : lap->total_distance;
943
				qs_distance.sprintf("%.2f %s", (Units == 1) ? lap->total_distance / 0.304 : lap->total_distance, (Units == 1) ? "ft" : "m");
944
		 qs_totdist.sprintf("%2.f %s", totdist, (Units == 1) ? "ft" : "m");
944
				totdist += (Units == 1) ? lap->total_distance / 0.304 : lap->total_distance;
945
		 t = QTime(0, 0, 0, 0);
945
				qs_totdist.sprintf("%2.f %s", totdist, (Units == 1) ? "ft" : "m");
946
		 t = t.addMSecs(lap->total_time * 10);
946
				t = QTime(0, 0, 0, 0);
947
		 qs_etime = t.toString("hh:mm:ss.zzz");
947
				t = t.addMSecs(lap->total_time * 10);
948
		 spd = lap->total_distance / (lap->total_time / 100.0);
948
				qs_etime = t.toString("hh:mm:ss.zzz");
949
		 delete qt;
949
				spd = lap->total_distance / (lap->total_time / 100.0);
950
		 qt = 0;
950
				delete qt;
951
 
951
				qt = 0;
952
		 if (Units == 0)
952
 
953
		 {
953
				if(Units == 0)
954
		    un = (char *)"km/h";
954
				{
955
		    spd *= 3.6;
955
					un = (char *)"km/h";
956
		 }
956
					spd *= 3.6;
957
		 else
957
				}
958
		 {
958
				else
959
		    spd *= 3.6 / 1.609344;
959
				{
960
		    un = (char *)"mph";
960
					spd *= 3.6 / 1.609344;
961
		 }
961
					un = (char *)"mph";
962
 
962
				}
963
		 qs_avgspeed.sprintf("%.2f %s", spd, un);
963
 
964
 
964
				qs_avgspeed.sprintf("%.2f %s", spd, un);
965
		 if (lap->total_distance > 0 && lap->total_time != 0)
965
 
966
		 {
966
				if(lap->total_distance > 0 && lap->total_time != 0)
967
		    double fact;
967
				{
968
 
968
					double fact;
969
		    if (Units == 0)
969
 
970
		       fact = 1000.0;		// 1 km
970
					if(Units == 0)
971
		    else
971
						fact = 1000.0;		// 1 km
972
		       fact = 1609.344;		// 1 mile in meters
972
					else
973
 
973
						fact = 1609.344;		// 1 mile in meters
974
		    long secs = (double)lap->total_time / 10000.0 * (fact / lap->total_distance * 100.0);
974
 
975
		    int h = secs / 3600;
975
					long secs = (double)lap->total_time / 10000.0 * (fact / lap->total_distance * 100.0);
976
		    int m = (secs - (h * 3600)) / 60;
976
					int h = secs / 3600;
977
		    int s = secs - ((h * 3600) + (m * 60));
977
					int m = (secs - (h * 3600)) / 60;
978
		    t = QTime(h, m, s, 0);
978
					int s = secs - ((h * 3600) + (m * 60));
979
		    qs_avgpace = kl->formatTime(t, true);
979
					t = QTime(h, m, s, 0);
980
 
980
					qs_avgpace = kl->formatTime(t, true);
981
		    if (Units == 0)
981
 
982
		       qs_avgpace.append(QString(" /km"));
982
					if(Units == 0)
983
		    else
983
						qs_avgpace.append(QString(" /km"));
984
		       qs_avgpace.append(QString(" /mi"));
984
					else
985
		 }
985
						qs_avgpace.append(QString(" /mi"));
986
 
986
				}
987
		 qs_avghr.sprintf("%d bpm", lap->avg_heart_rate);
987
 
988
 
988
				qs_avghr.sprintf("%d bpm", lap->avg_heart_rate);
989
		 if (lap->avg_cadence != 0xff)
989
 
990
		    qs_avgcadence.sprintf("%d", lap->avg_cadence);
990
				if(lap->avg_cadence != 0xff)
991
		 // Draw a new detail line
991
					qs_avgcadence.sprintf("%d", lap->avg_cadence);
992
		 if ((lastPage > 0 && page >= firstPage && page <= lastPage) ||
992
 
993
		     (lastPage == 0 && firstPage == 0))
993
				// Draw a new detail line
994
		 {
994
				if((lastPage > 0 && page >= firstPage && page <= lastPage) ||
995
		    rect.setCoords(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+35, printer), milToPixel(aktLine+lineH, printer, true));
995
				                  (lastPage == 0 && firstPage == 0))
996
		    printArea.drawText(rect, Qt::AlignLeft, qs_name);
996
				{
997
		    rect.setCoords(milToPixel(extMil[0]+35, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+60, printer), milToPixel(aktLine+lineH, printer, true));
997
					rect.setCoords(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 35, printer), milToPixel(aktLine + lineH, printer, true));
998
		    printArea.drawText(rect, Qt::AlignRight, kl->formatNumber(qs_distance, false));
998
					printArea.drawText(rect, Qt::AlignLeft, qs_name);
999
		    rect.setCoords(milToPixel(extMil[0]+60, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+85, printer), milToPixel(aktLine+lineH, printer, true));
999
					rect.setCoords(milToPixel(extMil[0] + 35, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 60, printer), milToPixel(aktLine + lineH, printer, true));
1000
		    printArea.drawText(rect, Qt::AlignRight, qs_etime);
1000
					printArea.drawText(rect, Qt::AlignRight, kl->formatNumber(qs_distance, false));
1001
		    rect.setCoords(milToPixel(extMil[0]+85, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+122, printer), milToPixel(aktLine+lineH, printer, true));
1001
					rect.setCoords(milToPixel(extMil[0] + 60, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 85, printer), milToPixel(aktLine + lineH, printer, true));
1002
		    printArea.drawText(rect, Qt::AlignRight, kl->formatNumber(qs_avgspeed, false));
1002
					printArea.drawText(rect, Qt::AlignRight, qs_etime);
1003
		    rect.setCoords(milToPixel(extMil[0]+122, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+147, printer), milToPixel(aktLine+lineH, printer, true));
1003
					rect.setCoords(milToPixel(extMil[0] + 85, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 122, printer), milToPixel(aktLine + lineH, printer, true));
1004
		    printArea.drawText(rect, Qt::AlignRight, qs_avghr);
1004
					printArea.drawText(rect, Qt::AlignRight, kl->formatNumber(qs_avgspeed, false));
1005
		    rect.setCoords(milToPixel(extMil[0]+147, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+170, printer), milToPixel(aktLine+lineH, printer, true));
1005
					rect.setCoords(milToPixel(extMil[0] + 122, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 147, printer), milToPixel(aktLine + lineH, printer, true));
1006
		    printArea.drawText(rect, Qt::AlignRight, qs_avgcadence);
1006
					printArea.drawText(rect, Qt::AlignRight, qs_avghr);
1007
		    printed = true;
1007
					rect.setCoords(milToPixel(extMil[0] + 147, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 170, printer), milToPixel(aktLine + lineH, printer, true));
1008
		 }
1008
					printArea.drawText(rect, Qt::AlignRight, qs_avgcadence);
1009
 
1009
					printed = true;
1010
		 aktLine += lineH;
1010
				}
1011
 
1011
 
1012
		 if (aktLine >= extMil[3])	// Print on the next page
1012
				aktLine += lineH;
1013
		 {
1013
 
1014
		    aktLine = extMil[3] + 10.0;
1014
				if(aktLine >= extMil[3])	// Print on the next page
1015
 
1015
				{
1016
		    if ((lastPage > 0 && page >= firstPage && page <= lastPage) ||
1016
					aktLine = extMil[3] + 10.0;
1017
		        (lastPage == 0 && firstPage == 0))
1017
 
1018
		    {
1018
					if((lastPage > 0 && page >= firstPage && page <= lastPage) ||
1019
		       printArea.setFont(QFont(QString("Helvetica"), 8, QFont::Normal, false));
1019
					                  (lastPage == 0 && firstPage == 0))
1020
		       rect.setCoords(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+170, printer), milToPixel(aktLine+lineH, printer, true));
1020
					{
1021
		       printArea.drawText(rect, Qt::AlignRight, i18n("Page %1").arg(page));
1021
						printArea.setFont(QFont(QString("Helvetica"), 8, QFont::Normal, false));
1022
		       aktLine = extMil[1];
1022
						rect.setCoords(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 170, printer), milToPixel(aktLine + lineH, printer, true));
1023
		       printed = true;
1023
						printArea.drawText(rect, Qt::AlignRight, i18n("Page %1").arg(page));
1024
		    }
1024
						aktLine = extMil[1];
1025
		    else
1025
						printed = true;
1026
		       aktLine = extMil[1];
1026
					}
1027
 
1027
					else
1028
		    if (printed)
1028
						aktLine = extMil[1];
1029
		       printer.newPage();
1029
 
1030
 
1030
					if(printed)
1031
		    page++;
1031
						printer.newPage();
1032
		    // Print the headline of the table
1032
 
1033
		    if ((lastPage > 0 && page >= firstPage && page <= lastPage) ||
1033
					page++;
1034
		        (lastPage == 0 && firstPage == 0))
1034
 
1035
		    {
1035
					// Print the headline of the table
1036
		       printArea.setFont(QFont(QString("Helvetica"), 10, QFont::Bold, false));
1036
					if((lastPage > 0 && page >= firstPage && page <= lastPage) ||
1037
		       rect.setCoords(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+35, printer), milToPixel(aktLine+lineH, printer, true));
1037
					                  (lastPage == 0 && firstPage == 0))
1038
		       printArea.drawText(rect, Qt::AlignHCenter, i18n("Lap"));
1038
					{
1039
		       rect.setCoords(milToPixel(extMil[0]+35, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+60, printer), milToPixel(aktLine+lineH, printer, true));
1039
						printArea.setFont(QFont(QString("Helvetica"), 10, QFont::Bold, false));
1040
		       printArea.drawText(rect, Qt::AlignHCenter, i18n("Distance"));
1040
						rect.setCoords(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 35, printer), milToPixel(aktLine + lineH, printer, true));
1041
		       rect.setCoords(milToPixel(extMil[0]+60, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+85, printer), milToPixel(aktLine+lineH, printer, true));
1041
						printArea.drawText(rect, Qt::AlignHCenter, i18n("Lap"));
1042
		       printArea.drawText(rect, Qt::AlignHCenter, i18n("Time"));
1042
						rect.setCoords(milToPixel(extMil[0] + 35, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 60, printer), milToPixel(aktLine + lineH, printer, true));
1043
		       rect.setCoords(milToPixel(extMil[0]+85, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+122, printer), milToPixel(aktLine+lineH, printer, true));
1043
						printArea.drawText(rect, Qt::AlignHCenter, i18n("Distance"));
1044
		       printArea.drawText(rect, Qt::AlignHCenter, i18n("Speed"));
1044
						rect.setCoords(milToPixel(extMil[0] + 60, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 85, printer), milToPixel(aktLine + lineH, printer, true));
1045
		       rect.setCoords(milToPixel(extMil[0]+122, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+147, printer), milToPixel(aktLine+lineH, printer, true));
1045
						printArea.drawText(rect, Qt::AlignHCenter, i18n("Time"));
1046
		       printArea.drawText(rect, Qt::AlignHCenter, i18n("Heart rate"));
1046
						rect.setCoords(milToPixel(extMil[0] + 85, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 122, printer), milToPixel(aktLine + lineH, printer, true));
1047
		       rect.setCoords(milToPixel(extMil[0]+147, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0]+170, printer), milToPixel(aktLine+lineH, printer, true));
1047
						printArea.drawText(rect, Qt::AlignHCenter, i18n("Speed"));
1048
		       printArea.drawText(rect, Qt::AlignHCenter, i18n("Cadence"));
1048
						rect.setCoords(milToPixel(extMil[0] + 122, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 147, printer), milToPixel(aktLine + lineH, printer, true));
1049
		       aktLine += lineH;
1049
						printArea.drawText(rect, Qt::AlignHCenter, i18n("Heart rate"));
1050
		       printArea.setPen(QPen(QBrush(QColor("black")), milToPixel(0.5, printer, false)));
1050
						rect.setCoords(milToPixel(extMil[0] + 147, printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 170, printer), milToPixel(aktLine + lineH, printer, true));
1051
		       printArea.drawLine(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 170, printer), milToPixel(aktLine, printer, true));
1051
						printArea.drawText(rect, Qt::AlignHCenter, i18n("Cadence"));
1052
		       aktLine += 1.0;
1052
						aktLine += lineH;
1053
		       printed = true;
1053
						printArea.setPen(QPen(QBrush(QColor("black")), milToPixel(0.5, printer, false)));
1054
		    }
1054
						printArea.drawLine(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true), milToPixel(extMil[0] + 170, printer), milToPixel(aktLine, printer, true));
1055
		    else
1055
						aktLine += 1.0;
1056
		    {
1056
						printed = true;
1057
		       aktLine += lineH;
1057
					}
1058
		       aktLine += 1.0;
1058
					else
1059
		    }
1059
					{
1060
 
1060
						aktLine += lineH;
1061
		    printArea.setFont(QFont(QString("Helvetica"), 10, QFont::Normal, false));
1061
						aktLine += 1.0;
1062
		 }
1062
					}
1063
 
1063
 
1064
		 delete qt;
1064
					printArea.setFont(QFont(QString("Helvetica"), 10, QFont::Normal, false));
1065
		 laps++;
1065
				}
1066
	      }
1066
 
1067
 
1067
				delete qt;
1068
	      aktLine = extMil[3] + 10.0;
1068
				laps++;
1069
	      if ((lastPage > 0 && page >= firstPage && page <= lastPage) ||
1069
			}
1070
		  (lastPage == 0 && firstPage == 0))
1070
 
1071
	      {
1071
			aktLine = extMil[3] + 10.0;
1072
		 printArea.setFont(QFont(QString("Helvetica"), 8, QFont::Normal, false));
1072
 
1073
		 rect.setCoords(milToPixel(extMil[0], printer),
1073
			if((lastPage > 0 && page >= firstPage && page <= lastPage) ||
1074
				milToPixel(aktLine, printer, true),
1074
			                  (lastPage == 0 && firstPage == 0))
1075
				milToPixel(extMil[0]+170, printer),
1075
			{
1076
				milToPixel(aktLine+lineH, printer, true));
1076
				printArea.setFont(QFont(QString("Helvetica"), 8, QFont::Normal, false));
1077
		 printArea.drawText(rect, Qt::AlignRight, i18n("Page %1").arg(page));
1077
				rect.setCoords(milToPixel(extMil[0], printer),
1078
		 printed = true;
1078
				               milToPixel(aktLine, printer, true),
1079
	      }
1079
				               milToPixel(extMil[0] + 170, printer),
1080
 
1080
				               milToPixel(aktLine + lineH, printer, true));
1081
	      aktLine = extMil[1];
1081
				printArea.drawText(rect, Qt::AlignRight, i18n("Page %1").arg(page));
1082
	      page++;
1082
				printed = true;
1083
 
1083
			}
1084
	      if (printed && (page <= lastPage || lastPage == 0))
1084
 
1085
		 printer.newPage();
1085
			aktLine = extMil[1];
1086
 
1086
			page++;
1087
	      if ((lastPage > 0 && (page < firstPage || page > lastPage)))
1087
 
1088
		 break;
1088
			if(printed && (page <= lastPage || lastPage == 0))
1089
 
1089
				printer.newPage();
1090
	      // Draw the map on top of a new page
1090
 
1091
	      // Use 1/3 of the available height for the map
1091
			if((lastPage > 0 && (page < firstPage || page > lastPage)))
1092
	      qreal resFact = 8;	// The factor to calculate the resolution for pixmaps
1092
				break;
1093
	      int width = (int)(milToPixel(170, printer) / resFact);
1093
 
1094
	      int height = (int)(milToPixel(extMil[3] - extMil[1], printer, true) / resFact);
1094
			// Draw the map on top of a new page
1095
	      pmPrMap = QPixmap(width, height / 3);	// 1/3 of page height
1095
			// Use 1/3 of the available height for the map
1096
	      DIRTY = true;
1096
			qreal resFact = 8;	// The factor to calculate the resolution for pixmaps
1097
	      int ct = curTab;
1097
			int width = (int)(milToPixel(170, printer) / resFact);
1098
	      curTab = 1;
1098
			int height = (int)(milToPixel(extMil[3] - extMil[1], printer, true) / resFact);
1099
	      QApplication::restoreOverrideCursor();
1099
			pmPrMap = QPixmap(width, height / 3);	// 1/3 of page height
1100
	      showTrack();
1100
			DIRTY = true;
1101
	      QApplication::setOverrideCursor (QCursor(Qt::WaitCursor));
1101
			int ct = curTab;
1102
	      DIRTY = false;
1102
			curTab = 1;
1103
	      curTab = ct;
1103
			QApplication::restoreOverrideCursor();
1104
	      printArea.drawPixmap(milToPixel(extMil[0], printer),
1104
			showTrack();
1105
				milToPixel(extMil[1], printer),
1105
			QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
1106
				pmPrMap.scaled((int)milToPixel(170, printer),
1106
			DIRTY = false;
1107
				(int)milToPixel(extMil[3] - extMil[1], printer, true) / 3,
1107
			curTab = ct;
1108
				Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
1108
			printArea.drawPixmap(milToPixel(extMil[0], printer),
1109
	      // Put a frame around the map
1109
			                     milToPixel(extMil[1], printer),
1110
	      rect.setCoords(milToPixel(extMil[0], printer), milToPixel(extMil[1], printer, true),
1110
			                     pmPrMap.scaled((int)milToPixel(170, printer),
1111
				milToPixel(extMil[0] + 170, printer),
1111
			                                    (int)milToPixel(extMil[3] - extMil[1], printer, true) / 3,
1112
				milToPixel(extMil[1], printer, true) + (milToPixel(extMil[3] - extMil[1], printer, true) / 3));
1112
			                                    Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
1113
	      printArea.setPen(QPen(QBrush(QColor("black")), milToPixel(0.2, printer)));
1113
			// Put a frame around the map
1114
	      printArea.drawRect(rect);
1114
			rect.setCoords(milToPixel(extMil[0], printer), milToPixel(extMil[1], printer, true),
1115
	      aktLine = (extMil[3] - extMil[1]) / 3.0 + extMil[1] + lineH;
1115
			               milToPixel(extMil[0] + 170, printer),
1116
 
1116
			               milToPixel(extMil[1], printer, true) + (milToPixel(extMil[3] - extMil[1], printer, true) / 3));
1117
	      // Draw the heart rate diagram
1117
			printArea.setPen(QPen(QBrush(QColor("black")), milToPixel(0.2, printer)));
1118
	      rect.setCoords(milToPixel(extMil[0], printer),
1118
			printArea.drawRect(rect);
1119
				milToPixel(aktLine, printer, true),
1119
			aktLine = (extMil[3] - extMil[1]) / 3.0 + extMil[1] + lineH;
1120
				milToPixel(extMil[2], printer),
1120
 
1121
				milToPixel(aktLine + lineH, printer, true));
1121
			// Draw the heart rate diagram
1122
	      printArea.drawText(rect, Qt::AlignLeft, i18n("Heart rate:"));
1122
			rect.setCoords(milToPixel(extMil[0], printer),
1123
	      aktLine += lineH;
1123
			               milToPixel(aktLine, printer, true),
1124
	      qreal pixHeight = (extMil[3] - aktLine) / 3.0 - lineH * 2.0;
1124
			               milToPixel(extMil[2], printer),
1125
	      int realH = (int)milToPixel(pixHeight, printer, true);
1125
			               milToPixel(aktLine + lineH, printer, true));
1126
	      height = realH / (int)resFact;
1126
			printArea.drawText(rect, Qt::AlignLeft, i18n("Heart rate:"));
1127
	      showThreeCurve(width, height);	// Calculate the curves
1127
			aktLine += lineH;
1128
	      printArea.drawPixmap(milToPixel(extMil[0], printer),
1128
			qreal pixHeight = (extMil[3] - aktLine) / 3.0 - lineH * 2.0;
1129
				milToPixel(aktLine, printer, true),
1129
			int realH = (int)milToPixel(pixHeight, printer, true);
1130
				prHR.scaled((int)milToPixel(170, printer),
1130
			height = realH / (int)resFact;
1131
				realH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
1131
			showThreeCurve(width, height);	// Calculate the curves
1132
	      rect.setCoords(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true),
1132
			printArea.drawPixmap(milToPixel(extMil[0], printer),
1133
				milToPixel(extMil[0] + 170, printer),
1133
			                     milToPixel(aktLine, printer, true),
1134
				milToPixel(aktLine + pixHeight, printer, true));
1134
			                     prHR.scaled((int)milToPixel(170, printer),
1135
	      printArea.drawRect(rect);
1135
			                                 realH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
1136
	      aktLine += pixHeight + lineH;
1136
			rect.setCoords(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true),
1137
 
1137
			               milToPixel(extMil[0] + 170, printer),
1138
	      // Draw the elevation diagram
1138
			               milToPixel(aktLine + pixHeight, printer, true));
1139
	      rect.setCoords(milToPixel(extMil[0], printer),
1139
			printArea.drawRect(rect);
1140
				milToPixel(aktLine, printer, true),
1140
			aktLine += pixHeight + lineH;
1141
				milToPixel(extMil[2], printer),
1141
 
1142
				milToPixel(aktLine + lineH, printer, true));
1142
			// Draw the elevation diagram
1143
	      printArea.drawText(rect, Qt::AlignLeft, i18n("Elevation:"));
1143
			rect.setCoords(milToPixel(extMil[0], printer),
1144
	      aktLine += lineH;
1144
			               milToPixel(aktLine, printer, true),
1145
	      printArea.drawPixmap(milToPixel(extMil[0], printer),
1145
			               milToPixel(extMil[2], printer),
1146
				milToPixel(aktLine, printer, true),
1146
			               milToPixel(aktLine + lineH, printer, true));
1147
				prElevation.scaled((int)milToPixel(170, printer),
1147
			printArea.drawText(rect, Qt::AlignLeft, i18n("Elevation:"));
1148
				realH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
1148
			aktLine += lineH;
1149
	      rect.setCoords(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true),
1149
			printArea.drawPixmap(milToPixel(extMil[0], printer),
1150
				milToPixel(extMil[0] + 170, printer),
1150
			                     milToPixel(aktLine, printer, true),
1151
				milToPixel(aktLine + pixHeight, printer, true));
1151
			                     prElevation.scaled((int)milToPixel(170, printer),
1152
	      printArea.drawRect(rect);
1152
			                                        realH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
1153
	      aktLine += pixHeight + lineH;
1153
			rect.setCoords(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true),
1154
 
1154
			               milToPixel(extMil[0] + 170, printer),
1155
	      // Draw the speed diagram
1155
			               milToPixel(aktLine + pixHeight, printer, true));
1156
	      rect.setCoords(milToPixel(extMil[0], printer),
1156
			printArea.drawRect(rect);
1157
				milToPixel(aktLine, printer, true),
1157
			aktLine += pixHeight + lineH;
1158
				milToPixel(extMil[2], printer),
1158
 
1159
				milToPixel(aktLine + lineH, printer, true));
1159
			// Draw the speed diagram
1160
	      printArea.drawText(rect, Qt::AlignLeft, i18n("Speed:"));
1160
			rect.setCoords(milToPixel(extMil[0], printer),
1161
	      aktLine += lineH;
1161
			               milToPixel(aktLine, printer, true),
1162
	      printArea.drawPixmap(milToPixel(extMil[0], printer),
1162
			               milToPixel(extMil[2], printer),
1163
				milToPixel(aktLine, printer, true),
1163
			               milToPixel(aktLine + lineH, printer, true));
1164
				prSpeed.scaled((int)milToPixel(170, printer),
1164
			printArea.drawText(rect, Qt::AlignLeft, i18n("Speed:"));
1165
				realH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
1165
			aktLine += lineH;
1166
	      rect.setCoords(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true),
1166
			printArea.drawPixmap(milToPixel(extMil[0], printer),
1167
				milToPixel(extMil[0] + 170, printer),
1167
			                     milToPixel(aktLine, printer, true),
1168
				milToPixel(aktLine + pixHeight, printer, true));
1168
			                     prSpeed.scaled((int)milToPixel(170, printer),
1169
	      printArea.drawRect(rect);
1169
			                                    realH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
1170
 
1170
			rect.setCoords(milToPixel(extMil[0], printer), milToPixel(aktLine, printer, true),
1171
	      // Print the page number at the right bottom of the page
1171
			               milToPixel(extMil[0] + 170, printer),
1172
	      aktLine = extMil[3] + 10.0;
1172
			               milToPixel(aktLine + pixHeight, printer, true));
1173
	      printArea.setFont(QFont(QString("Helvetica"), 8, QFont::Normal, false));
1173
			printArea.drawRect(rect);
1174
	      rect.setCoords(milToPixel(extMil[0], printer),
1174
 
1175
				milToPixel(aktLine, printer, true),
1175
			// Print the page number at the right bottom of the page
1176
				milToPixel(extMil[0]+170, printer),
1176
			aktLine = extMil[3] + 10.0;
1177
				milToPixel(aktLine+lineH, printer, true));
1177
			printArea.setFont(QFont(QString("Helvetica"), 8, QFont::Normal, false));
1178
	      printArea.drawText(rect, Qt::AlignRight, i18n("Page %1").arg(page));
1178
			rect.setCoords(milToPixel(extMil[0], printer),
1179
	   }
1179
			               milToPixel(aktLine, printer, true),
-
 
1180
			               milToPixel(extMil[0] + 170, printer),
-
 
1181
			               milToPixel(aktLine + lineH, printer, true));
-
 
1182
			printArea.drawText(rect, Qt::AlignRight, i18n("Page %1").arg(page));
-
 
1183
		}
1180
 
1184
 
1181
	   rakt = rakt->next;
1185
		rakt = rakt->next;
1182
	}
1186
	}
1183
 
1187
 
1184
	printArea.end();
1188
	printArea.end();
1185
	// Mark printing as done
1189
	// Mark printing as done
1186
	ActivePrint = false;
1190
	ActivePrint = false;
Line 1190... Line 1194...
1190
qreal sportwatcherWidget::milToPixel(qreal dist, QPrinter &pr, bool dir)
1194
qreal sportwatcherWidget::milToPixel(qreal dist, QPrinter &pr, bool dir)
1191
{
1195
{
1192
	QSizeF r = pr.paperSize(QPrinter::DevicePixel);
1196
	QSizeF r = pr.paperSize(QPrinter::DevicePixel);
1193
	QSizeF m = pr.paperSize(QPrinter::Millimeter);
1197
	QSizeF m = pr.paperSize(QPrinter::Millimeter);
1194
 
1198
 
1195
	if (!dir)	// width
1199
	if(!dir)	// width
1196
	   return r.width() / m.width() * dist;
1200
		return r.width() / m.width() * dist;
1197
	else
1201
	else
1198
	   return r.height() / m.height() * dist;
1202
		return r.height() / m.height() * dist;
1199
}
1203
}
1200
 
1204
 
1201
/*
1205
/*
1202
 * This function allows the user to choose a file name, where we save the
1206
 * This function allows the user to choose a file name, where we save the
1203
 * actual lap in Garmins own TCX format. This format is simply a XML-file.
1207
 * actual lap in Garmins own TCX format. This format is simply a XML-file.
1204
 * For details about the schema of this file look at
1208
 * For details about the schema of this file look at
1205
 * http://developer.garmin.com/schemas/tcx/v2/
1209
 * http://developer.garmin.com/schemas/tcx/v2/
1206
 */
1210
 */
1207
void sportwatcherWidget::fileSaveAs()
1211
void sportwatcherWidget::fileSaveAs()
1208
{
1212
{
1209
QString fname;
1213
	QString fname;
1210
QFile fn;
1214
	QFile fn;
1211
QString buffer;
1215
	QString buffer;
1212
RUN_NODE *rn, *rakt;
1216
	RUN_NODE *rn, *rakt;
1213
LAP *lap;
1217
	LAP *lap;
1214
POINT *point;
1218
	POINT *point;
1215
int indent, i;
1219
	int indent, i;
1216
QDateTime *qt;
1220
	QDateTime *qt;
1217
KUrl sDir("~/");
1221
	KUrl sDir("~/");
1218
QRegExp rx("(\\.tcx|\\.gpx|\\.osm)$");
1222
	QRegExp rx("(\\.tcx|\\.gpx|\\.osm)$");
1219
 
1223
 
1220
	if (!gmn)
1224
	if(!gmn)
1221
	{
1225
	{
1222
	   KMessageBox::error(this, i18n("Currently no activity is selected!"));
1226
		KMessageBox::error(this, i18n("Currently no activity is selected!"));
1223
	   return;
1227
		return;
1224
	}
1228
	}
1225
 
1229
 
1226
	rx.setPatternSyntax(QRegExp::RegExp);
1230
	rx.setPatternSyntax(QRegExp::RegExp);
1227
	fname = KFileDialog::getSaveFileName(sDir, QString("*.tcx|Garmin Training Center (*.tcx)\n*.gpx|GPS Excange Format (*.gpx)\n*.osm|OpenStreetMap (*.osm)"), this, QString("SportWatcher"));
1231
	fname = KFileDialog::getSaveFileName(sDir, QString("*.tcx|Garmin Training Center (*.tcx)\n*.gpx|GPS Excange Format (*.gpx)\n*.osm|OpenStreetMap (*.osm)"), this, QString("SportWatcher"));
1228
 
1232
 
1229
	if (fname.isEmpty())
1233
	if(fname.isEmpty())
1230
	   return;
1234
		return;
1231
 
1235
 
1232
	if (rx.indexIn(fname) < 0)
1236
	if(rx.indexIn(fname) < 0)
1233
	{
1237
	{
1234
	   KMessageBox::error(this, i18n("The file %1 has no valid file extension!").arg(fname));
1238
		KMessageBox::error(this, i18n("The file %1 has no valid file extension!").arg(fname));
1235
	   return;
1239
		return;
1236
	}
1240
	}
1237
 
1241
 
1238
	fn.setFileName(fname);
1242
	fn.setFileName(fname);
1239
 
1243
 
1240
	if (fn.exists())
1244
	if(fn.exists())
1241
	{
1245
	{
1242
	   if (KMessageBox::questionYesNo(this, i18n("Do you really want to overwrite this file?")) == KMessageBox::No)
1246
		if(KMessageBox::questionYesNo(this, i18n("Do you really want to overwrite this file?")) == KMessageBox::No)
1243
	      return;
1247
			return;
1244
	}
1248
	}
1245
 
1249
 
1246
	rx.setPattern("*.gpx");
1250
	rx.setPattern("*.gpx");
1247
	rx.setPatternSyntax(QRegExp::Wildcard);
1251
	rx.setPatternSyntax(QRegExp::Wildcard);
1248
 
1252
 
1249
	if (rx.exactMatch(fname))	// Should we create a *.gpx file?
1253
	if(rx.exactMatch(fname))	// Should we create a *.gpx file?
1250
	{
1254
	{
1251
	   sportwatcherWidget::saveGPX(fname);
1255
		sportwatcherWidget::saveGPX(fname);
1252
	   return;
1256
		return;
1253
	}
1257
	}
1254
 
1258
 
1255
	rx.setPattern("*.osm");
1259
	rx.setPattern("*.osm");
1256
	rx.setPatternSyntax(QRegExp::Wildcard);
1260
	rx.setPatternSyntax(QRegExp::Wildcard);
1257
 
1261
 
1258
	if (rx.exactMatch(fname))	// Should we create a *.osm file?
1262
	if(rx.exactMatch(fname))	// Should we create a *.osm file?
1259
	{
1263
	{
1260
	   sportwatcherWidget::saveOSM(fname);
1264
		sportwatcherWidget::saveOSM(fname);
1261
	   return;
1265
		return;
1262
	}
1266
	}
1263
 
1267
 
1264
	// No, we create a *.tcx file!
1268
	// No, we create a *.tcx file!
1265
	indent = 0;
1269
	indent = 0;
1266
	rn = ds.getRunNode();
1270
	rn = ds.getRunNode();
1267
	lap = ds.getLap(rn->run->first_lap_index);
1271
	lap = ds.getLap(rn->run->first_lap_index);
1268
 
1272
 
1269
	if ((point = ds.getPoint(lap->start_time)) == 0)
1273
	if((point = ds.getPoint(lap->start_time)) == 0)
1270
	{
1274
	{
1271
	   KMessageBox::error(this, i18n("No data to save!"));
1275
		KMessageBox::error(this, i18n("No data to save!"));
1272
	   return;
1276
		return;
1273
	}
1277
	}
1274
 
1278
 
1275
	if (!fn.open(QIODevice::ReadWrite | QIODevice::Truncate))
1279
	if(!fn.open(QIODevice::ReadWrite | QIODevice::Truncate))
1276
	{
1280
	{
1277
	   KMessageBox::error(this, i18n("Error creating file %1!\nPlease check permissions").arg(fname));
1281
		KMessageBox::error(this, i18n("Error creating file %1!\nPlease check permissions").arg(fname));
1278
	   return;
1282
		return;
1279
	}
1283
	}
1280
 
1284
 
1281
	buffer = QString("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>\n");
1285
	buffer = QString("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>\n");
1282
	buffer.append("<TrainingCenterDatabase xmlns=\"http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2\" ");
1286
	buffer.append("<TrainingCenterDatabase xmlns=\"http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2\" ");
1283
	buffer.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ");
1287
	buffer.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ");
1284
	buffer.append("xsi:schemaLocation=\"http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2 ");
1288
	buffer.append("xsi:schemaLocation=\"http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2 ");
1285
	buffer.append("http://www.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd\">\n\n");
1289
	buffer.append("http://www.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd\">\n\n");
1286
	writeTag (fn, buffer, indent);
1290
	writeTag(fn, buffer, indent);
1287
	buffer = QString("<folders/>\n\n");
1291
	buffer = QString("<folders/>\n\n");
1288
	writeTag (fn, buffer, indent);
1292
	writeTag(fn, buffer, indent);
1289
 
1293
 
1290
	// Open a course
1294
	// Open a course
1291
	QFileInfo finfo(fname);
1295
	QFileInfo finfo(fname);
1292
	buffer = QString("<Courses>\n   <Course>\n      <name>%1</name>\n").arg(QFileInfo(finfo).baseName());
1296
	buffer = QString("<Courses>\n   <Course>\n      <name>%1</name>\n").arg(QFileInfo(finfo).baseName());
1293
	writeTag (fn, buffer, indent);
1297
	writeTag(fn, buffer, indent);
1294
	indent = 2;
1298
	indent = 2;
1295
 
1299
 
1296
	rakt = rn;
1300
	rakt = rn;
1297
 
1301
 
1298
	while (rakt)
1302
	while(rakt)
1299
	{
1303
	{
1300
	   if (rakt->run->type != data_D1000 && rakt->run->type != data_D1009 &&
1304
		if(rakt->run->type != data_D1000 && rakt->run->type != data_D1009 &&
1301
	   	rakt->run->type != data_D1010)
1305
		                  rakt->run->type != data_D1010)
1302
	   {
1306
		{
1303
	      rakt = rakt->next;
1307
			rakt = rakt->next;
1304
	      continue;
1308
			continue;
1305
	   }
1309
		}
1306
 
1310
 
1307
	   for (i = rakt->run->first_lap_index; (unsigned int)i <= rakt->run->last_lap_index; i++)
1311
		for(i = rakt->run->first_lap_index; (unsigned int)i <= rakt->run->last_lap_index; i++)
1308
	   {
1312
		{
1309
	      if ((lap = ds.getLap(i)) == NULL)
1313
			if((lap = ds.getLap(i)) == NULL)
1310
		 continue;
1314
				continue;
1311
 
1315
 
1312
	      // Write the information of the lap
1316
			// Write the information of the lap
1313
	      writeTag (fn, QString("<Lap>\n"), indent);
1317
			writeTag(fn, QString("<Lap>\n"), indent);
1314
	      indent++;
1318
			indent++;
1315
	      buffer.sprintf("<TotalTimeSeconds>%f</TotalTimeSeconds>\n", (double)lap->total_time / 100.0);
1319
			buffer.sprintf("<TotalTimeSeconds>%f</TotalTimeSeconds>\n", (double)lap->total_time / 100.0);
1316
	      writeTag (fn, buffer, indent);
1320
			writeTag(fn, buffer, indent);
1317
	      qt = garmin_dtime(lap->start_time);
1321
			qt = garmin_dtime(lap->start_time);
1318
	      buffer = QString("<StartTime>%1</StartTime>\n").arg(qt->toString("yyyy-MM-ddThh:mm:ssZ"));
1322
			buffer = QString("<StartTime>%1</StartTime>\n").arg(qt->toString("yyyy-MM-ddThh:mm:ssZ"));
1319
	      writeTag (fn, buffer, indent);
1323
			writeTag(fn, buffer, indent);
1320
	      buffer.sprintf("<DistanceMeters>%f</DistanceMeters>\n", lap->total_distance);
1324
			buffer.sprintf("<DistanceMeters>%f</DistanceMeters>\n", lap->total_distance);
1321
	      writeTag (fn, buffer, indent);
1325
			writeTag(fn, buffer, indent);
1322
 
1326
 
1323
	      writeTag (fn, QString("<BeginPosition>\n"), indent);
1327
			writeTag(fn, QString("<BeginPosition>\n"), indent);
1324
	      indent++;
1328
			indent++;
1325
	      buffer.sprintf("<LatitudeDegrees>%f</LatitudeDegrees>\n", SEMI2DEG(lap->begin.lat));
1329
			buffer.sprintf("<LatitudeDegrees>%f</LatitudeDegrees>\n", SEMI2DEG(lap->begin.lat));
1326
	      writeTag (fn, buffer, indent);
1330
			writeTag(fn, buffer, indent);
1327
	      buffer.sprintf("<LongitudeDegrees>%f</LongitudeDegrees>\n", SEMI2DEG(lap->begin.lon));
1331
			buffer.sprintf("<LongitudeDegrees>%f</LongitudeDegrees>\n", SEMI2DEG(lap->begin.lon));
1328
	      writeTag (fn, buffer, indent);
1332
			writeTag(fn, buffer, indent);
1329
	      indent--;
1333
			indent--;
1330
	      writeTag (fn, QString("</BeginPosition>\n"), indent);
1334
			writeTag(fn, QString("</BeginPosition>\n"), indent);
1331
 
1335
 
1332
	      writeTag (fn, QString("<EndPosition>\n"), indent);
1336
			writeTag(fn, QString("<EndPosition>\n"), indent);
1333
	      indent++;
1337
			indent++;
1334
	      buffer.sprintf("<LatitudeDegrees>%f</LatitudeDegrees>\n", SEMI2DEG(lap->end.lat));
1338
			buffer.sprintf("<LatitudeDegrees>%f</LatitudeDegrees>\n", SEMI2DEG(lap->end.lat));
1335
	      writeTag (fn, buffer, indent);
1339
			writeTag(fn, buffer, indent);
1336
	      buffer.sprintf("<LongitudeDegrees>%f</LongitudeDegrees>\n", SEMI2DEG(lap->end.lon));
1340
			buffer.sprintf("<LongitudeDegrees>%f</LongitudeDegrees>\n", SEMI2DEG(lap->end.lon));
1337
	      writeTag (fn, buffer, indent);
1341
			writeTag(fn, buffer, indent);
1338
	      indent--;
1342
			indent--;
1339
	      writeTag (fn, QString("</EndPosition>\n"), indent);
1343
			writeTag(fn, QString("</EndPosition>\n"), indent);
1340
 
1344
 
1341
	      writeTag (fn, QString("<AverageHeartRateBpm xsi:type=\"HeartRateInBeatsPerMinute_t\">\n"), indent);
1345
			writeTag(fn, QString("<AverageHeartRateBpm xsi:type=\"HeartRateInBeatsPerMinute_t\">\n"), indent);
1342
	      indent++;
1346
			indent++;
1343
	      buffer.sprintf("<Value>%d</Value>\n", lap->avg_heart_rate);
1347
			buffer.sprintf("<Value>%d</Value>\n", lap->avg_heart_rate);
1344
	      writeTag (fn, buffer, indent);
1348
			writeTag(fn, buffer, indent);
1345
	      indent--;
1349
			indent--;
1346
	      writeTag (fn, QString("</AverageHeartRateBpm>\n"), indent);
1350
			writeTag(fn, QString("</AverageHeartRateBpm>\n"), indent);
1347
 
1351
 
1348
	      writeTag (fn, QString("<MaximumHeartRateBpm xsi:type=\"HeartRateInBeatsPerMinute_t\">\n"), indent);
1352
			writeTag(fn, QString("<MaximumHeartRateBpm xsi:type=\"HeartRateInBeatsPerMinute_t\">\n"), indent);
1349
	      indent++;
1353
			indent++;
1350
	      buffer.sprintf("<Value>%d</Value>\n", lap->max_heart_rate);
1354
			buffer.sprintf("<Value>%d</Value>\n", lap->max_heart_rate);
1351
	      writeTag (fn, buffer, indent);
1355
			writeTag(fn, buffer, indent);
1352
	      indent--;
1356
			indent--;
1353
	      writeTag (fn, QString("</MaximumHeartRateBpm>\n"), indent);
1357
			writeTag(fn, QString("</MaximumHeartRateBpm>\n"), indent);
1354
 
1358
 
1355
	      if (lap->avg_cadence < 255)
1359
			if(lap->avg_cadence < 255)
1356
	      {
1360
			{
1357
		 buffer.sprintf("<AverageCadence>%d</AverageCadence>\n", lap->avg_cadence);
1361
				buffer.sprintf("<AverageCadence>%d</AverageCadence>\n", lap->avg_cadence);
1358
		 writeTag (fn, buffer, indent);
1362
				writeTag(fn, buffer, indent);
1359
		 buffer.sprintf("<Cadence>%d</Cadence>\n", lap->avg_cadence);
1363
				buffer.sprintf("<Cadence>%d</Cadence>\n", lap->avg_cadence);
1360
		 writeTag (fn, buffer, indent);
1364
				writeTag(fn, buffer, indent);
1361
	      }
1365
			}
1362
 
1366
 
1363
	      buffer = QString("<Intensity>%1</Intensity>\n").arg((!lap->intensity) ? "Active" : "Resting");
1367
			buffer = QString("<Intensity>%1</Intensity>\n").arg((!lap->intensity) ? "Active" : "Resting");
1364
	      writeTag (fn, buffer, indent);
1368
			writeTag(fn, buffer, indent);
1365
 
1369
 
1366
	      buffer.sprintf("<Calories>%d</Calories>\n", lap->calories);
1370
			buffer.sprintf("<Calories>%d</Calories>\n", lap->calories);
1367
	      writeTag (fn, buffer, indent);
1371
			writeTag(fn, buffer, indent);
1368
 
1372
 
1369
	      buffer.sprintf("<MaximumSpeed>%f</MaximumSpeed>\n", lap->max_speed);
1373
			buffer.sprintf("<MaximumSpeed>%f</MaximumSpeed>\n", lap->max_speed);
1370
	      writeTag (fn, buffer, indent);
1374
			writeTag(fn, buffer, indent);
1371
	      indent--;
1375
			indent--;
1372
	      writeTag (fn, QString("</Lap>\n"), indent);
1376
			writeTag(fn, QString("</Lap>\n"), indent);
1373
 
1377
 
1374
	      point = ds.getPoint(lap->start_time);
1378
			point = ds.getPoint(lap->start_time);
1375
	      writeTag (fn, QString("<Track>\n"), indent);
1379
			writeTag(fn, QString("<Track>\n"), indent);
1376
	      indent++;
1380
			indent++;
1377
 
1381
 
1378
	      while (point)
1382
			while(point)
1379
	      {
1383
			{
1380
		 if (point->time > (lap->start_time + (lap->total_time / 100)))
1384
				if(point->time > (lap->start_time + (lap->total_time / 100)))
1381
		    break;
1385
					break;
1382
 
1386
 
1383
		 writeTag (fn, QString("<Trackpoint>\n"), indent);
1387
				writeTag(fn, QString("<Trackpoint>\n"), indent);
1384
		 indent++;
1388
				indent++;
1385
		 qt = garmin_dtime(point->time);
1389
				qt = garmin_dtime(point->time);
1386
		 buffer = QString("<Time>%1</Time>\n").arg(qt->toString("yyyy-MM-ddThh:mm:ssZ"));
1390
				buffer = QString("<Time>%1</Time>\n").arg(qt->toString("yyyy-MM-ddThh:mm:ssZ"));
1387
		 writeTag (fn, buffer, indent);
1391
				writeTag(fn, buffer, indent);
1388
		 delete qt;
1392
				delete qt;
1389
		 writeTag (fn, QString("<Position>\n"), indent);
1393
				writeTag(fn, QString("<Position>\n"), indent);
1390
		 indent++;
1394
				indent++;
1391
		 buffer.sprintf("<LatitudeDegrees>%f</LatitudeDegrees>\n", SEMI2DEG(point->posn.lat));
1395
				buffer.sprintf("<LatitudeDegrees>%f</LatitudeDegrees>\n", SEMI2DEG(point->posn.lat));
1392
		 writeTag (fn, buffer, indent);
1396
				writeTag(fn, buffer, indent);
1393
		 buffer.sprintf("<LongitudeDegrees>%f</LongitudeDegrees>\n", SEMI2DEG(point->posn.lon));
1397
				buffer.sprintf("<LongitudeDegrees>%f</LongitudeDegrees>\n", SEMI2DEG(point->posn.lon));
1394
		 writeTag (fn, buffer, indent);
1398
				writeTag(fn, buffer, indent);
1395
		 indent--;
1399
				indent--;
1396
		 writeTag (fn, QString("</Position>\n"), indent);
1400
				writeTag(fn, QString("</Position>\n"), indent);
1397
 
1401
 
1398
		 if (point->alt < 20000.0)
1402
				if(point->alt < 20000.0)
1399
		 {
1403
				{
1400
		    buffer.sprintf("<AltitudeMeters>%f</AltitudeMeters>\n", point->alt);
1404
					buffer.sprintf("<AltitudeMeters>%f</AltitudeMeters>\n", point->alt);
1401
		    writeTag (fn, buffer, indent);
1405
					writeTag(fn, buffer, indent);
1402
		 }
1406
				}
1403
 
1407
 
1404
		 buffer.sprintf("<DistanceMeters>%f</DistanceMeters>\n", point->distance);
1408
				buffer.sprintf("<DistanceMeters>%f</DistanceMeters>\n", point->distance);
1405
		 writeTag (fn, buffer, indent);
1409
				writeTag(fn, buffer, indent);
1406
 
1410
 
1407
		 if (point->heart_rate > 0 && point->heart_rate < 250)
1411
				if(point->heart_rate > 0 && point->heart_rate < 250)
1408
		 {
1412
				{
1409
		    writeTag (fn, QString("<HeartRateBpm xsi:type=\"HeartRateInBeatsPerMinute_t\">\n"), indent);
1413
					writeTag(fn, QString("<HeartRateBpm xsi:type=\"HeartRateInBeatsPerMinute_t\">\n"), indent);
1410
		    indent++;
1414
					indent++;
1411
		    buffer.sprintf("<Value>%d</Value>\n", point->heart_rate);
1415
					buffer.sprintf("<Value>%d</Value>\n", point->heart_rate);
1412
		    writeTag (fn, buffer, indent);
1416
					writeTag(fn, buffer, indent);
1413
		    indent--;
1417
					indent--;
1414
		    writeTag (fn, QString("</HeartRateBpm>\n"), indent);
1418
					writeTag(fn, QString("</HeartRateBpm>\n"), indent);
1415
		 }
1419
				}
1416
 
1420
 
1417
		 if (point->cadence < 0xff)
1421
				if(point->cadence < 0xff)
1418
		 {
1422
				{
1419
		    buffer.sprintf("<Cadence>%d</Cadence>\n", point->cadence);
1423
					buffer.sprintf("<Cadence>%d</Cadence>\n", point->cadence);
1420
		    writeTag (fn, buffer, indent);
1424
					writeTag(fn, buffer, indent);
1421
		 }
1425
				}
1422
 
1426
 
1423
		 buffer.sprintf("<SensorState>%s</SensorState>\n", (!point->sensor) ? "Absent" : "Present");
1427
				buffer.sprintf("<SensorState>%s</SensorState>\n", (!point->sensor) ? "Absent" : "Present");
1424
		 writeTag (fn, buffer, indent);
1428
				writeTag(fn, buffer, indent);
1425
		 indent--;
1429
				indent--;
1426
		 writeTag (fn, QString("</Trackpoint>\n"), indent);
1430
				writeTag(fn, QString("</Trackpoint>\n"), indent);
1427
		 point = ds.getPoint(point->time + 1);
1431
				point = ds.getPoint(point->time + 1);
1428
	      }
1432
			}
1429
 
1433
 
1430
	      indent--;
1434
			indent--;
1431
	      writeTag (fn, QString("</Track>\n"), indent);
1435
			writeTag(fn, QString("</Track>\n"), indent);
1432
	   }
1436
		}
1433
 
1437
 
1434
	   indent--;
1438
		indent--;
1435
	   writeTag (fn, QString("</Course>\n"), indent);
1439
		writeTag(fn, QString("</Course>\n"), indent);
1436
	   indent--;
1440
		indent--;
1437
	   writeTag (fn, QString("</Courses>\n"), indent);
1441
		writeTag(fn, QString("</Courses>\n"), indent);
1438
	   rakt = rakt->next;
1442
		rakt = rakt->next;
1439
	}
1443
	}
1440
 
1444
 
1441
	// Write information about device
1445
	// Write information about device
1442
	// Here my personal signature is written :-)
1446
	// Here my personal signature is written :-)
1443
	writeTag (fn, QString("<Author xsi:type=\"Application_t\">\n"), indent);
1447
	writeTag(fn, QString("<Author xsi:type=\"Application_t\">\n"), indent);
1444
	indent++;
1448
	indent++;
1445
	writeTag (fn, QString("<Name>SportWatcher</Name>\n"), indent);
1449
	writeTag(fn, QString("<Name>SportWatcher</Name>\n"), indent);
1446
	writeTag (fn, QString("<Build>\n"), indent);
1450
	writeTag(fn, QString("<Build>\n"), indent);
1447
	indent++;
1451
	indent++;
1448
	writeTag (fn, QString("<Version>\n"), indent);
1452
	writeTag(fn, QString("<Version>\n"), indent);
1449
	indent++;
1453
	indent++;
1450
	writeTag (fn, QString("<VersionMajor>0</VersionMajor>\n"), indent);
1454
	writeTag(fn, QString("<VersionMajor>0</VersionMajor>\n"), indent);
1451
	writeTag (fn, QString("<VersionMinor>1</VersionMinor>\n"), indent);
1455
	writeTag(fn, QString("<VersionMinor>1</VersionMinor>\n"), indent);
1452
	writeTag (fn, QString("<BuildMajor>0</BuildMajor>\n"), indent);
1456
	writeTag(fn, QString("<BuildMajor>0</BuildMajor>\n"), indent);
1453
	writeTag (fn, QString("<BuildMinor>0</BuildMinor>\n"), indent);
1457
	writeTag(fn, QString("<BuildMinor>0</BuildMinor>\n"), indent);
1454
	indent--;
1458
	indent--;
1455
	writeTag (fn, QString("</Version>\n"), indent);
1459
	writeTag(fn, QString("</Version>\n"), indent);
1456
	writeTag (fn, QString("<Type>Beta</Type>\n"), indent);
1460
	writeTag(fn, QString("<Type>Beta</Type>\n"), indent);
1457
	writeTag (fn, QString("<Time>Jan 31 2008, 00:00:00</Time>\n"), indent);
1461
	writeTag(fn, QString("<Time>Jan 31 2008, 00:00:00</Time>\n"), indent);
1458
	writeTag (fn, QString("<Builder>theosys</Builder>\n"), indent);
1462
	writeTag(fn, QString("<Builder>theosys</Builder>\n"), indent);
1459
	indent--;
1463
	indent--;
1460
	writeTag (fn, QString("</Build>\n"), indent);
1464
	writeTag(fn, QString("</Build>\n"), indent);
1461
	writeTag (fn, QString("<LangID>EN</LangID>\n"), indent);
1465
	writeTag(fn, QString("<LangID>EN</LangID>\n"), indent);
1462
	writeTag (fn, QString("<PartNumber>000-00000-00</PartNumber>\n"), indent);
1466
	writeTag(fn, QString("<PartNumber>000-00000-00</PartNumber>\n"), indent);
1463
	indent--;
1467
	indent--;
1464
	writeTag (fn, QString("</Author>\n"), indent);
1468
	writeTag(fn, QString("</Author>\n"), indent);
1465
	writeTag (fn, QString("</TrainingCenterDatabase>\n"), indent);
1469
	writeTag(fn, QString("</TrainingCenterDatabase>\n"), indent);
1466
 
1470
 
1467
	fn.close();
1471
	fn.close();
1468
	KMessageBox::information(this, i18n("File ") + fname + i18n(" was written successfully."));
1472
	KMessageBox::information(this, i18n("File ") + fname + i18n(" was written successfully."));
1469
}
1473
}
1470
 
1474
 
Line 1473... Line 1477...
1473
	KMessageBox::information(this, i18n("This function is currently not implemented!"));
1477
	KMessageBox::information(this, i18n("This function is currently not implemented!"));
1474
}
1478
}
1475
 
1479
 
1476
void sportwatcherWidget::saveGPX(const QString &fn)
1480
void sportwatcherWidget::saveGPX(const QString &fn)
1477
{
1481
{
1478
QFile qf;
1482
	QFile qf;
1479
QString buffer;
1483
	QString buffer;
1480
RUN_NODE *rn, *rakt;
1484
	RUN_NODE *rn, *rakt;
1481
LAP *lap;
1485
	LAP *lap;
1482
POINT *point;
1486
	POINT *point;
1483
int indent;
1487
	int indent;
1484
unsigned int i;
1488
	unsigned int i;
1485
QDateTime *qt;
1489
	QDateTime *qt;
1486
double minLat, minLon, maxLat, maxLon;
1490
	double minLat, minLon, maxLat, maxLon;
1487
 
1491
 
1488
	indent = 0;
1492
	indent = 0;
1489
	rn = ds.getRunNode();
1493
	rn = ds.getRunNode();
1490
	lap = ds.getLap(rn->run->first_lap_index);
1494
	lap = ds.getLap(rn->run->first_lap_index);
1491
 
1495
 
1492
	if ((point = ds.getPoint(lap->start_time)) == 0)
1496
	if((point = ds.getPoint(lap->start_time)) == 0)
1493
	{
1497
	{
1494
	   KMessageBox::error(this, i18n("No data to save!"));
1498
		KMessageBox::error(this, i18n("No data to save!"));
1495
	   return;
1499
		return;
1496
	}
1500
	}
1497
 
1501
 
1498
	qf.setFileName(fn);
1502
	qf.setFileName(fn);
1499
 
1503
 
1500
	if (!qf.open(QIODevice::ReadWrite | QIODevice::Truncate))
1504
	if(!qf.open(QIODevice::ReadWrite | QIODevice::Truncate))
1501
	{
1505
	{
1502
	   KMessageBox::error(this, i18n("Error creating file %1!\nPlease check permissions").arg(fn));
1506
		KMessageBox::error(this, i18n("Error creating file %1!\nPlease check permissions").arg(fn));
1503
	   return;
1507
		return;
1504
	}
1508
	}
1505
 
1509
 
1506
	buffer = QString("<?xml version='1.0' encoding='UTF-8'?>\n");
1510
	buffer = QString("<?xml version='1.0' encoding='UTF-8'?>\n");
1507
	buffer.append("<gpx version=\"1.1\" creator=\"TheoSys SportWatcher\" xmlns=\"http://www.topografix.com/GPX/1/1\">\n");
1511
	buffer.append("<gpx version=\"1.1\" creator=\"TheoSys SportWatcher\" xmlns=\"http://www.topografix.com/GPX/1/1\">\n");
1508
	buffer.append("   <metadata>\n");
1512
	buffer.append("   <metadata>\n");
1509
	indent = 0;
1513
	indent = 0;
1510
	writeTag (qf, buffer, indent);
1514
	writeTag(qf, buffer, indent);
1511
 
1515
 
1512
	// Find the edges of our coordinates
1516
	// Find the edges of our coordinates
1513
	// We need this information in the header (metadata)
1517
	// We need this information in the header (metadata)
1514
	rakt = rn;
1518
	rakt = rn;
1515
	minLat = -90.0;
1519
	minLat = -90.0;
1516
	minLon = -180.0;
1520
	minLon = -180.0;
1517
	maxLat = 90.0;
1521
	maxLat = 90.0;
1518
	maxLon = 180.0;
1522
	maxLon = 180.0;
1519
 
1523
 
1520
	while (rakt)
1524
	while(rakt)
1521
	{
1525
	{
1522
	   if (rakt->run->type != data_D1000 && rakt->run->type != data_D1009 &&
1526
		if(rakt->run->type != data_D1000 && rakt->run->type != data_D1009 &&
1523
	   	rakt->run->type != data_D1010)
1527
		                  rakt->run->type != data_D1010)
1524
	   {
1528
		{
1525
	      rakt = rakt->next;
1529
			rakt = rakt->next;
1526
	      continue;
1530
			continue;
1527
	   }
1531
		}
1528
 
1532
 
1529
	   i = rakt->run->first_lap_index;
1533
		i = rakt->run->first_lap_index;
-
 
1534
 
1530
	   // get the first lap
1535
		// get the first lap
1531
	   if ((lap = ds.getLap(i)) == NULL)
1536
		if((lap = ds.getLap(i)) == NULL)
1532
	      continue;
1537
			continue;
1533
 
1538
 
1534
	   i = 0;
1539
		i = 0;
1535
	   // iterate the points associated with the laps
-
 
1536
	   while ((point = ds.getPoint(i)) != 0)
-
 
1537
	   {
-
 
1538
	      if (point->posn.lat == 0x7fffffff || point->posn.lon == 0x7fffffff)
-
 
1539
	      {
-
 
1540
		 i = point->time + 1;
-
 
1541
		 continue;
-
 
1542
	      }
-
 
1543
 
-
 
1544
	      if (SEMI2DEG(point->posn.lat) > minLat)
-
 
1545
		 minLat = SEMI2DEG(point->posn.lat);
-
 
1546
 
-
 
1547
	      if (SEMI2DEG(point->posn.lat) < maxLat)
-
 
1548
		 maxLat = SEMI2DEG(point->posn.lat);
-
 
1549
 
-
 
1550
	      if (SEMI2DEG(point->posn.lon) > minLon)
-
 
1551
		 minLon = SEMI2DEG(point->posn.lon);
-
 
1552
 
-
 
1553
	      if (SEMI2DEG(point->posn.lon) < maxLon)
-
 
1554
		 maxLon = SEMI2DEG(point->posn.lon);
-
 
1555
 
1540
 
-
 
1541
		// iterate the points associated with the laps
-
 
1542
		while((point = ds.getPoint(i)) != 0)
-
 
1543
		{
-
 
1544
			if(point->posn.lat == 0x7fffffff || point->posn.lon == 0x7fffffff)
-
 
1545
			{
1556
	      i = point->time + 1;
1546
				i = point->time + 1;
-
 
1547
				continue;
1557
	   }
1548
			}
1558
 
1549
 
-
 
1550
			if(SEMI2DEG(point->posn.lat) > minLat)
-
 
1551
				minLat = SEMI2DEG(point->posn.lat);
-
 
1552
 
-
 
1553
			if(SEMI2DEG(point->posn.lat) < maxLat)
-
 
1554
				maxLat = SEMI2DEG(point->posn.lat);
-
 
1555
 
-
 
1556
			if(SEMI2DEG(point->posn.lon) > minLon)
-
 
1557
				minLon = SEMI2DEG(point->posn.lon);
-
 
1558
 
-
 
1559
			if(SEMI2DEG(point->posn.lon) < maxLon)
-
 
1560
				maxLon = SEMI2DEG(point->posn.lon);
-
 
1561
 
-
 
1562
			i = point->time + 1;
-
 
1563
		}
-
 
1564
 
1559
	   rakt = rakt->next;
1565
		rakt = rakt->next;
1560
	}
1566
	}
1561
	
1567
 
1562
	buffer.sprintf("      <bounds minlat=\"%f\" minlon=\"%f\" maxlat=\"%f\" maxlon=\"%f\" />\n",
1568
	buffer.sprintf("      <bounds minlat=\"%f\" minlon=\"%f\" maxlat=\"%f\" maxlon=\"%f\" />\n",
1563
		maxLat, minLon, minLat, maxLon);
1569
	               maxLat, minLon, minLat, maxLon);
1564
	buffer.append("   </metadata>\n");
1570
	buffer.append("   </metadata>\n");
1565
	buffer.append("   <trk>\n");
1571
	buffer.append("   <trk>\n");
1566
	buffer.append("      <trkseg>\n");
1572
	buffer.append("      <trkseg>\n");
1567
	writeTag (qf, buffer, indent);
1573
	writeTag(qf, buffer, indent);
1568
	indent = 3;
1574
	indent = 3;
1569
	rn = ds.getRunNode();
1575
	rn = ds.getRunNode();
1570
	lap = ds.getLap(rn->run->first_lap_index);
1576
	lap = ds.getLap(rn->run->first_lap_index);
1571
	i = 0;
1577
	i = 0;
1572
 
1578
 
1573
	while ((point = ds.getPoint(i)) != 0)
1579
	while((point = ds.getPoint(i)) != 0)
1574
	{
1580
	{
1575
	   if (point->posn.lat == 0x7fffffff || point->posn.lon == 0x7fffffff)
1581
		if(point->posn.lat == 0x7fffffff || point->posn.lon == 0x7fffffff)
1576
	   {
1582
		{
1577
	      i = point->time + 1;
1583
			i = point->time + 1;
1578
	      continue;
1584
			continue;
1579
	   }
1585
		}
1580
 
1586
 
1581
	   buffer.sprintf("<trkpt lat=\"%f\" lon=\"%f\">\n",
1587
		buffer.sprintf("<trkpt lat=\"%f\" lon=\"%f\">\n",
1582
		SEMI2DEG(point->posn.lat), SEMI2DEG(point->posn.lon));
1588
		               SEMI2DEG(point->posn.lat), SEMI2DEG(point->posn.lon));
1583
	   writeTag(qf, buffer, indent);
1589
		writeTag(qf, buffer, indent);
1584
	   indent++;
1590
		indent++;
1585
	   buffer.sprintf("<ele>%f</ele>\n", point->alt);
1591
		buffer.sprintf("<ele>%f</ele>\n", point->alt);
1586
	   writeTag(qf, buffer, indent);
1592
		writeTag(qf, buffer, indent);
1587
	   qt = garmin_dtime(point->time);
1593
		qt = garmin_dtime(point->time);
1588
	   buffer = QString("<Time>%1</Time>\n").arg(qt->toString("yyyy-MM-ddThh:mm:ssZ"));
1594
		buffer = QString("<Time>%1</Time>\n").arg(qt->toString("yyyy-MM-ddThh:mm:ssZ"));
1589
	   writeTag(qf, buffer, indent);
1595
		writeTag(qf, buffer, indent);
1590
	   indent--;
1596
		indent--;
1591
	   writeTag(qf, QString("</trkpt>\n"), indent);
1597
		writeTag(qf, QString("</trkpt>\n"), indent);
1592
	   i = point->time + 1;
1598
		i = point->time + 1;
1593
	}
1599
	}
1594
 
1600
 
1595
	indent = 0;
1601
	indent = 0;
1596
	buffer = QString("      </trkseg>\n");
1602
	buffer = QString("      </trkseg>\n");
1597
	buffer.append("   </trk>\n");
1603
	buffer.append("   </trk>\n");
Line 1601... Line 1607...
1601
	KMessageBox::information(this, i18n("File ") + fn + i18n(" was written successfully."));
1607
	KMessageBox::information(this, i18n("File ") + fn + i18n(" was written successfully."));
1602
}
1608
}
1603
 
1609
 
1604
void sportwatcherWidget::saveOSM(const QString &fn)
1610
void sportwatcherWidget::saveOSM(const QString &fn)
1605
{
1611
{
1606
QFile qf;
1612
	QFile qf;
1607
QString buffer;
1613
	QString buffer;
1608
RUN_NODE *rn, *rakt;
1614
	RUN_NODE *rn, *rakt;
1609
LAP *lap;
1615
	LAP *lap;
1610
POINT *point;
1616
	POINT *point;
1611
int indent, id, j;
1617
	int indent, id, j;
1612
unsigned int i;
1618
	unsigned int i;
1613
double minLat, minLon, maxLat, maxLon;
1619
	double minLat, minLon, maxLat, maxLon;
1614
QDateTime *qt;
1620
	QDateTime *qt;
1615
 
1621
 
1616
	indent = 0;
1622
	indent = 0;
1617
	rn = ds.getRunNode();
1623
	rn = ds.getRunNode();
1618
	lap = ds.getLap(rn->run->first_lap_index);
1624
	lap = ds.getLap(rn->run->first_lap_index);
1619
 
1625
 
1620
	if ((point = ds.getPoint(lap->start_time)) == 0)
1626
	if((point = ds.getPoint(lap->start_time)) == 0)
1621
	{
1627
	{
1622
	   KMessageBox::error(this, i18n("No data to save!"));
1628
		KMessageBox::error(this, i18n("No data to save!"));
1623
	   return;
1629
		return;
1624
	}
1630
	}
1625
 
1631
 
1626
	qf.setFileName(fn);
1632
	qf.setFileName(fn);
1627
 
1633
 
1628
	if (!qf.open(QIODevice::ReadWrite | QIODevice::Truncate))
1634
	if(!qf.open(QIODevice::ReadWrite | QIODevice::Truncate))
1629
	{
1635
	{
1630
	   KMessageBox::error(this, i18n("Error creating file %1!\nPlease check permissions").arg(fn));
1636
		KMessageBox::error(this, i18n("Error creating file %1!\nPlease check permissions").arg(fn));
1631
	   return;
1637
		return;
1632
	}
1638
	}
1633
 
1639
 
1634
	buffer = QString("<?xml version='1.0' encoding='UTF-8'?>\n");
1640
	buffer = QString("<?xml version='1.0' encoding='UTF-8'?>\n");
1635
	buffer.append("<osm version=\"0.5\" generator=\"TheoSys SportWatcher\">\n");
1641
	buffer.append("<osm version=\"0.5\" generator=\"TheoSys SportWatcher\">\n");
1636
	indent = 0;
1642
	indent = 0;
1637
	writeTag (qf, buffer, indent);
1643
	writeTag(qf, buffer, indent);
1638
	// Find the edges of our coordinates
1644
	// Find the edges of our coordinates
1639
	// We need this information in the header (metadata)
1645
	// We need this information in the header (metadata)
1640
	rakt = rn;
1646
	rakt = rn;
1641
	minLat = -90.0;
1647
	minLat = -90.0;
1642
	minLon = -180.0;
1648
	minLon = -180.0;
1643
	maxLat = 90.0;
1649
	maxLat = 90.0;
1644
	maxLon = 180.0;
1650
	maxLon = 180.0;
1645
 
1651
 
1646
	while (rakt)
1652
	while(rakt)
1647
	{
1653
	{
1648
	   if (rakt->run->type != data_D1000 && rakt->run->type != data_D1009 &&
1654
		if(rakt->run->type != data_D1000 && rakt->run->type != data_D1009 &&
1649
	   	rakt->run->type != data_D1010)
1655
		                  rakt->run->type != data_D1010)
1650
	   {
1656
		{
1651
	      rakt = rakt->next;
1657
			rakt = rakt->next;
1652
	      continue;
1658
			continue;
1653
	   }
1659
		}
1654
 
1660
 
1655
	   i = rakt->run->first_lap_index;
1661
		i = rakt->run->first_lap_index;
1656
	   // get the first lap
-
 
1657
	   if ((lap = ds.getLap(i)) == NULL)
-
 
1658
	      continue;
-
 
1659
 
1662
 
1660
	   i = 0;
-
 
1661
	   // iterate the points associated with the laps
1663
		// get the first lap
1662
	   while ((point = ds.getPoint(i)) != 0)
1664
		if((lap = ds.getLap(i)) == NULL)
1663
	   {
-
 
1664
	      if (point->posn.lat == 0x7fffffff || point->posn.lon == 0x7fffffff)
-
 
1665
	      {
-
 
1666
		 i = point->time + 1;
-
 
1667
		 continue;
1665
			continue;
1668
	      }
-
 
1669
 
-
 
1670
	      if (SEMI2DEG(point->posn.lat) > minLat)
-
 
1671
		 minLat = SEMI2DEG(point->posn.lat);
-
 
1672
 
-
 
1673
	      if (SEMI2DEG(point->posn.lat) < maxLat)
-
 
1674
		 maxLat = SEMI2DEG(point->posn.lat);
-
 
1675
 
-
 
1676
	      if (SEMI2DEG(point->posn.lon) > minLon)
-
 
1677
		 minLon = SEMI2DEG(point->posn.lon);
-
 
1678
 
-
 
1679
	      if (SEMI2DEG(point->posn.lon) < maxLon)
-
 
1680
		 maxLon = SEMI2DEG(point->posn.lon);
-
 
1681
 
1666
 
1682
	      i = point->time + 1;
-
 
1683
	   }
1667
		i = 0;
1684
 
1668
 
-
 
1669
		// iterate the points associated with the laps
-
 
1670
		while((point = ds.getPoint(i)) != 0)
-
 
1671
		{
-
 
1672
			if(point->posn.lat == 0x7fffffff || point->posn.lon == 0x7fffffff)
-
 
1673
			{
-
 
1674
				i = point->time + 1;
-
 
1675
				continue;
-
 
1676
			}
-
 
1677
 
-
 
1678
			if(SEMI2DEG(point->posn.lat) > minLat)
-
 
1679
				minLat = SEMI2DEG(point->posn.lat);
-
 
1680
 
-
 
1681
			if(SEMI2DEG(point->posn.lat) < maxLat)
-
 
1682
				maxLat = SEMI2DEG(point->posn.lat);
-
 
1683
 
-
 
1684
			if(SEMI2DEG(point->posn.lon) > minLon)
-
 
1685
				minLon = SEMI2DEG(point->posn.lon);
-
 
1686
 
-
 
1687
			if(SEMI2DEG(point->posn.lon) < maxLon)
-
 
1688
				maxLon = SEMI2DEG(point->posn.lon);
-
 
1689
 
-
 
1690
			i = point->time + 1;
-
 
1691
		}
-
 
1692
 
1685
	   rakt = rakt->next;
1693
		rakt = rakt->next;
1686
	}
1694
	}
1687
	
1695
 
1688
	buffer.sprintf("   <bound box='%f,%f,%f,%f' origin='http://www.openstreetmap.org/api/0.5' />\n",
1696
	buffer.sprintf("   <bound box='%f,%f,%f,%f' origin='http://www.openstreetmap.org/api/0.5' />\n",
1689
		maxLat, minLon, minLat, maxLon);
1697
	               maxLat, minLon, minLat, maxLon);
1690
	writeTag (qf, buffer, indent);
1698
	writeTag(qf, buffer, indent);
1691
	indent = 1;
1699
	indent = 1;
1692
	rn = ds.getRunNode();
1700
	rn = ds.getRunNode();
1693
	lap = ds.getLap(rn->run->first_lap_index);
1701
	lap = ds.getLap(rn->run->first_lap_index);
1694
	i = 0;
1702
	i = 0;
1695
	id = -1;
1703
	id = -1;
1696
 
1704
 
1697
	while ((point = ds.getPoint(i)) != 0)
1705
	while((point = ds.getPoint(i)) != 0)
1698
	{
1706
	{
1699
	   if (point->posn.lat == 0x7fffffff || point->posn.lon == 0x7fffffff)
1707
		if(point->posn.lat == 0x7fffffff || point->posn.lon == 0x7fffffff)
1700
	   {
1708
		{
1701
	      i = point->time + 1;
1709
			i = point->time + 1;
1702
	      continue;
1710
			continue;
1703
	   }
1711
		}
1704
 
1712
 
1705
	   buffer.sprintf("<node id='%d' action='modify' visible='true' lat=\"%f\" lon=\"%f\">\n",
1713
		buffer.sprintf("<node id='%d' action='modify' visible='true' lat=\"%f\" lon=\"%f\">\n",
1706
		id, SEMI2DEG(point->posn.lat), SEMI2DEG(point->posn.lon));
1714
		               id, SEMI2DEG(point->posn.lat), SEMI2DEG(point->posn.lon));
1707
	   writeTag(qf, buffer, indent);
1715
		writeTag(qf, buffer, indent);
1708
	   indent++;
1716
		indent++;
1709
	   buffer = QString("<tag k='created_by' v='TheoSys Sportwatcher' />\n");
1717
		buffer = QString("<tag k='created_by' v='TheoSys Sportwatcher' />\n");
1710
	   writeTag(qf, buffer, indent);
1718
		writeTag(qf, buffer, indent);
1711
	   buffer = QString("<tag k='highway' v='tertiary' />\n");
1719
		buffer = QString("<tag k='highway' v='tertiary' />\n");
1712
	   writeTag(qf, buffer, indent);
1720
		writeTag(qf, buffer, indent);
1713
	   indent--;
1721
		indent--;
1714
	   writeTag(qf, QString("</node>\n"), indent);
1722
		writeTag(qf, QString("</node>\n"), indent);
1715
	   id--;
1723
		id--;
1716
	   i = point->time + 1;
1724
		i = point->time + 1;
1717
	}
1725
	}
1718
 
1726
 
1719
	qt = garmin_dtime(lap->start_time);
1727
	qt = garmin_dtime(lap->start_time);
1720
	buffer.sprintf("<way id='%d' action='modify' visible='true' timestamp='%s'>\n",
1728
	buffer.sprintf("<way id='%d' action='modify' visible='true' timestamp='%s'>\n",
1721
		id, QString(qt->toString("yyyy-MM-ddThh:mm:ssZ")).toAscii().data());
1729
	               id, QString(qt->toString("yyyy-MM-ddThh:mm:ssZ")).toAscii().data());
1722
	writeTag(qf, buffer, indent);
1730
	writeTag(qf, buffer, indent);
1723
	indent++;
1731
	indent++;
1724
 
1732
 
1725
	for (j = -1; j > id; j--)
1733
	for(j = -1; j > id; j--)
1726
	{
1734
	{
1727
	   buffer.sprintf("<nd ref='%d' />\n", j);
1735
		buffer.sprintf("<nd ref='%d' />\n", j);
1728
	   writeTag(qf, buffer, indent);
1736
		writeTag(qf, buffer, indent);
1729
	}
1737
	}
1730
 
1738
 
1731
	indent--;
1739
	indent--;
1732
	writeTag(qf, QString("</way>\n"), indent);
1740
	writeTag(qf, QString("</way>\n"), indent);
1733
	indent = 0;
1741
	indent = 0;
Line 1736... Line 1744...
1736
	KMessageBox::information(this, i18n("File %1 was written successfully.").arg(fn));
1744
	KMessageBox::information(this, i18n("File %1 was written successfully.").arg(fn));
1737
}
1745
}
1738
 
1746
 
1739
void sportwatcherWidget::fileOpen()
1747
void sportwatcherWidget::fileOpen()
1740
{
1748
{
1741
QString fname = KFileDialog::getOpenFileName(Data, QString("*.gmn"), this, QString("SportWatcher"));
1749
	QString fname = KFileDialog::getOpenFileName(Data, QString("*.gmn"), this, QString("SportWatcher"));
1742
int m;
1750
	int m;
1743
 
1751
 
1744
        if (fname.isEmpty())
1752
	if(fname.isEmpty())
1745
           return;
1753
		return;
1746
 
1754
 
1747
	spw.destroy();
1755
	spw.destroy();
1748
 
1756
 
1749
        if (spw.setFileName(fname.toAscii().data()) == -1)
1757
	if(spw.setFileName(fname.toAscii().data()) == -1)
1750
	   return;
1758
		return;
1751
 
1759
 
1752
	if (gmn)
1760
	if(gmn)
1753
	   garmin_free_data (gmn);
1761
		garmin_free_data(gmn);
1754
 
1762
 
1755
	gmn = spw.readFile();
1763
	gmn = spw.readFile();
1756
	zfactor = 0;
1764
	zfactor = 0;
1757
 
1765
 
1758
	if ((m = garmin_count_error()) > 0)
1766
	if((m = garmin_count_error()) > 0)
1759
	{
1767
	{
1760
	int i, key = -1;
1768
		int i, key = -1;
1761
 
1769
 
1762
	   for (i = 0; i < m; i++)
1770
		for(i = 0; i < m; i++)
1763
	      KMessageBox::error(this, QString(garmin_get_next_error(&key)));
1771
			KMessageBox::error(this, QString(garmin_get_next_error(&key)));
1764
 
1772
 
1765
	   garmin_clear_errors();
1773
		garmin_clear_errors();
1766
	   return;
1774
		return;
1767
	}
1775
	}
1768
 
1776
 
1769
	DIRTY = true;
1777
	DIRTY = true;
1770
	tabDirt0 = tabDirt1 = tabDirt2 = tabDirt3 = true;
1778
	tabDirt0 = tabDirt1 = tabDirt2 = tabDirt3 = true;
1771
	showLaps();
1779
	showLaps();
1772
	showTrack();
1780
	showTrack();
1773
	showCurves();
1781
	showCurves();
1774
 
1782
 
1775
	if (curTab == 2)
1783
	if(curTab == 2)
1776
	{
1784
	{
1777
	   showThreeCurve();
1785
		showThreeCurve();
1778
	   tabDirt2 = false;
1786
		tabDirt2 = false;
1779
	}
1787
	}
1780
 
1788
 
1781
	tabDirt0 = tabDirt3 = false;
1789
	tabDirt0 = tabDirt3 = false;
1782
	DIRTY = false;
1790
	DIRTY = false;
1783
}
1791
}
1784
 
1792
 
-
 
1793
/**
-
 
1794
 * This function is called from the XML parser in "gmn_import"
-
 
1795
 * whenever an activity is complete.
-
 
1796
 * Necessary because there may be more than one activity in a history
-
 
1797
 * file.
-
 
1798
 */
-
 
1799
void sportwatcherWidget::saveImported(void *gd)
-
 
1800
{
-
 
1801
gmn_import import;
-
 
1802
QString tgfile, fld, px;
-
 
1803
RUN_NODE *rn;
-
 
1804
LAP *lap;
-
 
1805
garmin_data *g = (garmin_data *)gd;
-
 
1806
QFileInfo datei;
-
 
1807
QPixmap qpx;
-
 
1808
QList<QTreeWidgetItem *>item;
-
 
1809
QTreeWidgetItem *el, *it;
-
 
1810
 
-
 
1811
	if(!g)
-
 
1812
	{
-
 
1813
		std::cerr << "sportwatcherWidget::saveImported: Empty data! Nothing was saved!" << std::endl;
-
 
1814
		return;
-
 
1815
	}
-
 
1816
 
-
 
1817
	// Find the filename;
-
 
1818
	// It consists of the date and the time.
-
 
1819
	// We need this information to set the correct path to store the file.
-
 
1820
	tgfile = Data;		// The base path
-
 
1821
	rn = ds.getRunNode();
-
 
1822
	lap = ds.getLap(rn->run->first_lap_index);
-
 
1823
	QDateTime *qt = garmin_dtime(lap->start_time);
-
 
1824
	tgfile.append(qt->toString("/yyyy"));   // year is a folder
-
 
1825
	tgfile.append(qt->toString("/MM"));	// month is a folder
-
 
1826
	tgfile.append(qt->toString("/yyyyMMddThhmmss"));	// The file name
-
 
1827
	tgfile.append(".gmn");		// Extension of file name
-
 
1828
	datei.setFile(tgfile);
-
 
1829
std:cerr << "sportwatcherWidget::saveImported:Saving to file " << datei.absoluteFilePath().toAscii().data() << std::endl;
-
 
1830
	// save the data to a real file, but only if it doesn't exist allready.
-
 
1831
	garmin_save_all(g, datei.fileName().toAscii().data(), datei.absolutePath().toAscii().data(), 0);
-
 
1832
 
-
 
1833
	// in case the item is already in the list on the left side, we
-
 
1834
	// only highlight the item.
-
 
1835
	item = ui_sportwatcherWidgetBase.liActivities->findItems(tgfile, Qt::MatchExactly);
-
 
1836
 
-
 
1837
	if(item.size() > 0)
-
 
1838
	{
-
 
1839
		ui_sportwatcherWidgetBase.liActivities->setItemSelected(item.at(0), true);
-
 
1840
		ui_sportwatcherWidgetBase.liActivities->setCurrentItem(item.at(0));
-
 
1841
		return;
-
 
1842
	}
-
 
1843
 
-
 
1844
	// insert everything into the list on the left side
-
 
1845
	switch(rn->run->sport_type)
-
 
1846
	{
-
 
1847
		case D1000_running:
-
 
1848
			fld = i18n("Running");
-
 
1849
			px = QString("spw-running");
-
 
1850
		break;
-
 
1851
 
-
 
1852
		case D1000_biking:
-
 
1853
			fld = i18n("Biking");
-
 
1854
			px = QString("bike");
-
 
1855
		break;
-
 
1856
 
-
 
1857
		default:
-
 
1858
			fld = i18n("Others");
-
 
1859
			px = QString("other");
-
 
1860
	}
-
 
1861
 
-
 
1862
	// Do we have allready so items in the list?
-
 
1863
	item = ui_sportwatcherWidgetBase.liActivities->findItems(fld, Qt::MatchExactly);
-
 
1864
 
-
 
1865
	if(item.size() > 0)
-
 
1866
	{
-
 
1867
		el = new QTreeWidgetItem(item.at(0));
-
 
1868
		el->setText(0, kl->formatDateTime(*qt, KLocale::ShortDate, true));
-
 
1869
		el->setData(0, Qt::UserRole, tgfile);
-
 
1870
		el->setIcon(0, KIcon(px));
-
 
1871
	}
-
 
1872
	else	// no, this is the first item. (shouldn't be!)
-
 
1873
	{
-
 
1874
		it = new QTreeWidgetItem(ui_sportwatcherWidgetBase.liActivities);
-
 
1875
		it->setText(0, fld);
-
 
1876
		it->setIcon(0, KIcon(QString("history")));
-
 
1877
 
-
 
1878
		el = new QTreeWidgetItem(item.at(0));
-
 
1879
		el->setText(0, kl->formatDateTime(*qt, KLocale::ShortDate, true));
-
 
1880
		el->setData(0, Qt::UserRole, tgfile);
-
 
1881
		el->setIcon(0, KIcon(px));
-
 
1882
	}
-
 
1883
}
-
 
1884
 
1785
void sportwatcherWidget::fileImport()
1885
void sportwatcherWidget::fileImport()
1786
{
1886
{
1787
QString fname = KFileDialog::getOpenFileName(QString("~/"), QString("*.tcx"), this, QString("SportWatcher"));
1887
QString fname = KFileDialog::getOpenFileName(QString("~/"), QString("*.tcx"), this, QString("SportWatcher"));
1788
gmn_import import;
1888
gmn_import import;
1789
int m;
1889
int m;
Line 1793... Line 1893...
1793
QList<QTreeWidgetItem *>item;
1893
QList<QTreeWidgetItem *>item;
1794
QTreeWidgetItem *el, *it;
1894
QTreeWidgetItem *el, *it;
1795
LAP *lap;
1895
LAP *lap;
1796
RUN_NODE *rn;
1896
RUN_NODE *rn;
1797
 
1897
 
1798
        if (fname.isEmpty())
1898
	if(fname.isEmpty())
1799
           return;
1899
		return;
1800
 
1900
 
-
 
1901
	import.connectCallback(this);
1801
        import.setFile(fname);
1902
	import.setFile(fname);
1802
 
1903
 
1803
	if ((m = import.import()) != 0)
1904
	if((m = import.import()) != 0)
1804
	{
1905
	{
1805
	   KMessageBox::error(this, QString(import.getError(m)));
1906
		KMessageBox::error(this, QString(import.getError(m)));
1806
	   return;
1907
		return;
1807
	}
1908
	}
1808
 
1909
 
1809
	if (gmn)
1910
	if(gmn)
1810
	{
1911
	{
1811
	   garmin_free_data (gmn);
1912
		garmin_free_data(gmn);
1812
	   gmn = 0;
1913
		gmn = 0;
1813
	}
1914
	}
1814
 
1915
 
1815
	if (!(gmn = import.getGarminData ()))
1916
	if(!(gmn = import.getGarminData()))
1816
	   return;
1917
		return;
1817
 
1918
 
1818
	DIRTY = true;
1919
	DIRTY = true;
1819
	tabDirt0 = tabDirt1 = tabDirt2 = tabDirt3 = true;
1920
	tabDirt0 = tabDirt1 = tabDirt2 = tabDirt3 = true;
1820
	showLaps();
1921
	showLaps();
1821
	showTrack();
1922
	showTrack();
1822
	showCurves();
1923
	showCurves();
1823
 
1924
 
1824
	if (curTab == 2)
1925
	if(curTab == 2)
1825
	{
1926
	{
1826
	   showThreeCurve();
1927
		showThreeCurve();
1827
	   tabDirt2 = false;
1928
		tabDirt2 = false;
1828
	}
1929
	}
1829
 
1930
 
1830
	tabDirt0 = tabDirt3 = false;
1931
	tabDirt0 = tabDirt3 = false;
1831
	DIRTY = false;
1932
	DIRTY = false;
1832
 
1933
 
Line 1834... Line 1935...
1834
	// It consists of the date and the time.
1935
	// It consists of the date and the time.
1835
	// We need this information to set the correct path to store the file.
1936
	// We need this information to set the correct path to store the file.
1836
	tgfile = Data;		// The base path
1937
	tgfile = Data;		// The base path
1837
	rn = ds.getRunNode();
1938
	rn = ds.getRunNode();
1838
	lap = ds.getLap(rn->run->first_lap_index);
1939
	lap = ds.getLap(rn->run->first_lap_index);
1839
	QDateTime *qt = garmin_dtime (lap->start_time);
1940
	QDateTime *qt = garmin_dtime(lap->start_time);
1840
	tgfile.append (qt->toString ("/yyyy")); // year is a folder
1941
	tgfile.append(qt->toString("/yyyy"));   // year is a folder
1841
	tgfile.append (qt->toString ("/MM"));	// month is a folder
1942
	tgfile.append(qt->toString("/MM"));	// month is a folder
1842
	tgfile.append (qt->toString ("/yyyyMMddThhmmss"));	// The file name
1943
	tgfile.append(qt->toString("/yyyyMMddThhmmss"));	// The file name
1843
	tgfile.append (".gmn");		// Extension of file name
1944
	tgfile.append(".gmn");		// Extension of file name
1844
	datei.setFile (tgfile);
1945
	datei.setFile(tgfile);
-
 
1946
	std:cerr << "sportwatcherWidget::fileImport:Saving to file " << datei.absoluteFilePath().toAscii().data() << std::endl;
1845
	// save the data to a real file, but only if it doesn't exist allready.
1947
	// save the data to a real file, but only if it doesn't exist allready.
1846
	garmin_save_all (gmn, datei.fileName().toAscii().data(), datei.absolutePath().toAscii().data(), 0);
1948
	garmin_save_all(gmn, datei.fileName().toAscii().data(), datei.absolutePath().toAscii().data(), 0);
1847
 
1949
 
1848
	// in case the item is already in the list on the left side, we
1950
	// in case the item is already in the list on the left side, we
1849
	// only highlight the item.
1951
	// only highlight the item.
1850
	item = ui_sportwatcherWidgetBase.liActivities->findItems (tgfile, Qt::MatchExactly);
1952
	item = ui_sportwatcherWidgetBase.liActivities->findItems(tgfile, Qt::MatchExactly);
1851
 
1953
 
1852
	if (item.size() > 0)
1954
	if(item.size() > 0)
1853
	{
1955
	{
1854
	   ui_sportwatcherWidgetBase.liActivities->setItemSelected (item.at(0), true);
1956
		ui_sportwatcherWidgetBase.liActivities->setItemSelected(item.at(0), true);
1855
	   ui_sportwatcherWidgetBase.liActivities->setCurrentItem (item.at(0));
1957
		ui_sportwatcherWidgetBase.liActivities->setCurrentItem(item.at(0));
1856
	   return;
1958
		return;
1857
	}
1959
	}
1858
 
1960
 
1859
	// insert everything into the list on the left side
1961
	// insert everything into the list on the left side
1860
	switch (rn->run->sport_type)
1962
	switch(rn->run->sport_type)
1861
	{
1963
	{
1862
	   case D1000_running:
1964
		case D1000_running:
1863
	      fld = i18n("Running");
1965
			fld = i18n("Running");
1864
	      px = QString("spw-running");
1966
			px = QString("spw-running");
1865
	   break;
1967
		break;
1866
 
1968
 
1867
	   case D1000_biking:
1969
		case D1000_biking:
1868
	      fld = i18n("Biking");
1970
			fld = i18n("Biking");
1869
	      px = QString("bike");
1971
			px = QString("bike");
1870
	   break;
1972
		break;
1871
 
1973
 
1872
	   default:
1974
		default:
1873
	      fld = i18n("Others");
1975
			fld = i18n("Others");
1874
	      px = QString("other");
1976
			px = QString("other");
1875
	}
1977
	}
1876
 
1978
 
1877
	// Do we have allready so items in the list?
1979
	// Do we have allready so items in the list?
1878
	item = ui_sportwatcherWidgetBase.liActivities->findItems (fld, Qt::MatchExactly);
1980
	item = ui_sportwatcherWidgetBase.liActivities->findItems(fld, Qt::MatchExactly);
1879
 
1981
 
1880
	if (item.size() > 0)
1982
	if(item.size() > 0)
1881
	{
1983
	{
1882
	   el = new QTreeWidgetItem(item.at(0));
1984
		el = new QTreeWidgetItem(item.at(0));
1883
	   el->setText(0, kl->formatDateTime(*qt, KLocale::ShortDate, true));
1985
		el->setText(0, kl->formatDateTime(*qt, KLocale::ShortDate, true));
1884
	   el->setData(0, Qt::UserRole, tgfile);
1986
		el->setData(0, Qt::UserRole, tgfile);
1885
	   el->setIcon(0, KIcon(px));
1987
		el->setIcon(0, KIcon(px));
1886
	}
1988
	}
1887
	else	// no, this is the first item. (shouldn't be!)
1989
	else	// no, this is the first item. (shouldn't be!)
1888
	{
1990
	{
1889
	   it = new QTreeWidgetItem(ui_sportwatcherWidgetBase.liActivities);
1991
		it = new QTreeWidgetItem(ui_sportwatcherWidgetBase.liActivities);
1890
	   it->setText(0, fld);
1992
		it->setText(0, fld);
1891
	   it->setIcon(0, KIcon(QString("history")));
1993
		it->setIcon(0, KIcon(QString("history")));
1892
 
1994
 
1893
	   el = new QTreeWidgetItem(item.at(0));
1995
		el = new QTreeWidgetItem(item.at(0));
1894
	   el->setText(0, kl->formatDateTime(*qt, KLocale::ShortDate, true));
1996
		el->setText(0, kl->formatDateTime(*qt, KLocale::ShortDate, true));
1895
	   el->setData(0, Qt::UserRole, tgfile);
1997
		el->setData(0, Qt::UserRole, tgfile);
1896
	   el->setIcon(0, KIcon(px));
1998
		el->setIcon(0, KIcon(px));
1897
	}
1999
	}
1898
}
2000
}
1899
 
2001
 
1900
/*
2002
/*
1901
 * Display a small dialog to rename the currently loaded session.
2003
 * Display a small dialog to rename the currently loaded session.
1902
 */
2004
 */
1903
void sportwatcherWidget::editRename()
2005
void sportwatcherWidget::editRename()
1904
{
2006
{
1905
bool ok;
2007
	bool ok;
1906
QString name, inhalt;
2008
	QString name, inhalt;
1907
QList<QTreeWidgetItem *> item;
2009
	QList<QTreeWidgetItem *> item;
1908
QTreeWidgetItem *lvItem;
2010
	QTreeWidgetItem *lvItem;
1909
QFileInfo datei;
2011
	QFileInfo datei;
1910
RUN_NODE *rn;
2012
	RUN_NODE *rn;
1911
LAP *lap;
2013
	LAP *lap;
1912
garmin_list *list;
2014
	garmin_list *list;
1913
D1009 *n;
2015
	D1009 *n;
1914
 
2016
 
1915
	if (!gmn)
2017
	if(!gmn)
1916
	{
2018
	{
1917
	   KMessageBox::error(this, i18n("There is no session selected!"));
2019
		KMessageBox::error(this, i18n("There is no session selected!"));
1918
	   return;
2020
		return;
1919
	}
2021
	}
1920
	
2022
 
1921
	rn = ds.getRunNode();
2023
	rn = ds.getRunNode();
1922
	item = ui_sportwatcherWidgetBase.liActivities->selectedItems ();
2024
	item = ui_sportwatcherWidgetBase.liActivities->selectedItems();
1923
	lvItem = item.first();
2025
	lvItem = item.first();
1924
 
2026
 
1925
	if (!isdigit(rn->run->workout.name[0]))
2027
	if(!isdigit(rn->run->workout.name[0]))
1926
	   inhalt = lvItem->text(0);
2028
		inhalt = lvItem->text(0);
1927
	else
2029
	else
1928
	   inhalt.clear();
2030
		inhalt.clear();
1929
 
2031
 
1930
	name = KInputDialog::getText(i18n("Rename session"), i18n("Session name"),
2032
	name = KInputDialog::getText(i18n("Rename session"), i18n("Session name"),
1931
		inhalt, &ok, this, (QValidator *)0, QString("Nxxxxxxxxxxxxxx"),
2033
	                             inhalt, &ok, this, (QValidator *)0, QString("Nxxxxxxxxxxxxxx"),
1932
		i18n("Enter a new name for the currently selected activity."));
2034
	                             i18n("Enter a new name for the currently selected activity."));
1933
 
2035
 
1934
	if (!ok)
2036
	if(!ok)
1935
	   return;
2037
		return;
1936
 
2038
 
1937
	if (name.length() <= 1)
2039
	if(name.length() <= 1)
1938
	{
2040
	{
1939
	   lap = ds.getLap(rn->run->first_lap_index);
2041
		lap = ds.getLap(rn->run->first_lap_index);
1940
	   const QDateTime *qt = garmin_dtime (lap->start_time);
2042
		const QDateTime *qt = garmin_dtime(lap->start_time);
1941
	   QString idx = kl->formatDateTime(*qt, KLocale::ShortDate, true);
2043
		QString idx = kl->formatDateTime(*qt, KLocale::ShortDate, true);
1942
	   lvItem->setText (0, idx);
2044
		lvItem->setText(0, idx);
1943
	   datei.setFile (lvItem->data(0, Qt::UserRole).toString());
2045
		datei.setFile(lvItem->data(0, Qt::UserRole).toString());
1944
	   garmin_save_all (gmn, datei.fileName().toAscii().data(), datei.absolutePath().toAscii().data(), 1);
2046
		garmin_save_all(gmn, datei.fileName().toAscii().data(), datei.absolutePath().toAscii().data(), 1);
1945
	   delete qt;
2047
		delete qt;
1946
	   return;
2048
		return;
1947
	}
2049
	}
1948
 
2050
 
1949
	strncpy (rn->run->workout.name, name.toAscii().data(), 16);
2051
	strncpy(rn->run->workout.name, name.toAscii().data(), 16);
1950
 
2052
 
1951
	if (gmn->type != data_Dlist)
2053
	if(gmn->type != data_Dlist)
1952
	{
2054
	{
1953
	   KMessageBox::error(this, i18n("editRename: Unexpected structure type %1 found!").arg(gmn->type));
2055
		KMessageBox::error(this, i18n("editRename: Unexpected structure type %1 found!").arg(gmn->type));
1954
	   return;
2056
		return;
1955
	}
2057
	}
1956
 
2058
 
1957
	list = (garmin_list *)gmn->data;
2059
	list = (garmin_list *)gmn->data;
1958
 
2060
 
1959
	if (list->head->data->type != data_D1009)	// This should be the run node
2061
	if(list->head->data->type != data_D1009)	// This should be the run node
1960
	{
2062
	{
1961
	   KMessageBox::error(this, i18n("editRename: The run node was not found!"));
2063
		KMessageBox::error(this, i18n("editRename: The run node was not found!"));
1962
	   return;
2064
		return;
1963
	}
2065
	}
1964
 
2066
 
1965
	n = (D1009 *)list->head->data->data;
2067
	n = (D1009 *)list->head->data->data;
1966
	strncpy (n->workout.name, rn->run->workout.name, 15);
2068
	strncpy(n->workout.name, rn->run->workout.name, 15);
1967
	lvItem->setText (0, name);
2069
	lvItem->setText(0, name);
1968
	datei.setFile (lvItem->data(0, Qt::UserRole).toString());
2070
	datei.setFile(lvItem->data(0, Qt::UserRole).toString());
1969
	garmin_save_all (gmn, datei.fileName().toAscii().data(), datei.absolutePath().toAscii().data(), 1);
2071
	garmin_save_all(gmn, datei.fileName().toAscii().data(), datei.absolutePath().toAscii().data(), 1);
1970
}
2072
}
1971
 
2073
 
1972
void sportwatcherWidget::fileNew()
2074
void sportwatcherWidget::fileNew()
1973
{
2075
{
1974
progressWidget *dlg = new progressWidget(this);
2076
	progressWidget *dlg = new progressWidget(this);
1975
 
2077
 
1976
	dlg->show();
2078
	dlg->show();
1977
 
2079
 
1978
	if (!dlg->Download())
2080
	if(!dlg->Download())
1979
	{
2081
	{
1980
	int m, key;
2082
		int m, key;
1981
 
2083
 
1982
	   key = -1;
2084
		key = -1;
1983
 
2085
 
1984
	   for (m = 0; m < garmin_count_error(); m++)
2086
		for(m = 0; m < garmin_count_error(); m++)
1985
	      KMessageBox::error(this, QString(garmin_get_next_error(&key)));
2087
			KMessageBox::error(this, QString(garmin_get_next_error(&key)));
1986
	}
2088
	}
1987
	else
2089
	else
1988
	   getActivities();
2090
		getActivities();
1989
 
2091
 
1990
	garmin_clear_errors();
2092
	garmin_clear_errors();
1991
	delete dlg;
2093
	delete dlg;
1992
}
2094
}
1993
 
2095
 
Line 2001... Line 2103...
2001
 * heart rate data. I've choosen this format, because it's popular and
2103
 * heart rate data. I've choosen this format, because it's popular and
2002
 * used by many other software too.
2104
 * used by many other software too.
2003
 */
2105
 */
2004
void sportwatcherWidget::extrasSaveHR()
2106
void sportwatcherWidget::extrasSaveHR()
2005
{
2107
{
2006
QString fname, str1, str2;
2108
	QString fname, str1, str2;
2007
QFile fdfile;
2109
	QFile fdfile;
2008
QDateTime *qt, *oldqt;
2110
	QDateTime *qt, *oldqt;
2009
QDate dat;
2111
	QDate dat;
2010
QTime t;
2112
	QTime t;
2011
QDir dir = QDir::home();
2113
	QDir dir = QDir::home();
2012
char hv0[256];
2114
	char hv0[256];
2013
RUN_NODE *rn;
2115
	RUN_NODE *rn;
2014
LAP *lap, *alap;
2116
	LAP *lap, *alap;
2015
POINT *point;
2117
	POINT *point;
2016
int samples, smp, seconds, anz, nsec, samsec;
2118
	int samples, smp, seconds, anz, nsec, samsec;
2017
int avgHeart, minHeart, maxHeart, aktHeart;
2119
	int avgHeart, minHeart, maxHeart, aktHeart;
2018
int secRange1, secRange2, secRange3, secAbove, secBeyond;
2120
	int secRange1, secRange2, secRange3, secAbove, secBeyond;
2019
 
2121
 
2020
	if (!gmn)
2122
	if(!gmn)
2021
	{
2123
	{
2022
	   KMessageBox::information(this, i18n("There is no activity open"));
2124
		KMessageBox::information(this, i18n("There is no activity open"));
2023
	   return;
2125
		return;
2024
	}
2126
	}
2025
 
2127
 
2026
	if (HRM.isEmpty())
2128
	if(HRM.isEmpty())
2027
	   str1 = dir.path();
2129
		str1 = dir.path();
2028
	else
2130
	else
2029
	   str1 = HRM;
2131
		str1 = HRM;
2030
 
2132
 
2031
	str1 +=  "/" + StartTime.toString("yyyyMMddThhmmss.zzz.hrm");
2133
	str1 +=  "/" + StartTime.toString("yyyyMMddThhmmss.zzz.hrm");
2032
	fname = KFileDialog::getSaveFileName(str1, QString("*.hrm"), this, QString("SportWatcher"));
2134
	fname = KFileDialog::getSaveFileName(str1, QString("*.hrm"), this, QString("SportWatcher"));
2033
 
2135
 
2034
	if (fname.isEmpty())
2136
	if(fname.isEmpty())
2035
	   return;
2137
		return;
2036
 
2138
 
2037
	fdfile.setFileName(fname);
2139
	fdfile.setFileName(fname);
2038
 
2140
 
2039
	if (fdfile.exists())
2141
	if(fdfile.exists())
2040
	{
2142
	{
2041
	   if (KMessageBox::questionYesNo(this, i18n("Do you really want to overwrite this file?")) == KMessageBox::No)
2143
		if(KMessageBox::questionYesNo(this, i18n("Do you really want to overwrite this file?")) == KMessageBox::No)
2042
	      return;
2144
			return;
2043
	}
2145
	}
2044
 
2146
 
2045
	if (!fdfile.open(QIODevice::ReadWrite | QIODevice::Truncate))
2147
	if(!fdfile.open(QIODevice::ReadWrite | QIODevice::Truncate))
2046
	{
2148
	{
2047
	   KMessageBox::error(this, i18n("Error creating a file!\nPlease check permissions."));
2149
		KMessageBox::error(this, i18n("Error creating a file!\nPlease check permissions."));
2048
	   return;
2150
		return;
2049
	}
2151
	}
2050
 
2152
 
2051
	rn = ds.getRunNode();
2153
	rn = ds.getRunNode();
2052
	lap = ds.getLap(rn->run->first_lap_index);
2154
	lap = ds.getLap(rn->run->first_lap_index);
2053
	t = StartTime.time();
2155
	t = StartTime.time();
2054
	dat = StartTime.date();
2156
	dat = StartTime.date();
2055
 
2157
 
2056
	if ((point = ds.getPoint(lap->start_time)) == 0)
2158
	if((point = ds.getPoint(lap->start_time)) == 0)
2057
	{
2159
	{
2058
	   fdfile.close();
2160
		fdfile.close();
2059
	   return;
2161
		return;
2060
	}
2162
	}
2061
 
2163
 
2062
	strcpy (hv0, "[Params]\n");
2164
	strcpy(hv0, "[Params]\n");
2063
	write(fdfile.handle(), &hv0[0], strlen(hv0));
2165
	write(fdfile.handle(), &hv0[0], strlen(hv0));
2064
	str1 = dat.toString("yyyyMMdd");
2166
	str1 = dat.toString("yyyyMMdd");
2065
	str2 = t.toString("hh:mm:ss.z");
2167
	str2 = t.toString("hh:mm:ss.z");
2066
	sprintf(hv0, "Version=106\nMonitor=11\nSMode=000000000\nDate=%s\nStartTime=%s\n",
2168
	sprintf(hv0, "Version=106\nMonitor=11\nSMode=000000000\nDate=%s\nStartTime=%s\n",
2067
		str1.toAscii().data(), str2.toAscii().data());
2169
	        str1.toAscii().data(), str2.toAscii().data());
2068
	write(fdfile.handle(), &hv0[0], strlen(hv0));
2170
	write(fdfile.handle(), &hv0[0], strlen(hv0));
2069
	t.setHMS(0, 0, 0);
2171
	t.setHMS(0, 0, 0);
2070
	t = t.addSecs(max_time);
2172
	t = t.addSecs(max_time);
2071
	str2 = t.toString("hh:mm:ss.z");
2173
	str2 = t.toString("hh:mm:ss.z");
2072
 
2174
 
2073
	switch (sampleTime)
2175
	switch(sampleTime)
2074
	{
2176
	{
2075
	   case 0: samsec = 5; break;
2177
		case 0: samsec = 5; break;
2076
	   case 1: samsec = 15; break;
2178
		case 1: samsec = 15; break;
2077
	   case 2: samsec = 30; break;
2179
		case 2: samsec = 30; break;
2078
	   case 3: samsec = 60; break;
2180
		case 3: samsec = 60; break;
2079
	   default:
2181
		default:
2080
	      samsec = 15;
2182
			samsec = 15;
2081
	}
2183
	}
2082
 
2184
 
2083
	sprintf(hv0, "Length=%s\nInterval=%d\nUpper1=%d\nLower1=%d\nUpper2=%d\n",
2185
	sprintf(hv0, "Length=%s\nInterval=%d\nUpper1=%d\nLower1=%d\nUpper2=%d\n",
2084
	   str2.toAscii().data(), samsec, upper1, lower1, upper2);
2186
	        str2.toAscii().data(), samsec, upper1, lower1, upper2);
2085
	write(fdfile.handle(), &hv0[0], strlen(hv0));
2187
	write(fdfile.handle(), &hv0[0], strlen(hv0));
2086
	sprintf(hv0, "Lower2=%d\nUpper3=%d\nLower3=%d\nTimer1=00:00:00.0\n",
2188
	sprintf(hv0, "Lower2=%d\nUpper3=%d\nLower3=%d\nTimer1=00:00:00.0\n",
2087
		lower2, upper3, lower3);
2189
	        lower2, upper3, lower3);
2088
	write(fdfile.handle(), &hv0[0], strlen(hv0));
2190
	write(fdfile.handle(), &hv0[0], strlen(hv0));
2089
	strcpy(hv0, "Timer2=00:00:00.0\nTimer3=00:00:00.0\nActiveLimit=0\n");
2191
	strcpy(hv0, "Timer2=00:00:00.0\nTimer3=00:00:00.0\nActiveLimit=0\n");
2090
	write(fdfile.handle(), &hv0[0], strlen(hv0));
2192
	write(fdfile.handle(), &hv0[0], strlen(hv0));
2091
	sprintf(hv0, "MaxHR=%d\nRestHR=%d\nStartDelay=0\nVO2max=%d\nWeight=%d\n\n",
2193
	sprintf(hv0, "MaxHR=%d\nRestHR=%d\nStartDelay=0\nVO2max=%d\nWeight=%d\n\n",
2092
		MaxHr, restHr, vo2max, weight);
2194
	        MaxHr, restHr, vo2max, weight);
2093
	write(fdfile.handle(), &hv0[0], strlen(hv0));
2195
	write(fdfile.handle(), &hv0[0], strlen(hv0));
2094
 
2196
 
2095
	// Write the intervall times. One block for every lap
2197
	// Write the intervall times. One block for every lap
2096
	secRange1 = secRange2 = secRange3 = secAbove = secBeyond = 0;
2198
	secRange1 = secRange2 = secRange3 = secAbove = secBeyond = 0;
2097
	strcpy(hv0, "[IntTimes]\n");
2199
	strcpy(hv0, "[IntTimes]\n");
2098
	write(fdfile.handle(), &hv0[0], strlen(hv0));
2200
	write(fdfile.handle(), &hv0[0], strlen(hv0));
2099
	t.setHMS(0, 0, 0);
2201
	t.setHMS(0, 0, 0);
2100
 
2202
 
2101
	for (unsigned int i = rn->run->first_lap_index; i < rn->run->last_lap_index; i++)
2203
	for(unsigned int i = rn->run->first_lap_index; i < rn->run->last_lap_index; i++)
2102
	{
2204
	{
2103
	   alap = ds.getLap(i);
2205
		alap = ds.getLap(i);
2104
	   point = ds.getPoint(alap->start_time);
2206
		point = ds.getPoint(alap->start_time);
2105
	   oldqt = garmin_dtime(point->time);
2207
		oldqt = garmin_dtime(point->time);
2106
	   avgHeart = minHeart = maxHeart = aktHeart = 0;
2208
		avgHeart = minHeart = maxHeart = aktHeart = 0;
2107
	   anz = 0;
2209
		anz = 0;
2108
	   unsigned long lastTime = point->time;
2210
		unsigned long lastTime = point->time;
2109
	   int totSec = 0;
2211
		int totSec = 0;
2110
 
2212
 
2111
	   while (point)
2213
		while(point)
2112
	   {
2214
		{
2113
	      if (point->time > (alap->start_time + (alap->total_time / 100)))
2215
			if(point->time > (alap->start_time + (alap->total_time / 100)))
2114
		 break;
2216
				break;
2115
 
2217
 
2116
	      if (point->heart_rate > 0)
2218
			if(point->heart_rate > 0)
2117
	      {
2219
			{
2118
		 avgHeart += point->heart_rate;
2220
				avgHeart += point->heart_rate;
2119
		 nsec = point->time - lastTime;
2221
				nsec = point->time - lastTime;
2120
		 totSec += nsec;
2222
				totSec += nsec;
2121
 
2223
 
2122
		 if (minHeart == 0 || minHeart > point->heart_rate)
2224
				if(minHeart == 0 || minHeart > point->heart_rate)
2123
		    minHeart = point->heart_rate;
2225
					minHeart = point->heart_rate;
2124
 
2226
 
2125
		 if (maxHeart < point->heart_rate)
2227
				if(maxHeart < point->heart_rate)
2126
		    maxHeart = point->heart_rate;
2228
					maxHeart = point->heart_rate;
2127
 
2229
 
2128
		 if (aktHeart == 0 && totSec >= samsec)
2230
				if(aktHeart == 0 && totSec >= samsec)
2129
		    aktHeart = avgHeart / (anz + 1);
2231
					aktHeart = avgHeart / (anz + 1);
2130
 
2232
 
2131
		 if (point->heart_rate < lower1)
2233
				if(point->heart_rate < lower1)
2132
		    secBeyond += nsec;
2234
					secBeyond += nsec;
2133
		 else if (point->heart_rate < lower2)
2235
				else if(point->heart_rate < lower2)
2134
		    secRange1 += nsec;
2236
					secRange1 += nsec;
2135
		 else if (point->heart_rate < lower3)
2237
				else if(point->heart_rate < lower3)
2136
		    secRange2 += nsec;
2238
					secRange2 += nsec;
2137
		 else if (point->heart_rate < upper3)
2239
				else if(point->heart_rate < upper3)
2138
		    secRange3 += nsec;
2240
					secRange3 += nsec;
2139
		 else
2241
				else
2140
		    secAbove += nsec;
2242
					secAbove += nsec;
2141
 
2243
 
2142
		 lastTime = point->time;
2244
				lastTime = point->time;
2143
		 anz++;
2245
				anz++;
2144
	      }
2246
			}
2145
 
2247
 
2146
	      point = ds.getPoint(point->time+1);
2248
			point = ds.getPoint(point->time + 1);
2147
	   }
2249
		}
2148
 
2250
 
2149
	   t = t.addSecs(alap->total_time / 100);
2251
		t = t.addSecs(alap->total_time / 100);
2150
	   str1 = t.toString("hh:mm:ss.z");
2252
		str1 = t.toString("hh:mm:ss.z");
2151
 
2253
 
2152
	   if (anz > 0)
2254
		if(anz > 0)
2153
	      avgHeart = avgHeart / anz;
2255
			avgHeart = avgHeart / anz;
2154
	   else
2256
		else
2155
	      avgHeart = 0;
2257
			avgHeart = 0;
2156
 
2258
 
2157
	   sprintf(hv0, "%s\t %d\t %d\t %d\t %d\n",
2259
		sprintf(hv0, "%s\t %d\t %d\t %d\t %d\n",
2158
	      str1.toAscii().data(), aktHeart, minHeart, avgHeart, maxHeart);
2260
		        str1.toAscii().data(), aktHeart, minHeart, avgHeart, maxHeart);
2159
	   write(fdfile.handle(), &hv0[0], strlen(hv0));
2261
		write(fdfile.handle(), &hv0[0], strlen(hv0));
2160
	   strcpy(hv0, "32\t 0\t 0\t 0\t 0\t 0\n");
2262
		strcpy(hv0, "32\t 0\t 0\t 0\t 0\t 0\n");
2161
	   write(fdfile.handle(), &hv0[0], strlen(hv0));
2263
		write(fdfile.handle(), &hv0[0], strlen(hv0));
2162
	   strcpy(hv0, "0\t 0\t 0\t 0\t 0\n");
2264
		strcpy(hv0, "0\t 0\t 0\t 0\t 0\n");
2163
	   write(fdfile.handle(), &hv0[0], strlen(hv0));
2265
		write(fdfile.handle(), &hv0[0], strlen(hv0));
2164
	   sprintf(hv0, "0\t %d\t 0\t 0\t 0\t 0\n", (int)alap->total_distance);
2266
		sprintf(hv0, "0\t %d\t 0\t 0\t 0\t 0\n", (int)alap->total_distance);
2165
	   write(fdfile.handle(), &hv0[0], strlen(hv0));
2267
		write(fdfile.handle(), &hv0[0], strlen(hv0));
2166
	   strcpy(hv0, "0\t 0\t 0\t 0\t 0\t 0\n");
2268
		strcpy(hv0, "0\t 0\t 0\t 0\t 0\t 0\n");
2167
	   write(fdfile.handle(), &hv0[0], strlen(hv0));
2269
		write(fdfile.handle(), &hv0[0], strlen(hv0));
2168
	}
2270
	}
2169
 
2271
 
2170
	strcpy(hv0, "\n[IntNotes]\n\n[ExtraData]\n\n");
2272
	strcpy(hv0, "\n[IntNotes]\n\n[ExtraData]\n\n");
2171
	write(fdfile.handle(), &hv0[0], strlen(hv0));
2273
	write(fdfile.handle(), &hv0[0], strlen(hv0));
2172
 
2274
 
2173
	strcpy(hv0, "[Summary-123]\n");
2275
	strcpy(hv0, "[Summary-123]\n");
2174
	write(fdfile.handle(), &hv0[0], strlen(hv0));	// Time limits 1
2276
	write(fdfile.handle(), &hv0[0], strlen(hv0));	// Time limits 1
2175
	smp = max_time - secBeyond - secRange1 - secRange2 - secRange3 - secAbove;
2277
	smp = max_time - secBeyond - secRange1 - secRange2 - secRange3 - secAbove;
2176
	sprintf(hv0, "%lu\t %u\t %u\t %u\t %u\n",
2278
	sprintf(hv0, "%lu\t %u\t %u\t %u\t %u\n",
2177
		max_time, secRange1, secRange2 + secRange3,
2279
	        max_time, secRange1, secRange2 + secRange3,
2178
		secAbove + secBeyond, smp);
2280
	        secAbove + secBeyond, smp);
2179
	write(fdfile.handle(), &hv0[0], strlen(hv0));	// limits 1
2281
	write(fdfile.handle(), &hv0[0], strlen(hv0));	// limits 1
2180
	sprintf(hv0, "%d\t %d\t %d\t %d\n",
2282
	sprintf(hv0, "%d\t %d\t %d\t %d\n",
2181
		MaxHr, upper1, lower1, restHr);
2283
	        MaxHr, upper1, lower1, restHr);
2182
	write(fdfile.handle(), &hv0[0], strlen(hv0));	// Time limits 1
2284
	write(fdfile.handle(), &hv0[0], strlen(hv0));	// Time limits 1
2183
	sprintf(hv0, "%lu\t %u\t %u\t %u\t %u\n",
2285
	sprintf(hv0, "%lu\t %u\t %u\t %u\t %u\n",
2184
		max_time, secRange2, secRange1 + secRange3,
2286
	        max_time, secRange2, secRange1 + secRange3,
2185
		secAbove + secBeyond, smp);
2287
	        secAbove + secBeyond, smp);
2186
	write(fdfile.handle(), &hv0[0], strlen(hv0));	// limits 2
2288
	write(fdfile.handle(), &hv0[0], strlen(hv0));	// limits 2
2187
	sprintf(hv0, "%d\t %d\t %d\t %d\n",
2289
	sprintf(hv0, "%d\t %d\t %d\t %d\n",
2188
		MaxHr, upper2, lower2, restHr);
2290
	        MaxHr, upper2, lower2, restHr);
2189
	write(fdfile.handle(), &hv0[0], strlen(hv0));	// Time limits 2
2291
	write(fdfile.handle(), &hv0[0], strlen(hv0));	// Time limits 2
2190
	sprintf(hv0, "%lu\t %u\t %u\t %u\t %u\n",
2292
	sprintf(hv0, "%lu\t %u\t %u\t %u\t %u\n",
2191
		max_time, secRange3, secRange1 + secRange2,
2293
	        max_time, secRange3, secRange1 + secRange2,
2192
		secAbove + secBeyond, smp);
2294
	        secAbove + secBeyond, smp);
2193
	write(fdfile.handle(), &hv0[0], strlen(hv0));	// limits 3
2295
	write(fdfile.handle(), &hv0[0], strlen(hv0));	// limits 3
2194
	sprintf(hv0, "%d\t %d\t %d\t %d\n",
2296
	sprintf(hv0, "%d\t %d\t %d\t %d\n",
2195
		MaxHr, upper3, lower3, restHr);
2297
	        MaxHr, upper3, lower3, restHr);
2196
	write(fdfile.handle(), &hv0[0], strlen(hv0));	// Time limits 3
2298
	write(fdfile.handle(), &hv0[0], strlen(hv0));	// Time limits 3
2197
	samples = max_time / samsec;
2299
	samples = max_time / samsec;
2198
	sprintf(hv0, "0\t %u\n\n", samples);	// samples
2300
	sprintf(hv0, "0\t %u\n\n", samples);	// samples
2199
	write(fdfile.handle(), &hv0[0], strlen(hv0));
2301
	write(fdfile.handle(), &hv0[0], strlen(hv0));
2200
 
2302
 
Line 2206... Line 2308...
2206
	write(fdfile.handle(), &hv0[0], strlen(hv0));
2308
	write(fdfile.handle(), &hv0[0], strlen(hv0));
2207
	sprintf(hv0, "0\t %u\n\n", samples);	// samples
2309
	sprintf(hv0, "0\t %u\n\n", samples);	// samples
2208
	write(fdfile.handle(), &hv0[0], strlen(hv0));
2310
	write(fdfile.handle(), &hv0[0], strlen(hv0));
2209
 
2311
 
2210
	sprintf(hv0, "[HRZones]\n%d\n%d\n%d\n%d\n%d\n%d\n0\n0\n0\n0\n0\n\n",
2312
	sprintf(hv0, "[HRZones]\n%d\n%d\n%d\n%d\n%d\n%d\n0\n0\n0\n0\n0\n\n",
2211
		MaxHr, upper3, upper2, upper1, lower1, restHr);
2313
	        MaxHr, upper3, upper2, upper1, lower1, restHr);
2212
	write(fdfile.handle(), &hv0[0], strlen(hv0));
2314
	write(fdfile.handle(), &hv0[0], strlen(hv0));
2213
 
2315
 
2214
	strcpy(hv0, "[HRData]\n");
2316
	strcpy(hv0, "[HRData]\n");
2215
	write(fdfile.handle(), &hv0[0], strlen(hv0));
2317
	write(fdfile.handle(), &hv0[0], strlen(hv0));
2216
 
2318
 
Line 2220... Line 2322...
2220
	nsec = samsec;
2322
	nsec = samsec;
2221
	oldqt = garmin_dtime(lap->start_time);
2323
	oldqt = garmin_dtime(lap->start_time);
2222
	qt = 0;
2324
	qt = 0;
2223
	point = ds.getPoint(lap->start_time);
2325
	point = ds.getPoint(lap->start_time);
2224
 
2326
 
2225
	while (point)
2327
	while(point)
2226
	{
2328
	{
2227
	   if (seconds >= nsec)
2329
		if(seconds >= nsec)
2228
	   {
2330
		{
2229
	      if (anz > 0)
2331
			if(anz > 0)
2230
	      {
2332
			{
2231
		 sprintf(hv0, "%d\n", smp / anz);
2333
				sprintf(hv0, "%d\n", smp / anz);
2232
		 write(fdfile.handle(), &hv0[0], strlen(hv0));
2334
				write(fdfile.handle(), &hv0[0], strlen(hv0));
2233
	      }
2335
			}
2234
 
2336
 
2235
	      if (smp > 0 && seconds >= (nsec + samsec))
2337
			if(smp > 0 && seconds >= (nsec + samsec))
2236
	      {
2338
			{
2237
		 if (anz <= 0)
2339
				if(anz <= 0)
2238
		    anz = 0;
2340
					anz = 0;
2239
 
2341
 
2240
		 for (int x = nsec; x < seconds; x += samsec)
2342
				for(int x = nsec; x < seconds; x += samsec)
2241
		 {
2343
				{
2242
		    sprintf(hv0, "%d\n", smp / anz);
2344
					sprintf(hv0, "%d\n", smp / anz);
2243
		    write(fdfile.handle(), &hv0[0], strlen(hv0));
2345
					write(fdfile.handle(), &hv0[0], strlen(hv0));
2244
		    nsec += samsec;
2346
					nsec += samsec;
2245
		 }
2347
				}
2246
	      }
2348
			}
2247
		
2349
 
2248
	      anz = 0;
2350
			anz = 0;
2249
	      smp = 0;
2351
			smp = 0;
2250
	      nsec += samsec;
2352
			nsec += samsec;
2251
	   }
2353
		}
2252
 
2354
 
2253
	   qt = garmin_dtime (point->time);
2355
		qt = garmin_dtime(point->time);
2254
	   seconds += oldqt->secsTo(*qt);
2356
		seconds += oldqt->secsTo(*qt);
2255
 
2357
 
2256
	   if (point->heart_rate > 0)
2358
		if(point->heart_rate > 0)
2257
	   {
2359
		{
2258
	      smp += point->heart_rate;
2360
			smp += point->heart_rate;
2259
	      anz++;
2361
			anz++;
2260
	   }
2362
		}
2261
 
2363
 
2262
	   delete oldqt;
2364
		delete oldqt;
2263
	   oldqt = qt;
2365
		oldqt = qt;
2264
	   point = ds.getPoint(point->time + 1);
2366
		point = ds.getPoint(point->time + 1);
2265
	}
2367
	}
2266
 
2368
 
2267
	fdfile.close();
2369
	fdfile.close();
2268
	KMessageBox::information(this, i18n("File successfully written."));
2370
	KMessageBox::information(this, i18n("File successfully written."));
2269
}
2371
}
2270
 
2372
 
2271
void sportwatcherWidget::extrasSettings()
2373
void sportwatcherWidget::extrasSettings()
2272
{
2374
{
2273
settingsWidget *dlg = new settingsWidget(this);
2375
	settingsWidget *dlg = new settingsWidget(this);
2274
 
2376
 
2275
	if (dlg->exec() == QDialog::Accepted)
2377
	if(dlg->exec() == QDialog::Accepted)
2276
	{
2378
	{
2277
	   KConfig cfg(QString("sportwatcher.rc"), KConfig::SimpleConfig);
2379
		KConfig cfg(QString("sportwatcher.rc"), KConfig::SimpleConfig);
2278
	   KConfigGroup ic (&cfg, "SportWatcher");
2380
		KConfigGroup ic(&cfg, "SportWatcher");
2279
	   lower1 = ic.readEntry("lower1", 0);
2381
		lower1 = ic.readEntry("lower1", 0);
2280
	   lower2 = ic.readEntry("lower2", 0);
2382
		lower2 = ic.readEntry("lower2", 0);
2281
	   lower3 = ic.readEntry("lower3", 0);
2383
		lower3 = ic.readEntry("lower3", 0);
2282
	   upper1 = ic.readEntry("upper1", 0);
2384
		upper1 = ic.readEntry("upper1", 0);
2283
	   upper2 = ic.readEntry("upper2", 0);
2385
		upper2 = ic.readEntry("upper2", 0);
2284
	   upper3 = ic.readEntry("upper3", 0);
2386
		upper3 = ic.readEntry("upper3", 0);
2285
	   MaxHr = ic.readEntry("maxHr", 0);
2387
		MaxHr = ic.readEntry("maxHr", 0);
2286
	   restHr = ic.readEntry("restHr", 0);
2388
		restHr = ic.readEntry("restHr", 0);
2287
	   vo2max = ic.readEntry("vo2max", 0);
2389
		vo2max = ic.readEntry("vo2max", 0);
2288
	   weight = ic.readEntry("weight", 0);
2390
		weight = ic.readEntry("weight", 0);
2289
	   sampleTime = ic.readEntry("seconds", 1);
2391
		sampleTime = ic.readEntry("seconds", 1);
2290
	   Serial = ic.readEntry("Serial", false);
2392
		Serial = ic.readEntry("Serial", false);
2291
	   Contour = ic.readEntry("Contour", false);
2393
		Contour = ic.readEntry("Contour", false);
2292
	   Device = ic.readEntry("Device", QString("/dev/ttyUSB0"));
2394
		Device = ic.readEntry("Device", QString("/dev/ttyUSB0"));
2293
	   Forerunner = ic.readEntry("Forerunner", false);
2395
		Forerunner = ic.readEntry("Forerunner", false);
2294
	   Data = ic.readEntry("Data", QString("/"));
2396
		Data = ic.readEntry("Data", QString("/"));
2295
	   HRM = ic.readEntry("HRM", QString("/"));
2397
		HRM = ic.readEntry("HRM", QString("/"));
2296
	   MAP = ic.readEntry("MAP", QString("/"));
2398
		MAP = ic.readEntry("MAP", QString("/"));
2297
	   Units = ic.readEntry("Units", 0);
2399
		Units = ic.readEntry("Units", 0);
2298
	   MapType = ic.readEntry("MapType", 0);
2400
		MapType = ic.readEntry("MapType", 0);
2299
	}
2401
	}
2300
 
2402
 
2301
	delete dlg;
2403
	delete dlg;
2302
}
2404
}
2303
 
2405
 
2304
void sportwatcherWidget::extrasWMSSettings()
2406
void sportwatcherWidget::extrasWMSSettings()
2305
{
2407
{
2306
#if defined HAVE_GDAL
2408
#if defined HAVE_GDAL
-
 
2409
 
2307
	if (MapType == MPT_BMP || MapType == MPT_GIF || MapType == MPT_PNG ||
2410
	if(MapType == MPT_BMP || MapType == MPT_GIF || MapType == MPT_PNG ||
2308
	    MapType == MPT_TIF)
2411
	                  MapType == MPT_TIF)
2309
	{
2412
	{
2310
	   coordinatesWidget *idlg = new coordinatesWidget(this);
2413
		coordinatesWidget *idlg = new coordinatesWidget(this);
2311
	   idlg->exec();
2414
		idlg->exec();
2312
	   delete idlg;
2415
		delete idlg;
2313
	   return;
2416
		return;
2314
	}
2417
	}
2315
 
2418
 
2316
	if (MapType == MPT_WMS)
2419
	if(MapType == MPT_WMS)
2317
	{
2420
	{
2318
	   wmsbase *dlg = new wmsbase(this);
2421
		wmsbase *dlg = new wmsbase(this);
2319
	   dlg->exec();
2422
		dlg->exec();
2320
	   delete dlg;
2423
		delete dlg;
2321
	}
2424
	}
-
 
2425
 
2322
#if defined HAVE_MAPNIK
2426
#if defined HAVE_MAPNIK
-
 
2427
 
2323
	if (MapType == MPT_SHP || MapType == MPT_OSM)
2428
	if(MapType == MPT_SHP || MapType == MPT_OSM)
2324
	{
2429
	{
2325
	   shapeWidget *dlg = new shapeWidget(this);
2430
		shapeWidget *dlg = new shapeWidget(this);
2326
 
2431
 
2327
	   if (MapType == MPT_SHP)
2432
		if(MapType == MPT_SHP)
2328
	      dlg->setMapType(shapeWidget::MAP_SHAPE);
2433
			dlg->setMapType(shapeWidget::MAP_SHAPE);
2329
	   else
2434
		else
2330
	      dlg->setMapType(shapeWidget::MAP_OSM);
2435
			dlg->setMapType(shapeWidget::MAP_OSM);
2331
 
2436
 
2332
	   dlg->exec();
2437
		dlg->exec();
2333
	   delete dlg;
2438
		delete dlg;
2334
	}
2439
	}
-
 
2440
 
2335
#else
2441
#else
2336
	KMessageBox::detailedSorry(this,
2442
	KMessageBox::detailedSorry(this,
2337
	   i18n("This function was disabled at compile time because of missing Mapnik!"),
2443
	                           i18n("This function was disabled at compile time because of missing Mapnik!"),
2338
	   i18n("SportWatcher needs Mapnik 0.6 or newer, to enable this function.\n") +
2444
	                           i18n("SportWatcher needs Mapnik 0.6 or newer, to enable this function.\n") +
2339
	   i18n("If you like this to be working, install Mapnik and recompile the source."));
2445
	                           i18n("If you like this to be working, install Mapnik and recompile the source."));
2340
#endif
2446
#endif
-
 
2447
 
2341
	if (MapType != MPT_WMS && MapType != MPT_SHP && MapType != MPT_OSM)
2448
	if(MapType != MPT_WMS && MapType != MPT_SHP && MapType != MPT_OSM)
2342
	{
2449
	{
2343
	   KMessageBox::detailedSorry(this,
2450
		KMessageBox::detailedSorry(this,
2344
	      i18n("You have not choosen a WMS tag file or shape file directory!"),
2451
		                           i18n("You have not choosen a WMS tag file or shape file directory!"),
2345
	      i18n("This dialog is especialy to set map specific parameters. ") +
2452
		                           i18n("This dialog is especialy to set map specific parameters. ") +
2346
	      i18n("Therefore this dialog is temporary disabled. It will be ") +
2453
		                           i18n("Therefore this dialog is temporary disabled. It will be ") +
2347
	      i18n("available again, as soon as you choose \"WMS server\" or ") +
2454
		                           i18n("available again, as soon as you choose \"WMS server\" or ") +
2348
	      i18n("Shape file as your map type."));
2455
		                           i18n("Shape file as your map type."));
2349
	      return;
2456
		return;
2350
	}
2457
	}
-
 
2458
 
2351
#else
2459
#else
2352
	KMessageBox::detailedSorry(this,
2460
	KMessageBox::detailedSorry(this,
2353
	   i18n("This function was disabled at compile time because of missing GDAL v1.x.x!"),
2461
	                           i18n("This function was disabled at compile time because of missing GDAL v1.x.x!"),
2354
	   i18n("Sportwatcher needs GDAL v1.5.x or newer, to enable this function.\n") +
2462
	                           i18n("Sportwatcher needs GDAL v1.5.x or newer, to enable this function.\n") +
2355
	   i18n("If you like this to be working, install GDAL and recompile the source!"));
2463
	                           i18n("If you like this to be working, install GDAL and recompile the source!"));
2356
#endif
2464
#endif
2357
}
2465
}
2358
 
2466
 
2359
/*
2467
/*
2360
 * Functions to fill in the boxes of the main mask.
2468
 * Functions to fill in the boxes of the main mask.
2361
 */
2469
 */
2362
void sportwatcherWidget::showLaps()
2470
void sportwatcherWidget::showLaps()
2363
{
2471
{
2364
QString qs_name, qs_distance, qs_etime, qs_avgpace, qs_avgspeed, qs_maxspeed;
2472
	QString qs_name, qs_distance, qs_etime, qs_avgpace, qs_avgspeed, qs_maxspeed;
2365
QString qs_calories, qs_avghr, qs_maxhr, qs_avgcadence, qs_ascent, qs_descent;
2473
	QString qs_calories, qs_avghr, qs_maxhr, qs_avgcadence, qs_ascent, qs_descent;
2366
QString qs_totdist;
2474
	QString qs_totdist;
2367
QDateTime dt;
2475
	QDateTime dt;
2368
QTime t, st;
2476
	QTime t, st;
2369
QDateTime *qt;
2477
	QDateTime *qt;
2370
LAP *lap;
2478
	LAP *lap;
2371
POINT *point;
2479
	POINT *point;
2372
RUN_NODE *rakt, *rn;
2480
	RUN_NODE *rakt, *rn;
2373
int laps, i, anz, men, cad;
2481
	int laps, i, anz, men, cad;
2374
double alt_asc, alt_dsc, sum_asc, sum_dsc, old_asc, old_dsc;
2482
	double alt_asc, alt_dsc, sum_asc, sum_dsc, old_asc, old_dsc;
2375
double totdist;
2483
	double totdist;
2376
bool pause;
2484
	bool pause;
2377
 
2485
 
2378
	if (!DIRTY)
2486
	if(!DIRTY)
2379
	   return;
2487
		return;
2380
 
2488
 
2381
	if (!gmn)
2489
	if(!gmn)
2382
	   return;
2490
		return;
2383
 
2491
 
2384
	if (gmn->type == data_Dnil)
2492
	if(gmn->type == data_Dnil)
2385
	{
2493
	{
2386
	   KMessageBox::error(this, i18n("No data found!"));
2494
		KMessageBox::error(this, i18n("No data found!"));
2387
	   return;
2495
		return;
2388
	}
2496
	}
2389
 
2497
 
2390
	if (gmn->type != data_Dlist)     /* List of data */
2498
	if(gmn->type != data_Dlist)      /* List of data */
2391
	{
2499
	{
2392
	   KMessageBox::error(this, i18n("Found unexpected data type %1!").arg(gmn->type));
2500
		KMessageBox::error(this, i18n("Found unexpected data type %1!").arg(gmn->type));
2393
	   return;
2501
		return;
2394
	}
2502
	}
2395
 
2503
 
2396
	ds.destroy();
2504
	ds.destroy();
2397
	min_hr = max_hr = avg_hr = 0;
2505
	min_hr = max_hr = avg_hr = 0;
2398
	min_height = max_height = 0.0;
2506
	min_height = max_height = 0.0;
Line 2403... Line 2511...
2403
	ui_sportwatcherWidgetBase.liLaps->setAllColumnsShowFocus(true);
2511
	ui_sportwatcherWidgetBase.liLaps->setAllColumnsShowFocus(true);
2404
	// Tab Laps
2512
	// Tab Laps
2405
	ui_sportwatcherWidgetBase.twLaps->clear();
2513
	ui_sportwatcherWidgetBase.twLaps->clear();
2406
	ds.garmin_print_data(gmn);
2514
	ds.garmin_print_data(gmn);
2407
 
2515
 
2408
	if (!(rn = ds.getRunNode()))
2516
	if(!(rn = ds.getRunNode()))
2409
	   return;
2517
		return;
2410
 
2518
 
2411
	rakt = rn;
2519
	rakt = rn;
2412
	// Tab Summary
2520
	// Tab Summary
2413
	ui_sportwatcherWidgetBase.liLaps->setRootIsDecorated(true);
2521
	ui_sportwatcherWidgetBase.liLaps->setRootIsDecorated(true);
2414
 
2522
 
2415
	for (i = 1; i < 12; i++)
2523
	for(i = 1; i < 12; i++)
2416
	   ui_sportwatcherWidgetBase.liLaps->setColumnAlignment(i, Qt::AlignRight);
2524
		ui_sportwatcherWidgetBase.liLaps->setColumnAlignment(i, Qt::AlignRight);
-
 
2525
 
2417
	// Tab Laps
2526
	// Tab Laps
2418
	ui_sportwatcherWidgetBase.edTotalDistance->clear();
2527
	ui_sportwatcherWidgetBase.edTotalDistance->clear();
2419
	ui_sportwatcherWidgetBase.edTotalTime->clear();
2528
	ui_sportwatcherWidgetBase.edTotalTime->clear();
2420
	ui_sportwatcherWidgetBase.edAvgSpeed->clear();
2529
	ui_sportwatcherWidgetBase.edAvgSpeed->clear();
2421
	ui_sportwatcherWidgetBase.edTotalHeight->clear();
2530
	ui_sportwatcherWidgetBase.edTotalHeight->clear();
Line 2427... Line 2536...
2427
	men = 0;
2536
	men = 0;
2428
	cad = 0;
2537
	cad = 0;
2429
 
2538
 
2430
	// The main loop.
2539
	// The main loop.
2431
	// If a supported run type is detected, it will be processed.
2540
	// If a supported run type is detected, it will be processed.
2432
	while (rakt)
2541
	while(rakt)
2433
	{
2542
	{
2434
	   // Check for a supported run type
2543
		// Check for a supported run type
2435
	   if (rakt->run->type == data_D1000 || rakt->run->type == data_D1009 ||
2544
		if(rakt->run->type == data_D1000 || rakt->run->type == data_D1009 ||
2436
	   	rakt->run->type == data_D1010)
2545
		                  rakt->run->type == data_D1010)
2437
	   {
2546
		{
2438
	   int cal, ahr, mhr;
2547
			int cal, ahr, mhr;
2439
	   double distance, speed, mspeed;
2548
			double distance, speed, mspeed;
2440
	   QDate dat;
2549
			QDate dat;
2441
 
2550
 
2442
	      // Set the name depending on the sport type
2551
			// Set the name depending on the sport type
2443
	      // This is used on the tab "Summary"
2552
			// This is used on the tab "Summary"
2444
	      switch (rakt->run->sport_type)
2553
			switch(rakt->run->sport_type)
2445
	      {
2554
			{
2446
		 case D1000_running: qs_name = i18n("Running: "); break;
2555
				case D1000_running: qs_name = i18n("Running: "); break;
2447
		 case D1000_biking:  qs_name = i18n("Biking: "); break;
2556
				case D1000_biking:  qs_name = i18n("Biking: "); break;
2448
		 case D1000_other:   qs_name = i18n("Other: "); break;
2557
				case D1000_other:   qs_name = i18n("Other: "); break;
2449
		 default:
2558
				default:
2450
		    qs_name = i18n("Unknown: ");
2559
					qs_name = i18n("Unknown: ");
2451
	      }
2560
			}
2452
 
2561
 
2453
	      if (!(lap = ds.getLap(rakt->run->first_lap_index)))
2562
			if(!(lap = ds.getLap(rakt->run->first_lap_index)))
2454
		 return;
2563
				return;
2455
 
2564
 
2456
	      qt = garmin_dtime (lap->start_time);
2565
			qt = garmin_dtime(lap->start_time);
2457
	      StartTime = *qt;
2566
			StartTime = *qt;
2458
	      st = qt->time();
2567
			st = qt->time();
2459
	      dat = qt->date();
2568
			dat = qt->date();
2460
	      delete qt;
2569
			delete qt;
2461
	      qt = 0;
2570
			qt = 0;
2462
	      // Find the last track;
2571
 
2463
	      //    It is possible to delete laps directly on the watch,
2572
			// Find the last track;
2464
	      //    so we can't be sure the last lap is really the last one.
2573
			//    It is possible to delete laps directly on the watch,
2465
	      //    Tracks are not deleted and the last track contains the
2574
			//    so we can't be sure the last lap is really the last one.
2466
	      //    summuraries we need.
2575
			//    Tracks are not deleted and the last track contains the
2467
	      if (!(point = ds.getLastPoint()))
2576
			//    summuraries we need.
2468
	      {
2577
			if(!(point = ds.getLastPoint()))
2469
		 KMessageBox::error(this, i18n("Error getting the last messure point!"));
2578
			{
2470
		 return;
2579
				KMessageBox::error(this, i18n("Error getting the last messure point!"));
2471
	      }
2580
				return;
2472
 
2581
			}
2473
	      qt = garmin_dtime(point->time);
2582
 
2474
	      t = qt->time();
2583
			qt = garmin_dtime(point->time);
2475
	      t.setHMS(0, 0, 0);
2584
			t = qt->time();
2476
	      t = t.addSecs(ds.getTotalTime());
2585
			t.setHMS(0, 0, 0);
2477
	      qt->setDate(dat);
2586
			t = t.addSecs(ds.getTotalTime());
2478
	      qt->setTime(t);
2587
			qt->setDate(dat);
2479
	      qs_name.append(kl->formatDate(dat, KLocale::ShortDate));
2588
			qt->setTime(t);
2480
	      qs_name.append(" ");
2589
			qs_name.append(kl->formatDate(dat, KLocale::ShortDate));
2481
	      qs_name.append(kl->formatTime(st, true));
2590
			qs_name.append(" ");
2482
	      max_time = ds.getTotalTime();
2591
			qs_name.append(kl->formatTime(st, true));
2483
	      qs_etime = QString(qt->toString("hh:mm:ss.zzz"));
2592
			max_time = ds.getTotalTime();
2484
 
2593
			qs_etime = QString(qt->toString("hh:mm:ss.zzz"));
2485
	      distance = 0.0;
2594
 
2486
	      cal = 0;
2595
			distance = 0.0;
2487
	      mspeed = 0;
2596
			cal = 0;
2488
	      ahr = mhr = 0;
2597
			mspeed = 0;
2489
	      anz = 0;
2598
			ahr = mhr = 0;
2490
	      cad = 0;
2599
			anz = 0;
2491
	      sum_asc = sum_dsc = old_asc = old_dsc = 0;
2600
			cad = 0;
2492
 
2601
			sum_asc = sum_dsc = old_asc = old_dsc = 0;
2493
	      // Find out the total distance, calories, maximum speed,
2602
 
2494
	      // maximum heart rate and the average heart rate. Get this
2603
			// Find out the total distance, calories, maximum speed,
2495
	      // values from the lap summary the watch made.
2604
			// maximum heart rate and the average heart rate. Get this
2496
	      for (i = rakt->run->first_lap_index; (unsigned int)i <= rakt->run->last_lap_index; i++)
2605
			// values from the lap summary the watch made.
2497
	      {
2606
			for(i = rakt->run->first_lap_index; (unsigned int)i <= rakt->run->last_lap_index; i++)
2498
		 if ((lap = ds.getLap(i)) == NULL)
2607
			{
2499
		    continue;
2608
				if((lap = ds.getLap(i)) == NULL)
2500
 
2609
					continue;
2501
		 distance += lap->total_distance;
2610
 
2502
		 cal += lap->calories;
2611
				distance += lap->total_distance;
2503
 
2612
				cal += lap->calories;
2504
		 if (lap->avg_cadence != 0xff)
2613
 
2505
		    cad += lap->avg_cadence;
2614
				if(lap->avg_cadence != 0xff)
2506
 
2615
					cad += lap->avg_cadence;
2507
		 ahr += lap->avg_heart_rate;
2616
 
2508
		 anz++;
2617
				ahr += lap->avg_heart_rate;
2509
 
2618
				anz++;
2510
		 if (lap->max_speed > mspeed)
2619
 
2511
		    mspeed = lap->max_speed;
2620
				if(lap->max_speed > mspeed)
2512
 
2621
					mspeed = lap->max_speed;
2513
		 if (lap->max_heart_rate > mhr)
2622
 
2514
		    mhr = lap->max_heart_rate;
2623
				if(lap->max_heart_rate > mhr)
2515
	      }
2624
					mhr = lap->max_heart_rate;
2516
 
2625
			}
2517
	      total_distance = distance = ds.getTotalDistance();
2626
 
2518
 
2627
			total_distance = distance = ds.getTotalDistance();
2519
	      if (Units == 1)		// Statute?
2628
 
2520
		 qs_distance.sprintf("%.2f ft", distance / 0.304);
2629
			if(Units == 1)		// Statute?
2521
	      else
2630
				qs_distance.sprintf("%.2f ft", distance / 0.304);
2522
	         qs_distance.sprintf("%.2f m", distance);
2631
			else
2523
 
2632
				qs_distance.sprintf("%.2f m", distance);
2524
	      if (distance > 0)
2633
 
2525
	      {
2634
			if(distance > 0)
2526
		 QTime tt = qt->time();
2635
			{
2527
		 long secs = (double)(tt.hour() * 3600 + tt.minute() * 60 + tt.second()) / 100.0;
2636
				QTime tt = qt->time();
2528
 
2637
				long secs = (double)(tt.hour() * 3600 + tt.minute() * 60 + tt.second()) / 100.0;
2529
		 if (Units == 0)
2638
 
2530
		    secs = secs * (1000.0 / distance * 100.0);
2639
				if(Units == 0)
2531
		 else
2640
					secs = secs * (1000.0 / distance * 100.0);
2532
		    secs = secs * (1609.344 / distance * 100.0);
2641
				else
2533
 
2642
					secs = secs * (1609.344 / distance * 100.0);
2534
		 int h = secs / 3600;
2643
 
2535
		 int m = (secs - (h * 3600)) / 60;
2644
				int h = secs / 3600;
2536
		 int s = secs - ((h * 3600) + (m * 60));
2645
				int m = (secs - (h * 3600)) / 60;
2537
		 t = QTime(h, m, s, 0);
2646
				int s = secs - ((h * 3600) + (m * 60));
2538
		 qs_avgpace = QString("  ") + kl->formatTime(t, true);
2647
				t = QTime(h, m, s, 0);
2539
 
2648
				qs_avgpace = QString("  ") + kl->formatTime(t, true);
2540
		 if (Units == 0)
2649
 
2541
		    qs_avgpace.append(QString(" /km"));
2650
				if(Units == 0)
2542
		 else
2651
					qs_avgpace.append(QString(" /km"));
2543
		    qs_avgpace.append(QString(" /mi"));
2652
				else
2544
	      }
2653
					qs_avgpace.append(QString(" /mi"));
2545
 
2654
			}
2546
	      if (Units == 1)		// Statute?
2655
 
2547
		 speed = distance / ds.getTotalTime() * 3.6 / 1.609344;
2656
			if(Units == 1)		// Statute?
2548
	      else
2657
				speed = distance / ds.getTotalTime() * 3.6 / 1.609344;
2549
		 speed = distance / ds.getTotalTime() * 3.6;
2658
			else
2550
 
2659
				speed = distance / ds.getTotalTime() * 3.6;
2551
	      qs_avgspeed.sprintf("%.2f %s", speed, (Units == 1) ? "mph" : "km/h");
2660
 
2552
	      qs_maxspeed.sprintf("%.2f %s", (Units == 1) ? mspeed * 3.6 / 1.609344 : mspeed * 3.6, (Units == 1) ? "mph" : "km/h");
2661
			qs_avgspeed.sprintf("%.2f %s", speed, (Units == 1) ? "mph" : "km/h");
2553
	      qs_calories.sprintf("%d", cal);
2662
			qs_maxspeed.sprintf("%.2f %s", (Units == 1) ? mspeed * 3.6 / 1.609344 : mspeed * 3.6, (Units == 1) ? "mph" : "km/h");
2554
	      qs_avghr.sprintf("%d bpm", ahr / anz);
2663
			qs_calories.sprintf("%d", cal);
2555
	      qs_maxhr.sprintf("%d bpm", mhr);
2664
			qs_avghr.sprintf("%d bpm", ahr / anz);
2556
 
2665
			qs_maxhr.sprintf("%d bpm", mhr);
2557
	      if (cad > 0)
2666
 
2558
		 qs_avgcadence.sprintf("%d", cad / anz);
2667
			if(cad > 0)
2559
 
2668
				qs_avgcadence.sprintf("%d", cad / anz);
2560
	      // Add the summary line columns to the tab "Summary"
2669
 
2561
	      K3ListViewItem *element = new K3ListViewItem(ui_sportwatcherWidgetBase.liLaps,
2670
			// Add the summary line columns to the tab "Summary"
2562
	        qs_name, kl->formatNumber(qs_distance, false),
2671
			K3ListViewItem *element = new K3ListViewItem(ui_sportwatcherWidgetBase.liLaps,
2563
		qs_etime, qs_avgpace, kl->formatNumber(qs_avgspeed, false),
2672
			                  qs_name, kl->formatNumber(qs_distance, false),
2564
		kl->formatNumber(qs_maxspeed, false), qs_calories, qs_avghr);
2673
			                  qs_etime, qs_avgpace, kl->formatNumber(qs_avgspeed, false),
2565
	      element->setText(8, qs_maxhr);
2674
			                  kl->formatNumber(qs_maxspeed, false), qs_calories, qs_avghr);
2566
	      element->setText(9, qs_avgcadence);
2675
			element->setText(8, qs_maxhr);
2567
	      element->setText(10, kl->formatNumber(qs_ascent, false));
2676
			element->setText(9, qs_avgcadence);
2568
	      element->setText(11, kl->formatNumber(qs_descent, false));
2677
			element->setText(10, kl->formatNumber(qs_ascent, false));
2569
	      element->sortChildItems(0, false);
2678
			element->setText(11, kl->formatNumber(qs_descent, false));
2570
	      element->setOpen(true);
2679
			element->sortChildItems(0, false);
2571
	      element->setPixmap(0, KIcon(QString("activity")).pixmap(16));
2680
			element->setOpen(true);
2572
	      ui_sportwatcherWidgetBase.liLaps->insertItem(element);
2681
			element->setPixmap(0, KIcon(QString("activity")).pixmap(16));
2573
	      // Add some of the summaries to the fields on the tab "Lap details"
2682
			ui_sportwatcherWidgetBase.liLaps->insertItem(element);
2574
	      ui_sportwatcherWidgetBase.edTotalDistance->setAlignment(Qt::AlignRight);
2683
			// Add some of the summaries to the fields on the tab "Lap details"
2575
	      ui_sportwatcherWidgetBase.edTotalDistance->insert(kl->formatNumber(qs_distance, false));
2684
			ui_sportwatcherWidgetBase.edTotalDistance->setAlignment(Qt::AlignRight);
2576
	      ui_sportwatcherWidgetBase.edTotalTime->setAlignment(Qt::AlignRight);
2685
			ui_sportwatcherWidgetBase.edTotalDistance->insert(kl->formatNumber(qs_distance, false));
2577
	      ui_sportwatcherWidgetBase.edTotalTime->insert(qs_etime);
2686
			ui_sportwatcherWidgetBase.edTotalTime->setAlignment(Qt::AlignRight);
2578
	      ui_sportwatcherWidgetBase.edAvgSpeed->setAlignment(Qt::AlignRight);
2687
			ui_sportwatcherWidgetBase.edTotalTime->insert(qs_etime);
2579
	      ui_sportwatcherWidgetBase.edAvgSpeed->insert(kl->formatNumber(qs_avgspeed, false));
2688
			ui_sportwatcherWidgetBase.edAvgSpeed->setAlignment(Qt::AlignRight);
2580
	      ui_sportwatcherWidgetBase.edTotalHeight->setAlignment(Qt::AlignRight);
2689
			ui_sportwatcherWidgetBase.edAvgSpeed->insert(kl->formatNumber(qs_avgspeed, false));
2581
	      ui_sportwatcherWidgetBase.edTotalHeight->insert(kl->formatNumber(qs_ascent, false));
2690
			ui_sportwatcherWidgetBase.edTotalHeight->setAlignment(Qt::AlignRight);
2582
	      ui_sportwatcherWidgetBase.edAvgHR->setAlignment(Qt::AlignRight);
2691
			ui_sportwatcherWidgetBase.edTotalHeight->insert(kl->formatNumber(qs_ascent, false));
2583
	      ui_sportwatcherWidgetBase.edAvgHR->insert(qs_avghr);
2692
			ui_sportwatcherWidgetBase.edAvgHR->setAlignment(Qt::AlignRight);
2584
	      delete qt;
2693
			ui_sportwatcherWidgetBase.edAvgHR->insert(qs_avghr);
2585
	      /* Get the laps. */
2694
			delete qt;
2586
	      laps = 1;
2695
			/* Get the laps. */
2587
 
2696
			laps = 1;
2588
	      for (i = rakt->run->first_lap_index; (unsigned int)i <= rakt->run->last_lap_index; i++)
2697
 
2589
	      {
2698
			for(i = rakt->run->first_lap_index; (unsigned int)i <= rakt->run->last_lap_index; i++)
2590
		 double spd;
2699
			{
2591
		 char *un;
2700
				double spd;
2592
 
2701
				char *un;
2593
		 if ((lap = ds.getLap(i)) == NULL)
2702
 
2594
		    continue;
2703
				if((lap = ds.getLap(i)) == NULL)
2595
 
2704
					continue;
2596
		 qt = garmin_dtime (lap->start_time);
2705
 
2597
		 qs_name.sprintf("Lap %03d - ", laps);
2706
				qt = garmin_dtime(lap->start_time);
2598
		 qs_name.append(kl->formatTime(qt->time(), true));
2707
				qs_name.sprintf("Lap %03d - ", laps);
2599
		 qs_distance.sprintf("%.2f %s", (Units == 1) ? lap->total_distance / 0.304 : lap->total_distance, (Units == 1) ? "ft" : "m");
2708
				qs_name.append(kl->formatTime(qt->time(), true));
2600
		 totdist += (Units == 1) ? lap->total_distance / 0.304 : lap->total_distance;
2709
				qs_distance.sprintf("%.2f %s", (Units == 1) ? lap->total_distance / 0.304 : lap->total_distance, (Units == 1) ? "ft" : "m");
2601
		 qs_totdist.sprintf("%2.f %s", totdist, (Units == 1) ? "ft" : "m");
2710
				totdist += (Units == 1) ? lap->total_distance / 0.304 : lap->total_distance;
2602
		 t = QTime(0, 0, 0, 0);
2711
				qs_totdist.sprintf("%2.f %s", totdist, (Units == 1) ? "ft" : "m");
2603
		 t = t.addMSecs(lap->total_time * 10);
2712
				t = QTime(0, 0, 0, 0);
2604
		 qs_etime = t.toString("hh:mm:ss.zzz");
2713
				t = t.addMSecs(lap->total_time * 10);
2605
		 spd = lap->total_distance / (lap->total_time / 100.0);
2714
				qs_etime = t.toString("hh:mm:ss.zzz");
2606
		 delete qt;
2715
				spd = lap->total_distance / (lap->total_time / 100.0);
2607
		 qt = 0;
2716
				delete qt;
2608
 
2717
				qt = 0;
2609
		 if (Units == 0)
2718
 
2610
		 {
2719
				if(Units == 0)
2611
		    un = (char *)"km/h";
2720
				{
2612
		    spd *= 3.6;
2721
					un = (char *)"km/h";
2613
		 }
2722
					spd *= 3.6;
2614
		 else
2723
				}
2615
		 {
2724
				else
2616
		    spd *= 3.6 / 1.609344;
2725
				{
2617
		    un = (char *)"mph";
2726
					spd *= 3.6 / 1.609344;
2618
		 }
2727
					un = (char *)"mph";
2619
 
2728
				}
2620
		 qs_avgspeed.sprintf("%.2f %s", spd, un);
2729
 
2621
		 qs_maxspeed.sprintf("%.2f %s", (Units == 1) ? lap->max_speed * 3.6 / 1.609344 : lap->max_speed * 3.6, un);
2730
				qs_avgspeed.sprintf("%.2f %s", spd, un);
2622
		 qs_calories.sprintf("%d", lap->calories);
2731
				qs_maxspeed.sprintf("%.2f %s", (Units == 1) ? lap->max_speed * 3.6 / 1.609344 : lap->max_speed * 3.6, un);
2623
 
2732
				qs_calories.sprintf("%d", lap->calories);
2624
		 if (lap->total_distance > 0 && lap->total_time != 0)
2733
 
2625
		 {
2734
				if(lap->total_distance > 0 && lap->total_time != 0)
2626
		    double fact;
2735
				{
2627
 
2736
					double fact;
2628
		    if (Units == 0)
2737
 
2629
		       fact = 1000.0;		// 1 km
2738
					if(Units == 0)
2630
		    else
2739
						fact = 1000.0;		// 1 km
2631
		       fact = 1609.344;		// 1 mile in meters
2740
					else
2632
 
2741
						fact = 1609.344;		// 1 mile in meters
2633
		    long secs = (double)lap->total_time / 10000.0 * (fact / lap->total_distance * 100.0);
2742
 
2634
		    int h = secs / 3600;
2743
					long secs = (double)lap->total_time / 10000.0 * (fact / lap->total_distance * 100.0);
2635
		    int m = (secs - (h * 3600)) / 60;
2744
					int h = secs / 3600;
2636
		    int s = secs - ((h * 3600) + (m * 60));
2745
					int m = (secs - (h * 3600)) / 60;
2637
		    t = QTime(h, m, s, 0);
2746
					int s = secs - ((h * 3600) + (m * 60));
2638
		    qs_avgpace = kl->formatTime(t, true);
2747
					t = QTime(h, m, s, 0);
2639
 
2748
					qs_avgpace = kl->formatTime(t, true);
2640
		    if (Units == 0)
2749
 
2641
		       qs_avgpace.append(QString(" /km"));
2750
					if(Units == 0)
2642
		    else
2751
						qs_avgpace.append(QString(" /km"));
2643
		       qs_avgpace.append(QString(" /mi"));
2752
					else
2644
		 }
2753
						qs_avgpace.append(QString(" /mi"));
2645
 
2754
				}
2646
		 qs_avghr.sprintf("%d bpm", lap->avg_heart_rate);
2755
 
2647
		 qs_maxhr.sprintf("%d bpm", lap->max_heart_rate);
2756
				qs_avghr.sprintf("%d bpm", lap->avg_heart_rate);
2648
 
2757
				qs_maxhr.sprintf("%d bpm", lap->max_heart_rate);
2649
		 anz = 0;
2758
 
2650
		 alt_asc = alt_dsc = 0;
2759
				anz = 0;
2651
		 // Add a new detail line to the tab "Lap details"
2760
				alt_asc = alt_dsc = 0;
2652
		 QTreeWidgetItem * trdetail = new QTreeWidgetItem(ui_sportwatcherWidgetBase.twLaps);
2761
				// Add a new detail line to the tab "Lap details"
2653
 
2762
				QTreeWidgetItem * trdetail = new QTreeWidgetItem(ui_sportwatcherWidgetBase.twLaps);
2654
		 if ((point = ds.getPoint(lap->start_time)) != 0)
2763
 
2655
		 {
2764
				if((point = ds.getPoint(lap->start_time)) != 0)
2656
		    if (point->alt < 20000)
2765
				{
2657
		    {
2766
					if(point->alt < 20000)
2658
		       alt_dsc = alt_asc = point->alt;
2767
					{
2659
 
2768
						alt_dsc = alt_asc = point->alt;
2660
		       if (old_asc == 0)
2769
 
2661
			  old_asc = alt_asc;
2770
						if(old_asc == 0)
2662
 
2771
							old_asc = alt_asc;
2663
		       if (old_dsc == 0)
2772
 
2664
			  old_dsc = alt_dsc;
2773
						if(old_dsc == 0)
2665
		    }
2774
							old_dsc = alt_dsc;
2666
		    else
2775
					}
2667
		       alt_dsc = alt_asc = 0;
2776
					else
2668
 
2777
						alt_dsc = alt_asc = 0;
2669
		    POINT *oldPoint = 0;
2778
 
2670
		    double sc, dist, speed;
2779
					POINT *oldPoint = 0;
2671
		    unsigned long t1, t2;
2780
					double sc, dist, speed;
2672
		    t1 = t2 = 0;
2781
					unsigned long t1, t2;
2673
		    pause = false;
2782
					t1 = t2 = 0;
2674
		    bool ignore = false;
2783
					pause = false;
2675
 
2784
					bool ignore = false;
2676
		    while (point)
2785
 
2677
		    {
2786
					while(point)
2678
		       if (point->time > (lap->start_time + (lap->total_time / 100)))
2787
					{
2679
			 break;
2788
						if(point->time > (lap->start_time + (lap->total_time / 100)))
2680
 
2789
							break;
2681
		       QTreeWidgetItem *child = new QTreeWidgetItem(trdetail);
2790
 
2682
		       qt = garmin_dtime (point->time);
2791
						QTreeWidgetItem *child = new QTreeWidgetItem(trdetail);
2683
		       child->setText(0, kl->formatTime(qt->time(), true));
2792
						qt = garmin_dtime(point->time);
2684
		       child->setTextAlignment(0, Qt::AlignRight);
2793
						child->setText(0, kl->formatTime(qt->time(), true));
2685
		       child->setText(8, QString("%1 %2").arg(kl->formatNumber((double)point->heart_rate, 0)).arg(" bpm"));
2794
						child->setTextAlignment(0, Qt::AlignRight);
2686
		       child->setTextAlignment(8, Qt::AlignRight);
2795
						child->setText(8, QString("%1 %2").arg(kl->formatNumber((double)point->heart_rate, 0)).arg(" bpm"));
2687
 
2796
						child->setTextAlignment(8, Qt::AlignRight);
2688
		       if (point->cadence < 0xff)
2797
 
2689
		       {
2798
						if(point->cadence < 0xff)
2690
			  child->setText(10, kl->formatNumber((double)point->cadence, 0));
2799
						{
2691
			  child->setTextAlignment(10, Qt::AlignRight);
2800
							child->setText(10, kl->formatNumber((double)point->cadence, 0));
2692
		       }
2801
							child->setTextAlignment(10, Qt::AlignRight);
2693
 
2802
						}
2694
		       if (point->alt < 20000)
2803
 
2695
		       {
2804
						if(point->alt < 20000)
2696
		       double alt = (Units == 0) ? (double)point->alt : (double)point->alt / 0.304;
2805
						{
2697
 
2806
							double alt = (Units == 0) ? (double)point->alt : (double)point->alt / 0.304;
2698
			  child->setText(11, QString("%1 %2").arg(kl->formatNumber(alt, 2)).arg((Units == 0) ? QString(" m") : QString(" ft")));
2807
 
2699
			  child->setTextAlignment(11, Qt::AlignRight);
2808
							child->setText(11, QString("%1 %2").arg(kl->formatNumber(alt, 2)).arg((Units == 0) ? QString(" m") : QString(" ft")));
2700
		       }
2809
							child->setTextAlignment(11, Qt::AlignRight);
2701
 
2810
						}
2702
		       if (!oldPoint)
2811
 
2703
			  oldPoint = point;
2812
						if(!oldPoint)
2704
 
2813
							oldPoint = point;
2705
		       if (point->alt > alt_asc && point->alt < 20000)
2814
 
2706
		       {
2815
						if(point->alt > alt_asc && point->alt < 20000)
2707
			  alt_asc = point->alt;
2816
						{
2708
 
2817
							alt_asc = point->alt;
2709
			  if (alt_dsc == 0)
2818
 
2710
			     alt_dsc = point->alt;
2819
							if(alt_dsc == 0)
2711
		       }
2820
								alt_dsc = point->alt;
2712
 
2821
						}
2713
		       if (point->alt < alt_dsc)
2822
 
2714
			  alt_dsc = point->alt;
2823
						if(point->alt < alt_dsc)
2715
 
2824
							alt_dsc = point->alt;
2716
		       // save the min and max values. We need this information to
2825
 
2717
		       // build the graphics.
2826
						// save the min and max values. We need this information to
2718
		       if (point->heart_rate > max_hr && point->heart_rate < 250)
2827
						// build the graphics.
2719
			  max_hr = point->heart_rate;
2828
						if(point->heart_rate > max_hr && point->heart_rate < 250)
2720
 
2829
							max_hr = point->heart_rate;
2721
		       if ((min_hr == 0 && point->heart_rate > 0 && point->heart_rate < 250)
2830
 
2722
			   || (point->heart_rate > 0 && point->heart_rate < min_hr))
2831
						if((min_hr == 0 && point->heart_rate > 0 && point->heart_rate < 250)
2723
			  min_hr = point->heart_rate;
2832
						                  || (point->heart_rate > 0 && point->heart_rate < min_hr))
2724
 
2833
							min_hr = point->heart_rate;
2725
		       if (point->alt < 20000 && max_height < point->alt)
2834
 
2726
			  max_height = point->alt;
2835
						if(point->alt < 20000 && max_height < point->alt)
2727
 
2836
							max_height = point->alt;
2728
		       if (point->alt < 20000 && (min_height == 0.0 || min_height > point->alt))
2837
 
2729
			  min_height = point->alt;
2838
						if(point->alt < 20000 && (min_height == 0.0 || min_height > point->alt))
2730
 
2839
							min_height = point->alt;
2731
		       // Calculate speed of current track
2840
 
2732
		       if (!pause && point->distance > 1.0e10)
2841
						// Calculate speed of current track
2733
		       {
2842
						if(!pause && point->distance > 1.0e10)
2734
			  t1 = point->time;
2843
						{
2735
			  pause = true;
2844
							t1 = point->time;
2736
			  ignore = true;
2845
							pause = true;
2737
		       }
2846
							ignore = true;
2738
		       else if (pause)
2847
						}
2739
		       {
2848
						else if(pause)
2740
			  t2 = point->time;
2849
						{
2741
			  pause = false;
2850
							t2 = point->time;
2742
			  point = ds.getPoint(point->time + 1);
2851
							pause = false;
2743
			  continue;
2852
							point = ds.getPoint(point->time + 1);
2744
		       }
2853
							continue;
2745
 
2854
						}
2746
		       if (!ignore && !pause)
2855
 
2747
		       {
2856
						if(!ignore && !pause)
2748
			  sc = point->time - oldPoint->time;
2857
						{
2749
			  dist = point->distance - oldPoint->distance;
2858
							sc = point->time - oldPoint->time;
2750
 
2859
							dist = point->distance - oldPoint->distance;
2751
			  child->setText(1, QString("%1 %2").arg(kl->formatNumber((Units == 0) ? (double)dist : (double)dist / 0.304, 2)).arg((Units == 0) ? QString(" m") : QString(" ft")));
2860
 
2752
			  child->setTextAlignment(1, Qt::AlignRight);
2861
							child->setText(1, QString("%1 %2").arg(kl->formatNumber((Units == 0) ? (double)dist : (double)dist / 0.304, 2)).arg((Units == 0) ? QString(" m") : QString(" ft")));
2753
 
2862
							child->setTextAlignment(1, Qt::AlignRight);
2754
			  if (t2 > t1)
2863
 
2755
			     sc -= t2 - t1;
2864
							if(t2 > t1)
2756
 
2865
								sc -= t2 - t1;
2757
			  if (sc > 0.0)
2866
 
2758
			  {
2867
							if(sc > 0.0)
2759
			     speed = (dist / sc) * 3.6;
2868
							{
2760
 
2869
								speed = (dist / sc) * 3.6;
2761
			     if (speed > lap->max_speed * 3.6)
2870
 
2762
			        speed = lap->max_speed * 3.6;
2871
								if(speed > lap->max_speed * 3.6)
2763
			  }
2872
									speed = lap->max_speed * 3.6;
2764
			  else
2873
							}
2765
			     speed = 0.0;
2874
							else
2766
 
2875
								speed = 0.0;
2767
			  if (Units == 1)
2876
 
2768
			     speed /= 1.609344;
2877
							if(Units == 1)
2769
 
2878
								speed /= 1.609344;
2770
			  child->setText(5, QString("%1 %2").arg(kl->formatNumber(speed, 2)).arg((Units == 0) ? QString(" Km/h") : QString(" mi/h")));
2879
 
2771
			  child->setTextAlignment(5, Qt::AlignRight);
2880
							child->setText(5, QString("%1 %2").arg(kl->formatNumber(speed, 2)).arg((Units == 0) ? QString(" Km/h") : QString(" mi/h")));
2772
 
2881
							child->setTextAlignment(5, Qt::AlignRight);
2773
			  if (speed > 0.0 && speed < 400.0 && max_speed < speed)
2882
 
2774
			     max_speed = speed;
2883
							if(speed > 0.0 && speed < 400.0 && max_speed < speed)
2775
 
2884
								max_speed = speed;
2776
			  if (speed > 0.0 && (min_speed == 0.0 || min_speed > speed))
2885
 
2777
			     min_speed = speed;
2886
							if(speed > 0.0 && (min_speed == 0.0 || min_speed > speed))
2778
 
2887
								min_speed = speed;
2779
			  oldPoint = point;
2888
 
2780
		       }
2889
							oldPoint = point;
2781
 
2890
						}
2782
		       if (!pause && ignore)
2891
 
2783
			  ignore = false;
2892
						if(!pause && ignore)
2784
 
2893
							ignore = false;
2785
		       if (point->heart_rate > 0 && point->heart_rate < 250)
2894
 
2786
		       {
2895
						if(point->heart_rate > 0 && point->heart_rate < 250)
2787
			  avg_hr += point->heart_rate;
2896
						{
2788
			  men++;
2897
							avg_hr += point->heart_rate;
2789
		       }
2898
							men++;
2790
 
2899
						}
2791
		       point = ds.getPoint(point->time + 1);
2900
 
2792
		    }
2901
						point = ds.getPoint(point->time + 1);
2793
 
2902
					}
2794
		    if (old_asc < alt_asc)
2903
 
2795
		       sum_asc += (alt_asc - old_asc);
2904
					if(old_asc < alt_asc)
2796
 
2905
						sum_asc += (alt_asc - old_asc);
2797
		    if (old_dsc > alt_dsc)
2906
 
2798
		       sum_dsc += (old_dsc - alt_dsc);
2907
					if(old_dsc > alt_dsc)
2799
 
2908
						sum_dsc += (old_dsc - alt_dsc);
2800
		    old_asc = alt_asc;
2909
 
2801
		    old_dsc = alt_dsc;
2910
					old_asc = alt_asc;
2802
		    qs_ascent.sprintf("%.2f %s", (Units == 1) ? (alt_asc / 0.304) : alt_asc, (Units == 1) ? "ft" : "m");
2911
					old_dsc = alt_dsc;
2803
		    qs_descent.sprintf("%.2f %s", (Units == 1) ? (alt_dsc / 0.304) : alt_dsc, (Units == 1) ? "ft" : "m");
2912
					qs_ascent.sprintf("%.2f %s", (Units == 1) ? (alt_asc / 0.304) : alt_asc, (Units == 1) ? "ft" : "m");
2804
		 }
2913
					qs_descent.sprintf("%.2f %s", (Units == 1) ? (alt_dsc / 0.304) : alt_dsc, (Units == 1) ? "ft" : "m");
2805
 
2914
				}
2806
		 if (lap->avg_cadence != 0xff)
2915
 
2807
		    qs_avgcadence.sprintf("%d", lap->avg_cadence);
2916
				if(lap->avg_cadence != 0xff)
2808
		 // Add a new detail line to the tab "Summary"
2917
					qs_avgcadence.sprintf("%d", lap->avg_cadence);
2809
		 K3ListViewItem *edetail = new K3ListViewItem(element, qs_name,
2918
 
2810
			kl->formatNumber(qs_distance, false),
2919
				// Add a new detail line to the tab "Summary"
2811
			qs_etime, qs_avgpace, kl->formatNumber(qs_avgspeed, false),
2920
				K3ListViewItem *edetail = new K3ListViewItem(element, qs_name,
2812
			kl->formatNumber(qs_maxspeed, false), qs_calories, qs_avghr);
2921
				                  kl->formatNumber(qs_distance, false),
2813
		 edetail->setText(8, qs_maxhr);
2922
				                  qs_etime, qs_avgpace, kl->formatNumber(qs_avgspeed, false),
2814
		 edetail->setText(9, qs_avgcadence);
2923
				                  kl->formatNumber(qs_maxspeed, false), qs_calories, qs_avghr);
2815
		 edetail->setText(10, kl->formatNumber(qs_ascent, false));
2924
				edetail->setText(8, qs_maxhr);
2816
		 edetail->setText(11, kl->formatNumber(qs_descent, false));
2925
				edetail->setText(9, qs_avgcadence);
2817
		 edetail->setPixmap(0, KIcon(QString("history")).pixmap(16));
2926
				edetail->setText(10, kl->formatNumber(qs_ascent, false));
2818
		 QPixmap qpx = KIcon(QString("other")).pixmap(16);
2927
				edetail->setText(11, kl->formatNumber(qs_descent, false));
2819
		 
2928
				edetail->setPixmap(0, KIcon(QString("history")).pixmap(16));
2820
		 trdetail->setText(0, qs_etime);
2929
				QPixmap qpx = KIcon(QString("other")).pixmap(16);
2821
		 trdetail->setTextAlignment(0, Qt::AlignRight);
2930
 
2822
		 trdetail->setText(1, kl->formatNumber(qs_distance));
2931
				trdetail->setText(0, qs_etime);
2823
		 trdetail->setTextAlignment(1, Qt::AlignRight);
2932
				trdetail->setTextAlignment(0, Qt::AlignRight);
2824
		 trdetail->setText(2, kl->formatNumber(qs_totdist));
2933
				trdetail->setText(1, kl->formatNumber(qs_distance));
2825
		 trdetail->setTextAlignment(2, Qt::AlignRight);
2934
				trdetail->setTextAlignment(1, Qt::AlignRight);
2826
		 trdetail->setText(4, qs_avgpace);
2935
				trdetail->setText(2, kl->formatNumber(qs_totdist));
2827
		 trdetail->setTextAlignment(4, Qt::AlignRight);
2936
				trdetail->setTextAlignment(2, Qt::AlignRight);
2828
		 trdetail->setText(5, kl->formatNumber(qs_avgspeed, false));
2937
				trdetail->setText(4, qs_avgpace);
2829
		 trdetail->setTextAlignment(5, Qt::AlignRight);
2938
				trdetail->setTextAlignment(4, Qt::AlignRight);
2830
		 trdetail->setText(6, kl->formatNumber(qs_maxspeed, false));
2939
				trdetail->setText(5, kl->formatNumber(qs_avgspeed, false));
2831
		 trdetail->setTextAlignment(6, Qt::AlignRight);
2940
				trdetail->setTextAlignment(5, Qt::AlignRight);
2832
		 trdetail->setText(7, qs_calories);
2941
				trdetail->setText(6, kl->formatNumber(qs_maxspeed, false));
2833
		 trdetail->setTextAlignment(7, Qt::AlignRight);
2942
				trdetail->setTextAlignment(6, Qt::AlignRight);
2834
		 trdetail->setText(8, qs_avghr);
2943
				trdetail->setText(7, qs_calories);
2835
		 trdetail->setTextAlignment(8, Qt::AlignRight);
2944
				trdetail->setTextAlignment(7, Qt::AlignRight);
2836
		 trdetail->setText(9, qs_maxhr);
2945
				trdetail->setText(8, qs_avghr);
2837
		 trdetail->setTextAlignment(9, Qt::AlignRight);
2946
				trdetail->setTextAlignment(8, Qt::AlignRight);
2838
		 trdetail->setText(10, qs_avgcadence);
2947
				trdetail->setText(9, qs_maxhr);
2839
		 trdetail->setTextAlignment(10, Qt::AlignRight);
2948
				trdetail->setTextAlignment(9, Qt::AlignRight);
2840
		 trdetail->setText(11, kl->formatNumber(qs_ascent, false));
2949
				trdetail->setText(10, qs_avgcadence);
2841
		 trdetail->setTextAlignment(11, Qt::AlignRight);
2950
				trdetail->setTextAlignment(10, Qt::AlignRight);
2842
		 
2951
				trdetail->setText(11, kl->formatNumber(qs_ascent, false));
2843
		 switch (rakt->run->sport_type)
2952
				trdetail->setTextAlignment(11, Qt::AlignRight);
2844
		 {
2953
 
2845
		    case D1000_running:
2954
				switch(rakt->run->sport_type)
2846
		       edetail->setPixmap(0, KIcon(QString("spw-running")).pixmap(16));
2955
				{
2847
		    break;
2956
					case D1000_running:
2848
 
2957
						edetail->setPixmap(0, KIcon(QString("spw-running")).pixmap(16));
2849
		    case D1000_biking:
2958
						break;
2850
		       edetail->setPixmap(0, KIcon(QString("bike")).pixmap(16));
2959
 
2851
		    break;
2960
					case D1000_biking:
2852
 
2961
						edetail->setPixmap(0, KIcon(QString("bike")).pixmap(16));
2853
		    case D1000_other:
2962
						break;
2854
		       edetail->setPixmap(0, qpx);
2963
 
2855
		    break;
2964
					case D1000_other:
2856
 
2965
						edetail->setPixmap(0, qpx);
2857
		    default:
2966
						break;
2858
		       edetail->setPixmap(0, qpx);
2967
 
2859
		 }
2968
					default:
2860
 
2969
						edetail->setPixmap(0, qpx);
2861
		 ui_sportwatcherWidgetBase.liLaps->clearSelection();
2970
				}
2862
		 element->insertItem(edetail);
2971
 
2863
		 delete qt;
2972
				ui_sportwatcherWidgetBase.liLaps->clearSelection();
2864
		 laps++;
2973
				element->insertItem(edetail);
2865
	      }
2974
				delete qt;
2866
 
2975
				laps++;
2867
	      qs_ascent.sprintf("%.2f %s", (Units == 1) ? sum_asc / 0.304 : sum_asc, (Units == 1) ? "ft" : "m");
2976
			}
2868
	      qs_descent.sprintf("%.2f %s", (Units == 1) ? sum_dsc / 0.304 : sum_dsc, (Units == 1) ? "ft" : "m");
2977
 
2869
      	      element->setText(10, qs_ascent);
2978
			qs_ascent.sprintf("%.2f %s", (Units == 1) ? sum_asc / 0.304 : sum_asc, (Units == 1) ? "ft" : "m");
2870
	      element->setText(11, qs_descent);
2979
			qs_descent.sprintf("%.2f %s", (Units == 1) ? sum_dsc / 0.304 : sum_dsc, (Units == 1) ? "ft" : "m");
2871
	      qs_ascent.sprintf("%s %s", (Units == 1) ? kl->formatNumber(ds.getAscend() / 0.304, 2).toAscii().data() : kl->formatNumber(ds.getAscend(), 2).toAscii().data(), (Units == 1) ? "ft" : "m");
2980
			element->setText(10, qs_ascent);
2872
	      ui_sportwatcherWidgetBase.edTotalHeight->clear();
2981
			element->setText(11, qs_descent);
2873
	      ui_sportwatcherWidgetBase.edTotalHeight->insert(qs_ascent);
2982
			qs_ascent.sprintf("%s %s", (Units == 1) ? kl->formatNumber(ds.getAscend() / 0.304, 2).toAscii().data() : kl->formatNumber(ds.getAscend(), 2).toAscii().data(), (Units == 1) ? "ft" : "m");
2874
	      ui_sportwatcherWidgetBase.edLapNumber->setAlignment(Qt::AlignRight);
2983
			ui_sportwatcherWidgetBase.edTotalHeight->clear();
2875
	      ui_sportwatcherWidgetBase.edLapNumber->insert(kl->formatNumber((double)laps, 0));
2984
			ui_sportwatcherWidgetBase.edTotalHeight->insert(qs_ascent);
2876
	   }
2985
			ui_sportwatcherWidgetBase.edLapNumber->setAlignment(Qt::AlignRight);
-
 
2986
			ui_sportwatcherWidgetBase.edLapNumber->insert(kl->formatNumber((double)laps, 0));
-
 
2987
		}
2877
 
2988
 
2878
	   rakt = rakt->next;
2989
		rakt = rakt->next;
2879
	}
2990
	}
2880
 
2991
 
2881
	if (men > 0)
2992
	if(men > 0)
2882
	   avg_hr /= men;
2993
		avg_hr /= men;
2883
	else
2994
	else
2884
	   min_hr = max_hr = avg_hr = 0;
2995
		min_hr = max_hr = avg_hr = 0;
2885
}
2996
}
2886
 
2997
 
2887
void sportwatcherWidget::showTrack()
2998
void sportwatcherWidget::showTrack()
2888
{
2999
{
2889
	showTrack(0, QRect(0, 0, 0, 0), 0);
3000
	showTrack(0, QRect(0, 0, 0, 0), 0);
Line 2894... Line 3005...
2894
	showTrack(zoom, mapPan, mapLap);
3005
	showTrack(zoom, mapPan, mapLap);
2895
}
3006
}
2896
 
3007
 
2897
void sportwatcherWidget::showTrack(int zoom, const QRect &pan, LAP *lap)
3008
void sportwatcherWidget::showTrack(int zoom, const QRect &pan, LAP *lap)
2898
{
3009
{
2899
int width, height;
3010
	int width, height;
2900
double x1, y1, x2, y2;
3011
	double x1, y1, x2, y2;
2901
int a, top, left, panX, panY;
3012
	int a, top, left, panX, panY;
2902
uint32 i;
3013
	uint32 i;
2903
double coordW, coordH, tick;
3014
	double coordW, coordH, tick;
2904
double meterW, dist, fact;
3015
	double meterW, dist, fact;
2905
QPainter paint;
3016
	QPainter paint;
2906
posn_type posNW, posSE, posLXY, posRXY;
3017
	posn_type posNW, posSE, posLXY, posRXY;
2907
POINT *point;
3018
	POINT *point;
2908
bool Fgeo = false;
3019
	bool Fgeo = false;
2909
bool Data = false;
3020
	bool Data = false;
2910
#if defined HAVE_GDAL
3021
#if defined HAVE_GDAL
2911
QString fName = MAP;
3022
	QString fName = MAP;
2912
//double adfGeoTransform[6];
3023
//double adfGeoTransform[6];
2913
GDALDataset *poDataset = 0;
3024
	GDALDataset *poDataset = 0;
2914
GDALRasterBand *poBand = 0;
3025
	GDALRasterBand *poBand = 0;
2915
unsigned char *pafScanline = 0;
3026
	unsigned char *pafScanline = 0;
2916
unsigned char *pafScanlineRed = 0;
3027
	unsigned char *pafScanlineRed = 0;
2917
unsigned char *pafScanlineGreen = 0;
3028
	unsigned char *pafScanlineGreen = 0;
2918
unsigned char *pafScanlineBlue = 0;
3029
	unsigned char *pafScanlineBlue = 0;
2919
unsigned char *pafScanlineAlpha = 0;
3030
	unsigned char *pafScanlineAlpha = 0;
2920
int nXSize, nYSize;
3031
	int nXSize, nYSize;
2921
int xOff, yOff;
3032
	int xOff, yOff;
2922
double oriLeftLon, oriLeftLat, oriRightLon, oriRightLat;
3033
	double oriLeftLon, oriLeftLat, oriRightLon, oriRightLat;
2923
#endif
3034
#endif
2924
 
3035
 
2925
	if (!DIRTY || curTab == 2 || curTab == 3)
3036
	if(!DIRTY || curTab == 2 || curTab == 3)
2926
	   return;
3037
		return;
2927
 
3038
 
2928
	if (!gmn)
3039
	if(!gmn)
2929
	   return;
3040
		return;
2930
 
3041
 
2931
	QApplication::setOverrideCursor (QCursor(Qt::WaitCursor));
3042
	QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
2932
 
3043
 
2933
	if (zoom != zfactor)
3044
	if(zoom != zfactor)
2934
	   zfactor = zoom;
3045
		zfactor = zoom;
2935
 
3046
 
2936
	if (mapLap != lap)
3047
	if(mapLap != lap)
2937
	   mapLap = lap;
3048
		mapLap = lap;
2938
 
3049
 
2939
	y2 = x2 = 0;
3050
	y2 = x2 = 0;
2940
#if defined HAVE_GDAL
3051
#if defined HAVE_GDAL
2941
	nXSize = nYSize = 0;
3052
	nXSize = nYSize = 0;
2942
	KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig);
3053
	KConfig cfg(QString("sportwatcher.rc"), KConfig::SimpleConfig);
2943
	KConfigGroup wms (&cfg, "WMS");
3054
	KConfigGroup wms(&cfg, "WMS");
2944
	bool square = wms.readEntry("Square", false);
3055
	bool square = wms.readEntry("Square", false);
2945
	int CorrX = wms.readEntry("CorrX", 0);
3056
	int CorrX = wms.readEntry("CorrX", 0);
2946
	int CorrY = wms.readEntry("CorrY", 0);
3057
	int CorrY = wms.readEntry("CorrY", 0);
2947
	KConfigGroup ic (&cfg, "ImageCoords");
3058
	KConfigGroup ic(&cfg, "ImageCoords");
2948
	oriLeftLon = ic.readEntry("LeftLon", 0.0);
3059
	oriLeftLon = ic.readEntry("LeftLon", 0.0);
2949
	oriLeftLat = ic.readEntry("LeftLat", 0.0);
3060
	oriLeftLat = ic.readEntry("LeftLat", 0.0);
2950
	oriRightLon = ic.readEntry("RightLon", 0.0);
3061
	oriRightLon = ic.readEntry("RightLon", 0.0);
2951
	oriRightLat = ic.readEntry("RightLat", 0.0);
3062
	oriRightLat = ic.readEntry("RightLat", 0.0);
2952
//	int isrs = ic.readEntry("SRS", 0);
3063
//	int isrs = ic.readEntry("SRS", 0);
2953
#endif
3064
#endif
-
 
3065
 
2954
	if (curTab == 0 && !ActivePrint)
3066
	if(curTab == 0 && !ActivePrint)
2955
	{
3067
	{
2956
	   width = ui_sportwatcherWidgetBase.imgMap->width() - 2;
3068
		width = ui_sportwatcherWidgetBase.imgMap->width() - 2;
2957
	   height = ui_sportwatcherWidgetBase.imgMap->height();
3069
		height = ui_sportwatcherWidgetBase.imgMap->height();
2958
	}
3070
	}
2959
	else if (ActivePrint)
3071
	else if(ActivePrint)
2960
	{
3072
	{
2961
	   width = pmPrMap.width();
3073
		width = pmPrMap.width();
2962
	   height = pmPrMap.height();
3074
		height = pmPrMap.height();
2963
	}
3075
	}
2964
	else
3076
	else
2965
	{
3077
	{
2966
	   width = ui_sportwatcherWidgetBase.grMap->width() - 2;
3078
		width = ui_sportwatcherWidgetBase.grMap->width() - 2;
2967
	   height = ui_sportwatcherWidgetBase.grMap->height();
3079
		height = ui_sportwatcherWidgetBase.grMap->height();
2968
	}
3080
	}
-
 
3081
 
2969
#if defined HAVE_GDAL
3082
#if defined HAVE_GDAL
-
 
3083
 
2970
	if (MapType == MPT_WMS && square)
3084
	if(MapType == MPT_WMS && square)
2971
	   pmMap = QPixmap(width / (int)mFactor * (int)mFactor, height / (int)mFactor * (int)mFactor);
3085
		pmMap = QPixmap(width / (int)mFactor * (int)mFactor, height / (int)mFactor * (int)mFactor);
2972
	else
3086
	else
2973
	   pmMap = QPixmap(width, height);
3087
		pmMap = QPixmap(width, height);
-
 
3088
 
2974
#else
3089
#else
2975
	pmMap = QPixmap(width, height);
3090
	pmMap = QPixmap(width, height);
2976
#endif
3091
#endif
-
 
3092
 
2977
	if (pmMap.isNull())
3093
	if(pmMap.isNull())
2978
	   return;
3094
		return;
2979
 
3095
 
2980
	// Here we begin do draw something
3096
	// Here we begin do draw something
2981
	paint.begin(&pmMap);
3097
	paint.begin(&pmMap);
2982
 
3098
 
2983
	panX = panY = 0;
3099
	panX = panY = 0;
2984
 
3100
 
2985
	if (stateHand && mapPan != pan)
3101
	if(stateHand && mapPan != pan)
2986
	{
3102
	{
2987
	   mapPan = pan;
3103
		mapPan = pan;
2988
	   panX = mapPan.right() - mapPan.left();
3104
		panX = mapPan.right() - mapPan.left();
2989
	   panY = mapPan.bottom() - mapPan.top();
3105
		panY = mapPan.bottom() - mapPan.top();
2990
	   oldTransX += (double)panX;
3106
		oldTransX += (double)panX;
2991
	   oldTransY += (double)panY;
3107
		oldTransY += (double)panY;
2992
	}
3108
	}
2993
 
3109
 
2994
	memset(&posNW, 0, sizeof(posn_type));
3110
	memset(&posNW, 0, sizeof(posn_type));
2995
	memset(&posSE, 0, sizeof(posn_type));
3111
	memset(&posSE, 0, sizeof(posn_type));
2996
 
3112
 
Line 3000... Line 3116...
3000
	posNW.lon = -180.0;
3116
	posNW.lon = -180.0;
3001
 
3117
 
3002
	/*
3118
	/*
3003
	 * Find out the corners of our track (NW, NE, SE, SW)
3119
	 * Find out the corners of our track (NW, NE, SE, SW)
3004
	 */
3120
	 */
3005
	if (mapLap)
3121
	if(mapLap)
3006
	   i = mapLap->start_time;
3122
		i = mapLap->start_time;
3007
	else
3123
	else
3008
	   i = 0;
3124
		i = 0;
3009
	
3125
 
3010
	while ((point = ds.getPoint(i)) != 0)
3126
	while((point = ds.getPoint(i)) != 0)
3011
	{
3127
	{
3012
	   if (mapLap && point->time > (mapLap->start_time + (mapLap->total_time / 100)))
3128
		if(mapLap && point->time > (mapLap->start_time + (mapLap->total_time / 100)))
3013
	      break;
3129
			break;
3014
 
3130
 
3015
	   if (point->posn.lat == 0x7fffffff || point->posn.lon == 0x7fffffff)
3131
		if(point->posn.lat == 0x7fffffff || point->posn.lon == 0x7fffffff)
3016
	   {
3132
		{
3017
	      i = point->time + 1;
3133
			i = point->time + 1;
3018
	      continue;
3134
			continue;
3019
	   }
3135
		}
3020
 
3136
 
3021
	   if (SEMI2DEG(point->posn.lat) > posNW.lat)
3137
		if(SEMI2DEG(point->posn.lat) > posNW.lat)
3022
	      posNW.lat = SEMI2DEG(point->posn.lat);
3138
			posNW.lat = SEMI2DEG(point->posn.lat);
3023
 
3139
 
3024
	   if (SEMI2DEG(point->posn.lat) < posSE.lat)
3140
		if(SEMI2DEG(point->posn.lat) < posSE.lat)
3025
	      posSE.lat = SEMI2DEG(point->posn.lat);
3141
			posSE.lat = SEMI2DEG(point->posn.lat);
3026
 
3142
 
3027
	   if (SEMI2DEG(point->posn.lon) > posNW.lon)
3143
		if(SEMI2DEG(point->posn.lon) > posNW.lon)
3028
	      posNW.lon = SEMI2DEG(point->posn.lon);
3144
			posNW.lon = SEMI2DEG(point->posn.lon);
3029
 
3145
 
3030
	   if (SEMI2DEG(point->posn.lon) < posSE.lon)
3146
		if(SEMI2DEG(point->posn.lon) < posSE.lon)
3031
	      posSE.lon = SEMI2DEG(point->posn.lon);
3147
			posSE.lon = SEMI2DEG(point->posn.lon);
3032
 
3148
 
3033
	   i = point->time + 1;
3149
		i = point->time + 1;
3034
	   Data = true;
3150
		Data = true;
3035
	}
3151
	}
3036
 
3152
 
3037
	coordW = (posNW.lon > posSE.lon) ? posNW.lon - posSE.lon : posSE.lon - posNW.lon;
3153
	coordW = (posNW.lon > posSE.lon) ? posNW.lon - posSE.lon : posSE.lon - posNW.lon;
3038
	coordH = (posNW.lat > posSE.lat) ? posNW.lat - posSE.lat : posSE.lat - posNW.lat;
3154
	coordH = (posNW.lat > posSE.lat) ? posNW.lat - posSE.lat : posSE.lat - posNW.lat;
3039
	meterW = ds.earth_distance(posNW.lat, posNW.lon, posNW.lat, posSE.lon);
3155
	meterW = ds.earth_distance(posNW.lat, posNW.lon, posNW.lat, posSE.lon);
3040
 
3156
 
3041
	// define the ticks to translate the GPS coordinates into pixels.
3157
	// define the ticks to translate the GPS coordinates into pixels.
3042
	// The track should be centered and we have to calculate the
3158
	// The track should be centered and we have to calculate the
3043
	// rectangular within we draw the track.
3159
	// rectangular within we draw the track.
3044
	if (coordW < coordH)
3160
	if(coordW < coordH)
3045
	{
3161
	{
3046
	   tick = (double)width / coordW + (double)zoom;
3162
		tick = (double)width / coordW + (double)zoom;
3047
 
3163
 
3048
	   if ((tick * coordH) > height)
3164
		if((tick * coordH) > height)
3049
	      tick = (double)height / coordH + (double)zoom;
3165
			tick = (double)height / coordH + (double)zoom;
3050
	}
3166
	}
3051
	else
3167
	else
3052
	{
3168
	{
3053
	   tick = (double)height / coordH + (double)zoom;
3169
		tick = (double)height / coordH + (double)zoom;
3054
 
3170
 
3055
	   if ((tick * coordW) > width)
3171
		if((tick * coordW) > width)
3056
	      tick = (double)width / coordW + (double)zoom;
3172
			tick = (double)width / coordW + (double)zoom;
3057
	}
3173
	}
3058
 
3174
 
3059
	left = width - (width - tick * coordW) / 2;
3175
	left = width - (width - tick * coordW) / 2;
3060
	top = (height - tick * coordH) / 2;
3176
	top = (height - tick * coordH) / 2;
3061
 
3177
 
3062
	a = tick * coordW;
3178
	a = tick * coordW;
3063
 
3179
 
3064
	if (Units == 0)
3180
	if(Units == 0)
3065
	   dist = meterW / a;			// Meters
3181
		dist = meterW / a;			// Meters
3066
	else
3182
	else
3067
	   dist = meterW * 1.609344 / a;	// 1/1000 mile (5.28 feet)
3183
		dist = meterW * 1.609344 / a;	// 1/1000 mile (5.28 feet)
3068
 
3184
 
3069
#if defined HAVE_GDAL
3185
#if defined HAVE_GDAL
3070
	geoRect.llat = 0.0;
3186
	geoRect.llat = 0.0;
3071
	geoRect.llon = 0.0;
3187
	geoRect.llon = 0.0;
3072
	geoRect.rlat = 0.0;
3188
	geoRect.rlat = 0.0;
3073
	geoRect.rlon = 0.0;
3189
	geoRect.rlon = 0.0;
3074
	geoRect.width = width;
3190
	geoRect.width = width;
3075
	geoRect.height = height;
3191
	geoRect.height = height;
-
 
3192
 
3076
	/*
3193
	/*
3077
	 * If we have a map file, we try to read it and if successfull,
3194
	 * If we have a map file, we try to read it and if successfull,
3078
	 * we should get a map painted.
3195
	 * we should get a map painted.
3079
	 *
3196
	 *
3080
	 * Currently only WMS-Server is supported, allthough GDAL allows
3197
	 * Currently only WMS-Server is supported, allthough GDAL allows
3081
	 * several other formats too.
3198
	 * several other formats too.
3082
	 */
3199
	 */
3083
	if (!MAP.isEmpty() && Data)
3200
	if(!MAP.isEmpty() && Data)
3084
	{
3201
	{
3085
	bool writeTag = true;
3202
		bool writeTag = true;
3086
	double mtx, mty;
3203
		double mtx, mty;
3087
	double vx, vy;
3204
		double vx, vy;
3088
 
3205
 
3089
	   xOff = yOff = 0;
3206
		xOff = yOff = 0;
3090
	   posRXY.lon = posNW.lon + (width - left + oldTransX) / tick;
3207
		posRXY.lon = posNW.lon + (width - left + oldTransX) / tick;
3091
	   posLXY.lat = posNW.lat + (top + oldTransY) / tick;
3208
		posLXY.lat = posNW.lat + (top + oldTransY) / tick;
3092
	   posLXY.lon = posSE.lon - (left - a - oldTransX) / tick;
3209
		posLXY.lon = posSE.lon - (left - a - oldTransX) / tick;
3093
	   posRXY.lat = posSE.lat - (height - top - (tick * coordH) - oldTransY) / tick;
3210
		posRXY.lat = posSE.lat - (height - top - (tick * coordH) - oldTransY) / tick;
3094
	   geoRect.llat = posLXY.lat;
3211
		geoRect.llat = posLXY.lat;
3095
	   geoRect.llon = posLXY.lon;
3212
		geoRect.llon = posLXY.lon;
3096
	   geoRect.rlat = posRXY.lat;
3213
		geoRect.rlat = posRXY.lat;
3097
	   geoRect.rlon = posRXY.lon;
3214
		geoRect.rlon = posRXY.lon;
3098
	   // width and height of map in meters
3215
		// width and height of map in meters
3099
	   mtx = ds.earth_distance(posRXY.lat, posRXY.lon, posRXY.lat, posLXY.lon);
3216
		mtx = ds.earth_distance(posRXY.lat, posRXY.lon, posRXY.lat, posLXY.lon);
3100
	   mty = ds.earth_distance(posRXY.lat, posRXY.lon, posLXY.lat, posRXY.lon);
3217
		mty = ds.earth_distance(posRXY.lat, posRXY.lon, posLXY.lat, posRXY.lon);
3101
 
3218
 
3102
	   // factor to correct the map, in case we use a WMS server
3219
		// factor to correct the map, in case we use a WMS server
3103
	   if (MapType == MPT_WMS)
3220
		if(MapType == MPT_WMS)
3104
	   {
3221
		{
3105
	      vx = (posRXY.lon - posLXY.lon) / mtx * CorrX;
3222
			vx = (posRXY.lon - posLXY.lon) / mtx * CorrX;
3106
	      vy = (posRXY.lat - posLXY.lat) / mty * CorrY;
3223
			vy = (posRXY.lat - posLXY.lat) / mty * CorrY;
3107
	      posRXY.lon += vx;
3224
			posRXY.lon += vx;
3108
	      posRXY.lat += vy;
3225
			posRXY.lat += vy;
3109
	      posLXY.lon += vx;
3226
			posLXY.lon += vx;
3110
	      posLXY.lat += vy;
3227
			posLXY.lat += vy;
3111
	   }
3228
		}
3112
 
3229
 
3113
	   /*
3230
		/*
3114
	    * Write a control file for GDAL, if we use a WMS server.
3231
		 * Write a control file for GDAL, if we use a WMS server.
3115
	    * Warp an image if we use PNG or BMP or GIF.
3232
		 * Warp an image if we use PNG or BMP or GIF.
3116
	    * Warp a region if we use TIFF
3233
		 * Warp a region if we use TIFF
3117
	    */
3234
		 */
3118
	   if (MapType == MPT_WMS)
3235
		if(MapType == MPT_WMS)
3119
	      writeTag = writeWMSTag(posLXY.lon, posLXY.lat, posRXY.lon, posRXY.lat, width, height);
3236
			writeTag = writeWMSTag(posLXY.lon, posLXY.lat, posRXY.lon, posRXY.lat, width, height);
3120
 
3237
 
3121
	   if (MapType == MPT_GIF || MapType == MPT_BMP || MapType == MPT_PNG ||
3238
		if(MapType == MPT_GIF || MapType == MPT_BMP || MapType == MPT_PNG ||
3122
	       MapType == MPT_SGI || MapType == MPT_TIF)
3239
		                  MapType == MPT_SGI || MapType == MPT_TIF)
3123
	      writeTag = warpImage(MAP, &fName);
3240
			writeTag = warpImage(MAP, &fName);
3124
 
3241
 
3125
	   if (writeTag)
3242
		if(writeTag)
3126
	   {
3243
		{
3127
	      if (MapType != MPT_SHP && (poDataset = (GDALDataset *)GDALOpen (fName.toAscii().constData(), GA_ReadOnly)) != NULL)
3244
			if(MapType != MPT_SHP && (poDataset = (GDALDataset *)GDALOpen(fName.toAscii().constData(), GA_ReadOnly)) != NULL)
3128
	      {
3245
			{
3129
		 QPixmap bild;
3246
				QPixmap bild;
3130
		 int nRasterCount = poDataset->GetRasterCount();
3247
				int nRasterCount = poDataset->GetRasterCount();
3131
		 int nXBlock, nYBlock;
3248
				int nXBlock, nYBlock;
3132
		 GDALColorTable *pCT, *pCTb, *pCTr, *pCTg, *pCTa;
3249
				GDALColorTable *pCT, *pCTb, *pCTr, *pCTg, *pCTa;
3133
 
3250
 
3134
		 int             bGotMin, bGotMax;
3251
				int      bGotMin, bGotMax;
3135
		 int		 tTypeLen, tColor, tColorEntrys;
3252
				int		 tTypeLen; //, tColorEntrys;
3136
		 GDALDataType    tRasterType;
3253
				GDALDataType tRasterType;
3137
		 double          adfMinMax[2];
3254
				double   adfMinMax[2];
3138
 
3255
 
3139
		 pCT = pCTb = pCTr = pCTg = pCTa = 0;
3256
				pCT = pCTb = pCTr = pCTg = pCTa = 0;
3140
		 tTypeLen = 0;
3257
				tTypeLen = 0;
3141
		 pafScanlineRed = pafScanlineGreen = pafScanlineBlue = pafScanlineAlpha = 0;
3258
				pafScanlineRed = pafScanlineGreen = pafScanlineBlue = pafScanlineAlpha = 0;
3142
		 Fgeo = true;
3259
				Fgeo = true;
3143
		 /*
3260
 
3144
		  * Read every raster band.
3261
				/*
3145
		  *
3262
				 * Read every raster band.
3146
		  * If we get 3 raster bands, the image is a 24 bit image.
3263
				 *
3147
		  * If we get 4 raster bands, the image is probably a 24 bit
3264
				 * If we get 3 raster bands, the image is a 24 bit image.
3148
		  * image with an alpha channel. Currently the alpha channel
3265
				 * If we get 4 raster bands, the image is probably a 24 bit
3149
		  * is ignored!
3266
				 * image with an alpha channel. Currently the alpha channel
3150
		  * If we have 1 raster band, the image is 8 bit monochrom.
3267
				 * is ignored!
3151
		  * Otherwise the image is undefined and the results are also.
3268
				 * If we have 1 raster band, the image is 8 bit monochrom.
3152
		  */
3269
				 * Otherwise the image is undefined and the results are also.
3153
		 for (a = 1; a <= nRasterCount; a++)
3270
				 */
3154
		 {
3271
				for(a = 1; a <= nRasterCount; a++)
3155
		    if (!Fgeo)
3272
				{
3156
		       break;
3273
					if(!Fgeo)
3157
 
3274
						break;
3158
		    if (!(poBand = poDataset->GetRasterBand (a)))
3275
 
3159
		    {
3276
					if(!(poBand = poDataset->GetRasterBand(a)))
3160
		       paint.end();
3277
					{
3161
		       return;
3278
						paint.end();
3162
		    }
3279
						return;
3163
 
3280
					}
3164
		    poBand->GetBlockSize (&nXBlock, &nYBlock);
3281
 
3165
		    nXSize = poBand->GetXSize();
3282
					poBand->GetBlockSize(&nXBlock, &nYBlock);
3166
		    nYSize = poBand->GetYSize();
3283
					nXSize = poBand->GetXSize();
3167
		    tRasterType = poBand->GetRasterDataType ();
3284
					nYSize = poBand->GetYSize();
3168
		    tTypeLen = GDALGetDataTypeSize (tRasterType) / 8;	// We need Bytes not Bits!
3285
					tRasterType = poBand->GetRasterDataType();
3169
		    tColor = poBand->GetColorInterpretation ();
3286
					tTypeLen = GDALGetDataTypeSize(tRasterType) / 8;	// We need Bytes not Bits!
3170
 
3287
//					tColor = poBand->GetColorInterpretation();
3171
		    adfMinMax[0] = poBand->GetMinimum (&bGotMin);
3288
 
3172
		    adfMinMax[1] = poBand->GetMaximum (&bGotMax);
3289
					adfMinMax[0] = poBand->GetMinimum(&bGotMin);
3173
 
3290
					adfMinMax[1] = poBand->GetMaximum(&bGotMax);
3174
		    if (!(bGotMin && bGotMax))
3291
 
3175
		       GDALComputeRasterMinMax ((GDALRasterBandH)poBand, TRUE, adfMinMax);
3292
					if(!(bGotMin && bGotMax))
3176
 
3293
						GDALComputeRasterMinMax((GDALRasterBandH)poBand, TRUE, adfMinMax);
3177
		    if ((pCT = poBand->GetColorTable()) != NULL)
3294
 
3178
		       tColorEntrys = poBand->GetColorTable()->GetColorEntryCount();
3295
//					if((pCT = poBand->GetColorTable()) != NULL)
3179
 
3296
//						tColorEntrys = poBand->GetColorTable()->GetColorEntryCount();
3180
		    switch (a)
3297
 
3181
		    {
3298
					switch(a)
3182
		       case 1: pafScanlineRed   = new unsigned char[tTypeLen * nXSize * nYSize]; pafScanline = pafScanlineRed; pCTr = pCT; break;
3299
					{
3183
		       case 2: pafScanlineGreen = new unsigned char[tTypeLen * nXSize * nYSize]; pafScanline = pafScanlineGreen; pCTg = pCT; break;
3300
						case 1: pafScanlineRed   = new unsigned char[tTypeLen * nXSize * nYSize]; pafScanline = pafScanlineRed; pCTr = pCT; break;
3184
		       case 3: pafScanlineBlue  = new unsigned char[tTypeLen * nXSize * nYSize]; pafScanline = pafScanlineBlue; pCTb = pCT; break;
3301
						case 2: pafScanlineGreen = new unsigned char[tTypeLen * nXSize * nYSize]; pafScanline = pafScanlineGreen; pCTg = pCT; break;
3185
		       case 4: pafScanlineAlpha  = new unsigned char[tTypeLen * nXSize * nYSize]; pafScanline = pafScanlineAlpha; pCTa = pCT; break;
3302
						case 3: pafScanlineBlue  = new unsigned char[tTypeLen * nXSize * nYSize]; pafScanline = pafScanlineBlue; pCTb = pCT; break;
3186
		    }
3303
						case 4: pafScanlineAlpha  = new unsigned char[tTypeLen * nXSize * nYSize]; pafScanline = pafScanlineAlpha; pCTa = pCT; break;
3187
 
3304
					}
3188
		    if (!pafScanline)
3305
 
3189
		    {
3306
					if(!pafScanline)
3190
		       paint.end();
3307
					{
3191
		       KMessageBox::error(this, i18n("Not enough memory for a raster operation!"));
3308
						paint.end();
3192
		       return;
3309
						KMessageBox::error(this, i18n("Not enough memory for a raster operation!"));
3193
		    }
3310
						return;
3194
 
3311
					}
3195
		    memset (pafScanline, 0, tTypeLen * nXSize * nYSize);
3312
 
3196
 
3313
					memset(pafScanline, 0, tTypeLen * nXSize * nYSize);
3197
		    /*
3314
 
3198
		     * Get the image (from the server) and put the tiles together.
3315
					/*
3199
		     *
3316
					 * Get the image (from the server) and put the tiles together.
3200
		     * The function reads only one raster band. This is,
3317
					 *
3201
		     * because the function is called for every raster band and
3318
					 * The function reads only one raster band. This is,
3202
		     * every raster band is stored into a separate array.
3319
					 * because the function is called for every raster band and
3203
		     */
3320
					 * every raster band is stored into a separate array.
3204
		    if (poBand->RasterIO (GF_Read, 0, 0, nXSize, nYSize, pafScanline, nXSize, nYSize, tRasterType, 0, 0) == CE_Failure)
3321
					 */
3205
		    {
3322
					if(poBand->RasterIO(GF_Read, 0, 0, nXSize, nYSize, pafScanline, nXSize, nYSize, tRasterType, 0, 0) == CE_Failure)
3206
		       paint.end();
3323
					{
3207
		       KMessageBox::error(this, i18n("Error reading a raster band!"));
3324
						paint.end();
3208
		       paint.begin(&pmMap);
3325
						KMessageBox::error(this, i18n("Error reading a raster band!"));
3209
		       Fgeo = false;
3326
						paint.begin(&pmMap);
3210
		       break;
3327
						Fgeo = false;
3211
		    }
3328
						break;
3212
		    else
3329
					}
3213
		       Fgeo = true;
3330
					else
3214
		 }
3331
						Fgeo = true;
3215
 
3332
				}
3216
		 /*
3333
 
3217
		  * Only if Fgeo is TRUE, we've read successfully all raster
3334
				/*
3218
		  * bands. Now we have to put the bands together to get
3335
				 * Only if Fgeo is TRUE, we've read successfully all raster
3219
		  * an image.
3336
				 * bands. Now we have to put the bands together to get
3220
		  */
3337
				 * an image.
3221
		 if (Fgeo)
3338
				 */
3222
		 {
3339
				if(Fgeo)
3223
		 unsigned char *pCombinedBytes = new unsigned char[(tTypeLen * nXSize * nYSize * nRasterCount)];
3340
				{
3224
		 unsigned char *ptr_dest, *ptr_src;
3341
					unsigned char *pCombinedBytes = new unsigned char[(tTypeLen * nXSize * nYSize * nRasterCount)];
3225
		 int j;
3342
					unsigned char *ptr_dest, *ptr_src;
3226
 
3343
					int j;
3227
		    ptr_dest = ptr_src = 0;
3344
 
3228
 
3345
					ptr_dest = ptr_src = 0;
3229
		    /*
3346
 
3230
		     * We need two nested loops to set the pixels in the wanted
3347
					/*
3231
		     * order.
3348
					 * We need two nested loops to set the pixels in the wanted
3232
		     */
3349
					 * order.
3233
		    for (a = 0, j = 0; a < (nXSize * nYSize * nRasterCount); a += nRasterCount, j++)
3350
					 */
3234
		    {
3351
					for(a = 0, j = 0; a < (nXSize * nYSize * nRasterCount); a += nRasterCount, j++)
3235
		       int k = a;
3352
					{
3236
 
3353
						int k = a;
3237
		       for (int m = nRasterCount - 1; m >= 0; m--, k++)
3354
 
3238
		       {
3355
						for(int m = nRasterCount - 1; m >= 0; m--, k++)
3239
		       unsigned char *pBytes = 0;
3356
						{
3240
 
3357
							unsigned char *pBytes = 0;
3241
			  switch (m)
3358
 
3242
			  {
3359
							switch(m)
3243
			     case 3: pBytes = pafScanlineAlpha; pCT = pCTa; break;
3360
							{
3244
			     case 2: pBytes = pafScanlineBlue; pCT = pCTb; break;
3361
								case 3: pBytes = pafScanlineAlpha; pCT = pCTa; break;
3245
			     case 1: pBytes = pafScanlineGreen; pCT = pCTg; break;
3362
								case 2: pBytes = pafScanlineBlue; pCT = pCTb; break;
3246
			     default: pBytes = pafScanlineRed; pCT = pCTr;
3363
								case 1: pBytes = pafScanlineGreen; pCT = pCTg; break;
3247
			  }
3364
								default: pBytes = pafScanlineRed; pCT = pCTr;
3248
 
3365
							}
3249
			  ptr_dest = pCombinedBytes + k;
3366
 
3250
			  unsigned char b = pBytes[j];
3367
							ptr_dest = pCombinedBytes + k;
3251
 
3368
							unsigned char b = pBytes[j];
3252
			  /*
3369
 
3253
			   * If we have a color table, the pixels are pointers
3370
							/*
3254
			   * to the color table. We need to convert them into
3371
							 * If we have a color table, the pixels are pointers
3255
			   * 24 bit pixels plus an optional alpha channel.
3372
							 * to the color table. We need to convert them into
3256
			   */
3373
							 * 24 bit pixels plus an optional alpha channel.
3257
			  if (pCT != NULL)
3374
							 */
3258
			  {
3375
							if(pCT != NULL)
3259
			     GDALColorEntry ce;
3376
							{
3260
			     unsigned int c = (unsigned int)b;
3377
								GDALColorEntry ce;
3261
			     c = pCT->GetColorEntryAsRGB (c, &ce);
3378
								unsigned int c = (unsigned int)b;
3262
 
3379
								c = pCT->GetColorEntryAsRGB(c, &ce);
3263
			     if  (m == 0) c = ce.c1;
3380
 
3264
			     if  (m == 1) c = ce.c2;
3381
								if(m == 0) c = ce.c1;
3265
			     if  (m == 2) c = ce.c3;
3382
 
3266
			     if  (m == 3) c = ce.c4;
3383
								if(m == 1) c = ce.c2;
3267
 
3384
 
3268
			     b = (unsigned char)c;
3385
								if(m == 2) c = ce.c3;
3269
			  }
3386
 
3270
 
3387
								if(m == 3) c = ce.c4;
3271
			  ptr_src = &b;
3388
 
3272
			  memcpy (ptr_dest, ptr_src, 1);
3389
								b = (unsigned char)c;
3273
		       }
3390
							}
3274
		    }
3391
 
3275
 
3392
							ptr_src = &b;
3276
		    x1 = y1 = 0;
3393
							memcpy(ptr_dest, ptr_src, 1);
3277
 
3394
						}
3278
		    /*
3395
					}
3279
		     * The following loop is QT specific! It sets the pixels
3396
 
3280
		     * of the raw image, pixel by pixel. This may be slow, but
3397
					x1 = y1 = 0;
3281
		     * everything else didn't work :-(
3398
 
3282
		     *
3399
					/*
3283
		     * FIXME: We need a more effective routine to put the
3400
					 * The following loop is QT specific! It sets the pixels
3284
		     *        raw image into QT's "painter" class.
3401
					 * of the raw image, pixel by pixel. This may be slow, but
3285
		     */
3402
					 * everything else didn't work :-(
3286
		    for (a = 0; a < (nXSize * nYSize * nRasterCount); a += nRasterCount)
3403
					 *
3287
		    {
3404
					 * FIXME: We need a more effective routine to put the
3288
		       if (x1 < width && y1 < height)
3405
					 *        raw image into QT's "painter" class.
3289
		       {
3406
					 */
3290
			  if (nRasterCount == 3)
3407
					for(a = 0; a < (nXSize * nYSize * nRasterCount); a += nRasterCount)
3291
			     paint.setPen (QPen(QColor((int)pCombinedBytes[a+2], (int)pCombinedBytes[a+1], (int)pCombinedBytes[a]), Qt::SolidLine));
3408
					{
3292
			  else if (nRasterCount > 3)
3409
						if(x1 < width && y1 < height)
3293
			     paint.setPen (QPen(QColor(qRgba((int)pCombinedBytes[a+3], (int)pCombinedBytes[a+2], (int)pCombinedBytes[a+1], (int)pCombinedBytes[a])), Qt::SolidLine));
3410
						{
3294
			  else if (nRasterCount == 2)
3411
							if(nRasterCount == 3)
3295
			     paint.setPen (QPen(QColor((int)pCombinedBytes[a+1], (int)pCombinedBytes[a], (int)pCombinedBytes[a+1]), Qt::SolidLine));
3412
								paint.setPen(QPen(QColor((int)pCombinedBytes[a + 2], (int)pCombinedBytes[a + 1], (int)pCombinedBytes[a]), Qt::SolidLine));
3296
			  else if (nRasterCount == 1)
3413
							else if(nRasterCount > 3)
3297
			     paint.setPen (QPen(QColor((int)pCombinedBytes[a], (int)pCombinedBytes[a], (int)pCombinedBytes[a]), Qt::SolidLine));
3414
								paint.setPen(QPen(QColor(qRgba((int)pCombinedBytes[a + 3], (int)pCombinedBytes[a + 2], (int)pCombinedBytes[a + 1], (int)pCombinedBytes[a])), Qt::SolidLine));
3298
 
3415
							else if(nRasterCount == 2)
3299
			  paint.drawPoint(x1, y1);
3416
								paint.setPen(QPen(QColor((int)pCombinedBytes[a + 1], (int)pCombinedBytes[a], (int)pCombinedBytes[a + 1]), Qt::SolidLine));
3300
		       }
3417
							else if(nRasterCount == 1)
3301
 
3418
								paint.setPen(QPen(QColor((int)pCombinedBytes[a], (int)pCombinedBytes[a], (int)pCombinedBytes[a]), Qt::SolidLine));
3302
		       x1++;
3419
 
3303
 
3420
							paint.drawPoint(x1, y1);
3304
		       if (x1 >= nXSize)
3421
						}
3305
		       {
3422
 
3306
			  x1 = 0;
3423
						x1++;
3307
			  y1++;
3424
 
3308
		       }
3425
						if(x1 >= nXSize)
3309
		    }
3426
						{
3310
 
3427
							x1 = 0;
3311
		    delete pCombinedBytes;
3428
							y1++;
3312
		    pCombinedBytes = 0;
3429
						}
3313
		 }
3430
					}
3314
 
3431
 
3315
		 if (pafScanlineRed)
3432
					delete pCombinedBytes;
3316
		    delete pafScanlineRed;
3433
					pCombinedBytes = 0;
3317
 
3434
				}
3318
		 if (pafScanlineGreen)
3435
 
3319
		    delete pafScanlineGreen;
3436
				if(pafScanlineRed)
3320
 
3437
					delete pafScanlineRed;
3321
		 if (pafScanlineBlue)
3438
 
3322
		    delete pafScanlineBlue;
3439
				if(pafScanlineGreen)
3323
 
3440
					delete pafScanlineGreen;
3324
		 if (pafScanlineAlpha)
3441
 
3325
		    delete pafScanlineAlpha;
3442
				if(pafScanlineBlue)
3326
 
3443
					delete pafScanlineBlue;
3327
		 GDALClose (poDataset);
3444
 
3328
		 poDataset = 0;
3445
				if(pafScanlineAlpha)
3329
 
3446
					delete pafScanlineAlpha;
3330
		 if (MAP != fName)
3447
 
3331
		    unlink (fName.toAscii().data());
3448
				GDALClose(poDataset);
3332
	      }
3449
				poDataset = 0;
-
 
3450
 
-
 
3451
				if(MAP != fName)
-
 
3452
					unlink(fName.toAscii().data());
-
 
3453
			}
-
 
3454
 
3333
#if defined HAVE_MAPNIK
3455
#if defined HAVE_MAPNIK
3334
	      else if (MapType == MPT_SHP)
3456
			else if(MapType == MPT_SHP)
3335
	      {
3457
			{
3336
		 QDir shpd(MAP, QString("*.shp"));
3458
				QDir shpd(MAP, QString("*.shp"));
3337
 
3459
 
3338
		 if (shpd.count() < 1)
3460
				if(shpd.count() < 1)
3339
		 {
3461
				{
3340
		    KMessageBox::error(this, i18n("There is no shape file in directory %1").arg(MAP));
3462
					KMessageBox::error(this, i18n("There is no shape file in directory %1").arg(MAP));
3341
		    Fgeo = false;
3463
					Fgeo = false;
3342
		 }
3464
				}
3343
		 else
3465
				else
3344
		 {
3466
				{
3345
		 SRender rd;
3467
					SRender rd;
3346
		 QColor bg(220, 220, 220);		// background color
3468
					QColor bg(220, 220, 220);		// background color
3347
 
3469
 
3348
		    if (curTab == 0 && !ActivePrint)
3470
					if(curTab == 0 && !ActivePrint)
3349
		       rd.setDrawArea(ui_sportwatcherWidgetBase.imgMap->width(), ui_sportwatcherWidgetBase.imgMap->height());
3471
						rd.setDrawArea(ui_sportwatcherWidgetBase.imgMap->width(), ui_sportwatcherWidgetBase.imgMap->height());
3350
		    else if (!ActivePrint)
3472
					else if(!ActivePrint)
3351
		       rd.setDrawArea(ui_sportwatcherWidgetBase.grMap->width(), ui_sportwatcherWidgetBase.grMap->height());
3473
						rd.setDrawArea(ui_sportwatcherWidgetBase.grMap->width(), ui_sportwatcherWidgetBase.grMap->height());
3352
		    else if (ActivePrint)
3474
					else if(ActivePrint)
3353
		       rd.setDrawArea(pmPrMap.width(), pmPrMap.height());
3475
						rd.setDrawArea(pmPrMap.width(), pmPrMap.height());
3354
 
3476
 
3355
		    rd.setMapType(SRender::MAP_SHAPE);
3477
					rd.setMapType(SRender::MAP_SHAPE);
3356
 
3478
 
3357
		    if (rd.getMap(posLXY.lon, posLXY.lat, posRXY.lon, posRXY.lat))
3479
					if(rd.getMap(posLXY.lon, posLXY.lat, posRXY.lon, posRXY.lat))
3358
		    {
3480
					{
3359
		       paint.fillRect(0, 0, width+2, height+2, bg);
3481
						paint.fillRect(0, 0, width + 2, height + 2, bg);
3360
		       paint.drawPixmap(0, 0, rd.pixmap());
3482
						paint.drawPixmap(0, 0, rd.pixmap());
3361
		       Fgeo = true;
3483
						Fgeo = true;
3362
		    }
3484
					}
3363
		    else
3485
					else
3364
		       Fgeo = false;
3486
						Fgeo = false;
3365
		 }
3487
				}
3366
	      }
3488
			}
3367
	      else if (MapType == MPT_OSM)
3489
			else if(MapType == MPT_OSM)
3368
	      {
3490
			{
3369
		 QFileInfo osmf(MAP);
3491
				QFileInfo osmf(MAP);
3370
 
3492
 
3371
		 if (!osmf.exists())
3493
				if(!osmf.exists())
3372
		 {
3494
				{
3373
		    KMessageBox::error(this, i18n("The OSM file %1 does not exist!").arg(MAP));
3495
					KMessageBox::error(this, i18n("The OSM file %1 does not exist!").arg(MAP));
3374
		    Fgeo = false;
3496
					Fgeo = false;
3375
		 }
3497
				}
3376
		 else
3498
				else
3377
		 {
3499
				{
3378
		 SRender rd;
3500
					SRender rd;
3379
		 QColor bg(220, 220, 220);		// background color
3501
					QColor bg(220, 220, 220);		// background color
3380
 
3502
 
3381
		    if (curTab == 0 && !ActivePrint)
3503
					if(curTab == 0 && !ActivePrint)
3382
		       rd.setDrawArea(ui_sportwatcherWidgetBase.imgMap->width(), ui_sportwatcherWidgetBase.imgMap->height());
3504
						rd.setDrawArea(ui_sportwatcherWidgetBase.imgMap->width(), ui_sportwatcherWidgetBase.imgMap->height());
3383
		    else if (!ActivePrint)
3505
					else if(!ActivePrint)
3384
		       rd.setDrawArea(ui_sportwatcherWidgetBase.grMap->width(), ui_sportwatcherWidgetBase.grMap->height());
3506
						rd.setDrawArea(ui_sportwatcherWidgetBase.grMap->width(), ui_sportwatcherWidgetBase.grMap->height());
3385
		    else if (ActivePrint)
3507
					else if(ActivePrint)
3386
		       rd.setDrawArea(pmPrMap.width(), pmPrMap.height());
3508
						rd.setDrawArea(pmPrMap.width(), pmPrMap.height());
3387
 
3509
 
3388
		    rd.setMapType(SRender::MAP_OSM);
3510
					rd.setMapType(SRender::MAP_OSM);
3389
 
3511
 
3390
		    if (rd.getMap(posLXY.lon, posLXY.lat, posRXY.lon, posRXY.lat))
3512
					if(rd.getMap(posLXY.lon, posLXY.lat, posRXY.lon, posRXY.lat))
3391
		    {
3513
					{
3392
		       paint.fillRect(0, 0, width+2, height+2, bg);
3514
						paint.fillRect(0, 0, width + 2, height + 2, bg);
3393
		       paint.drawPixmap(0, 0, rd.pixmap());
3515
						paint.drawPixmap(0, 0, rd.pixmap());
3394
		       Fgeo = true;
3516
						Fgeo = true;
3395
		    }
3517
					}
3396
		    else
3518
					else
3397
		       Fgeo = false;
3519
						Fgeo = false;
3398
		 }
3520
				}
3399
	      }
3521
			}
-
 
3522
 
3400
#endif	// HAVE_MAPNIK
3523
#endif	// HAVE_MAPNIK
3401
	      else
3524
			else
3402
	      {
3525
			{
3403
		 KMessageBox::error(this, i18n("Error opening map file!"));
3526
				KMessageBox::error(this, i18n("Error opening map file!"));
3404
		 Fgeo = false;
3527
				Fgeo = false;
3405
	      }
3528
			}
3406
	   }
3529
		}
3407
	}
3530
	}
-
 
3531
 
3408
#endif	// HAVE_GDAL
3532
#endif	// HAVE_GDAL
3409
	/*
3533
	/*
3410
	 * Here we come to draw the track. It will be drawn over the previous
3534
	 * Here we come to draw the track. It will be drawn over the previous
3411
	 * created map image.
3535
	 * created map image.
3412
	 */
3536
	 */
Line 3420... Line 3544...
3420
	fntNormal.setPixelSize(10);
3544
	fntNormal.setPixelSize(10);
3421
	fntNormal.setStyleHint(QFont::Helvetica);
3545
	fntNormal.setStyleHint(QFont::Helvetica);
3422
	QPen dot(red, 4, Qt::SolidLine);
3546
	QPen dot(red, 4, Qt::SolidLine);
3423
	QPen line(black, 2, Qt::SolidLine);
3547
	QPen line(black, 2, Qt::SolidLine);
3424
	QPen yline(yellow, 4, Qt::SolidLine);
3548
	QPen yline(yellow, 4, Qt::SolidLine);
-
 
3549
 
3425
	// Fill background with background colors, if there is no map.
3550
	// Fill background with background colors, if there is no map.
3426
	if (!Fgeo)
3551
	if(!Fgeo)
3427
	   paint.fillRect(0, 0, width+2, height+2, background);
3552
		paint.fillRect(0, 0, width + 2, height + 2, background);
3428
 
3553
 
3429
	if (Units == 0)
3554
	if(Units == 0)
3430
	   fact = 1000.0;
3555
		fact = 1000.0;
3431
	else
3556
	else
3432
	   fact = 1609.344;
3557
		fact = 1609.344;
3433
 
3558
 
3434
	paint.setPen(line);
3559
	paint.setPen(line);
3435
	paint.drawLine(10, height - 9, 10, height - 4);
3560
	paint.drawLine(10, height - 9, 10, height - 4);
3436
	paint.drawLine(10, height - 4, 10 + (fact / dist), height - 4);
3561
	paint.drawLine(10, height - 4, 10 + (fact / dist), height - 4);
3437
	paint.drawLine(10 + (fact / dist), height - 9, 10 + (fact / dist), height - 4);
3562
	paint.drawLine(10 + (fact / dist), height - 9, 10 + (fact / dist), height - 4);
3438
	paint.setFont(fntNormal);
3563
	paint.setFont(fntNormal);
3439
 
3564
 
3440
	if (Units == 0)
3565
	if(Units == 0)
3441
	   paint.drawText(10, height - 10, QString("1000 m"));
3566
		paint.drawText(10, height - 10, QString("1000 m"));
3442
	else
3567
	else
3443
	   paint.drawText(10, height - 10, QString("5280 ft"));
3568
		paint.drawText(10, height - 10, QString("5280 ft"));
3444
 
3569
 
3445
	// Draw track
3570
	// Draw track
3446
	if (mapLap)
3571
	if(mapLap)
3447
	   i = mapLap->start_time;
3572
		i = mapLap->start_time;
3448
	else
3573
	else
3449
	   i = 0;
3574
		i = 0;
3450
	
3575
 
3451
	x1 = y1 = 0.0;
3576
	x1 = y1 = 0.0;
3452
	bool wStart = false;
3577
	bool wStart = false;
3453
 
3578
 
3454
	while ((point = ds.getPoint(i)) != 0)
3579
	while((point = ds.getPoint(i)) != 0)
3455
	{
3580
	{
3456
	   if (mapLap && point->time > (mapLap->start_time + (mapLap->total_time / 100)))
3581
		if(mapLap && point->time > (mapLap->start_time + (mapLap->total_time / 100)))
3457
	      break;
3582
			break;
-
 
3583
 
-
 
3584
		if(point->posn.lat == 0x7fffffff || point->posn.lon == 0x7fffffff)
-
 
3585
		{
-
 
3586
			i = point->time + 1;
-
 
3587
			continue;
-
 
3588
		}
-
 
3589
 
-
 
3590
		x2 = (left + ((posNW.lon - SEMI2DEG(point->posn.lon)) * tick * -1)) + oldTransX;
-
 
3591
		y2 = (top + ((posNW.lat - SEMI2DEG(point->posn.lat)) * tick)) + oldTransY;
3458
 
3592
 
3459
	   if (point->posn.lat == 0x7fffffff || point->posn.lon == 0x7fffffff)
-
 
3460
	   {
-
 
3461
	      i = point->time + 1;
-
 
3462
	      continue;
-
 
3463
	   }
-
 
3464
 
-
 
3465
	   x2 = (left + ((posNW.lon - SEMI2DEG(point->posn.lon)) * tick * -1)) + oldTransX;
-
 
3466
	   y2 = (top + ((posNW.lat - SEMI2DEG(point->posn.lat)) * tick)) + oldTransY;
-
 
3467
 
-
 
3468
	   if (!wStart && x1 != 0.0 && y1 != 0.0)
3593
		if(!wStart && x1 != 0.0 && y1 != 0.0)
3469
	   {
3594
		{
3470
	      // Load the start symbol
3595
			// Load the start symbol
3471
	      QPixmap qpx (KIcon(QString("wstart")).pixmap(16));
3596
			QPixmap qpx(KIcon(QString("wstart")).pixmap(16));
3472
	      // Find the angle of the track and turn the symbol accordingly
3597
			// Find the angle of the track and turn the symbol accordingly
3473
	      // we use Pythagoras to calculate the triangle
3598
			// we use Pythagoras to calculate the triangle
3474
	      double xl = (x1 < x2) ? x2 - x1 : x1 - x2;
3599
			double xl = (x1 < x2) ? x2 - x1 : x1 - x2;
3475
	      double yl = (y1 < y2) ? y2 - y1 : y1 - y2;
3600
			double yl = (y1 < y2) ? y2 - y1 : y1 - y2;
3476
	      double da = fmin (xl, yl);
3601
			double da = fmin(xl, yl);
3477
	      double db = fmax (xl, yl);
3602
			double db = fmax(xl, yl);
3478
	      double zl = sqrt (pow (da, 2) + pow (db, 2));
3603
			double zl = sqrt(pow(da, 2) + pow(db, 2));
3479
	      double angle = (asin(da / zl) / M_PIl) * 180.0;
3604
			double angle = (asin(da / zl) / M_PIl) * 180.0;
-
 
3605
 
-
 
3606
			angle = (angle > 45.0) ? 90.0 - angle : angle;
3480
 
3607
 
3481
	      angle = (angle > 45.0) ? 90.0 - angle : angle;
-
 
3482
// cout << "Winkel: " << angle << " ---- X: " << xl << ", Y: " << yl << ", Z: " << zl << ", Point (x1,y1,x2,y2): " << x1 << ", " << y1 << ", " << x2 << ", " << y2 << endl;
3608
// cout << "Winkel: " << angle << " ---- X: " << xl << ", Y: " << yl << ", Z: " << zl << ", Point (x1,y1,x2,y2): " << x1 << ", " << y1 << ", " << x2 << ", " << y2 << endl;
3483
	      if (x1 < x2 && y1 < y2)		// right, down
3609
			if(x1 < x2 && y1 < y2)		// right, down
3484
		 angle = 90.0 + angle;
3610
				angle = 90.0 + angle;
3485
	      else if (x1 > x2 && y1 < y2)	// left, down
3611
			else if(x1 > x2 && y1 < y2)	// left, down
3486
		 angle = 270.0 - angle;
3612
				angle = 270.0 - angle;
3487
	      else if (x1 > x2 && y1 > y2)	// left, up
3613
			else if(x1 > x2 && y1 > y2)	// left, up
3488
		 angle = 270.0 + angle;
3614
				angle = 270.0 + angle;
3489
	      else				// right, up
3615
			else				// right, up
3490
		 angle = 90.0 - angle;
3616
				angle = 90.0 - angle;
-
 
3617
 
3491
// cout << "Realer Winkel: " << angle << endl;
3618
// cout << "Realer Winkel: " << angle << endl;
3492
	      // Set the center of the symbol
3619
			// Set the center of the symbol
3493
	      paint.save ();
3620
			paint.save();
3494
	      paint.translate (x1, y1);
3621
			paint.translate(x1, y1);
3495
	      // rotate the symbol
3622
			// rotate the symbol
3496
	      paint.rotate (angle);
3623
			paint.rotate(angle);
3497
	      paint.drawPixmap (-8, -8, qpx);
3624
			paint.drawPixmap(-8, -8, qpx);
3498
	      paint.restore ();
3625
			paint.restore();
3499
	      wStart = true;
3626
			wStart = true;
3500
	   }
3627
		}
3501
 
3628
 
3502
	   if (x1 == 0.0 && y1 == 0.0)
3629
		if(x1 == 0.0 && y1 == 0.0)
3503
	   {
3630
		{
3504
	      x1 = x2;
3631
			x1 = x2;
3505
	      y1 = y2;
3632
			y1 = y2;
3506
	   }
3633
		}
3507
 
3634
 
3508
	   paint.setPen(yline);
3635
		paint.setPen(yline);
3509
	   paint.drawLine(x1, y1, x2, y2);
3636
		paint.drawLine(x1, y1, x2, y2);
3510
 
3637
 
3511
	   if ((point->distance - dist) >= fact)	// a dot at every 1000 meters or at 1 mile
3638
		if((point->distance - dist) >= fact)	// a dot at every 1000 meters or at 1 mile
3512
	   {
3639
		{
3513
	      paint.setPen(dot);
3640
			paint.setPen(dot);
3514
	      paint.drawEllipse(x2-2, y2-2, 3, 3);
3641
			paint.drawEllipse(x2 - 2, y2 - 2, 3, 3);
3515
	      dist = (int)(point->distance / fact) * fact;
3642
			dist = (int)(point->distance / fact) * fact;
3516
	   }
3643
		}
3517
 
3644
 
3518
	   paint.setPen(line);
3645
		paint.setPen(line);
3519
	   paint.drawLine(x1, y1, x2, y2);
3646
		paint.drawLine(x1, y1, x2, y2);
3520
	   x1 = x2;
3647
		x1 = x2;
3521
	   y1 = y2;
3648
		y1 = y2;
3522
	   i = point->time + 1;
3649
		i = point->time + 1;
3523
	}
3650
	}
3524
 
3651
 
3525
	bool lastLap = false;
3652
	bool lastLap = false;
3526
 
3653
 
3527
	if (mapLap)
3654
	if(mapLap)
3528
	   if (ds.getRunNode()->run->last_lap_index == mapLap->index)
3655
		if(ds.getRunNode()->run->last_lap_index == mapLap->index)
3529
	      lastLap = true;
3656
			lastLap = true;
3530
 
3657
 
3531
	if ((!mapLap || lastLap) && wStart)
3658
	if((!mapLap || lastLap) && wStart)
3532
	{
3659
	{
3533
	   // load the end symbol
3660
		// load the end symbol
3534
	   QPixmap qpx (KIcon(QString("wtarget")).pixmap(16));
3661
		QPixmap qpx(KIcon(QString("wtarget")).pixmap(16));
3535
	   paint.drawPixmap (x2, y2 - 16, qpx);
3662
		paint.drawPixmap(x2, y2 - 16, qpx);
3536
	}
3663
	}
3537
 
3664
 
3538
	paint.end();
3665
	paint.end();
3539
 
3666
 
3540
	if (curTab == 0 && !ActivePrint)
3667
	if(curTab == 0 && !ActivePrint)
3541
	   ui_sportwatcherWidgetBase.imgMap->setPixmap(pmMap);
3668
		ui_sportwatcherWidgetBase.imgMap->setPixmap(pmMap);
3542
	else if (ActivePrint)
3669
	else if(ActivePrint)
3543
	   pmPrMap = pmMap;
3670
		pmPrMap = pmMap;
3544
	else
3671
	else
3545
	   ui_sportwatcherWidgetBase.grMap->setPixmap(pmMap);
3672
		ui_sportwatcherWidgetBase.grMap->setPixmap(pmMap);
3546
 
3673
 
3547
	QApplication::restoreOverrideCursor();
3674
	QApplication::restoreOverrideCursor();
3548
}
3675
}
3549
 
3676
 
3550
void sportwatcherWidget::kcbCurveSlot(int)
3677
void sportwatcherWidget::kcbCurveSlot(int)
Line 3556... Line 3683...
3556
 
3683
 
3557
void sportwatcherWidget::tabViewSlot(int tab)
3684
void sportwatcherWidget::tabViewSlot(int tab)
3558
{
3685
{
3559
	curTab = tab;
3686
	curTab = tab;
3560
 
3687
 
3561
	if (tab == 0 && tabDirt0)
3688
	if(tab == 0 && tabDirt0)
3562
	{
3689
	{
3563
	   DIRTY = true;
3690
		DIRTY = true;
3564
	   showLaps();
3691
		showLaps();
3565
	   showTrack();
3692
		showTrack();
3566
	   showCurves();
3693
		showCurves();
3567
	   DIRTY = false;
3694
		DIRTY = false;
3568
	   tabDirt0 = false;
3695
		tabDirt0 = false;
3569
	}
3696
	}
3570
	else if (tab == 1 && tabDirt1)
3697
	else if(tab == 1 && tabDirt1)
3571
	{
3698
	{
3572
	   DIRTY = true;
3699
		DIRTY = true;
3573
 
3700
 
3574
	   if (tabDirt0)
3701
		if(tabDirt0)
3575
	      showLaps();
3702
			showLaps();
3576
 
3703
 
3577
	   showTrack();
3704
		showTrack();
3578
	   DIRTY = false;
3705
		DIRTY = false;
3579
	   tabDirt1 = false;
3706
		tabDirt1 = false;
3580
	}
3707
	}
3581
	else if (tab == 2 && tabDirt2)
3708
	else if(tab == 2 && tabDirt2)
3582
	{
3709
	{
3583
	   DIRTY = true;
3710
		DIRTY = true;
3584
 
3711
 
3585
	   if (tabDirt0)
3712
		if(tabDirt0)
3586
	      showLaps();
3713
			showLaps();
3587
 
3714
 
3588
	   setMouseTracking (true);
3715
		setMouseTracking(true);
3589
	   ui_sportwatcherWidgetBase.tabView->setMouseTracking (true);
3716
		ui_sportwatcherWidgetBase.tabView->setMouseTracking(true);
3590
	   ui_sportwatcherWidgetBase.grHR->setMouseTracking (true);
3717
		ui_sportwatcherWidgetBase.grHR->setMouseTracking(true);
3591
	   ui_sportwatcherWidgetBase.grElevation->setMouseTracking (true);
3718
		ui_sportwatcherWidgetBase.grElevation->setMouseTracking(true);
3592
	   ui_sportwatcherWidgetBase.grSpeed->setMouseTracking (true);
3719
		ui_sportwatcherWidgetBase.grSpeed->setMouseTracking(true);
3593
	   showThreeCurve();
3720
		showThreeCurve();
3594
	   tabDirt2 = false;
3721
		tabDirt2 = false;
3595
	   DIRTY = false;
3722
		DIRTY = false;
3596
	}
3723
	}
3597
}
3724
}
3598
 
3725
 
3599
void sportwatcherWidget::showCurves()
3726
void sportwatcherWidget::showCurves()
3600
{
3727
{
3601
	showCurves (mapLap);
3728
	showCurves(mapLap);
3602
}
3729
}
3603
 
3730
 
3604
void sportwatcherWidget::showCurves(LAP *lap)
3731
void sportwatcherWidget::showCurves(LAP *lap)
3605
{
3732
{
3606
QPainter paint;
3733
	QPainter paint;
3607
int width, height;
3734
	int width, height;
3608
int i, secs, cuType;
3735
	int i, secs, cuType;
3609
int lineHeight, margin_left, margin_right, margin_bottom;
3736
	int lineHeight, margin_left, margin_right, margin_bottom;
3610
int x1, y1, x2, y2;		// Coordinates
3737
	int x1, y1, x2, y2;		// Coordinates
3611
bool meter;
3738
	bool meter;
3612
double maxHeight, minHeight, maxSpeed, minSpeed;
3739
	double maxHeight, minHeight, maxSpeed, minSpeed;
3613
int maxHr, minHr, rh;
3740
	int maxHr, minHr, rh;
3614
POINT *point;
3741
	POINT *point;
3615
RUN_NODE *rn;
3742
	RUN_NODE *rn;
3616
LAP *lp;
3743
	LAP *lp;
3617
double w_tick, h_tick;		// Number of pixels one "tick" has;
3744
	double w_tick, h_tick;		// Number of pixels one "tick" has;
-
 
3745
 
3618
				// This depends on the width and height
3746
	// This depends on the width and height
3619
				// of the image.
3747
	// of the image.
3620
	// First we draw a grid based on the min and max
3748
	// First we draw a grid based on the min and max
3621
	// values detected in the function showLap(). In case
3749
	// values detected in the function showLap(). In case
3622
	// all values are 0, we exit here.
3750
	// all values are 0, we exit here.
3623
	if (min_hr == 0 && max_hr == 0 && min_height == 0.0 && max_height == 0.0)
3751
	if(min_hr == 0 && max_hr == 0 && min_height == 0.0 && max_height == 0.0)
3624
	   return;
3752
		return;
3625
 
3753
 
3626
	if (!DIRTY || curTab != 0)
3754
	if(!DIRTY || curTab != 0)
3627
	   return;
3755
		return;
3628
 
3756
 
3629
	// Look up, what curves we should draw
3757
	// Look up, what curves we should draw
3630
	cuType = ui_sportwatcherWidgetBase.kcbCurveTypes->currentIndex();
3758
	cuType = ui_sportwatcherWidgetBase.kcbCurveTypes->currentIndex();
3631
	// Get the dimensions of the available draw area
3759
	// Get the dimensions of the available draw area
3632
	width = ui_sportwatcherWidgetBase.imgProfile->width() - 2;
3760
	width = ui_sportwatcherWidgetBase.imgProfile->width() - 2;
Line 3634... Line 3762...
3634
	pmProfile = QPixmap(width, height);
3762
	pmProfile = QPixmap(width, height);
3635
	paint.begin(&pmProfile);
3763
	paint.begin(&pmProfile);
3636
 
3764
 
3637
	// we need a somewhat bigger area to draw our curves than
3765
	// we need a somewhat bigger area to draw our curves than
3638
	// we have with the real min and max values.
3766
	// we have with the real min and max values.
3639
	if (max_height > 0.0)
3767
	if(max_height > 0.0)
3640
	{
3768
	{
3641
	double add = (max_height - min_height) / 100.0 * 5.0;	// Percent
3769
		double add = (max_height - min_height) / 100.0 * 5.0;	// Percent
3642
 
3770
 
3643
	   maxHeight = max_height + add;
3771
		maxHeight = max_height + add;
3644
	   minHeight = min_height - add;
3772
		minHeight = min_height - add;
3645
 
3773
 
3646
	   if (minHeight < 0.0)		// make sure, we are not too deep
3774
		if(minHeight < 0.0)		// make sure, we are not too deep
3647
	      minHeight = 0.0;
3775
			minHeight = 0.0;
3648
	}
3776
	}
3649
	else
3777
	else
3650
	   maxHeight = minHeight = 0.0;
3778
		maxHeight = minHeight = 0.0;
3651
 
3779
 
3652
	if (max_speed > 0.0)
3780
	if(max_speed > 0.0)
3653
	{
3781
	{
3654
	double add = (max_speed - min_speed) / 100.0 * 5.0;	// Percent
3782
		double add = (max_speed - min_speed) / 100.0 * 5.0;	// Percent
3655
 
3783
 
3656
	   maxSpeed = max_speed + add;
3784
		maxSpeed = max_speed + add;
3657
	   minSpeed = min_speed - add;
3785
		minSpeed = min_speed - add;
3658
 
3786
 
3659
	   if (minSpeed < 0.0)		// make sure, we are not too deep
3787
		if(minSpeed < 0.0)		// make sure, we are not too deep
3660
	      minSpeed = 0.0;
3788
			minSpeed = 0.0;
3661
	}
3789
	}
3662
	else
3790
	else
3663
	   maxSpeed = minSpeed = 0.0;
3791
		maxSpeed = minSpeed = 0.0;
3664
 
3792
 
3665
	if (max_hr > 0)
3793
	if(max_hr > 0)
3666
	{
3794
	{
3667
	   maxHr = max_hr + 10;
3795
		maxHr = max_hr + 10;
3668
	   minHr = min_hr - 10;
3796
		minHr = min_hr - 10;
3669
 
3797
 
3670
	   if (minHr < 0)
3798
		if(minHr < 0)
3671
	      minHr = 0;
3799
			minHr = 0;
3672
	}
3800
	}
3673
	else
3801
	else
3674
	   maxHr = minHr = 0;
3802
		maxHr = minHr = 0;
3675
 
3803
 
3676
	// Define colors
3804
	// Define colors
3677
	QColor background(220, 220, 220);	// Background of graphic
3805
	QColor background(220, 220, 220);	// Background of graphic
3678
	QColor mark(255, 255, 255);		// Lines inside curve area
3806
	QColor mark(255, 255, 255);		// Lines inside curve area
3679
	QColor hlight(180, 180, 180);		// area of current lap
3807
	QColor hlight(180, 180, 180);		// area of current lap
Line 3696... Line 3824...
3696
	lineHeight = 10;
3824
	lineHeight = 10;
3697
	rh = height - margin_bottom - 1;
3825
	rh = height - margin_bottom - 1;
3698
 
3826
 
3699
	w_tick = (double)(width - (margin_left + margin_right)) / (max_time + ds.getPauseTime());	// 1 tick = 1 second
3827
	w_tick = (double)(width - (margin_left + margin_right)) / (max_time + ds.getPauseTime());	// 1 tick = 1 second
3700
 
3828
 
3701
	if (cuType == 1)	// Speed and heart rate?
3829
	if(cuType == 1)	// Speed and heart rate?
-
 
3830
	{
-
 
3831
		if((maxSpeed - minSpeed) > (double)(maxHr - minHr))
-
 
3832
		{
-
 
3833
			h_tick = (double)rh / (maxSpeed - minSpeed);		// 1 tick = 1 km/h
-
 
3834
			meter = true;
-
 
3835
		}
-
 
3836
		else
-
 
3837
		{
-
 
3838
			h_tick = (double)rh / ((double)maxHr - (double)minHr);	// 1 tick = 1 bpm
-
 
3839
			meter = false;
-
 
3840
		}
-
 
3841
	}
-
 
3842
	else if(cuType == 2)	// Elevation and speed?
3702
	{
3843
	{
3703
	   if ((maxSpeed - minSpeed) > (double)(maxHr - minHr))
3844
		if((maxHeight - minHeight) > (double)(maxHr - minHr))
3704
	   {
-
 
3705
	      h_tick = (double)rh / (maxSpeed - minSpeed);		// 1 tick = 1 km/h
-
 
3706
	      meter = true;
-
 
3707
	   }
-
 
3708
	   else
-
 
3709
	   {
-
 
3710
	      h_tick = (double)rh / ((double)maxHr - (double)minHr);	// 1 tick = 1 bpm
-
 
3711
	      meter = false;
-
 
3712
	   }
-
 
3713
	}
-
 
3714
	else if (cuType == 2)	// Elevation and speed?
-
 
3715
	{
3845
		{
3716
	   if ((maxHeight - minHeight) > (double)(maxHr - minHr))
-
 
3717
	   {
-
 
3718
	      h_tick = (double)rh / (maxHeight - minHeight);		// 1 tick = 1 meter
3846
			h_tick = (double)rh / (maxHeight - minHeight);		// 1 tick = 1 meter
3719
	      meter = true;
3847
			meter = true;
3720
	   }
3848
		}
3721
	   else
3849
		else
3722
	   {
3850
		{
3723
	      h_tick = (double)rh / (maxSpeed - minSpeed);		// 1 tick = 1 km/h
3851
			h_tick = (double)rh / (maxSpeed - minSpeed);		// 1 tick = 1 km/h
3724
	      meter = false;
3852
			meter = false;
3725
	   }
3853
		}
3726
	}
3854
	}
3727
	else			// Elevation and heart rate
3855
	else			// Elevation and heart rate
3728
	{
3856
	{
3729
	   if ((maxHeight - minHeight) > (double)(maxHr - minHr))
3857
		if((maxHeight - minHeight) > (double)(maxHr - minHr))
3730
	   {
3858
		{
3731
	      h_tick = (double)rh / (maxHeight - minHeight);		// 1 tick = 1 meter
3859
			h_tick = (double)rh / (maxHeight - minHeight);		// 1 tick = 1 meter
3732
	      meter = true;
3860
			meter = true;
3733
	   }
3861
		}
3734
	   else
3862
		else
3735
	   {
3863
		{
3736
	      h_tick = (double)rh / ((double)maxHr - (double)minHr);	// 1 tick = 1 bpm
3864
			h_tick = (double)rh / ((double)maxHr - (double)minHr);	// 1 tick = 1 bpm
3737
	      meter = false;
3865
			meter = false;
3738
	   }
3866
		}
3739
	}
3867
	}
3740
 
3868
 
3741
	// Fill background with background colors
3869
	// Fill background with background colors
3742
	paint.fillRect(0, 0, width + 4, height + 4, background);
3870
	paint.fillRect(0, 0, width + 4, height + 4, background);
3743
	// Draw a grid with markers at every 10 minutes
3871
	// Draw a grid with markers at every 10 minutes
Line 3762... Line 3890...
3762
	QDateTime *qt;
3890
	QDateTime *qt;
3763
	QTime zeit = StartTime.time();
3891
	QTime zeit = StartTime.time();
3764
	rn = ds.getRunNode();
3892
	rn = ds.getRunNode();
3765
	paint.setPen(QPen(hlight, 1, Qt::SolidLine));
3893
	paint.setPen(QPen(hlight, 1, Qt::SolidLine));
3766
 
3894
 
3767
	for (i = rn->run->first_lap_index; (unsigned int)i <= rn->run->last_lap_index; i++)
3895
	for(i = rn->run->first_lap_index; (unsigned int)i <= rn->run->last_lap_index; i++)
3768
	{
3896
	{
3769
	   if ((lp = ds.getLap(i)) == NULL)
3897
		if((lp = ds.getLap(i)) == NULL)
3770
	      continue;
3898
			continue;
3771
 
3899
 
3772
	   qt = garmin_dtime(lp->start_time);
3900
		qt = garmin_dtime(lp->start_time);
3773
	   secs = zeit.secsTo(qt->time());
3901
		secs = zeit.secsTo(qt->time());
3774
	   delete qt;
3902
		delete qt;
3775
	   x1 = secs * w_tick + margin_left + 1;
3903
		x1 = secs * w_tick + margin_left + 1;
3776
 
3904
 
3777
	   if (lap && lp->start_time == lap->start_time)
3905
		if(lap && lp->start_time == lap->start_time)
3778
	      paint.fillRect(x1, 2, (int)((double)lap->total_time / 100.0 * w_tick), height - margin_bottom - 2, hlight);
3906
			paint.fillRect(x1, 2, (int)((double)lap->total_time / 100.0 * w_tick), height - margin_bottom - 2, hlight);
3779
	   else
3907
		else
3780
	      paint.drawLine(x1, 2, x1, height - margin_bottom);
3908
			paint.drawLine(x1, 2, x1, height - margin_bottom);
3781
	}
3909
	}
3782
 
3910
 
3783
	// Grid vertical
3911
	// Grid vertical
3784
	paint.setPen(QPen(frame, 1, Qt::SolidLine));
3912
	paint.setPen(QPen(frame, 1, Qt::SolidLine));
3785
	paint.setFont(fntNormal);
3913
	paint.setFont(fntNormal);
3786
	paint.drawText(margin_left - 20, height - lineHeight, 40, lineHeight, Qt::AlignCenter, QString("00:00"));
3914
	paint.drawText(margin_left - 20, height - lineHeight, 40, lineHeight, Qt::AlignCenter, QString("00:00"));
3787
	paint.save();
3915
	paint.save();
3788
	paint.rotate(270);
3916
	paint.rotate(270);
3789
 
3917
 
3790
	if (cuType == 1)
3918
	if(cuType == 1)
3791
	   paint.setPen(QPen(red, 1, Qt::SolidLine));
3919
		paint.setPen(QPen(red, 1, Qt::SolidLine));
3792
	else
3920
	else
3793
	   paint.setPen(QPen(barcol, 1, Qt::SolidLine));
3921
		paint.setPen(QPen(barcol, 1, Qt::SolidLine));
3794
 
3922
 
3795
	// Information on left side
3923
	// Information on left side
3796
	if (cuType == 0)
3924
	if(cuType == 0)
3797
	   paint.drawText((height + 4) * -1, 3, height - 2, lineHeight, Qt::AlignCenter, i18n("Elevation (%1)").arg((Units == 1) ? "ft" : "m"));
3925
		paint.drawText((height + 4) * -1, 3, height - 2, lineHeight, Qt::AlignCenter, i18n("Elevation (%1)").arg((Units == 1) ? "ft" : "m"));
3798
	else if (cuType == 1)
3926
	else if(cuType == 1)
3799
	   paint.drawText((height + 4) * -1, 3, height - 2, lineHeight, Qt::AlignCenter, i18n("Speed (%1)").arg((Units == 1) ? "mph" : "km/h"));
3927
		paint.drawText((height + 4) * -1, 3, height - 2, lineHeight, Qt::AlignCenter, i18n("Speed (%1)").arg((Units == 1) ? "mph" : "km/h"));
3800
	else
3928
	else
3801
	   paint.drawText((height + 4) * -1, 3, height - 2, lineHeight, Qt::AlignCenter, i18n("Elevation (%1)").arg((Units == 1) ? "ft" : "m"));
3929
		paint.drawText((height + 4) * -1, 3, height - 2, lineHeight, Qt::AlignCenter, i18n("Elevation (%1)").arg((Units == 1) ? "ft" : "m"));
3802
 
3930
 
3803
	if (cuType == 2)
3931
	if(cuType == 2)
3804
	   paint.setPen(QPen(red, 1, Qt::SolidLine));
3932
		paint.setPen(QPen(red, 1, Qt::SolidLine));
3805
	else
3933
	else
3806
	   paint.setPen(QPen(blue, 1, Qt::SolidLine));
3934
		paint.setPen(QPen(blue, 1, Qt::SolidLine));
3807
 
3935
 
3808
	// Information on right side
3936
	// Information on right side
3809
	if (cuType < 2)
3937
	if(cuType < 2)
3810
	   paint.drawText((height + 4) * -1, width - 1 - lineHeight, height - 2, lineHeight, Qt::AlignCenter, i18n("Heart Rate (bpm)"));
3938
		paint.drawText((height + 4) * -1, width - 1 - lineHeight, height - 2, lineHeight, Qt::AlignCenter, i18n("Heart Rate (bpm)"));
3811
	else
3939
	else
3812
	   paint.drawText((height + 4) * -1, width - 1 - lineHeight, height - 2, lineHeight, Qt::AlignCenter, i18n("Speed (%1)").arg((Units == 1) ? "mph" : "km/h"));
3940
		paint.drawText((height + 4) * -1, width - 1 - lineHeight, height - 2, lineHeight, Qt::AlignCenter, i18n("Speed (%1)").arg((Units == 1) ? "mph" : "km/h"));
3813
 
3941
 
3814
	paint.restore();
3942
	paint.restore();
3815
	paint.setPen(QPen(mark, 1, Qt::SolidLine));
3943
	paint.setPen(QPen(mark, 1, Qt::SolidLine));
-
 
3944
 
3816
	// Draw the time scale on the bottom of the graphic
3945
	// Draw the time scale on the bottom of the graphic
3817
	for (i = 0; (unsigned int)i < (max_time + ds.getPauseTime()); i++)
3946
	for(i = 0; (unsigned int)i < (max_time + ds.getPauseTime()); i++)
3818
	{
3947
	{
3819
	   if (i > 0 && !(i % 600))	// every 10 minutes
3948
		if(i > 0 && !(i % 600))	// every 10 minutes
3820
	   {
3949
		{
3821
	      x1 = x2 = margin_left + w_tick * i;
3950
			x1 = x2 = margin_left + w_tick * i;
3822
 
3951
 
3823
	      if (x1 == (width - margin_right))
3952
			if(x1 == (width - margin_right))
3824
		 continue;
3953
				continue;
3825
 
3954
 
3826
	      y1 = 2;
3955
			y1 = 2;
3827
	      y2 = height - margin_bottom;
3956
			y2 = height - margin_bottom;
3828
	      paint.drawLine(x1, y1, x2, y2);
3957
			paint.drawLine(x1, y1, x2, y2);
3829
	      QTime tm(0, 0, 0);
3958
			QTime tm(0, 0, 0);
3830
	      tm = tm.addSecs(i);
3959
			tm = tm.addSecs(i);
3831
	      paint.setPen(QPen(frame, 1, Qt::SolidLine));
3960
			paint.setPen(QPen(frame, 1, Qt::SolidLine));
3832
//	      paint.drawText(x1 - 25, height - lineHeight, 50, lineHeight, Qt::AlignCenter, tm.toString((i >= 3600) ? "hh:mm:ss" : "mm:ss"));
3961
//	      paint.drawText(x1 - 25, height - lineHeight, 50, lineHeight, Qt::AlignCenter, tm.toString((i >= 3600) ? "hh:mm:ss" : "mm:ss"));
3833
	      paint.drawText(x1 - 25, height - lineHeight, 50, lineHeight, Qt::AlignCenter, kl->formatTime (tm, (i >= 3600) ? true : false));
3962
			paint.drawText(x1 - 25, height - lineHeight, 50, lineHeight, Qt::AlignCenter, kl->formatTime(tm, (i >= 3600) ? true : false));
3834
	      paint.setPen(QPen(mark, 1, Qt::SolidLine));
3963
			paint.setPen(QPen(mark, 1, Qt::SolidLine));
3835
	   }
3964
		}
3836
	}
3965
	}
3837
 
3966
 
3838
	// This is the total time, with pauses included, at the lower right
3967
	// This is the total time, with pauses included, at the lower right
3839
	// corner of the graphic.
3968
	// corner of the graphic.
3840
	QTime tm(0, 0, 0);
3969
	QTime tm(0, 0, 0);
Line 3843... Line 3972...
3843
	paint.setPen(QPen(frame, 1, Qt::SolidLine));
3972
	paint.setPen(QPen(frame, 1, Qt::SolidLine));
3844
//	paint.drawText(width - margin_right - 25, height - lineHeight, 50, lineHeight, Qt::AlignCenter, tm.toString((max_time >= 3600) ? "hh:mm:ss" : "mm:ss"));
3973
//	paint.drawText(width - margin_right - 25, height - lineHeight, 50, lineHeight, Qt::AlignCenter, tm.toString((max_time >= 3600) ? "hh:mm:ss" : "mm:ss"));
3845
	paint.drawText(width - margin_right - 25, height - lineHeight, 50, lineHeight, Qt::AlignCenter, kl->formatTime(tm, (max_time >= 3600) ? true : false));
3974
	paint.drawText(width - margin_right - 25, height - lineHeight, 50, lineHeight, Qt::AlignCenter, kl->formatTime(tm, (max_time >= 3600) ? true : false));
3846
 
3975
 
3847
	// Draw the minimal elevation, speed and/or heart rate
3976
	// Draw the minimal elevation, speed and/or heart rate
3848
	if (max_height > 0.0 || max_speed > 0.0)
3977
	if(max_height > 0.0 || max_speed > 0.0)
-
 
3978
	{
-
 
3979
		// left side
-
 
3980
		if(cuType == 1)
-
 
3981
		{
-
 
3982
			paint.setPen(QPen(red, 1, Qt::SolidLine));
-
 
3983
			paint.drawText(12, height - margin_bottom - lineHeight / 2, margin_left - 14, lineHeight, Qt::AlignRight, qs.sprintf("%.0f", minSpeed));
-
 
3984
		}
-
 
3985
		else
-
 
3986
		{
-
 
3987
			paint.setPen(QPen(barcol, 1, Qt::SolidLine));
-
 
3988
			paint.drawText(12, height - margin_bottom - lineHeight / 2, margin_left - 14, lineHeight, Qt::AlignRight, qs.sprintf("%.0f", (Units == 1) ? minHeight / 0.304 : minHeight));
-
 
3989
		}
-
 
3990
	}
-
 
3991
 
-
 
3992
	if(max_hr > 0 || max_speed > 0.0)
3849
	{
3993
	{
3850
	   // left side
-
 
3851
	   if (cuType == 1)
-
 
3852
	   {
-
 
3853
	      paint.setPen(QPen(red, 1, Qt::SolidLine));
-
 
3854
	      paint.drawText(12, height - margin_bottom - lineHeight / 2, margin_left - 14, lineHeight, Qt::AlignRight, qs.sprintf("%.0f", minSpeed));
-
 
3855
	   }
-
 
3856
	   else
-
 
3857
	   {
-
 
3858
	      paint.setPen(QPen(barcol, 1, Qt::SolidLine));
-
 
3859
	      paint.drawText(12, height - margin_bottom - lineHeight / 2, margin_left - 14, lineHeight, Qt::AlignRight, qs.sprintf("%.0f", (Units == 1) ? minHeight / 0.304 : minHeight));
-
 
3860
	   }
-
 
3861
	}
-
 
3862
	
-
 
3863
	if (max_hr > 0 || max_speed > 0.0)
-
 
3864
	{
-
 
3865
	   // right side
3994
		// right side
3866
	   if (cuType == 2)
3995
		if(cuType == 2)
3867
	   {
3996
		{
3868
	      paint.setPen(QPen(red, 1, Qt::SolidLine));
3997
			paint.setPen(QPen(red, 1, Qt::SolidLine));
3869
	      paint.drawText(width - margin_right + 2, height - margin_bottom - lineHeight / 2, margin_right - 14, lineHeight, Qt::AlignLeft, qs.sprintf("%.0f", minSpeed));
3998
			paint.drawText(width - margin_right + 2, height - margin_bottom - lineHeight / 2, margin_right - 14, lineHeight, Qt::AlignLeft, qs.sprintf("%.0f", minSpeed));
3870
	   }
3999
		}
3871
	   else
4000
		else
3872
	   {
4001
		{
3873
	      paint.setPen(QPen(blue, 1, Qt::SolidLine));
4002
			paint.setPen(QPen(blue, 1, Qt::SolidLine));
3874
	      paint.drawText(width - margin_right + 2, height - margin_bottom - lineHeight / 2, margin_right - 14, lineHeight, Qt::AlignLeft, qs.sprintf("%d", minHr));
4003
			paint.drawText(width - margin_right + 2, height - margin_bottom - lineHeight / 2, margin_right - 14, lineHeight, Qt::AlignLeft, qs.sprintf("%d", minHr));
3875
	   }
4004
		}
3876
	}
4005
	}
3877
 
4006
 
3878
	paint.setPen(QPen(mark, 1, Qt::SolidLine));
4007
	paint.setPen(QPen(mark, 1, Qt::SolidLine));
3879
 
4008
 
3880
	// Grid horizontal
4009
	// Grid horizontal
3881
	int factor = 0;
4010
	int factor = 0;
3882
	int target = 0;
4011
	int target = 0;
3883
 
4012
 
3884
	if (cuType == 0)	// Elevation and heart rate
4013
	if(cuType == 0)	// Elevation and heart rate
3885
	{
4014
	{
3886
	   factor = (meter) ? (maxHeight - minHeight) / (rh / 12) : (maxHr - minHr) / (rh / 12);
4015
		factor = (meter) ? (maxHeight - minHeight) / (rh / 12) : (maxHr - minHr) / (rh / 12);
3887
	   target = (meter) ? (int)(maxHeight - minHeight) : (maxHr - minHr);
4016
		target = (meter) ? (int)(maxHeight - minHeight) : (maxHr - minHr);
3888
	}
4017
	}
3889
	else if (cuType == 1)	// Speed and heart rate
4018
	else if(cuType == 1)	// Speed and heart rate
3890
	{
4019
	{
3891
	   factor = (meter) ? (maxSpeed - minSpeed) / (rh / 12) : (maxHr - minHr) / (rh / 12);
4020
		factor = (meter) ? (maxSpeed - minSpeed) / (rh / 12) : (maxHr - minHr) / (rh / 12);
3892
	   target = (meter) ? (int)(maxSpeed - minSpeed) : (maxHr - minHr);
4021
		target = (meter) ? (int)(maxSpeed - minSpeed) : (maxHr - minHr);
3893
	}
4022
	}
3894
	else			// Elevation and speed
4023
	else			// Elevation and speed
3895
	{
4024
	{
3896
	   factor = (meter) ? (maxHeight - minHeight) / (rh /12) : (maxSpeed - minSpeed) / (rh / 12);
4025
		factor = (meter) ? (maxHeight - minHeight) / (rh / 12) : (maxSpeed - minSpeed) / (rh / 12);
3897
	   target = (meter) ? (int)(maxHeight - minHeight) : (int)(maxSpeed - minSpeed);
4026
		target = (meter) ? (int)(maxHeight - minHeight) : (int)(maxSpeed - minSpeed);
3898
	}
4027
	}
3899
 
4028
 
3900
	// To prevent a division by zero error, we check the <factor>
4029
	// To prevent a division by zero error, we check the <factor>
3901
	if (factor == 0)
4030
	if(factor == 0)
3902
	   factor = 1;
4031
		factor = 1;
3903
 
4032
 
3904
	// Beside the horizontal part of the grid, we draw the scale on the
4033
	// Beside the horizontal part of the grid, we draw the scale on the
3905
	// left and the right side.
4034
	// left and the right side.
3906
	int oldy = height;
4035
	int oldy = height;
3907
 
4036
 
3908
	for (i = 0; i < target; i++)
4037
	for(i = 0; i < target; i++)
3909
	{
4038
	{
3910
	   if (i > 0 && !(i % factor))
4039
		if(i > 0 && !(i % factor))
3911
	   {
4040
		{
3912
	      x1 = margin_left + 1;
4041
			x1 = margin_left + 1;
3913
	      x2 = width - margin_right - 1;
4042
			x2 = width - margin_right - 1;
3914
	      y1 = y2 = rh - h_tick * i;
4043
			y1 = y2 = rh - h_tick * i;
3915
 
4044
 
3916
	      if (y1 < 12)
4045
			if(y1 < 12)
3917
		 break;
4046
				break;
3918
 
4047
 
3919
	      paint.drawLine(x1, y1, x2, y2);
4048
			paint.drawLine(x1, y1, x2, y2);
3920
 
4049
 
3921
	      if (y1 < (oldy - lineHeight))
4050
			if(y1 < (oldy - lineHeight))
3922
	      {
4051
			{
3923
		 if (meter)
4052
				if(meter)
3924
		 {
4053
				{
3925
		    paint.setPen(QPen(barcol, 1, Qt::SolidLine));
4054
					paint.setPen(QPen(barcol, 1, Qt::SolidLine));
-
 
4055
 
3926
		    // left side
4056
					// left side
3927
		    if (cuType == 1)
4057
					if(cuType == 1)
3928
		    {
4058
					{
3929
		       paint.setPen(QPen(red, 1, Qt::SolidLine));
4059
						paint.setPen(QPen(red, 1, Qt::SolidLine));
3930
		       paint.drawText(12, y1 - lineHeight / 2, margin_left - 14, lineHeight, Qt::AlignRight, qs.sprintf("%.1f", minSpeed + i));
4060
						paint.drawText(12, y1 - lineHeight / 2, margin_left - 14, lineHeight, Qt::AlignRight, qs.sprintf("%.1f", minSpeed + i));
3931
		    }
4061
					}
3932
		    else
4062
					else
3933
		       paint.drawText(12, y1 - lineHeight / 2, margin_left - 14, lineHeight, Qt::AlignRight, qs.sprintf("%.0f", (Units == 1) ? (minHeight + i) / 0.304 : minHeight + i));
4063
						paint.drawText(12, y1 - lineHeight / 2, margin_left - 14, lineHeight, Qt::AlignRight, qs.sprintf("%.0f", (Units == 1) ? (minHeight + i) / 0.304 : minHeight + i));
3934
 
4064
 
3935
		    // right side
4065
					// right side
3936
		    if (maxHr > 0 && cuType != 2)
4066
					if(maxHr > 0 && cuType != 2)
3937
		    {
4067
					{
3938
		       double hrscale = (double)(maxHr - minHr) / (double)target;
4068
						double hrscale = (double)(maxHr - minHr) / (double)target;
3939
		       paint.setPen(QPen(blue, 1, Qt::SolidLine));
4069
						paint.setPen(QPen(blue, 1, Qt::SolidLine));
3940
		       paint.drawText(width - margin_right + 2, y1 - lineHeight / 2, margin_right - 14, lineHeight, Qt::AlignLeft, qs.sprintf("%d", (int)((double)minHr + hrscale * (double)i)));
4070
						paint.drawText(width - margin_right + 2, y1 - lineHeight / 2, margin_right - 14, lineHeight, Qt::AlignLeft, qs.sprintf("%d", (int)((double)minHr + hrscale * (double)i)));
3941
		    }
4071
					}
3942
		    else
4072
					else
3943
		    {
4073
					{
3944
		       double spscale = (maxSpeed - minSpeed) / (double)target;
4074
						double spscale = (maxSpeed - minSpeed) / (double)target;
3945
 
4075
 
3946
		       if (cuType == 2)
4076
						if(cuType == 2)
3947
			  paint.setPen(QPen(red, 1, Qt::SolidLine));
4077
							paint.setPen(QPen(red, 1, Qt::SolidLine));
3948
		       else
4078
						else
3949
			  paint.setPen(QPen(blue, 1, Qt::SolidLine));
4079
							paint.setPen(QPen(blue, 1, Qt::SolidLine));
3950
 
4080
 
3951
		       paint.drawText(width - margin_right + 2, y1 - lineHeight / 2, margin_right - 14, lineHeight, Qt::AlignLeft, qs.sprintf("%.1f", (minSpeed + spscale * (double)i)));
4081
						paint.drawText(width - margin_right + 2, y1 - lineHeight / 2, margin_right - 14, lineHeight, Qt::AlignLeft, qs.sprintf("%.1f", (minSpeed + spscale * (double)i)));
3952
		    }
4082
					}
3953
		 }
4083
				}
3954
		 else
4084
				else
3955
		 {
4085
				{
3956
		    // right side
4086
					// right side
3957
		    if (cuType == 2)
4087
					if(cuType == 2)
3958
		    {
4088
					{
3959
		       paint.setPen(QPen(red, 1, Qt::SolidLine));
4089
						paint.setPen(QPen(red, 1, Qt::SolidLine));
3960
		       paint.drawText(width - margin_right + 2, y1 - lineHeight / 2, margin_right - 14, lineHeight, Qt::AlignLeft, qs.sprintf("%.1f", minSpeed + i));
4090
						paint.drawText(width - margin_right + 2, y1 - lineHeight / 2, margin_right - 14, lineHeight, Qt::AlignLeft, qs.sprintf("%.1f", minSpeed + i));
3961
		    }
4091
					}
3962
		    else
4092
					else
3963
		    {
4093
					{
3964
		       paint.setPen(QPen(blue, 1, Qt::SolidLine));
4094
						paint.setPen(QPen(blue, 1, Qt::SolidLine));
3965
		       paint.drawText(width - margin_right + 2, y1 - lineHeight / 2, margin_right - 14, lineHeight, Qt::AlignLeft, qs.sprintf("%d", minHr + i));
4095
						paint.drawText(width - margin_right + 2, y1 - lineHeight / 2, margin_right - 14, lineHeight, Qt::AlignLeft, qs.sprintf("%d", minHr + i));
3966
		    }
4096
					}
3967
 
4097
 
3968
		    // left side
4098
					// left side
3969
		    if ((cuType == 0 || cuType == 2) && max_height > 0)
4099
					if((cuType == 0 || cuType == 2) && max_height > 0)
3970
		    {
4100
					{
3971
		       double hrscale = (maxHeight - minHeight) / (double)target;
4101
						double hrscale = (maxHeight - minHeight) / (double)target;
3972
		       paint.setPen(QPen(barcol, 1, Qt::SolidLine));
4102
						paint.setPen(QPen(barcol, 1, Qt::SolidLine));
3973
		       paint.drawText(12, y1 - lineHeight / 2, margin_left - 14, lineHeight, Qt::AlignRight, qs.sprintf("%.0f", minHeight + hrscale * (double)i));
4103
						paint.drawText(12, y1 - lineHeight / 2, margin_left - 14, lineHeight, Qt::AlignRight, qs.sprintf("%.0f", minHeight + hrscale * (double)i));
3974
		    }
4104
					}
3975
		    else if (max_speed > 0 && cuType == 1)
4105
					else if(max_speed > 0 && cuType == 1)
3976
		    {
4106
					{
3977
		       double hrscale = (maxSpeed - minSpeed) / (double)target;
4107
						double hrscale = (maxSpeed - minSpeed) / (double)target;
3978
		       paint.setPen(QPen(red, 1, Qt::SolidLine));
4108
						paint.setPen(QPen(red, 1, Qt::SolidLine));
3979
		       paint.drawText(12, y1 - lineHeight / 2, margin_left - 14, lineHeight, Qt::AlignRight, qs.sprintf("%.1f", minSpeed + hrscale * (double)i));
4109
						paint.drawText(12, y1 - lineHeight / 2, margin_left - 14, lineHeight, Qt::AlignRight, qs.sprintf("%.1f", minSpeed + hrscale * (double)i));
3980
		    }
4110
					}
3981
		}
4111
				}
3982
 
4112
 
3983
		 paint.setPen(QPen(mark, 1, Qt::SolidLine));
4113
				paint.setPen(QPen(mark, 1, Qt::SolidLine));
3984
		 oldy = y1;
4114
				oldy = y1;
3985
	      }
4115
			}
3986
	   }
4116
		}
3987
	}
4117
	}
3988
 
4118
 
3989
	// To make our graphics more beautiful, we draw lines for the
4119
	// To make our graphics more beautiful, we draw lines for the
3990
	// heart rate limits and the average heart rate.
4120
	// heart rate limits and the average heart rate.
3991
	if (max_hr > 0 && cuType != 2)
4121
	if(max_hr > 0 && cuType != 2)
3992
	{
4122
	{
3993
	int ay1, ay2, ay3, ay4, ay5;
4123
		int ay1, ay2, ay3, ay4, ay5;
-
 
4124
 
-
 
4125
		x1 = margin_left + 1;
-
 
4126
		x2 = width - margin_right - 1;
-
 
4127
 
-
 
4128
		if(meter)
-
 
4129
		{
-
 
4130
			double hrscale = rh / (double)(maxHr - minHr);
-
 
4131
			ay1 = (double)rh - (double)(lower1 - minHr) * hrscale;
-
 
4132
			ay2 = (double)rh - (double)(lower2 - minHr) * hrscale;
-
 
4133
			ay3 = (double)rh - (double)(lower3 - minHr) * hrscale;
-
 
4134
			ay4 = (double)rh - (double)(upper3 - minHr) * hrscale;
-
 
4135
			ay5 = (double)rh - (double)(avg_hr - minHr) * hrscale;
-
 
4136
		}
-
 
4137
		else
-
 
4138
		{
-
 
4139
			ay1 = (double)rh - (double)(lower1 - minHr) * h_tick;
-
 
4140
			ay2 = (double)rh - (double)(lower2 - minHr) * h_tick;
-
 
4141
			ay3 = (double)rh - (double)(lower3 - minHr) * h_tick;
-
 
4142
			ay4 = (double)rh - (double)(upper3 - minHr) * h_tick;
-
 
4143
			ay5 = (double)rh - (double)(avg_hr - minHr) * h_tick;
-
 
4144
		}
-
 
4145
 
-
 
4146
		paint.setPen(QPen(barcol2, 1, Qt::DashLine));	// color for limits
3994
 
4147
 
3995
	   x1 = margin_left + 1;
4148
		if(lower1 > minHr && lower1 < maxHr)
3996
	   x2 = width - margin_right - 1;
4149
			paint.drawLine(x1, ay1, x2, ay1);
3997
 
4150
 
3998
	   if (meter)
-
 
3999
	   {
-
 
4000
	      double hrscale = rh / (double)(maxHr - minHr);
-
 
4001
	      ay1 = (double)rh - (double)(lower1 - minHr) * hrscale;
-
 
4002
	      ay2 = (double)rh - (double)(lower2 - minHr) * hrscale;
-
 
4003
	      ay3 = (double)rh - (double)(lower3 - minHr) * hrscale;
-
 
4004
	      ay4 = (double)rh - (double)(upper3 - minHr) * hrscale;
-
 
4005
	      ay5 = (double)rh - (double)(avg_hr - minHr) * hrscale;
-
 
4006
	   }
-
 
4007
	   else
-
 
4008
	   {
-
 
4009
	      ay1 = (double)rh - (double)(lower1 - minHr) * h_tick;
-
 
4010
	      ay2 = (double)rh - (double)(lower2 - minHr) * h_tick;
-
 
4011
	      ay3 = (double)rh - (double)(lower3 - minHr) * h_tick;
-
 
4012
	      ay4 = (double)rh - (double)(upper3 - minHr) * h_tick;
-
 
4013
	      ay5 = (double)rh - (double)(avg_hr - minHr) * h_tick;
-
 
4014
	   }
-
 
4015
 
-
 
4016
	   paint.setPen(QPen(barcol2, 1, Qt::DashLine));	// color for limits
-
 
4017
 
-
 
4018
	   if (lower1 > minHr && lower1 < maxHr)
-
 
4019
	      paint.drawLine(x1, ay1, x2, ay1);
-
 
4020
 
-
 
4021
	   if (lower2 > minHr && lower2 < maxHr)
4151
		if(lower2 > minHr && lower2 < maxHr)
4022
	      paint.drawLine(x1, ay2, x2, ay2);
4152
			paint.drawLine(x1, ay2, x2, ay2);
4023
 
-
 
4024
	   if (lower3 > minHr && lower3 < maxHr)
-
 
4025
	      paint.drawLine(x1, ay3, x2, ay3);
-
 
4026
 
4153
 
4027
	   if (upper3 > minHr && upper3 < maxHr)
4154
		if(lower3 > minHr && lower3 < maxHr)
4028
	      paint.drawLine(x1, ay4, x2, ay4);
4155
			paint.drawLine(x1, ay3, x2, ay3);
4029
 
4156
 
-
 
4157
		if(upper3 > minHr && upper3 < maxHr)
4030
	   paint.setPen(QPen(red, 1, Qt::DashDotLine));	// color for average heart rate
4158
			paint.drawLine(x1, ay4, x2, ay4);
4031
 
4159
 
-
 
4160
		paint.setPen(QPen(red, 1, Qt::DashDotLine));	// color for average heart rate
-
 
4161
 
4032
	   if (avg_hr > minHr && avg_hr < maxHr)
4162
		if(avg_hr > minHr && avg_hr < maxHr)
4033
	      paint.drawLine(x1, ay5, x2, ay5);
4163
			paint.drawLine(x1, ay5, x2, ay5);
4034
	}
4164
	}
4035
 
4165
 
4036
	// Now we have a grid and we've done the scaling.
4166
	// Now we have a grid and we've done the scaling.
4037
	// This is the point where we draw the curves itself.
4167
	// This is the point where we draw the curves itself.
4038
	// We use different colors to draw the lines:
4168
	// We use different colors to draw the lines:
Line 4048... Line 4178...
4048
	sy1 = sy2 = sx1 = sx2 = 0;
4178
	sy1 = sy2 = sx1 = sx2 = 0;
4049
	int hEc = 0;
4179
	int hEc = 0;
4050
	i = 0;
4180
	i = 0;
4051
	AVGHEIGHT *avgHakt, *avgHfirst, *avgHlast, *avgHeight = 0;
4181
	AVGHEIGHT *avgHakt, *avgHfirst, *avgHlast, *avgHeight = 0;
4052
	avgHfirst = avgHlast = 0;
4182
	avgHfirst = avgHlast = 0;
-
 
4183
 
4053
	// To even the surface lines, we store every altitude in the
4184
	// To even the surface lines, we store every altitude in the
4054
	// memory, by building a chain. Then, if the user has set in the
4185
	// memory, by building a chain. Then, if the user has set in the
4055
	// settings (Contour == true), we will even the line by calculating
4186
	// settings (Contour == true), we will even the line by calculating
4056
	// the average of 10 messure points and setting every value to the
4187
	// the average of 10 messure points and setting every value to the
4057
	// average, who is up or down more than 2 meters from the average.
4188
	// average, who is up or down more than 2 meters from the average.
4058
	while ((point = ds.getPoint(i)) != 0)
4189
	while((point = ds.getPoint(i)) != 0)
4059
	{
4190
	{
4060
	   if (point->alt > 20000.0 || point->alt < -1000.0)
4191
		if(point->alt > 20000.0 || point->alt < -1000.0)
4061
	   {
4192
		{
4062
	      i++;
4193
			i++;
4063
	      continue;
4194
			continue;
4064
	   }
4195
		}
4065
 
4196
 
4066
	   if (!avgHeight)
4197
		if(!avgHeight)
4067
	   {
4198
		{
4068
	      avgHeight = new AVGHEIGHT;
4199
			avgHeight = new AVGHEIGHT;
4069
	      avgHeight->alt = point->alt;
4200
			avgHeight->alt = point->alt;
4070
	      avgHeight->pos = hEc;
4201
			avgHeight->pos = hEc;
4071
	      avgHeight->prev = 0;
4202
			avgHeight->prev = 0;
4072
	      avgHeight->next = 0;
4203
			avgHeight->next = 0;
4073
	      avgHakt = avgHeight;
4204
			avgHakt = avgHeight;
4074
	      avgHfirst = avgHeight;
4205
			avgHfirst = avgHeight;
4075
	   }
4206
		}
4076
	   else
4207
		else
4077
	   {
4208
		{
4078
	      avgHakt = new AVGHEIGHT;
4209
			avgHakt = new AVGHEIGHT;
4079
	      avgHakt->alt = point->alt;
4210
			avgHakt->alt = point->alt;
4080
	      avgHakt->pos = hEc;
4211
			avgHakt->pos = hEc;
4081
	      avgHakt->next = 0;
4212
			avgHakt->next = 0;
4082
	      avgHakt->prev = avgHeight;
4213
			avgHakt->prev = avgHeight;
4083
	      avgHeight->next = avgHakt;
4214
			avgHeight->next = avgHakt;
4084
	      avgHeight = avgHakt;
4215
			avgHeight = avgHakt;
4085
	   }
4216
		}
4086
 
-
 
4087
	   // FIXME: Currently we can not draw below 0 meters, because the
-
 
4088
	   // base line is always 0!
-
 
4089
	   if (avgHakt->alt < minHeight)
-
 
4090
	      avgHakt->alt = minHeight;
-
 
4091
 
4217
 
-
 
4218
		// FIXME: Currently we can not draw below 0 meters, because the
-
 
4219
		// base line is always 0!
-
 
4220
		if(avgHakt->alt < minHeight)
-
 
4221
			avgHakt->alt = minHeight;
-
 
4222
 
4092
	   hEc++;
4223
		hEc++;
4093
	   i++;
4224
		i++;
4094
	}
4225
	}
4095
 
4226
 
4096
	avgHlast = avgHeight;
4227
	avgHlast = avgHeight;
-
 
4228
 
4097
	// If wanted, even the lines
4229
	// If wanted, even the lines
4098
	if (Contour && hEc > 0 && cuType != 0)
4230
	if(Contour && hEc > 0 && cuType != 0)
4099
	{
4231
	{
4100
	double alt[100], avg, avg1, avg2, avg3, avg4;
4232
		double alt[100], avg, avg1, avg2, avg3, avg4;
4101
	int a, pos;
4233
		int a, pos;
4102
 
4234
 
4103
	   for (i = 0; i < (hEc + 100); i += 100)
4235
		for(i = 0; i < (hEc + 100); i += 100)
4104
	   {
4236
		{
4105
	      avg = avg1 = avg2 = avg3 = avg4 = 0.0;
4237
			avg = avg1 = avg2 = avg3 = avg4 = 0.0;
4106
	      pos = 0;
4238
			pos = 0;
4107
 
4239
 
4108
	      for (a = 0; a < 100; a++)
4240
			for(a = 0; a < 100; a++)
4109
	      {
4241
			{
4110
		 alt[a] = getAvgAlt(avgHfirst, i + a);
4242
				alt[a] = getAvgAlt(avgHfirst, i + a);
4111
		 avg += alt[a];
4243
				avg += alt[a];
4112
 
4244
 
4113
		 if (a < 25)
4245
				if(a < 25)
4114
		    avg1 += alt[a];
4246
					avg1 += alt[a];
4115
		 else if (a < 50)
4247
				else if(a < 50)
4116
		    avg2 += alt[a];
4248
					avg2 += alt[a];
4117
		 else if (a < 75)
4249
				else if(a < 75)
4118
		    avg3 += alt[a];
4250
					avg3 += alt[a];
4119
		 else
4251
				else
4120
		    avg4 += alt[a];
4252
					avg4 += alt[a];
4121
	      }
4253
			}
4122
 
4254
 
4123
	      if ((i + 100) >= hEc)
4255
			if((i + 100) >= hEc)
4124
		 avg /= (double)(hEc - i) + 1.0;
4256
				avg /= (double)(hEc - i) + 1.0;
4125
	      else
4257
			else
4126
		 avg /= 100.0;
4258
				avg /= 100.0;
4127
 
4259
 
4128
	      for (a = 0; a < 100; a++)
4260
			for(a = 0; a < 100; a++)
4129
	      {
4261
			{
4130
		 if ((avgHakt = getAvgPtr(avgHfirst, i + a)) != 0)
4262
				if((avgHakt = getAvgPtr(avgHfirst, i + a)) != 0)
4131
		 {
4263
				{
4132
		    if ((avgHakt->alt - avg) > 2 || (avgHakt->alt - avg) < -2)
4264
					if((avgHakt->alt - avg) > 2 || (avgHakt->alt - avg) < -2)
4133
		       avgHakt->alt = avg;
4265
						avgHakt->alt = avg;
4134
		 }
4266
				}
4135
	      }
4267
			}
4136
	   }
4268
		}
4137
	}
4269
	}
4138
 
4270
 
4139
	// plot the elevation, speed and/or heart rate. Depends on <cuType>)
4271
	// plot the elevation, speed and/or heart rate. Depends on <cuType>)
4140
	i = 0;
4272
	i = 0;
4141
	int j = 0;
4273
	int j = 0;
4142
	POINT *oldPoint = 0;
4274
	POINT *oldPoint = 0;
4143
	double speed = 0.0;	// calculated speed
4275
	double speed = 0.0;	// calculated speed
4144
	bool pause = false;	// filter pause out of speed
4276
	bool pause = false;	// filter pause out of speed
4145
	unsigned long t1, t2;
4277
	unsigned long t1, t2;
4146
	t1 = t2 = 0;
4278
	t1 = t2 = 0;
4147
	
4279
 
4148
	while ((point = ds.getPoint(i)) != 0)
4280
	while((point = ds.getPoint(i)) != 0)
4149
	{
4281
	{
4150
	   if (!oldPoint)
4282
		if(!oldPoint)
-
 
4283
			oldPoint = point;
-
 
4284
 
-
 
4285
		// calculate the y position based on the time
-
 
4286
		qt = garmin_dtime(point->time);
-
 
4287
		secs = zeit.secsTo(qt->time());
-
 
4288
		delete qt;
-
 
4289
		x2 = secs * w_tick + margin_left + 1;
-
 
4290
		hx2 = x2;
-
 
4291
		sx2 = x2;
-
 
4292
 
-
 
4293
		if(x1 == 0)
-
 
4294
			x1 = x2;
-
 
4295
 
-
 
4296
		if(hx1 == 0)
-
 
4297
			hx1 = hx2;
-
 
4298
 
-
 
4299
		if(sx1 == 0)
-
 
4300
			sx1 = sx2;
-
 
4301
 
-
 
4302
		// The speed is not very exact, because smallest time is
-
 
4303
		// one second. This allows a maximum error of 99 hundredths
-
 
4304
		// of a second, what is very close to one second. Because of
-
 
4305
		// this, speed seems to hop for every messure point. This
-
 
4306
		// looks ugly, but currently I don't know how to make it
-
 
4307
		// better.
-
 
4308
		if(cuType == 1 || cuType == 2)	// Draw speed?
-
 
4309
		{
-
 
4310
			double dist;
-
 
4311
			double sc;
-
 
4312
 
-
 
4313
			if(!pause && point->distance > 1.0e10)
-
 
4314
			{
-
 
4315
				pause = true;
-
 
4316
				t1 = point->time;
-
 
4317
			}
-
 
4318
			else if(pause)
-
 
4319
			{
-
 
4320
				pause = false;
-
 
4321
				t2 = point->time;
-
 
4322
				i += 2;
-
 
4323
				continue;
-
 
4324
			}
-
 
4325
 
-
 
4326
			if(point->distance >= 0.1 && point->distance < 1.0e10)
-
 
4327
			{
-
 
4328
				dist = point->distance - oldPoint->distance;
-
 
4329
				sc = point->time - oldPoint->time;
-
 
4330
				LAP *runde = ds.getLapT(point->time);
-
 
4331
 
-
 
4332
				if(t2 > t1)
-
 
4333
				{
-
 
4334
					sc -= t2 - t1;
-
 
4335
 
-
 
4336
					if(sc <= 0.0)
-
 
4337
						sc = 1.0;		// at least 1 second!
-
 
4338
				}
-
 
4339
 
-
 
4340
				speed = (dist / sc) * 3.6;
-
 
4341
 
-
 
4342
				if(runde && runde->max_speed > 0.0 && speed > (runde->max_speed * 3.6))
-
 
4343
					speed = runde->max_speed * 3.6;
-
 
4344
 
-
 
4345
				if(Units == 1)
-
 
4346
					speed /= 1.609344;
-
 
4347
 
-
 
4348
				if(speed < minSpeed || speed > 400.0)
-
 
4349
					speed = minSpeed;
-
 
4350
 
-
 
4351
				if((meter && cuType == 1) || (!meter && cuType == 2))
-
 
4352
					y2 = (double)rh - (speed - minSpeed) * h_tick;
-
 
4353
				else
-
 
4354
				{
-
 
4355
					double hrscale = rh / (maxSpeed - minSpeed);
-
 
4356
					y2 = (double)rh - (speed - minSpeed) * hrscale;
-
 
4357
				}
-
 
4358
 
-
 
4359
				if(y1 == 0)
-
 
4360
					y1 = y2;
-
 
4361
 
-
 
4362
				paint.setPen(QPen(red, 1, Qt::SolidLine));
-
 
4363
				paint.drawLine(x1, y1, x2, y2);
-
 
4364
				y1 = y2;
-
 
4365
				x1 = x2;
-
 
4366
				t1 = t2 = 0;
4151
	      oldPoint = point;
4367
				oldPoint = point;
-
 
4368
			}
-
 
4369
		}
4152
 
4370
 
4153
	   // calculate the y position based on the time
-
 
4154
	   qt = garmin_dtime(point->time);
-
 
4155
	   secs = zeit.secsTo(qt->time());
-
 
4156
	   delete qt;
-
 
4157
	   x2 = secs * w_tick + margin_left + 1;
-
 
4158
	   hx2 = x2;
-
 
4159
	   sx2 = x2;
-
 
4160
 
-
 
4161
	   if (x1 == 0)
-
 
4162
	      x1 = x2;
-
 
4163
 
-
 
4164
	   if (hx1 == 0)
-
 
4165
	      hx1 = hx2;
-
 
4166
 
-
 
4167
	   if (sx1 == 0)
-
 
4168
	      sx1 = sx2;
-
 
4169
 
-
 
4170
	   // The speed is not very exact, because smallest time is
-
 
4171
	   // one second. This allows a maximum error of 99 hundredths
-
 
4172
	   // of a second, what is very close to one second. Because of
-
 
4173
	   // this, speed seems to hop for every messure point. This
-
 
4174
	   // looks ugly, but currently I don't know how to make it
-
 
4175
	   // better.
-
 
4176
	   if (cuType == 1 || cuType == 2)	// Draw speed?
4371
		if(cuType == 0 || cuType == 2)		// Draw elevation?
4177
	   {
-
 
4178
	      double dist;
-
 
4179
	      double sc;
-
 
4180
 
-
 
4181
	      if (!pause && point->distance > 1.0e10)
-
 
4182
	      {
-
 
4183
		 pause = true;
-
 
4184
		 t1 = point->time;
-
 
4185
	      }
-
 
4186
	      else if (pause)
-
 
4187
	      {
-
 
4188
		 pause = false;
-
 
4189
		 t2 = point->time;
-
 
4190
		 i += 2;
-
 
4191
		 continue;
-
 
4192
	      }
-
 
4193
 
-
 
4194
	      if (point->distance >= 0.1 && point->distance < 1.0e10)
-
 
4195
	      {
-
 
4196
		 dist = point->distance - oldPoint->distance;
-
 
4197
		 sc = point->time - oldPoint->time;
-
 
4198
		 LAP *runde = ds.getLapT (point->time);
-
 
4199
 
-
 
4200
		 if (t2 > t1)
-
 
4201
		 {
4372
		{
4202
		    sc -= t2 - t1;
-
 
4203
 
-
 
4204
		    if (sc <= 0.0)
-
 
4205
		       sc = 1.0;		// at least 1 second!
-
 
4206
		 }
-
 
4207
 
-
 
4208
		 speed = (dist / sc) * 3.6;
-
 
4209
 
-
 
4210
		 if (runde && runde->max_speed > 0.0 && speed > (runde->max_speed * 3.6))
-
 
4211
		    speed = runde->max_speed * 3.6;
-
 
4212
 
-
 
4213
		 if (Units == 1)
-
 
4214
		    speed /= 1.609344;
-
 
4215
 
-
 
4216
		 if (speed < minSpeed || speed > 400.0)
-
 
4217
		    speed = minSpeed;
-
 
4218
 
-
 
4219
		 if ((meter && cuType == 1) || (!meter && cuType == 2))
-
 
4220
		    y2 = (double)rh - (speed - minSpeed) * h_tick;
-
 
4221
		 else
-
 
4222
		 {
-
 
4223
		    double hrscale = rh / (maxSpeed - minSpeed);
-
 
4224
		    y2 = (double)rh - (speed - minSpeed) * hrscale;
-
 
4225
		 }
-
 
4226
 
-
 
4227
		 if (y1 == 0)
-
 
4228
		    y1 = y2;
-
 
4229
 
-
 
4230
		 paint.setPen(QPen(red, 1, Qt::SolidLine));
-
 
4231
		 paint.drawLine(x1, y1, x2, y2);
-
 
4232
		 y1 = y2;
-
 
4233
		 x1 = x2;
-
 
4234
		 t1 = t2 = 0;
-
 
4235
		 oldPoint = point;
-
 
4236
	      }
-
 
4237
	   }
-
 
4238
 
-
 
4239
	   if (cuType == 0 || cuType == 2)		// Draw elevation?
-
 
4240
	   {
-
 
4241
	      if (point->alt < 20000.0 && point->alt > -1000.0)
4373
			if(point->alt < 20000.0 && point->alt > -1000.0)
4242
	      {
4374
			{
4243
	      double alt = getAvgAlt(avgHfirst, j);
4375
				double alt = getAvgAlt(avgHfirst, j);
4244
 
4376
 
4245
		 j++;
4377
				j++;
4246
 
4378
 
4247
		 if (meter)
4379
				if(meter)
4248
		    sy2 = (double)rh - (alt - minHeight) * h_tick;
4380
					sy2 = (double)rh - (alt - minHeight) * h_tick;
4249
		 else
4381
				else
4250
		 {
4382
				{
4251
		    double hrscale = rh / (maxHeight - minHeight);
4383
					double hrscale = rh / (maxHeight - minHeight);
4252
		    sy2 = (double)rh - (alt - minHeight) * hrscale;
4384
					sy2 = (double)rh - (alt - minHeight) * hrscale;
4253
		 }
4385
				}
4254
 
4386
 
4255
		 if (sy1 == 0)
4387
				if(sy1 == 0)
4256
		    sy1 = sy2;
4388
					sy1 = sy2;
4257
 
4389
 
4258
		 paint.setPen(QPen(barcol, 1, Qt::SolidLine));
4390
				paint.setPen(QPen(barcol, 1, Qt::SolidLine));
4259
		 paint.drawLine(sx1, sy1, sx2, sy2);
4391
				paint.drawLine(sx1, sy1, sx2, sy2);
4260
		 sy1 = sy2;
4392
				sy1 = sy2;
4261
		 sx1 = sx2;
4393
				sx1 = sx2;
4262
	      }
4394
			}
4263
	   }
4395
		}
4264
 
4396
 
4265
	   if (point->heart_rate > 0 && cuType < 2)	// Draw heart rate?
4397
		if(point->heart_rate > 0 && cuType < 2)	// Draw heart rate?
4266
	   {
4398
		{
4267
	      if (meter)
4399
			if(meter)
4268
	      {
4400
			{
4269
		 double hrscale = rh / (double)(maxHr - minHr);
4401
				double hrscale = rh / (double)(maxHr - minHr);
4270
		 hy2 = (double)rh - (double)(point->heart_rate - minHr) * hrscale;
4402
				hy2 = (double)rh - (double)(point->heart_rate - minHr) * hrscale;
4271
	      }
4403
			}
4272
	      else
4404
			else
4273
		 hy2 = (double)rh - (double)(point->heart_rate - minHr) * h_tick;
4405
				hy2 = (double)rh - (double)(point->heart_rate - minHr) * h_tick;
4274
 
4406
 
4275
	      if (hy1 == 0)
4407
			if(hy1 == 0)
4276
		 hy1 = hy2;
4408
				hy1 = hy2;
4277
 
4409
 
4278
	      paint.setPen(QPen(blue, 1, Qt::SolidLine));
4410
			paint.setPen(QPen(blue, 1, Qt::SolidLine));
4279
	      paint.drawLine(hx1, hy1, hx2, hy2);
4411
			paint.drawLine(hx1, hy1, hx2, hy2);
4280
	      hy1 = hy2;
4412
			hy1 = hy2;
4281
	      hx1 = hx2;
4413
			hx1 = hx2;
4282
	   }
4414
		}
4283
 
4415
 
4284
	   i++;
4416
		i++;
4285
	}
4417
	}
4286
 
4418
 
4287
	paint.end();
4419
	paint.end();
4288
	ui_sportwatcherWidgetBase.imgProfile->setPixmap(pmProfile);
4420
	ui_sportwatcherWidgetBase.imgProfile->setPixmap(pmProfile);
4289
 
4421
 
4290
	// free the chain of altitudes
4422
	// free the chain of altitudes
4291
	avgHakt = avgHfirst;
4423
	avgHakt = avgHfirst;
4292
 
4424
 
4293
	while (avgHakt)
4425
	while(avgHakt)
4294
	{
4426
	{
4295
	   avgHeight = avgHakt->next;
4427
		avgHeight = avgHakt->next;
4296
	   delete avgHakt;
4428
		delete avgHakt;
4297
	   avgHakt = avgHeight;
4429
		avgHakt = avgHeight;
4298
	}
4430
	}
4299
 
4431
 
4300
	DIRTY = false;
4432
	DIRTY = false;
4301
}
4433
}
4302
 
4434
 
4303
void sportwatcherWidget::showThreeCurve(int pw, int ph)
4435
void sportwatcherWidget::showThreeCurve(int pw, int ph)
4304
{
4436
{
4305
QPainter ptHR, ptElevation, ptSpeed;
4437
	QPainter ptHR, ptElevation, ptSpeed;
4306
int width, height, wdHR, htHR, wdElev, htElev, wdSpeed, htSpeed;
4438
	int width, height, wdHR, htHR, wdElev, htElev, wdSpeed, htSpeed;
4307
int i, secs;
4439
	int i, secs;
4308
int lineHeight, margin_left, margin_right, margin_bottom;
4440
	int lineHeight, margin_left, margin_right, margin_bottom;
4309
int x1, y1, x2, y2;		// Coordinates
4441
	int x1, y1, x2, y2;		// Coordinates
4310
double maxHeight, minHeight, maxSpeed, minSpeed;
4442
	double maxHeight, minHeight, maxSpeed, minSpeed;
4311
int maxHr, minHr, rh, rhHR, rhElev, rhSpeed;
4443
	int maxHr, minHr, rh, rhHR, rhElev, rhSpeed;
4312
POINT *point;
4444
	POINT *point;
4313
RUN_NODE *rn;
4445
	RUN_NODE *rn;
4314
LAP *lp;
4446
	LAP *lp;
4315
double wtiHR, htiHR, wtiElev, htiElev, wtiSpeed, htiSpeed;
4447
	double wtiHR, htiHR, wtiElev, htiElev, wtiSpeed, htiSpeed;
4316
double w_tick, h_tick;		// Number of pixels one "tick" has;
4448
	double w_tick, h_tick;		// Number of pixels one "tick" has;
-
 
4449
 
4317
				// This depends on the width and height
4450
	// This depends on the width and height
4318
				// of the image.
4451
	// of the image.
4319
	// First we draw a grid based on the min and max
4452
	// First we draw a grid based on the min and max
4320
	// values detected in the function showLap(). In case
4453
	// values detected in the function showLap(). In case
4321
	// all values are 0, we exit here.
4454
	// all values are 0, we exit here.
4322
	if (min_hr == 0 && max_hr == 0 && min_height == 0.0 && max_height == 0.0)
4455
	if(min_hr == 0 && max_hr == 0 && min_height == 0.0 && max_height == 0.0)
4323
	   return;
4456
		return;
4324
 
4457
 
4325
	if (!ActivePrint && (!DIRTY || curTab != 2))
4458
	if(!ActivePrint && (!DIRTY || curTab != 2))
4326
	   return;
4459
		return;
4327
 
4460
 
4328
	w_tick = h_tick = 0.0;
4461
	w_tick = h_tick = 0.0;
4329
	rh = 0;
4462
	rh = 0;
4330
	width = height = 0;
4463
	width = height = 0;
-
 
4464
 
4331
	// Get the dimensions of the available draw area
4465
	// Get the dimensions of the available draw area
4332
	// First for heart rate
4466
	// First for heart rate
4333
	if (!ActivePrint)
4467
	if(!ActivePrint)
4334
	{
4468
	{
4335
	   wdHR = ui_sportwatcherWidgetBase.grHR->width() - 2;
4469
		wdHR = ui_sportwatcherWidgetBase.grHR->width() - 2;
4336
	   htHR = ui_sportwatcherWidgetBase.grHR->height();
4470
		htHR = ui_sportwatcherWidgetBase.grHR->height();
4337
	   pmHR = QPixmap(wdHR, htHR);
4471
		pmHR = QPixmap(wdHR, htHR);
4338
	   // Then for elevation
4472
		// Then for elevation
4339
	   wdElev = ui_sportwatcherWidgetBase.grElevation->width() - 2;
4473
		wdElev = ui_sportwatcherWidgetBase.grElevation->width() - 2;
4340
	   htElev = ui_sportwatcherWidgetBase.grElevation->height();
4474
		htElev = ui_sportwatcherWidgetBase.grElevation->height();
4341
	   pmElevation = QPixmap(wdElev, htElev);
4475
		pmElevation = QPixmap(wdElev, htElev);
4342
	   // And at last for speed
4476
		// And at last for speed
4343
	   wdSpeed = ui_sportwatcherWidgetBase.grSpeed->width() - 2;
4477
		wdSpeed = ui_sportwatcherWidgetBase.grSpeed->width() - 2;
4344
	   htSpeed = ui_sportwatcherWidgetBase.grSpeed->height();
4478
		htSpeed = ui_sportwatcherWidgetBase.grSpeed->height();
4345
	   pmSpeed = QPixmap(wdSpeed, htSpeed);
4479
		pmSpeed = QPixmap(wdSpeed, htSpeed);
4346
	   // Initialize QPainter
4480
		// Initialize QPainter
4347
	   ptHR.begin(&pmHR);
4481
		ptHR.begin(&pmHR);
4348
	   ptElevation.begin(&pmElevation);
4482
		ptElevation.begin(&pmElevation);
4349
	   ptSpeed.begin(&pmSpeed);
4483
		ptSpeed.begin(&pmSpeed);
4350
	}
4484
	}
4351
	else if (ActivePrint && pw > 0 && ph > 0)
4485
	else if(ActivePrint && pw > 0 && ph > 0)
4352
	{
4486
	{
4353
	   wdHR = wdElev = wdSpeed = pw;
4487
		wdHR = wdElev = wdSpeed = pw;
4354
	   htHR = htElev = htSpeed = ph;
4488
		htHR = htElev = htSpeed = ph;
4355
	   prHR = prElevation = prSpeed = QPixmap(pw, ph);
4489
		prHR = prElevation = prSpeed = QPixmap(pw, ph);
4356
	   ptHR.begin(&prHR);
4490
		ptHR.begin(&prHR);
4357
	   ptElevation.begin(&prElevation);
4491
		ptElevation.begin(&prElevation);
4358
	   ptSpeed.begin(&prSpeed);
4492
		ptSpeed.begin(&prSpeed);
4359
	}
4493
	}
4360
	else
4494
	else
4361
	   return;
4495
		return;
4362
 
4496
 
4363
	// we need a somewhat bigger area to draw our curves than
4497
	// we need a somewhat bigger area to draw our curves than
4364
	// we have with the real min and max values.
4498
	// we have with the real min and max values.
4365
	if (max_height > 0.0)
4499
	if(max_height > 0.0)
4366
	{
4500
	{
4367
	double add = (max_height - min_height) / 100.0 * 5.0;	// Percent
4501
		double add = (max_height - min_height) / 100.0 * 5.0;	// Percent
4368
 
4502
 
4369
	   maxHeight = max_height + add;
4503
		maxHeight = max_height + add;
4370
	   minHeight = min_height - add;
4504
		minHeight = min_height - add;
4371
 
4505
 
4372
	   if (minHeight < 0.0)		// make sure, we are not too deep
4506
		if(minHeight < 0.0)		// make sure, we are not too deep
4373
	      minHeight = 0.0;
4507
			minHeight = 0.0;
4374
	}
4508
	}
4375
	else
4509
	else
4376
	   maxHeight = minHeight = 0.0;
4510
		maxHeight = minHeight = 0.0;
4377
 
4511
 
4378
	if (max_speed > 0.0)
4512
	if(max_speed > 0.0)
4379
	{
4513
	{
4380
	double add = (max_speed - min_speed) / 100.0 * 5.0;	// Percent
4514
		double add = (max_speed - min_speed) / 100.0 * 5.0;	// Percent
4381
 
4515
 
4382
	   maxSpeed = max_speed + add;
4516
		maxSpeed = max_speed + add;
4383
	   minSpeed = min_speed - add;
4517
		minSpeed = min_speed - add;
4384
 
4518
 
4385
	   if (minSpeed < 0.0)		// make sure, we are not too deep
4519
		if(minSpeed < 0.0)		// make sure, we are not too deep
4386
	      minSpeed = 0.0;
4520
			minSpeed = 0.0;
4387
	}
4521
	}
4388
	else
4522
	else
4389
	   maxSpeed = minSpeed = 0.0;
4523
		maxSpeed = minSpeed = 0.0;
4390
 
4524
 
4391
	if (max_hr > 0)
4525
	if(max_hr > 0)
4392
	{
4526
	{
4393
	   maxHr = max_hr + 10;
4527
		maxHr = max_hr + 10;
4394
	   minHr = min_hr - 10;
4528
		minHr = min_hr - 10;
4395
 
4529
 
4396
	   if (minHr < 0)
4530
		if(minHr < 0)
4397
	      minHr = 0;
4531
			minHr = 0;
4398
	}
4532
	}
4399
	else
4533
	else
4400
	   maxHr = minHr = 0;
4534
		maxHr = minHr = 0;
4401
 
4535
 
4402
	// Define colors
4536
	// Define colors
4403
	QColor background(220, 220, 220);	// Background of graphic
4537
	QColor background(220, 220, 220);	// Background of graphic
4404
	QColor mark(255, 255, 255);		// Lines inside curve area
4538
	QColor mark(255, 255, 255);		// Lines inside curve area
4405
	QColor hlight(180, 180, 180);		// area of current lap
4539
	QColor hlight(180, 180, 180);		// area of current lap
Line 4421... Line 4555...
4421
	margin_bottom = 12;
4555
	margin_bottom = 12;
4422
	lineHeight = 10;
4556
	lineHeight = 10;
4423
//	rh = height - margin_bottom - 1;
4557
//	rh = height - margin_bottom - 1;
4424
 
4558
 
4425
	// Calculate the ticks for width and height for every draw area
4559
	// Calculate the ticks for width and height for every draw area
4426
	for (i = 0; i < 3; i++)
4560
	for(i = 0; i < 3; i++)
4427
	{
4561
	{
4428
	   if (i == 2)	// Speed?
4562
		if(i == 2)	// Speed?
4429
	   {
4563
		{
4430
	      rhSpeed = htSpeed - margin_bottom - 1;
4564
			rhSpeed = htSpeed - margin_bottom - 1;
4431
	      wtiSpeed = (double)(wdSpeed - (margin_left + margin_right)) / (max_time + ds.getPauseTime());	// 1 tick = 1 second
4565
			wtiSpeed = (double)(wdSpeed - (margin_left + margin_right)) / (max_time + ds.getPauseTime());	// 1 tick = 1 second
4432
	      htiSpeed = (double)rhSpeed / (maxSpeed - minSpeed);		// 1 tick = 1 km/h
4566
			htiSpeed = (double)rhSpeed / (maxSpeed - minSpeed);		// 1 tick = 1 km/h
4433
	   }
4567
		}
4434
	   else if (i == 1)	// Elevation?
4568
		else if(i == 1)	// Elevation?
4435
	   {
4569
		{
4436
	      rhElev = htElev - margin_bottom - 1;
4570
			rhElev = htElev - margin_bottom - 1;
4437
	      wtiElev = (double)(wdElev - (margin_left + margin_right)) / (max_time + ds.getPauseTime());	// 1 tick = 1 second
4571
			wtiElev = (double)(wdElev - (margin_left + margin_right)) / (max_time + ds.getPauseTime());	// 1 tick = 1 second
4438
	      htiElev = (double)rhElev / (maxHeight - minHeight);		// 1 tick = 1 meter
4572
			htiElev = (double)rhElev / (maxHeight - minHeight);		// 1 tick = 1 meter
4439
	   }
4573
		}
4440
	   else			// heart rate
4574
		else			// heart rate
4441
	   {
4575
		{
4442
	      rhHR = htHR - margin_bottom - 1;
4576
			rhHR = htHR - margin_bottom - 1;
4443
	      wtiHR = (double)(wdHR - (margin_left + margin_right)) / (max_time + ds.getPauseTime());	// 1 tick = 1 second
4577
			wtiHR = (double)(wdHR - (margin_left + margin_right)) / (max_time + ds.getPauseTime());	// 1 tick = 1 second
4444
	      htiHR = (double)rhHR / ((double)maxHr - (double)minHr);	// 1 tick = 1 bpm
4578
			htiHR = (double)rhHR / ((double)maxHr - (double)minHr);	// 1 tick = 1 bpm
4445
	   }
4579
		}
4446
	}
4580
	}
4447
 
4581
 
4448
	// Fill background with background colors
4582
	// Fill background with background colors
4449
	ptHR.fillRect(0, 0, wdHR + 4, htHR + 4, background);
4583
	ptHR.fillRect(0, 0, wdHR + 4, htHR + 4, background);
4450
	ptElevation.fillRect(0, 0, wdElev + 4, htElev + 4, background);
4584
	ptElevation.fillRect(0, 0, wdElev + 4, htElev + 4, background);
Line 4474... Line 4608...
4474
	// Left border line
4608
	// Left border line
4475
	x1 = x2 = margin_left;
4609
	x1 = x2 = margin_left;
4476
	y1 = 2;
4610
	y1 = 2;
4477
	y2 = htHR - margin_bottom;
4611
	y2 = htHR - margin_bottom;
4478
	ptHR.drawLine(x1, y1, x2, y2);
4612
	ptHR.drawLine(x1, y1, x2, y2);
4479
	
4613
 
4480
	y2 = htElev - margin_bottom;
4614
	y2 = htElev - margin_bottom;
4481
	ptElevation.drawLine(x1, y1, x2, y2);
4615
	ptElevation.drawLine(x1, y1, x2, y2);
4482
	
4616
 
4483
	y2 = htSpeed - margin_bottom;
4617
	y2 = htSpeed - margin_bottom;
4484
	ptSpeed.drawLine(x1, y1, x2, y2);
4618
	ptSpeed.drawLine(x1, y1, x2, y2);
4485
	
4619
 
4486
	// right border line
4620
	// right border line
4487
	x1 = x2 = wdHR - margin_right;
4621
	x1 = x2 = wdHR - margin_right;
4488
	ptHR.drawLine(x1, y1, x2, y2);
4622
	ptHR.drawLine(x1, y1, x2, y2);
4489
 
4623
 
4490
	x1 = x2 = wdElev - margin_right;
4624
	x1 = x2 = wdElev - margin_right;
Line 4499... Line 4633...
4499
	rn = ds.getRunNode();
4633
	rn = ds.getRunNode();
4500
	ptHR.setPen(QPen(hlight, 1, Qt::SolidLine));
4634
	ptHR.setPen(QPen(hlight, 1, Qt::SolidLine));
4501
	ptElevation.setPen(QPen(hlight, 1, Qt::SolidLine));
4635
	ptElevation.setPen(QPen(hlight, 1, Qt::SolidLine));
4502
	ptSpeed.setPen(QPen(hlight, 1, Qt::SolidLine));
4636
	ptSpeed.setPen(QPen(hlight, 1, Qt::SolidLine));
4503
 
4637
 
4504
	for (i = rn->run->first_lap_index; (unsigned int)i <= rn->run->last_lap_index; i++)
4638
	for(i = rn->run->first_lap_index; (unsigned int)i <= rn->run->last_lap_index; i++)
4505
	{
4639
	{
4506
	   if ((lp = ds.getLap(i)) == NULL)
4640
		if((lp = ds.getLap(i)) == NULL)
4507
	      continue;
4641
			continue;
4508
 
4642
 
4509
	   qt = garmin_dtime(lp->start_time);
4643
		qt = garmin_dtime(lp->start_time);
4510
	   secs = zeit.secsTo(qt->time());
4644
		secs = zeit.secsTo(qt->time());
4511
	   delete qt;
4645
		delete qt;
4512
	   // heart rate
4646
		// heart rate
4513
	   x1 = secs * wtiHR + margin_left + 1;
4647
		x1 = secs * wtiHR + margin_left + 1;
4514
	   ptHR.drawLine(x1, 2, x1, htHR - margin_bottom);
4648
		ptHR.drawLine(x1, 2, x1, htHR - margin_bottom);
4515
	   // Elevation
4649
		// Elevation
4516
	   x1 = secs * wtiElev + margin_left + 1;
4650
		x1 = secs * wtiElev + margin_left + 1;
4517
	   ptElevation.drawLine(x1, 2, x1, htElev - margin_bottom);
4651
		ptElevation.drawLine(x1, 2, x1, htElev - margin_bottom);
4518
	   // Speed
4652
		// Speed
4519
	   x1 = secs * wtiSpeed + margin_left + 1;
4653
		x1 = secs * wtiSpeed + margin_left + 1;
4520
	   ptSpeed.drawLine(x1, 2, x1, htSpeed - margin_bottom);
4654
		ptSpeed.drawLine(x1, 2, x1, htSpeed - margin_bottom);
4521
	}
4655
	}
4522
 
4656
 
4523
	// Grid vertical
4657
	// Grid vertical
4524
	ptHR.setPen(QPen(frame, 1, Qt::SolidLine));
4658
	ptHR.setPen(QPen(frame, 1, Qt::SolidLine));
4525
	ptHR.setFont(fntNormal);
4659
	ptHR.setFont(fntNormal);
4526
	ptHR.drawText(margin_left, htHR - lineHeight, 40, lineHeight, Qt::AlignLeft, QString("0"));
4660
	ptHR.drawText(margin_left, htHR - lineHeight, 40, lineHeight, Qt::AlignLeft, QString("0"));
4527
	
4661
 
4528
	ptElevation.setPen(QPen(frame, 1, Qt::SolidLine));
4662
	ptElevation.setPen(QPen(frame, 1, Qt::SolidLine));
4529
	ptElevation.setFont(fntNormal);
4663
	ptElevation.setFont(fntNormal);
4530
	ptElevation.drawText(margin_left, htElev - lineHeight, 40, lineHeight, Qt::AlignLeft, QString("0"));
4664
	ptElevation.drawText(margin_left, htElev - lineHeight, 40, lineHeight, Qt::AlignLeft, QString("0"));
4531
	
4665
 
4532
	ptSpeed.setPen(QPen(frame, 1, Qt::SolidLine));
4666
	ptSpeed.setPen(QPen(frame, 1, Qt::SolidLine));
4533
	ptSpeed.setFont(fntNormal);
4667
	ptSpeed.setFont(fntNormal);
4534
	ptSpeed.drawText(margin_left, htSpeed - lineHeight, 40, lineHeight, Qt::AlignLeft, QString("0"));
4668
	ptSpeed.drawText(margin_left, htSpeed - lineHeight, 40, lineHeight, Qt::AlignLeft, QString("0"));
4535
	
4669
 
4536
	ptHR.save();
4670
	ptHR.save();
4537
	ptHR.rotate(270);
4671
	ptHR.rotate(270);
4538
	ptHR.setPen(QPen(blue, 1, Qt::SolidLine));
4672
	ptHR.setPen(QPen(blue, 1, Qt::SolidLine));
4539
 
4673
 
4540
	ptElevation.save();
4674
	ptElevation.save();
4541
	ptElevation.rotate(270);
4675
	ptElevation.rotate(270);
4542
	ptElevation.setPen(QPen(barcol, 1, Qt::SolidLine));
4676
	ptElevation.setPen(QPen(barcol, 1, Qt::SolidLine));
4543
	
4677
 
4544
	ptSpeed.save();
4678
	ptSpeed.save();
4545
	ptSpeed.rotate(270);
4679
	ptSpeed.rotate(270);
4546
	ptSpeed.setPen(QPen(red, 1, Qt::SolidLine));
4680
	ptSpeed.setPen(QPen(red, 1, Qt::SolidLine));
4547
 
4681
 
4548
	// Information on right side
4682
	// Information on right side
Line 4557... Line 4691...
4557
	ptElevation.restore();
4691
	ptElevation.restore();
4558
	ptElevation.setPen(QPen(mark, 1, Qt::SolidLine));
4692
	ptElevation.setPen(QPen(mark, 1, Qt::SolidLine));
4559
 
4693
 
4560
	ptSpeed.restore();
4694
	ptSpeed.restore();
4561
	ptSpeed.setPen(QPen(mark, 1, Qt::SolidLine));
4695
	ptSpeed.setPen(QPen(mark, 1, Qt::SolidLine));
-
 
4696
 
4562
	// Draw the time scale on the bottom of the graphic
4697
	// Draw the time scale on the bottom of the graphic
4563
	for (i = 0; (unsigned int)i < (max_time + ds.getPauseTime()); i++)
4698
	for(i = 0; (unsigned int)i < (max_time + ds.getPauseTime()); i++)
4564
	{
4699
	{
4565
	bool loop = false;
4700
		bool loop = false;
4566
 
4701
 
4567
	   if (i > 0 && !(i % 600))	// every 10 minutes
4702
		if(i > 0 && !(i % 600))	// every 10 minutes
4568
	   {
4703
		{
4569
	      for (int j = 0; j < 3; j++)
4704
			for(int j = 0; j < 3; j++)
4570
	      {
4705
			{
4571
		 switch (j)
4706
				switch(j)
4572
		 {
4707
				{
4573
		    case 0: w_tick = wtiHR; width = wdHR; height = htHR; break;
4708
					case 0: w_tick = wtiHR; width = wdHR; height = htHR; break;
4574
		    case 1: w_tick = wtiElev; width = wdElev; height = htElev; break;
4709
					case 1: w_tick = wtiElev; width = wdElev; height = htElev; break;
4575
		    case 2: w_tick = wtiSpeed; width = wdSpeed; height = htSpeed; break;
4710
					case 2: w_tick = wtiSpeed; width = wdSpeed; height = htSpeed; break;
4576
		 }
4711
				}
4577
 
4712
 
4578
		 x1 = x2 = margin_left + w_tick * i;
4713
				x1 = x2 = margin_left + w_tick * i;
4579
 
4714
 
4580
		 if (x1 == (width - margin_right - 25))
4715
				if(x1 == (width - margin_right - 25))
4581
		 {
4716
				{
4582
		    loop = true;
4717
					loop = true;
4583
		    break;
4718
					break;
4584
		 }
4719
				}
4585
 
4720
 
4586
		 y1 = 2;
4721
				y1 = 2;
4587
		 y2 = height - margin_bottom;
4722
				y2 = height - margin_bottom;
4588
		 QTime tm(0, 0, 0);
4723
				QTime tm(0, 0, 0);
4589
		 tm = tm.addSecs(i);
4724
				tm = tm.addSecs(i);
4590
 
4725
 
4591
		 if (j == 0)
4726
				if(j == 0)
4592
		 {
4727
				{
4593
		    ptHR.drawLine(x1, y1, x2, y2);
4728
					ptHR.drawLine(x1, y1, x2, y2);
4594
		    ptHR.setPen(QPen(frame, 1, Qt::SolidLine));
4729
					ptHR.setPen(QPen(frame, 1, Qt::SolidLine));
4595
		    ptHR.drawText(x1 - 25, height - lineHeight, 50, lineHeight, Qt::AlignCenter, kl->formatTime (tm, (i >= 3600) ? true : false));
4730
					ptHR.drawText(x1 - 25, height - lineHeight, 50, lineHeight, Qt::AlignCenter, kl->formatTime(tm, (i >= 3600) ? true : false));
4596
		    ptHR.setPen(QPen(mark, 1, Qt::SolidLine));
4731
					ptHR.setPen(QPen(mark, 1, Qt::SolidLine));
4597
		 }
4732
				}
4598
		 else if (j == 1)
4733
				else if(j == 1)
4599
		 {
4734
				{
4600
		    ptElevation.drawLine(x1, y1, x2, y2);
4735
					ptElevation.drawLine(x1, y1, x2, y2);
4601
		    ptElevation.setPen(QPen(frame, 1, Qt::SolidLine));
4736
					ptElevation.setPen(QPen(frame, 1, Qt::SolidLine));
4602
		    ptElevation.drawText(x1 - 25, height - lineHeight, 50, lineHeight, Qt::AlignCenter, kl->formatTime (tm, (i >= 3600) ? true : false));
4737
					ptElevation.drawText(x1 - 25, height - lineHeight, 50, lineHeight, Qt::AlignCenter, kl->formatTime(tm, (i >= 3600) ? true : false));
4603
		    ptElevation.setPen(QPen(mark, 1, Qt::SolidLine));
4738
					ptElevation.setPen(QPen(mark, 1, Qt::SolidLine));
4604
		 }
4739
				}
4605
		 else
4740
				else
4606
		 {
4741
				{
4607
		    ptSpeed.drawLine(x1, y1, x2, y2);
4742
					ptSpeed.drawLine(x1, y1, x2, y2);
4608
		    ptSpeed.setPen(QPen(frame, 1, Qt::SolidLine));
4743
					ptSpeed.setPen(QPen(frame, 1, Qt::SolidLine));
4609
		    ptSpeed.drawText(x1 - 25, height - lineHeight, 50, lineHeight, Qt::AlignCenter, kl->formatTime (tm, (i >= 3600) ? true : false));
4744
					ptSpeed.drawText(x1 - 25, height - lineHeight, 50, lineHeight, Qt::AlignCenter, kl->formatTime(tm, (i >= 3600) ? true : false));
4610
		    ptSpeed.setPen(QPen(mark, 1, Qt::SolidLine));
4745
					ptSpeed.setPen(QPen(mark, 1, Qt::SolidLine));
4611
		 }
4746
				}
4612
	      }
4747
			}
4613
 
4748
 
4614
	      if (loop)
4749
			if(loop)
4615
	      {
4750
			{
4616
		 loop = false;
4751
				loop = false;
4617
		 continue;
4752
				continue;
4618
	      }
4753
			}
4619
	   }
4754
		}
4620
	}
4755
	}
4621
 
4756
 
4622
	// This is the total time, with pauses included, at the lower right
4757
	// This is the total time, with pauses included, at the lower right
4623
	// corner of the graphic.
4758
	// corner of the graphic.
4624
	QTime tm(0, 0, 0);
4759
	QTime tm(0, 0, 0);
Line 4650... Line 4785...
4650
 
4785
 
4651
	// Grid horizontal
4786
	// Grid horizontal
4652
	int factor = 0;
4787
	int factor = 0;
4653
	int target = 0;
4788
	int target = 0;
4654
 
4789
 
4655
	for (int j = 0; j < 3; j++)
4790
	for(int j = 0; j < 3; j++)
4656
	{
4791
	{
4657
	   switch (j)
4792
		switch(j)
4658
	   {
4793
		{
4659
	      case 0: width = wdHR; height = htHR; w_tick = wtiHR; h_tick = htiHR; rh = rhHR;
4794
			case 0: width = wdHR; height = htHR; w_tick = wtiHR; h_tick = htiHR; rh = rhHR;
4660
		      factor = (maxHr - minHr) / (rhHR / 12);
4795
				factor = (maxHr - minHr) / (rhHR / 12);
4661
		      target = (maxHr - minHr);
4796
				target = (maxHr - minHr);
4662
	      break;
4797
				break;
4663
 
4798
 
4664
	      case 1: width = wdElev; height = htElev; w_tick = wtiElev; h_tick = htiElev; rh = rhElev;
4799
			case 1: width = wdElev; height = htElev; w_tick = wtiElev; h_tick = htiElev; rh = rhElev;
4665
		      factor = (maxHeight - minHeight) / (rhElev / 12);
4800
				factor = (maxHeight - minHeight) / (rhElev / 12);
4666
		      target = (int)(maxHeight - minHeight);
4801
				target = (int)(maxHeight - minHeight);
4667
	      break;
4802
				break;
4668
 
4803
 
4669
	      case 2: width = wdSpeed; height = htSpeed; w_tick = wtiSpeed; h_tick = htiSpeed; rh = rhSpeed;
4804
			case 2: width = wdSpeed; height = htSpeed; w_tick = wtiSpeed; h_tick = htiSpeed; rh = rhSpeed;
4670
		      factor = (maxSpeed - minSpeed) / (rhSpeed / 12);
4805
				factor = (maxSpeed - minSpeed) / (rhSpeed / 12);
4671
		      target = (int)(maxSpeed - minSpeed);
4806
				target = (int)(maxSpeed - minSpeed);
4672
	      break;
4807
				break;
4673
	   }
4808
		}
4674
 
4809
 
4675
	   // To prevent a division by zero error, we check the <factor>
4810
		// To prevent a division by zero error, we check the <factor>
4676
	   if (factor == 0)
4811
		if(factor == 0)
4677
	      factor = 1;
4812
			factor = 1;
4678
 
4813
 
4679
	   // Beside the horizontal part of the grid, we draw the scale on the
4814
		// Beside the horizontal part of the grid, we draw the scale on the
4680
	   // the right side too.
4815
		// the right side too.
4681
	   int oldy = height;
4816
		int oldy = height;
4682
 
4817
 
4683
	   for (i = 0; i < target; i++)
4818
		for(i = 0; i < target; i++)
4684
	   {
4819
		{
4685
	      if (i > 0 && !(i % factor))
4820
			if(i > 0 && !(i % factor))
4686
	      {
4821
			{
4687
		 x1 = margin_left + 1;
4822
				x1 = margin_left + 1;
4688
		 x2 = width - margin_right - 1;
4823
				x2 = width - margin_right - 1;
4689
		 y1 = y2 = rh - h_tick * i;
4824
				y1 = y2 = rh - h_tick * i;
4690
 
4825
 
4691
		 if (y1 < 12)
4826
				if(y1 < 12)
4692
		    break;
4827
					break;
4693
 
4828
 
4694
		 switch (j)
4829
				switch(j)
4695
		 {
4830
				{
4696
		    case 0:
4831
					case 0:
4697
		       ptHR.drawLine(x1, y1, x2, y2);
4832
						ptHR.drawLine(x1, y1, x2, y2);
4698
		       ptHR.setPen(QPen(blue, 1, Qt::SolidLine));
4833
						ptHR.setPen(QPen(blue, 1, Qt::SolidLine));
4699
		       ptHR.drawText(width - margin_right + 2, y1 - lineHeight / 2, margin_right - 14, lineHeight, Qt::AlignLeft, qs.sprintf("%d", minHr + i));
4834
						ptHR.drawText(width - margin_right + 2, y1 - lineHeight / 2, margin_right - 14, lineHeight, Qt::AlignLeft, qs.sprintf("%d", minHr + i));
4700
		       ptHR.setPen(QPen(mark, 1, Qt::SolidLine));
4835
						ptHR.setPen(QPen(mark, 1, Qt::SolidLine));
4701
		    break;
4836
						break;
4702
 
4837
 
4703
		    case 1:
4838
					case 1:
4704
		       ptElevation.drawLine(x1, y1, x2, y2);
4839
						ptElevation.drawLine(x1, y1, x2, y2);
4705
		       ptElevation.setPen(QPen(barcol, 1, Qt::SolidLine));
4840
						ptElevation.setPen(QPen(barcol, 1, Qt::SolidLine));
4706
		       ptElevation.drawText(width - margin_right + 2, y1 - lineHeight / 2, margin_right - 14, lineHeight, Qt::AlignLeft, qs.sprintf("%.0f", (Units == 1) ? (minHeight + i) / 0.304 : minHeight + i));
4841
						ptElevation.drawText(width - margin_right + 2, y1 - lineHeight / 2, margin_right - 14, lineHeight, Qt::AlignLeft, qs.sprintf("%.0f", (Units == 1) ? (minHeight + i) / 0.304 : minHeight + i));
4707
		       ptElevation.setPen(QPen(mark, 1, Qt::SolidLine));
4842
						ptElevation.setPen(QPen(mark, 1, Qt::SolidLine));
4708
		    break;
4843
						break;
4709
 
4844
 
4710
		    case 2:
4845
					case 2:
4711
		       ptSpeed.drawLine(x1, y1, x2, y2);
4846
						ptSpeed.drawLine(x1, y1, x2, y2);
4712
		       ptSpeed.setPen(QPen(red, 1, Qt::SolidLine));
4847
						ptSpeed.setPen(QPen(red, 1, Qt::SolidLine));
4713
		       ptSpeed.drawText(width - margin_right + 2, y1 - lineHeight / 2, margin_right - 14, lineHeight, Qt::AlignLeft, qs.sprintf("%.1f", minSpeed + i));
4848
						ptSpeed.drawText(width - margin_right + 2, y1 - lineHeight / 2, margin_right - 14, lineHeight, Qt::AlignLeft, qs.sprintf("%.1f", minSpeed + i));
4714
		       ptSpeed.setPen(QPen(mark, 1, Qt::SolidLine));
4849
						ptSpeed.setPen(QPen(mark, 1, Qt::SolidLine));
4715
		    break;
4850
						break;
4716
		 }
4851
				}
4717
 
4852
 
4718
		 oldy = y1;
4853
				oldy = y1;
4719
	      }
4854
			}
4720
	   }
4855
		}
4721
	}
4856
	}
4722
 
4857
 
4723
	// To make our graphics more beautiful, we draw lines for the
4858
	// To make our graphics more beautiful, we draw lines for the
4724
	// heart rate limits and the average heart rate.
4859
	// heart rate limits and the average heart rate.
4725
	if (max_hr > 0)
4860
	if(max_hr > 0)
4726
	{
4861
	{
4727
	int ay1, ay2, ay3, ay4, ay5;
4862
		int ay1, ay2, ay3, ay4, ay5;
4728
 
4863
 
4729
	   x1 = margin_left + 1;
4864
		x1 = margin_left + 1;
4730
	   x2 = wdHR - margin_right - 1;
4865
		x2 = wdHR - margin_right - 1;
4731
 
4866
 
4732
	   ay1 = (double)rh - (double)(lower1 - minHr) * htiHR;
4867
		ay1 = (double)rh - (double)(lower1 - minHr) * htiHR;
4733
	   ay2 = (double)rh - (double)(lower2 - minHr) * htiHR;
4868
		ay2 = (double)rh - (double)(lower2 - minHr) * htiHR;
4734
	   ay3 = (double)rh - (double)(lower3 - minHr) * htiHR;
4869
		ay3 = (double)rh - (double)(lower3 - minHr) * htiHR;
4735
	   ay4 = (double)rh - (double)(upper3 - minHr) * htiHR;
4870
		ay4 = (double)rh - (double)(upper3 - minHr) * htiHR;
4736
	   ay5 = (double)rh - (double)(avg_hr - minHr) * htiHR;
4871
		ay5 = (double)rh - (double)(avg_hr - minHr) * htiHR;
4737
 
4872
 
4738
	   ptHR.setPen(QPen(barcol2, 1, Qt::DashLine));	// color for limits
4873
		ptHR.setPen(QPen(barcol2, 1, Qt::DashLine));	// color for limits
4739
 
4874
 
4740
	   if (lower1 > minHr && lower1 < maxHr)
4875
		if(lower1 > minHr && lower1 < maxHr)
4741
	      ptHR.drawLine(x1, ay1, x2, ay1);
4876
			ptHR.drawLine(x1, ay1, x2, ay1);
4742
 
4877
 
4743
	   if (lower2 > minHr && lower2 < maxHr)
4878
		if(lower2 > minHr && lower2 < maxHr)
4744
	      ptHR.drawLine(x1, ay2, x2, ay2);
4879
			ptHR.drawLine(x1, ay2, x2, ay2);
4745
 
4880
 
4746
	   if (lower3 > minHr && lower3 < maxHr)
4881
		if(lower3 > minHr && lower3 < maxHr)
4747
	      ptHR.drawLine(x1, ay3, x2, ay3);
4882
			ptHR.drawLine(x1, ay3, x2, ay3);
4748
 
4883
 
4749
	   if (upper3 > minHr && upper3 < maxHr)
4884
		if(upper3 > minHr && upper3 < maxHr)
4750
	      ptHR.drawLine(x1, ay4, x2, ay4);
4885
			ptHR.drawLine(x1, ay4, x2, ay4);
4751
 
4886
 
4752
	   ptHR.setPen(QPen(red, 1, Qt::DashDotLine));	// color for average heart rate
4887
		ptHR.setPen(QPen(red, 1, Qt::DashDotLine));	// color for average heart rate
4753
 
4888
 
4754
	   if (avg_hr > minHr && avg_hr < maxHr)
4889
		if(avg_hr > minHr && avg_hr < maxHr)
4755
	      ptHR.drawLine(x1, ay5, x2, ay5);
4890
			ptHR.drawLine(x1, ay5, x2, ay5);
4756
	}
4891
	}
4757
 
4892
 
4758
	// Now we have a grid and we've done the scaling.
4893
	// Now we have a grid and we've done the scaling.
4759
	// This is the point where we draw the curves itself.
4894
	// This is the point where we draw the curves itself.
4760
	// We use different colors to draw the lines:
4895
	// We use different colors to draw the lines:
Line 4770... Line 4905...
4770
	sy1 = sy2 = sx1 = sx2 = 0;
4905
	sy1 = sy2 = sx1 = sx2 = 0;
4771
	int hEc = 0;
4906
	int hEc = 0;
4772
	i = 0;
4907
	i = 0;
4773
	AVGHEIGHT *avgHakt, *avgHfirst, *avgHlast, *avgHeight = 0;
4908
	AVGHEIGHT *avgHakt, *avgHfirst, *avgHlast, *avgHeight = 0;
4774
	avgHfirst = avgHlast = 0;
4909
	avgHfirst = avgHlast = 0;
-
 
4910
 
4775
	// To even the surface lines, we store every altitude in the
4911
	// To even the surface lines, we store every altitude in the
4776
	// memory, by building a chain. Then, if the user has set in the
4912
	// memory, by building a chain. Then, if the user has set in the
4777
	// settings (Contour == true), we will even the line by calculating
4913
	// settings (Contour == true), we will even the line by calculating
4778
	// the average of 10 messure points and setting every value to the
4914
	// the average of 10 messure points and setting every value to the
4779
	// average, who is up or down more than 2 meters from the average.
4915
	// average, who is up or down more than 2 meters from the average.
4780
	while ((point = ds.getPoint(i)) != 0)
4916
	while((point = ds.getPoint(i)) != 0)
4781
	{
4917
	{
4782
	   if (point->alt > 20000.0 || point->alt < -1000.0)
4918
		if(point->alt > 20000.0 || point->alt < -1000.0)
4783
	   {
4919
		{
4784
	      i++;
4920
			i++;
4785
	      continue;
4921
			continue;
4786
	   }
4922
		}
4787
 
4923
 
4788
	   if (!avgHeight)
4924
		if(!avgHeight)
4789
	   {
4925
		{
4790
	      avgHeight = new AVGHEIGHT;
4926
			avgHeight = new AVGHEIGHT;
4791
	      avgHeight->alt = point->alt;
4927
			avgHeight->alt = point->alt;
4792
	      avgHeight->pos = hEc;
4928
			avgHeight->pos = hEc;
4793
	      avgHeight->prev = 0;
4929
			avgHeight->prev = 0;
4794
	      avgHeight->next = 0;
4930
			avgHeight->next = 0;
4795
	      avgHakt = avgHeight;
4931
			avgHakt = avgHeight;
4796
	      avgHfirst = avgHeight;
4932
			avgHfirst = avgHeight;
4797
	   }
4933
		}
4798
	   else
4934
		else
4799
	   {
4935
		{
4800
	      avgHakt = new AVGHEIGHT;
4936
			avgHakt = new AVGHEIGHT;
4801
	      avgHakt->alt = point->alt;
4937
			avgHakt->alt = point->alt;
4802
	      avgHakt->pos = hEc;
4938
			avgHakt->pos = hEc;
4803
	      avgHakt->next = 0;
4939
			avgHakt->next = 0;
4804
	      avgHakt->prev = avgHeight;
4940
			avgHakt->prev = avgHeight;
4805
	      avgHeight->next = avgHakt;
4941
			avgHeight->next = avgHakt;
4806
	      avgHeight = avgHakt;
4942
			avgHeight = avgHakt;
4807
	   }
4943
		}
4808
 
4944
 
4809
	   // FIXME: Currently we can not draw below 0 meters, because the
4945
		// FIXME: Currently we can not draw below 0 meters, because the
4810
	   // base line is always 0!
4946
		// base line is always 0!
4811
	   if (avgHakt->alt < minHeight)
4947
		if(avgHakt->alt < minHeight)
4812
	      avgHakt->alt = minHeight;
4948
			avgHakt->alt = minHeight;
4813
 
4949
 
4814
	   hEc++;
4950
		hEc++;
4815
	   i++;
4951
		i++;
4816
	}
4952
	}
4817
 
4953
 
4818
	avgHlast = avgHeight;
4954
	avgHlast = avgHeight;
-
 
4955
 
4819
	// If wanted, even the lines
4956
	// If wanted, even the lines
4820
	if (Contour && hEc > 0)
4957
	if(Contour && hEc > 0)
4821
	{
4958
	{
4822
	double alt[100], avg, avg1, avg2, avg3, avg4;
4959
		double alt[100], avg, avg1, avg2, avg3, avg4;
4823
	int a, pos;
4960
		int a, pos;
4824
 
4961
 
4825
	   for (i = 0; i < (hEc + 100); i += 100)
4962
		for(i = 0; i < (hEc + 100); i += 100)
4826
	   {
4963
		{
4827
	      avg = avg1 = avg2 = avg3 = avg4 = 0.0;
4964
			avg = avg1 = avg2 = avg3 = avg4 = 0.0;
4828
	      pos = 0;
4965
			pos = 0;
4829
 
4966
 
4830
	      for (a = 0; a < 100; a++)
4967
			for(a = 0; a < 100; a++)
4831
	      {
4968
			{
4832
		 alt[a] = getAvgAlt(avgHfirst, i + a);
4969
				alt[a] = getAvgAlt(avgHfirst, i + a);
4833
		 avg += alt[a];
4970
				avg += alt[a];
4834
 
4971
 
4835
		 if (a < 25)
4972
				if(a < 25)
4836
		    avg1 += alt[a];
4973
					avg1 += alt[a];
4837
		 else if (a < 50)
4974
				else if(a < 50)
4838
		    avg2 += alt[a];
4975
					avg2 += alt[a];
4839
		 else if (a < 75)
4976
				else if(a < 75)
4840
		    avg3 += alt[a];
4977
					avg3 += alt[a];
4841
		 else
4978
				else
4842
		    avg4 += alt[a];
4979
					avg4 += alt[a];
4843
	      }
4980
			}
4844
 
4981
 
4845
	      if ((i + 100) >= hEc)
4982
			if((i + 100) >= hEc)
4846
		 avg /= (double)(hEc - i) + 1.0;
4983
				avg /= (double)(hEc - i) + 1.0;
4847
	      else
4984
			else
4848
		 avg /= 100.0;
4985
				avg /= 100.0;
4849
 
4986
 
4850
	      for (a = 0; a < 100; a++)
4987
			for(a = 0; a < 100; a++)
4851
	      {
4988
			{
4852
		 if ((avgHakt = getAvgPtr(avgHfirst, i + a)) != 0)
4989
				if((avgHakt = getAvgPtr(avgHfirst, i + a)) != 0)
4853
		 {
4990
				{
4854
		    if ((avgHakt->alt - avg) > 2 || (avgHakt->alt - avg) < -2)
4991
					if((avgHakt->alt - avg) > 2 || (avgHakt->alt - avg) < -2)
4855
		       avgHakt->alt = avg;
4992
						avgHakt->alt = avg;
4856
		 }
4993
				}
4857
	      }
4994
			}
4858
	   }
4995
		}
4859
	}
4996
	}
4860
 
4997
 
4861
	// plot the elevation, speed and/or heart rate. Depends on <cuType>)
4998
	// plot the elevation, speed and/or heart rate. Depends on <cuType>)
4862
	i = 0;
4999
	i = 0;
4863
	int j = 0;
5000
	int j = 0;
4864
	POINT *oldPoint = 0;
5001
	POINT *oldPoint = 0;
4865
	double speed = 0.0;	// calculated speed
5002
	double speed = 0.0;	// calculated speed
4866
	bool pause = false;	// filter pause out of speed
5003
	bool pause = false;	// filter pause out of speed
4867
	unsigned long t1, t2;
5004
	unsigned long t1, t2;
4868
	t1 = t2 = 0;
5005
	t1 = t2 = 0;
4869
	
5006
 
4870
	while ((point = ds.getPoint(i)) != 0)
5007
	while((point = ds.getPoint(i)) != 0)
4871
	{
5008
	{
4872
	bool loop = false;
5009
		bool loop = false;
-
 
5010
 
-
 
5011
		if(!oldPoint)
-
 
5012
			oldPoint = point;
4873
 
5013
 
-
 
5014
		// calculate the y position based on the time
-
 
5015
		qt = garmin_dtime(point->time);
-
 
5016
		secs = zeit.secsTo(qt->time());
-
 
5017
		delete qt;
-
 
5018
 
-
 
5019
		for(int c = 0; c < 3; c++)
-
 
5020
		{
-
 
5021
			if(c == 0)
-
 
5022
			{
-
 
5023
				x2 = secs * wtiHR + margin_left + 1;
-
 
5024
				hx2 = x2;
-
 
5025
				sx2 = x2;
-
 
5026
 
-
 
5027
				if(x1 == 0)
-
 
5028
					x1 = x2;
-
 
5029
 
-
 
5030
				if(hx1 == 0)
-
 
5031
					hx1 = hx2;
-
 
5032
 
-
 
5033
				if(sx1 == 0)
-
 
5034
					sx1 = sx2;
-
 
5035
			}
-
 
5036
			else if(c == 1)
-
 
5037
			{
-
 
5038
				x2 = secs * wtiElev + margin_left + 1;
-
 
5039
				hx2 = x2;
-
 
5040
				sx2 = x2;
-
 
5041
 
-
 
5042
				if(x1 == 0)
-
 
5043
					x1 = x2;
-
 
5044
 
-
 
5045
				if(hx1 == 0)
-
 
5046
					hx1 = hx2;
-
 
5047
 
-
 
5048
				if(sx1 == 0)
-
 
5049
					sx1 = sx2;
-
 
5050
			}
-
 
5051
			else
-
 
5052
			{
-
 
5053
				x2 = secs * wtiSpeed + margin_left + 1;
-
 
5054
				hx2 = x2;
-
 
5055
				sx2 = x2;
-
 
5056
 
-
 
5057
				if(x1 == 0)
-
 
5058
					x1 = x2;
-
 
5059
 
-
 
5060
				if(hx1 == 0)
-
 
5061
					hx1 = hx2;
-
 
5062
 
4874
	   if (!oldPoint)
5063
				if(sx1 == 0)
-
 
5064
					sx1 = sx2;
-
 
5065
			}
-
 
5066
 
-
 
5067
			// The speed is not very exact, because smallest time is
-
 
5068
			// one second. This allows a maximum error of 99 hundredths
-
 
5069
			// of a second, what is very close to one second. Because of
-
 
5070
			// this, speed seems to hop for every messure point. This
-
 
5071
			// looks ugly, but currently I don't know how to make it
-
 
5072
			// better.
-
 
5073
			if(c == 2)	// Draw speed?
-
 
5074
			{
-
 
5075
				double dist;
-
 
5076
				double sc;
-
 
5077
 
-
 
5078
				if(!pause && point->distance > 1.0e10)
-
 
5079
				{
-
 
5080
					pause = true;
-
 
5081
					t1 = point->time;
-
 
5082
				}
-
 
5083
				else if(pause)
-
 
5084
				{
-
 
5085
					pause = false;
-
 
5086
					t2 = point->time;
-
 
5087
					i += 2;
-
 
5088
					loop = true;
-
 
5089
				}
-
 
5090
 
-
 
5091
				if(point->distance >= 0.1 && point->distance < 1.0e10)
-
 
5092
				{
-
 
5093
					dist = point->distance - oldPoint->distance;
-
 
5094
					sc = point->time - oldPoint->time;
-
 
5095
					LAP *runde = ds.getLapT(point->time);
-
 
5096
 
-
 
5097
					if(t2 > t1)
-
 
5098
					{
-
 
5099
						sc -= t2 - t1;
-
 
5100
 
-
 
5101
						if(sc <= 0.0)
-
 
5102
							sc = 1.0;		// at least 1 second!
-
 
5103
					}
-
 
5104
 
-
 
5105
					speed = (dist / sc) * 3.6;
-
 
5106
 
-
 
5107
					if(runde && runde->max_speed > 0.0 && speed > (runde->max_speed * 3.6))
-
 
5108
						speed = runde->max_speed * 3.6;
-
 
5109
 
-
 
5110
					if(Units == 1)
-
 
5111
						speed /= 1.609344;
-
 
5112
 
-
 
5113
					if(speed < minSpeed || speed > 400.0)
-
 
5114
						speed = minSpeed;
-
 
5115
 
-
 
5116
					y2 = (double)rh - (speed - minSpeed) * htiSpeed;
-
 
5117
 
-
 
5118
					if(y1 == 0)
-
 
5119
						y1 = y2;
-
 
5120
 
-
 
5121
					ptSpeed.setPen(QPen(red, 1, Qt::SolidLine));
-
 
5122
					ptSpeed.drawLine(x1, y1, x2, y2);
-
 
5123
					y1 = y2;
-
 
5124
					x1 = x2;
-
 
5125
					t1 = t2 = 0;
4875
	      oldPoint = point;
5126
					oldPoint = point;
-
 
5127
				}
-
 
5128
			}
-
 
5129
 
-
 
5130
			if(c == 1)		// Draw elevation?
-
 
5131
			{
-
 
5132
				if(point->alt < 20000.0 && point->alt > -1000.0)
-
 
5133
				{
-
 
5134
					double alt = getAvgAlt(avgHfirst, j);
-
 
5135
 
-
 
5136
					j++;
-
 
5137
 
-
 
5138
					sy2 = (double)rh - (alt - minHeight) * htiElev;
-
 
5139
 
-
 
5140
					if(sy1 == 0)
-
 
5141
						sy1 = sy2;
-
 
5142
 
-
 
5143
					ptElevation.setPen(QPen(barcol, 1, Qt::SolidLine));
-
 
5144
					ptElevation.drawLine(sx1, sy1, sx2, sy2);
-
 
5145
					sy1 = sy2;
-
 
5146
					sx1 = sx2;
-
 
5147
				}
-
 
5148
			}
-
 
5149
 
-
 
5150
			if(point->heart_rate > 0 && c == 0)	// Draw heart rate?
-
 
5151
			{
-
 
5152
				hy2 = (double)rh - (double)(point->heart_rate - minHr) * htiHR;
-
 
5153
 
-
 
5154
				if(hy1 == 0)
-
 
5155
					hy1 = hy2;
-
 
5156
 
-
 
5157
				ptHR.setPen(QPen(blue, 1, Qt::SolidLine));
-
 
5158
				ptHR.drawLine(hx1, hy1, hx2, hy2);
-
 
5159
				hy1 = hy2;
-
 
5160
				hx1 = hx2;
-
 
5161
			}
-
 
5162
		}
4876
 
5163
 
4877
	   // calculate the y position based on the time
-
 
4878
	   qt = garmin_dtime(point->time);
-
 
4879
	   secs = zeit.secsTo(qt->time());
-
 
4880
	   delete qt;
-
 
4881
 
-
 
4882
	   for (int c = 0; c < 3; c++)
-
 
4883
	   {
-
 
4884
	      if (c == 0)
-
 
4885
	      {
-
 
4886
		 x2 = secs * wtiHR + margin_left + 1;
-
 
4887
		 hx2 = x2;
-
 
4888
		 sx2 = x2;
-
 
4889
 
-
 
4890
		 if (x1 == 0)
-
 
4891
		    x1 = x2;
-
 
4892
 
-
 
4893
		 if (hx1 == 0)
-
 
4894
		    hx1 = hx2;
-
 
4895
 
-
 
4896
		 if (sx1 == 0)
-
 
4897
		    sx1 = sx2;
-
 
4898
	      }
-
 
4899
	      else if (c == 1)
-
 
4900
	      {
-
 
4901
		 x2 = secs * wtiElev + margin_left + 1;
-
 
4902
		 hx2 = x2;
-
 
4903
		 sx2 = x2;
-
 
4904
 
-
 
4905
		 if (x1 == 0)
-
 
4906
		    x1 = x2;
-
 
4907
 
-
 
4908
		 if (hx1 == 0)
-
 
4909
		    hx1 = hx2;
-
 
4910
 
-
 
4911
		 if (sx1 == 0)
-
 
4912
		    sx1 = sx2;
-
 
4913
	      }
-
 
4914
	      else
-
 
4915
	      {
-
 
4916
		 x2 = secs * wtiSpeed + margin_left + 1;
-
 
4917
		 hx2 = x2;
-
 
4918
		 sx2 = x2;
-
 
4919
 
-
 
4920
		 if (x1 == 0)
-
 
4921
		    x1 = x2;
-
 
4922
 
-
 
4923
		 if (hx1 == 0)
-
 
4924
		    hx1 = hx2;
-
 
4925
 
-
 
4926
		 if (sx1 == 0)
-
 
4927
		    sx1 = sx2;
-
 
4928
	      }
-
 
4929
	      // The speed is not very exact, because smallest time is
-
 
4930
	      // one second. This allows a maximum error of 99 hundredths
-
 
4931
	      // of a second, what is very close to one second. Because of
-
 
4932
	      // this, speed seems to hop for every messure point. This
-
 
4933
	      // looks ugly, but currently I don't know how to make it
-
 
4934
	      // better.
-
 
4935
	      if (c == 2)	// Draw speed?
-
 
4936
	      {
-
 
4937
	      double dist;
-
 
4938
	      double sc;
-
 
4939
 
-
 
4940
		 if (!pause && point->distance > 1.0e10)
-
 
4941
		 {
-
 
4942
		    pause = true;
-
 
4943
		    t1 = point->time;
-
 
4944
		 }
-
 
4945
		 else if (pause)
-
 
4946
		 {
-
 
4947
		    pause = false;
-
 
4948
		    t2 = point->time;
-
 
4949
		    i += 2;
-
 
4950
		    loop = true;
-
 
4951
		 }
-
 
4952
 
-
 
4953
		 if (point->distance >= 0.1 && point->distance < 1.0e10)
-
 
4954
		 {
-
 
4955
		    dist = point->distance - oldPoint->distance;
-
 
4956
		    sc = point->time - oldPoint->time;
-
 
4957
		    LAP *runde = ds.getLapT (point->time);
-
 
4958
 
-
 
4959
		    if (t2 > t1)
-
 
4960
		    {
-
 
4961
		       sc -= t2 - t1;
-
 
4962
 
-
 
4963
		       if (sc <= 0.0)
-
 
4964
			  sc = 1.0;		// at least 1 second!
-
 
4965
		    }
-
 
4966
 
-
 
4967
		    speed = (dist / sc) * 3.6;
-
 
4968
 
-
 
4969
		    if (runde && runde->max_speed > 0.0 && speed > (runde->max_speed * 3.6))
-
 
4970
		       speed = runde->max_speed * 3.6;
-
 
4971
 
-
 
4972
		    if (Units == 1)
-
 
4973
		       speed /= 1.609344;
-
 
4974
 
-
 
4975
		    if (speed < minSpeed || speed > 400.0)
-
 
4976
		       speed = minSpeed;
-
 
4977
 
-
 
4978
		    y2 = (double)rh - (speed - minSpeed) * htiSpeed;
-
 
4979
 
-
 
4980
		    if (y1 == 0)
-
 
4981
		       y1 = y2;
-
 
4982
 
-
 
4983
		    ptSpeed.setPen(QPen(red, 1, Qt::SolidLine));
-
 
4984
		    ptSpeed.drawLine(x1, y1, x2, y2);
-
 
4985
		    y1 = y2;
-
 
4986
		    x1 = x2;
-
 
4987
		    t1 = t2 = 0;
-
 
4988
		    oldPoint = point;
-
 
4989
		 }
-
 
4990
	      }
-
 
4991
 
-
 
4992
	      if (c == 1)		// Draw elevation?
-
 
4993
	      {
-
 
4994
		 if (point->alt < 20000.0 && point->alt > -1000.0)
-
 
4995
		 {
-
 
4996
		 double alt = getAvgAlt(avgHfirst, j);
-
 
4997
 
-
 
4998
		    j++;
-
 
4999
 
-
 
5000
		    sy2 = (double)rh - (alt - minHeight) * htiElev;
-
 
5001
 
-
 
5002
		    if (sy1 == 0)
-
 
5003
		       sy1 = sy2;
-
 
5004
 
-
 
5005
		    ptElevation.setPen(QPen(barcol, 1, Qt::SolidLine));
-
 
5006
		    ptElevation.drawLine(sx1, sy1, sx2, sy2);
-
 
5007
		    sy1 = sy2;
-
 
5008
		    sx1 = sx2;
-
 
5009
		 }
-
 
5010
	      }
-
 
5011
 
-
 
5012
	      if (point->heart_rate > 0 && c == 0)	// Draw heart rate?
-
 
5013
	      {
-
 
5014
		 hy2 = (double)rh - (double)(point->heart_rate - minHr) * htiHR;
-
 
5015
 
-
 
5016
		 if (hy1 == 0)
-
 
5017
		    hy1 = hy2;
-
 
5018
 
-
 
5019
		 ptHR.setPen(QPen(blue, 1, Qt::SolidLine));
-
 
5020
		 ptHR.drawLine(hx1, hy1, hx2, hy2);
-
 
5021
		 hy1 = hy2;
-
 
5022
		 hx1 = hx2;
-
 
5023
	      }
-
 
5024
	   }
-
 
5025
 
-
 
5026
	   if (loop)
5164
		if(loop)
5027
	   {
5165
		{
5028
	      loop = false;
5166
			loop = false;
5029
	      continue;
5167
			continue;
5030
	   }
5168
		}
5031
 
5169
 
5032
	   i++;
5170
		i++;
5033
	}
5171
	}
5034
 
5172
 
5035
	ptHR.end();
5173
	ptHR.end();
5036
	ptElevation.end();
5174
	ptElevation.end();
5037
	ptSpeed.end();
5175
	ptSpeed.end();
5038
 
5176
 
5039
	if (!ActivePrint)
5177
	if(!ActivePrint)
5040
	{
5178
	{
5041
	   ui_sportwatcherWidgetBase.grHR->setPixmap(pmHR);
5179
		ui_sportwatcherWidgetBase.grHR->setPixmap(pmHR);
5042
	   ui_sportwatcherWidgetBase.grElevation->setPixmap(pmElevation);
5180
		ui_sportwatcherWidgetBase.grElevation->setPixmap(pmElevation);
5043
	   ui_sportwatcherWidgetBase.grSpeed->setPixmap(pmSpeed);
5181
		ui_sportwatcherWidgetBase.grSpeed->setPixmap(pmSpeed);
5044
	}
5182
	}
-
 
5183
 
5045
	// free the chain of altitudes
5184
	// free the chain of altitudes
5046
	avgHakt = avgHfirst;
5185
	avgHakt = avgHfirst;
5047
 
5186
 
5048
	while (avgHakt)
5187
	while(avgHakt)
5049
	{
5188
	{
5050
	   avgHeight = avgHakt->next;
5189
		avgHeight = avgHakt->next;
5051
	   delete avgHakt;
5190
		delete avgHakt;
5052
	   avgHakt = avgHeight;
5191
		avgHakt = avgHeight;
5053
	}
5192
	}
5054
 
5193
 
5055
	DIRTY = false;
5194
	DIRTY = false;
5056
}
5195
}
5057
 
5196
 
5058
double sportwatcherWidget::getAvgAlt(AVGHEIGHT *avgHeight, int pos)
5197
double sportwatcherWidget::getAvgAlt(AVGHEIGHT *avgHeight, int pos)
5059
{
5198
{
5060
AVGHEIGHT *akt;
5199
	AVGHEIGHT *akt;
5061
 
5200
 
5062
	if (!avgHeight)
5201
	if(!avgHeight)
5063
	   return 0.0;
5202
		return 0.0;
5064
 
5203
 
5065
	akt = avgHeight;
5204
	akt = avgHeight;
5066
 
5205
 
5067
	while (akt)
5206
	while(akt)
5068
	{
5207
	{
5069
	   if (akt->pos == pos)
5208
		if(akt->pos == pos)
5070
	      return akt->alt;
5209
			return akt->alt;
5071
 
5210
 
5072
	   akt = akt->next;
5211
		akt = akt->next;
5073
	}
5212
	}
5074
 
5213
 
5075
	return 0.0;
5214
	return 0.0;
5076
}
5215
}
5077
 
5216
 
5078
AVGHEIGHT *sportwatcherWidget::getAvgPtr(AVGHEIGHT *avgHeight, int pos)
5217
AVGHEIGHT *sportwatcherWidget::getAvgPtr(AVGHEIGHT *avgHeight, int pos)
5079
{
5218
{
5080
AVGHEIGHT *akt;
5219
	AVGHEIGHT *akt;
5081
 
5220
 
5082
	akt = avgHeight;
5221
	akt = avgHeight;
5083
 
5222
 
5084
	while (akt)
5223
	while(akt)
5085
	{
5224
	{
5086
	   if (akt->pos == pos)
5225
		if(akt->pos == pos)
5087
	      return akt;
5226
			return akt;
5088
 
5227
 
5089
	   akt = akt->next;
5228
		akt = akt->next;
5090
	}
5229
	}
5091
 
5230
 
5092
	return 0;
5231
	return 0;
5093
}
5232
}
5094
 
5233
 
5095
void sportwatcherWidget::resizeEvent(QResizeEvent *e)
5234
void sportwatcherWidget::resizeEvent(QResizeEvent *e)
5096
{
5235
{
5097
	if (e->size() != e->oldSize())
5236
	if(e->size() != e->oldSize())
5098
	   DIRTY=true;
5237
		DIRTY = true;
5099
 
5238
 
5100
	showTrack(zfactor);
5239
	showTrack(zfactor);
5101
	showCurves();
5240
	showCurves();
5102
	tabDirt2 = true;
5241
	tabDirt2 = true;
5103
 
5242
 
5104
	if (curTab == 2)
5243
	if(curTab == 2)
5105
	{
5244
	{
5106
	   showThreeCurve();
5245
		showThreeCurve();
5107
	   tabDirt2 = false;
5246
		tabDirt2 = false;
5108
	}
5247
	}
5109
 
5248
 
5110
	DIRTY=false;
5249
	DIRTY = false;
5111
}
5250
}
5112
 
5251
 
5113
void sportwatcherWidget::mouseMoveEvent(QMouseEvent *e)
5252
void sportwatcherWidget::mouseMoveEvent(QMouseEvent *e)
5114
{
5253
{
5115
QPoint pos(0, 0);
5254
	QPoint pos(0, 0);
5116
QPoint ev = ui_sportwatcherWidgetBase.imgMap->mapFrom(this, e->pos());
5255
	QPoint ev = ui_sportwatcherWidgetBase.imgMap->mapFrom(this, e->pos());
5117
static QRect coord;
5256
	static QRect coord;
5118
 
5257
 
5119
	DIRTY=true;
5258
	DIRTY = true;
5120
 
5259
 
5121
	if (curTab == 0)
5260
	if(curTab == 0)
5122
	{
5261
	{
5123
	   if (!stateHand)
5262
		if(!stateHand)
5124
	      return;
5263
			return;
5125
 
5264
 
5126
	   if (ev.x() >= pos.x() &&
5265
		if(ev.x() >= pos.x() &&
5127
	       ev.y() >= pos.y() &&
5266
		                  ev.y() >= pos.y() &&
5128
	       ev.x() <= (pos.x() + ui_sportwatcherWidgetBase.imgMap->geometry().width()) &&
5267
		                  ev.x() <= (pos.x() + ui_sportwatcherWidgetBase.imgMap->geometry().width()) &&
5129
	       ev.y() <= (pos.y() + ui_sportwatcherWidgetBase.imgMap->geometry().height()))
5268
		                  ev.y() <= (pos.y() + ui_sportwatcherWidgetBase.imgMap->geometry().height()))
5130
	   {
5269
		{
5131
	      if (lmbPressed == 1)
5270
			if(lmbPressed == 1)
5132
	      {
5271
			{
5133
		 coord.setCoords(ev.x(), ev.y(), 0, 0);
5272
				coord.setCoords(ev.x(), ev.y(), 0, 0);
5134
		 lmbPressed = 0;
5273
				lmbPressed = 0;
5135
	      }
5274
			}
5136
	      else
5275
			else
5137
	      {
5276
			{
5138
		 coord.setRight(ev.x());
5277
				coord.setRight(ev.x());
5139
		 coord.setBottom(ev.y());
5278
				coord.setBottom(ev.y());
5140
	      }
5279
			}
5141
 
5280
 
5142
	      if (lmbPressed == 2)
5281
			if(lmbPressed == 2)
5143
	      {
5282
			{
5144
		 showTrack(zfactor, coord, mapLap);
5283
				showTrack(zfactor, coord, mapLap);
5145
		 lmbPressed = 0;
5284
				lmbPressed = 0;
5146
	      }
5285
			}
5147
	   }
5286
		}
5148
	}
5287
	}
5149
 
5288
 
5150
	if (curTab == 2)
5289
	if(curTab == 2)
5151
	{
5290
	{
5152
	   // look in which of the three QLabels the mouse is, if it is in
5291
		// look in which of the three QLabels the mouse is, if it is in
5153
	   // one of them.
5292
		// one of them.
5154
	   ev = ui_sportwatcherWidgetBase.grHR->mapFrom(this, e->pos());
5293
		ev = ui_sportwatcherWidgetBase.grHR->mapFrom(this, e->pos());
5155
 
5294
 
5156
	   if (ev.x() >= pos.x() &&
5295
		if(ev.x() >= pos.x() &&
5157
	       ev.y() >= pos.y() &&
5296
		                  ev.y() >= pos.y() &&
5158
	       ev.x() <= (pos.x() + ui_sportwatcherWidgetBase.grHR->geometry().width()) &&
5297
		                  ev.x() <= (pos.x() + ui_sportwatcherWidgetBase.grHR->geometry().width()) &&
5159
	       ev.y() <= (pos.y() + ui_sportwatcherWidgetBase.grHR->geometry().height()))
5298
		                  ev.y() <= (pos.y() + ui_sportwatcherWidgetBase.grHR->geometry().height()))
5160
	   {
5299
		{
5161
	      drawGrHR (ev.x(), ev.y());
5300
			drawGrHR(ev.x(), ev.y());
5162
	      drawGrElev (ev.x(), -1);
5301
			drawGrElev(ev.x(), -1);
5163
	      drawGrSpeed (ev.x(), -1);
5302
			drawGrSpeed(ev.x(), -1);
5164
	   }
5303
		}
5165
 
5304
 
5166
	   ev = ui_sportwatcherWidgetBase.grElevation->mapFrom(this, e->pos());
5305
		ev = ui_sportwatcherWidgetBase.grElevation->mapFrom(this, e->pos());
5167
 
5306
 
5168
	   if (ev.x() >= pos.x() &&
5307
		if(ev.x() >= pos.x() &&
5169
	       ev.y() >= pos.y() &&
5308
		                  ev.y() >= pos.y() &&
5170
	       ev.x() <= (pos.x() + ui_sportwatcherWidgetBase.grElevation->geometry().width()) &&
5309
		                  ev.x() <= (pos.x() + ui_sportwatcherWidgetBase.grElevation->geometry().width()) &&
5171
	       ev.y() <= (pos.y() + ui_sportwatcherWidgetBase.grElevation->geometry().height()))
5310
		                  ev.y() <= (pos.y() + ui_sportwatcherWidgetBase.grElevation->geometry().height()))
5172
	   {
5311
		{
5173
	      drawGrHR (ev.x(), -1);
5312
			drawGrHR(ev.x(), -1);
5174
	      drawGrElev (ev.x(), ev.y());
5313
			drawGrElev(ev.x(), ev.y());
5175
	      drawGrSpeed (ev.x(), -1);
5314
			drawGrSpeed(ev.x(), -1);
5176
	   }
5315
		}
5177
 
5316
 
5178
	   ev = ui_sportwatcherWidgetBase.grSpeed->mapFrom(this, e->pos());
5317
		ev = ui_sportwatcherWidgetBase.grSpeed->mapFrom(this, e->pos());
5179
 
5318
 
5180
	   if (ev.x() >= pos.x() &&
5319
		if(ev.x() >= pos.x() &&
5181
	       ev.y() >= pos.y() &&
5320
		                  ev.y() >= pos.y() &&
5182
	       ev.x() <= (pos.x() + ui_sportwatcherWidgetBase.grSpeed->geometry().width()) &&
5321
		                  ev.x() <= (pos.x() + ui_sportwatcherWidgetBase.grSpeed->geometry().width()) &&
5183
	       ev.y() <= (pos.y() + ui_sportwatcherWidgetBase.grSpeed->geometry().height()))
5322
		                  ev.y() <= (pos.y() + ui_sportwatcherWidgetBase.grSpeed->geometry().height()))
5184
	   {
5323
		{
5185
	      drawGrHR (ev.x(), -1);
5324
			drawGrHR(ev.x(), -1);
5186
	      drawGrElev (ev.x(), -1);
5325
			drawGrElev(ev.x(), -1);
5187
	      drawGrSpeed (ev.x(), ev.y());
5326
			drawGrSpeed(ev.x(), ev.y());
5188
	   }
5327
		}
5189
	}
5328
	}
5190
 
5329
 
5191
	DIRTY=false;
5330
	DIRTY = false;
5192
}
5331
}
5193
 
5332
 
5194
void sportwatcherWidget::mousePressEvent(QMouseEvent *e)
5333
void sportwatcherWidget::mousePressEvent(QMouseEvent *e)
5195
{
5334
{
5196
	if (stateHand && e->button() == Qt::LeftButton)
5335
	if(stateHand && e->button() == Qt::LeftButton)
5197
	   lmbPressed = 1;	// Left Mouse Button is pressed
5336
		lmbPressed = 1;	// Left Mouse Button is pressed
5198
	else if (stateHand)
5337
	else if(stateHand)
5199
	   lmbPressed = 0;	// Wrong button is pressed
5338
		lmbPressed = 0;	// Wrong button is pressed
5200
 
5339
 
5201
	if (stateGlas)
5340
	if(stateGlas)
5202
	{
5341
	{
5203
	   if (e->button() == Qt::LeftButton)
5342
		if(e->button() == Qt::LeftButton)
5204
	      btGlasPlusSlot();
5343
			btGlasPlusSlot();
5205
	   else if (e->button() == Qt::RightButton)
5344
		else if(e->button() == Qt::RightButton)
5206
	      btGlasMinusSlot();
5345
			btGlasMinusSlot();
5207
	}
5346
	}
5208
}
5347
}
5209
 
5348
 
5210
void sportwatcherWidget::mouseReleaseEvent(QMouseEvent *e)
5349
void sportwatcherWidget::mouseReleaseEvent(QMouseEvent *e)
5211
{
5350
{
5212
	if (stateHand && e->button() == Qt::LeftButton)
5351
	if(stateHand && e->button() == Qt::LeftButton)
5213
	{
5352
	{
5214
	   lmbPressed = 2;	// Left Mouse Button was released
5353
		lmbPressed = 2;	// Left Mouse Button was released
5215
	   mouseMoveEvent(e);
5354
		mouseMoveEvent(e);
5216
	}
5355
	}
5217
}
5356
}
5218
 
5357
 
5219
/*
5358
/*
5220
 * Private functions to draw cross and/or a bar to reflect the mouse
5359
 * Private functions to draw cross and/or a bar to reflect the mouse
5221
 * pointer on tab 2.
5360
 * pointer on tab 2.
5222
 */
5361
 */
5223
void sportwatcherWidget::drawGrHR (int x, int y)
5362
void sportwatcherWidget::drawGrHR(int x, int y)
5224
{
5363
{
5225
int width, height;
5364
	int width, height;
5226
QPixmap pm = pmHR.copy(pmHR.rect());
5365
	QPixmap pm = pmHR.copy(pmHR.rect());
5227
QPainter paint;
5366
	QPainter paint;
5228
 
5367
 
5229
	width = ui_sportwatcherWidgetBase.grHR->width();
5368
	width = ui_sportwatcherWidgetBase.grHR->width();
5230
	height = ui_sportwatcherWidgetBase.grHR->height();
5369
	height = ui_sportwatcherWidgetBase.grHR->height();
5231
	ui_sportwatcherWidgetBase.grHR->setPixmap(pmHR);
5370
	ui_sportwatcherWidgetBase.grHR->setPixmap(pmHR);
5232
 
5371
 
5233
	if (x > (width - 40) || y > (height - 12) || x < 1)
5372
	if(x > (width - 40) || y > (height - 12) || x < 1)
5234
	{
5373
	{
5235
	   ui_sportwatcherWidgetBase.grElevation->setPixmap(pmElevation);
5374
		ui_sportwatcherWidgetBase.grElevation->setPixmap(pmElevation);
5236
	   ui_sportwatcherWidgetBase.grSpeed->setPixmap(pmSpeed);
5375
		ui_sportwatcherWidgetBase.grSpeed->setPixmap(pmSpeed);
5237
	   return;
5376
		return;
5238
	}
5377
	}
5239
 
5378
 
5240
	if (tabDirt2)
5379
	if(tabDirt2)
5241
	{
5380
	{
5242
	   DIRTY = true;
5381
		DIRTY = true;
5243
	   showThreeCurve ();
5382
		showThreeCurve();
5244
	   tabDirt2 = false;
5383
		tabDirt2 = false;
5245
	   DIRTY = false;
5384
		DIRTY = false;
5246
	}
5385
	}
5247
 
5386
 
5248
	paint.begin(&pm);
5387
	paint.begin(&pm);
5249
	QColor black(0, 0, 0);
5388
	QColor black(0, 0, 0);
5250
	black.setAlpha (128);
5389
	black.setAlpha(128);
5251
	paint.setPen(QPen(black, 1, Qt::SolidLine));
5390
	paint.setPen(QPen(black, 1, Qt::SolidLine));
-
 
5391
 
5252
	// horizontal line, if y != -1
5392
	// horizontal line, if y != -1
5253
	if (y >= 0)
5393
	if(y >= 0)
5254
	   paint.drawLine(2, y, width - 41, y);
5394
		paint.drawLine(2, y, width - 41, y);
5255
 
5395
 
5256
	// vertical line
5396
	// vertical line
5257
	paint.drawLine(x, 1, x, height - 13);
5397
	paint.drawLine(x, 1, x, height - 13);
5258
	paint.end();
5398
	paint.end();
5259
	ui_sportwatcherWidgetBase.grHR->setPixmap(pm);
5399
	ui_sportwatcherWidgetBase.grHR->setPixmap(pm);
5260
}
5400
}
5261
 
5401
 
5262
void sportwatcherWidget::drawGrElev (int x, int y)
5402
void sportwatcherWidget::drawGrElev(int x, int y)
5263
{
5403
{
5264
int width, height;
5404
	int width, height;
5265
QPixmap pm = pmElevation.copy(pmElevation.rect());
5405
	QPixmap pm = pmElevation.copy(pmElevation.rect());
5266
QPainter paint;
5406
	QPainter paint;
5267
 
5407
 
5268
	width = ui_sportwatcherWidgetBase.grElevation->width();
5408
	width = ui_sportwatcherWidgetBase.grElevation->width();
5269
	height = ui_sportwatcherWidgetBase.grElevation->height();
5409
	height = ui_sportwatcherWidgetBase.grElevation->height();
5270
	ui_sportwatcherWidgetBase.grElevation->setPixmap(pmElevation);
5410
	ui_sportwatcherWidgetBase.grElevation->setPixmap(pmElevation);
5271
 
5411
 
5272
	if (x > (width - 40) || y > (height - 12) || x < 1)
5412
	if(x > (width - 40) || y > (height - 12) || x < 1)
5273
	{
5413
	{
5274
	   ui_sportwatcherWidgetBase.grHR->setPixmap(pmHR);
5414
		ui_sportwatcherWidgetBase.grHR->setPixmap(pmHR);
5275
	   ui_sportwatcherWidgetBase.grSpeed->setPixmap(pmSpeed);
5415
		ui_sportwatcherWidgetBase.grSpeed->setPixmap(pmSpeed);
5276
	   return;
5416
		return;
5277
	}
5417
	}
5278
 
5418
 
5279
	if (tabDirt2)
5419
	if(tabDirt2)
5280
	{
5420
	{
5281
	   DIRTY = true;
5421
		DIRTY = true;
5282
	   showThreeCurve ();
5422
		showThreeCurve();
5283
	   tabDirt2 = false;
5423
		tabDirt2 = false;
5284
	   DIRTY = false;
5424
		DIRTY = false;
5285
	}
5425
	}
5286
 
5426
 
5287
	paint.begin(&pm);
5427
	paint.begin(&pm);
5288
	QColor black(0, 0, 0);
5428
	QColor black(0, 0, 0);
5289
	black.setAlpha (128);
5429
	black.setAlpha(128);
5290
	paint.setPen(QPen(black, 1, Qt::SolidLine));
5430
	paint.setPen(QPen(black, 1, Qt::SolidLine));
-
 
5431
 
5291
	// horizontal line, if y != -1
5432
	// horizontal line, if y != -1
5292
	if (y >= 0)
5433
	if(y >= 0)
5293
	   paint.drawLine(2, y, width - 41, y);
5434
		paint.drawLine(2, y, width - 41, y);
5294
 
5435
 
5295
	// vertical line
5436
	// vertical line
5296
	paint.drawLine(x, 1, x, height - 13);
5437
	paint.drawLine(x, 1, x, height - 13);
5297
	paint.end();
5438
	paint.end();
5298
	ui_sportwatcherWidgetBase.grElevation->setPixmap(pm);
5439
	ui_sportwatcherWidgetBase.grElevation->setPixmap(pm);
5299
}
5440
}
5300
 
5441
 
5301
void sportwatcherWidget::drawGrSpeed (int x, int y)
5442
void sportwatcherWidget::drawGrSpeed(int x, int y)
5302
{
5443
{
5303
int width, height;
5444
	int width, height;
5304
QPixmap pm = pmSpeed.copy(pmSpeed.rect());
5445
	QPixmap pm = pmSpeed.copy(pmSpeed.rect());
5305
QPainter paint;
5446
	QPainter paint;
5306
 
5447
 
5307
	width = ui_sportwatcherWidgetBase.grSpeed->width();
5448
	width = ui_sportwatcherWidgetBase.grSpeed->width();
5308
	height = ui_sportwatcherWidgetBase.grSpeed->height();
5449
	height = ui_sportwatcherWidgetBase.grSpeed->height();
5309
	ui_sportwatcherWidgetBase.grSpeed->setPixmap(pmSpeed);
5450
	ui_sportwatcherWidgetBase.grSpeed->setPixmap(pmSpeed);
5310
 
5451
 
5311
	if (x > (width - 40) || y > (height - 12) || x < 1)
5452
	if(x > (width - 40) || y > (height - 12) || x < 1)
5312
	{
5453
	{
5313
	   ui_sportwatcherWidgetBase.grHR->setPixmap(pmHR);
5454
		ui_sportwatcherWidgetBase.grHR->setPixmap(pmHR);
5314
	   ui_sportwatcherWidgetBase.grElevation->setPixmap(pmElevation);
5455
		ui_sportwatcherWidgetBase.grElevation->setPixmap(pmElevation);
5315
	   return;
5456
		return;
5316
	}
5457
	}
5317
 
5458
 
5318
	if (tabDirt2)
5459
	if(tabDirt2)
5319
	{
5460
	{
5320
	   DIRTY = true;
5461
		DIRTY = true;
5321
	   showThreeCurve ();
5462
		showThreeCurve();
5322
	   tabDirt2 = false;
5463
		tabDirt2 = false;
5323
	   DIRTY = false;
5464
		DIRTY = false;
5324
	}
5465
	}
5325
 
5466
 
5326
	paint.begin(&pm);
5467
	paint.begin(&pm);
5327
	QColor black(0, 0, 0);
5468
	QColor black(0, 0, 0);
5328
	black.setAlpha (128);
5469
	black.setAlpha(128);
5329
	paint.setPen(QPen(black, 1, Qt::SolidLine));
5470
	paint.setPen(QPen(black, 1, Qt::SolidLine));
-
 
5471
 
5330
	// horizontal line, if y != -1
5472
	// horizontal line, if y != -1
5331
	if (y >= 0)
5473
	if(y >= 0)
5332
	   paint.drawLine(2, y, width - 41, y);
5474
		paint.drawLine(2, y, width - 41, y);
5333
 
5475
 
5334
	// vertical line
5476
	// vertical line
5335
	paint.drawLine(x, 1, x, height - 13);
5477
	paint.drawLine(x, 1, x, height - 13);
5336
	paint.end();
5478
	paint.end();
5337
	ui_sportwatcherWidgetBase.grSpeed->setPixmap(pm);
5479
	ui_sportwatcherWidgetBase.grSpeed->setPixmap(pm);
5338
}
5480
}
5339
 
5481
 
5340
/*
5482
/*
5341
 * Private functions to help decode the data
5483
 * Private functions to help decode the data
5342
 */
5484
 */
5343
QDateTime *sportwatcherWidget::garmin_dtime (uint32 t)
5485
QDateTime *sportwatcherWidget::garmin_dtime(uint32 t)
5344
{
5486
{
5345
time_t     tval;
5487
	time_t     tval;
5346
struct tm  tmval;
5488
	struct tm  tmval;
5347
QTime ti;
5489
	QTime ti;
5348
QDate dt;
5490
	QDate dt;
5349
QDateTime *qt;
5491
	QDateTime *qt;
5350
 
5492
 
5351
	if (t == 0)
5493
	if(t == 0)
5352
	   return new QDateTime(QDate(1900, 1, 1), QTime(0, 0, 0, 0));
5494
		return new QDateTime(QDate(1900, 1, 1), QTime(0, 0, 0, 0));
5353
 
5495
 
5354
	tval = t + TIME_OFFSET;
5496
	tval = t + TIME_OFFSET;
5355
	localtime_r (&tval, &tmval);
5497
	localtime_r(&tval, &tmval);
5356
	qt = new QDateTime();
5498
	qt = new QDateTime();
5357
	qt->setDate(QDate(tmval.tm_year+1900, tmval.tm_mon+1, tmval.tm_mday));
5499
	qt->setDate(QDate(tmval.tm_year + 1900, tmval.tm_mon + 1, tmval.tm_mday));
5358
	qt->setTime(QTime(tmval.tm_hour, tmval.tm_min, tmval.tm_sec, 0));
5500
	qt->setTime(QTime(tmval.tm_hour, tmval.tm_min, tmval.tm_sec, 0));
5359
	/* OK.  Done. */
5501
	/* OK.  Done. */
5360
	return qt;
5502
	return qt;
5361
}
5503
}
5362
 
5504
 
5363
bool sportwatcherWidget::writeTag(const QFile &fn, const QString &str, int indent)
5505
bool sportwatcherWidget::writeTag(const QFile &fn, const QString &str, int indent)
5364
{
5506
{
5365
QString qs;
5507
	QString qs;
5366
char *p;
5508
	char *p;
5367
//QCString qcs;
5509
//QCString qcs;
5368
int i;
5510
	int i;
5369
 
5511
 
5370
	if (indent > 0)
5512
	if(indent > 0)
5371
	   qs.fill(' ', indent * 3);
5513
		qs.fill(' ', indent * 3);
5372
 
5514
 
5373
	qs.append(str);
5515
	qs.append(str);
5374
//	qcs = qs.utf8();
5516
//	qcs = qs.utf8();
5375
//	qstrcpy(p, qcs);
5517
//	qstrcpy(p, qcs);
5376
	p = strdup (qs.toUtf8().data());
5518
	p = strdup(qs.toUtf8().data());
5377
	i = strlen(p);
5519
	i = strlen(p);
5378
 
5520
 
5379
	if (write(fn.handle(), p, i) != i)
5521
	if(write(fn.handle(), p, i) != i)
5380
	{
5522
	{
5381
	   free (p);
5523
		free(p);
5382
	   return false;
5524
		return false;
5383
	}
5525
	}
5384
 
5526
 
5385
	free (p);
5527
	free(p);
5386
	return true;
5528
	return true;
5387
}
5529
}
5388
 
5530
 
5389
#if defined HAVE_GDAL
5531
#if defined HAVE_GDAL
5390
bool sportwatcherWidget::writeWMSTag(double llat, double llon, double rlat, double rlon, int width, int height)
5532
bool sportwatcherWidget::writeWMSTag(double llat, double llon, double rlat, double rlon, int width, int height)
5391
{
5533
{
5392
QFile fl(MAP);
5534
	QFile fl(MAP);
5393
QString xml, s, srs, crs, styles, bSize, ext;
5535
	QString xml, s, srs, crs, styles, bSize, ext;
5394
QDir dir = QDir::home();
5536
	QDir dir = QDir::home();
5395
QString path = dir.absolutePath();
5537
	QString path = dir.absolutePath();
5396
int item, isrs;
5538
	int item, isrs;
5397
double _llat, _llon, _rlat, _rlon;
5539
	double _llat, _llon, _rlat, _rlon;
5398
bool offline, square;
5540
	bool offline, square;
5399
 
5541
 
5400
	if (!fl.open(QIODevice::ReadWrite | QIODevice::Truncate))
5542
	if(!fl.open(QIODevice::ReadWrite | QIODevice::Truncate))
5401
	{
5543
	{
5402
	   KMessageBox::error (this, i18n("Error opening or creating the WMS tag file!\nPlease check file name and/or permissions."));
5544
		KMessageBox::error(this, i18n("Error opening or creating the WMS tag file!\nPlease check file name and/or permissions."));
5403
	   return false;
5545
		return false;
5404
	}
5546
	}
5405
 
5547
 
5406
	KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig);
5548
	KConfig cfg(QString("sportwatcher.rc"), KConfig::SimpleConfig);
5407
	KConfigGroup wms (&cfg, "WMS");
5549
	KConfigGroup wms(&cfg, "WMS");
5408
	square = wms.readEntry("Square", false);
5550
	square = wms.readEntry("Square", false);
5409
	styles = wms.readEntry("Styles", QString(""));
5551
	styles = wms.readEntry("Styles", QString(""));
5410
 
5552
 
5411
	xml = "<GDAL_WMS>\n";
5553
	xml = "<GDAL_WMS>\n";
5412
	xml += "   <Service name=\"WMS\">\n";
5554
	xml += "   <Service name=\"WMS\">\n";
Line 5417... Line 5559...
5417
	_llat = llat;
5559
	_llat = llat;
5418
	_rlon = rlon;
5560
	_rlon = rlon;
5419
	_rlat = rlat;
5561
	_rlat = rlat;
5420
	offline = false;
5562
	offline = false;
5421
 
5563
 
5422
	switch (isrs)
5564
	switch(isrs)
5423
	{
5565
	{
5424
	   case 0: srs = QString("EPSG:4326"); break;
5566
		case 0: srs = QString("EPSG:4326"); break;
5425
 
5567
 
5426
	   case 1:
5568
		case 1:
5427
	      srs = QString("EPSG:31257");
5569
			srs = QString("EPSG:31257");
5428
	      offline = transCoords(&_llat, &_llon, &_rlat, &_rlon, 31257, width, height, square);
5570
			offline = transCoords(&_llat, &_llon, &_rlat, &_rlon, 31257, width, height, square);
5429
	   break;
5571
			break;
5430
 
5572
 
5431
	   case 2:
5573
		case 2:
5432
	      srs = QString("EPSG:31258");
5574
			srs = QString("EPSG:31258");
5433
	      offline = transCoords(&_llat, &_llon, &_rlat, &_rlon, 31258, width, height, square);
5575
			offline = transCoords(&_llat, &_llon, &_rlat, &_rlon, 31258, width, height, square);
5434
	   break;
5576
			break;
5435
 
5577
 
5436
	   case 3:
5578
		case 3:
5437
	      srs = QString("EPSG:31259");
5579
			srs = QString("EPSG:31259");
5438
	      offline = transCoords(&_llat, &_llon, &_rlat, &_rlon, 31259, width, height, square);
5580
			offline = transCoords(&_llat, &_llon, &_rlat, &_rlon, 31259, width, height, square);
5439
	   break;
5581
			break;
5440
 
5582
 
5441
	   case 4:
5583
		case 4:
5442
	      srs = QString("EPSG:31286");
5584
			srs = QString("EPSG:31286");
5443
	      offline = transCoords(&_llat, &_llon, &_rlat, &_rlon, 31286, width, height, square);
5585
			offline = transCoords(&_llat, &_llon, &_rlat, &_rlon, 31286, width, height, square);
5444
	   break;
5586
			break;
5445
 
5587
 
5446
	   case 5:
5588
		case 5:
5447
	      srs = QString("EPSG:31287");
5589
			srs = QString("EPSG:31287");
5448
	      offline = transCoords(&_llat, &_llon, &_rlat, &_rlon, 31287, width, height, square);
5590
			offline = transCoords(&_llat, &_llon, &_rlat, &_rlon, 31287, width, height, square);
5449
	   break;
5591
			break;
5450
 
5592
 
5451
	   case 6:
5593
		case 6:
5452
	      srs = QString("EPSG:31288");
5594
			srs = QString("EPSG:31288");
5453
	      offline = transCoords(&_llat, &_llon, &_rlat, &_rlon, 31288, width, height, square);
5595
			offline = transCoords(&_llat, &_llon, &_rlat, &_rlon, 31288, width, height, square);
5454
	   break;
5596
			break;
5455
 
5597
 
5456
	   case 7:
5598
		case 7:
5457
	      srs = QString("EPSG:900913");
5599
			srs = QString("EPSG:900913");
5458
	      offline = transCoords(&_llat, &_llon, &_rlat, &_rlon, 900913, width, height, square);
5600
			offline = transCoords(&_llat, &_llon, &_rlat, &_rlon, 900913, width, height, square);
5459
	   break;
5601
			break;
5460
 
5602
 
5461
	   case 8:
5603
		case 8:
5462
	      srs = QString("EPSG:3395");
5604
			srs = QString("EPSG:3395");
5463
	      offline = transCoords(&_llat, &_llon, &_rlat, &_rlon, 3395, width, height, square);
5605
			offline = transCoords(&_llat, &_llon, &_rlat, &_rlon, 3395, width, height, square);
5464
	   break;
5606
			break;
5465
 
5607
 
5466
	   default: srs = QString("EPSG:4326");
5608
		default: srs = QString("EPSG:4326");
5467
	}
5609
	}
5468
 
5610
 
5469
	xml += "      <SRS>" + srs + "</SRS>\n";
5611
	xml += "      <SRS>" + srs + "</SRS>\n";
5470
	item = wms.readEntry("CRS", 0);
5612
	item = wms.readEntry("CRS", 0);
5471
 
5613
 
5472
	switch (item)
5614
	switch(item)
5473
	{
5615
	{
5474
	   case 0: crs = QString("CRS:83"); break;
5616
		case 0: crs = QString("CRS:83"); break;
5475
	   case 1: crs = QString("CRS:84"); break;
5617
		case 1: crs = QString("CRS:84"); break;
5476
	   case 2: crs = QString("EPSG:4326"); break;
5618
		case 2: crs = QString("EPSG:4326"); break;
5477
	   case 3: crs = QString("EPSG:31259"); break;
5619
		case 3: crs = QString("EPSG:31259"); break;
5478
	   case 4: crs = QString("EPSG:31287"); break;
5620
		case 4: crs = QString("EPSG:31287"); break;
5479
	   case 5: crs = QString("EPSG:900913"); break;
5621
		case 5: crs = QString("EPSG:900913"); break;
5480
	   case 6: crs = QString("EPSG:3395"); break;
5622
		case 6: crs = QString("EPSG:3395"); break;
5481
	   default: crs = QString("CRS:84"); break;
5623
		default: crs = QString("CRS:84"); break;
5482
	}
5624
	}
5483
 
5625
 
5484
	xml += "      <CRS>" + crs + "</CRS>\n";
5626
	xml += "      <CRS>" + crs + "</CRS>\n";
5485
	item = wms.readEntry("Image", 2);
5627
	item = wms.readEntry("Image", 2);
5486
	xml += "      <ImageFormat>image/";
5628
	xml += "      <ImageFormat>image/";
5487
 
5629
 
5488
	switch (item)
5630
	switch(item)
5489
	{
5631
	{
5490
	   case 0: xml += "gif"; ext = QString(".gif"); break;
5632
		case 0: xml += "gif"; ext = QString(".gif"); break;
5491
	   case 1: xml += "jpeg"; ext = QString(".jpg"); break;
5633
		case 1: xml += "jpeg"; ext = QString(".jpg"); break;
5492
	   case 2: xml += "png"; ext = QString(".png"); break;
5634
		case 2: xml += "png"; ext = QString(".png"); break;
5493
	   case 3: xml += "tiff"; ext = QString(".tif"); break;
5635
		case 3: xml += "tiff"; ext = QString(".tif"); break;
5494
	   default: xml += "png"; ext = QString(".png");
5636
		default: xml += "png"; ext = QString(".png");
5495
	}
5637
	}
5496
 
5638
 
5497
	xml += "</ImageFormat>\n";
5639
	xml += "</ImageFormat>\n";
5498
 
5640
 
5499
	xml += "      <Layers>" + wms.readEntry("Layer", QString("")) + "</Layers>\n";
5641
	xml += "      <Layers>" + wms.readEntry("Layer", QString("")) + "</Layers>\n";
5500
 
5642
 
5501
	if (!styles.isEmpty())
5643
	if(!styles.isEmpty())
5502
	   xml += "      <Styles>" + styles + "</Styles>\n";
5644
		xml += "      <Styles>" + styles + "</Styles>\n";
5503
 
5645
 
5504
	xml += "      <BBoxOrder>xyXY</BBoxOrder>\n";
5646
	xml += "      <BBoxOrder>xyXY</BBoxOrder>\n";
5505
	xml += "   </Service>\n";
5647
	xml += "   </Service>\n";
5506
	xml += "   <DataWindow>\n";
5648
	xml += "   <DataWindow>\n";
5507
	s.sprintf ("%f", _llat);
5649
	s.sprintf("%f", _llat);
5508
	xml += "      <UpperLeftX>" + s + "</UpperLeftX>\n";
5650
	xml += "      <UpperLeftX>" + s + "</UpperLeftX>\n";
5509
	s.sprintf ("%f", _llon);
5651
	s.sprintf("%f", _llon);
5510
	xml += "      <UpperLeftY>" + s + "</UpperLeftY>\n";
5652
	xml += "      <UpperLeftY>" + s + "</UpperLeftY>\n";
5511
	s.sprintf ("%f", _rlat);
5653
	s.sprintf("%f", _rlat);
5512
	xml += "      <LowerRightX>" + s + "</LowerRightX>\n";
5654
	xml += "      <LowerRightX>" + s + "</LowerRightX>\n";
5513
	s.sprintf ("%f", _rlon);
5655
	s.sprintf("%f", _rlon);
5514
	xml += "      <LowerRightY>" + s + "</LowerRightY>\n";
5656
	xml += "      <LowerRightY>" + s + "</LowerRightY>\n";
5515
	s.sprintf ("%d", width);
5657
	s.sprintf("%d", width);
5516
	xml += "      <SizeX>" + s + "</SizeX>\n";
5658
	xml += "      <SizeX>" + s + "</SizeX>\n";
5517
	s.sprintf ("%d", height);
5659
	s.sprintf("%d", height);
5518
	xml += "      <SizeY>" + s + "</SizeY>\n";
5660
	xml += "      <SizeY>" + s + "</SizeY>\n";
5519
	xml += "   </DataWindow>\n";
5661
	xml += "   </DataWindow>\n";
5520
 
5662
 
5521
/*	switch (isrs)
5663
	/*	switch (isrs)
5522
	{
5664
		{
5523
	   case 0: srs = QString("EPSG:4326"); break;
5665
		   case 0: srs = QString("EPSG:4326"); break;
5524
	   case 1: srs = QString("EPSG:31259"); break;
5666
		   case 1: srs = QString("EPSG:31259"); break;
5525
	   case 2: srs = QString("EPSG:31286"); break;
5667
		   case 2: srs = QString("EPSG:31286"); break;
5526
	   case 3: srs = QString("EPSG:31287"); break;
5668
		   case 3: srs = QString("EPSG:31287"); break;
5527
	   case 4: srs = QString("EPSG:31288"); break;
5669
		   case 4: srs = QString("EPSG:31288"); break;
5528
	   default: srs = QString("EPSG:4326");
5670
		   default: srs = QString("EPSG:4326");
5529
	}
5671
		}
5530
*/
5672
	*/
5531
//	srs = QString("EPSG:4326");
5673
//	srs = QString("EPSG:4326");
5532
	xml += "   <Projection>" + crs + "</Projection>\n";
5674
	xml += "   <Projection>" + crs + "</Projection>\n";
5533
	xml += "   <BandsCount>" + wms.readEntry("Bands", QString("3")) + "</BandsCount>\n";
5675
	xml += "   <BandsCount>" + wms.readEntry("Bands", QString("3")) + "</BandsCount>\n";
5534
	item = wms.readEntry("Tile", 2);
5676
	item = wms.readEntry("Tile", 2);
5535
 
5677
 
5536
	switch (item)
5678
	switch(item)
5537
	{
5679
	{
5538
	   case 0: bSize = QString("64"); break;
5680
		case 0: bSize = QString("64"); break;
5539
	   case 1: bSize = QString("128"); break;
5681
		case 1: bSize = QString("128"); break;
5540
	   case 2: bSize = QString("256"); break;
5682
		case 2: bSize = QString("256"); break;
5541
	   case 3: bSize = QString("512"); break;
5683
		case 3: bSize = QString("512"); break;
5542
	   case 4: bSize = QString("1024"); break;
5684
		case 4: bSize = QString("1024"); break;
5543
	   default: bSize = QString("256");
5685
		default: bSize = QString("256");
5544
	}
5686
	}
5545
 
5687
 
5546
	xml += "   <BlockSizeX>" + bSize + "</BlockSizeX>\n";
5688
	xml += "   <BlockSizeX>" + bSize + "</BlockSizeX>\n";
5547
	xml += "   <BlockSizeY>" + bSize + "</BlockSizeY>\n";
5689
	xml += "   <BlockSizeY>" + bSize + "</BlockSizeY>\n";
5548
	xml += "   <OverviewCount>" + wms.readEntry("Overview", QString("10")) + "</OverviewCount>\n";
5690
	xml += "   <OverviewCount>" + wms.readEntry("Overview", QString("10")) + "</OverviewCount>\n";
Line 5553... Line 5695...
5553
	xml += "   </Cache>\n";
5695
	xml += "   </Cache>\n";
5554
	QString off((wms.readEntry("Offline", false)) ? "true" : "false");
5696
	QString off((wms.readEntry("Offline", false)) ? "true" : "false");
5555
	QString adv((wms.readEntry("Advice", false)) ? "true" : "false");
5697
	QString adv((wms.readEntry("Advice", false)) ? "true" : "false");
5556
	QString ver((wms.readEntry("Verify", true)) ? "true" : "false");
5698
	QString ver((wms.readEntry("Verify", true)) ? "true" : "false");
5557
 
5699
 
5558
	if (offline)
5700
	if(offline)
5559
	   xml += "   <OfflineMode>true</OfflineMode>\n";
5701
		xml += "   <OfflineMode>true</OfflineMode>\n";
5560
	else
5702
	else
5561
	   xml += "   <OfflineMode>" + off + "</OfflineMode>\n";
5703
		xml += "   <OfflineMode>" + off + "</OfflineMode>\n";
5562
 
5704
 
5563
	xml += "   <AdviseRead>" + adv + "</AdviseRead>\n";
5705
	xml += "   <AdviseRead>" + adv + "</AdviseRead>\n";
5564
	xml += "   <VerifyAdviseRead>" + ver + "</VerifyAdviseRead>\n";
5706
	xml += "   <VerifyAdviseRead>" + ver + "</VerifyAdviseRead>\n";
5565
	xml += "</GDAL_WMS>\n";
5707
	xml += "</GDAL_WMS>\n";
5566
 
5708
 
5567
	write (fl.handle(), xml.toAscii().data(), strlen (xml.toAscii().data()));
5709
	write(fl.handle(), xml.toAscii().data(), strlen(xml.toAscii().data()));
5568
	fl.close();
5710
	fl.close();
5569
	return true;
5711
	return true;
5570
}
5712
}
5571
 
5713
 
5572
bool sportwatcherWidget::transCoords (double *x1, double *y1, double *x2, double *y2, int code, int width, int height, bool square)
5714
bool sportwatcherWidget::transCoords(double *x1, double *y1, double *x2, double *y2, int code, int width, int height, bool square)
5573
{
5715
{
5574
OGRSpatialReference oSourceSRS, oTargetSRS;
5716
	OGRSpatialReference oSourceSRS, oTargetSRS;
5575
OGRCoordinateTransformation *poCT;
5717
	OGRCoordinateTransformation *poCT;
5576
 
5718
 
5577
	oSourceSRS.SetWellKnownGeogCS ("WGS84");
5719
	oSourceSRS.SetWellKnownGeogCS("WGS84");
5578
	oTargetSRS.importFromEPSG(code);
5720
	oTargetSRS.importFromEPSG(code);
5579
	poCT = OGRCreateCoordinateTransformation (&oSourceSRS, &oTargetSRS);
5721
	poCT = OGRCreateCoordinateTransformation(&oSourceSRS, &oTargetSRS);
5580
 
5722
 
5581
	if (poCT == NULL || !poCT->Transform( 1, x1, y1))
5723
	if(poCT == NULL || !poCT->Transform(1, x1, y1))
5582
	{
5724
	{
5583
	   KMessageBox::error(this, i18n("Translation between coordinate systems failed!"));
5725
		KMessageBox::error(this, i18n("Translation between coordinate systems failed!"));
5584
 
5726
 
5585
	   if (poCT != NULL)
5727
		if(poCT != NULL)
5586
	      delete poCT;
5728
			delete poCT;
5587
 
5729
 
5588
	   return true;
5730
		return true;
5589
	}
5731
	}
5590
 
5732
 
5591
	if (poCT != NULL)
5733
	if(poCT != NULL)
5592
	{
5734
	{
5593
	   poCT->Transform (1, x2, y2);
5735
		poCT->Transform(1, x2, y2);
5594
	   delete poCT;
5736
		delete poCT;
5595
	}
5737
	}
5596
 
5738
 
5597
	if (square)
5739
	if(square)
5598
	{
5740
	{
5599
	double wdiff = (double)((long)(*x1 - *x2) / (width / 2 * 2) * (width / 2 * 2));
5741
		double wdiff = (double)((long)(*x1 - *x2) / (width / 2 * 2) * (width / 2 * 2));
5600
	double hdiff = (double)((long)(*y2 - *y1) / (height / 2 * 2) * (height / 2 * 2));
5742
		double hdiff = (double)((long)(*y2 - *y1) / (height / 2 * 2) * (height / 2 * 2));
5601
 
5743
 
5602
	   *x2 = *x1 - wdiff; // * (double)mFactor;
5744
		*x2 = *x1 - wdiff; // * (double)mFactor;
5603
	   *y2 = *y1 + hdiff; // * (double)mFactor;
5745
		*y2 = *y1 + hdiff; // * (double)mFactor;
5604
//	   *x2 = *x1 - (double)((long)(wdiff / mFactor * mFactor));
5746
//	   *x2 = *x1 - (double)((long)(wdiff / mFactor * mFactor));
5605
//	   *y2 = *y1 - (double)((long)(hdiff / mFactor * mFactor));
5747
//	   *y2 = *y1 - (double)((long)(hdiff / mFactor * mFactor));
5606
/*	   wdiff = wdiff - (*x1 - *x2);
5748
		/*	   wdiff = wdiff - (*x1 - *x2);
5607
	   hdiff = hdiff - (*y2 - *y1);
5749
			   hdiff = hdiff - (*y2 - *y1);
5608
	   *x1 -= wdiff / 2.0;
5750
			   *x1 -= wdiff / 2.0;
5609
	   *x2 -= wdiff / 2.0;
5751
			   *x2 -= wdiff / 2.0;
5610
	   *y1 += hdiff / 2.0;
5752
			   *y1 += hdiff / 2.0;
5611
	   *y2 += hdiff / 2.0; */
5753
			   *y2 += hdiff / 2.0; */
5612
	}
5754
	}
5613
 
5755
 
5614
	return false;
5756
	return false;
5615
}
5757
}
5616
 
5758
 
5617
QString *sportwatcherWidget::getProjection (int isrs, QString *srs)
5759
QString *sportwatcherWidget::getProjection(int isrs, QString *srs)
5618
{
5760
{
5619
	switch (isrs)
5761
	switch(isrs)
5620
	{
5762
	{
5621
	   case 0: *srs = QString("EPSG:4326"); break;
5763
		case 0: *srs = QString("EPSG:4326"); break;
5622
	   case 1: *srs = QString("EPSG:31257"); break;
5764
		case 1: *srs = QString("EPSG:31257"); break;
5623
	   case 2: *srs = QString("EPSG:31258"); break;
5765
		case 2: *srs = QString("EPSG:31258"); break;
5624
	   case 3: *srs = QString("EPSG:31259"); break;
5766
		case 3: *srs = QString("EPSG:31259"); break;
5625
	   case 4: *srs = QString("EPSG:31286"); break;
5767
		case 4: *srs = QString("EPSG:31286"); break;
5626
	   case 5: *srs = QString("EPSG:31287"); break;
5768
		case 5: *srs = QString("EPSG:31287"); break;
5627
	   case 6: *srs = QString("EPSG:31288"); break;
5769
		case 6: *srs = QString("EPSG:31288"); break;
5628
	   default: *srs = QString("EPSG:4326");
5770
		default: *srs = QString("EPSG:4326");
5629
	}
5771
	}
5630
 
5772
 
5631
	return srs;
5773
	return srs;
5632
}
5774
}
5633
 
5775
 
5634
bool sportwatcherWidget::warpImage(QString fn, QString *fName)
5776
bool sportwatcherWidget::warpImage(QString fn, QString *fName)
5635
{
5777
{
5636
GDALDatasetH  hSrcDS, hDstDS;
5778
	GDALDatasetH  hSrcDS, hDstDS;
5637
GDALDataset *inSet, *outSet;
5779
	GDALDataset *inSet, *outSet;
5638
GDALDataType eDT;
5780
	GDALDataType eDT;
5639
GDALRasterBand *poBand;
5781
	GDALRasterBand *poBand;
5640
GDALDriverH hDriver;
5782
	GDALDriverH hDriver;
5641
char hv0[256];
5783
	char hv0[256];
5642
int nXSize, nYSize;
5784
	int nXSize, nYSize;
5643
double adfGeoTransform[6];
5785
	double adfGeoTransform[6];
5644
double oriLeftLon, oriRightLon, oriLeftLat, oriRightLat;
5786
	double oriLeftLon, oriRightLon, oriLeftLat, oriRightLat;
5645
 
5787
 
5646
 
5788
 
5647
	// Loading the user set geo coords of our source image and
5789
	// Loading the user set geo coords of our source image and
5648
	// load the projection used for that image
5790
	// load the projection used for that image
5649
	KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig);
5791
	KConfig cfg(QString("sportwatcher.rc"), KConfig::SimpleConfig);
5650
	KConfigGroup ic (&cfg, "ImageCoords");
5792
	KConfigGroup ic(&cfg, "ImageCoords");
5651
	oriLeftLon = ic.readEntry("LeftLon", 0.0);
5793
	oriLeftLon = ic.readEntry("LeftLon", 0.0);
5652
	oriLeftLat = ic.readEntry("LeftLat", 0.0);
5794
	oriLeftLat = ic.readEntry("LeftLat", 0.0);
5653
	oriRightLon = ic.readEntry("RightLon", 0.0);
5795
	oriRightLon = ic.readEntry("RightLon", 0.0);
5654
	oriRightLat = ic.readEntry("RightLat", 0.0);
5796
	oriRightLat = ic.readEntry("RightLat", 0.0);
5655
	int isrs = ic.readEntry("SRS", 0);
5797
	int isrs = ic.readEntry("SRS", 0);
5656
 
5798
 
5657
	// Create a temporary file name for our output file
5799
	// Create a temporary file name for our output file
5658
	strcpy (hv0, "/tmp/SportWatcherTIFFXXXXXX");
5800
	strcpy(hv0, "/tmp/SportWatcherTIFFXXXXXX");
5659
	mkdtemp (&hv0[0]);
5801
	mkdtemp(&hv0[0]);
5660
	*fName = QString(hv0) + ".tif";
5802
	*fName = QString(hv0) + ".tif";
5661
 
5803
 
5662
	// Open input and output files.
5804
	// Open input and output files.
5663
	if ((hSrcDS = GDALOpen(fn.toAscii().data(), GA_ReadOnly)) == NULL)
5805
	if((hSrcDS = GDALOpen(fn.toAscii().data(), GA_ReadOnly)) == NULL)
5664
	{
5806
	{
5665
	   KMessageBox::error(this, i18n("Error opening an image file!"));
5807
		KMessageBox::error(this, i18n("Error opening an image file!"));
5666
	   return false;
5808
		return false;
5667
	}
5809
	}
5668
 
5810
 
5669
	inSet = (GDALDataset *)hSrcDS;
5811
	inSet = (GDALDataset *)hSrcDS;
5670
	// Create output with same datatype as first input band.
5812
	// Create output with same datatype as first input band.
5671
	poBand = inSet->GetRasterBand (1);
5813
	poBand = inSet->GetRasterBand(1);
5672
	eDT = poBand->GetRasterDataType ();
5814
	eDT = poBand->GetRasterDataType();
5673
 
5815
 
5674
	if ((hDriver = GDALGetDriverByName ("GTiff")) == NULL)
5816
	if((hDriver = GDALGetDriverByName("GTiff")) == NULL)
5675
	{
5817
	{
5676
	   KMessageBox::error(this, i18n("Error loading the TIFF driver!"));
5818
		KMessageBox::error(this, i18n("Error loading the TIFF driver!"));
5677
	   GDALClose (hSrcDS);
5819
		GDALClose(hSrcDS);
5678
	   return false;
5820
		return false;
5679
	}
5821
	}
5680
 
5822
 
5681
	// Get dimensions of image and set transform data
5823
	// Get dimensions of image and set transform data
5682
	int nRasterCount = inSet->GetRasterCount();
5824
	int nRasterCount = inSet->GetRasterCount();
5683
	nXSize = inSet->GetRasterXSize();
5825
	nXSize = inSet->GetRasterXSize();
5684
	nYSize = inSet->GetRasterYSize();
5826
	nYSize = inSet->GetRasterYSize();
5685
 
5827
 
5686
	// cut the wanted region out of image
5828
	// cut the wanted region out of image
5687
	transform *tf = new transform (oriLeftLat, oriLeftLon, oriRightLat, oriRightLon);
5829
	transform *tf = new transform(oriLeftLat, oriLeftLon, oriRightLat, oriRightLon);
5688
	tf->setDimensions(nXSize, nYSize);
5830
	tf->setDimensions(nXSize, nYSize);
5689
 
5831
 
5690
	if (!tf->cutImage (geoRect.llat, geoRect.llon, geoRect.rlat, geoRect.rlon, fn))
5832
	if(!tf->cutImage(geoRect.llat, geoRect.llon, geoRect.rlat, geoRect.rlon, fn))
5691
	{
5833
	{
5692
	   GDALClose (hSrcDS);
5834
		GDALClose(hSrcDS);
5693
	   return false;
5835
		return false;
5694
	}
5836
	}
5695
 
5837
 
5696
	GDALClose (hSrcDS);
5838
	GDALClose(hSrcDS);
5697
	QString nfn = fn + "_tmp.png";
5839
	QString nfn = fn + "_tmp.png";
5698
 
5840
 
5699
	// repeat the part above and open the now cutted part of the image.
5841
	// repeat the part above and open the now cutted part of the image.
5700
	// Open input and output files.
5842
	// Open input and output files.
5701
	if ((hSrcDS = GDALOpen(nfn.toAscii().data(), GA_ReadOnly)) == NULL)
5843
	if((hSrcDS = GDALOpen(nfn.toAscii().data(), GA_ReadOnly)) == NULL)
5702
	{
5844
	{
5703
	   KMessageBox::error(this, i18n("Error opening an image file!"));
5845
		KMessageBox::error(this, i18n("Error opening an image file!"));
5704
	   return false;
5846
		return false;
5705
	}
5847
	}
5706
 
5848
 
5707
	inSet = (GDALDataset *)hSrcDS;
5849
	inSet = (GDALDataset *)hSrcDS;
5708
	// Create output with same datatype as first input band.
5850
	// Create output with same datatype as first input band.
5709
	poBand = inSet->GetRasterBand (1);
5851
	poBand = inSet->GetRasterBand(1);
5710
	eDT = poBand->GetRasterDataType ();
5852
	eDT = poBand->GetRasterDataType();
5711
 
5853
 
5712
	if ((hDriver = GDALGetDriverByName ("GTiff")) == NULL)
5854
	if((hDriver = GDALGetDriverByName("GTiff")) == NULL)
5713
	{
5855
	{
5714
	   KMessageBox::error(this, i18n("Error loading the TIFF driver!"));
5856
		KMessageBox::error(this, i18n("Error loading the TIFF driver!"));
5715
	   GDALClose (hSrcDS);
5857
		GDALClose(hSrcDS);
5716
	   return false;
5858
		return false;
5717
	}
5859
	}
5718
 
5860
 
5719
	// Get dimensions of image and set transform data
5861
	// Get dimensions of image and set transform data
5720
	nRasterCount = inSet->GetRasterCount();
5862
	nRasterCount = inSet->GetRasterCount();
5721
	nXSize = inSet->GetRasterXSize();
5863
	nXSize = inSet->GetRasterXSize();
5722
	nYSize = inSet->GetRasterYSize();
5864
	nYSize = inSet->GetRasterYSize();
5723
 
5865
 
5724
	// Set the values needed to transform the image
5866
	// Set the values needed to transform the image
5725
	OGRSpatialReference iSRS;
5867
	OGRSpatialReference iSRS;
5726
	const char *iWKT;
5868
	const char *iWKT;
5727
	
5869
 
5728
	switch (isrs)
5870
	switch(isrs)
-
 
5871
	{
-
 
5872
		case 0: iSRS.importFromEPSG(4326); break;
-
 
5873
		case 1: iSRS.importFromEPSG(31257); break;
-
 
5874
		case 2: iSRS.importFromEPSG(31258); break;
-
 
5875
		case 3: iSRS.importFromEPSG(31259); break;
-
 
5876
		case 4: iSRS.importFromEPSG(31286); break;
-
 
5877
		case 5: iSRS.importFromEPSG(31287); break;
-
 
5878
		case 6: iSRS.importFromEPSG(31288); break;
-
 
5879
		default: iSRS.importFromEPSG(4326);
-
 
5880
	}
-
 
5881
 
-
 
5882
	iSRS.exportToWkt((char **)&iWKT);
-
 
5883
 
-
 
5884
	if(inSet->SetProjection(iWKT) != CE_None)
5729
	{
5885
	{
5730
	   case 0: iSRS.importFromEPSG(4326); break;
-
 
5731
	   case 1: iSRS.importFromEPSG(31257); break;
-
 
5732
	   case 2: iSRS.importFromEPSG(31258); break;
-
 
5733
	   case 3: iSRS.importFromEPSG(31259); break;
-
 
5734
	   case 4: iSRS.importFromEPSG(31286); break;
-
 
5735
	   case 5: iSRS.importFromEPSG(31287); break;
-
 
5736
	   case 6: iSRS.importFromEPSG(31288); break;
-
 
5737
	   default: iSRS.importFromEPSG(4326);
-
 
5738
	}
-
 
5739
 
-
 
5740
	iSRS.exportToWkt ((char **)&iWKT);
-
 
5741
 
-
 
5742
	if (inSet->SetProjection (iWKT) != CE_None)
-
 
5743
	{
-
 
5744
	   KMessageBox::error(this, i18n("Error setting projection on source!"));
5886
		KMessageBox::error(this, i18n("Error setting projection on source!"));
5745
	   GDALClose (hSrcDS);
5887
		GDALClose(hSrcDS);
5746
	   return false;
5888
		return false;
5747
	}
5889
	}
5748
 
5890
 
5749
	adfGeoTransform[0] = geoRect.llon;
5891
	adfGeoTransform[0] = geoRect.llon;
5750
	adfGeoTransform[1] = (geoRect.rlon - geoRect.llon) / (double)nXSize;
5892
	adfGeoTransform[1] = (geoRect.rlon - geoRect.llon) / (double)nXSize;
5751
	adfGeoTransform[2] = 0.0;
5893
	adfGeoTransform[2] = 0.0;
5752
	adfGeoTransform[3] = geoRect.llat;
5894
	adfGeoTransform[3] = geoRect.llat;
5753
	adfGeoTransform[4] = 0.0;
5895
	adfGeoTransform[4] = 0.0;
5754
	adfGeoTransform[5] = -1.0 * ((geoRect.llat - geoRect.rlat) / (double)nYSize);
5896
	adfGeoTransform[5] = -1.0 * ((geoRect.llat - geoRect.rlat) / (double)nYSize);
5755
 
5897
 
5756
	if (inSet->SetGeoTransform (&adfGeoTransform[0]) != CE_None)
5898
	if(inSet->SetGeoTransform(&adfGeoTransform[0]) != CE_None)
5757
	{
5899
	{
5758
	   KMessageBox::error(this, i18n("Error setting geo transform data to source!"));
5900
		KMessageBox::error(this, i18n("Error setting geo transform data to source!"));
5759
	   GDALClose (hSrcDS);
5901
		GDALClose(hSrcDS);
5760
	   return false;
5902
		return false;
5761
	}
5903
	}
5762
 
5904
 
5763
	// Get Source coordinate system.
5905
	// Get Source coordinate system.
5764
	const char *pszSrcWKT, *pszDstWKT = NULL;
5906
	const char *pszSrcWKT, *pszDstWKT = NULL;
5765
 
5907
 
5766
	if ((pszSrcWKT = GDALGetProjectionRef (hSrcDS)) == NULL)
5908
	if((pszSrcWKT = GDALGetProjectionRef(hSrcDS)) == NULL)
5767
	{
5909
	{
5768
	   KMessageBox::error(this, i18n("Error getting the projection reference"));
5910
		KMessageBox::error(this, i18n("Error getting the projection reference"));
5769
	   GDALClose (hSrcDS);
5911
		GDALClose(hSrcDS);
5770
	   return false;
5912
		return false;
5771
	}
5913
	}
5772
 
5914
 
5773
	// Setup output coordinate system that is UTM ? WGS84.
5915
	// Setup output coordinate system that is UTM ? WGS84.
5774
	OGRSpatialReference oSRS;
5916
	OGRSpatialReference oSRS;
5775
 
5917
 
5776
//	oSRS.SetUTM( 0, TRUE );
5918
//	oSRS.SetUTM( 0, TRUE );
5777
	oSRS.SetWellKnownGeogCS("WGS84");
5919
	oSRS.SetWellKnownGeogCS("WGS84");
5778
	oSRS.exportToWkt ((char **)&pszDstWKT);
5920
	oSRS.exportToWkt((char **)&pszDstWKT);
5779
 
5921
 
5780
	// Create the output file.
5922
	// Create the output file.
5781
	double adfDstGeoTransform[6];
5923
	double adfDstGeoTransform[6];
5782
	adfDstGeoTransform[0] = geoRect.llon;
5924
	adfDstGeoTransform[0] = geoRect.llon;
5783
	adfDstGeoTransform[1] = (geoRect.rlon - geoRect.llon) / (double)geoRect.width;
5925
	adfDstGeoTransform[1] = (geoRect.rlon - geoRect.llon) / (double)geoRect.width;
5784
	adfDstGeoTransform[2] = 0.0;
5926
	adfDstGeoTransform[2] = 0.0;
5785
	adfDstGeoTransform[3] = geoRect.llat;
5927
	adfDstGeoTransform[3] = geoRect.llat;
5786
	adfDstGeoTransform[4] = 0.0;
5928
	adfDstGeoTransform[4] = 0.0;
5787
	adfDstGeoTransform[5] = -1.0 * ((geoRect.llat - geoRect.rlat) / (double)geoRect.height);
5929
	adfDstGeoTransform[5] = -1.0 * ((geoRect.llat - geoRect.rlat) / (double)geoRect.height);
5788
 
5930
 
5789
	if ((hDstDS = GDALCreate(hDriver, fName->toAscii().data(), geoRect.width, geoRect.height,
5931
	if((hDstDS = GDALCreate(hDriver, fName->toAscii().data(), geoRect.width, geoRect.height,
5790
			nRasterCount, eDT, NULL )) == NULL)
5932
	                        nRasterCount, eDT, NULL)) == NULL)
5791
	{
5933
	{
5792
	   KMessageBox::error(this, i18n("Error creating a temporary image file! (%1)").arg(*fName));
5934
		KMessageBox::error(this, i18n("Error creating a temporary image file! (%1)").arg(*fName));
5793
	   GDALClose (hSrcDS);
5935
		GDALClose(hSrcDS);
5794
	   return false;
5936
		return false;
5795
	}
5937
	}
5796
 
5938
 
5797
	outSet = (GDALDataset *)hDstDS;
5939
	outSet = (GDALDataset *)hDstDS;
5798
 
5940
 
5799
	for (int i = 0; i < nRasterCount; i++)
5941
	for(int i = 0; i < nRasterCount; i++)
5800
	{
5942
	{
5801
	   poBand = outSet->GetRasterBand (i+1);
5943
		poBand = outSet->GetRasterBand(i + 1);
5802
	   poBand->Fill (0.0);
5944
		poBand->Fill(0.0);
5803
	}
5945
	}
5804
 
5946
 
5805
	if (outSet->SetProjection (pszDstWKT) != CE_None)
5947
	if(outSet->SetProjection(pszDstWKT) != CE_None)
5806
	{
5948
	{
5807
	   KMessageBox::error(this, i18n("Error setting projection on destination!"));
5949
		KMessageBox::error(this, i18n("Error setting projection on destination!"));
5808
	   GDALClose (hDstDS);
5950
		GDALClose(hDstDS);
5809
	   GDALClose (hSrcDS);
5951
		GDALClose(hSrcDS);
5810
	   unlink (fName->toAscii().data());
5952
		unlink(fName->toAscii().data());
5811
	   return false;
5953
		return false;
5812
	}
5954
	}
5813
 
5955
 
5814
	if (outSet->SetGeoTransform (&adfDstGeoTransform[0]) != CE_None)
5956
	if(outSet->SetGeoTransform(&adfDstGeoTransform[0]) != CE_None)
5815
	{
5957
	{
5816
	   KMessageBox::error(this, i18n("Error setting geo transform data to destination!"));
5958
		KMessageBox::error(this, i18n("Error setting geo transform data to destination!"));
5817
	   GDALClose (hDstDS);
5959
		GDALClose(hDstDS);
5818
	   GDALClose (hSrcDS);
5960
		GDALClose(hSrcDS);
5819
	   unlink (fName->toAscii().data());
5961
		unlink(fName->toAscii().data());
5820
	   return false;
5962
		return false;
5821
	}
5963
	}
5822
 
5964
 
5823
	// Copy the color table, if required.
5965
	// Copy the color table, if required.
5824
	GDALColorTableH hCT;
5966
	GDALColorTableH hCT;
5825
 
5967
 
5826
	for (int i = 0; i < nRasterCount; i++)
5968
	for(int i = 0; i < nRasterCount; i++)
5827
	{
5969
	{
5828
	   hCT = GDALGetRasterColorTable (inSet->GetRasterBand (i+1));
5970
		hCT = GDALGetRasterColorTable(inSet->GetRasterBand(i + 1));
5829
 
5971
 
5830
	   if (hCT != NULL)
5972
		if(hCT != NULL)
5831
              GDALSetRasterColorTable (outSet->GetRasterBand (i+1), hCT);
5973
			GDALSetRasterColorTable(outSet->GetRasterBand(i + 1), hCT);
5832
	}
5974
	}
5833
 
5975
 
5834
	// Setup warp options.
5976
	// Setup warp options.
5835
	GDALWarpOptions *psWarpOptions = GDALCreateWarpOptions();
5977
	GDALWarpOptions *psWarpOptions = GDALCreateWarpOptions();
5836
 
5978
 
5837
	psWarpOptions->hSrcDS = hSrcDS;
5979
	psWarpOptions->hSrcDS = hSrcDS;
5838
	psWarpOptions->hDstDS = hDstDS;
5980
	psWarpOptions->hDstDS = hDstDS;
5839
 
5981
 
5840
	psWarpOptions->nBandCount = nRasterCount;
5982
	psWarpOptions->nBandCount = nRasterCount;
5841
	psWarpOptions->panSrcBands =
5983
	psWarpOptions->panSrcBands =
5842
        	(int *) CPLMalloc(sizeof(int) * psWarpOptions->nBandCount );
5984
	         (int *) CPLMalloc(sizeof(int) * psWarpOptions->nBandCount);
5843
	psWarpOptions->panDstBands =
5985
	psWarpOptions->panDstBands =
5844
		(int *) CPLMalloc(sizeof(int) * psWarpOptions->nBandCount );
5986
	         (int *) CPLMalloc(sizeof(int) * psWarpOptions->nBandCount);
5845
 
5987
 
5846
	for (int i = 0; i < nRasterCount; i++)
5988
	for(int i = 0; i < nRasterCount; i++)
5847
	{
5989
	{
5848
	   psWarpOptions->panSrcBands[i] = i+1;
5990
		psWarpOptions->panSrcBands[i] = i + 1;
5849
	   psWarpOptions->panDstBands[i] = i+1;
5991
		psWarpOptions->panDstBands[i] = i + 1;
5850
	}
5992
	}
5851
 
5993
 
5852
//	psWarpOptions->pfnProgress = GDALTermProgress;
5994
//	psWarpOptions->pfnProgress = GDALTermProgress;
5853
 
5995
 
5854
	// Establish reprojection transformer.
5996
	// Establish reprojection transformer.
5855
	psWarpOptions->pTransformerArg =
5997
	psWarpOptions->pTransformerArg =
5856
        	GDALCreateGenImgProjTransformer(hSrcDS,
5998
	         GDALCreateGenImgProjTransformer(hSrcDS,
5857
					 GDALGetProjectionRef(hSrcDS), 
5999
	                           GDALGetProjectionRef(hSrcDS),
5858
					 hDstDS,
6000
	                           hDstDS,
5859
					 GDALGetProjectionRef(hDstDS),
6001
	                           GDALGetProjectionRef(hDstDS),
5860
					 FALSE, 0.0, 1);
6002
	                           FALSE, 0.0, 1);
5861
 
6003
 
5862
	psWarpOptions->pfnTransformer = GDALGenImgProjTransform;
6004
	psWarpOptions->pfnTransformer = GDALGenImgProjTransform;
5863
 
6005
 
5864
	// Initialize and execute the warp operation.
6006
	// Initialize and execute the warp operation.
5865
	GDALWarpOperation oOperation;
6007
	GDALWarpOperation oOperation;
5866
 
6008
 
5867
	if (oOperation.Initialize (psWarpOptions) != CE_None)
6009
	if(oOperation.Initialize(psWarpOptions) != CE_None)
5868
	{
6010
	{
5869
	   KMessageBox::error(this, i18n("Error initializing warp operation!"));
6011
		KMessageBox::error(this, i18n("Error initializing warp operation!"));
5870
	   GDALClose (hDstDS);
6012
		GDALClose(hDstDS);
5871
	   GDALClose (hSrcDS);
6013
		GDALClose(hSrcDS);
5872
	   unlink (fName->toAscii().data());
6014
		unlink(fName->toAscii().data());
5873
	   return false;
6015
		return false;
5874
	}
6016
	}
5875
 
6017
 
5876
	oOperation.ChunkAndWarpMulti (0, 0, geoRect.width, geoRect.height);
6018
	oOperation.ChunkAndWarpMulti(0, 0, geoRect.width, geoRect.height);
5877
	GDALDestroyGenImgProjTransformer (psWarpOptions->pTransformerArg);
6019
	GDALDestroyGenImgProjTransformer(psWarpOptions->pTransformerArg);
5878
	GDALDestroyWarpOptions(psWarpOptions);
6020
	GDALDestroyWarpOptions(psWarpOptions);
5879
 
6021
 
5880
	GDALClose (hDstDS);
6022
	GDALClose(hDstDS);
5881
	GDALClose (hSrcDS);
6023
	GDALClose(hSrcDS);
5882
	unlink (nfn.toAscii().data());
6024
	unlink(nfn.toAscii().data());
5883
	return true;
6025
	return true;
5884
}
6026
}
5885
 
6027
 
5886
#endif
6028
#endif
5887
 
6029
 
5888
#ifdef HAVE_GDAL
6030
#ifdef HAVE_GDAL
5889
void spwErrorHandler(CPLErr err, int num, const char *msg)
6031
void spwErrorHandler(CPLErr err, int num, const char *msg)
5890
{
6032
{
5891
ERRMSG *akt;
6033
	ERRMSG *akt;
5892
char et[32], hv0[4096];
6034
	char et[32], hv0[4096];
5893
 
6035
 
5894
	if (err == CE_None || !msg)
6036
	if(err == CE_None || !msg)
5895
	   return;
6037
		return;
5896
 
6038
 
5897
	if (err == CE_Fatal)
6039
	if(err == CE_Fatal)
5898
	   std::cerr << "ERROR " << num << ": " << msg << endl;
6040
		std::cerr << "ERROR " << num << ": " << msg << endl;
5899
 
6041
 
5900
	if (!firstError)
6042
	if(!firstError)
5901
	{
6043
	{
5902
	   firstError = new ERRMSG;
6044
		firstError = new ERRMSG;
5903
	   memset (firstError, 0, sizeof(ERRMSG));
6045
		memset(firstError, 0, sizeof(ERRMSG));
5904
	   akt = firstError;
6046
		akt = firstError;
5905
	}
6047
	}
5906
	else
6048
	else
5907
	{
6049
	{
5908
	   akt = firstError;
6050
		akt = firstError;
5909
 
6051
 
5910
	   while (akt)
6052
		while(akt)
5911
	   {
6053
		{
5912
	      if (!akt->next)
6054
			if(!akt->next)
5913
		 break;
6055
				break;
5914
 
6056
 
5915
	      akt = akt->next;
6057
			akt = akt->next;
5916
	   }
6058
		}
5917
 
6059
 
5918
	   akt->next = new ERRMSG;
6060
		akt->next = new ERRMSG;
5919
	   akt = akt->next;
6061
		akt = akt->next;
5920
	   memset (akt, 0, sizeof(ERRMSG));
6062
		memset(akt, 0, sizeof(ERRMSG));
5921
	}
6063
	}
5922
 
6064
 
5923
	switch (err)
6065
	switch(err)
5924
	{
6066
	{
5925
	   case CE_None: strcpy (et, "None"); break;
6067
		case CE_None: strcpy(et, "None"); break;
5926
	   case CE_Debug: strcpy (et, "DEBUG"); break;
6068
		case CE_Debug: strcpy(et, "DEBUG"); break;
5927
	   case CE_Warning: strcpy (et, "Warning"); break;
6069
		case CE_Warning: strcpy(et, "Warning"); break;
5928
	   case CE_Failure: strcpy (et, "Failure"); break;
6070
		case CE_Failure: strcpy(et, "Failure"); break;
5929
	   case CE_Fatal: strcpy (et, "Fatal"); break;
6071
		case CE_Fatal: strcpy(et, "Fatal"); break;
5930
	}
6072
	}
5931
 
6073
 
5932
	memset(hv0, 0, sizeof(hv0));
6074
	memset(hv0, 0, sizeof(hv0));
5933
	strncpy (hv0, msg, 4000);
6075
	strncpy(hv0, msg, 4000);
5934
	sprintf (akt->msg, "ERROR TYPE %s - %d: %s", et, num, hv0);
6076
	sprintf(akt->msg, "ERROR TYPE %s - %d: %s", et, num, hv0);
5935
}
6077
}
5936
 
6078
 
5937
void destroyErrors()
6079
void destroyErrors()
5938
{
6080
{
5939
ERRMSG *akt;
6081
	ERRMSG *akt;
5940
 
6082
 
5941
	if (!firstError)
6083
	if(!firstError)
5942
	   return;
6084
		return;
5943
 
6085
 
5944
	akt = firstError;
6086
	akt = firstError;
5945
 
6087
 
5946
	while (akt)
6088
	while(akt)
5947
	{
6089
	{
5948
	   firstError = akt->next;
6090
		firstError = akt->next;
5949
	   delete akt;
6091
		delete akt;
5950
	   akt = firstError;
6092
		akt = firstError;
5951
	}
6093
	}
5952
 
6094
 
5953
	firstError = 0;
6095
	firstError = 0;
5954
}
6096
}
5955
 
6097
 
5956
QString catGDALError()
6098
QString catGDALError()
5957
{
6099
{
5958
QString err;
6100
	QString err;
5959
ERRMSG *akt = firstError;
6101
	ERRMSG *akt = firstError;
5960
 
6102
 
5961
	while (akt)
6103
	while(akt)
5962
	{
6104
	{
5963
	   err += QString(akt->msg) + "\n";
6105
		err += QString(akt->msg) + "\n";
5964
	   akt = akt->next;
6106
		akt = akt->next;
5965
	}
6107
	}
5966
 
6108
 
5967
	destroyErrors();
6109
	destroyErrors();
5968
	return err;
6110
	return err;
5969
}
6111
}