VirtualBox

Ignore:
Timestamp:
Jul 4, 2018 9:28:36 AM (6 years ago)
Author:
vboxsync
Message:

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

File:
1 edited

Legend:

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

    r72678 r72856  
    7777
    7878    /** Constructs details element passing @a pParent to the base-class.
     79      * @param  strName       Brings the element name.
     80      * @param  icon          Brings the element icon.
    7981      * @param  fLinkSupport  Brings whether we should construct text-browser
    8082      *                       instead of simple text-edit otherwise. */
    81     UISnapshotDetailsElement(bool fLinkSupport, QWidget *pParent = 0);
     83    UISnapshotDetailsElement(const QString &strName, const QIcon &icon,
     84                             bool fLinkSupport, QWidget *pParent = 0);
    8285
    8386    /** Returns underlying text-document. */
     
    9295protected:
    9396
     97    /** Handles any Qt @a pEvent. */
     98    virtual bool event(QEvent *pEvent) /* override */;
     99
    94100    /** Handles paint @a pEvent. */
    95101    virtual void paintEvent(QPaintEvent *pEvent) /* override */;
     
    100106    void prepare();
    101107
     108    /** Updates pixmap. */
     109    void updatePixmap();
     110
     111    /** Holds the element name.*/
     112    QString  m_strName;
     113    /** Holds the element icon. */
     114    QIcon    m_icon;
    102115    /** Holds whether we should construct text-browser
    103116      * instead of simple text-edit otherwise. */
    104     bool  m_fLinkSupport;
     117    bool     m_fLinkSupport;
    105118
    106119    /** Holds the text-edit interface instance. */
     
    178191*********************************************************************************************************************************/
    179192
    180 UISnapshotDetailsElement::UISnapshotDetailsElement(bool fLinkSupport, QWidget *pParent /* = 0 */)
     193UISnapshotDetailsElement::UISnapshotDetailsElement(const QString &strName, const QIcon &icon,
     194                                                   bool fLinkSupport, QWidget *pParent /* = 0 */)
    181195    : QWidget(pParent)
     196    , m_strName(strName)
     197    , m_icon(icon)
    182198    , m_fLinkSupport(fLinkSupport)
    183199    , m_pTextEdit(0)
     
    212228    const int iIdealHeight = size.height() + 2 * iDocumentMargin + iTop + iBottom;
    213229    return QSize(iIdealWidth, iIdealHeight);
     230}
     231
     232bool UISnapshotDetailsElement::event(QEvent *pEvent)
     233{
     234    /* Handle know event types: */
     235    switch (pEvent->type())
     236    {
     237        case QEvent::Show:
     238        case QEvent::ScreenChangeInternal:
     239        {
     240            /* Update pixmap: */
     241            updatePixmap();
     242            break;
     243        }
     244        default:
     245            break;
     246    }
     247
     248    /* Call to base-class: */
     249    return QWidget::event(pEvent);
    214250}
    215251
     
    327363        }
    328364    }
     365
     366    /* Update pixmap: */
     367    updatePixmap();
     368}
     369
     370void UISnapshotDetailsElement::updatePixmap()
     371{
     372    /* Re-register icon in the element's text-document: */
     373    const int iMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
     374    document()->addResource(
     375        QTextDocument::ImageResource,
     376        QUrl(QString("details://%1").arg(m_strName)),
     377        QVariant(m_icon.pixmap(window()->windowHandle(), QSize(iMetric, iMetric))));
    329378}
    330379
     
    10031052    /* Create element: */
    10041053    const bool fWithHypertextNavigation = enmType == DetailsElementType_Preview;
    1005     UISnapshotDetailsElement *pElement = new UISnapshotDetailsElement(fWithHypertextNavigation);
     1054    UISnapshotDetailsElement *pElement = new UISnapshotDetailsElement(gpConverter->toInternalString(enmType),
     1055                                                                      gpConverter->toIcon(enmType),
     1056                                                                      fWithHypertextNavigation);
    10061057    AssertPtrReturn(pElement, 0);
    10071058    {
     
    10161067                break;
    10171068        }
    1018 
    1019         /* Register DetailsElementType icon in the element text-document: */
    1020         const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
    1021         const QSize iconSize = QSize(iIconMetric, iIconMetric);
    1022         pElement->document()->addResource(
    1023             QTextDocument::ImageResource,
    1024             QUrl(QString("details://%1").arg(gpConverter->toInternalString(enmType))),
    1025             QVariant(gpConverter->toIcon(enmType).pixmap(iconSize)));
    10261069    }
    10271070    /* Return element: */
Note: See TracChangeset for help on using the changeset viewer.

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