From 7e4458df8e083c73611bb9dc80355762255a5978 Mon Sep 17 00:00:00 2001 From: dogmaphobic Date: Tue, 10 Mar 2015 11:39:24 -0400 Subject: [PATCH 1/4] Added code to handle point size fonts in all QML widgets. --- src/AutoPilotPlugins/PX4/FlightModesComponent.qml | 29 +++++++++- src/AutoPilotPlugins/PX4/SafetyComponent.qml | 35 ++++++++++-- src/AutoPilotPlugins/PX4/SensorsComponent.qml | 27 ++++++++- src/FactSystem/FactSystemTest.qml | 29 +++++++++- src/QmlControls/ScreenTools.cc | 2 +- src/QmlControls/ScreenTools.h | 67 +++++++++++++++++++++++ src/QmlControls/VehicleRotationCal.qml | 29 +++++++++- src/VehicleSetup/FirmwareUpgrade.qml | 27 ++++++++- src/VehicleSetup/VehicleSummary.qml | 27 ++++++++- 9 files changed, 257 insertions(+), 15 deletions(-) diff --git a/src/AutoPilotPlugins/PX4/FlightModesComponent.qml b/src/AutoPilotPlugins/PX4/FlightModesComponent.qml index ce09311..90bd701 100644 --- a/src/AutoPilotPlugins/PX4/FlightModesComponent.qml +++ b/src/AutoPilotPlugins/PX4/FlightModesComponent.qml @@ -1,3 +1,26 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2015 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL 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. + + QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see . + + ======================================================================*/ + import QtQuick 2.2 import QtQuick.Controls 1.2 import QtQuick.Controls.Styles 1.2 @@ -7,11 +30,13 @@ import QGroundControl.FactControls 1.0 import QGroundControl.Palette 1.0 import QGroundControl.Controls 1.0 import QGroundControl.Controllers 1.0 +import QGroundControl.ScreenTools 1.0 Item { Loader { property FlightModesComponentController controller: FlightModesComponentController { } property QGCPalette qgcPal: QGCPalette { colorGroupEnabled: true } + property ScreenTools screenTools: ScreenTools { } property bool loading: true anchors.fill: parent @@ -357,7 +382,7 @@ Item { QGCLabel { text: "FLIGHT MODES CONFIG" - font.pointSize: 20 + font.pointSize: 20 * screenTools.dpiFactor; } Item { height: 20; width: 10 } // spacer @@ -848,7 +873,7 @@ Item { QGCLabel { text: "FLIGHT MODES CONFIG" - font.pointSize: 20 + font.pointSize: 20 * screenTools.dpiFactor; } QGCLabel { diff --git a/src/AutoPilotPlugins/PX4/SafetyComponent.qml b/src/AutoPilotPlugins/PX4/SafetyComponent.qml index 3721300..a7ad9fd 100644 --- a/src/AutoPilotPlugins/PX4/SafetyComponent.qml +++ b/src/AutoPilotPlugins/PX4/SafetyComponent.qml @@ -1,3 +1,26 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2015 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL 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. + + QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see . + + ======================================================================*/ + import QtQuick 2.2 import QtQuick.Controls 1.2 import QtQuick.Controls.Styles 1.2 @@ -6,6 +29,7 @@ import QGroundControl.FactSystem 1.0 import QGroundControl.FactControls 1.0 import QGroundControl.Palette 1.0 import QGroundControl.Controls 1.0 +import QGroundControl.ScreenTools 1.0 Rectangle { QGCPalette { id: palette; colorGroupEnabled: true } @@ -14,6 +38,7 @@ Rectangle { height: 600 color: palette.window + property ScreenTools screenTools: ScreenTools { } property int flightLineWidth: 2 // width of lines for flight graphic property int loiterAltitudeColumnWidth: 180 // width of loiter altitude column property int shadedMargin: 20 // margin inset for shaded areas @@ -29,7 +54,7 @@ Rectangle { QGCLabel { text: "SAFETY CONFIG" - font.pointSize: 20 + font.pointSize: 20 * screenTools.dpiFactor; } Item { height: 20; width: 10 } // spacer @@ -37,7 +62,7 @@ Rectangle { //----------------------------------------------------------------- //-- Return Home Triggers - QGCLabel { text: "Triggers For Return Home"; color: palette.text; font.pointSize: 20 } + QGCLabel { text: "Triggers For Return Home"; color: palette.text; font.pointSize: 20 * screenTools.dpiFactor; } Item { height: 10; width: 10 } // spacer @@ -96,7 +121,7 @@ Rectangle { //----------------------------------------------------------------- //-- Return Home Settings - QGCLabel { text: "Return Home Settings"; font.pointSize: 20 } + QGCLabel { text: "Return Home Settings"; font.pointSize: 20 * screenTools.dpiFactor; } Item { height: 10; width: 10 } // spacer @@ -266,7 +291,7 @@ Rectangle { QGCLabel { property Fact fact: Fact { name: "NAV_RCL_OBC" } width: parent.width - font.pointSize: 14 + font.pointSize: 14 * screenTools.dpiFactor; text: "Warning: You have an advanced safety configuration set using the NAV_RCL_OBC parameter. The above settings may not apply."; visible: fact.value != 0 wrapMode: Text.Wrap @@ -274,7 +299,7 @@ Rectangle { QGCLabel { property Fact fact: Fact { name: "NAV_DLL_OBC" } width: parent.width - font.pointSize: 14 + font.pointSize: 14 * screenTools.dpiFactor; text: "Warning: You have an advanced safety configuration set using the NAV_DLL_OBC parameter. The above settings may not apply."; visible: fact.value != 0 wrapMode: Text.Wrap diff --git a/src/AutoPilotPlugins/PX4/SensorsComponent.qml b/src/AutoPilotPlugins/PX4/SensorsComponent.qml index ad81597..5b2bf64 100644 --- a/src/AutoPilotPlugins/PX4/SensorsComponent.qml +++ b/src/AutoPilotPlugins/PX4/SensorsComponent.qml @@ -1,3 +1,26 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2015 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL 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. + + QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see . + + ======================================================================*/ + import QtQuick 2.2 import QtQuick.Controls 1.2 import QtQuick.Controls.Styles 1.2 @@ -6,9 +29,11 @@ import QGroundControl.FactSystem 1.0 import QGroundControl.FactControls 1.0 import QGroundControl.Palette 1.0 import QGroundControl.Controls 1.0 +import QGroundControl.ScreenTools 1.0 Rectangle { property QGCPalette qgcPal: QGCPalette { colorGroupEnabled: true } + property ScreenTools screenTools: ScreenTools { } readonly property int rotationColumnWidth: 200 readonly property var rotations: [ @@ -62,7 +87,7 @@ Rectangle { QGCLabel { text: "SENSORS CONFIG" - font.pointSize: 20 + font.pointSize: 20 * screenTools.dpiFactor; } Item { height: 20; width: 10 } // spacer diff --git a/src/FactSystem/FactSystemTest.qml b/src/FactSystem/FactSystemTest.qml index 7693ada..9d8daed 100644 --- a/src/FactSystem/FactSystemTest.qml +++ b/src/FactSystem/FactSystemTest.qml @@ -1,16 +1,41 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2015 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL 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. + + QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see . + + ======================================================================*/ + import QtQuick 2.2 import QtQuick.Controls 1.2 import QGroundControl.FactSystem 1.0 +import QGroundControl.ScreenTools 1.0 Item { + property ScreenTools screenTools: ScreenTools { } TextInput { objectName: "testControl" Fact { id: fact; name: "RC_MAP_THROTTLE" } text: fact.value font.family: "Helvetica" - font.pointSize: 24 + font.pointSize: 24 * screenTools.dpiFactor; color: "red" focus: true onAccepted: { fact.value = text; } } -} \ No newline at end of file +} diff --git a/src/QmlControls/ScreenTools.cc b/src/QmlControls/ScreenTools.cc index 5501a0d..90611e0 100644 --- a/src/QmlControls/ScreenTools.cc +++ b/src/QmlControls/ScreenTools.cc @@ -32,7 +32,7 @@ ScreenTools::ScreenTools() , _dpiFactor( 72.0 / 96.0) { // Get screen DPI to manage font sizes on different platforms - QScreen *srn = QGuiApplication::screens().at(0); // TODO: Find current monitor as opposed to picking first one + QScreen *srn = QGuiApplication::primaryScreen(); if(srn && srn->logicalDotsPerInch() > 50.0) { _dotsPerInch = (double)srn->logicalDotsPerInch(); // Font point sizes are based on Mac 72dpi _dpiFactor = 72.0 / _dotsPerInch; diff --git a/src/QmlControls/ScreenTools.h b/src/QmlControls/ScreenTools.h index 839a877..c7d74ef 100644 --- a/src/QmlControls/ScreenTools.h +++ b/src/QmlControls/ScreenTools.h @@ -30,6 +30,19 @@ #include #include +/*! + @brief Screen helper tools for QML widgets + To use its functions, you need to import the module with the following line: + @code + import QGroundControl.ScreenTools 1.0 + @endcode + @remark As for the screen density functions, QtQuick provides the \c Screen type (defined in QtQuick.Window) + but as of Qt 5.4 (QtQuick.Window 2.2), this only works if the main window is QtQuick. As QGC is primarily + a Qt application and only some of its UI elements are QLM widgets, this does not work. Hence, these function + defined here. + @sa Screen QML Type +*/ + /// This Qml control is used to return screen parameters class ScreenTools : public QObject { @@ -37,10 +50,64 @@ class ScreenTools : public QObject public: ScreenTools(); + //! Returns the screen density in Dots Per Inch Q_PROPERTY(double screenDPI READ screenDPI CONSTANT) + //! Returns a factor used to calculate the font point size to use + /*! + When defining fonts in point size, as in: + @code + Text { + text: "Foo Bar" + font.pointSize: 14 + } + @endcode + The size is device dependent. If you define this based on a screen set to 72dpi (Mac OS), once + this is displayed on a different screen with a different pixel density, such as 96dpi (Windows), + the text will be displayed in the wrong size. + Use \c dpiFactor to accomodate for these differences. All font point sizes are given in 72dpi + and \c dpiFactor returns a factor to use for adjusting it to the current target screen. + @code + import QGroundControl.ScreenTools 1.0 + property ScreenTools screenTools: ScreenTools { } + Text { + text: "Foo Bar" + font.pointSize: 14 * screenTools.dpiFactor + } + @endcode + */ Q_PROPERTY(double dpiFactor READ dpiFactor CONSTANT) + //! Returns the global mouse X position Q_PROPERTY(int mouseX READ mouseX) + //! Returns the global mouse Y position Q_PROPERTY(int mouseY READ mouseY) + //! Used to trigger a \c Canvas element repaint. + /*! + There is a bug as of Qt 5.4 where a Canvas element defined within a QQuickWidget does not receive + repaint events. QGC's main window will emit these signals when a \c Canvas element needs to be + repainted. + If you use a \c Canvas element inside some QML widget, you can use this cod to handle repaint: + @code + import QGroundControl.ScreenTools 1.0 + ... + property ScreenTools screenTools: ScreenTools { } + ... + Canvas { + id: myCanvas + height: 40 + width: 40 + Connections { + target: screenTools + onRepaintRequestedChanged: { + myCanvas.requestPaint(); + } + } + onPaint: { + var context = getContext("2d"); + ... + } + } + @endcode + */ Q_PROPERTY(bool repaintRequested READ repaintRequested NOTIFY repaintRequestedChanged) double screenDPI () { return _dotsPerInch; } diff --git a/src/QmlControls/VehicleRotationCal.qml b/src/QmlControls/VehicleRotationCal.qml index b65a762..b287840 100644 --- a/src/QmlControls/VehicleRotationCal.qml +++ b/src/QmlControls/VehicleRotationCal.qml @@ -1,11 +1,36 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2015 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL 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. + + QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see . + + ======================================================================*/ + import QtQuick 2.2 import QtQuick.Controls 1.2 import QtQuick.Controls.Styles 1.2 import QGroundControl.Palette 1.0 +import QGroundControl.ScreenTools 1.0 Rectangle { property var __qgcPal: QGCPalette { colorGroupEnabled: enabled } + property ScreenTools screenTools: ScreenTools { } // Indicates whether calibration is valid for this control property bool calValid: false @@ -43,7 +68,7 @@ Rectangle { height: parent.height horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignBottom - font.pointSize: 25 + font.pointSize: 25 * screenTools.dpiFactor; font.bold: true color: "black" @@ -54,7 +79,7 @@ Rectangle { height: parent.height horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignBottom - font.pointSize: 25 + font.pointSize: 25 * screenTools.dpiFactor; color: calInProgress ? "yellow" : "white" text: parent.calText diff --git a/src/VehicleSetup/FirmwareUpgrade.qml b/src/VehicleSetup/FirmwareUpgrade.qml index 7401421..dfa2387 100644 --- a/src/VehicleSetup/FirmwareUpgrade.qml +++ b/src/VehicleSetup/FirmwareUpgrade.qml @@ -1,3 +1,26 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2015 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL 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. + + QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see . + + ======================================================================*/ + import QtQuick 2.3 import QtQuick.Controls 1.2 import QtQuick.Controls.Styles 1.2 @@ -6,12 +29,14 @@ import QGroundControl.Controls 1.0 import QGroundControl.FactControls 1.0 import QGroundControl.Palette 1.0 import QGroundControl.FirmwareUpgradeController 1.0 +import QGroundControl.ScreenTools 1.0 Rectangle { width: 600 height: 600 property var qgcPal: QGCPalette { colorGroupEnabled: true } + property ScreenTools screenTools: ScreenTools { } property FirmwareUpgradeController controller: FirmwareUpgradeController { upgradeButton: upgradeButton progressBar: progressBar @@ -26,7 +51,7 @@ Rectangle { QGCLabel { text: "FIRMWARE UPDATE" - font.pointSize: 20 + font.pointSize: 20 * screenTools.dpiFactor; } Item { diff --git a/src/VehicleSetup/VehicleSummary.qml b/src/VehicleSetup/VehicleSummary.qml index f9105eb..99323e2 100644 --- a/src/VehicleSetup/VehicleSummary.qml +++ b/src/VehicleSetup/VehicleSummary.qml @@ -1,3 +1,26 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2015 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL 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. + + QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see . + + ======================================================================*/ + import QtQuick 2.2 import QtQuick.Controls 1.2 import QtQuick.Controls.Styles 1.2 @@ -5,12 +28,14 @@ import QtQuick.Controls.Styles 1.2 import QGroundControl.FactSystem 1.0 import QGroundControl.Palette 1.0 import QGroundControl.Controls 1.0 +import QGroundControl.ScreenTools 1.0 Rectangle { width: 600 height: 400 property var qgcPal: QGCPalette { id: palette; colorGroupEnabled: true } + property ScreenTools screenTools: ScreenTools { } id: topLevel objectName: "topLevel" @@ -22,7 +47,7 @@ Rectangle { QGCLabel { text: "VEHICLE SUMMARY" - font.pointSize: 20 + font.pointSize: 20 * screenTools.dpiFactor; } Item { From a5bd07945b99d99e92431d3e967a9bfc841824e4 Mon Sep 17 00:00:00 2001 From: dogmaphobic Date: Tue, 10 Mar 2015 11:48:55 -0400 Subject: [PATCH 2/4] Fixing fishy typo... --- src/QmlControls/ScreenTools.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/QmlControls/ScreenTools.h b/src/QmlControls/ScreenTools.h index c7d74ef..39138d0 100644 --- a/src/QmlControls/ScreenTools.h +++ b/src/QmlControls/ScreenTools.h @@ -85,7 +85,7 @@ public: There is a bug as of Qt 5.4 where a Canvas element defined within a QQuickWidget does not receive repaint events. QGC's main window will emit these signals when a \c Canvas element needs to be repainted. - If you use a \c Canvas element inside some QML widget, you can use this cod to handle repaint: + If you use a \c Canvas element inside some QML widget, you can use this code to handle repaint: @code import QGroundControl.ScreenTools 1.0 ... From 9b6e5499fd640bef43be5067ceafb385428f95e0 Mon Sep 17 00:00:00 2001 From: dogmaphobic Date: Tue, 10 Mar 2015 12:30:02 -0400 Subject: [PATCH 3/4] Added convenience function to ScreenTools to compute appropriate font point size. --- src/AutoPilotPlugins/PX4/FlightModesComponent.qml | 4 ++-- src/AutoPilotPlugins/PX4/PowerComponent.qml | 16 ++++++++-------- src/AutoPilotPlugins/PX4/SafetyComponent.qml | 18 +++++++++--------- src/AutoPilotPlugins/PX4/SensorsComponent.qml | 2 +- src/FactSystem/FactSystemTest.qml | 2 +- src/QmlControls/ScreenTools.cc | 5 +++++ src/QmlControls/ScreenTools.h | 6 ++++++ src/QmlControls/VehicleRotationCal.qml | 4 ++-- src/VehicleSetup/FirmwareUpgrade.qml | 2 +- src/VehicleSetup/VehicleSummary.qml | 2 +- src/ui/toolbar/MainToolBar.qml | 14 +++++++------- 11 files changed, 43 insertions(+), 32 deletions(-) diff --git a/src/AutoPilotPlugins/PX4/FlightModesComponent.qml b/src/AutoPilotPlugins/PX4/FlightModesComponent.qml index 90bd701..d809205 100644 --- a/src/AutoPilotPlugins/PX4/FlightModesComponent.qml +++ b/src/AutoPilotPlugins/PX4/FlightModesComponent.qml @@ -382,7 +382,7 @@ Item { QGCLabel { text: "FLIGHT MODES CONFIG" - font.pointSize: 20 * screenTools.dpiFactor; + font.pointSize: screenTools.dpiAdjustedPointSize(20); } Item { height: 20; width: 10 } // spacer @@ -873,7 +873,7 @@ Item { QGCLabel { text: "FLIGHT MODES CONFIG" - font.pointSize: 20 * screenTools.dpiFactor; + font.pointSize: screenTools.dpiAdjustedPointSize(20); } QGCLabel { diff --git a/src/AutoPilotPlugins/PX4/PowerComponent.qml b/src/AutoPilotPlugins/PX4/PowerComponent.qml index 0fc64b1..06d242b 100644 --- a/src/AutoPilotPlugins/PX4/PowerComponent.qml +++ b/src/AutoPilotPlugins/PX4/PowerComponent.qml @@ -98,13 +98,13 @@ Rectangle { QGCLabel { text: "POWER CONFIG" - font.pointSize: 20 * screenTools.dpiFactor; + font.pointSize: screenTools.dpiAdjustedPointSize(20); } QGCLabel { text: "Battery" color: palette.text - font.pointSize: 20 * screenTools.dpiFactor; + font.pointSize: screenTools.dpiAdjustedPointSize(20); } Rectangle { @@ -208,12 +208,12 @@ Rectangle { text: "Battery Max:" color: palette.text width: 80 - font.pointSize: 12 * screenTools.dpiFactor; + font.pointSize: screenTools.dpiAdjustedPointSize(12); } QGCLabel { text: (battNumCells.value * battHighVolt.value).toFixed(1) + ' V' color: palette.text - font.pointSize: 12 * screenTools.dpiFactor; + font.pointSize: screenTools.dpiAdjustedPointSize(12); } } Row { @@ -222,12 +222,12 @@ Rectangle { text: "Battery Min:" color: palette.text width: 80 - font.pointSize: 12 * screenTools.dpiFactor; + font.pointSize: screenTools.dpiAdjustedPointSize(12); } QGCLabel { text: (battNumCells.value * battLowVolt.value).toFixed(1) + ' V' color: palette.text - font.pointSize: 12 * screenTools.dpiFactor; + font.pointSize: screenTools.dpiAdjustedPointSize(12); } } } @@ -245,7 +245,7 @@ Rectangle { QGCLabel { text: "Propeller Function" color: palette.text - font.pointSize: 20 * screenTools.dpiFactor; + font.pointSize: screenTools.dpiAdjustedPointSize(20); } Rectangle { width: parent.width @@ -259,7 +259,7 @@ Rectangle { QGCLabel { text: "Magnetometer Distortion" color: palette.text - font.pointSize: 20 * screenTools.dpiFactor; + font.pointSize: screenTools.dpiAdjustedPointSize(20); } Rectangle { width: parent.width diff --git a/src/AutoPilotPlugins/PX4/SafetyComponent.qml b/src/AutoPilotPlugins/PX4/SafetyComponent.qml index a7ad9fd..ecf3e8e 100644 --- a/src/AutoPilotPlugins/PX4/SafetyComponent.qml +++ b/src/AutoPilotPlugins/PX4/SafetyComponent.qml @@ -54,7 +54,7 @@ Rectangle { QGCLabel { text: "SAFETY CONFIG" - font.pointSize: 20 * screenTools.dpiFactor; + font.pointSize: screenTools.dpiAdjustedPointSize(20); } Item { height: 20; width: 10 } // spacer @@ -62,7 +62,7 @@ Rectangle { //----------------------------------------------------------------- //-- Return Home Triggers - QGCLabel { text: "Triggers For Return Home"; color: palette.text; font.pointSize: 20 * screenTools.dpiFactor; } + QGCLabel { text: "Triggers For Return Home"; color: palette.text; font.pointSize: screenTools.dpiAdjustedPointSize(20); } Item { height: 10; width: 10 } // spacer @@ -121,7 +121,7 @@ Rectangle { //----------------------------------------------------------------- //-- Return Home Settings - QGCLabel { text: "Return Home Settings"; font.pointSize: 20 * screenTools.dpiFactor; } + QGCLabel { text: "Return Home Settings"; font.pointSize: screenTools.dpiAdjustedPointSize(20); } Item { height: 10; width: 10 } // spacer @@ -273,12 +273,12 @@ Rectangle { QGCLabel { text: "Home loiter altitude"; color: palette.text; - enabled: homeLoiterCheckbox.checked == true + enabled: homeLoiterCheckbox.checked === true } FactTextField { id: descendField; fact: Fact { name: "RTL_DESCEND_ALT" } - enabled: homeLoiterCheckbox.checked == true + enabled: homeLoiterCheckbox.checked === true showUnits: true } } @@ -291,17 +291,17 @@ Rectangle { QGCLabel { property Fact fact: Fact { name: "NAV_RCL_OBC" } width: parent.width - font.pointSize: 14 * screenTools.dpiFactor; + font.pointSize: screenTools.dpiAdjustedPointSize(14); text: "Warning: You have an advanced safety configuration set using the NAV_RCL_OBC parameter. The above settings may not apply."; - visible: fact.value != 0 + visible: fact.value !== 0 wrapMode: Text.Wrap } QGCLabel { property Fact fact: Fact { name: "NAV_DLL_OBC" } width: parent.width - font.pointSize: 14 * screenTools.dpiFactor; + font.pointSize: screenTools.dpiAdjustedPointSize(14); text: "Warning: You have an advanced safety configuration set using the NAV_DLL_OBC parameter. The above settings may not apply."; - visible: fact.value != 0 + visible: fact.value !== 0 wrapMode: Text.Wrap } } diff --git a/src/AutoPilotPlugins/PX4/SensorsComponent.qml b/src/AutoPilotPlugins/PX4/SensorsComponent.qml index 5b2bf64..38bdb27 100644 --- a/src/AutoPilotPlugins/PX4/SensorsComponent.qml +++ b/src/AutoPilotPlugins/PX4/SensorsComponent.qml @@ -87,7 +87,7 @@ Rectangle { QGCLabel { text: "SENSORS CONFIG" - font.pointSize: 20 * screenTools.dpiFactor; + font.pointSize: screenTools.dpiAdjustedPointSize(20); } Item { height: 20; width: 10 } // spacer diff --git a/src/FactSystem/FactSystemTest.qml b/src/FactSystem/FactSystemTest.qml index 9d8daed..fa73164 100644 --- a/src/FactSystem/FactSystemTest.qml +++ b/src/FactSystem/FactSystemTest.qml @@ -33,7 +33,7 @@ Item { Fact { id: fact; name: "RC_MAP_THROTTLE" } text: fact.value font.family: "Helvetica" - font.pointSize: 24 * screenTools.dpiFactor; + font.pointSize: screenTools.dpiAdjustedPointSize(24); color: "red" focus: true onAccepted: { fact.value = text; } diff --git a/src/QmlControls/ScreenTools.cc b/src/QmlControls/ScreenTools.cc index 90611e0..dde82a1 100644 --- a/src/QmlControls/ScreenTools.cc +++ b/src/QmlControls/ScreenTools.cc @@ -42,6 +42,11 @@ ScreenTools::ScreenTools() connect(MainWindow::instance(), &MainWindow::repaintCanvas, this, &ScreenTools::_updateCanvas); } +qreal ScreenTools::dpiAdjustedPointSize(qreal pointSize) +{ + return pointSize * _dpiFactor; +} + void ScreenTools::_updateCanvas() { emit repaintRequestedChanged(); diff --git a/src/QmlControls/ScreenTools.h b/src/QmlControls/ScreenTools.h index 39138d0..8365b93 100644 --- a/src/QmlControls/ScreenTools.h +++ b/src/QmlControls/ScreenTools.h @@ -110,6 +110,12 @@ public: */ Q_PROPERTY(bool repaintRequested READ repaintRequested NOTIFY repaintRequestedChanged) + //! Utility for adjusting font point size. + /*! + @sa dpiFactor + */ + Q_INVOKABLE qreal dpiAdjustedPointSize(qreal pointSize); + double screenDPI () { return _dotsPerInch; } double dpiFactor () { return _dpiFactor; } int mouseX () { return QCursor::pos().x(); } diff --git a/src/QmlControls/VehicleRotationCal.qml b/src/QmlControls/VehicleRotationCal.qml index b287840..847b506 100644 --- a/src/QmlControls/VehicleRotationCal.qml +++ b/src/QmlControls/VehicleRotationCal.qml @@ -68,7 +68,7 @@ Rectangle { height: parent.height horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignBottom - font.pointSize: 25 * screenTools.dpiFactor; + font.pointSize: screenTools.dpiAdjustedPointSize(25); font.bold: true color: "black" @@ -79,7 +79,7 @@ Rectangle { height: parent.height horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignBottom - font.pointSize: 25 * screenTools.dpiFactor; + font.pointSize: screenTools.dpiAdjustedPointSize(25); color: calInProgress ? "yellow" : "white" text: parent.calText diff --git a/src/VehicleSetup/FirmwareUpgrade.qml b/src/VehicleSetup/FirmwareUpgrade.qml index dfa2387..3315f46 100644 --- a/src/VehicleSetup/FirmwareUpgrade.qml +++ b/src/VehicleSetup/FirmwareUpgrade.qml @@ -51,7 +51,7 @@ Rectangle { QGCLabel { text: "FIRMWARE UPDATE" - font.pointSize: 20 * screenTools.dpiFactor; + font.pointSize: screenTools.dpiAdjustedPointSize(20); } Item { diff --git a/src/VehicleSetup/VehicleSummary.qml b/src/VehicleSetup/VehicleSummary.qml index 99323e2..d760a5d 100644 --- a/src/VehicleSetup/VehicleSummary.qml +++ b/src/VehicleSetup/VehicleSummary.qml @@ -47,7 +47,7 @@ Rectangle { QGCLabel { text: "VEHICLE SUMMARY" - font.pointSize: 20 * screenTools.dpiFactor; + font.pointSize: screenTools.dpiAdjustedPointSize(20); } Item { diff --git a/src/ui/toolbar/MainToolBar.qml b/src/ui/toolbar/MainToolBar.qml index 5f39ea2..b52ac3c 100644 --- a/src/ui/toolbar/MainToolBar.qml +++ b/src/ui/toolbar/MainToolBar.qml @@ -241,7 +241,7 @@ Rectangle { Text { id: messageText text: (mainToolBar.messageCount > 0) ? mainToolBar.messageCount : '' - font.pointSize: 14 * screenTools.dpiFactor + font.pointSize: screenTools.dpiAdjustedPointSize(14); 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: screenTools.dpiAdjustedPointSize(14); 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: screenTools.dpiAdjustedPointSize(14); 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: screenTools.dpiAdjustedPointSize(12); 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: screenTools.dpiAdjustedPointSize(12); 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: screenTools.dpiAdjustedPointSize(12); 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: screenTools.dpiAdjustedPointSize(14); font.weight: Font.DemiBold anchors.verticalCenter: parent.verticalCenter anchors.horizontalCenter: parent.horizontalCenter From 7afa27d4adbb802b07b4c293018a819b79564e63 Mon Sep 17 00:00:00 2001 From: dogmaphobic Date: Tue, 10 Mar 2015 14:42:24 -0400 Subject: [PATCH 4/4] Removed font sizing from unit test control as I don't know how it behaves without a visible window. --- src/FactSystem/FactSystemTest.qml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/FactSystem/FactSystemTest.qml b/src/FactSystem/FactSystemTest.qml index fa73164..29048fb 100644 --- a/src/FactSystem/FactSystemTest.qml +++ b/src/FactSystem/FactSystemTest.qml @@ -24,16 +24,14 @@ import QtQuick 2.2 import QtQuick.Controls 1.2 import QGroundControl.FactSystem 1.0 -import QGroundControl.ScreenTools 1.0 Item { - property ScreenTools screenTools: ScreenTools { } TextInput { objectName: "testControl" Fact { id: fact; name: "RC_MAP_THROTTLE" } text: fact.value font.family: "Helvetica" - font.pointSize: screenTools.dpiAdjustedPointSize(24); + font.pointSize: 24; color: "red" focus: true onAccepted: { fact.value = text; }