From f9c49d0488ab1d9e5da7acc93bb151be22c14767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20K=C3=BCgler?= Date: Sun, 7 Sep 2008 20:49:10 +0000 Subject: [PATCH] Cache the result of graphicsWidget(), it gets called quite often and might not be really fast for applets that do all the setting up of the widget in this function. Also fix the indenting, in some places it was 3 instead of 4 spaces. svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=858350 --- popupapplet.cpp | 49 +++++++++++++++++++++++++------------------------ popupapplet.h | 13 +++++++------ 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/popupapplet.cpp b/popupapplet.cpp index 83d0e1c74..079611a2d 100644 --- a/popupapplet.cpp +++ b/popupapplet.cpp @@ -171,12 +171,12 @@ void PopupApplet::constraintsEvent(Plasma::Constraints constraints) //get the margins QSizeF marginSize = size() - contentsRect().size(); - if (graphicsWidget()) { - d->layout->addItem(graphicsWidget()); - setMinimumSize(graphicsWidget()->minimumSize() + marginSize); - graphicsWidget()->installEventFilter(this); - } - else { + QGraphicsWidget *gWidget = graphicsWidget(); + if (gWidget) { + d->layout->addItem(gWidget); + setMinimumSize(gWidget->minimumSize() + marginSize); + gWidget->installEventFilter(this); + } else { if (!d->proxy) { d->proxy = new QGraphicsProxyWidget(this); d->proxy->setWidget(widget()); @@ -218,15 +218,16 @@ void PopupApplet::constraintsEvent(Plasma::Constraints constraints) connect(d->dialog, SIGNAL(dialogResized()), this, SLOT(dialogSizeChanged())); connect(d->dialog, SIGNAL(dialogVisible(bool)), this , SLOT(dialogStatusChanged(bool))); - if (graphicsWidget()) { - Corona *corona = qobject_cast(graphicsWidget()->scene()); + QGraphicsWidget *gWidget = graphicsWidget(); + if (gWidget) { + Corona *corona = qobject_cast(gWidget->scene()); //could that cast ever fail?? if (corona) { - corona->addOffscreenWidget(graphicsWidget()); - graphicsWidget()->resize(graphicsWidget()->preferredSize()); - graphicsWidget()->setMinimumSize(graphicsWidget()->preferredSize()); - d->dialog->setGraphicsWidget(graphicsWidget()); + corona->addOffscreenWidget(gWidget); + graphicsWidget()->resize(gWidget->preferredSize()); + graphicsWidget()->setMinimumSize(gWidget->preferredSize()); + d->dialog->setGraphicsWidget(gWidget); } } else { QVBoxLayout *l_layout = new QVBoxLayout(d->dialog); @@ -308,21 +309,21 @@ void PopupApplet::popupEvent(bool) void PopupAppletPrivate::togglePopup() { - if (dialog) { - if (timer) { - timer->stop(); - } + if (dialog) { + if (timer) { + timer->stop(); + } - dialog->move(q->popupPosition(dialog->size())); + dialog->move(q->popupPosition(dialog->size())); - if (dialog->isVisible()) { - dialog->hide(); - } else { - dialog->show(); - KWindowSystem::setState(dialog->winId(), NET::SkipTaskbar | NET::SkipPager); - } + if (dialog->isVisible()) { + dialog->hide(); + } else { + dialog->show(); + KWindowSystem::setState(dialog->winId(), NET::SkipTaskbar | NET::SkipPager); + } - dialog->clearFocus(); + dialog->clearFocus(); } } diff --git a/popupapplet.h b/popupapplet.h index c284e5862..84e701276 100644 --- a/popupapplet.h +++ b/popupapplet.h @@ -68,15 +68,15 @@ public: QIcon icon() const; /** - * Implement either this function or graphicsWidget. - * @return the widget that will get shown in either a layout in the applet, or in a Dialog, + * Implement either this function or graphicsWidget(). + * @return the widget that will get shown in either a layout, in the applet or in a Dialog, * depending on the form factor of the applet. */ virtual QWidget *widget(); /** - * Implement either this function or widget. - * @return the widget that will get shown in either a layout in the applet, or in a Dialog, + * Implement either this function or widget(). + * @return the widget that will get shown in either a layout, in the applet or in a Dialog, * depending on the form factor of the applet. */ virtual QGraphicsWidget *graphicsWidget(); @@ -89,8 +89,9 @@ public: void showPopup(uint displayTime = 0); /** - * This event handler can be reimplemented in a subclass to receive an event before the popup is showed or hidden. - * @arg show true if the popup is going to be showed, false if the popup is going to be hiden. + * This event handler can be reimplemented in a subclass to receive an event before the popup is shown or hidden. + * @arg show true if the popup is going to be shown, false if the popup is going to be hidden. + * Note that showing and hiding the popup on click is already done in PopupApplet. */ virtual void popupEvent(bool show);