Commit b6cf543e authored by dogmaphobic's avatar dogmaphobic

Created new ScreenTools exported control for QML code to obtain screen DPI...

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.
parent d98b1a80
......@@ -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
......
......@@ -281,7 +281,7 @@
<file alias="RadioComponentSummary.qml">src/AutoPilotPlugins/PX4/RadioComponentSummary.qml</file>
<file alias="FlightModesComponentSummary.qml">src/AutoPilotPlugins/PX4/FlightModesComponentSummary.qml</file>
<file alias="AirframeComponentSummary.qml">src/AutoPilotPlugins/PX4/AirframeComponentSummary.qml</file>
<file alias="SafetyComponentTree.png">src/AutoPilotPlugins/PX4/Images/SafetyComponentTree.png</file>
<file alias="SafetyComponentTree.svg">src/AutoPilotPlugins/PX4/Images/SafetyComponentTree.svg</file>
<file alias="SafetyComponentHome.png">src/AutoPilotPlugins/PX4/Images/SafetyComponentHome.png</file>
<file alias="SafetyComponentArrowDown.png">src/AutoPilotPlugins/PX4/Images/SafetyComponentArrowDown.png</file>
<file alias="SafetyComponentPlane.png">src/AutoPilotPlugins/PX4/Images/SafetyComponentPlane.png</file>
......
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 18.1.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="356 -168 306 480" enable-background="new 356 -168 306 480" xml:space="preserve">
<g>
<title>Layer 1</title>
<g id="layer1">
<g id="g4623">
<path id="rect2192" fill="#FFFFFF" d="M484.7,225.1h36.7v77.8c-10.8,5.1-23.7,6.6-36.7,0V225.1z"/>
<path id="path1307" fill="#FFFFFF" d="M633.7,234.3c-83.3-16.9-172.7,18.5-261.3,0C432.8,178.9,450.2,67.3,503,8
C545.8,65.7,572.4,178.9,633.7,234.3z"/>
<path id="path2183" fill="#FFFFFF" d="M607.5,89.1c-66.6-13.5-138.1,14.8-208.9,0C446.9,44.8,460.8-44.4,503-91.8
C537.2-45.7,558.5,44.8,607.5,89.1z"/>
<path id="path2185" fill="#FFFFFF" d="M583.6-26.4c-51.3-10.4-106.5,11.4-161.1,0c37.3-34.2,48-103,80.6-139.5
C529.4-130.3,545.8-60.5,583.6-26.4z"/>
</g>
</g>
</g>
</svg>
......@@ -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 {
......
......@@ -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
}
......
......@@ -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<QGCPalette>("QGroundControl.Palette", 1, 0, "QGCPalette");
qmlRegisterType<MousePosition>("QGroundControl.MousePosition", 1, 0, "MousePosition");
qmlRegisterType<ScreenTools>("QGroundControl.ScreenTools", 1, 0, "ScreenTools");
}
bool QGCApplication::_initForNormalAppBoot(void)
......
......@@ -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
......
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
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 <http://www.gnu.org/licenses/>.
======================================================================*/
/// @file
/// @author Don Gagne <don@thegagnes.com>
/// @author Gus Grubba <mavlink@grubba.com>
#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.";
}
}
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
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 <http://www.gnu.org/licenses/>.
======================================================================*/
/// @file
/// @author Don Gagne <don@thegagnes.com>
/// @author Gus Grubba <mavlink@grubba.com>
#ifndef MOUSEPOSITION_H
#define MOUSEPOSITION_H
#ifndef SCREENTOOLS_H
#define SCREENTOOLS_H
#include <QObject>
#include <QCursor>
/// 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
......@@ -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;
......
......@@ -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;
......
......@@ -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
......
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