Commit 6304ab9a authored by Scott Petrovic's avatar Scott Petrovic

Add context menu for transform tool. Quickly change type and a few additional actions

parent 95b62e50
......@@ -35,6 +35,7 @@
#include <QComboBox>
#include <QApplication>
#include <QMatrix4x4>
#include <QMenu>
#include <kis_debug.h>
#include <klocalizedstring.h>
......@@ -120,6 +121,27 @@ KisToolTransform::KisToolTransform(KoCanvasBase * canvas)
useCursor(KisCursor::selectCursor());
m_optionsWidget = 0;
warpAction = new KisAction(i18n("Warp"));
liquifyAction = new KisAction(i18n("Liquify"));;
cageAction = new KisAction(i18n("Cage"));;
freeTransformAction = new KisAction(i18n("Free"));;
perspectiveAction = new KisAction(i18n("Perspective"));
// extra actions for free transform that are in the tool options
mirrorHorizontalAction = new KisAction(i18n("Mirror Horizontal"));
mirrorVericalAction = new KisAction(i18n("Mirror Vertical"));
rotateNinteyCWAction = new KisAction(i18n("Rotate 90 degrees Clockwise"));
rotateNinteyCCWAction = new KisAction(i18n("Rotate 90 degrees CounterClockwise"));
m_contextMenu.reset(new QMenu());
connect(warpAction, SIGNAL(triggered(bool)), this, SLOT(slotUpdateToWarpType()));
connect(perspectiveAction, SIGNAL(triggered(bool)), this, SLOT(slotUpdateToPerspectiveType()));
connect(freeTransformAction, SIGNAL(triggered(bool)), this, SLOT(slotUpdateToFreeTransformType()));
connect(liquifyAction, SIGNAL(triggered(bool)), this, SLOT(slotUpdateToLiquifyType()));
connect(cageAction, SIGNAL(triggered(bool)), this, SLOT(slotUpdateToCageType()));
connect(m_warpStrategy.data(), SIGNAL(requestCanvasUpdate()), SLOT(canvasUpdateRequested()));
connect(m_cageStrategy.data(), SIGNAL(requestCanvasUpdate()), SLOT(canvasUpdateRequested()));
connect(m_liquifyStrategy.data(), SIGNAL(requestCanvasUpdate()), SLOT(canvasUpdateRequested()));
......@@ -323,6 +345,33 @@ void KisToolTransform::endActionImpl(KoPointerEvent *event, bool usePrimaryActio
updateApplyResetAvailability();
}
QMenu* KisToolTransform::popupActionsMenu()
{
if (m_contextMenu) {
m_contextMenu->clear();
// add a quick switch to different transform types
m_contextMenu->addAction(freeTransformAction);
m_contextMenu->addAction(perspectiveAction);
m_contextMenu->addAction(warpAction);
m_contextMenu->addAction(cageAction);
m_contextMenu->addAction(liquifyAction);
// extra options if free transform is selected
if (transformMode() == ToolTransformArgs::FREE_TRANSFORM) {
m_contextMenu->addSeparator();
m_contextMenu->addAction(mirrorHorizontalAction);
m_contextMenu->addAction(mirrorVericalAction);
m_contextMenu->addAction(rotateNinteyCWAction);
m_contextMenu->addAction(rotateNinteyCCWAction);
}
}
return m_contextMenu.data();
}
void KisToolTransform::beginPrimaryAction(KoPointerEvent *event)
{
beginActionImpl(event, true, KisTool::NONE);
......@@ -1038,6 +1087,13 @@ QWidget* KisToolTransform::createOptionWidget() {
connect(m_optionsWidget, SIGNAL(sigEditingFinished()),
this, SLOT(slotEditingFinished()));
connect(mirrorHorizontalAction, SIGNAL(triggered(bool)), m_optionsWidget, SLOT(slotFlipX()));
connect(mirrorVericalAction, SIGNAL(triggered(bool)), m_optionsWidget, SLOT(slotFlipY()));
connect(rotateNinteyCWAction, SIGNAL(triggered(bool)), m_optionsWidget, SLOT(slotRotateCW()));
connect(rotateNinteyCCWAction, SIGNAL(triggered(bool)), m_optionsWidget, SLOT(slotRotateCCW()));
updateOptionWidget();
return m_optionsWidget;
......@@ -1138,6 +1194,7 @@ void KisToolTransform::slotRestartTransform()
startStroke(savedArgs.mode(), true);
}
void KisToolTransform::forceRepaintDelayedLayers(KisNodeSP root)
{
KIS_SAFE_ASSERT_RECOVER_RETURN(root);
......@@ -1146,12 +1203,36 @@ void KisToolTransform::forceRepaintDelayedLayers(KisNodeSP root)
image()->waitForDone();
}
void KisToolTransform::slotEditingFinished()
{
commitChanges();
}
void KisToolTransform::slotUpdateToWarpType()
{
setTransformMode(KisToolTransform::TransformToolMode::WarpTransformMode);
}
void KisToolTransform::slotUpdateToPerspectiveType()
{
setTransformMode(KisToolTransform::TransformToolMode::PerspectiveTransformMode);
}
void KisToolTransform::slotUpdateToFreeTransformType()
{
setTransformMode(KisToolTransform::TransformToolMode::FreeTransformMode);
}
void KisToolTransform::slotUpdateToLiquifyType()
{
setTransformMode(KisToolTransform::TransformToolMode::LiquifyTransformMode);
}
void KisToolTransform::slotUpdateToCageType()
{
setTransformMode(KisToolTransform::TransformToolMode::CageTransformMode);
}
void KisToolTransform::setShearY(double shear)
{
m_optionsWidget->slotSetShearY(shear);
......
......@@ -42,6 +42,8 @@
#include <flake/kis_node_shape.h>
#include <kis_tool.h>
#include <kis_canvas2.h>
#include <kis_action.h>
#include "tool_transform_args.h"
#include "tool_transform_changes_tracker.h"
......@@ -145,6 +147,8 @@ public:
void beginActionImpl(KoPointerEvent *event, bool usePrimaryAction, KisTool::AlternateAction action);
void continueActionImpl(KoPointerEvent *event, bool usePrimaryAction, KisTool::AlternateAction action);
void endActionImpl(KoPointerEvent *event, bool usePrimaryAction, KisTool::AlternateAction action);
QMenu* popupActionsMenu() override;
void activatePrimaryAction() override;
void deactivatePrimaryAction() override;
......@@ -227,6 +231,7 @@ public Q_SLOTS:
private:
QList<KisNodeSP> fetchNodesList(ToolTransformArgs::TransformMode mode, KisNodeSP root, bool recursive);
QScopedPointer<QMenu> m_contextMenu;
bool clearDevices(const QList<KisNodeSP> &nodes);
void transformClearedDevices();
......@@ -292,6 +297,22 @@ private:
TransformTransactionProperties m_transaction;
TransformChangesTracker m_changesTracker;
/// actions for the context click menu
KisAction* warpAction;
KisAction* liquifyAction;
KisAction* cageAction;
KisAction* freeTransformAction;
KisAction* perspectiveAction;
// a few extra context click options if free transform is active
KisAction* mirrorHorizontalAction;
KisAction* mirrorVericalAction;
KisAction* rotateNinteyCWAction;
KisAction* rotateNinteyCCWAction;
/**
* This artificial rect is used to store the image to flake
* transformation. We check against this rect to get to know
......@@ -315,6 +336,15 @@ private Q_SLOTS:
void slotResetTransform();
void slotRestartTransform();
void slotEditingFinished();
// context menu options for updating the transform type
// this is to help with discoverability since come people can't find the tool options
void slotUpdateToWarpType();
void slotUpdateToPerspectiveType();
void slotUpdateToFreeTransformType();
void slotUpdateToLiquifyType();
void slotUpdateToCageType();
};
class KisToolTransformFactory : public KoToolFactoryBase
......
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