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"
|
|
|
|
|
|
|
|
#include <QGraphicsProxyWidget>
|
|
|
|
#include <QGraphicsLinearLayout>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QApplication>
|
|
|
|
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kicon.h>
|
|
|
|
#include <kiconloader.h>
|
|
|
|
#include <kwindowsystem.h>
|
|
|
|
#include <kglobalsettings.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"
|
2008-12-30 03:07:57 +01:00
|
|
|
#include "plasma/dialog.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "plasma/extender.h"
|
2009-02-09 19:10:45 +01:00
|
|
|
#include "plasma/extenderitem.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))
|
|
|
|
{
|
|
|
|
int iconSize = IconSize(KIconLoader::Desktop);
|
|
|
|
resize(iconSize, iconSize);
|
2008-12-30 03:06:06 +01:00
|
|
|
connect(this, SIGNAL(activate()), this, SLOT(internalTogglePopup()));
|
2009-02-09 19:10:45 +01:00
|
|
|
setAcceptDrops(true);
|
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);
|
|
|
|
|
|
|
|
if (formFactor() == Plasma::Vertical || formFactor() == Plasma::Horizontal ) {
|
|
|
|
d->savedAspectRatio = aspectRatioMode();
|
|
|
|
setAspectRatioMode(Plasma::ConstrainedSquare);
|
|
|
|
}
|
|
|
|
|
|
|
|
setLayout(layout);
|
|
|
|
} else {
|
|
|
|
d->icon->setIcon(icon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupApplet::setPopupIcon(const QString &iconName)
|
|
|
|
{
|
|
|
|
setPopupIcon(KIcon(iconName));
|
|
|
|
}
|
|
|
|
|
|
|
|
QIcon PopupApplet::popupIcon() const
|
|
|
|
{
|
|
|
|
return d->icon ? d->icon->icon() : QIcon();
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *PopupApplet::widget()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsWidget *PopupApplet::graphicsWidget()
|
|
|
|
{
|
|
|
|
return static_cast<Applet*>(this)->d->extender;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-12-09 20:07:21 +01:00
|
|
|
if (dialog) {
|
|
|
|
dialog->setGraphicsWidget(extender);
|
|
|
|
}
|
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());
|
|
|
|
|
|
|
|
if (icon && !icon->icon().isNull() && lay) {
|
|
|
|
lay->removeAt(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF minimum;
|
|
|
|
QSizeF containmentSize;
|
|
|
|
|
|
|
|
QGraphicsWidget *gWidget = q->graphicsWidget();
|
2008-12-12 16:03:18 +01: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();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (q->containment()) {
|
|
|
|
containmentSize = q->containment()->size();
|
|
|
|
}
|
|
|
|
|
2008-11-23 18:55:40 +01:00
|
|
|
//Applet on desktop
|
2008-11-04 00:08:39 +01:00
|
|
|
if (icon && !icon->icon().isNull() && ((f != Plasma::Vertical && f != Plasma::Horizontal) ||
|
|
|
|
((f == Plasma::Vertical && containmentSize.width() >= minimum.width()) ||
|
|
|
|
(f == Plasma::Horizontal && containmentSize.height() >= minimum.height())))) {
|
2008-12-12 16:03:18 +01:00
|
|
|
kDebug() << "we are expanding the popupapplet";
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dialog) {
|
|
|
|
if (dialog->layout() && qWidget) {
|
|
|
|
//we don't want to delete Widget inside the dialog layout
|
|
|
|
dialog->layout()->removeWidget(qWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (qWidget) {
|
|
|
|
qWidget->setParent(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete dialog;
|
|
|
|
dialog = 0;
|
|
|
|
}
|
|
|
|
|
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) {
|
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);
|
|
|
|
proxy->setWidget(qWidget);
|
|
|
|
proxy->show();
|
|
|
|
}
|
|
|
|
|
2009-01-06 19:08:58 +01:00
|
|
|
lay->addItem(proxy);
|
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());
|
2008-11-04 00:08:39 +01:00
|
|
|
q->setMinimumSize(minimum + QSizeF(left+right, top+bottom));
|
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 {
|
2008-12-12 16:03:18 +01:00
|
|
|
kDebug() << "about to switch to a popup";
|
2008-11-04 00:08:39 +01:00
|
|
|
//save the aspect ratio mode in case we drag'n drop in the Desktop later
|
|
|
|
savedAspectRatio = q->aspectRatioMode();
|
|
|
|
|
|
|
|
if (icon) {
|
|
|
|
icon->show();
|
2008-12-22 21:32:37 +01:00
|
|
|
q->setAspectRatioMode(Plasma::ConstrainedSquare);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (proxy) {
|
|
|
|
proxy->setWidget(0); // prevent it from deleting our widget!
|
|
|
|
delete proxy;
|
|
|
|
proxy = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dialog) {
|
|
|
|
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.
|
2008-11-27 07:03:53 +01:00
|
|
|
Qt::WindowFlags wflags = Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint;
|
|
|
|
|
|
|
|
if (passive) {
|
|
|
|
wflags |= Qt::X11BypassWindowManagerHint;
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog->setWindowFlags(wflags);
|
2008-11-04 00:08:39 +01:00
|
|
|
KWindowSystem::setState(dialog->winId(), NET::SkipTaskbar | NET::SkipPager);
|
|
|
|
dialog->installEventFilter(q);
|
|
|
|
|
|
|
|
q->setMinimumSize(QSize(0, 0));
|
|
|
|
if (gWidget) {
|
|
|
|
Corona *corona = qobject_cast<Corona *>(gWidget->scene());
|
|
|
|
|
|
|
|
//could that cast ever fail??
|
|
|
|
if (corona) {
|
|
|
|
corona->addOffscreenWidget(gWidget);
|
|
|
|
dialog->setGraphicsWidget(gWidget);
|
2009-03-04 16:47:59 +01:00
|
|
|
gWidget->resize(gWidget->preferredSize());
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
} else if (qWidget) {
|
|
|
|
QVBoxLayout *l_layout = new QVBoxLayout(dialog);
|
|
|
|
l_layout->setSpacing(0);
|
|
|
|
l_layout->setMargin(0);
|
|
|
|
l_layout->addWidget(qWidget);
|
2008-12-28 13:54:48 +01:00
|
|
|
dialog->adjustSize();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2008-12-30 03:11:10 +01:00
|
|
|
|
2008-12-28 13:54:48 +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);
|
|
|
|
}
|
|
|
|
|
|
|
|
q->setMinimumSize(0,0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (watched == d->dialog && (event->type() == QEvent::WindowDeactivate)) {
|
|
|
|
d->popupLostFocus = true;
|
|
|
|
hidePopup();
|
|
|
|
QTimer::singleShot(100, this, SLOT(clearPopupLostFocus()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
if (layout() && watched == graphicsWidget() && (event->type() == QEvent::GraphicsSceneResize)) {
|
|
|
|
//sizes are recalculated in the constraintsevent so let's just call that.
|
|
|
|
d->popupConstraintsEvent(Plasma::FormFactorConstraint);
|
|
|
|
|
|
|
|
//resize vertically if necesarry.
|
|
|
|
if (formFactor() == Plasma::MediaCenter || formFactor() == Plasma::Planar) {
|
|
|
|
resize(QSizeF(size().width(), minimumHeight()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
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.
|
|
|
|
if (d->dialog && !d->dialog->geometry().contains(event->screenPos()) &&
|
|
|
|
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)
|
|
|
|
{
|
2008-12-30 06:35:18 +01:00
|
|
|
if (d->dialog) {
|
2008-12-17 20:56:25 +01:00
|
|
|
// 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
|
2008-12-30 06:35:18 +01:00
|
|
|
if (!d->dialog->isVisible()) {
|
|
|
|
d->internalTogglePopup();
|
|
|
|
}
|
2008-11-04 00:08:39 +01: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupApplet::hidePopup()
|
|
|
|
{
|
2008-11-25 16:26:13 +01:00
|
|
|
if (d->dialog) {
|
2008-11-04 00:08:39 +01:00
|
|
|
d->dialog->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupApplet::popupEvent(bool)
|
|
|
|
{
|
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:03:53 +01:00
|
|
|
if (d->dialog) {
|
|
|
|
Qt::WindowFlags wflags = Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint;
|
|
|
|
|
|
|
|
if (d->passive) {
|
|
|
|
wflags |= Qt::X11BypassWindowManagerHint;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->dialog->setWindowFlags(wflags);
|
|
|
|
}
|
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-01-26 04:15:50 +01:00
|
|
|
return d->dialog && d->dialog->isVisible();
|
2008-12-29 07:03:43 +01:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
PopupAppletPrivate::PopupAppletPrivate(PopupApplet *applet)
|
|
|
|
: q(applet),
|
|
|
|
icon(0),
|
|
|
|
dialog(0),
|
|
|
|
proxy(0),
|
|
|
|
popupPlacement(Plasma::FloatingPopup),
|
|
|
|
savedAspectRatio(Plasma::InvalidAspectRatioMode),
|
|
|
|
timer(0),
|
2008-11-27 07:03:53 +01:00
|
|
|
popupLostFocus(false),
|
|
|
|
passive(false)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PopupAppletPrivate::~PopupAppletPrivate()
|
|
|
|
{
|
|
|
|
if (proxy) {
|
|
|
|
proxy->setWidget(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete dialog;
|
|
|
|
delete icon;
|
|
|
|
}
|
|
|
|
|
2008-12-30 03:06:06 +01:00
|
|
|
void PopupAppletPrivate::internalTogglePopup()
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2008-12-30 06:35:18 +01:00
|
|
|
if (!dialog) {
|
|
|
|
return;
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-12-30 06:35:18 +01:00
|
|
|
if (timer) {
|
|
|
|
timer->stop();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-12-30 06:35:18 +01:00
|
|
|
if (dialog->isVisible()) {
|
|
|
|
dialog->hide();
|
|
|
|
} else {
|
|
|
|
ToolTipManager::self()->hide(q);
|
|
|
|
updateDialogPosition();
|
|
|
|
KWindowSystem::setState(dialog->winId(), NET::SkipTaskbar | NET::SkipPager);
|
|
|
|
dialog->show();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2008-12-30 06:35:18 +01:00
|
|
|
|
|
|
|
dialog->clearFocus();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PopupAppletPrivate::hideTimedPopup()
|
|
|
|
{
|
|
|
|
timer->stop();
|
|
|
|
q->hidePopup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupAppletPrivate::clearPopupLostFocus()
|
|
|
|
{
|
|
|
|
popupLostFocus = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupAppletPrivate::dialogSizeChanged()
|
|
|
|
{
|
|
|
|
//Reposition the dialog
|
|
|
|
if (dialog) {
|
|
|
|
KConfigGroup sizeGroup = q->config();
|
|
|
|
sizeGroup = KConfigGroup(&sizeGroup, "PopupApplet");
|
|
|
|
sizeGroup.writeEntry("DialogHeight", dialog->height());
|
|
|
|
sizeGroup.writeEntry("DialogWidth", dialog->width());
|
|
|
|
|
2008-12-07 21:20:28 +01:00
|
|
|
updateDialogPosition();
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
emit q->configNeedsSaving();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupAppletPrivate::dialogStatusChanged(bool status)
|
|
|
|
{
|
|
|
|
q->popupEvent(status);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupAppletPrivate::updateDialogPosition()
|
|
|
|
{
|
|
|
|
QGraphicsView *view = q->view();
|
|
|
|
|
|
|
|
if (!view) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
KConfigGroup sizeGroup = q->config();
|
|
|
|
sizeGroup = KConfigGroup(&sizeGroup, "PopupApplet");
|
2008-12-05 00:57:47 +01:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
Q_ASSERT(q->containment());
|
|
|
|
Q_ASSERT(q->containment()->corona());
|
2008-12-28 13:54:48 +01:00
|
|
|
|
|
|
|
int preferredWidth = 0;
|
|
|
|
int preferredHeight = 0;
|
|
|
|
if (dialog->graphicsWidget()) {
|
|
|
|
preferredWidth = dialog->graphicsWidget()->preferredSize().width();
|
|
|
|
preferredHeight = dialog->graphicsWidget()->preferredSize().height();
|
|
|
|
}
|
|
|
|
|
|
|
|
const int width = qMin(sizeGroup.readEntry("DialogWidth", preferredWidth),
|
2008-11-04 00:08:39 +01:00
|
|
|
q->containment()->corona()->screenGeometry(-1).width() - 50);
|
2008-12-28 13:54:48 +01:00
|
|
|
const int height = qMin(sizeGroup.readEntry("DialogHeight", preferredHeight),
|
2008-11-04 00:08:39 +01:00
|
|
|
q->containment()->corona()->screenGeometry(-1).height() - 50);
|
|
|
|
|
|
|
|
QSize saved(width, height);
|
|
|
|
|
|
|
|
if (saved.isNull()) {
|
2009-01-23 08:33:30 +01:00
|
|
|
saved = dialog->sizeHint();
|
2008-11-04 00:08:39 +01:00
|
|
|
} else {
|
|
|
|
saved = saved.expandedTo(dialog->minimumSizeHint());
|
2009-01-23 08:33:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (saved.width() != dialog->width() || saved.height() != dialog->height()) {
|
2008-11-04 00:08:39 +01:00
|
|
|
dialog->resize(saved);
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize s = dialog->size();
|
|
|
|
QPoint pos = view->mapFromScene(q->scenePos());
|
2009-01-23 08:33:30 +01:00
|
|
|
|
2008-12-12 21:07:51 +01:00
|
|
|
//try to access a corona
|
2009-01-23 08:33:30 +01:00
|
|
|
Corona *corona = qobject_cast<Corona *>(q->scene());
|
|
|
|
if (corona) {
|
|
|
|
pos = corona->popupPosition(q, s);
|
2008-12-12 21:07:51 +01: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) {
|
|
|
|
if (view->mapToGlobal(view->mapFromScene(q->scenePos())).y() + q->size().height()/2 < pos.y() + dialog->size().width()/2) {
|
|
|
|
reverse = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (view->mapToGlobal(view->mapFromScene(q->scenePos())).x() + q->size().width()/2 < pos.x() + dialog->size().width()/2) {
|
|
|
|
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()) {
|
|
|
|
dialog->setResizeHandleCorners(Dialog::NorthEast);
|
2008-11-04 00:08:39 +01:00
|
|
|
} else {
|
|
|
|
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()) {
|
|
|
|
dialog->setResizeHandleCorners(Dialog::SouthEast);
|
|
|
|
} else {
|
2008-11-04 00:08:39 +01:00
|
|
|
dialog->setResizeHandleCorners(Dialog::SouthWest);
|
|
|
|
}
|
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()) {
|
|
|
|
dialog->setResizeHandleCorners(Dialog::SouthEast);
|
|
|
|
} else {
|
2008-11-04 00:08:39 +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()) {
|
|
|
|
dialog->setResizeHandleCorners(Dialog::SouthWest);
|
|
|
|
} else {
|
2008-11-04 00:08:39 +01:00
|
|
|
dialog->setResizeHandleCorners(Dialog::NorthWest);
|
|
|
|
}
|
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:
|
|
|
|
dialog->setResizeHandleCorners(Dialog::NorthEast);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
dialog->move(pos);
|
|
|
|
}
|
|
|
|
} // Plasma namespace
|
|
|
|
|
|
|
|
#include "popupapplet.moc"
|
|
|
|
|