diff --git a/src/AutoPilotPlugins/PX4/PowerComponent.qml b/src/AutoPilotPlugins/PX4/PowerComponent.qml index 592812b..5b75d31 100644 --- a/src/AutoPilotPlugins/PX4/PowerComponent.qml +++ b/src/AutoPilotPlugins/PX4/PowerComponent.qml @@ -197,12 +197,10 @@ Rectangle { text: "Battery Max:" color: palette.text width: 80 - font.pointSize: screenTools.dpiAdjustedPointSize(12); } QGCLabel { text: (battNumCells.value * battHighVolt.value).toFixed(1) + ' V' color: palette.text - font.pointSize: screenTools.dpiAdjustedPointSize(12); } } Row { @@ -211,12 +209,10 @@ Rectangle { text: "Battery Min:" color: palette.text width: 80 - font.pointSize: screenTools.dpiAdjustedPointSize(12); } QGCLabel { text: (battNumCells.value * battLowVolt.value).toFixed(1) + ' V' color: palette.text - font.pointSize: screenTools.dpiAdjustedPointSize(12); } } } diff --git a/src/QmlControls/QGCButton.qml b/src/QmlControls/QGCButton.qml index 19a76ff..8a5a386 100644 --- a/src/QmlControls/QGCButton.qml +++ b/src/QmlControls/QGCButton.qml @@ -103,10 +103,13 @@ Button { } Text { - id: text - renderType: Text.NativeRendering + id: text + renderType: Text.NativeRendering + text: control.text + font.pointSize: __qgcPal.dpiAdjustedDefaultFontPointSize + anchors.verticalCenter: parent.verticalCenter - text: control.text + color: __showHighlight ? control.__qgcPal.buttonHighlightText : (primary ? control.__qgcPal.primaryButtonText : control.__qgcPal.buttonText) diff --git a/src/QmlControls/QGCCheckBox.qml b/src/QmlControls/QGCCheckBox.qml index 356c4dd..4ce79c9 100644 --- a/src/QmlControls/QGCCheckBox.qml +++ b/src/QmlControls/QGCCheckBox.qml @@ -25,9 +25,12 @@ CheckBox { opacity: 0.6 } Text { - id: text - text: control.text + id: text + text: control.text + font.pointSize: __qgcPal.dpiAdjustedDefaultFontPointSize + anchors.centerIn: parent + color: control.__qgcPal.text } } diff --git a/src/QmlControls/QGCComboBox.qml b/src/QmlControls/QGCComboBox.qml index a8f3555..7624bef 100644 --- a/src/QmlControls/QGCComboBox.qml +++ b/src/QmlControls/QGCComboBox.qml @@ -11,6 +11,7 @@ ComboBox { property bool __showHighlight: pressed | hovered style: ComboBoxStyle { + font.pointSize: __qgcPal.dpiAdjustedDefaultFontPointSize textColor: __showHighlight ? control.__qgcPal.buttonHighlightText : control.__qgcPal.buttonText diff --git a/src/QmlControls/QGCLabel.qml b/src/QmlControls/QGCLabel.qml index 2afa5cd..bb09625 100644 --- a/src/QmlControls/QGCLabel.qml +++ b/src/QmlControls/QGCLabel.qml @@ -5,8 +5,10 @@ import QtQuick.Controls.Styles 1.2 import QGroundControl.Palette 1.0 Text { - property var __palette: QGCPalette { colorGroupEnabled: enabled } + QGCPalette { id: __qgcPal; colorGroupEnabled: enabled } + property bool enabled: true - color: __palette.text + font.pointSize: __qgcPal.dpiAdjustedDefaultFontPointSize + color: __qgcPal.text } diff --git a/src/QmlControls/QGCRadioButton.qml b/src/QmlControls/QGCRadioButton.qml index f1f9b86..ac23c53 100644 --- a/src/QmlControls/QGCRadioButton.qml +++ b/src/QmlControls/QGCRadioButton.qml @@ -25,9 +25,12 @@ RadioButton { opacity: 0.6 } Text { - id: text - text: control.text + id: text + text: control.text + font.pointSize: __qgcPal.dpiAdjustedDefaultFontPointSize + anchors.centerIn: parent + color: control.__qgcPal.text } } diff --git a/src/QmlControls/QGCTextField.qml b/src/QmlControls/QGCTextField.qml index 0b5dec2..cc10fed 100644 --- a/src/QmlControls/QGCTextField.qml +++ b/src/QmlControls/QGCTextField.qml @@ -49,6 +49,8 @@ TextField { width: unitsLabelWidthGenerator.width text: control.unitsLabel + font.pointSize: __qgcPal.dpiAdjustedDefaultFontPointSize + color: control.textColor visible: control.showUnits } diff --git a/src/QmlControls/QGCToolBarButton.qml b/src/QmlControls/QGCToolBarButton.qml index 0bfa181..e4b5ff1 100644 --- a/src/QmlControls/QGCToolBarButton.qml +++ b/src/QmlControls/QGCToolBarButton.qml @@ -53,6 +53,7 @@ QGCButton { } label: Label { text: button.text + font.pointSize: __qgcPal.dpiAdjustedDefaultFontPointSize horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter color: showHighlight ? __qgcPal.buttonHighlightText : (button.checked ? __qgcPal.primaryButtonText : __qgcPal.buttonText) diff --git a/src/QmlControls/ScreenTools.cc b/src/QmlControls/ScreenTools.cc index dde82a1..b707734 100644 --- a/src/QmlControls/ScreenTools.cc +++ b/src/QmlControls/ScreenTools.cc @@ -27,26 +27,45 @@ #include "ScreenTools.h" #include "MainWindow.h" +#include +#include + +bool ScreenTools::_dpiFactorSet = false; +double ScreenTools::_dotsPerInch = 96.0; +double ScreenTools::_dpiFactor = 72.0 / 96.0; + ScreenTools::ScreenTools() - : _dotsPerInch(96.0) - , _dpiFactor( 72.0 / 96.0) { - // Get screen DPI to manage font sizes on different platforms - 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; - } 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); } qreal ScreenTools::dpiAdjustedPointSize(qreal pointSize) { + return dpiAdjustedPointSize_s(pointSize); +} + +qreal ScreenTools::dpiAdjustedPointSize_s(qreal pointSize) +{ + _setDpiFactor(); return pointSize * _dpiFactor; } +void ScreenTools::_setDpiFactor(void) +{ + if (!_dpiFactorSet) { + _dpiFactorSet = true; + + // Get screen DPI to manage font sizes on different platforms + 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; + } 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."; + } + } +} + void ScreenTools::_updateCanvas() { emit repaintRequestedChanged(); diff --git a/src/QmlControls/ScreenTools.h b/src/QmlControls/ScreenTools.h index 8365b93..0f376f3 100644 --- a/src/QmlControls/ScreenTools.h +++ b/src/QmlControls/ScreenTools.h @@ -116,6 +116,9 @@ public: */ Q_INVOKABLE qreal dpiAdjustedPointSize(qreal pointSize); + /// Static version of dpiAdjustedPointSize of use in C++ code + static qreal dpiAdjustedPointSize_s(qreal pointSize); + double screenDPI () { return _dotsPerInch; } double dpiFactor () { return _dpiFactor; } int mouseX () { return QCursor::pos().x(); } @@ -129,9 +132,11 @@ private slots: void _updateCanvas(); private: - double _dotsPerInch; - double _dpiFactor; - + static void _setDpiFactor(void); + + static bool _dpiFactorSet; + static double _dotsPerInch; + static double _dpiFactor; }; #endif diff --git a/src/QmlControls/SubMenuButton.qml b/src/QmlControls/SubMenuButton.qml index 5282d3d..f77168f 100644 --- a/src/QmlControls/SubMenuButton.qml +++ b/src/QmlControls/SubMenuButton.qml @@ -39,7 +39,7 @@ Button { horizontalAlignment: TextEdit.AlignHCenter text: control.text - font.pixelSize: 12 + font.pointSize: __qgcPal.dpiAdjustedDefaultFontPointSize color: __showHighlight ? __qgcPal.buttonHighlightText : __qgcPal.buttonText Rectangle { diff --git a/src/QmlControls/VehicleRotationCal.qml b/src/QmlControls/VehicleRotationCal.qml index 847b506..47b1729 100644 --- a/src/QmlControls/VehicleRotationCal.qml +++ b/src/QmlControls/VehicleRotationCal.qml @@ -30,7 +30,7 @@ import QGroundControl.ScreenTools 1.0 Rectangle { property var __qgcPal: QGCPalette { colorGroupEnabled: enabled } - property ScreenTools screenTools: ScreenTools { } + property ScreenTools __screenTools: ScreenTools { } // Indicates whether calibration is valid for this control property bool calValid: false @@ -63,23 +63,23 @@ Rectangle { smooth: true } - Label { + QGCLabel { width: parent.width height: parent.height horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignBottom - font.pointSize: screenTools.dpiAdjustedPointSize(25); + font.pointSize: __screenTools.dpiAdjustedPointSize(25); font.bold: true color: "black" text: parent.calText } - Label { + QGCLabel { width: parent.width height: parent.height horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignBottom - font.pointSize: screenTools.dpiAdjustedPointSize(25); + 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 3315f46..7906ce6 100644 --- a/src/VehicleSetup/FirmwareUpgrade.qml +++ b/src/VehicleSetup/FirmwareUpgrade.qml @@ -114,11 +114,15 @@ Rectangle { TextArea { id: statusTextArea - width: parent.width - height: 300 - readOnly: true - frameVisible: false - text: qsTr("Please disconnect all connections and unplug board from USB before selecting Upgrade.") + + width: parent.width + height: 300 + readOnly: true + frameVisible: false + font.pointSize: qgcPal.dpiAdjustedDefaultFontPointSize + + text: qsTr("Please disconnect all connections and unplug board from USB before selecting Upgrade.") + style: TextAreaStyle { textColor: qgcPal.text backgroundColor: qgcPal.windowShade diff --git a/src/VehicleSetup/VehicleSummary.qml b/src/VehicleSetup/VehicleSummary.qml index a7a81c4..0c09791 100644 --- a/src/VehicleSetup/VehicleSummary.qml +++ b/src/VehicleSetup/VehicleSummary.qml @@ -90,11 +90,10 @@ Rectangle { color: qgcPal.windowShadeDark // Title text - Text { + QGCLabel { anchors.fill: parent color: qgcPal.buttonText - font.pixelSize: 12 text: modelData.name.toUpperCase() verticalAlignment: TextEdit.AlignVCenter diff --git a/src/ui/toolbar/MainToolBar.qml b/src/ui/toolbar/MainToolBar.qml index b52ac3c..61dafd1 100644 --- a/src/ui/toolbar/MainToolBar.qml +++ b/src/ui/toolbar/MainToolBar.qml @@ -238,7 +238,7 @@ Rectangle { anchors.verticalCenter: parent.verticalCenter anchors.right: parent.right width: messages.width - messageIcon.width - Text { + QGCLabel { id: messageText text: (mainToolBar.messageCount > 0) ? mainToolBar.messageCount : '' font.pointSize: screenTools.dpiAdjustedPointSize(14); @@ -326,7 +326,7 @@ Rectangle { smooth: true } - Text { + QGCLabel { id: satelitteText text: (mainToolBar.satelliteCount > 0) ? mainToolBar.satelliteCount : '' font.pointSize: screenTools.dpiAdjustedPointSize(14); @@ -361,7 +361,7 @@ Rectangle { smooth: true } - Text { + QGCLabel { id: batteryText text: mainToolBar.batteryVoltage.toFixed(1) + ' V'; font.pointSize: screenTools.dpiAdjustedPointSize(14); @@ -389,7 +389,7 @@ Rectangle { border.color: "#00000000" border.width: 0 - Text { + QGCLabel { id: armedStatusText text: (mainToolBar.systemArmed) ? qsTr("ARMED") : qsTr("DISARMED") font.pointSize: screenTools.dpiAdjustedPointSize(12); @@ -408,7 +408,7 @@ Rectangle { border.color: "#00000000" border.width: 0 - Text { + QGCLabel { id: stateStatusText text: mainToolBar.currentState font.pointSize: screenTools.dpiAdjustedPointSize(12); @@ -429,7 +429,7 @@ Rectangle { border.color: "#00000000" border.width: 0 - Text { + QGCLabel { id: modeStatusText text: mainToolBar.currentMode font.pointSize: screenTools.dpiAdjustedPointSize(12); @@ -450,7 +450,7 @@ Rectangle { border.color: "#00000000" border.width: 0 - Text { + QGCLabel { id: connectionStatusText text: qsTr("CONNECTION LOST") font.pointSize: screenTools.dpiAdjustedPointSize(14);