From 9fb9de53bcf3f13078cde455ee27002bd445e917 Mon Sep 17 00:00:00 2001 From: Ruslan Kabatsayev Date: Sun, 26 Jan 2025 22:37:40 +0800 Subject: [PATCH] Make it possible to scale screen buttons independently --- plugins/Oculars/src/Oculars.cpp | 4 + src/core/StelApp.cpp | 11 + src/core/StelApp.hpp | 8 + src/gui/ConfigurationDialog.cpp | 2 + src/gui/StelGuiItems.cpp | 22 +- src/gui/StelGuiItems.hpp | 1 + src/gui/configurationDialog.ui | 479 +++++++++++++++++--------------- 7 files changed, 305 insertions(+), 222 deletions(-) diff --git a/plugins/Oculars/src/Oculars.cpp b/plugins/Oculars/src/Oculars.cpp index d5eb9ef039a57..d82b413cf9b60 100644 --- a/plugins/Oculars/src/Oculars.cpp +++ b/plugins/Oculars/src/Oculars.cpp @@ -189,6 +189,10 @@ Oculars::Oculars() setObjectName("Oculars"); setFontSizeFromApp(StelApp::getInstance().getScreenFontSize()); connect(&StelApp::getInstance(), SIGNAL(screenFontSizeChanged(int)), this, SLOT(setFontSizeFromApp(int))); + connect(&StelApp::getInstance(), &StelApp::screenButtonScaleChanged, this, + [this]{const int size = StelApp::getInstance().getScreenFontSize(); + setFontSizeFromApp(size); /* and repeat to apply all the geometry changes */ + setFontSizeFromApp(size);}); ccds = QList(); oculars = QList(); diff --git a/src/core/StelApp.cpp b/src/core/StelApp.cpp index f6422d26eba40..ad574d19de34e 100644 --- a/src/core/StelApp.cpp +++ b/src/core/StelApp.cpp @@ -450,6 +450,7 @@ void StelApp::init(QSettings* conf) setScreenFontSize(confSettings->value("gui/screen_font_size", getDefaultGuiFontSize()).toInt()); setGuiFontSize(confSettings->value("gui/gui_font_size", getDefaultGuiFontSize()).toInt()); + setScreenButtonScale(confSettings->value("gui/screen_button_scale", 100).toDouble()); SplashScreen::present(guiFontSizeRatio()); @@ -1464,6 +1465,16 @@ void StelApp::setScreenFontSize(int s) } } +void StelApp::setScreenButtonScale(const double s) +{ + if (screenButtonScale!=s) + { + screenButtonScale = s; + StelApp::immediateSave("gui/screen_button_scale", s); + emit screenButtonScaleChanged(s); + } +} + double StelApp::screenFontSizeRatio() const { return double(getScreenFontSize()) / getDefaultGuiFontSize(); diff --git a/src/core/StelApp.hpp b/src/core/StelApp.hpp index 5a048ac12b073..d92ae213585f8 100644 --- a/src/core/StelApp.hpp +++ b/src/core/StelApp.hpp @@ -88,6 +88,7 @@ class StelApp : public QObject Q_PROPERTY(Vec3f daylightInfoColor READ getDaylightInfoColor WRITE setDaylightInfoColor NOTIFY daylightInfoColorChanged) Q_PROPERTY(int screenFontSize READ getScreenFontSize WRITE setScreenFontSize NOTIFY screenFontSizeChanged) Q_PROPERTY(int guiFontSize READ getGuiFontSize WRITE setGuiFontSize NOTIFY guiFontSizeChanged) + Q_PROPERTY(double screenButtonScale READ getScreenButtonScale WRITE setScreenButtonScale NOTIFY screenButtonScaleChanged) Q_PROPERTY(bool flagImmediateSave READ getFlagImmediateSave WRITE setFlagImmediateSave NOTIFY flagImmediateSaveChanged) Q_PROPERTY(QString version READ getVersion CONSTANT) @@ -225,6 +226,11 @@ class StelApp : public QObject //! change GUI font size. void setGuiFontSize(int s); + //! Get the ratio (in percent) of screen button size to the default screen scale-dependent one + double getScreenButtonScale() const { return screenButtonScale; } + //! Set the ratio (in percent) of screen button size to the default screen scale-dependent one + void setScreenButtonScale(double s); + //! Combines #getDevicePixelsPerPixel and #getScreenFontSize float getScreenScale() const; @@ -374,6 +380,7 @@ public slots: void languageChanged(); void screenFontSizeChanged(int); void guiFontSizeChanged(int); + void screenButtonScaleChanged(double); void fontChanged(const QFont&); void overwriteInfoColorChanged(const Vec3f & color); void daylightInfoColorChanged(const Vec3f & color); @@ -505,6 +512,7 @@ public slots: QList progressControllers; + double screenButtonScale = 100; // in percent int screenFontSize; int numMultiSamples = 1; diff --git a/src/gui/ConfigurationDialog.cpp b/src/gui/ConfigurationDialog.cpp index c1e7d174d221d..1eb027eee089e 100644 --- a/src/gui/ConfigurationDialog.cpp +++ b/src/gui/ConfigurationDialog.cpp @@ -354,6 +354,7 @@ void ConfigurationDialog::createDialogContent() // Font selection. We use a hidden, but documented entry in config.ini to optionally show a font selection option. connectIntProperty(ui->screenFontSizeSpinBox, "StelApp.screenFontSize"); connectIntProperty(ui->guiFontSizeSpinBox, "StelApp.guiFontSize"); + connectDoubleProperty(ui->screenButtonScaleSpinBox, "StelApp.screenButtonScale"); if (StelApp::getInstance().getSettings()->value("gui/flag_font_selection", true).toBool()) { populateFontWritingSystemCombo(); @@ -1235,6 +1236,7 @@ void ConfigurationDialog::saveAllSettings() //conf->setValue("gui/screen_font_size", propMgr->getStelPropertyValue("StelApp.screenFontSize").toInt()); //conf->setValue("gui/gui_font_size", propMgr->getStelPropertyValue("StelApp.guiFontSize").toInt()); storeFontSettings(); + conf->setValue("gui/screen_button_scale", propMgr->getStelPropertyValue("StelApp.screenButtonScale").toDouble()); conf->setValue("video/minimum_fps", propMgr->getStelPropertyValue("MainView.minFps").toInt()); conf->setValue("video/maximum_fps", propMgr->getStelPropertyValue("MainView.maxFps").toInt()); diff --git a/src/gui/StelGuiItems.cpp b/src/gui/StelGuiItems.cpp index 66fa390e7a233..28b794274eb88 100644 --- a/src/gui/StelGuiItems.cpp +++ b/src/gui/StelGuiItems.cpp @@ -234,6 +234,12 @@ int StelButton::toggleChecked(int checked) return checked; } +double StelButton::buttonSizeRatio() +{ + const auto& app = StelApp::getInstance(); + return app.screenFontSizeRatio() * app.getScreenButtonScale()/100; +} + void StelButton::hoverEnterEvent(QGraphicsSceneHoverEvent*) { timeLine->setDirection(QTimeLine::Forward); @@ -356,12 +362,12 @@ QRectF StelButton::boundingRect() const int StelButton::getButtonPixmapWidth() const { - const double baseWidth = pixOn.width() / pixmapsScale * StelApp::getInstance().screenFontSizeRatio(); + const double baseWidth = pixOn.width() / pixmapsScale * buttonSizeRatio(); return std::lround(baseWidth); } int StelButton::getButtonPixmapHeight() const { - const double baseHeight = pixOn.height() / pixmapsScale * StelApp::getInstance().screenFontSizeRatio(); + const double baseHeight = pixOn.height() / pixmapsScale * buttonSizeRatio(); return std::lround(baseHeight); } @@ -404,6 +410,10 @@ LeftStelBar::LeftStelBar(QGraphicsItem* parent) setFontSizeFromApp(StelApp::getInstance().getScreenFontSize()); connect(&StelApp::getInstance(), &StelApp::screenFontSizeChanged, this, &LeftStelBar::setFontSizeFromApp); + connect(&StelApp::getInstance(), &StelApp::screenButtonScaleChanged, this, + [this]{const int size = StelApp::getInstance().getScreenFontSize(); + setFontSizeFromApp(size); /* and repeat to apply all the geometry changes */ + setFontSizeFromApp(size);}); connect(&StelApp::getInstance(), &StelApp::fontChanged, this, &LeftStelBar::setFont); } @@ -423,7 +433,7 @@ void LeftStelBar::addButton(StelButton* button) button->setParentItem(this); button->setFocusOnSky(false); //button->prepareGeometryChange(); // could possibly be removed when qt 4.6 become stable - button->setPos(0., qRound(posY + 9.5 * StelApp::getInstance().screenFontSizeRatio())); + button->setPos(0., qRound(posY + 9.5 * StelButton::buttonSizeRatio())); connect(button, SIGNAL(hoverChanged(bool)), this, SLOT(buttonHoverChanged(bool))); } @@ -436,7 +446,7 @@ void LeftStelBar::updateButtonPositions() if (const auto b = dynamic_cast(button)) b->animValueChanged(0.); // update button pixmap button->setPos(0., posY); - posY += std::round(button->boundingRect().height() + 9.5 * StelApp::getInstance().screenFontSizeRatio()); + posY += std::round(button->boundingRect().height() + 9.5 * StelButton::buttonSizeRatio()); } } @@ -566,6 +576,10 @@ BottomStelBar::BottomStelBar(QGraphicsItem* parent, setFontSizeFromApp(StelApp::getInstance().getScreenFontSize()); connect(&StelApp::getInstance(), &StelApp::screenFontSizeChanged, this, [=](int fontsize){setFontSizeFromApp(fontsize); setFontSizeFromApp(fontsize);}); // We must call that twice to force all geom. updates + connect(&StelApp::getInstance(), &StelApp::screenButtonScaleChanged, this, + [this]{const int size = StelApp::getInstance().getScreenFontSize(); + setFontSizeFromApp(size); /* and repeat to apply all the geometry changes */ + setFontSizeFromApp(size);}); connect(&StelApp::getInstance(), &StelApp::fontChanged, this, &BottomStelBar::setFont); connect(StelApp::getInstance().getCore(), &StelCore::flagUseTopocentricCoordinatesChanged, this, [=](bool){updateText(false, true);}); diff --git a/src/gui/StelGuiItems.hpp b/src/gui/StelGuiItems.hpp index f61dc52ab6e1a..68b2a775647c9 100644 --- a/src/gui/StelGuiItems.hpp +++ b/src/gui/StelGuiItems.hpp @@ -173,6 +173,7 @@ private slots: bool noBackground, bool isTristate); int toggleChecked(int); + static double buttonSizeRatio(); QPixmap pixOn; QPixmap pixOff; diff --git a/src/gui/configurationDialog.ui b/src/gui/configurationDialog.ui index ae0e51d88c603..ab8082fdbf097 100644 --- a/src/gui/configurationDialog.ui +++ b/src/gui/configurationDialog.ui @@ -1749,20 +1749,6 @@ 0 - - - - - - Dithering - - - - - - - - @@ -1812,27 +1798,6 @@ - - - - - - Info text color for overwrite - - - - - - - Set one color for text in info panel for all objects - - - Overwrite text color - - - - - @@ -1843,16 +1808,34 @@ - - + + - When enabled, the "auto zoom out" key will also set the initial viewing direction + Kinetic scrolling means dragging text panels directly instead of dragging window handles. - Auto-direction at zoom out + Use kinetic scrolling + + + + + + Info text color at daylight + + + + + + + Info text color at daylight + + + + + @@ -1863,6 +1846,124 @@ + + + + + + + + + 0 + 0 + + + + Parallax is the apparent shift in the position of an object when viewed from two different points. + + + Parallax + + + + + + + Exaggerate parallax (for didactic explanations) + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 0 + + + 1.000000000000000 + + + 10000.000000000000000 + + + 1.000000000000000 + + + 1.000000000000000 + + + + + + + + + + + + 0 + 0 + + + + Annual aberration is an annual wobble in positions, amounting to max. about 20 arcseconds for observers on Earth. + + + Aberration + + + + + + + Exaggerate aberration (for didactic explanations) + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 1 + + + 5.000000000000000 + + + 0.100000000000000 + + + 1.000000000000000 + + + + + + + + + Include + + + + + + + Nutation is a small wobble of Earth's axis, amounting to a few arcseconds. + + + Nutation + + + + + + + Activate to view as seen from surface of the planet (recommended). If switched off, display planetocentric view. + + + Topocentric coordinates + + + + + @@ -1942,39 +2043,6 @@ - - - - Force date/time tab and focus on day input when activating date panel - - - Set keyboard focus to day input - - - - - - - Allow mouse to zoom (mousewheel) - - - Enable mouse zooming - - - - - - - Spheric mirror distortion is used when projecting Stellarium onto a spheric mirror for low-cost planetarium systems. - - - Spheric mirror distortion - - - true - - - @@ -2020,16 +2088,104 @@ - - + + + + + + Dithering + + + + + + + + + + - Kinetic scrolling means dragging text panels directly instead of dragging window handles. + Align labels with the screen center - Use kinetic scrolling + Gravity labels + + + + Spheric mirror distortion is used when projecting Stellarium onto a spheric mirror for low-cost planetarium systems. + + + Spheric mirror distortion + + + true + + + + + + + When enabled, the "auto zoom out" key will also set the initial viewing direction + + + Auto-direction at zoom out + + + + + + + Force date/time tab and focus on day input when activating date panel + + + Set keyboard focus to day input + + + + + + + Allow mouse to zoom (mousewheel) + + + Enable mouse zooming + + + + + + + Flash a short message when toggling mount mode. + + + Indication for mount mode + + + + + + + + + Info text color for overwrite + + + + + + + Set one color for text in info panel for all objects + + + Overwrite text color + + + + + @@ -2067,17 +2223,7 @@ - - - - Align labels with the screen center - - - Gravity labels - - - - + @@ -2184,147 +2330,44 @@ - - - - - - - - - 0 - 0 - - - - Parallax is the apparent shift in the position of an object when viewed from two different points. - - - Parallax - - - - - - - Exaggerate parallax (for didactic explanations) - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - 0 - - - 1.000000000000000 - - - 10000.000000000000000 - - - 1.000000000000000 - - - 1.000000000000000 - - - - - - - - - - - - 0 - 0 - - - - Annual aberration is an annual wobble in positions, amounting to max. about 20 arcseconds for observers on Earth. - - - Aberration - - - - - - - Exaggerate aberration (for didactic explanations) - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - 1 - - - 5.000000000000000 - - - 0.100000000000000 - - - 1.000000000000000 - - - - - - - + + + + - Include + Screen button scale: - - - - Nutation is a small wobble of Earth's axis, amounting to a few arcseconds. + + + + Qt::Horizontal - - Nutation + + + 40 + 20 + - + - - - - Activate to view as seen from surface of the planet (recommended). If switched off, display planetocentric view. + + + + % - - Topocentric coordinates + + 0 - - - - - - - - Flash a short message when toggling mount mode. - - - Indication for mount mode - - - - - - - - - Info text color at daylight + + 10.000000000000000 - - - - - - Info text color at daylight + + 500.000000000000000 + + + 100.000000000000000