summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/widgets')
-rw-r--r--src/widgets/widgets/qabstractbutton.cpp8
-rw-r--r--src/widgets/widgets/qabstractslider.cpp4
-rw-r--r--src/widgets/widgets/qabstractspinbox.cpp6
-rw-r--r--src/widgets/widgets/qcheckbox.cpp6
-rw-r--r--src/widgets/widgets/qcombobox.cpp18
-rw-r--r--src/widgets/widgets/qcommandlinkbutton.cpp6
-rw-r--r--src/widgets/widgets/qdatetimeedit.cpp10
-rw-r--r--src/widgets/widgets/qdial.cpp2
-rw-r--r--src/widgets/widgets/qdockwidget.cpp40
-rw-r--r--src/widgets/widgets/qdockwidget_p.h2
-rw-r--r--src/widgets/widgets/qframe.cpp6
-rw-r--r--src/widgets/widgets/qgroupbox.cpp6
-rw-r--r--src/widgets/widgets/qkeysequenceedit.cpp117
-rw-r--r--src/widgets/widgets/qkeysequenceedit.h8
-rw-r--r--src/widgets/widgets/qkeysequenceedit_p.h2
-rw-r--r--src/widgets/widgets/qlabel.cpp12
-rw-r--r--src/widgets/widgets/qlineedit.cpp6
-rw-r--r--src/widgets/widgets/qlineedit_p.cpp4
-rw-r--r--src/widgets/widgets/qmainwindowlayout.cpp2
-rw-r--r--src/widgets/widgets/qmainwindowlayout_p.h2
-rw-r--r--src/widgets/widgets/qmenu.cpp41
-rw-r--r--src/widgets/widgets/qmenubar.cpp6
-rw-r--r--src/widgets/widgets/qplaintextedit.cpp4
-rw-r--r--src/widgets/widgets/qprogressbar.cpp4
-rw-r--r--src/widgets/widgets/qpushbutton.cpp4
-rw-r--r--src/widgets/widgets/qscrollbar.cpp2
-rw-r--r--src/widgets/widgets/qsizegrip.cpp6
-rw-r--r--src/widgets/widgets/qslider.cpp4
-rw-r--r--src/widgets/widgets/qsplitter.cpp12
-rw-r--r--src/widgets/widgets/qstatusbar.cpp4
-rw-r--r--src/widgets/widgets/qtabbar.cpp21
-rw-r--r--src/widgets/widgets/qtabbar.h4
-rw-r--r--src/widgets/widgets/qtabbar_p.h2
-rw-r--r--src/widgets/widgets/qtextbrowser.cpp9
-rw-r--r--src/widgets/widgets/qtextedit.cpp8
-rw-r--r--src/widgets/widgets/qtoolbararealayout.cpp4
-rw-r--r--src/widgets/widgets/qwidgetlinecontrol.cpp16
-rw-r--r--src/widgets/widgets/qwidgettextcontrol.cpp33
38 files changed, 321 insertions, 130 deletions
diff --git a/src/widgets/widgets/qabstractbutton.cpp b/src/widgets/widgets/qabstractbutton.cpp
index 4eb871ea4b..c2f16dc335 100644
--- a/src/widgets/widgets/qabstractbutton.cpp
+++ b/src/widgets/widgets/qabstractbutton.cpp
@@ -16,7 +16,7 @@
#include "qpainter.h"
#include "qapplication.h"
#include "qstyle.h"
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
#include "qaccessible.h"
#endif
#include <qpa/qplatformtheme.h>
@@ -490,7 +490,7 @@ void QAbstractButton::setText(const QString &text)
d->sizeHint = QSize();
update();
updateGeometry();
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessibleEvent event(this, QAccessible::NameChanged);
QAccessible::updateAccessibility(&event);
#endif
@@ -614,7 +614,7 @@ void QAbstractButton::setChecked(bool checked)
d->emitToggled(checked);
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessible::State s;
s.checked = true;
QAccessibleStateChangeEvent event(this, s);
@@ -1050,7 +1050,7 @@ void QAbstractButton::keyPressEvent(QKeyEvent *e)
// cleaned up when fixing task 194373. It's here to ensure that we
// keep compatibility outside QAbstractItemView.
d->moveFocus(e->key());
- if (hasFocus()) // nothing happend, propagate
+ if (hasFocus()) // nothing happened, propagate
e->ignore();
} else {
// Prefer parent widget, use this if parent is absent
diff --git a/src/widgets/widgets/qabstractslider.cpp b/src/widgets/widgets/qabstractslider.cpp
index 524b274bd6..6e44b2d432 100644
--- a/src/widgets/widgets/qabstractslider.cpp
+++ b/src/widgets/widgets/qabstractslider.cpp
@@ -6,7 +6,7 @@
#include "qevent.h"
#include "qabstractslider_p.h"
#include "qdebug.h"
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
#include "qaccessible.h"
#endif
#include <limits.h>
@@ -504,7 +504,7 @@ void QAbstractSlider::setValue(int value)
if (d->pressed)
emit sliderMoved((d->position = value));
}
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessibleValueChangeEvent event(this, d->value);
QAccessible::updateAccessibility(&event);
#endif
diff --git a/src/widgets/widgets/qabstractspinbox.cpp b/src/widgets/widgets/qabstractspinbox.cpp
index fde0e62538..ff41a72fca 100644
--- a/src/widgets/widgets/qabstractspinbox.cpp
+++ b/src/widgets/widgets/qabstractspinbox.cpp
@@ -22,7 +22,7 @@
#include <qpalette.h>
#include <qstylepainter.h>
#include <qdebug.h>
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
# include <qaccessible.h>
#endif
@@ -1020,7 +1020,7 @@ void QAbstractSpinBox::keyPressEvent(QKeyEvent *event)
d->updateState(up, true);
}
}
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessibleValueChangeEvent event(this, d->value);
QAccessible::updateAccessibility(&event);
#endif
@@ -1651,7 +1651,7 @@ void QAbstractSpinBoxPrivate::updateState(bool up, bool fromKeyboard /* = false
steps *= 10;
q->stepBy(steps);
spinClickThresholdTimerId = q->startTimer(spinClickThresholdTimerInterval);
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessibleValueChangeEvent event(q, value);
QAccessible::updateAccessibility(&event);
#endif
diff --git a/src/widgets/widgets/qcheckbox.cpp b/src/widgets/widgets/qcheckbox.cpp
index 7164676f96..151c8b1e94 100644
--- a/src/widgets/widgets/qcheckbox.cpp
+++ b/src/widgets/widgets/qcheckbox.cpp
@@ -9,7 +9,7 @@
#include "qstyle.h"
#include "qstyleoption.h"
#include "qevent.h"
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
#include "qaccessible.h"
#endif
@@ -211,7 +211,7 @@ Qt::CheckState QCheckBox::checkState() const
void QCheckBox::setCheckState(Qt::CheckState state)
{
Q_D(QCheckBox);
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
bool noChange = d->noChange;
#endif
if (state == Qt::PartiallyChecked) {
@@ -229,7 +229,7 @@ void QCheckBox::setCheckState(Qt::CheckState state)
emit stateChanged(state);
}
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
if (noChange != d->noChange) {
QAccessible::State s;
s.checkStateMixed = true;
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp
index de8f98d1da..9caac239f9 100644
--- a/src/widgets/widgets/qcombobox.cpp
+++ b/src/widgets/widgets/qcombobox.cpp
@@ -45,7 +45,7 @@
# include <private/qeffects_p.h>
#endif
#include <private/qstyle_p.h>
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
#include "qaccessible.h"
#endif
@@ -1082,7 +1082,7 @@ void QComboBoxPrivate::_q_dataChanged(const QModelIndex &topLeft, const QModelIn
emit q->currentTextChanged(text);
}
q->update();
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessibleValueChangeEvent event(q, text);
QAccessible::updateAccessibility(&event);
#endif
@@ -1385,7 +1385,7 @@ void QComboBoxPrivate::_q_emitCurrentIndexChanged(const QModelIndex &index)
// signal lineEdit.textChanged already connected to signal currentTextChanged, so don't emit double here
if (!lineEdit)
emit q->currentTextChanged(text);
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessibleValueChangeEvent event(q, text);
QAccessible::updateAccessibility(&event);
#endif
@@ -2135,7 +2135,11 @@ void QComboBoxPrivate::setCurrentIndex(const QModelIndex &mi)
}
updateLineEditGeometry();
}
- if (indexChanged) {
+ // If the model was reset to an empty, currentIndex will be invalidated
+ // (because it's a QPersistentModelIndex), but the index change will never
+ // be advertised. So we need an explicit check for such condition.
+ const bool modelResetToEmpty = !normalized.isValid() && indexBeforeChange != -1;
+ if (indexChanged || modelResetToEmpty) {
q->update();
_q_emitCurrentIndexChanged(currentIndex);
}
@@ -2867,7 +2871,7 @@ void QComboBox::clear()
{
Q_D(QComboBox);
d->model->removeRows(0, d->model->rowCount(d->root), d->root);
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessibleValueChangeEvent event(this, QString());
QAccessible::updateAccessibility(&event);
#endif
@@ -2881,7 +2885,7 @@ void QComboBox::clearEditText()
Q_D(QComboBox);
if (d->lineEdit)
d->lineEdit->clear();
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessibleValueChangeEvent event(this, QString());
QAccessible::updateAccessibility(&event);
#endif
@@ -2895,7 +2899,7 @@ void QComboBox::setEditText(const QString &text)
Q_D(QComboBox);
if (d->lineEdit)
d->lineEdit->setText(text);
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessibleValueChangeEvent event(this, text);
QAccessible::updateAccessibility(&event);
#endif
diff --git a/src/widgets/widgets/qcommandlinkbutton.cpp b/src/widgets/widgets/qcommandlinkbutton.cpp
index 5a82e63f44..2c59e78c1a 100644
--- a/src/widgets/widgets/qcommandlinkbutton.cpp
+++ b/src/widgets/widgets/qcommandlinkbutton.cpp
@@ -171,7 +171,7 @@ bool QCommandLinkButtonPrivate::usingVistaStyle() const
Q_Q(const QCommandLinkButton);
//### This is a hack to detect if we are indeed running Vista style themed and not in classic
// When we add api to query for this, we should change this implementation to use it.
- return q->style()->inherits("QWindowsVistaStyle")
+ return q->property("_qt_usingVistaStyle").toBool()
&& q->style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal, nullptr) == 0;
}
@@ -339,9 +339,9 @@ void QCommandLinkButton::paintEvent(QPaintEvent *)
//Draw title
QColor textColor = palette().buttonText().color();
if (isEnabled() && d->usingVistaStyle()) {
- textColor = QColor(21, 28, 85);
+ textColor = option.palette.buttonText().color();
if (underMouse() && !isDown())
- textColor = QColor(7, 64, 229);
+ textColor = option.palette.brightText().color();
//A simple text color transition
d->currentColor = d->mergedColors(textColor, d->currentColor, 60);
option.palette.setColor(QPalette::ButtonText, d->currentColor);
diff --git a/src/widgets/widgets/qdatetimeedit.cpp b/src/widgets/widgets/qdatetimeedit.cpp
index 5e61a87fd7..8691e98144 100644
--- a/src/widgets/widgets/qdatetimeedit.cpp
+++ b/src/widgets/widgets/qdatetimeedit.cpp
@@ -957,7 +957,7 @@ void QDateTimeEdit::setDisplayFormat(const QString &format)
}
} else if (dateShown && !timeShown) {
setTimeRange(QDATETIMEEDIT_TIME_MIN, QDATETIMEEDIT_TIME_MAX);
- d->value = QDateTime(d->value.toDate(), QTime(), d->spec);
+ d->value = d->value.toDate().startOfDay(d->spec);
}
d->updateEdit();
d->_q_editorCursorPositionChanged(-1, 0);
@@ -1597,7 +1597,7 @@ QTimeEdit::QTimeEdit(QWidget *parent)
*/
QTimeEdit::QTimeEdit(QTime time, QWidget *parent)
- : QDateTimeEdit(time, QMetaType::QTime, parent)
+ : QDateTimeEdit(time.isValid() ? time : QDATETIMEEDIT_TIME_MIN, QMetaType::QTime, parent)
{
connect(this, &QTimeEdit::timeChanged, this, &QTimeEdit::userTimeChanged);
}
@@ -1667,7 +1667,7 @@ QDateEdit::QDateEdit(QWidget *parent)
*/
QDateEdit::QDateEdit(QDate date, QWidget *parent)
- : QDateTimeEdit(date, QMetaType::QDate, parent)
+ : QDateTimeEdit(date.isValid() ? date : QDATETIMEEDIT_DATE_INITIAL, QMetaType::QDate, parent)
{
connect(this, &QDateEdit::dateChanged, this, &QDateEdit::userDateChanged);
}
@@ -2480,7 +2480,7 @@ void QDateTimeEditPrivate::init(const QVariant &var)
Q_Q(QDateTimeEdit);
switch (var.userType()) {
case QMetaType::QDate:
- value = var.toDate().startOfDay();
+ value = var.toDate().startOfDay(spec);
updateTimeSpec();
q->setDisplayFormat(defaultDateFormat);
if (sectionNodes.isEmpty()) // ### safeguard for broken locale
@@ -2494,7 +2494,7 @@ void QDateTimeEditPrivate::init(const QVariant &var)
q->setDisplayFormat("dd/MM/yyyy hh:mm:ss"_L1);
break;
case QMetaType::QTime:
- value = QDateTime(QDATETIMEEDIT_DATE_INITIAL, var.toTime());
+ value = QDateTime(QDATETIMEEDIT_DATE_INITIAL, var.toTime(), spec);
updateTimeSpec();
q->setDisplayFormat(defaultTimeFormat);
if (sectionNodes.isEmpty()) // ### safeguard for broken locale
diff --git a/src/widgets/widgets/qdial.cpp b/src/widgets/widgets/qdial.cpp
index ccd5ab25b8..e16b6eadaf 100644
--- a/src/widgets/widgets/qdial.cpp
+++ b/src/widgets/widgets/qdial.cpp
@@ -16,7 +16,7 @@
#include <qslider.h>
#include <private/qabstractslider_p.h>
#include <private/qmath_p.h>
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
#include "qaccessible.h"
#endif
#include <qmath.h>
diff --git a/src/widgets/widgets/qdockwidget.cpp b/src/widgets/widgets/qdockwidget.cpp
index ccd8c4cd71..6072740db8 100644
--- a/src/widgets/widgets/qdockwidget.cpp
+++ b/src/widgets/widgets/qdockwidget.cpp
@@ -20,6 +20,7 @@
#include <private/qstylesheetstyle_p.h>
#include <qpa/qplatformtheme.h>
+#include <private/qhighdpiscaling_p.h>
#include "qdockwidget_p.h"
#include "qmainwindowlayout_p.h"
@@ -708,7 +709,7 @@ void QDockWidgetPrivate::updateButtons()
= qobject_cast<QAbstractButton*>(dwLayout->widgetForRole(QDockWidgetLayout::FloatButton));
button->setIcon(q->style()->standardIcon(QStyle::SP_TitleBarNormalButton, &opt, q));
button->setVisible(canFloat && !hideButtons);
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
//: Accessible name for button undocking a dock widget (floating state)
button->setAccessibleName(QDockWidget::tr("Float"));
button->setAccessibleDescription(QDockWidget::tr("Undocks and re-attaches the dock widget"));
@@ -717,7 +718,7 @@ void QDockWidgetPrivate::updateButtons()
= qobject_cast <QAbstractButton*>(dwLayout->widgetForRole(QDockWidgetLayout::CloseButton));
button->setIcon(q->style()->standardIcon(QStyle::SP_TitleBarCloseButton, &opt, q));
button->setVisible(canClose && !hideButtons);
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
//: Accessible name for button closing a dock widget
button->setAccessibleName(QDockWidget::tr("Close"));
button->setAccessibleDescription(QDockWidget::tr("Closes the dock widget"));
@@ -752,6 +753,8 @@ void QDockWidgetPrivate::initDrag(const QPoint &pos, bool nca)
state = new QDockWidgetPrivate::DragState;
state->pressPos = pos;
+ state->globalPressPos = q->mapToGlobal(pos);
+ state->widgetInitialPos = q->pos();
state->dragging = false;
state->widgetItem = nullptr;
state->ownWidgetItem = false;
@@ -981,7 +984,34 @@ bool QDockWidgetPrivate::mouseMoveEvent(QMouseEvent *event)
if (state && state->dragging && !state->nca) {
QMargins windowMargins = q->window()->windowHandle()->frameMargins();
QPoint windowMarginOffset = QPoint(windowMargins.left(), windowMargins.top());
- QPoint pos = event->globalPosition().toPoint() - state->pressPos - windowMarginOffset;
+
+ // TODO maybe use QScreen API (if/when available) to simplify the below code.
+ const QScreen *orgWdgScreen = QGuiApplication::screenAt(state->widgetInitialPos);
+ const QScreen *screenFrom = QGuiApplication::screenAt(state->globalPressPos);
+ const QScreen *screenTo = QGuiApplication::screenAt(event->globalPosition().toPoint());
+ const QScreen *wdgScreen = q->screen();
+
+ QPoint pos;
+ if (Q_LIKELY(screenFrom && screenTo && wdgScreen && orgWdgScreen)) {
+ const QPoint nativeWdgOrgPos = QHighDpiScaling::mapPositionToNative(
+ state->widgetInitialPos, orgWdgScreen->handle());
+ const QPoint nativeTo = QHighDpiScaling::mapPositionToNative(
+ event->globalPosition().toPoint(), screenTo->handle());
+ const QPoint nativeFrom = QHighDpiScaling::mapPositionToNative(state->globalPressPos,
+ screenFrom->handle());
+
+ // Calculate new nativePos based on startPos + mouse delta move.
+ const QPoint nativeNewPos = nativeWdgOrgPos + (nativeTo - nativeFrom);
+ pos = QHighDpiScaling::mapPositionFromNative(nativeNewPos, wdgScreen->handle())
+ - windowMarginOffset;
+ } else {
+ // Fallback in the unlikely case that source and target screens could not be established
+ qCWarning(lcQpaDockWidgets)
+ << "QDockWidget failed to find relevant screen info. screenFrom:" << screenFrom
+ << "screenTo:" << screenTo << " wdgScreen:" << wdgScreen << "orgWdgScreen"
+ << orgWdgScreen;
+ pos = event->globalPosition().toPoint() - state->pressPos - windowMarginOffset;
+ }
QDockWidgetGroupWindow *floatingTab = qobject_cast<QDockWidgetGroupWindow*>(parent);
if (floatingTab && !q->isFloating())
@@ -1049,14 +1079,14 @@ void QDockWidgetPrivate::nonClientAreaMouseEvent(QMouseEvent *event)
if (state == nullptr || !state->dragging)
break;
-#ifndef Q_OS_MAC
+#if !defined(Q_OS_MAC) && !defined(Q_OS_WASM)
if (state->nca) {
endDrag();
}
#endif
break;
case QEvent::NonClientAreaMouseButtonRelease:
-#ifdef Q_OS_MAC
+#if defined(Q_OS_MAC) || defined(Q_OS_WASM)
if (state)
endDrag();
#endif
diff --git a/src/widgets/widgets/qdockwidget_p.h b/src/widgets/widgets/qdockwidget_p.h
index 8e9f80d412..326c55cc78 100644
--- a/src/widgets/widgets/qdockwidget_p.h
+++ b/src/widgets/widgets/qdockwidget_p.h
@@ -41,6 +41,8 @@ class QDockWidgetPrivate : public QWidgetPrivate
struct DragState {
QPoint pressPos;
+ QPoint globalPressPos;
+ QPoint widgetInitialPos;
bool dragging;
QLayoutItem *widgetItem;
bool ownWidgetItem;
diff --git a/src/widgets/widgets/qframe.cpp b/src/widgets/widgets/qframe.cpp
index 6f4310facb..db8dc20be2 100644
--- a/src/widgets/widgets/qframe.cpp
+++ b/src/widgets/widgets/qframe.cpp
@@ -428,9 +428,9 @@ int QFrame::frameWidth() const
\brief the frame's rectangle
The frame's rectangle is the rectangle the frame is drawn in. By
- default, this is the entire widget. Setting the rectangle does
- does \e not cause a widget update. The frame rectangle is
- automatically adjusted when the widget changes size.
+ default, this is the entire widget. Setting the rectangle \e doesn't
+ cause a widget update. The frame rectangle is automatically adjusted
+ when the widget changes size.
If you set the rectangle to a null rectangle (for example,
QRect(0, 0, 0, 0)), then the resulting frame rectangle is
diff --git a/src/widgets/widgets/qgroupbox.cpp b/src/widgets/widgets/qgroupbox.cpp
index 836a3c615d..8fd90f8b77 100644
--- a/src/widgets/widgets/qgroupbox.cpp
+++ b/src/widgets/widgets/qgroupbox.cpp
@@ -14,7 +14,7 @@
#include "qstyle.h"
#include "qstyleoption.h"
#include "qstylepainter.h"
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
#include "qaccessible.h"
#endif
#include <private/qwidget_p.h>
@@ -200,7 +200,7 @@ void QGroupBox::setTitle(const QString &title)
update();
updateGeometry();
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessibleEvent event(this, QAccessible::NameChanged);
QAccessible::updateAccessibility(&event);
#endif
@@ -609,7 +609,7 @@ void QGroupBox::setChecked(bool b)
update();
d->checked = b;
d->_q_setChildrenEnabled(b);
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessible::State st;
st.checked = true;
QAccessibleStateChangeEvent e(this, st);
diff --git a/src/widgets/widgets/qkeysequenceedit.cpp b/src/widgets/widgets/qkeysequenceedit.cpp
index 3dafb9396b..565ea08001 100644
--- a/src/widgets/widgets/qkeysequenceedit.cpp
+++ b/src/widgets/widgets/qkeysequenceedit.cpp
@@ -29,6 +29,7 @@ void QKeySequenceEditPrivate::init()
keyNum = 0;
prevKey = -1;
releaseTimer = 0;
+ finishingKeyCombinations = {Qt::Key_Tab, Qt::Key_Backtab};
QVBoxLayout *layout = new QVBoxLayout(q);
layout->setContentsMargins(0, 0, 0, 0);
@@ -136,6 +137,9 @@ QKeySequenceEdit::~QKeySequenceEdit()
\brief This property contains the currently chosen key sequence.
The shortcut can be changed by the user or via setter function.
+
+ \note If the QKeySequence is longer than the maximumSequenceLength
+ property, the key sequence is truncated.
*/
QKeySequence QKeySequenceEdit::keySequence() const
{
@@ -169,6 +173,68 @@ bool QKeySequenceEdit::isClearButtonEnabled() const
return d->lineEdit->isClearButtonEnabled();
}
+/*!
+ \property QKeySequenceEdit::maximumSequenceLength
+ \brief The maximum sequence length.
+
+ The value is clamped to [1-4] inclusive, i.e. the maximum value of the
+ maximum sequence length is 4 driven by QKeySequence. The minimum value is
+ 1, which can be useful for single sequence, like a typical shortcut.
+
+ The QKeySequence stored in QKeySequenceEdit is truncated if longer than the
+ value of this property.
+
+ \since 6.5
+*/
+qsizetype QKeySequenceEdit::maximumSequenceLength() const
+{
+ Q_D(const QKeySequenceEdit);
+ return d->maximumSequenceLength;
+}
+
+void QKeySequenceEdit::setMaximumSequenceLength(qsizetype count)
+{
+ Q_D(QKeySequenceEdit);
+
+ if (count < 1 || count > QKeySequencePrivate::MaxKeyCount) {
+ qWarning("QKeySequenceEdit: maximumSequenceLength %lld is out of range (1..%d)",
+ qlonglong(count), QKeySequencePrivate::MaxKeyCount);
+ return;
+ }
+ d->maximumSequenceLength = int(count);
+ if (d->keyNum > count) {
+ for (qsizetype i = d->keyNum; i < count; ++i)
+ d->key[i] = QKeyCombination::fromCombined(0);
+ d->keyNum = count;
+ d->rebuildKeySequence();
+ }
+}
+
+/*!
+ \property QKeySequenceEdit::finishingKeyCombinations
+ \brief The list of key combinations that finish editing the key sequences.
+
+ Any combination in the list will finish the editing of key sequences.
+ All other key combinations can be recorded as part of a key sequence. By
+ default, Qt::Key_Tab and Qt::Key_Backtab will finish recording the key
+ sequence.
+
+ \since 6.5
+*/
+void QKeySequenceEdit::setFinishingKeyCombinations(const QList<QKeyCombination> &finishingKeyCombinations)
+{
+ Q_D(QKeySequenceEdit);
+
+ d->finishingKeyCombinations = finishingKeyCombinations;
+}
+
+QList<QKeyCombination> QKeySequenceEdit::finishingKeyCombinations() const
+{
+ Q_D(const QKeySequenceEdit);
+
+ return d->finishingKeyCombinations;
+}
+
void QKeySequenceEdit::setKeySequence(const QKeySequence &keySequence)
{
Q_D(QKeySequenceEdit);
@@ -178,16 +244,24 @@ void QKeySequenceEdit::setKeySequence(const QKeySequence &keySequence)
if (d->keySequence == keySequence)
return;
- d->keySequence = keySequence;
+ const auto desiredCount = keySequence.count();
+ if (desiredCount > d->maximumSequenceLength) {
+ qWarning("QKeySequenceEdit: setting a key sequence of length %d "
+ "when maximumSequenceLength is %d, truncating.",
+ desiredCount, d->maximumSequenceLength);
+ }
- d->key[0] = d->key[1] = d->key[2] = d->key[3] = QKeyCombination::fromCombined(0);
- d->keyNum = keySequence.count();
+ d->keyNum = std::min(desiredCount, d->maximumSequenceLength);
for (int i = 0; i < d->keyNum; ++i)
d->key[i] = keySequence[i];
+ for (int i = d->keyNum; i < QKeySequencePrivate::MaxKeyCount; ++i)
+ d->key[i] = QKeyCombination::fromCombined(0);
- d->lineEdit->setText(keySequence.toString(QKeySequence::NativeText));
+ d->rebuildKeySequence();
+
+ d->lineEdit->setText(d->keySequence.toString(QKeySequence::NativeText));
- emit keySequenceChanged(keySequence);
+ emit keySequenceChanged(d->keySequence);
}
/*!
@@ -212,13 +286,23 @@ void QKeySequenceEdit::clear()
*/
bool QKeySequenceEdit::event(QEvent *e)
{
+ Q_D(const QKeySequenceEdit);
+
switch (e->type()) {
case QEvent::Shortcut:
return true;
case QEvent::ShortcutOverride:
e->accept();
return true;
- default :
+ case QEvent::KeyPress: {
+ QKeyEvent *ke = static_cast<QKeyEvent *>(e);
+ if (!d->finishingKeyCombinations.contains(ke->keyCombination())) {
+ keyPressEvent(ke);
+ return true;
+ }
+ }
+ break;
+ default:
break;
}
@@ -232,6 +316,11 @@ void QKeySequenceEdit::keyPressEvent(QKeyEvent *e)
{
Q_D(QKeySequenceEdit);
+ if (d->finishingKeyCombinations.contains(e->keyCombination())) {
+ d->finishEditing();
+ return;
+ }
+
int nextKey = e->key();
if (d->prevKey == -1) {
@@ -255,7 +344,7 @@ void QKeySequenceEdit::keyPressEvent(QKeyEvent *e)
return;
}
- if (d->keyNum >= QKeySequencePrivate::MaxKeyCount)
+ if (d->keyNum >= d->maximumSequenceLength)
return;
if (e->modifiers() & Qt::ShiftModifier) {
@@ -285,7 +374,7 @@ void QKeySequenceEdit::keyPressEvent(QKeyEvent *e)
d->rebuildKeySequence();
QString text = d->keySequence.toString(QKeySequence::NativeText);
- if (d->keyNum < QKeySequencePrivate::MaxKeyCount) {
+ if (d->keyNum < d->maximumSequenceLength) {
//: This text is an "unfinished" shortcut, expands like "Ctrl+A, ..."
text = tr("%1, ...").arg(text);
}
@@ -301,7 +390,7 @@ void QKeySequenceEdit::keyReleaseEvent(QKeyEvent *e)
Q_D(QKeySequenceEdit);
if (d->prevKey == e->key()) {
- if (d->keyNum < QKeySequencePrivate::MaxKeyCount)
+ if (d->keyNum < d->maximumSequenceLength)
d->releaseTimer = startTimer(1000);
else
d->finishEditing();
@@ -323,6 +412,16 @@ void QKeySequenceEdit::timerEvent(QTimerEvent *e)
QWidget::timerEvent(e);
}
+/*!
+ \reimp
+*/
+void QKeySequenceEdit::focusOutEvent(QFocusEvent *e)
+{
+ Q_D(QKeySequenceEdit);
+ d->finishEditing();
+ QWidget::focusOutEvent(e);
+}
+
QT_END_NAMESPACE
#include "moc_qkeysequenceedit.cpp"
diff --git a/src/widgets/widgets/qkeysequenceedit.h b/src/widgets/widgets/qkeysequenceedit.h
index 3ddf2e5ded..15b40133b1 100644
--- a/src/widgets/widgets/qkeysequenceedit.h
+++ b/src/widgets/widgets/qkeysequenceedit.h
@@ -19,6 +19,8 @@ class Q_WIDGETS_EXPORT QKeySequenceEdit : public QWidget
Q_PROPERTY(QKeySequence keySequence READ keySequence WRITE setKeySequence
NOTIFY keySequenceChanged USER true)
Q_PROPERTY(bool clearButtonEnabled READ isClearButtonEnabled WRITE setClearButtonEnabled)
+ Q_PROPERTY(qsizetype maximumSequenceLength READ maximumSequenceLength WRITE setMaximumSequenceLength)
+ Q_PROPERTY(QList<QKeyCombination> finishingKeyCombinations READ finishingKeyCombinations WRITE setFinishingKeyCombinations)
public:
explicit QKeySequenceEdit(QWidget *parent = nullptr);
@@ -26,13 +28,18 @@ public:
~QKeySequenceEdit();
QKeySequence keySequence() const;
+ qsizetype maximumSequenceLength() const;
void setClearButtonEnabled(bool enable);
bool isClearButtonEnabled() const;
+ void setFinishingKeyCombinations(const QList<QKeyCombination> &inishingKeyCombinations);
+ QList<QKeyCombination> finishingKeyCombinations() const;
+
public Q_SLOTS:
void setKeySequence(const QKeySequence &keySequence);
void clear();
+ void setMaximumSequenceLength(qsizetype count);
Q_SIGNALS:
void editingFinished();
@@ -45,6 +52,7 @@ protected:
void keyPressEvent(QKeyEvent *) override;
void keyReleaseEvent(QKeyEvent *) override;
void timerEvent(QTimerEvent *) override;
+ void focusOutEvent(QFocusEvent *) override;
private:
Q_DISABLE_COPY(QKeySequenceEdit)
diff --git a/src/widgets/widgets/qkeysequenceedit_p.h b/src/widgets/widgets/qkeysequenceedit_p.h
index eaaaf63e8a..bdf3bfe788 100644
--- a/src/widgets/widgets/qkeysequenceedit_p.h
+++ b/src/widgets/widgets/qkeysequenceedit_p.h
@@ -42,9 +42,11 @@ public:
QLineEdit *lineEdit;
QKeySequence keySequence;
int keyNum;
+ int maximumSequenceLength = QKeySequencePrivate::MaxKeyCount;
QKeyCombination key[QKeySequencePrivate::MaxKeyCount];
int prevKey;
int releaseTimer;
+ QList<QKeyCombination> finishingKeyCombinations;
};
QT_END_NAMESPACE
diff --git a/src/widgets/widgets/qlabel.cpp b/src/widgets/widgets/qlabel.cpp
index be57285761..4d1c4ebb74 100644
--- a/src/widgets/widgets/qlabel.cpp
+++ b/src/widgets/widgets/qlabel.cpp
@@ -18,7 +18,7 @@
#include "private/qstylesheetstyle_p.h"
#include <qmath.h>
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
#include <qaccessible.h>
#endif
@@ -304,7 +304,7 @@ void QLabel::setText(const QString &text)
d->updateLabel();
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
if (accessibleName().isEmpty()) {
QAccessibleEvent event(this, QAccessible::NameChanged);
QAccessible::updateAccessibility(&event);
@@ -1091,8 +1091,10 @@ void QLabel::paintEvent(QPaintEvent *)
#endif
if (d->pixmap && !d->pixmap->isNull()) {
QPixmap pix;
- if (d->scaledcontents) {
- QSize scaledSize = cr.size() * devicePixelRatio();
+ const qreal dpr = devicePixelRatio();
+ if (d->scaledcontents || dpr != d->pixmap->devicePixelRatio()) {
+ QSize scaledSize = d->scaledcontents ? (cr.size() * dpr)
+ : (d->pixmap->size() * (dpr / d->pixmap->devicePixelRatio()));
if (!d->scaledpixmap || d->scaledpixmap->size() != scaledSize) {
if (!d->cachedimage)
d->cachedimage = d->pixmap->toImage();
@@ -1101,7 +1103,7 @@ void QLabel::paintEvent(QPaintEvent *)
d->cachedimage->scaled(scaledSize,
Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
d->scaledpixmap = QPixmap::fromImage(std::move(scaledImage));
- d->scaledpixmap->setDevicePixelRatio(devicePixelRatio());
+ d->scaledpixmap->setDevicePixelRatio(dpr);
}
pix = *d->scaledpixmap;
} else
diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp
index 50e2cf7deb..b87d7e09cc 100644
--- a/src/widgets/widgets/qlineedit.cpp
+++ b/src/widgets/widgets/qlineedit.cpp
@@ -35,7 +35,7 @@
#endif
#include <private/qwidgettextcontrol_p.h>
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
#include "qaccessible.h"
#endif
#if QT_CONFIG(itemviews)
@@ -1341,7 +1341,7 @@ void QLineEdit::setReadOnly(bool enable)
QEvent event(QEvent::ReadOnlyChange);
QCoreApplication::sendEvent(this, &event);
update();
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessible::State changedState;
changedState.readOnly = true;
QAccessibleStateChangeEvent ev(this, changedState);
@@ -1811,6 +1811,8 @@ QVariant QLineEdit::inputMethodQuery(Qt::InputMethodQuery property, QVariant arg
{
Q_D(const QLineEdit);
switch(property) {
+ case Qt::ImEnabled:
+ return isEnabled();
case Qt::ImCursorRectangle:
return d->cursorRect();
case Qt::ImAnchorRectangle:
diff --git a/src/widgets/widgets/qlineedit_p.cpp b/src/widgets/widgets/qlineedit_p.cpp
index ae5fe80d4d..cdfe6df7f6 100644
--- a/src/widgets/widgets/qlineedit_p.cpp
+++ b/src/widgets/widgets/qlineedit_p.cpp
@@ -15,7 +15,7 @@
# include "qwidgetaction.h"
#endif
#include "qclipboard.h"
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
#include "qaccessible.h"
#endif
#ifndef QT_NO_IM
@@ -143,7 +143,7 @@ void QLineEditPrivate::_q_selectionChanged()
}
emit q->selectionChanged();
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessibleTextSelectionEvent ev(q, control->selectionStart(), control->selectionEnd());
ev.setCursorPosition(control->cursorPosition());
QAccessible::updateAccessibility(&ev);
diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp
index 4a199e0b18..10732aecbe 100644
--- a/src/widgets/widgets/qmainwindowlayout.cpp
+++ b/src/widgets/widgets/qmainwindowlayout.cpp
@@ -2798,7 +2798,7 @@ void QMainWindowLayout::hover(QLayoutItem *hoverTarget,
QDockAreaLayoutItem(parentLayout->takeAt(parentLayout->indexOf(dropTo))));
dropTo->setParent(floatingTabs);
- qCDebug(lcQpaDockWidgets) << "Wrapping" << w << "into floating tabs" << floatingTabs;
+ qCDebug(lcQpaDockWidgets) << "Wrapping" << widget << "into floating tabs" << floatingTabs;
w = floatingTabs;
}
diff --git a/src/widgets/widgets/qmainwindowlayout_p.h b/src/widgets/widgets/qmainwindowlayout_p.h
index 394a052a09..9196e8b269 100644
--- a/src/widgets/widgets/qmainwindowlayout_p.h
+++ b/src/widgets/widgets/qmainwindowlayout_p.h
@@ -43,7 +43,7 @@ QT_REQUIRE_CONFIG(mainwindow);
QT_BEGIN_NAMESPACE
-Q_DECLARE_LOGGING_CATEGORY(lcQpaDockWidgets);
+Q_DECLARE_EXPORTED_LOGGING_CATEGORY(lcQpaDockWidgets, Q_WIDGETS_EXPORT);
class QToolBar;
class QRubberBand;
diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp
index 8e62928f41..ff4236f4f1 100644
--- a/src/widgets/widgets/qmenu.cpp
+++ b/src/widgets/widgets/qmenu.cpp
@@ -12,10 +12,10 @@
#include "qevent.h"
#include "qtimer.h"
#include "qlayout.h"
-#include "qpainter.h"
+#include "qstylepainter.h"
#include <qpa/qplatformtheme.h>
#include "qapplication.h"
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
# include "qaccessible.h"
#endif
#if QT_CONFIG(effects)
@@ -215,13 +215,21 @@ void QMenuPrivate::syncPlatformMenu()
platformMenu->setEnabled(q->isEnabled());
}
+static QWidget *getParentWidget(const QAction *action)
+{
+ auto result = action->parent();
+ while (result && !qobject_cast<QWidget *>(result))
+ result = result->parent();
+ return static_cast<QWidget *>(result);
+}
+
void QMenuPrivate::copyActionToPlatformItem(const QAction *action, QPlatformMenuItem *item)
{
item->setText(action->text());
item->setIsSeparator(action->isSeparator());
if (action->isIconVisibleInMenu()) {
item->setIcon(action->icon());
- if (QWidget *w = action->parentWidget()) {
+ if (QWidget *w = getParentWidget(action)) {
QStyleOption opt;
opt.initFrom(w);
item->setIconSize(w->style()->pixelMetric(QStyle::PM_SmallIconSize, &opt, w));
@@ -1462,7 +1470,7 @@ void QMenuPrivate::activateAction(QAction *action, QAction::ActionEvent action_e
if (action_e == QAction::Hover) {
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
if (QAccessible::isActive()) {
int actionIndex = indexOf(action);
QAccessibleEvent focusEvent(q, QAccessible::Focus);
@@ -2315,6 +2323,15 @@ void QMenuPrivate::popup(const QPoint &p, QAction *atAction, PositionFunction po
lastContextMenu = contextMenu;
}
+ // Until QWidget::metric accepts the screen set on a widget (without having a window handle)
+ // we need to make sure we get a window handle. This must be done near here because
+ // we want the screen to be correctly set and items to be marked dirty.
+ // (and screen set could 'fail' on oldscreen == newScreen if created before causing the
+ // itemsDirty not to be set though needed to get the correct size on first show).
+ if (!windowHandle()) {
+ createWinId();
+ }
+
#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
@@ -2531,7 +2548,7 @@ void QMenuPrivate::popup(const QPoint &p, QAction *atAction, PositionFunction po
q->show();
}
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessibleEvent event(q, QAccessible::PopupMenuStart);
QAccessible::updateAccessibility(&event);
#endif
@@ -2660,7 +2677,7 @@ void QMenu::hideEvent(QHideEvent *)
if (d->eventLoop)
d->eventLoop->exit();
d->setCurrentAction(nullptr);
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessibleEvent event(this, QAccessible::PopupMenuEnd);
QAccessible::updateAccessibility(&event);
#endif
@@ -2686,7 +2703,7 @@ void QMenu::paintEvent(QPaintEvent *e)
{
Q_D(QMenu);
d->updateActionRects();
- QPainter p(this);
+ QStylePainter p(this);
QRegion emptyArea = QRegion(rect());
QStyleOptionMenuItem menuOpt;
@@ -2695,7 +2712,7 @@ void QMenu::paintEvent(QPaintEvent *e)
menuOpt.checkType = QStyleOptionMenuItem::NotCheckable;
menuOpt.maxIconWidth = 0;
menuOpt.reservedShortcutWidth = 0;
- style()->drawPrimitive(QStyle::PE_PanelMenu, &menuOpt, &p, this);
+ p.drawPrimitive(QStyle::PE_PanelMenu, menuOpt);
//calculate the scroll up / down rect
const int fw = style()->pixelMetric(QStyle::PM_MenuPanelWidth, nullptr, this);
@@ -2763,7 +2780,7 @@ void QMenu::paintEvent(QPaintEvent *e)
QStyleOptionMenuItem opt;
initStyleOption(&opt, action);
opt.rect = actionRect;
- style()->drawControl(QStyle::CE_MenuItem, &opt, &p, this);
+ p.drawControl(QStyle::CE_MenuItem, opt);
}
emptyArea -= QRegion(scrollUpTearOffRect);
@@ -2797,7 +2814,7 @@ void QMenu::paintEvent(QPaintEvent *e)
frame.state = QStyle::State_None;
frame.lineWidth = style()->pixelMetric(QStyle::PM_MenuPanelWidth, &frame);
frame.midLineWidth = 0;
- style()->drawPrimitive(QStyle::PE_FrameMenu, &frame, &p, this);
+ p.drawPrimitive(QStyle::PE_FrameMenu, frame);
}
//finally the rest of the spaces
@@ -2807,7 +2824,7 @@ void QMenu::paintEvent(QPaintEvent *e)
menuOpt.checkType = QStyleOptionMenuItem::NotCheckable;
menuOpt.rect = rect();
menuOpt.menuRect = rect();
- style()->drawControl(QStyle::CE_MenuEmptyArea, &menuOpt, &p, this);
+ p.drawControl(QStyle::CE_MenuEmptyArea, menuOpt);
}
#if QT_CONFIG(wheelevent)
@@ -3570,7 +3587,7 @@ void QMenu::internalDelayedPopup()
const QRect actionRect(d->actionRect(d->currentAction));
QPoint subMenuPos(mapToGlobal(QPoint(actionRect.right() + subMenuOffset + 1, actionRect.top())));
if (subMenuPos.x() > screen.right())
- subMenuPos.setX(QCursor::pos().x());
+ subMenuPos.setX(geometry().left());
const auto &subMenuActions = d->activeMenu->actions();
if (!subMenuActions.isEmpty()) {
diff --git a/src/widgets/widgets/qmenubar.cpp b/src/widgets/widgets/qmenubar.cpp
index 6a628ad8d4..15c6f521b3 100644
--- a/src/widgets/widgets/qmenubar.cpp
+++ b/src/widgets/widgets/qmenubar.cpp
@@ -6,7 +6,7 @@
#include <qstyle.h>
#include <qlayout.h>
#include <qapplication.h>
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
# include <qaccessible.h>
#endif
#include <qpainter.h>
@@ -495,14 +495,14 @@ void QMenuBarPrivate::_q_actionHovered()
Q_Q(QMenuBar);
if (QAction *action = qobject_cast<QAction *>(q->sender())) {
emit q->hovered(action);
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
if (QAccessible::isActive()) {
int actionIndex = actions.indexOf(action);
QAccessibleEvent focusEvent(q, QAccessible::Focus);
focusEvent.setChild(actionIndex);
QAccessible::updateAccessibility(&focusEvent);
}
-#endif //QT_NO_ACCESSIBILITY
+#endif // QT_CONFIG(accessibility)
}
}
diff --git a/src/widgets/widgets/qplaintextedit.cpp b/src/widgets/widgets/qplaintextedit.cpp
index 49be13cebc..cd9889e9ff 100644
--- a/src/widgets/widgets/qplaintextedit.cpp
+++ b/src/widgets/widgets/qplaintextedit.cpp
@@ -422,7 +422,7 @@ void QPlainTextEditPrivate::_q_cursorPositionChanged()
{
pageUpDownLastCursorYIsValid = false;
Q_Q(QPlainTextEdit);
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessibleTextCursorEvent ev(q, q->textCursor().position());
QAccessible::updateAccessibility(&ev);
#endif
@@ -2206,6 +2206,8 @@ QVariant QPlainTextEdit::inputMethodQuery(Qt::InputMethodQuery query, QVariant a
{
Q_D(const QPlainTextEdit);
switch (query) {
+ case Qt::ImEnabled:
+ return isEnabled();
case Qt::ImHints:
case Qt::ImInputItemClipRectangle:
return QWidget::inputMethodQuery(query);
diff --git a/src/widgets/widgets/qprogressbar.cpp b/src/widgets/widgets/qprogressbar.cpp
index b5eedde904..79cdecd22a 100644
--- a/src/widgets/widgets/qprogressbar.cpp
+++ b/src/widgets/widgets/qprogressbar.cpp
@@ -9,7 +9,7 @@
#include <qstylepainter.h>
#include <qstyleoption.h>
#include <private/qwidget_p.h>
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
#include <qaccessible.h>
#endif
#include <limits.h>
@@ -283,7 +283,7 @@ void QProgressBar::setValue(int value)
return;
d->value = value;
emit valueChanged(value);
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
if (isVisible()) {
QAccessibleValueChangeEvent event(this, value);
QAccessible::updateAccessibility(&event);
diff --git a/src/widgets/widgets/qpushbutton.cpp b/src/widgets/widgets/qpushbutton.cpp
index 081964b2cd..ec882db175 100644
--- a/src/widgets/widgets/qpushbutton.cpp
+++ b/src/widgets/widgets/qpushbutton.cpp
@@ -24,7 +24,7 @@
#include "qdialogbuttonbox.h"
#endif
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
#include "qaccessible.h"
#endif
@@ -334,7 +334,7 @@ void QPushButton::setDefault(bool enable)
}
#endif
update();
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessible::State s;
s.defaultButton = true;
QAccessibleStateChangeEvent event(this, s);
diff --git a/src/widgets/widgets/qscrollbar.cpp b/src/widgets/widgets/qscrollbar.cpp
index dce761923c..ed456c56b8 100644
--- a/src/widgets/widgets/qscrollbar.cpp
+++ b/src/widgets/widgets/qscrollbar.cpp
@@ -14,7 +14,7 @@
#endif
#include <QtCore/qelapsedtimer.h>
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
#include "qaccessible.h"
#endif
#include <limits.h>
diff --git a/src/widgets/widgets/qsizegrip.cpp b/src/widgets/widgets/qsizegrip.cpp
index 0e6ac5332a..8ffcb0081b 100644
--- a/src/widgets/widgets/qsizegrip.cpp
+++ b/src/widgets/widgets/qsizegrip.cpp
@@ -5,7 +5,7 @@
#include "qapplication.h"
#include "qevent.h"
-#include "qpainter.h"
+#include "qstylepainter.h"
#include "qwindow.h"
#include <qpa/qplatformwindow.h>
#include "qstyle.h"
@@ -212,11 +212,11 @@ void QSizeGrip::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
Q_D(QSizeGrip);
- QPainter painter(this);
+ QStylePainter painter(this);
QStyleOptionSizeGrip opt;
opt.initFrom(this);
opt.corner = d->m_corner;
- style()->drawControl(QStyle::CE_SizeGrip, &opt, &painter, this);
+ painter.drawControl(QStyle::CE_SizeGrip, opt);
}
/*!
diff --git a/src/widgets/widgets/qslider.cpp b/src/widgets/widgets/qslider.cpp
index 11904d49f4..e39521a2e9 100644
--- a/src/widgets/widgets/qslider.cpp
+++ b/src/widgets/widgets/qslider.cpp
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qslider.h"
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
#include "qaccessible.h"
#endif
#include "qapplication.h"
@@ -392,8 +392,6 @@ void QSlider::mouseMoveEvent(QMouseEvent *ev)
}
ev->accept();
int newPosition = d->pixelPosToRangeValue(d->pick(ev->position().toPoint()) - d->clickOffset);
- QStyleOptionSlider opt;
- initStyleOption(&opt);
setSliderPosition(newPosition);
}
diff --git a/src/widgets/widgets/qsplitter.cpp b/src/widgets/widgets/qsplitter.cpp
index 7dfc2a04fa..a954d6ce66 100644
--- a/src/widgets/widgets/qsplitter.cpp
+++ b/src/widgets/widgets/qsplitter.cpp
@@ -701,6 +701,11 @@ void QSplitterPrivate::setSizes_helper(const QList<int> &sizes, bool clampNegati
doResize();
}
+/*
+ Used by various methods inserting a widget to find out if we need to show the widget
+ explicitly, which we have to if the splitter is already visible, and if the widget hasn't
+ been explicitly hidden before inserting it.
+*/
bool QSplitterPrivate::shouldShowWidget(const QWidget *w) const
{
Q_Q(const QSplitter);
@@ -1144,7 +1149,7 @@ QWidget *QSplitter::replaceWidget(int index, QWidget *widget)
QBoolBlocker b(d->blockChildAdd);
const QRect geom = current->geometry();
- const bool shouldShow = d->shouldShowWidget(current);
+ const bool wasHidden = current->isHidden();
s->widget = widget;
current->setParent(nullptr);
@@ -1154,7 +1159,10 @@ QWidget *QSplitter::replaceWidget(int index, QWidget *widget)
// should not change. Only set the geometry on the new widget
widget->setGeometry(geom);
widget->lower();
- widget->setVisible(shouldShow);
+ if (wasHidden)
+ widget->hide();
+ else if (d->shouldShowWidget(widget))
+ widget->show();
return current;
}
diff --git a/src/widgets/widgets/qstatusbar.cpp b/src/widgets/widgets/qstatusbar.cpp
index 3ab7bee5ad..d5ae7d5cd2 100644
--- a/src/widgets/widgets/qstatusbar.cpp
+++ b/src/widgets/widgets/qstatusbar.cpp
@@ -18,7 +18,7 @@
#include "qmainwindow.h"
#endif
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
#include "qaccessible.h"
#endif
@@ -583,7 +583,7 @@ void QStatusBar::hideOrShow()
emit messageChanged(d->tempItem);
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
if (QAccessible::isActive()) {
QAccessibleEvent event(this, QAccessible::NameChanged);
QAccessible::updateAccessibility(&event);
diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp
index ed0b5f2f21..29b568f29d 100644
--- a/src/widgets/widgets/qtabbar.cpp
+++ b/src/widgets/widgets/qtabbar.cpp
@@ -21,7 +21,7 @@
#include "qwhatsthis.h"
#endif
#include "private/qtextengine_p.h"
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
#include "qaccessible.h"
#endif
#ifdef Q_OS_MACOS
@@ -390,7 +390,7 @@ void QTabBarPrivate::init()
#endif
q->setFocusPolicy(Qt::TabFocus);
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
leftB->setAccessibleName(QTabBar::tr("Scroll Left"));
rightB->setAccessibleName(QTabBar::tr("Scroll Right"));
#endif
@@ -926,7 +926,7 @@ int QTabBar::addTab(const QIcon& icon, const QString &text)
/*!
Inserts a new tab with text \a text at position \a index. If \a
- index is out of range, the new tab is appened. Returns the new
+ index is out of range, the new tab is appended. Returns the new
tab's index.
*/
int QTabBar::insertTab(int index, const QString &text)
@@ -1052,8 +1052,6 @@ void QTabBar::removeTab(int index)
break;
case SelectLeftTab:
newIndex = qBound(d->firstVisible, index-1, d->lastVisible);
- if (newIndex < 0)
- newIndex = 0;
break;
default:
break;
@@ -1064,6 +1062,9 @@ void QTabBar::removeTab(int index)
int bump = d->tabList.at(newIndex)->lastTab;
setCurrentIndex(newIndex);
d->tabList.at(newIndex)->lastTab = bump;
+ } else {
+ // we had a valid current index, but there are no visible tabs left
+ emit currentChanged(-1);
}
} else {
emit currentChanged(-1);
@@ -1404,7 +1405,7 @@ void QTabBar::setCurrentIndex(int index)
// If the size hint depends on whether the tab is selected (for instance a style
// sheet rule that sets a bold font on the 'selected' tab) then we need to
// re-layout the entire tab bar. To minimize the cost, do that only if the
- // size hint changes for the tab that becomes the current tab (the old curent tab
+ // size hint changes for the tab that becomes the current tab (the old current tab
// will most certainly do the same). QTBUG-6905
if (tabRect(index).size() != tabSizeHint(index))
d->layoutTabs();
@@ -1415,7 +1416,7 @@ void QTabBar::setCurrentIndex(int index)
d->layoutTab(oldIndex);
}
d->layoutTab(index);
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
if (QAccessible::isActive()) {
if (hasFocus()) {
QAccessibleEvent focusEvent(this, QAccessible::Focus);
@@ -1921,8 +1922,6 @@ void QTabBarPrivate::calculateFirstLastVisible(int index, bool visible, bool rem
break;
}
}
- if (firstVisible < 0)
- firstVisible = 0;
}
if (remove || (index == lastVisible)) {
lastVisible = -1;
@@ -2804,7 +2803,7 @@ QWidget *QTabBar::tabButton(int index, ButtonPosition position) const
return nullptr;
}
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
/*!
Sets the accessibleName of the tab at position \a index to \a name.
*/
@@ -2830,7 +2829,7 @@ QString QTabBar::accessibleTabName(int index) const
return tab->accessibleName;
return QString();
}
-#endif // QT_NO_ACCESSIBILITY
+#endif // QT_CONFIG(accessibility)
CloseButton::CloseButton(QWidget *parent)
: QAbstractButton(parent)
diff --git a/src/widgets/widgets/qtabbar.h b/src/widgets/widgets/qtabbar.h
index 17e655120c..2d3179e2d0 100644
--- a/src/widgets/widgets/qtabbar.h
+++ b/src/widgets/widgets/qtabbar.h
@@ -140,7 +140,7 @@ public:
bool changeCurrentOnDrag() const;
void setChangeCurrentOnDrag(bool change);
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QString accessibleTabName(int index) const;
void setAccessibleTabName(int index, const QString &name);
#endif
@@ -179,7 +179,7 @@ protected:
void timerEvent(QTimerEvent *event) override;
virtual void initStyleOption(QStyleOptionTab *option, int tabIndex) const;
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
friend class QAccessibleTabBar;
#endif
private:
diff --git a/src/widgets/widgets/qtabbar_p.h b/src/widgets/widgets/qtabbar_p.h
index 71ac772182..e38b1ef6f9 100644
--- a/src/widgets/widgets/qtabbar_p.h
+++ b/src/widgets/widgets/qtabbar_p.h
@@ -119,7 +119,7 @@ public:
#if QT_CONFIG(whatsthis)
QString whatsThis;
#endif
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QString accessibleName;
#endif
QIcon icon;
diff --git a/src/widgets/widgets/qtextbrowser.cpp b/src/widgets/widgets/qtextbrowser.cpp
index 0273331c40..2bab2efc61 100644
--- a/src/widgets/widgets/qtextbrowser.cpp
+++ b/src/widgets/widgets/qtextbrowser.cpp
@@ -288,12 +288,11 @@ void QTextBrowserPrivate::setSource(const QUrl &url, QTextDocument::ResourceType
} else if (data.userType() == QMetaType::QByteArray) {
QByteArray ba = data.toByteArray();
if (type == QTextDocument::HtmlResource) {
- auto encoding = QStringConverter::encodingForHtml(ba);
- if (!encoding)
+ auto decoder = QStringDecoder::decoderForHtml(ba);
+ if (!decoder.isValid())
// fall back to utf8
- encoding = QStringDecoder::Utf8;
- QStringDecoder toUtf16(*encoding);
- txt = toUtf16(ba);
+ decoder = QStringDecoder(QStringDecoder::Utf8);
+ txt = decoder(ba);
} else {
txt = QString::fromUtf8(ba);
}
diff --git a/src/widgets/widgets/qtextedit.cpp b/src/widgets/widgets/qtextedit.cpp
index c11b87c6bb..b3a8963431 100644
--- a/src/widgets/widgets/qtextedit.cpp
+++ b/src/widgets/widgets/qtextedit.cpp
@@ -22,7 +22,7 @@
#endif
#include <qstyle.h>
#include <qtimer.h>
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
#include <qaccessible.h>
#endif
#include "private/qtextdocumentlayout_p.h"
@@ -192,7 +192,7 @@ void QTextEditPrivate::_q_cursorPositionChanged()
{
Q_Q(QTextEdit);
emit q->cursorPositionChanged();
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessibleTextCursorEvent event(q, q->textCursor().position());
QAccessible::updateAccessibility(&event);
#endif
@@ -1803,6 +1803,8 @@ QVariant QTextEdit::inputMethodQuery(Qt::InputMethodQuery query, QVariant argume
{
Q_D(const QTextEdit);
switch (query) {
+ case Qt::ImEnabled:
+ return isEnabled();
case Qt::ImHints:
case Qt::ImInputItemClipRectangle:
return QWidget::inputMethodQuery(query);
@@ -2083,7 +2085,7 @@ void QTextEdit::setCursorWidth(int width)
\brief whether the text edit accepts rich text insertions by the user
\since 4.1
- When this propery is set to false text edit will accept only
+ When this property is set to false text edit will accept only
plain text input from the user. For example through clipboard or drag and drop.
This property's default is true.
diff --git a/src/widgets/widgets/qtoolbararealayout.cpp b/src/widgets/widgets/qtoolbararealayout.cpp
index 09929e7234..adddfbc529 100644
--- a/src/widgets/widgets/qtoolbararealayout.cpp
+++ b/src/widgets/widgets/qtoolbararealayout.cpp
@@ -1328,6 +1328,10 @@ bool QToolBarAreaLayout::restoreState(QDataStream &stream, const QList<QToolBar*
}
if (applyingLayout) {
+ // Clear the previous widgetItem for the toolBar, so that it's
+ // assigned correctly in QWidgetItemV2 constructor.
+ auto *toolBarPrivate = QWidgetPrivate::get(toolBar);
+ toolBarPrivate->widgetItem = nullptr;
item.widgetItem = new QWidgetItemV2(toolBar);
toolBar->setOrientation(floating ? ((shown & 2) ? Qt::Vertical : Qt::Horizontal) : dock.o);
toolBar->setVisible(shown & 1);
diff --git a/src/widgets/widgets/qwidgetlinecontrol.cpp b/src/widgets/widgets/qwidgetlinecontrol.cpp
index 6805492143..e95509ae89 100644
--- a/src/widgets/widgets/qwidgetlinecontrol.cpp
+++ b/src/widgets/widgets/qwidgetlinecontrol.cpp
@@ -13,7 +13,7 @@
#endif
#include <qpa/qplatformtheme.h>
#include <qstylehints.h>
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
#include "qaccessible.h"
#endif
@@ -749,7 +749,7 @@ void QWidgetLineControl::internalSetText(const QString &txt, int pos, bool edite
m_textDirty = (oldText != m_text);
const bool changed = finishChange(-1, true, edited);
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
if (changed) {
if (oldText.isEmpty()) {
QAccessibleTextInsertEvent event(accessibleObject(), 0, txt);
@@ -819,7 +819,7 @@ void QWidgetLineControl::internalInsert(const QString &s)
QString ms = maskString(m_cursor, s);
if (ms.isEmpty() && !s.isEmpty())
emit inputRejected();
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessibleTextInsertEvent insertEvent(accessibleObject(), m_cursor, ms);
QAccessible::updateAccessibility(&insertEvent);
#endif
@@ -831,14 +831,14 @@ void QWidgetLineControl::internalInsert(const QString &s)
m_cursor += ms.length();
m_cursor = nextMaskBlank(m_cursor);
m_textDirty = true;
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessibleTextCursorEvent event(accessibleObject(), m_cursor);
QAccessible::updateAccessibility(&event);
#endif
} else {
int remaining = m_maxLength - m_text.length();
if (remaining != 0) {
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessibleTextInsertEvent insertEvent(accessibleObject(), m_cursor, s);
QAccessible::updateAccessibility(&insertEvent);
#endif
@@ -871,7 +871,7 @@ void QWidgetLineControl::internalDelete(bool wasBackspace)
addCommand(Command(SetSelection, m_cursor, u'\0', m_selstart, m_selend));
addCommand(Command((CommandType)((m_maskData ? 2 : 0) + (wasBackspace ? Remove : Delete)),
m_cursor, m_text.at(m_cursor), -1, -1));
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessibleTextRemoveEvent event(accessibleObject(), m_cursor, m_text.at(m_cursor));
QAccessible::updateAccessibility(&event);
#endif
@@ -912,7 +912,7 @@ void QWidgetLineControl::removeSelectedText()
for (i = m_selend-1; i >= m_selstart; --i)
addCommand (Command(RemoveSelection, i, m_text.at(i), -1, -1));
}
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessibleTextRemoveEvent event(accessibleObject(), m_selstart, m_text.mid(m_selstart, m_selend - m_selstart));
QAccessible::updateAccessibility(&event);
#endif
@@ -1397,7 +1397,7 @@ void QWidgetLineControl::emitCursorPositionChanged()
const int oldLast = m_lastCursorPos;
m_lastCursorPos = m_cursor;
cursorPositionChanged(oldLast, m_cursor);
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
// otherwise we send a selection update which includes the cursor
if (!hasSelectedText()) {
QAccessibleTextCursorEvent event(accessibleObject(), m_cursor);
diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp
index e73975f9e2..cec18dbe69 100644
--- a/src/widgets/widgets/qwidgettextcontrol.cpp
+++ b/src/widgets/widgets/qwidgettextcontrol.cpp
@@ -24,6 +24,7 @@
#endif
#include "qtextdocument.h"
#include "private/qtextdocument_p.h"
+#include "private/qtextdocumentfragment_p.h"
#include "qtextlist.h"
#include "private/qwidgettextcontrol_p.h"
#if QT_CONFIG(style_stylesheet)
@@ -578,7 +579,7 @@ void QWidgetTextControlPrivate::selectionChanged(bool forceEmitSelectionChanged
Q_Q(QWidgetTextControl);
if (forceEmitSelectionChanged) {
emit q->selectionChanged();
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
if (q->parent() && q->parent()->isWidgetType()) {
QAccessibleTextSelectionEvent ev(q->parent(), cursor.anchor(), cursor.position());
QAccessible::updateAccessibility(&ev);
@@ -601,7 +602,7 @@ void QWidgetTextControlPrivate::selectionChanged(bool forceEmitSelectionChanged
&& (cursor.position() != lastSelectionPosition
|| cursor.anchor() != lastSelectionAnchor)))) {
emit q->selectionChanged();
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
if (q->parent() && q->parent()->isWidgetType()) {
QAccessibleTextSelectionEvent ev(q->parent(), cursor.anchor(), cursor.position());
QAccessible::updateAccessibility(&ev);
@@ -642,7 +643,7 @@ void QWidgetTextControlPrivate::_q_emitCursorPosChanged(const QTextCursor &someC
void QWidgetTextControlPrivate::_q_contentsChanged(int from, int charsRemoved, int charsAdded)
{
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
Q_Q(QWidgetTextControl);
if (QAccessible::isActive() && q->parent() && q->parent()->isWidgetType()) {
@@ -2697,6 +2698,13 @@ void QWidgetTextControl::insertFromMimeData(const QMimeData *source)
bool hasData = false;
QTextDocumentFragment fragment;
+#if QT_CONFIG(textmarkdownreader)
+ if (source->formats().first() == "text/markdown"_L1) {
+ auto s = QString::fromUtf8(source->data("text/markdown"_L1));
+ fragment = QTextDocumentFragment::fromMarkdown(s);
+ hasData = true;
+ } else
+#endif
#ifndef QT_NO_TEXTHTMLPARSER
if (source->hasFormat("application/x-qrichtext"_L1) && d->acceptRichText) {
// x-qrichtext is always UTF-8 (taken from Qt3 since we don't use it anymore).
@@ -2707,16 +2715,15 @@ void QWidgetTextControl::insertFromMimeData(const QMimeData *source)
} else if (source->hasHtml() && d->acceptRichText) {
fragment = QTextDocumentFragment::fromHtml(source->html(), d->doc);
hasData = true;
- } else {
- QString text = source->text();
+ }
+#endif // QT_NO_TEXTHTMLPARSER
+ if (!hasData) {
+ const QString text = source->text();
if (!text.isNull()) {
fragment = QTextDocumentFragment::fromPlainText(text);
hasData = true;
}
}
-#else
- fragment = QTextDocumentFragment::fromPlainText(source->text());
-#endif // QT_NO_TEXTHTMLPARSER
if (hasData)
d->cursor.insertFragment(fragment);
@@ -3433,9 +3440,12 @@ void QUnicodeControlCharacterMenu::menuActionTriggered()
QStringList QTextEditMimeData::formats() const
{
if (!fragment.isEmpty())
- return QStringList() << QString::fromLatin1("text/plain") << QString::fromLatin1("text/html")
+ return QStringList() << u"text/plain"_s << u"text/html"_s
+#if QT_CONFIG(textmarkdownwriter)
+ << u"text/markdown"_s
+#endif
#ifndef QT_NO_TEXTODFWRITER
- << QString::fromLatin1("application/vnd.oasis.opendocument.text")
+ << u"application/vnd.oasis.opendocument.text"_s
#endif
;
else
@@ -3455,6 +3465,9 @@ void QTextEditMimeData::setup() const
#ifndef QT_NO_TEXTHTMLPARSER
that->setData("text/html"_L1, fragment.toHtml().toUtf8());
#endif
+#if QT_CONFIG(textmarkdownwriter)
+ that->setData("text/markdown"_L1, fragment.toMarkdown().toUtf8());
+#endif
#ifndef QT_NO_TEXTODFWRITER
{
QBuffer buffer;