Add possibility to user to choose hdpi round policy

Add combo box in general configuration dialog to let user
choose the round policy to use with hdpi screen.
This commit is contained in:
joshua
2021-12-04 14:38:41 +01:00
parent eed1223c1d
commit b94ec0938b
5 changed files with 218 additions and 4 deletions

View File

@@ -20,6 +20,7 @@
#include "qetapp.h" #include "qetapp.h"
#include "singleapplication.h" #include "singleapplication.h"
#include "utils/macosxopenevent.h" #include "utils/macosxopenevent.h"
#include "utils/qetsettings.h"
#include <QStyleFactory> #include <QStyleFactory>
#include <QtConcurrent> #include <QtConcurrent>
@@ -178,7 +179,7 @@ int main(int argc, char **argv)
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
qputenv("QT_ENABLE_HIGHDPI_SCALING", "1"); qputenv("QT_ENABLE_HIGHDPI_SCALING", "1");
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); QGuiApplication::setHighDpiScaleFactorRoundingPolicy(QetSettings::hdpiScaleFactorRoundingPolicy());
#endif #endif

View File

@@ -20,6 +20,7 @@
#include "../../qetapp.h" #include "../../qetapp.h"
#include "../../qeticons.h" #include "../../qeticons.h"
#include "ui_generalconfigurationpage.h" #include "ui_generalconfigurationpage.h"
#include "../../utils/qetsettings.h"
#include <QFileDialog> #include <QFileDialog>
#include <QFontDialog> #include <QFontDialog>
@@ -37,6 +38,33 @@ GeneralConfigurationPage::GeneralConfigurationPage(QWidget *parent) :
QSettings settings; QSettings settings;
//Appearance tab
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) // ###Qt 6:remove
ui->m_hdpi_round_policy_widget->setDisabled(true);
#else
ui->m_hdpi_round_policy_cb->addItem(tr("Arrondi supérieur pour 0.5 et plus"), QLatin1String("Round"));
ui->m_hdpi_round_policy_cb->addItem(tr("Toujours arrondi supérieur"), QLatin1String("Ceil"));
ui->m_hdpi_round_policy_cb->addItem(tr("Toujours arrondi inférieur"), QLatin1String("Floor"));
ui->m_hdpi_round_policy_cb->addItem(tr("Arrondi supérieur pour 0.75 et plus"), QLatin1String("RoundPreferFloor"));
ui->m_hdpi_round_policy_cb->addItem(tr("Pas d'arrondi"), QLatin1String("PassThrough"));
switch (QetSettings::hdpiScaleFactorRoundingPolicy()) {
case Qt::HighDpiScaleFactorRoundingPolicy::Round:
ui->m_hdpi_round_policy_cb->setCurrentIndex(0);
break;
case Qt::HighDpiScaleFactorRoundingPolicy::Ceil:
ui->m_hdpi_round_policy_cb->setCurrentIndex(1);
break;
case Qt::HighDpiScaleFactorRoundingPolicy::Floor:
ui->m_hdpi_round_policy_cb->setCurrentIndex(2);
break;
case Qt::HighDpiScaleFactorRoundingPolicy::RoundPreferFloor:
ui->m_hdpi_round_policy_cb->setCurrentIndex(3);
break;
default:
ui->m_hdpi_round_policy_cb->setCurrentIndex(4);
break;
}
#endif
ui->DiagramEditor_xGrid_sb->setValue(settings.value("diagrameditor/Xgrid", 10).toInt()); ui->DiagramEditor_xGrid_sb->setValue(settings.value("diagrameditor/Xgrid", 10).toInt());
ui->DiagramEditor_yGrid_sb->setValue(settings.value("diagrameditor/Ygrid", 10).toInt()); ui->DiagramEditor_yGrid_sb->setValue(settings.value("diagrameditor/Ygrid", 10).toInt());
ui->DiagramEditor_xKeyGrid_sb->setValue(settings.value("diagrameditor/key_Xgrid", 10).toInt()); ui->DiagramEditor_xKeyGrid_sb->setValue(settings.value("diagrameditor/key_Xgrid", 10).toInt());
@@ -149,6 +177,10 @@ void GeneralConfigurationPage::applyConf()
settings.setValue("border-columns_0",ui->m_border_0->isChecked()); settings.setValue("border-columns_0",ui->m_border_0->isChecked());
settings.setValue("lang", ui->m_lang_cb->itemData(ui->m_lang_cb->currentIndex()).toString()); settings.setValue("lang", ui->m_lang_cb->itemData(ui->m_lang_cb->currentIndex()).toString());
//hdpi
QetSettings::setHdpiScaleFactorRoundingPolicy(ui->m_hdpi_round_policy_cb->currentData().toString());
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(QetSettings::hdpiScaleFactorRoundingPolicy());
//ELEMENT EDITOR //ELEMENT EDITOR
settings.setValue("elementeditor/default-informations", ui->m_default_elements_info->toPlainText()); settings.setValue("elementeditor/default-informations", ui->m_default_elements_info->toPlainText());

View File

@@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>727</width> <width>822</width>
<height>510</height> <height>411</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@@ -17,7 +17,7 @@
<item row="0" column="0"> <item row="0" column="0">
<widget class="QTabWidget" name="tabWidget"> <widget class="QTabWidget" name="tabWidget">
<property name="currentIndex"> <property name="currentIndex">
<number>5</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="tab_3"> <widget class="QWidget" name="tab_3">
<attribute name="title"> <attribute name="title">
@@ -73,6 +73,41 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="Line" name="line_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="m_hdpi_round_policy_widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Méthode de mise à l'echelle des écrans à haute densité de pixels (hdpi) (appliqué au prochain lancement de QElectroTech) :</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="m_hdpi_round_policy_cb"/>
</item>
</layout>
</widget>
</item>
<item> <item>
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">

View File

@@ -0,0 +1,109 @@
/*
Copyright 2006-2021 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech 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 2 of the License, or
(at your option) any later version.
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "qetsettings.h"
#include <QSettings>
#include <QVariant>
namespace QetSettings
{
/**
* @brief setHdpiScaleFactorRoundingPolicy
* Write the value of HdpiScaleFactorRoundingPolicy in
* QElectroTech settings
* the value is in form of a string.
* @a policy can be : Round, Ceil, Floor, RoundPreferFloor, PassThrough
* In case of wrong policy, PassThrough is use as defaukt value.
* The value is stored with key : hdpi_scale_factor_rounding_policy
* @sa Qt::HighDpiScaleFactorRoundingPolicy
* @param policy
*/
void setHdpiScaleFactorRoundingPolicy(const QString &policy_str)
{
auto policy = QString("PassThrough");
if (policy_str == QLatin1String("Round")) {
policy = "Round";
} else if (policy_str == QLatin1String("Ceil")) {
policy = "Ceil";
} else if (policy_str == QLatin1String("Floor")) {
policy = "Floor";
} else if (policy_str == QLatin1String("RoundPreferFloor")) {
policy = "RoundPreferFloor";
}
QSettings settings;
settings.setValue("hdpi_scale_factor_rounding_policy", policy);
}
/**
* @brief setHdpiScaleFactorRoundingPolicy
* Overload function
* @sa void setHdpiScaleFactorRoundingPolicy(const QString &policy_str)
* @param policy
*/
void setHdpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy policy)
{
QString policy_str;
switch (policy) {
case Qt::HighDpiScaleFactorRoundingPolicy::Round:
policy_str = "Round";
break;
case Qt::HighDpiScaleFactorRoundingPolicy::Ceil:
policy_str = "Ceil";
break;
case Qt::HighDpiScaleFactorRoundingPolicy::Floor:
policy_str = "Floor";
break;
case Qt::HighDpiScaleFactorRoundingPolicy::RoundPreferFloor:
policy_str = "RoundPreferFloor";
break;
default:
policy_str = "PassThrough";
break;
}
QSettings settings;
settings.setValue("hdpi_scale_factor_rounding_policy", policy_str);
}
/**
* @brief hdpiScaleFactorRoundingPolicy
* @param default_policy
* @return the hdpiScaleFactorRoundingPolicy value stored in current settings.
* @sa setHdpiScaleFactorRoundingPolicy
*/
Qt::HighDpiScaleFactorRoundingPolicy hdpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy default_policy)
{
QSettings settings;
auto value_ = settings.value("hdpi_scale_factor_rounding_policy");
if (value_ == QLatin1String("Round")) {
return Qt::HighDpiScaleFactorRoundingPolicy::Round;
} else if (value_ == QLatin1String("Ceil")) {
return Qt::HighDpiScaleFactorRoundingPolicy::Ceil;
} else if (value_ == QLatin1String("Floor")) {
return Qt::HighDpiScaleFactorRoundingPolicy::Floor;
} else if (value_ == QLatin1String("RoundPreferFloor")) {
return Qt::HighDpiScaleFactorRoundingPolicy::RoundPreferFloor;
} else if (value_ == QLatin1String("PassThrough")) {
return Qt::HighDpiScaleFactorRoundingPolicy::PassThrough;
} else {
return default_policy;
}
}
}

View File

@@ -0,0 +1,37 @@
/*
Copyright 2006-2021 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech 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 2 of the License, or
(at your option) any later version.
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef QETSETTINGS_H
#define QETSETTINGS_H
#include <Qt>
/**
*Interface to use QSettings in QElectroTech
*Prefer use this namespace instead of directly QSettings
*It's notably usefull when some QSettings value are use in
*different part of QElectroTech source code
*/
namespace QetSettings
{
void setHdpiScaleFactorRoundingPolicy(const QString &policy_str);
void setHdpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy policy);
Qt::HighDpiScaleFactorRoundingPolicy hdpiScaleFactorRoundingPolicy(
Qt::HighDpiScaleFactorRoundingPolicy default_policy = Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
}
#endif // QETSETTINGS_H