Re: Status updates, Summer of Code
José Millán Soto <[email protected]>
| Newsgroups | gmane.comp.kde.devel.accessibility |
|---|---|
| Organization | GPUL |
| Message-ID | <[email protected]> |
On Lunes 06 Junio 2011 22:47:38 usted escribió: > José Millán works on KDE Accessibility as a Summer of Code project, so he > will update us about the status of the KDE widgets. Hi, As Frederik told I'm working this summer in KDE Accessibility. However, until now I've worked mainly in qt-at-spi and Qt accessible widgets itself. I KDE widget I created an accessible widget for is KAccessibleRestrictedValue. I also created a QAccessiblePlugin which may be used for handling the KDE accessible widgets. (I'm attaching the patch) I'm not sure this solution is the right one for KAccessibleRestrictedValue tought, as another possible solution is to make it internally use QValidator. What do you think? _______________________________________________ kde-accessibility mailing list [email protected] https://mail.kde.org/mailman/listinfo/kde-accessibility
kaccessiblewidgets.patch
(text/x-patch, 11.8 KB)
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt (revision 1235359)
+++ CMakeLists.txt (working copy)
@@ -15,6 +15,7 @@
include_directories (${KDE4_INCLUDES} )
macro_optional_add_subdirectory(kaccessible)
+macro_optional_add_subdirectory(kaccessiblewidgets)
macro_optional_add_subdirectory(kmag)
macro_optional_add_subdirectory(kmouth)
macro_optional_add_subdirectory(kmousetool)
Index: kaccessiblewidgets/kaccessiblerestrictedline.h
===================================================================
--- kaccessiblewidgets/kaccessiblerestrictedline.h (revision 0)
+++ kaccessiblewidgets/kaccessiblerestrictedline.h (revision 0)
@@ -0,0 +1,55 @@
+/*
+ Copyright 2011 José Millán Soto <[email protected]>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef KACCESSIBLELINEEDIT_H
+#define KACCESSIBLELINEEDIT_H
+
+#include <QtGui/qaccessible2.h>
+#include <QtGui/QAccessibleWidget>
+
+class KRestrictedLine;
+class KAccessibleRestrictedLine : public QAccessibleWidgetEx,
+ public QAccessibleTextInterface,
+ public QAccessibleSimpleEditableTextInterface
+{
+ Q_ACCESSIBLE_OBJECT
+public:
+ KAccessibleRestrictedLine(QWidget *widget);
+ virtual void addSelection(int startOffset, int endOffset);
+ virtual QString attributes(int offset, int* startOffset, int* endOffset);
+ virtual int characterCount();
+ virtual QRect characterRect(int offset, QAccessible2::CoordinateType coordType);
+ virtual int cursorPosition();
+ virtual int offsetAtPoint(const QPoint& point, QAccessible2::CoordinateType coordType);
+ virtual void removeSelection(int selectionIndex);
+ virtual void scrollToSubstring(int startIndex, int endIndex);
+ virtual void selection(int selectionIndex, int* startOffset, int* endOffset);
+ virtual int selectionCount();
+ virtual void setCursorPosition(int position);
+ virtual void setSelection(int selectionIndex, int startOffset, int endOffset);
+ virtual QString text(int startOffset, int endOffset);
+ virtual QString text(Text t, int child) const;
+ virtual QString textAfterOffset(int offset, QAccessible2::BoundaryType boundaryType, int* startOffset, int* endOffset);
+ virtual QString textAtOffset(int offset, QAccessible2::BoundaryType boundaryType, int* startOffset, int* endOffset);
+ virtual QString textBeforeOffset(int offset, QAccessible2::BoundaryType boundaryType, int* startOffset, int* endOffset);
+ virtual void setText(Text t, int child, const QString& text);
+ virtual State state(int child) const;
+private:
+ KRestrictedLine *m_widget;
+};
+
+#endif // KACCESSIBLELINEEDIT_H
Index: kaccessiblewidgets/kaccessiblewidgetfactory.cpp
===================================================================
--- kaccessiblewidgets/kaccessiblewidgetfactory.cpp (revision 0)
+++ kaccessiblewidgets/kaccessiblewidgetfactory.cpp (revision 0)
@@ -0,0 +1,45 @@
+/*
+ Copyright 2011 José Millán Soto <[email protected]>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "kaccessiblewidgetfactory.h"
+
+#include <QtCore/qplugin.h>
+#include "kaccessiblerestrictedline.h"
+#include <krestrictedline.h>
+
+Q_EXPORT_PLUGIN(KAccessibleWidgetFactory)
+
+QAccessibleInterface* KAccessibleWidgetFactory::create(const QString& key, QObject* object)
+{
+ if (key == QLatin1String("KRestrictedLine")) {
+ return new KAccessibleRestrictedLine(reinterpret_cast<QWidget* >(object));
+ }
+
+ return 0;
+}
+
+KAccessibleWidgetFactory::KAccessibleWidgetFactory(QObject* parent):
+ QAccessiblePlugin(parent)
+{
+}
+
+QStringList KAccessibleWidgetFactory::keys() const
+{
+ QStringList l;
+ l.append(QLatin1String("KRestrictedLine"));
+ return l;
+}
Index: kaccessiblewidgets/kaccessiblewidgetfactory.h
===================================================================
--- kaccessiblewidgets/kaccessiblewidgetfactory.h (revision 0)
+++ kaccessiblewidgets/kaccessiblewidgetfactory.h (revision 0)
@@ -0,0 +1,26 @@
+/*
+ Copyright 2011 José Millán Soto <[email protected]>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <QtGui/qaccessible.h>
+#include <QtGui/QAccessiblePlugin>
+
+class KAccessibleWidgetFactory: public QAccessiblePlugin {
+public:
+ KAccessibleWidgetFactory(QObject *parent = 0);
+ virtual QAccessibleInterface *create(const QString &key, QObject *object);
+ virtual QStringList keys() const;
+};
Index: kaccessiblewidgets/kaccessiblerestrictedline.cpp
===================================================================
--- kaccessiblewidgets/kaccessiblerestrictedline.cpp (revision 0)
+++ kaccessiblewidgets/kaccessiblerestrictedline.cpp (revision 0)
@@ -0,0 +1,170 @@
+/*
+ Copyright 2011 José Millán Soto <[email protected]>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "kaccessiblerestrictedline.h"
+
+#include <krestrictedline.h>
+
+KAccessibleRestrictedLine::KAccessibleRestrictedLine(QWidget* widget):
+ QAccessibleWidgetEx(widget, QAccessible::EditableText),
+ QAccessibleTextInterface(),
+ QAccessibleSimpleEditableTextInterface(this)
+{
+ m_widget = qobject_cast<KRestrictedLine *>(widget);
+ Q_ASSERT(m_widget);
+}
+
+int KAccessibleRestrictedLine::characterCount()
+{
+ return m_widget->text().count();
+}
+
+QString KAccessibleRestrictedLine::attributes(int offset, int* startOffset, int* endOffset)
+{
+ return QString();
+}
+
+int KAccessibleRestrictedLine::cursorPosition()
+{
+ return m_widget->cursorPosition();
+}
+
+void KAccessibleRestrictedLine::addSelection(int startOffset, int endOffset)
+{
+ setSelection(0, startOffset, endOffset);
+}
+
+void KAccessibleRestrictedLine::setSelection(int selectionIndex, int startOffset, int endOffset)
+{
+ if (selectionIndex != 0)
+ return;
+
+ m_widget->setSelection(selectionIndex, endOffset);
+}
+
+QRect KAccessibleRestrictedLine::characterRect(int offset, QAccessible2::CoordinateType coordType)
+{
+ //TODO
+ return QRect();
+}
+
+int KAccessibleRestrictedLine::offsetAtPoint(const QPoint& point, QAccessible2::CoordinateType coordType)
+{
+ //TODO
+ return 0;
+}
+
+void KAccessibleRestrictedLine::selection(int selectionIndex, int* startOffset, int* endOffset)
+{
+ *startOffset = -1;
+ *endOffset = -1;
+
+ if (selectionIndex == 0) {
+ *startOffset = m_widget->selectionStart();
+
+ if (*startOffset >= 0) {
+ *endOffset = m_widget->selectedText().count() + *startOffset;
+ }
+ }
+}
+
+int KAccessibleRestrictedLine::selectionCount()
+{
+ return m_widget->selectionStart() >= 0 ? 1 : 0;
+}
+
+void KAccessibleRestrictedLine::setCursorPosition(int position)
+{
+ m_widget->setCursorPosition(position);
+}
+
+QString KAccessibleRestrictedLine::text(int startOffset, int endOffset)
+{
+ return m_widget->text().mid(startOffset, endOffset);
+}
+
+void KAccessibleRestrictedLine::removeSelection(int selectionIndex)
+{
+ if (selectionIndex == 0) {
+ m_widget->deselect();
+ }
+}
+
+QString KAccessibleRestrictedLine::textAfterOffset(int offset, QAccessible2::BoundaryType boundaryType, int* startOffset, int* endOffset)
+{
+ //TODO
+ return QString();
+}
+
+QString KAccessibleRestrictedLine::textBeforeOffset(int offset, QAccessible2::BoundaryType boundaryType, int* startOffset, int* endOffset)
+{
+ //TODO
+ return QString();
+}
+
+QString KAccessibleRestrictedLine::textAtOffset(int offset, QAccessible2::BoundaryType boundaryType, int* startOffset, int* endOffset)
+{
+ //TODO
+ return QString();
+}
+
+void KAccessibleRestrictedLine::scrollToSubstring(int startIndex, int endIndex)
+{
+ //Does nothing
+}
+
+QAccessible::State KAccessibleRestrictedLine::state(int child) const
+{
+ State state = QAccessibleWidgetEx::state(child);
+
+ if (child > 0)
+ return state;
+
+ if (m_widget->isReadOnly())
+ state |= ReadOnly;
+ if (m_widget->echoMode() != QLineEdit::Normal)
+ state |= Protected;
+ if (m_widget->hasSelectedText())
+ state |= Selected;
+ state |= (Selectable | HasPopup);
+
+ return state;
+}
+
+QString KAccessibleRestrictedLine::text(QAccessible::Text t, int child) const
+{
+ if (t == Value) {
+ return m_widget->text();
+ } else {
+ return QAccessibleWidgetEx::text(t, child);
+ }
+}
+
+void KAccessibleRestrictedLine::setText(Text t, int child, const QString& text) {
+ if ((t != QAccessible::Value) || (child != 0)) {
+ QAccessibleWidgetEx::setText(t, child, text);
+ } else {
+ QString validChars = m_widget->validChars();
+ foreach(QChar c, text) {
+ if (!validChars.contains(c)) {
+ return;
+ }
+ }
+ QAccessibleWidgetEx::setText(t, child, text);
+ m_widget->setText(text);
+ }
+}
Index: kaccessiblewidgets/CMakeLists.txt
===================================================================
--- kaccessiblewidgets/CMakeLists.txt (revision 0)
+++ kaccessiblewidgets/CMakeLists.txt (revision 0)
@@ -0,0 +1,8 @@
+project(kaccessiblewidgets)
+
+include_directories(${KDE4_INCLUDES})
+set(kaccessiblewidgets_SRCS kaccessiblerestrictedline.cpp kaccessiblewidgetfactory.cpp)
+kde4_add_plugin(kaccessiblewidgets ${kaccessiblewidgets_SRCS})
+target_link_libraries(kaccessiblewidgets ${QT_LIBRARIES} ${KDE4_KDEUI_LIBS})
+install(TARGETS kaccessiblewidgets DESTINATION ${PLUGIN_INSTALL_DIR}/plugins/accessible)
+