?? fetchmap.cpp
字號:
/*
qpegps is a program for displaying a map centered at the current longitude/
latitude as read from a gps receiver.
Copyright (C) 2002 Ralf Haselmeier <Ralf.Haselmeier@gmx.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "fetchmap.h"
#include "mapdisp.h"
MapSource::MapSource(QString *sourceInfo)
{
QTextIStream *sourceIStream;
sourceIStream = new QTextIStream (sourceInfo);
*sourceIStream >> name >> pixelWidth >> pixelHeight >> url;
}
MapSource::MapSource(QString lname, int pWidth, int pHeight, QString lurl)
{
name = lname;
pixelWidth = pWidth;
pixelHeight = pHeight;
url = lurl;
}
MapSource::~MapSource(){};
int MapSource::operator<(MapSource& source)
{
return (this->name < source.name);
}
int MapSource::operator==(MapSource& source)
{
return (this->name == source.name);
}
int MapSource::operator>(MapSource& source)
{
return (this->name > source.name);
}
QString MapSource::makeURLString(DownloadSpecification *spec)
{
QString urlstr = url;
QString string;
const QString lon = "<LON>";
const QString lat = "<LAT>";
const QString sca = "<SCA>";
const QString lonVal = string.setNum(spec->longitude * spec->lonHem);
const QString latVal = string.setNum(spec->latitude * spec->latHem);
const QString scaVal = string.setNum(spec->scale);
urlstr.replace(lon, lonVal);
urlstr.replace(lat, latVal);
urlstr.replace(sca, scaVal);
return urlstr;
}
MapSourceFile::MapSourceFile(QString mapSourceFilename)
{
filename = mapSourceFilename;
}
MapSourceFile::~MapSourceFile(){};
MapSourceList* MapSourceFile::makeMapSourceList()
{
MapSourceList *mapSourceList;
mapSourceList = new MapSourceList();
QFile sourceFile(filename);
int ok = sourceFile.open(IO_ReadOnly);
if ( ok )
{
MapSource *ms;
QString line;
QTextStream t( &sourceFile );
mapSourceList->setAutoDelete(TRUE);
while ( !t.eof() )
{
line = t.readLine().stripWhiteSpace();
if (line.length() > 0) {
if (line[0] != '#') {
ms = new MapSource(&line);
mapSourceList->append(ms);
}
}
}
}
return mapSourceList;
}
void MapSourceFile::write(MapSourceList *)
{
//write the sources to the file
}
MapSourceWidget::MapSourceWidget(QWidget *parent, const char *name)
: QVBox(parent,name)
{
sourceGB = new QVGroupBox(tr("Map Source"), this);
sourceCB = new QComboBox(sourceGB);
urlL = new QLabel(tr("URL:"),sourceGB);
urlMLE = new QMultiLineEdit(sourceGB);
urlMLE->setWordWrap(QMultiLineEdit::WidgetWidth);
urlMLE->setWrapPolicy(QMultiLineEdit::Anywhere);
urlMLE->setReadOnly(TRUE);
//QHBox *hBox;
//hBox = new QHBox(sourceGB);
//sourceDeletePB = new QPushButton("delete",hBox);
//sourceEditPB = new QPushButton("edit...",hBox);
//sourceAddPB = new QPushButton("add...",hBox);
connect(sourceCB,SIGNAL(highlighted(int)),SLOT(sourceChanged(int)));
//connect(sourceDeletePB,SIGNAL(clicked()),SLOT(remove()));
//connect(sourceEditPB,SIGNAL(clicked()),SLOT(edit()));
//connect(sourceAddPB,SIGNAL(clicked()),SLOT(add()));
}
MapSourceWidget::~MapSourceWidget(){};
void MapSourceWidget::setMapSourceList(MapSourceList *mapSourceList)
{
_mapSourceList = mapSourceList;
for (MapSource *source=_mapSourceList->first(); source!=0; source=_mapSourceList->next()) {
sourceCB->insertItem(source->name);
}
if (_mapSourceList->count() > 0)
urlMLE->setText(_mapSourceList->first()->url);
}
int MapSourceWidget::getSourceIndex()
{
return sourceCB->currentItem();
}
void MapSourceWidget::sourceChanged(int index)
{
urlMLE->setText(_mapSourceList->at(index)->url);
}
void MapSourceWidget::remove()
{
qDebug(tr("delete clicked"));
}
void MapSourceWidget::edit()
{
MapSourceEditorDialog msDialog(this, "edit map source", TRUE, 0);
msDialog.setCaption(tr("Edit"));
msDialog.exec();
if(msDialog.result()==QDialog::Accepted)
{
}
}
void MapSourceWidget::add()
{
MapSourceEditorDialog msDialog(this, "add map source", TRUE, 0);
msDialog.setCaption(tr("Add"));
msDialog.exec();
if(msDialog.result()==QDialog::Accepted)
{
}
}
MapSourceEditorDialog::MapSourceEditorDialog(QWidget *parent, const char *name,
bool modal,WFlags f) :
QDialog(parent,name,modal,f)
{
resize(parent->geometry().size());
mapSrcEditW = new MapSourceEditorWidget(this);
}
MapSourceEditorDialog::~MapSourceEditorDialog(){};
MapSourceEditorWidget::MapSourceEditorWidget( QWidget *parent, const char *name )
: QVBox(parent,name)
{
QHBox *hBox;
QVBox *vBox;
resize(parent->geometry().size());
vBox = new QVBox(this);
sourceGB = new QVGroupBox(tr("Download Source Information"),vBox);
hBox = new QHBox(sourceGB);
nameL = new QLabel(tr("name:"),hBox);
nameLE = new QLineEdit(hBox);
urlL = new QLabel(tr("URL:"),sourceGB);
urlMLE = new QMultiLineEdit(sourceGB);
urlMLE->setWordWrap(QMultiLineEdit::WidgetWidth);
urlMLE->setWrapPolicy(QMultiLineEdit::Anywhere);
hBox = new QHBox(sourceGB);
mapLatLonL = new QLabel(tr("<LAT>,<LON> specify map:"),hBox);
mapLatLonCB = new QComboBox(hBox);
mapLatLonCB->insertItem(tr("Center"));
mapLatLonCB->insertItem(tr("Lower Left"));
mapLatLonCB->insertItem(tr("Upper Left"));
mapLatLonCB->insertItem(tr("Lower Right"));
mapLatLonCB->insertItem(tr("Upper Right"));
gifGB = new QVGroupBox(tr("GIF Conversion"),this);
gifL = new QLabel(tr("GIF maps must be converted to PNG"),gifGB);
gifCB = new QCheckBox(tr("Downloaded maps are in GIF format"),gifGB);
optimizeCB = new QCheckBox(tr("Optimize converted PNGs"),gifGB);
}
MapSourceEditorWidget::MapSourceEditorWidget( MapSource *, QWidget *parent,
const char *name ) : QVBox(parent,name)
{
MapSourceEditorWidget();
}
MapSourceEditorWidget::~MapSourceEditorWidget(){};
DownloadSpecification::DownloadSpecification(Position &pos, MapSelector *maps)
{
mapSelector = maps;
longitude = pos.lon;
latitude = pos.lat;
// default to current position from map info page
/* longitude = mapInfo->mapPos.lon;
latitude = mapInfo->mapPos.lat;
if ((longitude == 0) && (latitude == 0)) {
// use current location from GPS
longitude = gpsData->gpsdData.fix.position.lon;
latitude = gpsData->gpsdData.fix.position.lat;
}*/
scale = 100000;
}
DownloadSpecification::~DownloadSpecification(){};
void DownloadSpecification::download(MapSource *mapSource)
{
QString fullPath = mapSelector->mapPathStr() + "/" + name;
QString urlStr = mapSource->makeURLString(this);
// --quick and dirty implemtation with wget for now - this will be replaced with a fully Qt solution
// with a progress bar and everything
#if 0 // PROXY
if(!gpsData->proxyUrl.isEmpty())
system("export http_proxy=" + gpsData->proxyUrl + "; wget -O " + fullPath + ".gif \"" + urlStr + "\"");
else
#endif
system("wget -O " + fullPath + ".gif \"" + urlStr + "\"");
// not in Qtopia 1.5 :-(
//ServiceRequest srv("WebAccess", "getURL(QString,QString)");
//srv << urlStr << fullPath;
//if(!srv.send())
//qWarning("service getURL not available");
// we're assuming we're downloading a gif for now. this should be configurable in the MapSource
// Qt/E comes compiled w/o gif support by default for licensing reasons - i think allowing users
// to install a gif2png ipk if they want to use this feature might be a good option
system("gif2png -O -d " + fullPath + ".gif");
QString str = name +".png "+ str.setNum(scale) +" "+
str.setNum(mapSource->pixelWidth) +" "+ str.setNum(mapSource->pixelHeight) +" "+
str.setNum(latitude*latHem) +" "+ str.setNum(longitude*lonHem);
QString nosub = "";
MapFritz * mapFritz = new MapFritz(str, nosub);
mapSelector->addMap(mapFritz);
}
DownloadSpecificationWidget::DownloadSpecificationWidget(DownloadSpecification *spec, QWidget *parent, const char *name)
: QVBox(parent,name)
{
QHBox *hBox;
detailsGB = new QVGroupBox(tr("Download"), this);
hBox = new QHBox(detailsGB);
nameL = new QLabel(tr("map name:"),hBox);
nameLE = new QLineEdit(hBox);
hBox = new QHBox(detailsGB);
latitudeL = new QLabel(tr("latitude:"),hBox);
latitudeLE = new QLineEdit(hBox);
latitudeLE->setValidator(new QDoubleValidator(-1000,1000,10,latitudeLE));
latitudeCB = new QComboBox(hBox);
latitudeCB->insertItem(tr("North"));
latitudeCB->insertItem(tr("South"));
hBox = new QHBox(detailsGB);
longitudeL = new QLabel(tr("longitude:"),hBox);
longitudeLE = new QLineEdit(hBox);
longitudeLE->setValidator(new QDoubleValidator(-1000,1000,10,longitudeLE));
longitudeCB = new QComboBox(hBox);
longitudeCB->insertItem(tr("East"));
longitudeCB->insertItem(tr("West"));
hBox = new QHBox(detailsGB);
scaleL = new QLabel(tr("scale 1:"),hBox);
scaleCB = new QComboBox(TRUE,hBox);
scaleCB->setValidator(new QIntValidator(1,100000000,scaleCB));
scaleCB->insertItem("002500");
scaleCB->insertItem("005000");
scaleCB->insertItem("007500");
scaleCB->insertItem("010000");
scaleCB->insertItem("015000");
scaleCB->insertItem("025000");
scaleCB->insertItem("050000");
scaleCB->insertItem("075000");
scaleCB->insertItem("100000");
scaleCB->insertItem("250000");
scaleCB->insertItem("500000");
//scalePB = new QPushButton( "...",hBox,"edit scales");
setDownloadSpecification(spec);
}
DownloadSpecificationWidget::~DownloadSpecificationWidget(){};
bool DownloadSpecificationWidget::validate()
{
bool valid=TRUE;
if (longitudeLE->text().stripWhiteSpace().isEmpty()) {
QMessageBox mb( tr("Map Download"),
tr("Longitude not specified.\n\nYou must specify a longitude."),
QMessageBox::Warning,
QMessageBox::Ok | QMessageBox::Default,
QMessageBox::NoButton,
QMessageBox::NoButton );
mb.exec();
mb.hide();
valid = FALSE;
} else if (latitudeLE->text().stripWhiteSpace().isEmpty()) {
QMessageBox mb( tr("Map Download"),
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -