diff options
-rw-r--r-- | src/plugins/accessible/widgets/main.cpp | 3 | ||||
-rw-r--r-- | src/plugins/accessible/widgets/qaccessiblewidgets.cpp | 63 | ||||
-rw-r--r-- | src/plugins/accessible/widgets/qaccessiblewidgets.h | 25 |
3 files changed, 83 insertions, 8 deletions
diff --git a/src/plugins/accessible/widgets/main.cpp b/src/plugins/accessible/widgets/main.cpp index d947d08..06f0abd 100644 --- a/src/plugins/accessible/widgets/main.cpp +++ b/src/plugins/accessible/widgets/main.cpp @@ -125,6 +125,7 @@ QStringList AccessibleFactory::keys() const #ifndef QT_NO_TEXTEDIT list << QLatin1String("QTextEdit"); #endif + list << QLatin1String("QPlainTextEdit"); list << QLatin1String("QTipLabel"); list << QLatin1String("QFrame"); list << QLatin1String("QStackedWidget"); @@ -300,6 +301,8 @@ QAccessibleInterface *AccessibleFactory::create(const QString &classname, QObjec } else if (classname == QLatin1String("QTextEdit")) { iface = new QAccessibleTextEdit(widget); #endif + } else if (classname == QLatin1String("QPlainTextEdit")) { + iface = new QAccessiblePlainTextEdit(widget); } else if (classname == QLatin1String("QTipLabel")) { iface = new QAccessibleDisplay(widget, ToolTip); } else if (classname == QLatin1String("QFrame")) { diff --git a/src/plugins/accessible/widgets/qaccessiblewidgets.cpp b/src/plugins/accessible/widgets/qaccessiblewidgets.cpp index c7396fc..70dae86 100644 --- a/src/plugins/accessible/widgets/qaccessiblewidgets.cpp +++ b/src/plugins/accessible/widgets/qaccessiblewidgets.cpp @@ -47,6 +47,7 @@ #include "private/qtextedit_p.h" #include "qtextdocument.h" #include "qtextobject.h" +#include "qplaintextedit.h" #include "qscrollbar.h" #include "qdebug.h" #include <QApplication> @@ -245,6 +246,57 @@ static int qTextBlockPosition(QTextBlock block) return child; } +QAccessiblePlainTextEdit::QAccessiblePlainTextEdit(QWidget* o) + :QAccessibleTextWidget(o) +{ +} + +QPlainTextEdit* QAccessiblePlainTextEdit::plainTextEdit() const +{ + return static_cast<QPlainTextEdit *>(widget()); +} + +QPoint QAccessiblePlainTextEdit::scrollBarPosition() const +{ + QPoint result; + result.setX(plainTextEdit()->horizontalScrollBar() ? plainTextEdit()->horizontalScrollBar()->sliderPosition() : 0); + result.setY(plainTextEdit()->verticalScrollBar() ? plainTextEdit()->verticalScrollBar()->sliderPosition() : 0); + return result; +} + +QTextCursor QAccessiblePlainTextEdit::textCursor() const +{ + return plainTextEdit()->textCursor(); +} + +void QAccessiblePlainTextEdit::setTextCursor(const QTextCursor &textCursor) +{ + plainTextEdit()->setTextCursor(textCursor); +} + +int QAccessiblePlainTextEdit::childCount() const +{ + return 0; +} + +QTextDocument* QAccessiblePlainTextEdit::textDocument() const +{ + return plainTextEdit()->document(); +} + +QWidget* QAccessiblePlainTextEdit::viewport() const +{ + return plainTextEdit()->viewport(); +} + +void QAccessiblePlainTextEdit::scrollToSubstring(int startIndex, int endIndex) +{ + //TODO: Not implemented + Q_UNUSED(startIndex); + Q_UNUSED(endIndex); +} + + /*! \fn QAccessibleTextEdit::QAccessibleTextEdit(QWidget* widget) @@ -283,9 +335,9 @@ QWidget* QAccessibleTextEdit::viewport() const return textEdit()->viewport(); } -QPoint QAccessibleTextEdit::scrollBarsCurrentPosition() const +QPoint QAccessibleTextEdit::scrollBarPosition() const { - QPoint result(0, 0); + QPoint result; result.setX(textEdit()->horizontalScrollBar() ? textEdit()->horizontalScrollBar()->sliderPosition() : 0); result.setY(textEdit()->verticalScrollBar() ? textEdit()->verticalScrollBar()->sliderPosition() : 0); return result; @@ -1388,10 +1440,9 @@ QRect QAccessibleTextWidget::characterRect(int offset, CoordinateType coordType) r.moveTo(viewport()->mapToGlobal(r.topLeft())); } + r.translate(-scrollBarPosition()); } - r.translate(-scrollBarsCurrentPosition()); - return r; } @@ -1401,7 +1452,7 @@ int QAccessibleTextWidget::offsetAtPoint(const QPoint &point, CoordinateType coo if (coordType == RelativeToScreen) p = viewport()->mapFromGlobal(p); - p += scrollBarsCurrentPosition(); + p += scrollBarPosition(); return textDocument()->documentLayout()->hitTest(p, Qt::ExactHit); } @@ -1548,7 +1599,7 @@ QString QAccessibleTextWidget::text(int startOffset, int endOffset) return cursor.selectedText(); } -QPoint QAccessibleTextWidget::scrollBarsCurrentPosition() const +QPoint QAccessibleTextWidget::scrollBarPosition() const { return QPoint(0, 0); } diff --git a/src/plugins/accessible/widgets/qaccessiblewidgets.h b/src/plugins/accessible/widgets/qaccessiblewidgets.h index 81ceee6..faffbc8 100644 --- a/src/plugins/accessible/widgets/qaccessiblewidgets.h +++ b/src/plugins/accessible/widgets/qaccessiblewidgets.h @@ -65,6 +65,7 @@ class QAbstractItemView; class QDockWidget; class QDockWidgetLayout; class QMainWindow; +class QPlainTextEdit; class QTextCursor; class QTextDocument; @@ -111,13 +112,33 @@ public: protected: QTextCursor textCursorForRange(int startOffset, int endOffset) const; QPair<int, int> getBoundaries(int offset, QAccessible2::BoundaryType boundaryType); - virtual QPoint scrollBarsCurrentPosition() const; + virtual QPoint scrollBarPosition() const; virtual QTextCursor textCursor() const = 0; virtual void setTextCursor(const QTextCursor &) = 0; virtual QTextDocument *textDocument() const = 0; virtual QWidget *viewport() const = 0; }; +class QAccessiblePlainTextEdit : public QAccessibleTextWidget +{ + Q_ACCESSIBLE_OBJECT +public: + explicit QAccessiblePlainTextEdit(QWidget *o); + + int childCount() const; + + // QAccessibleTextInterface + void scrollToSubstring(int startIndex, int endIndex); +protected: + QPlainTextEdit *plainTextEdit() const; + + QPoint scrollBarPosition() const; + QTextCursor textCursor() const; + void setTextCursor(const QTextCursor &textCursor); + QTextDocument *textDocument() const; + QWidget *viewport() const; +}; + #ifndef QT_NO_TEXTEDIT class QAccessibleTextEdit : public QAccessibleTextWidget { @@ -148,7 +169,7 @@ public: protected: QTextEdit *textEdit() const; - QPoint scrollBarsCurrentPosition() const; + QPoint scrollBarPosition() const; QTextCursor textCursor() const; void setTextCursor(const QTextCursor &textCursor); QTextDocument *textDocument() const; |