summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThierry Bastian <thierry.bastian@nokia.com>2009-08-25 13:33:15 +0200
committerThierry Bastian <thierry.bastian@nokia.com>2009-08-25 13:34:13 +0200
commitf384dd306c022aa70015133be3a7b4d4c8bb1121 (patch)
tree704187f228bb2f7dbc76c9d72ae51e65388cc853 /src
parentf8acf3b9a9398eabef98be7007fd6766574a788a (diff)
Make sure we use layoutDirection from the widget and not always the app
Task-number: 259331
Diffstat (limited to 'src')
-rw-r--r--src/gui/styles/qcleanlooksstyle.cpp4
-rw-r--r--src/gui/styles/qcommonstyle.cpp18
-rw-r--r--src/gui/styles/qplastiquestyle.cpp2
-rw-r--r--src/gui/styles/qstylesheetstyle.cpp8
-rw-r--r--src/gui/styles/qwindowsstyle.cpp6
-rw-r--r--src/gui/styles/qwindowsxpstyle.cpp2
-rw-r--r--src/gui/widgets/qcommandlinkbutton.cpp4
-rw-r--r--src/gui/widgets/qdatetimeedit.cpp1
-rw-r--r--src/gui/widgets/qdatetimeedit_p.h1
-rw-r--r--src/gui/widgets/qmainwindowlayout.cpp2
-rw-r--r--src/gui/widgets/qmenu.cpp6
-rw-r--r--src/gui/widgets/qmenubar.cpp8
-rw-r--r--src/gui/widgets/qtoolbar.cpp8
-rw-r--r--src/gui/widgets/qtoolbarextension.cpp6
14 files changed, 40 insertions, 36 deletions
diff --git a/src/gui/styles/qcleanlooksstyle.cpp b/src/gui/styles/qcleanlooksstyle.cpp
index 0a82c9c256..426ebfd005 100644
--- a/src/gui/styles/qcleanlooksstyle.cpp
+++ b/src/gui/styles/qcleanlooksstyle.cpp
@@ -1499,7 +1499,7 @@ void QCleanlooksStyle::drawControl(ControlElement element, const QStyleOption *o
default:
break;
}
- if (QApplication::layoutDirection() == Qt::RightToLeft) { //reverse layout changes the order of Beginning/end
+ if (toolbar->direction == Qt::RightToLeft) { //reverse layout changes the order of Beginning/end
bool tmp = paintLeftBorder;
paintRightBorder=paintLeftBorder;
paintLeftBorder=tmp;
@@ -4323,7 +4323,7 @@ QRect QCleanlooksStyle::subElementRect(SubElement sr, const QStyleOption *opt, c
if (verticalTitleBar) {
r.adjust(0, 0, 0, -4);
} else {
- if (QApplication::layoutDirection() == Qt::LeftToRight)
+ if (opt->direction == Qt::LeftToRight)
r.adjust(4, 0, 0, 0);
else
r.adjust(0, 0, -4, 0);
diff --git a/src/gui/styles/qcommonstyle.cpp b/src/gui/styles/qcommonstyle.cpp
index d4488ec923..2dab9b3cd9 100644
--- a/src/gui/styles/qcommonstyle.cpp
+++ b/src/gui/styles/qcommonstyle.cpp
@@ -564,7 +564,7 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q
p->translate(opt->rect.x(), opt->rect.y());
if (opt->state & State_Horizontal) {
int x = opt->rect.width() / 3;
- if (QApplication::layoutDirection() == Qt::RightToLeft)
+ if (opt->direction == Qt::RightToLeft)
x -= 2;
if (opt->rect.height() > 4) {
qDrawShadePanel(p, x, 2, 3, opt->rect.height() - 4,
@@ -5224,6 +5224,7 @@ QPixmap QCommonStyle::standardPixmap(StandardPixmap sp, const QStyleOption *opti
Q_UNUSED(sp);
#else
QPixmap pixmap;
+ const bool rtl = (option && option->direction == Qt::RightToLeft) || !option && QApplication::isRightToLeft();
if (QApplication::desktopSettingsAware() && !QIcon::themeName().isEmpty()) {
switch (sp) {
@@ -5382,7 +5383,7 @@ QPixmap QCommonStyle::standardPixmap(StandardPixmap sp, const QStyleOption *opti
switch (sp) {
#ifndef QT_NO_IMAGEFORMAT_XPM
case SP_ToolBarHorizontalExtensionButton:
- if (QApplication::layoutDirection() == Qt::RightToLeft) {
+ if (rtl) {
QImage im(tb_extension_arrow_h_xpm);
im = im.convertToFormat(QImage::Format_ARGB32).mirrored(true, false);
return QPixmap::fromImage(im);
@@ -5398,11 +5399,11 @@ QPixmap QCommonStyle::standardPixmap(StandardPixmap sp, const QStyleOption *opti
#ifndef QT_NO_IMAGEFORMAT_PNG
case SP_CommandLink:
case SP_ArrowForward:
- if (QApplication::layoutDirection() == Qt::RightToLeft)
+ if (rtl)
return proxy()->standardPixmap(SP_ArrowLeft, option, widget);
return proxy()->standardPixmap(SP_ArrowRight, option, widget);
case SP_ArrowBack:
- if (QApplication::layoutDirection() == Qt::RightToLeft)
+ if (rtl)
return proxy()->standardPixmap(SP_ArrowRight, option, widget);
return proxy()->standardPixmap(SP_ArrowLeft, option, widget);
case SP_ArrowLeft:
@@ -5513,6 +5514,7 @@ QIcon QCommonStyle::standardIconImplementation(StandardPixmap standardIcon, cons
const QWidget *widget) const
{
QIcon icon;
+ const bool rtl = (option && option->direction == Qt::RightToLeft) || !option && QApplication::isRightToLeft();
if (QApplication::desktopSettingsAware() && !QIcon::themeName().isEmpty()) {
switch (standardIcon) {
case SP_DirHomeIcon:
@@ -5637,11 +5639,11 @@ QIcon QCommonStyle::standardIconImplementation(StandardPixmap standardIcon, cons
icon = QIcon::fromTheme(QLatin1String("edit-clear"));
break;
case SP_ArrowForward:
- if (QApplication::layoutDirection() == Qt::RightToLeft)
+ if (rtl)
return standardIconImplementation(SP_ArrowLeft, option, widget);
return standardIconImplementation(SP_ArrowRight, option, widget);
case SP_ArrowBack:
- if (QApplication::layoutDirection() == Qt::RightToLeft)
+ if (rtl)
return standardIconImplementation(SP_ArrowRight, option, widget);
return standardIconImplementation(SP_ArrowLeft, option, widget);
case SP_FileLinkIcon:
@@ -5865,11 +5867,11 @@ QIcon QCommonStyle::standardIconImplementation(StandardPixmap standardIcon, cons
icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-no-128.png"));
break;
case SP_ArrowForward:
- if (QApplication::layoutDirection() == Qt::RightToLeft)
+ if (rtl)
return standardIconImplementation(SP_ArrowLeft, option, widget);
return standardIconImplementation(SP_ArrowRight, option, widget);
case SP_ArrowBack:
- if (QApplication::layoutDirection() == Qt::RightToLeft)
+ if (rtl)
return standardIconImplementation(SP_ArrowRight, option, widget);
return standardIconImplementation(SP_ArrowLeft, option, widget);
case SP_ArrowLeft:
diff --git a/src/gui/styles/qplastiquestyle.cpp b/src/gui/styles/qplastiquestyle.cpp
index 04559dcd61..0c3c2a3098 100644
--- a/src/gui/styles/qplastiquestyle.cpp
+++ b/src/gui/styles/qplastiquestyle.cpp
@@ -3749,7 +3749,7 @@ void QPlastiqueStyle::drawControl(ControlElement element, const QStyleOption *op
QPixmap pixmap = comboBox->currentIcon.pixmap(comboBox->iconSize, mode);
QRect iconRect(editRect);
iconRect.setWidth(comboBox->iconSize.width() + 5);
- iconRect = alignedRect(QApplication::layoutDirection(),
+ iconRect = alignedRect(comboBox->direction,
Qt::AlignLeft | Qt::AlignVCenter,
iconRect.size(), editRect);
painter->fillRect(iconRect, option->palette.brush(QPalette::Base));
diff --git a/src/gui/styles/qstylesheetstyle.cpp b/src/gui/styles/qstylesheetstyle.cpp
index 8ac811c6ec..7acb3a6a5b 100644
--- a/src/gui/styles/qstylesheetstyle.cpp
+++ b/src/gui/styles/qstylesheetstyle.cpp
@@ -3196,7 +3196,7 @@ void QStyleSheetStyle::drawComplexControl(ComplexControl cc, const QStyleOptionC
if (subRule.hasDrawable()) {
QRect rect = subRule.boxRect(subControlRect(CC_MdiControls, opt, control, w), Margin);
subRule.drawRule(p, rect);
- QIcon icon = standardIcon(subControlIcon(layoutButton));
+ QIcon icon = standardIcon(subControlIcon(layoutButton), opt);
icon.paint(p, subRule.contentsRect(rect), Qt::AlignCenter);
} else {
optCopy.subControls |= control;
@@ -3643,9 +3643,9 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q
QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, mode);
QRect iconRect(editRect);
iconRect.setWidth(cb->iconSize.width());
- iconRect = alignedRect(QApplication::layoutDirection(),
- Qt::AlignLeft | Qt::AlignVCenter,
- iconRect.size(), editRect);
+ iconRect = alignedRect(cb->direction,
+ Qt::AlignLeft | Qt::AlignVCenter,
+ iconRect.size(), editRect);
drawItemPixmap(p, iconRect, Qt::AlignCenter, pixmap);
if (cb->direction == Qt::RightToLeft)
diff --git a/src/gui/styles/qwindowsstyle.cpp b/src/gui/styles/qwindowsstyle.cpp
index e5588444b4..8097a3d574 100644
--- a/src/gui/styles/qwindowsstyle.cpp
+++ b/src/gui/styles/qwindowsstyle.cpp
@@ -1261,7 +1261,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt,
p->translate(opt->rect.x(), opt->rect.y());
if (opt->state & State_Horizontal) {
int x = opt->rect.width() / 2 - 4;
- if (QApplication::layoutDirection() == Qt::RightToLeft)
+ if (opt->direction == Qt::RightToLeft)
x -= 2;
if (opt->rect.height() > 4) {
qDrawShadePanel(p, x, 2, 3, opt->rect.height() - 4,
@@ -2312,7 +2312,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai
default:
break;
}
- if(QApplication::layoutDirection() == Qt::RightToLeft){ //reverse layout changes the order of Beginning/end
+ if(opt->direction == Qt::RightToLeft){ //reverse layout changes the order of Beginning/end
bool tmp = paintLeftBorder;
paintRightBorder=paintLeftBorder;
paintLeftBorder=tmp;
@@ -2564,7 +2564,7 @@ QRect QWindowsStyle::subElementRect(SubElement sr, const QStyleOption *opt, cons
if (verticalTitleBar) {
r.adjust(0, 0, 0, -m);
} else {
- if (QApplication::layoutDirection() == Qt::LeftToRight)
+ if (opt->direction == Qt::LeftToRight)
r.adjust(m, 0, 0, 0);
else
r.adjust(0, 0, -m, 0);
diff --git a/src/gui/styles/qwindowsxpstyle.cpp b/src/gui/styles/qwindowsxpstyle.cpp
index 0e087308b1..e365873134 100644
--- a/src/gui/styles/qwindowsxpstyle.cpp
+++ b/src/gui/styles/qwindowsxpstyle.cpp
@@ -2331,7 +2331,7 @@ void QWindowsXPStyle::drawControl(ControlElement element, const QStyleOption *op
bool hasIcon = (ico.cacheKey() != QApplication::windowIcon().cacheKey());
if (hasIcon) {
QPixmap pxIco = ico.pixmap(titleHeight);
- if (!verticalTitleBar && QApplication::layoutDirection() == Qt::RightToLeft)
+ if (!verticalTitleBar && dwOpt->direction == Qt::RightToLeft)
p->drawPixmap(rect.width() - titleHeight - pxIco.width(), rect.bottom() - titleHeight - 2, pxIco);
else
p->drawPixmap(fw, rect.bottom() - titleHeight - 2, pxIco);
diff --git a/src/gui/widgets/qcommandlinkbutton.cpp b/src/gui/widgets/qcommandlinkbutton.cpp
index 206221f376..fd69f5595b 100644
--- a/src/gui/widgets/qcommandlinkbutton.cpp
+++ b/src/gui/widgets/qcommandlinkbutton.cpp
@@ -205,7 +205,9 @@ void QCommandLinkButtonPrivate::init()
q->setSizePolicy(policy);
q->setIconSize(QSize(20, 20));
- q->setIcon(q->style()->standardIcon(QStyle::SP_CommandLink));
+ QStyleOptionButton opt;
+ q->initStyleOption(&opt);
+ q->setIcon(q->style()->standardIcon(QStyle::SP_CommandLink, &opt));
}
// Calculates the height of the description text based on widget width
diff --git a/src/gui/widgets/qdatetimeedit.cpp b/src/gui/widgets/qdatetimeedit.cpp
index 5a9c7e16bb..d1ebdf4b4a 100644
--- a/src/gui/widgets/qdatetimeedit.cpp
+++ b/src/gui/widgets/qdatetimeedit.cpp
@@ -1643,7 +1643,6 @@ QDateTimeEditPrivate::QDateTimeEditPrivate()
cachedDay = -1;
currentSectionIndex = FirstSectionIndex;
- layoutDirection = QApplication::layoutDirection();
first.type = FirstSection;
last.type = LastSection;
none.type = NoSection;
diff --git a/src/gui/widgets/qdatetimeedit_p.h b/src/gui/widgets/qdatetimeedit_p.h
index 7b29e51ecd..33c09c0f14 100644
--- a/src/gui/widgets/qdatetimeedit_p.h
+++ b/src/gui/widgets/qdatetimeedit_p.h
@@ -132,7 +132,6 @@ public:
mutable bool cacheGuard;
QString defaultDateFormat, defaultTimeFormat, defaultDateTimeFormat, unreversedFormat;
- Qt::LayoutDirection layoutDirection;
mutable QVariant conflictGuard;
bool hasHadFocus, formatExplicitlySet, calendarPopup;
QStyle::StateFlag arrowState;
diff --git a/src/gui/widgets/qmainwindowlayout.cpp b/src/gui/widgets/qmainwindowlayout.cpp
index 529a22587e..0ea9b565dc 100644
--- a/src/gui/widgets/qmainwindowlayout.cpp
+++ b/src/gui/widgets/qmainwindowlayout.cpp
@@ -1463,7 +1463,7 @@ void QMainWindowLayout::setGeometry(const QRect &_r)
QSize(r.width(), statusbar->heightForWidth(r.width()))
.expandedTo(statusbar->minimumSize()));
sbr.moveBottom(r.bottom());
- QRect vr = QStyle::visualRect(QApplication::layoutDirection(), _r, sbr);
+ QRect vr = QStyle::visualRect(parentWidget()->layoutDirection(), _r, sbr);
statusbar->setGeometry(vr);
r.setBottom(sbr.top() - 1);
}
diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp
index 92d12713c2..f0f425f5c7 100644
--- a/src/gui/widgets/qmenu.cpp
+++ b/src/gui/widgets/qmenu.cpp
@@ -1832,7 +1832,7 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
if (adjustToDesktop) {
//handle popup falling "off screen"
- if (QApplication::layoutDirection() == Qt::RightToLeft) {
+ if (isRightToLeft()) {
if(snapToMouse) //position flowing left from the mouse
pos.setX(mouse.x()-size.width());
@@ -1870,9 +1870,9 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
}
setGeometry(QRect(pos, size));
#ifndef QT_NO_EFFECTS
- int hGuess = QApplication::layoutDirection() == Qt::RightToLeft ? QEffects::LeftScroll : QEffects::RightScroll;
+ int hGuess = isRightToLeft() ? QEffects::LeftScroll : QEffects::RightScroll;
int vGuess = QEffects::DownScroll;
- if (QApplication::layoutDirection() == Qt::RightToLeft) {
+ if (isRightToLeft()) {
if ((snapToMouse && (pos.x() + size.width()/2 > mouse.x())) ||
(qobject_cast<QMenu*>(d->causedPopup.widget) && pos.x() + size.width()/2 > d->causedPopup.widget->x()))
hGuess = QEffects::RightScroll;
diff --git a/src/gui/widgets/qmenubar.cpp b/src/gui/widgets/qmenubar.cpp
index 0967f716e1..6633f2a9a4 100644
--- a/src/gui/widgets/qmenubar.cpp
+++ b/src/gui/widgets/qmenubar.cpp
@@ -132,7 +132,7 @@ QRect QMenuBarPrivate::menuRect(bool extVisible) const
result.adjust(hmargin, 0, -hmargin, 0);
if (extVisible) {
- if (q->layoutDirection() == Qt::RightToLeft)
+ if (q->isRightToLeft())
result.setLeft(result.left() + extension->sizeHint().width());
else
result.setWidth(result.width() - extension->sizeHint().width());
@@ -140,7 +140,7 @@ QRect QMenuBarPrivate::menuRect(bool extVisible) const
if (leftWidget && leftWidget->isVisible()) {
QSize sz = leftWidget->sizeHint();
- if (q->layoutDirection() == Qt::RightToLeft)
+ if (q->isRightToLeft())
result.setRight(result.right() - sz.width());
else
result.setLeft(result.left() + sz.width());
@@ -148,7 +148,7 @@ QRect QMenuBarPrivate::menuRect(bool extVisible) const
if (rightWidget && rightWidget->isVisible()) {
QSize sz = rightWidget->sizeHint();
- if (q->layoutDirection() == Qt::RightToLeft)
+ if (q->isRightToLeft())
result.setLeft(result.left() + sz.width());
else
result.setRight(result.right() - sz.width());
@@ -245,7 +245,7 @@ void QMenuBarPrivate::updateGeometries()
pop->addActions(hiddenActions);
int vmargin = q->style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, q);
- int x = q->layoutDirection() == Qt::RightToLeft
+ int x = q->isRightToLeft()
? menuRect.left() - extension->sizeHint().width() + 1
: menuRect.right();
extension->setGeometry(x, vmargin, extension->sizeHint().width(), menuRect.height() - vmargin*2);
diff --git a/src/gui/widgets/qtoolbar.cpp b/src/gui/widgets/qtoolbar.cpp
index ef0847b819..bf44ea1612 100644
--- a/src/gui/widgets/qtoolbar.cpp
+++ b/src/gui/widgets/qtoolbar.cpp
@@ -205,7 +205,7 @@ void QToolBarPrivate::initDrag(const QPoint &pos)
state->moving = false;
state->widgetItem = 0;
- if (q->layoutDirection() == Qt::RightToLeft)
+ if (q->isRightToLeft())
state->pressPos = QPoint(q->width() - state->pressPos.x(), state->pressPos.y());
}
@@ -359,7 +359,7 @@ bool QToolBarPrivate::mouseMoveEvent(QMouseEvent *event)
QPoint pos = event->globalPos();
// if we are right-to-left, we move so as to keep the right edge the same distance
// from the mouse
- if (q->layoutDirection() == Qt::LeftToRight)
+ if (q->isLeftToRight())
pos -= state->pressPos;
else
pos += QPoint(state->pressPos.x() - q->width(), -state->pressPos.y());
@@ -369,14 +369,14 @@ bool QToolBarPrivate::mouseMoveEvent(QMouseEvent *event)
} else if (state->moving) {
const QPoint rtl(q->width() - state->pressPos.x(), state->pressPos.y()); //for RTL
- const QPoint globalPressPos = q->mapToGlobal(q->layoutDirection() == Qt::RightToLeft ? rtl : state->pressPos);
+ const QPoint globalPressPos = q->mapToGlobal(q->isRightToLeft() ? rtl : state->pressPos);
int pos = 0;
QPoint delta = event->globalPos() - globalPressPos;
if (orientation == Qt::Vertical) {
pos = q->y() + delta.y();
} else {
- if (q->layoutDirection() == Qt::RightToLeft) {
+ if (q->isRightToLeft()) {
pos = win->width() - q->width() - q->x() - delta.x();
} else {
pos = q->x() + delta.x();
diff --git a/src/gui/widgets/qtoolbarextension.cpp b/src/gui/widgets/qtoolbarextension.cpp
index 1f1186ca4b..6a70326c71 100644
--- a/src/gui/widgets/qtoolbarextension.cpp
+++ b/src/gui/widgets/qtoolbarextension.cpp
@@ -61,10 +61,12 @@ QToolBarExtension::QToolBarExtension(QWidget *parent)
void QToolBarExtension::setOrientation(Qt::Orientation o)
{
+ QStyleOption opt;
+ opt.init(this);
if (o == Qt::Horizontal) {
- setIcon(style()->standardIcon(QStyle::SP_ToolBarHorizontalExtensionButton));
+ setIcon(style()->standardIcon(QStyle::SP_ToolBarHorizontalExtensionButton, &opt));
} else {
- setIcon(style()->standardIcon(QStyle::SP_ToolBarVerticalExtensionButton));
+ setIcon(style()->standardIcon(QStyle::SP_ToolBarVerticalExtensionButton, &opt));
}
}