diff --git a/qgcresources.qrc b/qgcresources.qrc index 35d5469e7a51ea4d2220bb7d142a7a768c3e4067..9c9b04fa7ac3349bfca45a6612267bdbd2596fe0 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 70452387bcaf4ba9f548c766dd2f6d526b319cde..d42338f2e4fb917088e0abb23403d813e6a55531 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 9f07ce7af625d403ad339a88f17f1af51ce8856a..6b95c5192795535875943fd4227b26a345a44325 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 63c34e59c160b697ee8549ecd1e16a2fe8197b27..c831e2361187925585db3a956c3711a2bfab8aa3 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 23f04418b66550d2fe3d6c3565312c7d1b0cc327..5739c317f2a5fece161c3ed2d58792e6da0b4d36 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..30e1c50059a1f6f2afe731deaefe503c44daa68d Binary files /dev/null and b/src/FlightMap/Images/scaleLight.png differ diff --git a/src/FlightMap/Images/scale_endLight.png b/src/FlightMap/Images/scale_endLight.png new file mode 100644 index 0000000000000000000000000000000000000000..85030641188c8115dee5d2b668bfc802f0f96f96 Binary files /dev/null and b/src/FlightMap/Images/scale_endLight.png differ diff --git a/src/ui/preferences/GeneralSettings.qml b/src/ui/preferences/GeneralSettings.qml index e346a33b88d240d863f0c2528bc5119fe7dfc778..75156d38e3ae0265398150512292ca06201d08aa 100644 --- a/src/ui/preferences/GeneralSettings.qml +++ b/src/ui/preferences/GeneralSettings.qml @@ -40,7 +40,9 @@ Rectangle { anchors.fill: parent anchors.margins: ScreenTools.defaultFontPixelWidth - property Fact _percentRemainingAnnounce: QGroundControl.multiVehicleManager.disconnectedVehicle.battery.percentRemainingAnnounce + property Fact _percentRemainingAnnounce: QGroundControl.multiVehicleManager.disconnectedVehicle.battery.percentRemainingAnnounce + property real _firstLabelWidth: ScreenTools.defaultFontPixelWidth * 16 + property real _editFieldWidth: ScreenTools.defaultFontPixelWidth * 22 QGCPalette { id: qgcPal } @@ -76,16 +78,16 @@ Rectangle { spacing: ScreenTools.defaultFontPixelWidth QGCLabel { - id: distanceUnitsLabel + width: _firstLabelWidth anchors.baseline: distanceUnitsCombo.baseline text: qsTr("Distance units:") } FactComboBox { - id: distanceUnitsCombo - width: ScreenTools.defaultFontPixelWidth * 10 - fact: QGroundControl.distanceUnits - indexModel: false + id: distanceUnitsCombo + width: _editFieldWidth + fact: QGroundControl.distanceUnits + indexModel: false } QGCLabel { @@ -96,19 +98,19 @@ Rectangle { } Row { - spacing: ScreenTools.defaultFontPixelWidth + spacing: ScreenTools.defaultFontPixelWidth QGCLabel { anchors.baseline: speedUnitsCombo.baseline - width: distanceUnitsLabel.width + width: _firstLabelWidth text: qsTr("Speed units:") } FactComboBox { - id: speedUnitsCombo - width: ScreenTools.defaultFontPixelWidth * 20 - fact: QGroundControl.speedUnits - indexModel: false + id: speedUnitsCombo + width: _editFieldWidth + fact: QGroundControl.speedUnits + indexModel: false } QGCLabel { @@ -117,6 +119,17 @@ Rectangle { } } + //----------------------------------------------------------------- + //-- Scale on Flight View + QGCCheckBox { + text: qsTr("Show scale on Fly View") + onClicked: { + QGroundControl.flightMapSettings.showScaleOnFlyView = checked + } + Component.onCompleted: { + checked = QGroundControl.flightMapSettings.showScaleOnFlyView + } + } //----------------------------------------------------------------- //-- Audio preferences QGCCheckBox { @@ -211,13 +224,13 @@ Rectangle { spacing: ScreenTools.defaultFontPixelWidth QGCLabel { anchors.baseline: mapProviders.baseline - width: ScreenTools.defaultFontPixelWidth * 16 + width: _firstLabelWidth text: qsTr("Map Providers:") } QGCComboBox { - id: mapProviders - width: ScreenTools.defaultFontPixelWidth * 16 - model: QGroundControl.flightMapSettings.mapProviders + id: mapProviders + width: _editFieldWidth + model: QGroundControl.flightMapSettings.mapProviders Component.onCompleted: { var index = mapProviders.find(QGroundControl.flightMapSettings.mapProvider) if (index < 0) { @@ -241,14 +254,14 @@ Rectangle { spacing: ScreenTools.defaultFontPixelWidth QGCLabel { anchors.baseline: paletteCombo.baseline - width: ScreenTools.defaultFontPixelWidth * 16 + width: _firstLabelWidth text: qsTr("Style:") } QGCComboBox { - id: paletteCombo - width: ScreenTools.defaultFontPixelWidth * 16 - model: [ qsTr("Indoor"), qsTr("Outdoor") ] - currentIndex: QGroundControl.isDarkStyle ? 0 : 1 + id: paletteCombo + width: _editFieldWidth + model: [ qsTr("Indoor"), qsTr("Outdoor") ] + currentIndex: QGroundControl.isDarkStyle ? 0 : 1 onActivated: { if (index != -1) { currentIndex = index