diff options
Diffstat (limited to 'src/widgets/widgets/qcombobox.cpp')
-rw-r--r-- | src/widgets/widgets/qcombobox.cpp | 86 |
1 files changed, 47 insertions, 39 deletions
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 483cfd8c55..8b54d61e8e 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -223,7 +223,7 @@ void QComboBoxPrivate::_q_completerActivated(const QModelIndex &index) } # ifdef QT_KEYPAD_NAVIGATION - if ( QApplication::keypadNavigationEnabled() + if ( QApplicationPrivate::keypadNavigationEnabled() && q->isEditable() && q->completer() && q->completer()->completionMode() == QCompleter::UnfilteredPopupCompletion ) { @@ -691,7 +691,7 @@ void QComboBoxPrivateContainer::changeEvent(QEvent *e) setFrameStyle(combo->style()->styleHint(QStyle::SH_ComboBox_PopupFrameStyle, &opt, combo)); } - QWidget::changeEvent(e); + QFrame::changeEvent(e); } @@ -1355,7 +1355,13 @@ void QComboBoxPrivate::emitActivated(const QModelIndex &index) return; QString text(itemText(index)); emit q->activated(index.row()); + emit q->textActivated(text); +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED emit q->activated(text); +QT_WARNING_POP +#endif } void QComboBoxPrivate::_q_emitHighlighted(const QModelIndex &index) @@ -1365,7 +1371,13 @@ void QComboBoxPrivate::_q_emitHighlighted(const QModelIndex &index) return; QString text(itemText(index)); emit q->highlighted(index.row()); + emit q->textHighlighted(text); +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED emit q->highlighted(text); +QT_WARNING_POP +#endif } void QComboBoxPrivate::_q_emitCurrentIndexChanged(const QModelIndex &index) @@ -1522,7 +1534,7 @@ void QComboBox::setAutoCompletion(bool enable) Q_D(QComboBox); #ifdef QT_KEYPAD_NAVIGATION - if (Q_UNLIKELY(QApplication::keypadNavigationEnabled() && !enable && isEditable())) + if (Q_UNLIKELY(QApplicationPrivate::keypadNavigationEnabled() && !enable && isEditable())) qWarning("QComboBox::setAutoCompletion: auto completion is mandatory when combo box editable"); #endif @@ -1864,13 +1876,12 @@ void QComboBox::setLineEdit(QLineEdit *edit) d->updateFocusPolicy(); d->lineEdit->setFocusProxy(this); d->lineEdit->setAttribute(Qt::WA_MacShowFocusRect, false); +#if QT_DEPRECATED_SINCE(5, 13) #if QT_CONFIG(completer) setAutoCompletion(d->autoCompletion); -#endif #ifdef QT_KEYPAD_NAVIGATION -#if QT_CONFIG(completer) - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { // Editable combo boxes will have a completer that is set to UnfilteredPopupCompletion. // This means that when the user enters edit mode they are immediately presented with a // list of possible completions. @@ -1882,6 +1893,7 @@ void QComboBox::setLineEdit(QLineEdit *edit) } #endif #endif +#endif setAttribute(Qt::WA_InputMethodEnabled); d->updateLayoutDirection(); @@ -2601,7 +2613,7 @@ bool QComboBoxPrivate::showNativePopup() // We need to fake one here to un-press the button. QMouseEvent mouseReleased(QEvent::MouseButtonRelease, q->pos(), Qt::LeftButton, Qt::MouseButtons(Qt::LeftButton), Qt::KeyboardModifiers()); - qApp->sendEvent(q, &mouseReleased); + QCoreApplication::sendEvent(q, &mouseReleased); #endif return true; @@ -2641,7 +2653,7 @@ void QComboBox::showPopup() #ifdef QT_KEYPAD_NAVIGATION #if QT_CONFIG(completer) - if (QApplication::keypadNavigationEnabled() && d->completer) { + if (QApplicationPrivate::keypadNavigationEnabled() && d->completer) { // editable combo box is line edit plus completer setEditFocus(true); d->completer->complete(); // show popup @@ -2702,15 +2714,14 @@ void QComboBox::showPopup() int heightMargin = container->topMargin() + container->bottomMargin(); // add the frame of the container - int marginTop, marginBottom; - container->getContentsMargins(0, &marginTop, 0, &marginBottom); - heightMargin += marginTop + marginBottom; + const QMargins cm = container->contentsMargins(); + heightMargin += cm.top() + cm.bottom(); //add the frame of the view - view()->getContentsMargins(0, &marginTop, 0, &marginBottom); - marginTop += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->top; - marginBottom += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->bottom; - heightMargin += marginTop + marginBottom; + const QMargins vm = view()->contentsMargins(); + heightMargin += vm.top() + vm.bottom(); + heightMargin += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->top; + heightMargin += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->bottom; listRect.setHeight(listRect.height() + heightMargin); } @@ -2821,19 +2832,15 @@ void QComboBox::showPopup() bool startTimer = !container->isVisible(); container->raise(); container->create(); - QWindow *containerWindow = container->window()->windowHandle(); - if (containerWindow) { - QWindow *win = window()->windowHandle(); - if (win) { - QScreen *currentScreen = win->screen(); - if (currentScreen && !currentScreen->virtualSiblings().contains(containerWindow->screen())) { - containerWindow->setScreen(currentScreen); - - // This seems to workaround an issue in xcb+multi GPU+multiscreen - // environment where the window might not always show up when screen - // is changed. - container->hide(); - } + if (QWindow *containerWindow = qt_widget_private(container)->windowHandle(QWidgetPrivate::WindowHandleMode::TopLevel)) { + QScreen *currentScreen = d->associatedScreen(); + if (currentScreen && !currentScreen->virtualSiblings().contains(containerWindow->screen())) { + containerWindow->setScreen(currentScreen); + + // This seems to workaround an issue in xcb+multi GPU+multiscreen + // environment where the window might not always show up when screen + // is changed. + container->hide(); } } container->show(); @@ -2851,7 +2858,7 @@ void QComboBox::showPopup() container->update(); #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled()) + if (QApplicationPrivate::keypadNavigationEnabled()) view()->setEditFocus(true); #endif if (startTimer) { @@ -2902,7 +2909,7 @@ void QComboBox::hidePopup() bool didFade = false; if (needFade) { #if defined(Q_OS_MAC) - QPlatformNativeInterface *platformNativeInterface = qApp->platformNativeInterface(); + QPlatformNativeInterface *platformNativeInterface = QGuiApplication::platformNativeInterface(); int at = platformNativeInterface->metaObject()->indexOfMethod("fadeWindow()"); if (at != -1) { QMetaMethod windowFade = platformNativeInterface->metaObject()->method(at); @@ -2923,7 +2930,7 @@ void QComboBox::hidePopup() d->container->hide(); } #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled() && isEditable() && hasFocus()) + if (QApplicationPrivate::keypadNavigationEnabled() && isEditable() && hasFocus()) setEditFocus(true); #endif d->_q_resetButton(); @@ -3182,7 +3189,7 @@ void QComboBoxPrivate::showPopupFromMouseEvent(QMouseEvent *e) } } else { #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled() && sc == QStyle::SC_ComboBoxEditField && lineEdit) { + if (QApplicationPrivate::keypadNavigationEnabled() && sc == QStyle::SC_ComboBoxEditField && lineEdit) { lineEdit->event(e); //so lineedit can move cursor, etc return; } @@ -3231,7 +3238,7 @@ void QComboBox::keyPressEvent(QKeyEvent *e) Q_FALLTHROUGH(); case Qt::Key_PageUp: #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled()) + if (QApplicationPrivate::keypadNavigationEnabled()) e->ignore(); else #endif @@ -3246,7 +3253,7 @@ void QComboBox::keyPressEvent(QKeyEvent *e) Q_FALLTHROUGH(); case Qt::Key_PageDown: #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled()) + if (QApplicationPrivate::keypadNavigationEnabled()) e->ignore(); else #endif @@ -3280,7 +3287,7 @@ void QComboBox::keyPressEvent(QKeyEvent *e) break; #ifdef QT_KEYPAD_NAVIGATION case Qt::Key_Select: - if (QApplication::keypadNavigationEnabled() + if (QApplicationPrivate::keypadNavigationEnabled() && (!hasEditFocus() || !d->lineEdit)) { showPopup(); return; @@ -3288,11 +3295,11 @@ void QComboBox::keyPressEvent(QKeyEvent *e) break; case Qt::Key_Left: case Qt::Key_Right: - if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) + if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) e->ignore(); break; case Qt::Key_Back: - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { if (!hasEditFocus() || !d->lineEdit) e->ignore(); } else { @@ -3370,12 +3377,13 @@ void QComboBox::wheelEvent(QWheelEvent *e) !d->viewContainer()->isVisible()) { const int rowCount = count(); int newIndex = currentIndex(); + int delta = e->angleDelta().y(); - if (e->delta() > 0) { + if (delta > 0) { newIndex--; while ((newIndex >= 0) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled)) newIndex--; - } else if (e->delta() < 0) { + } else if (delta < 0) { newIndex++; while (newIndex < rowCount && !(d->model->index(newIndex, d->modelColumn, d->root).flags() & Qt::ItemIsEnabled)) newIndex++; |