Changeset 71484 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Mar 23, 2018 12:07:29 PM (7 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/widgets
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPopupBox.cpp
r69726 r71484 5 5 6 6 /* 7 * Copyright (C) 2010-201 7Oracle Corporation7 * Copyright (C) 2010-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 22 22 /* Qt includes: */ 23 23 # include <QApplication> 24 # include <QStyle>25 24 # include <QLabel> 26 25 # include <QPainter> 26 # include <QPaintEvent> 27 # include <QStyle> 27 28 # include <QVBoxLayout> 28 # include <QPaintEvent>29 29 30 30 /* GUI includes: */ … … 36 36 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 37 37 38 39 /********************************************************************************************************************************* 40 * Class UIPopupBox implementation. * 41 *********************************************************************************************************************************/ 42 38 43 UIPopupBox::UIPopupBox(QWidget *pParent) 39 44 : QWidget(pParent) 40 , m_pTitleIcon( new QLabel(this))41 , m_pWarningIcon( new QLabel(this))42 , m_pTitleLabel( new QLabel(this))45 , m_pTitleIcon(0) 46 , m_pWarningIcon(0) 47 , m_pTitleLabel(0) 43 48 , m_fLinkEnabled(false) 49 , m_fOpened(true) 50 , m_fHovered(false) 44 51 , m_pContentWidget(0) 45 , m_fOpen(true)46 52 , m_pLabelPath(0) 47 53 , m_iArrowWidth(9) 48 , m_fHeaderHover(false) 49 { 50 /* Setup main-layout: */ 51 QVBoxLayout *pMainLayout = new QVBoxLayout(this); 52 /* Setup title-layout: */ 53 QHBoxLayout *pTitleLayout = new QHBoxLayout; 54 pTitleLayout->addWidget(m_pTitleIcon); 55 pTitleLayout->addWidget(m_pWarningIcon); 56 pTitleLayout->addWidget(m_pTitleLabel, Qt::AlignLeft); 57 /* Add title-layout into main-layout: */ 58 pMainLayout->addLayout(pTitleLayout); 59 60 /* Configure widgets: */ 61 m_pWarningIcon->setHidden(true); 54 { 55 /* Configure self: */ 56 installEventFilter(this); 57 58 /* Configure painter-path: */ 62 59 m_arrowPath.lineTo(m_iArrowWidth / 2.0, m_iArrowWidth / 2.0); 63 60 m_arrowPath.lineTo(m_iArrowWidth, 0); 64 61 65 /* Setup connections: */ 66 connect(m_pTitleLabel, SIGNAL(linkActivated(const QString)), this, SIGNAL(sigTitleClicked(const QString))); 67 68 /* Install local event-filters: */ 69 installEventFilter(this); 70 m_pTitleIcon->installEventFilter(this); 71 m_pWarningIcon->installEventFilter(this); 72 m_pTitleLabel->installEventFilter(this); 62 /* Create main-layout: */ 63 QVBoxLayout *pMainLayout = new QVBoxLayout(this); 64 if (pMainLayout) 65 { 66 /* Create title-layout: */ 67 QHBoxLayout *pTitleLayout = new QHBoxLayout; 68 if (pTitleLayout) 69 { 70 /* Create title-icon label. */ 71 m_pTitleIcon = new QLabel; 72 if (m_pTitleIcon) 73 { 74 /* Configure label: */ 75 m_pTitleIcon->installEventFilter(this); 76 77 /* Add into layout: */ 78 pTitleLayout->addWidget(m_pTitleIcon); 79 } 80 /* Create warning-icon label. */ 81 m_pWarningIcon = new QLabel; 82 if (m_pWarningIcon) 83 { 84 /* Configure label: */ 85 m_pWarningIcon->setHidden(true); 86 m_pWarningIcon->installEventFilter(this); 87 88 /* Add into layout: */ 89 pTitleLayout->addWidget(m_pWarningIcon); 90 } 91 /* Create title-text label. */ 92 m_pTitleLabel = new QLabel; 93 if (m_pTitleLabel) 94 { 95 /* Configure label: */ 96 m_pTitleLabel->installEventFilter(this); 97 connect(m_pTitleLabel, SIGNAL(linkActivated(const QString)), 98 this, SIGNAL(sigTitleClicked(const QString))); 99 100 /* Add into layout: */ 101 pTitleLayout->addWidget(m_pTitleLabel, Qt::AlignLeft); 102 } 103 104 /* Add into layout: */ 105 pMainLayout->addLayout(pTitleLayout); 106 } 107 } 108 73 109 } 74 110 75 111 UIPopupBox::~UIPopupBox() 76 112 { 113 /* Delete label painter-path if any: */ 77 114 if (m_pLabelPath) 78 115 delete m_pLabelPath; … … 170 207 } 171 208 172 void UIPopupBox::setOpen(bool fOpen )209 void UIPopupBox::setOpen(bool fOpened) 173 210 { 174 211 /* Check if we should toggle popup-box: */ 175 if (m_fOpen == fOpen)212 if (m_fOpened == fOpened) 176 213 return; 177 214 178 215 /* Store new value: */ 179 m_fOpen = fOpen;216 m_fOpened = fOpened; 180 217 181 218 /* Update content-widget if present or this itself: */ 182 219 if (m_pContentWidget) 183 m_pContentWidget->setVisible(m_fOpen );220 m_pContentWidget->setVisible(m_fOpened); 184 221 else 185 222 update(); … … 193 230 { 194 231 /* Switch 'opened' state: */ 195 setOpen(!m_fOpen );232 setOpen(!m_fOpened); 196 233 197 234 /* Notify listeners about toggling: */ 198 emit sigToggled(m_fOpen );235 emit sigToggled(m_fOpened); 199 236 } 200 237 201 238 bool UIPopupBox::isOpen() const 202 239 { 203 return m_fOpen ;204 } 205 206 bool UIPopupBox::eventFilter(QObject *p Watched, QEvent *pEvent)240 return m_fOpened; 241 } 242 243 bool UIPopupBox::eventFilter(QObject *pObject, QEvent *pEvent) 207 244 { 208 245 /* Handle all mouse-event to update hover: */ … … 214 251 updateHover(); 215 252 /* Call to base-class: */ 216 return QWidget::eventFilter(p Watched, pEvent);253 return QWidget::eventFilter(pObject, pEvent); 217 254 } 218 255 … … 223 260 /* Call to base-class: */ 224 261 QWidget::resizeEvent(pEvent); 225 }226 227 void UIPopupBox::mouseDoubleClickEvent(QMouseEvent * /* pEvent */)228 {229 /* Toggle popup-box: */230 toggleOpen();231 262 } 232 263 … … 250 281 lg.setColorAt(1, base.darker(110)); 251 282 int theight = rect.height(); 252 if (m_fOpen )283 if (m_fOpened) 253 284 theight = 2 * 5 + iMaxHeightHint; 254 285 painter.fillRect(QRect(rect.x(), rect.y(), rect.width(), theight), lg); … … 257 288 painter.strokePath(*m_pLabelPath, base.darker(110)); 258 289 /* Arrow */ 259 if (m_fH eaderHover)290 if (m_fHovered) 260 291 { 261 292 painter.setBrush(base.darker(106)); 262 293 painter.setPen(QPen(base.darker(128), 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); 263 294 QSizeF s = m_arrowPath.boundingRect().size(); 264 if (m_fOpen )295 if (m_fOpened) 265 296 { 266 297 painter.translate(rect.x() + rect.width() - s.width() - 10, rect.y() + theight / 2 + s.height() / 2); … … 274 305 painter.drawPath(m_arrowPath); 275 306 } 307 } 308 309 void UIPopupBox::mouseDoubleClickEvent(QMouseEvent *) 310 { 311 /* Toggle popup-box: */ 312 toggleOpen(); 276 313 } 277 314 … … 308 345 QPalette pal = m_pTitleLabel->palette(); 309 346 m_pTitleLabel->setText(QString("<b><a style=\"text-decoration: none; color: %1\" href=\"%2\">%3</a></b>") 310 .arg(m_fH eaderHover? pal.color(QPalette::Link).name() : pal.color(QPalette::WindowText).name())347 .arg(m_fHovered ? pal.color(QPalette::Link).name() : pal.color(QPalette::WindowText).name()) 311 348 .arg(m_strLink) 312 349 .arg(m_strTitle)); … … 317 354 { 318 355 /* Calculate new header-hover state: */ 319 bool fNewH eaderHover = m_fHeaderHover;356 bool fNewHovered = m_fHovered; 320 357 if (m_pLabelPath && m_pLabelPath->contains(mapFromGlobal(QCursor::pos()))) 321 fNewH eaderHover= true;358 fNewHovered = true; 322 359 else 323 fNewH eaderHover= false;360 fNewHovered = false; 324 361 325 362 /* Check if we should toggle hover: */ 326 if (m_fH eaderHover == fNewHeaderHover)363 if (m_fHovered == fNewHovered) 327 364 return; 328 365 329 366 /* If header-hover state switched from disabled to enabled: */ 330 if (!m_fH eaderHover && fNewHeaderHover)367 if (!m_fHovered && fNewHovered) 331 368 /* Notify listeners: */ 332 369 emit sigGotHover(); 333 370 334 371 /* Toggle hover: */ 335 toggleHover(fNewH eaderHover);372 toggleHover(fNewHovered); 336 373 } 337 374 … … 339 376 { 340 377 /* Check if we should toggle hover: */ 341 if (m_fH eaderHover== false)378 if (m_fHovered == false) 342 379 return; 343 380 … … 349 386 { 350 387 /* Remember header-hover state: */ 351 m_fH eaderHover= fHeaderHover;388 m_fHovered = fHeaderHover; 352 389 353 390 /* Update title: */ … … 373 410 } 374 411 412 413 /********************************************************************************************************************************* 414 * Class UIPopupBoxGroup implementation. * 415 *********************************************************************************************************************************/ 416 375 417 UIPopupBoxGroup::UIPopupBoxGroup(QObject *pParent) 376 418 : QObject(pParent) -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPopupBox.h
r69500 r71484 5 5 6 6 /* 7 * Copyright (C) 2010-201 7Oracle Corporation7 * Copyright (C) 2010-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 16 16 */ 17 17 18 #ifndef __ UIPopupBoxStuff_h__19 #define __ UIPopupBoxStuff_h__20 21 /* Globalincludes: */18 #ifndef ___UIPopupBoxStuff_h___ 19 #define ___UIPopupBoxStuff_h___ 20 21 /* Qt includes: */ 22 22 #include <QIcon> 23 23 #include <QWidget> 24 24 25 25 /* Forward declarations: */ 26 class QEvent; 27 class QIcon; 26 28 class QLabel; 27 28 /* QWidget reimplementation, 29 * wraps content-widget with nice/collapsable frame: */ 29 class QMouseEvent; 30 class QObject; 31 class QPainterPath; 32 class QPaintEvent; 33 class QResizeEvent; 34 class QString; 35 class QWidget; 36 37 38 /** QWidget extension, 39 * wrapping content-widget with nice collapsable frame. */ 30 40 class UIPopupBox : public QWidget 31 41 { … … 34 44 signals: 35 45 36 /* Signals:*/46 /** Notifies about title with @a strLink was clicked. */ 37 47 void sigTitleClicked(const QString &strLink); 48 49 /** Notifies box was toggled and currently @a fOpened. */ 38 50 void sigToggled(bool fOpened); 51 52 /** Asks to update contents widget. */ 39 53 void sigUpdateContentWidget(); 54 55 /** Notify about box is hovered. */ 40 56 void sigGotHover(); 41 57 42 58 public: 43 59 44 /* Constructor/destructor:*/60 /** Construct popup-box passing @a pParent to the base-class. */ 45 61 UIPopupBox(QWidget *pParent); 46 ~UIPopupBox(); 47 48 /* Title-icon stuff: */ 62 /** Destruct popup-box. */ 63 virtual ~UIPopupBox() /* override */; 64 65 /** Defines title @a icon. */ 49 66 void setTitleIcon(const QIcon &icon); 67 /** Returns title icon. */ 50 68 QIcon titleIcon() const; 51 69 52 /* Warning-icon stuff:*/70 /** Defines warning @a icon. */ 53 71 void setWarningIcon(const QIcon &icon); 72 /** Returns warnings icon. */ 54 73 QIcon warningIcon() const; 55 74 56 /* Title stuff:*/75 /** Defines @a strTitle. */ 57 76 void setTitle(const QString &strTitle); 77 /** Returns title. */ 58 78 QString title() const; 59 79 60 /* Link stuff:*/80 /** Defines title @a strLink. */ 61 81 void setTitleLink(const QString &strLink); 82 /** Returns title link. */ 62 83 QString titleLink() const; 84 /** Defines whether title link is @a fEnabled. */ 63 85 void setTitleLinkEnabled(bool fEnabled); 86 /** Returns whether title link is enabled. */ 64 87 bool isTitleLinkEnabled() const; 65 88 66 /* Content-widget stuff:*/89 /** Defines content @a pWidget. */ 67 90 void setContentWidget(QWidget *pWidget); 68 QWidget* contentWidget() const; 69 70 /* Toggle stuff: */ 71 void setOpen(bool fOpen); 91 /** Returns content widget. */ 92 QWidget *contentWidget() const; 93 94 /** Defines whether box is @a fOpened. */ 95 void setOpen(bool fOpened); 96 /** Toggles current opened state. */ 72 97 void toggleOpen(); 98 /** Returns whether box is opened. */ 73 99 bool isOpen() const; 74 100 75 /* Update stuff:*/101 /** Calls for content iwdget update. */ 76 102 void callForUpdateContentWidget() { emit sigUpdateContentWidget(); } 77 103 78 104 protected: 79 105 80 /* Event filter: */ 81 bool eventFilter(QObject *pWatched, QEvent *pEvent); 82 83 /* Event handlers: */ 84 void resizeEvent(QResizeEvent *pEvent); 85 void mouseDoubleClickEvent(QMouseEvent *pEvent); 86 void paintEvent(QPaintEvent *pEvent); 106 /** Pre-handles standard Qt @a pEvent for passed @a pObject. */ 107 virtual bool eventFilter(QObject *pObject, QEvent *pEvent) /* override */; 108 109 /** Handles resize @a pEvent. */ 110 virtual void resizeEvent(QResizeEvent *pEvent) /* override */; 111 112 /** Handles paint @a pEvent. */ 113 virtual void paintEvent(QPaintEvent *pEvent) /* override */; 114 115 /** Handles mouse double-click @a pEvent. */ 116 virtual void mouseDoubleClickEvent(QMouseEvent *pEvent) /* override */; 87 117 88 118 private: 89 119 90 /* Helpers:*/120 /** Updates title icon. */ 91 121 void updateTitleIcon(); 122 /** Updates warning icon. */ 92 123 void updateWarningIcon(); 124 /** Updates title. */ 93 125 void updateTitle(); 126 /** Updates hovered state. */ 94 127 void updateHover(); 128 /** Revokes hovered state. */ 95 129 void revokeHover(); 130 /** Toggles hovered state to @a fHeaderHover. */ 96 131 void toggleHover(bool fHeaderHover); 132 /** Recalculates geometry. */ 97 133 void recalc(); 98 134 99 /* Widgets:*/135 /** Holds the title icon label. */ 100 136 QLabel *m_pTitleIcon; 137 /** Holds the warning icon label. */ 101 138 QLabel *m_pWarningIcon; 139 /** Holds the title label. */ 102 140 QLabel *m_pTitleLabel; 103 141 104 /* Variables: */ 105 QIcon m_titleIcon; 106 QIcon m_warningIcon; 107 QString m_strTitle; 108 QString m_strLink; 109 bool m_fLinkEnabled; 142 /** Holds the title icon. */ 143 QIcon m_titleIcon; 144 /** Holds the warning icon. */ 145 QIcon m_warningIcon; 146 /** Holds the title text. */ 147 QString m_strTitle; 148 /** Holds the link icon. */ 149 QString m_strLink; 150 151 /** Holds whether the link is enabled. */ 152 bool m_fLinkEnabled : 1; 153 /** Holds whether box is opened. */ 154 bool m_fOpened : 1; 155 /** Holds whether header is hovered. */ 156 bool m_fHovered : 1; 157 158 /** Holds the content widget. */ 110 159 QWidget *m_pContentWidget; 111 bool m_fOpen; 160 161 /** Holds the label painter path. */ 112 162 QPainterPath *m_pLabelPath; 163 164 /** Holds the arrow width. */ 113 165 const int m_iArrowWidth; 166 /** Holds the arrow painter-path. */ 114 167 QPainterPath m_arrowPath; 115 bool m_fHeaderHover; 116 117 /* Friend class: */ 168 169 /** Allow popup-box group to access private API. */ 118 170 friend class UIPopupBoxGroup; 119 171 }; 120 172 121 /* QObject reimplementation, 122 * provides a container to organize groups of popup-boxes: */ 173 174 /** QObject extension, 175 * provides a container to organize groups of popup-boxes. */ 123 176 class UIPopupBoxGroup : public QObject 124 177 { … … 127 180 public: 128 181 129 /* Constructor/destructor:*/182 /** Construct popup-box passing @a pParent to the base-class. */ 130 183 UIPopupBoxGroup(QObject *pParent); 131 ~UIPopupBoxGroup(); 132 133 /* Add popup-box: */ 184 /** Destruct popup-box. */ 185 virtual ~UIPopupBoxGroup() /* override */; 186 187 /** Adds @a pPopupBox into group. */ 134 188 void addPopupBox(UIPopupBox *pPopupBox); 135 189 136 190 private slots: 137 191 138 /* Hover-change handler:*/192 /** Handles group hovering. */ 139 193 void sltHoverChanged(); 140 194 141 195 private: 142 196 143 /* Variables:*/197 /** Holds the list of popup-boxes. */ 144 198 QList<UIPopupBox*> m_list; 145 199 }; 146 200 147 #endif /* !__UIPopupBoxStuff_h__ */ 148 201 202 #endif /* !___UIPopupBoxStuff_h___ */ 203
Note:
See TracChangeset
for help on using the changeset viewer.