diff --git a/ground/openpilotgcs/share/openpilotgcs/pfd/default/AltitudeScale.qml b/ground/openpilotgcs/share/openpilotgcs/pfd/default/AltitudeScale.qml index 6e5b608f7..ff85ffc74 100644 --- a/ground/openpilotgcs/share/openpilotgcs/pfd/default/AltitudeScale.qml +++ b/ground/openpilotgcs/share/openpilotgcs/pfd/default/AltitudeScale.qml @@ -2,12 +2,12 @@ import Qt 4.7 Item { id: sceneItem - property variant sourceSize + property variant sceneSize - Image { + SvgElementImage { id: altitude_bg - source: "image://svg/pfd.svg!altitude-bg" - sourceSize: sceneItem.sourceSize + elementName: "altitude-bg" + sceneSize: sceneItem.sceneSize clip: true property variant scaledBounds: svgRenderer.scaledElementBounds("pfd.svg", "altitude-bg") @@ -17,11 +17,11 @@ Item { width: scaledBounds.width * sceneItem.width height: scaledBounds.height * sceneItem.height - Image { + SvgElementImage { id: altitude_scale - source: "image://svg/pfd.svg!altitude-scale" - sourceSize: sceneItem.sourceSize + elementName: "altitude-scale" + sceneSize: sceneItem.sceneSize anchors.verticalCenter: parent.verticalCenter // The altitude scale represents 30 meters, @@ -55,12 +55,12 @@ Item { } - Image { + SvgElementImage { id: altitude_window clip: true - source: "image://svg/pfd.svg!altitude-window" - sourceSize: sceneItem.sourceSize + elementName: "altitude-window" + sceneSize: sceneItem.sceneSize property variant scaledBounds: svgRenderer.scaledElementBounds("pfd.svg", "altitude-window") diff --git a/ground/openpilotgcs/share/openpilotgcs/pfd/default/Pfd.qml b/ground/openpilotgcs/share/openpilotgcs/pfd/default/Pfd.qml index 0827b7d30..77f4e3f7d 100644 --- a/ground/openpilotgcs/share/openpilotgcs/pfd/default/Pfd.qml +++ b/ground/openpilotgcs/share/openpilotgcs/pfd/default/Pfd.qml @@ -4,15 +4,13 @@ import "." Rectangle { color: "#666666" - Image { + SvgElementImage { id: background - source: "image://svg/pfd.svg!background" - + elementName: "background" fillMode: Image.PreserveAspectFit anchors.fill: parent - sourceSize.width: width - sourceSize.height: height + sceneSize: Qt.size(width, height) Item { id: sceneItem @@ -27,10 +25,11 @@ Rectangle { source: qmlWidget.terrainEnabled ? "PfdTerrainView.qml" : "PfdWorldView.qml" } - Image { + SvgElementImage { id: rollscale - source: "image://svg/pfd.svg!rollscale" - sourceSize: background.sourceSize + elementName: "rollscale" + sceneSize: background.sceneSize + smooth: true anchors.centerIn: parent //rotate it around the center of scene @@ -41,26 +40,28 @@ Rectangle { } } - Image { + SvgElementImage { id: foreground - source: "image://svg/pfd.svg!foreground" - sourceSize: background.sourceSize + elementName: "foreground" + sceneSize: background.sceneSize + anchors.centerIn: parent } - Image { + SvgElementImage { id: compass - source: "image://svg/pfd.svg!compass" - sourceSize: background.sourceSize + elementName: "compass" + sceneSize: background.sceneSize + clip: true y: 12 anchors.horizontalCenter: parent.horizontalCenter - Image { + SvgElementImage { id: compass_band - source: "image://svg/pfd.svg!compass-band" - sourceSize: background.sourceSize + elementName: "compass-band" + sceneSize: background.sceneSize anchors.centerIn: parent //the band is 540 degrees wide, AttitudeActual.Yaw is converted to -180..180 range @@ -70,22 +71,22 @@ Rectangle { SpeedScale { anchors.fill: parent - sourceSize: background.sourceSize + sceneSize: background.sceneSize } AltitudeScale { anchors.fill: parent - sourceSize: background.sourceSize + sceneSize: background.sourceSize } VsiScale { anchors.fill: parent - sourceSize: background.sourceSize + sceneSize: background.sourceSize } PfdIndicators { anchors.fill: parent - sourceSize: background.sourceSize + sceneSize: background.sourceSize } } } diff --git a/ground/openpilotgcs/share/openpilotgcs/pfd/default/PfdIndicators.qml b/ground/openpilotgcs/share/openpilotgcs/pfd/default/PfdIndicators.qml index d520dcf00..e71e75dda 100644 --- a/ground/openpilotgcs/share/openpilotgcs/pfd/default/PfdIndicators.qml +++ b/ground/openpilotgcs/share/openpilotgcs/pfd/default/PfdIndicators.qml @@ -2,17 +2,17 @@ import Qt 4.7 Item { id: sceneItem - property variant sourceSize + property variant sceneSize //telemetry status arrow - Image { + SvgElementImage { id: telemetry_status - source: "image://svg/pfd.svg!gcstelemetry-"+statusName - sourceSize: sceneItem.sourceSize + elementName: "gcstelemetry-"+statusName + sceneSize: sceneItem.sceneSize property string statusName : ["Disconnected","HandshakeReq","HandshakeAck","Connected"][GCSTelemetryStats.Status] - property variant scaledBounds: svgRenderer.scaledElementBounds("pfd.svg", "gcstelemetry-Disconnected") + scaledBounds: svgRenderer.scaledElementBounds("pfd.svg", "gcstelemetry-Disconnected") x: scaledBounds.x * sceneItem.width y: scaledBounds.y * sceneItem.height width: scaledBounds.width * sceneItem.width diff --git a/ground/openpilotgcs/share/openpilotgcs/pfd/default/PfdWorldView.qml b/ground/openpilotgcs/share/openpilotgcs/pfd/default/PfdWorldView.qml index 9e4a02b3b..9c658afdb 100644 --- a/ground/openpilotgcs/share/openpilotgcs/pfd/default/PfdWorldView.qml +++ b/ground/openpilotgcs/share/openpilotgcs/pfd/default/PfdWorldView.qml @@ -1,15 +1,13 @@ import Qt 4.7 Item { - //worldView should fill the source size of svg document id: worldView - Image { + SvgElementImage { id: world - source: "image://svg/pfd.svg!world" - - sourceSize.width: worldView.width - sourceSize.height: worldView.height + elementName: "world" + //worldView is loaded with Loader, so background element is visible + sceneSize: background.sceneSize smooth: true diff --git a/ground/openpilotgcs/share/openpilotgcs/pfd/default/SpeedScale.qml b/ground/openpilotgcs/share/openpilotgcs/pfd/default/SpeedScale.qml index ddc82b571..cb3845575 100644 --- a/ground/openpilotgcs/share/openpilotgcs/pfd/default/SpeedScale.qml +++ b/ground/openpilotgcs/share/openpilotgcs/pfd/default/SpeedScale.qml @@ -2,28 +2,26 @@ import Qt 4.7 Item { id: sceneItem - property variant sourceSize + property variant sceneSize property real groundSpeed : 3.6 * Math.sqrt(Math.pow(VelocityActual.North,2)+ Math.pow(VelocityActual.East,2)) - Image { + SvgElementImage { id: speed_bg - source: "image://svg/pfd.svg!speed-bg" - sourceSize: sceneItem.sourceSize + elementName: "speed-bg" + sceneSize: sceneItem.sceneSize clip: true - property variant scaledBounds: svgRenderer.scaledElementBounds("pfd.svg", "speed-bg") - x: scaledBounds.x * sceneItem.width y: scaledBounds.y * sceneItem.height width: scaledBounds.width * sceneItem.width height: scaledBounds.height * sceneItem.height - Image { + SvgElementImage { id: speed_scale - source: "image://svg/pfd.svg!speed-scale" - sourceSize: sceneItem.sourceSize + elementName: "speed-scale" + sceneSize: sceneItem.sceneSize anchors.verticalCenter: parent.verticalCenter // The speed scale represents 30 meters, @@ -63,14 +61,12 @@ Item { } - Image { + SvgElementImage { id: speed_window clip: true - source: "image://svg/pfd.svg!speed-window" - sourceSize: sceneItem.sourceSize - - property variant scaledBounds: svgRenderer.scaledElementBounds("pfd.svg", "speed-window") + elementName: "speed-window" + sceneSize: sceneItem.sceneSize x: scaledBounds.x * sceneItem.width y: scaledBounds.y * sceneItem.height diff --git a/ground/openpilotgcs/share/openpilotgcs/pfd/default/SvgElementImage.qml b/ground/openpilotgcs/share/openpilotgcs/pfd/default/SvgElementImage.qml new file mode 100644 index 000000000..f5646b9bd --- /dev/null +++ b/ground/openpilotgcs/share/openpilotgcs/pfd/default/SvgElementImage.qml @@ -0,0 +1,14 @@ +import Qt 4.7 + +Image { + id: sceneItem + property variant sceneSize + property string elementName + property string svgFileName : "pfd.svg" + property variant scaledBounds: svgRenderer.scaledElementBounds(svgFileName, elementName) + + sourceSize.width: Math.round(sceneSize.width*scaledBounds.width) + sourceSize.height: Math.round(sceneSize.height*scaledBounds.height) + + Component.onCompleted: source = "image://svg/"+svgFileName+"!"+elementName +} diff --git a/ground/openpilotgcs/share/openpilotgcs/pfd/default/VsiScale.qml b/ground/openpilotgcs/share/openpilotgcs/pfd/default/VsiScale.qml index 455104462..b543809be 100644 --- a/ground/openpilotgcs/share/openpilotgcs/pfd/default/VsiScale.qml +++ b/ground/openpilotgcs/share/openpilotgcs/pfd/default/VsiScale.qml @@ -2,26 +2,24 @@ import Qt 4.7 Item { id: sceneItem - property variant sourceSize + property variant sceneSize - Image { + SvgElementImage { id: vsi_bg - source: "image://svg/pfd.svg!vsi-bg" - sourceSize: sceneItem.sourceSize + elementName: "vsi-bg" + sceneSize: sceneItem.sceneSize clip: true - property variant scaledBounds: svgRenderer.scaledElementBounds("pfd.svg", "vsi-bg") - x: scaledBounds.x * sceneItem.width y: scaledBounds.y * sceneItem.height width: scaledBounds.width * sceneItem.width height: scaledBounds.height * sceneItem.height - Image { + SvgElementImage { id: vsi_bar - source: "image://svg/pfd.svg!vsi-bar" - sourceSize: sceneItem.sourceSize + elementName: "vsi-bar" + sceneSize: sceneItem.sceneSize //the scale in 1000 ft/min with height == 5200 ft/min height: (-VelocityActual.Down*3.28*60/1000)*(vsi_scale.height/5.2) @@ -31,11 +29,11 @@ Item { anchors.left: parent.left } - Image { + SvgElementImage { id: vsi_scale - source: "image://svg/pfd.svg!vsi-scale" - sourceSize: sceneItem.sourceSize + elementName: "vsi-scale" + sceneSize: sceneItem.sceneSize anchors.verticalCenter: parent.verticalCenter anchors.left: parent.left @@ -67,15 +65,13 @@ Item { } - Image { + SvgElementImage { id: vsi_window clip: true smooth: true - source: "image://svg/pfd.svg!vsi-window" - sourceSize: sceneItem.sourceSize - - property variant scaledBounds: svgRenderer.scaledElementBounds("pfd.svg", "vsi-window") + elementName: "vsi-window" + sceneSize: sceneItem.sceneSize x: scaledBounds.x * sceneItem.width y: scaledBounds.y * sceneItem.height diff --git a/ground/openpilotgcs/src/libs/utils/svgimageprovider.cpp b/ground/openpilotgcs/src/libs/utils/svgimageprovider.cpp index e0f571369..8d60f2e31 100644 --- a/ground/openpilotgcs/src/libs/utils/svgimageprovider.cpp +++ b/ground/openpilotgcs/src/libs/utils/svgimageprovider.cpp @@ -92,9 +92,15 @@ QImage SvgImageProvider::requestImage(const QString &id, QSize *size, const QSiz QSize docSize = renderer->defaultSize(); - if (!requestedSize.isEmpty() && !docSize.isEmpty()) { - xScale = qreal(requestedSize.width())/docSize.width(); - yScale = qreal(requestedSize.height())/docSize.height(); + if (!requestedSize.isEmpty()) { + if (!element.isEmpty()) { + QRectF elementBounds = renderer->boundsOnElement(element); + xScale = qreal(requestedSize.width())/elementBounds.width(); + yScale = qreal(requestedSize.height())/elementBounds.height(); + } else if (!docSize.isEmpty()) { + xScale = qreal(requestedSize.width())/docSize.width(); + yScale = qreal(requestedSize.height())/docSize.height(); + } } //keep the aspect ratio @@ -114,10 +120,16 @@ QImage SvgImageProvider::requestImage(const QString &id, QSize *size, const QSiz QImage img(w, h, QImage::Format_ARGB32_Premultiplied); img.fill(0); QPainter p(&img); - renderer->render(&p, element); + p.setRenderHints(QPainter::TextAntialiasing | + QPainter::Antialiasing | + QPainter::SmoothPixmapTransform); + + renderer->render(&p, element, QRectF(0, 0, w, h)); if (size) *size = QSize(w, h); + + //img.save(element+".png"); return img; } else { //render the whole svg file @@ -127,7 +139,12 @@ QImage SvgImageProvider::requestImage(const QString &id, QSize *size, const QSiz QImage img(w, h, QImage::Format_ARGB32_Premultiplied); img.fill(0); QPainter p(&img); - renderer->render(&p); + p.setRenderHints(QPainter::TextAntialiasing | + QPainter::Antialiasing | + QPainter::SmoothPixmapTransform); + + p.scale(xScale, yScale); + renderer->render(&p, QRectF(QPointF(), QSizeF(docSize))); if (size) *size = QSize(w, h);