#include "private/qtextedit_p.h"
#include "qtextdocument.h"
#include "qtextobject.h"
+#include "qplaintextedit.h"
#include "qtextboundaryfinder.h"
#include "qscrollbar.h"
#include "qdebug.h"
#ifndef QT_NO_TEXTEDIT
+QAccessiblePlainTextEdit::QAccessiblePlainTextEdit(QWidget* o)
+ :QAccessibleTextWidget(o)
+{
+ Q_ASSERT(widget()->inherits("QPlainTextEdit"));
+}
+
+QPlainTextEdit* QAccessiblePlainTextEdit::plainTextEdit() const
+{
+ return static_cast<QPlainTextEdit *>(widget());
+}
+
+QString QAccessiblePlainTextEdit::text(QAccessible::Text t) const
+{
+ if (t == QAccessible::Value)
+ return plainTextEdit()->toPlainText();
+
+ return QAccessibleWidget::text(t);
+}
+
+void QAccessiblePlainTextEdit::setText(QAccessible::Text t, const QString &text)
+{
+ if (t != QAccessible::Value) {
+ QAccessibleWidget::setText(t, text);
+ return;
+ }
+ if (plainTextEdit()->isReadOnly())
+ return;
+
+ plainTextEdit()->setPlainText(text);
+}
+
+QAccessible::State QAccessiblePlainTextEdit::state() const
+{
+ QAccessible::State st = QAccessibleWidget::state();
+ if (plainTextEdit()->isReadOnly())
+ st.readOnly = true;
+ else
+ st.editable = true;
+ return st;
+}
+
+void *QAccessiblePlainTextEdit::interface_cast(QAccessible::InterfaceType t)
+{
+ if (t == QAccessible::TextInterface)
+ return static_cast<QAccessibleTextInterface*>(this);
+ return QAccessibleWidget::interface_cast(t);
+}
+
+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);
+}
+
+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);
+}
+
+
/*!
\class QAccessibleTextEdit
\brief The QAccessibleTextEdit class implements the QAccessibleInterface for richtext editors.
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;
w, h);
r.moveTo(viewport()->mapToGlobal(r.topLeft()));
}
+ r.translate(-scrollBarPosition());
}
- r.translate(-scrollBarsCurrentPosition());
-
return r;
}
{
QPoint p = viewport()->mapFromGlobal(point);
// convert to document coordinates
- p += scrollBarsCurrentPosition();
+ p += scrollBarPosition();
return textDocument()->documentLayout()->hitTest(p, Qt::ExactHit);
}
return cursor.selectedText();
}
-QPoint QAccessibleTextWidget::scrollBarsCurrentPosition() const
+QPoint QAccessibleTextWidget::scrollBarPosition() const
{
return QPoint(0, 0);
}
class QDockWidget;
class QDockWidgetLayout;
class QMainWindow;
+class QPlainTextEdit;
class QTextCursor;
class QTextDocument;
protected:
QTextCursor textCursorForRange(int startOffset, int endOffset) const;
QPair<int, int> getBoundaries(int offset, QAccessible2::BoundaryType boundaryType) const;
- virtual QPoint scrollBarsCurrentPosition() const;
+ virtual QPoint scrollBarPosition() const;
virtual QTextCursor textCursor() const = 0;
virtual void setTextCursor(const QTextCursor &) = 0;
virtual QTextDocument *textDocument() const = 0;
#endif //QT_NO_CURSOR
#ifndef QT_NO_TEXTEDIT
+class QAccessiblePlainTextEdit : public QAccessibleTextWidget
+{
+public:
+ explicit QAccessiblePlainTextEdit(QWidget *o);
+
+ QString text(QAccessible::Text t) const;
+ void setText(QAccessible::Text t, const QString &text);
+ QAccessible::State state() const;
+
+ void *interface_cast(QAccessible::InterfaceType t);
+
+ // 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;
+};
+
class QAccessibleTextEdit : public QAccessibleTextWidget
{
public:
protected:
QTextEdit *textEdit() const;
- QPoint scrollBarsCurrentPosition() const;
+ QPoint scrollBarPosition() const;
QTextCursor textCursor() const;
void setTextCursor(const QTextCursor &textCursor);
QTextDocument *textDocument() const;
QWidget *viewport() const;
-private:
- int childOffset;
};
#endif // QT_NO_TEXTEDIT