2008-09-07 23:33:02 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2008 by Montel Laurent <montel@kde.org>
|
2008-09-17 13:31:26 +02:00
|
|
|
* Copyright 2008 by Marco Martin <notmart@gmail.com>
|
2008-09-07 23:33:02 +02:00
|
|
|
*
|
2008-09-08 19:32:25 +02:00
|
|
|
* 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.
|
2008-09-07 23:33:02 +02:00
|
|
|
*
|
2008-09-08 19:32:25 +02:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2008-09-07 23:33:02 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-09-08 19:32:25 +02:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2008-09-07 23:33:02 +02:00
|
|
|
*
|
2008-09-08 19:32:25 +02:00
|
|
|
* 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,
|
2008-09-07 23:33:02 +02:00
|
|
|
* Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2008-07-17 11:30:57 +02:00
|
|
|
|
|
|
|
#include "popupapplet.h"
|
2008-09-19 05:26:24 +02:00
|
|
|
#include "private/popupapplet_p.h"
|
2008-07-17 11:30:57 +02:00
|
|
|
|
|
|
|
#include <QGraphicsProxyWidget>
|
|
|
|
#include <QGraphicsLinearLayout>
|
|
|
|
#include <QVBoxLayout>
|
2008-07-28 01:23:57 +02:00
|
|
|
#include <QTimer>
|
2008-09-12 19:16:58 +02:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QDesktopWidget>
|
2008-07-17 11:30:57 +02:00
|
|
|
|
|
|
|
#include <KIcon>
|
|
|
|
#include <KIconLoader>
|
2008-09-04 19:09:34 +02:00
|
|
|
#include <KWindowSystem>
|
2008-09-12 20:32:01 +02:00
|
|
|
#include <KGlobalSettings>
|
2008-07-17 11:30:57 +02:00
|
|
|
|
2008-09-18 04:49:14 +02:00
|
|
|
#include "plasma/private/applet_p.h"
|
|
|
|
#include "plasma/dialog.h"
|
|
|
|
#include "plasma/corona.h"
|
|
|
|
#include "plasma/containment.h"
|
|
|
|
#include "plasma/extender.h"
|
|
|
|
#include "plasma/widgets/icon.h"
|
2008-07-17 11:30:57 +02:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
PopupApplet::PopupApplet(QObject *parent, const QVariantList &args)
|
|
|
|
: Plasma::Applet(parent, args),
|
|
|
|
d(new PopupAppletPrivate(this))
|
|
|
|
{
|
|
|
|
int iconSize = IconSize(KIconLoader::Desktop);
|
|
|
|
resize(iconSize, iconSize);
|
2008-09-17 21:15:24 +02:00
|
|
|
connect(this, SIGNAL(activate()), this, SLOT(togglePopup()));
|
2008-07-17 11:30:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PopupApplet::~PopupApplet()
|
|
|
|
{
|
2008-10-22 20:51:59 +02:00
|
|
|
delete widget();
|
2008-07-17 11:30:57 +02:00
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2008-09-12 20:32:01 +02:00
|
|
|
void PopupApplet::setPopupIcon(const QIcon &icon)
|
2008-07-17 11:30:57 +02:00
|
|
|
{
|
2008-09-12 20:32:01 +02:00
|
|
|
if (icon.isNull()) {
|
|
|
|
if (d->icon) {
|
|
|
|
delete d->icon;
|
|
|
|
d->icon = 0;
|
|
|
|
setLayout(0);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-17 11:30:57 +02:00
|
|
|
if (!d->icon) {
|
|
|
|
d->icon = new Plasma::Icon(icon, QString(), this);
|
2008-09-12 20:32:01 +02:00
|
|
|
connect(d->icon, SIGNAL(clicked()), this, SLOT(togglePopup()));
|
|
|
|
|
|
|
|
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout();
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
layout->setSpacing(0);
|
|
|
|
layout->setOrientation(Qt::Horizontal);
|
2008-10-17 15:49:11 +02:00
|
|
|
|
|
|
|
if (formFactor() == Plasma::Vertical || formFactor() == Plasma::Horizontal ) {
|
|
|
|
d->savedAspectRatio = aspectRatioMode();
|
2008-10-23 02:16:07 +02:00
|
|
|
setAspectRatioMode(Plasma::ConstrainedSquare);
|
|
|
|
}
|
2008-10-17 15:49:11 +02:00
|
|
|
|
2008-09-12 20:32:01 +02:00
|
|
|
setLayout(layout);
|
2008-07-17 11:30:57 +02:00
|
|
|
} else {
|
|
|
|
d->icon->setIcon(icon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-12 20:32:01 +02:00
|
|
|
void PopupApplet::setPopupIcon(const QString &iconName)
|
2008-07-17 11:30:57 +02:00
|
|
|
{
|
2008-09-12 20:32:01 +02:00
|
|
|
setPopupIcon(KIcon(iconName));
|
2008-07-17 11:30:57 +02:00
|
|
|
}
|
|
|
|
|
2008-09-12 20:32:01 +02:00
|
|
|
QIcon PopupApplet::popupIcon() const
|
2008-07-17 11:30:57 +02:00
|
|
|
{
|
2008-09-12 20:32:01 +02:00
|
|
|
return d->icon ? d->icon->icon() : QIcon();
|
2008-07-17 11:30:57 +02:00
|
|
|
}
|
|
|
|
|
2008-07-28 01:23:57 +02:00
|
|
|
QWidget *PopupApplet::widget()
|
|
|
|
{
|
|
|
|
return 0;
|
2008-07-28 08:59:20 +02:00
|
|
|
}
|
2008-07-28 01:23:57 +02:00
|
|
|
|
|
|
|
QGraphicsWidget *PopupApplet::graphicsWidget()
|
|
|
|
{
|
2008-09-18 04:49:14 +02:00
|
|
|
return static_cast<Applet*>(this)->d->extender;
|
2008-07-28 08:59:20 +02:00
|
|
|
}
|
2008-07-28 01:23:57 +02:00
|
|
|
|
2008-09-19 05:26:24 +02:00
|
|
|
void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints)
|
2008-07-17 11:30:57 +02:00
|
|
|
{
|
|
|
|
if (constraints & Plasma::StartupCompletedConstraint) {
|
2008-09-19 05:26:24 +02:00
|
|
|
startupComplete = true;
|
2008-07-17 11:30:57 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 05:26:24 +02:00
|
|
|
if (!startupComplete) {
|
2008-08-25 15:55:26 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-09-19 05:26:24 +02:00
|
|
|
Plasma::FormFactor f = q->formFactor();
|
2008-09-17 13:31:26 +02:00
|
|
|
if (constraints & Plasma::FormFactorConstraint ||
|
2008-10-12 00:48:38 +02:00
|
|
|
(constraints & Plasma::SizeConstraint &&
|
|
|
|
(f == Plasma::Vertical || f == Plasma::Horizontal))) {
|
2008-10-03 19:20:01 +02:00
|
|
|
QGraphicsLinearLayout *lay = dynamic_cast<QGraphicsLinearLayout *>(q->layout());
|
|
|
|
|
2008-10-23 02:16:07 +02:00
|
|
|
if (icon && !icon->icon().isNull() && lay) {
|
2008-09-12 20:32:01 +02:00
|
|
|
lay->removeAt(0);
|
|
|
|
}
|
2008-07-28 01:23:57 +02:00
|
|
|
|
2008-09-17 13:31:26 +02:00
|
|
|
QSizeF minimum;
|
|
|
|
QSizeF containmentSize;
|
|
|
|
|
2008-09-19 05:26:24 +02:00
|
|
|
QGraphicsWidget *gWidget = q->graphicsWidget();
|
2008-10-03 19:20:01 +02:00
|
|
|
kDebug() << "graphics widget is" << (QObject*)gWidget;
|
2008-09-19 05:26:24 +02:00
|
|
|
QWidget *qWidget = q->widget();
|
2008-09-17 13:31:26 +02:00
|
|
|
|
|
|
|
if (gWidget) {
|
|
|
|
minimum = gWidget->minimumSize();
|
2008-10-14 07:02:29 +02:00
|
|
|
// our layout may have been replaced on us in the call to graphicsWidget!
|
|
|
|
lay = dynamic_cast<QGraphicsLinearLayout *>(q->layout());
|
2008-09-18 04:44:53 +02:00
|
|
|
} else if (qWidget) {
|
|
|
|
minimum = qWidget->minimumSizeHint();
|
2008-09-17 13:31:26 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 05:26:24 +02:00
|
|
|
if (q->containment()) {
|
|
|
|
containmentSize = q->containment()->size();
|
2008-09-17 13:31:26 +02:00
|
|
|
}
|
|
|
|
|
2008-10-03 20:01:55 +02:00
|
|
|
if (icon && !icon->icon().isNull() && ((f != Plasma::Vertical && f != Plasma::Horizontal) ||
|
2008-10-03 19:20:01 +02:00
|
|
|
((f == Plasma::Vertical && containmentSize.width() >= minimum.width()) ||
|
2008-10-03 20:01:55 +02:00
|
|
|
(f == Plasma::Horizontal && containmentSize.height() >= minimum.height())))) {
|
2008-09-12 20:32:01 +02: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
|
2008-10-03 19:20:01 +02:00
|
|
|
if (icon) {
|
|
|
|
icon->hide();
|
|
|
|
}
|
2008-08-11 20:15:37 +02:00
|
|
|
|
2008-09-19 05:26:24 +02:00
|
|
|
if (savedAspectRatio != Plasma::InvalidAspectRatioMode) {
|
|
|
|
q->setAspectRatioMode(savedAspectRatio);
|
2008-07-28 01:23:57 +02:00
|
|
|
}
|
2008-07-17 11:30:57 +02:00
|
|
|
|
2008-09-19 05:26:24 +02:00
|
|
|
if (dialog) {
|
|
|
|
if (dialog->layout() && qWidget) {
|
2008-10-12 13:12:24 +02:00
|
|
|
//we don't want to delete Widget inside the dialog layout
|
2008-09-19 05:26:24 +02:00
|
|
|
dialog->layout()->removeWidget(qWidget);
|
2008-07-28 01:23:57 +02:00
|
|
|
}
|
2008-07-17 11:30:57 +02:00
|
|
|
|
2008-10-22 20:51:59 +02:00
|
|
|
if (qWidget) {
|
|
|
|
qWidget->setParent(0);
|
|
|
|
}
|
|
|
|
|
2008-09-19 05:26:24 +02:00
|
|
|
delete dialog;
|
|
|
|
dialog = 0;
|
2008-07-17 11:30:57 +02:00
|
|
|
}
|
|
|
|
|
2008-10-23 02:16:07 +02:00
|
|
|
if (!lay && !q->layout()) {
|
|
|
|
lay = new QGraphicsLinearLayout();
|
|
|
|
lay->setContentsMargins(0, 0, 0, 0);
|
|
|
|
lay->setSpacing(0);
|
|
|
|
lay->setOrientation(Qt::Horizontal);
|
|
|
|
q->setLayout(lay);
|
|
|
|
}
|
2008-07-26 17:05:16 +02:00
|
|
|
|
2008-09-07 22:49:10 +02:00
|
|
|
if (gWidget) {
|
2008-10-20 12:58:37 +02:00
|
|
|
Extender *extender = qobject_cast<Extender*>(gWidget);
|
|
|
|
if (extender) {
|
|
|
|
extender->setExtenderAppearance(Extender::NoBorders);
|
|
|
|
}
|
|
|
|
|
2008-10-07 18:15:33 +02:00
|
|
|
lay->addItem(gWidget);
|
2008-09-18 04:44:53 +02:00
|
|
|
} else if (qWidget) {
|
2008-09-19 05:26:24 +02:00
|
|
|
if (!proxy) {
|
|
|
|
proxy = new QGraphicsProxyWidget(q);
|
|
|
|
proxy->setWidget(qWidget);
|
|
|
|
proxy->show();
|
2008-07-28 01:23:57 +02:00
|
|
|
}
|
|
|
|
|
2008-09-12 20:32:01 +02:00
|
|
|
if (lay) {
|
2008-09-19 05:26:24 +02:00
|
|
|
lay->addItem(proxy);
|
2008-09-12 20:32:01 +02:00
|
|
|
}
|
2008-07-28 01:23:57 +02:00
|
|
|
}
|
2008-09-12 20:32:01 +02:00
|
|
|
} else {
|
2008-07-28 01:23:57 +02:00
|
|
|
//save the aspect ratio mode in case we drag'n drop in the Desktop later
|
2008-09-19 05:26:24 +02:00
|
|
|
savedAspectRatio = q->aspectRatioMode();
|
|
|
|
q->setAspectRatioMode(Plasma::ConstrainedSquare);
|
2008-07-17 11:30:57 +02:00
|
|
|
|
2008-09-19 05:26:24 +02:00
|
|
|
if (icon) {
|
|
|
|
icon->show();
|
2008-08-11 20:15:37 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 05:26:24 +02:00
|
|
|
if (proxy) {
|
|
|
|
proxy->setWidget(0); // prevent it from deleting our widget!
|
|
|
|
delete proxy;
|
|
|
|
proxy = 0;
|
2008-07-17 11:30:57 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 05:26:24 +02:00
|
|
|
if (!dialog) {
|
|
|
|
dialog = new Plasma::Dialog();
|
2008-09-04 19:09:34 +02: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.
|
2008-09-19 05:26:24 +02:00
|
|
|
dialog->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
|
|
|
|
KWindowSystem::setState(dialog->winId(), NET::SkipTaskbar | NET::SkipPager);
|
|
|
|
dialog->installEventFilter(q);
|
2008-09-04 19:09:34 +02:00
|
|
|
|
2008-10-12 00:48:38 +02:00
|
|
|
QObject::connect(dialog, SIGNAL(dialogResized()),
|
|
|
|
q, SLOT(dialogSizeChanged()));
|
|
|
|
QObject::connect(dialog, SIGNAL(dialogVisible(bool)),
|
|
|
|
q, SLOT(dialogStatusChanged(bool)));
|
2008-09-19 05:26:24 +02:00
|
|
|
q->setMinimumSize(QSize(0, 0));
|
2008-09-07 22:49:10 +02:00
|
|
|
if (gWidget) {
|
|
|
|
Corona *corona = qobject_cast<Corona *>(gWidget->scene());
|
2008-08-06 22:41:10 +02:00
|
|
|
|
2008-10-20 12:58:37 +02:00
|
|
|
Extender *extender = qobject_cast<Extender*>(gWidget);
|
|
|
|
if (extender) {
|
|
|
|
if (q->location() == TopEdge) {
|
|
|
|
extender->setExtenderAppearance(Extender::TopDownStacked);
|
|
|
|
} else {
|
|
|
|
extender->setExtenderAppearance(Extender::BottomUpStacked);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-06 22:41:10 +02:00
|
|
|
//could that cast ever fail??
|
|
|
|
if (corona) {
|
2008-09-07 22:49:10 +02:00
|
|
|
corona->addOffscreenWidget(gWidget);
|
2008-09-19 05:26:24 +02:00
|
|
|
gWidget->resize(gWidget->preferredSize());
|
|
|
|
gWidget->setMinimumSize(gWidget->preferredSize());
|
|
|
|
dialog->setGraphicsWidget(gWidget);
|
2008-08-06 22:41:10 +02:00
|
|
|
}
|
2008-09-18 04:44:53 +02:00
|
|
|
} else if (qWidget) {
|
2008-09-19 05:26:24 +02:00
|
|
|
QVBoxLayout *l_layout = new QVBoxLayout(dialog);
|
2008-08-06 22:41:10 +02:00
|
|
|
l_layout->setSpacing(0);
|
|
|
|
l_layout->setMargin(0);
|
2008-09-18 04:44:53 +02:00
|
|
|
l_layout->addWidget(qWidget);
|
2008-07-28 01:23:57 +02:00
|
|
|
}
|
2008-07-17 11:30:57 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 05:26:24 +02:00
|
|
|
dialog->adjustSize();
|
2008-08-25 15:55:26 +02:00
|
|
|
|
2008-09-19 05:26:24 +02:00
|
|
|
if (icon && lay) {
|
|
|
|
lay->addItem(icon);
|
2008-09-12 20:32:01 +02:00
|
|
|
}
|
2008-07-17 11:30:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-12 20:32:01 +02:00
|
|
|
void PopupApplet::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
2008-09-18 06:11:03 +02:00
|
|
|
if (!d->icon && !d->popupLostFocus && event->buttons() == Qt::LeftButton) {
|
2008-09-12 20:32:01 +02:00
|
|
|
d->clicked = scenePos().toPoint();
|
|
|
|
event->setAccepted(true);
|
|
|
|
return;
|
|
|
|
} else {
|
2008-09-18 06:11:03 +02:00
|
|
|
d->popupLostFocus = false;
|
2008-09-12 20:32:01 +02:00
|
|
|
Applet::mousePressEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupApplet::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
2008-10-12 00:48:38 +02:00
|
|
|
if (!d->icon &&
|
|
|
|
(d->clicked - scenePos().toPoint()).manhattanLength() < KGlobalSettings::dndEventDelay()) {
|
2008-09-12 20:32:01 +02:00
|
|
|
d->togglePopup();
|
|
|
|
} else {
|
|
|
|
Applet::mouseReleaseEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-29 21:00:10 +02:00
|
|
|
bool PopupApplet::eventFilter(QObject *watched, QEvent *event)
|
|
|
|
{
|
2008-09-04 19:09:34 +02:00
|
|
|
if (watched == d->dialog && (event->type() == QEvent::WindowDeactivate)) {
|
2008-09-18 06:11:03 +02:00
|
|
|
d->popupLostFocus = true;
|
2008-09-04 19:09:34 +02:00
|
|
|
hidePopup();
|
2008-09-18 06:11:03 +02:00
|
|
|
QTimer::singleShot(100, this, SLOT(clearPopupLostFocus()));
|
2008-09-04 19:09:34 +02:00
|
|
|
}
|
|
|
|
|
2008-10-20 12:58:37 +02:00
|
|
|
/**
|
|
|
|
if (layout() && watched == graphicsWidget() && (event->type() == QEvent::GraphicsSceneResize)) {
|
2008-08-29 21:00:10 +02:00
|
|
|
//sizes are recalculated in the constraintsevent so let's just call that.
|
2008-10-07 18:15:33 +02:00
|
|
|
d->popupConstraintsEvent(Plasma::FormFactorConstraint);
|
2008-08-29 21:00:10 +02:00
|
|
|
|
|
|
|
//resize vertically if necesarry.
|
|
|
|
if (formFactor() == Plasma::MediaCenter || formFactor() == Plasma::Planar) {
|
|
|
|
resize(QSizeF(size().width(), minimumHeight()));
|
|
|
|
}
|
|
|
|
}
|
2008-10-07 18:15:33 +02:00
|
|
|
*/
|
|
|
|
|
2008-08-29 21:00:10 +02:00
|
|
|
return Applet::eventFilter(watched, event);
|
|
|
|
}
|
|
|
|
|
2008-07-28 01:23:57 +02:00
|
|
|
void PopupApplet::showPopup(uint popupDuration)
|
2008-07-17 11:30:57 +02:00
|
|
|
{
|
|
|
|
if (d->dialog && (formFactor() == Horizontal || formFactor() == Vertical)) {
|
2008-09-12 19:16:58 +02:00
|
|
|
d->updateDialogPosition();
|
2008-07-17 11:30:57 +02:00
|
|
|
d->dialog->show();
|
2008-09-04 19:09:34 +02:00
|
|
|
KWindowSystem::setState(d->dialog->winId(), NET::SkipTaskbar | NET::SkipPager);
|
2008-07-28 01:23:57 +02:00
|
|
|
|
|
|
|
if (d->timer) {
|
|
|
|
d->timer->stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (popupDuration > 0) {
|
|
|
|
if (!d->timer) {
|
|
|
|
d->timer = new QTimer(this);
|
|
|
|
connect(d->timer, SIGNAL(timeout()), this, SLOT(hideTimedPopup()));
|
|
|
|
}
|
|
|
|
|
|
|
|
d->timer->start(popupDuration);
|
|
|
|
}
|
2008-07-17 11:30:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupApplet::hidePopup()
|
|
|
|
{
|
|
|
|
if (d->dialog && (formFactor() == Horizontal || formFactor() == Vertical)) {
|
|
|
|
d->dialog->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-12 19:16:58 +02:00
|
|
|
Plasma::PopupPlacement PopupApplet::popupPlacement() const
|
|
|
|
{
|
|
|
|
return d->popupPlacement;
|
|
|
|
}
|
|
|
|
|
2008-08-28 20:30:50 +02:00
|
|
|
void PopupApplet::popupEvent(bool)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-09-19 05:26:24 +02:00
|
|
|
PopupAppletPrivate::PopupAppletPrivate(PopupApplet *applet)
|
|
|
|
: q(applet),
|
|
|
|
icon(0),
|
|
|
|
dialog(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;
|
|
|
|
}
|
|
|
|
|
2008-07-17 11:30:57 +02:00
|
|
|
void PopupAppletPrivate::togglePopup()
|
|
|
|
{
|
2008-09-07 22:49:10 +02:00
|
|
|
if (dialog) {
|
|
|
|
if (timer) {
|
|
|
|
timer->stop();
|
|
|
|
}
|
2008-09-02 16:54:58 +02:00
|
|
|
|
2008-09-07 22:49:10 +02:00
|
|
|
if (dialog->isVisible()) {
|
|
|
|
dialog->hide();
|
|
|
|
} else {
|
2008-09-12 19:16:58 +02:00
|
|
|
updateDialogPosition();
|
2008-09-07 22:49:10 +02:00
|
|
|
dialog->show();
|
|
|
|
KWindowSystem::setState(dialog->winId(), NET::SkipTaskbar | NET::SkipPager);
|
|
|
|
}
|
2008-09-02 16:54:58 +02:00
|
|
|
|
2008-09-07 22:49:10 +02:00
|
|
|
dialog->clearFocus();
|
2008-07-17 11:30:57 +02:00
|
|
|
}
|
2008-07-28 01:23:57 +02:00
|
|
|
}
|
2008-07-17 11:30:57 +02:00
|
|
|
|
2008-07-28 01:23:57 +02:00
|
|
|
void PopupAppletPrivate::hideTimedPopup()
|
|
|
|
{
|
|
|
|
timer->stop();
|
|
|
|
q->hidePopup();
|
2008-07-17 11:30:57 +02:00
|
|
|
}
|
|
|
|
|
2008-09-18 06:11:03 +02:00
|
|
|
void PopupAppletPrivate::clearPopupLostFocus()
|
|
|
|
{
|
|
|
|
popupLostFocus = false;
|
|
|
|
}
|
|
|
|
|
2008-08-28 16:32:48 +02:00
|
|
|
void PopupAppletPrivate::dialogSizeChanged()
|
|
|
|
{
|
2008-09-12 19:16:58 +02:00
|
|
|
//Reposition the dialog
|
2008-08-28 16:32:48 +02:00
|
|
|
if (dialog) {
|
|
|
|
dialog->updateGeometry();
|
|
|
|
dialog->move(q->popupPosition(dialog->size()));
|
2008-09-12 19:16:58 +02:00
|
|
|
|
2008-09-17 21:15:24 +02:00
|
|
|
KConfigGroup sizeGroup = q->config();
|
|
|
|
sizeGroup = KConfigGroup(&sizeGroup, "PopupApplet");
|
2008-09-12 19:16:58 +02:00
|
|
|
sizeGroup.writeEntry("DialogHeight", dialog->height());
|
|
|
|
sizeGroup.writeEntry("DialogWidth", dialog->width());
|
|
|
|
|
|
|
|
emit q->configNeedsSaving();
|
2008-08-28 16:32:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-01 12:45:33 +02:00
|
|
|
void PopupAppletPrivate::dialogStatusChanged(bool status)
|
|
|
|
{
|
|
|
|
q->popupEvent(status);
|
|
|
|
}
|
|
|
|
|
2008-09-12 19:16:58 +02:00
|
|
|
void PopupAppletPrivate::updateDialogPosition()
|
|
|
|
{
|
2008-10-20 18:42:37 +02:00
|
|
|
QGraphicsView *view = q->view();
|
|
|
|
|
|
|
|
if (!view) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-09-17 21:15:24 +02:00
|
|
|
KConfigGroup sizeGroup = q->config();
|
|
|
|
sizeGroup = KConfigGroup(&sizeGroup, "PopupApplet");
|
2008-10-12 00:48:38 +02:00
|
|
|
const int width = qMin(sizeGroup.readEntry("DialogWidth", 0),
|
|
|
|
QApplication::desktop()->screen()->width() - 50);
|
|
|
|
const int height = qMin(sizeGroup.readEntry("DialogHeight", 0),
|
|
|
|
QApplication::desktop()->screen()->height() - 50);
|
2008-09-12 19:16:58 +02:00
|
|
|
|
|
|
|
QSize saved(width, height);
|
|
|
|
|
|
|
|
if (saved.isNull()) {
|
|
|
|
dialog->adjustSize();
|
|
|
|
} else {
|
|
|
|
saved = saved.expandedTo(dialog->minimumSizeHint());
|
|
|
|
dialog->resize(saved);
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize s = dialog->size();
|
2008-10-20 18:42:37 +02:00
|
|
|
QPoint pos = view->mapFromScene(q->scenePos());
|
|
|
|
pos = view->mapToGlobal(pos);
|
2008-09-12 19:16:58 +02:00
|
|
|
|
|
|
|
switch (q->location()) {
|
|
|
|
case BottomEdge:
|
|
|
|
pos = QPoint(pos.x(), pos.y() - s.height());
|
|
|
|
popupPlacement = Plasma::TopPosedLeftAlignedPopup;
|
|
|
|
dialog->setResizeHandleCorners(Dialog::NorthEast);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case TopEdge:
|
|
|
|
pos = QPoint(pos.x(), pos.y() + (int)q->boundingRect().size().height());
|
|
|
|
popupPlacement = Plasma::BottomPosedLeftAlignedPopup;
|
|
|
|
dialog->setResizeHandleCorners(Dialog::SouthEast);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case LeftEdge:
|
|
|
|
pos = QPoint(pos.x() + (int)q->boundingRect().size().width(), pos.y());
|
|
|
|
popupPlacement = Plasma::RightPosedTopAlignedPopup;
|
|
|
|
dialog->setResizeHandleCorners(Dialog::SouthEast);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RightEdge:
|
|
|
|
pos = QPoint(pos.x() - s.width(), pos.y());
|
|
|
|
popupPlacement = Plasma::LeftPosedTopAlignedPopup;
|
|
|
|
dialog->setResizeHandleCorners(Dialog::SouthWest);
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (pos.y() - s.height() > 0) {
|
|
|
|
pos = QPoint(pos.x(), pos.y() - s.height());
|
|
|
|
} else {
|
|
|
|
pos = QPoint(pos.x(), pos.y() + (int)q->boundingRect().size().height());
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog->setResizeHandleCorners(Dialog::NorthEast);
|
|
|
|
}
|
|
|
|
//are we out of screen?
|
|
|
|
|
2008-10-12 00:48:38 +02:00
|
|
|
QRect screenRect =
|
|
|
|
QApplication::desktop()->screenGeometry(q->containment() ? q->containment()->screen() : -1);
|
|
|
|
//kDebug() << "==> rect for"
|
|
|
|
// << (containment() ? containment()->screen() : -1)
|
|
|
|
// << "is" << screenRect;
|
2008-09-12 19:16:58 +02:00
|
|
|
|
|
|
|
if (pos.rx() + s.width() > screenRect.right()) {
|
|
|
|
pos.rx() += (int)q->boundingRect().size().width() - s.width();
|
|
|
|
|
|
|
|
if (q->location() == BottomEdge) {
|
|
|
|
popupPlacement = Plasma::TopPosedRightAlignedPopup;
|
|
|
|
dialog->setResizeHandleCorners(Dialog::NorthWest);
|
|
|
|
} else if (q->location() == TopEdge) {
|
|
|
|
popupPlacement = Plasma::BottomPosedRightAlignedPopup;
|
|
|
|
dialog->setResizeHandleCorners(Dialog::SouthWest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos.ry() + s.height() > screenRect.bottom()) {
|
|
|
|
pos.ry() += (int)q->boundingRect().size().height() - s.height();
|
|
|
|
|
|
|
|
if (q->location() == LeftEdge) {
|
|
|
|
popupPlacement = Plasma::RightPosedBottomAlignedPopup;
|
|
|
|
dialog->setResizeHandleCorners(Dialog::NorthEast);
|
|
|
|
} else if (q->location() == RightEdge) {
|
|
|
|
popupPlacement = Plasma::LeftPosedBottomAlignedPopup;
|
|
|
|
dialog->setResizeHandleCorners(Dialog::NorthWest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pos.rx() = qMax(0, pos.rx());
|
|
|
|
|
|
|
|
dialog->move(pos);
|
|
|
|
}
|
2008-07-17 11:30:57 +02:00
|
|
|
} // Plasma namespace
|
|
|
|
|
|
|
|
#include "popupapplet.moc"
|
|
|
|
|