From 1ca970c48e9c36ed540da1a678361db2ec0c5426 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 1 Jan 2008 20:58:36 +0000 Subject: [PATCH] added the method void invertLayout(bool invert); it inverts the layout of the icons if the orientation is horizontal, normally we get icon on the left with left-to-right languages, this inverts the behaviour svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=755562 --- widgets/icon.cpp | 18 +++++++++++++----- widgets/icon.h | 7 +++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/widgets/icon.cpp b/widgets/icon.cpp index a06e9cb02..40b5c5810 100644 --- a/widgets/icon.cpp +++ b/widgets/icon.cpp @@ -62,7 +62,8 @@ Icon::Private::Private() svgElements(0), iconSize(48, 48), states(Private::NoState), - orientation(Qt::Vertical) + orientation(Qt::Vertical), + invertLayout(false) { svg.setContentType(Plasma::Svg::ImageSet); @@ -636,6 +637,8 @@ QPointF Icon::Private::iconPosition(const QStyleOptionGraphicsItem *option, cons // Compute the nominal decoration rectangle const QSizeF size = addMargin(iconSize, Private::IconMargin); + Qt::LayoutDirection direction = iconDirection(option); + //alignment depends from orientation and option->direction Qt::Alignment alignment; if (text.isEmpty() && infoText.isEmpty()) { @@ -644,10 +647,10 @@ QPointF Icon::Private::iconPosition(const QStyleOptionGraphicsItem *option, cons alignment = Qt::Alignment(Qt::AlignHCenter | Qt::AlignTop); //Horizontal }else{ - alignment = QStyle::visualAlignment(option->direction, Qt::Alignment(Qt::AlignLeft | Qt::AlignVCenter)); + alignment = QStyle::visualAlignment(direction, Qt::Alignment(Qt::AlignLeft | Qt::AlignVCenter)); } - const QRect iconRect = QStyle::alignedRect(option->direction, alignment, size.toSize(), itemRect.toRect()); + const QRect iconRect = QStyle::alignedRect(direction, alignment, size.toSize(), itemRect.toRect()); // Position the pixmap in the center of the rectangle QRect pixmapRect = pixmap.rect(); @@ -683,7 +686,7 @@ QRectF Icon::Private::labelRectangle(const QStyleOptionGraphicsItem *option, con textArea.translate(itemRect.topLeft()); - return QRectF(QStyle::visualRect(option->direction, option->rect, textArea.toRect())); + return QRectF(QStyle::visualRect(iconDirection(option), option->rect, textArea.toRect())); } // Lays the text out in a rectangle no larger than constraints, eliding it as necessary @@ -816,7 +819,7 @@ void Icon::Private::layoutTextItems(const QStyleOptionGraphicsItem *option, // Compute the bounding rect of the text const Qt::Alignment alignment = labelLayout->textOption().alignment(); const QSizeF size(qMax(labelSize.width(), infoSize.width()), labelSize.height() + infoSize.height()); - *textBoundingRect = QStyle::alignedRect(option->direction, alignment, size.toSize(), textRect.toRect()); + *textBoundingRect = QStyle::alignedRect(iconDirection(option), alignment, size.toSize(), textRect.toRect()); // Compute the positions where we should draw the layouts labelLayout->setPosition(QPointF(textRect.x(), textBoundingRect->y())); @@ -1120,6 +1123,11 @@ void Icon::setOrientation(Qt::Orientation orientation) d->orientation = orientation; } +void Icon::invertLayout(bool invert) +{ + d->invertLayout = invert; +} + QSizeF Icon::sizeFromIconSize(const qreal iconWidth) const { //no text, less calculations diff --git a/widgets/icon.h b/widgets/icon.h index 034d2a86c..f92774e08 100644 --- a/widgets/icon.h +++ b/widgets/icon.h @@ -151,6 +151,13 @@ public: */ void setOrientation(Qt::Orientation orientation); + /** + * inverts the layout of the icons if the orientation is horizontal, + * normally we get icon on the left with left-to-right languages + * @param invert if we want to invert the layout of icons + */ + void invertLayout(bool invert); + /** * @return optimal size given a size for the icon * @param iconWidth desidered width of the icon