mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-25 03:12:56 +00:00
implement QStackedLayout's hfw-related methods
upstream commits:
07ae18f96e
Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
parent
842e2a1861
commit
e4107d5af7
4 changed files with 39 additions and 52 deletions
|
@ -478,6 +478,41 @@ void QStackedLayout::setGeometry(const QRect &rect)
|
|||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
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)) {
|
||||
if (QWidget *w = item->widget())
|
||||
hfw = qMax(hfw, w->heightForWidth(width));
|
||||
}
|
||||
}
|
||||
|
||||
hfw = qMax(hfw, minimumSize().height());
|
||||
return hfw;
|
||||
}
|
||||
|
||||
/*!
|
||||
\enum QStackedLayout::StackingMode
|
||||
\since 4.4
|
||||
|
|
|
@ -94,6 +94,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);
|
||||
|
|
|
@ -376,11 +376,6 @@ bool QProxyStyle::event(QEvent *e)
|
|||
information required to find the appropriate icon. The \a widget
|
||||
argument is optional and can also be used to help find the icon.
|
||||
|
||||
\note Because of binary compatibility constraints, standardIcon()
|
||||
introduced in Qt 4.1 is not virtual. Therefore it must dynamically
|
||||
detect and call \e this slot. This default implementation simply
|
||||
calls standardIcon() with the given parameters.
|
||||
|
||||
\sa standardIcon()
|
||||
*/
|
||||
QIcon QProxyStyle::standardIcon(StandardPixmap standardIcon,
|
||||
|
|
|
@ -49,57 +49,12 @@
|
|||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
/**
|
||||
QStackedLayout does not support height for width (simply because it does not reimplement
|
||||
heightForWidth() and hasHeightForWidth()). That is not possible to fix without breaking
|
||||
binary compatibility. (QLayout is subject to multiple inheritance).
|
||||
However, we can fix QStackedWidget by simply using a modified version of QStackedLayout
|
||||
that reimplements the hfw-related functions:
|
||||
*/
|
||||
class QStackedLayoutHFW : public QStackedLayout
|
||||
{
|
||||
public:
|
||||
QStackedLayoutHFW(QWidget *parent = 0) : QStackedLayout(parent) {}
|
||||
bool hasHeightForWidth() const;
|
||||
int heightForWidth(int width) const;
|
||||
};
|
||||
|
||||
bool QStackedLayoutHFW::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 QStackedLayoutHFW::heightForWidth(int width) const
|
||||
{
|
||||
const int n = count();
|
||||
|
||||
int hfw = 0;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
if (QLayoutItem *item = itemAt(i)) {
|
||||
if (QWidget *w = item->widget())
|
||||
hfw = qMax(hfw, w->heightForWidth(width));
|
||||
}
|
||||
}
|
||||
|
||||
hfw = qMax(hfw, minimumSize().height());
|
||||
return hfw;
|
||||
}
|
||||
|
||||
|
||||
class QStackedWidgetPrivate : public QFramePrivate
|
||||
{
|
||||
Q_DECLARE_PUBLIC(QStackedWidget)
|
||||
public:
|
||||
QStackedWidgetPrivate():layout(0){}
|
||||
QStackedLayoutHFW *layout;
|
||||
QStackedLayout *layout;
|
||||
bool blockChildAdd;
|
||||
};
|
||||
|
||||
|
@ -183,7 +138,7 @@ QStackedWidget::QStackedWidget(QWidget *parent)
|
|||
: QFrame(*new QStackedWidgetPrivate, parent)
|
||||
{
|
||||
Q_D(QStackedWidget);
|
||||
d->layout = new QStackedLayoutHFW(this);
|
||||
d->layout = new QStackedLayout(this);
|
||||
connect(d->layout, SIGNAL(widgetRemoved(int)), this, SIGNAL(widgetRemoved(int)));
|
||||
connect(d->layout, SIGNAL(currentChanged(int)), this, SIGNAL(currentChanged(int)));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue