diff options
author | Sami Merila <sami.merila@nokia.com> | 2010-03-17 12:21:22 (GMT) |
---|---|---|
committer | Sami Merila <sami.merila@nokia.com> | 2010-03-17 12:21:22 (GMT) |
commit | ceff979ce3c9401151acdcd53af872cefbaaa962 (patch) | |
tree | 08025b3c65f04de0665dd01cd85326bd25dc0122 /src/gui | |
parent | 24096c5613731ae19e8fefe071570fa1d0e7ab36 (diff) | |
download | Qt-ceff979ce3c9401151acdcd53af872cefbaaa962.zip Qt-ceff979ce3c9401151acdcd53af872cefbaaa962.tar.gz Qt-ceff979ce3c9401151acdcd53af872cefbaaa962.tar.bz2 |
Change QS60Style to use combobox popup menu
Instead of using traditional dropdown menus, use popup menu, like
native side does.
Related to https://qtrequirements.europe.nokia.com/browse/QT-2274
Popup is positioned according to S60 popup position rules:
- in portrait at the bottom, with square popup (dimension is
screen width minus border)
- in landscape, centered on Y-axis, on X-axis to the right
border (with LeftToRight UI direction)
Background behind popup is dimmed.
Popup has automatic scrollbar if content does not fit into the popup.
Popup background graphic is S60 dialog graphic.
Task-number: QT-2274
Reviewed-by: Alessandro Portale
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/kernel/qapplication_s60.cpp | 8 | ||||
-rw-r--r-- | src/gui/styles/qs60style.cpp | 26 | ||||
-rw-r--r-- | src/gui/widgets/qcombobox.cpp | 50 | ||||
-rw-r--r-- | src/gui/widgets/qcombobox_p.h | 2 |
4 files changed, 82 insertions, 4 deletions
diff --git a/src/gui/kernel/qapplication_s60.cpp b/src/gui/kernel/qapplication_s60.cpp index 4a15cf2..e7a7093 100644 --- a/src/gui/kernel/qapplication_s60.cpp +++ b/src/gui/kernel/qapplication_s60.cpp @@ -52,6 +52,7 @@ #include "qstring.h" #include "qdebug.h" #include "qimage.h" +#include "qcombobox.h" #include "private/qkeymapper_p.h" #include "private/qfont_p.h" #ifndef QT_NO_STYLE_S60 @@ -1407,11 +1408,13 @@ void QApplicationPrivate::leaveModal_sys(QWidget *widget) void QApplicationPrivate::openPopup(QWidget *popup) { + if (popup && qobject_cast<QComboBox *>(popup->parentWidget())) + static_cast<QSymbianControl *>(popup->effectiveWinId())->FadeBehindPopup(ETrue); + if (!QApplicationPrivate::popupWidgets) QApplicationPrivate::popupWidgets = new QWidgetList; QApplicationPrivate::popupWidgets->append(popup); - // Cancel focus widget pointer capture and long tap timer if (QApplication::focusWidget()) { static_cast<QSymbianControl*>(QApplication::focusWidget()->effectiveWinId())->CancelLongTapTimer(); @@ -1450,6 +1453,9 @@ void QApplicationPrivate::openPopup(QWidget *popup) void QApplicationPrivate::closePopup(QWidget *popup) { + if (popup && qobject_cast<QComboBox *>(popup->parentWidget())) + static_cast<QSymbianControl *>(popup->effectiveWinId())->FadeBehindPopup(EFalse); + if (!QApplicationPrivate::popupWidgets) return; QApplicationPrivate::popupWidgets->removeAll(popup); diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index bf5a62e..a610176 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -2475,6 +2475,9 @@ int QS60Style::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *w { int retValue = -1; switch (sh) { + case SH_ComboBox_Popup: + retValue = true; + break; case SH_Table_GridLineColor: retValue = int(QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnLineColors, 2, 0).rgba()); break; @@ -2690,6 +2693,19 @@ QRect QS60Style::subControlRect(ComplexControl control, const QStyleOptionComple height - 2 * frameThickness); } break; + case SC_ComboBoxListBoxPopup: { + const QRect desktopContent = QApplication::desktop()->availableGeometry(); + + // take the size of this and position bottom above available area + QRect popupRect; + const int width = desktopContent.width() - pixelMetric(PM_LayoutRightMargin) - pixelMetric(PM_LayoutLeftMargin); + popupRect.setWidth(width); + popupRect.setHeight(desktopContent.height()); //combobox resets height anyway based on content + popupRect.setBottom(desktopContent.bottom()); + popupRect.translate(pixelMetric(PM_LayoutLeftMargin), 0); + ret = popupRect; + } + break; default: break; } @@ -2844,9 +2860,13 @@ QRect QS60Style::subElementRect(SubElement element, const QStyleOption *opt, con ret = menuItem->rect; if (element == SE_ItemViewItemDecoration) { - if (menuItem->direction == Qt::RightToLeft) - ret.translate(ret.width()-indicatorWidth, 0); - ret.setWidth(indicatorWidth); + if (menuItem->icon.isNull()) { + ret = QRect(); + } else { + if (menuItem->direction == Qt::RightToLeft) + ret.translate(ret.width()-indicatorWidth, 0); + ret.setWidth(indicatorWidth); + } } else { ret = menuItem->rect; if (!menuItem->icon.isNull()) diff --git a/src/gui/widgets/qcombobox.cpp b/src/gui/widgets/qcombobox.cpp index 585db70..7d02e14 100644 --- a/src/gui/widgets/qcombobox.cpp +++ b/src/gui/widgets/qcombobox.cpp @@ -532,9 +532,11 @@ void QComboBoxPrivateContainer::setItemView(QAbstractItemView *itemView) QStyleOptionComboBox opt = comboStyleOption(); const bool usePopup = combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo); #ifndef QT_NO_SCROLLBAR +#ifndef Q_WS_S60 if (usePopup) view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); #endif +#endif if (combo->style()->styleHint(QStyle::SH_ComboBox_ListMouseTracking, &opt, combo) || usePopup) { view->setMouseTracking(true); @@ -2416,24 +2418,44 @@ void QComboBox::showPopup() // Position horizontally. listRect.moveLeft(above.x()); +#ifndef Q_WS_S60 // Position vertically so the curently selected item lines up // with the combo box. const QRect currentItemRect = view()->visualRect(view()->currentIndex()); const int offset = listRect.top() - currentItemRect.top(); listRect.moveTop(above.y() + offset - listRect.top()); +#endif // Clamp the listRect height and vertical position so we don't expand outside the // available screen geometry.This may override the vertical position, but it is more // important to show as much as possible of the popup. const int height = !boundToScreen ? listRect.height() : qMin(listRect.height(), screen.height()); +#ifdef Q_WS_S60 + //popup needs to be stretched with screen minimum dimension + listRect.setHeight(qMin(screen.height(), screen.width())); +#else listRect.setHeight(height); +#endif + if (boundToScreen) { if (listRect.top() < screen.top()) listRect.moveTop(screen.top()); if (listRect.bottom() > screen.bottom()) listRect.moveBottom(screen.bottom()); } +#ifdef Q_WS_S60 + if (screen.width() < screen.height()) { + // in portait, menu should be positioned above softkeys + listRect.moveBottom(screen.bottom()); + } else { + // landscape, menu should be at the right and horizontally centered + listRect.setWidth(listRect.height()); + listRect.moveCenter(screen.center()); + (opt.direction == Qt::LeftToRight) ? listRect.setRight(screen.right()) : + listRect.setLeft(screen.left()); + } +#endif } else if (!boundToScreen || listRect.height() <= belowHeight) { listRect.moveTopLeft(below); } else if (listRect.height() <= aboveHeight) { @@ -2642,6 +2664,34 @@ void QComboBox::changeEvent(QEvent *e) if (d->lineEdit) d->updateLineEditGeometry(); d->setLayoutItemMargins(QStyle::SE_ComboBoxLayoutItem); + +#ifdef Q_WS_S60 + if (d->container) { + QStyleOptionComboBox opt; + initStyleOption(&opt); + + if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) { + const QRect screen = d->popupGeometry(QApplication::desktop()->screenNumber(this)); + + QRect listRect(style()->subControlRect(QStyle::CC_ComboBox, &opt, + QStyle::SC_ComboBoxListBoxPopup, this)); + listRect.setHeight(qMin(screen.height(), screen.width())); + + if (screen.width() < screen.height()) { + // in portait, menu should be positioned above softkeys + listRect.moveBottom(screen.bottom()); + } else { + // landscape, menu should be at the right and horizontally centered + listRect.setWidth(listRect.height()); + listRect.moveCenter(screen.center()); + (opt.direction == Qt::LeftToRight) ? listRect.setRight(screen.right()) : + listRect.setLeft(screen.left()); + } + d->container->setGeometry(listRect); + } + } +#endif + // ### need to update scrollers etc. as well here break; case QEvent::EnabledChange: diff --git a/src/gui/widgets/qcombobox_p.h b/src/gui/widgets/qcombobox_p.h index 74dfdc9..92d85cc 100644 --- a/src/gui/widgets/qcombobox_p.h +++ b/src/gui/widgets/qcombobox_p.h @@ -270,7 +270,9 @@ protected: const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionMenuItem opt = getStyleOption(option, index); +#ifndef Q_WS_S60 painter->fillRect(option.rect, opt.palette.background()); +#endif mCombo->style()->drawControl(QStyle::CE_MenuItem, &opt, painter, mCombo); } QSize sizeHint(const QStyleOptionViewItem &option, |