Changeset 41255 in vbox
- Timestamp:
- May 11, 2012 1:55:40 PM (13 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/selector/UIVMDesktop.cpp
r40192 r41255 281 281 CMachine m_machine; 282 282 QList<Section> m_sections; 283 UIPopupBoxGroup *m_pPopupBoxGroup; 283 284 QMap<Section, UIPopupBox*> m_block; 284 285 }; … … 631 632 , m_cSectionCount(0) 632 633 , m_sections(sections) 634 , m_pPopupBoxGroup(new UIPopupBoxGroup(this)) 633 635 { 634 636 } … … 1310 1312 /* Prepare new section (popup box): */ 1311 1313 UIPopupBox *pPopup = m_block[section] = new UIPopupBox(this); 1314 m_pPopupBoxGroup->addPopupBox(pPopup); 1312 1315 pPopup->hide(); 1313 connect(pPopup, SIGNAL( titleClicked(const QString &)), details()->detailsPage(), SIGNAL(linkClicked(const QString &)));1314 connect(pPopup, SIGNAL( toggled(bool)), parent(), SLOT(sltPopupToggled(bool)));1316 connect(pPopup, SIGNAL(sigTitleClicked(const QString &)), details()->detailsPage(), SIGNAL(linkClicked(const QString &))); 1317 connect(pPopup, SIGNAL(sigToggled(bool)), parent(), SLOT(sltPopupToggled(bool))); 1315 1318 pPopup->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); 1316 1319 pPopup->setProperty("section-type", static_cast<int>(section)); -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPopupBox.cpp
r41250 r41255 3 3 * 4 4 * VBox frontends: Qt GUI ("VirtualBox"): 5 * UIPopupBox class implementation5 * UIPopupBox/UIPopupBoxGroup classes implementation 6 6 */ 7 7 8 8 /* 9 * Copyright (C) 2010-201 1Oracle Corporation9 * Copyright (C) 2010-2012 Oracle Corporation 10 10 * 11 11 * This file is part of VirtualBox Open Source Edition (OSE), as … … 18 18 */ 19 19 20 /* Local includes */ 20 /* Global includes: */ 21 #include <QLabel> 22 #include <QPaintEvent> 23 #include <QPainter> 24 #include <QVBoxLayout> 25 26 /* Local includes: */ 21 27 #include "UIPopupBox.h" 22 28 #ifdef Q_WS_MAC … … 24 30 #endif /* Q_WS_MAC */ 25 31 26 /* Global includes */27 #include <QApplication>28 #include <QLabel>29 #include <QPaintEvent>30 #include <QPainter>31 #include <QVBoxLayout>32 33 32 UIPopupBox::UIPopupBox(QWidget *pParent) 34 33 : QWidget(pParent) 34 , m_pTitleIcon(new QLabel(this)) 35 , m_pWarningIcon(new QLabel(this)) 36 , m_pTitleLabel(new QLabel(this)) 35 37 , m_fLinkEnabled(false) 36 38 , m_pContentWidget(0) 37 39 , m_fOpen(true) 38 40 , m_pLabelPath(0) 39 , m_ aw(9)41 , m_iArrowWidth(9) 40 42 , m_fHeaderHover(false) 41 43 { 42 /* Placing content: */44 /* Setup main-layout: */ 43 45 QVBoxLayout *pMainLayout = new QVBoxLayout(this); 44 46 pMainLayout->setContentsMargins(10, 5, 5, 5); 45 QHBoxLayout *pTitleLayout = new QHBoxLayout(); 46 m_pTitleIcon = new QLabel(this); 47 m_pWarningIcon = new QLabel(this); 48 m_pTitleLabel = new QLabel(this); 47 /* Setup title-layout: */ 48 QHBoxLayout *pTitleLayout = new QHBoxLayout; 49 49 pTitleLayout->addWidget(m_pTitleIcon); 50 50 pTitleLayout->addWidget(m_pWarningIcon); 51 51 pTitleLayout->addWidget(m_pTitleLabel, Qt::AlignLeft); 52 /* Add title-layout into main-layout: */ 52 53 pMainLayout->addLayout(pTitleLayout); 53 54 54 55 /* Configure widgets: */ 55 56 m_pWarningIcon->setHidden(true); 56 m_arrowPath.lineTo(m_ aw / 2.0, m_aw/ 2.0);57 m_arrowPath.lineTo(m_ aw, 0);57 m_arrowPath.lineTo(m_iArrowWidth / 2.0, m_iArrowWidth / 2.0); 58 m_arrowPath.lineTo(m_iArrowWidth, 0); 58 59 59 60 /* Setup connections: */ 60 connect(m_pTitleLabel, SIGNAL(linkActivated(const QString)), this, SIGNAL( titleClicked(const QString)));61 connect(m_pTitleLabel, SIGNAL(linkActivated(const QString)), this, SIGNAL(sigTitleClicked(const QString))); 61 62 62 63 /* Install local event-filters: */ … … 73 74 } 74 75 75 void UIPopupBox::setTitle(const QString& strTitle) 76 { 76 void UIPopupBox::setTitleIcon(const QIcon &icon) 77 { 78 /* Remember new title-icon: */ 79 m_titleIcon = icon; 80 /* Update title-icon: */ 81 updateTitleIcon(); 82 } 83 84 QIcon UIPopupBox::titleIcon() const 85 { 86 return m_titleIcon; 87 } 88 89 void UIPopupBox::setWarningIcon(const QIcon &icon) 90 { 91 /* Remember new warning-icon: */ 92 m_warningIcon = icon; 93 /* Update warning-icon: */ 94 updateWarningIcon(); 95 } 96 97 QIcon UIPopupBox::warningIcon() const 98 { 99 return m_warningIcon; 100 } 101 102 void UIPopupBox::setTitle(const QString &strTitle) 103 { 104 /* Remember new title: */ 77 105 m_strTitle = strTitle; 78 updateHover(true);79 recalc();106 /* Update title: */ 107 updateTitle(); 80 108 } 81 109 … … 85 113 } 86 114 87 void UIPopupBox::setTitleIcon(const QIcon& icon) 88 { 89 m_titleIcon = icon; 90 updateHover(true); 91 recalc(); 92 } 93 94 QIcon UIPopupBox::titleIcon() const 95 { 96 return m_titleIcon; 97 } 98 99 void UIPopupBox::setWarningIcon(const QIcon& icon) 100 { 101 m_warningIcon = icon; 102 m_pWarningIcon->setHidden(m_warningIcon.isNull()); 103 updateHover(true); 104 recalc(); 105 } 106 107 QIcon UIPopupBox::warningIcon() const 108 { 109 return m_warningIcon; 110 } 111 112 void UIPopupBox::setTitleLink(const QString& strLink) 113 { 115 void UIPopupBox::setTitleLink(const QString &strLink) 116 { 117 /* Remember new title-link: */ 114 118 m_strLink = strLink; 119 /* Update title: */ 120 updateTitle(); 115 121 } 116 122 … … 122 128 void UIPopupBox::setTitleLinkEnabled(bool fEnabled) 123 129 { 130 /* Remember new title-link availability flag: */ 124 131 m_fLinkEnabled = fEnabled; 132 /* Update title: */ 133 updateTitle(); 125 134 } 126 135 … … 132 141 void UIPopupBox::setContentWidget(QWidget *pWidget) 133 142 { 143 /* Cleanup old content-widget if any: */ 134 144 if (m_pContentWidget) 135 145 { … … 137 147 layout()->removeWidget(m_pContentWidget); 138 148 } 149 /* Prepare new content-wodget: */ 139 150 m_pContentWidget = pWidget; 140 151 layout()->addWidget(m_pContentWidget); … … 150 161 void UIPopupBox::setOpen(bool fOpen) 151 162 { 152 /* Do not do anything if already done: */163 /* Check if we should toggle popup-box: */ 153 164 if (m_fOpen == fOpen) 154 165 return; … … 157 168 m_fOpen = fOpen; 158 169 159 /* Update content 170 /* Update content-widget if present or this itself: */ 160 171 if (m_pContentWidget) 161 172 m_pContentWidget->setVisible(m_fOpen); … … 163 174 update(); 164 175 165 /* Notify listeners about content 176 /* Notify listeners about content-widget visibility: */ 166 177 if (m_pContentWidget && m_pContentWidget->isVisible()) 167 178 emit sigUpdateContentWidget(); … … 174 185 175 186 /* Notify listeners about toggling: */ 176 emit toggled(m_fOpen);187 emit sigToggled(m_fOpen); 177 188 } 178 189 … … 182 193 } 183 194 184 bool UIPopupBox::eventFilter(QObject * /* pWatched */, QEvent *pEvent) 185 { 195 bool UIPopupBox::eventFilter(QObject *pWatched, QEvent *pEvent) 196 { 197 /* Handle all mouse-event to update hover: */ 186 198 QEvent::Type type = pEvent->type(); 187 199 if (type == QEvent::Enter || … … 190 202 type == QEvent::Wheel) 191 203 updateHover(); 192 return false; 204 /* Call to base-class: */ 205 return QWidget::eventFilter(pWatched, pEvent); 193 206 } 194 207 195 208 void UIPopupBox::resizeEvent(QResizeEvent *pEvent) 196 209 { 197 updateHover(); 198 recalc(); 210 /* Recalculate title-size: */ 211 recalc(); 212 /* Call to base-class: */ 199 213 QWidget::resizeEvent(pEvent); 200 214 } … … 202 216 void UIPopupBox::mouseDoubleClickEvent(QMouseEvent * /* pEvent */) 203 217 { 218 /* Toggle popup-box: */ 204 219 toggleOpen(); 205 220 } … … 207 222 void UIPopupBox::paintEvent(QPaintEvent *pEvent) 208 223 { 224 /* Create painter: */ 209 225 QPainter painter(this); 210 226 painter.setClipRect(pEvent->rect()); … … 247 263 } 248 264 249 void UIPopupBox::updateHover(bool fForce /* = false */) 250 { 251 bool fOld = m_fHeaderHover; 252 // QPoint bl = mapFromGlobal(QCursor::pos()); 253 // printf("%d %d\n", bl.x(), bl.y()); 254 if ( m_pLabelPath 255 && m_pLabelPath->contains(mapFromGlobal(QCursor::pos()))) 256 // if (underMouse()) 257 m_fHeaderHover = true; 265 void UIPopupBox::updateTitleIcon() 266 { 267 /* Assign title-icon: */ 268 m_pTitleIcon->setPixmap(m_titleIcon.pixmap(16, 16)); 269 /* Recalculate title-size: */ 270 recalc(); 271 } 272 273 void UIPopupBox::updateWarningIcon() 274 { 275 /* Hide warning-icon if its null: */ 276 m_pWarningIcon->setHidden(m_warningIcon.isNull()); 277 /* Assign warning-icon: */ 278 m_pWarningIcon->setPixmap(m_warningIcon.pixmap(16, 16)); 279 /* Recalculate title-size: */ 280 recalc(); 281 } 282 283 void UIPopupBox::updateTitle() 284 { 285 /* Update title: */ 286 if (!m_fLinkEnabled || m_strLink.isEmpty()) 287 m_pTitleLabel->setText(QString("<b>%1</b>").arg(m_strTitle)); 288 /* Recalculate title-size: */ 289 recalc(); 290 } 291 292 void UIPopupBox::updateHover() 293 { 294 /* Calculate new header-hover state: */ 295 bool fNewHeaderHover = m_fHeaderHover; 296 if (m_pLabelPath && m_pLabelPath->contains(mapFromGlobal(QCursor::pos()))) 297 fNewHeaderHover = true; 258 298 else 259 m_fHeaderHover = false; 260 261 if ( !m_fLinkEnabled 262 || m_strLink.isEmpty()) 263 { 264 m_pTitleLabel->setText(QString("<b>%1</b>").arg(m_strTitle)); 265 } 266 if ( fForce 267 || fOld != m_fHeaderHover) 268 { 269 QPalette pal = m_pTitleLabel->palette(); 270 m_pTitleLabel->setText(QString("<b><a style=\"text-decoration: none; color: %1\" href=\"%2\">%3</a></b>") 271 .arg(m_fHeaderHover ? pal.color(QPalette::Link).name() : pal.color(QPalette::WindowText).name()) 272 .arg(m_strLink) 273 .arg(m_strTitle)); 274 275 QPixmap titleIcon = m_titleIcon.pixmap(16, 16); 276 QPixmap warningIcon = m_warningIcon.pixmap(16, 16); 277 #ifdef Q_WS_MAC 278 /* TODO: Fix this! */ 279 // if (!m_fHeaderHover) 280 // titleIcon = QPixmap::fromImage(toGray(titleIcon.toImage())); 281 // if (!m_fHeaderHover) 282 // warningIcon = QPixmap::fromImage(toGray(warningIcon.toImage())); 283 #endif /* Q_WS_MAC */ 284 m_pTitleIcon->setPixmap(titleIcon); 285 m_pWarningIcon->setPixmap(warningIcon); 286 update(); 287 } 299 fNewHeaderHover = false; 300 301 /* Check if we should toggle hover: */ 302 if (m_fHeaderHover == fNewHeaderHover) 303 return; 304 305 /* If header-hover state switched from disabled to enabled: */ 306 if (!m_fHeaderHover && fNewHeaderHover) 307 /* Notify listeners: */ 308 emit sigGotHover(); 309 310 /* Toggle hover: */ 311 toggleHover(fNewHeaderHover); 312 } 313 314 void UIPopupBox::revokeHover() 315 { 316 /* Check if we should toggle hover: */ 317 if (m_fHeaderHover == false) 318 return; 319 320 /* Toggle hover off: */ 321 toggleHover(false); 322 } 323 324 void UIPopupBox::toggleHover(bool fHeaderHover) 325 { 326 /* Remember header-hover state: */ 327 m_fHeaderHover = fHeaderHover; 328 329 /* Update title: */ 330 QPalette pal = m_pTitleLabel->palette(); 331 m_pTitleLabel->setText(QString("<b><a style=\"text-decoration: none; color: %1\" href=\"%2\">%3</a></b>") 332 .arg(m_fHeaderHover ? pal.color(QPalette::Link).name() : pal.color(QPalette::WindowText).name()) 333 .arg(m_strLink) 334 .arg(m_strTitle)); 335 update(); 288 336 } 289 337 … … 303 351 } 304 352 353 UIPopupBoxGroup::UIPopupBoxGroup(QObject *pParent) 354 : QObject(pParent) 355 { 356 } 357 358 UIPopupBoxGroup::~UIPopupBoxGroup() 359 { 360 /* Clear the list early: */ 361 m_list.clear(); 362 } 363 364 void UIPopupBoxGroup::addPopupBox(UIPopupBox *pPopupBox) 365 { 366 /* Add popup-box into list: */ 367 m_list << pPopupBox; 368 369 /* Connect got-hover signal of the popup-box to hover-change slot of the popup-box group: */ 370 connect(pPopupBox, SIGNAL(sigGotHover()), this, SLOT(sltHoverChanged())); 371 } 372 373 void UIPopupBoxGroup::sltHoverChanged() 374 { 375 /* Fetch the sender: */ 376 UIPopupBox *pPopupBox = qobject_cast<UIPopupBox*>(sender()); 377 378 /* Check if sender popup-box exists/registered: */ 379 if (!pPopupBox || !m_list.contains(pPopupBox)) 380 return; 381 382 /* Filter the sender: */ 383 QList<UIPopupBox*> list(m_list); 384 list.removeOne(pPopupBox); 385 386 /* Notify all other popup-boxes: */ 387 for (int i = 0; i < list.size(); ++i) 388 list[i]->revokeHover(); 389 } 390 -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPopupBox.h
r41250 r41255 2 2 * 3 3 * VBox frontends: Qt GUI ("VirtualBox"): 4 * UIPopupBox class declaration4 * UIPopupBox/UIPopupBoxGroup classes declaration 5 5 */ 6 6 7 7 /* 8 * Copyright (C) 2010-201 1Oracle Corporation8 * Copyright (C) 2010-2012 Oracle Corporation 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 17 17 */ 18 18 19 #ifndef __UIPopupBox _h__20 #define __UIPopupBox _h__19 #ifndef __UIPopupBoxStuff_h__ 20 #define __UIPopupBoxStuff_h__ 21 21 22 /* Global includes */22 /* Global includes: */ 23 23 #include <QIcon> 24 24 #include <QWidget> 25 25 26 /* Global forward declarations*/26 /* Forward declarations: */ 27 27 class QLabel; 28 28 29 /* QWidget reimplementation, 30 * wraps content-widget with nice/collapsable frame: */ 29 31 class UIPopupBox : public QWidget 30 32 { 31 33 Q_OBJECT; 32 34 35 signals: 36 37 /* Signals: */ 38 void sigTitleClicked(const QString &strLink); 39 void sigToggled(bool fOpened); 40 void sigUpdateContentWidget(); 41 void sigGotHover(); 42 33 43 public: 34 44 45 /* Constructor/destructor: */ 35 46 UIPopupBox(QWidget *pParent); 36 47 ~UIPopupBox(); 37 48 38 void setTitle(const QString& strTitle); 49 /* Title-icon stuff: */ 50 void setTitleIcon(const QIcon &icon); 51 QIcon titleIcon() const; 52 53 /* Warning-icon stuff: */ 54 void setWarningIcon(const QIcon &icon); 55 QIcon warningIcon() const; 56 57 /* Title stuff: */ 58 void setTitle(const QString &strTitle); 39 59 QString title() const; 40 60 41 void setTitleIcon(const QIcon& icon); 42 QIcon titleIcon() const; 43 44 void setWarningIcon(const QIcon& icon); 45 QIcon warningIcon() const; 46 47 void setTitleLink(const QString& strLink); 61 /* Link stuff: */ 62 void setTitleLink(const QString &strLink); 48 63 QString titleLink() const; 49 50 64 void setTitleLinkEnabled(bool fEnabled); 51 65 bool isTitleLinkEnabled() const; 52 66 67 /* Content-widget stuff: */ 53 68 void setContentWidget(QWidget *pWidget); 54 69 QWidget* contentWidget() const; 55 70 71 /* Toggle stuff: */ 56 72 void setOpen(bool fOpen); 57 73 void toggleOpen(); 58 74 bool isOpen() const; 59 75 76 /* Update stuff: */ 60 77 void callForUpdateContentWidget() { emit sigUpdateContentWidget(); } 61 62 signals:63 64 void titleClicked(const QString &);65 void toggled(bool fOpened);66 void sigUpdateContentWidget();67 78 68 79 protected: 69 80 81 /* Event filter: */ 70 82 bool eventFilter(QObject *pWatched, QEvent *pEvent); 71 83 84 /* Event handlers: */ 72 85 void resizeEvent(QResizeEvent *pEvent); 73 86 void mouseDoubleClickEvent(QMouseEvent *pEvent); … … 76 89 private: 77 90 78 void updateHover(bool fForce = false); 91 /* Helpers: */ 92 void updateTitleIcon(); 93 void updateWarningIcon(); 94 void updateTitle(); 95 void updateHover(); 96 void revokeHover(); 97 void toggleHover(bool fHeaderHover); 79 98 void recalc(); 80 99 81 /* Private member vars */ 82 QLabel *m_pTitleLabel; 83 QString m_strTitle; 100 /* Widgets: */ 84 101 QLabel *m_pTitleIcon; 85 102 QLabel *m_pWarningIcon; 103 QLabel *m_pTitleLabel; 104 105 /* Variables: */ 86 106 QIcon m_titleIcon; 87 107 QIcon m_warningIcon; 108 QString m_strTitle; 88 109 QString m_strLink; 89 110 bool m_fLinkEnabled; 90 111 QWidget *m_pContentWidget; 91 112 bool m_fOpen; 92 93 113 QPainterPath *m_pLabelPath; 94 const int m_ aw;114 const int m_iArrowWidth; 95 115 QPainterPath m_arrowPath; 96 116 bool m_fHeaderHover; 117 118 /* Friend class: */ 119 friend class UIPopupBoxGroup; 97 120 }; 98 121 99 #endif /* !__UIPopupBox_h__ */ 122 /* QObject reimplementation, 123 * provides a container to organize groups of popup-boxes: */ 124 class UIPopupBoxGroup : public QObject 125 { 126 Q_OBJECT; 100 127 128 public: 129 130 /* Constructor/destructor: */ 131 UIPopupBoxGroup(QObject *pParent); 132 ~UIPopupBoxGroup(); 133 134 /* Add popup-box: */ 135 void addPopupBox(UIPopupBox *pPopupBox); 136 137 private slots: 138 139 /* Hover-change handler: */ 140 void sltHoverChanged(); 141 142 private: 143 144 /* Variables: */ 145 QList<UIPopupBox*> m_list; 146 }; 147 148 #endif /* !__UIPopupBoxStuff_h__ */ 149
Note:
See TracChangeset
for help on using the changeset viewer.