⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mapinfo.cpp

📁 给予QT的qps开源最新源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*
  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 "mapinfo.h"

#include <qpopupmenu.h>
#include <unistd.h>

#include "convert.h"
#include "fetchmap.h"
#include "client.h"
#include "track.h"

MapInfoView::MapInfoView(QWidget *parent, const char *name, WFlags fl):
        QScrollView(parent,name,fl| WRepaintNoErase)
{
   xx = -1; 
   yy = -1;
   selectedMap = NULL;
   setBackgroundMode(NoBackground);
}

MapInfoView::~MapInfoView()
{
}

void MapInfoView::contentsMousePressEvent(QMouseEvent *e)
{
   xx = e->x();
   yy = e->y();
   emit mouseClick(e->x(), e->y());
   int x, y, w, h;
   viewportToContents(0, 0, x, y);
   viewportToContents(visibleWidth(), visibleHeight(), w, h);
   updateContents(x, y, w, h);
}

void MapInfoView::drawContents( QPainter *painter, int cx, int cy, int cw, int ch )
{
   if (selectedMap != 0)
   {
      QPixmap pixmap(cw, ch, 8);

      // middle point
      int mx = cx + cw/2; 
      int my = cy + ch/2;
      Position mpos;
      selectedMap->calcPos(mpos, mx, my);

      selectedMap->draw(&pixmap, mpos);

      painter->drawPixmap(cx, cy, pixmap);
      if (xx >= cx && xx < cx+cw) {
        painter->drawLine(xx,cy,xx,cy+ch);
      }
      if (yy >= cy && yy < cy+ch){
        painter->drawLine(cx,yy,cx+cw,yy);
      }
   }
}

void MapInfoView::setMap( MapBase *map )
{
   xx = -1; 
   yy = -1;
   selectedMap = map;
   if (selectedMap){
      resizeContents(selectedMap->mapSizeX, selectedMap->mapSizeY);
      setContentsPos(0, 0);
      updateContents(0, 0, selectedMap->mapSizeX, selectedMap->mapSizeY);
   }
   else{
      resizeContents(1, 1);
      setContentsPos(0, 0);
   }
}

MapInfo::MapInfo(Qpegps *appl, MapSelector *maps, QWidget *parent, const char *name, WFlags fl):
        QVBox (parent, name, fl)
{
    application = appl;
    mapSelector = maps;

    mapSelect = new QComboBox(FALSE, this);
    //mapDescGB = new QVGroupBox("Map Info", this);
    /*mapDescL = new QLabel(mapDescGB);*/
    mapView = new MapInfoView(this);
    positionInfo = new QLabel(this);
    positionInfo->setAlignment(Qt::AlignHCenter);

    QHBox *hBox;
    hBox = new QHBox(this);
    hBox->setFixedHeight(18);
    removePB = new QPushButton(tr("remove"), hBox);
    downloadPB = new QPushButton(tr("download"), hBox);
    importPB = new QPushButton(tr("import"), hBox);
    propertiesPB = new QPushButton(tr("properties"), hBox);

    connect(mapSelect , SIGNAL(activated(int)),
            SLOT(selectionChanged(int)) );
    connect(mapView, SIGNAL(mouseClick(int, int)),
            SLOT(calcPosInfo(int, int)) );
    connect( downloadPB, SIGNAL(clicked()),
             this, SLOT(startDownLoadD()));
    connect( importPB, SIGNAL(clicked()),
             this, SLOT(startImportD()));
    connect( propertiesPB, SIGNAL(clicked()),
             this, SLOT(startChangeD()));
    connect( removePB, SIGNAL(clicked()),
             this, SLOT(startRemoveD()));

    mapsIndex = -1;
    mapListChanged();
}

void MapInfo::mapListChanged()
{
    mapNames.clear();
    /*mapDescList.clear();*/
    mapSelect->clear();
    MapBase *aMap;
    for (aMap = mapSelector->first(); aMap != 0; aMap = mapSelector->next())
    {
        mapNames.append(aMap->name());
        /*mapDescList.append(aMap->getInfo());*/
         mapsIndex = 0;
    }
    mapSelect->insertStringList(mapNames);
    mapSelect->setCurrentItem(mapsIndex);
    selectionChanged(mapsIndex);
}

MapInfo::~MapInfo()
{
}

void MapInfo::selectionChanged(int index)
{
   if (index>=0 && mapSelect->count()) {
      mapsIndex = index;
      positionInfo->setText("");

      QString mapName = mapSelect->currentText();
      MapBase *aMap;
      aMap = mapSelector->at(mapsIndex);
      
      mapView->setMap(aMap);
   }
   else {
      positionInfo->setText("");
      mapView->setMap(NULL);
   }
   if (mapView->selectedMap != NULL) {
      removePB->setEnabled(TRUE);
      propertiesPB->setEnabled(TRUE);    
   }
   else {
      removePB->setEnabled(FALSE);
      propertiesPB->setEnabled(FALSE);    
   }
}

void MapInfo::calcPosInfo(int x, int y)
{
    QString posInfoStr;
    MapBase *aMap;
    aMap = mapSelector->at(mapsIndex);
//    mapPos = new Position();
    Position pos;
    if(aMap->calcPos(pos, (double)x, (double)y))
    {
         mapPos = pos;
         posInfoStr = tr("Lat: %1, Lon: %2 (%3,%4)")
            .arg(Position::string(mapPos.lat, Position::Lat))
            .arg(Position::string(mapPos.lon, Position::Lon))
            .arg(x).arg(y);
    }
    else
        posInfoStr = "";
    positionInfo->setText(posInfoStr);
}

void MapInfo::startDownLoadD()
{
QPopupMenu *pMenu = new QPopupMenu;		/* Added by A. Karkhov */
   Position pos;
    pos.lon = mapPos.lon;
    pos.lat = mapPos.lat;

    if ((pos.lon == 0) && (pos.lat == 0)) {
        // use current location from GPS
        pos.lon = application->gpsd->gpsData.fix.position.lon;
        pos.lat  = application->gpsd->gpsData.fix.position.lat;
    }
DownLoadDialog dlDialog(pos, mapSelector, this, "download map", TRUE, 0);
DownloadAreaSpecification *spec;
   pos.lon = mapPos.lon;
   pos.lat = mapPos.lat;
   if ((pos.lon == 0) && (pos.lat == 0)) {
     // use current location from GPS
     pos.lon = application->gpsd->gpsData.fix.position.lon;
     pos.lat  = application->gpsd->gpsData.fix.position.lat;
   }
spec = new DownloadAreaSpecification(pos); // pass the current gps data in here for suggested lat,long,name!
DownLoadAreaDialog dlDialog1(application, spec, this, "download maps", TRUE, 0);
QString	as("downmap");
	pMenu->insertItem("Download few maps cover area from expedia.",0,0);
	pMenu->insertItem("Download few maps cover area from multimap.",1,1);
	pMenu->insertItem("Download single map from configurable source.",2,2);
	pMenu->setCheckable(FALSE);
	pMenu->popup(QPoint(16,150));
	pMenu->setActiveItem(0);
	switch ( pMenu->exec() )
	{
	case 2:	// Standard dialog
		dlDialog.setCaption(tr("Download Map"));
		dlDialog.exec();
		if(dlDialog.result()==QDialog::Accepted)
		{
			mapSelector->writeMapFile();
	        mapListChanged();
		}
	break;
	case 1:
	as+="_m";
	case 0:
	default:
	dlDialog1.setCaption(tr("Download Maps"));
		bool valid=0;
	do {
		this->mapPos.lon = this->mapPos.lat=0;
		dlDialog1.exec();
		if(dlDialog1.result()==QDialog::Accepted)
		{
		valid=1;
		if (spec->dir.length()>=140)
		{ QMessageBox mb( tr("Map Download"), tr("Downloag directory path too long. You must specify another path."), QMessageBox::Warning, QMessageBox::Ok | QMessageBox::Default, QMessageBox::NoButton, QMessageBox::NoButton );
 		       mb.exec();
        		mb.hide();
		        valid = 0;
		}
		if (spec->scale<1000)
		{ QMessageBox mb( tr("Map Download"), tr("Scale not walid. You must specify another scale."), QMessageBox::Warning, QMessageBox::Ok | QMessageBox::Default, QMessageBox::NoButton, QMessageBox::NoButton );
 		       mb.exec();
        		mb.hide();
		        valid = 0;
		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -