VirtualBox

Changeset 103068 in vbox


Ignore:
Timestamp:
Jan 25, 2024 3:59:38 PM (12 months ago)
Author:
vboxsync
Message:

FE/Qt: UIWelcomePane: Heavy rework; Replacing UIWrappableLabel with QIRichTextLabel, cleaning corresponding stuff.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r102493 r103068  
    10121012        src/manager/UIVirtualBoxManager.cpp \
    10131013        src/manager/UIVirtualMachineItemCloud.cpp \
    1014         src/manager/UIWelcomePane.cpp \
    10151014        src/manager/chooser/UIChooserAbstractModel.cpp \
    10161015        src/activity/overview/UIVMActivityOverviewWidget.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIWelcomePane.cpp

    r103061 r103068  
    3131#include <QStyle>
    3232#include <QVBoxLayout>
     33#include <QUrl>
    3334
    3435/* GUI includes */
     36#include "QIRichTextLabel.h"
    3537#include "QIWithRetranslateUI.h"
    3638#include "UICommon.h"
     
    3840#include "UIIconPool.h"
    3941#include "UIWelcomePane.h"
    40 
    41 
    42 /** Wrappable QLabel extension for tools pane of the desktop widget.
    43   * The main idea behind this stuff is to allow dynamically calculate
    44   * [minimum] size hint for changeable one-the-fly widget width.
    45   * That's a "white unicorn" task for QLabel which never worked since
    46   * the beginning, because out-of-the-box version just uses static
    47   * hints calculation which is very stupid taking into account
    48   * QLayout "eats it raw" and tries to be dynamical on it's basis. */
    49 class UIWrappableLabel : public QLabel
    50 {
    51     Q_OBJECT;
    52 
    53 public:
    54 
    55     /** Constructs wrappable label passing @a pParent to the base-class. */
    56     UIWrappableLabel(QWidget *pParent = 0);
    57 
    58 protected:
    59 
    60     /** Handles resize @a pEvent. */
    61     virtual void resizeEvent(QResizeEvent *pEvent) RT_OVERRIDE;
    62 
    63     /** Returns whether the widget's preferred height depends on its width. */
    64     virtual bool hasHeightForWidth() const RT_OVERRIDE;
    65 
    66     /** Holds the minimum widget size. */
    67     virtual QSize minimumSizeHint() const RT_OVERRIDE;
    68 
    69     /** Holds the preferred widget size. */
    70     virtual QSize sizeHint() const RT_OVERRIDE;
    71 };
    72 
    73 
    74 /*********************************************************************************************************************************
    75 *   Class UIWrappableLabel implementation.                                                                                       *
    76 *********************************************************************************************************************************/
    77 
    78 UIWrappableLabel::UIWrappableLabel(QWidget *pParent /* = 0 */)
    79     : QLabel(pParent)
    80 {
    81 }
    82 
    83 void UIWrappableLabel::resizeEvent(QResizeEvent *pEvent)
    84 {
    85     /* Call to base-class: */
    86     QLabel::resizeEvent(pEvent);
    87 
    88     // WORKAROUND:
    89     // That's not cheap procedure but we need it to
    90     // make sure geometry is updated after width changed.
    91     if (minimumWidth() > 0)
    92         updateGeometry();
    93 }
    94 
    95 bool UIWrappableLabel::hasHeightForWidth() const
    96 {
    97     // WORKAROUND:
    98     // No need to panic, we do it ourselves in resizeEvent() and
    99     // this 'false' here to prevent automatic layout fighting for it.
    100     return   minimumWidth() > 0
    101            ? false
    102            : QLabel::hasHeightForWidth();
    103 }
    104 
    105 QSize UIWrappableLabel::minimumSizeHint() const
    106 {
    107     // WORKAROUND:
    108     // We should calculate hint height on the basis of width,
    109     // keeping the hint width equal to minimum we have set.
    110     return   minimumWidth() > 0
    111            ? QSize(minimumWidth(), heightForWidth(width()))
    112            : QLabel::minimumSizeHint();
    113 }
    114 
    115 QSize UIWrappableLabel::sizeHint() const
    116 {
    117     // WORKAROUND:
    118     // Keep widget always minimal.
    119     return minimumSizeHint();
    120 }
    12142
    12243
     
    14263        {
    14364            /* Update pixmap: */
     65            updateTextLabels();
    14466            updatePixmap();
    14567            break;
     
    16789}
    16890
    169 void UIWelcomePane::sltHandleLinkActivated(const QString &strLink)
     91void UIWelcomePane::sltHandleLinkActivated(const QUrl &urlLink)
    17092{
    171     uiCommon().openURL(strLink);
     93    uiCommon().openURL(urlLink.toString());
    17294}
    17395
     
    189111
    190112            /* Prepare greetings label: */
    191             m_pLabelGreetings = new UIWrappableLabel(this);
     113            m_pLabelGreetings = new QIRichTextLabel(this);
    192114            if (m_pLabelGreetings)
    193115            {
    194                 m_pLabelGreetings->setWordWrap(true);
    195                 m_pLabelGreetings->setMinimumWidth(160); /// @todo make dynamic
    196                 m_pLabelGreetings->setAlignment(Qt::AlignLeading | Qt::AlignTop);
    197116                m_pLabelGreetings->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
    198                 connect(m_pLabelGreetings, &QLabel::linkActivated, this, &UIWelcomePane::sltHandleLinkActivated);
    199 
    200                 /* Add into layout: */
     117                connect(m_pLabelGreetings, &QIRichTextLabel::sigLinkClicked, this, &UIWelcomePane::sltHandleLinkActivated);
    201118                pLayoutWelcome->addWidget(m_pLabelGreetings);
    202119            }
     
    226143    /* Translate finally: */
    227144    retranslateUi();
    228     /* Update pixmap: */
     145    /* Update stuff: */
     146    updateTextLabels();
    229147    updatePixmap();
     148}
     149
     150void UIWelcomePane::updateTextLabels()
     151{
     152    /* For all the text-labels: */
     153    QList<QIRichTextLabel*> labels = findChildren<QIRichTextLabel*>();
     154    if (!labels.isEmpty())
     155    {
     156        /* Make sure their minimum width is around 20% of the screen width: */
     157        const QSize screenGeometry = gpDesktop->screenGeometry(this).size();
     158        foreach (QIRichTextLabel *pLabel, labels)
     159            pLabel->setMinimumTextWidth(screenGeometry.width() * .2);
     160    }
    230161}
    231162
     
    243174    }
    244175}
    245 
    246 
    247 #include "UIWelcomePane.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIWelcomePane.h

    r103061 r103068  
    4141/* Forward declarations: */
    4242class QLabel;
     43class QIRichTextLabel;
    4344
    4445/** QWidget subclass holding Welcome information about VirtualBox. */
     
    6263private slots:
    6364
    64     /** Handles activated @a strLink. */
    65     void sltHandleLinkActivated(const QString &strLink);
     65    /** Handles activated @a urlLink. */
     66    void sltHandleLinkActivated(const QUrl &urlLink);
    6667
    6768private:
     
    7071    void prepare();
    7172
     73    /** Updates text labels. */
     74    void updateTextLabels();
    7275    /** Updates pixmap. */
    7376    void updatePixmap();
     
    7780
    7881    /** Holds the greetings label instance. */
    79     QLabel *m_pLabelGreetings;
     82    QIRichTextLabel *m_pLabelGreetings;
    8083    /** Holds the icon label instance. */
    81     QLabel *m_pLabelIcon;
     84    QLabel          *m_pLabelIcon;
    8285};
    8386
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