2008-11-04 00:08:39 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2008 by Montel Laurent <montel@kde.org>
|
|
|
|
* Copyright 2008 by Marco Martin <notmart@gmail.com>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "popupapplet.h"
|
|
|
|
#include "private/popupapplet_p.h"
|
2010-12-17 23:37:09 +01:00
|
|
|
#include "private/dialog_p.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-04-16 06:47:48 +02:00
|
|
|
#include <QApplication>
|
2008-11-04 00:08:39 +01:00
|
|
|
#include <QGraphicsProxyWidget>
|
|
|
|
#include <QGraphicsLinearLayout>
|
|
|
|
#include <QTimer>
|
2009-04-16 06:47:48 +02:00
|
|
|
#include <QVBoxLayout>
|
2009-04-17 15:21:41 +02:00
|
|
|
|
|
|
|
#ifdef Q_WS_X11
|
2009-04-16 06:47:48 +02:00
|
|
|
#include <QX11Info>
|
2009-04-17 15:21:41 +02:00
|
|
|
#endif
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kicon.h>
|
|
|
|
#include <kiconloader.h>
|
|
|
|
#include <kwindowsystem.h>
|
|
|
|
#include <kglobalsettings.h>
|
2009-04-16 06:47:48 +02:00
|
|
|
#include <netwm.h>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
#include "plasma/private/applet_p.h"
|
2009-02-09 19:10:45 +01:00
|
|
|
#include "plasma/private/extenderitemmimedata_p.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "plasma/corona.h"
|
|
|
|
#include "plasma/containment.h"
|
2009-10-01 01:07:42 +02:00
|
|
|
#include "plasma/private/containment_p.h"
|
2008-12-30 03:07:57 +01:00
|
|
|
#include "plasma/dialog.h"
|
2009-09-03 23:53:56 +02:00
|
|
|
#include "plasma/extenders/extender.h"
|
|
|
|
#include "plasma/extenders/extenderitem.h"
|
2009-12-16 19:35:04 +01:00
|
|
|
#include "plasma/package.h"
|
2010-04-15 18:14:37 +02:00
|
|
|
#include "plasma/theme.h"
|
2010-02-28 16:10:30 +01:00
|
|
|
#include "plasma/scripting/appletscript.h"
|
2008-12-30 03:07:57 +01:00
|
|
|
#include "plasma/tooltipmanager.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "plasma/widgets/iconwidget.h"
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
PopupApplet::PopupApplet(QObject *parent, const QVariantList &args)
|
|
|
|
: Plasma::Applet(parent, args),
|
|
|
|
d(new PopupAppletPrivate(this))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-10-23 15:48:29 +02:00
|
|
|
PopupApplet::PopupApplet(const QString &packagePath, uint appletId, const QVariantList &args)
|
|
|
|
: Plasma::Applet(packagePath, appletId, args),
|
|
|
|
d(new PopupAppletPrivate(this))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
PopupApplet::~PopupApplet()
|
|
|
|
{
|
|
|
|
delete widget();
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupApplet::setPopupIcon(const QIcon &icon)
|
|
|
|
{
|
|
|
|
if (icon.isNull()) {
|
|
|
|
if (d->icon) {
|
|
|
|
delete d->icon;
|
|
|
|
d->icon = 0;
|
|
|
|
setLayout(0);
|
2008-12-22 21:32:37 +01:00
|
|
|
setAspectRatioMode(d->savedAspectRatio);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2008-12-29 07:03:43 +01:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!d->icon) {
|
|
|
|
d->icon = new Plasma::IconWidget(icon, QString(), this);
|
2008-12-30 03:06:06 +01:00
|
|
|
connect(d->icon, SIGNAL(clicked()), this, SLOT(internalTogglePopup()));
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout();
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
layout->setSpacing(0);
|
|
|
|
layout->setOrientation(Qt::Horizontal);
|
|
|
|
|
|
|
|
setLayout(layout);
|
|
|
|
} else {
|
|
|
|
d->icon->setIcon(icon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupApplet::setPopupIcon(const QString &iconName)
|
|
|
|
{
|
2009-12-16 19:35:04 +01:00
|
|
|
if (package()) {
|
2010-04-15 18:14:37 +02:00
|
|
|
//Attempt1: is it in the plasmoid package?
|
2009-12-16 19:35:04 +01:00
|
|
|
const QString file = package()->filePath("images", iconName);
|
|
|
|
if (!file.isEmpty()) {
|
|
|
|
setPopupIcon(KIcon(file));
|
|
|
|
return;
|
|
|
|
}
|
2010-04-15 18:14:37 +02:00
|
|
|
//Attempt2: is it a svg in the icons directory?
|
|
|
|
}
|
|
|
|
QString name = QString("icons/") + iconName.split("-").first();
|
|
|
|
if (!Plasma::Theme::defaultTheme()->imagePath(name).isEmpty()) {
|
|
|
|
if (!d->icon) {
|
|
|
|
d->icon = new Plasma::IconWidget(this);
|
|
|
|
d->icon->setSvg(name, iconName);
|
2010-05-22 13:40:22 +02:00
|
|
|
if (d->icon->svg().isEmpty()) {
|
|
|
|
setPopupIcon(KIcon(iconName));
|
|
|
|
}
|
2010-04-15 18:14:37 +02:00
|
|
|
connect(d->icon, SIGNAL(clicked()), this, SLOT(internalTogglePopup()));
|
|
|
|
|
|
|
|
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout();
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
layout->setSpacing(0);
|
|
|
|
layout->setOrientation(Qt::Horizontal);
|
|
|
|
|
|
|
|
setLayout(layout);
|
|
|
|
} else {
|
|
|
|
d->icon->setSvg(name, iconName);
|
2010-05-22 13:40:22 +02:00
|
|
|
if (d->icon->svg().isEmpty()) {
|
|
|
|
setPopupIcon(KIcon(iconName));
|
|
|
|
}
|
2010-04-15 18:14:37 +02:00
|
|
|
}
|
|
|
|
// Final Attempt: use KIcon
|
|
|
|
} else {
|
|
|
|
setPopupIcon(KIcon(iconName));
|
2009-12-16 19:35:04 +01:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QIcon PopupApplet::popupIcon() const
|
|
|
|
{
|
|
|
|
return d->icon ? d->icon->icon() : QIcon();
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *PopupApplet::widget()
|
|
|
|
{
|
2009-07-17 14:31:08 +02:00
|
|
|
return d->widget;
|
|
|
|
}
|
|
|
|
|
2009-09-24 15:28:56 +02:00
|
|
|
void PopupApplet::setWidget(QWidget *widget)
|
2009-07-17 14:31:08 +02:00
|
|
|
{
|
2009-09-24 15:28:56 +02:00
|
|
|
if (d->widget) {
|
2009-11-11 21:51:59 +01:00
|
|
|
Plasma::Dialog *dialog = d->dialogPtr.data();
|
|
|
|
if (dialog) {
|
|
|
|
dialog->setGraphicsWidget(0);
|
2009-10-13 14:40:13 +02:00
|
|
|
QVBoxLayout *lay = 0;
|
2009-10-13 19:42:32 +02:00
|
|
|
|
2009-11-11 21:51:59 +01:00
|
|
|
QLayout *existingLayout = dialog->layout();
|
2009-10-13 19:42:32 +02:00
|
|
|
if (existingLayout) {
|
|
|
|
lay = dynamic_cast<QVBoxLayout *>(existingLayout);
|
|
|
|
if (!lay) {
|
|
|
|
delete existingLayout;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lay) {
|
|
|
|
lay = new QVBoxLayout;
|
2009-11-11 21:51:59 +01:00
|
|
|
dialog->setLayout(lay);
|
2009-09-24 15:28:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
lay->removeWidget(d->widget);
|
|
|
|
lay->addWidget(widget);
|
|
|
|
} else if (d->proxy) {
|
2009-10-15 18:42:41 +02:00
|
|
|
d->proxy.data()->setWidget(widget);
|
2009-09-24 15:28:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-17 14:31:08 +02:00
|
|
|
d->widget = widget;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsWidget *PopupApplet::graphicsWidget()
|
|
|
|
{
|
2009-07-17 14:31:08 +02:00
|
|
|
if (d->graphicsWidget != 0) {
|
|
|
|
return d->graphicsWidget;
|
|
|
|
} else {
|
2009-12-29 20:38:37 +01:00
|
|
|
return static_cast<Applet*>(this)->d->extender.data();
|
2009-07-17 14:31:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-24 15:28:56 +02:00
|
|
|
void PopupApplet::setGraphicsWidget(QGraphicsWidget *graphicsWidget)
|
2009-07-17 14:31:08 +02:00
|
|
|
{
|
2009-09-24 15:28:56 +02:00
|
|
|
if (d->graphicsWidget) {
|
2009-11-11 21:51:59 +01:00
|
|
|
if (d->dialogPtr) {
|
|
|
|
d->dialogPtr.data()->setGraphicsWidget(graphicsWidget);
|
2009-09-24 15:28:56 +02:00
|
|
|
} else {
|
|
|
|
QGraphicsLinearLayout *lay = static_cast<QGraphicsLinearLayout *>(layout());
|
|
|
|
lay->removeAt(0);
|
|
|
|
lay->addItem(graphicsWidget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-17 14:31:08 +02:00
|
|
|
d->graphicsWidget = graphicsWidget;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2008-12-08 19:03:23 +01:00
|
|
|
void PopupAppletPrivate::checkExtenderAppearance(Plasma::FormFactor f)
|
|
|
|
{
|
|
|
|
Extender *extender = qobject_cast<Extender*>(q->graphicsWidget());
|
|
|
|
if (extender) {
|
|
|
|
if (f != Plasma::Horizontal && f != Plasma::Vertical) {
|
|
|
|
extender->setAppearance(Extender::NoBorders);
|
|
|
|
} else if (q->location() == TopEdge) {
|
|
|
|
extender->setAppearance(Extender::TopDownStacked);
|
|
|
|
} else {
|
|
|
|
extender->setAppearance(Extender::BottomUpStacked);
|
|
|
|
}
|
|
|
|
|
2009-11-11 21:51:59 +01:00
|
|
|
if (dialogPtr) {
|
|
|
|
dialogPtr.data()->setGraphicsWidget(extender);
|
2008-12-09 20:07:21 +01:00
|
|
|
}
|
2008-12-08 19:03:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints)
|
|
|
|
{
|
|
|
|
Plasma::FormFactor f = q->formFactor();
|
2008-12-08 19:03:23 +01:00
|
|
|
|
|
|
|
if (constraints & Plasma::LocationConstraint) {
|
|
|
|
checkExtenderAppearance(f);
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
if (constraints & Plasma::FormFactorConstraint ||
|
2008-12-12 16:15:40 +01:00
|
|
|
constraints & Plasma::StartupCompletedConstraint ||
|
2008-11-04 00:08:39 +01:00
|
|
|
(constraints & Plasma::SizeConstraint &&
|
|
|
|
(f == Plasma::Vertical || f == Plasma::Horizontal))) {
|
|
|
|
QGraphicsLinearLayout *lay = dynamic_cast<QGraphicsLinearLayout *>(q->layout());
|
|
|
|
|
2011-01-07 23:02:36 +01:00
|
|
|
if (icon && lay && lay->count() > 0) {
|
2008-11-04 00:08:39 +01:00
|
|
|
lay->removeAt(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF minimum;
|
2009-08-08 13:34:49 +02:00
|
|
|
QSizeF parentSize;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
QGraphicsWidget *gWidget = q->graphicsWidget();
|
2009-04-27 18:04:28 +02:00
|
|
|
//kDebug() << "graphics widget is" << (QObject*)gWidget;
|
2008-11-04 00:08:39 +01:00
|
|
|
QWidget *qWidget = q->widget();
|
|
|
|
|
|
|
|
if (gWidget) {
|
|
|
|
minimum = gWidget->minimumSize();
|
|
|
|
// our layout may have been replaced on us in the call to graphicsWidget!
|
|
|
|
lay = dynamic_cast<QGraphicsLinearLayout *>(q->layout());
|
2008-12-08 19:03:23 +01:00
|
|
|
|
|
|
|
if (!(constraints & LocationConstraint)) {
|
|
|
|
checkExtenderAppearance(f);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
} else if (qWidget) {
|
|
|
|
minimum = qWidget->minimumSizeHint();
|
|
|
|
}
|
|
|
|
|
2009-08-08 13:34:49 +02:00
|
|
|
//99% of the times q->parentWidget() is the containment, but using it we can also manage the applet-in-applet case (i.e. systray)
|
2010-07-10 17:10:08 +02:00
|
|
|
//there are also cases where the parentlayoutitem is bigger than the containment (e.g. newspaper)
|
2009-08-19 22:06:47 +02:00
|
|
|
if (q->parentLayoutItem()) {
|
|
|
|
parentSize = q->parentLayoutItem()->geometry().size();
|
|
|
|
} else if (q->parentWidget()) {
|
2009-08-08 13:34:49 +02:00
|
|
|
parentSize = q->parentWidget()->size();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2010-07-10 17:10:08 +02:00
|
|
|
//check if someone did the nasty trick of applets in applets, in this case we always want to be collapsed
|
|
|
|
QGraphicsWidget *candidateParentApplet = q;
|
|
|
|
Plasma::Applet *parentApplet = 0;
|
|
|
|
//this loop should be executed normally a single time, at most 2-3 times for quite complex containments
|
|
|
|
while (candidateParentApplet) {
|
|
|
|
candidateParentApplet = candidateParentApplet->parentWidget();
|
|
|
|
parentApplet = qobject_cast<Plasma::Applet *>(candidateParentApplet);
|
|
|
|
if (parentApplet) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-23 18:55:40 +01:00
|
|
|
//Applet on desktop
|
2010-07-10 17:10:08 +02:00
|
|
|
if ((!parentApplet || parentApplet->isContainment() ) && icon && (!icon->svg().isEmpty() || !icon->icon().isNull()) && ((f != Plasma::Vertical && f != Plasma::Horizontal) ||
|
2009-08-08 13:34:49 +02:00
|
|
|
((f == Plasma::Vertical && parentSize.width() >= minimum.width()) ||
|
|
|
|
(f == Plasma::Horizontal && parentSize.height() >= minimum.height())))) {
|
2009-04-27 18:04:28 +02:00
|
|
|
//kDebug() << "we are expanding the popupapplet";
|
2008-12-12 16:03:18 +01:00
|
|
|
|
2010-05-13 23:10:59 +02:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
// 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
|
|
|
|
if (icon) {
|
|
|
|
icon->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (savedAspectRatio != Plasma::InvalidAspectRatioMode) {
|
|
|
|
q->setAspectRatioMode(savedAspectRatio);
|
|
|
|
}
|
|
|
|
|
2009-11-11 21:51:59 +01:00
|
|
|
Dialog *dialog = dialogPtr.data();
|
2008-11-04 00:08:39 +01:00
|
|
|
if (dialog) {
|
2009-11-11 21:51:59 +01:00
|
|
|
if (dialog->layout() && qWidget) {
|
2008-11-04 00:08:39 +01:00
|
|
|
//we don't want to delete Widget inside the dialog layout
|
2009-11-11 21:51:59 +01:00
|
|
|
dialog->layout()->removeWidget(qWidget);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (qWidget) {
|
|
|
|
qWidget->setParent(0);
|
|
|
|
}
|
|
|
|
|
2009-11-11 21:51:59 +01:00
|
|
|
delete dialog;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-01-06 19:08:58 +01:00
|
|
|
if (!lay) {
|
2008-11-04 00:08:39 +01:00
|
|
|
lay = new QGraphicsLinearLayout();
|
|
|
|
lay->setContentsMargins(0, 0, 0, 0);
|
|
|
|
lay->setSpacing(0);
|
|
|
|
lay->setOrientation(Qt::Horizontal);
|
|
|
|
q->setLayout(lay);
|
|
|
|
}
|
|
|
|
|
2008-11-22 17:23:11 +01:00
|
|
|
QSize prefSize;
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
if (gWidget) {
|
2009-06-10 04:05:31 +02:00
|
|
|
if (proxy) {
|
2009-10-15 18:42:41 +02:00
|
|
|
proxy.data()->setWidget(0);
|
|
|
|
delete proxy.data();
|
2009-06-10 04:05:31 +02:00
|
|
|
}
|
|
|
|
|
2008-12-24 20:13:05 +01:00
|
|
|
Corona *corona = qobject_cast<Corona *>(gWidget->scene());
|
|
|
|
|
|
|
|
if (corona) {
|
|
|
|
corona->removeOffscreenWidget(gWidget);
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
lay->addItem(gWidget);
|
2008-11-22 17:23:11 +01:00
|
|
|
prefSize = gWidget->preferredSize().toSize();
|
2008-11-04 00:08:39 +01:00
|
|
|
} else if (qWidget) {
|
|
|
|
if (!proxy) {
|
|
|
|
proxy = new QGraphicsProxyWidget(q);
|
2009-10-15 18:42:41 +02:00
|
|
|
proxy.data()->setWidget(qWidget);
|
|
|
|
proxy.data()->show();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-10-15 18:42:41 +02:00
|
|
|
lay->addItem(proxy.data());
|
2008-11-22 17:23:11 +01:00
|
|
|
prefSize = qWidget->sizeHint();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2008-11-23 20:24:49 +01:00
|
|
|
//we could be on a big panel, but in that case we will be able to resize
|
|
|
|
//more than the natural minimum size, because we'll transform into an icon
|
|
|
|
if (f == Plasma::Horizontal) {
|
|
|
|
minimum.setHeight(0);
|
|
|
|
} else if (f == Plasma::Vertical) {
|
|
|
|
minimum.setWidth(0);
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
qreal left, top, right, bottom;
|
|
|
|
q->getContentsMargins(&left, &top, &right, &bottom);
|
2008-11-22 22:09:34 +01:00
|
|
|
QSizeF oldSize(q->size());
|
2010-04-21 19:47:38 +02:00
|
|
|
|
2008-11-22 22:09:34 +01:00
|
|
|
//size not saved/invalid size saved
|
|
|
|
if (oldSize.width() < q->minimumSize().width() || oldSize.height() < q->minimumSize().height()) {
|
|
|
|
q->resize(prefSize);
|
2009-02-09 16:09:28 +01:00
|
|
|
emit q->appletTransformedItself();
|
2008-11-22 22:09:34 +01:00
|
|
|
}
|
2008-11-23 18:55:40 +01:00
|
|
|
//Applet on popup
|
2008-11-04 00:08:39 +01:00
|
|
|
} else {
|
2009-04-27 18:04:28 +02:00
|
|
|
//kDebug() << "about to switch to a popup";
|
2011-02-26 17:33:34 +01:00
|
|
|
|
|
|
|
//there was already a dialog? don't make the switch again
|
|
|
|
if (dialogPtr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
if (proxy) {
|
2009-10-15 18:42:41 +02:00
|
|
|
proxy.data()->setWidget(0); // prevent it from deleting our widget!
|
|
|
|
delete proxy.data();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-11-11 21:51:59 +01:00
|
|
|
if (!dialogPtr) {
|
2009-11-18 21:11:03 +01:00
|
|
|
//save the aspect ratio mode in case we drag'n drop in the Desktop later
|
|
|
|
savedAspectRatio = q->aspectRatioMode();
|
|
|
|
|
|
|
|
if (icon) {
|
|
|
|
icon->show();
|
|
|
|
q->setAspectRatioMode(Plasma::ConstrainedSquare);
|
|
|
|
}
|
|
|
|
|
2010-05-08 22:47:42 +02:00
|
|
|
Dialog *dialog = new Dialog();
|
2010-12-17 23:37:09 +01:00
|
|
|
dialog->d->appletPtr = q;
|
2009-11-11 21:51:59 +01:00
|
|
|
dialogPtr = dialog;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-11-18 21:11:03 +01:00
|
|
|
dialog->setAspectRatioMode(savedAspectRatio);
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
//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.
|
|
|
|
|
|
|
|
if (gWidget) {
|
|
|
|
Corona *corona = qobject_cast<Corona *>(gWidget->scene());
|
|
|
|
|
|
|
|
if (corona) {
|
|
|
|
corona->addOffscreenWidget(gWidget);
|
|
|
|
}
|
2009-06-01 12:33:41 +02:00
|
|
|
|
2010-04-04 03:55:56 +02:00
|
|
|
dialog->setGraphicsWidget(gWidget);
|
2011-02-24 18:26:40 +01:00
|
|
|
//gWidget->resize(gWidget->preferredSize());
|
2009-11-11 21:51:59 +01:00
|
|
|
dialog->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | (gWidget->windowFlags() & Qt::X11BypassWindowManagerHint));
|
2008-11-04 00:08:39 +01:00
|
|
|
} else if (qWidget) {
|
2009-11-11 21:51:59 +01:00
|
|
|
QVBoxLayout *l_layout = new QVBoxLayout(dialog);
|
2008-11-04 00:08:39 +01:00
|
|
|
l_layout->setSpacing(0);
|
|
|
|
l_layout->setMargin(0);
|
|
|
|
l_layout->addWidget(qWidget);
|
2009-11-11 21:51:59 +01:00
|
|
|
dialog->adjustSize();
|
|
|
|
dialog->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | (qWidget->windowFlags() & Qt::X11BypassWindowManagerHint));
|
2009-06-08 21:52:21 +02:00
|
|
|
} else {
|
2009-11-11 21:51:59 +01:00
|
|
|
dialog->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2009-06-08 21:52:21 +02:00
|
|
|
|
2010-04-04 03:55:56 +02:00
|
|
|
restoreDialogSize();
|
2009-11-11 21:51:59 +01:00
|
|
|
KWindowSystem::setState(dialog->winId(), NET::SkipTaskbar | NET::SkipPager);
|
|
|
|
dialog->installEventFilter(q);
|
2009-06-01 12:33:41 +02:00
|
|
|
|
2009-11-11 21:51:59 +01:00
|
|
|
QObject::connect(dialog, SIGNAL(dialogResized()), q, SLOT(dialogSizeChanged()));
|
|
|
|
QObject::connect(dialog, SIGNAL(dialogVisible(bool)), q, SLOT(dialogStatusChanged(bool)));
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (icon && lay) {
|
|
|
|
lay->addItem(icon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-09-03 20:11:49 +02:00
|
|
|
|
2009-11-11 21:51:59 +01:00
|
|
|
if (constraints & Plasma::PopupConstraint) {
|
2009-09-03 20:11:49 +02:00
|
|
|
updateDialogPosition();
|
|
|
|
}
|
|
|
|
|
2011-02-04 05:36:17 +01:00
|
|
|
if (icon) {
|
|
|
|
// emit the size hint changing stuff for our applet as we are handling
|
|
|
|
// the size changings
|
|
|
|
emit q->sizeHintChanged(Qt::PreferredSize);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2010-04-15 21:25:30 +02:00
|
|
|
void PopupAppletPrivate::appletActivated()
|
|
|
|
{
|
2011-02-05 01:18:03 +01:00
|
|
|
internalTogglePopup();
|
2010-04-15 21:25:30 +02:00
|
|
|
}
|
|
|
|
|
2010-05-25 20:21:04 +02:00
|
|
|
QSizeF PopupApplet::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const
|
|
|
|
{
|
2010-05-29 20:20:01 +02:00
|
|
|
if (!d->dialogPtr || which != Qt::PreferredSize) {
|
2010-05-25 20:21:04 +02:00
|
|
|
return Applet::sizeHint(which, constraint);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (formFactor()) {
|
|
|
|
case Vertical:
|
|
|
|
case Horizontal: {
|
|
|
|
const int size = IconSize(KIconLoader::Panel);
|
|
|
|
return QSizeF(size, size);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int size = IconSize(KIconLoader::Desktop);
|
|
|
|
return QSizeF(size, size);
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void PopupApplet::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (!d->icon && !d->popupLostFocus && event->buttons() == Qt::LeftButton) {
|
|
|
|
d->clicked = scenePos().toPoint();
|
|
|
|
event->setAccepted(true);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
d->popupLostFocus = false;
|
|
|
|
Applet::mousePressEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupApplet::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (!d->icon &&
|
|
|
|
(d->clicked - scenePos().toPoint()).manhattanLength() < KGlobalSettings::dndEventDelay()) {
|
2008-12-30 03:06:06 +01:00
|
|
|
d->internalTogglePopup();
|
2008-11-04 00:08:39 +01:00
|
|
|
} else {
|
|
|
|
Applet::mouseReleaseEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PopupApplet::eventFilter(QObject *watched, QEvent *event)
|
|
|
|
{
|
2009-11-11 21:51:59 +01:00
|
|
|
if (!d->passive && watched == d->dialogPtr.data() && (event->type() == QEvent::WindowDeactivate)) {
|
2008-11-04 00:08:39 +01:00
|
|
|
d->popupLostFocus = true;
|
|
|
|
QTimer::singleShot(100, this, SLOT(clearPopupLostFocus()));
|
|
|
|
}
|
|
|
|
|
2009-11-11 21:51:59 +01:00
|
|
|
if (watched == d->dialogPtr.data() && event->type() == QEvent::ContextMenu) {
|
2009-10-01 01:07:42 +02:00
|
|
|
//pass it up to the applet
|
|
|
|
//well, actually we have to pass it to the *containment*
|
|
|
|
//because all the code for showing an applet's contextmenu is actually in Containment.
|
|
|
|
Containment *c = containment();
|
|
|
|
if (c) {
|
2010-05-08 21:10:07 +02:00
|
|
|
Applet *applet = this;
|
|
|
|
Dialog *dialog = d->dialogPtr.data();
|
|
|
|
if (dialog && dialog->graphicsWidget()) {
|
|
|
|
int left, top, right, bottom;
|
|
|
|
dialog->getContentsMargins(&left, &top, &right, &bottom);
|
2010-05-08 22:47:42 +02:00
|
|
|
const QPoint eventPos = static_cast<QContextMenuEvent*>(event)->pos() - QPoint(left, top);
|
|
|
|
QPointF pos = dialog->graphicsWidget()->mapToScene(eventPos);
|
2010-05-08 21:10:07 +02:00
|
|
|
|
|
|
|
if (Applet *actual = c->d->appletAt(pos)) {
|
|
|
|
applet = actual;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-09 20:37:28 +02:00
|
|
|
KMenu desktopMenu;
|
|
|
|
c->d->addAppletActions(desktopMenu, applet, event);
|
|
|
|
|
|
|
|
if (!desktopMenu.isEmpty()) {
|
|
|
|
desktopMenu.exec(static_cast<QContextMenuEvent*>(event)->globalPos());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2009-10-01 01:07:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
return Applet::eventFilter(watched, event);
|
|
|
|
}
|
|
|
|
|
2009-02-09 19:10:45 +01:00
|
|
|
//FIXME: some duplication between the drag events... maybe add some simple helper function?
|
|
|
|
void PopupApplet::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
|
|
|
|
{
|
|
|
|
if (event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())) {
|
|
|
|
const ExtenderItemMimeData *mimeData =
|
|
|
|
qobject_cast<const ExtenderItemMimeData*>(event->mimeData());
|
|
|
|
if (mimeData && qobject_cast<Extender*>(graphicsWidget())) {
|
|
|
|
event->accept();
|
|
|
|
showPopup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupApplet::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
|
|
|
|
{
|
|
|
|
if (event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())) {
|
|
|
|
const ExtenderItemMimeData *mimeData =
|
|
|
|
qobject_cast<const ExtenderItemMimeData*>(event->mimeData());
|
|
|
|
if (mimeData && qobject_cast<Extender*>(graphicsWidget())) {
|
|
|
|
//We want to hide the popup if we're not moving onto the popup AND it is not the popup
|
|
|
|
//we started.
|
2009-11-11 21:51:59 +01:00
|
|
|
if (d->dialogPtr && !d->dialogPtr.data()->geometry().contains(event->screenPos()) &&
|
2009-02-09 19:10:45 +01:00
|
|
|
mimeData->extenderItem()->extender() != qobject_cast<Extender*>(graphicsWidget())) {
|
2009-02-09 23:10:35 +01:00
|
|
|
//We actually try to hide the popup, with a call to showPopup, with a smal timeout,
|
|
|
|
//so if the user moves into the popup fast enough, it remains open (the extender
|
|
|
|
//will call showPopup which will cancel the timeout.
|
|
|
|
showPopup(250);
|
2009-02-09 19:10:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupApplet::dropEvent(QGraphicsSceneDragDropEvent *event)
|
|
|
|
{
|
|
|
|
if (event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())) {
|
|
|
|
const ExtenderItemMimeData *mimeData =
|
|
|
|
qobject_cast<const ExtenderItemMimeData*>(event->mimeData());
|
|
|
|
if (mimeData && qobject_cast<Extender*>(graphicsWidget())) {
|
|
|
|
mimeData->extenderItem()->setExtender(extender());
|
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void PopupApplet::showPopup(uint popupDuration)
|
|
|
|
{
|
2010-12-14 04:14:14 +01:00
|
|
|
// use autohideTimer to store when the next show should be
|
|
|
|
if (popupDuration > 0 || d->autohideTimer) {
|
|
|
|
if (!d->autohideTimer) {
|
|
|
|
d->autohideTimer = new QTimer(this);
|
|
|
|
d->autohideTimer->setSingleShot(true);
|
|
|
|
connect(d->autohideTimer, SIGNAL(timeout()), this, SLOT(hideTimedPopup()));
|
2008-12-30 06:35:18 +01:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-12-14 04:14:14 +01:00
|
|
|
d->autohideTimer->stop();
|
|
|
|
d->autohideTimer->setInterval(popupDuration);
|
|
|
|
}
|
|
|
|
|
|
|
|
//kDebug() << "starting delayed show, duration for popup is" << popupDuration;
|
|
|
|
d->delayedShowTimer.start(0, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupApplet::timerEvent(QTimerEvent *event)
|
|
|
|
{
|
|
|
|
if (event->timerId() == d->delayedShowTimer.timerId()) {
|
|
|
|
d->delayedShowTimer.stop();
|
|
|
|
Dialog *dialog = d->dialogPtr.data();
|
|
|
|
if (dialog) {
|
|
|
|
// move the popup before its fist show, even if the show isn't triggered by
|
|
|
|
// a click, this should fix the first random position seen in some widgets
|
|
|
|
if (!dialog->isVisible()) {
|
|
|
|
d->internalTogglePopup();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2010-12-14 04:14:14 +01:00
|
|
|
const int popupDuration = d->autohideTimer ? d->autohideTimer->interval() : 0;
|
2010-12-14 23:53:50 +01:00
|
|
|
//kDebug() << "popupDuration is:" << (d->autohideTimer ? d->autohideTimer->interval() : 0);
|
2010-12-14 04:14:14 +01:00
|
|
|
if (popupDuration > 0) {
|
|
|
|
d->autohideTimer->start();
|
|
|
|
} else if (d->autohideTimer) {
|
|
|
|
d->autohideTimer->stop();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2010-12-14 04:14:14 +01:00
|
|
|
} else {
|
|
|
|
Applet::timerEvent(event);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupApplet::hidePopup()
|
|
|
|
{
|
2010-12-14 04:14:14 +01:00
|
|
|
d->delayedShowTimer.stop();
|
|
|
|
|
2009-11-11 21:51:59 +01:00
|
|
|
Dialog *dialog = d->dialogPtr.data();
|
|
|
|
if (dialog) {
|
2009-04-16 05:20:29 +02:00
|
|
|
if (location() != Floating) {
|
2009-11-11 21:51:59 +01:00
|
|
|
dialog->animatedHide(locationToInverseDirection(location()));
|
2009-04-16 05:20:29 +02:00
|
|
|
} else {
|
2009-11-11 21:51:59 +01:00
|
|
|
dialog->hide();
|
2009-04-16 05:20:29 +02:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-17 21:03:20 +01:00
|
|
|
void PopupApplet::togglePopup()
|
|
|
|
{
|
2008-12-30 06:35:18 +01:00
|
|
|
d->internalTogglePopup();
|
2008-11-17 21:03:20 +01:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
Plasma::PopupPlacement PopupApplet::popupPlacement() const
|
|
|
|
{
|
|
|
|
return d->popupPlacement;
|
|
|
|
}
|
|
|
|
|
2010-09-13 01:54:30 +02:00
|
|
|
void PopupApplet::setPopupAlignment(Qt::AlignmentFlag alignment)
|
|
|
|
{
|
|
|
|
d->popupAlignment = alignment;
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::AlignmentFlag PopupApplet::popupAlignment() const
|
|
|
|
{
|
|
|
|
return d->popupAlignment;
|
|
|
|
}
|
|
|
|
|
2010-02-28 16:10:30 +01:00
|
|
|
void PopupApplet::popupEvent(bool popped)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2010-02-28 16:10:30 +01:00
|
|
|
if (Applet::d->script) {
|
|
|
|
emit Applet::d->script->popupEvent(popped);
|
|
|
|
}
|
2008-11-27 07:03:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PopupApplet::setPassivePopup(bool passive)
|
|
|
|
{
|
|
|
|
d->passive = passive;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2008-11-27 07:09:00 +01:00
|
|
|
bool PopupApplet::isPassivePopup() const
|
|
|
|
{
|
|
|
|
return d->passive;
|
|
|
|
}
|
|
|
|
|
2008-12-29 07:03:43 +01:00
|
|
|
bool PopupApplet::isPopupShowing() const
|
|
|
|
{
|
2009-11-11 21:51:59 +01:00
|
|
|
return d->dialogPtr && d->dialogPtr.data()->isVisible();
|
2008-12-29 07:03:43 +01:00
|
|
|
}
|
|
|
|
|
2010-10-19 22:02:51 +02:00
|
|
|
bool PopupApplet::isIconified() const
|
|
|
|
{
|
|
|
|
return d->dialogPtr;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
PopupAppletPrivate::PopupAppletPrivate(PopupApplet *applet)
|
|
|
|
: q(applet),
|
|
|
|
icon(0),
|
2009-07-17 14:31:08 +02:00
|
|
|
widget(0),
|
|
|
|
graphicsWidget(0),
|
2008-11-04 00:08:39 +01:00
|
|
|
popupPlacement(Plasma::FloatingPopup),
|
2010-09-13 01:54:30 +02:00
|
|
|
popupAlignment(Qt::AlignLeft),
|
2008-11-04 00:08:39 +01:00
|
|
|
savedAspectRatio(Plasma::InvalidAspectRatioMode),
|
2010-12-14 04:14:14 +01:00
|
|
|
autohideTimer(0),
|
2011-04-08 18:55:37 +02:00
|
|
|
preShowStatus(UnknownStatus),
|
2008-11-27 07:03:53 +01:00
|
|
|
popupLostFocus(false),
|
|
|
|
passive(false)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2010-05-25 20:21:04 +02:00
|
|
|
int iconSize = IconSize(KIconLoader::Desktop);
|
|
|
|
q->resize(iconSize, iconSize);
|
|
|
|
q->setAcceptDrops(true);
|
|
|
|
QObject::disconnect(q, SIGNAL(activate()), static_cast<Applet*>(q), SLOT(setFocus()));
|
|
|
|
QObject::connect(q, SIGNAL(activate()), q, SLOT(appletActivated()));
|
|
|
|
QObject::connect(KGlobalSettings::self(), SIGNAL(iconChanged(int)), q, SLOT(iconSizeChanged(int)));
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
PopupAppletPrivate::~PopupAppletPrivate()
|
|
|
|
{
|
|
|
|
if (proxy) {
|
2009-10-15 18:42:41 +02:00
|
|
|
proxy.data()->setWidget(0);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-11-11 21:51:59 +01:00
|
|
|
delete dialogPtr.data();
|
2008-11-04 00:08:39 +01:00
|
|
|
delete icon;
|
|
|
|
}
|
|
|
|
|
2010-05-25 20:21:04 +02:00
|
|
|
void PopupAppletPrivate::iconSizeChanged(int group)
|
|
|
|
{
|
|
|
|
if (icon && (group == KIconLoader::Desktop || group == KIconLoader::Panel)) {
|
|
|
|
q->updateGeometry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-30 03:06:06 +01:00
|
|
|
void PopupAppletPrivate::internalTogglePopup()
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2010-12-14 04:14:14 +01:00
|
|
|
if (autohideTimer) {
|
|
|
|
autohideTimer->stop();
|
2010-01-12 19:35:03 +01:00
|
|
|
}
|
|
|
|
|
2010-12-14 04:14:14 +01:00
|
|
|
delayedShowTimer.stop();
|
|
|
|
|
2010-01-12 19:35:03 +01:00
|
|
|
Plasma::Dialog *dialog = dialogPtr.data();
|
|
|
|
if (!dialog) {
|
2009-04-27 17:25:02 +02:00
|
|
|
q->setFocus(Qt::ShortcutFocusReason);
|
2008-12-30 06:35:18 +01:00
|
|
|
return;
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-09-03 20:37:27 +02:00
|
|
|
if (!q->view()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-12 19:35:03 +01:00
|
|
|
if (dialog->isVisible()) {
|
2009-04-16 05:20:29 +02:00
|
|
|
if (q->location() != Floating) {
|
2010-01-12 19:35:03 +01:00
|
|
|
dialog->animatedHide(locationToInverseDirection(q->location()));
|
2009-04-16 05:20:29 +02:00
|
|
|
} else {
|
2010-01-12 19:35:03 +01:00
|
|
|
dialog->hide();
|
2009-04-16 05:20:29 +02:00
|
|
|
}
|
2009-04-27 17:25:02 +02:00
|
|
|
|
2010-01-12 19:35:03 +01:00
|
|
|
dialog->clearFocus();
|
2008-12-30 06:35:18 +01:00
|
|
|
} else {
|
2009-04-27 17:25:02 +02:00
|
|
|
if (q->graphicsWidget() &&
|
2009-12-29 20:38:37 +01:00
|
|
|
q->graphicsWidget() == static_cast<Applet*>(q)->d->extender.data() &&
|
|
|
|
static_cast<Applet*>(q)->d->extender.data()->isEmpty()) {
|
2009-04-27 17:25:02 +02:00
|
|
|
// we have nothing to show, so let's not.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-12-30 06:35:18 +01:00
|
|
|
ToolTipManager::self()->hide(q);
|
|
|
|
updateDialogPosition();
|
2009-06-09 00:15:48 +02:00
|
|
|
|
2010-01-12 19:35:03 +01:00
|
|
|
KWindowSystem::setOnAllDesktops(dialog->winId(), true);
|
|
|
|
KWindowSystem::setState(dialog->winId(), NET::SkipTaskbar | NET::SkipPager);
|
2009-04-16 06:47:48 +02:00
|
|
|
|
2010-01-12 19:35:03 +01:00
|
|
|
dialog->setAspectRatioMode(savedAspectRatio);
|
2009-11-18 21:11:03 +01:00
|
|
|
|
2009-04-16 06:19:03 +02:00
|
|
|
if (q->location() != Floating) {
|
2010-01-12 19:35:03 +01:00
|
|
|
dialog->animatedShow(locationToDirection(q->location()));
|
2009-04-16 06:19:03 +02:00
|
|
|
} else {
|
2010-01-12 19:35:03 +01:00
|
|
|
dialog->show();
|
2009-04-16 06:19:03 +02:00
|
|
|
}
|
2009-05-06 20:40:44 +02:00
|
|
|
|
2010-01-12 19:35:03 +01:00
|
|
|
if (!(dialog->windowFlags() & Qt::X11BypassWindowManagerHint)) {
|
|
|
|
KWindowSystem::activateWindow(dialog->winId());
|
2009-06-09 00:15:48 +02:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupAppletPrivate::hideTimedPopup()
|
|
|
|
{
|
2010-12-14 04:14:14 +01:00
|
|
|
autohideTimer->stop();
|
2008-11-04 00:08:39 +01:00
|
|
|
q->hidePopup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupAppletPrivate::clearPopupLostFocus()
|
|
|
|
{
|
2010-03-10 15:20:20 +01:00
|
|
|
if (!icon || !icon->isDown()) {
|
|
|
|
q->hidePopup();
|
|
|
|
}
|
2010-12-14 04:14:14 +01:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
popupLostFocus = false;
|
|
|
|
}
|
|
|
|
|
2009-11-11 22:47:56 +01:00
|
|
|
KConfigGroup PopupAppletPrivate::popupConfigGroup()
|
|
|
|
{
|
|
|
|
KConfigGroup *mainGroup = static_cast<Applet*>(q)->d->mainConfigGroup();
|
|
|
|
return KConfigGroup(mainGroup, "PopupApplet");
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void PopupAppletPrivate::dialogSizeChanged()
|
|
|
|
{
|
|
|
|
//Reposition the dialog
|
2009-11-11 21:51:59 +01:00
|
|
|
Plasma::Dialog *dialog = dialogPtr.data();
|
2008-11-04 00:08:39 +01:00
|
|
|
if (dialog) {
|
2009-11-11 22:47:56 +01:00
|
|
|
KConfigGroup sizeGroup = popupConfigGroup();
|
2009-11-11 21:51:59 +01:00
|
|
|
sizeGroup.writeEntry("DialogHeight", dialog->height());
|
|
|
|
sizeGroup.writeEntry("DialogWidth", dialog->width());
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-12-07 21:20:28 +01:00
|
|
|
updateDialogPosition();
|
|
|
|
|
2010-04-04 23:08:54 +02:00
|
|
|
emit q->configNeedsSaving();
|
2009-11-15 22:53:10 +01:00
|
|
|
emit q->appletTransformedByUser();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-05 02:51:12 +01:00
|
|
|
void PopupAppletPrivate::dialogStatusChanged(bool shown)
|
|
|
|
{
|
|
|
|
if (shown) {
|
|
|
|
preShowStatus = q->status();
|
|
|
|
q->setStatus(NeedsAttentionStatus);
|
|
|
|
QObject::connect(q, SIGNAL(newStatus(Plasma::ItemStatus)),
|
|
|
|
q, SLOT(statusChangeWhileShown(Plasma::ItemStatus)),
|
2011-02-07 19:37:50 +01:00
|
|
|
Qt::UniqueConnection);
|
2011-02-05 02:51:12 +01:00
|
|
|
} else {
|
|
|
|
QObject::disconnect(q, SIGNAL(newStatus(Plasma::ItemStatus)),
|
|
|
|
q, SLOT(statusChangeWhileShown(Plasma::ItemStatus)));
|
|
|
|
q->setStatus(preShowStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
q->popupEvent(shown);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupAppletPrivate::statusChangeWhileShown(Plasma::ItemStatus status)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2011-02-05 02:51:12 +01:00
|
|
|
preShowStatus = status;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2010-04-04 03:55:56 +02:00
|
|
|
void PopupAppletPrivate::restoreDialogSize()
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2009-11-11 21:51:59 +01:00
|
|
|
Plasma::Dialog *dialog = dialogPtr.data();
|
2009-06-25 16:13:14 +02:00
|
|
|
if (!dialog) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-12 02:18:57 +02:00
|
|
|
Corona *corona = qobject_cast<Corona *>(q->scene());
|
2010-01-08 22:58:04 +01:00
|
|
|
if (!corona) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
KConfigGroup sizeGroup = popupConfigGroup();
|
2008-12-28 13:54:48 +01:00
|
|
|
|
|
|
|
int preferredWidth = 0;
|
|
|
|
int preferredHeight = 0;
|
2011-02-24 18:26:40 +01:00
|
|
|
QGraphicsWidget *gWidget = dialog->graphicsWidget();
|
|
|
|
if (gWidget) {
|
|
|
|
preferredWidth = gWidget->preferredSize().width();
|
|
|
|
preferredHeight = gWidget->preferredSize().height();
|
2008-12-28 13:54:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const int width = qMin(sizeGroup.readEntry("DialogWidth", preferredWidth),
|
2009-09-12 02:18:57 +02:00
|
|
|
corona->screenGeometry(-1).width() - 50);
|
2008-12-28 13:54:48 +01:00
|
|
|
const int height = qMin(sizeGroup.readEntry("DialogHeight", preferredHeight),
|
2009-09-12 02:18:57 +02:00
|
|
|
corona->screenGeometry(-1).height() - 50);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
QSize saved(width, height);
|
|
|
|
|
|
|
|
if (saved.isNull()) {
|
2009-11-11 21:51:59 +01:00
|
|
|
saved = dialog->sizeHint();
|
2008-11-04 00:08:39 +01:00
|
|
|
} else {
|
2009-11-11 21:51:59 +01:00
|
|
|
saved = saved.expandedTo(dialog->minimumSizeHint());
|
2009-01-23 08:33:30 +01:00
|
|
|
}
|
|
|
|
|
2009-11-11 21:51:59 +01:00
|
|
|
if (saved.width() != dialog->width() || saved.height() != dialog->height()) {
|
|
|
|
dialog->resize(saved);
|
2011-02-24 18:26:40 +01:00
|
|
|
/*if (gWidget) {
|
|
|
|
gWidget->resize(saved);
|
|
|
|
}*/
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2010-04-04 03:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PopupAppletPrivate::updateDialogPosition()
|
|
|
|
{
|
|
|
|
Plasma::Dialog *dialog = dialogPtr.data();
|
|
|
|
if (!dialog) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Corona *corona = qobject_cast<Corona *>(q->scene());
|
|
|
|
if (!corona) {
|
|
|
|
return;
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-11-11 22:47:56 +01:00
|
|
|
QGraphicsView *view = q->view();
|
|
|
|
if (!view) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-11 21:51:59 +01:00
|
|
|
QSize s = dialog->size();
|
2008-11-04 00:08:39 +01:00
|
|
|
QPoint pos = view->mapFromScene(q->scenePos());
|
2009-01-23 08:33:30 +01:00
|
|
|
|
2010-04-15 21:25:30 +02:00
|
|
|
if (!q->containment() || view == q->containment()->view()) {
|
2010-09-13 01:54:30 +02:00
|
|
|
pos = corona->popupPosition(q, s, popupAlignment);
|
2010-04-15 21:25:30 +02:00
|
|
|
} else {
|
2010-09-13 01:54:30 +02:00
|
|
|
pos = corona->popupPosition(q->parentItem(), s, popupAlignment);
|
2010-04-15 21:25:30 +02:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-12-16 12:43:21 +01:00
|
|
|
bool reverse = false;
|
|
|
|
if (q->formFactor() == Plasma::Vertical) {
|
2009-11-11 21:51:59 +01:00
|
|
|
if (view->mapToGlobal(view->mapFromScene(q->scenePos())).y() + q->size().height()/2 < pos.y() + dialog->size().width()/2) {
|
2008-12-16 12:43:21 +01:00
|
|
|
reverse = true;
|
|
|
|
}
|
|
|
|
} else {
|
2009-11-11 21:51:59 +01:00
|
|
|
if (view->mapToGlobal(view->mapFromScene(q->scenePos())).x() + q->size().width()/2 < pos.x() + dialog->size().width()/2) {
|
2008-12-16 12:43:21 +01:00
|
|
|
reverse = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
switch (q->location()) {
|
|
|
|
case BottomEdge:
|
2008-12-12 21:07:51 +01:00
|
|
|
if (pos.x() >= q->pos().x()) {
|
2009-11-11 21:51:59 +01:00
|
|
|
dialog->setResizeHandleCorners(Dialog::NorthEast);
|
2008-11-04 00:08:39 +01:00
|
|
|
} else {
|
2009-11-11 21:51:59 +01:00
|
|
|
dialog->setResizeHandleCorners(Dialog::NorthWest);
|
2008-12-12 21:07:51 +01:00
|
|
|
}
|
2008-12-16 12:43:21 +01:00
|
|
|
|
|
|
|
if (reverse) {
|
|
|
|
popupPlacement = Plasma::TopPosedLeftAlignedPopup;
|
|
|
|
} else {
|
|
|
|
popupPlacement = Plasma::TopPosedRightAlignedPopup;
|
|
|
|
}
|
2008-12-12 21:07:51 +01:00
|
|
|
break;
|
|
|
|
case TopEdge:
|
|
|
|
if (pos.x() >= q->pos().x()) {
|
2009-11-11 21:51:59 +01:00
|
|
|
dialog->setResizeHandleCorners(Dialog::SouthEast);
|
2008-12-12 21:07:51 +01:00
|
|
|
} else {
|
2009-11-11 21:51:59 +01:00
|
|
|
dialog->setResizeHandleCorners(Dialog::SouthWest);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2008-12-16 12:43:21 +01:00
|
|
|
|
|
|
|
if (reverse) {
|
|
|
|
popupPlacement = Plasma::BottomPosedLeftAlignedPopup;
|
|
|
|
} else {
|
|
|
|
popupPlacement = Plasma::BottomPosedRightAlignedPopup;
|
|
|
|
}
|
2008-12-12 21:07:51 +01:00
|
|
|
break;
|
|
|
|
case LeftEdge:
|
|
|
|
if (pos.y() >= q->pos().y()) {
|
2009-11-11 21:51:59 +01:00
|
|
|
dialog->setResizeHandleCorners(Dialog::SouthEast);
|
2008-12-12 21:07:51 +01:00
|
|
|
} else {
|
2009-11-11 21:51:59 +01:00
|
|
|
dialog->setResizeHandleCorners(Dialog::NorthEast);
|
2008-12-12 21:07:51 +01:00
|
|
|
}
|
2008-12-16 12:43:21 +01:00
|
|
|
|
|
|
|
if (reverse) {
|
|
|
|
popupPlacement = Plasma::RightPosedTopAlignedPopup;
|
|
|
|
} else {
|
|
|
|
popupPlacement = Plasma::RightPosedBottomAlignedPopup;
|
|
|
|
}
|
2008-12-12 21:07:51 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RightEdge:
|
|
|
|
if (pos.y() >= q->pos().y()) {
|
2009-11-11 21:51:59 +01:00
|
|
|
dialog->setResizeHandleCorners(Dialog::SouthWest);
|
2008-12-12 21:07:51 +01:00
|
|
|
} else {
|
2009-11-11 21:51:59 +01:00
|
|
|
dialog->setResizeHandleCorners(Dialog::NorthWest);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2008-12-16 12:43:21 +01:00
|
|
|
|
|
|
|
if (reverse) {
|
|
|
|
popupPlacement = Plasma::LeftPosedTopAlignedPopup;
|
|
|
|
} else {
|
|
|
|
popupPlacement = Plasma::LeftPosedBottomAlignedPopup;
|
|
|
|
}
|
2008-12-12 21:07:51 +01:00
|
|
|
break;
|
|
|
|
default:
|
2009-11-11 21:51:59 +01:00
|
|
|
dialog->setResizeHandleCorners(Dialog::NorthEast);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-11-11 21:51:59 +01:00
|
|
|
dialog->move(pos);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2009-04-17 10:45:46 +02:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
} // Plasma namespace
|
|
|
|
|
|
|
|
#include "popupapplet.moc"
|
|
|
|
|