Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 79e76e73 authored by Jan Hambrecht's avatar Jan Hambrecht

Add some signals to KoTool and KoToolManager so that

tools can send a status text which can be displayed
i.e. in the status bar to help the user use the tools.
The default tool is a showcase of that functionality.


svn path=/trunk/koffice/; revision=850187
parent bb4304bf
......@@ -210,4 +210,9 @@ KoCanvasBase * KoTool::canvas() const
return m_canvas;
}
void KoTool::setStatusText( const QString &statusText )
{
emit statusTextChanged( statusText );
}
#include "KoTool.moc"
......@@ -302,6 +302,11 @@ public slots:
*/
virtual void resourceChanged( int key, const QVariant & res );
/**
* This method just relays the given text via the tools statusTextChanged signal.
* @param statusText the new status text
*/
void setStatusText( const QString &statusText );
signals:
......@@ -340,6 +345,12 @@ signals:
*/
void selectionChanged(bool hasSelection);
/**
* Emitted when the tool wants to display a different status text
* @param statusText the new status text
*/
void statusTextChanged( const QString &statusText );
protected:
/**
* Classes inheriting from this one can call this method to signify which cursor
......
......@@ -325,6 +325,8 @@ void KoToolManager::switchTool(KoTool *tool, bool temporary) {
disconnect(d->canvasData->activeTool, SIGNAL(activateTemporary(const QString &)),
this, SLOT(switchToolTemporaryRequested(const QString &)));
disconnect(d->canvasData->activeTool, SIGNAL(done()), this, SLOT(switchBackRequested()));
disconnect(d->canvasData->activeTool, SIGNAL(statusTextChanged(const QString &)),
this, SIGNAL(changedStatusText(const QString &)) );
}
d->canvasData->activeTool = tool;
......@@ -335,6 +337,11 @@ void KoToolManager::switchTool(KoTool *tool, bool temporary) {
connect(d->canvasData->activeTool, SIGNAL(activateTemporary(const QString &)),
this, SLOT(switchToolTemporaryRequested(const QString &)));
connect(d->canvasData->activeTool, SIGNAL(done()), this, SLOT(switchBackRequested()));
connect(d->canvasData->activeTool, SIGNAL(statusTextChanged(const QString &)),
this, SIGNAL(changedStatusText(const QString &)) );
// emit a empty status text to clear status text from last active tool
emit changedStatusText( "" );
// we expect the tool to emit a cursor on activation. This is for quick-fail :)
d->canvasData->canvas->canvas()->canvasWidget()->setCursor(Qt::ForbiddenCursor);
......
......@@ -213,6 +213,12 @@ signals:
*/
void changedCanvas( const KoCanvasBase * canvas );
/**
* Emitted whenever the active tool changes the status text.
* @param statusText the new status text
*/
void changedStatusText( const QString &statusText );
protected:
friend class KoToolProxy;
/**
......
......@@ -47,6 +47,10 @@ KoInteractionStrategy::KoInteractionStrategy(KoTool *parent, KoCanvasBase *canva
{
}
KoInteractionStrategy::~KoInteractionStrategy()
{
m_parent->setStatusText( "" );
}
void KoInteractionStrategy::applyGrid(QPointF &point) {
// The 1e-10 here is a workaround for some weird division problem.
......
......@@ -49,7 +49,7 @@ class FLAKE_EXPORT KoInteractionStrategy
{
public:
/// Destructor
virtual ~KoInteractionStrategy() {}
virtual ~KoInteractionStrategy();
/**
* Reimplement this if the action needs to draw a "blob" on the canvas;
......
......@@ -376,6 +376,8 @@ double DefaultTool::rotationOfHandle( KoFlake::SelectionHandle handle, bool useE
void DefaultTool::updateCursor() {
QCursor cursor = Qt::ArrowCursor;
QString statusText;
if(koSelection()->count() > 0) { // has a selection
bool editable=false;
// check if we have at least one shape that is edtiable
......@@ -390,80 +392,111 @@ void DefaultTool::updateCursor() {
m_angle = rotationOfHandle( m_lastHandle, true );
int rotOctant = 8 + int(8.5 + m_angle / 45);
bool rotateHandle = false;
bool shearHandle = false;
switch(m_lastHandle) {
case KoFlake::TopMiddleHandle:
cursor = m_shearCursors[(0 +rotOctant)%8];
shearHandle = true;
break;
case KoFlake::TopRightHandle:
cursor = m_rotateCursors[(1 +rotOctant)%8];
rotateHandle = true;
break;
case KoFlake::RightMiddleHandle:
cursor = m_shearCursors[(2 +rotOctant)%8];
shearHandle = true;
break;
case KoFlake::BottomRightHandle:
cursor = m_rotateCursors[(3 +rotOctant)%8];
rotateHandle = true;
break;
case KoFlake::BottomMiddleHandle:
cursor = m_shearCursors[(4 +rotOctant)%8];
shearHandle = true;
break;
case KoFlake::BottomLeftHandle:
cursor = m_rotateCursors[(5 +rotOctant)%8];
rotateHandle = true;
break;
case KoFlake::LeftMiddleHandle:
cursor = m_shearCursors[(6 +rotOctant)%8];
shearHandle = true;
break;
case KoFlake::TopLeftHandle:
cursor = m_rotateCursors[(7 +rotOctant)%8];
rotateHandle = true;
break;
case KoFlake::NoHandle:
if( m_guideLine->isValid() )
{
cursor = m_guideLine->orientation() == Qt::Horizontal ? Qt::SizeVerCursor : Qt::SizeHorCursor;
statusText = i18n( "Click and drag to move guide line." );
}
else
cursor = Qt::ArrowCursor;
break;
}
}
if( rotateHandle )
statusText = i18n("Left click rotates around center, right click around highlighted position.");
if( shearHandle )
statusText = i18n("Click and drag to shear selection.");
}
else {
statusText = i18n( "Click and drag to resize selection." );
m_angle = rotationOfHandle( m_lastHandle, false );
int rotOctant = 8 + int(8.5 + m_angle / 45);
bool cornerHandle = false;
switch(m_lastHandle) {
case KoFlake::TopMiddleHandle:
cursor = m_sizeCursors[(0 +rotOctant)%8];
break;
case KoFlake::TopRightHandle:
cursor = m_sizeCursors[(1 +rotOctant)%8];
cornerHandle = true;
break;
case KoFlake::RightMiddleHandle:
cursor = m_sizeCursors[(2 +rotOctant)%8];
break;
case KoFlake::BottomRightHandle:
cursor = m_sizeCursors[(3 +rotOctant)%8];
cornerHandle = true;
break;
case KoFlake::BottomMiddleHandle:
cursor = m_sizeCursors[(4 +rotOctant)%8];
break;
case KoFlake::BottomLeftHandle:
cursor = m_sizeCursors[(5 +rotOctant)%8];
cornerHandle = true;
break;
case KoFlake::LeftMiddleHandle:
cursor = m_sizeCursors[(6 +rotOctant)%8];
break;
case KoFlake::TopLeftHandle:
cursor = m_sizeCursors[(7 +rotOctant)%8];
cornerHandle = true;
break;
case KoFlake::NoHandle:
cursor = Qt::SizeAllCursor;
statusText = i18n( "Click and drag to move selection." );
break;
}
if( cornerHandle )
statusText = i18n( "Click and drag to resize selection. Middle click to set highlighted position." );
}
if( !editable)
cursor = Qt::ArrowCursor;
}
else {
if( m_guideLine->isValid() )
{
cursor = m_guideLine->orientation() == Qt::Horizontal ? Qt::SizeVerCursor : Qt::SizeHorCursor;
statusText = i18n( "Click and drag to move guide line." );
}
}
useCursor(cursor);
if( ! m_currentStrategy )
emit statusTextChanged( statusText );
}
void DefaultTool::paint( QPainter &painter, const KoViewConverter &converter) {
......
......@@ -30,6 +30,8 @@
#include <commands/KoShapeMoveCommand.h>
#include <KoSnapGuide.h>
#include <KoPointerEvent.h>
#include <KoTool.h>
#include <KLocale>
ShapeMoveStrategy::ShapeMoveStrategy( KoTool *tool, KoCanvasBase *canvas, const QPointF &clicked)
: KoInteractionStrategy(tool, canvas)
......@@ -49,6 +51,8 @@ ShapeMoveStrategy::ShapeMoveStrategy( KoTool *tool, KoCanvasBase *canvas, const
m_initialOffset = selection->absolutePosition( SelectionDecorator::hotPosition() ) - m_start;
m_initialSelectionPosition = selection->position();
m_canvas->snapGuide()->setIgnoredShapes( selection->selectedShapes( KoFlake::FullSelection ) );
tool->setStatusText( i18n("Press ALT to hold x- or y-position.") );
}
void ShapeMoveStrategy::handleMouseMove(const QPointF &point, Qt::KeyboardModifiers modifiers)
......
......@@ -28,6 +28,7 @@
#include <commands/KoShapeSizeCommand.h>
#include <commands/KoShapeTransformCommand.h>
#include <KoSnapGuide.h>
#include <KoTool.h>
#include <klocale.h>
......@@ -90,6 +91,8 @@ ShapeResizeStrategy::ShapeResizeStrategy( KoTool *tool, KoCanvasBase *canvas,
default:
Q_ASSERT(0); // illegal 'corner'
}
tool->setStatusText( i18n("Press CTRL to resize from center.") );
}
void ShapeResizeStrategy::handleMouseMove(const QPointF &point, Qt::KeyboardModifiers modifiers)
......
......@@ -53,6 +53,8 @@ ShapeRotateStrategy::ShapeRotateStrategy( KoTool *tool, KoCanvasBase *canvas, co
m_rotationCenter = canvas->shapeManager()->selection()->absolutePosition( SelectionDecorator::hotPosition() );
else
m_rotationCenter = m_initialBoundingRect.center();
tool->setStatusText( i18n( "Press ALT to rotate in 45 degree steps." ) );
}
void ShapeRotateStrategy::handleMouseMove(const QPointF &point, Qt::KeyboardModifiers modifiers) {
......
......@@ -208,6 +208,8 @@ void SimpleTextTool::activate( bool )
createTextCursorShape();
updateActions();
emit statusTextChanged( i18n("Press return to finish editing.") );
}
void SimpleTextTool::blinkCursor()
......
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