diff options
author | Bernd Lamecker <blam@sepp.nbg.basyskom.de> | 2010-06-23 11:42:25 +0200 |
---|---|---|
committer | Torsten Rahn <Torsten.Rahn@basyskom.de> | 2010-06-25 13:20:44 +0200 |
commit | 6003038ef166cded8b0e8dceedbd3d5f3f0a875b (patch) | |
tree | 37a254bc49189f106ec924c6c888e3012007bd8f | |
parent | dabfd7ceaad5270a392df6eeb2c270f1b197d855 (diff) |
Changes: VKB focus on dialogs
RevBy: TrustMe
-rw-r--r-- | plainqt/style/qtmaemo6dialogproxy.cpp | 62 | ||||
-rw-r--r-- | plainqt/style/qtmaemo6dialogproxy.h | 14 | ||||
-rw-r--r-- | plainqt/style/qtmaemo6style.cpp | 9 |
3 files changed, 76 insertions, 9 deletions
diff --git a/plainqt/style/qtmaemo6dialogproxy.cpp b/plainqt/style/qtmaemo6dialogproxy.cpp index df3c5a03..0c41a6c1 100644 --- a/plainqt/style/qtmaemo6dialogproxy.cpp +++ b/plainqt/style/qtmaemo6dialogproxy.cpp @@ -41,17 +41,28 @@ QtMaemo6DialogProxy::QtMaemo6DialogProxy(QWidget *mw, QWidget *parent) palette.setBrush(QPalette::Window, QBrush(QColor(0, 0, 0, 192))); setPalette(palette); - m_dialogTitle = new QtMaemo6DialogTitle(NULL); + //m_dialogTitle = new QtMaemo6DialogTitle(NULL); + + m_dialogWidget = new QWidget(NULL); + m_dialogWidget->setObjectName("dialog_widget"); + m_dialogTitle = new QtMaemo6DialogTitle(m_dialogWidget); + + QVBoxLayout* dialogLayout = new QVBoxLayout(m_dialogWidget); + dialogLayout->setSpacing(0); + dialogLayout->setMargin(0); + dialogLayout->addWidget(m_dialogTitle); + dialogLayout->addWidget(centralWidget()); QSpacerItem *leftSideSpacer = new QSpacerItem(9, 0); QSpacerItem *rightSideSpacer = new QSpacerItem(9, 0); QSpacerItem *topSpacer = new QSpacerItem(10, 10, QSizePolicy::Minimum, QSizePolicy::Expanding); - m_windowLayout->addItem(topSpacer, 0, 0, 1, 3); - m_windowLayout->addItem(leftSideSpacer, 1, 0, 2, 1); - m_windowLayout->addWidget(m_dialogTitle, 1, 1, 1, 1); - m_windowLayout->addWidget(centralWidget(), 2, 1, 1, 1); - m_windowLayout->addItem(rightSideSpacer, 1, 2, 2, 1); + m_windowLayout->addItem(topSpacer, 0, 0, 1, 3); + m_windowLayout->addItem(leftSideSpacer, 1, 0, 2, 1); + m_windowLayout->addWidget(m_dialogWidget, 1, 1, 1, 1); + //m_windowLayout->addWidget(m_dialogTitle, 1, 1, 1, 1); + //m_windowLayout->addWidget(centralWidget(), 2, 1, 1, 1); + m_windowLayout->addItem(rightSideSpacer, 1, 2, 2, 1); //only works if mw is a QDialog, otherwise the connect simply fails connect(m_dialogTitle, SIGNAL(closeRequest()), mw, SLOT(reject())); @@ -74,8 +85,35 @@ void QtMaemo6DialogProxy::setPixmap(const QPixmap &icon) } void QtMaemo6DialogProxy::ensureWidgetVisible(QWidget* widget, QRect visibleArea) { - Q_UNUSED(widget) - Q_UNUSED(visibleArea) + if(visibleArea.isValid()) { + //that is the real visible area of the viewport, the navigation bar is excluded here + QRect realVisibleRect = visibleArea.intersected( + QRect(m_dialogWidget->mapToGlobal(QPoint(0,0)), m_dialogWidget->size() )); + + QRect globalWidgetRect = QRect( + widget->mapToGlobal(QPoint(0,0)), + widget->size() + ); + + QPoint widgetGlobalPosition = widget->mapToGlobal(QPoint(0,0)); + + //the widget is not fully covered by the visible Area + if(globalWidgetRect.intersected(realVisibleRect) != globalWidgetRect) { + QPoint originalViewportPos = m_dialogWidget->mapToGlobal(QPoint(0,0)); + m_originalWidgetPos.widget = m_dialogWidget; + m_originalWidgetPos.position = m_dialogWidget->pos(); + + int newYPos = realVisibleRect.top() + ((realVisibleRect.height() - widget->height()) / 2); + + //centered in visibleArea + m_dialogWidget->move(m_dialogWidget->pos().x(), newYPos); + } + } else { + if(m_originalWidgetPos.widget) { + m_originalWidgetPos.widget->move(m_originalWidgetPos.position); + m_originalWidgetPos.widget = 0; + } + } } void QtMaemo6DialogProxy::resizeEvent(QResizeEvent *) { @@ -85,6 +123,14 @@ void QtMaemo6DialogProxy::resizeEvent(QResizeEvent *) { } } +void QtMaemo6DialogProxy::mousePressEvent(QMouseEvent *event) +{ + //close dialog if some click occurs outside the dialogs window + if(!m_dialogWidget->geometry().contains(event->pos())) + close(); +} + + bool QtMaemo6DialogProxy::eventFilter(QObject *obj, QEvent *event) { //in dialog case, also close the decoration on hide event, because the //dialogs are only hidden, not closed by default diff --git a/plainqt/style/qtmaemo6dialogproxy.h b/plainqt/style/qtmaemo6dialogproxy.h index 2a21283e..3f9120d3 100644 --- a/plainqt/style/qtmaemo6dialogproxy.h +++ b/plainqt/style/qtmaemo6dialogproxy.h @@ -58,11 +58,25 @@ protected: //bool eventFilter(QObject* watched, QEvent* ev); //void closeEvent(QCloseEvent* event); virtual void resizeEvent(QResizeEvent *); + virtual void mousePressEvent(QMouseEvent *event); bool eventFilter(QObject *obj, QEvent *event); /*! \reimp_end */ private: QtMaemo6DialogTitle *m_dialogTitle; + + //this contains the visible part of the dialog (titlebar + content) + QWidget* m_dialogWidget; + + struct WidgetPos { + WidgetPos() : widget(NULL) {}; + WidgetPos(QWidget* w, QPoint p) : widget(w), position(p) {}; + WidgetPos(const WidgetPos& other) { widget = other.widget; position = other.position; } + QWidget* widget; + QPoint position; + }; + WidgetPos m_originalWidgetPos; + }; #endif diff --git a/plainqt/style/qtmaemo6style.cpp b/plainqt/style/qtmaemo6style.cpp index 2d2da8de..4992f02f 100644 --- a/plainqt/style/qtmaemo6style.cpp +++ b/plainqt/style/qtmaemo6style.cpp @@ -227,7 +227,14 @@ bool QtMaemo6Style::setPaletteBackground(QWidget *widget, QString styleClass) const { bool ret = false; + if (NULL != widget) { + + //ensure the layout was activated, so the widget already has correct size + if(widget->parentWidget()) + if(widget->parentWidget()->layout()) + widget->parentWidget()->layout()->activate(); + if(widget->size().isValid()) { widget->setAutoFillBackground(true); @@ -1090,7 +1097,7 @@ void QtMaemo6Style::polish(QWidget *widget) if (QAbstractScrollArea *abstractScrollArea = qobject_cast<QAbstractScrollArea *>(widget)) { abstractScrollArea->grabGesture(Qt::PanGesture); - //d->m_kinetic->enableOn(abstractScrollArea); + d->m_kinetic->enableOn(abstractScrollArea); d->m_kinetic->setRightToLeft(qApp->isRightToLeft()); d->m_scrollBarEventFilter->enableOn(abstractScrollArea); |