Adding hasHeightForWidth as a virtual Widget funcion
authorThorbjørn Lund Martsum <tmartsum@gmail.com>
Mon, 6 Feb 2012 08:24:50 +0000 (09:24 +0100)
committerQt by Nokia <qt-info@nokia.com>
Sat, 18 Feb 2012 17:40:15 +0000 (18:40 +0100)
Just implements what the note states (and removes the private function)

Change-Id: I9a6fd5134460712accf09ba01691df8b9b1f5d0d
Reviewed-by: Jan-Arve Sæther <jan-arve.saether@nokia.com>
src/widgets/kernel/qlayoutitem.cpp
src/widgets/kernel/qwidget.cpp
src/widgets/kernel/qwidget.h
src/widgets/kernel/qwidget_p.h
src/widgets/widgets/qsizegrip.cpp
src/widgets/widgets/qtabwidget.cpp
src/widgets/widgets/qtabwidget.h

index 860f1cc..664334d 100644 (file)
@@ -522,7 +522,7 @@ bool QWidgetItem::hasHeightForWidth() const
 {
     if (isEmpty())
         return false;
-    return wid->d_func()->hasHeightForWidth();
+    return wid->hasHeightForWidth();
 }
 
 /*!
index f095e47..44995f0 100644 (file)
@@ -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();
 }
 
 /*!
index 0594fd6..78b693c 100644 (file)
@@ -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;
 
index 0da0c65..8b66f14 100644 (file)
@@ -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;
index 145bdf0..09557a3 100644 (file)
@@ -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)) ;
index 66d31e7..612d518 100644 (file)
@@ -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;
 }
 
index 1865ddf..26d9243 100644 (file)
@@ -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;