load and save toolbox position between restarts!
still to come: * don't paint when zoomed, replace with tool strip instead * respect available area during drag * smarter positioning (right now it just loads the saved position whenever it needs to reposition) svn path=/trunk/KDE/kdelibs/; revision=884072
This commit is contained in:
parent
18885bd0f0
commit
d0c7968b18
@ -307,6 +307,10 @@ void Containment::save(KConfigGroup &g) const
|
|||||||
group.writeEntry("location", (int)d->location);
|
group.writeEntry("location", (int)d->location);
|
||||||
group.writeEntry("activity", d->context()->currentActivity());
|
group.writeEntry("activity", d->context()->currentActivity());
|
||||||
|
|
||||||
|
if (d->toolBox) {
|
||||||
|
d->toolBox->save(group);
|
||||||
|
}
|
||||||
|
|
||||||
if (d->wallpaper) {
|
if (d->wallpaper) {
|
||||||
group.writeEntry("wallpaperplugin", d->wallpaper->pluginName());
|
group.writeEntry("wallpaperplugin", d->wallpaper->pluginName());
|
||||||
group.writeEntry("wallpaperpluginmode", d->wallpaper->renderingMode().name());
|
group.writeEntry("wallpaperpluginmode", d->wallpaper->renderingMode().name());
|
||||||
@ -1476,6 +1480,7 @@ ToolBox *ContainmentPrivate::createToolBox()
|
|||||||
|
|
||||||
if (toolBox) {
|
if (toolBox) {
|
||||||
QObject::connect(toolBox, SIGNAL(toggled()), q, SIGNAL(toolBoxToggled()));
|
QObject::connect(toolBox, SIGNAL(toggled()), q, SIGNAL(toolBoxToggled()));
|
||||||
|
toolBox->load();
|
||||||
positionToolBox();
|
positionToolBox();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1485,73 +1490,8 @@ ToolBox *ContainmentPrivate::createToolBox()
|
|||||||
|
|
||||||
void ContainmentPrivate::positionToolBox()
|
void ContainmentPrivate::positionToolBox()
|
||||||
{
|
{
|
||||||
if (!toolBox) {
|
if (toolBox) {
|
||||||
return;
|
toolBox->reposition();
|
||||||
}
|
|
||||||
|
|
||||||
kDebug();
|
|
||||||
//The placement assumes that the geometry width/height is no more than the screen
|
|
||||||
if (type == Containment::PanelContainment) {
|
|
||||||
if (q->formFactor() == Vertical) {
|
|
||||||
toolBox->setCorner(ToolBox::Bottom);
|
|
||||||
toolBox->setPos(q->geometry().width() / 2 - toolBox->boundingRect().width() / 2,
|
|
||||||
q->geometry().height());
|
|
||||||
} else {
|
|
||||||
//defaulting to Horizontal right now
|
|
||||||
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
|
||||||
toolBox->setPos(q->geometry().left(),
|
|
||||||
q->geometry().height() / 2 - toolBox->boundingRect().height() / 2);
|
|
||||||
toolBox->setCorner(ToolBox::Left);
|
|
||||||
} else {
|
|
||||||
toolBox->setPos(q->geometry().width(),
|
|
||||||
q->geometry().height() / 2 - toolBox->boundingRect().height() / 2);
|
|
||||||
toolBox->setCorner(ToolBox::Right);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (q->corona()) {
|
|
||||||
kDebug() << "desktop";
|
|
||||||
|
|
||||||
QRectF avail = q->corona()->availableScreenRegion(screen).boundingRect();
|
|
||||||
QRectF screenGeom = q->corona()->screenGeometry(screen);
|
|
||||||
|
|
||||||
// Transform to the containment's coordinate system.
|
|
||||||
avail.translate(-screenGeom.topLeft());
|
|
||||||
screenGeom.moveTo(0, 0);
|
|
||||||
const int toolBoxSize = toolBox->size();
|
|
||||||
|
|
||||||
if (!q->view() || !q->view()->transform().isScaling()) {
|
|
||||||
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
|
||||||
if (avail.top() > screenGeom.top()) {
|
|
||||||
toolBox->setPos(avail.topLeft() - QPoint(0, toolBoxSize));
|
|
||||||
toolBox->setCorner(ToolBox::Left);
|
|
||||||
} else if (avail.left() > screenGeom.left()) {
|
|
||||||
toolBox->setPos(avail.topLeft() - QPoint(toolBoxSize, 0));
|
|
||||||
toolBox->setCorner(ToolBox::Top);
|
|
||||||
} else {
|
|
||||||
toolBox->setPos(avail.topLeft());
|
|
||||||
toolBox->setCorner(ToolBox::TopLeft);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (avail.top() > screenGeom.top()) {
|
|
||||||
toolBox->setPos(avail.topRight() - QPoint(0, toolBoxSize));
|
|
||||||
toolBox->setCorner(ToolBox::Right);
|
|
||||||
} else if (avail.right() < screenGeom.right()) {
|
|
||||||
toolBox->setPos(avail.topRight() - QPoint(toolBoxSize, 0));
|
|
||||||
toolBox->setCorner(ToolBox::Top);
|
|
||||||
} else {
|
|
||||||
toolBox->setPos(avail.topRight() - QPoint(toolBoxSize, 0));
|
|
||||||
toolBox->setCorner(ToolBox::TopRight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
|
||||||
toolBox->setPos(q->mapFromScene(QPointF(q->geometry().topLeft())));
|
|
||||||
toolBox->setCorner(ToolBox::TopLeft);
|
|
||||||
} else {
|
|
||||||
toolBox->setPos(q->mapFromScene(QPointF(q->geometry().topRight())));
|
|
||||||
toolBox->setCorner(ToolBox::TopRight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ public:
|
|||||||
bool hovering : 1;
|
bool hovering : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
DesktopToolBox::DesktopToolBox(QGraphicsItem *parent)
|
DesktopToolBox::DesktopToolBox(Containment *parent)
|
||||||
: ToolBox(parent),
|
: ToolBox(parent),
|
||||||
d(new DesktopToolBoxPrivate)
|
d(new DesktopToolBoxPrivate)
|
||||||
{
|
{
|
||||||
|
@ -43,7 +43,7 @@ class DesktopToolBox : public ToolBox
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DesktopToolBox(QGraphicsItem *parent = 0);
|
explicit DesktopToolBox(Containment *parent = 0);
|
||||||
~DesktopToolBox();
|
~DesktopToolBox();
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
QPainterPath shape() const;
|
QPainterPath shape() const;
|
||||||
|
@ -95,7 +95,7 @@ public:
|
|||||||
bool toggled;
|
bool toggled;
|
||||||
};
|
};
|
||||||
|
|
||||||
PanelToolBox::PanelToolBox(QGraphicsItem *parent)
|
PanelToolBox::PanelToolBox(Containment *parent)
|
||||||
: ToolBox(parent),
|
: ToolBox(parent),
|
||||||
d(new PanelToolBoxPrivate)
|
d(new PanelToolBoxPrivate)
|
||||||
{
|
{
|
||||||
|
@ -43,7 +43,7 @@ class PanelToolBox : public ToolBox
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit PanelToolBox(QGraphicsItem *parent = 0);
|
explicit PanelToolBox(Containment *parent);
|
||||||
~PanelToolBox();
|
~PanelToolBox();
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
QPainterPath shape() const;
|
QPainterPath shape() const;
|
||||||
|
@ -21,14 +21,18 @@
|
|||||||
#include "toolbox_p.h"
|
#include "toolbox_p.h"
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
#include <QApplication>
|
||||||
#include <QGraphicsSceneHoverEvent>
|
#include <QGraphicsSceneHoverEvent>
|
||||||
|
#include <QGraphicsView>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QRadialGradient>
|
#include <QRadialGradient>
|
||||||
|
|
||||||
#include <kcolorscheme.h>
|
#include <kcolorscheme.h>
|
||||||
|
#include <kconfiggroup.h>
|
||||||
#include <kdebug.h>
|
#include <kdebug.h>
|
||||||
|
|
||||||
#include <plasma/theme.h>
|
#include "corona.h"
|
||||||
|
#include "theme.h"
|
||||||
#include "widgets/iconwidget.h"
|
#include "widgets/iconwidget.h"
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
@ -37,16 +41,18 @@ namespace Plasma
|
|||||||
class ToolBoxPrivate
|
class ToolBoxPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ToolBoxPrivate()
|
ToolBoxPrivate(Containment *c)
|
||||||
: size(50),
|
: containment(c),
|
||||||
iconSize(32, 32),
|
size(50),
|
||||||
corner(ToolBox::TopRight),
|
iconSize(32, 32),
|
||||||
hidden(false),
|
corner(ToolBox::TopRight),
|
||||||
showing(false),
|
hidden(false),
|
||||||
movable(false),
|
showing(false),
|
||||||
dragging(false)
|
movable(false),
|
||||||
|
dragging(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
Containment *containment;
|
||||||
int size;
|
int size;
|
||||||
QSize iconSize;
|
QSize iconSize;
|
||||||
ToolBox::Corner corner;
|
ToolBox::Corner corner;
|
||||||
@ -55,11 +61,12 @@ public:
|
|||||||
bool showing : 1;
|
bool showing : 1;
|
||||||
bool movable : 1;
|
bool movable : 1;
|
||||||
bool dragging : 1;
|
bool dragging : 1;
|
||||||
|
bool userMoved : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
ToolBox::ToolBox(QGraphicsItem *parent)
|
ToolBox::ToolBox(Containment *parent)
|
||||||
: QGraphicsItem(parent),
|
: QGraphicsItem(parent),
|
||||||
d(new ToolBoxPrivate)
|
d(new ToolBoxPrivate(parent))
|
||||||
{
|
{
|
||||||
setAcceptsHoverEvents(true);
|
setAcceptsHoverEvents(true);
|
||||||
}
|
}
|
||||||
@ -194,6 +201,7 @@ void ToolBox::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
// sticky points at midpoints
|
// sticky points at midpoints
|
||||||
// change how buttons appear depending on the location of the box
|
// change how buttons appear depending on the location of the box
|
||||||
d->dragging = true;
|
d->dragging = true;
|
||||||
|
d->userMoved = true;
|
||||||
const QPoint newPos = mapToParent(event->pos()).toPoint();
|
const QPoint newPos = mapToParent(event->pos()).toPoint();
|
||||||
const QPoint curPos = pos().toPoint();
|
const QPoint curPos = pos().toPoint();
|
||||||
const int h = abs(boundingRect().height());
|
const int h = abs(boundingRect().height());
|
||||||
@ -284,6 +292,131 @@ void ToolBox::setIsMovable(bool movable)
|
|||||||
d->movable = movable;
|
d->movable = movable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
} else if (d->corner == ToolBox::Left ||
|
||||||
|
d->corner == ToolBox::Right) {
|
||||||
|
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);
|
||||||
|
if (d->corner == ToolBox::Left) {
|
||||||
|
setPos(0, offset);
|
||||||
|
} else if (d->corner == ToolBox::Right) {
|
||||||
|
setPos(d->containment->size().width() - d->size, offset);
|
||||||
|
} else if (d->corner == ToolBox::Top) {
|
||||||
|
setPos(offset, 0);
|
||||||
|
} else if (d->corner == ToolBox::Bottom) {
|
||||||
|
setPos(offset, d->containment->size().height() - d->size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ToolBox::reposition()
|
||||||
|
{
|
||||||
|
if (d->userMoved) {
|
||||||
|
//FIXME: adjust for situations like changing of the available space
|
||||||
|
load();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (d->containment->containmentType() == Containment::PanelContainment) {
|
||||||
|
if (d->containment->formFactor() == Vertical) {
|
||||||
|
setCorner(ToolBox::Bottom);
|
||||||
|
setPos(d->containment->geometry().width() / 2 - boundingRect().width() / 2,
|
||||||
|
d->containment->geometry().height());
|
||||||
|
} else {
|
||||||
|
//defaulting to Horizontal right now
|
||||||
|
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
||||||
|
setPos(d->containment->geometry().left(),
|
||||||
|
d->containment->geometry().height() / 2 - boundingRect().height() / 2);
|
||||||
|
setCorner(ToolBox::Left);
|
||||||
|
} else {
|
||||||
|
setPos(d->containment->geometry().width(),
|
||||||
|
d->containment->geometry().height() / 2 - boundingRect().height() / 2);
|
||||||
|
setCorner(ToolBox::Right);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (d->containment->corona()) {
|
||||||
|
//kDebug() << "desktop";
|
||||||
|
|
||||||
|
int screen = d->containment->screen();
|
||||||
|
QRectF avail = d->containment->corona()->availableScreenRegion(screen).boundingRect();
|
||||||
|
QRectF screenGeom = d->containment->corona()->screenGeometry(screen);
|
||||||
|
|
||||||
|
// Transform to the containment's coordinate system.
|
||||||
|
avail.translate(-screenGeom.topLeft());
|
||||||
|
screenGeom.moveTo(0, 0);
|
||||||
|
|
||||||
|
if (!d->containment->view() || !d->containment->view()->transform().isScaling()) {
|
||||||
|
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
||||||
|
if (avail.top() > screenGeom.top()) {
|
||||||
|
setPos(avail.topLeft() - QPoint(0, d->size));
|
||||||
|
setCorner(ToolBox::Left);
|
||||||
|
} else if (avail.left() > screenGeom.left()) {
|
||||||
|
setPos(avail.topLeft() - QPoint(d->size, 0));
|
||||||
|
setCorner(ToolBox::Top);
|
||||||
|
} else {
|
||||||
|
setPos(avail.topLeft());
|
||||||
|
setCorner(ToolBox::TopLeft);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (avail.top() > screenGeom.top()) {
|
||||||
|
setPos(avail.topRight() - QPoint(0, d->size));
|
||||||
|
setCorner(ToolBox::Right);
|
||||||
|
} else if (avail.right() < screenGeom.right()) {
|
||||||
|
setPos(avail.topRight() - QPoint(d->size, 0));
|
||||||
|
setCorner(ToolBox::Top);
|
||||||
|
} else {
|
||||||
|
setPos(avail.topRight() - QPoint(d->size, 0));
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // plasma namespace
|
} // plasma namespace
|
||||||
|
|
||||||
#include "toolbox_p.moc"
|
#include "toolbox_p.moc"
|
||||||
|
@ -24,10 +24,12 @@
|
|||||||
#include <QGraphicsItem>
|
#include <QGraphicsItem>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
#include "animator.h"
|
#include "containment.h"
|
||||||
|
|
||||||
class QAction;
|
class QAction;
|
||||||
|
|
||||||
|
class KConfigGroup;
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -54,7 +56,7 @@ public:
|
|||||||
BottomLeft
|
BottomLeft
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit ToolBox(QGraphicsItem *parent = 0);
|
explicit ToolBox(Containment *parent);
|
||||||
~ToolBox();
|
~ToolBox();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,6 +80,10 @@ public:
|
|||||||
bool isMovable() const;
|
bool isMovable() const;
|
||||||
void setIsMovable(bool movable);
|
void setIsMovable(bool movable);
|
||||||
|
|
||||||
|
void save(KConfigGroup &cg) const;
|
||||||
|
void load();
|
||||||
|
void reposition();
|
||||||
|
|
||||||
virtual void showToolBox() = 0;
|
virtual void showToolBox() = 0;
|
||||||
virtual void hideToolBox() = 0;
|
virtual void hideToolBox() = 0;
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
|
Loading…
Reference in New Issue
Block a user