VirtualBox

Ignore:
Timestamp:
Aug 9, 2017 2:21:48 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:8900: UIDesktopPane: Move wrapping labels from QILabel onto UILabel basis implemented just for UIDesktopPane; allows for _really_ dynamical size hint calculation.

File:
1 edited

Legend:

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

    r68310 r68353  
    3333
    3434/* GUI includes */
    35 # include "QILabel.h"
    3635# include "QIWithRetranslateUI.h"
    3736# include "UIDesktopPane.h"
     
    5756
    5857
     58/** Wrappable QLabel extension for tools pane of the desktop widget.
     59  * The main idea behind this stuff is to allow dynamically calculate
     60  * [minimum] size hint for changeable one-the-fly widget width.
     61  * That's a "white unicorn" task for QLabel which never worked since
     62  * the beginning, because out-of-the-box version just uses static
     63  * hints calculation which is very stupid taking into account
     64  * QLayout "eats it raw" and tries to be dynamical on it's basis. */
     65class UILabel : public QLabel
     66{
     67    Q_OBJECT;
     68
     69public:
     70
     71    /** Constructs scroll-area passing @a pParent to the base-class. */
     72    UILabel(QWidget *pParent = 0);
     73
     74protected:
     75
     76    /** Handles resize @a pEvent. */
     77    virtual void resizeEvent(QResizeEvent *pEvent) /* override */;
     78
     79    /** Returns whether the widget's preferred height depends on its width. */
     80    virtual bool hasHeightForWidth() const /* override */;
     81
     82    /** Holds the minimum widget size. */
     83    virtual QSize minimumSizeHint() const /* override */;
     84
     85    /** Holds the preferred widget size. */
     86    virtual QSize sizeHint() const /* override */;
     87};
     88
     89
    5990/** Our own skinnable implementation of tool widget header for UIDesktopPane. */
    6091class UIToolWidgetHeader : public QLabel
     
    115146    QLabel      *m_pLabelName;
    116147    /** Holds the description label instance. */
    117     QILabel     *m_pLabelDescription;
     148    QLabel      *m_pLabelDescription;
    118149};
    119150
     
    176207    QVBoxLayout *m_pLayoutWidget;
    177208    /** Holds the tools pane text label instance. */
    178     QILabel     *m_pLabelToolsPaneText;
     209    QLabel      *m_pLabelToolsPaneText;
    179210    /** Holds the tools pane icon label instance. */
    180211    QLabel      *m_pLabelToolsPaneIcon;
    181212};
     213
     214
     215/*********************************************************************************************************************************
     216*   Class UILabel implementation.                                                                                                *
     217*********************************************************************************************************************************/
     218
     219UILabel::UILabel(QWidget *pParent /* = 0 */)
     220    : QLabel(pParent)
     221{
     222}
     223
     224void UILabel::resizeEvent(QResizeEvent *pEvent)
     225{
     226    /* Call to base-class: */
     227    QLabel::resizeEvent(pEvent);
     228
     229    // WORKAROUND:
     230    // That's not cheap procedure but we need it to
     231    // make sure geometry is updated after width changed.
     232    if (minimumWidth() > 0)
     233        updateGeometry();
     234}
     235
     236bool UILabel::hasHeightForWidth() const
     237{
     238    // WORKAROUND:
     239    // No need to panic, we do it ourselves in resizeEvent() and
     240    // this 'false' here to prevent automatic layout fighting for it.
     241    return   minimumWidth() > 0
     242           ? false
     243           : QLabel::hasHeightForWidth();
     244}
     245
     246QSize UILabel::minimumSizeHint() const /* override */
     247{
     248    // WORKAROUND:
     249    // We should calculate hint height on the basis of width,
     250    // keeping the hint width equal to minimum we have set.
     251    return   minimumWidth() > 0
     252           ? QSize(minimumWidth(), heightForWidth(width()))
     253           : QLabel::minimumSizeHint();
     254}
     255
     256QSize UILabel::sizeHint() const /* override */
     257{
     258    // WORKAROUND:
     259    // Keep widget always minimal.
     260    return minimumSizeHint();
     261}
    182262
    183263
     
    424504
    425505        /* Create description label: */
    426         m_pLabelDescription = new QILabel;
     506        m_pLabelDescription = new UILabel;
    427507        AssertPtrReturnVoid(m_pLabelDescription);
    428508        {
     
    430510            m_pLabelDescription->setAttribute(Qt::WA_TransparentForMouseEvents);
    431511            m_pLabelDescription->setWordWrap(true);
    432             m_pLabelDescription->useSizeHintForWidth(400);
     512            m_pLabelDescription->setMinimumWidth(400);
    433513            m_pLabelDescription->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
    434514            m_pLabelDescription->setText(m_strDescription);
     
    636716
    637717                /* Create welcome text label: */
    638                 m_pLabelToolsPaneText = new QILabel;
     718                m_pLabelToolsPaneText = new UILabel;
    639719                AssertPtrReturnVoid(m_pLabelToolsPaneText);
    640720                {
    641721                    /* Configure label: */
    642722                    m_pLabelToolsPaneText->setWordWrap(true);
    643                     m_pLabelToolsPaneText->useSizeHintForWidth(200);
     723                    m_pLabelToolsPaneText->setMinimumWidth(200);
    644724                    m_pLabelToolsPaneText->setAlignment(Qt::AlignLeading | Qt::AlignTop);
    645                     m_pLabelToolsPaneText->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
     725                    m_pLabelToolsPaneText->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
    646726
    647727                    /* Add into layout: */
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