1 /****************************************************************************
3 ** Copyright (C) 2011 Tito Eritja Real <jtitoo@gmail.com>
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
7 ** the Free Software Foundation, either version 3 of the License, or
8 ** (at your option) any later version.
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program. If not, see <http://www.gnu.org/licenses/>.
18 ****************************************************************************/
20 #include "loadTracksWindow.h"
21 #include "ui_loadtracksWindow.h"
23 #include "windowMap.h"
26 #include <QFileDialog>
27 #include <QColorDialog>
28 #include <QMessageBox>
29 #include <QCloseEvent>
31 LoadTracksWindow::LoadTracksWindow(WindowMap *parent, Settings* settings_p, Log *log) :
32 QDialog(parent), log(log),windowMap(parent),settings(settings_p),
33 ui(new Ui::LoadTracksWindow)
36 currentDir.setPath(APPLICATION_PATH);
38 setWindowTitle(tr("Load track"));
39 QColor color = QColor(settings->getTrackToSniffColor());
40 ui->colorLabel->setText(color.name());
41 ui->colorLabel->setPalette(QPalette(color));
42 ui->colorLabel->setAutoFillBackground(true);
44 // Centering MapType items
45 QAbstractItemView *viewMaps = ui->mapsType->view();
46 QAbstractItemModel *modelMaps = viewMaps->model();
48 for(int i=0; i < ui->mapsType->count();i++){
49 modelMaps->setData(modelMaps->index(i, 0), QVariant(Qt::AlignCenter), Qt::TextAlignmentRole);
52 connect(ui->colorButton, SIGNAL(clicked()), this, SLOT(setColor()));
53 connect(ui->browseButton, SIGNAL(clicked()), SLOT(browse()));
56 LoadTracksWindow::~LoadTracksWindow()
61 void LoadTracksWindow::setColor(){
64 QColor color = QColorDialog::getColor(QColor(settings->getTrackToSniffColor()), this);
67 ui->colorLabel->setText(color.name());
68 ui->colorLabel->setPalette(QPalette(color));
69 ui->colorLabel->setAutoFillBackground(true);
70 settings->setTrackToSniffColor(color.name());
74 void LoadTracksWindow::browse(){
76 QString directory = QFileDialog::getOpenFileName(this,tr("Open XML Files"), currentDir.path(), tr("XML Files (*.gpx *.tcx)"));
78 if (!directory.isNull())
80 currentDir.setPath(directory);
82 if (!directory.isEmpty()) {
83 if (ui->fileCombo->findText(directory) == -1)
84 ui->fileCombo->addItem(directory);
85 ui->fileCombo->setCurrentIndex(ui->fileCombo->findText(directory));
92 void LoadTracksWindow::closeEvent(QCloseEvent *event){
95 log->debug("CLOSE EVENT OF LOADTRACKS!!!!!!!!!!!!!!!!!!!");
96 QMessageBox::warning(this, tr("GPSSniffer"),QString(tr("No file selected!")));
100 this->parentWidget()->hide();
101 this->parentWidget()->parentWidget()->show();
105 void LoadTracksWindow::showEvent(QShowEvent *){
107 if(windowMap->getMode()==Mode_NewActivityMode){
108 // loading track in new activity
109 ui->mapsType->setCurrentIndex(settings->getMapType());
110 ui->mapsType->setEnabled(false);
114 void LoadTracksWindow::accept(){
117 QString fileName = ui->fileCombo->currentText();
118 //QString fileName=QString("/home/user/MyDocs/FitxersGPXiTCX/VallDelRiuLac.tcx");
119 //QString fileName=QString("/home/user/MyDocs/GPSSniffer/12-07-2011_09-09-16_Cycling.tcx");
121 if(!fileName.endsWith(".gpx",Qt::CaseInsensitive) && !fileName.endsWith(".tcx",Qt::CaseInsensitive) ){
122 QMessageBox::warning(this, tr("GPSSniffer"),QString(tr("No file selected!")));
124 Track* toSniff = readFromXML(fileName);
125 log->debug("XML readed without problem");
126 windowMap->setTrackToSniff(toSniff);
127 settings->setIsCache(ui->mapCacheOn->isChecked());
130 if(windowMap->getMode()==Mode_LoadTracksWindow){
131 settings->setMapType((MapType)ui->mapsType->currentIndex());
132 windowMap->startNetworking();
133 windowMap->startMaps();
136 if(windowMap->simulatingGPS()){
137 windowMap->desactivatePossitionPaint();
140 windowMap->setIsCacheEnabled(ui->mapCacheOn->isChecked());
141 windowMap->updateSummary();
142 windowMap->drawFullTrackMaps(toSniff);
143 settings->setIsConfigured(true);
144 windowMap->fixZoomButtons();