summaryrefslogtreecommitdiffstats
path: root/src/gui/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/qlabel.cpp27
-rw-r--r--src/gui/widgets/qlabel_p.h1
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