Commit 8e11dfdb authored by Grigory Tantsevov's avatar Grigory Tantsevov Committed by Dmitry Kazakov

Add a toggle on/off switch for pen pressure

Summary:
Feature for https://phabricator.kde.org/T3279. Button is located in the Tool Bar but not visible by defult. User can add it in Tool bar options. Has a customizable shortcut.
Based on @dkazakov branch krita-hud-kazakov.

Test Plan:
Does anyone have better name for button?
Unfortunately, I haven't tablet with pen, so I can't test it, but by @dkazakov, this option seems to work.

Reviewers: dkazakov, #krita

Subscribers: Deevad, timotheegiet, scottpetrovic, rempt, dkazakov

Differential Revision: https://phabricator.kde.org/D2308
parent 19ed2c65
......@@ -355,6 +355,17 @@
<isCheckable>true</isCheckable>
<statusTip></statusTip>
</Action>
<Action name="disable_pressure">
<icon>transform_icons_penPressure</icon>
<text>Use Pen Pressure</text>
<whatsThis></whatsThis>
<toolTip>Use Pen Pressure</toolTip>
<iconText>Use Pen Pressure</iconText>
<activationFlags>10000</activationFlags>
<shortcut></shortcut>
<isCheckable>true</isCheckable>
<statusTip></statusTip>
</Action>
<Action name="hmirror_action">
<icon>symmetry-horizontal</icon>
<text>Horizontal Mirror Tool</text>
......
<!DOCTYPE RCC>
<RCC version="1.0">
<qresource>
<RCC>
<qresource prefix="/">
<file>dark_transform_icons_cage.png</file>
<file>dark_transform_icons_liquify_erase.png</file>
<file>dark_transform_icons_liquify_main.png</file>
......@@ -18,7 +17,6 @@
<file>dark_transform_icons_mirror_y.svg</file>
<file>dark_transform_icons_rotate_cw.svg</file>
<file>dark_transform_icons_rotate_ccw.svg</file>
<file>light_transform_icons_cage.png</file>
<file>light_transform_icons_liquify_erase.png</file>
<file>light_transform_icons_liquify_main.png</file>
......@@ -36,5 +34,7 @@
<file>light_transform_icons_mirror_y.svg</file>
<file>light_transform_icons_rotate_cw.svg</file>
<file>light_transform_icons_rotate_ccw.svg</file>
<file>dark_transform_icons_penPressure_locked.png</file>
<file>light_transform_icons_penPressure_locked.png</file>
</qresource>
</RCC>
......@@ -532,6 +532,16 @@ bool KisCanvasResourceProvider::globalAlphaLock() const
return m_resourceManager->resource(GlobalAlphaLock).toBool();
}
void KisCanvasResourceProvider::setDisablePressure(bool value)
{
m_resourceManager->setResource(DisablePressure, value);
}
bool KisCanvasResourceProvider::disablePressure() const
{
return m_resourceManager->resource(DisablePressure).toBool();
}
void KisCanvasResourceProvider::notifyLoadingWorkspace(KisWorkspaceResource* workspace)
{
emit sigLoadingWorkspace(workspace);
......
......@@ -75,6 +75,7 @@ public:
Size,
HdrGamma,
GlobalAlphaLock,
DisablePressure,
PreviousPaintOpPreset,
EffectiveZoom, ///<-Used only by painting tools for non-displaying purposes
PresetAllowsLod,
......@@ -165,6 +166,8 @@ public:
void setGlobalAlphaLock(bool lock);
bool globalAlphaLock() const;
void setDisablePressure(bool value);
bool disablePressure() const;
///Notify that the workspace is saved and settings should be saved to it
void notifySavingWorkspace(KisWorkspaceResource* workspace);
......
......@@ -156,7 +156,13 @@ KisPaintopBox::KisPaintopBox(KisViewManager *view, QWidget *parent, const char *
m_alphaLockButton->setDefaultAction(alphaLockAction);
// pen pressure
m_disablePressureButton = new KisHighlightedToolButton(this);
m_disablePressureButton->setFixedSize(iconsize, iconsize);
m_disablePressureButton->setCheckable(true);
m_disablePressureAction = m_viewManager->actionManager()->createAction("disable_pressure");
m_disablePressureButton->setDefaultAction(m_disablePressureAction);
// horizontal and vertical mirror toolbar buttons
......@@ -334,6 +340,17 @@ KisPaintopBox::KisPaintopBox(KisViewManager *view, QWidget *parent, const char *
action->setText(i18n("Brush composite"));
action->setDefaultWidget(compositeActions);
QWidget* compositePressure = new QWidget(this);
QHBoxLayout* pressureLayout = new QHBoxLayout(compositePressure);
pressureLayout->addWidget(m_disablePressureButton);
pressureLayout->setSpacing(4);
pressureLayout->setContentsMargins(0, 0, 0, 0);
action = new QWidgetAction(this);
view->actionCollection()->addAction("pressure_action", action);
action->setText(i18n("Pressure usage (small button)"));
action->setDefaultWidget(compositePressure);
action = new QWidgetAction(this);
KisActionRegistry::instance()->propertizeAction("brushslider1", action);
view->actionCollection()->addAction("brushslider1", action);
......@@ -445,7 +462,9 @@ KisPaintopBox::KisPaintopBox(KisViewManager *view, QWidget *parent, const char *
connect(m_cmbCompositeOp , SIGNAL(currentIndexChanged(int)) , SLOT(slotSetCompositeMode(int)));
connect(m_eraseAction , SIGNAL(toggled(bool)) , SLOT(slotToggleEraseMode(bool)));
connect(alphaLockAction , SIGNAL(toggled(bool)) , SLOT(slotToggleAlphaLockMode(bool)));
connect(m_disablePressureAction , SIGNAL(toggled(bool)) , SLOT(slotDisablePressureMode(bool)));
m_disablePressureAction->setChecked(true);
connect(m_hMirrorAction , SIGNAL(toggled(bool)) , SLOT(slotHorizontalMirrorChanged(bool)));
connect(m_vMirrorAction , SIGNAL(toggled(bool)) , SLOT(slotVerticalMirrorChanged(bool)));
......@@ -782,6 +801,10 @@ void KisPaintopBox::slotCanvasResourceChanged(int key, const QVariant &value)
m_eraseAction->setChecked(value.toBool());
}
if (key == KisCanvasResourceProvider::DisablePressure) {
m_disablePressureAction->setChecked(value.toBool());
}
sender()->blockSignals(false);
}
}
......@@ -1076,6 +1099,17 @@ void KisPaintopBox::slotToggleAlphaLockMode(bool checked)
m_resourceProvider->setGlobalAlphaLock(checked);
}
void KisPaintopBox::slotDisablePressureMode(bool checked)
{
if (checked) {
m_disablePressureButton->actions()[0]->setIcon(KisIconUtils::loadIcon("transform_icons_penPressure"));
} else {
m_disablePressureButton->actions()[0]->setIcon(KisIconUtils::loadIcon("transform_icons_penPressure_locked"));
}
m_resourceProvider->setDisablePressure(checked);
}
void KisPaintopBox::slotReloadPreset()
{
KisSignalsBlocker blocker(m_optionWidget);
......@@ -1168,6 +1202,12 @@ void KisPaintopBox::slotUpdateSelectionIcon()
m_eraseAction->setIcon(KisIconUtils::loadIcon("draw-eraser"));
m_reloadAction->setIcon(KisIconUtils::loadIcon("view-refresh"));
if (m_disablePressureAction->isChecked()) {
m_disablePressureButton->setIcon(KisIconUtils::loadIcon("transform_icons_penPressure"));
} else {
m_disablePressureButton->setIcon(KisIconUtils::loadIcon("transform_icons_penPressure_locked"));
}
}
void KisPaintopBox::slotLockXMirrorToggle(bool toggleLock) {
......
......@@ -153,6 +153,7 @@ private Q_SLOTS:
void slotSwitchToPreviousPreset();
void slotUnsetEraseMode();
void slotToggleAlphaLockMode(bool);
void slotDisablePressureMode(bool);
void slotReloadPreset();
void slotGuiChangedCurrentPreset();
......@@ -182,6 +183,7 @@ private:
KisCompositeOpComboBox* m_cmbCompositeOp;
QToolButton* m_eraseModeButton;
QToolButton* m_alphaLockButton;
QToolButton* m_disablePressureButton;
QToolButton* m_hMirrorButton;
QToolButton* m_vMirrorButton;
KisToolOptionsPopup* m_toolOptionsPopup;
......@@ -195,6 +197,7 @@ private:
QToolButton* m_reloadButton;
KisAction* m_eraseAction;
KisAction* m_reloadAction;
KisAction* m_disablePressureAction;
QString m_currCompositeOpID;
KisNodeWSP m_previousNode;
......
......@@ -26,6 +26,9 @@
#include "kis_cubic_curve.h"
#include "kis_speed_smoother.h"
#include <KoCanvasResourceManager.h>
#include "kis_canvas_resource_provider.h"
/***********************************************************************/
/* KisPaintingInformationBuilder */
......@@ -36,7 +39,8 @@ const int KisPaintingInformationBuilder::LEVEL_OF_PRESSURE_RESOLUTION = 1024;
KisPaintingInformationBuilder::KisPaintingInformationBuilder()
: m_speedSmoother(new KisSpeedSmoother())
: m_speedSmoother(new KisSpeedSmoother()),
m_pressureDisabled(false)
{
connect(KisConfigNotifier::instance(), SIGNAL(configChanged()),
SLOT(updateSettings()));
......@@ -58,8 +62,13 @@ void KisPaintingInformationBuilder::updateSettings()
}
KisPaintInformation KisPaintingInformationBuilder::startStroke(KoPointerEvent *event,
int timeElapsed)
int timeElapsed,
const KoCanvasResourceManager *manager)
{
if (manager) {
m_pressureDisabled = manager->resource(KisCanvasResourceProvider::DisablePressure).toBool();
}
m_startPoint = event->point;
return createPaintingInformation(event, timeElapsed);
......@@ -103,7 +112,7 @@ KisPaintInformation KisPaintingInformationBuilder::createPaintingInformation(KoP
qreal speed = m_speedSmoother->getNextSpeed(imageToView(imagePoint));
return KisPaintInformation(imagePoint,
pressureToCurve(event->pressure()),
!m_pressureDisabled ? 1.0 : pressureToCurve(event->pressure()),
event->xTilt(), event->yTilt(),
event->rotation(),
event->tangentialPressure(),
......
......@@ -30,6 +30,7 @@ class KoPointerEvent;
class KisToolFreehand;
class KisCoordinatesConverter;
class KisSpeedSmoother;
class KoCanvasResourceManager;
class KRITAUI_EXPORT KisPaintingInformationBuilder : public QObject
{
......@@ -39,7 +40,7 @@ public:
KisPaintingInformationBuilder();
~KisPaintingInformationBuilder();
KisPaintInformation startStroke(KoPointerEvent *event, int timeElapsed);
KisPaintInformation startStroke(KoPointerEvent *event, int timeElapsed, const KoCanvasResourceManager *manager);
KisPaintInformation continueStroke(KoPointerEvent *event,
int timeElapsed);
......@@ -72,6 +73,7 @@ private:
QVector<qreal> m_pressureSamples;
QPointF m_startPoint;
QScopedPointer<KisSpeedSmoother> m_speedSmoother;
bool m_pressureDisabled;
};
class KRITAUI_EXPORT KisConverterPaintingInformationBuilder : public KisPaintingInformationBuilder
......
......@@ -194,7 +194,7 @@ void KisToolFreehandHelper::initPaint(KoPointerEvent *event,
KisDefaultBoundsBaseSP bounds)
{
KisPaintInformation pi =
m_d->infoBuilder->startStroke(event, elapsedStrokeTime());
m_d->infoBuilder->startStroke(event, elapsedStrokeTime(), resourceManager);
initPaintImpl(pi,
resourceManager,
......
......@@ -196,7 +196,7 @@ void KisToolLine::beginPrimaryAction(KoPointerEvent *event)
updatePreviewTimer(m_showGuideline);
m_helper->setEnabled(nodeAbility == PAINT);
m_helper->setUseSensors(m_chkUseSensors->isChecked());
m_helper->start(event);
m_helper->start(event, canvas()->resourceManager());
m_startPoint = convertToPixelCoordAndSnap(event);
m_endPoint = m_startPoint;
......
......@@ -81,12 +81,12 @@ void KisToolLineHelper::repaintLine(KoCanvasResourceManager *resourceManager,
}
}
void KisToolLineHelper::start(KoPointerEvent *event)
void KisToolLineHelper::start(KoPointerEvent *event, KoCanvasResourceManager *resourceManager)
{
if (!m_d->enabled) return;
KisPaintInformation pi =
m_d->infoBuilder->startStroke(event, elapsedStrokeTime());
m_d->infoBuilder->startStroke(event, elapsedStrokeTime(), resourceManager);
if (!m_d->useSensors) {
pi = KisPaintInformation(pi.pos());
......
......@@ -40,7 +40,7 @@ public:
KisStrokesFacade *strokesFacade,
KisPostExecutionUndoAdapter *undoAdapter);
void start(KoPointerEvent *event);
void start(KoPointerEvent *event, KoCanvasResourceManager *resourceManager);
void addPoint(KoPointerEvent *event, const QPointF &overridePos = QPointF());
void translatePoints(const QPointF &offset);
void end();
......
......@@ -85,13 +85,13 @@ void KisLiquifyPaintHelper::configurePaintOp(const KisLiquifyProperties &props,
m_d->paintOp.reset(new KisLiquifyPaintop(props, worker));
}
void KisLiquifyPaintHelper::startPaint(KoPointerEvent *event)
void KisLiquifyPaintHelper::startPaint(KoPointerEvent *event, const KoCanvasResourceManager *manager)
{
KIS_ASSERT_RECOVER_RETURN(m_d->paintOp);
m_d->strokeTime.start();
KisPaintInformation pi =
m_d->infoBuilder->startStroke(event, m_d->strokeTime.elapsed());
m_d->infoBuilder->startStroke(event, m_d->strokeTime.elapsed(), manager);
m_d->updatePreviousPaintInfo(pi);
m_d->hasPaintedAtLeastOnce = false;
......
......@@ -26,7 +26,7 @@ class KisCoordinatesConverter;
class KoPointerEvent;
class KisLiquifyProperties;
class QPainterPath;
class KoCanvasResourceManager;
class KisLiquifyPaintHelper
{
......@@ -37,7 +37,7 @@ public:
void configurePaintOp(const KisLiquifyProperties &_props,
KisLiquifyTransformWorker *worker);
void startPaint(KoPointerEvent *event);
void startPaint(KoPointerEvent *event, const KoCanvasResourceManager *manager);
void continuePaint(KoPointerEvent *event);
bool endPaint(KoPointerEvent *event);
......
......@@ -35,6 +35,7 @@
#include "kis_transform_utils.h"
#include "kis_liquify_paint_helper.h"
#include "kis_liquify_transform_worker.h"
#include "KoCanvasResourceManager.h"
struct KisLiquifyTransformStrategy::Private
......@@ -42,8 +43,10 @@ struct KisLiquifyTransformStrategy::Private
Private(KisLiquifyTransformStrategy *_q,
const KisCoordinatesConverter *_converter,
ToolTransformArgs &_currentArgs,
TransformTransactionProperties &_transaction)
: q(_q),
TransformTransactionProperties &_transaction,
const KoCanvasResourceManager *_manager)
: manager(_manager),
q(_q),
converter(_converter),
currentArgs(_currentArgs),
transaction(_transaction),
......@@ -52,6 +55,8 @@ struct KisLiquifyTransformStrategy::Private
{
}
const KoCanvasResourceManager *manager;
KisLiquifyTransformStrategy * const q;
/// standard members ///
......@@ -87,9 +92,10 @@ struct KisLiquifyTransformStrategy::Private
KisLiquifyTransformStrategy::KisLiquifyTransformStrategy(const KisCoordinatesConverter *converter,
ToolTransformArgs &currentArgs,
TransformTransactionProperties &transaction)
TransformTransactionProperties &transaction,
const KoCanvasResourceManager *manager)
: m_d(new Private(this, converter, currentArgs, transaction))
: m_d(new Private(this, converter, currentArgs, transaction, manager))
{
}
......@@ -144,7 +150,7 @@ bool KisLiquifyTransformStrategy::acceptsClicks() const
bool KisLiquifyTransformStrategy::beginPrimaryAction(KoPointerEvent *event)
{
m_d->helper.configurePaintOp(*m_d->currentArgs.liquifyProperties(), m_d->currentArgs.liquifyWorker());
m_d->helper.startPaint(event);
m_d->helper.startPaint(event, m_d->manager);
m_d->recalculateTransformations();
......
......@@ -38,7 +38,7 @@ class KisLiquifyTransformStrategy : public KisTransformStrategyBase
public:
KisLiquifyTransformStrategy(const KisCoordinatesConverter *converter,
ToolTransformArgs &currentArgs,
TransformTransactionProperties &transaction);
TransformTransactionProperties &transaction, const KoCanvasResourceManager *manager);
~KisLiquifyTransformStrategy();
void setTransformFunction(const QPointF &mousePos, bool perspectiveModifierActive);
......
......@@ -99,7 +99,7 @@ KisToolTransform::KisToolTransform(KoCanvasBase * canvas)
, m_liquifyStrategy(
new KisLiquifyTransformStrategy(
dynamic_cast<KisCanvas2*>(canvas)->coordinatesConverter(),
m_currentArgs, m_transaction))
m_currentArgs, m_transaction, canvas->resourceManager()))
, m_freeStrategy(
new KisFreeTransformStrategy(
dynamic_cast<KisCanvas2*>(canvas)->coordinatesConverter(),
......
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