5#include "private/qaccessiblecolorwell_p.h"
7#include <QtCore/qcoreapplication.h>
11#if QT_CONFIG(colordialog)
13#include "private/qcolorwell_p.h"
16class QAccessibleColorWellItem :
public QAccessibleInterface
18 QAccessibleColorWell *m_parent;
20 Q_DECLARE_TR_FUNCTIONS(QAccessibleColorWellItem)
22 QAccessibleColorWellItem(QAccessibleColorWell *parent);
24 virtual bool isValid()
const override;
25 virtual QObject *object()
const override;
27 virtual QAccessibleInterface *parent()
const override;
28 virtual QAccessibleInterface *child(
int index)
const override;
29 virtual QAccessibleInterface *childAt(
int x,
int y)
const override;
30 virtual int childCount()
const override;
31 virtual int indexOfChild(
const QAccessibleInterface *)
const override;
33 virtual QString text(QAccessible::Text t)
const override;
34 virtual void setText(QAccessible::Text t,
const QString &text) override;
35 virtual QRect rect()
const override;
36 virtual QAccessible::Role role()
const override;
37 virtual QAccessible::State state()
const override;
40QAccessibleColorWellItem::QAccessibleColorWellItem(QAccessibleColorWell *parent)
45bool QAccessibleColorWellItem::isValid()
const
47 return m_parent->isValid();
50QObject *QAccessibleColorWellItem::object()
const
55QAccessibleInterface *QAccessibleColorWellItem::parent()
const
60QAccessibleInterface *QAccessibleColorWellItem::child(
int)
const
65QAccessibleInterface *QAccessibleColorWellItem::childAt(
int,
int)
const
70int QAccessibleColorWellItem::childCount()
const
75int QAccessibleColorWellItem::indexOfChild(
const QAccessibleInterface *)
const
80QString QAccessibleColorWellItem::text(QAccessible::Text t)
const
83 if (t == QAccessible::Name) {
84 QRgb color = m_parent->colorWell()->rgbValues()[m_parent->indexOfChild(
this)];
86 return tr(
"RGB %1, %2, %3")
87 .arg(QString::number(qRed(color)), QString::number(qGreen(color)),
88 QString::number(qBlue(color)));
94void QAccessibleColorWellItem::setText(QAccessible::Text,
const QString &) { }
96QRect QAccessibleColorWellItem::rect()
const
98 const QColorWell *well = m_parent->colorWell();
99 const int childIndex = m_parent->indexOfChild(
this);
102 const int col = childIndex / well->numRows();
103 const int row = childIndex % well->numRows();
105 return m_parent->colorWell()->cellGeometry(row, col).translated(m_parent->rect().topLeft());
108QAccessible::Role QAccessibleColorWellItem::role()
const
110 return QAccessible::ListItem;
113QAccessible::State QAccessibleColorWellItem::state()
const
115 QAccessible::State state;
117 state.invisible = m_parent->state().invisible;
119 state.focusable =
true;
120 const int childIndex = m_parent->indexOfChild(
this);
121 Q_ASSERT(childIndex >= 0);
122 QColorWell *well = m_parent->colorWell();
123 if (well->hasFocus() && well->index(well->currentRow(), well->currentColumn()) == childIndex)
124 state.focused =
true;
126 state.selectable =
true;
127 if (well->index(well->selectedRow(), well->selectedColumn() == childIndex))
128 state.selected =
true;
133QAccessibleColorWell::QAccessibleColorWell(QWidget *widget)
134 : QAccessibleWidgetV2(widget, QAccessible::List)
136 m_childIds.resize(childCount());
139QAccessibleColorWell::~QAccessibleColorWell()
141 for (
const std::optional<QAccessible::Id> &childId : m_childIds) {
142 if (childId.has_value())
143 QAccessible::deleteAccessibleInterface(childId.value());
147QAccessibleInterface *QAccessibleColorWell::child(
int index)
const
149 if (index < 0 ||
static_cast<size_t>(index) >= m_childIds.size())
152 std::optional<QAccessible::Id> childId = m_childIds.at(index);
153 if (childId.has_value())
154 return QAccessible::accessibleInterface(childId.value());
156 QAccessibleInterface *child =
157 new QAccessibleColorWellItem(
const_cast<QAccessibleColorWell *>(
this));
158 const QAccessible::Id id = QAccessible::registerAccessibleInterface(child);
159 m_childIds[index] = id;
163int QAccessibleColorWell::indexOfChild(
const QAccessibleInterface *child)
const
165 auto it = std::find_if(m_childIds.cbegin(), m_childIds.cend(),
166 [child](
const std::optional<QAccessible::Id> &id) {
167 return id.has_value()
168 && QAccessible::accessibleInterface(id.value()) == child;
170 if (it != m_childIds.cend())
171 return std::distance(m_childIds.cbegin(), it);
176int QAccessibleColorWell::childCount()
const
178 const QColorWell *well = colorWell();
179 return well->numCols() * well->numRows();
182QColorWell *QAccessibleColorWell::colorWell()
const
184 return qobject_cast<QColorWell *>(object());
QT_REQUIRE_CONFIG(accessibility)