From b6cf543e322f47271d480c31e1e3d4c20316a377 Mon Sep 17 00:00:00 2001 From: dogmaphobic Date: Sun, 8 Mar 2015 21:05:04 -0400 Subject: [PATCH] Created new ScreenTools exported control for QML code to obtain screen DPI factor to be used for computing font point sizes. This code used to be in the tool bar code and now is available to all QML widgets. Moved global mouse position tool into ScreenTools as I felt it would be a place to collect these sort of functionality. Replaced Tree used in the Safety Component from a PNG file to a SVG file as the PNG was not scaling up properly. --- qgroundcontrol.pro | 4 +- qgroundcontrol.qrc | 2 +- .../PX4/Images/SafetyComponentTree.png | Bin 918 -> 0 bytes .../PX4/Images/SafetyComponentTree.svg | 19 ++++++++ src/AutoPilotPlugins/PX4/PowerComponent.qml | 6 ++- src/AutoPilotPlugins/PX4/SafetyComponent.qml | 6 +-- src/QGCApplication.cc | 4 +- src/QmlControls/QGCButton.qml | 14 +++--- .../{MousePosition.cc => ScreenTools.cc} | 33 +++++++++----- .../{MousePosition.h => ScreenTools.h} | 43 ++++++++++-------- src/ui/toolbar/MainToolBar.cc | 8 ---- src/ui/toolbar/MainToolBar.h | 4 -- src/ui/toolbar/MainToolBar.qml | 17 +++---- 13 files changed, 94 insertions(+), 66 deletions(-) delete mode 100644 src/AutoPilotPlugins/PX4/Images/SafetyComponentTree.png create mode 100644 src/AutoPilotPlugins/PX4/Images/SafetyComponentTree.svg rename src/QmlControls/{MousePosition.cc => ScreenTools.cc} (54%) rename src/QmlControls/{MousePosition.h => ScreenTools.h} (71%) diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index 15676750a..d3be1b28f 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -497,7 +497,7 @@ HEADERS += \ src/ui/QGCUDPLinkConfiguration.h \ src/uas/UASMessageHandler.h \ src/ui/toolbar/MainToolBar.h \ - src/QmlControls/MousePosition.h + src/QmlControls/ScreenTools.h SOURCES += \ src/main.cc \ @@ -639,7 +639,7 @@ SOURCES += \ src/ui/QGCUDPLinkConfiguration.cc \ src/uas/UASMessageHandler.cc \ src/ui/toolbar/MainToolBar.cc \ - src/QmlControls/MousePosition.cc + src/QmlControls/ScreenTools.cc # # Unit Test specific configuration goes here diff --git a/qgroundcontrol.qrc b/qgroundcontrol.qrc index 3210730c1..408e89bb9 100644 --- a/qgroundcontrol.qrc +++ b/qgroundcontrol.qrc @@ -281,7 +281,7 @@ src/AutoPilotPlugins/PX4/RadioComponentSummary.qml src/AutoPilotPlugins/PX4/FlightModesComponentSummary.qml src/AutoPilotPlugins/PX4/AirframeComponentSummary.qml - src/AutoPilotPlugins/PX4/Images/SafetyComponentTree.png + src/AutoPilotPlugins/PX4/Images/SafetyComponentTree.svg src/AutoPilotPlugins/PX4/Images/SafetyComponentHome.png src/AutoPilotPlugins/PX4/Images/SafetyComponentArrowDown.png src/AutoPilotPlugins/PX4/Images/SafetyComponentPlane.png diff --git a/src/AutoPilotPlugins/PX4/Images/SafetyComponentTree.png b/src/AutoPilotPlugins/PX4/Images/SafetyComponentTree.png deleted file mode 100644 index 9c618a3060326f456f2cb2ac7aee2cdb466e1025..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 918 zcmeAS@N?(olHy`uVBq!ia0vp^0YDth!3HFsTw}@uQk(@Ik;M!Q+`=Ht$S`Y;1W-`2 z#5JNMI6tkVJh3R1!7(L2DOJHUH!(dmC^a#qvhZZ84FdzSvZsqNTm9Xa!`J1Pt)0KE zn%ze3=G!fEWq$nIUn#Vmufk@N_i3Lcx(sq%Z!Q@LzP!`mJux=wrt(~20inpv6VEYr z^sYJSkWoUM0hR>Pc$rox%L4l7U0>eynkpd@9pdz4Us@ur(fx{NclH$^I)<(*-@ z>D9z%EL%h(w|W#a9y@96{pY6R4~q|KAJgA6A7hri3sVrc%DRj|v@UB?YA=DuD@rb}qM%~Aq3PnuQ8jkm!V2u!x z(^g_n=&Z=;2stq6V}yWagXx2bf*Tu5A5Ii7Y%qPaP;g;`>;v&5?2&72^o8d0OENNl zn(=#GjLSY_v)KJj2QJSh+gQ`b3k4J#bRRSd1~Wz}Vp zJJ_&Q%&mAjJK)^Pz4F&{J?zhZk9xJQpk~Q;_k|7h%ic;q<+^r6+CZd7{JNz==9}-W zk3FB(Yrov_{_?iVEIoV0&lmj<;!LpFy`Q^dx@`jE@k5JGUu&PiC!=-5`MY8XQ}!#{ zX?86P*RECT)N(M&X!q)^-yLdyNG81A%l_){d4|2;8K6?PIltU<{_>D}!FRb${P94E3AGZ8zaRL= zCtaVqwEW}Uv#P%P$`|asX6M59qJeM4ek*PBBbWSCe$da*P}+`EobG;^^70>v2FEx;IJd-{x6oiXPk@vxX<2U zT$xwOw7v1$yh|T9?f%Js@eEMLHsgGS#wUrm`|n-13jgOeVBk!j-?cKT$sL%d7(8A5 KT-G@yGywqAC6 + + + + Layer 1 + + + + + + + + + + diff --git a/src/AutoPilotPlugins/PX4/PowerComponent.qml b/src/AutoPilotPlugins/PX4/PowerComponent.qml index 671a0cf45..5a20eecd4 100644 --- a/src/AutoPilotPlugins/PX4/PowerComponent.qml +++ b/src/AutoPilotPlugins/PX4/PowerComponent.qml @@ -33,6 +33,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 } @@ -42,6 +43,7 @@ Rectangle { color: palette.window property int firstColumnWidth: 220 + property ScreenTools __screenTools: ScreenTools { } Column { anchors.fill: parent @@ -49,7 +51,7 @@ Rectangle { QGCLabel { text: "POWER CONFIG" - font.pointSize: 20 + font.pointSize: 20 * __screenTools.dpiFactor; } Item { height: 1; width: 10 } @@ -57,7 +59,7 @@ Rectangle { QGCLabel { text: "Battery" color: palette.text - font.pointSize: 20 + font.pointSize: 20 * __screenTools.dpiFactor; } Rectangle { diff --git a/src/AutoPilotPlugins/PX4/SafetyComponent.qml b/src/AutoPilotPlugins/PX4/SafetyComponent.qml index 42ca8cc0e..3721300f7 100644 --- a/src/AutoPilotPlugins/PX4/SafetyComponent.qml +++ b/src/AutoPilotPlugins/PX4/SafetyComponent.qml @@ -201,7 +201,7 @@ Rectangle { y: parent.height - height - 20 width: 80 height: parent.height / 2 - source: "/qml/SafetyComponentTree.png" + source: "/qml/SafetyComponentTree.svg" fillMode: Image.Stretch smooth: true color: palette.windowShadeDark @@ -212,8 +212,8 @@ Rectangle { y: parent.height - height width: 100 height: parent.height * .75 - source: "/qml/SafetyComponentTree.png" - fillMode: Image.Stretch + source: "/qml/SafetyComponentTree.svg" + fillMode: Image.PreserveAspectFit smooth: true color: palette.button } diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index 631649ba4..df3d9e272 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -59,7 +59,7 @@ #include "QGCTemporaryFile.h" #include "QGCFileDialog.h" #include "QGCPalette.h" -#include "MousePosition.h" +#include "ScreenTools.h" #ifdef QGC_RTLAB_ENABLED #include "OpalLink.h" @@ -252,7 +252,7 @@ void QGCApplication::_initCommon(void) // Register our Qml objects qmlRegisterType("QGroundControl.Palette", 1, 0, "QGCPalette"); - qmlRegisterType("QGroundControl.MousePosition", 1, 0, "MousePosition"); + qmlRegisterType("QGroundControl.ScreenTools", 1, 0, "ScreenTools"); } bool QGCApplication::_initForNormalAppBoot(void) diff --git a/src/QmlControls/QGCButton.qml b/src/QmlControls/QGCButton.qml index a3d31b267..19a76ffe3 100644 --- a/src/QmlControls/QGCButton.qml +++ b/src/QmlControls/QGCButton.qml @@ -4,7 +4,7 @@ import QtQuick.Controls.Styles 1.2 import QtQuick.Controls.Private 1.0 import QGroundControl.Palette 1.0 -import QGroundControl.MousePosition 1.0 +import QGroundControl.ScreenTools 1.0 Button { // primary: true - this is the primary button for this group of buttons @@ -23,17 +23,17 @@ Button { property int __lastGlobalMouseX: 0 property int __lastGlobalMouseY: 0 - property MousePosition __globalMousePosition: MousePosition { } + property ScreenTools __screenTools: ScreenTools { } Connections { target: __behavior onMouseXChanged: { - __lastGlobalMouseX = __globalMousePosition.mouseX - __lastGlobalMouseY = __globalMousePosition.mouseY + __lastGlobalMouseX = __screenTools.mouseX + __lastGlobalMouseY = __screenTools.mouseY } onMouseYChanged: { - __lastGlobalMouseX = __globalMousePosition.mouseX - __lastGlobalMouseY = __globalMousePosition.mouseY + __lastGlobalMouseX = __screenTools.mouseX + __lastGlobalMouseY = __screenTools.mouseY } onEntered: { __forceHoverOff; false; hoverTimer.start() } onExited: { __forceHoverOff; false; hoverTimer.stop() } @@ -45,7 +45,7 @@ Button { repeat: true onTriggered: { - if (__lastGlobalMouseX != __globalMousePosition.mouseX || __lastGlobalMouseY != __globalMousePosition.mouseY) { + if (__lastGlobalMouseX != __screenTools.mouseX || __lastGlobalMouseY != __screenTools.mouseY) { __forceHoverOff = true } else { __forceHoverOff = false diff --git a/src/QmlControls/MousePosition.cc b/src/QmlControls/ScreenTools.cc similarity index 54% rename from src/QmlControls/MousePosition.cc rename to src/QmlControls/ScreenTools.cc index 594f313e1..345819b59 100644 --- a/src/QmlControls/MousePosition.cc +++ b/src/QmlControls/ScreenTools.cc @@ -1,32 +1,43 @@ /*===================================================================== - + 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 . - + ======================================================================*/ /// @file -/// @author Don Gagne +/// @author Gus Grubba -#include "MousePosition.h" +#include "ScreenTools.h" +#include "MainWindow.h" -MousePosition::MousePosition(void) +ScreenTools::ScreenTools() + : _dotsPerInch(96.0) + , _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 + 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."; + } } + diff --git a/src/QmlControls/MousePosition.h b/src/QmlControls/ScreenTools.h similarity index 71% rename from src/QmlControls/MousePosition.h rename to src/QmlControls/ScreenTools.h index 64c7a3a4f..fbec19d78 100644 --- a/src/QmlControls/MousePosition.h +++ b/src/QmlControls/ScreenTools.h @@ -1,50 +1,57 @@ /*===================================================================== - + 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 . - + ======================================================================*/ /// @file -/// @author Don Gagne +/// @author Gus Grubba -#ifndef MOUSEPOSITION_H -#define MOUSEPOSITION_H +#ifndef SCREENTOOLS_H +#define SCREENTOOLS_H #include #include -/// This Qml control is used to return global mouse positions. It is needed to fix -/// a problem with hover state of buttons not being updated correctly if the mouse -/// moves out of a QQuickWidget control. -class MousePosition : public QObject +/// This Qml control is used to return screen parameters +class ScreenTools : public QObject { Q_OBJECT - public: - MousePosition(void); - + 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(); } + +private: + double _dotsPerInch; + double _dpiFactor; + }; #endif diff --git a/src/ui/toolbar/MainToolBar.cc b/src/ui/toolbar/MainToolBar.cc index 1a708e4e4..e8f88fd2c 100644 --- a/src/ui/toolbar/MainToolBar.cc +++ b/src/ui/toolbar/MainToolBar.cc @@ -55,7 +55,6 @@ MainToolBar::MainToolBar(QWidget* parent) , _currentNormalCount(0) , _currentMessageType(MessageNone) , _satelliteCount(-1) - , _dotsPerInch(96.0) // Default to Windows as it's more likely not to report below , _satelliteLock(0) , _showGPS(true) , _showMav(true) @@ -73,13 +72,6 @@ MainToolBar::MainToolBar(QWidget* parent) if(pl) { pl->setContentsMargins(0,0,0,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 - if(srn && srn->logicalDotsPerInch() > 50.0) { - _dotsPerInch = (qreal)srn->logicalDotsPerInch(); // Font point sizes are based on Mac 72dpi - } 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."; - } // Tool Bar Preferences QSettings settings; diff --git a/src/ui/toolbar/MainToolBar.h b/src/ui/toolbar/MainToolBar.h index f903127e8..3f8d5415a 100644 --- a/src/ui/toolbar/MainToolBar.h +++ b/src/ui/toolbar/MainToolBar.h @@ -92,7 +92,6 @@ public: Q_PROPERTY(QStringList connectedList READ connectedList NOTIFY connectedListChanged) Q_PROPERTY(bool mavPresent READ mavPresent NOTIFY mavPresentChanged) Q_PROPERTY(QString currentState READ currentState NOTIFY currentStateChanged) - Q_PROPERTY(double dotsPerInch READ dotsPerInch NOTIFY dotsPerInchChanged) Q_PROPERTY(int satelliteLock READ satelliteLock NOTIFY satelliteLockChanged) Q_PROPERTY(bool showGPS READ showGPS NOTIFY showGPSChanged) Q_PROPERTY(bool showMav READ showMav NOTIFY showMavChanged) @@ -117,7 +116,6 @@ public: QStringList connectedList () { return _connectedList; } bool mavPresent () { return _mav != NULL; } QString currentState () { return _currentState; } - double dotsPerInch () { return _dotsPerInch; } int satelliteLock () { return _satelliteLock; } bool showGPS () { return _showGPS; } bool showMav () { return _showMav; } @@ -147,7 +145,6 @@ signals: void connectedListChanged (QStringList connectedList); void mavPresentChanged (bool present); void currentStateChanged (QString state); - void dotsPerInchChanged (); void satelliteLockChanged (int lock); void showGPSChanged (bool value); void showMavChanged (bool value); @@ -205,7 +202,6 @@ private: MessageType_t _currentMessageType; int _satelliteCount; QStringList _connectedList; - qreal _dotsPerInch; int _satelliteLock; bool _showGPS; bool _showMav; diff --git a/src/ui/toolbar/MainToolBar.qml b/src/ui/toolbar/MainToolBar.qml index c044fbc17..acf1f0b43 100644 --- a/src/ui/toolbar/MainToolBar.qml +++ b/src/ui/toolbar/MainToolBar.qml @@ -35,14 +35,15 @@ import QGroundControl.Controls 1.0 import QGroundControl.FactControls 1.0 import QGroundControl.Palette 1.0 import QGroundControl.MainToolBar 1.0 +import QGroundControl.ScreenTools 1.0 Rectangle { property var qgcPal: QGCPalette { id: palette; colorGroupEnabled: true } + property ScreenTools __screenTools: ScreenTools { } property int cellSpacerSize: 4 property int cellHeight: 30 property int cellRadius: 3 - property double dpiFactor: (72.0 / mainToolBar.dotsPerInch); property var colorBlue: "#1a6eaa" property var colorGreen: "#079527" @@ -240,7 +241,7 @@ Rectangle { Text { id: messageText text: (mainToolBar.messageCount > 0) ? mainToolBar.messageCount : '' - font.pointSize: 14 * dpiFactor + font.pointSize: 14 * __screenTools.dpiFactor font.weight: Font.DemiBold anchors.verticalCenter: parent.verticalCenter anchors.horizontalCenter: parent.horizontalCenter @@ -328,7 +329,7 @@ Rectangle { Text { id: satelitteText text: (mainToolBar.satelliteCount > 0) ? mainToolBar.satelliteCount : '' - font.pointSize: 14 * dpiFactor + font.pointSize: 14 * __screenTools.dpiFactor font.weight: Font.DemiBold anchors.verticalCenter: parent.verticalCenter anchors.right: parent.right @@ -363,7 +364,7 @@ Rectangle { Text { id: batteryText text: mainToolBar.batteryVoltage.toFixed(1) + ' V'; - font.pointSize: 14 * dpiFactor + font.pointSize: 14 * __screenTools.dpiFactor font.weight: Font.DemiBold anchors.verticalCenter: parent.verticalCenter anchors.right: parent.right @@ -391,7 +392,7 @@ Rectangle { Text { id: armedStatusText text: (mainToolBar.systemArmed) ? qsTr("ARMED") : qsTr("DISARMED") - font.pointSize: 12 * dpiFactor + font.pointSize: 12 * __screenTools.dpiFactor font.weight: Font.DemiBold anchors.centerIn: parent color: (mainToolBar.systemArmed) ? colorOrangeText : colorGreenText @@ -410,7 +411,7 @@ Rectangle { Text { id: stateStatusText text: mainToolBar.currentState - font.pointSize: 12 * dpiFactor + font.pointSize: 12 * __screenTools.dpiFactor font.weight: Font.DemiBold anchors.centerIn: parent color: (mainToolBar.currentState === "STANDBY") ? colorGreenText : colorRedText @@ -431,7 +432,7 @@ Rectangle { Text { id: modeStatusText text: mainToolBar.currentMode - font.pointSize: 12 * dpiFactor + font.pointSize: 12 * __screenTools.dpiFactor font.weight: Font.DemiBold anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter @@ -452,7 +453,7 @@ Rectangle { Text { id: connectionStatusText text: qsTr("CONNECTION LOST") - font.pointSize: 14 * dpiFactor + font.pointSize: 14 * __screenTools.dpiFactor font.weight: Font.DemiBold anchors.verticalCenter: parent.verticalCenter anchors.horizontalCenter: parent.horizontalCenter -- 2.22.0