call a private constraints event on the PopupApplet so that subclasses don't have to think about it
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=862502
This commit is contained in:
parent
15da8e1555
commit
8d1e6cdf85
@ -70,6 +70,7 @@
|
||||
#include "scripting/appletscript.h"
|
||||
#include "svg.h"
|
||||
#include "panelsvg.h"
|
||||
#include "popupapplet.h"
|
||||
#include "theme.h"
|
||||
#include "view.h"
|
||||
#include "widgets/label.h"
|
||||
@ -80,6 +81,7 @@
|
||||
#include "private/containment_p.h"
|
||||
#include "private/extenderapplet_p.h"
|
||||
#include "private/packages_p.h"
|
||||
#include "private/popupapplet_p.h"
|
||||
#include "private/toolbox_p.h"
|
||||
|
||||
//#define DYNAMIC_SHADOWS
|
||||
@ -836,6 +838,11 @@ void Applet::flushPendingConstraintsEvents()
|
||||
containment->d->containmentConstraintsEvent(c);
|
||||
}
|
||||
|
||||
PopupApplet* popup = qobject_cast<Plasma::PopupApplet*>(this);
|
||||
if (popup) {
|
||||
popup->d->popupConstraintsEvent(c);
|
||||
}
|
||||
|
||||
constraintsEvent(c);
|
||||
|
||||
if (layout()) {
|
||||
|
174
popupapplet.cpp
174
popupapplet.cpp
@ -19,6 +19,7 @@
|
||||
*/
|
||||
|
||||
#include "popupapplet.h"
|
||||
#include "private/popupapplet_p.h"
|
||||
|
||||
#include <QGraphicsProxyWidget>
|
||||
#include <QGraphicsLinearLayout>
|
||||
@ -42,53 +43,6 @@
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class PopupAppletPrivate
|
||||
{
|
||||
public:
|
||||
PopupAppletPrivate(PopupApplet *applet)
|
||||
: q(applet),
|
||||
icon(0),
|
||||
dialog(0),
|
||||
layout(0),
|
||||
proxy(0),
|
||||
popupPlacement(Plasma::FloatingPopup),
|
||||
savedAspectRatio(Plasma::InvalidAspectRatioMode),
|
||||
timer(0),
|
||||
startupComplete(false),
|
||||
popupLostFocus(false)
|
||||
{
|
||||
}
|
||||
|
||||
~PopupAppletPrivate()
|
||||
{
|
||||
if (proxy) {
|
||||
proxy->setWidget(0);
|
||||
}
|
||||
|
||||
delete dialog;
|
||||
delete icon;
|
||||
}
|
||||
|
||||
void togglePopup();
|
||||
void hideTimedPopup();
|
||||
void clearPopupLostFocus();
|
||||
void dialogSizeChanged();
|
||||
void dialogStatusChanged(bool status);
|
||||
void updateDialogPosition();
|
||||
|
||||
PopupApplet *q;
|
||||
Plasma::Icon *icon;
|
||||
Plasma::Dialog *dialog;
|
||||
QGraphicsLinearLayout *layout;
|
||||
QGraphicsProxyWidget *proxy;
|
||||
Plasma::PopupPlacement popupPlacement;
|
||||
Plasma::AspectRatioMode savedAspectRatio;
|
||||
QTimer *timer;
|
||||
QPoint clicked;
|
||||
bool startupComplete : 1;
|
||||
bool popupLostFocus : 1;
|
||||
};
|
||||
|
||||
PopupApplet::PopupApplet(QObject *parent, const QVariantList &args)
|
||||
: Plasma::Applet(parent, args),
|
||||
d(new PopupAppletPrivate(this))
|
||||
@ -156,18 +110,18 @@ QGraphicsWidget *PopupApplet::graphicsWidget()
|
||||
return static_cast<Applet*>(this)->d->extender;
|
||||
}
|
||||
|
||||
void PopupApplet::constraintsEvent(Plasma::Constraints constraints)
|
||||
void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints)
|
||||
{
|
||||
if (constraints & Plasma::StartupCompletedConstraint) {
|
||||
d->startupComplete = true;
|
||||
startupComplete = true;
|
||||
}
|
||||
|
||||
if (!d->startupComplete) {
|
||||
if (!startupComplete) {
|
||||
return;
|
||||
}
|
||||
|
||||
QGraphicsLinearLayout *lay = dynamic_cast<QGraphicsLinearLayout *>(layout());
|
||||
Plasma::FormFactor f = formFactor();
|
||||
QGraphicsLinearLayout *lay = dynamic_cast<QGraphicsLinearLayout *>(q->layout());
|
||||
Plasma::FormFactor f = q->formFactor();
|
||||
|
||||
if (constraints & Plasma::FormFactorConstraint ||
|
||||
(constraints & Plasma::SizeConstraint && (f == Plasma::Vertical || f == Plasma::Horizontal))) {
|
||||
@ -178,8 +132,8 @@ void PopupApplet::constraintsEvent(Plasma::Constraints constraints)
|
||||
QSizeF minimum;
|
||||
QSizeF containmentSize;
|
||||
|
||||
QGraphicsWidget *gWidget = graphicsWidget();
|
||||
QWidget *qWidget = widget();
|
||||
QGraphicsWidget *gWidget = q->graphicsWidget();
|
||||
QWidget *qWidget = q->widget();
|
||||
|
||||
if (gWidget) {
|
||||
minimum = gWidget->minimumSize();
|
||||
@ -187,106 +141,106 @@ void PopupApplet::constraintsEvent(Plasma::Constraints constraints)
|
||||
minimum = qWidget->minimumSizeHint();
|
||||
}
|
||||
|
||||
if (containment()) {
|
||||
containmentSize = containment()->size();
|
||||
if (q->containment()) {
|
||||
containmentSize = q->containment()->size();
|
||||
}
|
||||
|
||||
if (d->icon &&
|
||||
if (icon &&
|
||||
((f != Plasma::Vertical && f != Plasma::Horizontal) ||
|
||||
((f == Plasma::Vertical && containmentSize.width() >= minimum.width()) ||(f == Plasma::Horizontal && containmentSize.height() >= minimum.height())))) {
|
||||
// we only switch to expanded if we aren't horiz/vert constrained and
|
||||
// this applet has an icon.
|
||||
// otherwise, we leave it up to the applet itself to figure it out
|
||||
d->icon->hide();
|
||||
icon->hide();
|
||||
|
||||
if (d->savedAspectRatio != Plasma::InvalidAspectRatioMode) {
|
||||
setAspectRatioMode(d->savedAspectRatio);
|
||||
if (savedAspectRatio != Plasma::InvalidAspectRatioMode) {
|
||||
q->setAspectRatioMode(savedAspectRatio);
|
||||
}
|
||||
|
||||
if (d->dialog) {
|
||||
if (d->dialog->layout() && qWidget) {
|
||||
if (dialog) {
|
||||
if (dialog->layout() && qWidget) {
|
||||
//we dont want to delete Widget inside the dialog layout
|
||||
d->dialog->layout()->removeWidget(qWidget);
|
||||
dialog->layout()->removeWidget(qWidget);
|
||||
}
|
||||
|
||||
delete d->dialog;
|
||||
d->dialog = 0;
|
||||
delete dialog;
|
||||
dialog = 0;
|
||||
}
|
||||
|
||||
//get the margins
|
||||
QSizeF marginSize = size() - contentsRect().size();
|
||||
QSizeF marginSize = q->size() - q->contentsRect().size();
|
||||
|
||||
if (gWidget) {
|
||||
if (lay) {
|
||||
lay->addItem(gWidget);
|
||||
}
|
||||
setMinimumSize(gWidget->minimumSize() + marginSize);
|
||||
gWidget->installEventFilter(this);
|
||||
q->setMinimumSize(gWidget->minimumSize() + marginSize);
|
||||
gWidget->installEventFilter(q);
|
||||
} else if (qWidget) {
|
||||
if (!d->proxy) {
|
||||
d->proxy = new QGraphicsProxyWidget(this);
|
||||
d->proxy->setWidget(qWidget);
|
||||
d->proxy->show();
|
||||
if (!proxy) {
|
||||
proxy = new QGraphicsProxyWidget(q);
|
||||
proxy->setWidget(qWidget);
|
||||
proxy->show();
|
||||
}
|
||||
|
||||
if (lay) {
|
||||
lay->addItem(d->proxy);
|
||||
lay->addItem(proxy);
|
||||
}
|
||||
|
||||
setMinimumSize(qWidget ? qWidget->minimumSize() + marginSize : QSizeF(300, 200));
|
||||
q->setMinimumSize(qWidget ? qWidget->minimumSize() + marginSize : QSizeF(300, 200));
|
||||
}
|
||||
} else {
|
||||
//save the aspect ratio mode in case we drag'n drop in the Desktop later
|
||||
d->savedAspectRatio = aspectRatioMode();
|
||||
setAspectRatioMode(Plasma::ConstrainedSquare);
|
||||
savedAspectRatio = q->aspectRatioMode();
|
||||
q->setAspectRatioMode(Plasma::ConstrainedSquare);
|
||||
|
||||
if (d->icon) {
|
||||
d->icon->show();
|
||||
if (icon) {
|
||||
icon->show();
|
||||
}
|
||||
|
||||
if (d->proxy) {
|
||||
d->proxy->setWidget(0); // prevent it from deleting our widget!
|
||||
delete d->proxy;
|
||||
d->proxy = 0;
|
||||
if (proxy) {
|
||||
proxy->setWidget(0); // prevent it from deleting our widget!
|
||||
delete proxy;
|
||||
proxy = 0;
|
||||
}
|
||||
|
||||
if (!d->dialog) {
|
||||
kDebug() << "making dialog with view" << view();
|
||||
d->dialog = new Plasma::Dialog();
|
||||
if (!dialog) {
|
||||
//kDebug() << "making dialog with view" << q->view();
|
||||
dialog = new Plasma::Dialog();
|
||||
|
||||
//no longer use Qt::Popup since that seems to cause a lot of problem when you drag
|
||||
//stuff out of your Dialog (extenders). Monitor WindowDeactivate events so we can
|
||||
//emulate the same kind of behavior as Qt::Popup (close when you click somewhere
|
||||
//else.
|
||||
d->dialog->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
|
||||
KWindowSystem::setState(d->dialog->winId(), NET::SkipTaskbar | NET::SkipPager);
|
||||
d->dialog->installEventFilter(this);
|
||||
dialog->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
|
||||
KWindowSystem::setState(dialog->winId(), NET::SkipTaskbar | NET::SkipPager);
|
||||
dialog->installEventFilter(q);
|
||||
|
||||
connect(d->dialog, SIGNAL(dialogResized()), this, SLOT(dialogSizeChanged()));
|
||||
connect(d->dialog, SIGNAL(dialogVisible(bool)), this , SLOT(dialogStatusChanged(bool)));
|
||||
setMinimumSize(QSize(0, 0));
|
||||
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<Corona *>(gWidget->scene());
|
||||
|
||||
//could that cast ever fail??
|
||||
if (corona) {
|
||||
corona->addOffscreenWidget(gWidget);
|
||||
graphicsWidget()->resize(gWidget->preferredSize());
|
||||
graphicsWidget()->setMinimumSize(gWidget->preferredSize());
|
||||
d->dialog->setGraphicsWidget(gWidget);
|
||||
gWidget->resize(gWidget->preferredSize());
|
||||
gWidget->setMinimumSize(gWidget->preferredSize());
|
||||
dialog->setGraphicsWidget(gWidget);
|
||||
}
|
||||
} else if (qWidget) {
|
||||
QVBoxLayout *l_layout = new QVBoxLayout(d->dialog);
|
||||
QVBoxLayout *l_layout = new QVBoxLayout(dialog);
|
||||
l_layout->setSpacing(0);
|
||||
l_layout->setMargin(0);
|
||||
l_layout->addWidget(qWidget);
|
||||
}
|
||||
}
|
||||
|
||||
d->dialog->adjustSize();
|
||||
dialog->adjustSize();
|
||||
|
||||
if (d->icon && lay) {
|
||||
lay->addItem(d->icon);
|
||||
if (icon && lay) {
|
||||
lay->addItem(icon);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -382,6 +336,30 @@ void PopupApplet::popupEvent(bool)
|
||||
|
||||
}
|
||||
|
||||
PopupAppletPrivate::PopupAppletPrivate(PopupApplet *applet)
|
||||
: q(applet),
|
||||
icon(0),
|
||||
dialog(0),
|
||||
layout(0),
|
||||
proxy(0),
|
||||
popupPlacement(Plasma::FloatingPopup),
|
||||
savedAspectRatio(Plasma::InvalidAspectRatioMode),
|
||||
timer(0),
|
||||
startupComplete(false),
|
||||
popupLostFocus(false)
|
||||
{
|
||||
}
|
||||
|
||||
PopupAppletPrivate::~PopupAppletPrivate()
|
||||
{
|
||||
if (proxy) {
|
||||
proxy->setWidget(0);
|
||||
}
|
||||
|
||||
delete dialog;
|
||||
delete icon;
|
||||
}
|
||||
|
||||
void PopupAppletPrivate::togglePopup()
|
||||
{
|
||||
if (dialog) {
|
||||
|
@ -108,7 +108,6 @@ public Q_SLOTS:
|
||||
void hidePopup();
|
||||
|
||||
protected:
|
||||
void constraintsEvent(Plasma::Constraints constraints);
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
@ -121,6 +120,7 @@ private:
|
||||
Q_PRIVATE_SLOT(d, void dialogSizeChanged())
|
||||
Q_PRIVATE_SLOT(d, void dialogStatusChanged(bool))
|
||||
|
||||
friend class Applet;
|
||||
PopupAppletPrivate * const d;
|
||||
};
|
||||
|
||||
|
56
private/popupapplet_p.h
Normal file
56
private/popupapplet_p.h
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2008 by Montel Laurent <montel@kde.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef POPUPAPPLET_P_H
|
||||
#define POPUPAPPLET_P_H
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class PopupAppletPrivate
|
||||
{
|
||||
public:
|
||||
PopupAppletPrivate(PopupApplet *applet);
|
||||
~PopupAppletPrivate();
|
||||
|
||||
void togglePopup();
|
||||
void hideTimedPopup();
|
||||
void clearPopupLostFocus();
|
||||
void dialogSizeChanged();
|
||||
void dialogStatusChanged(bool status);
|
||||
void updateDialogPosition();
|
||||
void popupConstraintsEvent(Plasma::Constraints constraints);
|
||||
|
||||
PopupApplet *q;
|
||||
Plasma::Icon *icon;
|
||||
Plasma::Dialog *dialog;
|
||||
QGraphicsLinearLayout *layout;
|
||||
QGraphicsProxyWidget *proxy;
|
||||
Plasma::PopupPlacement popupPlacement;
|
||||
Plasma::AspectRatioMode savedAspectRatio;
|
||||
QTimer *timer;
|
||||
QPoint clicked;
|
||||
bool startupComplete : 1;
|
||||
bool popupLostFocus : 1;
|
||||
};
|
||||
|
||||
} // Plasma namespace
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user