diff options
Diffstat (limited to 'src/widgets')
| -rw-r--r-- | src/widgets/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/widgets/accessible/itemviews.cpp | 31 | ||||
| -rw-r--r-- | src/widgets/dialogs/qcolordialog.cpp | 15 | ||||
| -rw-r--r-- | src/widgets/itemviews/qabstractitemview.cpp | 41 | ||||
| -rw-r--r-- | src/widgets/itemviews/qabstractitemview_p.h | 12 | ||||
| -rw-r--r-- | src/widgets/itemviews/qlistview.cpp | 16 | ||||
| -rw-r--r-- | src/widgets/itemviews/qlistview_p.h | 4 | ||||
| -rw-r--r-- | src/widgets/itemviews/qtableview.cpp | 6 | ||||
| -rw-r--r-- | src/widgets/itemviews/qtableview_p.h | 5 | ||||
| -rw-r--r-- | src/widgets/itemviews/qtreeview.cpp | 10 | ||||
| -rw-r--r-- | src/widgets/itemviews/qtreeview_p.h | 4 | ||||
| -rw-r--r-- | src/widgets/kernel/qtooltip.cpp | 65 | ||||
| -rw-r--r-- | src/widgets/kernel/qtooltip_p.h | 74 | ||||
| -rw-r--r-- | src/widgets/widgets/qmenu.cpp | 6 |
14 files changed, 215 insertions, 76 deletions
diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt index d43b6ec4fb2..c47e3bee13c 100644 --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -412,7 +412,7 @@ qt_internal_extend_target(Widgets CONDITION QT_FEATURE_shortcut qt_internal_extend_target(Widgets CONDITION QT_FEATURE_tooltip SOURCES - kernel/qtooltip.cpp kernel/qtooltip.h + kernel/qtooltip.cpp kernel/qtooltip.h kernel/qtooltip_p.h ) qt_internal_extend_target(Widgets CONDITION QT_FEATURE_whatsthis diff --git a/src/widgets/accessible/itemviews.cpp b/src/widgets/accessible/itemviews.cpp index cc3a230f9b4..ba941012dd7 100644 --- a/src/widgets/accessible/itemviews.cpp +++ b/src/widgets/accessible/itemviews.cpp @@ -99,6 +99,21 @@ QHeaderView *QAccessibleTable::verticalHeader() const return header; } +// Normally cellAt takes row/column in the range +// [0 .. rowCount()) +// [0 .. columnCount()) +// +// As an extension we allow clients to ask for headers +// +// * Has both vertical and horizontal headers: +// (-1,-1) -> corner button +// * Has column headers: +// (-1, column) -> column header for column \a column +// * has row headers +// (row, -1) -> row header for row \a row +// +// If asking for a header that does not exist, The invalid +// index warning is logged, and nullptr is returned. QAccessibleInterface *QAccessibleTable::cellAt(int row, int column) const { const QAbstractItemView *theView = view(); @@ -107,6 +122,22 @@ QAccessibleInterface *QAccessibleTable::cellAt(int row, int column) const return nullptr; Q_ASSERT(role() != QAccessible::List); Q_ASSERT(role() != QAccessible::Tree); + + const int vHeader = verticalHeader() ? 1 : 0; + const int hHeader = horizontalHeader() ? 1 : 0; + + const int doHHeader = ((row == -1) && hHeader); + const int doVHeader = ((column == -1) && vHeader); + + if (doVHeader && doHHeader) + return child(0); + + if (doVHeader) + return child((row + hHeader) * (columnCount() + vHeader) + (column + vHeader)); + + if (doHHeader) + return child((row + hHeader) * (columnCount() + vHeader) + (column + vHeader)); + QModelIndex index = theModel->index(row, column, theView->rootIndex()); if (Q_UNLIKELY(!index.isValid())) { qWarning() << "QAccessibleTable::cellAt: invalid index: " << index << " for " << theView; diff --git a/src/widgets/dialogs/qcolordialog.cpp b/src/widgets/dialogs/qcolordialog.cpp index d51c408ab5c..ce46170bba5 100644 --- a/src/widgets/dialogs/qcolordialog.cpp +++ b/src/widgets/dialogs/qcolordialog.cpp @@ -662,7 +662,7 @@ private: int val2y(int val); void setVal(int v); - QPixmap *pix; + QPixmap pix; }; @@ -682,14 +682,12 @@ QColorLuminancePicker::QColorLuminancePicker(QWidget* parent) :QWidget(parent) { hue = 100; val = 100; sat = 100; - pix = nullptr; // setAttribute(WA_NoErase, true); setFocusPolicy(Qt::StrongFocus); } QColorLuminancePicker::~QColorLuminancePicker() { - delete pix; } void QColorLuminancePicker::keyPressEvent(QKeyEvent *event) @@ -725,7 +723,7 @@ void QColorLuminancePicker::setVal(int v) if (val == v) return; val = qMax(0, qMin(v,255)); - delete pix; pix=nullptr; + pix = QPixmap(); repaint(); emit newHsv(hue, sat, val); } @@ -744,8 +742,7 @@ void QColorLuminancePicker::paintEvent(QPaintEvent *) QRect r(0, foff, w, height() - 2*foff); int wi = r.width() - 2; int hi = r.height() - 2; - if (!pix || pix->height() != hi || pix->width() != wi) { - delete pix; + if (pix.isNull() || pix.height() != hi || pix.width() != wi) { QImage img(wi, hi, QImage::Format_RGB32); int y; uint *pixel = (uint *) img.scanLine(0); @@ -754,10 +751,10 @@ void QColorLuminancePicker::paintEvent(QPaintEvent *) std::fill(pixel, end, QColor::fromHsv(hue, sat, y2val(y + coff)).rgb()); pixel = end; } - pix = new QPixmap(QPixmap::fromImage(img)); + pix = QPixmap::fromImage(img); } QPainter p(this); - p.drawPixmap(1, coff, *pix); + p.drawPixmap(1, coff, pix); const QPalette &g = palette(); qDrawShadePanel(&p, r, g, true); p.setPen(g.windowText().color()); @@ -773,7 +770,7 @@ void QColorLuminancePicker::setCol(int h, int s , int v) val = v; hue = h; sat = s; - delete pix; pix=nullptr; + pix = QPixmap(); repaint(); } diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index 6288aae096a..05233ba5801 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -172,6 +172,43 @@ void QAbstractItemViewPrivate::checkMouseMove(const QPersistentModelIndex &index } } +#if QT_CONFIG(accessibility) +void QAbstractItemViewPrivate::updateItemAccessibility(const QModelIndex &index, + const QList<int> &roles) +{ + Q_Q(QAbstractItemView); + + if (!QAccessible::isActive()) + return; + + const int childIndex = accessibleChildIndex(index); + if (childIndex < 0) + return; + + // see QAccessibleTableCell for how role data are mapped to the a11y layer + + for (int role : roles) { + if (role == Qt::AccessibleTextRole + || (role == Qt::DisplayRole + && index.data(Qt::AccessibleTextRole).toString().isEmpty())) { + QAccessibleEvent event(q, QAccessible::NameChanged); + event.setChild(childIndex); + QAccessible::updateAccessibility(&event); + } else if (role == Qt::AccessibleDescriptionRole) { + QAccessibleEvent event(q, QAccessible::DescriptionChanged); + event.setChild(childIndex); + QAccessible::updateAccessibility(&event); + } else if (role == Qt::CheckStateRole) { + QAccessible::State state; + state.checked = true; + QAccessibleStateChangeEvent event(q, state); + event.setChild(childIndex); + QAccessible::updateAccessibility(&event); + } + } +} +#endif + #if QT_CONFIG(gestures) && QT_CONFIG(scroller) // stores and restores the selection and current item when flicking @@ -3495,6 +3532,10 @@ void QAbstractItemView::dataChanged(const QModelIndex &topLeft, const QModelInde accessibleEvent.setLastRow(bottomRight.row()); accessibleEvent.setLastColumn(bottomRight.column()); QAccessible::updateAccessibility(&accessibleEvent); + + // send accessibility events as needed when current item is modified + if (topLeft == bottomRight && topLeft == currentIndex()) + d->updateItemAccessibility(topLeft, roles); } #endif d->updateGeometry(); diff --git a/src/widgets/itemviews/qabstractitemview_p.h b/src/widgets/itemviews/qabstractitemview_p.h index 60799fb8a50..f9e899d7fc8 100644 --- a/src/widgets/itemviews/qabstractitemview_p.h +++ b/src/widgets/itemviews/qabstractitemview_p.h @@ -272,6 +272,18 @@ public: return isIndexValid(index) && isIndexSelectable(index); } +#if QT_CONFIG(accessibility) + virtual int accessibleChildIndex(const QModelIndex &index) const + { + Q_UNUSED(index); + return -1; + } +#endif + +#if QT_CONFIG(accessibility) + void updateItemAccessibility(const QModelIndex &index, const QList<int> &roles); +#endif + // reimplemented from QAbstractScrollAreaPrivate QPoint contentsOffset() const override { Q_Q(const QAbstractItemView); diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp index e245f98151b..50b6034500d 100644 --- a/src/widgets/itemviews/qlistview.cpp +++ b/src/widgets/itemviews/qlistview.cpp @@ -1959,6 +1959,14 @@ bool QListViewPrivate::dropOn(QDropEvent *event, int *dropRow, int *dropCol, QMo } #endif +#if QT_CONFIG(accessibility) +int QListViewPrivate::accessibleChildIndex(const QModelIndex &index) const +{ + Q_Q(const QListView); + return q->visualIndex(index); +} +#endif + void QListViewPrivate::removeCurrentAndDisabled(QList<QModelIndex> *indexes, const QModelIndex ¤t) const { @@ -3397,11 +3405,12 @@ void QIconModeViewBase::updateContentsSize() */ void QListView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) { + Q_D(const QListView); QAbstractItemView::currentChanged(current, previous); #if QT_CONFIG(accessibility) if (QAccessible::isActive()) { if (current.isValid() && hasFocus()) { - int entry = visualIndex(current); + int entry = d->accessibleChildIndex(current); QAccessibleEvent event(this, QAccessible::Focus); event.setChild(entry); QAccessible::updateAccessibility(&event); @@ -3417,18 +3426,19 @@ void QListView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) { #if QT_CONFIG(accessibility) + Q_D(const QListView); if (QAccessible::isActive()) { // ### does not work properly for selection ranges. QModelIndex sel = selected.indexes().value(0); if (sel.isValid()) { - int entry = visualIndex(sel); + int entry = d->accessibleChildIndex(sel); QAccessibleEvent event(this, QAccessible::SelectionAdd); event.setChild(entry); QAccessible::updateAccessibility(&event); } QModelIndex desel = deselected.indexes().value(0); if (desel.isValid()) { - int entry = visualIndex(desel); + int entry = d->accessibleChildIndex(desel); QAccessibleEvent event(this, QAccessible::SelectionRemove); event.setChild(entry); QAccessible::updateAccessibility(&event); diff --git a/src/widgets/itemviews/qlistview_p.h b/src/widgets/itemviews/qlistview_p.h index 4475fa5461f..7e36887a65c 100644 --- a/src/widgets/itemviews/qlistview_p.h +++ b/src/widgets/itemviews/qlistview_p.h @@ -346,6 +346,10 @@ public: bool dropOn(QDropEvent *event, int *row, int *col, QModelIndex *index) override; #endif +#if QT_CONFIG(accessibility) + int accessibleChildIndex(const QModelIndex &index) const override; +#endif + inline void setGridSize(const QSize &size) { grid = size; } inline QSize gridSize() const { return grid; } inline void setWrapping(bool b) { wrap = b; } diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp index 40e3fcaf91b..2d28b3d4a81 100644 --- a/src/widgets/itemviews/qtableview.cpp +++ b/src/widgets/itemviews/qtableview.cpp @@ -3593,7 +3593,7 @@ void QTableView::currentChanged(const QModelIndex ¤t, const QModelIndex &p if (QAccessible::isActive()) { if (current.isValid() && hasFocus()) { Q_D(QTableView); - int entry = d->accessibleTable2Index(current); + int entry = d->accessibleChildIndex(current); QAccessibleEvent event(this, QAccessible::Focus); event.setChild(entry); QAccessible::updateAccessibility(&event); @@ -3616,14 +3616,14 @@ void QTableView::selectionChanged(const QItemSelection &selected, // ### does not work properly for selection ranges. QModelIndex sel = selected.indexes().value(0); if (sel.isValid()) { - int entry = d->accessibleTable2Index(sel); + int entry = d->accessibleChildIndex(sel); QAccessibleEvent event(this, QAccessible::SelectionAdd); event.setChild(entry); QAccessible::updateAccessibility(&event); } QModelIndex desel = deselected.indexes().value(0); if (desel.isValid()) { - int entry = d->accessibleTable2Index(desel); + int entry = d->accessibleChildIndex(desel); QAccessibleEvent event(this, QAccessible::SelectionRemove); event.setChild(entry); QAccessible::updateAccessibility(&event); diff --git a/src/widgets/itemviews/qtableview_p.h b/src/widgets/itemviews/qtableview_p.h index 8ddb8e797a9..9a7ce229880 100644 --- a/src/widgets/itemviews/qtableview_p.h +++ b/src/widgets/itemviews/qtableview_p.h @@ -141,11 +141,14 @@ public: QStyleOptionViewItem::ViewItemPosition viewItemPosition(const QModelIndex &index) const; - inline int accessibleTable2Index(const QModelIndex &index) const { +#if QT_CONFIG(accessibility) + inline int accessibleChildIndex(const QModelIndex &index) const override + { const int vHeader = verticalHeader ? 1 : 0; return (index.row() + (horizontalHeader ? 1 : 0)) * (index.model()->columnCount() + vHeader) + index.column() + vHeader; } +#endif int sectionSpanEndLogical(const QHeaderView *header, int logical, int span) const; int sectionSpanSize(const QHeaderView *header, int logical, int span) const; diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp index e38d78b72f8..570566793dc 100644 --- a/src/widgets/itemviews/qtreeview.cpp +++ b/src/widgets/itemviews/qtreeview.cpp @@ -4083,13 +4083,15 @@ void QTreeViewPrivate::sortIndicatorChanged(int column, Qt::SortOrder order) model->sort(column, order); } -int QTreeViewPrivate::accessibleTree2Index(const QModelIndex &index) const +#if QT_CONFIG(accessibility) +int QTreeViewPrivate::accessibleChildIndex(const QModelIndex &index) const { Q_Q(const QTreeView); // Note that this will include the header, even if its hidden. return (q->visualIndex(index) + (q->header() ? 1 : 0)) * index.model()->columnCount() + index.column(); } +#endif void QTreeViewPrivate::updateIndentationFromStyle() { @@ -4116,7 +4118,7 @@ void QTreeView::currentChanged(const QModelIndex ¤t, const QModelIndex &pr Q_D(QTreeView); QAccessibleEvent event(this, QAccessible::Focus); - event.setChild(d->accessibleTree2Index(current)); + event.setChild(d->accessibleChildIndex(current)); QAccessible::updateAccessibility(&event); } #endif @@ -4136,7 +4138,7 @@ void QTreeView::selectionChanged(const QItemSelection &selected, // ### does not work properly for selection ranges. QModelIndex sel = selected.indexes().value(0); if (sel.isValid()) { - int entry = d->accessibleTree2Index(sel); + int entry = d->accessibleChildIndex(sel); Q_ASSERT(entry >= 0); QAccessibleEvent event(this, QAccessible::SelectionAdd); event.setChild(entry); @@ -4144,7 +4146,7 @@ void QTreeView::selectionChanged(const QItemSelection &selected, } QModelIndex desel = deselected.indexes().value(0); if (desel.isValid()) { - int entry = d->accessibleTree2Index(desel); + int entry = d->accessibleChildIndex(desel); Q_ASSERT(entry >= 0); QAccessibleEvent event(this, QAccessible::SelectionRemove); event.setChild(entry); diff --git a/src/widgets/itemviews/qtreeview_p.h b/src/widgets/itemviews/qtreeview_p.h index 5a4e057901c..34db2fcdacb 100644 --- a/src/widgets/itemviews/qtreeview_p.h +++ b/src/widgets/itemviews/qtreeview_p.h @@ -234,7 +234,9 @@ public: return (viewIndex(index) + (header ? 1 : 0)) * model->columnCount()+index.column(); } - int accessibleTree2Index(const QModelIndex &index) const; +#if QT_CONFIG(accessibility) + int accessibleChildIndex(const QModelIndex &index) const override; +#endif void updateIndentationFromStyle(); diff --git a/src/widgets/kernel/qtooltip.cpp b/src/widgets/kernel/qtooltip.cpp index fa17c94a23f..3417d93d587 100644 --- a/src/widgets/kernel/qtooltip.cpp +++ b/src/widgets/kernel/qtooltip.cpp @@ -29,6 +29,7 @@ #include <qtooltip.h> #include <QtCore/qbasictimer.h> +#include <QtWidgets/private/qtooltip_p.h> QT_BEGIN_NAMESPACE @@ -93,57 +94,6 @@ using namespace Qt::StringLiterals; \sa QWidget::toolTip, QAction::toolTip */ -class QTipLabel : public QLabel -{ - Q_OBJECT -public: - QTipLabel(const QString &text, const QPoint &pos, QWidget *w, int msecDisplayTime); - ~QTipLabel(); - static QTipLabel *instance; - - void adjustTooltipScreen(const QPoint &pos); - void updateSize(const QPoint &pos); - - bool eventFilter(QObject *, QEvent *) override; - - QBasicTimer hideTimer, expireTimer; - - bool fadingOut; - - void reuseTip(const QString &text, int msecDisplayTime, const QPoint &pos); - void hideTip(); - void hideTipImmediately(); - void setTipRect(QWidget *w, const QRect &r); - void restartExpireTimer(int msecDisplayTime); - bool tipChanged(const QPoint &pos, const QString &text, QObject *o); - void placeTip(const QPoint &pos, QWidget *w); - - static QScreen *getTipScreen(const QPoint &pos, QWidget *w); -protected: - void timerEvent(QTimerEvent *e) override; - void paintEvent(QPaintEvent *e) override; - void mouseMoveEvent(QMouseEvent *e) override; - void resizeEvent(QResizeEvent *e) override; - -#if QT_CONFIG(style_stylesheet) -public slots: - /** \internal - Cleanup the _q_stylesheet_parent property. - */ - void styleSheetParentDestroyed() { - setProperty("_q_stylesheet_parent", QVariant()); - styleSheetParent = nullptr; - } - -private: - QWidget *styleSheetParent; -#endif - -private: - QWidget *widget; - QRect rect; -}; - QTipLabel *QTipLabel::instance = nullptr; QTipLabel::QTipLabel(const QString &text, const QPoint &pos, QWidget *w, int msecDisplayTime) @@ -152,6 +102,7 @@ QTipLabel::QTipLabel(const QString &text, const QPoint &pos, QWidget *w, int mse , styleSheetParent(nullptr) #endif , widget(nullptr) + , fadingOut(false) { delete instance; instance = this; @@ -166,7 +117,6 @@ QTipLabel::QTipLabel(const QString &text, const QPoint &pos, QWidget *w, int mse qApp->installEventFilter(this); setWindowOpacity(style()->styleHint(QStyle::SH_ToolTipLabel_Opacity, nullptr, this) / 255.0); setMouseTracking(true); - fadingOut = false; reuseTip(text, msecDisplayTime, pos); } @@ -433,6 +383,15 @@ bool QTipLabel::tipChanged(const QPoint &pos, const QString &text, QObject *o) return false; } +/** \internal + Cleanup the _q_stylesheet_parent property. + */ +void QTipLabel::styleSheetParentDestroyed() +{ + setProperty("_q_stylesheet_parent", QVariant()); + styleSheetParent = nullptr; +} + /*! Shows \a text as a tool tip, with the global position \a pos as the point of interest. The tool tip will be shown with a platform @@ -594,4 +553,4 @@ void QToolTip::setFont(const QFont &font) QT_END_NAMESPACE -#include "qtooltip.moc" +#include "moc_qtooltip_p.cpp" diff --git a/src/widgets/kernel/qtooltip_p.h b/src/widgets/kernel/qtooltip_p.h new file mode 100644 index 00000000000..51faaf58c34 --- /dev/null +++ b/src/widgets/kernel/qtooltip_p.h @@ -0,0 +1,74 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +// Qt-Security score:significant reason:default + +#ifndef QTOOLTIP_P_H +#define QTOOLTIP_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of qlayout*.cpp, and qabstractlayout.cpp. This header +// file may change from version to version without notice, or even be removed. +// +// We mean it. +// + +#include <QLabel> +#include <QString> +#include <QRect> +#include <QToolTip> + +QT_REQUIRE_CONFIG(tooltip); +QT_BEGIN_NAMESPACE + +class Q_WIDGETS_EXPORT QTipLabel final : public QLabel +{ + Q_OBJECT +public: + explicit QTipLabel(const QString &text, const QPoint &pos, QWidget *w, int msecDisplayTime); + ~QTipLabel() override; + + void adjustTooltipScreen(const QPoint &pos); + void updateSize(const QPoint &pos); + + bool eventFilter(QObject *, QEvent *) override; + + void reuseTip(const QString &text, int msecDisplayTime, const QPoint &pos); + void hideTip(); + void hideTipImmediately(); + void setTipRect(QWidget *w, const QRect &r); + void restartExpireTimer(int msecDisplayTime); + bool tipChanged(const QPoint &pos, const QString &text, QObject *o); + void placeTip(const QPoint &pos, QWidget *w); + + static QScreen *getTipScreen(const QPoint &pos, QWidget *w); +protected: + void timerEvent(QTimerEvent *e) override; + void paintEvent(QPaintEvent *e) override; + void mouseMoveEvent(QMouseEvent *e) override; + void resizeEvent(QResizeEvent *e) override; + +#if QT_CONFIG(style_stylesheet) +public Q_SLOTS: + void styleSheetParentDestroyed(); + +private: + QWidget *styleSheetParent; +#endif + +private: + friend class QToolTip; + + static QTipLabel *instance; + QBasicTimer hideTimer, expireTimer; + QWidget *widget; + QRect rect; + bool fadingOut; +}; + +QT_END_NAMESPACE + +#endif // QTOOLTIP_P_H diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 3575eb78ac4..9b6b96d911b 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -1537,8 +1537,12 @@ void QMenuPrivate::_q_actionTriggered() } activateCausedStack(list, action, QAction::Trigger, false); // if a widget action fires, we need to hide the menu explicitly - if (qobject_cast<QWidgetAction*>(action)) + if (qobject_cast<QWidgetAction*>(action)) { + // make sure QMenu::exec returns the triggered widget action + currentAction = action; + setSyncAction(); hideUpToMenuBar(); + } } } } |
