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 @@
<short_desc>Number of cells</short_desc>
<long_desc>Defines the number of cells the attached battery consists of.</long_desc>
<default>3</default>
<unit>S</unit>
</parameter>
<parameter name="BAT_CAPACITY" type="FLOAT">
<short_desc>Battery capacity</short_desc>
......
......@@ -38,13 +38,14 @@ import QGroundControl.ScreenTools 1.0
Rectangle {
QGCPalette { id: palette; colorGroupEnabled: true }
id: powerSettings
width: 600
height: 600
color: palette.window
property int firstColumnWidth: 220
property int textEditWidth: 60
property ScreenTools __screenTools: ScreenTools { }
property ScreenTools screenTools: ScreenTools { }
property Fact battNumCells: Fact { name: "BAT_N_CELLS" }
property Fact battHighVolt: Fact { name: "BAT_V_CHARGED" }
......@@ -97,13 +98,13 @@ Rectangle {
QGCLabel {
text: "POWER CONFIG"
font.pointSize: 20 * __screenTools.dpiFactor;
font.pointSize: 20 * screenTools.dpiFactor;
}
QGCLabel {
text: "Battery"
color: palette.text
font.pointSize: 20 * __screenTools.dpiFactor;
font.pointSize: 20 * screenTools.dpiFactor;
}
Rectangle {
......@@ -124,7 +125,7 @@ Rectangle {
spacing: 10
Row {
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 {
id: cellsField
width: textEditWidth
......@@ -171,6 +172,12 @@ Rectangle {
height: voltageCol.height
width: 40
antialiasing: true
Connections {
target: screenTools
onRepaintRequestedChanged: {
arrows.requestPaint();
}
}
onPaint: {
var y0 = voltageCol.mapFromItem(battHigh, 0, battHigh.height / 2).y;
var y1 = voltageCol.mapFromItem(battLow, 0, battLow.height / 2).y;
......@@ -201,12 +208,12 @@ Rectangle {
text: "Battery Max:"
color: palette.text
width: 80
font.pointSize: 12 * __screenTools.dpiFactor;
font.pointSize: 12 * screenTools.dpiFactor;
}
QGCLabel {
text: (battNumCells.value * battHighVolt.value).toFixed(1) + ' V'
color: palette.text
font.pointSize: 12 * __screenTools.dpiFactor;
font.pointSize: 12 * screenTools.dpiFactor;
}
}
Row {
......@@ -215,12 +222,12 @@ Rectangle {
text: "Battery Min:"
color: palette.text
width: 80
font.pointSize: 12 * __screenTools.dpiFactor;
font.pointSize: 12 * screenTools.dpiFactor;
}
QGCLabel {
text: (battNumCells.value * battLowVolt.value).toFixed(1) + ' V'
color: palette.text
font.pointSize: 12 * __screenTools.dpiFactor;
font.pointSize: 12 * screenTools.dpiFactor;
}
}
}
......@@ -238,7 +245,7 @@ Rectangle {
QGCLabel {
text: "Propeller Function"
color: palette.text
font.pointSize: 20 * __screenTools.dpiFactor;
font.pointSize: 20 * screenTools.dpiFactor;
}
Rectangle {
width: parent.width
......@@ -252,7 +259,7 @@ Rectangle {
QGCLabel {
text: "Magnetometer Distortion"
color: palette.text
font.pointSize: 20 * __screenTools.dpiFactor;
font.pointSize: 20 * screenTools.dpiFactor;
}
Rectangle {
width: parent.width
......
......@@ -39,5 +39,10 @@ ScreenTools::ScreenTools()
} 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.";
}
connect(MainWindow::instance(), &MainWindow::repaintCanvas, this, &ScreenTools::_updateCanvas);
}
void ScreenTools::_updateCanvas()
{
emit repaintRequestedChanged();
}
......@@ -37,16 +37,23 @@ class ScreenTools : public QObject
public:
ScreenTools();
Q_PROPERTY(double screenDPI READ screenDPI CONSTANT)
Q_PROPERTY(double dpiFactor READ dpiFactor CONSTANT)
Q_PROPERTY(int mouseX READ mouseX)
Q_PROPERTY(int mouseY READ mouseY)
double screenDPI(void) { return _dotsPerInch; }
double dpiFactor(void) { return _dpiFactor; }
int mouseX(void) { return QCursor::pos().x(); }
int mouseY(void) { return QCursor::pos().y(); }
Q_PROPERTY(double screenDPI READ screenDPI CONSTANT)
Q_PROPERTY(double dpiFactor READ dpiFactor CONSTANT)
Q_PROPERTY(int mouseX READ mouseX)
Q_PROPERTY(int mouseY READ mouseY)
Q_PROPERTY(bool repaintRequested READ repaintRequested NOTIFY repaintRequestedChanged)
double screenDPI () { return _dotsPerInch; }
double dpiFactor () { return _dpiFactor; }
int mouseX () { return QCursor::pos().x(); }
int mouseY () { return QCursor::pos().y(); }
bool repaintRequested () { return true; }
signals:
void repaintRequestedChanged();
private slots:
void _updateCanvas();
private:
double _dotsPerInch;
......
......@@ -947,7 +947,7 @@ void MainWindow::connectCommonActions()
connect(_ui.actionSimulate, SIGNAL(triggered(bool)), this, SLOT(simulateLink(bool)));
// Update Tool Bar
_mainToolBar->setCurrentView((MainToolBar::ViewType_t)_currentView);
_mainToolBar->setCurrentView(_currentView);
}
void MainWindow::_openUrl(const QString& url, const QString& errorMessage)
......@@ -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
// need to happen after we restore state
_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)
......@@ -1372,22 +1376,3 @@ void MainWindow::_showQmlTestWidget(void)
new QmlTestWidget();
}
#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:
void initStatusChanged(const QString& message, int alignment, const QColor &color);
/** 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);
/** Emitted when any the Canvas elements within QML wudgets need updating */
void repaintCanvas();
#ifdef QGC_MOUSE_ENABLED_LINUX
/** @brief Forward X11Event to catch 3DMouse inputs */
......@@ -219,8 +221,6 @@ public:
protected:
bool event(QEvent *);
typedef enum _VIEW_SECTIONS
{
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
#include <QQmlContext>
#include <QQmlEngine>
#include "MainWindow.h"
#include "MainToolBar.h"
#include "MainWindow.h"
#include "UASMessageHandler.h"
#include "UASMessageView.h"
......@@ -130,25 +130,25 @@ void MainToolBar::viewStateChanged(const QString &key, bool value)
void MainToolBar::onSetupView()
{
setCurrentView(ViewSetup);
setCurrentView(MainWindow::VIEW_SETUP);
MainWindow::instance()->loadSetupView();
}
void MainToolBar::onPlanView()
{
setCurrentView(ViewPlan);
setCurrentView(MainWindow::VIEW_MISSION);
MainWindow::instance()->loadOperatorView();
}
void MainToolBar::onFlyView()
{
setCurrentView(ViewFly);
setCurrentView(MainWindow::VIEW_FLIGHT);
MainWindow::instance()->loadPilotView();
}
void MainToolBar::onAnalyzeView()
{
setCurrentView(ViewAnalyze);
setCurrentView(MainWindow::VIEW_ENGINEER);
MainWindow::instance()->loadEngineerView();
}
......@@ -647,8 +647,3 @@ void MainToolBar::_setSatLoc(UASInterface*, int fix)
emit satelliteLockChanged(_satelliteLock);
}
}
void MainToolBar::updateCanvas()
{
emit repaintRequestedChanged();
}
......@@ -97,7 +97,6 @@ public:
Q_PROPERTY(bool showMav READ showMav NOTIFY showMavChanged)
Q_PROPERTY(bool showMessages READ showMessages NOTIFY showMessagesChanged)
Q_PROPERTY(bool showBattery READ showBattery NOTIFY showBatteryChanged)
Q_PROPERTY(bool repaintRequested READ repaintRequested NOTIFY repaintRequestedChanged)
int connectionCount () { return _connectionCount; }
double batteryVoltage () { return _batteryVoltage; }
......@@ -121,11 +120,9 @@ public:
bool showMav () { return _showMav; }
bool showMessages () { return _showMessages; }
bool showBattery () { return _showBattery; }
bool repaintRequested () { return true; }
void setCurrentView (int currentView);
void viewStateChanged (const QString& key, bool value);
void updateCanvas ();
signals:
void connectionCountChanged (int count);
......@@ -150,7 +147,6 @@ signals:
void showMavChanged (bool value);
void showMessagesChanged (bool value);
void showBatteryChanged (bool value);
void repaintRequestedChanged ();
private slots:
void _setActiveUAS (UASInterface* active);
......
......@@ -40,7 +40,8 @@ import QGroundControl.ScreenTools 1.0
Rectangle {
property var qgcPal: QGCPalette { id: palette; colorGroupEnabled: true }
property ScreenTools __screenTools: ScreenTools { }
property ScreenTools screenTools: ScreenTools { }
property int cellSpacerSize: 4
property int cellHeight: 30
property int cellRadius: 3
......@@ -134,13 +135,12 @@ Rectangle {
height: cellHeight
spacing: -12
anchors.verticalCenter: parent.verticalCenter
Connections {
target: mainToolBar
target: screenTools
onRepaintRequestedChanged: {
setupButton.repaintChevron = true;
planButton.repaintChevron = true;
flyButton.repaintChevron = true;
setupButton.repaintChevron = true;
planButton.repaintChevron = true;
flyButton.repaintChevron = true;
analyzeButton.repaintChevron = true;
}
}
......@@ -241,7 +241,7 @@ Rectangle {
Text {
id: messageText
text: (mainToolBar.messageCount > 0) ? mainToolBar.messageCount : ''
font.pointSize: 14 * __screenTools.dpiFactor
font.pointSize: 14 * screenTools.dpiFactor
font.weight: Font.DemiBold
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
......@@ -329,7 +329,7 @@ Rectangle {
Text {
id: satelitteText
text: (mainToolBar.satelliteCount > 0) ? mainToolBar.satelliteCount : ''
font.pointSize: 14 * __screenTools.dpiFactor
font.pointSize: 14 * screenTools.dpiFactor
font.weight: Font.DemiBold
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
......@@ -364,7 +364,7 @@ Rectangle {
Text {
id: batteryText
text: mainToolBar.batteryVoltage.toFixed(1) + ' V';
font.pointSize: 14 * __screenTools.dpiFactor
font.pointSize: 14 * screenTools.dpiFactor
font.weight: Font.DemiBold
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
......@@ -392,7 +392,7 @@ Rectangle {
Text {
id: armedStatusText
text: (mainToolBar.systemArmed) ? qsTr("ARMED") : qsTr("DISARMED")
font.pointSize: 12 * __screenTools.dpiFactor
font.pointSize: 12 * screenTools.dpiFactor
font.weight: Font.DemiBold
anchors.centerIn: parent
color: (mainToolBar.systemArmed) ? colorOrangeText : colorGreenText
......@@ -411,7 +411,7 @@ Rectangle {
Text {
id: stateStatusText
text: mainToolBar.currentState
font.pointSize: 12 * __screenTools.dpiFactor
font.pointSize: 12 * screenTools.dpiFactor
font.weight: Font.DemiBold
anchors.centerIn: parent
color: (mainToolBar.currentState === "STANDBY") ? colorGreenText : colorRedText
......@@ -432,7 +432,7 @@ Rectangle {
Text {
id: modeStatusText
text: mainToolBar.currentMode
font.pointSize: 12 * __screenTools.dpiFactor
font.pointSize: 12 * screenTools.dpiFactor
font.weight: Font.DemiBold
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
......@@ -453,7 +453,7 @@ Rectangle {
Text {
id: connectionStatusText
text: qsTr("CONNECTION LOST")
font.pointSize: 14 * __screenTools.dpiFactor
font.pointSize: 14 * screenTools.dpiFactor
font.weight: Font.DemiBold
anchors.verticalCenter: parent.verticalCenter
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