2008-11-04 00:08:39 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
|
|
|
|
* Copyright 2008 by Marco Martin <notmart@gmail.com>
|
|
|
|
*
|
|
|
|
* 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 "toolbox_p.h"
|
|
|
|
|
|
|
|
#include <QAction>
|
2008-11-14 08:28:02 +01:00
|
|
|
#include <QApplication>
|
2008-11-04 00:08:39 +01:00
|
|
|
#include <QGraphicsSceneHoverEvent>
|
2008-11-14 08:28:02 +01:00
|
|
|
#include <QGraphicsView>
|
2008-11-04 00:08:39 +01:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QRadialGradient>
|
|
|
|
|
2008-11-04 03:39:56 +01:00
|
|
|
#include <kcolorscheme.h>
|
2008-11-14 08:28:02 +01:00
|
|
|
#include <kconfiggroup.h>
|
2009-02-15 17:35:52 +01:00
|
|
|
#include <kiconloader.h>
|
2008-11-04 03:39:56 +01:00
|
|
|
#include <kdebug.h>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-11-14 08:28:02 +01:00
|
|
|
#include "corona.h"
|
|
|
|
#include "theme.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "widgets/iconwidget.h"
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
class ToolBoxPrivate
|
|
|
|
{
|
|
|
|
public:
|
2008-11-14 08:28:02 +01:00
|
|
|
ToolBoxPrivate(Containment *c)
|
|
|
|
: containment(c),
|
|
|
|
size(50),
|
2009-02-15 17:35:52 +01:00
|
|
|
iconSize(KIconLoader::SizeMedium, KIconLoader::SizeMedium),
|
2008-11-14 08:28:02 +01:00
|
|
|
corner(ToolBox::TopRight),
|
|
|
|
hidden(false),
|
|
|
|
showing(false),
|
|
|
|
movable(false),
|
2008-11-28 18:32:21 +01:00
|
|
|
toolbar(false),
|
2008-11-24 23:27:42 +01:00
|
|
|
dragging(false),
|
|
|
|
userMoved(false)
|
2008-11-04 00:08:39 +01:00
|
|
|
{}
|
|
|
|
|
2008-11-14 08:28:02 +01:00
|
|
|
Containment *containment;
|
2008-11-04 00:08:39 +01:00
|
|
|
int size;
|
|
|
|
QSize iconSize;
|
|
|
|
ToolBox::Corner corner;
|
2008-12-25 09:29:03 +01:00
|
|
|
QPoint dragStartRelative;
|
2008-11-28 18:32:21 +01:00
|
|
|
QTransform viewTransform;
|
2008-11-10 04:53:35 +01:00
|
|
|
bool hidden : 1;
|
|
|
|
bool showing : 1;
|
|
|
|
bool movable : 1;
|
2008-11-28 18:32:21 +01:00
|
|
|
bool toolbar : 1;
|
2008-11-10 04:53:35 +01:00
|
|
|
bool dragging : 1;
|
2008-11-14 08:28:02 +01:00
|
|
|
bool userMoved : 1;
|
2008-11-04 00:08:39 +01:00
|
|
|
};
|
|
|
|
|
2008-11-14 08:28:02 +01:00
|
|
|
ToolBox::ToolBox(Containment *parent)
|
2008-11-04 00:08:39 +01:00
|
|
|
: QGraphicsItem(parent),
|
2008-11-14 08:28:02 +01:00
|
|
|
d(new ToolBoxPrivate(parent))
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2008-12-01 02:54:07 +01:00
|
|
|
d->userMoved = false;
|
2008-11-04 00:08:39 +01:00
|
|
|
setAcceptsHoverEvents(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
ToolBox::~ToolBox()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPoint ToolBox::toolPosition(int toolHeight)
|
|
|
|
{
|
|
|
|
switch (d->corner) {
|
|
|
|
case TopRight:
|
2009-03-05 23:15:06 +01:00
|
|
|
return QPoint(boundingRect().width(), -toolHeight);
|
2008-11-04 00:08:39 +01:00
|
|
|
case Top:
|
2009-03-05 23:15:06 +01:00
|
|
|
return QPoint((int)boundingRect().center().x() - boundingRect().width(), -toolHeight);
|
2008-11-04 00:08:39 +01:00
|
|
|
case TopLeft:
|
2009-03-05 23:15:06 +01:00
|
|
|
return QPoint(-boundingRect().width(), -toolHeight);
|
2008-11-04 00:08:39 +01:00
|
|
|
case Left:
|
2009-03-05 23:15:06 +01:00
|
|
|
return QPoint(-boundingRect().width(), (int)boundingRect().center().y() - boundingRect().height());
|
2008-11-04 00:08:39 +01:00
|
|
|
case Right:
|
2009-03-05 23:15:06 +01:00
|
|
|
return QPoint(boundingRect().width(), (int)boundingRect().center().y() - boundingRect().height());
|
2008-11-04 00:08:39 +01:00
|
|
|
case BottomLeft:
|
2009-03-05 23:15:06 +01:00
|
|
|
return QPoint(-boundingRect().width(), toolHeight);
|
2008-11-04 00:08:39 +01:00
|
|
|
case Bottom:
|
|
|
|
return QPoint((int)boundingRect().center().x() - d->iconSize.width(), toolHeight);
|
|
|
|
case BottomRight:
|
|
|
|
default:
|
2009-03-05 23:15:06 +01:00
|
|
|
return QPoint(boundingRect().width(), toolHeight);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolBox::addTool(QAction *action)
|
|
|
|
{
|
|
|
|
if (!action) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Plasma::IconWidget *tool = new Plasma::IconWidget(this);
|
|
|
|
|
|
|
|
tool->setAction(action);
|
|
|
|
tool->setDrawBackground(true);
|
|
|
|
tool->setOrientation(Qt::Horizontal);
|
2009-02-15 17:35:52 +01:00
|
|
|
tool->resize(tool->sizeFromIconSize(KIconLoader::SizeSmallMedium));
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
tool->hide();
|
|
|
|
const int height = static_cast<int>(tool->boundingRect().height());
|
|
|
|
tool->setPos(toolPosition(height));
|
2008-12-17 01:51:30 +01:00
|
|
|
tool->setZValue(zValue() + 10);
|
2008-12-15 17:42:29 +01:00
|
|
|
tool->setToolTip(action->text());
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
//make enabled/disabled tools appear/disappear instantly
|
|
|
|
connect(tool, SIGNAL(changed()), this, SLOT(updateToolBox()));
|
2009-01-29 20:11:15 +01:00
|
|
|
connect(action, SIGNAL(triggered(bool)), this, SLOT(toolTriggered(bool)));
|
2008-11-27 19:33:11 +01:00
|
|
|
//kDebug() << "added tool" << action->text() << (QGraphicsItem*)tool;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ToolBox::updateToolBox()
|
|
|
|
{
|
2009-02-08 19:27:55 +01:00
|
|
|
Plasma::IconWidget *tool = qobject_cast<Plasma::IconWidget *>(sender());
|
|
|
|
if (tool && tool->action() == 0) {
|
|
|
|
delete tool;
|
|
|
|
tool = 0;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
if (d->showing) {
|
|
|
|
d->showing = false;
|
|
|
|
showToolBox();
|
2009-02-08 19:27:55 +01:00
|
|
|
} else if (tool && !tool->isEnabled()) {
|
2008-12-18 13:32:06 +01:00
|
|
|
tool->hide();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-28 14:38:57 +01:00
|
|
|
void ToolBox::toolTriggered(bool)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void ToolBox::removeTool(QAction *action)
|
|
|
|
{
|
|
|
|
foreach (QGraphicsItem *child, QGraphicsItem::children()) {
|
|
|
|
//kDebug() << "checking tool" << child << child->data(ToolName);
|
|
|
|
Plasma::IconWidget *tool = dynamic_cast<Plasma::IconWidget*>(child);
|
|
|
|
if (tool && tool->action() == action) {
|
|
|
|
//kDebug() << "tool found!";
|
2008-11-18 01:43:52 +01:00
|
|
|
delete tool;
|
2008-11-04 00:08:39 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int ToolBox::size() const
|
|
|
|
{
|
|
|
|
return d->size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolBox::setSize(const int newSize)
|
|
|
|
{
|
|
|
|
d->size = newSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize ToolBox::iconSize() const
|
|
|
|
{
|
|
|
|
return d->iconSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolBox::setIconSize(const QSize newSize)
|
|
|
|
{
|
|
|
|
d->iconSize = newSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ToolBox::showing() const
|
|
|
|
{
|
|
|
|
return d->showing;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolBox::setShowing(const bool show)
|
|
|
|
{
|
|
|
|
d->showing = show;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolBox::setCorner(const Corner corner)
|
|
|
|
{
|
|
|
|
d->corner = corner;
|
|
|
|
}
|
|
|
|
|
|
|
|
ToolBox::Corner ToolBox::corner() const
|
|
|
|
{
|
|
|
|
return d->corner;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolBox::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
event->accept();
|
2008-12-25 09:29:03 +01:00
|
|
|
// set grab position relative to toolbox
|
|
|
|
d->dragStartRelative = mapToParent(event->pos()).toPoint() - pos().toPoint();
|
2008-11-10 04:53:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ToolBox::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
2008-11-28 18:32:21 +01:00
|
|
|
if (!d->movable || (!d->dragging && boundingRect().contains(event->pos())) || isToolbar()) {
|
2008-11-10 04:53:35 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->dragging = true;
|
2008-11-14 08:28:02 +01:00
|
|
|
d->userMoved = true;
|
2008-11-10 04:53:35 +01:00
|
|
|
const QPoint newPos = mapToParent(event->pos()).toPoint();
|
|
|
|
const QPoint curPos = pos().toPoint();
|
2008-12-27 01:31:24 +01:00
|
|
|
const int h = abs((int)boundingRect().height());
|
|
|
|
const int w = abs((int)boundingRect().width());
|
2008-11-10 04:53:35 +01:00
|
|
|
|
|
|
|
const int areaWidth = parentWidget()->size().width();
|
|
|
|
const int areaHeight = parentWidget()->size().height();
|
|
|
|
|
|
|
|
int x = curPos.x();
|
|
|
|
int y = curPos.y();
|
|
|
|
|
2008-12-25 09:29:03 +01:00
|
|
|
// jump to the nearest desktop border
|
|
|
|
int distanceToLeft = newPos.x() - d->dragStartRelative.x();
|
|
|
|
int distanceToRight = areaWidth - w - distanceToLeft;
|
|
|
|
int distanceToTop = newPos.y() - d->dragStartRelative.y();
|
|
|
|
int distanceToBottom = areaHeight - h - distanceToTop;
|
|
|
|
|
|
|
|
// decide which border is the nearest
|
|
|
|
if (distanceToLeft < distanceToTop && distanceToLeft < distanceToRight &&
|
|
|
|
distanceToLeft < distanceToBottom ) {
|
|
|
|
x = 0;
|
|
|
|
y = (newPos.y() - d->dragStartRelative.y());
|
|
|
|
}
|
|
|
|
else if (distanceToRight < distanceToTop && distanceToRight < distanceToLeft &&
|
|
|
|
distanceToRight < distanceToBottom) {
|
|
|
|
x = areaWidth - w;
|
|
|
|
y = (newPos.y() - d->dragStartRelative.y());
|
|
|
|
}
|
|
|
|
else if (distanceToTop < distanceToLeft && distanceToTop < distanceToRight &&
|
|
|
|
distanceToTop < distanceToBottom ) {
|
|
|
|
y = 0;
|
|
|
|
x = (newPos.x() - d->dragStartRelative.x());
|
|
|
|
}
|
|
|
|
else if (distanceToBottom < distanceToLeft && distanceToBottom < distanceToRight &&
|
|
|
|
distanceToBottom < distanceToTop) {
|
|
|
|
y = areaHeight - h;
|
|
|
|
x = (newPos.x() - d->dragStartRelative.x());
|
|
|
|
}
|
|
|
|
|
|
|
|
//kDebug() << "distances from borders" << (newPos - d->dragStartRelative) << distanceToLeft << distanceToRight << distanceToTop << distanceToBottom << "=>" << x << y;
|
|
|
|
/*
|
2008-11-10 04:53:35 +01:00
|
|
|
if (y == 0 || y + h >= areaHeight) {
|
|
|
|
x = curPos.x() + (newPos.x() - d->dragStart.x());
|
|
|
|
if (x < 0) {
|
|
|
|
x = 0;
|
|
|
|
} else if (x + w > areaWidth) {
|
|
|
|
x = areaWidth - w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//kDebug() << x << w << areaWidth;
|
|
|
|
if (x == 0 || x + w >= areaWidth) {
|
|
|
|
//kDebug() << "moving along the y axis" << curPos << newPos << d->dragStart;
|
|
|
|
y = curPos.y() + (newPos.y() - d->dragStart.y());
|
|
|
|
|
|
|
|
if (y < 0) {
|
|
|
|
y = 0;
|
|
|
|
} else if (y + h > areaHeight) {
|
|
|
|
y = areaHeight - h;
|
|
|
|
}
|
|
|
|
}
|
2008-12-25 09:29:03 +01:00
|
|
|
*/
|
2008-11-10 04:53:35 +01:00
|
|
|
x = qBound(0, x, areaWidth - w);
|
|
|
|
y = qBound(0, y, areaHeight - h);
|
|
|
|
|
|
|
|
Corner newCorner = d->corner;
|
|
|
|
if (x == 0) {
|
|
|
|
if (y == 0) {
|
|
|
|
newCorner = TopLeft;
|
|
|
|
} else if (y + h >= areaHeight) {
|
|
|
|
newCorner = BottomLeft;
|
|
|
|
} else {
|
|
|
|
newCorner = Left;
|
|
|
|
}
|
|
|
|
} else if (y == 0) {
|
|
|
|
if (x + w >= areaWidth) {
|
|
|
|
newCorner = TopRight;
|
|
|
|
} else {
|
|
|
|
newCorner = Top;
|
|
|
|
}
|
|
|
|
} else if (x + w >= areaWidth) {
|
|
|
|
if (y + h >= areaHeight) {
|
|
|
|
newCorner = BottomRight;
|
|
|
|
} else {
|
|
|
|
newCorner = Right;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
newCorner = Bottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newCorner != d->corner) {
|
|
|
|
prepareGeometryChange();
|
|
|
|
d->corner = newCorner;
|
|
|
|
}
|
|
|
|
|
|
|
|
setPos(x, y);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ToolBox::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
2008-11-10 04:53:35 +01:00
|
|
|
if (!d->dragging && boundingRect().contains(event->pos())) {
|
2008-11-04 00:08:39 +01:00
|
|
|
emit toggled();
|
|
|
|
}
|
2008-11-10 04:53:35 +01:00
|
|
|
|
|
|
|
d->dragging = false;
|
2008-11-14 08:30:35 +01:00
|
|
|
KConfigGroup cg(d->containment->config());
|
|
|
|
save(cg);
|
2008-11-10 04:53:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ToolBox::isMovable() const
|
|
|
|
{
|
|
|
|
return d->movable;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolBox::setIsMovable(bool movable)
|
|
|
|
{
|
|
|
|
d->movable = movable;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2008-11-28 18:32:21 +01:00
|
|
|
bool ToolBox::isToolbar() const
|
|
|
|
{
|
|
|
|
return d->toolbar;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolBox::setIsToolbar(bool toolbar)
|
|
|
|
{
|
|
|
|
d->toolbar = toolbar;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTransform ToolBox::viewTransform() const
|
|
|
|
{
|
|
|
|
return d->viewTransform;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolBox::setViewTransform(QTransform transform)
|
|
|
|
{
|
2008-12-03 23:44:16 +01:00
|
|
|
if (transform.isScaling()) {
|
|
|
|
d->toolbar = true;
|
|
|
|
showToolBox();
|
|
|
|
} else {
|
|
|
|
d->toolbar = false;
|
2008-12-05 19:16:30 +01:00
|
|
|
if (d->viewTransform != transform) {
|
|
|
|
hideToolBox();
|
|
|
|
}
|
2008-12-03 23:44:16 +01:00
|
|
|
}
|
2008-12-05 19:16:30 +01:00
|
|
|
d->viewTransform = transform;
|
2008-11-28 18:32:21 +01:00
|
|
|
}
|
|
|
|
|
2008-11-14 08:28:02 +01:00
|
|
|
void ToolBox::save(KConfigGroup &cg) const
|
|
|
|
{
|
|
|
|
if (!d->movable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
KConfigGroup group(&cg, "ToolBox");
|
|
|
|
if (!d->userMoved) {
|
|
|
|
group.deleteGroup();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int offset = 0;
|
|
|
|
if (d->corner == ToolBox::Left ||
|
|
|
|
d->corner == ToolBox::Right) {
|
|
|
|
offset = y();
|
2009-03-05 23:15:06 +01:00
|
|
|
} else if (d->corner == ToolBox::Top ||
|
|
|
|
d->corner == ToolBox::Bottom) {
|
2008-11-14 08:28:02 +01:00
|
|
|
offset = x();
|
|
|
|
}
|
|
|
|
|
|
|
|
group.writeEntry("corner", int(d->corner));
|
|
|
|
group.writeEntry("offset", offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolBox::load()
|
|
|
|
{
|
|
|
|
if (!d->movable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
KConfigGroup group = d->containment->config();
|
|
|
|
group = KConfigGroup(&group, "ToolBox");
|
|
|
|
|
|
|
|
if (!group.hasKey("corner")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->userMoved = true;
|
|
|
|
d->corner = Corner(group.readEntry("corner", int(d->corner)));
|
|
|
|
|
|
|
|
int offset = group.readEntry("offset", 0);
|
2008-11-14 09:04:46 +01:00
|
|
|
switch (d->corner) {
|
|
|
|
case ToolBox::TopLeft:
|
|
|
|
setPos(0, 0);
|
|
|
|
break;
|
|
|
|
case ToolBox::Top:
|
|
|
|
setPos(offset, 0);
|
|
|
|
break;
|
|
|
|
case ToolBox::TopRight:
|
2009-03-05 23:15:06 +01:00
|
|
|
setPos(d->containment->size().width() - boundingRect().width(), 0);
|
2008-11-14 09:04:46 +01:00
|
|
|
break;
|
|
|
|
case ToolBox::Right:
|
2009-03-05 23:15:06 +01:00
|
|
|
setPos(d->containment->size().width() - boundingRect().width(), offset);
|
2008-11-14 09:04:46 +01:00
|
|
|
break;
|
|
|
|
case ToolBox::BottomRight:
|
2009-03-05 23:15:06 +01:00
|
|
|
setPos(d->containment->size().width() - boundingRect().width(), d->containment->size().height() - boundingRect().height());
|
2008-11-14 09:04:46 +01:00
|
|
|
break;
|
|
|
|
case ToolBox::Bottom:
|
2009-03-05 23:15:06 +01:00
|
|
|
setPos(offset, d->containment->size().height() - boundingRect().height());
|
2008-11-14 09:04:46 +01:00
|
|
|
break;
|
|
|
|
case ToolBox::BottomLeft:
|
2009-03-05 23:15:06 +01:00
|
|
|
setPos(0, d->containment->size().height() - boundingRect().height());
|
2008-11-14 09:04:46 +01:00
|
|
|
break;
|
|
|
|
case ToolBox::Left:
|
|
|
|
setPos(0, offset);
|
|
|
|
break;
|
2008-11-14 08:28:02 +01:00
|
|
|
}
|
2008-11-27 19:33:11 +01:00
|
|
|
//kDebug() << "marked as user moved" << pos()
|
|
|
|
// << (d->containment->containmentType() == Containment::PanelContainment);
|
2008-11-14 08:28:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ToolBox::reposition()
|
|
|
|
{
|
|
|
|
if (d->userMoved) {
|
|
|
|
//FIXME: adjust for situations like changing of the available space
|
|
|
|
load();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-02-24 05:54:57 +01:00
|
|
|
if (d->containment->containmentType() == Containment::PanelContainment ||
|
|
|
|
d->containment->containmentType() == Containment::CustomPanelContainment) {
|
2008-11-18 01:12:05 +01:00
|
|
|
QRectF rect = boundingRect();
|
2008-11-14 08:28:02 +01:00
|
|
|
if (d->containment->formFactor() == Vertical) {
|
|
|
|
setCorner(ToolBox::Bottom);
|
2008-11-18 01:12:05 +01:00
|
|
|
setPos(d->containment->geometry().width() / 2 - rect.width() / 2,
|
|
|
|
d->containment->geometry().height() - rect.height());
|
2008-11-14 08:28:02 +01:00
|
|
|
} else {
|
|
|
|
//defaulting to Horizontal right now
|
|
|
|
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
|
|
|
setPos(d->containment->geometry().left(),
|
2008-11-18 01:12:05 +01:00
|
|
|
d->containment->geometry().height() / 2 - rect.height() / 2);
|
2008-11-14 08:28:02 +01:00
|
|
|
setCorner(ToolBox::Left);
|
|
|
|
} else {
|
2008-11-18 01:12:05 +01:00
|
|
|
setPos(d->containment->geometry().width() - rect.width(),
|
|
|
|
d->containment->geometry().height() / 2 - rect.height() / 2);
|
2008-11-14 08:28:02 +01:00
|
|
|
setCorner(ToolBox::Right);
|
|
|
|
}
|
|
|
|
}
|
2009-02-24 05:54:57 +01:00
|
|
|
|
|
|
|
//kDebug() << "got ourselves a panel containment, moving to" << pos();
|
2008-11-14 08:28:02 +01:00
|
|
|
} else if (d->containment->corona()) {
|
|
|
|
//kDebug() << "desktop";
|
|
|
|
|
|
|
|
int screen = d->containment->screen();
|
2008-11-19 22:18:37 +01:00
|
|
|
QRectF avail = d->containment->geometry();
|
|
|
|
QRectF screenGeom = avail;
|
|
|
|
|
|
|
|
if (screen > -1 && screen < d->containment->corona()->numScreens()) {
|
2008-12-02 13:44:39 +01:00
|
|
|
avail = d->containment->corona()->availableScreenRegion(screen).boundingRect();
|
2008-11-19 22:18:37 +01:00
|
|
|
screenGeom = d->containment->corona()->screenGeometry(screen);
|
|
|
|
avail.translate(-screenGeom.topLeft());
|
|
|
|
}
|
2008-11-14 08:28:02 +01:00
|
|
|
|
|
|
|
// Transform to the containment's coordinate system.
|
|
|
|
screenGeom.moveTo(0, 0);
|
|
|
|
|
|
|
|
if (!d->containment->view() || !d->containment->view()->transform().isScaling()) {
|
|
|
|
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
|
|
|
if (avail.top() > screenGeom.top()) {
|
2009-03-05 23:15:06 +01:00
|
|
|
setPos(avail.topLeft() - QPoint(0, boundingRect().height()));
|
2008-11-14 08:28:02 +01:00
|
|
|
setCorner(ToolBox::Left);
|
|
|
|
} else if (avail.left() > screenGeom.left()) {
|
2009-03-05 23:15:06 +01:00
|
|
|
setPos(avail.topLeft() - QPoint(boundingRect().width(), 0));
|
2008-11-14 08:28:02 +01:00
|
|
|
setCorner(ToolBox::Top);
|
|
|
|
} else {
|
|
|
|
setPos(avail.topLeft());
|
|
|
|
setCorner(ToolBox::TopLeft);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (avail.top() > screenGeom.top()) {
|
2009-03-05 23:15:06 +01:00
|
|
|
setPos(avail.topRight() - QPoint(0, boundingRect().height()));
|
2008-11-14 08:28:02 +01:00
|
|
|
setCorner(ToolBox::Right);
|
|
|
|
} else if (avail.right() < screenGeom.right()) {
|
2009-03-05 23:15:06 +01:00
|
|
|
setPos(avail.topRight() - QPoint(boundingRect().width(), 0));
|
2008-11-14 08:28:02 +01:00
|
|
|
setCorner(ToolBox::Top);
|
|
|
|
} else {
|
2009-03-05 23:15:06 +01:00
|
|
|
setPos(avail.topRight() - QPoint(boundingRect().width(), 0));
|
2008-11-14 08:28:02 +01:00
|
|
|
setCorner(ToolBox::TopRight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
|
|
|
setPos(d->containment->mapFromScene(QPointF(d->containment->geometry().topLeft())));
|
|
|
|
setCorner(ToolBox::TopLeft);
|
|
|
|
} else {
|
|
|
|
setPos(d->containment->mapFromScene(QPointF(d->containment->geometry().topRight())));
|
|
|
|
setCorner(ToolBox::TopRight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
} // plasma namespace
|
|
|
|
|
|
|
|
#include "toolbox_p.moc"
|
|
|
|
|