diff options
author | Dominik Holland <dominik.holland@nokia.com> | 2010-05-06 12:39:01 (GMT) |
---|---|---|
committer | Robert Griebl <rgriebl@trolltech.com> | 2010-05-06 15:51:16 (GMT) |
commit | 3a9c669816c2b0784b5c9e1790bc3bbd036cf013 (patch) | |
tree | 1b81bd3e026d4cda836ed038cb181db177a00b6e /src/gui/util | |
parent | 46fe7922e90610d8b0f4b9d648909e98368b5487 (diff) | |
download | Qt-3a9c669816c2b0784b5c9e1790bc3bbd036cf013.zip Qt-3a9c669816c2b0784b5c9e1790bc3bbd036cf013.tar.gz Qt-3a9c669816c2b0784b5c9e1790bc3bbd036cf013.tar.bz2 |
Make QCompleter cope with restricted screen real estate (mobile devices)
Always prefer the bottom area for the list popup - if that doesn't work out
use the maximum available space (top or bottom) and resize the popup if
it still does not fit.
RevBy: Dominik Holland
RevBy: ogoffart
Diffstat (limited to 'src/gui/util')
-rw-r--r-- | src/gui/util/qcompleter.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/gui/util/qcompleter.cpp b/src/gui/util/qcompleter.cpp index 8e7ec80..05fe744 100644 --- a/src/gui/util/qcompleter.cpp +++ b/src/gui/util/qcompleter.cpp @@ -873,7 +873,7 @@ void QCompleterPrivate::showPopup(const QRect& rect) const QRect screen = QApplication::desktop()->availableGeometry(widget); Qt::LayoutDirection dir = widget->layoutDirection(); QPoint pos; - int rw, rh, w; + int rh, w; int h = (popup->sizeHintForRow(0) * qMin(maxVisibleItems, popup->model()->rowCount()) + 3) + 3; QScrollBar *hsb = popup->horizontalScrollBar(); if (hsb && hsb->isVisible()) @@ -881,21 +881,30 @@ void QCompleterPrivate::showPopup(const QRect& rect) if (rect.isValid()) { rh = rect.height(); - w = rw = rect.width(); + w = rect.width(); pos = widget->mapToGlobal(dir == Qt::RightToLeft ? rect.bottomRight() : rect.bottomLeft()); } else { rh = widget->height(); - rw = widget->width(); pos = widget->mapToGlobal(QPoint(0, widget->height() - 2)); w = widget->width(); } - if ((pos.x() + rw) > (screen.x() + screen.width())) + if (w > screen.width()) + w = screen.width(); + if ((pos.x() + w) > (screen.x() + screen.width())) pos.setX(screen.x() + screen.width() - w); if (pos.x() < screen.x()) pos.setX(screen.x()); - if (((pos.y() + rh) > (screen.y() + screen.height())) && ((pos.y() - h - rh) >= 0)) - pos.setY(pos.y() - qMax(h, popup->minimumHeight()) - rh + 2); + + int top = pos.y() - rh - screen.top() + 2; + int bottom = screen.bottom() - pos.y(); + h = qMax(h, popup->minimumHeight()); + if (h > bottom) { + h = qMin(qMax(top, bottom), h); + + if (top > bottom) + pos.setY(pos.y() - h - rh + 2); + } popup->setGeometry(pos.x(), pos.y(), w, h); |