1138 |
1138 |
1139 return p->blockCharFormatIndex(n); |
1139 return p->blockCharFormatIndex(n); |
1140 } |
1140 } |
1141 |
1141 |
1142 /*! |
1142 /*! |
|
1143 \since 4.7 |
|
1144 |
|
1145 Returns the resolved text direction. |
|
1146 |
|
1147 If the block has no explicit direction set, it will resolve the |
|
1148 direction from the blocks content. Returns either Qt::LeftToRight |
|
1149 or Qt::RightToLeft. |
|
1150 |
|
1151 \sa QTextFormat::layoutDirection(), QString::isRightToLeft(), Qt::LayoutDirection |
|
1152 */ |
|
1153 Qt::LayoutDirection QTextBlock::textDirection() const |
|
1154 { |
|
1155 Qt::LayoutDirection dir = blockFormat().layoutDirection(); |
|
1156 if (dir != Qt::LayoutDirectionAuto) |
|
1157 return dir; |
|
1158 |
|
1159 const QString buffer = p->buffer(); |
|
1160 |
|
1161 const int pos = position(); |
|
1162 QTextDocumentPrivate::FragmentIterator it = p->find(pos); |
|
1163 QTextDocumentPrivate::FragmentIterator end = p->find(pos + length() - 1); // -1 to omit the block separator char |
|
1164 for (; it != end; ++it) { |
|
1165 const QTextFragmentData * const frag = it.value(); |
|
1166 const QChar *p = buffer.constData() + frag->stringPosition; |
|
1167 const QChar * const end = p + frag->size_array[0]; |
|
1168 while (p < end) { |
|
1169 switch(QChar::direction(p->unicode())) |
|
1170 { |
|
1171 case QChar::DirL: |
|
1172 return Qt::LeftToRight; |
|
1173 case QChar::DirR: |
|
1174 case QChar::DirAL: |
|
1175 return Qt::RightToLeft; |
|
1176 default: |
|
1177 break; |
|
1178 } |
|
1179 ++p; |
|
1180 } |
|
1181 } |
|
1182 return Qt::LeftToRight; |
|
1183 } |
|
1184 |
|
1185 /*! |
1143 Returns the block's contents as plain text. |
1186 Returns the block's contents as plain text. |
1144 |
1187 |
1145 \sa length() charFormat() blockFormat() |
1188 \sa length() charFormat() blockFormat() |
1146 */ |
1189 */ |
1147 QString QTextBlock::text() const |
1190 QString QTextBlock::text() const |