Changeset 47461 in vbox
- Timestamp:
- Jul 29, 2013 1:41:05 PM (11 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 3 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r47087 r47461 378 378 src/widgets/UIPopupPaneButtonPane.h \ 379 379 src/widgets/UIPopupStack.h \ 380 src/widgets/UIPopupStackViewport.h \ 380 381 src/widgets/UIProgressDialog.h \ 381 382 src/widgets/UISpacerWidgets.h \ … … 626 627 src/widgets/UIPopupPaneButtonPane.cpp \ 627 628 src/widgets/UIPopupStack.cpp \ 629 src/widgets/UIPopupStackViewport.cpp \ 628 630 src/widgets/UIProgressDialog.cpp \ 629 631 src/widgets/UISpecialControls.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPopupStack.cpp
r47455 r47461 28 28 /* GUI includes: */ 29 29 #include "UIPopupStack.h" 30 #include "UIPopupPane.h" 31 #include "UIMachineWindowNormal.h" 32 33 /* Other VBox includes: */ 34 #include <VBox/sup.h> 30 #include "UIPopupStackViewport.h" 35 31 36 32 UIPopupStack::UIPopupStack() … … 305 301 } 306 302 307 308 UIPopupStackViewport::UIPopupStackViewport()309 : m_iLayoutMargin(1)310 , m_iLayoutSpacing(1)311 {312 }313 314 bool UIPopupStackViewport::exists(const QString &strPopupPaneID) const315 {316 /* Is there already popup-pane with the same ID? */317 return m_panes.contains(strPopupPaneID);318 }319 320 void UIPopupStackViewport::createPopupPane(const QString &strPopupPaneID,321 const QString &strMessage, const QString &strDetails,322 const QMap<int, QString> &buttonDescriptions,323 bool fProposeAutoConfirmation)324 {325 /* Make sure there is no such popup-pane already: */326 if (m_panes.contains(strPopupPaneID))327 {328 AssertMsgFailed(("Popup-pane already exists!"));329 return;330 }331 332 /* Create new popup-pane: */333 UIPopupPane *pPopupPane = m_panes[strPopupPaneID] = new UIPopupPane(this,334 strMessage, strDetails,335 buttonDescriptions,336 fProposeAutoConfirmation);337 338 /* Attach popup-pane connection: */339 connect(this, SIGNAL(sigProposePopupPaneWidth(int)), pPopupPane, SLOT(sltHandleProposalForWidth(int)));340 connect(pPopupPane, SIGNAL(sigSizeHintChanged()), this, SLOT(sltAdjustGeometry()));341 connect(pPopupPane, SIGNAL(sigDone(int)), this, SLOT(sltPopupPaneDone(int)));342 343 /* Show popup-pane: */344 pPopupPane->show();345 }346 347 void UIPopupStackViewport::updatePopupPane(const QString &strPopupPaneID,348 const QString &strMessage, const QString &strDetails)349 {350 /* Make sure there is such popup-pane already: */351 if (!m_panes.contains(strPopupPaneID))352 {353 AssertMsgFailed(("Popup-pane doesn't exists!"));354 return;355 }356 357 /* Get existing popup-pane: */358 UIPopupPane *pPopupPane = m_panes[strPopupPaneID];359 360 /* Update message and details: */361 pPopupPane->setMessage(strMessage);362 pPopupPane->setDetails(strDetails);363 }364 365 void UIPopupStackViewport::recallPopupPane(const QString &strPopupPaneID)366 {367 /* Make sure there is such popup-pane already: */368 if (!m_panes.contains(strPopupPaneID))369 {370 AssertMsgFailed(("Popup-pane doesn't exists!"));371 return;372 }373 374 /* Get existing popup-pane: */375 UIPopupPane *pPopupPane = m_panes[strPopupPaneID];376 377 /* Recall popup-pane: */378 pPopupPane->recall();379 }380 381 void UIPopupStackViewport::sltHandleProposalForWidth(int iWidth)382 {383 /* Subtract layout margins: */384 iWidth -= 2 * m_iLayoutMargin;385 386 /* Propagate resulting width to popups: */387 emit sigProposePopupPaneWidth(iWidth);388 }389 390 void UIPopupStackViewport::sltAdjustGeometry()391 {392 /* Update size-hint: */393 updateSizeHint();394 395 /* Layout content: */396 layoutContent();397 398 /* Notify parent popup-stack: */399 emit sigSizeHintChanged();400 }401 402 void UIPopupStackViewport::sltPopupPaneDone(int iResultCode)403 {404 /* Make sure the sender is the popup-pane: */405 UIPopupPane *pPopupPane = qobject_cast<UIPopupPane*>(sender());406 if (!pPopupPane)407 {408 AssertMsgFailed(("Should be called by popup-pane only!"));409 return;410 }411 412 /* Make sure the popup-pane still exists: */413 const QString strPopupPaneID(m_panes.key(pPopupPane, QString()));414 if (strPopupPaneID.isNull())415 {416 AssertMsgFailed(("Popup-pane already destroyed!"));417 return;418 }419 420 /* Notify listeners about popup-pane removal: */421 emit sigPopupPaneDone(strPopupPaneID, iResultCode);422 423 /* Cleanup the popup-pane: */424 m_panes.remove(strPopupPaneID);425 delete pPopupPane;426 427 /* Notify listeners about popup-pane removed: */428 emit sigPopupPaneRemoved(strPopupPaneID);429 430 /* Adjust geometry: */431 sltAdjustGeometry();432 433 /* Make sure this stack still contains popup-panes: */434 if (!m_panes.isEmpty())435 return;436 437 /* Notify listeners about popup-stack: */438 emit sigRemove();439 }440 441 void UIPopupStackViewport::updateSizeHint()442 {443 /* Calculate minimum width-hint: */444 int iMinimumWidthHint = 0;445 {446 /* Take into account all the panes: */447 foreach (UIPopupPane *pPane, m_panes)448 iMinimumWidthHint = qMax(iMinimumWidthHint, pPane->minimumSizeHint().width());449 450 /* And two margins finally: */451 iMinimumWidthHint += 2 * m_iLayoutMargin;452 }453 454 /* Calculate minimum height-hint: */455 int iMinimumHeightHint = 0;456 {457 /* Take into account all the panes: */458 foreach (UIPopupPane *pPane, m_panes)459 iMinimumHeightHint += pPane->minimumSizeHint().height();460 461 /* Take into account all the spacings, if any: */462 if (!m_panes.isEmpty())463 iMinimumHeightHint += (m_panes.size() - 1) * m_iLayoutSpacing;464 465 /* And two margins finally: */466 iMinimumHeightHint += 2 * m_iLayoutMargin;467 }468 469 /* Compose minimum size-hint: */470 m_minimumSizeHint = QSize(iMinimumWidthHint, iMinimumHeightHint);471 }472 473 void UIPopupStackViewport::layoutContent()474 {475 /* Get attributes: */476 int iX = m_iLayoutMargin;477 int iY = m_iLayoutMargin;478 479 /* Layout every pane we have: */480 foreach (UIPopupPane *pPane, m_panes)481 {482 /* Get pane attributes: */483 QSize paneSize = pPane->minimumSizeHint();484 const int iPaneWidth = paneSize.width();485 const int iPaneHeight = paneSize.height();486 /* Adjust geometry for the pane: */487 pPane->setGeometry(iX, iY, iPaneWidth, iPaneHeight);488 pPane->layoutContent();489 /* Increment placeholder: */490 iY += (iPaneHeight + m_iLayoutSpacing);491 }492 }493 -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPopupStack.h
r47455 r47461 27 27 class QVBoxLayout; 28 28 class QScrollArea; 29 class UIPopupPane;30 29 class UIPopupStackViewport; 31 30 … … 102 101 }; 103 102 104 /* Popup-stack viewport prototype class: */105 class UIPopupStackViewport : public QWidget106 {107 Q_OBJECT;108 109 signals:110 111 /* Notifier: Layout stuff: */112 void sigProposePopupPaneWidth(int iWidth);113 void sigSizeHintChanged();114 115 /* Notifier: Popup-pane stuff: */116 void sigPopupPaneDone(QString strPopupPaneID, int iResultCode);117 void sigPopupPaneRemoved(QString strPopupPaneID);118 119 /* Notifier: Popup-stack stuff: */120 void sigRemove();121 122 public:123 124 /* Constructor: */125 UIPopupStackViewport();126 127 /* API: Popup-pane stuff: */128 bool exists(const QString &strPopupPaneID) const;129 void createPopupPane(const QString &strPopupPaneID,130 const QString &strMessage, const QString &strDetails,131 const QMap<int, QString> &buttonDescriptions,132 bool fProposeAutoConfirmation);133 void updatePopupPane(const QString &strPopupPaneID,134 const QString &strMessage, const QString &strDetails);135 void recallPopupPane(const QString &strPopupPaneID);136 137 /* API: Layout stuff: */138 QSize minimumSizeHint() const { return m_minimumSizeHint; }139 140 private slots:141 142 /* Handlers: Layout stuff: */143 void sltHandleProposalForWidth(int iWidth);144 void sltAdjustGeometry();145 146 /* Handler: Popup-pane stuff: */147 void sltPopupPaneDone(int iButtonCode);148 149 private:150 151 /* Helpers: Layout stuff: */152 void updateSizeHint();153 void layoutContent();154 155 /* Variables: Layout stuff: */156 const int m_iLayoutMargin;157 const int m_iLayoutSpacing;158 QSize m_minimumSizeHint;159 160 /* Variables: Children stuff: */161 QMap<QString, UIPopupPane*> m_panes;162 };163 164 103 #endif /* __UIPopupStack_h__ */ -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPopupStackViewport.cpp
r47455 r47461 3 3 * 4 4 * VBox frontends: Qt GUI ("VirtualBox"): 5 * UIPopupStack class implementation5 * UIPopupStackViewport class implementation 6 6 */ 7 7 … … 18 18 */ 19 19 20 /* Qt includes: */21 #include <QVBoxLayout>22 #include <QScrollArea>23 #include <QEvent>24 #include <QMainWindow>25 #include <QMenuBar>26 #include <QStatusBar>27 28 20 /* GUI includes: */ 29 #include "UIPopupStack .h"21 #include "UIPopupStackViewport.h" 30 22 #include "UIPopupPane.h" 31 #include "UIMachineWindowNormal.h"32 23 33 24 /* Other VBox includes: */ 34 25 #include <VBox/sup.h> 35 36 UIPopupStack::UIPopupStack()37 : m_pScrollArea(0)38 , m_pScrollViewport(0)39 , m_iParentMenuBarHeight(0)40 , m_iParentStatusBarHeight(0)41 {42 /* Prepare: */43 prepare();44 }45 46 bool UIPopupStack::exists(const QString &strPopupPaneID) const47 {48 /* Redirect question to viewport: */49 return m_pScrollViewport->exists(strPopupPaneID);50 }51 52 void UIPopupStack::createPopupPane(const QString &strPopupPaneID,53 const QString &strMessage, const QString &strDetails,54 const QMap<int, QString> &buttonDescriptions,55 bool fProposeAutoConfirmation)56 {57 /* Redirect request to viewport: */58 m_pScrollViewport->createPopupPane(strPopupPaneID,59 strMessage, strDetails,60 buttonDescriptions,61 fProposeAutoConfirmation);62 63 /* Propagate width: */64 propagateWidth();65 }66 67 void UIPopupStack::updatePopupPane(const QString &strPopupPaneID,68 const QString &strMessage, const QString &strDetails)69 {70 /* Redirect request to viewport: */71 m_pScrollViewport->updatePopupPane(strPopupPaneID,72 strMessage, strDetails);73 74 /* Propagate width: */75 propagateWidth();76 }77 78 void UIPopupStack::recallPopupPane(const QString &strPopupPaneID)79 {80 /* Redirect request to viewport: */81 m_pScrollViewport->recallPopupPane(strPopupPaneID);82 83 /* Propagate width: */84 propagateWidth();85 }86 87 void UIPopupStack::setParent(QWidget *pParent)88 {89 /* Call to base-class: */90 QWidget::setParent(pParent);91 /* Recalculate parent menu-bar height: */92 m_iParentMenuBarHeight = parentMenuBarHeight(pParent);93 /* Recalculate parent status-bar height: */94 m_iParentStatusBarHeight = parentStatusBarHeight(pParent);95 }96 97 void UIPopupStack::setParent(QWidget *pParent, Qt::WindowFlags flags)98 {99 /* Call to base-class: */100 QWidget::setParent(pParent, flags);101 /* Recalculate parent menu-bar height: */102 m_iParentMenuBarHeight = parentMenuBarHeight(pParent);103 /* Recalculate parent status-bar height: */104 m_iParentStatusBarHeight = parentStatusBarHeight(pParent);105 }106 107 void UIPopupStack::sltAdjustGeometry()108 {109 /* Make sure parent is currently set: */110 if (!parent())111 return;112 113 /* Read parent geometry: */114 QRect geo(parentWidget()->geometry());115 116 /* Determine origin: */117 bool fIsWindow = isWindow();118 int iX = fIsWindow ? geo.x() : 0;119 int iY = fIsWindow ? geo.y() : 0;120 /* Subtract menu-bar height: */121 iY += m_iParentMenuBarHeight;122 123 /* Determine size: */124 int iWidth = parentWidget()->width();125 int iHeight = parentWidget()->height();126 /* Subtract menu-bar and status-bar heights: */127 iHeight -= (m_iParentMenuBarHeight + m_iParentStatusBarHeight);128 /* Check if minimum height is even less than current: */129 if (m_pScrollViewport)130 {131 /* Get minimum viewport height: */132 int iMinimumHeight = m_pScrollViewport->minimumSizeHint().height();133 /* Subtract layout margins: */134 int iLeft, iTop, iRight, iBottom;135 m_pMainLayout->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom);136 iMinimumHeight += (iTop + iBottom);137 /* Compare minimum and current height: */138 iHeight = qMin(iHeight, iMinimumHeight);139 }140 141 /* Adjust geometry: */142 setGeometry(iX, iY, iWidth, iHeight);143 }144 145 void UIPopupStack::sltPopupPaneRemoved(QString)146 {147 /* Move focus to the parent: */148 if (parentWidget())149 parentWidget()->setFocus();150 }151 152 void UIPopupStack::prepare()153 {154 /* Configure background: */155 setAutoFillBackground(false);156 #if defined(Q_WS_WIN) || defined (Q_WS_MAC)157 /* Using Qt API to enable translucent background for the Win/Mac host.158 * - Under x11 host Qt 4.8.3 has it broken wih KDE 4.9 for now: */159 setAttribute(Qt::WA_TranslucentBackground);160 #endif /* Q_WS_WIN || Q_WS_MAC */161 162 #ifdef Q_WS_MAC163 /* Do not hide popup-stack164 * and actually the seamless machine-window too165 * due to Qt bug on window deactivation... */166 setAttribute(Qt::WA_MacAlwaysShowToolWindow);167 #endif /* Q_WS_MAC */168 169 /* Prepare content: */170 prepareContent();171 }172 173 void UIPopupStack::prepareContent()174 {175 /* Create main-layout: */176 m_pMainLayout = new QVBoxLayout(this);177 {178 /* Configure main-layout: */179 m_pMainLayout->setContentsMargins(0, 0, 0, 0);180 /* Create scroll-area: */181 m_pScrollArea = new QScrollArea;182 {183 /* Configure scroll-area: */184 m_pScrollArea->setCursor(Qt::ArrowCursor);185 m_pScrollArea->setWidgetResizable(true);186 m_pScrollArea->setFrameStyle(QFrame::NoFrame | QFrame::Plain);187 m_pScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);188 //m_pScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);189 QPalette pal = m_pScrollArea->palette();190 pal.setColor(QPalette::Window, QColor(Qt::transparent));191 m_pScrollArea->setPalette(pal);192 /* Create scroll-viewport: */193 m_pScrollViewport = new UIPopupStackViewport;194 {195 /* Configure scroll-viewport: */196 m_pScrollViewport->setCursor(Qt::ArrowCursor);197 /* Connect scroll-viewport: */198 connect(this, SIGNAL(sigProposeStackViewportWidth(int)),199 m_pScrollViewport, SLOT(sltHandleProposalForWidth(int)));200 connect(m_pScrollViewport, SIGNAL(sigSizeHintChanged()),201 this, SLOT(sltAdjustGeometry()));202 connect(m_pScrollViewport, SIGNAL(sigPopupPaneDone(QString, int)),203 this, SIGNAL(sigPopupPaneDone(QString, int)));204 connect(m_pScrollViewport, SIGNAL(sigPopupPaneRemoved(QString)),205 this, SLOT(sltPopupPaneRemoved(QString)));206 connect(m_pScrollViewport, SIGNAL(sigRemove()),207 this, SIGNAL(sigRemove()));208 }209 /* Assign scroll-viewport to scroll-area: */210 m_pScrollArea->setWidget(m_pScrollViewport);211 }212 /* Add scroll-area to layout: */213 m_pMainLayout->addWidget(m_pScrollArea);214 }215 }216 217 bool UIPopupStack::eventFilter(QObject *pWatched, QEvent *pEvent)218 {219 /* Call to base-class if that is not parent event: */220 if (!parent() || pWatched != parent())221 return QWidget::eventFilter(pWatched, pEvent);222 223 /* Handle parent geometry events: */224 switch (pEvent->type())225 {226 case QEvent::Resize:227 {228 /* Propagate stack width: */229 propagateWidth();230 /* Adjust geometry: */231 sltAdjustGeometry();232 break;233 }234 case QEvent::Move:235 {236 /* Adjust geometry: */237 sltAdjustGeometry();238 break;239 }240 }241 242 /* Call to base-class: */243 return QWidget::eventFilter(pWatched, pEvent);244 }245 246 void UIPopupStack::showEvent(QShowEvent*)247 {248 /* Propagate width: */249 propagateWidth();250 /* Adjust geometry: */251 sltAdjustGeometry();252 }253 254 void UIPopupStack::propagateWidth()255 {256 /* Make sure parent is currently set: */257 if (!parent())258 return;259 260 /* Get parent width: */261 int iWidth = parentWidget()->width();262 /* Subtract left/right layout margins: */263 if (m_pMainLayout)264 {265 int iLeft, iTop, iRight, iBottom;266 m_pMainLayout->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom);267 iWidth -= (iLeft + iRight);268 }269 /* Subtract scroll-area frame-width: */270 if (m_pScrollArea)271 {272 iWidth -= 2 * m_pScrollArea->frameWidth();273 }274 275 /* Propose resulting width to viewport: */276 emit sigProposeStackViewportWidth(iWidth);277 }278 279 /* static */280 int UIPopupStack::parentMenuBarHeight(QWidget *pParent)281 {282 /* Menu-bar can exist only on QMainWindow sub-class: */283 if (QMainWindow *pMainWindow = qobject_cast<QMainWindow*>(pParent))284 {285 /* Search for existing menu-bar child: */286 if (QMenuBar *pMenuBar = pMainWindow->findChild<QMenuBar*>())287 return pMenuBar->height();288 }289 /* Zero by default: */290 return 0;291 }292 293 /* static */294 int UIPopupStack::parentStatusBarHeight(QWidget *pParent)295 {296 /* Status-bar can exist only on QMainWindow sub-class: */297 if (QMainWindow *pMainWindow = qobject_cast<QMainWindow*>(pParent))298 {299 /* Search for existing status-bar child: */300 if (QStatusBar *pStatusBar = pMainWindow->findChild<QStatusBar*>())301 return pStatusBar->height();302 }303 /* Zero by default: */304 return 0;305 }306 307 26 308 27 UIPopupStackViewport::UIPopupStackViewport() -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPopupStackViewport.h
r47455 r47461 2 2 * 3 3 * VBox frontends: Qt GUI ("VirtualBox"): 4 * UIPopupStack class declaration4 * UIPopupStackViewport class declaration 5 5 */ 6 6 … … 17 17 */ 18 18 19 #ifndef __UIPopupStack _h__20 #define __UIPopupStack _h__19 #ifndef __UIPopupStackViewport_h__ 20 #define __UIPopupStackViewport_h__ 21 21 22 22 /* Qt includes: */ … … 25 25 26 26 /* Forward declaration: */ 27 class QVBoxLayout;28 class QScrollArea;29 27 class UIPopupPane; 30 class UIPopupStackViewport;31 32 /* Popup-stack prototype class: */33 class UIPopupStack : public QWidget34 {35 Q_OBJECT;36 37 signals:38 39 /* Notifier: Layout stuff: */40 void sigProposeStackViewportWidth(int iWidth);41 42 /* Notifier: Popup-pane stuff: */43 void sigPopupPaneDone(QString strPopupPaneID, int iResultCode);44 45 /* Notifier: Popup-stack stuff: */46 void sigRemove();47 48 public:49 50 /* Constructor: */51 UIPopupStack();52 53 /* API: Popup-pane stuff: */54 bool exists(const QString &strPopupPaneID) const;55 void createPopupPane(const QString &strPopupPaneID,56 const QString &strMessage, const QString &strDetails,57 const QMap<int, QString> &buttonDescriptions,58 bool fProposeAutoConfirmation);59 void updatePopupPane(const QString &strPopupPaneID,60 const QString &strMessage, const QString &strDetails);61 void recallPopupPane(const QString &strPopupPaneID);62 63 /* API: Parent stuff: */64 void setParent(QWidget *pParent);65 void setParent(QWidget *pParent, Qt::WindowFlags flags);66 67 private slots:68 69 /* Handler: Layout stuff: */70 void sltAdjustGeometry();71 72 /* Handler: Popuyp-pane stuff: */73 void sltPopupPaneRemoved(QString strPopupPaneID);74 75 private:76 77 /* Helpers: Prepare stuff: */78 void prepare();79 void prepareContent();80 81 /* Handler: Event-filter stuff: */82 bool eventFilter(QObject *pWatched, QEvent *pEvent);83 84 /* Handler: Event stuff: */85 void showEvent(QShowEvent *pEvent);86 87 /* Helper: Layout stuff: */88 void propagateWidth();89 90 /* Static helpers: Prepare stuff: */91 static int parentMenuBarHeight(QWidget *pParent);92 static int parentStatusBarHeight(QWidget *pParent);93 94 /* Variables: Widget stuff: */95 QVBoxLayout *m_pMainLayout;96 QScrollArea *m_pScrollArea;97 UIPopupStackViewport *m_pScrollViewport;98 99 /* Variables: Layout stuff: */100 int m_iParentMenuBarHeight;101 int m_iParentStatusBarHeight;102 };103 28 104 29 /* Popup-stack viewport prototype class: */ … … 162 87 }; 163 88 164 #endif /* __UIPopupStack _h__ */89 #endif /* __UIPopupStackViewport_h__ */
Note:
See TracChangeset
for help on using the changeset viewer.