propagate sizehints from mainItem

This commit is contained in:
Marco Martin 2014-01-31 19:59:45 +01:00
parent 856e16e803
commit 89cb417e9f
2 changed files with 77 additions and 0 deletions

View File

@ -44,6 +44,10 @@
#include <xcb/shape.h>
#endif
//Unfortunately QWINDOWSIZE_MAX is not exported
#define DIALOGSIZE_MAX ((1<<24)-1)
DialogProxy::DialogProxy(QQuickItem *parent)
: QQuickWindow(parent ? parent->window() : 0),
m_location(Plasma::Types::BottomEdge),
@ -111,6 +115,35 @@ void DialogProxy::setMainItem(QQuickItem *mainItem)
m_syncTimer->stop();
syncToMainItemSize();
}
//Extract the representation's Layout, if any
QObject *layout = 0;
//Search a child that has the needed Layout properties
//HACK: here we are not type safe, but is the only way to access to a pointer of Layout
foreach (QObject *child, mainItem->children()) {
//find for the needed property of Layout: minimum/maximum/preferred sizes and fillWidth/fillHeight
if (child->property("minimumWidth").isValid() && child->property("minimumHeight").isValid() &&
child->property("preferredWidth").isValid() && child->property("preferredHeight").isValid() &&
child->property("maximumWidth").isValid() && child->property("maximumHeight").isValid() &&
child->property("fillWidth").isValid() && child->property("fillHeight").isValid()
) {
layout = child;
}
}
m_mainItemLayout = layout;
if (layout) {
connect(layout, SIGNAL(minimumWidthChanged()), this, SLOT(updateMinimumWidth()));
connect(layout, SIGNAL(minimumHeightChanged()), this, SLOT(updateMinimumHeight()));
connect(layout, SIGNAL(maximumWidthChanged()), this, SLOT(updatemaximumWidth()));
connect(layout, SIGNAL(maximumHeightChanged()), this, SLOT(updatemaximumHeight()));
updateMinimumWidth();
updateMinimumHeight();
updateMaximumWidth();
updateMaximumHeight();
}
}
//if this is called in Component.onCompleted we have to wait a loop the item is added to a scene
@ -559,5 +592,41 @@ void DialogProxy::updateInputShape()
#endif
}
void DialogProxy::updateMinimumWidth()
{
if (m_mainItemLayout) {
setMinimumWidth(m_mainItemLayout.data()->property("minimumWidth").toInt());
} else {
setMinimumWidth(-1);
}
}
void DialogProxy::updateMinimumHeight()
{
if (m_mainItemLayout) {
setMinimumHeight(m_mainItemLayout.data()->property("minimumHeight").toInt());
} else {
setMinimumHeight(-1);
}
}
void DialogProxy::updateMaximumWidth()
{
if (m_mainItemLayout) {
setMaximumWidth(m_mainItemLayout.data()->property("maximumWidth").toInt());
} else {
setMaximumWidth(DIALOGSIZE_MAX);
}
}
void DialogProxy::updateMaximumHeight()
{
if (m_mainItemLayout) {
setMaximumHeight(m_mainItemLayout.data()->property("maximumWidth").toInt());
} else {
setMaximumHeight(DIALOGSIZE_MAX);
}
}
#include "dialog.moc"

View File

@ -171,12 +171,20 @@ private Q_SLOTS:
void updateVisibility(bool visible);
void updateMinimumWidth();
void updateMinimumHeight();
void updateMaximumWidth();
void updateMaximumHeight();
private:
QRect m_cachedGeometry;
WindowType m_type;
bool m_hideOnWindowDeactivate;
bool m_outputOnly;
Plasma::Theme m_theme;
//Attached Layout property of mainItem, if any
QWeakPointer <QObject> m_mainItemLayout;
};
#endif