Commit 72d501bf authored by Jan Hambrecht's avatar Jan Hambrecht

make handle radius and grab sensitivity application wide settings

changes the scope of handle radius and grab sensitivity from per canvas
to per application, i.e. the are shared via the shape controllers
resource manager. added some convenience methods to KoToolBase and
KoInteractionStrategy to have fewer places where these settings are
pulle from the proper resource manager.
both settings are now correctly read and saved to the applications
config file.
parent de3f7efd
......@@ -129,13 +129,13 @@ void KoResourceManager::setHandleRadius(int handleRadius)
// do not allow arbitrary small handles
if (handleRadius < 3)
handleRadius = 3;
setResource(KoCanvasResource::HandleRadius, QVariant(handleRadius));
setResource(KoDocumentResource::HandleRadius, QVariant(handleRadius));
}
int KoResourceManager::handleRadius() const
{
if (d->resources.contains(KoCanvasResource::HandleRadius))
return d->resources.value(KoCanvasResource::HandleRadius).toInt();
if (d->resources.contains(KoDocumentResource::HandleRadius))
return d->resources.value(KoDocumentResource::HandleRadius).toInt();
return 3; // default value.
}
......@@ -149,12 +149,12 @@ void KoResourceManager::setGrabSensitivity(int grabSensitivity)
// do not allow arbitrary small handles
if (grabSensitivity < 1)
grabSensitivity = 1;
setResource(KoCanvasResource::GrabSensitivity, QVariant(grabSensitivity));
setResource(KoDocumentResource::GrabSensitivity, QVariant(grabSensitivity));
}
int KoResourceManager::grabSensitivity() const
{
return resource(KoCanvasResource::GrabSensitivity).toInt();
return resource(KoDocumentResource::GrabSensitivity).toInt();
}
void KoResourceManager::setPasteOffset(qreal pasteOffset)
......
......@@ -53,8 +53,6 @@ enum CanvasResource {
ForegroundColor, ///< The active forground color selected for this canvas.
BackgroundColor, ///< The active background color selected for this canvas.
ActiveBorder, ///< The active border selected for this canvas
HandleRadius, ///< The handle radius used for drawing handles of any kind
GrabSensitivity, ///< The grab sensitivity used for grabbing handles of any kind
PageSize, ///< The size of the (current) page in postscript points.
Unit, ///< The unit of this canvas
CurrentPage, ///< The current page number
......@@ -89,6 +87,8 @@ enum DocumentResource {
OdfDocument, ///< The document this canvas shows (KoOdfDocument)
PasteOffset, ///< Application wide paste offset
PasteAtCursor, ///< Application wide paste at cursor setting
HandleRadius, ///< The handle radius used for drawing handles of any kind
GrabSensitivity, ///< The grab sensitivity used for grabbing handles of any kind
KarbonStart = 1000, ///< Base number for karbon specific values.
KexiStart = 2000, ///< Base number for kexi specific values.
......
......@@ -44,6 +44,10 @@ public:
resourceManager->setPasteOffset(pasteOffset);
const bool pasteAtCursor = miscGroup.readEntry("PasteAtCursor", true);
resourceManager->enablePasteAtCursor(pasteAtCursor);
const uint grabSensitivity = miscGroup.readEntry("GrabSensitivity", 3);
resourceManager->setGrabSensitivity(grabSensitivity);
const uint handleRadius = miscGroup.readEntry("HandleRadius", 3);
resourceManager->setHandleRadius(handleRadius);
}
}
......
......@@ -23,6 +23,7 @@
#include "KoPointerEvent.h"
#include "KoResourceManager.h"
#include "KoViewConverter.h"
#include "KoShapeController.h"
#include <klocale.h>
#include <kactioncollection.h>
......@@ -34,9 +35,14 @@ KoToolBase::KoToolBase(KoCanvasBase *canvas)
Q_D(KoToolBase);
if (d->canvas) { // in the case of KoToolManagers dummytool it can be zero :(
KoResourceManager * crp = d->canvas->resourceManager();
Q_ASSERT_X(crp, "KoToolBase::KoToolBase", "No KoResourceManager");
Q_ASSERT_X(crp, "KoToolBase::KoToolBase", "No Canvas KoResourceManager");
if (crp)
connect(d->canvas->resourceManager(), SIGNAL(resourceChanged(int, const QVariant &)),
connect(crp, SIGNAL(resourceChanged(int, const QVariant &)),
this, SLOT(resourceChanged(int, const QVariant &)));
KoResourceManager *scrm = d->canvas->shapeController()->resourceManager();
Q_ASSERT_X(scrm, "KoToolBase::KoToolBase", "No Document KoResourceManager");
if (scrm)
connect(scrm, SIGNAL(resourceChanged(int, const QVariant &)),
this, SLOT(resourceChanged(int, const QVariant &)));
}
}
......@@ -228,11 +234,23 @@ void KoToolBase::setStatusText(const QString &statusText)
emit statusTextChanged(statusText);
}
uint KoToolBase::handleRadius() const
{
Q_D(const KoToolBase);
return d->canvas->shapeController()->resourceManager()->handleRadius();
}
uint KoToolBase::grabSensitivity() const
{
Q_D(const KoToolBase);
return d->canvas->shapeController()->resourceManager()->grabSensitivity();
}
QRectF KoToolBase::handleGrabRect(const QPointF &position) const
{
Q_D(const KoToolBase);
const KoViewConverter * converter = d->canvas->viewConverter();
uint handleSize = 2*d->canvas->resourceManager()->grabSensitivity();
uint handleSize = 2*grabSensitivity();
QRectF r = converter->viewToDocument(QRectF(0, 0, handleSize, handleSize));
r.moveCenter(position);
return r;
......@@ -242,7 +260,7 @@ QRectF KoToolBase::handlePaintRect(const QPointF &position) const
{
Q_D(const KoToolBase);
const KoViewConverter * converter = d->canvas->viewConverter();
uint handleSize = 2*d->canvas->resourceManager()->handleRadius();
uint handleSize = 2*handleRadius();
QRectF r = converter->viewToDocument(QRectF(0, 0, handleSize, handleSize));
r.moveCenter(position);
return r;
......
......@@ -400,6 +400,12 @@ protected:
*/
void setPopupActionList(const QList<QAction*> &list);
/// Convenience function to get the current handle radius
uint handleRadius() const;
/// Convencience function to get the current grab sensitivity
uint grabSensitivity() const;
/**
* Returns a handle grab rect at the given position.
*
......
......@@ -291,7 +291,7 @@ void KoCreatePathTool::activate(ToolActivation, const QSet<KoShape*> &)
useCursor(Qt::ArrowCursor);
// retrieve the actual global handle radius
d->handleRadius = canvas()->resourceManager()->handleRadius();
d->handleRadius = handleRadius();
// reset snap guide
canvas()->updateCanvas(canvas()->snapGuide()->boundingRect());
......@@ -316,7 +316,7 @@ void KoCreatePathTool::resourceChanged(int key, const QVariant & res)
Q_D(KoCreatePathTool);
switch (key) {
case KoCanvasResource::HandleRadius: {
case KoDocumentResource::HandleRadius: {
d->handleRadius = res.toUInt();
}
break;
......
......@@ -248,7 +248,7 @@ public:
KoPathPoint * nearestPoint = 0;
qreal minDistance = HUGE_VAL;
uint grabSensitivity = q->canvas()->resourceManager()->grabSensitivity();
uint grabSensitivity = q->grabSensitivity();
qreal maxDistance = q->canvas()->viewConverter()->viewToDocumentX(grabSensitivity);
foreach(KoShape *shape, shapes) {
......
......@@ -19,6 +19,9 @@
#include "KoInteractionStrategy.h"
#include "KoInteractionStrategy_p.h"
#include "KoCanvasBase.h"
#include "KoShapeController.h"
#include "KoResourceManager.h"
#include <QUndoCommand>
......@@ -61,3 +64,13 @@ KoToolBase *KoInteractionStrategy::tool() const
Q_D(const KoInteractionStrategy);
return d->tool;
}
uint KoInteractionStrategy::handleRadius() const
{
return tool()->canvas()->shapeController()->resourceManager()->handleRadius();
}
uint KoInteractionStrategy::grabSensitivity() const
{
return tool()->canvas()->shapeController()->resourceManager()->grabSensitivity();
}
......@@ -98,6 +98,12 @@ protected:
KoInteractionStrategyPrivate *d_ptr;
/// Convenience function to get the global handle radius
uint handleRadius() const;
/// Cenvenience function to get the global grab sensitivity
uint grabSensitivity() const;
private:
Q_DECLARE_PRIVATE(KoInteractionStrategy)
};
......
......@@ -48,6 +48,7 @@
#include "PathToolOptionWidget.h"
#include "KoConnectionShape.h"
#include "KoSnapGuide.h"
#include "KoShapeController.h"
#include <KAction>
#include <KIcon>
......@@ -660,12 +661,13 @@ void KoPathTool::keyPressEvent(QKeyEvent *event)
switch (event->key()) {
// TODO move these to the actions in the constructor.
case Qt::Key_I: {
int handleRadius = d->canvas->resourceManager()->handleRadius();
KoResourceManager *rm = d->canvas->shapeController()->resourceManager();
int handleRadius = rm->handleRadius();
if (event->modifiers() & Qt::ControlModifier)
handleRadius--;
else
handleRadius++;
d->canvas->resourceManager()->setHandleRadius(handleRadius);
rm->setHandleRadius(handleRadius);
break;
}
#ifndef NDEBUG
......@@ -839,7 +841,7 @@ void KoPathTool::activate(ToolActivation toolActivation, const QSet<KoShape*> &s
Q_D(KoToolBase);
Q_UNUSED(toolActivation);
// retrieve the actual global handle radius
m_handleRadius = d->canvas->resourceManager()->handleRadius();
m_handleRadius = handleRadius();
d->canvas->snapGuide()->reset();
repaintDecorations();
......@@ -937,7 +939,7 @@ void KoPathTool::deactivate()
void KoPathTool::resourceChanged(int key, const QVariant & res)
{
if (key == KoCanvasResource::HandleRadius) {
if (key == KoDocumentResource::HandleRadius) {
int oldHandleRadius = m_handleRadius;
m_handleRadius = res.toUInt();
......
......@@ -35,6 +35,7 @@
#include "KoConnectionShape.h"
#include "KoViewConverter.h"
#include "KoPointerEvent.h"
#include "KoShapeController.h"
#include <QtGui/QPainter>
KoPathToolHandle::KoPathToolHandle(KoPathTool *tool)
......@@ -46,6 +47,11 @@ KoPathToolHandle::~KoPathToolHandle()
{
}
uint KoPathToolHandle::handleRadius() const
{
return m_tool->canvas()->shapeController()->resourceManager()->handleRadius();
}
PointHandle::PointHandle(KoPathTool *tool, KoPathPoint *activePoint, KoPathPoint::PointType activePointType)
: KoPathToolHandle(tool)
, m_activePoint(activePoint)
......@@ -64,8 +70,7 @@ void PointHandle::paint(QPainter &painter, const KoViewConverter &converter)
KoPathPoint::PointType type = KoPathPoint::Node;
if (selection && selection->contains(m_activePoint))
type = KoPathPoint::All;
int handleRadius = m_tool->canvas()->resourceManager()->handleRadius();
m_activePoint->paint(painter, handleRadius, type);
m_activePoint->paint(painter, handleRadius(), type);
painter.restore();
}
......@@ -158,8 +163,7 @@ void ParameterHandle::paint(QPainter &painter, const KoViewConverter &converter)
painter.save();
painter.setTransform(m_parameterShape->absoluteTransformation(&converter) * painter.transform());
int handleRadius = m_tool->canvas()->resourceManager()->handleRadius();
m_parameterShape->paintHandle(painter, converter, m_handleId, handleRadius);
m_parameterShape->paintHandle(painter, converter, m_handleId, handleRadius());
painter.restore();
}
......
......@@ -47,6 +47,7 @@ public:
virtual bool check(const QList<KoPathShape*> &selectedShapes) = 0;
protected:
uint handleRadius() const;
KoPathTool *m_tool;
};
......
......@@ -28,6 +28,7 @@
#include <KoViewConverter.h>
#include <KoCanvasBase.h>
#include <KoResourceManager.h>
#include <KoShapeController.h>
#include <QtGui/QPainter>
KoPathToolSelection::KoPathToolSelection(KoPathTool * tool)
......@@ -41,7 +42,7 @@ KoPathToolSelection::~KoPathToolSelection()
void KoPathToolSelection::paint(QPainter &painter, const KoViewConverter &converter)
{
int handleRadius = m_tool->canvas()->resourceManager()->handleRadius();
int handleRadius = m_tool->canvas()->shapeController()->resourceManager()->handleRadius();
PathShapePointMap::iterator it(m_shapePointMap.begin());
for (; it != m_shapePointMap.end(); ++it) {
......
......@@ -68,18 +68,11 @@ KoConfigMiscPage::KoConfigMiscPage(KoDocument* doc, KoResourceManager *documentR
d->config = d->doc->componentData().config();
d->oldGrabSensitivity = 3;
d->oldHandleRadius = 3;
d->oldGrabSensitivity = d->docResources->grabSensitivity();
d->oldHandleRadius = d->docResources->handleRadius();
d->oldPasteOffset = d->docResources->pasteOffset();
d->oldPasteAtCursor = d->docResources->pasteAtCursor();
if (d->config->hasGroup("Misc")) {
KConfigGroup miscGroup = d->config->group("Misc");
d->oldGrabSensitivity = miscGroup.readEntry("GrabSensitivity", d->oldGrabSensitivity);
d->oldHandleRadius = miscGroup.readEntry("HandleRadius", d->oldHandleRadius);
}
KoUnit unit = d->doc->unit();
QGroupBox* tmpQGroupBox = new QGroupBox(i18n("Misc"), this);
......@@ -159,11 +152,13 @@ void KoConfigMiscPage::apply()
uint currentHandleRadius = d->handleRadius->value();
if (currentHandleRadius != d->oldHandleRadius) {
miscGroup.writeEntry( "HandleRadius", currentHandleRadius );
d->docResources->setHandleRadius(currentHandleRadius);
}
uint currentGrabSensitivity = d->grabSensitivity->value();
if (currentGrabSensitivity != d->oldGrabSensitivity) {
miscGroup.writeEntry("GrabSensitivity", currentGrabSensitivity);
d->docResources->setGrabSensitivity(currentGrabSensitivity);
}
qreal currentCopyOffset = d->pasteOffset->value();
......@@ -177,8 +172,6 @@ void KoConfigMiscPage::apply()
miscGroup.writeEntry("PasteAtCursor", currentPasteAtCursor);
d->docResources->enablePasteAtCursor(currentPasteAtCursor);
}
// FIXME how is the handle radius and grap sensitivitiy set?
}
void KoConfigMiscPage::slotDefault()
......
......@@ -166,7 +166,7 @@ void ConnectionTool::paint(QPainter &painter, const KoViewConverter &converter)
// on the shape the mouse is currently
KoConnectionShape *connectionShape = dynamic_cast<KoConnectionShape*>(m_currentShape);
if (connectionShape) {
int radius = canvas()->resourceManager()->handleRadius();
int radius = handleRadius();
int handleCount = connectionShape->handleCount();
for(int i = 0; i < handleCount; ++i) {
painter.save();
......@@ -198,7 +198,7 @@ void ConnectionTool::paint(QPainter &painter, const KoViewConverter &converter)
void ConnectionTool::repaintDecorations()
{
if (m_currentShape) {
const qreal radius = canvas()->resourceManager()->handleRadius();
const qreal radius = handleRadius();
QRectF repaintRect = m_currentShape->boundingRect();
canvas()->updateCanvas(repaintRect.adjusted(-radius, -radius, radius, radius));
......@@ -353,9 +353,9 @@ void ConnectionTool::mouseReleaseEvent(KoPointerEvent *event)
// get both handle positions in document coordinates
QPointF p1 = connectionShape->shapeToDocument(connectionShape->handlePosition(0));
QPointF p2 = connectionShape->shapeToDocument(connectionShape->handlePosition(1));
int grabSensitivity = canvas()->resourceManager()->grabSensitivity();
int grabDistance = grabSensitivity();
// use grabbing sensitivity as minimal distance threshold
if (squareDistance(p1, p2) < grabSensitivity*grabSensitivity) {
if (squareDistance(p1, p2) < grabDistance*grabDistance) {
// minimal distance was not reached, so we have to undo the started work:
// - cleanup and delete the strategy
// - remove connection shape from shape manager and delete it
......@@ -477,7 +477,7 @@ int ConnectionTool::handleAtPoint(KoShape *shape, const QPointF &mousePoint) con
return connectionShape->handleIdAt(handleGrabRect(shapePoint));
} else {
// check connection points
int grabSensitivity = canvas()->resourceManager()->grabSensitivity();
int grabDistance = grabSensitivity();
qreal minDistance = HUGE_VAL;
int handleId = -1;
KoConnectionPoints connectionPoints = shape->connectionPoints();
......@@ -485,7 +485,7 @@ int ConnectionTool::handleAtPoint(KoShape *shape, const QPointF &mousePoint) con
KoConnectionPoints::const_iterator lastCp = connectionPoints.constEnd();
for(; cp != lastCp; ++cp) {
qreal d = squareDistance(shapePoint, cp.value().position);
if (d <= grabSensitivity && d < minDistance) {
if (d <= grabDistance && d < minDistance) {
handleId = cp.key();
minDistance = d;
}
......@@ -496,11 +496,11 @@ int ConnectionTool::handleAtPoint(KoShape *shape, const QPointF &mousePoint) con
KoConnectionShape * ConnectionTool::nearestConnectionShape(const QList<KoShape*> &shapes, const QPointF &mousePos) const
{
int grabSensitivity = canvas()->resourceManager()->grabSensitivity();
int grabDistance = grabSensitivity();
KoConnectionShape * nearestConnectionShape = 0;
qreal minSquaredDistance = HUGE_VAL;
const qreal maxSquaredDistance = grabSensitivity*grabSensitivity;
const qreal maxSquaredDistance = grabDistance*grabDistance;
foreach(KoShape *shape, shapes) {
KoConnectionShape * connectionShape = dynamic_cast<KoConnectionShape*>(shape);
......
......@@ -59,7 +59,7 @@ void MoveConnectionPointStrategy::finishInteraction(Qt::KeyboardModifiers /*modi
QUndoCommand* MoveConnectionPointStrategy::createCommand()
{
int grabDistance = tool()->canvas()->resourceManager()->grabSensitivity();
int grabDistance = grabSensitivity();
const qreal dx = m_newPoint.position.x()-m_oldPoint.position.x();
const qreal dy = m_newPoint.position.y()-m_oldPoint.position.y();
// check if we have moved the connection point at least a little bit
......
......@@ -487,7 +487,7 @@ void DefaultTool::paint(QPainter &painter, const KoViewConverter &converter)
SelectionDecorator decorator(m_mouseWasInsideHandles ? m_lastHandle : KoFlake::NoHandle,
true, true);
decorator.setSelection(koSelection());
decorator.setHandleRadius(canvas()->resourceManager()->handleRadius());
decorator.setHandleRadius(handleRadius());
decorator.setHotPosition(m_hotPosition);
decorator.paint(painter, converter);
}
......@@ -555,8 +555,7 @@ void DefaultTool::selectGuideAtPosition(const QPointF &position)
// check if we are on a guide line
KoGuidesData * guidesData = canvas()->guidesData();
if (guidesData && guidesData->showGuideLines()) {
qreal grabSensitivity = canvas()->resourceManager()->grabSensitivity();
qreal minDistance = canvas()->viewConverter()->viewToDocumentX(grabSensitivity);
qreal minDistance = canvas()->viewConverter()->viewToDocumentX(grabSensitivity());
uint i = 0;
foreach (qreal guidePos, guidesData->horizontalGuideLines()) {
qreal distance = qAbs(guidePos - position.y());
......
......@@ -129,6 +129,6 @@ void ShapeMoveStrategy::paint( QPainter &painter, const KoViewConverter &convert
{
SelectionDecorator decorator (KoFlake::NoHandle, false, false);
decorator.setSelection(tool()->canvas()->shapeManager()->selection());
decorator.setHandleRadius( tool()->canvas()->resourceManager()->handleRadius() );
decorator.setHandleRadius(handleRadius());
decorator.paint(painter, converter);
}
......@@ -247,6 +247,6 @@ void ShapeResizeStrategy::paint( QPainter &painter, const KoViewConverter &conve
{
SelectionDecorator decorator (KoFlake::NoHandle, false, false);
decorator.setSelection(tool()->canvas()->shapeManager()->selection());
decorator.setHandleRadius( tool()->canvas()->resourceManager()->handleRadius() );
decorator.setHandleRadius(handleRadius());
decorator.paint(painter, converter);
}
......@@ -126,7 +126,7 @@ void ShapeRotateStrategy::rotateBy( qreal angle )
void ShapeRotateStrategy::paint( QPainter &painter, const KoViewConverter &converter) {
SelectionDecorator decorator(KoFlake::NoHandle, true, false);
decorator.setSelection(tool()->canvas()->shapeManager()->selection());
decorator.setHandleRadius( tool()->canvas()->resourceManager()->handleRadius() );
decorator.setHandleRadius(handleRadius());
decorator.paint(painter, converter);
// paint the rotation center
......
......@@ -168,7 +168,7 @@ void ShapeShearStrategy::handleMouseMove(const QPointF &point, Qt::KeyboardModif
void ShapeShearStrategy::paint( QPainter &painter, const KoViewConverter &converter) {
SelectionDecorator decorator(KoFlake::NoHandle, true, false);
decorator.setSelection(tool()->canvas()->shapeManager()->selection());
decorator.setHandleRadius( tool()->canvas()->resourceManager()->handleRadius() );
decorator.setHandleRadius(handleRadius());
decorator.paint(painter, converter);
}
......
......@@ -341,8 +341,7 @@ GuidesTool::GuideLine GuidesTool::guideLineAtPosition(const QPointF &position)
// check if we are on a guide line
KoGuidesData *guidesData = canvas()->guidesData();
if (guidesData && guidesData->showGuideLines()) {
qreal handleRadius = canvas()->resourceManager()->handleRadius();
qreal minDistance = canvas()->viewConverter()->viewToDocumentX(handleRadius);
qreal minDistance = canvas()->viewConverter()->viewToDocumentX(handleRadius());
int i = 0;
foreach (qreal guidePos, guidesData->horizontalGuideLines()) {
qreal distance = qAbs(guidePos - position.y());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment