From 8db63c42a996247a3f2612b2ed013f51d58068b1 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 20 Sep 2012 11:49:17 +0200 Subject: [PATCH] support maximum and preferred sizes as well --- widgets/declarativewidget.cpp | 59 +++++++++++++++++++++++++++++++++-- widgets/declarativewidget.h | 4 +++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/widgets/declarativewidget.cpp b/widgets/declarativewidget.cpp index 878164efa..93d043898 100644 --- a/widgets/declarativewidget.cpp +++ b/widgets/declarativewidget.cpp @@ -62,6 +62,10 @@ public: void scheduleExecutionEnd(); void minimumWidthChanged(); void minimumHeightChanged(); + void maximumWidthChanged(); + void maximumHeightChanged(); + void preferredWidthChanged(); + void preferredHeightChanged(); DeclarativeWidget *q; @@ -157,13 +161,28 @@ void DeclarativeWidgetPrivate::finishExecute() q->setLayout(0); qreal minimumWidth = 0; qreal minimumHeight = 0; + qreal maximumWidth = 0; + qreal maximumHeight = 0; + qreal preferredWidth = 0; + qreal preferredHeight = 0; if (object) { - minimumWidth = object->property("minimumWidth").toReal(); - minimumHeight = object->property("minimumHeight").toReal(); object->setProperty("width", q->size().width()); object->setProperty("height", q->size().height()); + + minimumWidth = object->property("minimumWidth").toReal(); + minimumHeight = object->property("minimumHeight").toReal(); QObject::connect(object, SIGNAL(minimumWidthChanged()), q, SLOT(minimumWidthChanged())); QObject::connect(object, SIGNAL(minimumHeightChanged()), q, SLOT(minimumHeightChanged())); + + maximumWidth = object->property("maximumWidth").toReal(); + maximumHeight = object->property("maximumHeight").toReal(); + QObject::connect(object, SIGNAL(maximumWidthChanged()), q, SLOT(maximumWidthChanged())); + QObject::connect(object, SIGNAL(maximumHeightChanged()), q, SLOT(maximumHeightChanged())); + + preferredWidth = object->property("preferredWidth").toReal(); + preferredHeight = object->property("preferredHeight").toReal(); + QObject::connect(object, SIGNAL(preferredWidthChanged()), q, SLOT(preferredWidthChanged())); + QObject::connect(object, SIGNAL(preferredHeightChanged()), q, SLOT(preferredHeightChanged())); } if (minimumWidth > 0 && minimumHeight > 0) { @@ -171,6 +190,18 @@ void DeclarativeWidgetPrivate::finishExecute() } else { q->setMinimumSize(-1, -1); } + + if (maximumWidth > 0 && maximumHeight > 0) { + q->setMaximumSize(maximumWidth, maximumHeight); + } else { + q->setMaximumSize(-1, -1); + } + + if (preferredWidth > 0 && preferredHeight > 0) { + q->setPreferredSize(preferredWidth, preferredHeight); + } else { + q->setPreferredSize(-1, -1); + } } emit q->finished(); } @@ -187,6 +218,30 @@ void DeclarativeWidgetPrivate::minimumHeightChanged() q->setMinimumHeight(minimumHeight); } +void DeclarativeWidgetPrivate::maximumWidthChanged() +{ + qreal maximumWidth = root->property("maximumWidth").toReal(); + q->setMaximumWidth(maximumWidth); +} + +void DeclarativeWidgetPrivate::maximumHeightChanged() +{ + qreal maximumHeight = root->property("maximumHeight").toReal(); + q->setMaximumHeight(maximumHeight); +} + +void DeclarativeWidgetPrivate::preferredWidthChanged() +{ + qreal preferredWidth = root->property("preferredWidth").toReal(); + q->setPreferredWidth(preferredWidth); +} + +void DeclarativeWidgetPrivate::preferredHeightChanged() +{ + qreal preferredHeight = root->property("preferredHeight").toReal(); + q->setPreferredHeight(preferredHeight); +} + DeclarativeWidget::DeclarativeWidget(QGraphicsWidget *parent) : QGraphicsWidget(parent), d(new DeclarativeWidgetPrivate(this)) diff --git a/widgets/declarativewidget.h b/widgets/declarativewidget.h index 28270cb6e..b187e0f88 100644 --- a/widgets/declarativewidget.h +++ b/widgets/declarativewidget.h @@ -131,6 +131,10 @@ private: Q_PRIVATE_SLOT(d, void scheduleExecutionEnd()) Q_PRIVATE_SLOT(d, void minimumWidthChanged()) Q_PRIVATE_SLOT(d, void minimumHeightChanged()) + Q_PRIVATE_SLOT(d, void maximumWidthChanged()) + Q_PRIVATE_SLOT(d, void maximumHeightChanged()) + Q_PRIVATE_SLOT(d, void preferredWidthChanged()) + Q_PRIVATE_SLOT(d, void preferredHeightChanged()) }; } // namespace Plasma