diff --git a/src/gui/SkyGui.cpp b/src/gui/SkyGui.cpp index 4dc92cd0a74cf..4d80092a78544 100644 --- a/src/gui/SkyGui.cpp +++ b/src/gui/SkyGui.cpp @@ -386,6 +386,7 @@ void SkyGui::updateBarsPos() progressBarMgr->setZValue(400); // Update position of the auto-hide buttons + btHorizAutoHide->setPos(1,btVertAutoHide->getButtonPixmapHeight()-btHorizAutoHide->getButtonPixmapHeight()+1); autoHidebts->setPos(0, hh-autoHidebts->childrenBoundingRect().height()+1); double opacity = qMax(animLeftBarTimeLine->currentValue(), animBottomBarTimeLine->currentValue()); autoHidebts->setOpacity(qMax(0.01, opacity)); // Work around a qt bug diff --git a/src/gui/StelGuiItems.cpp b/src/gui/StelGuiItems.cpp index c24bae1624952..92ccbda1e4e52 100644 --- a/src/gui/StelGuiItems.cpp +++ b/src/gui/StelGuiItems.cpp @@ -55,6 +55,16 @@ #include #include +namespace +{ + +constexpr double DEFAULT_FONT_SIZE = 13; + +double fontSizeRatio() +{ + return StelApp::getInstance().getScreenFontSize() / DEFAULT_FONT_SIZE; +} + void brightenImage(QImage &img, float factor) { for (int y=0; yscreen()->devicePixelRatio(); if(scaledCurrentPixmap.isNull() || ratio != scaledCurrentPixmap.devicePixelRatioF()) { - const auto scale = ratio / pixmapsScale; - scaledCurrentPixmap = pixmap().scaled(pixOn.size()*scale, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + const auto size = boundingRect().size() * ratio; + scaledCurrentPixmap = pixmap().scaled(size.toSize(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); scaledCurrentPixmap.setDevicePixelRatio(ratio); } // Align the pixmap to pixel grid, otherwise we'll get artifacts at some scaling factors. @@ -402,16 +424,28 @@ void LeftStelBar::addButton(StelButton* button) if (QGraphicsItem::childItems().size()!=0) { const QRectF& r = childrenBoundingRect(); - posY += r.bottom()-1; + posY += r.bottom(); } button->setParentItem(this); button->setFocusOnSky(false); //button->prepareGeometryChange(); // could possibly be removed when qt 4.6 become stable - button->setPos(0., qRound(posY+10.5)); + button->setPos(0., qRound(posY + 9.5 * fontSizeRatio())); connect(button, SIGNAL(hoverChanged(bool)), this, SLOT(buttonHoverChanged(bool))); } +void LeftStelBar::updateButtonPositions() +{ + double posY = 0; + for (const auto button : childItems()) + { + 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 * fontSizeRatio()); + } +} + void LeftStelBar::paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) { } @@ -476,6 +510,7 @@ void LeftStelBar::setColor(const QColor& c) //! connect from StelApp to resize fonts on the fly. void LeftStelBar::setFontSizeFromApp(int size) { + prepareGeometryChange(); // Font size was developed based on base font size 13, i.e. 12 int screenFontSize = size-1; QFont font=QGuiApplication::font(); @@ -487,7 +522,10 @@ void LeftStelBar::setFontSizeFromApp(int size) // to avoid crash SkyGui* skyGui=gui->getSkyGui(); if (skyGui) + { skyGui->updateBarsPos(); + updateButtonPositions(); + } } } diff --git a/src/gui/StelGuiItems.hpp b/src/gui/StelGuiItems.hpp index d9c7862a3e9f9..f2f38637c20a6 100644 --- a/src/gui/StelGuiItems.hpp +++ b/src/gui/StelGuiItems.hpp @@ -116,8 +116,8 @@ class StelButton : public QObject, public QGraphicsPixmapItem //! Get the width of the button image. //! The width is based on pixOn. - int getButtonPixmapWidth() const {return pixOn.width() / pixmapsScale;} - int getButtonPixmapHeight() const {return pixOn.height() / pixmapsScale;} + int getButtonPixmapWidth() const; + int getButtonPixmapHeight() const; //! Set the button opacity void setOpacity(double v) {opacity=v; updateIcon();} @@ -220,6 +220,7 @@ private slots: void setFontSizeFromApp(int size); //! connect from StelApp to set font on the fly. void setFont(const QFont &cfont); + void updateButtonPositions(); private: QTimeLine* hideTimeLine; QGraphicsSimpleTextItem* helpLabel;