Changeset 68353 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Aug 9, 2017 2:21:48 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/selector/UIDesktopPane.cpp
r68310 r68353 33 33 34 34 /* GUI includes */ 35 # include "QILabel.h"36 35 # include "QIWithRetranslateUI.h" 37 36 # include "UIDesktopPane.h" … … 57 56 58 57 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. */ 65 class UILabel : public QLabel 66 { 67 Q_OBJECT; 68 69 public: 70 71 /** Constructs scroll-area passing @a pParent to the base-class. */ 72 UILabel(QWidget *pParent = 0); 73 74 protected: 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 59 90 /** Our own skinnable implementation of tool widget header for UIDesktopPane. */ 60 91 class UIToolWidgetHeader : public QLabel … … 115 146 QLabel *m_pLabelName; 116 147 /** Holds the description label instance. */ 117 Q ILabel*m_pLabelDescription;148 QLabel *m_pLabelDescription; 118 149 }; 119 150 … … 176 207 QVBoxLayout *m_pLayoutWidget; 177 208 /** Holds the tools pane text label instance. */ 178 Q ILabel*m_pLabelToolsPaneText;209 QLabel *m_pLabelToolsPaneText; 179 210 /** Holds the tools pane icon label instance. */ 180 211 QLabel *m_pLabelToolsPaneIcon; 181 212 }; 213 214 215 /********************************************************************************************************************************* 216 * Class UILabel implementation. * 217 *********************************************************************************************************************************/ 218 219 UILabel::UILabel(QWidget *pParent /* = 0 */) 220 : QLabel(pParent) 221 { 222 } 223 224 void 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 236 bool 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 246 QSize 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 256 QSize UILabel::sizeHint() const /* override */ 257 { 258 // WORKAROUND: 259 // Keep widget always minimal. 260 return minimumSizeHint(); 261 } 182 262 183 263 … … 424 504 425 505 /* Create description label: */ 426 m_pLabelDescription = new QILabel;506 m_pLabelDescription = new UILabel; 427 507 AssertPtrReturnVoid(m_pLabelDescription); 428 508 { … … 430 510 m_pLabelDescription->setAttribute(Qt::WA_TransparentForMouseEvents); 431 511 m_pLabelDescription->setWordWrap(true); 432 m_pLabelDescription-> useSizeHintForWidth(400);512 m_pLabelDescription->setMinimumWidth(400); 433 513 m_pLabelDescription->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); 434 514 m_pLabelDescription->setText(m_strDescription); … … 636 716 637 717 /* Create welcome text label: */ 638 m_pLabelToolsPaneText = new QILabel;718 m_pLabelToolsPaneText = new UILabel; 639 719 AssertPtrReturnVoid(m_pLabelToolsPaneText); 640 720 { 641 721 /* Configure label: */ 642 722 m_pLabelToolsPaneText->setWordWrap(true); 643 m_pLabelToolsPaneText-> useSizeHintForWidth(200);723 m_pLabelToolsPaneText->setMinimumWidth(200); 644 724 m_pLabelToolsPaneText->setAlignment(Qt::AlignLeading | Qt::AlignTop); 645 m_pLabelToolsPaneText->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy:: Fixed);725 m_pLabelToolsPaneText->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); 646 726 647 727 /* Add into layout: */
Note:
See TracChangeset
for help on using the changeset viewer.