From 996a1277bc9d555622cccef9aa6399f28c750f2d Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Sun, 28 Dec 2008 12:54:48 +0000 Subject: [PATCH] better manage save and restore of popup size of popupapplets when the content is a qgraphicswidget (i.e it works now), also ensure the default size when it first pops up is the gwidget's preferred size svn path=/trunk/KDE/kdelibs/; revision=902439 --- dialog.cpp | 9 +++++++++ popupapplet.cpp | 21 +++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/dialog.cpp b/dialog.cpp index 9963b68f5..ea8fd3323 100644 --- a/dialog.cpp +++ b/dialog.cpp @@ -397,6 +397,15 @@ void Dialog::hideEvent(QHideEvent * event) void Dialog::showEvent(QShowEvent * event) { Q_UNUSED(event); + + //check if the widget size is still synced with the view + if (d->widget && d->view && d->widget->size().toSize() != d->view->size()) { + d->widget->resize(d->view->size()); + + d->view->setSceneRect(d->widget->mapToScene(d->widget->boundingRect()).boundingRect()); + d->view->centerOn(d->widget); + } + emit dialogVisible(true); } diff --git a/popupapplet.cpp b/popupapplet.cpp index 5a0f23770..dfaf6b825 100644 --- a/popupapplet.cpp +++ b/popupapplet.cpp @@ -291,8 +291,6 @@ void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints) KWindowSystem::setState(dialog->winId(), NET::SkipTaskbar | NET::SkipPager); dialog->installEventFilter(q); - QObject::connect(dialog, SIGNAL(dialogResized()), q, SLOT(dialogSizeChanged())); - QObject::connect(dialog, SIGNAL(dialogVisible(bool)), q, SLOT(dialogStatusChanged(bool))); q->setMinimumSize(QSize(0, 0)); if (gWidget) { Corona *corona = qobject_cast(gWidget->scene()); @@ -307,10 +305,13 @@ void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints) l_layout->setSpacing(0); l_layout->setMargin(0); l_layout->addWidget(qWidget); + dialog->adjustSize(); } + + QObject::connect(dialog, SIGNAL(dialogResized()), q, SLOT(dialogSizeChanged())); + QObject::connect(dialog, SIGNAL(dialogVisible(bool)), q, SLOT(dialogStatusChanged(bool))); } - dialog->adjustSize(); if (icon && lay) { lay->addItem(icon); @@ -470,7 +471,7 @@ void PopupAppletPrivate::togglePopup() updateDialogPosition(); KWindowSystem::setState(dialog->winId(), NET::SkipTaskbar | NET::SkipPager); dialog->show(); - dialog->adjustSize(); + dialog->resize(dialog->size()); } dialog->clearFocus(); @@ -521,9 +522,17 @@ void PopupAppletPrivate::updateDialogPosition() Q_ASSERT(q->containment()); Q_ASSERT(q->containment()->corona()); - const int width = qMin(sizeGroup.readEntry("DialogWidth", 0), + + int preferredWidth = 0; + int preferredHeight = 0; + if (dialog->graphicsWidget()) { + preferredWidth = dialog->graphicsWidget()->preferredSize().width(); + preferredHeight = dialog->graphicsWidget()->preferredSize().height(); + } + + const int width = qMin(sizeGroup.readEntry("DialogWidth", preferredWidth), q->containment()->corona()->screenGeometry(-1).width() - 50); - const int height = qMin(sizeGroup.readEntry("DialogHeight", 0), + const int height = qMin(sizeGroup.readEntry("DialogHeight", preferredHeight), q->containment()->corona()->screenGeometry(-1).height() - 50); QSize saved(width, height);