src/gui/widgets/qcombobox.cpp
branchRCL_3
changeset 7 3f74d0d4af4c
parent 4 3b1da2848fc7
child 13 c0432d11811c
equal deleted inserted replaced
6:dee5afe5301f 7:3f74d0d4af4c
   530     view->viewport()->installEventFilter(this);
   530     view->viewport()->installEventFilter(this);
   531     view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
   531     view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
   532     QStyleOptionComboBox opt = comboStyleOption();
   532     QStyleOptionComboBox opt = comboStyleOption();
   533     const bool usePopup = combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo);
   533     const bool usePopup = combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo);
   534 #ifndef QT_NO_SCROLLBAR
   534 #ifndef QT_NO_SCROLLBAR
       
   535 #ifndef Q_WS_S60
   535     if (usePopup)
   536     if (usePopup)
   536         view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
   537         view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
       
   538 #endif
   537 #endif
   539 #endif
   538     if (combo->style()->styleHint(QStyle::SH_ComboBox_ListMouseTracking, &opt, combo) ||
   540     if (combo->style()->styleHint(QStyle::SH_ComboBox_ListMouseTracking, &opt, combo) ||
   539         usePopup) {
   541         usePopup) {
   540         view->setMouseTracking(true);
   542         view->setMouseTracking(true);
   541     }
   543     }
   605     if (e->type() == QEvent::StyleChange) {
   607     if (e->type() == QEvent::StyleChange) {
   606         QStyleOptionComboBox opt = comboStyleOption();
   608         QStyleOptionComboBox opt = comboStyleOption();
   607         view->setMouseTracking(combo->style()->styleHint(QStyle::SH_ComboBox_ListMouseTracking, &opt, combo) ||
   609         view->setMouseTracking(combo->style()->styleHint(QStyle::SH_ComboBox_ListMouseTracking, &opt, combo) ||
   608                                combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo));
   610                                combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo));
   609         setFrameStyle(combo->style()->styleHint(QStyle::SH_ComboBox_PopupFrameStyle, &opt, combo));
   611         setFrameStyle(combo->style()->styleHint(QStyle::SH_ComboBox_PopupFrameStyle, &opt, combo));
   610     }
   612 #ifdef QT_SOFTKEYS_ENABLED
       
   613     } else if (e->type() == QEvent::LanguageChange) {
       
   614         selectAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::SelectSoftKey));
       
   615         cancelAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::CancelSoftKey));
       
   616 #endif
       
   617     }
       
   618 
   611     QWidget::changeEvent(e);
   619     QWidget::changeEvent(e);
   612 }
   620 }
   613 
   621 
   614 
   622 
   615 bool QComboBoxPrivateContainer::eventFilter(QObject *o, QEvent *e)
   623 bool QComboBoxPrivateContainer::eventFilter(QObject *o, QEvent *e)
  2408 
  2416 
  2409     if (usePopup) {
  2417     if (usePopup) {
  2410         // Position horizontally.
  2418         // Position horizontally.
  2411         listRect.moveLeft(above.x());
  2419         listRect.moveLeft(above.x());
  2412 
  2420 
       
  2421 #ifndef Q_WS_S60
  2413         // Position vertically so the curently selected item lines up
  2422         // Position vertically so the curently selected item lines up
  2414         // with the combo box.
  2423         // with the combo box.
  2415         const QRect currentItemRect = view()->visualRect(view()->currentIndex());
  2424         const QRect currentItemRect = view()->visualRect(view()->currentIndex());
  2416         const int offset = listRect.top() - currentItemRect.top();
  2425         const int offset = listRect.top() - currentItemRect.top();
  2417         listRect.moveTop(above.y() + offset - listRect.top());
  2426         listRect.moveTop(above.y() + offset - listRect.top());
       
  2427 #endif
  2418 
  2428 
  2419 
  2429 
  2420         // Clamp the listRect height and vertical position so we don't expand outside the
  2430         // Clamp the listRect height and vertical position so we don't expand outside the
  2421         // available screen geometry.This may override the vertical position, but it is more
  2431         // available screen geometry.This may override the vertical position, but it is more
  2422         // important to show as much as possible of the popup.
  2432         // important to show as much as possible of the popup.
  2423         const int height = !boundToScreen ? listRect.height() : qMin(listRect.height(), screen.height());
  2433         const int height = !boundToScreen ? listRect.height() : qMin(listRect.height(), screen.height());
       
  2434 #ifdef Q_WS_S60
       
  2435         //popup needs to be stretched with screen minimum dimension
       
  2436         listRect.setHeight(qMin(screen.height(), screen.width()));
       
  2437 #else
  2424         listRect.setHeight(height);
  2438         listRect.setHeight(height);
       
  2439 #endif
       
  2440 
  2425         if (boundToScreen) {
  2441         if (boundToScreen) {
  2426             if (listRect.top() < screen.top())
  2442             if (listRect.top() < screen.top())
  2427                 listRect.moveTop(screen.top());
  2443                 listRect.moveTop(screen.top());
  2428             if (listRect.bottom() > screen.bottom())
  2444             if (listRect.bottom() > screen.bottom())
  2429                 listRect.moveBottom(screen.bottom());
  2445                 listRect.moveBottom(screen.bottom());
  2430         }
  2446         }
       
  2447 #ifdef Q_WS_S60
       
  2448         if (screen.width() < screen.height()) {
       
  2449             // in portait, menu should be positioned above softkeys
       
  2450             listRect.moveBottom(screen.bottom());
       
  2451         } else {
       
  2452             // landscape, menu should be at the right and horizontally centered
       
  2453             listRect.setWidth(listRect.height());
       
  2454             listRect.moveCenter(screen.center());
       
  2455             (opt.direction == Qt::LeftToRight) ? listRect.setRight(screen.right()) :
       
  2456                                                  listRect.setLeft(screen.left());
       
  2457         }
       
  2458 #endif
  2431     } else if (!boundToScreen || listRect.height() <= belowHeight) {
  2459     } else if (!boundToScreen || listRect.height() <= belowHeight) {
  2432         listRect.moveTopLeft(below);
  2460         listRect.moveTopLeft(below);
  2433     } else if (listRect.height() <= aboveHeight) {
  2461     } else if (listRect.height() <= aboveHeight) {
  2434         listRect.moveBottomLeft(above);
  2462         listRect.moveBottomLeft(above);
  2435     } else if (belowHeight >= aboveHeight) {
  2463     } else if (belowHeight >= aboveHeight) {
  2634         d->minimumSizeHint = QSize();
  2662         d->minimumSizeHint = QSize();
  2635         d->updateLayoutDirection();
  2663         d->updateLayoutDirection();
  2636         if (d->lineEdit)
  2664         if (d->lineEdit)
  2637             d->updateLineEditGeometry();
  2665             d->updateLineEditGeometry();
  2638         d->setLayoutItemMargins(QStyle::SE_ComboBoxLayoutItem);
  2666         d->setLayoutItemMargins(QStyle::SE_ComboBoxLayoutItem);
       
  2667 
       
  2668 #ifdef Q_WS_S60
       
  2669         if (d->container) {
       
  2670             QStyleOptionComboBox opt;
       
  2671             initStyleOption(&opt);
       
  2672 
       
  2673             if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) {
       
  2674                 const QRect screen = d->popupGeometry(QApplication::desktop()->screenNumber(this));
       
  2675 
       
  2676                 QRect listRect(style()->subControlRect(QStyle::CC_ComboBox, &opt,
       
  2677                     QStyle::SC_ComboBoxListBoxPopup, this));
       
  2678                 listRect.setHeight(qMin(screen.height(), screen.width()));
       
  2679 
       
  2680                 if (screen.width() < screen.height()) {
       
  2681                     // in portait, menu should be positioned above softkeys
       
  2682                     listRect.moveBottom(screen.bottom());
       
  2683                 } else {
       
  2684                     // landscape, menu should be at the right and horizontally centered
       
  2685                     listRect.setWidth(listRect.height());
       
  2686                     listRect.moveCenter(screen.center());
       
  2687                     (opt.direction == Qt::LeftToRight) ? listRect.setRight(screen.right()) :
       
  2688                                                          listRect.setLeft(screen.left());
       
  2689                 }
       
  2690                 d->container->setGeometry(listRect);
       
  2691             }
       
  2692         }
       
  2693 #endif
       
  2694 
  2639         // ### need to update scrollers etc. as well here
  2695         // ### need to update scrollers etc. as well here
  2640         break;
  2696         break;
  2641     case QEvent::EnabledChange:
  2697     case QEvent::EnabledChange:
  2642         if (!isEnabled())
  2698         if (!isEnabled())
  2643             hidePopup();
  2699             hidePopup();