Update the size in two ways

A dialog can be resized for two reasons: the mainItem size changes, or the dialog size changes.

the first can happen programmatically, caused by the Layout, or just by assigning the width.

the second can be caused either programmatically, assigning the size of the dialog or externally by the windowmanager, that is the only one theat in the end has the only final control of the window size

Change-Id: Ifc5c7f683039f83d13a5046c10d6dd0227169542
REVIEW:120235
This commit is contained in:
Marco Martin 2014-09-18 17:25:48 +02:00
parent a393284338
commit dff792a86b
2 changed files with 48 additions and 6 deletions

View File

@ -114,7 +114,6 @@ public:
void syncToMainItemSize();
Dialog *q;
QTimer *syncTimer;
Plasma::Types::Location location;
Plasma::FrameSvgItem *frameSvgItem;
QPointer<QQuickItem> mainItem;
@ -238,7 +237,9 @@ void DialogPrivate::updateVisibility(bool visible)
}
cachedGeometry = QRect();
}
if (mainItem) {
syncToMainItemSize();
}
if (mainItemLayout) {
updateLayoutParameters();
}
@ -540,7 +541,9 @@ void DialogPrivate::updateInputShape()
void DialogPrivate::syncToMainItemSize()
{
if (!componentComplete || !mainItem || !q->isVisible()) {
Q_ASSERT(mainItem);
if (!componentComplete || !q->isVisible()) {
return;
}
@ -733,8 +736,10 @@ void Dialog::setVisualParent(QQuickItem *visualParent)
if (visualParent->window()) {
setTransientParent(visualParent->window());
}
if (d->mainItem) {
d->syncToMainItemSize();
}
}
}
QPoint Dialog::popupPosition(QQuickItem *item, const QSize &size)
@ -881,7 +886,9 @@ void Dialog::setLocation(Plasma::Types::Location location)
d->location = location;
emit locationChanged();
if (d->mainItem) {
d->syncToMainItemSize();
}
}
QObject *Dialog::margins() const
@ -903,6 +910,19 @@ void Dialog::adjustGeometry(const QRect &geom)
void Dialog::resizeEvent(QResizeEvent* re)
{
QQuickWindow::resizeEvent(re);
d->mainItem->disconnect(this);
d->frameSvgItem->setWidth(re->size().width());
d->frameSvgItem->setHeight(re->size().height());
auto margin = d->frameSvgItem->margins();
d->mainItem->setX(margin->left());
d->mainItem->setY(margin->top());
d->mainItem->setWidth(re->size().width() - margin->left() - margin->right());
d->mainItem->setHeight(re->size().height() - margin->top() - margin->bottom());
QObject::connect(d->mainItem, SIGNAL(widthChanged()), this, SLOT(slotMainItemSizeChanged()));
QObject::connect(d->mainItem, SIGNAL(heightChanged()), this, SLOT(slotMainItemSizeChanged()));
}
void Dialog::setType(WindowType type)
@ -1013,7 +1033,12 @@ void Dialog::classBegin()
void Dialog::componentComplete()
{
d->componentComplete = true;
d->updateTheme();
if (d->mainItem) {
d->syncToMainItemSize();
}
if (d->mainItemLayout) {
d->updateLayoutParameters();

View File

@ -25,6 +25,7 @@ import QtQuick.Layouts 1.1
import org.kde.plasma.core 2.0 as PlasmaCore
PlasmaCore.Dialog {
id: root
location: PlasmaCore.Types.Floating
Rectangle {
@ -34,6 +35,10 @@ PlasmaCore.Dialog {
color: "red"
Rectangle {
width: rect.Layout.minimumWidth
height: rect.Layout.minimumHeight
}
ColumnLayout {
anchors.top: parent.top
Controls.Label {
@ -53,6 +58,18 @@ PlasmaCore.Dialog {
rect.Layout.minimumHeight = rect.Layout.minimumHeight + 10
}
}
Controls.Button {
text: "Increase dialog width"
onClicked: {
root.width = root.width + 10
}
}
Controls.Button {
text: "Increase dialog height"
onClicked: {
root.height = root.height + 10
}
}
}
}
}