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

📄 qpegps.cpp

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

#include <sys/types.h>
#include <sys/stat.h> 
#include "stdlib.h"
#include "gpsdata.h"
#include "client.h"
#include "mapdisp.h"
#include "mapinfo.h"
#include "maps.h"
#include "settings.h"
#include "fetchmap.h"
#include "route.h"
#include "gpsstatus.h"
#include "track.h"
#include "convert.h"

Qpegps::Qpegps(
      QString dir, QWidgetStack * viewer, const char * name, WFlags f)
   : QTabWidget(viewer, name, f), stackViewer(viewer),  
   lastTab(0), qpedir(dir)
{
   waitBox = new WaitBox(viewer);

   // make sure this widget is visible in viewer
   stackViewer->raiseWidget(this);

#ifndef DESKTOP
   // disable "light off" and "power off"
   QCopEnvelope e("QPE/System", "setScreenSaverMode(int)");
   e << (int)QPEApplication::Disable;
#endif
   setenv("DATUM_DATA", qpedir+"qpegps",1); //datum conversion needs env variable to the .dat files
   setenv("ELLIPSOID_DATA", qpedir+"qpegps",1); //datum conversion needs env variable to the .dat files
   geoDatum = new GeoDatum(this);
	mapSelector = new MapSelector(this);
   places = new PlaceList();
   gpsd = new Client(this);

   // create the map viewer, note must not be a child of qpegps or we can't use it in the viewer
   viewMapDisp = new MapDisp(this, mapSelector, &gpsd->gpsData, 
      stackViewer, tr("Map"));
   viewMapInfo = new MapInfo(this, mapSelector, viewer, tr("Info"));
#if 0 // Disabled until implemented
   route = new Route(gpsData, viewer);
#endif
   viewGpsStatus = new GpsStatus(this, &gpsd->gpsData, &gpsd->gpsOptions, 
      viewer, tr("GPS"));
   viewTrack = new Track(this, &viewMapDisp->placesOptions, 
      viewer, tr("Track"));

   viewSettings = new Settings(this, &viewMapDisp->mapDispOptions, 
      &viewMapDisp->placesOptions, &mapSelector->mapOptions, 
      &viewTrack->trackOptions, &geodatumOptions, viewer, tr("Config"));

   QString iconPath = qpedir + "qpegps/icons";
   QPixmap pixmap;
   pixmap.load(iconPath + "/map16x16.xpm");
   addTab(viewMapDisp, pixmap,"");//"Map");
   pixmap.load(iconPath + "/info16x16.xpm");
   addTab(viewMapInfo, pixmap, "");//"Info");
   pixmap.load(iconPath + "/config16x16.xpm");
   addTab(viewSettings, pixmap, "");//"Config");
#if 0 // Disabled until implemented
   addTab(route, tr("Route"));
#endif
   pixmap.load(iconPath + "/gps16x16.xpm");
   addTab(viewGpsStatus, pixmap, "");//"GPS");
   pixmap.load(iconPath + "/track16x16.xpm");
   addTab(viewTrack, pixmap, "");//"Track");

   connect( viewGpsStatus, SIGNAL(gpsdArgChanged()),
      gpsd, SLOT(restartGpsd()) );

   connect( this, SIGNAL(currentChanged(QWidget*)),
         SLOT(tabChanged(QWidget*)) );

   connect( gpsd, SIGNAL(updated(int)),
         SLOT(updateData(int)) );

   connect( viewSettings, SIGNAL(mapPathChanged()),
         this, SLOT(initMaps()) );

   connect( mapSelector, SIGNAL(mapsChanged()),
         viewMapInfo, SLOT(mapListChanged()) );

   connect( this, SIGNAL(configReaded()),
         viewSettings, SLOT(updateConfig()) );

   connect( this, SIGNAL(configReaded()),
         viewTrack, SLOT(updateConfig()) );

   connect( this, SIGNAL(configReaded()),
      viewGpsStatus, SLOT(updateConfig()) );
   
   connect( qApp, SIGNAL(aboutToQuit()),
         SLOT(quitInProgress()) );

   connect( viewMapDisp, SIGNAL(mouseClick(QWidget *)),
         this, SLOT(toggleFullScreen(QWidget *)) );

   connect( viewMapDisp, SIGNAL(waypointsChanged()),
      viewTrack, SLOT(updatePlaces()) );
   
   connect( viewTrack, SIGNAL(trackChanged()),
         mapSelector, SLOT(clearMapsLoaded()) );

   connect( viewTrack, SIGNAL(waypointsChanged()),
         mapSelector, SLOT(clearMapsLoaded()) );

   // read config
   viewSettings->selectConfigR(true);

   // everything is started up, ready to go
   // need info about satellites as quickly as possible
   // start sniffing for gps
//   gpsd->startGpsd();
   gpsd->startConnection();
} 

/*
void Qpegps::readPlaces()  
{
   Places *curr, *next;

   QString filename = viewTrack->trackOptions.trackPathStr;
   filename.append("/places.txt");
   QFile placesFile(filename);
	curr=places=next=(Places *)malloc(sizeof (Places));
	curr->next=NULL;
	curr->name= new QString ("none");
	curr->comment= new QString ("");

   if ( placesFile.open(IO_ReadOnly) ) {
      QTextStream t( &placesFile );
      t.setEncoding(QTextStream::UnicodeUTF8);
      QString pro;
      while ( !t.eof() ) {
         t >> pro;
	      if ( pro[0]=='#')  
            pro= t.readLine();
	      else {
	         next=(Places *)malloc(sizeof(Places));
	         curr->next=next;
	         curr=next;
	         curr->name= new QString (pro);
	         t >> pro;
	         curr->pos.lat = pro.toDouble();
	         t >> pro;
	         curr->pos.lon = pro.toDouble();
	         t >> pro;
	         curr->altitude = pro.toDouble();
	         pro = t.readLine().stripWhiteSpace();
	         curr->comment= new QString (pro);

	         if ( *curr->name==gpsData->startupPlace ) {
               gpsData->currPos.latitude=curr->pos.latitude;
			      gpsData->currPos.longitude=curr->pos.longitude; 
			      gpsData->altitude.altitude=(curr->altitude);
			   }
         }
      }
      curr->next=NULL;
      placesFile.close();
   }
}

void Qpegps::writePlaces()  
{
   Places *curr;
   int ok=0;
   bool newpl;
   QString filename = viewTrack->trackOptions.trackPathStr;
   filename.append("/places.txt");
   remove(filename+"~");
   rename(filename, filename+"~");
   
   QFile *placesFile;
   placesFile = new QFile(filename);
	if ( placesFile->exists() ) 
      newpl=FALSE;
   else 
      newpl=TRUE;
   if ( ! (placesFile->open(IO_WriteOnly)) ) { 
      while ( !QMessageBox::warning( this, "Saving places...", 
            "Can't open/create file:\n" + filename +
            "\nPlace not saved. Please check file/directory access rights.\n",
            "Try again","Ignore", 0, 0, 1 ) ) {
         ok =  placesFile->open(IO_WriteOnly);
         if (ok) 
            break;
      }
		if ( !ok ) {
         rename(filename+"~",filename); 
         return; 
      }
	}
   QTextStream t( placesFile );
	t.setEncoding(QTextStream::UnicodeUTF8);
		 
   if ( newpl ) { 
      t << "#format is: <Name> <latitude (fload decimal)> <longitude (fload decimal)> <altitude> <comment>\r\n"; 
   }

   curr=places;
   curr=curr->next;
   while ( curr != NULL ) {
      t << (*curr->name+"\t"+tr("%1")
         .arg(curr->pos.lat,6,'f')+"\t"+tr("%1")
         .arg(curr->pos.lon,6,'f')+"\t"+tr("%1")
         .arg(curr->altitude.val,6,'f')+"\t"+*curr->comment+"\r\n");
		curr=curr->next;
   };
   placesFile->close();
   delete placesFile;
}
*/
void Qpegps::tabChanged(QWidget * tb)
{
   this->changeTab(tb, tb->name());
   if ( lastTab && (tb != lastTab) ) {
      this->changeTab(lastTab, "");
   }
   lastTab = tb;
}

void Qpegps::toggleFullScreen(QWidget * w)
{
   static QSize cachedSize;

   // make sure viewer is visible
   if ( stackViewer->isVisible() ) {
      // freeze the viewer
      stackViewer->setUpdatesEnabled(false);

      // if the current widget is already visible then switch back to main widget
      if ( w == stackViewer->visibleWidget() ) {
         // switch to normal

         // remove the widget from the viewer and add it back to the main widget
         // Note: this is neccessary because it is not possible to have a widget
         // belong to two widget-stacks
         stackViewer->removeWidget(w);

         // this is really nice, have to add the widget back to the main widget
         // which means we need to restore tab name/icon and position
         QString iconPath = qpedir + "qpegps/icons";
         if ( w == viewMapDisp ) {
            QPixmap pixmap(iconPath + "/map16x16.xpm");
            insertTab(viewMapDisp, pixmap, tr("Map"), 0);
            showPage(w);
         }

         // raise the main widget ID=0
         stackViewer->raiseWidget(0);
         stackViewer->showNormal();
         // restore the WidgetFlags !
         stackViewer->reparent(0, WStyle_Customize|WStyle_NoBorder, QPoint(0,0));
         stackViewer->showMaximized();
         stackViewer->resize(cachedSize);
      } else {
         // raise specified widget and switch to fullscreen
         cachedSize = stackViewer->size();
         if ( stackViewer->size() != qApp->desktop()->size() ) {
            stackViewer->resize(qApp->desktop()->size());
         }

         // remove the widget from the main widget
         // Note: this is necessary since a widget can not belong to two widget-stacks
         removePage(w);

         // add the widget to the viewer as fixed ID=1
         stackViewer->addWidget(w, 2);

         // make sure widget is valid
         if ( stackViewer->id(w) == 2 ) {
            stackViewer->raiseWidget(2);
            stackViewer->showFullScreen();
         }
      }

      // unfreeze the viewer
      stackViewer->setUpdatesEnabled(true);
      // gpsd->readyToConnect("SPWAVHBLDC", 500); change to rawData 07/2005

   }
   w->setFocus();
}


void Qpegps::wait(bool wait, const QString &text)
{
   static int cachedId;

   if (!text.isEmpty())
      waitBox->setText(text);

   if (wait) {
      if (stackViewer->visibleWidget() != waitBox) {
         cachedId = stackViewer->id(stackViewer->visibleWidget());
         stackViewer->raiseWidget(waitBox);
      }   
      waitBox->repaint();
   }
   else {
      if (stackViewer->visibleWidget() == waitBox) {
         stackViewer->raiseWidget(cachedId);
      }
   }   
}

void Qpegps::updateData(int type)
{
   // called when GPS Data has changed
   const QWidget * const tb = currentPage();
   switch(type)
   {
   case Client::POS: // position
      // update track => new track point
      if (!viewMapDisp->mapDispOptions.mode) 
         viewTrack->update(&gpsd->gpsData);

⌨️ 快捷键说明

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