Skip to content

Commit

Permalink
merge consti's fixes, dpi/fonts (#627)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelscholle authored Dec 3, 2023
1 parent 7c11a80 commit a0118b7
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 16 deletions.
30 changes: 18 additions & 12 deletions app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,15 @@ int main(int argc, char *argv[]) {

QSettings settings;
qDebug()<<"Storing settings at ["<<settings.fileName()<<"]";
// RPI only - set a smaller default screen scale, for whatever reason thats needed
if(QOpenHD::instance().is_platform_rpi() || QOpenHD::instance().is_platform_rock()){
if(!settings.value("qopenhd_custom_default_screen_has_been_set",false).toBool()){
qDebug()<<"Setting initial rpi screen scale";
settings.setValue("qopenhd_custom_default_screen_has_been_set",true);
settings.setValue("global_scale",0.7);
// RPI and ROCK - disable font dpi. The user has to scale manually when using displays
// (Bigger than) 640x480 according to its preferences. On rpi, auto scale is just bugged,
// nothing more to say.
if(QOpenHD::instance().is_platform_rpi() || QOpenHD::instance().is_platform_rock() || true){
static constexpr auto TAG_QOPENHD_INITIAL_FONT_DPI_HAS_BEEN_SET="qopenhd_initial_font_dpi_has_been_set";
if(!settings.value(TAG_QOPENHD_INITIAL_FONT_DPI_HAS_BEEN_SET,false).toBool()){
qDebug()<<"RPI/ROCK: Disable font dpi by default";
settings.setValue(TAG_QOPENHD_INITIAL_FONT_DPI_HAS_BEEN_SET,true);
settings.setValue("screen_custom_font_dpi",-1);
}
}
if(QOpenHD::instance().is_platform_rock()){
Expand All @@ -222,21 +225,24 @@ int main(int argc, char *argv[]) {
settings.setValue("dev_always_use_generic_external_decode_service",true);
}
}

const int screen_custom_font_dpi = settings.value("screen_custom_font_dpi").toInt();
if (screen_custom_font_dpi) {
if(screen_custom_font_dpi<0){
// Disabled
QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling);
}else if(screen_custom_font_dpi==0){
// Enabled (whatever qt thinks it wanna do on auto). Works on android, on other devices, meh
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
}else{
// Custom font dpi set by the user
QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling);
const std::string font_dpi_s = std::to_string(screen_custom_font_dpi);
qputenv("QT_FONT_DPI", QByteArray(font_dpi_s.c_str(), font_dpi_s.length()));
} else {
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
}
//QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);
//QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling);
const double global_scale = settings.value("global_scale", 1.0).toDouble();
const std::string global_scale_s = std::to_string(global_scale);
QByteArray scaleAsQByteArray(global_scale_s.c_str(), global_scale_s.length());
qputenv("QT_SCALE_FACTOR", scaleAsQByteArray);
qputenv("QT_SCALE_FACTOR", QByteArray(global_scale_s.c_str(), global_scale_s.length()));

// https://doc.qt.io/qt-6/qtquick-visualcanvas-scenegraph-renderer.html
//qputenv("QSG_VISUALIZE", "overdraw");
Expand Down
4 changes: 4 additions & 0 deletions qml/ui/configpopup/connect/PaneConnectionMode.qml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Rectangle{
color: m_is_air_or_ground_connected ? "red" : "black"
verticalAlignment: Qt.AlignVCenter
horizontalAlignment: Qt.AlignHCenter
font.pixelSize: settings.qopenhd_general_font_pixel_size
}
ComboBox {
Layout.fillWidth: false
Expand Down Expand Up @@ -93,6 +94,7 @@ Rectangle{
text: _mavlinkTelemetry.telemetry_connection_status
verticalAlignment: Qt.AlignVCenter
horizontalAlignment: Qt.AlignHCenter
font.pixelSize: settings.qopenhd_general_font_pixel_size
}

// Visible when auto mode is enabled ------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -218,6 +220,7 @@ Rectangle{
Text{
Layout.alignment: Qt.AlignCenter
text: "Listening on localhost:5600"
font.pixelSize: settings.qopenhd_general_font_pixel_size
}
Item{ // filler
Layout.fillWidth: true
Expand Down Expand Up @@ -253,6 +256,7 @@ Rectangle{
Layout.alignment: Qt.AlignCenter
Layout.columnSpan: 2
text: "TCP PORT: 5760"
font.pixelSize: settings.qopenhd_general_font_pixel_size
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions qml/ui/configpopup/log/LogMessagesView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ Rectangle{
verticalAlignment: Text.AlignVCenter
height: parent.height
opacity: 1.0
font.pixelSize: settings.qopenhd_general_font_pixel_size
}
Text {
text: model.message
anchors { left:tagViewFC.right; verticalCenter: tagViewFC.verticalCenter; leftMargin: 5 }
verticalAlignment: Text.AlignVCenter
height: parent.height
opacity: 1.0
font.pixelSize: settings.qopenhd_general_font_pixel_size
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions qml/ui/configpopup/openhd_settings/LinkQuickPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ Rectangle{
verticalAlignment: Qt.AlignVCenter
horizontalAlignment: Qt.AlignHCenter
font.bold: false
font.pixelSize: settings.qopenhd_general_font_pixel_size
}
Text{
Layout.preferredHeight: 50
Expand All @@ -329,6 +330,7 @@ Rectangle{
verticalAlignment: Qt.AlignVCenter
horizontalAlignment: Qt.AlignHCenter
font.bold: false
font.pixelSize: settings.qopenhd_general_font_pixel_size
}
Text{
Layout.preferredHeight: 50
Expand All @@ -348,6 +350,7 @@ Rectangle{
verticalAlignment: Qt.AlignVCenter
horizontalAlignment: Qt.AlignHCenter
font.bold: false
font.pixelSize: settings.qopenhd_general_font_pixel_size
}
Item{ // FILLER
Layout.fillWidth: true
Expand Down Expand Up @@ -387,6 +390,7 @@ Rectangle{
verticalAlignment: Qt.AlignVCenter
horizontalAlignment: Qt.AlignHCenter
font.bold: false
font.pixelSize: settings.qopenhd_general_font_pixel_size
}
Button{
text: "EDIT"
Expand All @@ -403,6 +407,7 @@ Rectangle{
verticalAlignment: Qt.AlignVCenter
horizontalAlignment: Qt.AlignHCenter
font.bold: false
font.pixelSize: settings.qopenhd_general_font_pixel_size
}
Button{
text: "EDIT"
Expand Down Expand Up @@ -435,13 +440,15 @@ Rectangle{
verticalAlignment: Qt.AlignVCenter
horizontalAlignment: Qt.AlignHCenter
font.bold: false
font.pixelSize: settings.qopenhd_general_font_pixel_size
}
Text{
Layout.preferredWidth: 120
text: "GND:\n"+get_text_stbc_ldpc(false);
verticalAlignment: Qt.AlignVCenter
horizontalAlignment: Qt.AlignHCenter
font.bold: false
font.pixelSize: settings.qopenhd_general_font_pixel_size
}
Button{
text: "EDIT";
Expand Down
10 changes: 6 additions & 4 deletions qml/ui/configpopup/qopenhd_settings/AppScreenSettingsView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ ScrollView {
anchors.horizontalCenter: parent.horizonatalCenter
width: 320
model: ListModel {
id: font_dpi
ListElement { text: qsTr("-1 Disable") ; value: -1 }
ListElement { text: qsTr("0 Auto (Recommended)") ; value: 0 }
ListElement { text: qsTr("50 (ultra small)") ; value: 50 }
ListElement { text: qsTr("72 (smaller)") ; value: 72 }
Expand All @@ -145,12 +145,14 @@ ScrollView {
}
}
}
onCurrentIndexChanged: {
const value_fdpi = font_dpi.get(currentIndex).value
onActivated:{
const value_fdpi = model.get(currentIndex).value
if(settings.screen_custom_font_dpi != value_fdpi){
console.log("font dpi changed from :"+settings.screen_custom_font_dpi+" to:"+value_fdpi);
_restartqopenhdmessagebox.show();
settings.screen_custom_font_dpi = value_fdpi
}
settings.screen_custom_font_dpi = value_fdpi

}
}
}
Expand Down
6 changes: 6 additions & 0 deletions qml/ui/elements/AppSettings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Settings {
// Set a custom font dpi instead of QT high dpi auto scaling.
// Requires restart to be applied
property int screen_custom_font_dpi: 0
// Consti10: Since we rely on font.pixel size in the HUD anyways, in general,
// small to medium sized text should use this pixel size. Please dont't touch for now,
// in general, if you increase this value, text(fields) with hard coded width / height values
// will not handle this value properly ! If you increase this one, you (might) have to touch
// 100s of code places, too
property int qopenhd_general_font_pixel_size: 14

// Dirty, rotate everything even though that can create issues
property int general_screen_rotation: 0
Expand Down

0 comments on commit a0118b7

Please sign in to comment.