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)
|
2009-10-07 19:08:44 +02:00
|
|
|
: QGraphicsWidget(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;
|
|
|
|
}
|
|
|
|
|
2009-10-07 19:08:44 +02:00
|
|
|
Containment *ToolBox::containment()
|
|
|
|
{
|
|
|
|
return d->containment;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-08-29 02:33:27 +02:00
|
|
|
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) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
Plasma::IconWidget *tool = new Plasma::IconWidget(this);
|
|
|
|
|
2009-04-10 23:56:12 +02:00
|
|
|
tool->setTextBackgroundColor(QColor());
|
2008-11-04 00:08:39 +01:00
|
|
|
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) {
|
2009-03-20 01:23:21 +01:00
|
|
|
tool->deleteLater();
|
2009-02-08 19:27:55 +01:00
|
|
|
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!";
|
2009-03-20 01:23:21 +01:00
|
|
|
tool->deleteLater();
|
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
|
|
|
|
{
|
2009-04-24 21:28:37 +02:00
|
|
|
return d->showing;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2009-08-31 11:30:13 +02:00
|
|
|
if (event->button() == Qt::LeftButton) {
|
|
|
|
event->accept();
|
|
|
|
// set grab position relative to toolbox
|
|
|
|
d->dragStartRelative = mapToParent(event->pos()).toPoint() - pos().toPoint();
|
|
|
|
} else {
|
|
|
|
event->ignore();
|
|
|
|
}
|
2008-11-10 04:53:35 +01:00
|
|
|
}
|
|
|
|
|
2009-07-28 05:19:33 +02:00
|
|
|
QSize ToolBox::cornerSize() const
|
|
|
|
{
|
|
|
|
return boundingRect().size().toSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize ToolBox::fullWidth() const
|
|
|
|
{
|
|
|
|
return boundingRect().size().toSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize ToolBox::fullHeight() const
|
|
|
|
{
|
|
|
|
return boundingRect().size().toSize();
|
|
|
|
}
|
|
|
|
|
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();
|
2009-07-28 05:19:33 +02:00
|
|
|
|
|
|
|
const QSize cSize = cornerSize();
|
|
|
|
const QSize fHeight = fullHeight();
|
|
|
|
const QSize fWidth = fullWidth();
|
|
|
|
const int h = fHeight.height();
|
|
|
|
const int w = fWidth.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;
|
|
|
|
|
2009-03-11 23:33:46 +01:00
|
|
|
int distancetoHorizontalMiddle = qAbs(newPos.x() - areaWidth/2);
|
|
|
|
int distancetoVerticalMiddle = qAbs(newPos.y() - areaHeight/2);
|
|
|
|
|
2008-12-25 09:29:03 +01:00
|
|
|
// decide which border is the nearest
|
|
|
|
if (distanceToLeft < distanceToTop && distanceToLeft < distanceToRight &&
|
|
|
|
distanceToLeft < distanceToBottom ) {
|
|
|
|
x = 0;
|
|
|
|
y = (newPos.y() - d->dragStartRelative.y());
|
2009-07-28 05:19:33 +02:00
|
|
|
} else if (distanceToRight < distanceToTop && distanceToRight < distanceToLeft &&
|
|
|
|
distanceToRight < distanceToBottom) {
|
2008-12-25 09:29:03 +01:00
|
|
|
x = areaWidth - w;
|
|
|
|
y = (newPos.y() - d->dragStartRelative.y());
|
2009-07-28 05:19:33 +02:00
|
|
|
} else if (distanceToTop < distanceToLeft && distanceToTop < distanceToRight &&
|
|
|
|
distanceToTop < distanceToBottom ) {
|
2008-12-25 09:29:03 +01:00
|
|
|
y = 0;
|
|
|
|
x = (newPos.x() - d->dragStartRelative.x());
|
2009-07-28 05:19:33 +02:00
|
|
|
} else if (distanceToBottom < distanceToLeft && distanceToBottom < distanceToRight &&
|
|
|
|
distanceToBottom < distanceToTop) {
|
2008-12-25 09:29:03 +01:00
|
|
|
y = areaHeight - h;
|
|
|
|
x = (newPos.x() - d->dragStartRelative.x());
|
|
|
|
}
|
|
|
|
|
2009-03-11 23:33:46 +01:00
|
|
|
if (distancetoHorizontalMiddle < 10) {
|
|
|
|
x = areaWidth/2 - d->dragStartRelative.x();
|
|
|
|
} else if (distancetoVerticalMiddle < 10) {
|
|
|
|
y = areaHeight/2 - d->dragStartRelative.y();
|
|
|
|
}
|
|
|
|
|
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;
|
2009-07-28 05:19:33 +02:00
|
|
|
} else if (areaHeight - cSize.height() < newPos.y()) {
|
|
|
|
y = areaHeight - cSize.height();
|
2008-11-10 04:53:35 +01:00
|
|
|
newCorner = BottomLeft;
|
|
|
|
} else {
|
|
|
|
newCorner = Left;
|
|
|
|
}
|
|
|
|
} else if (y == 0) {
|
2009-07-28 05:19:33 +02:00
|
|
|
if (areaWidth - cSize.width() < newPos.x()) {
|
|
|
|
x = areaWidth - cSize.width();
|
2008-11-10 04:53:35 +01:00
|
|
|
newCorner = TopRight;
|
|
|
|
} else {
|
|
|
|
newCorner = Top;
|
|
|
|
}
|
|
|
|
} else if (x + w >= areaWidth) {
|
2009-07-28 05:19:33 +02:00
|
|
|
if (areaHeight - cSize.height() < newPos.y()) {
|
|
|
|
y = areaHeight - cSize.height();
|
|
|
|
x = areaWidth - cSize.width();
|
2008-11-10 04:53:35 +01:00
|
|
|
newCorner = BottomRight;
|
|
|
|
} else {
|
2009-07-28 05:19:33 +02:00
|
|
|
x = areaWidth - fHeight.width();
|
2008-11-10 04:53:35 +01:00
|
|
|
newCorner = Right;
|
|
|
|
}
|
|
|
|
} else {
|
2009-07-28 05:19:33 +02:00
|
|
|
y = areaHeight - fWidth.height();
|
2008-11-10 04:53:35 +01:00
|
|
|
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)
|
|
|
|
{
|
2009-08-31 11:30:13 +02:00
|
|
|
if (event->button() == Qt::LeftButton && !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;
|
|
|
|
}
|
|
|
|
|
2009-07-16 15:09:19 +02:00
|
|
|
void ToolBox::setViewTransform(const QTransform &transform)
|
2008-11-28 18:32:21 +01:00
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
|
2009-06-11 22:04:10 +02:00
|
|
|
void ToolBox::load(const KConfigGroup &containmentGroup)
|
2008-11-14 08:28:02 +01:00
|
|
|
{
|
|
|
|
if (!d->movable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-11 22:04:10 +02:00
|
|
|
KConfigGroup group;
|
|
|
|
if (containmentGroup.isValid()) {
|
|
|
|
group = containmentGroup;
|
|
|
|
} else {
|
|
|
|
group = d->containment->config();
|
|
|
|
}
|
|
|
|
|
2008-11-14 08:28:02 +01:00
|
|
|
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-06-10 22:25:15 +02:00
|
|
|
setPos(avail.topLeft() - QPoint(0, avail.top()));
|
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-06-10 22:25:15 +02:00
|
|
|
setPos(avail.topRight() - QPoint(boundingRect().width(), -avail.top()));
|
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"
|
|
|
|
|