From ffab89c94522422181264944387c825dc248e4bb Mon Sep 17 00:00:00 2001 From: dogmaphobic Date: Mon, 25 Apr 2016 21:47:49 -0400 Subject: [PATCH] Show scale on Fly View. --- qgcresources.qrc | 2 + src/FlightDisplay/FlightDisplayViewMap.qml | 1 + src/FlightMap/FlightMap.qml | 244 +++++++++++++++-------------- src/FlightMap/FlightMapSettings.cc | 25 ++- src/FlightMap/FlightMapSettings.h | 23 ++- src/FlightMap/Images/scaleLight.png | Bin 0 -> 15465 bytes src/FlightMap/Images/scale_endLight.png | Bin 0 -> 15439 bytes src/ui/preferences/GeneralSettings.qml | 55 ++++--- 8 files changed, 197 insertions(+), 153 deletions(-) create mode 100644 src/FlightMap/Images/scaleLight.png create mode 100644 src/FlightMap/Images/scale_endLight.png diff --git a/qgcresources.qrc b/qgcresources.qrc index 35d5469..9c9b04f 100644 --- a/qgcresources.qrc +++ b/qgcresources.qrc @@ -99,6 +99,8 @@ src/FlightMap/Images/rollPointerWhite.svg src/FlightMap/Images/scale.png src/FlightMap/Images/scale_end.png + src/FlightMap/Images/scaleLight.png + src/FlightMap/Images/scale_endLight.png src/FlightMap/Images/airplaneOutline.svg src/FlightMap/Images/airplaneOpaque.svg src/FlightMap/Images/ZoomPlus.svg diff --git a/src/FlightDisplay/FlightDisplayViewMap.qml b/src/FlightDisplay/FlightDisplayViewMap.qml index 7045238..d42338f 100644 --- a/src/FlightDisplay/FlightDisplayViewMap.qml +++ b/src/FlightDisplay/FlightDisplayViewMap.qml @@ -39,6 +39,7 @@ FlightMap { id: flightMap anchors.fill: parent mapName: _mapName + showScale: QGroundControl.flightMapSettings.showScaleOnFlyView property alias missionController: _missionController property var flightWidgets diff --git a/src/FlightMap/FlightMap.qml b/src/FlightMap/FlightMap.qml index 9f07ce7..6b95c51 100644 --- a/src/FlightMap/FlightMap.qml +++ b/src/FlightMap/FlightMap.qml @@ -33,6 +33,7 @@ import QtLocation 5.3 import QtPositioning 5.3 import QGroundControl 1.0 +import QGroundControl.FactSystem 1.0 import QGroundControl.Controls 1.0 import QGroundControl.FlightMap 1.0 import QGroundControl.ScreenTools 1.0 @@ -47,14 +48,59 @@ Map { property string mapType: QGroundControl.flightMapSettings.mapTypeForMapName(mapName) // property alias mapWidgets: controlWidgets property bool isSatelliteMap: mapType == "Satellite Map" || mapType == "Hybrid Map" + property bool showScale: false - readonly property real maxZoomLevel: 20 + readonly property real maxZoomLevel: 20 + property variant scaleLengths: [5, 10, 25, 50, 100, 150, 250, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000, 500000, 1000000, 2000000] + + function formatDistance(meters) + { + var dist = Math.round(meters) + if (dist > 1000 ){ + if (dist > 100000){ + dist = Math.round(dist / 1000) + } + else{ + dist = Math.round(dist / 100) + dist = dist / 10 + } + dist = dist + " km" + } + else{ + dist = dist + " m" + } + return dist + } + + function calculateScale() { + var coord1, coord2, dist, text, f + f = 0 + coord1 = _map.toCoordinate(Qt.point(0, scale.y)) + coord2 = _map.toCoordinate(Qt.point(0 + scaleImage.sourceSize.width, scale.y)) + dist = Math.round(coord1.distanceTo(coord2)) + if (dist === 0) { + // not visible + } else { + for (var i = 0; i < scaleLengths.length - 1; i++) { + if (dist < (scaleLengths[i] + scaleLengths[i+1]) / 2 ) { + f = scaleLengths[i] / dist + dist = scaleLengths[i] + break; + } + } + if (f === 0) { + f = dist / scaleLengths[i] + dist = scaleLengths[i] + } + } + text = formatDistance(dist) + scaleImage.width = (scaleImage.sourceSize.width * f) - 2 * scaleImageLeft.sourceSize.width + scaleText.text = text + } zoomLevel: 18 center: QGroundControl.lastKnownHomePosition gesture.flickDeceleration: 3000 - // This no longer exists in Qt 5.6. The options below also happen the be the default anyway. - //gesture.activeGestures: MapGestureArea.ZoomGesture | MapGestureArea.PanGesture | MapGestureArea.FlickGesture plugin: Plugin { name: "QGroundControl" } @@ -63,9 +109,9 @@ Map { Component.onCompleted: onMapTypeChanged property bool _initialMapPositionSet: false + Connections { target: mainWindow - onGcsPositionChanged: { if (!_initialMapPositionSet) { _initialMapPositionSet = true @@ -90,12 +136,83 @@ Map { anchorPoint.y: sourceItem.height / 2 visible: mainWindow.gcsPosition.isValid coordinate: mainWindow.gcsPosition - - sourceItem: MissionItemIndexLabel { + sourceItem: MissionItemIndexLabel { label: "Q" } } + onWidthChanged: { + if(_map.showScale) + scaleTimer.restart() + } + + onHeightChanged: { + if(_map.showScale) + scaleTimer.restart() + } + + onZoomLevelChanged:{ + if(_map.showScale) + scaleTimer.restart() + } + + Timer { + id: scaleTimer + interval: 100 + running: false + repeat: false + onTriggered: { + _map.calculateScale() + } + } + /* + Scale + */ + Item { + id: scale + visible: _map.showScale && scaleText.text !== "0 m" + z: _map.z + 20 + width: scaleImageLeft.width + scaleImage.width + scaleImageRight.width + anchors { + bottom: parent.bottom + bottomMargin: ScreenTools.defaultFontPixelSize * (0.66) + right: parent.right + rightMargin: ScreenTools.defaultFontPixelSize * (0.33) + } + Image { + id: scaleImageLeft + source: isSatelliteMap ? "/qmlimages/scale_end.png" : "/qmlimages/scale_endLight.png" + anchors.bottom: parent.bottom + anchors.left: parent.left + } + Image { + id: scaleImage + source: isSatelliteMap ? "/qmlimages/scale.png" : "/qmlimages/scaleLight.png" + anchors.bottom: parent.bottom + anchors.left: scaleImageLeft.right + } + Image { + id: scaleImageRight + source: isSatelliteMap ? "/qmlimages/scale_end.png" : "/qmlimages/scale_endLight.png" + anchors.bottom: parent.bottom + anchors.left: scaleImage.right + } + QGCLabel { + id: scaleText + color: isSatelliteMap ? "white" : "black" + font.weight: Font.DemiBold + horizontalAlignment: Text.AlignHCenter + anchors.bottom: parent.bottom + anchors.right: parent.right + anchors.bottomMargin: ScreenTools.defaultFontPixelSize * (0.83) + text: "0 m" + } + Component.onCompleted: { + if(_map.showScale) + _map.calculateScale(); + } + } + /********************************************* /// Map control widgets Column { @@ -174,65 +291,6 @@ Map { The slider and scale display are commented out for now to try to save real estate - DonLakeFlyer Not sure if I'll bring them back or not. Need room for waypoint list at bottom - property variant scaleLengths: [5, 10, 25, 50, 100, 150, 250, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000, 500000, 1000000, 2000000] - - function formatDistance(meters) - { - var dist = Math.round(meters) - if (dist > 1000 ){ - if (dist > 100000){ - dist = Math.round(dist / 1000) - } - else{ - dist = Math.round(dist / 100) - dist = dist / 10 - } - dist = dist + " km" - } - else{ - dist = dist + " m" - } - return dist - } - - onWidthChanged: { - scaleTimer.restart() - } - - onHeightChanged: { - scaleTimer.restart() - } - - onZoomLevelChanged:{ - scaleTimer.restart() - } - - function calculateScale() { - var coord1, coord2, dist, text, f - f = 0 - coord1 = map.toCoordinate(Qt.point(0,scale.y)) - coord2 = map.toCoordinate(Qt.point(0+scaleImage.sourceSize.width,scale.y)) - dist = Math.round(coord1.distanceTo(coord2)) - if (dist === 0) { - // not visible - } else { - for (var i = 0; i < scaleLengths.length-1; i++) { - if (dist < (scaleLengths[i] + scaleLengths[i+1]) / 2 ) { - f = scaleLengths[i] / dist - dist = scaleLengths[i] - break; - } - } - if (f === 0) { - f = dist / scaleLengths[i] - dist = scaleLengths[i] - } - } - text = formatDistance(dist) - scaleImage.width = (scaleImage.sourceSize.width * f) - 2 * scaleImageLeft.sourceSize.width - scaleText.text = text - } - QGCSlider { id: zoomSlider; minimum: map.minimumZoomLevel; @@ -256,60 +314,6 @@ Map { map.zoomLevel = value } } - - Item { - id: scale - parent: zoomSlider.parent - visible: scaleText.text !== "0 m" - z: map.z + 20 - opacity: 1 - anchors { - bottom: zoomSlider.top; - bottomMargin: ScreenTools.defaultFontPixelSize * (0.66); - left: zoomSlider.left - leftMargin: ScreenTools.defaultFontPixelSize * (0.33) - } - Image { - id: scaleImageLeft - source: "/qmlimages/scale_end.png" - anchors.bottom: parent.bottom - anchors.left: parent.left - } - Image { - id: scaleImage - source: "/qmlimages/scale.png" - anchors.bottom: parent.bottom - anchors.left: scaleImageLeft.right - } - Image { - id: scaleImageRight - source: "/qmlimages/scale_end.png" - anchors.bottom: parent.bottom - anchors.left: scaleImage.right - } - QGCLabel { - id: scaleText - color: "white" - font.weight: Font.DemiBold - horizontalAlignment: Text.AlignHCenter - anchors.bottom: parent.bottom - anchors.left: parent.left - anchors.bottomMargin: ScreenTools.defaultFontPixelSize * (0.83) - text: "0 m" - } - Component.onCompleted: { - map.calculateScale(); - } - } - - Timer { - id: scaleTimer - interval: 100 - running: false - repeat: false - onTriggered: { - map.calculateScale() - } - } */ + } // Map diff --git a/src/FlightMap/FlightMapSettings.cc b/src/FlightMap/FlightMapSettings.cc index 63c34e5..c831e23 100644 --- a/src/FlightMap/FlightMapSettings.cc +++ b/src/FlightMap/FlightMapSettings.cc @@ -26,10 +26,11 @@ #include #include -const char* FlightMapSettings::_defaultMapProvider = "Bing"; // Bing is default since it support full street/satellite/hybrid set -const char* FlightMapSettings::_settingsGroup = "FlightMapSettings"; -const char* FlightMapSettings::_mapProviderKey = "MapProvider"; -const char* FlightMapSettings::_mapTypeKey = "MapType"; +const char* FlightMapSettings::_defaultMapProvider = "Bing"; // Bing is default since it support full street/satellite/hybrid set +const char* FlightMapSettings::_settingsGroup = "FlightMapSettings"; +const char* FlightMapSettings::_mapProviderKey = "MapProvider"; +const char* FlightMapSettings::_mapTypeKey = "MapType"; +const char* FlightMapSettings::_showScaleOnFlyViewKey = "ShowScaleOnFlyView"; FlightMapSettings::FlightMapSettings(QGCApplication* app) : QGCTool(app) @@ -157,3 +158,19 @@ bool FlightMapSettings::loadBoolMapSetting (const QString &mapName, const QStrin settings.beginGroup(mapName); return settings.value(key, defaultValue).toBool(); } + +bool FlightMapSettings::showScaleOnFlyView() +{ + QSettings settings; + settings.beginGroup(_settingsGroup); + bool show = settings.value(_showScaleOnFlyViewKey, true).toBool(); + return show; +} + +void FlightMapSettings::setShowScaleOnFlyView(bool show) +{ + QSettings settings; + settings.beginGroup(_settingsGroup); + settings.setValue(_showScaleOnFlyViewKey, show); + emit showScaleOnFlyViewChanged(); +} diff --git a/src/FlightMap/FlightMapSettings.h b/src/FlightMap/FlightMapSettings.h index 23f0441..5739c31 100644 --- a/src/FlightMap/FlightMapSettings.h +++ b/src/FlightMap/FlightMapSettings.h @@ -37,13 +37,15 @@ public: FlightMapSettings(QGCApplication* app); /// mapProvider is either Bing, Google or Open to specify to set of maps available - Q_PROPERTY(QString mapProvider READ mapProvider WRITE setMapProvider NOTIFY mapProviderChanged) + Q_PROPERTY(QString mapProvider READ mapProvider WRITE setMapProvider NOTIFY mapProviderChanged) /// Map providers - Q_PROPERTY(QStringList mapProviders READ mapProviders CONSTANT) + Q_PROPERTY(QStringList mapProviders READ mapProviders CONSTANT) /// Map types associated with current map provider - Q_PROPERTY(QStringList mapTypes MEMBER _mapTypes NOTIFY mapTypesChanged) + Q_PROPERTY(QStringList mapTypes MEMBER _mapTypes NOTIFY mapTypesChanged) + + Q_PROPERTY(bool showScaleOnFlyView READ showScaleOnFlyView WRITE setShowScaleOnFlyView NOTIFY showScaleOnFlyViewChanged) Q_INVOKABLE QString mapTypeForMapName (const QString& mapName); Q_INVOKABLE void setMapTypeForMapName(const QString& mapName, const QString& mapType); @@ -63,15 +65,19 @@ public: QStringList mapProviders() { return _supportedMapProviders; } + bool showScaleOnFlyView (); + void setShowScaleOnFlyView (bool show); + signals: - void mapProviderChanged(const QString& mapProvider); - void mapTypesChanged(const QStringList& mapTypes); + void mapProviderChanged (const QString& mapProvider); + void mapTypesChanged (const QStringList& mapTypes); + void showScaleOnFlyViewChanged (); private: - void _storeSettings(void); - void _loadSettings(void); + void _storeSettings (void); + void _loadSettings (void); - void _setMapTypesForCurrentProvider(void); + void _setMapTypesForCurrentProvider(void); QString _mapProvider; ///< Current map provider QStringList _supportedMapProviders; @@ -81,6 +87,7 @@ private: static const char* _settingsGroup; static const char* _mapProviderKey; static const char* _mapTypeKey; + static const char* _showScaleOnFlyViewKey; }; #endif diff --git a/src/FlightMap/Images/scaleLight.png b/src/FlightMap/Images/scaleLight.png new file mode 100644 index 0000000000000000000000000000000000000000..30e1c50059a1f6f2afe731deaefe503c44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