diff options
Diffstat (limited to 'src/widgets/widgets')
-rw-r--r-- | src/widgets/widgets/qabstractscrollarea.cpp | 6 | ||||
-rw-r--r-- | src/widgets/widgets/qabstractspinbox.cpp | 70 | ||||
-rw-r--r-- | src/widgets/widgets/qabstractspinbox_p.h | 2 | ||||
-rw-r--r-- | src/widgets/widgets/qcombobox.cpp | 10 | ||||
-rw-r--r-- | src/widgets/widgets/qdatetimeedit.cpp | 32 | ||||
-rw-r--r-- | src/widgets/widgets/qdatetimeedit.h | 3 | ||||
-rw-r--r-- | src/widgets/widgets/qdialogbuttonbox.cpp | 2 | ||||
-rw-r--r-- | src/widgets/widgets/qdockwidget.cpp | 4 | ||||
-rw-r--r-- | src/widgets/widgets/qlabel.cpp | 78 | ||||
-rw-r--r-- | src/widgets/widgets/qlabel.h | 20 | ||||
-rw-r--r-- | src/widgets/widgets/qmdiarea.cpp | 4 | ||||
-rw-r--r-- | src/widgets/widgets/qmenu.cpp | 188 | ||||
-rw-r--r-- | src/widgets/widgets/qmenu_p.h | 6 | ||||
-rw-r--r-- | src/widgets/widgets/qplaintextedit.cpp | 20 | ||||
-rw-r--r-- | src/widgets/widgets/qspinbox.cpp | 4 | ||||
-rw-r--r-- | src/widgets/widgets/qtabbar.cpp | 2 | ||||
-rw-r--r-- | src/widgets/widgets/qtabwidget.cpp | 2 | ||||
-rw-r--r-- | src/widgets/widgets/qtextbrowser.cpp | 41 | ||||
-rw-r--r-- | src/widgets/widgets/qtextbrowser.h | 3 | ||||
-rw-r--r-- | src/widgets/widgets/qtextedit.cpp | 24 | ||||
-rw-r--r-- | src/widgets/widgets/qtoolbutton.cpp | 67 |
21 files changed, 361 insertions, 227 deletions
diff --git a/src/widgets/widgets/qabstractscrollarea.cpp b/src/widgets/widgets/qabstractscrollarea.cpp index 320b3bf7ef..257cffda62 100644 --- a/src/widgets/widgets/qabstractscrollarea.cpp +++ b/src/widgets/widgets/qabstractscrollarea.cpp @@ -512,8 +512,8 @@ QAbstractScrollArea::~QAbstractScrollArea() Sets the viewport to be the given \a widget. The QAbstractScrollArea will take ownership of the given \a widget. - If \a widget is 0, QAbstractScrollArea will assign a new QWidget instance - for the viewport. + If \a widget is \nullptr, QAbstractScrollArea will assign a new QWidget + instance for the viewport. \sa viewport() */ @@ -720,7 +720,7 @@ QWidget *QAbstractScrollArea::cornerWidget() const You will probably also want to set at least one of the scroll bar modes to \c AlwaysOn. - Passing 0 shows no widget in the corner. + Passing \nullptr shows no widget in the corner. Any previous corner widget is hidden. diff --git a/src/widgets/widgets/qabstractspinbox.cpp b/src/widgets/widgets/qabstractspinbox.cpp index 6a0d2f5019..04176ab5e2 100644 --- a/src/widgets/widgets/qabstractspinbox.cpp +++ b/src/widgets/widgets/qabstractspinbox.cpp @@ -570,7 +570,7 @@ void QAbstractSpinBox::clear() QAbstractSpinBox::StepEnabled QAbstractSpinBox::stepEnabled() const { Q_D(const QAbstractSpinBox); - if (d->readOnly || d->type == QVariant::Invalid) + if (d->readOnly || d->type == QMetaType::UnknownType) return StepNone; if (d->wrapping) return StepEnabled(StepUpEnabled | StepDownEnabled); @@ -723,7 +723,7 @@ void QAbstractSpinBox::setLineEdit(QLineEdit *lineEdit) d->edit->setFocusProxy(this); d->edit->setAcceptDrops(false); - if (d->type != QVariant::Invalid) { + if (d->type != QMetaType::UnknownType) { connect(d->edit, SIGNAL(textChanged(QString)), this, SLOT(_q_editorTextChanged(QString))); connect(d->edit, SIGNAL(cursorPositionChanged(int,int)), @@ -1421,7 +1421,7 @@ void QAbstractSpinBox::mouseReleaseEvent(QMouseEvent *event) */ QAbstractSpinBoxPrivate::QAbstractSpinBoxPrivate() - : edit(nullptr), type(QVariant::Invalid), spinClickTimerId(-1), + : edit(nullptr), type(QMetaType::UnknownType), spinClickTimerId(-1), spinClickTimerInterval(100), spinClickThresholdTimerId(-1), spinClickThresholdTimerInterval(-1), effectiveSpinRepeatRate(1), buttonState(None), cachedText(QLatin1String("\x01")), cachedState(QValidator::Invalid), pendingEmit(false), readOnly(false), wrapping(false), @@ -1805,7 +1805,7 @@ void QAbstractSpinBoxPrivate::setValue(const QVariant &val, EmitPolicy ep, void QAbstractSpinBoxPrivate::updateEdit() { Q_Q(QAbstractSpinBox); - if (type == QVariant::Invalid) + if (type == QMetaType::UnknownType) return; const QString newText = specialValue() ? specialValueText : prefix + textFromValue(value) + suffix; if (newText == edit->displayText() || cleared) @@ -1865,8 +1865,8 @@ QVariant QAbstractSpinBoxPrivate::getZeroVariant() const { QVariant ret; switch (type) { - case QVariant::Int: ret = QVariant((int)0); break; - case QVariant::Double: ret = QVariant((double)0.0); break; + case QMetaType::Int: ret = QVariant(0); break; + case QMetaType::Double: ret = QVariant(0.0); break; default: break; } return ret; @@ -1913,7 +1913,7 @@ QVariant QAbstractSpinBoxPrivate::valueFromText(const QString &) const void QAbstractSpinBoxPrivate::interpret(EmitPolicy ep) { Q_Q(QAbstractSpinBox); - if (type == QVariant::Invalid || cleared) + if (type == QMetaType::UnknownType || cleared) return; QVariant v = getZeroVariant(); @@ -2013,11 +2013,11 @@ void QSpinBoxValidator::fixup(QString &input) const QVariant operator+(const QVariant &arg1, const QVariant &arg2) { QVariant ret; - if (Q_UNLIKELY(arg1.type() != arg2.type())) + if (Q_UNLIKELY(arg1.userType() != arg2.userType())) qWarning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)", arg1.typeName(), arg2.typeName(), __FILE__, __LINE__); - switch (arg1.type()) { - case QVariant::Int: { + switch (arg1.userType()) { + case QMetaType::Int: { const int int1 = arg1.toInt(); const int int2 = arg2.toInt(); if (int1 > 0 && (int2 >= INT_MAX - int1)) { @@ -2031,9 +2031,9 @@ QVariant operator+(const QVariant &arg1, const QVariant &arg2) } break; } - case QVariant::Double: ret = QVariant(arg1.toDouble() + arg2.toDouble()); break; + case QMetaType::Double: ret = QVariant(arg1.toDouble() + arg2.toDouble()); break; #if QT_CONFIG(datetimeparser) - case QVariant::DateTime: { + case QMetaType::QDateTime: { QDateTime a2 = arg2.toDateTime(); QDateTime a1 = arg1.toDateTime().addDays(QDATETIMEEDIT_DATE_MIN.daysTo(a2.date())); a1.setTime(a1.time().addMSecs(a2.time().msecsSinceStartOfDay())); @@ -2055,13 +2055,13 @@ QVariant operator+(const QVariant &arg1, const QVariant &arg2) QVariant operator-(const QVariant &arg1, const QVariant &arg2) { QVariant ret; - if (Q_UNLIKELY(arg1.type() != arg2.type())) + if (Q_UNLIKELY(arg1.userType() != arg2.userType())) qWarning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)", arg1.typeName(), arg2.typeName(), __FILE__, __LINE__); - switch (arg1.type()) { - case QVariant::Int: ret = QVariant(arg1.toInt() - arg2.toInt()); break; - case QVariant::Double: ret = QVariant(arg1.toDouble() - arg2.toDouble()); break; - case QVariant::DateTime: { + switch (arg1.userType()) { + case QMetaType::Int: ret = QVariant(arg1.toInt() - arg2.toInt()); break; + case QMetaType::Double: ret = QVariant(arg1.toDouble() - arg2.toDouble()); break; + case QMetaType::QDateTime: { QDateTime a1 = arg1.toDateTime(); QDateTime a2 = arg2.toDateTime(); int days = a2.daysTo(a1); @@ -2090,13 +2090,13 @@ QVariant operator*(const QVariant &arg1, double multiplier) { QVariant ret; - switch (arg1.type()) { - case QVariant::Int: + switch (arg1.userType()) { + case QMetaType::Int: ret = static_cast<int>(qBound<double>(INT_MIN, arg1.toInt() * multiplier, INT_MAX)); break; - case QVariant::Double: ret = QVariant(arg1.toDouble() * multiplier); break; + case QMetaType::Double: ret = QVariant(arg1.toDouble() * multiplier); break; #if QT_CONFIG(datetimeparser) - case QVariant::DateTime: { + case QMetaType::QDateTime: { double days = QDATETIMEEDIT_DATE_MIN.daysTo(arg1.toDateTime().date()) * multiplier; const qint64 daysInt = qint64(days); days -= daysInt; @@ -2119,17 +2119,17 @@ double operator/(const QVariant &arg1, const QVariant &arg2) double a1 = 0; double a2 = 0; - switch (arg1.type()) { - case QVariant::Int: + switch (arg1.userType()) { + case QMetaType::Int: a1 = (double)arg1.toInt(); a2 = (double)arg2.toInt(); break; - case QVariant::Double: + case QMetaType::Double: a1 = arg1.toDouble(); a2 = arg2.toDouble(); break; #if QT_CONFIG(datetimeparser) - case QVariant::DateTime: + case QMetaType::QDateTime: a1 = QDATETIMEEDIT_DATE_MIN.daysTo(arg1.toDate()); a2 = QDATETIMEEDIT_DATE_MIN.daysTo(arg2.toDate()); a1 += arg1.toDateTime().time().msecsSinceStartOfDay() / (36e5 * 24); @@ -2144,9 +2144,9 @@ double operator/(const QVariant &arg1, const QVariant &arg2) int QAbstractSpinBoxPrivate::variantCompare(const QVariant &arg1, const QVariant &arg2) { - switch (arg2.type()) { - case QVariant::Date: - Q_ASSERT_X(arg1.type() == QVariant::Date, "QAbstractSpinBoxPrivate::variantCompare", + switch (arg2.userType()) { + case QMetaType::QDate: + Q_ASSERT_X(arg1.userType() == QMetaType::QDate, "QAbstractSpinBoxPrivate::variantCompare", qPrintable(QString::fromLatin1("Internal error 1 (%1)"). arg(QString::fromLatin1(arg1.typeName())))); if (arg1.toDate() == arg2.toDate()) { @@ -2156,8 +2156,8 @@ int QAbstractSpinBoxPrivate::variantCompare(const QVariant &arg1, const QVariant } else { return 1; } - case QVariant::Time: - Q_ASSERT_X(arg1.type() == QVariant::Time, "QAbstractSpinBoxPrivate::variantCompare", + case QMetaType::QTime: + Q_ASSERT_X(arg1.userType() == QMetaType::QTime, "QAbstractSpinBoxPrivate::variantCompare", qPrintable(QString::fromLatin1("Internal error 2 (%1)"). arg(QString::fromLatin1(arg1.typeName())))); if (arg1.toTime() == arg2.toTime()) { @@ -2169,7 +2169,7 @@ int QAbstractSpinBoxPrivate::variantCompare(const QVariant &arg1, const QVariant } - case QVariant::DateTime: + case QMetaType::QDateTime: if (arg1.toDateTime() == arg2.toDateTime()) { return 0; } else if (arg1.toDateTime() < arg2.toDateTime()) { @@ -2177,7 +2177,7 @@ int QAbstractSpinBoxPrivate::variantCompare(const QVariant &arg1, const QVariant } else { return 1; } - case QVariant::Int: + case QMetaType::Int: if (arg1.toInt() == arg2.toInt()) { return 0; } else if (arg1.toInt() < arg2.toInt()) { @@ -2185,7 +2185,7 @@ int QAbstractSpinBoxPrivate::variantCompare(const QVariant &arg1, const QVariant } else { return 1; } - case QVariant::Double: + case QMetaType::Double: if (arg1.toDouble() == arg2.toDouble()) { return 0; } else if (arg1.toDouble() < arg2.toDouble()) { @@ -2193,8 +2193,8 @@ int QAbstractSpinBoxPrivate::variantCompare(const QVariant &arg1, const QVariant } else { return 1; } - case QVariant::Invalid: - if (arg2.type() == QVariant::Invalid) + case QMetaType::UnknownType: + if (arg2.userType() == QMetaType::UnknownType) return 0; Q_FALLTHROUGH(); default: diff --git a/src/widgets/widgets/qabstractspinbox_p.h b/src/widgets/widgets/qabstractspinbox_p.h index ad169fde19..63b19c7317 100644 --- a/src/widgets/widgets/qabstractspinbox_p.h +++ b/src/widgets/widgets/qabstractspinbox_p.h @@ -127,7 +127,7 @@ public: QLineEdit *edit; QString prefix, suffix, specialValueText; QVariant value, minimum, maximum, singleStep; - QVariant::Type type; + QMetaType::Type type; int spinClickTimerId, spinClickTimerInterval, spinClickThresholdTimerId, spinClickThresholdTimerInterval; int effectiveSpinRepeatRate; uint buttonState; diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 785de35090..53a711adc4 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -144,11 +144,11 @@ QStyleOptionMenuItem QComboMenuDelegate::getStyleOption(const QStyleOptionViewIt menuOption.menuItemType = QStyleOptionMenuItem::Normal; QVariant variant = index.model()->data(index, Qt::DecorationRole); - switch (variant.type()) { - case QVariant::Icon: + switch (variant.userType()) { + case QMetaType::QIcon: menuOption.icon = qvariant_cast<QIcon>(variant); break; - case QVariant::Color: { + case QMetaType::QColor: { static QPixmap pixmap(option.decorationSize); pixmap.fill(qvariant_cast<QColor>(variant)); menuOption.icon = pixmap; @@ -1888,7 +1888,7 @@ void QComboBoxPrivate::updateDelegate(bool force) QIcon QComboBoxPrivate::itemIcon(const QModelIndex &index) const { QVariant decoration = model->data(index, Qt::DecorationRole); - if (decoration.type() == QVariant::Pixmap) + if (decoration.userType() == QMetaType::QPixmap) return QIcon(qvariant_cast<QPixmap>(decoration)); else return qvariant_cast<QIcon>(decoration); @@ -2044,7 +2044,7 @@ const QValidator *QComboBox::validator() const \since 4.2 Sets the \a completer to use instead of the current completer. - If \a completer is 0, auto completion is disabled. + If \a completer is \nullptr, auto completion is disabled. By default, for an editable combo box, a QCompleter that performs case insensitive inline completion is automatically created. diff --git a/src/widgets/widgets/qdatetimeedit.cpp b/src/widgets/widgets/qdatetimeedit.cpp index e4abb89636..4880b5ee46 100644 --- a/src/widgets/widgets/qdatetimeedit.cpp +++ b/src/widgets/widgets/qdatetimeedit.cpp @@ -198,11 +198,19 @@ QDateTimeEdit::QDateTimeEdit(const QTime &time, QWidget *parent) d->init(time.isValid() ? time : QDATETIMEEDIT_TIME_MIN); } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) /*! \internal */ - QDateTimeEdit::QDateTimeEdit(const QVariant &var, QVariant::Type parserType, QWidget *parent) + : QDateTimeEdit(var, QMetaType::Type(parserType), parent) +{ } +/*! + \internal +*/ +#endif + +QDateTimeEdit::QDateTimeEdit(const QVariant &var, QMetaType::Type parserType, QWidget *parent) : QAbstractSpinBox(*new QDateTimeEditPrivate, parent) { Q_D(QDateTimeEdit); @@ -1570,7 +1578,7 @@ void QDateTimeEdit::mousePressEvent(QMouseEvent *event) QTimeEdit::QTimeEdit(QWidget *parent) - : QDateTimeEdit(QDATETIMEEDIT_TIME_MIN, QVariant::Time, parent) + : QDateTimeEdit(QDATETIMEEDIT_TIME_MIN, QMetaType::QTime, parent) { connect(this, &QTimeEdit::timeChanged, this, &QTimeEdit::userTimeChanged); } @@ -1581,7 +1589,7 @@ QTimeEdit::QTimeEdit(QWidget *parent) */ QTimeEdit::QTimeEdit(const QTime &time, QWidget *parent) - : QDateTimeEdit(time, QVariant::Time, parent) + : QDateTimeEdit(time, QMetaType::QTime, parent) { connect(this, &QTimeEdit::timeChanged, this, &QTimeEdit::userTimeChanged); } @@ -1640,7 +1648,7 @@ QTimeEdit::~QTimeEdit() */ QDateEdit::QDateEdit(QWidget *parent) - : QDateTimeEdit(QDATETIMEEDIT_DATE_INITIAL, QVariant::Date, parent) + : QDateTimeEdit(QDATETIMEEDIT_DATE_INITIAL, QMetaType::QDate, parent) { connect(this, &QDateEdit::dateChanged, this, &QDateEdit::userDateChanged); } @@ -1651,7 +1659,7 @@ QDateEdit::QDateEdit(QWidget *parent) */ QDateEdit::QDateEdit(const QDate &date, QWidget *parent) - : QDateTimeEdit(date, QVariant::Date, parent) + : QDateTimeEdit(date, QMetaType::QDate, parent) { connect(this, &QDateEdit::dateChanged, this, &QDateEdit::userDateChanged); } @@ -1688,13 +1696,13 @@ QDateEdit::~QDateEdit() QDateTimeEditPrivate::QDateTimeEditPrivate() - : QDateTimeParser(QVariant::DateTime, QDateTimeParser::DateTimeEdit, QCalendar()) + : QDateTimeParser(QMetaType::QDateTime, QDateTimeParser::DateTimeEdit, QCalendar()) { hasHadFocus = false; formatExplicitlySet = false; cacheGuard = false; fixday = true; - type = QVariant::DateTime; + type = QMetaType::QDateTime; sections = { }; cachedDay = -1; currentSectionIndex = FirstSectionIndex; @@ -2428,22 +2436,22 @@ void QDateTimeEdit::initStyleOption(QStyleOptionSpinBox *option) const void QDateTimeEditPrivate::init(const QVariant &var) { Q_Q(QDateTimeEdit); - switch (var.type()) { - case QVariant::Date: + switch (var.userType()) { + case QMetaType::QDate: value = var.toDate().startOfDay(); updateTimeSpec(); q->setDisplayFormat(defaultDateFormat); if (sectionNodes.isEmpty()) // ### safeguard for broken locale q->setDisplayFormat(QLatin1String("dd/MM/yyyy")); break; - case QVariant::DateTime: + case QMetaType::QDateTime: value = var; updateTimeSpec(); q->setDisplayFormat(defaultDateTimeFormat); if (sectionNodes.isEmpty()) // ### safeguard for broken locale q->setDisplayFormat(QLatin1String("dd/MM/yyyy hh:mm:ss")); break; - case QVariant::Time: + case QMetaType::QTime: value = QDateTime(QDATETIMEEDIT_DATE_INITIAL, var.toTime()); updateTimeSpec(); q->setDisplayFormat(defaultTimeFormat); @@ -2522,7 +2530,7 @@ void QDateTimeEditPrivate::updateEditFieldGeometry() QVariant QDateTimeEditPrivate::getZeroVariant() const { - Q_ASSERT(type == QVariant::DateTime); + Q_ASSERT(type == QMetaType::QDateTime); return QDateTime(QDATETIMEEDIT_DATE_INITIAL, QTime(), spec); } diff --git a/src/widgets/widgets/qdatetimeedit.h b/src/widgets/widgets/qdatetimeedit.h index 03994675ae..8905ad4a9c 100644 --- a/src/widgets/widgets/qdatetimeedit.h +++ b/src/widgets/widgets/qdatetimeedit.h @@ -195,7 +195,10 @@ protected: void paintEvent(QPaintEvent *event) override; void initStyleOption(QStyleOptionSpinBox *option) const; +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QDateTimeEdit(const QVariant &val, QVariant::Type parserType, QWidget *parent = nullptr); +#endif + QDateTimeEdit(const QVariant &val, QMetaType::Type parserType, QWidget *parent = nullptr); private: Q_DECLARE_PRIVATE(QDateTimeEdit) Q_DISABLE_COPY(QDateTimeEdit) diff --git a/src/widgets/widgets/qdialogbuttonbox.cpp b/src/widgets/widgets/qdialogbuttonbox.cpp index 2e12320bc3..28c4f59d0d 100644 --- a/src/widgets/widgets/qdialogbuttonbox.cpp +++ b/src/widgets/widgets/qdialogbuttonbox.cpp @@ -699,7 +699,7 @@ QList<QAbstractButton *> QDialogButtonBox::buttons() const /*! Returns the button role for the specified \a button. This function returns - \l InvalidRole if \a button is 0 or has not been added to the button box. + \l InvalidRole if \a button is \nullptr or has not been added to the button box. \sa buttons(), addButton() */ diff --git a/src/widgets/widgets/qdockwidget.cpp b/src/widgets/widgets/qdockwidget.cpp index 299e5da8d3..1d358c493e 100644 --- a/src/widgets/widgets/qdockwidget.cpp +++ b/src/widgets/widgets/qdockwidget.cpp @@ -1674,8 +1674,8 @@ QAction * QDockWidget::toggleViewAction() const \since 4.3 Sets an arbitrary \a widget as the dock widget's title bar. If \a widget - is 0, any custom title bar widget previously set on the dock widget is - removed, but not deleted, and the default title bar will be used + is \nullptr, any custom title bar widget previously set on the dock widget + is removed, but not deleted, and the default title bar will be used instead. If a title bar widget is set, QDockWidget will not use native window diff --git a/src/widgets/widgets/qlabel.cpp b/src/widgets/widgets/qlabel.cpp index 7bd7283adf..147ab9b855 100644 --- a/src/widgets/widgets/qlabel.cpp +++ b/src/widgets/widgets/qlabel.cpp @@ -187,8 +187,13 @@ QLabelPrivate::~QLabelPrivate() */ #ifndef QT_NO_PICTURE +#if QT_DEPRECATED_SINCE(5, 15) /*! - Returns the label's picture or nullptr if the label doesn't have a + \deprecated + + New code should use the other overload which returns QPicture by-value. + + This function returns the label's picture or \c nullptr if the label doesn't have a picture. */ @@ -197,6 +202,37 @@ const QPicture *QLabel::picture() const Q_D(const QLabel); return d->picture; } +#endif // QT_DEPRECATED_SINCE(5, 15) + +/*! + \since 5.15 + Returns the label's picture. + + Previously, Qt provided a version of \c picture() which returned the picture + by-pointer. That version is now deprecated. To maintain compatibility + with old code, you can explicitly differentiate between the by-pointer + function and the by-value function: + + \code + const QPicture *picPtr = label->picture(); + QPicture picVal = label->picture(Qt::ReturnByValue); + \endcode + + If you disable the deprecated version using the QT_DISABLE_DEPRECATED_BEFORE + macro, then you can omit \c Qt::ReturnByValue as shown below: + + \code + QPicture picVal = label->picture(); + \endcode +*/ + +QPicture QLabel::picture(Qt::ReturnByValue_t) const +{ + Q_D(const QLabel); + if (d->picture) + return *(d->picture); + return QPicture(); +} #endif @@ -351,9 +387,27 @@ void QLabel::clear() /*! \property QLabel::pixmap - \brief the label's pixmap + \brief the label's pixmap. - If no pixmap has been set this will return nullptr. + Previously, Qt provided a version of \c pixmap() which returned the pixmap + by-pointer. That version is now deprecated. To maintain compatibility + with old code, you can explicitly differentiate between the by-pointer + function and the by-value function: + + \code + const QPixmap *pixmapPtr = label->pixmap(); + QPixmap pixmapVal = label->pixmap(Qt::ReturnByValue); + \endcode + + If you disable the deprecated version using the QT_DISABLE_DEPRECATED_BEFORE + macro, then you can omit \c Qt::ReturnByValue as shown below: + + \code + QPixmap pixmapVal = label->pixmap(); + \endcode + + If no pixmap has been set, the deprecated getter function will return + \c nullptr. Setting the pixmap clears any previous content. The buddy shortcut, if any, is disabled. @@ -372,11 +426,29 @@ void QLabel::setPixmap(const QPixmap &pixmap) d->updateLabel(); } +#if QT_DEPRECATED_SINCE(5, 15) +/*! + \deprecated + + New code should use the other overload which returns QPixmap by-value. +*/ const QPixmap *QLabel::pixmap() const { Q_D(const QLabel); return d->pixmap; } +#endif // QT_DEPRECATED_SINCE(5, 15) + +/*! + \since 5.15 +*/ +QPixmap QLabel::pixmap(Qt::ReturnByValue_t) const +{ + Q_D(const QLabel); + if (d->pixmap) + return *(d->pixmap); + return QPixmap(); +} #ifndef QT_NO_PICTURE /*! diff --git a/src/widgets/widgets/qlabel.h b/src/widgets/widgets/qlabel.h index 2f5db5a7d3..288022a71e 100644 --- a/src/widgets/widgets/qlabel.h +++ b/src/widgets/widgets/qlabel.h @@ -72,9 +72,25 @@ public: ~QLabel(); QString text() const; - const QPixmap *pixmap() const; + +#if QT_DEPRECATED_SINCE(5,15) + QT_DEPRECATED_VERSION_X(5, 15, "Use the other overload which returns QPixmap by-value") + const QPixmap *pixmap() const; // ### Qt 7: Remove function + + QPixmap pixmap(Qt::ReturnByValue_t) const; +#else + QPixmap pixmap(Qt::ReturnByValue_t = Qt::ReturnByValue) const; // ### Qt 7: Remove arg +#endif // QT_DEPRECATED_SINCE(5,15) + #ifndef QT_NO_PICTURE - const QPicture *picture() const; +# if QT_DEPRECATED_SINCE(5,15) + QT_DEPRECATED_VERSION_X(5, 15, "Use the other overload which returns QPicture by-value") + const QPicture *picture() const; // ### Qt 7: Remove function + + QPicture picture(Qt::ReturnByValue_t) const; +# else + QPicture picture(Qt::ReturnByValue_t = Qt::ReturnByValue) const; // ### Qt 7: Remove arg +# endif // QT_DEPRECATED_SINCE(5,15) #endif #if QT_CONFIG(movie) QMovie *movie() const; diff --git a/src/widgets/widgets/qmdiarea.cpp b/src/widgets/widgets/qmdiarea.cpp index 3272ac440b..da6eb47372 100644 --- a/src/widgets/widgets/qmdiarea.cpp +++ b/src/widgets/widgets/qmdiarea.cpp @@ -103,8 +103,8 @@ \fn void QMdiArea::subWindowActivated(QMdiSubWindow *window) QMdiArea emits this signal after \a window has been activated. When \a - window is 0, QMdiArea has just deactivated its last active window, and - there are no active windows on the workspace. + window is \nullptr, QMdiArea has just deactivated its last active window, + and there are no active windows on the workspace. \sa QMdiArea::activeSubWindow() */ diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index fc7e2dbbcb..daa50aa8ee 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -2326,76 +2326,86 @@ QSize QMenu::sizeHint() const void QMenu::popup(const QPoint &p, QAction *atAction) { Q_D(QMenu); - if (d->scroll) { // reset scroll state from last popup - if (d->scroll->scrollOffset) - d->itemsDirty = 1; // sizeHint will be incorrect if there is previous scroll - d->scroll->scrollOffset = 0; - d->scroll->scrollFlags = QMenuPrivate::QMenuScroller::ScrollNone; + d->popup(p, atAction); +} + +void QMenuPrivate::popup(const QPoint &p, QAction *atAction, PositionFunction positionFunction) +{ + Q_Q(QMenu); + if (scroll) { // reset scroll state from last popup + if (scroll->scrollOffset) + itemsDirty = 1; // sizeHint will be incorrect if there is previous scroll + scroll->scrollOffset = 0; + scroll->scrollFlags = QMenuPrivate::QMenuScroller::ScrollNone; } - d->tearoffHighlighted = 0; - d->motions = 0; - d->doChildEffects = true; - d->updateLayoutDirection(); + tearoffHighlighted = 0; + motions = 0; + doChildEffects = true; + updateLayoutDirection(); // Ensure that we get correct sizeHints by placing this window on the correct screen. // However if the QMenu was constructed with a QDesktopScreenWidget as its parent, // then initialScreenIndex was set, so we should respect that for the lifetime of this menu. // Use d->popupScreen to remember, because initialScreenIndex will be reset after the first showing. // However if eventLoop exists, then exec() already did this by calling createWinId(); so leave it alone. (QTBUG-76162) - if (!d->eventLoop) { - const int screenIndex = d->topData()->initialScreenIndex; + if (!eventLoop) { + const int screenIndex = topData()->initialScreenIndex; if (screenIndex >= 0) - d->popupScreen = screenIndex; - if (auto s = QGuiApplication::screens().value(d->popupScreen)) { - if (d->setScreen(s)) - d->itemsDirty = true; - } else if (d->setScreenForPoint(p)) { - d->itemsDirty = true; + popupScreen = screenIndex; + if (auto s = QGuiApplication::screens().value(popupScreen)) { + if (setScreen(s)) + itemsDirty = true; + } else if (setScreenForPoint(p)) { + itemsDirty = true; } } - const bool contextMenu = d->isContextMenu(); - if (d->lastContextMenu != contextMenu) { - d->itemsDirty = true; - d->lastContextMenu = contextMenu; + const bool contextMenu = isContextMenu(); + if (lastContextMenu != contextMenu) { + itemsDirty = true; + lastContextMenu = contextMenu; } #if QT_CONFIG(menubar) // if this menu is part of a chain attached to a QMenuBar, set the // _NET_WM_WINDOW_TYPE_DROPDOWN_MENU X11 window type - setAttribute(Qt::WA_X11NetWmWindowTypeDropDownMenu, qobject_cast<QMenuBar *>(d->topCausedWidget()) != 0); + q->setAttribute(Qt::WA_X11NetWmWindowTypeDropDownMenu, qobject_cast<QMenuBar *>(topCausedWidget()) != nullptr); #endif - ensurePolished(); // Get the right font - emit aboutToShow(); - const bool actionListChanged = d->itemsDirty; + q->ensurePolished(); // Get the right font + emit q->aboutToShow(); + const bool actionListChanged = itemsDirty; QRect screen; #if QT_CONFIG(graphicsview) - bool isEmbedded = !bypassGraphicsProxyWidget(this) && QMenuPrivate::nearestGraphicsProxyWidget(this); + bool isEmbedded = !bypassGraphicsProxyWidget(q) && QMenuPrivate::nearestGraphicsProxyWidget(q); if (isEmbedded) - screen = d->popupGeometry(); + screen = popupGeometry(); else #endif - screen = d->popupGeometry(QDesktopWidgetPrivate::screenNumber(p)); - d->updateActionRects(screen); + screen = popupGeometry(QDesktopWidgetPrivate::screenNumber(p)); + updateActionRects(screen); QPoint pos; - QPushButton *causedButton = qobject_cast<QPushButton*>(d->causedPopup.widget); + QPushButton *causedButton = qobject_cast<QPushButton*>(causedPopup.widget); if (actionListChanged && causedButton) pos = QPushButtonPrivate::get(causedButton)->adjustedMenuPosition(); else pos = p; - const QSize menuSizeHint(sizeHint()); + const QSize menuSizeHint(q->sizeHint()); QSize size = menuSizeHint; - const int desktopFrame = style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, nullptr, this); - bool adjustToDesktop = !window()->testAttribute(Qt::WA_DontShowOnScreen); + + if (positionFunction) + pos = positionFunction(menuSizeHint); + + const int desktopFrame = q->style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, nullptr, q); + bool adjustToDesktop = !q->window()->testAttribute(Qt::WA_DontShowOnScreen); // if the screens have very different geometries and the menu is too big, we have to recalculate if ((size.height() > screen.height() || size.width() > screen.width()) || // Layout is not right, we might be able to save horizontal space - (d->ncols >1 && size.height() < screen.height())) { + (ncols >1 && size.height() < screen.height())) { size.setWidth(qMin(menuSizeHint.width(), screen.width() - desktopFrame * 2)); size.setHeight(qMin(menuSizeHint.height(), screen.height() - desktopFrame * 2)); adjustToDesktop = true; @@ -2404,61 +2414,61 @@ void QMenu::popup(const QPoint &p, QAction *atAction) #ifdef QT_KEYPAD_NAVIGATION if (!atAction && QApplicationPrivate::keypadNavigationEnabled()) { // Try to have one item activated - if (d->defaultAction && d->defaultAction->isEnabled()) { - atAction = d->defaultAction; + if (defaultAction && defaultAction->isEnabled()) { + atAction = defaultAction; // TODO: This works for first level menus, not yet sub menus } else { - for (QAction *action : qAsConst(d->actions)) + for (QAction *action : qAsConst(actions)) if (action->isEnabled()) { atAction = action; break; } } - d->currentAction = atAction; + currentAction = atAction; } #endif - if (d->ncols > 1) { + if (ncols > 1) { pos.setY(screen.top() + desktopFrame); } else if (atAction) { - for (int i = 0, above_height = 0; i < d->actions.count(); i++) { - QAction *action = d->actions.at(i); + for (int i = 0, above_height = 0; i < actions.count(); i++) { + QAction *action = actions.at(i); if (action == atAction) { int newY = pos.y() - above_height; - if (d->scroll && newY < desktopFrame) { - d->scroll->scrollFlags = d->scroll->scrollFlags + if (scroll && newY < desktopFrame) { + scroll->scrollFlags = scroll->scrollFlags | QMenuPrivate::QMenuScroller::ScrollUp; - d->scroll->scrollOffset = newY; + scroll->scrollOffset = newY; newY = desktopFrame; } pos.setY(newY); - if (d->scroll && d->scroll->scrollFlags != QMenuPrivate::QMenuScroller::ScrollNone - && !style()->styleHint(QStyle::SH_Menu_FillScreenWithScroll, nullptr, this)) { - int below_height = above_height + d->scroll->scrollOffset; - for (int i2 = i; i2 < d->actionRects.count(); i2++) - below_height += d->actionRects.at(i2).height(); + if (scroll && scroll->scrollFlags != QMenuPrivate::QMenuScroller::ScrollNone + && !q->style()->styleHint(QStyle::SH_Menu_FillScreenWithScroll, nullptr, q)) { + int below_height = above_height + scroll->scrollOffset; + for (int i2 = i; i2 < actionRects.count(); i2++) + below_height += actionRects.at(i2).height(); size.setHeight(below_height); } break; } else { - above_height += d->actionRects.at(i).height(); + above_height += actionRects.at(i).height(); } } } QPoint mouse = QCursor::pos(); - d->mousePopupPos = mouse; - const bool snapToMouse = !d->causedPopup.widget && (QRect(p.x() - 3, p.y() - 3, 6, 6).contains(mouse)); + mousePopupPos = mouse; + const bool snapToMouse = !causedPopup.widget && (QRect(p.x() - 3, p.y() - 3, 6, 6).contains(mouse)); if (adjustToDesktop) { // handle popup falling "off screen" - if (isRightToLeft()) { + if (q->isRightToLeft()) { if (snapToMouse) // position flowing left from the mouse pos.setX(mouse.x() - size.width()); #if QT_CONFIG(menubar) // if the menu is in a menubar or is a submenu, it should be right-aligned - if (qobject_cast<QMenuBar*>(d->causedPopup.widget) || qobject_cast<QMenu*>(d->causedPopup.widget)) + if (qobject_cast<QMenuBar*>(causedPopup.widget) || qobject_cast<QMenu*>(causedPopup.widget)) pos.rx() -= size.width(); #endif // QT_CONFIG(menubar) @@ -2482,8 +2492,8 @@ void QMenu::popup(const QPoint &p, QAction *atAction) if (pos.y() < screen.top() + desktopFrame) pos.setY(screen.top() + desktopFrame); if (pos.y() + menuSizeHint.height() - 1 > screen.bottom() - desktopFrame) { - if (d->scroll) { - d->scroll->scrollFlags |= uint(QMenuPrivate::QMenuScroller::ScrollDown); + if (scroll) { + scroll->scrollFlags |= uint(QMenuPrivate::QMenuScroller::ScrollDown); int y = qMax(screen.y(),pos.y()); size.setHeight(screen.bottom() - (desktopFrame * 2) - y); } else { @@ -2492,13 +2502,13 @@ void QMenu::popup(const QPoint &p, QAction *atAction) } } } - const int subMenuOffset = style()->pixelMetric(QStyle::PM_SubMenuOverlap, nullptr, this); - QMenu *caused = qobject_cast<QMenu*>(d_func()->causedPopup.widget); + const int subMenuOffset = q->style()->pixelMetric(QStyle::PM_SubMenuOverlap, nullptr, q); + QMenu *caused = qobject_cast<QMenu*>(causedPopup.widget); if (caused && caused->geometry().width() + menuSizeHint.width() + subMenuOffset < screen.width()) { QRect parentActionRect(caused->d_func()->actionRect(caused->d_func()->currentAction)); const QPoint actionTopLeft = caused->mapToGlobal(parentActionRect.topLeft()); parentActionRect.moveTopLeft(actionTopLeft); - if (isRightToLeft()) { + if (q->isRightToLeft()) { if ((pos.x() + menuSizeHint.width() > parentActionRect.left() - subMenuOffset) && (pos.x() < parentActionRect.right())) { @@ -2520,61 +2530,61 @@ void QMenu::popup(const QPoint &p, QAction *atAction) } } } - setGeometry(QRect(pos, size)); + q->setGeometry(QRect(pos, size)); #if QT_CONFIG(effects) - int hGuess = isRightToLeft() ? QEffects::LeftScroll : QEffects::RightScroll; + int hGuess = q->isRightToLeft() ? QEffects::LeftScroll : QEffects::RightScroll; int vGuess = QEffects::DownScroll; - if (isRightToLeft()) { + if (q->isRightToLeft()) { if ((snapToMouse && (pos.x() + size.width() / 2 > mouse.x())) || - (qobject_cast<QMenu*>(d->causedPopup.widget) && pos.x() + size.width() / 2 > d->causedPopup.widget->x())) + (qobject_cast<QMenu*>(causedPopup.widget) && pos.x() + size.width() / 2 > causedPopup.widget->x())) hGuess = QEffects::RightScroll; } else { if ((snapToMouse && (pos.x() + size.width() / 2 < mouse.x())) || - (qobject_cast<QMenu*>(d->causedPopup.widget) && pos.x() + size.width() / 2 < d->causedPopup.widget->x())) + (qobject_cast<QMenu*>(causedPopup.widget) && pos.x() + size.width() / 2 < causedPopup.widget->x())) hGuess = QEffects::LeftScroll; } #if QT_CONFIG(menubar) if ((snapToMouse && (pos.y() + size.height() / 2 < mouse.y())) || - (qobject_cast<QMenuBar*>(d->causedPopup.widget) && - pos.y() + size.width() / 2 < d->causedPopup.widget->mapToGlobal(d->causedPopup.widget->pos()).y())) + (qobject_cast<QMenuBar*>(causedPopup.widget) && + pos.y() + size.width() / 2 < causedPopup.widget->mapToGlobal(causedPopup.widget->pos()).y())) vGuess = QEffects::UpScroll; #endif if (QApplication::isEffectEnabled(Qt::UI_AnimateMenu)) { bool doChildEffects = true; #if QT_CONFIG(menubar) - if (QMenuBar *mb = qobject_cast<QMenuBar*>(d->causedPopup.widget)) { + if (QMenuBar *mb = qobject_cast<QMenuBar*>(causedPopup.widget)) { doChildEffects = mb->d_func()->doChildEffects; mb->d_func()->doChildEffects = false; } else #endif - if (QMenu *m = qobject_cast<QMenu*>(d->causedPopup.widget)) { + if (QMenu *m = qobject_cast<QMenu*>(causedPopup.widget)) { doChildEffects = m->d_func()->doChildEffects; m->d_func()->doChildEffects = false; } if (doChildEffects) { if (QApplication::isEffectEnabled(Qt::UI_FadeMenu)) - qFadeEffect(this); - else if (d->causedPopup.widget) - qScrollEffect(this, qobject_cast<QMenu*>(d->causedPopup.widget) ? hGuess : vGuess); + qFadeEffect(q); + else if (causedPopup.widget) + qScrollEffect(q, qobject_cast<QMenu*>(causedPopup.widget) ? hGuess : vGuess); else - qScrollEffect(this, hGuess | vGuess); + qScrollEffect(q, hGuess | vGuess); } else { // kill any running effect qFadeEffect(nullptr); qScrollEffect(nullptr); - show(); + q->show(); } } else #endif { - show(); + q->show(); } #ifndef QT_NO_ACCESSIBILITY - QAccessibleEvent event(this, QAccessible::PopupMenuStart); + QAccessibleEvent event(q, QAccessible::PopupMenuStart); QAccessible::updateAccessibility(&event); #endif } @@ -2640,20 +2650,26 @@ QAction *QMenu::exec() QAction *QMenu::exec(const QPoint &p, QAction *action) { Q_D(QMenu); - ensurePolished(); - createWinId(); - QEventLoop eventLoop; - d->eventLoop = &eventLoop; - popup(p, action); - - QPointer<QObject> guard = this; - (void) eventLoop.exec(); + return d->exec(p, action); +} + +QAction *QMenuPrivate::exec(const QPoint &p, QAction *action, PositionFunction positionFunction) +{ + Q_Q(QMenu); + q->ensurePolished(); + q->createWinId(); + QEventLoop evtLoop; + eventLoop = &evtLoop; + popup(p, action, positionFunction); + + QPointer<QObject> guard = q; + (void) evtLoop.exec(); if (guard.isNull()) return nullptr; - action = d->syncAction; - d->syncAction = nullptr; - d->eventLoop = nullptr; + action = syncAction; + syncAction = nullptr; + eventLoop = nullptr; return action; } diff --git a/src/widgets/widgets/qmenu_p.h b/src/widgets/widgets/qmenu_p.h index efbbc099a1..02fe9f31a1 100644 --- a/src/widgets/widgets/qmenu_p.h +++ b/src/widgets/widgets/qmenu_p.h @@ -64,6 +64,8 @@ #include <qpa/qplatformmenu.h> +#include <functional> + QT_REQUIRE_CONFIG(menu); QT_BEGIN_NAMESPACE @@ -302,6 +304,8 @@ class QMenuPrivate : public QWidgetPrivate { Q_DECLARE_PUBLIC(QMenu) public: + using PositionFunction = std::function<QPoint(const QSize &)>; + QMenuPrivate() : itemsDirty(false), hasCheckableItems(false), @@ -351,6 +355,8 @@ public: QRect popupGeometry(int screen) const; bool useFullScreenForPopup() const; int getLastVisibleAction() const; + void popup(const QPoint &p, QAction *atAction, PositionFunction positionFunction = {}); + QAction *exec(const QPoint &p, QAction *action, PositionFunction positionFunction = {}); //selection static QMenu *mouseDown; diff --git a/src/widgets/widgets/qplaintextedit.cpp b/src/widgets/widgets/qplaintextedit.cpp index d54c0d0b20..87e8af1382 100644 --- a/src/widgets/widgets/qplaintextedit.cpp +++ b/src/widgets/widgets/qplaintextedit.cpp @@ -2250,17 +2250,17 @@ QVariant QPlainTextEdit::inputMethodQuery(Qt::InputMethodQuery query, QVariant a } const QPointF offset = contentOffset(); - switch (argument.type()) { - case QVariant::RectF: + switch (argument.userType()) { + case QMetaType::QRectF: argument = argument.toRectF().translated(-offset); break; - case QVariant::PointF: + case QMetaType::QPointF: argument = argument.toPointF() - offset; break; - case QVariant::Rect: + case QMetaType::QRect: argument = argument.toRect().translated(-offset.toPoint()); break; - case QVariant::Point: + case QMetaType::QPoint: argument = argument.toPoint() - offset; break; default: @@ -2268,14 +2268,14 @@ QVariant QPlainTextEdit::inputMethodQuery(Qt::InputMethodQuery query, QVariant a } const QVariant v = d->control->inputMethodQuery(query, argument); - switch (v.type()) { - case QVariant::RectF: + switch (v.userType()) { + case QMetaType::QRectF: return v.toRectF().translated(offset); - case QVariant::PointF: + case QMetaType::QPointF: return v.toPointF() + offset; - case QVariant::Rect: + case QMetaType::QRect: return v.toRect().translated(offset.toPoint()); - case QVariant::Point: + case QMetaType::QPoint: return v.toPoint() + offset.toPoint(); default: break; diff --git a/src/widgets/widgets/qspinbox.cpp b/src/widgets/widgets/qspinbox.cpp index 61ea81c892..08428f673e 100644 --- a/src/widgets/widgets/qspinbox.cpp +++ b/src/widgets/widgets/qspinbox.cpp @@ -1081,7 +1081,7 @@ QSpinBoxPrivate::QSpinBoxPrivate() value = minimum; displayIntegerBase = 10; singleStep = QVariant((int)1); - type = QVariant::Int; + type = QMetaType::Int; } /*! @@ -1238,7 +1238,7 @@ QDoubleSpinBoxPrivate::QDoubleSpinBoxPrivate() value = minimum; singleStep = QVariant(1.0); decimals = 2; - type = QVariant::Double; + type = QMetaType::Double; } /*! diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp index a7b115a1bc..df480629da 100644 --- a/src/widgets/widgets/qtabbar.cpp +++ b/src/widgets/widgets/qtabbar.cpp @@ -208,7 +208,7 @@ void QTabBarPrivate::initBasicStyleOption(QStyleOptionTab *option, int tabIndex) option->selectedPosition = QStyleOptionTab::NotAdjacent; const bool paintBeginning = (tabIndex == firstVisible) || (dragInProgress && tabIndex == pressedIndex + 1); - const bool paintEnd = (tabIndex == lastVisible - 1) || (dragInProgress && tabIndex == pressedIndex - 1); + const bool paintEnd = (tabIndex == lastVisible) || (dragInProgress && tabIndex == pressedIndex - 1); if (paintBeginning) { if (paintEnd) option->position = QStyleOptionTab::OnlyOneTab; diff --git a/src/widgets/widgets/qtabwidget.cpp b/src/widgets/widgets/qtabwidget.cpp index f0bfe67e3a..a19dacda52 100644 --- a/src/widgets/widgets/qtabwidget.cpp +++ b/src/widgets/widgets/qtabwidget.cpp @@ -612,7 +612,7 @@ void QTabWidget::setTabVisible(int index, bool visible) Only the horizontal element of the \a corner will be used. - Passing 0 shows no widget in the corner. + Passing \nullptr shows no widget in the corner. Any previously set corner widget is hidden. diff --git a/src/widgets/widgets/qtextbrowser.cpp b/src/widgets/widgets/qtextbrowser.cpp index d0ccd435b3..78fde94fad 100644 --- a/src/widgets/widgets/qtextbrowser.cpp +++ b/src/widgets/widgets/qtextbrowser.cpp @@ -152,6 +152,16 @@ public: QTextCursor prevFocus; int lastKeypadScrollValue; #endif + void emitHighlighted(const QUrl &url) + { + Q_Q(QTextBrowser); + emit q->highlighted(url); +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED + emit q->highlighted(url.toString()); +#endif + } }; Q_DECLARE_TYPEINFO(QTextBrowserPrivate::HistoryEntry, Q_MOVABLE_TYPE); @@ -256,24 +266,20 @@ void QTextBrowserPrivate::_q_activateAnchor(const QString &href) void QTextBrowserPrivate::_q_highlightLink(const QString &anchor) { - Q_Q(QTextBrowser); if (anchor.isEmpty()) { #ifndef QT_NO_CURSOR if (viewport->cursor().shape() != Qt::PointingHandCursor) oldCursor = viewport->cursor(); viewport->setCursor(oldCursor); #endif - emit q->highlighted(QUrl()); - emit q->highlighted(QString()); + emitHighlighted(QUrl()); } else { #ifndef QT_NO_CURSOR viewport->setCursor(Qt::PointingHandCursor); #endif const QUrl url = resolveUrl(anchor); - emit q->highlighted(url); - // convenience to ease connecting to QStatusBar::showMessage(const QString &) - emit q->highlighted(url.toString()); + emitHighlighted(url); } } @@ -310,9 +316,9 @@ void QTextBrowserPrivate::setSource(const QUrl &url, QTextDocument::ResourceType if (url.isValid() && (newUrlWithoutFragment != currentUrlWithoutFragment || forceLoadOnSourceChange)) { QVariant data = q->loadResource(type, resolveUrl(url)); - if (data.type() == QVariant::String) { + if (data.userType() == QMetaType::QString) { txt = data.toString(); - } else if (data.type() == QVariant::ByteArray) { + } else if (data.userType() == QMetaType::QByteArray) { if (type == QTextDocument::HtmlResource) { #if QT_CONFIG(textcodec) QByteArray ba = data.toByteArray(); @@ -383,8 +389,7 @@ void QTextBrowserPrivate::setSource(const QUrl &url, QTextDocument::ResourceType } #ifdef QT_KEYPAD_NAVIGATION lastKeypadScrollValue = vbar->value(); - emit q->highlighted(QUrl()); - emit q->highlighted(QString()); + emitHighlighted(QUrl()); #endif #ifndef QT_NO_CURSOR @@ -559,8 +564,7 @@ void QTextBrowserPrivate::keypadMove(bool next) // Ensure that the new selection is highlighted. const QString href = control->anchorAtCursor(); QUrl url = resolveUrl(href); - emit q->highlighted(url); - emit q->highlighted(url.toString()); + emitHighlighted(url); } else { // Scroll vbar->setValue(scrollYOffset); @@ -575,8 +579,7 @@ void QTextBrowserPrivate::keypadMove(bool next) hbar->setValue(savedXOffset); vbar->setValue(scrollYOffset); - emit q->highlighted(QUrl()); - emit q->highlighted(QString()); + emitHighlighted(QUrl()); } } #endif @@ -619,8 +622,7 @@ void QTextBrowserPrivate::restoreHistoryEntry(const HistoryEntry &entry) Q_Q(QTextBrowser); const QString href = prevFocus.charFormat().anchorHref(); QUrl url = resolveUrl(href); - emit q->highlighted(url); - emit q->highlighted(url.toString()); + emitHighlighted(url); #endif } @@ -927,6 +929,7 @@ void QTextBrowser::doSetSource(const QUrl &url, QTextDocument::ResourceType type /*! \fn void QTextBrowser::highlighted(const QString &link) \overload + \obsolete Convenience signal that allows connecting to a slot that takes just a QString, like for example QStatusBar's @@ -1127,8 +1130,7 @@ bool QTextBrowser::focusNextPrevChild(bool next) if (d->prevFocus != d->control->textCursor() && d->control->textCursor().hasSelection()) { const QString href = d->control->anchorAtCursor(); QUrl url = d->resolveUrl(href); - emit highlighted(url); - emit highlighted(url.toString()); + emitHighlighted(url); } d->prevFocus = d->control->textCursor(); #endif @@ -1136,8 +1138,7 @@ bool QTextBrowser::focusNextPrevChild(bool next) } else { #ifdef QT_KEYPAD_NAVIGATION // We assume we have no highlight now. - emit highlighted(QUrl()); - emit highlighted(QString()); + emitHighlighted(QUrl()); #endif } return QTextEdit::focusNextPrevChild(next); diff --git a/src/widgets/widgets/qtextbrowser.h b/src/widgets/widgets/qtextbrowser.h index 33e5b3980c..4b3ec491ee 100644 --- a/src/widgets/widgets/qtextbrowser.h +++ b/src/widgets/widgets/qtextbrowser.h @@ -107,7 +107,10 @@ Q_SIGNALS: void historyChanged(); void sourceChanged(const QUrl &); void highlighted(const QUrl &); +#if QT_DEPRECATED_SINCE(5, 15) + QT_DEPRECATED_VERSION_X_5_15("Use QTextBrowser::highlighted(QUrl) instead") void highlighted(const QString &); +#endif void anchorClicked(const QUrl &); protected: diff --git a/src/widgets/widgets/qtextedit.cpp b/src/widgets/widgets/qtextedit.cpp index 10de7d0b9e..913ca6ec16 100644 --- a/src/widgets/widgets/qtextedit.cpp +++ b/src/widgets/widgets/qtextedit.cpp @@ -1502,7 +1502,7 @@ void QTextEdit::resizeEvent(QResizeEvent *e) QVariant alignmentProperty = doc->documentLayout()->property("contentHasAlignment"); if (!doc->pageSize().isNull() - && alignmentProperty.type() == QVariant::Bool + && alignmentProperty.userType() == QMetaType::Bool && !alignmentProperty.toBool()) { d->_q_adjustScrollbars(); @@ -1547,7 +1547,7 @@ void QTextEditPrivate::relayoutDocument() width = lineWrapColumnOrWidth; else if (lineWrap == QTextEdit::NoWrap) { QVariant alignmentProperty = doc->documentLayout()->property("contentHasAlignment"); - if (alignmentProperty.type() == QVariant::Bool && !alignmentProperty.toBool()) { + if (alignmentProperty.userType() == QMetaType::Bool && !alignmentProperty.toBool()) { width = 0; } @@ -1835,17 +1835,17 @@ QVariant QTextEdit::inputMethodQuery(Qt::InputMethodQuery query, QVariant argume } const QPointF offset(-d->horizontalOffset(), -d->verticalOffset()); - switch (argument.type()) { - case QVariant::RectF: + switch (argument.userType()) { + case QMetaType::QRectF: argument = argument.toRectF().translated(-offset); break; - case QVariant::PointF: + case QMetaType::QPointF: argument = argument.toPointF() - offset; break; - case QVariant::Rect: + case QMetaType::QRect: argument = argument.toRect().translated(-offset.toPoint()); break; - case QVariant::Point: + case QMetaType::QPoint: argument = argument.toPoint() - offset; break; default: @@ -1853,14 +1853,14 @@ QVariant QTextEdit::inputMethodQuery(Qt::InputMethodQuery query, QVariant argume } const QVariant v = d->control->inputMethodQuery(query, argument); - switch (v.type()) { - case QVariant::RectF: + switch (v.userType()) { + case QMetaType::QRectF: return v.toRectF().translated(offset); - case QVariant::PointF: + case QMetaType::QPointF: return v.toPointF() + offset; - case QVariant::Rect: + case QMetaType::QRect: return v.toRect().translated(offset.toPoint()); - case QVariant::Point: + case QMetaType::QPoint: return v.toPoint() + offset.toPoint(); default: break; diff --git a/src/widgets/widgets/qtoolbutton.cpp b/src/widgets/widgets/qtoolbutton.cpp index 127960b23c..cfa4782d78 100644 --- a/src/widgets/widgets/qtoolbutton.cpp +++ b/src/widgets/widgets/qtoolbutton.cpp @@ -723,38 +723,12 @@ void QToolButtonPrivate::_q_buttonReleased() popupTimer.stop(); } -void QToolButtonPrivate::popupTimerDone() +static QPoint positionMenu(const QToolButton *q, bool horizontal, + const QSize &sh) { - Q_Q(QToolButton); - popupTimer.stop(); - if (!menuButtonDown && !down) - return; - - menuButtonDown = true; - QPointer<QMenu> actualMenu; - bool mustDeleteActualMenu = false; - if(menuAction) { - actualMenu = menuAction->menu(); - } else if (defaultAction && defaultAction->menu()) { - actualMenu = defaultAction->menu(); - } else { - actualMenu = new QMenu(q); - mustDeleteActualMenu = true; - for(int i = 0; i < actions.size(); i++) - actualMenu->addAction(actions.at(i)); - } - repeat = q->autoRepeat(); - q->setAutoRepeat(false); - bool horizontal = true; -#if QT_CONFIG(toolbar) - QToolBar *tb = qobject_cast<QToolBar*>(parent); - if (tb && tb->orientation() == Qt::Vertical) - horizontal = false; -#endif QPoint p; const QRect rect = q->rect(); // Find screen via point in case of QGraphicsProxyWidget. QRect screen = QDesktopWidgetPrivate::availableGeometry(q->mapToGlobal(rect.center())); - QSize sh = ((QToolButton*)(QMenu*)actualMenu)->receivers(SIGNAL(aboutToShow()))? QSize() : actualMenu->sizeHint(); if (horizontal) { if (q->isRightToLeft()) { if (q->mapToGlobal(QPoint(0, rect.bottom())).y() + sh.height() <= screen.bottom()) { @@ -788,6 +762,37 @@ void QToolButtonPrivate::popupTimerDone() } p.rx() = qMax(screen.left(), qMin(p.x(), screen.right() - sh.width())); p.ry() += 1; + return p; +} + +void QToolButtonPrivate::popupTimerDone() +{ + Q_Q(QToolButton); + popupTimer.stop(); + if (!menuButtonDown && !down) + return; + + menuButtonDown = true; + QPointer<QMenu> actualMenu; + bool mustDeleteActualMenu = false; + if (menuAction) { + actualMenu = menuAction->menu(); + } else if (defaultAction && defaultAction->menu()) { + actualMenu = defaultAction->menu(); + } else { + actualMenu = new QMenu(q); + mustDeleteActualMenu = true; + for (int i = 0; i < actions.size(); i++) + actualMenu->addAction(actions.at(i)); + } + repeat = q->autoRepeat(); + q->setAutoRepeat(false); + bool horizontal = true; +#if QT_CONFIG(toolbar) + QToolBar *tb = qobject_cast<QToolBar*>(parent); + if (tb && tb->orientation() == Qt::Vertical) + horizontal = false; +#endif QPointer<QToolButton> that = q; actualMenu->setNoReplayFor(q); if (!mustDeleteActualMenu) //only if action are not in this widget @@ -796,7 +801,11 @@ void QToolButtonPrivate::popupTimerDone() actualMenu->d_func()->causedPopup.widget = q; actualMenu->d_func()->causedPopup.action = defaultAction; actionsCopy = q->actions(); //(the list of action may be modified in slots) - actualMenu->exec(p); + + // QTBUG-78966, Delay positioning until after aboutToShow(). + auto positionFunction = [q, horizontal](const QSize &sizeHint) { + return positionMenu(q, horizontal, sizeHint); }; + actualMenu->d_func()->exec({}, nullptr, positionFunction); if (!that) return; |