Commit 7e4458df authored by dogmaphobic's avatar dogmaphobic

Added code to handle point size fonts in all QML widgets.

parent ed9c6f45
/*=====================================================================
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/>.
======================================================================*/
import QtQuick 2.2 import QtQuick 2.2
import QtQuick.Controls 1.2 import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2 import QtQuick.Controls.Styles 1.2
...@@ -7,11 +30,13 @@ import QGroundControl.FactControls 1.0 ...@@ -7,11 +30,13 @@ import QGroundControl.FactControls 1.0
import QGroundControl.Palette 1.0 import QGroundControl.Palette 1.0
import QGroundControl.Controls 1.0 import QGroundControl.Controls 1.0
import QGroundControl.Controllers 1.0 import QGroundControl.Controllers 1.0
import QGroundControl.ScreenTools 1.0
Item { Item {
Loader { Loader {
property FlightModesComponentController controller: FlightModesComponentController { } property FlightModesComponentController controller: FlightModesComponentController { }
property QGCPalette qgcPal: QGCPalette { colorGroupEnabled: true } property QGCPalette qgcPal: QGCPalette { colorGroupEnabled: true }
property ScreenTools screenTools: ScreenTools { }
property bool loading: true property bool loading: true
anchors.fill: parent anchors.fill: parent
...@@ -357,7 +382,7 @@ Item { ...@@ -357,7 +382,7 @@ Item {
QGCLabel { QGCLabel {
text: "FLIGHT MODES CONFIG" text: "FLIGHT MODES CONFIG"
font.pointSize: 20 font.pointSize: 20 * screenTools.dpiFactor;
} }
Item { height: 20; width: 10 } // spacer Item { height: 20; width: 10 } // spacer
...@@ -848,7 +873,7 @@ Item { ...@@ -848,7 +873,7 @@ Item {
QGCLabel { QGCLabel {
text: "FLIGHT MODES CONFIG" text: "FLIGHT MODES CONFIG"
font.pointSize: 20 font.pointSize: 20 * screenTools.dpiFactor;
} }
QGCLabel { QGCLabel {
......
/*=====================================================================
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/>.
======================================================================*/
import QtQuick 2.2 import QtQuick 2.2
import QtQuick.Controls 1.2 import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2 import QtQuick.Controls.Styles 1.2
...@@ -6,6 +29,7 @@ import QGroundControl.FactSystem 1.0 ...@@ -6,6 +29,7 @@ import QGroundControl.FactSystem 1.0
import QGroundControl.FactControls 1.0 import QGroundControl.FactControls 1.0
import QGroundControl.Palette 1.0 import QGroundControl.Palette 1.0
import QGroundControl.Controls 1.0 import QGroundControl.Controls 1.0
import QGroundControl.ScreenTools 1.0
Rectangle { Rectangle {
QGCPalette { id: palette; colorGroupEnabled: true } QGCPalette { id: palette; colorGroupEnabled: true }
...@@ -14,6 +38,7 @@ Rectangle { ...@@ -14,6 +38,7 @@ Rectangle {
height: 600 height: 600
color: palette.window color: palette.window
property ScreenTools screenTools: ScreenTools { }
property int flightLineWidth: 2 // width of lines for flight graphic property int flightLineWidth: 2 // width of lines for flight graphic
property int loiterAltitudeColumnWidth: 180 // width of loiter altitude column property int loiterAltitudeColumnWidth: 180 // width of loiter altitude column
property int shadedMargin: 20 // margin inset for shaded areas property int shadedMargin: 20 // margin inset for shaded areas
...@@ -29,7 +54,7 @@ Rectangle { ...@@ -29,7 +54,7 @@ Rectangle {
QGCLabel { QGCLabel {
text: "SAFETY CONFIG" text: "SAFETY CONFIG"
font.pointSize: 20 font.pointSize: 20 * screenTools.dpiFactor;
} }
Item { height: 20; width: 10 } // spacer Item { height: 20; width: 10 } // spacer
...@@ -37,7 +62,7 @@ Rectangle { ...@@ -37,7 +62,7 @@ Rectangle {
//----------------------------------------------------------------- //-----------------------------------------------------------------
//-- Return Home Triggers //-- 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 Item { height: 10; width: 10 } // spacer
...@@ -96,7 +121,7 @@ Rectangle { ...@@ -96,7 +121,7 @@ Rectangle {
//----------------------------------------------------------------- //-----------------------------------------------------------------
//-- Return Home Settings //-- 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 Item { height: 10; width: 10 } // spacer
...@@ -266,7 +291,7 @@ Rectangle { ...@@ -266,7 +291,7 @@ Rectangle {
QGCLabel { QGCLabel {
property Fact fact: Fact { name: "NAV_RCL_OBC" } property Fact fact: Fact { name: "NAV_RCL_OBC" }
width: parent.width 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."; 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 wrapMode: Text.Wrap
...@@ -274,7 +299,7 @@ Rectangle { ...@@ -274,7 +299,7 @@ Rectangle {
QGCLabel { QGCLabel {
property Fact fact: Fact { name: "NAV_DLL_OBC" } property Fact fact: Fact { name: "NAV_DLL_OBC" }
width: parent.width 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."; 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 wrapMode: Text.Wrap
......
/*=====================================================================
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/>.
======================================================================*/
import QtQuick 2.2 import QtQuick 2.2
import QtQuick.Controls 1.2 import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2 import QtQuick.Controls.Styles 1.2
...@@ -6,9 +29,11 @@ import QGroundControl.FactSystem 1.0 ...@@ -6,9 +29,11 @@ import QGroundControl.FactSystem 1.0
import QGroundControl.FactControls 1.0 import QGroundControl.FactControls 1.0
import QGroundControl.Palette 1.0 import QGroundControl.Palette 1.0
import QGroundControl.Controls 1.0 import QGroundControl.Controls 1.0
import QGroundControl.ScreenTools 1.0
Rectangle { Rectangle {
property QGCPalette qgcPal: QGCPalette { colorGroupEnabled: true } property QGCPalette qgcPal: QGCPalette { colorGroupEnabled: true }
property ScreenTools screenTools: ScreenTools { }
readonly property int rotationColumnWidth: 200 readonly property int rotationColumnWidth: 200
readonly property var rotations: [ readonly property var rotations: [
...@@ -62,7 +87,7 @@ Rectangle { ...@@ -62,7 +87,7 @@ Rectangle {
QGCLabel { QGCLabel {
text: "SENSORS CONFIG" text: "SENSORS CONFIG"
font.pointSize: 20 font.pointSize: 20 * screenTools.dpiFactor;
} }
Item { height: 20; width: 10 } // spacer Item { height: 20; width: 10 } // spacer
......
/*=====================================================================
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/>.
======================================================================*/
import QtQuick 2.2 import QtQuick 2.2
import QtQuick.Controls 1.2 import QtQuick.Controls 1.2
import QGroundControl.FactSystem 1.0 import QGroundControl.FactSystem 1.0
import QGroundControl.ScreenTools 1.0
Item { Item {
property ScreenTools screenTools: ScreenTools { }
TextInput { TextInput {
objectName: "testControl" objectName: "testControl"
Fact { id: fact; name: "RC_MAP_THROTTLE" } Fact { id: fact; name: "RC_MAP_THROTTLE" }
text: fact.value text: fact.value
font.family: "Helvetica" font.family: "Helvetica"
font.pointSize: 24 font.pointSize: 24 * screenTools.dpiFactor;
color: "red" color: "red"
focus: true focus: true
onAccepted: { fact.value = text; } onAccepted: { fact.value = text; }
} }
} }
\ No newline at end of file
...@@ -32,7 +32,7 @@ ScreenTools::ScreenTools() ...@@ -32,7 +32,7 @@ ScreenTools::ScreenTools()
, _dpiFactor( 72.0 / 96.0) , _dpiFactor( 72.0 / 96.0)
{ {
// Get screen DPI to manage font sizes on different platforms // 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) { if(srn && srn->logicalDotsPerInch() > 50.0) {
_dotsPerInch = (double)srn->logicalDotsPerInch(); // Font point sizes are based on Mac 72dpi _dotsPerInch = (double)srn->logicalDotsPerInch(); // Font point sizes are based on Mac 72dpi
_dpiFactor = 72.0 / _dotsPerInch; _dpiFactor = 72.0 / _dotsPerInch;
......
...@@ -30,6 +30,19 @@ ...@@ -30,6 +30,19 @@
#include <QObject> #include <QObject>
#include <QCursor> #include <QCursor>
/*!
@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 <a href="http://doc.qt.io/qt-5/qml-qtquick-window-screen.html">Screen QML Type</a>
*/
/// This Qml control is used to return screen parameters /// This Qml control is used to return screen parameters
class ScreenTools : public QObject class ScreenTools : public QObject
{ {
...@@ -37,10 +50,64 @@ class ScreenTools : public QObject ...@@ -37,10 +50,64 @@ class ScreenTools : public QObject
public: public:
ScreenTools(); ScreenTools();
//! Returns the screen density in Dots Per Inch
Q_PROPERTY(double screenDPI READ screenDPI CONSTANT) 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) Q_PROPERTY(double dpiFactor READ dpiFactor CONSTANT)
//! Returns the global mouse X position
Q_PROPERTY(int mouseX READ mouseX) Q_PROPERTY(int mouseX READ mouseX)
//! Returns the global mouse Y position
Q_PROPERTY(int mouseY READ mouseY) 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) Q_PROPERTY(bool repaintRequested READ repaintRequested NOTIFY repaintRequestedChanged)
double screenDPI () { return _dotsPerInch; } double screenDPI () { return _dotsPerInch; }
......
/*=====================================================================
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/>.
======================================================================*/
import QtQuick 2.2 import QtQuick 2.2
import QtQuick.Controls 1.2 import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2 import QtQuick.Controls.Styles 1.2
import QGroundControl.Palette 1.0 import QGroundControl.Palette 1.0
import QGroundControl.ScreenTools 1.0
Rectangle { Rectangle {
property var __qgcPal: QGCPalette { colorGroupEnabled: enabled } property var __qgcPal: QGCPalette { colorGroupEnabled: enabled }
property ScreenTools screenTools: ScreenTools { }
// Indicates whether calibration is valid for this control // Indicates whether calibration is valid for this control
property bool calValid: false property bool calValid: false
...@@ -43,7 +68,7 @@ Rectangle { ...@@ -43,7 +68,7 @@ Rectangle {
height: parent.height height: parent.height
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignBottom verticalAlignment: Text.AlignBottom
font.pointSize: 25 font.pointSize: 25 * screenTools.dpiFactor;
font.bold: true font.bold: true
color: "black" color: "black"
...@@ -54,7 +79,7 @@ Rectangle { ...@@ -54,7 +79,7 @@ Rectangle {
height: parent.height height: parent.height
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignBottom verticalAlignment: Text.AlignBottom
font.pointSize: 25 font.pointSize: 25 * screenTools.dpiFactor;
color: calInProgress ? "yellow" : "white" color: calInProgress ? "yellow" : "white"
text: parent.calText text: parent.calText
......
/*=====================================================================
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/>.
======================================================================*/
import QtQuick 2.3 import QtQuick 2.3
import QtQuick.Controls 1.2 import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2 import QtQuick.Controls.Styles 1.2
...@@ -6,12 +29,14 @@ import QGroundControl.Controls 1.0 ...@@ -6,12 +29,14 @@ import QGroundControl.Controls 1.0
import QGroundControl.FactControls 1.0 import QGroundControl.FactControls 1.0
import QGroundControl.Palette 1.0 import QGroundControl.Palette 1.0
import QGroundControl.FirmwareUpgradeController 1.0 import QGroundControl.FirmwareUpgradeController 1.0
import QGroundControl.ScreenTools 1.0
Rectangle { Rectangle {
width: 600 width: 600
height: 600 height: 600
property var qgcPal: QGCPalette { colorGroupEnabled: true } property var qgcPal: QGCPalette { colorGroupEnabled: true }
property ScreenTools screenTools: ScreenTools { }
property FirmwareUpgradeController controller: FirmwareUpgradeController { property FirmwareUpgradeController controller: FirmwareUpgradeController {
upgradeButton: upgradeButton upgradeButton: upgradeButton
progressBar: progressBar progressBar: progressBar
...@@ -26,7 +51,7 @@ Rectangle { ...@@ -26,7 +51,7 @@ Rectangle {
QGCLabel { QGCLabel {
text: "FIRMWARE UPDATE" text: "FIRMWARE UPDATE"
font.pointSize: 20 font.pointSize: 20 * screenTools.dpiFactor;
} }
Item { Item {
......
/*=====================================================================
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/>.
======================================================================*/
import QtQuick 2.2 import QtQuick 2.2
import QtQuick.Controls 1.2 import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2 import QtQuick.Controls.Styles 1.2
...@@ -5,12 +28,14 @@ import QtQuick.Controls.Styles 1.2 ...@@ -5,12 +28,14 @@ import QtQuick.Controls.Styles 1.2
import QGroundControl.FactSystem 1.0 import QGroundControl.FactSystem 1.0
import QGroundControl.Palette 1.0 import QGroundControl.Palette 1.0
import QGroundControl.Controls 1.0 import QGroundControl.Controls 1.0
import QGroundControl.ScreenTools 1.0
Rectangle { Rectangle {
width: 600 width: 600
height: 400 height: 400
property var qgcPal: QGCPalette { id: palette; colorGroupEnabled: true } property var qgcPal: QGCPalette { id: palette; colorGroupEnabled: true }
property ScreenTools screenTools: ScreenTools { }
id: topLevel id: topLevel
objectName: "topLevel" objectName: "topLevel"
...@@ -22,7 +47,7 @@ Rectangle { ...@@ -22,7 +47,7 @@ Rectangle {
QGCLabel { QGCLabel {
text: "VEHICLE SUMMARY" text: "VEHICLE SUMMARY"
font.pointSize: 20 font.pointSize: 20 * screenTools.dpiFactor;
} }
Item { Item {
......
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