Qt 4.8
Public Functions | Protected Functions | List of all members
QAccessibleTextWidget Class Referenceabstract

#include <qaccessiblewidgets.h>

Inheritance diagram for QAccessibleTextWidget:
QAccessibleWidgetEx QAccessibleTextInterface QAccessibleEditableTextInterface QAccessibleObjectEx QAccessible2Interface QAccessible2Interface QAccessibleInterfaceEx QAccessibleInterface QAccessible QAccessiblePlainTextEdit QAccessibleTextEdit QAccessibleTextBrowser

Public Functions

void addSelection (int startOffset, int endOffset)
 
QString attributes (int offset, int *startOffset, int *endOffset)
 
int characterCount ()
 
QRect characterRect (int offset, QAccessible2::CoordinateType coordType)
 
void copyText (int startOffset, int endOffset)
 
int cursorPosition ()
 
void cutText (int startOffset, int endOffset)
 
void deleteText (int startOffset, int endOffset)
 
void insertText (int offset, const QString &text)
 
int offsetAtPoint (const QPoint &point, QAccessible2::CoordinateType coordType)
 
void pasteText (int offset)
 
 QAccessibleTextWidget (QWidget *o, Role r=EditableText, const QString &name=QString())
 
void removeSelection (int selectionIndex)
 
void replaceText (int startOffset, int endOffset, const QString &text)
 
void selection (int selectionIndex, int *startOffset, int *endOffset)
 
int selectionCount ()
 
void setAttributes (int startOffset, int endOffset, const QString &attributes)
 
void setCursorPosition (int position)
 
void setSelection (int selectionIndex, int startOffset, int endOffset)
 
QString text (int startOffset, int endOffset)
 
QString textAfterOffset (int offset, QAccessible2::BoundaryType boundaryType, int *startOffset, int *endOffset)
 
QString textAtOffset (int offset, QAccessible2::BoundaryType boundaryType, int *startOffset, int *endOffset)
 
QString textBeforeOffset (int offset, QAccessible2::BoundaryType boundaryType, int *startOffset, int *endOffset)
 
- Public Functions inherited from QAccessibleWidgetEx
QString actionText (int action, Text t, int child) const
 Returns the text property t of the action action supported by the object, or of the object's child if child is not 0. More...
 
int childAt (int x, int y) const
 Returns the 1-based index of the child that contains the screen coordinates (x, y). More...
 
int childCount () const
 Returns the number of children that belong to this object. More...
 
bool doAction (int action, int child, const QVariantList &params)
 Asks the object, or the object's child if child is not 0, to execute action using the parameters, params. More...
 
int indexOfChild (const QAccessibleInterface *child) const
 Returns the 1-based index of the object child in this object's children list, or -1 if child is not a child of this object. More...
 
QVariant invokeMethodEx (Method method, int child, const QVariantList &params)
 
int navigate (RelationFlag rel, int entry, QAccessibleInterface **target) const
 Navigates from this object to an object that has a relationship relation to this object, and returns the respective object in target. More...
 
 QAccessibleWidgetEx (QWidget *o, Role r=Client, const QString &name=QString())
 
QRect rect (int child) const
 Returns the geometry of the object, or of the object's child if child is not 0. More...
 
Relation relationTo (int child, const QAccessibleInterface *other, int otherChild) const
 
Returns the relationship between this object's \a child and the \a
other object's \a otherChild.
More...
 
Role role (int child) const
 Returns the role of the object, or of the object's child if child is not 0. More...
 
State state (int child) const
 Returns the current state of the object, or of the object's child if child is not 0. More...
 
QString text (Text t, int child) const
 Returns the value of the text property t of the object, or of the object's child if child is not 0. More...
 
- Public Functions inherited from QAccessibleObjectEx
bool isValid () const
 Returns true if all the data necessary to use this interface implementation is valid (e. More...
 
QObjectobject () const
 Returns a pointer to the QObject this interface implementation provides information for. More...
 
 QAccessibleObjectEx (QObject *object)
 
void setText (Text t, int child, const QString &text)
 Sets the text property t of the object, or of the object's child if child is not 0, to text. More...
 
int userActionCount (int child) const
 Returns the number of custom actions of the object, or of the object's child if child is not 0. More...
 
- Public Functions inherited from QAccessibleInterfaceEx
virtual QAccessible2Interfaceinterface_cast (QAccessible2::InterfaceType)
 
virtual QVariant virtual_hook (const QVariant &data)
 
- Public Functions inherited from QAccessibleInterface
QAccessibleActionInterfaceactionInterface ()
 
QColor backgroundColor ()
 
QAccessibleEditableTextInterfaceeditableTextInterface ()
 
QColor foregroundColor ()
 
QAccessibleImageInterfaceimageInterface ()
 
QVariant invokeMethod (Method method, int child=0, const QVariantList &params=QVariantList())
 Invokes a method on child with the given parameters params and returns the result of the operation as QVariant. More...
 
QSet< MethodsupportedMethods ()
 Returns a QSet of QAccessible::Method that are supported by this accessible interface. More...
 
QAccessibleTable2Interfacetable2Interface ()
 
QAccessibleTableInterfacetableInterface ()
 
QAccessibleTextInterfacetextInterface ()
 
QAccessibleValueInterfacevalueInterface ()
 
virtual ~QAccessibleInterface ()
 Destroys the object. More...
 
- Public Functions inherited from QAccessibleTextInterface
QAccessible2InterfaceqAccessibleTextCastHelper ()
 
virtual void scrollToSubstring (int startIndex, int endIndex)=0
 
virtual ~QAccessibleTextInterface ()
 
- Public Functions inherited from QAccessible2Interface
virtual ~QAccessible2Interface ()
 
- Public Functions inherited from QAccessibleEditableTextInterface
QAccessible2InterfaceqAccessibleEditableTextCastHelper ()
 
virtual ~QAccessibleEditableTextInterface ()
 

Protected Functions

QPair< int, int > getBoundaries (int offset, QAccessible2::BoundaryType boundaryType)
 
virtual QPoint scrollBarPosition () const
 
virtual void setTextCursor (const QTextCursor &)=0
 
virtual QTextCursor textCursor () const =0
 
QTextCursor textCursorForRange (int startOffset, int endOffset) const
 
virtual QTextDocumenttextDocument () const =0
 
virtual QWidgetviewport () const =0
 
- Protected Functions inherited from QAccessibleWidgetEx
void addControllingSignal (const QString &signal)
 
QObjectparentObject () const
 
void setAccelerator (const QString &accel)
 
void setDescription (const QString &desc)
 
void setHelp (const QString &help)
 
void setValue (const QString &value)
 
QWidgetwidget () const
 
 ~QAccessibleWidgetEx ()
 
- Protected Functions inherited from QAccessibleObjectEx
virtual ~QAccessibleObjectEx ()
 

Additional Inherited Members

- Public Types inherited from QAccessible
enum  Action {
  DefaultAction = 0, Press = -1, FirstStandardAction = Press, SetFocus = -2,
  Increase = -3, Decrease = -4, Accept = -5, Cancel = -6,
  Select = -7, ClearSelection = -8, RemoveSelection = -9, ExtendSelection = -10,
  AddToSelection = -11, LastStandardAction = AddToSelection
}
 This enum describes the possible types of action that can occur. More...
 
enum  Event {
  SoundPlayed = 0x0001, Alert = 0x0002, ForegroundChanged = 0x0003, MenuStart = 0x0004,
  MenuEnd = 0x0005, PopupMenuStart = 0x0006, PopupMenuEnd = 0x0007, ContextHelpStart = 0x000C,
  ContextHelpEnd = 0x000D, DragDropStart = 0x000E, DragDropEnd = 0x000F, DialogStart = 0x0010,
  DialogEnd = 0x0011, ScrollingStart = 0x0012, ScrollingEnd = 0x0013, MenuCommand = 0x0018,
  ActionChanged = 0x0101, ActiveDescendantChanged = 0x0102, AttributeChanged = 0x0103, DocumentContentChanged = 0x0104,
  DocumentLoadComplete = 0x0105, DocumentLoadStopped = 0x0106, DocumentReload = 0x0107, HyperlinkEndIndexChanged = 0x0108,
  HyperlinkNumberOfAnchorsChanged = 0x0109, HyperlinkSelectedLinkChanged = 0x010A, HypertextLinkActivated = 0x010B, HypertextLinkSelected = 0x010C,
  HyperlinkStartIndexChanged = 0x010D, HypertextChanged = 0x010E, HypertextNLinksChanged = 0x010F, ObjectAttributeChanged = 0x0110,
  PageChanged = 0x0111, SectionChanged = 0x0112, TableCaptionChanged = 0x0113, TableColumnDescriptionChanged = 0x0114,
  TableColumnHeaderChanged = 0x0115, TableModelChanged = 0x0116, TableRowDescriptionChanged = 0x0117, TableRowHeaderChanged = 0x0118,
  TableSummaryChanged = 0x0119, TextAttributeChanged = 0x011A, TextCaretMoved = 0x011B, TextColumnChanged = 0x011D,
  TextInserted = 0x011E, TextRemoved = 0x011F, TextUpdated = 0x0120, TextSelectionChanged = 0x0121,
  VisibleDataChanged = 0x0122, ObjectCreated = 0x8000, ObjectDestroyed = 0x8001, ObjectShow = 0x8002,
  ObjectHide = 0x8003, ObjectReorder = 0x8004, Focus = 0x8005, Selection = 0x8006,
  SelectionAdd = 0x8007, SelectionRemove = 0x8008, SelectionWithin = 0x8009, StateChanged = 0x800A,
  LocationChanged = 0x800B, NameChanged = 0x800C, DescriptionChanged = 0x800D, ValueChanged = 0x800E,
  ParentChanged = 0x800F, HelpChanged = 0x80A0, DefaultActionChanged = 0x80B0, AcceleratorChanged = 0x80C0
}
 This enum type defines accessible event types. More...
 
typedef QAccessibleInterface *(* InterfaceFactory) (const QString &key, QObject *)
 This is a typedef for a pointer to a function with the following signature: More...
 
enum  Method {
  ListSupportedMethods = 0, SetCursorPosition = 1, GetCursorPosition = 2, ForegroundColor = 3,
  BackgroundColor = 4
}
 This enum describes the possible types of methods that can be invoked on an accessible object. More...
 
enum  RelationFlag {
  Unrelated = 0x00000000, Self = 0x00000001, Ancestor = 0x00000002, Child = 0x00000004,
  Descendent = 0x00000008, Sibling = 0x00000010, HierarchyMask = 0x000000ff, Up = 0x00000100,
  Down = 0x00000200, Left = 0x00000400, Right = 0x00000800, Covers = 0x00001000,
  Covered = 0x00002000, GeometryMask = 0x0000ff00, FocusChild = 0x00010000, Label = 0x00020000,
  Labelled = 0x00040000, Controller = 0x00080000, Controlled = 0x00100000, LogicalMask = 0x00ff0000
}
 This enum type defines bit flags that can be combined to indicate the relationship between two accessible objects. More...
 
enum  Role {
  NoRole = 0x00000000, TitleBar = 0x00000001, MenuBar = 0x00000002, ScrollBar = 0x00000003,
  Grip = 0x00000004, Sound = 0x00000005, Cursor = 0x00000006, Caret = 0x00000007,
  AlertMessage = 0x00000008, Window = 0x00000009, Client = 0x0000000A, PopupMenu = 0x0000000B,
  MenuItem = 0x0000000C, ToolTip = 0x0000000D, Application = 0x0000000E, Document = 0x0000000F,
  Pane = 0x00000010, Chart = 0x00000011, Dialog = 0x00000012, Border = 0x00000013,
  Grouping = 0x00000014, Separator = 0x00000015, ToolBar = 0x00000016, StatusBar = 0x00000017,
  Table = 0x00000018, ColumnHeader = 0x00000019, RowHeader = 0x0000001A, Column = 0x0000001B,
  Row = 0x0000001C, Cell = 0x0000001D, Link = 0x0000001E, HelpBalloon = 0x0000001F,
  Assistant = 0x00000020, List = 0x00000021, ListItem = 0x00000022, Tree = 0x00000023,
  TreeItem = 0x00000024, PageTab = 0x00000025, PropertyPage = 0x00000026, Indicator = 0x00000027,
  Graphic = 0x00000028, StaticText = 0x00000029, EditableText = 0x0000002A, PushButton = 0x0000002B,
  CheckBox = 0x0000002C, RadioButton = 0x0000002D, ComboBox = 0x0000002E, ProgressBar = 0x00000030,
  Dial = 0x00000031, HotkeyField = 0x00000032, Slider = 0x00000033, SpinBox = 0x00000034,
  Canvas = 0x00000035, Animation = 0x00000036, Equation = 0x00000037, ButtonDropDown = 0x00000038,
  ButtonMenu = 0x00000039, ButtonDropGrid = 0x0000003A, Whitespace = 0x0000003B, PageTabList = 0x0000003C,
  Clock = 0x0000003D, Splitter = 0x0000003E, LayeredPane = 0x0000003F, Terminal = 0x00000040,
  Desktop = 0x00000041, UserRole = 0x0000ffff
}
 This enum defines the role of an accessible object. More...
 
typedef void(* RootObjectHandler) (QObject *)
 A function pointer type. More...
 
enum  StateFlag {
  Normal = 0x00000000, Unavailable = 0x00000001, Selected = 0x00000002, Focused = 0x00000004,
  Pressed = 0x00000008, Checked = 0x00000010, Mixed = 0x00000020, ReadOnly = 0x00000040,
  HotTracked = 0x00000080, DefaultButton = 0x00000100, Expanded = 0x00000200, Collapsed = 0x00000400,
  Busy = 0x00000800, Marqueed = 0x00002000, Animated = 0x00004000, Invisible = 0x00008000,
  Offscreen = 0x00010000, Sizeable = 0x00020000, Movable = 0x00040000, SelfVoicing = 0x00080000,
  Focusable = 0x00100000, Selectable = 0x00200000, Linked = 0x00400000, Traversed = 0x00800000,
  MultiSelectable = 0x01000000, ExtSelectable = 0x02000000, Protected = 0x20000000, HasPopup = 0x40000000,
  Modal = 0x80000000, HasInvokeExtension = 0x10000000
}
 This enum type defines bit flags that can be combined to indicate the state of an accessible object. More...
 
enum  Text {
  Name = 0, Description, Value, Help,
  Accelerator, UserText = 0x0000ffff
}
 This enum specifies string information that an accessible object returns. More...
 
typedef void(* UpdateHandler) (QObject *, int who, Event reason)
 A function pointer type. More...
 
- Static Public Functions inherited from QAccessible
static void cleanup ()
 
static void initialize ()
 
static void installFactory (InterfaceFactory)
 Installs the InterfaceFactory factory. More...
 
static RootObjectHandler installRootObjectHandler (RootObjectHandler)
 Installs the given handler as the function to be used by setRootObject(), and returns the previously installed handler. More...
 
static UpdateHandler installUpdateHandler (UpdateHandler)
 Installs the given handler as the function to be used by updateAccessibility(), and returns the previously installed handler. More...
 
static bool isActive ()
 Returns true if an accessibility implementation has been requested during the runtime of the application; otherwise returns false. More...
 
static QAccessibleInterfacequeryAccessibleInterface (QObject *)
 If a QAccessibleInterface implementation exists for the given object, this function returns a pointer to the implementation; otherwise it returns 0. More...
 
static void removeFactory (InterfaceFactory)
 Removes factory from the list of installed InterfaceFactories. More...
 
static void setRootObject (QObject *)
 Sets the root accessible object of this application to object. More...
 
static void updateAccessibility (QObject *, int who, Event reason)
 Notifies accessibility clients about a change in object's accessibility information. More...
 

Detailed Description

Definition at line 72 of file qaccessiblewidgets.h.

Constructors and Destructors

◆ QAccessibleTextWidget()

QAccessibleTextWidget::QAccessibleTextWidget ( QWidget o,
QAccessible::Role  r = EditableText,
const QString name = QString() 
)

Definition at line 1399 of file qaccessiblewidgets.cpp.

1399  :
1400  QAccessibleWidgetEx(o, r, name)
1401 {
1402 }
QAccessibleWidgetEx(QWidget *o, Role r=Client, const QString &name=QString())

Functions

◆ addSelection()

void QAccessibleTextWidget::addSelection ( int  startOffset,
int  endOffset 
)
virtual

Implements QAccessibleTextInterface.

Definition at line 1716 of file qaccessiblewidgets.cpp.

1717 {
1718  setSelection(0, startOffset, endOffset);
1719 }
void setSelection(int selectionIndex, int startOffset, int endOffset)

◆ attributes()

QString QAccessibleTextWidget::attributes ( int  offset,
int *  startOffset,
int *  endOffset 
)
virtual

Implements QAccessibleTextInterface.

Definition at line 1473 of file qaccessiblewidgets.cpp.

1474 {
1475  /* The list of attributes can be found at:
1476  http://linuxfoundation.org/collaborate/workgroups/accessibility/iaccessible2/textattributes
1477  */
1478 
1479  if (offset >= characterCount()) {
1480  *startOffset = -1;
1481  *endOffset = -1;
1482  return QString();
1483  }
1484 
1485  QMap<QString, QString> attrs;
1486 
1487  QTextCursor cursor = textCursor();
1488 
1489  //cursor.charFormat returns the format of the previous character
1490  cursor.setPosition(offset + 1);
1491  QTextCharFormat charFormat = cursor.charFormat();
1492 
1493  cursor.setPosition(offset);
1494  QTextBlockFormat blockFormat = cursor.blockFormat();
1495 
1496  QTextCharFormat charFormatComp;
1497  QTextBlockFormat blockFormatComp;
1498 
1499  *startOffset = offset;
1500  cursor.setPosition(*startOffset);
1501  while (*startOffset > 0) {
1502  charFormatComp = cursor.charFormat();
1503  cursor.setPosition(*startOffset - 1);
1504  blockFormatComp = cursor.blockFormat();
1505  if ((charFormat == charFormatComp) && (blockFormat == blockFormatComp))
1506  (*startOffset)--;
1507  else
1508  break;
1509  }
1510 
1511  int limit = characterCount() + 1;
1512  *endOffset = offset + 1;
1513  cursor.setPosition(*endOffset);
1514  while (*endOffset < limit) {
1515  blockFormatComp = cursor.blockFormat();
1516  cursor.setPosition(*endOffset + 1);
1517  charFormatComp = cursor.charFormat();
1518  if ((charFormat == charFormatComp) && (cursor.blockFormat() == blockFormatComp))
1519  (*endOffset)++;
1520  else
1521  break;
1522  }
1523 
1524  QString family = charFormat.fontFamily();
1525  if (!family.isEmpty()) {
1526  family = family.replace('\\',"\\\\");
1527  family = family.replace(':',"\\:");
1528  family = family.replace(',',"\\,");
1529  family = family.replace('=',"\\=");
1530  family = family.replace(';',"\\;");
1531  family = family.replace('\"',"\\\"");
1532  attrs["font-family"] = '"'+family+'"';
1533  }
1534 
1535  int fontSize = int(charFormat.fontPointSize());
1536  if (fontSize)
1537  attrs["font-size"] = QString::number(fontSize).append("pt");
1538 
1539  //Different weight values are not handled
1540  attrs["font-weight"] = (charFormat.fontWeight() > QFont::Normal) ? "bold" : "normal";
1541 
1542  QFont::Style style = charFormat.font().style();
1543  attrs["font-style"] = (style == QFont::StyleItalic) ? "italic" : ((style == QFont::StyleOblique) ? "oblique": "normal");
1544 
1545  attrs["text-underline-style"] = charFormat.font().underline() ? "solid" : "none";
1546 
1547  QTextCharFormat::VerticalAlignment alignment = charFormat.verticalAlignment();
1548  attrs["text-position"] = (alignment == QTextCharFormat::AlignSubScript) ? "sub" : ((alignment == QTextCharFormat::AlignSuperScript) ? "super" : "baseline" );
1549 
1550  QBrush background = charFormat.background();
1551  if (background.style() == Qt::SolidPattern) {
1552  attrs["background-color"] = QString("rgb(%1,%2,%3)").arg(background.color().red()).arg(background.color().green()).arg(background.color().blue());
1553  }
1554 
1555  QBrush foreground = charFormat.foreground();
1556  if (foreground.style() == Qt::SolidPattern) {
1557  attrs["color"] = QString("rgb(%1,%2,%3)").arg(foreground.color().red()).arg(foreground.color().green()).arg(foreground.color().blue());
1558  }
1559 
1560  switch (blockFormat.alignment() & (Qt::AlignLeft | Qt::AlignRight | Qt::AlignHCenter | Qt::AlignJustify)) {
1561  case Qt::AlignLeft:
1562  attrs["text-align"] = "left";
1563  break;
1564  case Qt::AlignRight:
1565  attrs["text-align"] = "right";
1566  break;
1567  case Qt::AlignHCenter:
1568  attrs["text-align"] = "center";
1569  break;
1570  case Qt::AlignJustify:
1571  attrs["text-align"] = "left";
1572  break;
1573  }
1574 
1575  QString result;
1576  foreach (const QString &attributeName, attrs.keys()) {
1577  result.append(attributeName).append(':').append(attrs[attributeName]).append(';');
1578  }
1579 
1580  return result;
1581 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
QFont font() const
Returns the font for this character format.
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
QTextCharFormat charFormat() const
Returns the format of the character immediately before the cursor position().
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
virtual QTextCursor textCursor() const =0
bool underline() const
Returns true if underline has been set; otherwise returns false.
Definition: qfont.cpp:1320
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
Style style() const
Returns the style of the font.
Definition: qfont.cpp:1223
QTextBlockFormat blockFormat() const
Returns the block format of the block the cursor is in.
ushort red
Returns the red color component of this color.
Definition: qcolor.h:243
The QString class provides a Unicode character string.
Definition: qstring.h:83
Qt::Alignment alignment() const
Returns the paragraph&#39;s alignment.
Definition: qtextformat.h:561
VerticalAlignment
This enum describes the ways that adjacent characters can be vertically aligned.
Definition: qtextformat.h:375
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
int fontWeight() const
Returns the text format&#39;s font weight.
Definition: qtextformat.h:413
QList< Key > keys() const
Returns a list containing all the keys in the map in ascending order.
Definition: qmap.h:818
QBrush background() const
Returns the brush used to paint the document&#39;s background.
Definition: qtextformat.h:345
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
Style
This enum describes the different styles of glyphs that are used to display text. ...
Definition: qfont.h:111
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
VerticalAlignment verticalAlignment() const
Returns the vertical alignment used for characters with this format.
Definition: qtextformat.h:486
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
QString & append(QChar c)
Definition: qstring.cpp:1777
ushort blue
Returns the blue color component of this color.
Definition: qcolor.h:245
The QTextBlockFormat class provides formatting information for blocks of text in a QTextDocument...
Definition: qtextformat.h:545
QBrush foreground() const
Returns the brush used to render foreground details, such as text, frame outlines, and table borders.
Definition: qtextformat.h:352
void setPosition(int pos, MoveMode mode=MoveAnchor)
Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified...
qreal fontPointSize() const
Returns the font size used to display text in this format.
Definition: qtextformat.h:408
QString fontFamily() const
Returns the text format&#39;s font family.
Definition: qtextformat.h:403
ushort green
Returns the green color component of this color.
Definition: qcolor.h:244

◆ characterCount()

int QAccessibleTextWidget::characterCount ( )
virtual

Implements QAccessibleTextInterface.

Definition at line 1742 of file qaccessiblewidgets.cpp.

Referenced by attributes(), and getBoundaries().

1743 {
1744  QTextCursor cursor = textCursor();
1746  return cursor.position();
1747 }
virtual QTextCursor textCursor() const =0
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
int position() const
Returns the absolute position of the cursor within the document.
bool movePosition(MoveOperation op, MoveMode=MoveAnchor, int n=1)
Moves the cursor by performing the given operation n times, using the specified mode, and returns true if all operations were completed successfully; otherwise returns false.

◆ characterRect()

QRect QAccessibleTextWidget::characterRect ( int  offset,
QAccessible2::CoordinateType  coordType 
)
virtual

Implements QAccessibleTextInterface.

Definition at line 1412 of file qaccessiblewidgets.cpp.

1413 {
1414  QTextBlock block = textDocument()->findBlock(offset);
1415  if (!block.isValid())
1416  return QRect();
1417 
1418  QTextLayout *layout = block.layout();
1419  QPointF layoutPosition = layout->position();
1420  int relativeOffset = offset - block.position();
1421  QTextLine line = layout->lineForTextPosition(relativeOffset);
1422 
1423  QRect r;
1424 
1425  if (line.isValid()) {
1426  qreal x = line.cursorToX(relativeOffset);
1427  qreal w = 0;
1428 
1429  if ((relativeOffset - line.textStart())< line.textLength()) {
1430  w = line.cursorToX(relativeOffset + 1) - x;
1431  } else {
1432  // If the width of a character is not known, IAccessible2 tells to return the width of a default character
1433  int averageCharWidth = QFontMetrics(textCursor().charFormat().font()).averageCharWidth();
1434  if (block.blockFormat().layoutDirection() == Qt::RightToLeft)
1435  averageCharWidth *= -1;
1436 
1437  r.setWidth(averageCharWidth);
1438  }
1439  int height = line.height();
1440 
1441  // make sure that height does not include leading. (only ascent + descent + 1)
1442  if (line.leadingIncluded())
1443  height -= qRound(line.leading());
1444  r = QRect(layoutPosition.x() + x, layoutPosition.y() + line.y(),
1445  w, height);
1446 
1447  if (coordType == RelativeToScreen) {
1448  r.moveTo(viewport()->mapToGlobal(r.topLeft()));
1449  }
1450 
1452  }
1453 
1454  return r;
1455 }
QPointF position() const
The global position of the layout.
double qreal
Definition: qglobal.h:1193
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
qreal y() const
Returns the line&#39;s y position.
virtual QTextCursor textCursor() const =0
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QTextLine class represents a line of text inside a QTextLayout.
Definition: qtextlayout.h:197
int textLength() const
Returns the length of the text in the line.
qreal leading() const
Returns the line&#39;s leading.
void moveTo(int x, int t)
Moves the rectangle, leaving the top-left corner at the given position (x, y).
Definition: qrect.h:334
bool isValid() const
Returns true if this text line is valid; otherwise returns false.
Definition: qtextlayout.h:201
Qt::LayoutDirection layoutDirection() const
Returns the document&#39;s layout direction.
Definition: qtextformat.h:340
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QTextLine lineForTextPosition(int pos) const
Returns the line that contains the cursor position specified by pos.
int position() const
Returns the index of the block&#39;s first character within the document.
bool leadingIncluded() const
Returns true if positive leading is included into the line&#39;s height; otherwise returns false...
qreal cursorToX(int *cursorPos, Edge edge=Leading) const
Converts the cursor position cursorPos to the corresponding x position inside the line...
int averageCharWidth() const
Returns the average width of glyphs in the font.
const char * layout
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
virtual QTextDocument * textDocument() const =0
virtual QWidget * viewport() const =0
The QTextLayout class is used to lay out and render text.
Definition: qtextlayout.h:105
virtual QPoint scrollBarPosition() const
QTextBlock findBlock(int pos) const
Returns the text block that contains the {pos}-th character.
void setWidth(int w)
Sets the width of the rectangle to the given width.
Definition: qrect.h:442
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
Definition: qtextobject.h:208
void translate(int dx, int dy)
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position...
Definition: qrect.h:312
QTextBlockFormat blockFormat() const
Returns the QTextBlockFormat that describes block-specific properties.
qreal height() const
Returns the line&#39;s height.
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
int textStart() const
Returns the start of the line from the beginning of the string passed to the QTextLayout.
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288
QTextLayout * layout() const
Returns the QTextLayout that is used to lay out and display the block&#39;s contents. ...

◆ copyText()

void QAccessibleTextWidget::copyText ( int  startOffset,
int  endOffset 
)
virtual

Implements QAccessibleEditableTextInterface.

Reimplemented in QAccessibleTextEdit.

Definition at line 1781 of file qaccessiblewidgets.cpp.

1782 {
1783 #ifndef QT_NO_CLIPBOARD
1784  QString text = this->text(startOffset, endOffset);
1786 #endif
1787 }
QString text(int startOffset, int endOffset)
The QString class provides a Unicode character string.
Definition: qstring.h:83
void setText(const QString &, Mode mode=Clipboard)
Copies text into the clipboard as plain text.
Definition: qclipboard.cpp:375
static QClipboard * clipboard()
Returns a pointer to the application global clipboard.

◆ cursorPosition()

int QAccessibleTextWidget::cursorPosition ( )
virtual

Implements QAccessibleTextInterface.

Definition at line 1583 of file qaccessiblewidgets.cpp.

1584 {
1585  return textCursor().position();
1586 }
virtual QTextCursor textCursor() const =0
int position() const
Returns the absolute position of the cursor within the document.

◆ cutText()

void QAccessibleTextWidget::cutText ( int  startOffset,
int  endOffset 
)
virtual

Implements QAccessibleEditableTextInterface.

Reimplemented in QAccessibleTextEdit.

Definition at line 1789 of file qaccessiblewidgets.cpp.

1790 {
1791 #ifndef QT_NO_CLIPBOARD
1792  QString text = this->text(startOffset, endOffset);
1794  deleteText(startOffset, endOffset);
1795 #endif
1796 }
QString text(int startOffset, int endOffset)
The QString class provides a Unicode character string.
Definition: qstring.h:83
void setText(const QString &, Mode mode=Clipboard)
Copies text into the clipboard as plain text.
Definition: qclipboard.cpp:375
void deleteText(int startOffset, int endOffset)
static QClipboard * clipboard()
Returns a pointer to the application global clipboard.

◆ deleteText()

void QAccessibleTextWidget::deleteText ( int  startOffset,
int  endOffset 
)
virtual

Implements QAccessibleEditableTextInterface.

Definition at line 1758 of file qaccessiblewidgets.cpp.

Referenced by cutText().

1759 {
1760  QTextCursor cursor = textCursorForRange(startOffset, endOffset);
1761 
1762  cursor.removeSelectedText();
1763 }
QTextCursor textCursorForRange(int startOffset, int endOffset) const
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
void removeSelectedText()
If there is a selection, its content is deleted; otherwise does nothing.

◆ getBoundaries()

QPair< int, int > QAccessibleTextWidget::getBoundaries ( int  offset,
QAccessible2::BoundaryType  boundaryType 
)
protected

Definition at line 1615 of file qaccessiblewidgets.cpp.

Referenced by textAfterOffset(), textAtOffset(), and textBeforeOffset().

1616 {
1617  if (offset >= characterCount())
1619  if (offset < 0)
1620  return QPair<int, int>(0, 0);
1621 
1622  QTextCursor cursor = textCursor();
1623 
1624  QPair<int, int> result;
1625 
1626  cursor.setPosition(offset);
1627  switch (boundaryType) {
1628  case CharBoundary:
1629  result.first = cursor.position();
1631  result.second = cursor.position();
1632  break;
1633  case WordBoundary:
1634  cursor.movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor);
1635  result.first = cursor.position();
1636  cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
1637  result.second = cursor.position();
1638  break;
1639  case SentenceBoundary:
1640  // TODO - what's a sentence?
1641  case LineBoundary:
1642  cursor.movePosition(QTextCursor::StartOfLine, QTextCursor::MoveAnchor);
1643  result.first = cursor.position();
1644  cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
1645  result.second = cursor.position();
1646  break;
1647  case ParagraphBoundary:
1648  cursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor);
1649  result.first = cursor.position();
1650  cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
1651  result.second = cursor.position();
1652  break;
1653  case NoBoundary:
1654  result.first = 0;
1655  result.second = characterCount();
1656  break;
1657  default:
1658  qDebug("QAccessibleTextWidget::getBoundaries: Unknown boundary type %d", boundaryType);
1659  result.first = -1;
1660  result.second = -1;
1661  }
1662  return result;
1663 }
virtual QTextCursor textCursor() const =0
T1 first
Definition: qpair.h:65
T2 second
Definition: qpair.h:66
Q_CORE_EXPORT void qDebug(const char *,...)
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70

◆ insertText()

void QAccessibleTextWidget::insertText ( int  offset,
const QString text 
)
virtual

Implements QAccessibleEditableTextInterface.

Definition at line 1765 of file qaccessiblewidgets.cpp.

Referenced by pasteText().

1766 {
1767  QTextCursor cursor = textCursor();
1768  cursor.setPosition(offset);
1769 
1770  cursor.insertText(text);
1771 }
virtual QTextCursor textCursor() const =0
void insertText(const QString &text)
Inserts text at the current position, using the current character format.
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
void setPosition(int pos, MoveMode mode=MoveAnchor)
Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified...

◆ offsetAtPoint()

int QAccessibleTextWidget::offsetAtPoint ( const QPoint point,
QAccessible2::CoordinateType  coordType 
)
virtual

Implements QAccessibleTextInterface.

Definition at line 1457 of file qaccessiblewidgets.cpp.

1458 {
1459  QPoint p = point;
1460  if (coordType == RelativeToScreen)
1461  p = viewport()->mapFromGlobal(p);
1462 
1463  p += scrollBarPosition();
1464 
1466 }
virtual QTextDocument * textDocument() const =0
virtual QWidget * viewport() const =0
virtual QPoint scrollBarPosition() const
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QAbstractTextDocumentLayout * documentLayout() const
Returns the document layout for this document.
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
virtual int hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const =0
Returns the cursor postion for the given point with the specified accuracy.

◆ pasteText()

void QAccessibleTextWidget::pasteText ( int  offset)
virtual

Implements QAccessibleEditableTextInterface.

Reimplemented in QAccessibleTextEdit.

Definition at line 1798 of file qaccessiblewidgets.cpp.

1799 {
1800 #ifndef QT_NO_CLIPBOARD
1802  insertText(offset, text);
1803 #endif
1804 }
QString text(int startOffset, int endOffset)
void insertText(int offset, const QString &text)
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QClipboard * clipboard()
Returns a pointer to the application global clipboard.
QString text(Mode mode=Clipboard) const
Returns the clipboard text as plain text, or an empty string if the clipboard does not contain any te...
Definition: qclipboard.cpp:357

◆ removeSelection()

void QAccessibleTextWidget::removeSelection ( int  selectionIndex)
virtual

Implements QAccessibleTextInterface.

Definition at line 1721 of file qaccessiblewidgets.cpp.

1722 {
1723  if (selectionIndex != 0)
1724  return;
1725 
1726  QTextCursor cursor = textCursor();
1727  cursor.clearSelection();
1728  setTextCursor(cursor);
1729 }
virtual QTextCursor textCursor() const =0
virtual void setTextCursor(const QTextCursor &)=0
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
void clearSelection()
Clears the current selection by setting the anchor to the cursor position.

◆ replaceText()

void QAccessibleTextWidget::replaceText ( int  startOffset,
int  endOffset,
const QString text 
)
virtual

Implements QAccessibleEditableTextInterface.

Definition at line 1773 of file qaccessiblewidgets.cpp.

1774 {
1775  QTextCursor cursor = textCursorForRange(startOffset, endOffset);
1776 
1777  cursor.removeSelectedText();
1778  cursor.insertText(text);
1779 }
QTextCursor textCursorForRange(int startOffset, int endOffset) const
void insertText(const QString &text)
Inserts text at the current position, using the current character format.
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
void removeSelectedText()
If there is a selection, its content is deleted; otherwise does nothing.

◆ scrollBarPosition()

QPoint QAccessibleTextWidget::scrollBarPosition ( ) const
protectedvirtual

Reimplemented in QAccessibleTextEdit, and QAccessiblePlainTextEdit.

Definition at line 1610 of file qaccessiblewidgets.cpp.

Referenced by characterRect(), and offsetAtPoint().

1611 {
1612  return QPoint(0, 0);
1613 }
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53

◆ selection()

void QAccessibleTextWidget::selection ( int  selectionIndex,
int *  startOffset,
int *  endOffset 
)
virtual

Implements QAccessibleTextInterface.

Definition at line 1588 of file qaccessiblewidgets.cpp.

1589 {
1590  *startOffset = *endOffset = 0;
1591  QTextCursor cursor = textCursor();
1592 
1593  if (selectionIndex != 0 || !cursor.hasSelection())
1594  return;
1595 
1596  *startOffset = cursor.selectionStart();
1597  *endOffset = cursor.selectionEnd();
1598 }
virtual QTextCursor textCursor() const =0
int selectionEnd() const
Returns the end of the selection or position() if the cursor doesn&#39;t have a selection.
bool hasSelection() const
Returns true if the cursor contains a selection; otherwise returns false.
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
int selectionStart() const
Returns the start of the selection or position() if the cursor doesn&#39;t have a selection.

◆ selectionCount()

int QAccessibleTextWidget::selectionCount ( )
virtual

Implements QAccessibleTextInterface.

Definition at line 1468 of file qaccessiblewidgets.cpp.

1469 {
1470  return textCursor().hasSelection() ? 1 : 0;
1471 }
virtual QTextCursor textCursor() const =0
bool hasSelection() const
Returns true if the cursor contains a selection; otherwise returns false.

◆ setAttributes()

void QAccessibleTextWidget::setAttributes ( int  startOffset,
int  endOffset,
const QString attributes 
)
virtual

Implements QAccessibleEditableTextInterface.

Reimplemented in QAccessibleTextEdit.

Definition at line 1404 of file qaccessiblewidgets.cpp.

1405 {
1406  //TODO: not implemented
1407  Q_UNUSED(startOffset);
1408  Q_UNUSED(endOffset);
1409  Q_UNUSED(attributes);
1410 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ setCursorPosition()

void QAccessibleTextWidget::setCursorPosition ( int  position)
virtual

Implements QAccessibleTextInterface.

Definition at line 1709 of file qaccessiblewidgets.cpp.

Referenced by QAccessibleTextEdit::invokeMethodEx().

1710 {
1711  QTextCursor cursor = textCursor();
1712  cursor.setPosition(position);
1713  setTextCursor(cursor);
1714 }
virtual QTextCursor textCursor() const =0
virtual void setTextCursor(const QTextCursor &)=0
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
void setPosition(int pos, MoveMode mode=MoveAnchor)
Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified...

◆ setSelection()

void QAccessibleTextWidget::setSelection ( int  selectionIndex,
int  startOffset,
int  endOffset 
)
virtual

Implements QAccessibleTextInterface.

Definition at line 1731 of file qaccessiblewidgets.cpp.

Referenced by addSelection().

1732 {
1733  if (selectionIndex != 0)
1734  return;
1735 
1736  QTextCursor cursor = textCursor();
1737  cursor.setPosition(startOffset, QTextCursor::MoveAnchor);
1738  cursor.setPosition(endOffset, QTextCursor::KeepAnchor);
1739  setTextCursor(cursor);
1740 }
virtual QTextCursor textCursor() const =0
virtual void setTextCursor(const QTextCursor &)=0
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
void setPosition(int pos, MoveMode mode=MoveAnchor)
Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified...

◆ setTextCursor()

virtual void QAccessibleTextWidget::setTextCursor ( const QTextCursor )
protectedpure virtual

◆ text()

QString QAccessibleTextWidget::text ( int  startOffset,
int  endOffset 
)
virtual

Implements QAccessibleTextInterface.

Definition at line 1600 of file qaccessiblewidgets.cpp.

Referenced by copyText(), cutText(), pasteText(), textAfterOffset(), textAtOffset(), and textBeforeOffset().

1601 {
1602  QTextCursor cursor = textCursor();
1603 
1604  cursor.setPosition(startOffset, QTextCursor::MoveAnchor);
1605  cursor.setPosition(endOffset, QTextCursor::KeepAnchor);
1606 
1607  return cursor.selectedText();
1608 }
virtual QTextCursor textCursor() const =0
QString selectedText() const
Returns the current selection&#39;s text (which may be empty).
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
void setPosition(int pos, MoveMode mode=MoveAnchor)
Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified...

◆ textAfterOffset()

QString QAccessibleTextWidget::textAfterOffset ( int  offset,
QAccessible2::BoundaryType  boundaryType,
int *  startOffset,
int *  endOffset 
)
virtual

Implements QAccessibleTextInterface.

Definition at line 1680 of file qaccessiblewidgets.cpp.

1682 {
1683  Q_ASSERT(startOffset);
1684  Q_ASSERT(endOffset);
1685 
1686  QPair<int, int> boundaries = getBoundaries(offset, boundaryType);
1687  boundaries = getBoundaries(boundaries.second, boundaryType);
1688 
1689  *startOffset = boundaries.first;
1690  *endOffset = boundaries.second;
1691 
1692  return text(boundaries.first, boundaries.second);
1693 }
QString text(int startOffset, int endOffset)
T1 first
Definition: qpair.h:65
T2 second
Definition: qpair.h:66
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QPair< int, int > getBoundaries(int offset, QAccessible2::BoundaryType boundaryType)

◆ textAtOffset()

QString QAccessibleTextWidget::textAtOffset ( int  offset,
QAccessible2::BoundaryType  boundaryType,
int *  startOffset,
int *  endOffset 
)
virtual

Implements QAccessibleTextInterface.

Definition at line 1695 of file qaccessiblewidgets.cpp.

1697 {
1698  Q_ASSERT(startOffset);
1699  Q_ASSERT(endOffset);
1700 
1701  QPair<int, int> boundaries = getBoundaries(offset, boundaryType);
1702 
1703  *startOffset = boundaries.first;
1704  *endOffset = boundaries.second;
1705 
1706  return text(boundaries.first, boundaries.second);
1707 }
QString text(int startOffset, int endOffset)
T1 first
Definition: qpair.h:65
T2 second
Definition: qpair.h:66
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QPair< int, int > getBoundaries(int offset, QAccessible2::BoundaryType boundaryType)

◆ textBeforeOffset()

QString QAccessibleTextWidget::textBeforeOffset ( int  offset,
QAccessible2::BoundaryType  boundaryType,
int *  startOffset,
int *  endOffset 
)
virtual

Implements QAccessibleTextInterface.

Definition at line 1665 of file qaccessiblewidgets.cpp.

1667 {
1668  Q_ASSERT(startOffset);
1669  Q_ASSERT(endOffset);
1670 
1671  QPair<int, int> boundaries = getBoundaries(offset, boundaryType);
1672  boundaries = getBoundaries(boundaries.first - 1, boundaryType);
1673 
1674  *startOffset = boundaries.first;
1675  *endOffset = boundaries.second;
1676 
1677  return text(boundaries.first, boundaries.second);
1678 }
QString text(int startOffset, int endOffset)
T1 first
Definition: qpair.h:65
T2 second
Definition: qpair.h:66
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QPair< int, int > getBoundaries(int offset, QAccessible2::BoundaryType boundaryType)

◆ textCursor()

virtual QTextCursor QAccessibleTextWidget::textCursor ( ) const
protectedpure virtual

◆ textCursorForRange()

QTextCursor QAccessibleTextWidget::textCursorForRange ( int  startOffset,
int  endOffset 
) const
protected

Definition at line 1749 of file qaccessiblewidgets.cpp.

Referenced by QAccessibleTextEdit::copyText(), QAccessibleTextEdit::cutText(), deleteText(), and replaceText().

1750 {
1751  QTextCursor cursor = textCursor();
1752  cursor.setPosition(startOffset, QTextCursor::MoveAnchor);
1753  cursor.setPosition(endOffset, QTextCursor::KeepAnchor);
1754 
1755  return cursor;
1756 }
virtual QTextCursor textCursor() const =0
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
void setPosition(int pos, MoveMode mode=MoveAnchor)
Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified...

◆ textDocument()

virtual QTextDocument* QAccessibleTextWidget::textDocument ( ) const
protectedpure virtual

◆ viewport()

virtual QWidget* QAccessibleTextWidget::viewport ( ) const
protectedpure virtual

The documentation for this class was generated from the following files: