diff options
-rw-r--r-- | src/gui/kernel/qlayoutitem.cpp | 4 | ||||
-rw-r--r-- | src/gui/kernel/qstackedlayout.cpp | 26 | ||||
-rw-r--r-- | src/gui/kernel/qstackedlayout.h | 2 | ||||
-rw-r--r-- | src/gui/kernel/qwidget.cpp | 17 | ||||
-rw-r--r-- | src/gui/kernel/qwidget.h | 1 | ||||
-rw-r--r-- | src/gui/kernel/qwidget_p.h | 1 | ||||
-rw-r--r-- | src/gui/widgets/qsizegrip.cpp | 17 | ||||
-rw-r--r-- | src/gui/widgets/qtabwidget.cpp | 49 | ||||
-rw-r--r-- | src/gui/widgets/qtabwidget.h | 1 | ||||
-rw-r--r-- | tests/auto/qtabwidget/tst_qtabwidget.cpp | 47 |
10 files changed, 16 insertions, 149 deletions
diff --git a/src/gui/kernel/qlayoutitem.cpp b/src/gui/kernel/qlayoutitem.cpp index e615b2d..6a91d95 100644 --- a/src/gui/kernel/qlayoutitem.cpp +++ b/src/gui/kernel/qlayoutitem.cpp @@ -516,7 +516,9 @@ bool QWidgetItem::hasHeightForWidth() const { if (isEmpty()) return false; - return wid->hasHeightForWidth(); + if (wid->layout()) + return wid->layout()->hasHeightForWidth(); + return wid->sizePolicy().hasHeightForWidth(); } /*! diff --git a/src/gui/kernel/qstackedlayout.cpp b/src/gui/kernel/qstackedlayout.cpp index 4b49638..7559066 100644 --- a/src/gui/kernel/qstackedlayout.cpp +++ b/src/gui/kernel/qstackedlayout.cpp @@ -475,32 +475,6 @@ void QStackedLayout::setGeometry(const QRect &rect) } } -bool QStackedLayout::hasHeightForWidth() const -{ - const int n = count(); - - for (int i = 0; i < n; ++i) { - if (QLayoutItem *item = itemAt(i)) { - if (item->hasHeightForWidth()) - return true; - } - } - return false; -} - -int QStackedLayout::heightForWidth(int width) const -{ - const int n = count(); - - int hfw = 0; - for (int i = 0; i < n; ++i) { - if (QLayoutItem *item = itemAt(i)) { - hfw = qMax(hfw, item->heightForWidth(width)); - } - } - return hfw; -} - /*! \enum QStackedLayout::StackingMode \since 4.4 diff --git a/src/gui/kernel/qstackedlayout.h b/src/gui/kernel/qstackedlayout.h index 842b62b..c069149 100644 --- a/src/gui/kernel/qstackedlayout.h +++ b/src/gui/kernel/qstackedlayout.h @@ -95,8 +95,6 @@ public: QLayoutItem *itemAt(int) const; QLayoutItem *takeAt(int); void setGeometry(const QRect &rect); - bool hasHeightForWidth() const; - int heightForWidth(int width) const; Q_SIGNALS: void widgetRemoved(int index); diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 399a27b..20d1d30 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -3825,11 +3825,6 @@ void QWidget::setMaximumSize(int maxw, int maxh) d->updateGeometry_helper(d->extra->minw == d->extra->maxw && d->extra->minh == d->extra->maxh); } -bool QWidgetPrivate::hasHeightForWidth() const -{ - return layout ? layout->hasHeightForWidth() : size_policy.hasHeightForWidth(); -} - /*! \overload @@ -7975,18 +7970,6 @@ QSize QWidget::minimumSizeHint() const return QSize(-1, -1); } -/*! - \internal - This is a bit hackish, but ideally this would have been a virtual - function so that subclasses could reimplement their own function. - Instead we add a virtual function to QWidgetPrivate. -*/ -bool QWidget::hasHeightForWidth() const -{ - Q_D(const QWidget); - return d->hasHeightForWidth(); -} - /*! \fn QWidget *QWidget::parentWidget() const diff --git a/src/gui/kernel/qwidget.h b/src/gui/kernel/qwidget.h index 6e5de7d..e12148b 100644 --- a/src/gui/kernel/qwidget.h +++ b/src/gui/kernel/qwidget.h @@ -524,7 +524,6 @@ public: virtual QSize sizeHint() const; virtual QSize minimumSizeHint() const; - bool hasHeightForWidth() const; QSizePolicy sizePolicy() const; void setSizePolicy(QSizePolicy); diff --git a/src/gui/kernel/qwidget_p.h b/src/gui/kernel/qwidget_p.h index 9926b2c..cad60b5 100644 --- a/src/gui/kernel/qwidget_p.h +++ b/src/gui/kernel/qwidget_p.h @@ -493,7 +493,6 @@ public: bool setMinimumSize_helper(int &minw, int &minh); bool setMaximumSize_helper(int &maxw, int &maxh); - virtual bool hasHeightForWidth() const; void setConstraints_sys(); QWidget *childAt_helper(const QPoint &, bool) const; void updateGeometry_helper(bool forceUpdate); diff --git a/src/gui/widgets/qsizegrip.cpp b/src/gui/widgets/qsizegrip.cpp index 40f3129..c9d613a 100644 --- a/src/gui/widgets/qsizegrip.cpp +++ b/src/gui/widgets/qsizegrip.cpp @@ -78,6 +78,15 @@ static QWidget *qt_sizegrip_topLevelWidget(QWidget* w) return w; } +static inline bool hasHeightForWidth(QWidget *widget) +{ + if (!widget) + return false; + if (QLayout *layout = widget->layout()) + return layout->hasHeightForWidth(); + return widget->sizePolicy().hasHeightForWidth(); +} + class QSizeGripPrivate : public QWidgetPrivate { Q_DECLARE_PUBLIC(QSizeGrip) @@ -309,7 +318,7 @@ void QSizeGrip::mousePressEvent(QMouseEvent * e) #ifdef Q_WS_X11 // Use a native X11 sizegrip for "real" top-level windows if supported. if (tlw->isWindow() && X11->isSupportedByWM(ATOM(_NET_WM_MOVERESIZE)) - && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !tlw->hasHeightForWidth()) { + && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !hasHeightForWidth(tlw)) { XEvent xev; xev.xclient.type = ClientMessage; xev.xclient.message_type = ATOM(_NET_WM_MOVERESIZE); @@ -331,7 +340,7 @@ void QSizeGrip::mousePressEvent(QMouseEvent * e) } #endif // Q_WS_X11 #ifdef Q_WS_WIN - if (tlw->isWindow() && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !tlw->hasHeightForWidth()) { + if (tlw->isWindow() && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !hasHeightForWidth(tlw)) { uint orientation = 0; if (d->atBottom()) orientation = d->atLeft() ? SZ_SIZEBOTTOMLEFT : SZ_SIZEBOTTOMRIGHT; @@ -420,12 +429,12 @@ void QSizeGrip::mouseMoveEvent(QMouseEvent * e) #ifdef Q_WS_X11 if (tlw->isWindow() && X11->isSupportedByWM(ATOM(_NET_WM_MOVERESIZE)) - && tlw->isTopLevel() && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !tlw->hasHeightForWidth()) + && tlw->isTopLevel() && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !hasHeightForWidth(tlw)) return; #endif #ifdef Q_WS_WIN if (tlw->isWindow() && GetSystemMenu(tlw->winId(), FALSE) != 0 && internalWinId() - && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !tlw->hasHeightForWidth()) { + && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !hasHeightForWidth(tlw)) { MSG msg; while(PeekMessage(&msg, winId(), WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE)); return; diff --git a/src/gui/widgets/qtabwidget.cpp b/src/gui/widgets/qtabwidget.cpp index 3463241..4a61935 100644 --- a/src/gui/widgets/qtabwidget.cpp +++ b/src/gui/widgets/qtabwidget.cpp @@ -195,7 +195,6 @@ public: void _q_removeTab(int); void _q_tabMoved(int from, int to); void init(); - bool hasHeightForWidth() const; QTabBar *tabs; QStackedWidget *stack; @@ -874,46 +873,6 @@ QSize QTabWidget::minimumSizeHint() const .expandedTo(QApplication::globalStrut()); } -int QTabWidget::heightForWidth(int width) const -{ - Q_D(const QTabWidget); - QStyleOption opt(0); - opt.init(this); - 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 */ @@ -946,14 +905,6 @@ void QTabWidgetPrivate::updateTabBarPosition() q->setUpLayout(); } -bool QTabWidgetPrivate::hasHeightForWidth() const -{ - bool has = size_policy.hasHeightForWidth(); - if (!has && stack) - has = stack->hasHeightForWidth(); - return has; -} - /*! \property QTabWidget::tabPosition \brief the position of the tabs in this tab widget diff --git a/src/gui/widgets/qtabwidget.h b/src/gui/widgets/qtabwidget.h index ee50655..68200c8 100644 --- a/src/gui/widgets/qtabwidget.h +++ b/src/gui/widgets/qtabwidget.h @@ -129,7 +129,6 @@ public: QSize sizeHint() const; QSize minimumSizeHint() const; - int heightForWidth(int width) const; void setCornerWidget(QWidget * w, Qt::Corner corner = Qt::TopRightCorner); QWidget * cornerWidget(Qt::Corner corner = Qt::TopRightCorner) const; diff --git a/tests/auto/qtabwidget/tst_qtabwidget.cpp b/tests/auto/qtabwidget/tst_qtabwidget.cpp index 54e7259..504579f 100644 --- a/tests/auto/qtabwidget/tst_qtabwidget.cpp +++ b/tests/auto/qtabwidget/tst_qtabwidget.cpp @@ -45,7 +45,6 @@ #include <qdebug.h> #include <qapplication.h> #include <qlabel.h> -#include <qboxlayout.h> //TESTED_CLASS= //TESTED_FILES= @@ -121,8 +120,6 @@ class tst_QTabWidget:public QObject { void clear(); void keyboardNavigation(); void paintEventCount(); - void heightForWidth(); - void heightForWidth_data(); private: int addPage(); @@ -627,50 +624,6 @@ void tst_QTabWidget::paintEventCount() QCOMPARE(tab2->count, 1); } -void tst_QTabWidget::heightForWidth_data() -{ - QTest::addColumn<int>("tabPosition"); - QTest::newRow("West") << int(QTabWidget::West); - QTest::newRow("North") << int(QTabWidget::North); - QTest::newRow("East") << int(QTabWidget::East); - QTest::newRow("South") << int(QTabWidget::South); -} - -void tst_QTabWidget::heightForWidth() -{ - QFETCH(int, tabPosition); - - QWidget *window = new QWidget; - QVBoxLayout *lay = new QVBoxLayout(window); - lay->setMargin(0); - lay->setSpacing(0); - QTabWidget *tabWid = new QTabWidget(window); - QWidget *w = new QWidget; - tabWid->addTab(w, QLatin1String("HFW page")); - tabWid->setTabPosition(QTabWidget::TabPosition(tabPosition)); - QVBoxLayout *lay2 = new QVBoxLayout(w); - QLabel *label = new QLabel("Label with wordwrap turned on makes it trade height for width." - " Make it a really long text so that it spans on several lines" - " when the label is on its narrowest." - " I don't like to repeat myself." - " I don't like to repeat myself." - " I don't like to repeat myself." - " I don't like to repeat myself." - ); - label->setWordWrap(true); - lay2->addWidget(label); - lay2->setMargin(0); - - lay->addWidget(tabWid); - int h = window->heightForWidth(160); - window->resize(160, h); - window->show(); - - QTest::qWaitForWindowShown(window); - QVERIFY(label->height() >= label->heightForWidth(label->width())); - - delete window; -} QTEST_MAIN(tst_QTabWidget) #include "tst_qtabwidget.moc" |