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.
|
|
|
|
*/
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
#include "internaltoolbox_p.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
#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
|
|
|
|
{
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
class InternalToolBoxPrivate
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
public:
|
2009-10-20 16:14:53 +02:00
|
|
|
InternalToolBoxPrivate(Containment *c)
|
2008-11-14 08:28:02 +01:00
|
|
|
: containment(c),
|
2009-10-20 16:14:53 +02:00
|
|
|
corner(InternalToolBox::TopRight),
|
2008-11-14 08:28:02 +01:00
|
|
|
size(50),
|
2009-02-15 17:35:52 +01:00
|
|
|
iconSize(KIconLoader::SizeMedium, KIconLoader::SizeMedium),
|
2008-11-14 08:28:02 +01:00
|
|
|
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;
|
2009-10-20 16:14:53 +02:00
|
|
|
InternalToolBox::Corner corner;
|
2008-11-04 00:08:39 +01:00
|
|
|
int size;
|
|
|
|
QSize iconSize;
|
2008-12-25 09:29:03 +01:00
|
|
|
QPoint dragStartRelative;
|
2008-11-28 18:32:21 +01:00
|
|
|
QTransform viewTransform;
|
2010-01-04 07:41:43 +01:00
|
|
|
QMultiMap<AbstractToolBox::ToolType, IconWidget *> tools;
|
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
|
|
|
};
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
InternalToolBox::InternalToolBox(Containment *parent)
|
|
|
|
: AbstractToolBox(parent),
|
|
|
|
d(new InternalToolBoxPrivate(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);
|
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
InternalToolBox::~InternalToolBox()
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
Containment *InternalToolBox::containment()
|
2009-10-07 19:08:44 +02:00
|
|
|
{
|
|
|
|
return d->containment;
|
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
QPoint InternalToolBox::toolPosition(int toolHeight)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2009-10-20 16:14:53 +02:00
|
|
|
switch (corner()) {
|
2008-11-04 00:08:39 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-04 07:41:43 +01:00
|
|
|
QMap<AbstractToolBox::ToolType, IconWidget *> InternalToolBox::tools() const
|
|
|
|
{
|
|
|
|
return d->tools;
|
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsWidget *InternalToolBox::toolParent()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
void InternalToolBox::addTool(QAction *action)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
if (!action) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-04 07:41:43 +01:00
|
|
|
foreach (IconWidget *tool, d->tools) {
|
2009-08-29 02:33:27 +02:00
|
|
|
//kDebug() << "checking tool" << child << child->data(ToolName);
|
2010-01-04 07:41:43 +01:00
|
|
|
if (tool->action() == action) {
|
2009-08-29 02:33:27 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-04 07:41:43 +01:00
|
|
|
Plasma::IconWidget *tool = new Plasma::IconWidget(toolParent());
|
2008-11-04 00:08:39 +01:00
|
|
|
|
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)));
|
2010-01-04 07:41:43 +01:00
|
|
|
|
|
|
|
ToolType type = AbstractToolBox::MiscTool;
|
|
|
|
if (!action->data().isNull() && action->data().type() == QVariant::Int) {
|
|
|
|
int t = action->data().toInt();
|
|
|
|
if (t >= 0 && t < AbstractToolBox::LastToolType) {
|
|
|
|
type = static_cast<AbstractToolBox::ToolType>(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
d->tools.insert(type, tool);
|
|
|
|
//kDebug() << "added tool" << type << action->text();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
void InternalToolBox::updateToolBox()
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
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-10-20 16:14:53 +02:00
|
|
|
void InternalToolBox::toolTriggered(bool)
|
2009-01-28 14:38:57 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
void InternalToolBox::removeTool(QAction *action)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2010-01-04 07:41:43 +01:00
|
|
|
QMutableMapIterator<ToolType, IconWidget *> it(d->tools);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
IconWidget *tool = it.value();
|
|
|
|
//kDebug() << "checking tool" << tool
|
2008-11-04 00:08:39 +01:00
|
|
|
if (tool && tool->action() == action) {
|
|
|
|
//kDebug() << "tool found!";
|
2009-03-20 01:23:21 +01:00
|
|
|
tool->deleteLater();
|
2010-01-04 07:41:43 +01:00
|
|
|
it.remove();
|
2008-11-04 00:08:39 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
int InternalToolBox::size() const
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
return d->size;
|
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
void InternalToolBox::setSize(const int newSize)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
d->size = newSize;
|
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
QSize InternalToolBox::iconSize() const
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
return d->iconSize;
|
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
void InternalToolBox::setIconSize(const QSize newSize)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
d->iconSize = newSize;
|
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
bool InternalToolBox::isShowing() const
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2009-04-24 21:28:37 +02:00
|
|
|
return d->showing;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
void InternalToolBox::setShowing(const bool show)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2010-01-04 07:41:43 +01:00
|
|
|
if (show) {
|
|
|
|
kDebug() << "showing";
|
|
|
|
showToolBox();
|
|
|
|
} else {
|
|
|
|
kDebug() << "hiding";
|
|
|
|
hideToolBox();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
d->showing = show;
|
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
void InternalToolBox::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
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-10-20 16:14:53 +02:00
|
|
|
QSize InternalToolBox::cornerSize() const
|
2009-07-28 05:19:33 +02:00
|
|
|
{
|
|
|
|
return boundingRect().size().toSize();
|
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
QSize InternalToolBox::fullWidth() const
|
2009-07-28 05:19:33 +02:00
|
|
|
{
|
|
|
|
return boundingRect().size().toSize();
|
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
QSize InternalToolBox::fullHeight() const
|
2009-07-28 05:19:33 +02:00
|
|
|
{
|
|
|
|
return boundingRect().size().toSize();
|
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
void InternalToolBox::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
2008-11-10 04:53:35 +01:00
|
|
|
{
|
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);
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
Corner newCorner = corner();
|
2008-11-10 04:53:35 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
if (newCorner != corner()) {
|
2008-11-10 04:53:35 +01:00
|
|
|
prepareGeometryChange();
|
2009-10-20 16:14:53 +02:00
|
|
|
setCorner(newCorner);
|
2008-11-10 04:53:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
setPos(x, y);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
void InternalToolBox::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
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();
|
2010-01-04 07:41:43 +01:00
|
|
|
return;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
bool InternalToolBox::isMovable() const
|
2008-11-10 04:53:35 +01:00
|
|
|
{
|
|
|
|
return d->movable;
|
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
void InternalToolBox::setIsMovable(bool movable)
|
2008-11-10 04:53:35 +01:00
|
|
|
{
|
|
|
|
d->movable = movable;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
bool InternalToolBox::isToolbar() const
|
2008-11-28 18:32:21 +01:00
|
|
|
{
|
|
|
|
return d->toolbar;
|
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
void InternalToolBox::setIsToolbar(bool toolbar)
|
2008-11-28 18:32:21 +01:00
|
|
|
{
|
|
|
|
d->toolbar = toolbar;
|
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
QTransform InternalToolBox::viewTransform() const
|
2008-11-28 18:32:21 +01:00
|
|
|
{
|
|
|
|
return d->viewTransform;
|
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
void InternalToolBox::setCorner(const Corner corner)
|
|
|
|
{
|
|
|
|
d->corner = corner;
|
|
|
|
}
|
|
|
|
|
|
|
|
InternalToolBox::Corner InternalToolBox::corner() const
|
|
|
|
{
|
|
|
|
return d->corner;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InternalToolBox::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
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
void InternalToolBox::save(KConfigGroup &cg) const
|
2008-11-14 08:28:02 +01:00
|
|
|
{
|
|
|
|
if (!d->movable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
KConfigGroup group(&cg, "ToolBox");
|
|
|
|
if (!d->userMoved) {
|
|
|
|
group.deleteGroup();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int offset = 0;
|
2009-10-20 16:14:53 +02:00
|
|
|
if (corner() == InternalToolBox::Left ||
|
|
|
|
corner() == InternalToolBox::Right) {
|
2008-11-14 08:28:02 +01:00
|
|
|
offset = y();
|
2009-10-20 16:14:53 +02:00
|
|
|
} else if (corner() == InternalToolBox::Top ||
|
|
|
|
corner() == InternalToolBox::Bottom) {
|
2008-11-14 08:28:02 +01:00
|
|
|
offset = x();
|
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
group.writeEntry("corner", int(corner()));
|
2008-11-14 08:28:02 +01:00
|
|
|
group.writeEntry("offset", offset);
|
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
void InternalToolBox::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;
|
2009-10-20 16:14:53 +02:00
|
|
|
setCorner(Corner(group.readEntry("corner", int(corner()))));
|
2008-11-14 08:28:02 +01:00
|
|
|
|
|
|
|
int offset = group.readEntry("offset", 0);
|
2009-10-20 16:14:53 +02:00
|
|
|
switch (corner()) {
|
|
|
|
case InternalToolBox::TopLeft:
|
2008-11-14 09:04:46 +01:00
|
|
|
setPos(0, 0);
|
|
|
|
break;
|
2009-10-20 16:14:53 +02:00
|
|
|
case InternalToolBox::Top:
|
2008-11-14 09:04:46 +01:00
|
|
|
setPos(offset, 0);
|
|
|
|
break;
|
2009-10-20 16:14:53 +02:00
|
|
|
case InternalToolBox::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;
|
2009-10-20 16:14:53 +02:00
|
|
|
case InternalToolBox::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;
|
2009-10-20 16:14:53 +02:00
|
|
|
case InternalToolBox::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;
|
2009-10-20 16:14:53 +02:00
|
|
|
case InternalToolBox::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;
|
2009-10-20 16:14:53 +02:00
|
|
|
case InternalToolBox::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;
|
2009-10-20 16:14:53 +02:00
|
|
|
case InternalToolBox::Left:
|
2008-11-14 09:04:46 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
void InternalToolBox::reposition()
|
2008-11-14 08:28:02 +01:00
|
|
|
{
|
|
|
|
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) {
|
2009-10-20 16:14:53 +02:00
|
|
|
setCorner(InternalToolBox::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);
|
2009-10-20 16:14:53 +02:00
|
|
|
setCorner(InternalToolBox::Left);
|
2008-11-14 08:28:02 +01:00
|
|
|
} else {
|
2008-11-18 01:12:05 +01:00
|
|
|
setPos(d->containment->geometry().width() - rect.width(),
|
|
|
|
d->containment->geometry().height() / 2 - rect.height() / 2);
|
2009-10-20 16:14:53 +02:00
|
|
|
setCorner(InternalToolBox::Right);
|
2008-11-14 08:28:02 +01:00
|
|
|
}
|
|
|
|
}
|
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()));
|
2009-10-20 16:14:53 +02:00
|
|
|
setCorner(InternalToolBox::Left);
|
2008-11-14 08:28:02 +01:00
|
|
|
} else if (avail.left() > screenGeom.left()) {
|
2009-03-05 23:15:06 +01:00
|
|
|
setPos(avail.topLeft() - QPoint(boundingRect().width(), 0));
|
2009-10-20 16:14:53 +02:00
|
|
|
setCorner(InternalToolBox::Top);
|
2008-11-14 08:28:02 +01:00
|
|
|
} else {
|
|
|
|
setPos(avail.topLeft());
|
2009-10-20 16:14:53 +02:00
|
|
|
setCorner(InternalToolBox::TopLeft);
|
2008-11-14 08:28:02 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (avail.top() > screenGeom.top()) {
|
2009-06-10 22:25:15 +02:00
|
|
|
setPos(avail.topRight() - QPoint(boundingRect().width(), -avail.top()));
|
2009-10-20 16:14:53 +02:00
|
|
|
setCorner(InternalToolBox::Right);
|
2008-11-14 08:28:02 +01:00
|
|
|
} else if (avail.right() < screenGeom.right()) {
|
2009-03-05 23:15:06 +01:00
|
|
|
setPos(avail.topRight() - QPoint(boundingRect().width(), 0));
|
2009-10-20 16:14:53 +02:00
|
|
|
setCorner(InternalToolBox::Top);
|
2008-11-14 08:28:02 +01:00
|
|
|
} else {
|
2009-03-05 23:15:06 +01:00
|
|
|
setPos(avail.topRight() - QPoint(boundingRect().width(), 0));
|
2009-10-20 16:14:53 +02:00
|
|
|
setCorner(InternalToolBox::TopRight);
|
2008-11-14 08:28:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
|
|
|
setPos(d->containment->mapFromScene(QPointF(d->containment->geometry().topLeft())));
|
2009-10-20 16:14:53 +02:00
|
|
|
setCorner(InternalToolBox::TopLeft);
|
2008-11-14 08:28:02 +01:00
|
|
|
} else {
|
|
|
|
setPos(d->containment->mapFromScene(QPointF(d->containment->geometry().topRight())));
|
2009-10-20 16:14:53 +02:00
|
|
|
setCorner(InternalToolBox::TopRight);
|
2008-11-14 08:28:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
} // plasma namespace
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
#include "internaltoolbox_p.moc"
|
2008-11-04 00:08:39 +01:00
|
|
|
|