summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel
diff options
context:
space:
mode:
authorJan-Arve Sæther <jan-arve.saether@nokia.com>2010-04-09 12:48:41 (GMT)
committerJan-Arve Sæther <jan-arve.saether@nokia.com>2010-04-12 06:31:40 (GMT)
commitd22c8c60ffd986cc46d1f1cab878d60b03b5d4ea (patch)
tree179467591fcda27b0fd53b65ab22039ad3d4788c /src/gui/kernel
parentef3b0420bfa9ef810267d174922ff2477f983c8d (diff)
downloadQt-d22c8c60ffd986cc46d1f1cab878d60b03b5d4ea.zip
Qt-d22c8c60ffd986cc46d1f1cab878d60b03b5d4ea.tar.gz
Qt-d22c8c60ffd986cc46d1f1cab878d60b03b5d4ea.tar.bz2
Implement heightForWidth support for QTabWidget and QStackedLayout.
In order to add the support we also had to add hasHeightForWidth to QWidget that calls the new virtual hasHeightForWidth() in QWidgetPrivate Task-number: QTBUG-7792 Reviewed-by: Paul
Diffstat (limited to 'src/gui/kernel')
-rw-r--r--src/gui/kernel/qlayoutitem.cpp4
-rw-r--r--src/gui/kernel/qstackedlayout.cpp26
-rw-r--r--src/gui/kernel/qstackedlayout.h2
-rw-r--r--src/gui/kernel/qwidget.cpp17
-rw-r--r--src/gui/kernel/qwidget.h1
-rw-r--r--src/gui/kernel/qwidget_p.h1
6 files changed, 48 insertions, 3 deletions
diff --git a/src/gui/kernel/qlayoutitem.cpp b/src/gui/kernel/qlayoutitem.cpp
index 6a91d95..e615b2d 100644
--- a/src/gui/kernel/qlayoutitem.cpp
+++ b/src/gui/kernel/qlayoutitem.cpp
@@ -516,9 +516,7 @@ bool QWidgetItem::hasHeightForWidth() const
{
if (isEmpty())
return false;
- if (wid->layout())
- return wid->layout()->hasHeightForWidth();
- return wid->sizePolicy().hasHeightForWidth();
+ return wid->hasHeightForWidth();
}
/*!
diff --git a/src/gui/kernel/qstackedlayout.cpp b/src/gui/kernel/qstackedlayout.cpp
index 7559066..4b49638 100644
--- a/src/gui/kernel/qstackedlayout.cpp
+++ b/src/gui/kernel/qstackedlayout.cpp
@@ -475,6 +475,32 @@ 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 c069149..842b62b 100644
--- a/src/gui/kernel/qstackedlayout.h
+++ b/src/gui/kernel/qstackedlayout.h
@@ -95,6 +95,8 @@ 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 e88026c..7a8b700 100644
--- a/src/gui/kernel/qwidget.cpp
+++ b/src/gui/kernel/qwidget.cpp
@@ -3816,6 +3816,11 @@ 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
@@ -7961,6 +7966,18 @@ 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 e12148b..6e5de7d 100644
--- a/src/gui/kernel/qwidget.h
+++ b/src/gui/kernel/qwidget.h
@@ -524,6 +524,7 @@ 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 89ea256..05a859c 100644
--- a/src/gui/kernel/qwidget_p.h
+++ b/src/gui/kernel/qwidget_p.h
@@ -493,6 +493,7 @@ 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);