2005-12-29 22:55:22 +01:00
|
|
|
/*
|
2007-08-06 13:20:02 +02:00
|
|
|
* Copyright 2005 by Aaron Seigo <aseigo@kde.org>
|
2005-12-29 22:55:22 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2007-09-14 21:06:18 +02:00
|
|
|
* 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.
|
2005-12-29 22:55:22 +01:00
|
|
|
*
|
|
|
|
* 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.,
|
2006-01-23 12:37:31 +01:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-12-29 22:55:22 +01:00
|
|
|
*/
|
|
|
|
|
2008-07-17 01:48:41 +02:00
|
|
|
#include <plasma/plasma.h>
|
|
|
|
|
|
|
|
#include <QDesktopWidget>
|
|
|
|
#include <QGraphicsScene>
|
|
|
|
#include <QGraphicsView>
|
|
|
|
|
|
|
|
#include <plasma/containment.h>
|
|
|
|
#include <plasma/view.h>
|
2005-12-29 22:55:22 +01:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2007-07-26 00:43:43 +02:00
|
|
|
qreal scalingFactor(ZoomLevel level)
|
|
|
|
{
|
|
|
|
switch (level) {
|
|
|
|
case DesktopZoom:
|
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
case GroupZoom:
|
|
|
|
return 0.5;
|
|
|
|
break;
|
|
|
|
case OverviewZoom:
|
2007-07-26 00:54:35 +02:00
|
|
|
return 0.2;
|
2007-07-26 00:43:43 +02:00
|
|
|
break;
|
|
|
|
}
|
2007-07-26 00:54:35 +02:00
|
|
|
|
|
|
|
// to make odd compilers not warn like silly beasts
|
|
|
|
return 1;
|
2007-07-26 00:43:43 +02:00
|
|
|
}
|
|
|
|
|
2007-05-26 00:51:23 +02:00
|
|
|
Direction locationToDirection(Location location)
|
2005-12-29 22:55:22 +01:00
|
|
|
{
|
2008-10-12 00:48:38 +02:00
|
|
|
switch (location) {
|
|
|
|
case Floating:
|
|
|
|
case Desktop:
|
|
|
|
case TopEdge:
|
|
|
|
case FullScreen:
|
|
|
|
//TODO: should we be smarter for floating and planer?
|
|
|
|
// perhaps we should take a QRect and/or QPos as well?
|
|
|
|
return Down;
|
|
|
|
case BottomEdge:
|
|
|
|
return Up;
|
|
|
|
case LeftEdge:
|
|
|
|
return Right;
|
|
|
|
case RightEdge:
|
|
|
|
return Left;
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
2007-05-26 00:51:23 +02:00
|
|
|
|
|
|
|
return Down;
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
|
2008-10-12 00:48:38 +02:00
|
|
|
QPoint popupPosition(const QGraphicsItem *item, const QSize &s)
|
2008-07-17 01:48:41 +02:00
|
|
|
{
|
|
|
|
QGraphicsView *v = viewFor(item);
|
|
|
|
|
|
|
|
if (!v) {
|
2008-10-12 00:48:38 +02:00
|
|
|
return QPoint(0, 0);
|
2008-07-17 01:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QPoint pos = v->mapFromScene(item->scenePos());
|
|
|
|
pos = v->mapToGlobal(pos);
|
2008-08-27 03:06:40 +02:00
|
|
|
//kDebug() << "==> position is" << item->scenePos() << v->mapFromScene(item->scenePos()) << pos;
|
2008-07-17 01:48:41 +02:00
|
|
|
Plasma::View *pv = dynamic_cast<Plasma::View *>(v);
|
|
|
|
|
|
|
|
Plasma::Location loc = Floating;
|
|
|
|
if (pv) {
|
|
|
|
loc = pv->containment()->location();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (loc) {
|
|
|
|
case BottomEdge:
|
|
|
|
pos = QPoint(pos.x(), pos.y() - s.height());
|
|
|
|
break;
|
|
|
|
case TopEdge:
|
|
|
|
pos = QPoint(pos.x(), pos.y() + (int)item->boundingRect().size().height());
|
|
|
|
break;
|
|
|
|
case LeftEdge:
|
|
|
|
pos = QPoint(pos.x() + (int)item->boundingRect().size().width(), pos.y());
|
|
|
|
break;
|
|
|
|
case RightEdge:
|
|
|
|
pos = QPoint(pos.x() - s.width(), pos.y());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (pos.y() - s.height() > 0) {
|
|
|
|
pos = QPoint(pos.x(), pos.y() - s.height());
|
|
|
|
} else {
|
|
|
|
pos = QPoint(pos.x(), pos.y() + (int)item->boundingRect().size().height());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//are we out of screen?
|
2008-10-12 00:48:38 +02:00
|
|
|
QRect screenRect =
|
|
|
|
QApplication::desktop()->screenGeometry(pv ? pv->containment()->screen() : -1);
|
2008-07-17 01:48:41 +02:00
|
|
|
//kDebug() << "==> rect for" << (pv ? pv->containment()->screen() : -1) << "is" << screenRect;
|
|
|
|
|
|
|
|
if (pos.rx() + s.width() > screenRect.right()) {
|
|
|
|
pos.rx() -= ((pos.rx() + s.width()) - screenRect.right());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos.ry() + s.height() > screenRect.bottom()) {
|
|
|
|
pos.ry() -= ((pos.ry() + s.height()) - screenRect.bottom());
|
|
|
|
}
|
|
|
|
|
|
|
|
pos.rx() = qMax(0, pos.rx());
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2008-10-12 00:48:38 +02:00
|
|
|
QGraphicsView *viewFor(const QGraphicsItem *item)
|
2008-07-17 01:48:41 +02:00
|
|
|
{
|
|
|
|
if (!item->scene()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsView *found = 0;
|
|
|
|
foreach (QGraphicsView *view, item->scene()->views()) {
|
|
|
|
if (view->sceneRect().intersects(item->sceneBoundingRect()) ||
|
|
|
|
view->sceneRect().contains(item->scenePos())) {
|
|
|
|
if (!found || view->isActiveWindow()) {
|
|
|
|
found = view;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2005-12-29 22:55:22 +01:00
|
|
|
} // Plasma namespace
|