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 "scripting/appletscript.h"
|
||||||
#include "svg.h"
|
#include "svg.h"
|
||||||
#include "panelsvg.h"
|
#include "panelsvg.h"
|
||||||
|
#include "popupapplet.h"
|
||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
#include "view.h"
|
#include "view.h"
|
||||||
#include "widgets/label.h"
|
#include "widgets/label.h"
|
||||||
@ -80,6 +81,7 @@
|
|||||||
#include "private/containment_p.h"
|
#include "private/containment_p.h"
|
||||||
#include "private/extenderapplet_p.h"
|
#include "private/extenderapplet_p.h"
|
||||||
#include "private/packages_p.h"
|
#include "private/packages_p.h"
|
||||||
|
#include "private/popupapplet_p.h"
|
||||||
#include "private/toolbox_p.h"
|
#include "private/toolbox_p.h"
|
||||||
|
|
||||||
//#define DYNAMIC_SHADOWS
|
//#define DYNAMIC_SHADOWS
|
||||||
@ -836,6 +838,11 @@ void Applet::flushPendingConstraintsEvents()
|
|||||||
containment->d->containmentConstraintsEvent(c);
|
containment->d->containmentConstraintsEvent(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PopupApplet* popup = qobject_cast<Plasma::PopupApplet*>(this);
|
||||||
|
if (popup) {
|
||||||
|
popup->d->popupConstraintsEvent(c);
|
||||||
|
}
|
||||||
|
|
||||||
constraintsEvent(c);
|
constraintsEvent(c);
|
||||||
|
|
||||||
if (layout()) {
|
if (layout()) {
|
||||||
|
174
popupapplet.cpp
174
popupapplet.cpp
@ -19,6 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "popupapplet.h"
|
#include "popupapplet.h"
|
||||||
|
#include "private/popupapplet_p.h"
|
||||||
|
|
||||||
#include <QGraphicsProxyWidget>
|
#include <QGraphicsProxyWidget>
|
||||||
#include <QGraphicsLinearLayout>
|
#include <QGraphicsLinearLayout>
|
||||||
@ -42,53 +43,6 @@
|
|||||||
namespace Plasma
|
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)
|
PopupApplet::PopupApplet(QObject *parent, const QVariantList &args)
|
||||||
: Plasma::Applet(parent, args),
|
: Plasma::Applet(parent, args),
|
||||||
d(new PopupAppletPrivate(this))
|
d(new PopupAppletPrivate(this))
|
||||||
@ -156,18 +110,18 @@ QGraphicsWidget *PopupApplet::graphicsWidget()
|
|||||||
return static_cast<Applet*>(this)->d->extender;
|
return static_cast<Applet*>(this)->d->extender;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PopupApplet::constraintsEvent(Plasma::Constraints constraints)
|
void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints)
|
||||||
{
|
{
|
||||||
if (constraints & Plasma::StartupCompletedConstraint) {
|
if (constraints & Plasma::StartupCompletedConstraint) {
|
||||||
d->startupComplete = true;
|
startupComplete = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!d->startupComplete) {
|
if (!startupComplete) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QGraphicsLinearLayout *lay = dynamic_cast<QGraphicsLinearLayout *>(layout());
|
QGraphicsLinearLayout *lay = dynamic_cast<QGraphicsLinearLayout *>(q->layout());
|
||||||
Plasma::FormFactor f = formFactor();
|
Plasma::FormFactor f = q->formFactor();
|
||||||
|
|
||||||
if (constraints & Plasma::FormFactorConstraint ||
|
if (constraints & Plasma::FormFactorConstraint ||
|
||||||
(constraints & Plasma::SizeConstraint && (f == Plasma::Vertical || f == Plasma::Horizontal))) {
|
(constraints & Plasma::SizeConstraint && (f == Plasma::Vertical || f == Plasma::Horizontal))) {
|
||||||
@ -178,8 +132,8 @@ void PopupApplet::constraintsEvent(Plasma::Constraints constraints)
|
|||||||
QSizeF minimum;
|
QSizeF minimum;
|
||||||
QSizeF containmentSize;
|
QSizeF containmentSize;
|
||||||
|
|
||||||
QGraphicsWidget *gWidget = graphicsWidget();
|
QGraphicsWidget *gWidget = q->graphicsWidget();
|
||||||
QWidget *qWidget = widget();
|
QWidget *qWidget = q->widget();
|
||||||
|
|
||||||
if (gWidget) {
|
if (gWidget) {
|
||||||
minimum = gWidget->minimumSize();
|
minimum = gWidget->minimumSize();
|
||||||
@ -187,106 +141,106 @@ void PopupApplet::constraintsEvent(Plasma::Constraints constraints)
|
|||||||
minimum = qWidget->minimumSizeHint();
|
minimum = qWidget->minimumSizeHint();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (containment()) {
|
if (q->containment()) {
|
||||||
containmentSize = containment()->size();
|
containmentSize = q->containment()->size();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d->icon &&
|
if (icon &&
|
||||||
((f != Plasma::Vertical && f != Plasma::Horizontal) ||
|
((f != Plasma::Vertical && f != Plasma::Horizontal) ||
|
||||||
((f == Plasma::Vertical && containmentSize.width() >= minimum.width()) ||(f == Plasma::Horizontal && containmentSize.height() >= minimum.height())))) {
|
((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
|
// we only switch to expanded if we aren't horiz/vert constrained and
|
||||||
// this applet has an icon.
|
// this applet has an icon.
|
||||||
// otherwise, we leave it up to the applet itself to figure it out
|
// otherwise, we leave it up to the applet itself to figure it out
|
||||||
d->icon->hide();
|
icon->hide();
|
||||||
|
|
||||||
if (d->savedAspectRatio != Plasma::InvalidAspectRatioMode) {
|
if (savedAspectRatio != Plasma::InvalidAspectRatioMode) {
|
||||||
setAspectRatioMode(d->savedAspectRatio);
|
q->setAspectRatioMode(savedAspectRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d->dialog) {
|
if (dialog) {
|
||||||
if (d->dialog->layout() && qWidget) {
|
if (dialog->layout() && qWidget) {
|
||||||
//we dont want to delete Widget inside the dialog layout
|
//we dont want to delete Widget inside the dialog layout
|
||||||
d->dialog->layout()->removeWidget(qWidget);
|
dialog->layout()->removeWidget(qWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete d->dialog;
|
delete dialog;
|
||||||
d->dialog = 0;
|
dialog = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//get the margins
|
//get the margins
|
||||||
QSizeF marginSize = size() - contentsRect().size();
|
QSizeF marginSize = q->size() - q->contentsRect().size();
|
||||||
|
|
||||||
if (gWidget) {
|
if (gWidget) {
|
||||||
if (lay) {
|
if (lay) {
|
||||||
lay->addItem(gWidget);
|
lay->addItem(gWidget);
|
||||||
}
|
}
|
||||||
setMinimumSize(gWidget->minimumSize() + marginSize);
|
q->setMinimumSize(gWidget->minimumSize() + marginSize);
|
||||||
gWidget->installEventFilter(this);
|
gWidget->installEventFilter(q);
|
||||||
} else if (qWidget) {
|
} else if (qWidget) {
|
||||||
if (!d->proxy) {
|
if (!proxy) {
|
||||||
d->proxy = new QGraphicsProxyWidget(this);
|
proxy = new QGraphicsProxyWidget(q);
|
||||||
d->proxy->setWidget(qWidget);
|
proxy->setWidget(qWidget);
|
||||||
d->proxy->show();
|
proxy->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lay) {
|
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 {
|
} else {
|
||||||
//save the aspect ratio mode in case we drag'n drop in the Desktop later
|
//save the aspect ratio mode in case we drag'n drop in the Desktop later
|
||||||
d->savedAspectRatio = aspectRatioMode();
|
savedAspectRatio = q->aspectRatioMode();
|
||||||
setAspectRatioMode(Plasma::ConstrainedSquare);
|
q->setAspectRatioMode(Plasma::ConstrainedSquare);
|
||||||
|
|
||||||
if (d->icon) {
|
if (icon) {
|
||||||
d->icon->show();
|
icon->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d->proxy) {
|
if (proxy) {
|
||||||
d->proxy->setWidget(0); // prevent it from deleting our widget!
|
proxy->setWidget(0); // prevent it from deleting our widget!
|
||||||
delete d->proxy;
|
delete proxy;
|
||||||
d->proxy = 0;
|
proxy = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!d->dialog) {
|
if (!dialog) {
|
||||||
kDebug() << "making dialog with view" << view();
|
//kDebug() << "making dialog with view" << q->view();
|
||||||
d->dialog = new Plasma::Dialog();
|
dialog = new Plasma::Dialog();
|
||||||
|
|
||||||
//no longer use Qt::Popup since that seems to cause a lot of problem when you drag
|
//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
|
//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
|
//emulate the same kind of behavior as Qt::Popup (close when you click somewhere
|
||||||
//else.
|
//else.
|
||||||
d->dialog->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
|
dialog->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
|
||||||
KWindowSystem::setState(d->dialog->winId(), NET::SkipTaskbar | NET::SkipPager);
|
KWindowSystem::setState(dialog->winId(), NET::SkipTaskbar | NET::SkipPager);
|
||||||
d->dialog->installEventFilter(this);
|
dialog->installEventFilter(q);
|
||||||
|
|
||||||
connect(d->dialog, SIGNAL(dialogResized()), this, SLOT(dialogSizeChanged()));
|
QObject::connect(dialog, SIGNAL(dialogResized()), q, SLOT(dialogSizeChanged()));
|
||||||
connect(d->dialog, SIGNAL(dialogVisible(bool)), this , SLOT(dialogStatusChanged(bool)));
|
QObject::connect(dialog, SIGNAL(dialogVisible(bool)), q, SLOT(dialogStatusChanged(bool)));
|
||||||
setMinimumSize(QSize(0, 0));
|
q->setMinimumSize(QSize(0, 0));
|
||||||
if (gWidget) {
|
if (gWidget) {
|
||||||
Corona *corona = qobject_cast<Corona *>(gWidget->scene());
|
Corona *corona = qobject_cast<Corona *>(gWidget->scene());
|
||||||
|
|
||||||
//could that cast ever fail??
|
//could that cast ever fail??
|
||||||
if (corona) {
|
if (corona) {
|
||||||
corona->addOffscreenWidget(gWidget);
|
corona->addOffscreenWidget(gWidget);
|
||||||
graphicsWidget()->resize(gWidget->preferredSize());
|
gWidget->resize(gWidget->preferredSize());
|
||||||
graphicsWidget()->setMinimumSize(gWidget->preferredSize());
|
gWidget->setMinimumSize(gWidget->preferredSize());
|
||||||
d->dialog->setGraphicsWidget(gWidget);
|
dialog->setGraphicsWidget(gWidget);
|
||||||
}
|
}
|
||||||
} else if (qWidget) {
|
} else if (qWidget) {
|
||||||
QVBoxLayout *l_layout = new QVBoxLayout(d->dialog);
|
QVBoxLayout *l_layout = new QVBoxLayout(dialog);
|
||||||
l_layout->setSpacing(0);
|
l_layout->setSpacing(0);
|
||||||
l_layout->setMargin(0);
|
l_layout->setMargin(0);
|
||||||
l_layout->addWidget(qWidget);
|
l_layout->addWidget(qWidget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
d->dialog->adjustSize();
|
dialog->adjustSize();
|
||||||
|
|
||||||
if (d->icon && lay) {
|
if (icon && lay) {
|
||||||
lay->addItem(d->icon);
|
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()
|
void PopupAppletPrivate::togglePopup()
|
||||||
{
|
{
|
||||||
if (dialog) {
|
if (dialog) {
|
||||||
|
@ -108,7 +108,6 @@ public Q_SLOTS:
|
|||||||
void hidePopup();
|
void hidePopup();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void constraintsEvent(Plasma::Constraints constraints);
|
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
bool eventFilter(QObject *watched, QEvent *event);
|
bool eventFilter(QObject *watched, QEvent *event);
|
||||||
@ -121,6 +120,7 @@ private:
|
|||||||
Q_PRIVATE_SLOT(d, void dialogSizeChanged())
|
Q_PRIVATE_SLOT(d, void dialogSizeChanged())
|
||||||
Q_PRIVATE_SLOT(d, void dialogStatusChanged(bool))
|
Q_PRIVATE_SLOT(d, void dialogStatusChanged(bool))
|
||||||
|
|
||||||
|
friend class Applet;
|
||||||
PopupAppletPrivate * const d;
|
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