Changeset 103068 in vbox
- Timestamp:
- Jan 25, 2024 3:59:38 PM (12 months ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r102493 r103068 1012 1012 src/manager/UIVirtualBoxManager.cpp \ 1013 1013 src/manager/UIVirtualMachineItemCloud.cpp \ 1014 src/manager/UIWelcomePane.cpp \1015 1014 src/manager/chooser/UIChooserAbstractModel.cpp \ 1016 1015 src/activity/overview/UIVMActivityOverviewWidget.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/manager/UIWelcomePane.cpp
r103061 r103068 31 31 #include <QStyle> 32 32 #include <QVBoxLayout> 33 #include <QUrl> 33 34 34 35 /* GUI includes */ 36 #include "QIRichTextLabel.h" 35 37 #include "QIWithRetranslateUI.h" 36 38 #include "UICommon.h" … … 38 40 #include "UIIconPool.h" 39 41 #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 calculate44 * [minimum] size hint for changeable one-the-fly widget width.45 * That's a "white unicorn" task for QLabel which never worked since46 * the beginning, because out-of-the-box version just uses static47 * hints calculation which is very stupid taking into account48 * QLayout "eats it raw" and tries to be dynamical on it's basis. */49 class UIWrappableLabel : public QLabel50 {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 to90 // make sure geometry is updated after width changed.91 if (minimumWidth() > 0)92 updateGeometry();93 }94 95 bool UIWrappableLabel::hasHeightForWidth() const96 {97 // WORKAROUND:98 // No need to panic, we do it ourselves in resizeEvent() and99 // this 'false' here to prevent automatic layout fighting for it.100 return minimumWidth() > 0101 ? false102 : QLabel::hasHeightForWidth();103 }104 105 QSize UIWrappableLabel::minimumSizeHint() const106 {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() > 0111 ? QSize(minimumWidth(), heightForWidth(width()))112 : QLabel::minimumSizeHint();113 }114 115 QSize UIWrappableLabel::sizeHint() const116 {117 // WORKAROUND:118 // Keep widget always minimal.119 return minimumSizeHint();120 }121 42 122 43 … … 142 63 { 143 64 /* Update pixmap: */ 65 updateTextLabels(); 144 66 updatePixmap(); 145 67 break; … … 167 89 } 168 90 169 void UIWelcomePane::sltHandleLinkActivated(const Q String &strLink)91 void UIWelcomePane::sltHandleLinkActivated(const QUrl &urlLink) 170 92 { 171 uiCommon().openURL( strLink);93 uiCommon().openURL(urlLink.toString()); 172 94 } 173 95 … … 189 111 190 112 /* Prepare greetings label: */ 191 m_pLabelGreetings = new UIWrappableLabel(this);113 m_pLabelGreetings = new QIRichTextLabel(this); 192 114 if (m_pLabelGreetings) 193 115 { 194 m_pLabelGreetings->setWordWrap(true);195 m_pLabelGreetings->setMinimumWidth(160); /// @todo make dynamic196 m_pLabelGreetings->setAlignment(Qt::AlignLeading | Qt::AlignTop);197 116 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); 201 118 pLayoutWelcome->addWidget(m_pLabelGreetings); 202 119 } … … 226 143 /* Translate finally: */ 227 144 retranslateUi(); 228 /* Update pixmap: */ 145 /* Update stuff: */ 146 updateTextLabels(); 229 147 updatePixmap(); 148 } 149 150 void 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 } 230 161 } 231 162 … … 243 174 } 244 175 } 245 246 247 #include "UIWelcomePane.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/manager/UIWelcomePane.h
r103061 r103068 41 41 /* Forward declarations: */ 42 42 class QLabel; 43 class QIRichTextLabel; 43 44 44 45 /** QWidget subclass holding Welcome information about VirtualBox. */ … … 62 63 private slots: 63 64 64 /** Handles activated @a strLink. */65 void sltHandleLinkActivated(const Q String &strLink);65 /** Handles activated @a urlLink. */ 66 void sltHandleLinkActivated(const QUrl &urlLink); 66 67 67 68 private: … … 70 71 void prepare(); 71 72 73 /** Updates text labels. */ 74 void updateTextLabels(); 72 75 /** Updates pixmap. */ 73 76 void updatePixmap(); … … 77 80 78 81 /** Holds the greetings label instance. */ 79 Q Label *m_pLabelGreetings;82 QIRichTextLabel *m_pLabelGreetings; 80 83 /** Holds the icon label instance. */ 81 QLabel *m_pLabelIcon;84 QLabel *m_pLabelIcon; 82 85 }; 83 86
Note:
See TracChangeset
for help on using the changeset viewer.