diff options
author | Jiang Jiang <jiang.jiang@nokia.com> | 2010-09-13 14:48:39 (GMT) |
---|---|---|
committer | Jiang Jiang <jiang.jiang@nokia.com> | 2010-09-23 09:59:21 (GMT) |
commit | 9b20aac0ad83b917c46cc44b78dc90fb1d238fe8 (patch) | |
tree | e107dd857f1a09c9355c2d9e8e622ca827a62a01 /src | |
parent | 3f90a835f43258b5c19f82da8a0f1e4d1b348e42 (diff) | |
download | Qt-9b20aac0ad83b917c46cc44b78dc90fb1d238fe8.zip Qt-9b20aac0ad83b917c46cc44b78dc90fb1d238fe8.tar.gz Qt-9b20aac0ad83b917c46cc44b78dc90fb1d238fe8.tar.bz2 |
Fix text direction handling in QLabel
For QLabel, text direction should be determined by actual text
(if it's a simple text label) or the textDirection() property
of the defaultTextOption of corresponding QTextDocument.
Task-number: QTBUG-13552
Reviewed-by: Lars Knoll
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/widgets/qlabel.cpp | 27 | ||||
-rw-r--r-- | src/gui/widgets/qlabel_p.h | 1 |
2 files changed, 17 insertions, 11 deletions
diff --git a/src/gui/widgets/qlabel.cpp b/src/gui/widgets/qlabel.cpp index bdbd0b0..42be03b 100644 --- a/src/gui/widgets/qlabel.cpp +++ b/src/gui/widgets/qlabel.cpp @@ -635,7 +635,7 @@ QSize QLabelPrivate::sizeForWidth(int w) const br = movie->currentPixmap().rect(); #endif else if (isTextLabel) { - int align = QStyle::visualAlignment(q->layoutDirection(), QFlag(this->align)); + int align = QStyle::visualAlignment(textDirection(), QFlag(this->align)); // Add indentation int m = indent; @@ -1059,7 +1059,8 @@ void QLabel::paintEvent(QPaintEvent *) drawFrame(&painter); QRect cr = contentsRect(); cr.adjust(d->margin, d->margin, -d->margin, -d->margin); - int align = QStyle::visualAlignment(layoutDirection(), QFlag(d->align)); + int align = QStyle::visualAlignment(d->isTextLabel ? d->textDirection() + : layoutDirection(), QFlag(d->align)); #ifndef QT_NO_MOVIE if (d->movie) { @@ -1119,7 +1120,8 @@ void QLabel::paintEvent(QPaintEvent *) d->control->drawContents(&painter, QRectF(), this); painter.restore(); } else { - int flags = align; + int flags = align | (d->textDirection() == Qt::LeftToRight ? Qt::TextForceLeftToRight + : Qt::TextForceRightToLeft); if (d->hasShortcut) { flags |= Qt::TextShowMnemonic; if (!style->styleHint(QStyle::SH_UnderlineShortcut, &opt, this)) @@ -1447,10 +1449,6 @@ void QLabel::changeEvent(QEvent *ev) d->control->setPalette(palette()); } else if (ev->type() == QEvent::ContentsRectChange) { d->updateLabel(); - } else if (ev->type() == QEvent::LayoutDirectionChange) { - if (d->isTextLabel && d->control) { - d->sendControlEvent(ev); - } } QFrame::changeEvent(ev); } @@ -1486,6 +1484,15 @@ void QLabel::setScaledContents(bool enable) update(contentsRect()); } +Qt::LayoutDirection QLabelPrivate::textDirection() const +{ + if (control) { + QTextOption opt = control->document()->defaultTextOption(); + return opt.textDirection(); + } + + return text.isRightToLeft() ? Qt::RightToLeft : Qt::LeftToRight; +} /*! \fn void QLabel::setAlignment(Qt::AlignmentFlag flag) @@ -1503,7 +1510,8 @@ QRect QLabelPrivate::documentRect() const Q_ASSERT_X(isTextLabel, "documentRect", "document rect called for label that is not a text label!"); QRect cr = q->contentsRect(); cr.adjust(margin, margin, -margin, -margin); - const int align = QStyle::visualAlignment(q->layoutDirection(), QFlag(this->align)); + const int align = QStyle::visualAlignment(isTextLabel ? textDirection() + : q->layoutDirection(), QFlag(this->align)); int m = indent; if (m < 0 && q->frameWidth()) // no indent, but we do have a frame m = q->fontMetrics().width(QLatin1Char('x')) / 2 - margin; @@ -1564,7 +1572,6 @@ void QLabelPrivate::ensureTextLayouted() const if (!textLayoutDirty) return; ensureTextPopulated(); - Q_Q(const QLabel); if (control) { QTextDocument *doc = control->document(); QTextOption opt = doc->defaultTextOption(); @@ -1576,8 +1583,6 @@ void QLabelPrivate::ensureTextLayouted() const else opt.setWrapMode(QTextOption::ManualWrap); - opt.setTextDirection(q->layoutDirection()); - doc->setDefaultTextOption(opt); QTextFrameFormat fmt = doc->rootFrame()->frameFormat(); diff --git a/src/gui/widgets/qlabel_p.h b/src/gui/widgets/qlabel_p.h index fba7224..83624c7 100644 --- a/src/gui/widgets/qlabel_p.h +++ b/src/gui/widgets/qlabel_p.h @@ -132,6 +132,7 @@ public: QRectF layoutRect() const; QRect documentRect() const; QPoint layoutPoint(const QPoint& p) const; + Qt::LayoutDirection textDirection() const; #ifndef QT_NO_CONTEXTMENU QMenu *createStandardContextMenu(const QPoint &pos); #endif |