sync sizes also on the other way

This commit is contained in:
Marco Martin 2013-02-20 19:31:06 +01:00
parent f7e3a72d14
commit 7ce2d0f7d6
4 changed files with 56 additions and 17 deletions

View File

@ -108,11 +108,15 @@ DialogProxy::DialogProxy(QQuickItem *parent)
m_margins = new DialogMargins(this, this); m_margins = new DialogMargins(this, this);
m_flags = flags(); m_flags = flags();
m_syncTimer = new QTimer(this);
m_syncTimer->setSingleShot(true);
m_syncTimer->setInterval(250);
connect(m_syncTimer, &QTimer::timeout, this, &DialogProxy::syncToMainItemSize);
} }
DialogProxy::~DialogProxy() DialogProxy::~DialogProxy()
{ {
//delete m_dialog;
} }
QQuickItem *DialogProxy::mainItem() const QQuickItem *DialogProxy::mainItem() const
@ -128,12 +132,35 @@ void DialogProxy::setMainItem(QQuickItem *mainItem)
if (m_mainItem) { if (m_mainItem) {
m_mainItem.data()->setParent(parent()); m_mainItem.data()->setParent(parent());
} }
//HACK: this property is invoked due to the initialization that gets done to contentItem() in the getter
property("data");
m_mainItem = mainItem; m_mainItem = mainItem;
if (mainItem) { if (mainItem) {
//mainItem->setParentItem(0); //mainItem->setParentItem(0);
mainItem->setParent(contentItem()); mainItem->setParent(contentItem());
mainItem->setProperty("parent", QVariant::fromValue(contentItem()));
if (mainItem->metaObject()->indexOfSignal("widthChanged")) {
connect(mainItem, SIGNAL(widthChanged()), m_syncTimer, SIGNAL(start()));
}
if (mainItem->metaObject()->indexOfSignal("heightChanged")) {
connect(mainItem, SIGNAL(heightChanged()), m_syncTimer, SIGNAL(start()));
}
if (mainItem->metaObject()->indexOfSignal("minimumWidthChanged")) {
connect(mainItem, SIGNAL(minimumWidthChanged()), this, SIGNAL(minimumWidthChanged()));
}
if (mainItem->metaObject()->indexOfSignal("minimumHeightChanged")) {
connect(mainItem, SIGNAL(minimumHeightChanged()), this, SIGNAL(minimumHeightChanged()));
}
if (mainItem->metaObject()->indexOfSignal("maximumWidthChanged")) {
connect(mainItem, SIGNAL(maximumWidthChanged()), this, SIGNAL(maximumWidthChanged()));
}
if (mainItem->metaObject()->indexOfSignal("maximumHeightChanged")) {
connect(mainItem, SIGNAL(maximumHeightChanged()), this, SIGNAL(maximumHeightChanged()));
}
} }
//if this is called in Compenent.onCompleted we have to wait a loop the item is added to a scene //if this is called in Compenent.onCompleted we have to wait a loop the item is added to a scene
@ -149,12 +176,7 @@ bool DialogProxy::isVisible() const
void DialogProxy::setVisible(const bool visible) void DialogProxy::setVisible(const bool visible)
{ {
if (isVisible() != visible) { if (isVisible() != visible) {
//FIXME: workaround to prevent dialogs of Popup type disappearing on the second show syncToMainItemSize();
const QSize s = QSize(m_mainItem.data()->width(), m_mainItem.data()->height());
//resize(0,0);
resize(s);
emit widthChanged(s.width());
emit heightChanged(s.height());
const QRect workArea(KWindowSystem::workArea()); const QRect workArea(KWindowSystem::workArea());
@ -334,6 +356,20 @@ void DialogProxy::resizeEvent(QResizeEvent *re)
QQuickWindow::resizeEvent(re); QQuickWindow::resizeEvent(re);
} }
void DialogProxy::syncToMainItemSize()
{
if (!m_mainItem) {
return;
}
//FIXME: workaround to prevent dialogs of Popup type disappearing on the second show
const QSize s = QSize(m_mainItem.data()->width(), m_mainItem.data()->height());
//resize(0,0);
resize(s);
emit widthChanged(s.width());
emit heightChanged(s.height());
}
/* /*
bool DialogProxy::eventFilter(QObject *watched, QEvent *event) bool DialogProxy::eventFilter(QObject *watched, QEvent *event)
{ {
@ -388,5 +424,5 @@ void DialogProxy::setAttribute(int attribute, bool on)
} }
} }
#include "dialog.moc" #include "moc_dialog.cpp"

View File

@ -133,6 +133,8 @@ class DialogProxy : public QQuickWindow
Q_PROPERTY(qulonglong windowId READ windowId CONSTANT) Q_PROPERTY(qulonglong windowId READ windowId CONSTANT)
#endif #endif
Q_CLASSINFO("DefaultProperty", "mainItem")
public: public:
enum WidgetAttribute { enum WidgetAttribute {
WA_X11NetWmWindowTypeDock = Qt::WA_X11NetWmWindowTypeDock WA_X11NetWmWindowTypeDock = Qt::WA_X11NetWmWindowTypeDock
@ -195,6 +197,8 @@ Q_SIGNALS:
void activeWindowChanged(); void activeWindowChanged();
void locationChanged(); void locationChanged();
private Q_SLOTS:
void syncToMainItemSize();
protected: protected:
// bool eventFilter(QObject *watched, QEvent *event); // bool eventFilter(QObject *watched, QEvent *event);
@ -203,6 +207,7 @@ protected:
private: private:
Qt::WindowFlags m_flags; Qt::WindowFlags m_flags;
QQuickItem *m_declarativeItemContainer; QQuickItem *m_declarativeItemContainer;
QTimer *m_syncTimer;
QWeakPointer<QQuickItem> m_mainItem; QWeakPointer<QQuickItem> m_mainItem;
DialogMargins *m_margins; DialogMargins *m_margins;
bool m_activeWindow; bool m_activeWindow;

View File

@ -83,10 +83,10 @@ PlasmaComponents.Page {
PlasmaCore.Dialog { PlasmaCore.Dialog {
id: pcDialog id: pcDialog
windowFlags: Qt.Popup windowFlags: Qt.Popup
mainItem: dContent2 //mainItem: dContent2
color: Qt.rgba(0,0,0,0) color: Qt.rgba(0,0,0,0)
DialogContent { mainItem: DialogContent {
id: dContent2 id: dContent2
onCloseMe: pcDialog.visible = false onCloseMe: pcDialog.visible = false
} }

View File

@ -49,14 +49,12 @@ Item {
plasmoid.expanded = false plasmoid.expanded = false
} }
} }
//onWidthChanged: appletParent.width = width
//onHeightChanged:appletParent.height = height mainItem: Rectangle {
mainItem: appletParent
Rectangle {
id: appletParent id: appletParent
radius: 10 radius: 5
width: 200//applet.implicitWidth width: applet && applet.implicitWidth > 0 ? applet.implicitWidth : theme.defaultFont.mSize.width * 35
height: 200//applet.implicitHeight height: applet && applet.implicitHeight > 0 ? applet.implicitHeight : theme.defaultFont.mSize.height * 25
onWidthChanged: applet.width = width onWidthChanged: applet.width = width
onHeightChanged: applet.height = height onHeightChanged: applet.height = height
} }