diff options
Diffstat (limited to 'src/widgets/widgets')
26 files changed, 197 insertions, 197 deletions
diff --git a/src/widgets/widgets/qabstractbutton.cpp b/src/widgets/widgets/qabstractbutton.cpp index f30a3bc7b8..d956d2ba23 100644 --- a/src/widgets/widgets/qabstractbutton.cpp +++ b/src/widgets/widgets/qabstractbutton.cpp @@ -44,6 +44,7 @@ #endif #if QT_CONFIG(buttongroup) #include "qbuttongroup.h" +#include "private/qapplication_p.h" #include "private/qbuttongroup_p.h" #endif #include "qabstractbutton_p.h" @@ -319,7 +320,7 @@ void QAbstractButtonPrivate::moveFocus(int key) if (exclusive #ifdef QT_KEYPAD_NAVIGATION - && !QApplication::keypadNavigationEnabled() + && !QApplicationPrivate::keypadNavigationEnabled() #endif && candidate && fb->d_func()->checked @@ -1063,7 +1064,7 @@ void QAbstractButton::keyPressEvent(QKeyEvent *e) case Qt::Key_Right: case Qt::Key_Down: { #ifdef QT_KEYPAD_NAVIGATION - if ((QApplication::keypadNavigationEnabled() + if ((QApplicationPrivate::keypadNavigationEnabled() && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right)) || (!QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional || (e->key() == Qt::Key_Up || e->key() == Qt::Key_Down))) { @@ -1159,7 +1160,7 @@ void QAbstractButton::focusInEvent(QFocusEvent *e) { Q_D(QAbstractButton); #ifdef QT_KEYPAD_NAVIGATION - if (!QApplication::keypadNavigationEnabled()) + if (!QApplicationPrivate::keypadNavigationEnabled()) #endif d->fixFocusPolicy(); QWidget::focusInEvent(e); diff --git a/src/widgets/widgets/qabstractscrollarea.cpp b/src/widgets/widgets/qabstractscrollarea.cpp index b9e0d3280f..55b2dcd662 100644 --- a/src/widgets/widgets/qabstractscrollarea.cpp +++ b/src/widgets/widgets/qabstractscrollarea.cpp @@ -1324,7 +1324,7 @@ void QAbstractScrollArea::mouseMoveEvent(QMouseEvent *e) void QAbstractScrollArea::wheelEvent(QWheelEvent *e) { Q_D(QAbstractScrollArea); - if (e->orientation() == Qt::Horizontal) + if (qAbs(e->angleDelta().x()) > qAbs(e->angleDelta().y())) QCoreApplication::sendEvent(d->hbar, e); else QCoreApplication::sendEvent(d->vbar, e); @@ -1362,7 +1362,7 @@ void QAbstractScrollArea::keyPressEvent(QKeyEvent * e) #endif } else { #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { + if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) { e->ignore(); return; } @@ -1376,7 +1376,7 @@ void QAbstractScrollArea::keyPressEvent(QKeyEvent * e) break; case Qt::Key_Left: #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled() && hasEditFocus() + if (QApplicationPrivate::keypadNavigationEnabled() && hasEditFocus() && (!d->hbar->isVisible() || d->hbar->value() == d->hbar->minimum())) { //if we aren't using the hbar or we are already at the leftmost point ignore e->ignore(); @@ -1389,7 +1389,7 @@ void QAbstractScrollArea::keyPressEvent(QKeyEvent * e) break; case Qt::Key_Right: #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled() && hasEditFocus() + if (QApplicationPrivate::keypadNavigationEnabled() && hasEditFocus() && (!d->hbar->isVisible() || d->hbar->value() == d->hbar->maximum())) { //if we aren't using the hbar or we are already at the rightmost point ignore e->ignore(); diff --git a/src/widgets/widgets/qabstractslider.cpp b/src/widgets/widgets/qabstractslider.cpp index 2172ebc99c..129d540f50 100644 --- a/src/widgets/widgets/qabstractslider.cpp +++ b/src/widgets/widgets/qabstractslider.cpp @@ -47,6 +47,8 @@ #endif #include <limits.h> +#include <private/qapplication_p.h> + QT_BEGIN_NAMESPACE /*! @@ -764,10 +766,11 @@ void QAbstractSlider::wheelEvent(QWheelEvent * e) { Q_D(QAbstractSlider); e->ignore(); - int delta = e->delta(); + bool vertical = bool(e->angleDelta().y()); + int delta = vertical ? e->angleDelta().y() : e->angleDelta().x(); if (e->inverted()) delta = -delta; - if (d->scrollByDelta(e->orientation(), e->modifiers(), delta)) + if (d->scrollByDelta(vertical ? Qt::Vertical : Qt::Horizontal, e->modifiers(), delta)) e->accept(); } @@ -815,13 +818,13 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev) switch (ev->key()) { #ifdef QT_KEYPAD_NAVIGATION case Qt::Key_Select: - if (QApplication::keypadNavigationEnabled()) + if (QApplicationPrivate::keypadNavigationEnabled()) setEditFocus(!hasEditFocus()); else ev->ignore(); break; case Qt::Key_Back: - if (QApplication::keypadNavigationEnabled() && hasEditFocus()) { + if (QApplicationPrivate::keypadNavigationEnabled() && hasEditFocus()) { setValue(d->origValue); setEditFocus(false); } else @@ -834,7 +837,7 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev) // In QApplication::KeypadNavigationDirectional, we want to change the slider // value if there is no left/right navigation possible and if this slider is not // inside a tab widget. - if (QApplication::keypadNavigationEnabled() + if (QApplicationPrivate::keypadNavigationEnabled() && (!hasEditFocus() && QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder || d->orientation == Qt::Vertical || !hasEditFocus() @@ -842,7 +845,7 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev) ev->ignore(); return; } - if (QApplication::keypadNavigationEnabled() && d->orientation == Qt::Vertical) + if (QApplicationPrivate::keypadNavigationEnabled() && d->orientation == Qt::Vertical) action = d->invertedControls ? SliderSingleStepSub : SliderSingleStepAdd; else #endif @@ -854,7 +857,7 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev) case Qt::Key_Right: #ifdef QT_KEYPAD_NAVIGATION // Same logic as in Qt::Key_Left - if (QApplication::keypadNavigationEnabled() + if (QApplicationPrivate::keypadNavigationEnabled() && (!hasEditFocus() && QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder || d->orientation == Qt::Vertical || !hasEditFocus() @@ -862,7 +865,7 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev) ev->ignore(); return; } - if (QApplication::keypadNavigationEnabled() && d->orientation == Qt::Vertical) + if (QApplicationPrivate::keypadNavigationEnabled() && d->orientation == Qt::Vertical) action = d->invertedControls ? SliderSingleStepAdd : SliderSingleStepSub; else #endif @@ -875,7 +878,7 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev) #ifdef QT_KEYPAD_NAVIGATION // In QApplication::KeypadNavigationDirectional, we want to change the slider // value if there is no up/down navigation possible. - if (QApplication::keypadNavigationEnabled() + if (QApplicationPrivate::keypadNavigationEnabled() && (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder || d->orientation == Qt::Horizontal || !hasEditFocus() && QWidgetPrivate::canKeypadNavigate(Qt::Vertical))) { @@ -888,7 +891,7 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev) case Qt::Key_Down: #ifdef QT_KEYPAD_NAVIGATION // Same logic as in Qt::Key_Up - if (QApplication::keypadNavigationEnabled() + if (QApplicationPrivate::keypadNavigationEnabled() && (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder || d->orientation == Qt::Horizontal || !hasEditFocus() && QWidgetPrivate::canKeypadNavigate(Qt::Vertical))) { diff --git a/src/widgets/widgets/qabstractspinbox.cpp b/src/widgets/widgets/qabstractspinbox.cpp index e6e9939a10..f5708788b8 100644 --- a/src/widgets/widgets/qabstractspinbox.cpp +++ b/src/widgets/widgets/qabstractspinbox.cpp @@ -39,6 +39,7 @@ #include <qplatformdefs.h> #include <private/qabstractspinbox_p.h> +#include <private/qapplication_p.h> #if QT_CONFIG(datetimeparser) #include <private/qdatetimeparser_p.h> #endif @@ -803,7 +804,7 @@ bool QAbstractSpinBox::event(QEvent *event) #ifdef QT_KEYPAD_NAVIGATION case QEvent::EnterEditFocus: case QEvent::LeaveEditFocus: - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { const bool b = d->edit->event(event); d->edit->setSelection(d->edit->displayText().size() - d->suffix.size(),0); if (event->type() == QEvent::LeaveEditFocus) @@ -1025,7 +1026,7 @@ void QAbstractSpinBox::keyPressEvent(QKeyEvent *event) case Qt::Key_Up: case Qt::Key_Down: { #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { // Reserve up/down for nav - use left/right for edit. if (!hasEditFocus() && (event->key() == Qt::Key_Up || event->key() == Qt::Key_Down)) { @@ -1061,13 +1062,13 @@ void QAbstractSpinBox::keyPressEvent(QKeyEvent *event) #ifdef QT_KEYPAD_NAVIGATION case Qt::Key_Left: case Qt::Key_Right: - if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { + if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) { event->ignore(); return; } break; case Qt::Key_Back: - if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { + if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) { event->ignore(); return; } @@ -1085,7 +1086,7 @@ void QAbstractSpinBox::keyPressEvent(QKeyEvent *event) #ifdef QT_KEYPAD_NAVIGATION case Qt::Key_Select: - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { // Toggles between left/right moving cursor and inc/dec. setEditFocus(!hasEditFocus()); } @@ -1221,7 +1222,7 @@ void QAbstractSpinBox::focusOutEvent(QFocusEvent *event) #ifdef QT_KEYPAD_NAVIGATION // editingFinished() is already emitted on LeaveEditFocus - if (!QApplication::keypadNavigationEnabled()) + if (!QApplicationPrivate::keypadNavigationEnabled()) #endif emit editingFinished(); } diff --git a/src/widgets/widgets/qcalendarwidget.cpp b/src/widgets/widgets/qcalendarwidget.cpp index 510b34cb18..78706b1854 100644 --- a/src/widgets/widgets/qcalendarwidget.cpp +++ b/src/widgets/widgets/qcalendarwidget.cpp @@ -54,6 +54,7 @@ #include <qspinbox.h> #include <qmenu.h> #include <qapplication.h> +#include <private/qapplication_p.h> #include <qbasictimer.h> #include <qstylepainter.h> @@ -1384,14 +1385,14 @@ void QCalendarView::keyPressEvent(QKeyEvent *event) { #ifdef QT_KEYPAD_NAVIGATION if (event->key() == Qt::Key_Select) { - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { if (!hasEditFocus()) { setEditFocus(true); return; } } } else if (event->key() == Qt::Key_Back) { - if (QApplication::keypadNavigationEnabled() && hasEditFocus()) { + if (QApplicationPrivate::keypadNavigationEnabled() && hasEditFocus()) { if (qobject_cast<QCalendarModel *>(model())) { emit changeDate(origDate, true); //changes selection back to origDate, but doesn't activate setEditFocus(false); @@ -1418,7 +1419,7 @@ void QCalendarView::keyPressEvent(QKeyEvent *event) #if QT_CONFIG(wheelevent) void QCalendarView::wheelEvent(QWheelEvent *event) { - const int numDegrees = event->delta() / 8; + const int numDegrees = event->angleDelta().y() / 8; const int numSteps = numDegrees / 15; const QModelIndex index = currentIndex(); QDate currentDate = static_cast<QCalendarModel*>(model())->dateForCell(index.row(), index.column()); diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 0b52747b6a..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 ) { @@ -896,11 +896,6 @@ QStyleOptionComboBox QComboBoxPrivateContainer::comboStyleOption() const \fn void QComboBox::currentIndexChanged(const QString &text) \since 4.1 - \obsolete - - Use currentTextChanged(const QString &) or currentIndexChanged(int) - instead. - This signal is sent whenever the currentIndex in the combobox changes either through user interaction or programmatically. The item's \a text is passed. @@ -1539,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 @@ -1886,7 +1881,7 @@ void QComboBox::setLineEdit(QLineEdit *edit) setAutoCompletion(d->autoCompletion); #ifdef QT_KEYPAD_NAVIGATION - 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. @@ -2628,7 +2623,7 @@ bool QComboBoxPrivate::showNativePopup() /*! Displays the list of items in the combobox. If the list is empty - then the no items will be shown. + then no items will be shown. If you reimplement this function to show a custom pop-up, make sure you call hidePopup() to reset the internal state. @@ -2658,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 @@ -2719,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); } @@ -2864,7 +2858,7 @@ void QComboBox::showPopup() container->update(); #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled()) + if (QApplicationPrivate::keypadNavigationEnabled()) view()->setEditFocus(true); #endif if (startTimer) { @@ -2936,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(); @@ -3195,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; } @@ -3244,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 @@ -3259,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 @@ -3293,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; @@ -3301,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 { @@ -3383,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++; diff --git a/src/widgets/widgets/qcombobox.h b/src/widgets/widgets/qcombobox.h index 3b48b151a1..286772c091 100644 --- a/src/widgets/widgets/qcombobox.h +++ b/src/widgets/widgets/qcombobox.h @@ -227,11 +227,8 @@ Q_SIGNALS: void highlighted(int index); void textHighlighted(const QString &); void currentIndexChanged(int index); - void currentTextChanged(const QString &); -#if QT_DEPRECATED_SINCE(5, 13) - QT_DEPRECATED_VERSION_X(5, 13, "Use currentTextChanged() instead") void currentIndexChanged(const QString &); -#endif + void currentTextChanged(const QString &); #if QT_DEPRECATED_SINCE(5, 15) QT_DEPRECATED_VERSION_X(5, 15, "Use textActivated() instead") void activated(const QString &); diff --git a/src/widgets/widgets/qcommandlinkbutton.cpp b/src/widgets/widgets/qcommandlinkbutton.cpp index 68dfefb3b7..2b9258fd91 100644 --- a/src/widgets/widgets/qcommandlinkbutton.cpp +++ b/src/widgets/widgets/qcommandlinkbutton.cpp @@ -58,7 +58,7 @@ QT_BEGIN_NAMESPACE \ingroup basicwidgets \inmodule QtWidgets - The command link is a new control that was introduced by Windows Vista. It's + The command link is a new control that was introduced by Windows Vista. Its intended use is similar to that of a radio button in that it is used to choose between a set of mutually exclusive options. Command link buttons should not be used by themselves but rather as an alternative to radio buttons in diff --git a/src/widgets/widgets/qdatetimeedit.cpp b/src/widgets/widgets/qdatetimeedit.cpp index 45c72e24d4..3c92d4be0e 100644 --- a/src/widgets/widgets/qdatetimeedit.cpp +++ b/src/widgets/widgets/qdatetimeedit.cpp @@ -37,6 +37,7 @@ ** ****************************************************************************/ +#include <private/qapplication_p.h> #include <private/qdatetimeedit_p.h> #include <qabstractspinbox.h> #include <qapplication.h> @@ -642,7 +643,7 @@ QDateTimeEdit::Section QDateTimeEdit::currentSection() const { Q_D(const QDateTimeEdit); #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled() && d->focusOnButton) + if (QApplicationPrivate::keypadNavigationEnabled() && d->focusOnButton) return NoSection; #endif return QDateTimeEditPrivate::convertToPublic(d->sectionType(d->currentSectionIndex)); @@ -1055,7 +1056,7 @@ void QDateTimeEdit::keyPressEvent(QKeyEvent *event) switch (event->key()) { #ifdef QT_KEYPAD_NAVIGATION case Qt::Key_NumberSign: //shortcut to popup calendar - if (QApplication::keypadNavigationEnabled() && d->calendarPopupEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled() && d->calendarPopupEnabled()) { d->initCalendarPopup(); d->positionCalendarPopup(); d->monthCalendar->show(); @@ -1063,7 +1064,7 @@ void QDateTimeEdit::keyPressEvent(QKeyEvent *event) } break; case Qt::Key_Select: - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { if (hasEditFocus()) { if (d->focusOnButton) { d->initCalendarPopup(); @@ -1095,7 +1096,7 @@ void QDateTimeEdit::keyPressEvent(QKeyEvent *event) return; default: #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled() && !hasEditFocus() + if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus() && !event->text().isEmpty() && event->text().at(0).isLetterOrNumber()) { setEditFocus(true); @@ -1117,8 +1118,8 @@ void QDateTimeEdit::keyPressEvent(QKeyEvent *event) if (event->key() == Qt::Key_Left || event->key() == Qt::Key_Right) { if ( #ifdef QT_KEYPAD_NAVIGATION - QApplication::keypadNavigationEnabled() && !hasEditFocus() - || !QApplication::keypadNavigationEnabled() && + QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus() + || !QApplicationPrivate::keypadNavigationEnabled() && #endif !(event->modifiers() & Qt::ControlModifier)) { select = false; @@ -1127,7 +1128,7 @@ void QDateTimeEdit::keyPressEvent(QKeyEvent *event) #if 0 // Used to be included in Qt4 for Q_WS_MAC else #ifdef QT_KEYPAD_NAVIGATION - if (!QApplication::keypadNavigationEnabled()) + if (!QApplicationPrivate::keypadNavigationEnabled()) #endif { select = (event->modifiers() & Qt::ShiftModifier); @@ -1147,7 +1148,7 @@ void QDateTimeEdit::keyPressEvent(QKeyEvent *event) && (event->key() != Qt::Key_Tab || !(event->modifiers() & Qt::ShiftModifier)); #ifdef QT_KEYPAD_NAVIGATION int newSection = d->nextPrevSection(d->currentSectionIndex, forward); - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { if (d->focusOnButton) { newSection = forward ? 0 : d->sectionNodes.size() - 1; d->focusOnButton = false; @@ -1290,7 +1291,7 @@ void QDateTimeEdit::stepBy(int steps) Q_D(QDateTimeEdit); #ifdef QT_KEYPAD_NAVIGATION // with keypad navigation and not editFocus, left right change the date/time by a fixed amount. - if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { + if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) { // if date based, shift by day. else shift by 15min if (d->sections & DateSections_Mask) { setDateTime(dateTime().addDays(steps)); @@ -1417,7 +1418,7 @@ QDateTimeEdit::StepEnabled QDateTimeEdit::stepEnabled() const QAbstractSpinBox::StepEnabled ret = 0; #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { + if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) { if (d->wrapping) return StepEnabled(StepUpEnabled | StepDownEnabled); // 3 cases. date, time, datetime. each case look @@ -1702,7 +1703,7 @@ void QDateTimeEditPrivate::updateEdit() if (!specialValue() #ifdef QT_KEYPAD_NAVIGATION - && !(QApplication::keypadNavigationEnabled() && !edit->hasEditFocus()) + && !(QApplicationPrivate::keypadNavigationEnabled() && !edit->hasEditFocus()) #endif ) { int cursor = sectionPos(currentSectionIndex); @@ -1731,7 +1732,7 @@ void QDateTimeEditPrivate::setSelected(int sectionIndex, bool forward) { if (specialValue() #ifdef QT_KEYPAD_NAVIGATION - || (QApplication::keypadNavigationEnabled() && !edit->hasEditFocus()) + || (QApplicationPrivate::keypadNavigationEnabled() && !edit->hasEditFocus()) #endif ) { edit->selectAll(); @@ -2426,7 +2427,7 @@ void QDateTimeEditPrivate::init(const QVariant &var) break; } #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled()) + if (QApplicationPrivate::keypadNavigationEnabled()) q->setCalendarPopup(true); #endif q->setInputMethodHints(Qt::ImhPreferNumbers); @@ -2602,7 +2603,7 @@ QCalendarWidget *QCalendarPopup::verifyCalendarInstance() QCalendarWidget *cw = new QCalendarWidget(this); cw->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader); #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled()) + if (QApplicationPrivate::keypadNavigationEnabled()) cw->setHorizontalHeaderFormat(QCalendarWidget::SingleLetterDayNames); #endif setCalendarWidget(cw); diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp index 68e3de05bc..7f482a6a4e 100644 --- a/src/widgets/widgets/qlineedit.cpp +++ b/src/widgets/widgets/qlineedit.cpp @@ -293,7 +293,7 @@ QLineEdit::~QLineEdit() /*! \property QLineEdit::text - \brief the line edit's text + \brief the line edit's text. Setting this property clears the selection, clears the undo/redo history, moves the cursor to the end of the line and resets the @@ -322,7 +322,7 @@ void QLineEdit::setText(const QString& text) \since 4.7 \property QLineEdit::placeholderText - \brief the line edit's placeholder text + \brief the line edit's placeholder text. Setting this property makes the line edit display a grayed-out placeholder text as long as the line edit is empty. @@ -354,7 +354,7 @@ void QLineEdit::setPlaceholderText(const QString& placeholderText) /*! \property QLineEdit::displayText - \brief the displayed text + \brief the displayed text. If \l echoMode is \l Normal this returns the same as text(); if \l EchoMode is \l Password or \l PasswordEchoOnEdit it returns a string of @@ -375,7 +375,7 @@ QString QLineEdit::displayText() const /*! \property QLineEdit::maxLength - \brief the maximum permitted length of the text + \brief the maximum permitted length of the text. If the text is too long, it is truncated at the limit. @@ -405,7 +405,7 @@ void QLineEdit::setMaxLength(int maxLength) /*! \property QLineEdit::frame - \brief whether the line edit draws itself with a frame + \brief whether the line edit draws itself with a frame. If enabled (the default) the line edit draws itself inside a frame, otherwise the line edit draws itself without any frame. @@ -544,7 +544,7 @@ void QLineEdit::setFrame(bool enable) /*! \property QLineEdit::echoMode - \brief the line edit's echo mode + \brief the line edit's echo mode. The echo mode determines how the text entered in the line edit is displayed (or echoed) to the user. @@ -684,11 +684,12 @@ QSize QLineEdit::sizeHint() const ensurePolished(); QFontMetrics fm(font()); const int iconSize = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this); - int h = qMax(fm.height(), iconSize - 2) + 2 * QLineEditPrivate::verticalMargin - + d->topTextMargin + d->bottomTextMargin + const QMargins tm = d->effectiveTextMargins(); + int h = qMax(fm.height(), qMax(14, iconSize - 2)) + 2 * QLineEditPrivate::verticalMargin + + tm.top() + tm.bottom() + d->topmargin + d->bottommargin; int w = fm.horizontalAdvance(QLatin1Char('x')) * 17 + 2 * QLineEditPrivate::horizontalMargin - + d->effectiveLeftTextMargin() + d->effectiveRightTextMargin() + + tm.left() + tm.right() + d->leftmargin + d->rightmargin; // "some" QStyleOptionFrame opt; initStyleOption(&opt); @@ -708,11 +709,12 @@ QSize QLineEdit::minimumSizeHint() const Q_D(const QLineEdit); ensurePolished(); QFontMetrics fm = fontMetrics(); + const QMargins tm = d->effectiveTextMargins(); int h = fm.height() + qMax(2 * QLineEditPrivate::verticalMargin, fm.leading()) - + d->topTextMargin + d->bottomTextMargin + + tm.top() + tm.bottom() + d->topmargin + d->bottommargin; int w = fm.maxWidth() - + d->effectiveLeftTextMargin() + d->effectiveRightTextMargin() + + tm.left() + tm.right() + d->leftmargin + d->rightmargin; QStyleOptionFrame opt; initStyleOption(&opt); @@ -723,7 +725,7 @@ QSize QLineEdit::minimumSizeHint() const /*! \property QLineEdit::cursorPosition - \brief the current cursor position for this line edit + \brief the current cursor position for this line edit. Setting the cursor position causes a repaint when appropriate. @@ -756,7 +758,7 @@ int QLineEdit::cursorPositionAt(const QPoint &pos) /*! \property QLineEdit::alignment - \brief the alignment of the line edit + \brief the alignment of the line edit. Both horizontal and vertical alignment is allowed here, Qt::AlignJustify will map to Qt::AlignLeft. @@ -894,7 +896,7 @@ void QLineEdit::end(bool mark) /*! \property QLineEdit::modified - \brief whether the line edit's contents has been modified by the user + \brief whether the line edit's contents has been modified by the user. The modified flag is never read by QLineEdit; it has a default value of false and is changed to true whenever the user changes the line @@ -924,7 +926,7 @@ void QLineEdit::setModified(bool modified) /*! \property QLineEdit::hasSelectedText - \brief whether there is any text selected + \brief whether there is any text selected. hasSelectedText() returns \c true if some or all of the text has been selected by the user; otherwise returns \c false. @@ -943,7 +945,7 @@ bool QLineEdit::hasSelectedText() const /*! \property QLineEdit::selectedText - \brief the selected text + \brief the selected text. If there is no selected text this property's value is an empty string. @@ -1030,7 +1032,7 @@ void QLineEdit::setSelection(int start, int length) /*! \property QLineEdit::undoAvailable - \brief whether undo is available + \brief whether undo is available. Undo becomes available once the user has modified the text in the line edit. @@ -1045,7 +1047,7 @@ bool QLineEdit::isUndoAvailable() const /*! \property QLineEdit::redoAvailable - \brief whether redo is available + \brief whether redo is available. Redo becomes available once the user has performed one or more undo operations on text in the line edit. @@ -1062,7 +1064,7 @@ bool QLineEdit::isRedoAvailable() const /*! \property QLineEdit::dragEnabled \brief whether the lineedit starts a drag if the user presses and - moves the mouse on some selected text + moves the mouse on some selected text. Dragging is disabled by default. */ @@ -1081,7 +1083,7 @@ void QLineEdit::setDragEnabled(bool b) /*! \property QLineEdit::cursorMoveStyle - \brief the movement style of cursor in this line edit + \brief the movement style of cursor in this line edit. \since 4.8 When this property is set to Qt::VisualMoveStyle, the line edit will use visual @@ -1127,17 +1129,11 @@ bool QLineEdit::hasAcceptableInput() const sizes \a left, \a top, \a right, and \a bottom. \since 4.5 - See also getTextMargins(). + See also textMargins(). */ void QLineEdit::setTextMargins(int left, int top, int right, int bottom) { - Q_D(QLineEdit); - d->leftTextMargin = left; - d->topTextMargin = top; - d->rightTextMargin = right; - d->bottomTextMargin = bottom; - updateGeometry(); - update(); + setTextMargins({left, top, right, bottom}); } /*! @@ -1148,10 +1144,17 @@ void QLineEdit::setTextMargins(int left, int top, int right, int bottom) */ void QLineEdit::setTextMargins(const QMargins &margins) { - setTextMargins(margins.left(), margins.top(), margins.right(), margins.bottom()); + Q_D(QLineEdit); + d->textMargins = margins; + updateGeometry(); + update(); } +#if QT_DEPRECATED_SINCE(5, 14) /*! + \obsolete + Use textMargins() + Returns the widget's text margins for \a left, \a top, \a right, and \a bottom. \since 4.5 @@ -1159,16 +1162,17 @@ void QLineEdit::setTextMargins(const QMargins &margins) */ void QLineEdit::getTextMargins(int *left, int *top, int *right, int *bottom) const { - Q_D(const QLineEdit); + QMargins m = textMargins(); if (left) - *left = d->leftTextMargin; + *left = m.left(); if (top) - *top = d->topTextMargin; + *top = m.top(); if (right) - *right = d->rightTextMargin; + *right = m.right(); if (bottom) - *bottom = d->bottomTextMargin; + *bottom = m.bottom(); } +#endif /*! \since 4.6 @@ -1179,12 +1183,12 @@ void QLineEdit::getTextMargins(int *left, int *top, int *right, int *bottom) con QMargins QLineEdit::textMargins() const { Q_D(const QLineEdit); - return QMargins(d->leftTextMargin, d->topTextMargin, d->rightTextMargin, d->bottomTextMargin); + return d->textMargins; } /*! \property QLineEdit::inputMask - \brief The validation input mask + \brief The validation input mask. If no mask is set, inputMask() returns an empty string. @@ -1481,7 +1485,7 @@ bool QLineEdit::event(QEvent * e) d->initMouseYThreshold(); } #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { if (e->type() == QEvent::EnterEditFocus) { end(false); d->setCursorVisible(true); @@ -1513,7 +1517,7 @@ void QLineEdit::mousePressEvent(QMouseEvent* e) if (e->button() == Qt::RightButton) return; #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { + if (QApplication::QApplicationPrivate() && !hasEditFocus()) { setEditFocus(true); // Get the completion list to pop up. if (d->control->completer()) @@ -1722,7 +1726,7 @@ void QLineEdit::keyPressEvent(QKeyEvent *event) bool select = false; switch (event->key()) { case Qt::Key_Select: - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { if (hasEditFocus()) { setEditFocus(false); if (d->control->completer() && d->control->completer()->popup()->isVisible()) @@ -1733,13 +1737,13 @@ void QLineEdit::keyPressEvent(QKeyEvent *event) break; case Qt::Key_Back: case Qt::Key_No: - if (!QApplication::keypadNavigationEnabled() || !hasEditFocus()) { + if (!QApplicationPrivate::keypadNavigationEnabled() || !hasEditFocus()) { event->ignore(); return; } break; default: - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { if (!hasEditFocus() && !(event->modifiers() & Qt::ControlModifier)) { if (!event->text().isEmpty() && event->text().at(0).isPrint() && !isReadOnly()) @@ -1754,7 +1758,7 @@ void QLineEdit::keyPressEvent(QKeyEvent *event) - if (QApplication::keypadNavigationEnabled() && !select && !hasEditFocus()) { + if (QApplicationPrivate::keypadNavigationEnabled() && !select && !hasEditFocus()) { setEditFocus(true); if (event->key() == Qt::Key_Select) return; // Just start. No action. @@ -1801,7 +1805,7 @@ void QLineEdit::inputMethodEvent(QInputMethodEvent *e) // Focus in if currently in navigation focus on the widget // Only focus in on preedits, to allow input methods to // commit text as they focus out without interfering with focus - if (QApplication::keypadNavigationEnabled() + if (QApplicationPrivate::keypadNavigationEnabled() && hasFocus() && !hasEditFocus() && !e->preeditString().isEmpty()) setEditFocus(true); @@ -1874,7 +1878,7 @@ void QLineEdit::focusInEvent(QFocusEvent *e) d->clickCausedFocus = 1; } #ifdef QT_KEYPAD_NAVIGATION - if (!QApplication::keypadNavigationEnabled() || (hasEditFocus() && ( e->reason() == Qt::PopupFocusReason))) { + if (!QApplicationPrivate::keypadNavigationEnabled() || (hasEditFocus() && ( e->reason() == Qt::PopupFocusReason))) { #endif d->control->setBlinkingCursorEnabled(true); QStyleOptionFrame opt; @@ -1918,7 +1922,7 @@ void QLineEdit::focusOutEvent(QFocusEvent *e) d->control->setBlinkingCursorEnabled(false); #ifdef QT_KEYPAD_NAVIGATION // editingFinished() is already emitted on LeaveEditFocus - if (!QApplication::keypadNavigationEnabled()) + if (!QApplicationPrivate::keypadNavigationEnabled()) #endif if (reason != Qt::PopupFocusReason || !(QApplication::activePopupWidget() && QApplication::activePopupWidget()->parentWidget() == this)) { @@ -1950,10 +1954,7 @@ void QLineEdit::paintEvent(QPaintEvent *) initStyleOption(&panel); style()->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, &p, this); QRect r = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this); - r.setX(r.x() + d->effectiveLeftTextMargin()); - r.setY(r.y() + d->topTextMargin); - r.setRight(r.right() - d->effectiveRightTextMargin()); - r.setBottom(r.bottom() - d->bottomTextMargin); + r = r.marginsRemoved(d->effectiveTextMargins()); p.setClipRect(r); QFontMetrics fm = fontMetrics(); @@ -2041,7 +2042,7 @@ void QLineEdit::paintEvent(QPaintEvent *) int flags = QWidgetLineControl::DrawText; #ifdef QT_KEYPAD_NAVIGATION - if (!QApplication::keypadNavigationEnabled() || hasEditFocus()) + if (!QApplicationPrivate::keypadNavigationEnabled() || hasEditFocus()) #endif if (d->control->hasSelectedText() || (d->cursorVisible && !d->control->inputMask().isEmpty() && !d->control->isReadOnly())){ flags |= QWidgetLineControl::DrawSelections; diff --git a/src/widgets/widgets/qlineedit.h b/src/widgets/widgets/qlineedit.h index de82927f74..1cf1f24449 100644 --- a/src/widgets/widgets/qlineedit.h +++ b/src/widgets/widgets/qlineedit.h @@ -172,7 +172,10 @@ public: void setTextMargins(int left, int top, int right, int bottom); void setTextMargins(const QMargins &margins); +#if QT_DEPRECATED_SINCE(5, 14) + QT_DEPRECATED_X("use textMargins()") void getTextMargins(int *left, int *top, int *right, int *bottom) const; +#endif QMargins textMargins() const; #if QT_CONFIG(action) diff --git a/src/widgets/widgets/qlineedit_p.cpp b/src/widgets/widgets/qlineedit_p.cpp index 7d580e50a5..d2b5f87906 100644 --- a/src/widgets/widgets/qlineedit_p.cpp +++ b/src/widgets/widgets/qlineedit_p.cpp @@ -254,10 +254,7 @@ QRect QLineEditPrivate::adjustedContentsRect() const QStyleOptionFrame opt; q->initStyleOption(&opt); QRect r = q->style()->subElementRect(QStyle::SE_LineEditContents, &opt, q); - r.setX(r.x() + effectiveLeftTextMargin()); - r.setY(r.y() + topTextMargin); - r.setRight(r.right() - effectiveRightTextMargin()); - r.setBottom(r.bottom() - bottomTextMargin); + r = r.marginsRemoved(effectiveTextMargins()); return r; } @@ -672,14 +669,12 @@ static int effectiveTextMargin(int defaultMargin, const QLineEditPrivate::SideWi return e.widget->isVisibleTo(e.widget->parentWidget()); })); } -int QLineEditPrivate::effectiveLeftTextMargin() const +QMargins QLineEditPrivate::effectiveTextMargins() const { - return effectiveTextMargin(leftTextMargin, leftSideWidgetList(), sideWidgetParameters()); -} - -int QLineEditPrivate::effectiveRightTextMargin() const -{ - return effectiveTextMargin(rightTextMargin, rightSideWidgetList(), sideWidgetParameters()); + return {effectiveTextMargin(textMargins.left(), leftSideWidgetList(), sideWidgetParameters()), + textMargins.top(), + effectiveTextMargin(textMargins.right(), rightSideWidgetList(), sideWidgetParameters()), + textMargins.bottom()}; } diff --git a/src/widgets/widgets/qlineedit_p.h b/src/widgets/widgets/qlineedit_p.h index 3f98aab901..a11fea6bbe 100644 --- a/src/widgets/widgets/qlineedit_p.h +++ b/src/widgets/widgets/qlineedit_p.h @@ -67,6 +67,7 @@ #endif #include "QtCore/qpointer.h" #include "QtCore/qmimedata.h" +#include <QtCore/qmargins.h> #include "private/qwidgetlinecontrol_p.h" @@ -153,7 +154,7 @@ public: : control(0), frame(1), contextMenuEnabled(1), cursorVisible(0), dragEnabled(0), clickCausedFocus(0), edited(0), hscroll(0), vscroll(0), alignment(Qt::AlignLeading | Qt::AlignVCenter), - leftTextMargin(0), topTextMargin(0), rightTextMargin(0), bottomTextMargin(0), + textMargins{0, 0, 0, 0}, lastTextSize(0), mouseYThreshold(0) { } @@ -233,10 +234,7 @@ public: void _q_textChanged(const QString &); void _q_clearButtonClicked(); - int leftTextMargin; // use effectiveLeftTextMargin() in case of icon. - int topTextMargin; - int rightTextMargin; // use effectiveRightTextMargin() in case of icon. - int bottomTextMargin; + QMargins textMargins; // use effectiveTextMargins() in case of icon. QString placeholderText; @@ -252,8 +250,7 @@ public: inline const SideWidgetEntryList &rightSideWidgetList() const { return q_func()->layoutDirection() == Qt::LeftToRight ? trailingSideWidgets : leadingSideWidgets; } - int effectiveLeftTextMargin() const; - int effectiveRightTextMargin() const; + QMargins effectiveTextMargins() const; private: struct SideWidgetLocation { diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 72653b377d..e38490dabd 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -142,9 +142,7 @@ public: #endif if (style() != p->style()) setStyle(p->style()); - int leftMargin, topMargin, rightMargin, bottomMargin; - p->getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin); - setContentsMargins(leftMargin, topMargin, rightMargin, bottomMargin); + setContentsMargins(p->contentsMargins()); setLayoutDirection(p->layoutDirection()); //QObject::connect(this, SIGNAL(triggered(QAction*)), this, SLOT(onTrigger(QAction*))); //QObject::connect(this, SIGNAL(hovered(QAction*)), this, SLOT(onHovered(QAction*))); @@ -200,7 +198,7 @@ void QMenuPrivate::init() q->setAttribute(Qt::WA_X11NetWmWindowTypePopupMenu); defaultMenuAction = menuAction = new QAction(q); menuAction->d_func()->menu = q; - QObject::connect(menuAction, &QAction::changed, [=] { + QObject::connect(menuAction, &QAction::changed, [this] { if (!tornPopup.isNull()) tornPopup->updateWindowTitle(); }); @@ -2392,7 +2390,7 @@ void QMenu::popup(const QPoint &p, QAction *atAction) } #ifdef QT_KEYPAD_NAVIGATION - if (!atAction && QApplication::keypadNavigationEnabled()) { + if (!atAction && QApplicationPrivate::keypadNavigationEnabled()) { // Try to have one item activated if (d->defaultAction && d->defaultAction->isEnabled()) { atAction = d->defaultAction; @@ -2847,8 +2845,8 @@ void QMenu::paintEvent(QPaintEvent *e) void QMenu::wheelEvent(QWheelEvent *e) { Q_D(QMenu); - if (d->scroll && rect().contains(e->pos())) - d->scrollMenu(e->delta() > 0 ? + if (d->scroll && rect().contains(e->position().toPoint())) + d->scrollMenu(e->angleDelta().y() > 0 ? QMenuPrivate::QMenuScroller::ScrollUp : QMenuPrivate::QMenuScroller::ScrollDown); } #endif diff --git a/src/widgets/widgets/qplaintextedit.cpp b/src/widgets/widgets/qplaintextedit.cpp index 397304ec44..8843797430 100644 --- a/src/widgets/widgets/qplaintextedit.cpp +++ b/src/widgets/widgets/qplaintextedit.cpp @@ -54,6 +54,7 @@ #endif #include <qstyle.h> #include <qtimer.h> +#include "private/qapplication_p.h" #include "private/qtextdocumentlayout_p.h" #include "private/qabstracttextdocumentlayout_p.h" #include "qtextdocument.h" @@ -1573,7 +1574,7 @@ bool QPlainTextEdit::event(QEvent *e) } #ifdef QT_KEYPAD_NAVIGATION else if (e->type() == QEvent::EnterEditFocus || e->type() == QEvent::LeaveEditFocus) { - if (QApplication::keypadNavigationEnabled()) + if (QApplicationPrivate::keypadNavigationEnabled()) d->sendControlEvent(e); } #endif @@ -1691,7 +1692,7 @@ void QPlainTextEdit::keyPressEvent(QKeyEvent *e) #ifdef QT_KEYPAD_NAVIGATION switch (e->key()) { case Qt::Key_Select: - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { if (!(d->control->textInteractionFlags() & Qt::LinksAccessibleByKeyboard)) setEditFocus(!hasEditFocus()); else { @@ -1709,14 +1710,14 @@ void QPlainTextEdit::keyPressEvent(QKeyEvent *e) break; case Qt::Key_Back: case Qt::Key_No: - if (!QApplication::keypadNavigationEnabled() - || (QApplication::keypadNavigationEnabled() && !hasEditFocus())) { + if (!QApplicationPrivate::keypadNavigationEnabled() + || (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus())) { e->ignore(); return; } break; default: - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { if (!hasEditFocus() && !(e->modifiers() & Qt::ControlModifier)) { if (e->text()[0].isPrint()) { setEditFocus(true); @@ -1792,7 +1793,7 @@ void QPlainTextEdit::keyPressEvent(QKeyEvent *e) switch (e->key()) { case Qt::Key_Up: case Qt::Key_Down: - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { // Cursor position didn't change, so we want to leave // these keys to change focus. e->ignore(); @@ -1801,7 +1802,7 @@ void QPlainTextEdit::keyPressEvent(QKeyEvent *e) break; case Qt::Key_Left: case Qt::Key_Right: - if (QApplication::keypadNavigationEnabled() + if (QApplicationPrivate::keypadNavigationEnabled() && QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) { // Same as for Key_Up and Key_Down. e->ignore(); @@ -1810,7 +1811,7 @@ void QPlainTextEdit::keyPressEvent(QKeyEvent *e) break; case Qt::Key_Back: if (!e->isAutoRepeat()) { - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { if (document()->isEmpty()) { setEditFocus(false); e->accept(); @@ -1836,7 +1837,7 @@ void QPlainTextEdit::keyReleaseEvent(QKeyEvent *e) { #ifdef QT_KEYPAD_NAVIGATION Q_D(QPlainTextEdit); - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { if (!e->isAutoRepeat() && e->key() == Qt::Key_Back && d->deleteAllTimer.isActive()) { d->deleteAllTimer.stop(); @@ -2080,7 +2081,7 @@ void QPlainTextEdit::mousePressEvent(QMouseEvent *e) { Q_D(QPlainTextEdit); #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) + if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) setEditFocus(true); #endif d->sendControlEvent(e); @@ -2212,7 +2213,7 @@ void QPlainTextEdit::inputMethodEvent(QInputMethodEvent *e) Q_D(QPlainTextEdit); #ifdef QT_KEYPAD_NAVIGATION if (d->control->textInteractionFlags() & Qt::TextEditable - && QApplication::keypadNavigationEnabled() + && QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) { setEditFocus(true); selectAll(); // so text is replaced rather than appended to diff --git a/src/widgets/widgets/qscrollarea.cpp b/src/widgets/widgets/qscrollarea.cpp index 9994344d79..68aa545082 100644 --- a/src/widgets/widgets/qscrollarea.cpp +++ b/src/widgets/widgets/qscrollarea.cpp @@ -46,6 +46,7 @@ #include "qapplication.h" #include "qvariant.h" #include "qdebug.h" +#include "private/qapplication_p.h" #include "private/qlayoutengine_p.h" QT_BEGIN_NAMESPACE @@ -300,7 +301,7 @@ bool QScrollArea::event(QEvent *e) d->updateScrollBars(); } #ifdef QT_KEYPAD_NAVIGATION - else if (QApplication::keypadNavigationEnabled()) { + else if (QApplicationPrivate::keypadNavigationEnabled()) { if (e->type() == QEvent::Show) QApplication::instance()->installEventFilter(this); else if (e->type() == QEvent::Hide) @@ -319,7 +320,7 @@ bool QScrollArea::eventFilter(QObject *o, QEvent *e) Q_D(QScrollArea); #ifdef QT_KEYPAD_NAVIGATION if (d->widget && o != d->widget && e->type() == QEvent::FocusIn - && QApplication::keypadNavigationEnabled()) { + && QApplicationPrivate::keypadNavigationEnabled()) { if (o->isWidgetType()) ensureWidgetVisible(static_cast<QWidget *>(o)); } diff --git a/src/widgets/widgets/qscrollbar.cpp b/src/widgets/widgets/qscrollbar.cpp index b4168268a0..08d771a27a 100644 --- a/src/widgets/widgets/qscrollbar.cpp +++ b/src/widgets/widgets/qscrollbar.cpp @@ -497,16 +497,14 @@ bool QScrollBar::event(QEvent *event) void QScrollBar::wheelEvent(QWheelEvent *event) { event->ignore(); - int delta = event->delta(); // scrollbar is a special case - in vertical mode it reaches minimum // value in the upper position, however QSlider's minimum value is on - // the bottom. So we need to invert a value, but since the scrollbar is - // inverted by default, we need to inverse the delta value for the + // the bottom. So we need to invert the value, but since the scrollbar is + // inverted by default, we need to invert the delta value only for the // horizontal orientation. - if (event->orientation() == Qt::Horizontal) - delta = -delta; + int delta = (orientation() == Qt::Horizontal ? -event->angleDelta().x() : event->angleDelta().y()); Q_D(QScrollBar); - if (d->scrollByDelta(event->orientation(), event->modifiers(), delta)) + if (d->scrollByDelta(orientation(), event->modifiers(), delta)) event->accept(); if (event->phase() == Qt::ScrollBegin) diff --git a/src/widgets/widgets/qslider.cpp b/src/widgets/widgets/qslider.cpp index 47d3b2fb81..161e4ba27a 100644 --- a/src/widgets/widgets/qslider.cpp +++ b/src/widgets/widgets/qslider.cpp @@ -46,6 +46,7 @@ #include "qpainter.h" #include "qstyle.h" #include "qstyleoption.h" +#include "private/qapplication_p.h" #include "private/qabstractslider_p.h" #include "qdebug.h" @@ -360,7 +361,7 @@ void QSlider::mousePressEvent(QMouseEvent *ev) return; } #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled()) + if (QApplicationPrivate::keypadNavigationEnabled()) setEditFocus(true); #endif ev->accept(); diff --git a/src/widgets/widgets/qsplitter.cpp b/src/widgets/widgets/qsplitter.cpp index 08533040a7..e7a4889996 100644 --- a/src/widgets/widgets/qsplitter.cpp +++ b/src/widgets/widgets/qsplitter.cpp @@ -771,14 +771,13 @@ void QSplitterPrivate::setGeo(QSplitterLayoutStruct *sls, int p, int s, bool all if (!sls->handle->isHidden()) { QSplitterHandle *h = sls->handle; QSize hs = h->sizeHint(); - int left, top, right, bottom; - h->getContentsMargins(&left, &top, &right, &bottom); + const QMargins m = h->contentsMargins(); if (orient==Qt::Horizontal) { if (q->isRightToLeft()) p = contents.width() - p + hs.width(); - h->setGeometry(p-hs.width() - left, contents.y(), hs.width() + left + right, contents.height()); + h->setGeometry(p-hs.width() - m.left(), contents.y(), hs.width() + m.left() + m.right(), contents.height()); } else { - h->setGeometry(contents.x(), p-hs.height() - top, contents.width(), hs.height() + top + bottom); + h->setGeometry(contents.x(), p-hs.height() - m.top(), contents.width(), hs.height() + m.top() + m.bottom()); } } } diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp index f6f56c12d1..18fda11ddf 100644 --- a/src/widgets/widgets/qtabbar.cpp +++ b/src/widgets/widgets/qtabbar.cpp @@ -65,6 +65,7 @@ #endif #include "qdebug.h" +#include "private/qapplication_p.h" #include "private/qtabbar_p.h" #if 0 // Used to be included in Qt4 for Q_WS_MAC @@ -415,7 +416,7 @@ void QTabBarPrivate::init() QObject::connect(rightB, SIGNAL(clicked()), q, SLOT(_q_scrollTabs())); rightB->hide(); #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { leftB->setFocusPolicy(Qt::NoFocus); rightB->setFocusPolicy(Qt::NoFocus); q->setFocusPolicy(Qt::NoFocus); @@ -2210,7 +2211,9 @@ void QTabBar::wheelEvent(QWheelEvent *event) { #ifndef Q_OS_MAC Q_D(QTabBar); - int offset = event->delta() > 0 ? -1 : 1; + int delta = (qAbs(event->angleDelta().x()) > qAbs(event->angleDelta().y()) ? + event->angleDelta().x() : event->angleDelta().y()); + int offset = delta > 0 ? -1 : 1; d->setCurrentNextEnabledIndex(offset); QWidget::wheelEvent(event); #else diff --git a/src/widgets/widgets/qtabwidget.cpp b/src/widgets/widgets/qtabwidget.cpp index 547b8a82f9..4d7b39ae01 100644 --- a/src/widgets/widgets/qtabwidget.cpp +++ b/src/widgets/widgets/qtabwidget.cpp @@ -39,6 +39,7 @@ #include "qtabwidget.h" +#include "private/qapplication_p.h" #include "private/qwidget_p.h" #include "private/qtabbar_p.h" #include "qapplication.h" @@ -241,7 +242,7 @@ void QTabWidgetPrivate::init() q->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding, QSizePolicy::TabWidget)); #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled()) + if (QApplicationPrivate::keypadNavigationEnabled()) q->setFocusPolicy(Qt::NoFocus); else #endif @@ -1108,14 +1109,14 @@ void QTabWidget::keyPressEvent(QKeyEvent *e) if (((e->key() == Qt::Key_Tab || e->key() == Qt::Key_Backtab) && count() > 1 && e->modifiers() & Qt::ControlModifier) #ifdef QT_KEYPAD_NAVIGATION - || QApplication::keypadNavigationEnabled() && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right) && count() > 1 + || QApplicationPrivate::keypadNavigationEnabled() && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right) && count() > 1 #endif ) { int pageCount = d->tabs->count(); int page = currentIndex(); int dx = (e->key() == Qt::Key_Backtab || e->modifiers() & Qt::ShiftModifier) ? -1 : 1; #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled() && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right)) + if (QApplicationPrivate::keypadNavigationEnabled() && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right)) dx = e->key() == (isRightToLeft() ? Qt::Key_Right : Qt::Key_Left) ? -1 : 1; #endif for (int pass = 0; pass < pageCount; ++pass) { diff --git a/src/widgets/widgets/qtextbrowser.cpp b/src/widgets/widgets/qtextbrowser.cpp index 7a77f86de2..3e49390315 100644 --- a/src/widgets/widgets/qtextbrowser.cpp +++ b/src/widgets/widgets/qtextbrowser.cpp @@ -42,6 +42,7 @@ #include <qstack.h> #include <qapplication.h> +#include <private/qapplication_p.h> #include <qevent.h> #include <qdesktopwidget.h> #include <qdebug.h> @@ -1016,7 +1017,7 @@ void QTextBrowser::keyPressEvent(QKeyEvent *ev) Q_D(QTextBrowser); switch (ev->key()) { case Qt::Key_Select: - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { if (!hasEditFocus()) { setEditFocus(true); return; @@ -1031,7 +1032,7 @@ void QTextBrowser::keyPressEvent(QKeyEvent *ev) } break; case Qt::Key_Back: - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { if (hasEditFocus()) { setEditFocus(false); ev->accept(); @@ -1041,7 +1042,7 @@ void QTextBrowser::keyPressEvent(QKeyEvent *ev) QTextEdit::keyPressEvent(ev); return; default: - if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { + if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) { ev->ignore(); return; } diff --git a/src/widgets/widgets/qtextedit.cpp b/src/widgets/widgets/qtextedit.cpp index 8599573e5a..bd9e5f8159 100644 --- a/src/widgets/widgets/qtextedit.cpp +++ b/src/widgets/widgets/qtextedit.cpp @@ -70,6 +70,7 @@ #include <qtextformat.h> #include <qdatetime.h> #include <qapplication.h> +#include <private/qapplication_p.h> #include <limits.h> #include <qtexttable.h> #include <qvariant.h> @@ -1116,7 +1117,7 @@ bool QTextEdit::event(QEvent *e) #endif // QT_NO_CONTEXTMENU #ifdef QT_KEYPAD_NAVIGATION if (e->type() == QEvent::EnterEditFocus || e->type() == QEvent::LeaveEditFocus) { - if (QApplication::keypadNavigationEnabled()) + if (QApplicationPrivate::keypadNavigationEnabled()) d->sendControlEvent(e); } #endif @@ -1301,7 +1302,7 @@ void QTextEdit::keyPressEvent(QKeyEvent *e) #ifdef QT_KEYPAD_NAVIGATION switch (e->key()) { case Qt::Key_Select: - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { // code assumes linksaccessible + editable isn't meaningful if (d->control->textInteractionFlags() & Qt::TextEditable) { setEditFocus(!hasEditFocus()); @@ -1322,14 +1323,14 @@ void QTextEdit::keyPressEvent(QKeyEvent *e) break; case Qt::Key_Back: case Qt::Key_No: - if (!QApplication::keypadNavigationEnabled() - || (QApplication::keypadNavigationEnabled() && !hasEditFocus())) { + if (!QApplicationPrivate::keypadNavigationEnabled() + || (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus())) { e->ignore(); return; } break; default: - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { if (!hasEditFocus() && !(e->modifiers() & Qt::ControlModifier)) { if (e->text()[0].isPrint()) setEditFocus(true); @@ -1418,7 +1419,7 @@ void QTextEdit::keyPressEvent(QKeyEvent *e) switch (e->key()) { case Qt::Key_Up: case Qt::Key_Down: - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { // Cursor position didn't change, so we want to leave // these keys to change focus. e->ignore(); @@ -1427,7 +1428,7 @@ void QTextEdit::keyPressEvent(QKeyEvent *e) break; case Qt::Key_Back: if (!e->isAutoRepeat()) { - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { if (document()->isEmpty() || !(d->control->textInteractionFlags() & Qt::TextEditable)) { setEditFocus(false); e->accept(); @@ -1453,7 +1454,7 @@ void QTextEdit::keyReleaseEvent(QKeyEvent *e) { #ifdef QT_KEYPAD_NAVIGATION Q_D(QTextEdit); - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { if (!e->isAutoRepeat() && e->key() == Qt::Key_Back && d->deleteAllTimer.isActive()) { d->deleteAllTimer.stop(); @@ -1665,7 +1666,7 @@ void QTextEdit::mousePressEvent(QMouseEvent *e) { Q_D(QTextEdit); #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) + if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) setEditFocus(true); #endif d->sendControlEvent(e); @@ -1796,7 +1797,7 @@ void QTextEdit::inputMethodEvent(QInputMethodEvent *e) Q_D(QTextEdit); #ifdef QT_KEYPAD_NAVIGATION if (d->control->textInteractionFlags() & Qt::TextEditable - && QApplication::keypadNavigationEnabled() + && QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) setEditFocus(true); #endif diff --git a/src/widgets/widgets/qtoolbar.cpp b/src/widgets/widgets/qtoolbar.cpp index fcaafbc581..d1a0f5ea78 100644 --- a/src/widgets/widgets/qtoolbar.cpp +++ b/src/widgets/widgets/qtoolbar.cpp @@ -53,7 +53,6 @@ #if QT_CONFIG(rubberband) #include <qrubberband.h> #endif -#include <qsignalmapper.h> #include <qstylepainter.h> #include <qstyleoption.h> #include <qtoolbutton.h> diff --git a/src/widgets/widgets/qwidgetlinecontrol.cpp b/src/widgets/widgets/qwidgetlinecontrol.cpp index 56dba1dd32..46bc29eed7 100644 --- a/src/widgets/widgets/qwidgetlinecontrol.cpp +++ b/src/widgets/widgets/qwidgetlinecontrol.cpp @@ -54,6 +54,7 @@ #endif #include "qapplication.h" +#include "private/qapplication_p.h" #if QT_CONFIG(graphicsview) #include "qgraphicssceneevent.h" #endif @@ -1662,7 +1663,7 @@ void QWidgetLineControl::processKeyEvent(QKeyEvent* event) case Qt::Key_F4: #ifdef QT_KEYPAD_NAVIGATION case Qt::Key_Select: - if (!QApplication::keypadNavigationEnabled()) + if (!QApplicationPrivate::keypadNavigationEnabled()) break; #endif if (!m_completer->currentCompletion().isEmpty() && hasSelectedText() @@ -1912,7 +1913,7 @@ void QWidgetLineControl::processKeyEvent(QKeyEvent* event) break; #ifdef QT_KEYPAD_NAVIGATION case Qt::Key_Back: - if (QApplication::keypadNavigationEnabled() && !event->isAutoRepeat() + if (QApplicationPrivate::keypadNavigationEnabled() && !event->isAutoRepeat() && !isReadOnly()) { if (text().length() == 0) { setText(m_cancelText); diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp index 70e1c148a1..fdbaf29dd8 100644 --- a/src/widgets/widgets/qwidgettextcontrol.cpp +++ b/src/widgets/widgets/qwidgettextcontrol.cpp @@ -55,6 +55,7 @@ #endif #include <qstyle.h> #include <qtimer.h> +#include "private/qapplication_p.h" #include "private/qtextdocumentlayout_p.h" #include "private/qabstracttextdocumentlayout_p.h" #include "qtextdocument.h" @@ -294,7 +295,7 @@ bool QWidgetTextControlPrivate::cursorMoveKeyEvent(QKeyEvent *e) bool isNavigationEvent = e->key() == Qt::Key_Up || e->key() == Qt::Key_Down; #ifdef QT_KEYPAD_NAVIGATION - ignoreNavigationEvents = ignoreNavigationEvents || QApplication::keypadNavigationEnabled(); + ignoreNavigationEvents = ignoreNavigationEvents || QApplicationPrivate::keypadNavigationEnabled(); isNavigationEvent = isNavigationEvent || (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right)); @@ -1159,7 +1160,7 @@ void QWidgetTextControl::processEvent(QEvent *e, const QMatrix &matrix, QWidget #ifdef QT_KEYPAD_NAVIGATION case QEvent::EnterEditFocus: case QEvent::LeaveEditFocus: - if (QApplication::keypadNavigationEnabled()) + if (QApplicationPrivate::keypadNavigationEnabled()) d->editFocusEvent(e); break; #endif @@ -2218,7 +2219,7 @@ void QWidgetTextControlPrivate::focusEvent(QFocusEvent *e) emit q->updateRequest(q->selectionRect()); if (e->gotFocus()) { #ifdef QT_KEYPAD_NAVIGATION - if (!QApplication::keypadNavigationEnabled() || (hasEditFocus && (e->reason() == Qt::PopupFocusReason))) { + if (!QApplicationPrivate::keypadNavigationEnabled() || (hasEditFocus && (e->reason() == Qt::PopupFocusReason))) { #endif cursorOn = (interactionFlags & (Qt::TextSelectableByKeyboard | Qt::TextEditable)); if (interactionFlags & Qt::TextEditable) { @@ -2259,7 +2260,7 @@ void QWidgetTextControlPrivate::editFocusEvent(QEvent *e) { Q_Q(QWidgetTextControl); - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { if (e->type() == QEvent::EnterEditFocus && interactionFlags & Qt::TextEditable) { const QTextCursor oldSelection = cursor; const int oldCursorPos = cursor.position(); @@ -3280,7 +3281,7 @@ QAbstractTextDocumentLayout::PaintContext QWidgetTextControl::getPaintContext(QW if (!d->dndFeedbackCursor.isNull()) ctx.cursorPosition = d->dndFeedbackCursor.position(); #ifdef QT_KEYPAD_NAVIGATION - if (!QApplication::keypadNavigationEnabled() || d->hasEditFocus) + if (!QApplicationPrivate::keypadNavigationEnabled() || d->hasEditFocus) #endif if (d->cursor.hasSelection()) { QAbstractTextDocumentLayout::Selection selection; |