📄 mapdisp.cpp
字号:
if ( ! (e->state() && ShiftButton) ) {
currentPos.lat -= 0.25 * (mapSelector->scale() / 592500);
app->adjustDatum(currentPos, currentAltitude);
update();
} else {
emit lessDetail();
update();
}
break;
case Qt::Key_Right:
if ( !(e->state() && ShiftButton) ) {
currentPos.lon += (mapSelector->scale() / 592500) * 0.3
/ fabs(cos(deg2rad(currentPos.lat)));
app->adjustDatum(currentPos, currentAltitude);
update();
} else {
emit lessDetail();
update();
}
break;
case Qt::Key_Up:
if ( !(e->state() && ShiftButton) ) {
currentPos.lat += 0.25*(mapSelector->scale()/592500);
app->adjustDatum(currentPos, currentAltitude);
update();
}
else {
emit moreDetail();
update();
}
break;
case Qt::Key_Left:
if ( ! (e->state() && ShiftButton) ) {
currentPos.lon-=(mapSelector->scale()/592500)*0.3
/ fabs(cos(deg2rad(currentPos.lat)));
app->adjustDatum(currentPos, currentAltitude);
update();
}
else {
emit moreDetail();
update();
}
break;
case Qt::Key_Backspace:
if( inAnimation ) {
inAnimation = false;
aniTimer->stop();
delete aniTS;
aniFile->close();
delete aniFile;
}
swichMode();
break;
default:
e->ignore();
break;
}
} else {
switch( e->key() ) {
case Qt::Key_F33:
case Qt::Key_Space: // Select
case Qt::Key_Escape: // Select
emit mouseClick(this);
break;
case Qt::Key_Return:
if ( ! (e->state() && ShiftButton) ) {
// cursor at center of screen
ContextMenuGps(QPoint(mapdisp->width() / 2,
mapdisp->height() / 2));
}
else
MapDispAddPos(currentPos, currentAltitude.val);
break;
case Qt::Key_Down:
case Qt::Key_Right:
emit lessDetail();
update();
break;
case Qt::Key_Up:
case Qt::Key_Left:
emit moreDetail();
update();
break;
// case Qt::Key_Left:
// emit debugMaps(); // only for debugging, don't forget to remove !!!!
// break;
case Qt::Key_Backspace:
swichMode();
break;
default:
e->ignore();
break;
}
}
}
void MapDisp::animateTrack()
{
if ( inAnimation )
{
currentPos.lat = aniNextLatitude;
currentPos.lon = aniNextLongitude;
currentAltitude.val = aniNextAltitude;
aniTime = aniNextTime;
update();
}
// read latitude
aniNextLatitude = 99999999;
aniTS->skipWhiteSpace ();
*aniTS >> aniNextLatitude;
if (!aniTS->atEnd() && aniNextLatitude != 99999999 ) {
// read longitude
aniNextLongitude = 99999999;
aniTS->skipWhiteSpace ();
*aniTS >> aniNextLongitude;
if (!aniTS->atEnd() && aniNextLongitude != 99999999 ) {
// read altitude
aniNextAltitude = 99999999;
aniTS->skipWhiteSpace ();
*aniTS >> aniNextAltitude;
if ( !aniTS->atEnd() && aniNextAltitude != 99999999 ) {
// read time
aniTS->skipWhiteSpace ();
QString strTime;
*aniTS >> strTime;
int iH = strTime.find(':');
int iM = strTime.find(':', iH+1);
if (iH != -1 || iM != -1) {
strTime[iH] = strTime[iM] = ' ';
int timeTemp = strTime.left(iH).toInt();
aniNextTime = (timeTemp+aniTimeZone)*60*60*1000;
//strTime[0] = strTime[3];
//strTime[1] = strTime[4];
timeTemp = strTime.mid(iH,iM-iH).toInt();
aniNextTime = aniNextTime + timeTemp*60*1000;
//ts[0]=ts[6]; ts[1]=ts[7];
timeTemp = strTime.mid(iM, strTime.length()-iM).toInt();
aniNextTime = aniNextTime + timeTemp*1000;
if ( inAnimation ) {
if ( aniNextTime < 0 ) {
aniNextTime = aniTime + (app->viewTrack->trackOptions.updt_freq*1000);
}
timeTemp = int((aniNextTime - aniTime)/aniAccelerator);
if ( (timeTemp < 0) || ((timeTemp > 60000) && aniShortcutTime) )
aniTimer->start(5000, true);
else
aniTimer->start( timeTemp, true );
} else {
inAnimation = true;
aniTimer->start( 50, true );
}
// end iteration, continue after timer
return;
}
}
}
}
// error reading data or end of file: finish animation
inAnimation = false;
delete aniTS;
aniFile->close();
delete aniFile;
app->adjustDatum(currentPos, currentAltitude);
update();
return;
}
void MapDisp::MapDispAddPos(const Position & pos, double altitude)
{
MapPlaceEditorDialog pDialog(this, "Saving Places", TRUE, 0);
pDialog.setCaption(tr("Saving Place"));
if (pDialog.exec()!=0 ) {
Place *place = new Place();;
QString tempStr;
if ( pDialog.NameLEd->text().length() == 0 ) {
tempStr = QString (tr("p%1").arg(time(NULL),0,16));
}
else
tempStr = (pDialog.NameLEd->text());
tempStr = tempStr.stripWhiteSpace();
tempStr = tempStr.simplifyWhiteSpace();
tempStr.truncate(30);
tempStr.replace( QRegExp("\40+"),"_");
place->name = tempStr;
place->pos.lat = pos.lat;
place->pos.lon = pos.lon;
place->altitude.val = altitude; // Save Altitude
tempStr = QString (pDialog.CommentLEd->text());
tempStr = tempStr.stripWhiteSpace();
tempStr = tempStr.simplifyWhiteSpace();
place->comment = tempStr + " :: "+ QDateTime::currentDateTime().toString();
places->append(place);
places->sort();
places->writePlaces(app->viewTrack->trackOptions.trackPathStr + "/places.txt");
// if (placesOptions.showPlaces)
emit waypointsChanged();
}
}
QString MapDisp::timeToString()
{
if ( gpsData->avspeed.val > 0 ) {
ttwph = wpDistance.val / gpsData->avspeed.val;
ttwpm = (ttwph - floor(ttwph)) * 60.0;
ttwph = floor(ttwph);
ttwps = floor((ttwpm - floor(ttwpm)) * 60.0);
ttwpm = floor(ttwpm);
}
if ( mapDispOptions.showTime ) {
return tr("%1:%2:%3").arg(ttwph, 2, 'f', 0)
.arg(ttwpm, 2, 'f', 0).arg(ttwps, 2, 'f', 0);
} else {
return tr("");
}
}
void MapDisp::ContextMenuGps(const QPoint &pos)
{
QPopupMenu * pMenu = new QPopupMenu;
pMenu->insertItem("Save Place/Waypoint", 0, 0);
if (!mapSelector->isMap())
pMenu->setItemEnabled(0, false);
pMenu->insertItem("Set/Clear Destination", 1, 1);
pMenu->insertItem("Change View", 2, 2);
pMenu->insertItem("Switch to Map mode", 3, 3);
pMenu->setCheckable(false);
if (mapDispOptions.zoom2x)
pMenu->insertItem("Disable zoom 2x", 4, 4);
else
pMenu->insertItem("Enable zoom 2x", 4, 4);
pMenu->popup(mapToGlobal(pos));
// pMenu->setActiveItem(0);
switch ( pMenu->exec() ) {
case 0: // Save Place/Waypoint
{
QPoint mapPos = screenToMap(pos);
Position placePos;
if (mapSelector->isMap() &&
mapSelector->currentMap()->calcPos(placePos,
mapPos.x(), mapPos.y()))
MapDispAddPos(placePos, currentAltitude.val);
}
break;
case 1: // Set/Clear Destination
{
MapCoordEditorDialog mDialog(places, this,
"edit map coord", true, 0);
mDialog.setCaption(tr("Set/Clear Destination"));
if ( mDialog.exec() != 0 ) {
ManualWp = true;
dest = mDialog.getPosition();
// currentAltitude.val = mDialog->getAltitude();
//printf("Long=%e Lat=%e\n",gpsData->currPos.lon,gpsData->currPos.lat);
} else {
dest.lat = dest.lon = 0;
ManualWp = false;
}
app->adjustDatum(dest, currentAltitude);
update();
}
break;
case 2: //"Change View"
emit mouseClick(this);
break;
case 3:
swichMode();
break;
case 4: // Toggle zoom 2x
mapDispOptions.zoom2x = !mapDispOptions.zoom2x;
app->writeConfig();
// redraw maps
mapSelector->clearMapsLoaded();
break;
default:
break;
}
}
void MapDisp::ContextMenuManual(const QPoint &pos)
{
QPopupMenu * pMenu = new QPopupMenu;
pMenu->insertItem("Go to Place/Waypoint", 0, 0);
pMenu->insertItem("Save Place/Waypoint", 1, 1);
pMenu->insertItem("Change View", 2, 2);
if ( inAnimation )
pMenu->insertItem("Stop track animation", 3, 3);
else
pMenu->insertItem("Animate track", 3, 3);
pMenu->insertItem("Switch to GPS mode", 4, 4);
pMenu->insertItem("More detailed map (Shift+Up)", 5, 5);
pMenu->insertItem("Less detailed map (Shift+Down)", 6, 6);
if (!mapSelector->isMap()){
pMenu->setItemEnabled(1, false);
pMenu->setItemEnabled(5, false);
pMenu->setItemEnabled(6, false);
} else {
if (!mapSelector->canMoreDetail())
pMenu->setItemEnabled(5, false);
if (!mapSelector->canLessDetail())
pMenu->setItemEnabled(6, false);
}
if (mapDispOptions.zoom2x)
pMenu->insertItem("Disable zoom 2x", 7, 7);
else
pMenu->insertItem("Enable zoom 2x", 7, 7);
pMenu->setCheckable(false);
pMenu->popup(mapToGlobal(pos));
// pMenu->setActiveItem(0);
switch ( pMenu->exec() ) {
case 0: // Go to Place/Waypoint
{
MapCoordEditorDialog mDialog(places, this,
"edit map coord", true, 0);
mDialog.setCaption(tr("Place Coordinates"));
if ( mDialog.exec() != 0 ) {
currentPos = mDialog.getPosition();
currentAltitude.val = mDialog.getAltitude();
}
//printf("Long=%e Lat=%e\n",gpsData->currPos.lon,gpsData->currPos.lat);
// }
app->adjustDatum(currentPos, currentAltitude);
update();
}
break;
case 1: // Save Place/Waypoint
{
QPoint mapPos = screenToMap(pos);
Position placePos;
if (mapSelector->isMap() &&
mapSelector->currentMap()->calcPos(placePos,
mapPos.x(), mapPos.y()))
MapDispAddPos(placePos, currentAltitude.val);
}
break;
case 2: // "Change View"
emit mouseClick(this);
break;
case 3: // Animate track
if ( !inAnimation ) {
AnimateParamsDialog aDialog(app->viewTrack->trackOptions.trackPathStr,
this, "Animate track", true, 0);
aDialog.setCaption(tr("Animation"));
if ( aDialog.exec()!=0 ) {
aniAccelerator = aDialog.AccelLEd->text().toDouble();
aniTimeZone = aDialog.TZLEd->text().toInt();
aniShortcutTime = aDialog.scTimeTB->isOn();
aniFile = new QFile (app->viewTrack->trackOptions.trackPathStr+"/" +
aDialog.trackFileCB->currentText());
if ( aniFile->open(IO_ReadOnly) ) {
aniTS = new QTextStream( aniFile );
aniTimer->start(50,TRUE);
}
else {
// error message
}
}
} else {
inAnimation = false;
aniTimer->stop();
delete aniTS;
aniFile->close();
delete aniFile;
break;
}
break;
case 4:
swichMode();
break;
case 5: //"More detailed map (<shift> + Up)"
emit moreDetail();
update();
break;
case 6: //Less detailed map (<shift> + Down)"
emit lessDetail();
update();
break;
case 7: // Toggle zoom 2x
mapDispOptions.zoom2x = !mapDispOptions.zoom2x;
app->writeConfig();
update();
break;
}
delete pMenu;
}
QPoint MapDisp::screenToMap( const QPoint &screenPos )
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -