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
This commit is contained in:
Sebastian Kügler 2008-09-07 20:49:10 +00:00
parent ca0a7d962f
commit f9c49d0488
2 changed files with 32 additions and 30 deletions

View File

@ -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<Corona *>(graphicsWidget()->scene());
QGraphicsWidget *gWidget = graphicsWidget();
if (gWidget) {
Corona *corona = qobject_cast<Corona *>(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();
}
}

View File

@ -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);