bool UIPopupStack::eventFilter(QObject *pWatched, QEvent *pEvent) { /* Call to base-class if that is not parent event: */ if (!parent() || pWatched != parent()) return QWidget::eventFilter(pWatched, pEvent); /* Handle parent geometry events: */ switch (pEvent->type()) { case QEvent::Resize: { /* Propagate width: */ propagateWidth(); /* Adjust geometry: */ sltAdjustGeometry(); break; } case QEvent::Move: { /* Adjust geometry: */ sltAdjustGeometry(); break; } } /* Call to base-class: */ return QWidget::eventFilter(pWatched, pEvent); }
void UIPopupStack::showEvent(QShowEvent*) { /* Propagate width: */ propagateWidth(); /* Adjust geometry: */ sltAdjustGeometry(); }
void UIPopupStack::setOrientation(UIPopupStackOrientation orientation) { /* Make sure orientation has changed: */ if (m_orientation == orientation) return; /* Update orientation: */ m_orientation = orientation; sltAdjustGeometry(); }
void UIPopupStack::prepareContent() { /* Create main-layout: */ m_pMainLayout = new QVBoxLayout(this); { /* Configure main-layout: */ m_pMainLayout->setContentsMargins(0, 0, 0, 0); /* Create scroll-area: */ m_pScrollArea = new QScrollArea; { /* Configure scroll-area: */ m_pScrollArea->setCursor(Qt::ArrowCursor); m_pScrollArea->setWidgetResizable(true); m_pScrollArea->setFrameStyle(QFrame::NoFrame | QFrame::Plain); m_pScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); //m_pScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); QPalette pal = m_pScrollArea->palette(); pal.setColor(QPalette::Window, QColor(Qt::transparent)); m_pScrollArea->setPalette(pal); /* Create scroll-viewport: */ m_pScrollViewport = new UIPopupStackViewport; { /* Configure scroll-viewport: */ m_pScrollViewport->setCursor(Qt::ArrowCursor); /* Connect scroll-viewport: */ connect(this, SIGNAL(sigProposeStackViewportWidth(int)), m_pScrollViewport, SLOT(sltHandleProposalForWidth(int))); connect(m_pScrollViewport, SIGNAL(sigSizeHintChanged()), this, SLOT(sltAdjustGeometry())); connect(m_pScrollViewport, SIGNAL(sigPopupPaneDone(QString, int)), this, SIGNAL(sigPopupPaneDone(QString, int))); connect(m_pScrollViewport, SIGNAL(sigPopupPaneRemoved(QString)), this, SLOT(sltPopupPaneRemoved(QString))); connect(m_pScrollViewport, SIGNAL(sigPopupPanesRemoved()), this, SLOT(sltPopupPanesRemoved())); } /* Assign scroll-viewport to scroll-area: */ m_pScrollArea->setWidget(m_pScrollViewport); } /* Add scroll-area to layout: */ m_pMainLayout->addWidget(m_pScrollArea); } }
void UIPopupStackViewport::sltPopupPaneDone(int iResultCode) { /* Make sure the sender is the popup-pane: */ UIPopupPane *pPopupPane = qobject_cast<UIPopupPane*>(sender()); if (!pPopupPane) { AssertMsgFailed(("Should be called by popup-pane only!")); return; } /* Make sure the popup-pane still exists: */ const QString strPopupPaneID(m_panes.key(pPopupPane, QString())); if (strPopupPaneID.isNull()) { AssertMsgFailed(("Popup-pane already destroyed!")); return; } /* Notify listeners about popup-pane removal: */ emit sigPopupPaneDone(strPopupPaneID, iResultCode); /* Delete popup-pane asyncronously. * To avoid issues with events which already posted: */ m_panes.remove(strPopupPaneID); pPopupPane->deleteLater(); /* Notify listeners about popup-pane removed: */ emit sigPopupPaneRemoved(strPopupPaneID); /* Adjust geometry: */ sltAdjustGeometry(); /* Make sure this stack still contains popup-panes: */ if (!m_panes.isEmpty()) return; /* Notify listeners about popup-stack: */ emit sigPopupPanesRemoved(); }
void UIPopupStackViewport::createPopupPane(const QString &strPopupPaneID, const QString &strMessage, const QString &strDetails, const QMap<int, QString> &buttonDescriptions) { /* Make sure there is no such popup-pane already: */ if (m_panes.contains(strPopupPaneID)) { AssertMsgFailed(("Popup-pane already exists!")); return; } /* Create new popup-pane: */ UIPopupPane *pPopupPane = m_panes[strPopupPaneID] = new UIPopupPane(this, strMessage, strDetails, buttonDescriptions); /* Attach popup-pane connection: */ connect(this, SIGNAL(sigProposePopupPaneWidth(int)), pPopupPane, SLOT(sltHandleProposalForWidth(int))); connect(pPopupPane, SIGNAL(sigSizeHintChanged()), this, SLOT(sltAdjustGeometry())); connect(pPopupPane, SIGNAL(sigDone(int)), this, SLOT(sltPopupPaneDone(int))); /* Show popup-pane: */ pPopupPane->show(); }