mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-17 02:52:12 +01:00
GCS/PFDqml: use the correct sceneSize for svg element images
Pass the element source size instead of the scene source size to ensure the element is not downscalled.
This commit is contained in:
parent
1102587570
commit
4cc13c9eea
@ -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")
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user