summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2010-06-05 21:23:42 (GMT)
committerLars Knoll <lars.knoll@nokia.com>2010-06-09 22:08:16 (GMT)
commit726607baf707318de6f685573553d22df4966f61 (patch)
tree16f7d7a64661920f52a46b3afa31eefab78b82bf /src
parentb69e592b2b8fb3eae75c112e491e3ed90fc0248a (diff)
downloadQt-726607baf707318de6f685573553d22df4966f61.zip
Qt-726607baf707318de6f685573553d22df4966f61.tar.gz
Qt-726607baf707318de6f685573553d22df4966f61.tar.bz2
consistent handling of directionality in QTextLayout
Make sure we use the same method to determine RTL/LTR for the layout everywhere. Task-number: Part of QT-3292 Reviewed-by: Simon Hausmann
Diffstat (limited to 'src')
-rw-r--r--src/gui/text/qtextengine.cpp31
-rw-r--r--src/gui/text/qtextengine_p.h1
-rw-r--r--src/gui/text/qtextlayout.cpp6
3 files changed, 23 insertions, 15 deletions
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp
index 191508c..ac1fffd 100644
--- a/src/gui/text/qtextengine.cpp
+++ b/src/gui/text/qtextengine.cpp
@@ -1405,17 +1405,7 @@ void QTextEngine::itemize() const
bool ignore = ignoreBidi;
#endif
- bool rtl = false;
- switch (option.textDirection()) {
- case Qt::LeftToRight:
- break;
- case Qt::RightToLeft:
- rtl = true;
- break;
- case Qt::LayoutDirectionAuto:
- rtl = layoutData->string.isRightToLeft();
- break;
- }
+ bool rtl = isRightToLeft();
if (!ignore && !rtl) {
ignore = true;
@@ -1528,6 +1518,23 @@ void QTextEngine::itemize() const
resolveAdditionalFormats();
}
+bool QTextEngine::isRightToLeft() const
+{
+ switch (option.textDirection()) {
+ case Qt::LeftToRight:
+ return false;
+ case Qt::RightToLeft:
+ return true;
+ default:
+ break;
+ }
+ // this places the cursor in the right position depending on the keyboard layout
+ if (layoutData->string.isEmpty())
+ return QApplication::keyboardInputDirection() == Qt::RightToLeft;
+ return layoutData->string.isRightToLeft();
+}
+
+
int QTextEngine::findItem(int strPos) const
{
itemize();
@@ -2524,7 +2531,7 @@ QFixed QTextEngine::calculateTabWidth(int item, QFixed x) const
QList<QTextOption::Tab> tabArray = option.tabs();
if (!tabArray.isEmpty()) {
- if (option.textDirection() == Qt::RightToLeft) { // rebase the tabArray positions.
+ if (isRightToLeft()) { // rebase the tabArray positions.
QList<QTextOption::Tab> newTabs;
QList<QTextOption::Tab>::Iterator iter = tabArray.begin();
while(iter != tabArray.end()) {
diff --git a/src/gui/text/qtextengine_p.h b/src/gui/text/qtextengine_p.h
index 00b1392..908a0ec 100644
--- a/src/gui/text/qtextengine_p.h
+++ b/src/gui/text/qtextengine_p.h
@@ -458,6 +458,7 @@ public:
void validate() const;
void itemize() const;
+ bool isRightToLeft() const;
static void bidiReorder(int numRuns, const quint8 *levels, int *visualOrder);
const HB_CharAttributes *attributes() const;
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp
index f5e252c..ddf9411 100644
--- a/src/gui/text/qtextlayout.cpp
+++ b/src/gui/text/qtextlayout.cpp
@@ -69,7 +69,7 @@ static inline QFixed leadingSpaceWidth(QTextEngine *eng, const QScriptLine &line
if (!line.hasTrailingSpaces
|| (eng->option.flags() & QTextOption::IncludeTrailingSpaces)
|| !(eng->option.alignment() & Qt::AlignRight)
- || (eng->option.textDirection() != Qt::RightToLeft))
+ || !eng->isRightToLeft())
return QFixed();
int pos = line.length;
@@ -86,7 +86,7 @@ static QFixed alignLine(QTextEngine *eng, const QScriptLine &line)
// if width is QFIXED_MAX that means we used setNumColumns() and that implicitly makes this line left aligned.
if (!line.justified && line.width != QFIXED_MAX) {
int align = eng->option.alignment();
- if (align & Qt::AlignJustify && eng->option.textDirection() == Qt::RightToLeft)
+ if (align & Qt::AlignJustify && eng->isRightToLeft())
align = Qt::AlignRight;
if (align & Qt::AlignRight)
x = line.width - (line.textAdvance + leadingSpaceWidth(eng, line));
@@ -1337,7 +1337,7 @@ void QTextLayout::drawCursor(QPainter *p, const QPointF &pos, int cursorPosition
int itm = d->findItem(cursorPosition - 1);
QFixed base = sl.base();
QFixed descent = sl.descent;
- bool rightToLeft = (d->option.textDirection() == Qt::RightToLeft);
+ bool rightToLeft = d->isRightToLeft();
if (itm >= 0) {
const QScriptItem &si = d->layoutData->items.at(itm);
if (si.ascent > 0)