2008-11-04 00:08:39 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2007 Matt Broadstone <mbroadst@gmail.com>
|
2011-01-11 21:45:24 +01:00
|
|
|
* Copyright 2007-2011 Aaron Seigo <aseigo@kde.org>
|
2008-11-04 00:08:39 +01:00
|
|
|
* Copyright 2007 Riccardo Iaconelli <riccardo@kde.org>
|
2009-08-18 00:31:18 +02:00
|
|
|
* Copyright (c) 2009 Chani Armitage <chani@kde.org>
|
2008-11-04 00:08:39 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "corona.h"
|
2012-02-28 20:00:42 +01:00
|
|
|
#include "graphicsview/private/corona_p.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
#include <QApplication>
|
2010-06-11 19:20:29 +02:00
|
|
|
#include <QDesktopWidget>
|
2008-11-04 00:08:39 +01:00
|
|
|
#include <QGraphicsView>
|
|
|
|
#include <QGraphicsGridLayout>
|
|
|
|
#include <QMimeData>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QTimer>
|
|
|
|
|
2008-12-12 15:41:15 +01:00
|
|
|
#include <cmath>
|
|
|
|
|
2010-11-18 18:17:56 +01:00
|
|
|
#include <kaction.h>
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kdebug.h>
|
|
|
|
#include <kglobal.h>
|
2012-03-18 17:45:41 +01:00
|
|
|
#include <klocalizedstring.h>
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kmimetype.h>
|
2009-05-03 22:22:14 +02:00
|
|
|
#include <kshortcutsdialog.h>
|
2010-11-18 18:17:56 +01:00
|
|
|
#include <kwindowsystem.h>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2012-02-28 20:24:41 +01:00
|
|
|
#include "coronabase.h"
|
2011-07-19 22:04:22 +02:00
|
|
|
#include "abstractdialogmanager.h"
|
2010-01-04 07:37:41 +01:00
|
|
|
#include "abstracttoolbox.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "containment.h"
|
2009-10-05 22:50:57 +02:00
|
|
|
#include "containmentactionspluginsconfig.h"
|
2011-07-19 22:04:22 +02:00
|
|
|
#include "pluginloader.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "private/applet_p.h"
|
2009-05-03 22:22:14 +02:00
|
|
|
#include "private/containment_p.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "tooltipmanager.h"
|
2011-07-19 22:04:22 +02:00
|
|
|
#include "view.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
using namespace Plasma;
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2010-02-24 15:24:52 +01:00
|
|
|
bool CoronaPrivate::s_positioningContainments = false;
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
Corona::Corona(QObject *parent)
|
|
|
|
: QGraphicsScene(parent),
|
|
|
|
d(new CoronaPrivate(this))
|
|
|
|
{
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2010-01-31 20:45:48 +01:00
|
|
|
kDebug() << "!!{} STARTUP TIME" << QTime().msecsTo(QTime::currentTime()) << "Corona ctor start";
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2012-02-28 20:24:41 +01:00
|
|
|
d->coronaBase = new CoronaBase(this);
|
2008-11-04 00:08:39 +01:00
|
|
|
d->init();
|
|
|
|
//setViewport(new QGLWidget(QGLFormat(QGL::StencilBuffer | QGL::AlphaChannel)));
|
|
|
|
}
|
|
|
|
|
|
|
|
Corona::~Corona()
|
|
|
|
{
|
2012-03-24 19:33:54 +01:00
|
|
|
KConfigGroup trans(KSharedConfig::openConfig(), "PlasmaTransientsConfig");
|
2009-01-22 01:00:16 +01:00
|
|
|
trans.deleteGroup();
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
// FIXME: Same fix as in Plasma::View - make sure that when the focused widget is
|
|
|
|
// destroyed we don't try to transfer it to something that's already been
|
|
|
|
// deleted.
|
|
|
|
clearFocus();
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Corona::setAppletMimeType(const QString &type)
|
|
|
|
{
|
2012-02-28 20:24:41 +01:00
|
|
|
d->coronaBase->setAppletMimeType(type);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Corona::appletMimeType()
|
|
|
|
{
|
2012-02-28 20:24:41 +01:00
|
|
|
return d->coronaBase->appletMimeType();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2011-01-12 01:05:13 +01:00
|
|
|
void Corona::setDefaultContainmentPlugin(const QString &name)
|
|
|
|
{
|
2012-02-28 20:24:41 +01:00
|
|
|
d->coronaBase->setDefaultContainmentPlugin(name);
|
2011-01-12 01:05:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Corona::defaultContainmentPlugin() const
|
|
|
|
{
|
2012-02-28 20:24:41 +01:00
|
|
|
return d->coronaBase->defaultContainmentPlugin();
|
2011-01-12 01:05:13 +01:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void Corona::saveLayout(const QString &configName) const
|
|
|
|
{
|
2012-02-28 20:24:41 +01:00
|
|
|
d->coronaBase->saveLayout(configName);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2010-09-27 20:16:43 +02:00
|
|
|
void Corona::exportLayout(KConfigGroup &config, QList<Containment*> containments)
|
|
|
|
{
|
2012-02-28 20:40:28 +01:00
|
|
|
d->coronaBase->exportLayout(config, containments);
|
2010-09-27 20:16:43 +02:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void Corona::requestConfigSync()
|
|
|
|
{
|
2012-02-28 20:40:28 +01:00
|
|
|
d->coronaBase->requestConfigSync();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2008-12-18 23:12:49 +01:00
|
|
|
void Corona::requireConfigSync()
|
|
|
|
{
|
2012-02-28 20:40:28 +01:00
|
|
|
d->coronaBase->requestConfigSync();
|
2008-12-18 23:12:49 +01:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void Corona::initializeLayout(const QString &configName)
|
|
|
|
{
|
2012-02-28 20:40:28 +01:00
|
|
|
d->coronaBase->initializeLayout();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2010-02-24 15:24:52 +01:00
|
|
|
bool containmentSortByPosition(const Containment *c1, const Containment *c2)
|
|
|
|
{
|
|
|
|
return c1->id() < c2->id();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Corona::layoutContainments()
|
|
|
|
{
|
|
|
|
if (CoronaPrivate::s_positioningContainments) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CoronaPrivate::s_positioningContainments = true;
|
|
|
|
|
|
|
|
//TODO: we should avoid running this too often; consider compressing requests
|
|
|
|
// with a timer.
|
|
|
|
QList<Containment*> c = containments();
|
|
|
|
QMutableListIterator<Containment*> it(c);
|
|
|
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
Containment *containment = it.next();
|
|
|
|
if (containment->containmentType() == Containment::PanelContainment ||
|
|
|
|
containment->containmentType() == Containment::CustomPanelContainment ||
|
|
|
|
offscreenWidgets().contains(containment)) {
|
|
|
|
// weed out all containments we don't care about at all
|
|
|
|
// e.g. Panels and ourself
|
|
|
|
it.remove();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
qSort(c.begin(), c.end(), containmentSortByPosition);
|
|
|
|
|
|
|
|
if (c.isEmpty()) {
|
|
|
|
CoronaPrivate::s_positioningContainments = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int column = 0;
|
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
|
|
|
int rowHeight = 0;
|
|
|
|
|
|
|
|
it.toFront();
|
|
|
|
while (it.hasNext()) {
|
|
|
|
Containment *containment = it.next();
|
|
|
|
containment->setPos(x, y);
|
|
|
|
//kDebug() << ++count << "setting to" << x << y;
|
|
|
|
|
|
|
|
int height = containment->size().height();
|
|
|
|
if (height > rowHeight) {
|
|
|
|
rowHeight = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
++column;
|
|
|
|
|
|
|
|
if (column == CONTAINMENT_COLUMNS) {
|
|
|
|
column = 0;
|
|
|
|
x = 0;
|
|
|
|
y += rowHeight + INTER_CONTAINMENT_MARGIN + TOOLBOX_MARGIN;
|
|
|
|
rowHeight = 0;
|
|
|
|
} else {
|
|
|
|
x += containment->size().width() + INTER_CONTAINMENT_MARGIN;
|
|
|
|
}
|
|
|
|
//kDebug() << "column: " << column << "; x " << x << "; y" << y << "; width was"
|
|
|
|
// << containment->size().width();
|
|
|
|
}
|
|
|
|
|
|
|
|
CoronaPrivate::s_positioningContainments = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void Corona::loadLayout(const QString &configName)
|
|
|
|
{
|
2012-02-28 20:24:41 +01:00
|
|
|
d->coronaBase->loadLayout();
|
2010-05-14 19:00:54 +02:00
|
|
|
}
|
2009-10-11 19:06:26 +02:00
|
|
|
|
2010-09-27 20:16:43 +02:00
|
|
|
QList<Plasma::Containment *> Corona::importLayout(const KConfigGroup &conf)
|
|
|
|
{
|
2012-02-28 20:24:41 +01:00
|
|
|
return d->coronaBase->importLayout(conf);
|
2010-09-27 20:16:43 +02:00
|
|
|
}
|
|
|
|
|
2008-11-17 05:34:55 +01:00
|
|
|
Containment *Corona::containmentForScreen(int screen, int desktop) const
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2012-02-28 20:40:28 +01:00
|
|
|
return d->coronaBase->containmentForScreen(screen, desktop);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2010-11-18 18:17:56 +01:00
|
|
|
Containment *Corona::containmentForScreen(int screen, int desktop,
|
|
|
|
const QString &defaultPluginIfNonExistent, const QVariantList &defaultArgs)
|
|
|
|
{
|
2012-02-28 20:24:41 +01:00
|
|
|
return d->coronaBase->containmentForScreen(screen, desktop, defaultPluginIfNonExistent, defaultArgs);
|
2010-11-18 18:17:56 +01:00
|
|
|
}
|
2011-01-11 21:45:24 +01:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
QList<Containment*> Corona::containments() const
|
|
|
|
{
|
2012-02-28 20:40:28 +01:00
|
|
|
return d->coronaBase->containments();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Corona::clearContainments()
|
|
|
|
{
|
2012-02-28 20:40:28 +01:00
|
|
|
d->coronaBase->clearContainments();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
KSharedConfigPtr Corona::config() const
|
|
|
|
{
|
2012-02-28 20:40:28 +01:00
|
|
|
return d->coronaBase->config();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Containment *Corona::addContainment(const QString &name, const QVariantList &args)
|
|
|
|
{
|
2012-02-28 20:24:41 +01:00
|
|
|
Plasma::Containment *containment = d->coronaBase->addContainment(name, args);
|
|
|
|
addItem(containment);
|
|
|
|
return containment;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Containment *Corona::addContainmentDelayed(const QString &name, const QVariantList &args)
|
|
|
|
{
|
2012-02-28 20:24:41 +01:00
|
|
|
Plasma::Containment *containment = d->coronaBase->addContainmentDelayed(name, args);
|
|
|
|
addItem(containment);
|
|
|
|
return containment;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Corona::addOffscreenWidget(QGraphicsWidget *widget)
|
|
|
|
{
|
2009-11-05 02:12:22 +01:00
|
|
|
foreach (QGraphicsWidget *w, d->offscreenWidgets) {
|
|
|
|
if (w == widget) {
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2009-11-05 02:12:22 +01:00
|
|
|
kDebug() << "widget is already an offscreen widget!";
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2009-11-05 02:12:22 +01:00
|
|
|
return;
|
|
|
|
}
|
2009-08-31 21:06:06 +02:00
|
|
|
}
|
|
|
|
|
2008-12-10 01:57:42 +01:00
|
|
|
//search for an empty spot in the topleft quadrant of the scene. each 'slot' is QWIDGETSIZE_MAX
|
|
|
|
//x QWIDGETSIZE_MAX, so we're guaranteed to never have to move widgets once they're placed here.
|
|
|
|
int i = 0;
|
|
|
|
while (d->offscreenWidgets.contains(i)) {
|
|
|
|
i++;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2008-12-10 01:57:42 +01:00
|
|
|
d->offscreenWidgets[i] = widget;
|
|
|
|
widget->setPos((-i - 1) * QWIDGETSIZE_MAX, -QWIDGETSIZE_MAX);
|
2009-11-05 02:12:22 +01:00
|
|
|
|
|
|
|
QGraphicsWidget *pw = widget->parentWidget();
|
|
|
|
widget->setParentItem(0);
|
2011-04-30 10:10:42 +02:00
|
|
|
if (pw) {
|
|
|
|
widget->setParent(pw);
|
|
|
|
}
|
2009-11-05 02:12:22 +01:00
|
|
|
|
|
|
|
//kDebug() << "adding offscreen widget at slot " << i;
|
|
|
|
if (!widget->scene()) {
|
|
|
|
addItem(widget);
|
|
|
|
}
|
2008-12-10 01:57:42 +01:00
|
|
|
|
2008-11-06 19:21:10 +01:00
|
|
|
connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(offscreenWidgetDestroyed(QObject*)));
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2008-12-10 01:57:42 +01:00
|
|
|
void Corona::removeOffscreenWidget(QGraphicsWidget *widget)
|
2008-11-06 19:21:10 +01:00
|
|
|
{
|
2008-12-10 01:57:42 +01:00
|
|
|
QMutableHashIterator<uint, QGraphicsWidget *> it(d->offscreenWidgets);
|
2008-11-06 19:21:10 +01:00
|
|
|
|
2008-12-10 01:57:42 +01:00
|
|
|
while (it.hasNext()) {
|
|
|
|
if (it.next().value() == widget) {
|
|
|
|
it.remove();
|
|
|
|
return;
|
2008-11-06 19:21:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-07 23:22:18 +02:00
|
|
|
QList <QGraphicsWidget *> Corona::offscreenWidgets() const
|
|
|
|
{
|
|
|
|
return d->offscreenWidgets.values();
|
|
|
|
}
|
|
|
|
|
2008-12-10 01:57:42 +01:00
|
|
|
void CoronaPrivate::offscreenWidgetDestroyed(QObject *o)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2008-12-10 01:57:42 +01:00
|
|
|
// at this point, it's just a QObject, not a QGraphicsWidget, but we still need
|
|
|
|
// a pointer of the appropriate type.
|
|
|
|
// WARNING: DO NOT USE THE WIDGET POINTER FOR ANYTHING OTHER THAN POINTER COMPARISONS
|
|
|
|
QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(o);
|
|
|
|
q->removeOffscreenWidget(widget);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int Corona::numScreens() const
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect Corona::screenGeometry(int id) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(id);
|
2011-01-28 23:30:54 +01:00
|
|
|
QGraphicsView *v = views().value(0);
|
|
|
|
if (v) {
|
2008-11-04 00:08:39 +01:00
|
|
|
QRect r = sceneRect().toRect();
|
2010-07-28 18:57:41 +02:00
|
|
|
r.moveTo(v->mapToGlobal(QPoint(0, 0)));
|
2008-11-04 00:08:39 +01:00
|
|
|
return r;
|
|
|
|
}
|
2011-01-28 23:30:54 +01:00
|
|
|
|
|
|
|
return sceneRect().toRect();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QRegion Corona::availableScreenRegion(int id) const
|
|
|
|
{
|
|
|
|
return QRegion(screenGeometry(id));
|
|
|
|
}
|
|
|
|
|
2009-09-28 19:28:17 +02:00
|
|
|
QPoint Corona::popupPosition(const QGraphicsItem *item, const QSize &s, Qt::AlignmentFlag alignment)
|
|
|
|
{
|
2011-04-20 18:07:06 +02:00
|
|
|
const QGraphicsItem *actualItem = item;
|
2010-12-23 00:37:56 +01:00
|
|
|
const QGraphicsView *v = viewFor(item);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
if (!v) {
|
|
|
|
return QPoint(0, 0);
|
|
|
|
}
|
|
|
|
|
2011-04-20 18:07:06 +02:00
|
|
|
//its own view could be hidden, for instance if item is in an hidden Dialog
|
|
|
|
//try to position it using the parent applet as the item
|
|
|
|
if (!v->isVisible()) {
|
|
|
|
actualItem = item->parentItem();
|
|
|
|
if (!actualItem) {
|
|
|
|
const QGraphicsWidget *widget = qgraphicsitem_cast<const QGraphicsWidget*>(item);
|
|
|
|
if (widget) {
|
|
|
|
actualItem = qobject_cast<QGraphicsItem*>(widget->parent());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2011-04-20 18:07:06 +02:00
|
|
|
kDebug() << actualItem;
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2011-04-20 18:07:06 +02:00
|
|
|
|
2011-05-27 15:51:20 +02:00
|
|
|
if (actualItem) {
|
2011-05-28 00:21:59 +02:00
|
|
|
v = viewFor(actualItem);
|
|
|
|
if (!v) {
|
|
|
|
return QPoint(0, 0);
|
2011-05-27 15:51:20 +02:00
|
|
|
}
|
2011-04-20 18:07:06 +02:00
|
|
|
}
|
|
|
|
}
|
2011-05-27 15:51:20 +02:00
|
|
|
|
2011-04-20 18:10:02 +02:00
|
|
|
if (!actualItem) {
|
|
|
|
actualItem = item;
|
|
|
|
}
|
2011-04-20 18:07:06 +02:00
|
|
|
|
2008-12-12 15:41:15 +01:00
|
|
|
QPoint pos;
|
2011-04-20 18:07:06 +02:00
|
|
|
QTransform sceneTransform = actualItem->sceneTransform();
|
2008-12-12 15:41:15 +01:00
|
|
|
|
2009-09-28 19:28:17 +02:00
|
|
|
//swap direction if necessary
|
|
|
|
if (QApplication::isRightToLeft() && alignment != Qt::AlignCenter) {
|
|
|
|
if (alignment == Qt::AlignRight) {
|
2009-10-05 20:26:25 +02:00
|
|
|
alignment = Qt::AlignLeft;
|
2009-09-28 19:28:17 +02:00
|
|
|
} else {
|
2009-10-05 20:26:25 +02:00
|
|
|
alignment = Qt::AlignRight;
|
2009-09-28 19:28:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-12 15:41:15 +01:00
|
|
|
//if the applet is rotated the popup position has to be un-transformed
|
|
|
|
if (sceneTransform.isRotating()) {
|
|
|
|
qreal angle = acos(sceneTransform.m11());
|
|
|
|
QTransform newTransform;
|
2011-04-20 18:07:06 +02:00
|
|
|
QPointF center = actualItem->sceneBoundingRect().center();
|
2008-12-12 15:41:15 +01:00
|
|
|
|
|
|
|
newTransform.translate(center.x(), center.y());
|
|
|
|
newTransform.rotateRadians(-angle);
|
|
|
|
newTransform.translate(-center.x(), -center.y());
|
2011-04-20 18:07:06 +02:00
|
|
|
pos = v->mapFromScene(newTransform.inverted().map(actualItem->scenePos()));
|
2008-12-12 15:41:15 +01:00
|
|
|
} else {
|
2011-04-20 18:07:06 +02:00
|
|
|
pos = v->mapFromScene(actualItem->scenePos());
|
2008-12-12 15:41:15 +01:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
pos = v->mapToGlobal(pos);
|
2011-04-20 18:07:06 +02:00
|
|
|
//kDebug() << "==> position is" << actualItem->scenePos() << v->mapFromScene(actualItem->scenePos()) << pos;
|
2011-07-28 18:13:33 +02:00
|
|
|
const Plasma::View *pv = qobject_cast<const Plasma::View *>(v);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
Plasma::Location loc = Floating;
|
|
|
|
if (pv && pv->containment()) {
|
|
|
|
loc = pv->containment()->location();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (loc) {
|
|
|
|
case BottomEdge:
|
2009-03-20 23:17:44 +01:00
|
|
|
case TopEdge: {
|
2009-09-28 19:28:17 +02:00
|
|
|
if (alignment == Qt::AlignCenter) {
|
2011-04-20 18:07:06 +02:00
|
|
|
pos.setX(pos.x() + actualItem->boundingRect().width()/2 - s.width()/2);
|
2009-09-28 19:28:17 +02:00
|
|
|
} else if (alignment == Qt::AlignRight) {
|
2011-04-20 18:07:06 +02:00
|
|
|
pos.setX(pos.x() + actualItem->boundingRect().width() - s.width());
|
2009-09-28 19:28:17 +02:00
|
|
|
}
|
|
|
|
|
2011-12-31 08:45:02 +01:00
|
|
|
if (pos.x() + s.width() > v->geometry().x() + v->geometry().width()) {
|
|
|
|
pos.setX((v->geometry().x() + v->geometry().width()) - s.width());
|
2009-03-20 23:17:44 +01:00
|
|
|
} else {
|
|
|
|
pos.setX(qMax(pos.x(), v->geometry().left()));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LeftEdge:
|
|
|
|
case RightEdge: {
|
2009-09-28 19:28:17 +02:00
|
|
|
if (alignment == Qt::AlignCenter) {
|
2011-04-20 18:07:06 +02:00
|
|
|
pos.setY(pos.y() + actualItem->boundingRect().height()/2 - s.height()/2);
|
2009-09-28 19:28:17 +02:00
|
|
|
} else if (alignment == Qt::AlignRight) {
|
2011-04-20 18:07:06 +02:00
|
|
|
pos.setY(pos.y() + actualItem->boundingRect().height() - s.height());
|
2009-09-28 19:28:17 +02:00
|
|
|
}
|
|
|
|
|
2011-12-31 08:45:02 +01:00
|
|
|
if (pos.y() + s.height() > v->geometry().y() + v->geometry().height()) {
|
|
|
|
pos.setY((v->geometry().y() + v->geometry().height()) - s.height());
|
2009-03-20 23:17:44 +01:00
|
|
|
} else {
|
|
|
|
pos.setY(qMax(pos.y(), v->geometry().top()));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2009-09-28 19:28:17 +02:00
|
|
|
if (alignment == Qt::AlignCenter) {
|
2011-04-20 18:07:06 +02:00
|
|
|
pos.setX(pos.x() + actualItem->boundingRect().width()/2 - s.width()/2);
|
2009-09-28 19:28:17 +02:00
|
|
|
} else if (alignment == Qt::AlignRight) {
|
2011-04-20 18:07:06 +02:00
|
|
|
pos.setX(pos.x() + actualItem->boundingRect().width() - s.width());
|
2009-09-28 19:28:17 +02:00
|
|
|
}
|
2009-03-20 23:17:44 +01:00
|
|
|
break;
|
|
|
|
}
|
2010-05-05 22:00:36 +02:00
|
|
|
|
2011-07-28 18:53:21 +02:00
|
|
|
|
|
|
|
//are we out of screen?
|
|
|
|
int screen = ((pv && pv->containment()) ? pv->containment()->screen() : -1);
|
|
|
|
if (screen == -1) {
|
|
|
|
if (pv) {
|
|
|
|
screen = pv->screen();
|
|
|
|
} else {
|
|
|
|
// fall back to asking the actual system what screen the view is on
|
|
|
|
// in the case we are dealing with a non-PlasmaView QGraphicsView
|
|
|
|
screen = QApplication::desktop()->screenNumber(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect screenRect = screenGeometry(screen);
|
|
|
|
|
2009-03-20 23:17:44 +01:00
|
|
|
switch (loc) {
|
|
|
|
case BottomEdge:
|
|
|
|
pos.setY(v->geometry().y() - s.height());
|
2008-11-04 00:08:39 +01:00
|
|
|
break;
|
|
|
|
case TopEdge:
|
2011-12-31 08:45:02 +01:00
|
|
|
pos.setY(v->geometry().y() + v->geometry().height());
|
2008-11-04 00:08:39 +01:00
|
|
|
break;
|
|
|
|
case LeftEdge:
|
2011-12-31 08:45:02 +01:00
|
|
|
pos.setX(v->geometry().x() + v->geometry().width());
|
2008-11-04 00:08:39 +01:00
|
|
|
break;
|
|
|
|
case RightEdge:
|
2009-03-20 23:17:44 +01:00
|
|
|
pos.setX(v->geometry().x() - s.width());
|
2008-11-04 00:08:39 +01:00
|
|
|
break;
|
|
|
|
default:
|
2011-07-28 18:53:21 +02:00
|
|
|
if (pos.y() - s.height() > screenRect.top()) {
|
2009-10-17 01:00:24 +02:00
|
|
|
pos.ry() = pos.y() - s.height();
|
2008-11-04 00:08:39 +01:00
|
|
|
} else {
|
2011-04-20 18:07:06 +02:00
|
|
|
pos.ry() = pos.y() + (int)actualItem->boundingRect().size().height() + 1;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-29 20:53:03 +01:00
|
|
|
//kDebug() << "==> rect for" << screen << "is" << screenRect;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2011-12-31 08:45:02 +01:00
|
|
|
if (loc != LeftEdge && pos.x() + s.width() > screenRect.x() + screenRect.width()) {
|
|
|
|
pos.rx() -= ((pos.x() + s.width()) - (screenRect.x() + screenRect.width()));
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2011-12-31 08:45:02 +01:00
|
|
|
if (loc != TopEdge && pos.y() + s.height() > screenRect.y() + screenRect.height()) {
|
|
|
|
pos.ry() -= ((pos.y() + s.height()) - (screenRect.y() + screenRect.height()));
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-10-17 01:00:24 +02:00
|
|
|
pos.rx() = qMax(0, pos.x());
|
2011-12-16 14:52:16 +01:00
|
|
|
pos.ry() = qMax(0, pos.y());
|
2008-11-04 00:08:39 +01:00
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Corona::loadDefaultLayout()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-07-30 14:46:22 +02:00
|
|
|
void Corona::setPreferredToolBoxPlugin(const Containment::Type type, const QString &plugin)
|
|
|
|
{
|
2012-02-28 20:40:28 +01:00
|
|
|
d->coronaBase->setPreferredToolBoxPlugin(type, plugin);
|
2010-07-30 14:46:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Corona::preferredToolBoxPlugin(const Containment::Type type) const
|
|
|
|
{
|
2012-02-28 20:40:28 +01:00
|
|
|
return d->coronaBase->preferredToolBoxPlugin(type);
|
2010-07-30 14:46:22 +02:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
ImmutabilityType Corona::immutability() const
|
|
|
|
{
|
2012-02-28 20:40:28 +01:00
|
|
|
return d->coronaBase->immutability();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Corona::setImmutability(const ImmutabilityType immutable)
|
|
|
|
{
|
2012-02-28 20:40:28 +01:00
|
|
|
d->coronaBase->setImmutability(immutable);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2008-12-21 11:23:45 +01:00
|
|
|
QList<Plasma::Location> Corona::freeEdges(int screen) const
|
|
|
|
{
|
2012-02-28 20:40:28 +01:00
|
|
|
return d->coronaBase->freeEdges(screen);
|
2008-12-21 11:23:45 +01:00
|
|
|
}
|
|
|
|
|
2009-03-10 20:52:50 +01:00
|
|
|
QAction *Corona::action(QString name) const
|
|
|
|
{
|
2012-02-28 20:40:28 +01:00
|
|
|
return d->coronaBase->action(name);
|
2009-03-10 20:52:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Corona::addAction(QString name, QAction *action)
|
|
|
|
{
|
2012-02-28 20:40:28 +01:00
|
|
|
d->coronaBase->addAction(name, action);
|
2009-03-10 20:52:50 +01:00
|
|
|
}
|
|
|
|
|
2009-05-04 00:13:05 +02:00
|
|
|
KAction* Corona::addAction(QString name)
|
|
|
|
{
|
2012-02-28 20:40:28 +01:00
|
|
|
return d->coronaBase->addAction(name);
|
2009-05-04 00:13:05 +02:00
|
|
|
}
|
|
|
|
|
2009-03-10 20:52:50 +01:00
|
|
|
QList<QAction*> Corona::actions() const
|
|
|
|
{
|
2012-02-28 20:40:28 +01:00
|
|
|
return d->coronaBase->actions();
|
2009-03-10 20:52:50 +01:00
|
|
|
}
|
|
|
|
|
2009-03-11 19:37:12 +01:00
|
|
|
void Corona::enableAction(const QString &name, bool enable)
|
|
|
|
{
|
2012-02-28 20:40:28 +01:00
|
|
|
d->coronaBase->enableAction(name, enable);
|
2009-03-11 19:37:12 +01:00
|
|
|
}
|
|
|
|
|
2009-05-03 22:22:14 +02:00
|
|
|
void Corona::updateShortcuts()
|
|
|
|
{
|
2012-02-28 20:40:28 +01:00
|
|
|
d->coronaBase->updateShortcuts();
|
2009-05-03 22:22:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Corona::addShortcuts(KActionCollection *newShortcuts)
|
|
|
|
{
|
2012-02-28 20:40:28 +01:00
|
|
|
d->coronaBase->addShortcuts(newShortcuts);
|
2009-05-03 22:22:14 +02:00
|
|
|
}
|
|
|
|
|
2009-10-05 22:50:57 +02:00
|
|
|
void Corona::setContainmentActionsDefaults(Containment::Type containmentType, const ContainmentActionsPluginsConfig &config)
|
|
|
|
{
|
2012-02-28 20:40:28 +01:00
|
|
|
d->coronaBase->setContainmentActionsDefaults(containmentType, config);
|
2009-10-05 22:50:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ContainmentActionsPluginsConfig Corona::containmentActionsDefaults(Containment::Type containmentType)
|
|
|
|
{
|
2012-02-28 20:40:28 +01:00
|
|
|
return d->coronaBase->containmentActionsDefaults(containmentType);
|
2009-10-05 22:50:57 +02:00
|
|
|
}
|
|
|
|
|
2010-04-03 21:10:32 +02:00
|
|
|
void Corona::setDialogManager(AbstractDialogManager *dialogManager)
|
|
|
|
{
|
2012-02-28 20:40:28 +01:00
|
|
|
d->coronaBase->setDialogManager(dialogManager);
|
2010-04-03 21:10:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
AbstractDialogManager *Corona::dialogManager()
|
|
|
|
{
|
2012-02-28 20:40:28 +01:00
|
|
|
return d->coronaBase->dialogManager();
|
2010-04-03 21:10:32 +02:00
|
|
|
}
|
|
|
|
|
2011-01-11 21:45:24 +01:00
|
|
|
CoronaPrivate::CoronaPrivate(Corona *corona)
|
2012-02-28 20:40:28 +01:00
|
|
|
: q(corona)
|
2011-01-11 21:45:24 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CoronaPrivate::~CoronaPrivate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoronaPrivate::init()
|
|
|
|
{
|
|
|
|
q->setStickyFocus(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
} // namespace Plasma
|
|
|
|
|
|
|
|
|
2012-02-08 23:33:03 +01:00
|
|
|
|
|
|
|
#include "moc_corona.cpp"
|