diff options
author | Jan-Arve Sæther <jan-arve.saether@nokia.com> | 2010-04-22 13:40:44 (GMT) |
---|---|---|
committer | Jan-Arve Sæther <jan-arve.saether@nokia.com> | 2010-04-22 13:40:44 (GMT) |
commit | 4780f94e391b5e881497c5228661dead42c821fa (patch) | |
tree | 2e60b5f8a599e8c927cad3d218d0126262cfdbea /src/gui/widgets/qtabwidget.cpp | |
parent | 12eac6fa53680b5c7a6c898749a4ac0d3c427c18 (diff) | |
download | Qt-4780f94e391b5e881497c5228661dead42c821fa.zip Qt-4780f94e391b5e881497c5228661dead42c821fa.tar.gz Qt-4780f94e391b5e881497c5228661dead42c821fa.tar.bz2 |
Implement heightForWidth support for QTabWidget and QStackedWidget.
The problem was simply that QTabWidget does not have a layout (it
does manual layouting, and since that the heightForWidth implementation
it inherits from QWidget require that the widget has a layout it will
not work and it always returned -1 for QTabWidget). The solution is then
to reimplement heightForWidth().
Unfortunately the patch has several workarounds for BIC:
1. QWidget::hasHeightForWidth() should really have been virtual. Instead
we add the virtual QWidgetPrivate::hasHeightForWidth().
Since this is a workaround/bugfix for QTabWidget we decided to keep
QWidget::hasHeightForWidth() internal for now.
2. We cannot reimplement a virtual function in QStackedLayout.
We therefore fix QStackedWidget by subclassing QStackedLayout and
reimplement the virtual functions in the subclass.
This is not an ideal fix, but improves QTabWidget and QStackedWidget
wrt height for width.
Task-number: QTBUG-7792
Reviewed-by: Paul
Reviewed-by: Olivier
Diffstat (limited to 'src/gui/widgets/qtabwidget.cpp')
-rw-r--r-- | src/gui/widgets/qtabwidget.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/gui/widgets/qtabwidget.cpp b/src/gui/widgets/qtabwidget.cpp index 583c112..01e9d40 100644 --- a/src/gui/widgets/qtabwidget.cpp +++ b/src/gui/widgets/qtabwidget.cpp @@ -195,6 +195,7 @@ public: void _q_removeTab(int); void _q_tabMoved(int from, int to); void init(); + bool hasHeightForWidth() const; QTabBar *tabs; QStackedWidget *stack; @@ -246,6 +247,15 @@ void QTabWidgetPrivate::init() } +bool QTabWidgetPrivate::hasHeightForWidth() const +{ + bool has = size_policy.hasHeightForWidth(); + if (!has && stack) + has = qt_widget_private(stack)->hasHeightForWidth(); + return has; +} + + /*! Initialize \a option with the values from this QTabWidget. This method is useful for subclasses when they need a QStyleOptionTabWidgetFrame, but don't want to fill @@ -871,6 +881,50 @@ QSize QTabWidget::minimumSizeHint() const .expandedTo(QApplication::globalStrut()); } +/* + \reimp +*/ +int QTabWidget::heightForWidth(int width) const +{ + Q_D(const QTabWidget); + QStyleOptionTabWidgetFrameV2 opt; + initStyleOption(&opt); + opt.state = QStyle::State_None; + + QSize zero(0,0); + const QSize padding = style()->sizeFromContents(QStyle::CT_TabWidget, &opt, zero, this) + .expandedTo(QApplication::globalStrut()); + + QSize lc(0, 0), rc(0, 0); + if (d->leftCornerWidget) + lc = d->leftCornerWidget->sizeHint(); + if(d->rightCornerWidget) + rc = d->rightCornerWidget->sizeHint(); + if (!d->dirty) { + QTabWidget *that = (QTabWidget*)this; + that->setUpLayout(true); + } + QSize t(d->tabs->sizeHint()); + + if(usesScrollButtons()) + t = t.boundedTo(QSize(200,200)); + else + t = t.boundedTo(QApplication::desktop()->size()); + + const bool tabIsHorizontal = (d->pos == North || d->pos == South); + const int contentsWidth = width - padding.width(); + int stackWidth = contentsWidth; + if (!tabIsHorizontal) + stackWidth -= qMax(t.width(), qMax(lc.width(), rc.width())); + + int stackHeight = d->stack->heightForWidth(stackWidth); + QSize s(stackWidth, stackHeight); + + QSize contentSize = basicSize(tabIsHorizontal, lc, rc, s, t); + return (contentSize + padding).expandedTo(QApplication::globalStrut()).height(); +} + + /*! \reimp */ |