Skip to content

Commit

Permalink
add per QQuickPaintedItem font scale
Browse files Browse the repository at this point in the history
  • Loading branch information
Consti10 committed Oct 30, 2023
1 parent e64c397 commit 6a3a079
Show file tree
Hide file tree
Showing 19 changed files with 146 additions and 32 deletions.
11 changes: 10 additions & 1 deletion app/osd/altitudeladder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "debug_overdraw.hpp"

static constexpr int DEFAULT_FONT_PIXEL_SIZE=11;

AltitudeLadder::AltitudeLadder(QQuickItem *parent): QQuickPaintedItem(parent) {
qDebug() << "AltitudeLadder::AltitudeLadder()";
setRenderTarget(RenderTarget::FramebufferObject);
Expand Down Expand Up @@ -119,6 +121,13 @@ void AltitudeLadder::setAltitudeRange(int altitudeRange) {
void AltitudeLadder::setFontFamily(QString fontFamily) {
m_fontFamily = fontFamily;
emit fontFamilyChanged(m_fontFamily);
m_font = QFont(m_fontFamily, 13, QFont::Bold, false);
m_font = QFont(m_fontFamily, DEFAULT_FONT_PIXEL_SIZE*m_custom_font_scale, QFont::Bold, false);
update();
}

void AltitudeLadder::set_custom_font_scale(double custom_font_scale)
{
m_custom_font_scale=custom_font_scale;
m_font.setPointSize(DEFAULT_FONT_PIXEL_SIZE*m_custom_font_scale);
update();
}
8 changes: 7 additions & 1 deletion app/osd/altitudeladder.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <QQuickPaintedItem>
#include <QPainter>

#include "../../../lib/lqtutils_master/lqtutils_prop.h"

class AltitudeLadder : public QQuickPaintedItem {
Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
Expand All @@ -10,7 +12,8 @@ class AltitudeLadder : public QQuickPaintedItem {
// actual altitude, unit - less
Q_PROPERTY(int altitude MEMBER m_altitude WRITE set_altitude NOTIFY altitude_changed)
Q_PROPERTY(QString fontFamily MEMBER m_fontFamily WRITE setFontFamily NOTIFY fontFamilyChanged)

public:
Q_PROPERTY(double custom_font_scale WRITE set_custom_font_scale)
public:
explicit AltitudeLadder(QQuickItem* parent = nullptr);

Expand All @@ -25,6 +28,7 @@ public slots:
void setAltitudeRange(int altitudeRange);
void set_altitude(double alt);
void setFontFamily(QString fontFamily);
void set_custom_font_scale(double custom_font_scale);
signals:
void colorChanged(QColor color);
void glowChanged(QColor glow);
Expand All @@ -43,4 +47,6 @@ public slots:
QString m_fontFamily;
QFont m_font;

double m_custom_font_scale=1.0;

};
1 change: 0 additions & 1 deletion app/osd/aoagauge.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <QQuickPaintedItem>
#include <QPainter>


class AoaGauge : public QQuickPaintedItem {
Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
Expand Down
1 change: 1 addition & 0 deletions app/osd/debug_overdraw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
// Such that we can enable / disable the "overdraw debugging" with just a single variable change
static constexpr bool ENABLE_DEBUG_OVERDRAW=false;


#endif // DEBUG_OVERDRAW_HPP
1 change: 0 additions & 1 deletion app/osd/flightpathvector.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <QQuickPaintedItem>
#include <QPainter>


class FlightPathVector : public QQuickPaintedItem {
Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
Expand Down
11 changes: 10 additions & 1 deletion app/osd/headingladder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "debug_overdraw.hpp"

static constexpr int DEFAULT_FONT_PIXEL_SIZE=11;

HeadingLadder::HeadingLadder(QQuickItem *parent): QQuickPaintedItem(parent) {
qDebug() << "HeadingLadder::HeadingLadder()";
setRenderTarget(RenderTarget::FramebufferObject);
Expand Down Expand Up @@ -235,6 +237,13 @@ void HeadingLadder::setHomeHeading(int homeHeading) {
void HeadingLadder::setFontFamily(QString fontFamily) {
m_fontFamily = fontFamily;
emit fontFamilyChanged(m_fontFamily);
m_font = QFont(m_fontFamily, 11, QFont::Bold, false);
m_font = QFont(m_fontFamily, DEFAULT_FONT_PIXEL_SIZE*m_custom_font_scale, QFont::Bold, false);
update();
}

void HeadingLadder::set_custom_font_scale(double custom_font_scale)
{
m_custom_font_scale=custom_font_scale;
m_font.setPointSize(DEFAULT_FONT_PIXEL_SIZE*m_custom_font_scale);
update();
}
9 changes: 6 additions & 3 deletions app/osd/headingladder.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <QQuickPaintedItem>
#include <QPainter>

#include "../../../lib/lqtutils_master/lqtutils_prop.h"

class HeadingLadder : public QQuickPaintedItem {
Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
Expand All @@ -16,8 +18,8 @@ class HeadingLadder : public QQuickPaintedItem {

Q_PROPERTY(QString fontFamily MEMBER m_fontFamily WRITE setFontFamily NOTIFY fontFamilyChanged)


//show_horizon_heading_ladder
public:
Q_PROPERTY(double custom_font_scale WRITE set_custom_font_scale)

public:
explicit HeadingLadder(QQuickItem* parent = nullptr);
Expand All @@ -39,7 +41,7 @@ public slots:
void setHomeHeading(int homeHeading);

void setFontFamily(QString fontFamily);

void set_custom_font_scale(double custom_font_scale);
signals:
void colorChanged(QColor color);
void glowChanged(QColor glow);
Expand Down Expand Up @@ -69,4 +71,5 @@ public slots:
QFont m_font;

QFont m_fontAwesome = QFont("Font Awesome 5 Free", 14, QFont::Bold, false);
double m_custom_font_scale=1.0;
};
12 changes: 10 additions & 2 deletions app/osd/horizonladder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
#include <QPainter>
#include <math.h>

#include "common/TimeHelper.hpp"
#include "debug_overdraw.hpp"

static constexpr int DEFAULT_FONT_PIXEL_SIZE=11;

HorizonLadder::HorizonLadder(QQuickItem *parent): QQuickPaintedItem(parent) {
qDebug() << "HorizonLadder::HorizonLadder()";
setRenderTarget(RenderTarget::FramebufferObject);
Expand Down Expand Up @@ -491,6 +492,13 @@ void HorizonLadder::setShowHorizonHome(bool showHorizonHome) {
void HorizonLadder::setFontFamily(QString fontFamily) {
m_fontFamily = fontFamily;
emit fontFamilyChanged(m_fontFamily);
m_font = QFont(m_fontFamily, 11, QFont::Bold, false);
m_font = QFont(m_fontFamily, DEFAULT_FONT_PIXEL_SIZE*m_custom_font_scale, QFont::Bold, false);
update();
}

void HorizonLadder::set_custom_font_scale(double custom_font_scale)
{
m_custom_font_scale=custom_font_scale;
m_font.setPointSize(DEFAULT_FONT_PIXEL_SIZE*m_custom_font_scale);
update();
}
6 changes: 4 additions & 2 deletions app/osd/horizonladder.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class HorizonLadder : public QQuickPaintedItem {
L_RW_PROP(bool,show_center_indicator, set_show_center_indicator, true)
// Adjust the stroke strength of the lines, in percent
//L_RW_PROP(double,line_stroke_strength_perc, set_line_stroke_strength_perc, 100)

public:
Q_PROPERTY(double custom_font_scale WRITE set_custom_font_scale)
public:
explicit HorizonLadder(QQuickItem* parent = nullptr);

Expand Down Expand Up @@ -61,7 +62,7 @@ public slots:
void setShowHorizonHome(bool showHorizonHome);

void setFontFamily(QString fontFamily);

void set_custom_font_scale(double custom_font_scale);
signals:
void colorChanged(QColor color);
void glowChanged(QColor glow);
Expand Down Expand Up @@ -108,5 +109,6 @@ public slots:
QFont m_font;

QFont m_fontAwesome = QFont("Font Awesome 5 Free", 15, QFont::Bold, false);
double m_custom_font_scale=1.0;
};
#endif //QOPENHD_HORIZON_LADDER
11 changes: 10 additions & 1 deletion app/osd/speedladder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "debug_overdraw.hpp"

static constexpr int DEFAULT_FONT_PIXEL_SIZE=11;

SpeedLadder::SpeedLadder(QQuickItem *parent): QQuickPaintedItem(parent) {
qDebug() << "SpeedLadder::SpeedLadder()";
setRenderTarget(RenderTarget::FramebufferObject);
Expand Down Expand Up @@ -129,6 +131,13 @@ void SpeedLadder::setSpeed(int speed) {
void SpeedLadder::setFontFamily(QString fontFamily) {
m_fontFamily = fontFamily;
emit fontFamilyChanged(m_fontFamily);
m_font = QFont(m_fontFamily, 10, QFont::Bold, false);
m_font = QFont(m_fontFamily, DEFAULT_FONT_PIXEL_SIZE*m_custom_font_scale, QFont::Bold, false);
update();
}

void SpeedLadder::set_custom_font_scale(double custom_font_scale)
{
m_custom_font_scale=custom_font_scale;
m_font.setPointSize(DEFAULT_FONT_PIXEL_SIZE*m_custom_font_scale);
update();
}
8 changes: 5 additions & 3 deletions app/osd/speedladder.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <QQuickPaintedItem>
#include <QPainter>

#include "../../../lib/lqtutils_master/lqtutils_prop.h"

class SpeedLadder : public QQuickPaintedItem {
Q_OBJECT
Expand All @@ -13,7 +14,8 @@ class SpeedLadder : public QQuickPaintedItem {
Q_PROPERTY(int speed MEMBER m_speed WRITE setSpeed NOTIFY speedChanged)

Q_PROPERTY(QString fontFamily MEMBER m_fontFamily WRITE setFontFamily NOTIFY fontFamilyChanged)

public:
Q_PROPERTY(double custom_font_scale WRITE set_custom_font_scale)
public:
explicit SpeedLadder(QQuickItem* parent = nullptr);

Expand All @@ -31,7 +33,7 @@ public slots:

void setSpeed(int speed);
void setFontFamily(QString fontFamily);

void set_custom_font_scale(double custom_font_scale);
signals:
void colorChanged(QColor color);
void glowChanged(QColor glow);
Expand All @@ -51,5 +53,5 @@ public slots:
QString m_fontFamily;

QFont m_font;

double m_custom_font_scale=1.0;
};
2 changes: 2 additions & 0 deletions qml/ui/HUDOverlayGrid.qml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Item {
property bool m_show_vertical_center_indicator: false
property bool m_show_horizontal_center_indicator: false

//scale: settings.dev_some_scale

//signal settingsButtonClicked
property int m_highlight_index : 0
property int m_MAX_ITEM_INDEX: 15
Expand Down
18 changes: 15 additions & 3 deletions qml/ui/elements/OSDCustomizer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import "colorwheel"
Rectangle {
id: osdCustomizer

width: 196
height: 312
//width: 196
//height: 312
width: 250
height: 350

color: "#ffeaeaea"


property bool stateVisible: visible

states: [
Expand Down Expand Up @@ -191,6 +192,17 @@ Rectangle {
}
}

/*Item{
height: 60
width: parent.width - 24
Slider{
from: 0.5
to: 1.5
value: settings.hud_osd_qquickpainteditem_font_scale
onValueChanged: settings.hud_osd_qquickpainteditem_font_scale=value
}
}*/

Button {
height: 60
width: parent.width - 24
Expand Down
4 changes: 3 additions & 1 deletion qml/ui/widgets/AltitudeWidget.qml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ BaseWidget {
id: idBaseWidgetDefaultUiControlElements

show_vertical_lock: true
show_horizontal_lock: true
//show_horizontal_lock: true
show_quickpainteditem_font_scale: true

Item {
width: parent.width
Expand Down Expand Up @@ -192,6 +193,7 @@ BaseWidget {
altitudeRange: settings.altitude_ladder_range
Behavior on altitude {NumberAnimation { duration: settings.smoothing }}
fontFamily: settings.font_text
custom_font_scale: bw_qquickpainteditem_font_scale
}
}
//-----------------------ladder end---------------
Expand Down
37 changes: 25 additions & 12 deletions qml/ui/widgets/BaseWidget.qml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,34 @@ BaseWidgetForm {
settings.sync();
}
// Feature persist scale end --------------------------------------------------------------------------------------
// Feature persist opacity begin

// Feature persist opacity begin ------------------------------------------------------------------------------------
property string bw_opacity_identifier: "%1_opacity".arg(widgetIdentifier);
// Default opacity is 1, the value is persistent
property double bw_current_opacity : settings.value(bw_opacity_identifier,1.0);
// Feature persist opacity end
// Updates the current base widget scale (unique per widgetIdentifier) and persist the value for later use
function bw_set_current_opacity(opacity){
if(opacity <=0 || opacity>1){
console.warn("perhaps invalid widget opacity");
}
bw_current_opacity=opacity
settings.setValue(bw_opacity_identifier, bw_current_opacity);
settings.sync();
}
// Feature persist opacity end --------------------------------------------------------------------------------------

// Feature persist 'qquickpainteditem_font_scale' begin ------------------------------------------------------------
// only for qquick painted items (few)
property string bw_qquickpainteditem_font_scale_identifier: "%1_qquickpainteditem_font_scale".arg(widgetIdentifier);
property double bw_qquickpainteditem_font_scale: settings.value(bw_qquickpainteditem_font_scale_identifier,1.0);
function bw_set_qquickpainteditem_font_scale(scale){
bw_qquickpainteditem_font_scale=scale;
settings.setValue(bw_qquickpainteditem_font_scale_identifier,bw_qquickpainteditem_font_scale);
settings.sync();
}
// Feature persist 'qquickpainteditem_font_scale' end --------------------------------------------------------------


// Feature: Show grid when dragging
property bool m_show_grid_when_dragging: false
onDraggingChanged: {
Expand All @@ -81,16 +104,6 @@ BaseWidgetForm {
}
}

// Updates the current base widget scale (unique per widgetIdentifier) and persist the value for later use
function bw_set_current_opacity(opacity){
if(opacity <=0 || opacity>1){
console.warn("perhaps invalid widget opacity");
}
bw_current_opacity=opacity
settings.setValue(bw_opacity_identifier, bw_current_opacity);
settings.sync();
}
// Feature persist opacity end


// Added by Consti10 -
Expand Down
Loading

0 comments on commit 6a3a079

Please sign in to comment.