Commit 72a7acc5 authored by dogmaphobic's avatar dogmaphobic

Moved update canvas to ScreenTools

Moved update canvas signal to perspective load instead of hooking it to the paint event.
Added an "S" as the unit for the number of cells fact (as in 4S).
parent b2c32682
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
<short_desc>Number of cells</short_desc> <short_desc>Number of cells</short_desc>
<long_desc>Defines the number of cells the attached battery consists of.</long_desc> <long_desc>Defines the number of cells the attached battery consists of.</long_desc>
<default>3</default> <default>3</default>
<unit>S</unit>
</parameter> </parameter>
<parameter name="BAT_CAPACITY" type="FLOAT"> <parameter name="BAT_CAPACITY" type="FLOAT">
<short_desc>Battery capacity</short_desc> <short_desc>Battery capacity</short_desc>
......
...@@ -38,13 +38,14 @@ import QGroundControl.ScreenTools 1.0 ...@@ -38,13 +38,14 @@ import QGroundControl.ScreenTools 1.0
Rectangle { Rectangle {
QGCPalette { id: palette; colorGroupEnabled: true } QGCPalette { id: palette; colorGroupEnabled: true }
id: powerSettings
width: 600 width: 600
height: 600 height: 600
color: palette.window color: palette.window
property int firstColumnWidth: 220 property int firstColumnWidth: 220
property int textEditWidth: 60 property int textEditWidth: 60
property ScreenTools __screenTools: ScreenTools { } property ScreenTools screenTools: ScreenTools { }
property Fact battNumCells: Fact { name: "BAT_N_CELLS" } property Fact battNumCells: Fact { name: "BAT_N_CELLS" }
property Fact battHighVolt: Fact { name: "BAT_V_CHARGED" } property Fact battHighVolt: Fact { name: "BAT_V_CHARGED" }
...@@ -97,13 +98,13 @@ Rectangle { ...@@ -97,13 +98,13 @@ Rectangle {
QGCLabel { QGCLabel {
text: "POWER CONFIG" text: "POWER CONFIG"
font.pointSize: 20 * __screenTools.dpiFactor; font.pointSize: 20 * screenTools.dpiFactor;
} }
QGCLabel { QGCLabel {
text: "Battery" text: "Battery"
color: palette.text color: palette.text
font.pointSize: 20 * __screenTools.dpiFactor; font.pointSize: 20 * screenTools.dpiFactor;
} }
Rectangle { Rectangle {
...@@ -124,7 +125,7 @@ Rectangle { ...@@ -124,7 +125,7 @@ Rectangle {
spacing: 10 spacing: 10
Row { Row {
spacing: 10 spacing: 10
QGCLabel { text: "Number of Cells"; width: firstColumnWidth; anchors.baseline: cellsField.baseline} QGCLabel { text: "Number of Cells (in Series)"; width: firstColumnWidth; anchors.baseline: cellsField.baseline}
FactTextField { FactTextField {
id: cellsField id: cellsField
width: textEditWidth width: textEditWidth
...@@ -171,6 +172,12 @@ Rectangle { ...@@ -171,6 +172,12 @@ Rectangle {
height: voltageCol.height height: voltageCol.height
width: 40 width: 40
antialiasing: true antialiasing: true
Connections {
target: screenTools
onRepaintRequestedChanged: {
arrows.requestPaint();
}
}
onPaint: { onPaint: {
var y0 = voltageCol.mapFromItem(battHigh, 0, battHigh.height / 2).y; var y0 = voltageCol.mapFromItem(battHigh, 0, battHigh.height / 2).y;
var y1 = voltageCol.mapFromItem(battLow, 0, battLow.height / 2).y; var y1 = voltageCol.mapFromItem(battLow, 0, battLow.height / 2).y;
...@@ -201,12 +208,12 @@ Rectangle { ...@@ -201,12 +208,12 @@ Rectangle {
text: "Battery Max:" text: "Battery Max:"
color: palette.text color: palette.text
width: 80 width: 80
font.pointSize: 12 * __screenTools.dpiFactor; font.pointSize: 12 * screenTools.dpiFactor;
} }
QGCLabel { QGCLabel {
text: (battNumCells.value * battHighVolt.value).toFixed(1) + ' V' text: (battNumCells.value * battHighVolt.value).toFixed(1) + ' V'
color: palette.text color: palette.text
font.pointSize: 12 * __screenTools.dpiFactor; font.pointSize: 12 * screenTools.dpiFactor;
} }
} }
Row { Row {
...@@ -215,12 +222,12 @@ Rectangle { ...@@ -215,12 +222,12 @@ Rectangle {
text: "Battery Min:" text: "Battery Min:"
color: palette.text color: palette.text
width: 80 width: 80
font.pointSize: 12 * __screenTools.dpiFactor; font.pointSize: 12 * screenTools.dpiFactor;
} }
QGCLabel { QGCLabel {
text: (battNumCells.value * battLowVolt.value).toFixed(1) + ' V' text: (battNumCells.value * battLowVolt.value).toFixed(1) + ' V'
color: palette.text color: palette.text
font.pointSize: 12 * __screenTools.dpiFactor; font.pointSize: 12 * screenTools.dpiFactor;
} }
} }
} }
...@@ -238,7 +245,7 @@ Rectangle { ...@@ -238,7 +245,7 @@ Rectangle {
QGCLabel { QGCLabel {
text: "Propeller Function" text: "Propeller Function"
color: palette.text color: palette.text
font.pointSize: 20 * __screenTools.dpiFactor; font.pointSize: 20 * screenTools.dpiFactor;
} }
Rectangle { Rectangle {
width: parent.width width: parent.width
...@@ -252,7 +259,7 @@ Rectangle { ...@@ -252,7 +259,7 @@ Rectangle {
QGCLabel { QGCLabel {
text: "Magnetometer Distortion" text: "Magnetometer Distortion"
color: palette.text color: palette.text
font.pointSize: 20 * __screenTools.dpiFactor; font.pointSize: 20 * screenTools.dpiFactor;
} }
Rectangle { Rectangle {
width: parent.width width: parent.width
......
...@@ -39,5 +39,10 @@ ScreenTools::ScreenTools() ...@@ -39,5 +39,10 @@ ScreenTools::ScreenTools()
} else { } else {
qWarning() << "System not reporting logical DPI, which is used to compute the appropriate font size. The default being used is 96dpi. If the text within buttons and UI elements are too big or too small, that's the reason."; qWarning() << "System not reporting logical DPI, which is used to compute the appropriate font size. The default being used is 96dpi. If the text within buttons and UI elements are too big or too small, that's the reason.";
} }
connect(MainWindow::instance(), &MainWindow::repaintCanvas, this, &ScreenTools::_updateCanvas);
} }
void ScreenTools::_updateCanvas()
{
emit repaintRequestedChanged();
}
...@@ -41,12 +41,19 @@ public: ...@@ -41,12 +41,19 @@ public:
Q_PROPERTY(double dpiFactor READ dpiFactor CONSTANT) Q_PROPERTY(double dpiFactor READ dpiFactor CONSTANT)
Q_PROPERTY(int mouseX READ mouseX) Q_PROPERTY(int mouseX READ mouseX)
Q_PROPERTY(int mouseY READ mouseY) Q_PROPERTY(int mouseY READ mouseY)
Q_PROPERTY(bool repaintRequested READ repaintRequested NOTIFY repaintRequestedChanged)
double screenDPI(void) { return _dotsPerInch; } double screenDPI () { return _dotsPerInch; }
double dpiFactor(void) { return _dpiFactor; } double dpiFactor () { return _dpiFactor; }
int mouseX () { return QCursor::pos().x(); }
int mouseY () { return QCursor::pos().y(); }
bool repaintRequested () { return true; }
int mouseX(void) { return QCursor::pos().x(); } signals:
int mouseY(void) { return QCursor::pos().y(); } void repaintRequestedChanged();
private slots:
void _updateCanvas();
private: private:
double _dotsPerInch; double _dotsPerInch;
......
...@@ -947,7 +947,7 @@ void MainWindow::connectCommonActions() ...@@ -947,7 +947,7 @@ void MainWindow::connectCommonActions()
connect(_ui.actionSimulate, SIGNAL(triggered(bool)), this, SLOT(simulateLink(bool))); connect(_ui.actionSimulate, SIGNAL(triggered(bool)), this, SLOT(simulateLink(bool)));
// Update Tool Bar // Update Tool Bar
_mainToolBar->setCurrentView((MainToolBar::ViewType_t)_currentView); _mainToolBar->setCurrentView(_currentView);
} }
void MainWindow::_openUrl(const QString& url, const QString& errorMessage) void MainWindow::_openUrl(const QString& url, const QString& errorMessage)
...@@ -1173,6 +1173,10 @@ void MainWindow::_loadCurrentViewState(void) ...@@ -1173,6 +1173,10 @@ void MainWindow::_loadCurrentViewState(void)
// HIL dock widget are dynamic and don't take part in the saved window state, so this // HIL dock widget are dynamic and don't take part in the saved window state, so this
// need to happen after we restore state // need to happen after we restore state
_showHILConfigurationWidgets(); _showHILConfigurationWidgets();
// There is a bug in Qt where a Canvas element inside a QQuickWidget does not
// receive update requests. Here we emit a signal for them to get repainted.
emit repaintCanvas();
} }
void MainWindow::_hideAllHilDockWidgets(void) void MainWindow::_hideAllHilDockWidgets(void)
...@@ -1372,22 +1376,3 @@ void MainWindow::_showQmlTestWidget(void) ...@@ -1372,22 +1376,3 @@ void MainWindow::_showQmlTestWidget(void)
new QmlTestWidget(); new QmlTestWidget();
} }
#endif #endif
// There is a bug in Qt where a Canvas element inside a QQuickWidget does not
// receive update requests. We hook into this event and notify the tool bar
// to update its canvas elements. If other QQuickWidgets start using Canvas
// and this bug is not fixed, this should be turned into a signal emited by
// MainWindow and the various QQuickWidgets that need it should connect to it.
bool MainWindow::event(QEvent* e)
{
bool result = true;
switch (e->type()) {
case QEvent::Paint:
result = QMainWindow::event(e);
_mainToolBar->updateCanvas();
return result;
default:
break;
}
return QMainWindow::event(e);
}
...@@ -205,6 +205,8 @@ signals: ...@@ -205,6 +205,8 @@ signals:
void initStatusChanged(const QString& message, int alignment, const QColor &color); void initStatusChanged(const QString& message, int alignment, const QColor &color);
/** Emitted when any value changes from any source */ /** Emitted when any value changes from any source */
void valueChanged(const int uasId, const QString& name, const QString& unit, const QVariant& value, const quint64 msec); void valueChanged(const int uasId, const QString& name, const QString& unit, const QVariant& value, const quint64 msec);
/** Emitted when any the Canvas elements within QML wudgets need updating */
void repaintCanvas();
#ifdef QGC_MOUSE_ENABLED_LINUX #ifdef QGC_MOUSE_ENABLED_LINUX
/** @brief Forward X11Event to catch 3DMouse inputs */ /** @brief Forward X11Event to catch 3DMouse inputs */
...@@ -219,8 +221,6 @@ public: ...@@ -219,8 +221,6 @@ public:
protected: protected:
bool event(QEvent *);
typedef enum _VIEW_SECTIONS typedef enum _VIEW_SECTIONS
{ {
VIEW_ENGINEER, // Engineering/Analyze view mode. Used for analyzing data and modifying onboard parameters VIEW_ENGINEER, // Engineering/Analyze view mode. Used for analyzing data and modifying onboard parameters
......
...@@ -30,8 +30,8 @@ This file is part of the QGROUNDCONTROL project ...@@ -30,8 +30,8 @@ This file is part of the QGROUNDCONTROL project
#include <QQmlContext> #include <QQmlContext>
#include <QQmlEngine> #include <QQmlEngine>
#include "MainWindow.h"
#include "MainToolBar.h" #include "MainToolBar.h"
#include "MainWindow.h"
#include "UASMessageHandler.h" #include "UASMessageHandler.h"
#include "UASMessageView.h" #include "UASMessageView.h"
...@@ -130,25 +130,25 @@ void MainToolBar::viewStateChanged(const QString &key, bool value) ...@@ -130,25 +130,25 @@ void MainToolBar::viewStateChanged(const QString &key, bool value)
void MainToolBar::onSetupView() void MainToolBar::onSetupView()
{ {
setCurrentView(ViewSetup); setCurrentView(MainWindow::VIEW_SETUP);
MainWindow::instance()->loadSetupView(); MainWindow::instance()->loadSetupView();
} }
void MainToolBar::onPlanView() void MainToolBar::onPlanView()
{ {
setCurrentView(ViewPlan); setCurrentView(MainWindow::VIEW_MISSION);
MainWindow::instance()->loadOperatorView(); MainWindow::instance()->loadOperatorView();
} }
void MainToolBar::onFlyView() void MainToolBar::onFlyView()
{ {
setCurrentView(ViewFly); setCurrentView(MainWindow::VIEW_FLIGHT);
MainWindow::instance()->loadPilotView(); MainWindow::instance()->loadPilotView();
} }
void MainToolBar::onAnalyzeView() void MainToolBar::onAnalyzeView()
{ {
setCurrentView(ViewAnalyze); setCurrentView(MainWindow::VIEW_ENGINEER);
MainWindow::instance()->loadEngineerView(); MainWindow::instance()->loadEngineerView();
} }
...@@ -647,8 +647,3 @@ void MainToolBar::_setSatLoc(UASInterface*, int fix) ...@@ -647,8 +647,3 @@ void MainToolBar::_setSatLoc(UASInterface*, int fix)
emit satelliteLockChanged(_satelliteLock); emit satelliteLockChanged(_satelliteLock);
} }
} }
void MainToolBar::updateCanvas()
{
emit repaintRequestedChanged();
}
...@@ -97,7 +97,6 @@ public: ...@@ -97,7 +97,6 @@ public:
Q_PROPERTY(bool showMav READ showMav NOTIFY showMavChanged) Q_PROPERTY(bool showMav READ showMav NOTIFY showMavChanged)
Q_PROPERTY(bool showMessages READ showMessages NOTIFY showMessagesChanged) Q_PROPERTY(bool showMessages READ showMessages NOTIFY showMessagesChanged)
Q_PROPERTY(bool showBattery READ showBattery NOTIFY showBatteryChanged) Q_PROPERTY(bool showBattery READ showBattery NOTIFY showBatteryChanged)
Q_PROPERTY(bool repaintRequested READ repaintRequested NOTIFY repaintRequestedChanged)
int connectionCount () { return _connectionCount; } int connectionCount () { return _connectionCount; }
double batteryVoltage () { return _batteryVoltage; } double batteryVoltage () { return _batteryVoltage; }
...@@ -121,11 +120,9 @@ public: ...@@ -121,11 +120,9 @@ public:
bool showMav () { return _showMav; } bool showMav () { return _showMav; }
bool showMessages () { return _showMessages; } bool showMessages () { return _showMessages; }
bool showBattery () { return _showBattery; } bool showBattery () { return _showBattery; }
bool repaintRequested () { return true; }
void setCurrentView (int currentView); void setCurrentView (int currentView);
void viewStateChanged (const QString& key, bool value); void viewStateChanged (const QString& key, bool value);
void updateCanvas ();
signals: signals:
void connectionCountChanged (int count); void connectionCountChanged (int count);
...@@ -150,7 +147,6 @@ signals: ...@@ -150,7 +147,6 @@ signals:
void showMavChanged (bool value); void showMavChanged (bool value);
void showMessagesChanged (bool value); void showMessagesChanged (bool value);
void showBatteryChanged (bool value); void showBatteryChanged (bool value);
void repaintRequestedChanged ();
private slots: private slots:
void _setActiveUAS (UASInterface* active); void _setActiveUAS (UASInterface* active);
......
...@@ -40,7 +40,8 @@ import QGroundControl.ScreenTools 1.0 ...@@ -40,7 +40,8 @@ import QGroundControl.ScreenTools 1.0
Rectangle { Rectangle {
property var qgcPal: QGCPalette { id: palette; colorGroupEnabled: true } property var qgcPal: QGCPalette { id: palette; colorGroupEnabled: true }
property ScreenTools __screenTools: ScreenTools { } property ScreenTools screenTools: ScreenTools { }
property int cellSpacerSize: 4 property int cellSpacerSize: 4
property int cellHeight: 30 property int cellHeight: 30
property int cellRadius: 3 property int cellRadius: 3
...@@ -134,9 +135,8 @@ Rectangle { ...@@ -134,9 +135,8 @@ Rectangle {
height: cellHeight height: cellHeight
spacing: -12 spacing: -12
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
Connections { Connections {
target: mainToolBar target: screenTools
onRepaintRequestedChanged: { onRepaintRequestedChanged: {
setupButton.repaintChevron = true; setupButton.repaintChevron = true;
planButton.repaintChevron = true; planButton.repaintChevron = true;
...@@ -241,7 +241,7 @@ Rectangle { ...@@ -241,7 +241,7 @@ Rectangle {
Text { Text {
id: messageText id: messageText
text: (mainToolBar.messageCount > 0) ? mainToolBar.messageCount : '' text: (mainToolBar.messageCount > 0) ? mainToolBar.messageCount : ''
font.pointSize: 14 * __screenTools.dpiFactor font.pointSize: 14 * screenTools.dpiFactor
font.weight: Font.DemiBold font.weight: Font.DemiBold
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
...@@ -329,7 +329,7 @@ Rectangle { ...@@ -329,7 +329,7 @@ Rectangle {
Text { Text {
id: satelitteText id: satelitteText
text: (mainToolBar.satelliteCount > 0) ? mainToolBar.satelliteCount : '' text: (mainToolBar.satelliteCount > 0) ? mainToolBar.satelliteCount : ''
font.pointSize: 14 * __screenTools.dpiFactor font.pointSize: 14 * screenTools.dpiFactor
font.weight: Font.DemiBold font.weight: Font.DemiBold
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right anchors.right: parent.right
...@@ -364,7 +364,7 @@ Rectangle { ...@@ -364,7 +364,7 @@ Rectangle {
Text { Text {
id: batteryText id: batteryText
text: mainToolBar.batteryVoltage.toFixed(1) + ' V'; text: mainToolBar.batteryVoltage.toFixed(1) + ' V';
font.pointSize: 14 * __screenTools.dpiFactor font.pointSize: 14 * screenTools.dpiFactor
font.weight: Font.DemiBold font.weight: Font.DemiBold
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right anchors.right: parent.right
...@@ -392,7 +392,7 @@ Rectangle { ...@@ -392,7 +392,7 @@ Rectangle {
Text { Text {
id: armedStatusText id: armedStatusText
text: (mainToolBar.systemArmed) ? qsTr("ARMED") : qsTr("DISARMED") text: (mainToolBar.systemArmed) ? qsTr("ARMED") : qsTr("DISARMED")
font.pointSize: 12 * __screenTools.dpiFactor font.pointSize: 12 * screenTools.dpiFactor
font.weight: Font.DemiBold font.weight: Font.DemiBold
anchors.centerIn: parent anchors.centerIn: parent
color: (mainToolBar.systemArmed) ? colorOrangeText : colorGreenText color: (mainToolBar.systemArmed) ? colorOrangeText : colorGreenText
...@@ -411,7 +411,7 @@ Rectangle { ...@@ -411,7 +411,7 @@ Rectangle {
Text { Text {
id: stateStatusText id: stateStatusText
text: mainToolBar.currentState text: mainToolBar.currentState
font.pointSize: 12 * __screenTools.dpiFactor font.pointSize: 12 * screenTools.dpiFactor
font.weight: Font.DemiBold font.weight: Font.DemiBold
anchors.centerIn: parent anchors.centerIn: parent
color: (mainToolBar.currentState === "STANDBY") ? colorGreenText : colorRedText color: (mainToolBar.currentState === "STANDBY") ? colorGreenText : colorRedText
...@@ -432,7 +432,7 @@ Rectangle { ...@@ -432,7 +432,7 @@ Rectangle {
Text { Text {
id: modeStatusText id: modeStatusText
text: mainToolBar.currentMode text: mainToolBar.currentMode
font.pointSize: 12 * __screenTools.dpiFactor font.pointSize: 12 * screenTools.dpiFactor
font.weight: Font.DemiBold font.weight: Font.DemiBold
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
...@@ -453,7 +453,7 @@ Rectangle { ...@@ -453,7 +453,7 @@ Rectangle {
Text { Text {
id: connectionStatusText id: connectionStatusText
text: qsTr("CONNECTION LOST") text: qsTr("CONNECTION LOST")
font.pointSize: 14 * __screenTools.dpiFactor font.pointSize: 14 * screenTools.dpiFactor
font.weight: Font.DemiBold font.weight: Font.DemiBold
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment