From 466107107a85e7211c4b7f77b36ec50625657061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lund=20Martsum?= Date: Mon, 6 Feb 2012 09:24:50 +0100 Subject: Adding hasHeightForWidth as a virtual Widget funcion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Just implements what the note states (and removes the private function) Change-Id: I9a6fd5134460712accf09ba01691df8b9b1f5d0d Reviewed-by: Jan-Arve Sæther --- src/widgets/kernel/qlayoutitem.cpp | 2 +- src/widgets/kernel/qwidget.cpp | 15 ++++----------- src/widgets/kernel/qwidget.h | 1 + src/widgets/kernel/qwidget_p.h | 1 - src/widgets/widgets/qsizegrip.cpp | 8 ++++---- src/widgets/widgets/qtabwidget.cpp | 14 +++++++++----- src/widgets/widgets/qtabwidget.h | 1 + 7 files changed, 20 insertions(+), 22 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/kernel/qlayoutitem.cpp b/src/widgets/kernel/qlayoutitem.cpp index 860f1cc193..664334d725 100644 --- a/src/widgets/kernel/qlayoutitem.cpp +++ b/src/widgets/kernel/qlayoutitem.cpp @@ -522,7 +522,7 @@ bool QWidgetItem::hasHeightForWidth() const { if (isEmpty()) return false; - return wid->d_func()->hasHeightForWidth(); + return wid->hasHeightForWidth(); } /*! diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index f095e475af..44995f0959 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -9226,19 +9226,12 @@ int QWidget::heightForWidth(int w) const /*! - \internal - - *virtual private* - - This is a bit hackish, but ideally we would have created a virtual function - in the public API (however, too late...) so that subclasses could reimplement - their own function. - Instead we add a virtual function to QWidgetPrivate. - ### Qt5: move to public class and make virtual + Returns true if the widget's preferred height depends on its width; otherwise returns false. */ -bool QWidgetPrivate::hasHeightForWidth() const +bool QWidget::hasHeightForWidth() const { - return layout ? layout->hasHeightForWidth() : size_policy.hasHeightForWidth(); + Q_D(const QWidget); + return d->layout ? d->layout->hasHeightForWidth() : d->size_policy.hasHeightForWidth(); } /*! diff --git a/src/widgets/kernel/qwidget.h b/src/widgets/kernel/qwidget.h index 0594fd6f50..78b693c78d 100644 --- a/src/widgets/kernel/qwidget.h +++ b/src/widgets/kernel/qwidget.h @@ -524,6 +524,7 @@ public: void setSizePolicy(QSizePolicy); inline void setSizePolicy(QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical); virtual int heightForWidth(int) const; + virtual bool hasHeightForWidth() const; QRegion visibleRegion() const; diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h index 0da0c65aaa..8b66f14540 100644 --- a/src/widgets/kernel/qwidget_p.h +++ b/src/widgets/kernel/qwidget_p.h @@ -468,7 +468,6 @@ public: bool setMinimumSize_helper(int &minw, int &minh); bool setMaximumSize_helper(int &maxw, int &maxh); - virtual bool hasHeightForWidth() const; void setConstraints_sys(); bool pointInsideRectAndMask(const QPoint &) const; QWidget *childAt_helper(const QPoint &, bool) const; diff --git a/src/widgets/widgets/qsizegrip.cpp b/src/widgets/widgets/qsizegrip.cpp index 145bdf02d4..09557a3c90 100644 --- a/src/widgets/widgets/qsizegrip.cpp +++ b/src/widgets/widgets/qsizegrip.cpp @@ -301,7 +301,7 @@ void QSizeGrip::mousePressEvent(QMouseEvent * e) // Use a native X11 sizegrip for "real" top-level windows if supported. if (tlw->isWindow() && X11->isSupportedByWM(ATOM(_NET_WM_MOVERESIZE)) && !(tlw->windowFlags() & Qt::X11BypassWindowManagerHint) - && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !qt_widget_private(tlw)->hasHeightForWidth()) { + && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !tlw->hasHeightForWidth()) { XEvent xev; xev.xclient.type = ClientMessage; xev.xclient.message_type = ATOM(_NET_WM_MOVERESIZE); @@ -323,7 +323,7 @@ void QSizeGrip::mousePressEvent(QMouseEvent * e) } #endif // Q_WS_X11 #ifdef Q_OS_WIN - if (tlw->isWindow() && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !qt_widget_private(tlw)->hasHeightForWidth()) { + if (tlw->isWindow() && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !tlw->hasHeightForWidth()) { uint orientation = 0; if (d->atBottom()) orientation = d->atLeft() ? SZ_SIZEBOTTOMLEFT : SZ_SIZEBOTTOMRIGHT; @@ -413,11 +413,11 @@ void QSizeGrip::mouseMoveEvent(QMouseEvent * e) #ifdef Q_WS_X11 if (tlw->isWindow() && X11->isSupportedByWM(ATOM(_NET_WM_MOVERESIZE)) && tlw->isTopLevel() && !(tlw->windowFlags() & Qt::X11BypassWindowManagerHint) - && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !qt_widget_private(tlw)->hasHeightForWidth()) + && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !tlw->hasHeightForWidth()) return; #endif #ifdef Q_OS_WIN - if (tlw->isWindow() && qt_getWindowsSystemMenu(tlw) && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !qt_widget_private(tlw)->hasHeightForWidth()) { + if (tlw->isWindow() && qt_getWindowsSystemMenu(tlw) && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !tlw->hasHeightForWidth()) { if (const HWND hwnd = QApplicationPrivate::getHWNDForWidget(tlw)) { MSG msg; while (PeekMessage(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE)) ; diff --git a/src/widgets/widgets/qtabwidget.cpp b/src/widgets/widgets/qtabwidget.cpp index 66d31e72c7..612d51826c 100644 --- a/src/widgets/widgets/qtabwidget.cpp +++ b/src/widgets/widgets/qtabwidget.cpp @@ -186,7 +186,6 @@ public: void _q_removeTab(int); void _q_tabMoved(int from, int to); void init(); - bool hasHeightForWidth() const; QTabBar *tabs; QStackedWidget *stack; @@ -238,11 +237,16 @@ void QTabWidgetPrivate::init() } -bool QTabWidgetPrivate::hasHeightForWidth() const +/*! + \reimp +*/ + +bool QTabWidget::hasHeightForWidth() const { - bool has = size_policy.hasHeightForWidth(); - if (!has && stack) - has = qt_widget_private(stack)->hasHeightForWidth(); + Q_D(const QTabWidget); + bool has = d->size_policy.hasHeightForWidth(); + if (!has && d->stack) + has = d->stack->hasHeightForWidth(); return has; } diff --git a/src/widgets/widgets/qtabwidget.h b/src/widgets/widgets/qtabwidget.h index 1865ddf897..26d9243eb9 100644 --- a/src/widgets/widgets/qtabwidget.h +++ b/src/widgets/widgets/qtabwidget.h @@ -125,6 +125,7 @@ public: QSize sizeHint() const; QSize minimumSizeHint() const; int heightForWidth(int width) const; + bool hasHeightForWidth() const; void setCornerWidget(QWidget * w, Qt::Corner corner = Qt::TopRightCorner); QWidget * cornerWidget(Qt::Corner corner = Qt::TopRightCorner) const; -- cgit v1.2.3