diff --git a/autotests/kcombobox_unittest.cpp b/autotests/kcombobox_unittest.cpp --- a/autotests/kcombobox_unittest.cpp +++ b/autotests/kcombobox_unittest.cpp @@ -55,7 +55,11 @@ // KComboBox signals QSignalSpy comboReturnPressedSpy(&w, SIGNAL(returnPressed())); QSignalSpy comboReturnPressedStringSpy(&w, SIGNAL(returnPressed(QString))); +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) QSignalSpy comboActivatedSpy(&w, SIGNAL(activated(QString))); +#else + QSignalSpy comboActivatedSpy(&w, &QComboBox::textActivated); +#endif QTest::keyClick(&w, Qt::Key_Return); QCOMPARE(qReturnPressedSpy.count(), 1); QCOMPARE(kReturnPressedSpy.count(), 1); @@ -78,11 +82,17 @@ { KHistoryComboBox w; QVERIFY(qobject_cast(w.lineEdit())); - connect(&w, SIGNAL(activated(QString)), - &w, SLOT(addToHistory(QString))); QSignalSpy comboReturnPressedSpy(&w, SIGNAL(returnPressed())); QSignalSpy comboReturnPressedStringSpy(&w, SIGNAL(returnPressed(QString))); +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) + connect(&w, SIGNAL(activated(QString)), + &w, SLOT(addToHistory(QString))); QSignalSpy comboActivatedSpy(&w, SIGNAL(activated(QString))); +#else + connect(&w, &KHistoryComboBox::textActivated, + &w, &KHistoryComboBox::addToHistory); + QSignalSpy comboActivatedSpy(&w, &QComboBox::textActivated); +#endif QTest::keyClicks(&w, QStringLiteral("Hello world")); QTest::keyClick(&w, Qt::Key_Return); qApp->processEvents(); // QueuedConnection in KHistoryComboBox diff --git a/src/kcombobox.cpp b/src/kcombobox.cpp --- a/src/kcombobox.cpp +++ b/src/kcombobox.cpp @@ -56,10 +56,9 @@ void KComboBoxPrivate::init() { Q_Q(KComboBox); - q->QComboBox::setAutoCompletion(false); // otherwise setLineEdit will create a completer... if (q->isEditable()) { - q->setCompleter(nullptr); + q->setCompleter(nullptr); // remove the builtin completer, we have our own q->lineEdit()->setContextMenuPolicy(Qt::DefaultContextMenu); } } @@ -354,8 +353,15 @@ connect(d->klineEdit, &KLineEdit::aboutToShowContextMenu, this, &KComboBox::aboutToShowContextMenu); + // match the declaration of the deprecated signal +#if QT_DEPRECATED_SINCE(5, 15) || QT_VERSION < QT_VERSION_CHECK(5, 14, 0) connect(d->klineEdit, &KLineEdit::completionBoxActivated, this, QOverload::of(&QComboBox::activated)); +#endif +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + connect(d->klineEdit, &KLineEdit::completionBoxActivated, + this, QOverload::of(&QComboBox::textActivated)); +#endif d->klineEdit->setTrapReturnKey(d->trapReturnKey); } diff --git a/src/kcompletion.cpp b/src/kcompletion.cpp --- a/src/kcompletion.cpp +++ b/src/kcompletion.cpp @@ -639,7 +639,7 @@ } else if (m_compOrder == KCompletion::Sorted) { QCollator c; c.setCaseSensitivity(Qt::CaseSensitive); - qStableSort(m_stringList.begin(), m_stringList.end(), c); + std::stable_sort(m_stringList.begin(), m_stringList.end(), c); } return m_stringList; diff --git a/src/kcompletionbox.cpp b/src/kcompletionbox.cpp --- a/src/kcompletionbox.cpp +++ b/src/kcompletionbox.cpp @@ -25,8 +25,9 @@ #include #include -#include #include +#include +#include class KCompletionBoxPrivate { @@ -305,18 +306,21 @@ int x = currentPos.x(), y = currentPos.y(); if (d->m_parent) { if (!isVisible()) { - QPoint orig = globalPositionHint(); - QRect screenSize = QApplication::desktop()->screenGeometry(orig); + const QPoint orig = globalPositionHint(); + QScreen *screen = QGuiApplication::screenAt(orig); + if (screen) { + const QRect screenSize = screen->geometry(); - x = orig.x() + geom.x(); - y = orig.y() + geom.y(); + x = orig.x() + geom.x(); + y = orig.y() + geom.y(); - if (x + width() > screenSize.right()) { - x = screenSize.right() - width(); - } - if (y + height() > screenSize.bottom()) { - y = y - height() - d->m_parent->height(); - d->upwardBox = true; + if (x + width() > screenSize.right()) { + x = screenSize.right() - width(); + } + if (y + height() > screenSize.bottom()) { + y = y - height() - d->m_parent->height(); + d->upwardBox = true; + } } } else { // Are we above our parent? If so we must keep bottom edge anchored. diff --git a/src/khistorycombobox.cpp b/src/khistorycombobox.cpp --- a/src/khistorycombobox.cpp +++ b/src/khistorycombobox.cpp @@ -463,15 +463,25 @@ which is perhaps reasonable. Generate the signal ourselves if that's the case. */ if ((q->insertPolicy() == q->NoInsert && q->findText(text, Qt::MatchFixedString | Qt::MatchCaseSensitive) == -1)) { +#if QT_DEPRECATED_SINCE(5, 15) || QT_VERSION < QT_VERSION_CHECK(5, 14, 0) emit q->activated(text); +#endif +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + emit q->textActivated(text); +#endif } /* Qt also doesn't emit it if the box is full, and policy is not InsertAtCurrent */ else if (q->insertPolicy() != q->InsertAtCurrent && q->count() >= q->maxCount()) { +#if QT_DEPRECATED_SINCE(5, 15) || QT_VERSION < QT_VERSION_CHECK(5, 14, 0) emit q->activated(text); +#endif +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + emit q->textActivated(text); +#endif } } diff --git a/src/klineedit.cpp b/src/klineedit.cpp --- a/src/klineedit.cpp +++ b/src/klineedit.cpp @@ -385,7 +385,7 @@ const int fullLength = fullText.length(); const QFontMetrics fm(q->fontMetrics()); const int labelWidth = q->size().width() - 2 * q->style()->pixelMetric(QStyle::PM_DefaultFrameWidth) - 2; - const int textWidth = fm.width(fullText); + const int textWidth = fm.boundingRect(fullText).width(); // TODO: investigate use of QFontMetrics::elidedText for this if (textWidth > labelWidth) { @@ -395,20 +395,20 @@ const QString ellipsisText = QStringLiteral("..."); // start with the dots only QString squeezedText = ellipsisText; - int squeezedWidth = fm.width(squeezedText); + int squeezedWidth = fm.boundingRect(squeezedText).width(); // estimate how many letters we can add to the dots on both sides int letters = fullText.length() * (labelWidth - squeezedWidth) / textWidth / 2; squeezedText = fullText.leftRef(letters) + ellipsisText + fullText.rightRef(letters); - squeezedWidth = fm.width(squeezedText); + squeezedWidth = fm.boundingRect(squeezedText).width(); if (squeezedWidth < labelWidth) { // we estimated too short // add letters while text < label do { letters++; squeezedText = fullText.leftRef(letters) + ellipsisText + fullText.rightRef(letters); - squeezedWidth = fm.width(squeezedText); + squeezedWidth = fm.boundingRect(squeezedText).width(); } while (squeezedWidth < labelWidth && letters <= fullLength / 2); letters--; squeezedText = fullText.leftRef(letters) + ellipsisText + fullText.rightRef(letters); @@ -418,7 +418,7 @@ do { letters--; squeezedText = fullText.leftRef(letters) + ellipsisText + fullText.rightRef(letters); - squeezedWidth = fm.width(squeezedText); + squeezedWidth = fm.boundingRect(squeezedText).width(); } while (squeezedWidth > labelWidth && letters >= 5); } diff --git a/src/ksortablelist.h b/src/ksortablelist.h --- a/src/ksortablelist.h +++ b/src/ksortablelist.h @@ -24,6 +24,7 @@ #include #include +#include /** * \class KSortableItem ksortablelist.h @@ -196,7 +197,7 @@ */ void sort() { - qSort(*this); + std::sort(this->begin(), this->end()); } }; diff --git a/tests/kcompletionuitest.cpp b/tests/kcompletionuitest.cpp --- a/tests/kcompletionuitest.cpp +++ b/tests/kcompletionuitest.cpp @@ -10,15 +10,10 @@ #include #include -/* - * Constructs a Form1 which is a child of 'parent', with the - * widget flags set to 'f' - */ Form1::Form1(QWidget *parent) : QWidget(parent) { setAttribute(Qt::WA_DeleteOnClose); - setObjectName(QStringLiteral("Form1")); resize(559, 465); setWindowTitle(QStringLiteral("Form1")); Form1Layout = new QVBoxLayout(this); @@ -30,8 +25,6 @@ GroupBox1->layout()->setContentsMargins(0, 0, 0, 0); GroupBox1Layout = new QVBoxLayout; GroupBox1Layout->setAlignment(Qt::AlignTop); - GroupBox1Layout->setSpacing(6); - GroupBox1Layout->setMargin(11); GroupBox1->layout()->addItem(GroupBox1Layout); GroupBox1Layout->setParent(GroupBox1->layout());