summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-08-27 11:46:55 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-08-27 14:54:19 (GMT)
commite534abc781cb5751736d24a1a5610370c243b519 (patch)
tree38426220b5962f486d90195358d9ece77d584eed /src/gui
parent2c6cfddf3e1f3674f0b70880c12f6812650cd08d (diff)
downloadQt-e534abc781cb5751736d24a1a5610370c243b519.zip
Qt-e534abc781cb5751736d24a1a5610370c243b519.tar.gz
Qt-e534abc781cb5751736d24a1a5610370c243b519.tar.bz2
Refactor the way QCommonStyle layout the tab
Merge all the code in a common layoutTab function This commit only moves the code around and doesn't change any behavour. The fixes for the broken layouts will go in another commit Reviewed-by: jbache
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/styles/qcommonstyle.cpp165
-rw-r--r--src/gui/styles/qcommonstyle_p.h3
2 files changed, 87 insertions, 81 deletions
diff --git a/src/gui/styles/qcommonstyle.cpp b/src/gui/styles/qcommonstyle.cpp
index 2dab9b3..ccdce28 100644
--- a/src/gui/styles/qcommonstyle.cpp
+++ b/src/gui/styles/qcommonstyle.cpp
@@ -870,7 +870,6 @@ int QCommonStylePrivate::lookupToolButtonStyle() const
#ifndef QT_NO_ITEMVIEWS
-
QSize QCommonStylePrivate::viewItemSize(const QStyleOptionViewItemV4 *option, int role) const
{
Q_Q(const QCommonStyle);
@@ -1158,6 +1157,83 @@ void QCommonStylePrivate::viewItemLayout(const QStyleOptionViewItemV4 *opt, QRe
}
#endif // QT_NO_ITEMVIEWS
+
+#ifndef QT_NO_TABBAR
+/*! \internal
+ Compute the textRect and the pixmapRect from the opt rect
+
+ Uses the same computation than in QTabBar::tabSizeHint
+ */
+void QCommonStylePrivate::tabLayout(const QStyleOptionTabV3 *opt, const QWidget *widget, QRect *textRect, QRect *iconRect) const
+{
+ Q_ASSERT(textRect);
+ Q_ASSERT(iconRect);
+ QRect tr = opt->rect;
+ bool verticalTabs = opt->shape == QTabBar::RoundedEast
+ || opt->shape == QTabBar::RoundedWest
+ || opt->shape == QTabBar::TriangularEast
+ || opt->shape == QTabBar::TriangularWest;
+ if (verticalTabs)
+ tr.setRect(0, 0, tr.height(), tr.width()); //0, 0 as we will have a translate transform
+
+ int verticalShift = proxyStyle->pixelMetric(QStyle::PM_TabBarTabShiftVertical, opt, widget);
+ int horizontalShift = proxyStyle->pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, opt, widget);
+ int hpadding = proxyStyle->pixelMetric(QStyle::PM_TabBarTabHSpace, opt, widget) / 2;
+ int vpadding = proxyStyle->pixelMetric(QStyle::PM_TabBarTabVSpace, opt, widget) / 2;
+ if (opt->shape == QTabBar::RoundedSouth || opt->shape == QTabBar::TriangularSouth)
+ verticalShift = -verticalShift;
+ tr.adjust(hpadding, vpadding, horizontalShift - hpadding, verticalShift - vpadding);
+ bool selected = opt->state & QStyle::State_Selected;
+ if (selected) {
+ tr.setBottom(tr.bottom() - verticalShift);
+ tr.setRight(tr.right() - horizontalShift);
+ }
+
+ // left widget
+ if (!opt->leftButtonSize.isEmpty()) {
+ tr.setLeft(tr.left() + 6 + 2 +
+ (verticalTabs ? opt->leftButtonSize.height() : opt->leftButtonSize.width()));
+ }
+
+ // icon
+ if (!opt->icon.isNull()) {
+ QSize iconSize = opt->iconSize;
+ if (!iconSize.isValid()) {
+ int iconExtent = proxyStyle->pixelMetric(QStyle::PM_SmallIconSize);
+ iconSize = QSize(iconExtent, iconExtent);
+ }
+ QSize tabIconSize = opt->icon.actualSize(iconSize,
+ (opt->state & QStyle::State_Enabled) ? QIcon::Normal : QIcon::Disabled,
+ (opt->state & QStyle::State_Selected) ? QIcon::On : QIcon::Off );
+
+ int left = opt->rect.left();
+ int offset = 4;
+ if (opt->leftButtonSize.isEmpty())
+ offset += 2;
+ else
+ left += opt->leftButtonSize.width() + (6 + 2) + 2;
+
+ *iconRect = QRect(left + offset, tr.center().y() - tabIconSize.height() / 2,
+ tabIconSize.width(), tabIconSize .height());
+ if (!verticalTabs)
+ *iconRect = proxyStyle->visualRect(opt->direction, opt->rect, *iconRect);
+ tr.setLeft(tr.left() + tabIconSize.width() + offset + 2);
+ }
+
+ // right widget
+ if (!opt->rightButtonSize.isEmpty()) {
+ tr.setRight(tr.right() - 6 - 2 -
+ (verticalTabs ? opt->rightButtonSize.height() : opt->rightButtonSize.width()));
+ }
+
+ if (!verticalTabs)
+ tr = proxyStyle->visualRect(opt->direction, opt->rect, tr);
+
+ *textRect = tr;
+}
+#endif //QT_NO_TABBAR
+
+
/*!
\reimp
*/
@@ -1840,38 +1916,20 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
newY = tr.y() + tr.height();
newRot = -90;
}
- tr.setRect(0, 0, tr.height(), tr.width());
QTransform m = QTransform::fromTranslate(newX, newY);
m.rotate(newRot);
p->setTransform(m, true);
}
- tr = subElementRect(SE_TabBarTabText, opt, widget);
+ QRect iconRect;
+ d->tabLayout(&tabV2, widget, &tr, &iconRect);
+ tr = proxy()->subElementRect(SE_TabBarTabText, opt, widget); //we compute tr twice because the style may override subElementRect
if (!tabV2.icon.isNull()) {
- QSize iconSize = tabV2.iconSize;
- if (!iconSize.isValid()) {
- int iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
- iconSize = QSize(iconExtent, iconExtent);
- }
- QSize tabIconSize = tabV2.icon.actualSize(iconSize,
- (tabV2.state & State_Enabled) ? QIcon::Normal
- : QIcon::Disabled);
- QPixmap tabIcon = tabV2.icon.pixmap(iconSize,
+ QPixmap tabIcon = tabV2.icon.pixmap(tabV2.iconSize,
(tabV2.state & State_Enabled) ? QIcon::Normal
: QIcon::Disabled,
(tabV2.state & State_Selected) ? QIcon::On
: QIcon::Off);
-
- int offset = 4;
- int left = opt->rect.left();
- if (tabV2.leftButtonSize.isEmpty())
- offset += 2;
- else
- left += tabV2.leftButtonSize.width() + (6 + 2) + 2;
- QRect iconRect = QRect(left + offset, tr.center().y() - tabIcon.height() / 2,
- tabIconSize.width(), tabIconSize.height());
- if (!verticalTabs)
- iconRect = visualRect(opt->direction, opt->rect, iconRect);
p->drawPixmap(iconRect.x(), iconRect.y(), tabIcon);
}
@@ -2718,65 +2776,10 @@ QRect QCommonStyle::subElementRect(SubElement sr, const QStyleOption *opt,
}
break;
case SE_TabBarTabText:
- // ### consider merging this with CE_TabBarTabLabel
if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
- QStyleOptionTabV3 tabV2(*tab);
- QRect tr = tabV2.rect;
- bool verticalTabs = tabV2.shape == QTabBar::RoundedEast
- || tabV2.shape == QTabBar::RoundedWest
- || tabV2.shape == QTabBar::TriangularEast
- || tabV2.shape == QTabBar::TriangularWest;
- if (verticalTabs)
- tr.setRect(0, 0, tr.height(), tr.width());
- int verticalShift = pixelMetric(QStyle::PM_TabBarTabShiftVertical, tab, widget);
- int horizontalShift = pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, tab, widget);
- int hpadding = proxy()->pixelMetric(QStyle::PM_TabBarTabHSpace, opt, widget) / 2;
- int vpadding = proxy()->pixelMetric(QStyle::PM_TabBarTabVSpace, opt, widget) / 2;
- if (tabV2.shape == QTabBar::RoundedSouth || tabV2.shape == QTabBar::TriangularSouth)
- verticalShift = -verticalShift;
- tr.adjust(hpadding, vpadding, horizontalShift - hpadding, verticalShift - vpadding);
- bool selected = tabV2.state & State_Selected;
- if (selected) {
- tr.setBottom(tr.bottom() - verticalShift);
- tr.setRight(tr.right() - horizontalShift);
- }
-
- // left widget
- if (!tabV2.leftButtonSize.isEmpty()) {
- tr.setLeft(tr.left() + 6 + 2 +
- (verticalTabs ? tabV2.leftButtonSize.height() : tabV2.leftButtonSize.width()));
- }
-
- // icon
- if (!tabV2.icon.isNull()) {
- QSize iconSize = tabV2.iconSize;
- if (!iconSize.isValid()) {
- int iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
- iconSize = QSize(iconExtent, iconExtent);
- }
- QSize tabIconSize = tabV2.icon.actualSize(iconSize,
- (tabV2.state & State_Enabled) ? QIcon::Normal
- : QIcon::Disabled);
- int offset = 4;
- if (tabV2.leftButtonSize.isEmpty())
- offset += 2;
-
- QRect iconRect = QRect(tr.left() + offset, tr.center().y() - tabIconSize.height() / 2,
- tabIconSize.width(), tabIconSize .height());
- if (!verticalTabs)
- iconRect = visualRect(opt->direction, opt->rect, iconRect);
- tr.setLeft(tr.left() + tabIconSize.width() + offset + 2);
- }
-
- // right widget
- if (!tabV2.rightButtonSize.isEmpty()) {
- tr.setRight(tr.right() - 6 - 2 -
- (verticalTabs ? tabV2.rightButtonSize.height() : tabV2.rightButtonSize.width()));
- }
-
- if (!verticalTabs)
- tr = visualRect(opt->direction, opt->rect, tr);
- r = tr;
+ QStyleOptionTabV3 tabV3(*tab);
+ QRect dummyIconRect;
+ d->tabLayout(&tabV3, widget, &r, &dummyIconRect);
}
break;
case SE_TabBarTabLeftButton:
diff --git a/src/gui/styles/qcommonstyle_p.h b/src/gui/styles/qcommonstyle_p.h
index 7e58b37..14f5558 100644
--- a/src/gui/styles/qcommonstyle_p.h
+++ b/src/gui/styles/qcommonstyle_p.h
@@ -123,6 +123,9 @@ public:
#endif
mutable QIcon tabBarcloseButtonIcon;
int lookupToolButtonStyle() const;
+#ifndef QT_NO_TABBAR
+ void tabLayout(const QStyleOptionTabV3 *opt, const QWidget *widget, QRect *textRect, QRect *pixmapRect) const;
+#endif
};
QT_END_NAMESPACE