Commit 770ece07 authored by Gus Grubba's avatar Gus Grubba

Merge pull request #3341 from dogmaphobic/adjustableUI

Allow users to change base UI font point size.
parents 654a4d6b 709a126f
......@@ -37,7 +37,8 @@ FactMetaData* QGroundControlQmlGlobal::_distanceUnitsMetaData =
SettingsFact* QGroundControlQmlGlobal::_speedUnitsFact = NULL;
FactMetaData* QGroundControlQmlGlobal::_speedUnitsMetaData = NULL;
const char* QGroundControlQmlGlobal::_virtualTabletJoystickKey = "VirtualTabletJoystick";
const char* QGroundControlQmlGlobal::_virtualTabletJoystickKey = "VirtualTabletJoystick";
const char* QGroundControlQmlGlobal::_baseFontPointSizeKey = "BaseFontPointSize";
QGroundControlQmlGlobal::QGroundControlQmlGlobal(QGCApplication* app)
: QGCTool(app)
......@@ -48,9 +49,11 @@ QGroundControlQmlGlobal::QGroundControlQmlGlobal(QGCApplication* app)
, _multiVehicleManager(NULL)
, _mapEngineManager(NULL)
, _virtualTabletJoystick(false)
, _baseFontPointSize(0.0)
{
QSettings settings;
_virtualTabletJoystick = settings.value(_virtualTabletJoystickKey, false). toBool();
_virtualTabletJoystick = settings.value(_virtualTabletJoystickKey, false).toBool();
_baseFontPointSize = settings.value(_baseFontPointSizeKey, 0.0).toDouble();
// We clear the parent on this object since we run into shutdown problems caused by hybrid qml app. Instead we let it leak on shutdown.
setParent(NULL);
......@@ -207,6 +210,16 @@ void QGroundControlQmlGlobal::setVirtualTabletJoystick(bool enabled)
}
}
void QGroundControlQmlGlobal::setBaseFontPointSize(qreal size)
{
if (size >= 6.0 && size <= 48.0) {
QSettings settings;
settings.setValue(_baseFontPointSizeKey, size);
_baseFontPointSize = size;
emit baseFontPointSizeChanged(size);
}
}
bool QGroundControlQmlGlobal::experimentalSurvey(void) const
{
QSettings settings;
......
......@@ -86,6 +86,7 @@ public:
Q_PROPERTY(bool isSaveLogPrompt READ isSaveLogPrompt WRITE setIsSaveLogPrompt NOTIFY isSaveLogPromptChanged)
Q_PROPERTY(bool isSaveLogPromptNotArmed READ isSaveLogPromptNotArmed WRITE setIsSaveLogPromptNotArmed NOTIFY isSaveLogPromptNotArmedChanged)
Q_PROPERTY(bool virtualTabletJoystick READ virtualTabletJoystick WRITE setVirtualTabletJoystick NOTIFY virtualTabletJoystickChanged)
Q_PROPERTY(qreal baseFontPointSize READ baseFontPointSize WRITE setBaseFontPointSize NOTIFY baseFontPointSizeChanged)
// MavLink Protocol
Q_PROPERTY(bool isMultiplexingEnabled READ isMultiplexingEnabled WRITE setIsMultiplexingEnabled NOTIFY isMultiplexingEnabledChanged)
......@@ -151,6 +152,7 @@ public:
bool isSaveLogPrompt () { return _app->promptFlightDataSave(); }
bool isSaveLogPromptNotArmed () { return _app->promptFlightDataSaveNotArmed(); }
bool virtualTabletJoystick () { return _virtualTabletJoystick; }
qreal baseFontPointSize () { return _baseFontPointSize; }
bool isMultiplexingEnabled () { return _toolbox->mavlinkProtocol()->multiplexingEnabled(); }
bool isVersionCheckEnabled () { return _toolbox->mavlinkProtocol()->versionCheckEnabled(); }
......@@ -170,6 +172,7 @@ public:
void setIsSaveLogPrompt (bool prompt);
void setIsSaveLogPromptNotArmed (bool prompt);
void setVirtualTabletJoystick (bool enabled);
void setBaseFontPointSize (qreal size);
void setIsMultiplexingEnabled (bool enable);
void setIsVersionCheckEnabled (bool enable);
......@@ -191,6 +194,7 @@ signals:
void isSaveLogPromptChanged (bool prompt);
void isSaveLogPromptNotArmedChanged (bool prompt);
void virtualTabletJoystickChanged (bool enabled);
void baseFontPointSizeChanged (qreal size);
void isMultiplexingEnabledChanged (bool enabled);
void isVersionCheckEnabledChanged (bool enabled);
void mavlinkSystemIDChanged (int id);
......@@ -207,10 +211,10 @@ private:
QGCMapEngineManager* _mapEngineManager;
QGCPositionManager* _qgcPositionManager;
bool _virtualTabletJoystick;
QGeoCoordinate _flightMapPosition;
double _flightMapZoom;
bool _virtualTabletJoystick;
qreal _baseFontPointSize;
QGeoCoordinate _flightMapPosition;
double _flightMapZoom;
// These are static so they are available to C++ code as well as Qml
static SettingsFact* _offlineEditingFirmwareTypeFact;
......@@ -221,6 +225,7 @@ private:
static FactMetaData* _speedUnitsMetaData;
static const char* _virtualTabletJoystickKey;
static const char* _baseFontPointSizeKey;
};
#endif
......@@ -4,6 +4,7 @@ import QtQuick 2.4
import QtQuick.Controls 1.2
import QtQuick.Window 2.2
import QGroundControl 1.0
import QGroundControl.ScreenToolsController 1.0
Item {
......@@ -35,6 +36,17 @@ Item {
readonly property string normalFontFamily: "opensans"
readonly property string demiboldFontFamily: "opensans-demibold"
/* This mostly works but for some reason, reflowWidths() in SetupView doesn't change size.
I've disabled (in release builds) until I figure out why. Changes require a restart for now.
*/
Connections {
target: QGroundControl
onBaseFontPointSizeChanged: {
if(ScreenToolsController.isDebug)
setBasePointSize(QGroundControl.baseFontPointSize)
}
}
function mouseX() {
return ScreenToolsController.mouseX()
}
......@@ -43,48 +55,61 @@ Item {
return ScreenToolsController.mouseY()
}
function setBasePointSize(pointSize) {
_textMeasure.font.pointSize = pointSize
defaultFontPointSize = pointSize
defaultFontPixelHeight = _textMeasure.fontHeight
defaultFontPixelWidth = _textMeasure.fontWidth
smallFontPointSize = defaultFontPointSize * _screenTools.smallFontPointRatio
mediumFontPointSize = defaultFontPointSize * _screenTools.mediumFontPointRatio
largeFontPointSize = defaultFontPointSize * _screenTools.largeFontPointRatio
}
Text {
id: _defaultFont
text: "X"
property real fontHeight: contentHeight
}
Text {
id: _textMeasure
text: "X"
font.family: normalFontFamily
font.pointSize: {
if(ScreenToolsController.isMobile) {
// Small Devices
if((Screen.width / Screen.pixelDensity) < 120) {
return 11;
// iOS
} else if(ScreenToolsController.isiOS) {
return 13;
// Android
property real fontWidth: contentWidth
property real fontHeight: contentHeight
Component.onCompleted: {
var baseSize = QGroundControl.baseFontPointSize;
//-- If this is the first time (not saved in settings)
if(baseSize < 6 || baseSize > 48) {
//-- Init base size base on the platform
if(ScreenToolsController.isMobile) {
// Small Devices
if((Screen.width / Screen.pixelDensity) < 120)
baseSize = 11;
// iOS
else if(ScreenToolsController.isiOS)
baseSize = 13;
// Android
else
baseSize = 14;
} else {
return 14;
//-- Mac OS
if(ScreenToolsController.isMacOS)
baseSize = _defaultFont.font.pointSize;
//-- Linux
else if(ScreenToolsController.isLinux)
baseSize = _defaultFont.font.pointSize - 3.25;
//-- Windows
else
baseSize = _defaultFont.font.pointSize;
}
QGroundControl.baseFontPointSize = baseSize
//-- Release build doesn't get signal
if(!ScreenToolsController.isDebug)
_screenTools.setBasePointSize(baseSize);
} else {
//-- Mac OS
if(ScreenToolsController.isMacOS)
return _defaultFont.font.pointSize - 1
//-- Linux
if(ScreenToolsController.isLinux)
return _defaultFont.font.pointSize - 3.25
else
return _defaultFont.font.pointSize
//-- Set size saved in settings
_screenTools.setBasePointSize(baseSize);
}
}
property real fontWidth: contentWidth
property real fontHeight: contentHeight
Component.onCompleted: {
defaultFontPointSize = _textMeasure.font.pointSize
defaultFontPixelHeight = _textMeasure.fontHeight
defaultFontPixelWidth = _textMeasure.fontWidth
smallFontPointSize = defaultFontPointSize * _screenTools.smallFontPointRatio
mediumFontPointSize = defaultFontPointSize * _screenTools.mediumFontPointRatio
largeFontPointSize = defaultFontPointSize * _screenTools.largeFontPointRatio
}
}
}
......@@ -238,16 +238,22 @@ Rectangle {
Connections {
target: componentRepeater
onModelChanged: buttonColumn.reflowWidths()
}
// I don't know why this does not work
Connections {
target: QGroundControl
onBaseFontPointSizeChanged: buttonColumn.reflowWidths()
}
function reflowWidths() {
for (var i=0; i<children.length; i++) {
_maxButtonWidth = Math.max(_maxButtonWidth, children[i].width)
buttonColumn._maxButtonWidth = 0
for (var i = 0; i < children.length; i++) {
buttonColumn._maxButtonWidth = Math.max(buttonColumn._maxButtonWidth, children[i].width)
}
for (var i=0; i<children.length; i++) {
children[i].width = _maxButtonWidth
for (var j = 0; j < children.length; j++) {
children[j].width = buttonColumn._maxButtonWidth
}
}
......
......@@ -71,6 +71,70 @@ Rectangle {
width: parent.width
}
//-----------------------------------------------------------------
//-- Base UI Font Point Size
Row {
spacing: ScreenTools.defaultFontPixelWidth
QGCLabel {
width: _firstLabelWidth
text: qsTr("Base UI font size:")
anchors.verticalCenter: parent.verticalCenter
}
Row {
anchors.verticalCenter: parent.verticalCenter
Rectangle {
width: baseFontEdit.height
height: width
color: qgcPal.button
QGCLabel {
text: "-"
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked: {
if(ScreenTools.defaultFontPointSize > 6)
QGroundControl.baseFontPointSize = QGroundControl.baseFontPointSize - 1
}
}
}
QGCTextField {
id: baseFontEdit
width: _editFieldWidth - (height * 2)
text: QGroundControl.baseFontPointSize
showUnits: true
unitsLabel: "pt"
maximumLength: 6
validator: DoubleValidator {bottom: 6.0; top: 48.0; decimals: 2;}
onEditingFinished: {
var point = parseFloat(text)
if(point >= 6.0 && point <= 48.0)
QGroundControl.baseFontPointSize = point;
}
}
Rectangle {
width: baseFontEdit.height
height: width
color: qgcPal.button
QGCLabel {
text: "+"
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked: {
if(ScreenTools.defaultFontPointSize < 49)
QGroundControl.baseFontPointSize = QGroundControl.baseFontPointSize + 1
}
}
}
}
QGCLabel {
anchors.verticalCenter: parent.verticalCenter
text: qsTr("(requires reboot to take affect)")
}
}
//-----------------------------------------------------------------
//-- Units
......
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