1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

Merged in james-duley/librepilot/qt5.5_compat (pull request #124)

Qt5.5 compatibility
This commit is contained in:
James Duley 2015-11-26 18:24:25 +00:00
commit 0fe3b971b8
14 changed files with 107 additions and 390 deletions

View File

@ -1,159 +0,0 @@
/**
******************************************************************************
*
* @file cachedsvgitem.h
* @author Dmytro Poplavskiy Copyright (C) 2011.
* @{
* @brief OpenGL texture cached SVG item
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "cachedsvgitem.h"
#include <QDebug>
#ifndef GL_CLAMP_TO_EDGE
#define GL_CLAMP_TO_EDGE 0x812F
#endif
CachedSvgItem::CachedSvgItem(QGraphicsItem *parent) :
QGraphicsSvgItem(parent),
m_context(0),
m_texture(0),
m_scale(1.0)
{
setCacheMode(NoCache);
}
CachedSvgItem::CachedSvgItem(const QString & fileName, QGraphicsItem *parent) :
QGraphicsSvgItem(fileName, parent),
m_context(0),
m_texture(0),
m_scale(1.0)
{
setCacheMode(NoCache);
}
CachedSvgItem::~CachedSvgItem()
{
if (m_context && m_texture) {
m_context->makeCurrent();
glDeleteTextures(1, &m_texture);
}
}
void CachedSvgItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
if (painter->paintEngine()->type() != QPaintEngine::OpenGL &&
painter->paintEngine()->type() != QPaintEngine::OpenGL2) {
// Fallback to direct painting
QGraphicsSvgItem::paint(painter, option, widget);
return;
}
QRectF br = boundingRect();
QTransform transform = painter->worldTransform();
qreal sceneScale = transform.map(QLineF(0, 0, 1, 0)).length();
bool stencilTestEnabled = glIsEnabled(GL_STENCIL_TEST);
bool scissorTestEnabled = glIsEnabled(GL_SCISSOR_TEST);
painter->beginNativePainting();
if (stencilTestEnabled) {
glEnable(GL_STENCIL_TEST);
}
if (scissorTestEnabled) {
glEnable(GL_SCISSOR_TEST);
}
bool dirty = false;
if (!m_texture) {
glGenTextures(1, &m_texture);
m_context = const_cast<QGLContext *>(QGLContext::currentContext());
dirty = true;
}
if (!qFuzzyCompare(sceneScale, m_scale)) {
m_scale = sceneScale;
dirty = true;
}
int textureWidth = (int(br.width() * m_scale) + 3) & ~3;
int textureHeight = (int(br.height() * m_scale) + 3) & ~3;
if (dirty) {
// qDebug() << "re-render image";
QImage img(textureWidth, textureHeight, QImage::Format_ARGB32);
{
img.fill(Qt::transparent);
QPainter p;
p.begin(&img);
p.setRenderHints(painter->renderHints());
p.translate(br.topLeft());
p.scale(m_scale, m_scale);
QGraphicsSvgItem::paint(&p, option, 0);
p.end();
img = img.rgbSwapped();
}
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_texture);
glTexImage2D(
GL_TEXTURE_2D,
0,
GL_RGBA,
textureWidth,
textureHeight,
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
img.bits());
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glDisable(GL_TEXTURE_2D);
dirty = false;
}
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_texture);
// texture may be slightly large than svn image, ensure only used area is rendered
qreal tw = br.width() * m_scale / textureWidth;
qreal th = br.height() * m_scale / textureHeight;
glBegin(GL_QUADS);
glTexCoord2d(0, 0); glVertex3d(br.left(), br.top(), -1);
glTexCoord2d(tw, 0); glVertex3d(br.right(), br.top(), -1);
glTexCoord2d(tw, th); glVertex3d(br.right(), br.bottom(), -1);
glTexCoord2d(0, th); glVertex3d(br.left(), br.bottom(), -1);
glEnd();
glDisable(GL_TEXTURE_2D);
painter->endNativePainting();
}

View File

@ -1,54 +0,0 @@
/**
******************************************************************************
*
* @file cachedsvgitem.h
* @author Dmytro Poplavskiy Copyright (C) 2011.
* @{
* @brief OpenGL texture cached SVG item
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef CACHEDSVGITEM_H
#define CACHEDSVGITEM_H
#include <QGraphicsSvgItem>
#include <QtOpenGL>
#include <QtOpenGL/QGLContext>
#include "utils_global.h"
class QGLContext;
// Cache Svg item as GL Texture.
// Texture is regenerated each time item is scaled
// but it's reused during rotation, unlike DeviceCoordinateCache mode
class QTCREATOR_UTILS_EXPORT CachedSvgItem : public QGraphicsSvgItem {
Q_OBJECT
public:
CachedSvgItem(QGraphicsItem *parent = 0);
CachedSvgItem(const QString & fileName, QGraphicsItem *parent = 0);
~CachedSvgItem();
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
private:
QGLContext *m_context;
GLuint m_texture;
qreal m_scale;
};
#endif // ifndef CACHEDSVGITEM_H

View File

@ -31,7 +31,6 @@
#include "utils_global.h"
#include <QSlider>
#include <QtDesigner/QDesignerExportWidget>
class QTCREATOR_UTILS_EXPORT TextBubbleSlider : public QSlider {
Q_OBJECT

View File

@ -1,7 +1,7 @@
TEMPLATE = lib
TARGET = Utils
QT += network xml svg opengl gui widgets qml quick quickwidgets
QT += network xml svg gui widgets qml quick quickwidgets
DEFINES += QTCREATOR_UTILS_LIB
@ -52,7 +52,6 @@ SOURCES += \
mytabbedstackwidget.cpp \
mytabwidget.cpp \
quickwidgetproxy.cpp \
cachedsvgitem.cpp \
svgimageprovider.cpp \
hostosinfo.cpp \
logfile.cpp \
@ -116,7 +115,6 @@ HEADERS += \
mytabbedstackwidget.h \
mytabwidget.h \
quickwidgetproxy.h \
cachedsvgitem.h \
svgimageprovider.h \
hostosinfo.h \
logfile.h \

View File

@ -210,8 +210,8 @@ void UdpReceiver::onReadyRead()
while (inSocket->hasPendingDatagrams()) {
QByteArray datagram;
datagram.resize(inSocket->pendingDatagramSize());
quint64 datagramSize;
datagramSize = inSocket->readDatagram(datagram.data(), datagram.size());
// quint64 datagramSize;
/*datagramSize =*/ inSocket->readDatagram(datagram.data(), datagram.size());
processDatagram(datagram);
}

View File

@ -65,7 +65,7 @@
#include "extensionsystem/pluginmanager.h"
#include <coreplugin/icore.h>
#include <coreplugin/threadmanager.h>
#include <math.h>
#include <cmath>
const float IL2Simulator::FT2M = 12 * .254;
const float IL2Simulator::KT2MPS = 0.514444444;
@ -194,13 +194,13 @@ void IL2Simulator::processUpdate(const QByteArray & inp)
current.Y = old.Y + (current.dY * current.dT);
// accelerations (filtered)
if (isnan(old.ddX) || isinf(old.ddX)) {
if (std::isnan(old.ddX) || std::isinf(old.ddX)) {
old.ddX = 0;
}
if (isnan(old.ddY) || isinf(old.ddY)) {
if (std::isnan(old.ddY) || std::isinf(old.ddY)) {
old.ddY = 0;
}
if (isnan(old.ddZ) || isinf(old.ddZ)) {
if (std::isnan(old.ddZ) || std::isinf(old.ddZ)) {
old.ddZ = 0;
}
#define SPEED_FILTER 10
@ -210,13 +210,13 @@ void IL2Simulator::processUpdate(const QByteArray & inp)
#define TURN_FILTER 10
// turn speeds (filtered)
if (isnan(old.dAzimuth) || isinf(old.dAzimuth)) {
if (std::isnan(old.dAzimuth) || std::isinf(old.dAzimuth)) {
old.dAzimuth = 0;
}
if (isnan(old.dPitch) || isinf(old.dPitch)) {
if (std::isnan(old.dPitch) || std::isinf(old.dPitch)) {
old.dPitch = 0;
}
if (isnan(old.dRoll) || isinf(old.dRoll)) {
if (std::isnan(old.dRoll) || std::isinf(old.dRoll)) {
old.dRoll = 0;
}
current.dAzimuth = (angleDifference(current.azimuth, old.azimuth) / current.dT + TURN_FILTER * (old.dAzimuth)) / (TURN_FILTER + 1);

View File

@ -293,10 +293,8 @@ void modelMapProxy::rowsInserted(const QModelIndex &parent, int first, int last)
{
Q_UNUSED(parent);
for (int x = first; x < last + 1; x++) {
QModelIndex index;
WayPointItem *item;
internals::PointLatLng latlng;
distBearingAltitude distBearing;
double altitude;
@ -318,9 +316,9 @@ void modelMapProxy::rowsInserted(const QModelIndex &parent, int first, int last)
index = model->index(x, flightDataModel::ALTITUDE);
altitude = index.data(Qt::DisplayRole).toDouble();
if (relative) {
item = myMap->WPInsert(distBearing, desc, x);
myMap->WPInsert(distBearing, desc, x);
} else {
item = myMap->WPInsert(latlng, altitude, desc, x);
myMap->WPInsert(latlng, altitude, desc, x);
}
}

View File

@ -1,5 +1,6 @@
import QtQuick 2.0
import "."
import "common.js" as Utils
Item {
id: sceneItem
@ -50,7 +51,7 @@ Item {
rotation: -AttitudeState.Yaw + home_degrees
transformOrigin: Item.Bottom
visible: TakeOffLocation.Status == 0
visible: Utils.toInt(TakeOffLocation.Status) == 0
}

View File

@ -1,4 +1,5 @@
import QtQuick 2.0
import "common.js" as Utils
Item {
id: info
@ -58,15 +59,6 @@ Item {
}
}
function formatTime(time) {
if (time === 0)
return "00"
if (time < 10)
return "0" + time;
else
return time.toString();
}
// End Functions
//
// Start Drawing
@ -84,16 +76,14 @@ Item {
//
property real bar_width: (info_bg.height + info_bg.width) / 110
property int satsInView: String(GPSSatellites.SatsInView).charCodeAt(0)
property int satsInView: Utils.toInt(GPSSatellites.SatsInView)
property variant gps_tooltip: "Altitude : "+GPSPositionSensor.Altitude.toFixed(2) +"m\n"+
"H/V/P DOP : "+GPSPositionSensor.HDOP.toFixed(2)+"/"+GPSPositionSensor.VDOP.toFixed(2)+"/"+GPSPositionSensor.PDOP.toFixed(2)+"m\n"+
satsInView+" Sats in view"
Repeater {
id: satNumberBar
//smooth: true
// hack, qml/js treats qint8 as a char, necessary to convert it back to integer value
property int satNumber : String(GPSPositionSensor.Satellites).charCodeAt(0)
property int satNumber : Utils.toInt(GPSPositionSensor.Satellites)
model: 13
Rectangle {
@ -122,10 +112,10 @@ Item {
}
Text {
property int satNumber : String(GPSPositionSensor.Satellites).charCodeAt(0)
property int satNumber : Utils.toInt(GPSPositionSensor.Satellites)
text: [satNumber > 5 ? " " + satNumber.toString() + " sats - " : ""] +
["NO GPS", "NO FIX", "2D", "3D"][GPSPositionSensor.Status]
["NO GPS", "NO FIX", "2D", "3D"][Utils.toInt(GPSPositionSensor.Status)]
anchors.centerIn: parent
font.pixelSize: parent.height*1.3
font.family: pt_bold.name
@ -154,7 +144,7 @@ Item {
width: scaledBounds.width * sceneItem.width
height: scaledBounds.height * sceneItem.height
y: Math.floor(scaledBounds.y * sceneItem.height)
visible: SystemAlarms.Alarm_PathPlan == 1
visible: Utils.toInt(SystemAlarms.Alarm_PathPlan) == 1
}
SvgElementPositionItem {
@ -163,7 +153,7 @@ Item {
width: scaledBounds.width * sceneItem.width
height: scaledBounds.height * sceneItem.height
y: Math.floor(scaledBounds.y * sceneItem.height)
visible: SystemAlarms.Alarm_PathPlan == 1
visible: Utils.toInt(SystemAlarms.Alarm_PathPlan) == 1
Text {
text: " "+wp_heading.toFixed(1)+"°"
@ -184,7 +174,7 @@ Item {
width: scaledBounds.width * sceneItem.width
height: scaledBounds.height * sceneItem.height
y: Math.floor(scaledBounds.y * sceneItem.height)
visible: SystemAlarms.Alarm_PathPlan == 1
visible: Utils.toInt(SystemAlarms.Alarm_PathPlan) == 1
Text {
text: " "+wp_distance.toFixed(0)+" m"
@ -205,7 +195,7 @@ Item {
width: scaledBounds.width * sceneItem.width
height: scaledBounds.height * sceneItem.height
y: Math.floor(scaledBounds.y * sceneItem.height)
visible: SystemAlarms.Alarm_PathPlan == 1
visible: Utils.toInt(SystemAlarms.Alarm_PathPlan) == 1
MouseArea { id: total_dist_mouseArea; anchors.fill: parent; cursorShape: Qt.PointingHandCursor; onClicked: reset_distance()}
@ -223,7 +213,7 @@ Item {
Timer {
interval: 1000; running: true; repeat: true;
onTriggered: {if (GPSPositionSensor.Status == 3) compute_distance(PositionState.East,PositionState.North)}
onTriggered: {if (Utils.toInt(GPSPositionSensor.Status) == 3) compute_distance(PositionState.East,PositionState.North)}
}
}
@ -233,10 +223,10 @@ Item {
width: scaledBounds.width * sceneItem.width
height: scaledBounds.height * sceneItem.height
y: Math.floor(scaledBounds.y * sceneItem.height)
visible: SystemAlarms.Alarm_PathPlan == 1
visible: Utils.toInt(SystemAlarms.Alarm_PathPlan) == 1
Text {
text: formatTime(wp_eta_h) + ":" + formatTime(wp_eta_m) + ":" + formatTime(wp_eta_s)
text: Utils.formatTime(wp_eta_h) + ":" + Utils.formatTime(wp_eta_m) + ":" + Utils.formatTime(wp_eta_s)
anchors.centerIn: parent
color: "cyan"
@ -254,7 +244,7 @@ Item {
width: scaledBounds.width * sceneItem.width
height: scaledBounds.height * sceneItem.height
y: Math.floor(scaledBounds.y * sceneItem.height)
visible: SystemAlarms.Alarm_PathPlan == 1
visible: Utils.toInt(SystemAlarms.Alarm_PathPlan) == 1
Text {
text: (WaypointActive.Index+1)+" / "+PathPlan.WaypointCount
@ -275,10 +265,10 @@ Item {
width: scaledBounds.width * sceneItem.width
height: scaledBounds.height * sceneItem.height
y: Math.floor(scaledBounds.y * sceneItem.height)
visible: SystemAlarms.Alarm_PathPlan == 1
visible: Utils.toInt(SystemAlarms.Alarm_PathPlan) == 1
Text {
text: ["GOTO ENDPOINT","FOLLOW VECTOR","CIRCLE RIGHT","CIRCLE LEFT","FIXED ATTITUDE","SET ACCESSORY","DISARM ALARM","LAND","BRAKE","VELOCITY","AUTO TAKEOFF"][PathDesired.Mode]
text: ["GOTO ENDPOINT","FOLLOW VECTOR","CIRCLE RIGHT","CIRCLE LEFT","FIXED ATTITUDE","SET ACCESSORY","DISARM ALARM","LAND","BRAKE","VELOCITY","AUTO TAKEOFF"][Utils.toInt(PathDesired.Mode)]
anchors.centerIn: parent
color: "cyan"
@ -301,11 +291,11 @@ Item {
width: scaledBounds.width * sceneItem.width
height: scaledBounds.height * sceneItem.height
y: scaledBounds.y * sceneItem.height
visible: (SystemAlarms.Alarm_PathPlan != 1) && (HwSettings.OptionalModules_Battery == 1)
visible: (Utils.toInt(SystemAlarms.Alarm_PathPlan) != 1) && (Utils.toInt(HwSettings.OptionalModules_Battery) == 1)
Rectangle {
anchors.fill: parent
color: FlightBatterySettings.NbCells > 0 ? info.batColors[SystemAlarms.Alarm_Battery] : "black"
color: Utils.toInt(FlightBatterySettings.NbCells) > 0 ? info.batColors[Utils.toInt(SystemAlarms.Alarm_Battery)] : "black"
}
}
@ -316,7 +306,7 @@ Item {
width: scaledBounds.width * sceneItem.width
height: scaledBounds.height * sceneItem.height
y: Math.floor(scaledBounds.y * sceneItem.height)
visible: (SystemAlarms.Alarm_PathPlan != 1) && (HwSettings.OptionalModules_Battery == 1)
visible: (Utils.toInt(SystemAlarms.Alarm_PathPlan) != 1) && (Utils.toInt(HwSettings.OptionalModules_Battery) == 1)
}
SvgElementPositionItem {
@ -327,7 +317,7 @@ Item {
width: scaledBounds.width * sceneItem.width
height: scaledBounds.height * sceneItem.height
y: scaledBounds.y * sceneItem.height
visible: (SystemAlarms.Alarm_PathPlan != 1) && (HwSettings.OptionalModules_Battery == 1)
visible: (Utils.toInt(SystemAlarms.Alarm_PathPlan) != 1) && (Utils.toInt(HwSettings.OptionalModules_Battery) == 1)
Rectangle {
anchors.fill: parent
@ -354,7 +344,7 @@ Item {
width: scaledBounds.width * sceneItem.width
height: scaledBounds.height * sceneItem.height
y: scaledBounds.y * sceneItem.height
visible: (SystemAlarms.Alarm_PathPlan != 1) && (HwSettings.OptionalModules_Battery == 1)
visible: (Utils.toInt(SystemAlarms.Alarm_PathPlan) != 1) && (Utils.toInt(HwSettings.OptionalModules_Battery) == 1)
Rectangle {
anchors.fill: parent
@ -381,7 +371,7 @@ Item {
width: scaledBounds.width * sceneItem.width
height: scaledBounds.height * sceneItem.height
y: scaledBounds.y * sceneItem.height
visible: (SystemAlarms.Alarm_PathPlan != 1) && (HwSettings.OptionalModules_Battery == 1)
visible: (Utils.toInt(SystemAlarms.Alarm_PathPlan) != 1) && (Utils.toInt(HwSettings.OptionalModules_Battery) == 1)
Rectangle {
anchors.fill: parent
@ -399,7 +389,7 @@ Item {
// Alarm based on FlightBatteryState.EstimatedFlightTime < 120s orange, < 60s red
color: (FlightBatteryState.EstimatedFlightTime <= 120 && FlightBatteryState.EstimatedFlightTime > 60 ? "orange" :
(FlightBatteryState.EstimatedFlightTime <= 60 ? "red": info.batColors[SystemAlarms.Alarm_Battery]))
(FlightBatteryState.EstimatedFlightTime <= 60 ? "red": info.batColors[Utils.toInt(SystemAlarms.Alarm_Battery)]))
border.color: "white"
border.width: topbattery_volt.width * 0.01
@ -427,7 +417,7 @@ Item {
width: scaledBounds.width * sceneItem.width
height: scaledBounds.height * sceneItem.height
y: Math.floor(scaledBounds.y * sceneItem.height)
visible: SystemAlarms.Alarm_PathPlan != 1
visible: Utils.toInt(SystemAlarms.Alarm_PathPlan) != 1
}
SvgElementPositionItem {
@ -436,7 +426,7 @@ Item {
width: scaledBounds.width * sceneItem.width
height: scaledBounds.height * sceneItem.height
y: Math.floor(scaledBounds.y * sceneItem.height)
visible: SystemAlarms.Alarm_PathPlan != 1
visible: Utils.toInt(SystemAlarms.Alarm_PathPlan) != 1
TooltipArea {
text: "Reset distance counter"
@ -458,7 +448,7 @@ Item {
Timer {
interval: 1000; running: true; repeat: true;
onTriggered: {if (GPSPositionSensor.Status == 3) compute_distance(PositionState.East,PositionState.North)}
onTriggered: {if (Utils.toInt(GPSPositionSensor.Status) == 3) compute_distance(PositionState.East,PositionState.North)}
}
}
@ -477,7 +467,7 @@ Item {
states: State {
name: "fading"
when: TakeOffLocation.Status == 0
when: Utils.toInt(TakeOffLocation.Status) == 0
PropertyChanges { target: home_bg; x: Math.floor(scaledBounds.x * sceneItem.width) - home_bg.width; }
}
@ -498,7 +488,7 @@ Item {
states: State {
name: "fading_heading"
when: TakeOffLocation.Status == 0
when: Utils.toInt(TakeOffLocation.Status) == 0
PropertyChanges { target: home_heading_text; x: Math.floor(scaledBounds.x * sceneItem.width) - home_bg.width; }
}
@ -529,7 +519,7 @@ Item {
states: State {
name: "fading_distance"
when: TakeOffLocation.Status == 0
when: Utils.toInt(TakeOffLocation.Status) == 0
PropertyChanges { target: home_distance_text; x: Math.floor(scaledBounds.x * sceneItem.width) - home_bg.width; }
}
@ -560,7 +550,7 @@ Item {
states: State {
name: "fading_distance"
when: TakeOffLocation.Status == 0
when: Utils.toInt(TakeOffLocation.Status) == 0
PropertyChanges { target: home_eta_text; x: Math.floor(scaledBounds.x * sceneItem.width) - home_bg.width; }
}
@ -571,7 +561,7 @@ Item {
}
Text {
text: formatTime(home_eta_h) + ":" + formatTime(home_eta_m) + ":" + formatTime(home_eta_s)
text: Utils.formatTime(home_eta_h) + ":" + Utils.formatTime(home_eta_m) + ":" + Utils.formatTime(home_eta_s)
anchors.centerIn: parent
color: "cyan"
font {

View File

@ -1,4 +1,5 @@
import QtQuick 2.0
import "common.js" as Utils
Item {
id: panels
@ -9,15 +10,6 @@ Item {
property real est_time_m: (est_flight_time > 0 ? Math.floor((est_flight_time - est_time_h*3600)/60) : 0)
property real est_time_s: (est_flight_time > 0 ? Math.floor(est_flight_time - est_time_h*3600 - est_time_m*60) : 0)
function formatTime(time) {
if (time === 0)
return "00"
if (time < 10)
return "0" + time;
else
return time.toString();
}
//
// Panel functions
//
@ -100,7 +92,7 @@ Item {
function telemetry_check() {
telemetry_sum = OPLinkStatus.RXRate + OPLinkStatus.RXRate
if (telemetry_sum != telemetry_sum_old || OPLinkStatus.LinkState == 4) {
if (telemetry_sum != telemetry_sum_old || Utils.toInt(OPLinkStatus.LinkState) == 4) {
telemetry_link = 1
} else {
telemetry_link = 0
@ -451,7 +443,7 @@ Item {
Rectangle {
anchors.fill: parent
color: panels.batColors[SystemAlarms.Alarm_Battery]
color: panels.batColors[Utils.toInt(SystemAlarms.Alarm_Battery)]
border.color: "white"
border.width: battery_volt.width * 0.01
radius: border.width * 4
@ -492,7 +484,7 @@ Item {
Rectangle {
anchors.fill: parent
color: panels.batColors[SystemAlarms.Alarm_Battery]
color: panels.batColors[Utils.toInt(SystemAlarms.Alarm_Battery)]
border.color: "white"
border.width: battery_volt.width * 0.01
radius: border.width * 4
@ -549,7 +541,7 @@ Item {
// Alarm based on FlightBatteryState.EstimatedFlightTime < 120s orange, < 60s red
color: (FlightBatteryState.EstimatedFlightTime <= 120 && FlightBatteryState.EstimatedFlightTime > 60 ? "orange" :
(FlightBatteryState.EstimatedFlightTime <= 60 ? "red": panels.batColors[SystemAlarms.Alarm_Battery]))
(FlightBatteryState.EstimatedFlightTime <= 60 ? "red": panels.batColors[Utils.toInt(SystemAlarms.Alarm_Battery)]))
border.color: "white"
border.width: battery_volt.width * 0.01
@ -591,7 +583,7 @@ Item {
Rectangle {
anchors.fill: parent
//color: panels.batColors[SystemAlarms.Alarm_Battery]
//color: panels.batColors[Utils.toInt(SystemAlarms.Alarm_Battery)]
TooltipArea {
text: "Reset consumed energy"
@ -608,14 +600,14 @@ Item {
// Alarm based on FlightBatteryState.EstimatedFlightTime < 120s orange, < 60s red
color: (FlightBatteryState.EstimatedFlightTime <= 120 && FlightBatteryState.EstimatedFlightTime > 60 ? "orange" :
(FlightBatteryState.EstimatedFlightTime <= 60 ? "red": panels.batColors[SystemAlarms.Alarm_Battery]))
(FlightBatteryState.EstimatedFlightTime <= 60 ? "red": panels.batColors[Utils.toInt(SystemAlarms.Alarm_Battery)]))
border.color: "white"
border.width: battery_volt.width * 0.01
radius: border.width * 4
Text {
text: formatTime(est_time_h) + ":" + formatTime(est_time_m) + ":" + formatTime(est_time_s)
text: Utils.formatTime(est_time_h) + ":" + Utils.formatTime(est_time_m) + ":" + Utils.formatTime(est_time_s)
anchors.centerIn: parent
color: "white"
font {
@ -954,7 +946,7 @@ Item {
}
Text {
text: ReceiverStatus.Quality > 0 ? ReceiverStatus.Quality+"%" : "?? %"
text: Utils.toInt(ReceiverStatus.Quality) > 0 ? Utils.toInt(ReceiverStatus.Quality)+"%" : "?? %"
anchors.centerIn: parent
color: "white"
font {
@ -1043,7 +1035,7 @@ Item {
Text {
text: ["FixedWing", "FixedWingElevon", "FixedWingVtail", "VTOL", "HeliCP", "QuadX", "QuadP",
"Hexa+", "Octo+", "Custom", "HexaX", "HexaH", "OctoV", "OctoCoaxP", "OctoCoaxX", "OctoX", "HexaCoax",
"Tricopter", "GroundVehicleCar", "GroundVehicleDiff", "GroundVehicleMoto"][SystemSettings.AirframeType]
"Tricopter", "GroundVehicleCar", "GroundVehicleDiff", "GroundVehicleMoto"][Utils.toInt(SystemSettings.AirframeType)]
anchors.right: parent.right
color: "white"
font {
@ -1075,7 +1067,7 @@ Item {
Text {
// Coptercontrol detect with mem free : Only display Cpu load, no temperature available.
text: SystemStats.CPULoad+"%"+
text: Utils.toInt(SystemStats.CPULoad)+"%"+
[SystemStats.HeapRemaining < 3000 ? "" : " | "+cpuTemp+"°C"]
anchors.right: parent.right
color: "white"
@ -1138,7 +1130,7 @@ Item {
}
Text {
text: ["None", "Basic (No Nav)", "CompMag", "Comp+Mag+GPS", "EKFIndoor", "GPS Nav (INS13)"][RevoSettings.FusionAlgorithm]
text: ["None", "Basic (No Nav)", "CompMag", "Comp+Mag+GPS", "EKFIndoor", "GPS Nav (INS13)"][Utils.toInt(RevoSettings.FusionAlgorithm)]
anchors.right: parent.right
color: "white"
font {
@ -1169,7 +1161,7 @@ Item {
}
Text {
text: ["Invalid", "OnBoard", "External"][MagState.Source]
text: ["Invalid", "OnBoard", "External"][Utils.toInt(MagState.Source)]
anchors.right: parent.right
color: "white"
font {
@ -1200,7 +1192,7 @@ Item {
}
Text {
text: ["Unknown", "NMEA", "UBX", "UBX7", "UBX8"][GPSPositionSensor.SensorType]
text: ["Unknown", "NMEA", "UBX", "UBX7", "UBX8"][Utils.toInt(GPSPositionSensor.SensorType)]
anchors.right: parent.right
color: "white"
font {

View File

@ -1,67 +0,0 @@
import QtQuick 2.0
Item {
id: sceneItem
property variant sceneSize
//telemetry status arrow
SvgElementImage {
id: telemetry_status
elementName: "gcstelemetry-"+statusName
sceneSize: sceneItem.sceneSize
property string statusName : ["Disconnected","HandshakeReq","HandshakeAck","Connected"][GCSTelemetryStats.Status]
scaledBounds: svgRenderer.scaledElementBounds("pfd.svg", "gcstelemetry-Disconnected")
x: Math.floor(scaledBounds.x * sceneItem.width)
y: Math.floor(scaledBounds.y * sceneItem.height)
}
//telemetry rate text
Text {
id: telemetry_rate
text: GCSTelemetryStats.TxDataRate.toFixed()+"/"+GCSTelemetryStats.RxDataRate.toFixed()
color: "white"
font.family: pt_bold.name
font.pixelSize: telemetry_status.height * 0.75
anchors.top: telemetry_status.bottom
anchors.horizontalCenter: telemetry_status.horizontalCenter
}
Text {
id: gps_text
text: "GPS: " + GPSPositionSensor.Satellites + "\nPDP: " + Math.round(GPSPositionSensor.PDOP*10)/10
color: "white"
font.family: pt_bold.name
font.pixelSize: telemetry_status.height * 0.75
visible: GPSPositionSensor.Satellites > 0
property variant scaledBounds: svgRenderer.scaledElementBounds("pfd.svg", "gps-txt")
x: Math.floor(scaledBounds.x * sceneItem.width)
y: Math.floor(scaledBounds.y * sceneItem.height)
}
Text {
id: battery_text
text: FlightBatteryState.Voltage.toFixed(2)+" V\n" +
FlightBatteryState.Current.toFixed(2)+" A\n" +
FlightBatteryState.ConsumedEnergy.toFixed()+" mAh"
color: "white"
font.family: pt_bold.name
//I think it should be pixel size,
//but making it more consistent with C++ version instead
font.pointSize: scaledBounds.height * sceneItem.height
visible: FlightBatteryState.Voltage > 0 || FlightBatteryState.Current > 0
property variant scaledBounds: svgRenderer.scaledElementBounds("pfd.svg", "battery-txt")
x: Math.floor(scaledBounds.x * sceneItem.width)
y: Math.floor(scaledBounds.y * sceneItem.height)
}
}

View File

@ -1,4 +1,5 @@
import QtQuick 2.0
import "common.js" as Utils
Item {
id: sceneItem
@ -22,7 +23,7 @@ Item {
y: scaledBounds.y * sceneItem.height
smooth: true
visible: VelocityDesired.Down !== 0.0 && FlightStatus.FlightMode > 7
visible: VelocityDesired.Down !== 0.0 && Utils.toInt(FlightStatus.FlightMode) > 7
//rotate it around the center
transform: Rotation {

View File

@ -1,4 +1,5 @@
import QtQuick 2.0
import "common.js" as Utils
Item {
id: warnings
@ -26,10 +27,10 @@ Item {
// SystemSettings.AirframeType 3 - 17 : VtolPathFollower, check ThrustControl
property var thrust_mode: FlightStatus.FlightMode < 7 ? StabilizationDesired.StabilizationMode_Thrust :
FlightStatus.FlightMode > 6 && SystemSettings.AirframeType > 2 && SystemSettings.AirframeType < 18
&& VtolPathFollowerSettings.ThrustControl == 1 ? 12 :
FlightStatus.FlightMode > 6 && SystemSettings.AirframeType < 3 ? 12: 0
property var thrust_mode: Utils.toInt(FlightStatus.FlightMode) < 7 ? Utils.toInt(StabilizationDesired.StabilizationMode_Thrust) :
Utils.toInt(FlightStatus.FlightMode) > 6 && Utils.toInt(SystemSettings.AirframeType) > 2 &&
Utils.toInt(SystemSettings.AirframeType) < 18 && Utils.toInt(VtolPathFollowerSettings.ThrustControl) == 1 ? 12 :
Utils.toInt(FlightStatus.FlightMode) > 6 && Utils.toInt(SystemSettings.AirframeType) < 3 ? 12: 0
property real flight_time: Math.round(SystemStats.FlightTime / 1000)
@ -37,15 +38,6 @@ Item {
property real time_m: (flight_time > 0 ? Math.floor((flight_time - time_h*3600)/60) : 0)
property real time_s: (flight_time > 0 ? Math.floor(flight_time - time_h*3600 - time_m*60) : 0)
function formatTime(time) {
if (time === 0)
return "00"
if (time < 10)
return "0" + time;
else
return time.toString();
}
SvgElementImage {
id: warning_bg
elementName: "warnings-bg"
@ -69,7 +61,7 @@ Item {
Text {
anchors.centerIn: parent
text: formatTime(time_h) + ":" + formatTime(time_m) + ":" + formatTime(time_s)
text: Utils.formatTime(time_h) + ":" + Utils.formatTime(time_m) + ":" + Utils.formatTime(time_s)
font {
family: pt_bold.name
pixelSize: Math.floor(parent.height * 0.8)
@ -90,11 +82,11 @@ Item {
Rectangle {
anchors.fill: parent
color: warnings.armColors[FlightStatus.Armed]
color: warnings.armColors[Utils.toInt(FlightStatus.Armed)]
Text {
anchors.centerIn: parent
text: ["DISARMED","ARMING","ARMED"][FlightStatus.Armed]
text: ["DISARMED","ARMING","ARMED"][Utils.toInt(FlightStatus.Armed)]
font {
family: pt_bold.name
pixelSize: Math.floor(parent.height * 0.74)
@ -115,7 +107,7 @@ Item {
Rectangle {
anchors.fill: parent
color: warnings.statusColors[SystemAlarms.Alarm_ManualControl]
color: warnings.statusColors[Utils.toInt(SystemAlarms.Alarm_ManualControl)]
Text {
anchors.centerIn: parent
@ -138,11 +130,11 @@ Item {
x: scaledBounds.x * sceneItem.width
y: scaledBounds.y * sceneItem.height
property bool warningActive: (SystemAlarms.Alarm_BootFault > 1 ||
SystemAlarms.Alarm_OutOfMemory > 1 ||
SystemAlarms.Alarm_StackOverflow > 1 ||
SystemAlarms.Alarm_CPUOverload > 1 ||
SystemAlarms.Alarm_EventSystem > 1)
property bool warningActive: (Utils.toInt(SystemAlarms.Alarm_BootFault) > 1 ||
Utils.toInt(SystemAlarms.Alarm_OutOfMemory) > 1 ||
Utils.toInt(SystemAlarms.Alarm_StackOverflow) > 1 ||
Utils.toInt(SystemAlarms.Alarm_CPUOverload) > 1 ||
Utils.toInt(SystemAlarms.Alarm_EventSystem) > 1)
Rectangle {
anchors.fill: parent
color: parent.warningActive ? "red" : "red"
@ -172,7 +164,7 @@ Item {
Rectangle {
anchors.fill: parent
color: warnings.statusColors[SystemAlarms.Alarm_Guidance]
color: warnings.statusColors[Utils.toInt(SystemAlarms.Alarm_Guidance)]
Text {
anchors.centerIn: parent
@ -197,14 +189,14 @@ Item {
Rectangle {
anchors.fill: parent
color: warnings.flightmodeColors[FlightStatus.FlightMode]
color: warnings.flightmodeColors[Utils.toInt(FlightStatus.FlightMode)]
// Manual,Stabilized1,Stabilized2,Stabilized3,Stabilized4,Stabilized5,Stabilized6,PositionHold,CourseLock,
// VelocityRoam,HomeLeash,AbsolutePosition,ReturnToBase,Land,PathPlanner,POI,AutoCruise,AutoTakeoff
Text {
anchors.centerIn: parent
text: ["MANUAL","STAB 1","STAB 2", "STAB 3", "STAB 4", "STAB 5", "STAB 6", "POS HOLD", "COURSELOCK",
"VEL ROAM", "HOME LEASH", "ABS POS", "RTB", "LAND", "PATHPLAN", "POI", "AUTOCRUISE", "AUTOTAKEOFF"][FlightStatus.FlightMode]
"VEL ROAM", "HOME LEASH", "ABS POS", "RTB", "LAND", "PATHPLAN", "POI", "AUTOCRUISE", "AUTOTAKEOFF"][Utils.toInt(FlightStatus.FlightMode)]
font {
family: pt_bold.name
pixelSize: Math.floor(parent.height * 0.74)
@ -225,7 +217,7 @@ Item {
Rectangle {
anchors.fill: parent
color: FlightStatus.FlightMode < 1 ? "grey" : warnings.thrustmodeColors[thrust_mode.toString()]
color: Utils.toInt(FlightStatus.FlightMode) < 1 ? "grey" : warnings.thrustmodeColors[thrust_mode]
// Manual,Rate,RateTrainer,Attitude,AxisLock,WeakLeveling,VirtualBar,Acro+,Rattitude,
// AltitudeHold,AltitudeVario,CruiseControl
@ -233,7 +225,7 @@ Item {
Text {
anchors.centerIn: parent
text: ["MANUAL"," "," ", " ", " ", " ", " ", " ", " ",
"ALT HOLD", "ALT VARIO", "CRUISECTRL", "AUTO"][thrust_mode.toString()]
"ALT HOLD", "ALT VARIO", "CRUISECTRL", "AUTO"][thrust_mode]
font {
family: pt_bold.name
pixelSize: Math.floor(parent.height * 0.74)
@ -248,7 +240,7 @@ Item {
elementName: "warning-gps"
sceneSize: warnings.sceneSize
visible: SystemAlarms.Alarm_GPS > 1
visible: Utils.toInt(SystemAlarms.Alarm_GPS) > 1
}
SvgElementImage {
@ -256,6 +248,6 @@ Item {
elementName: "warning-attitude"
sceneSize: warnings.sceneSize
anchors.centerIn: background.centerIn
visible: SystemAlarms.Alarm_Attitude > 1
visible: Utils.toInt(SystemAlarms.Alarm_Attitude) > 1
}
}

View File

@ -0,0 +1,26 @@
// ***********************
// common.js
//
// Common javascript utils
//
// Librepilot
// ***********************
//
// qml/js treats qint8 as a char, necessary to convert it back to integer value
function toInt(enum_value) {
if (Object.prototype.toString.call(enum_value) == "[object String]") {
return enum_value.charCodeAt(0);
}
return enum_value;
}
// Format time
function formatTime(time) {
if (time === 0)
return "00"
if (time < 10)
return "0" + time;
else
return time.toString();
}