VirtualBox

Changeset 72824 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Jul 3, 2018 2:33:58 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
123369
Message:

FE/Qt: bugref:8694: Adjust icons when moving GUI between screen with different DPI: UIDesktopPane.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UIDesktopPane.cpp

    r69726 r72824  
    131131    void prepare();
    132132
     133    /** Updates pixmap. */
     134    void updatePixmap();
     135
    133136    /** Holds the action reference. */
    134137    QAction *m_pAction;
     
    180183protected:
    181184
     185    /** Handles any Qt @a pEvent. */
     186    virtual bool event(QEvent *pEvent) /* override */;
     187
    182188    /** Handles translation event. */
    183189    void retranslateUi();
     
    188194    /** Prepares tools pane. */
    189195    void prepareToolsPane();
     196
     197    /** Updates pixmap. */
     198    void updatePixmap();
    190199
    191200private:
     
    212221    /** Holds the tools pane icon label instance. */
    213222    QLabel           *m_pLabelToolsPaneIcon;
     223
     224    /** Holds the tools pane icon instance. */
     225    QIcon  m_icon;
    214226};
    215227
     
    308320    switch (pEvent->type())
    309321    {
     322        case QEvent::Show:
     323        case QEvent::ScreenChangeInternal:
     324        {
     325            /* Update pixmap: */
     326            updatePixmap();
     327            break;
     328        }
     329
    310330        /* Update the hovered state on/off: */
    311331        case QEvent::Enter:
     
    493513            /* Configure label: */
    494514            m_pLabelIcon->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    495             m_pLabelIcon->setPixmap(m_pAction->icon().pixmap(iMetric));
    496515
    497516            /* Add into layout: */
     
    500519        }
    501520    }
     521
     522    /* Update pixmap: */
     523    updatePixmap();
     524}
     525
     526void UIToolWidget::updatePixmap()
     527{
     528    const int iMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) * 1.375;
     529    m_pLabelIcon->setPixmap(m_pAction->icon().pixmap(window()->windowHandle(), QSize(iMetric, iMetric)));
    502530}
    503531
     
    546574    prepareToolsPane();
    547575
    548     /* Assign corresponding icon: */
    549     const QList<QSize> aSizes = icon.availableSizes();
    550     const QSize firstOne = aSizes.isEmpty() ? QSize(200, 200) : aSizes.first();
    551     const double dRatio = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize) / 32;
    552     m_pLabelToolsPaneIcon->setPixmap(icon.pixmap(QSize(firstOne.width() * dRatio, firstOne.height() * dRatio)));
     576    /* Save icon: */
     577    m_icon = icon;
     578    /* Update pixmap: */
     579    updatePixmap();
    553580
    554581    /* Raise corresponding widget: */
     
    585612        delete pChild;
    586613    }
     614}
     615
     616bool UIDesktopPanePrivate::event(QEvent *pEvent)
     617{
     618    /* Handle know event types: */
     619    switch (pEvent->type())
     620    {
     621        case QEvent::Show:
     622        case QEvent::ScreenChangeInternal:
     623        {
     624            /* Update pixmap: */
     625            updatePixmap();
     626            break;
     627        }
     628        default:
     629            break;
     630    }
     631
     632    /* Call to base-class: */
     633    return QIWithRetranslateUI<QStackedWidget>::event(pEvent);
    587634}
    588635
     
    743790}
    744791
     792void UIDesktopPanePrivate::updatePixmap()
     793{
     794    /* Assign corresponding icon: */
     795    const QList<QSize> aSizes = m_icon.availableSizes();
     796    const QSize firstOne = aSizes.isEmpty() ? QSize(200, 200) : aSizes.first();
     797    const double dRatio = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize) / 32;
     798    m_pLabelToolsPaneIcon->setPixmap(m_icon.pixmap(window()->windowHandle(), QSize(firstOne.width() * dRatio, firstOne.height() * dRatio)));
     799}
     800
    745801
    746802/*********************************************************************************************************************************
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette