Skip to content

Commit

Permalink
Make it possible to scale screen buttons independently
Browse files Browse the repository at this point in the history
  • Loading branch information
10110111 committed Jan 27, 2025
1 parent 02c2756 commit 9fb9de5
Show file tree
Hide file tree
Showing 7 changed files with 305 additions and 222 deletions.
4 changes: 4 additions & 0 deletions plugins/Oculars/src/Oculars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CCD *>();
oculars = QList<Ocular *>();
Expand Down
11 changes: 11 additions & 0 deletions src/core/StelApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions src/core/StelApp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -505,6 +512,7 @@ public slots:

QList<StelProgressController*> progressControllers;

double screenButtonScale = 100; // in percent
int screenFontSize;
int numMultiSamples = 1;

Expand Down
2 changes: 2 additions & 0 deletions src/gui/ConfigurationDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand Down
22 changes: 18 additions & 4 deletions src/gui/StelGuiItems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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)));
}
Expand All @@ -436,7 +446,7 @@ void LeftStelBar::updateButtonPositions()
if (const auto b = dynamic_cast<StelButton*>(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());
}
}

Expand Down Expand Up @@ -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);});

Expand Down
1 change: 1 addition & 0 deletions src/gui/StelGuiItems.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ private slots:
bool noBackground,
bool isTristate);
int toggleChecked(int);
static double buttonSizeRatio();

QPixmap pixOn;
QPixmap pixOff;
Expand Down
Loading

0 comments on commit 9fb9de5

Please sign in to comment.