[calligra/calligra/2.9] krita: Add snap-single checkbox under assistant snapping.
Wolthera van Hovell
griffinvalley at gmail.com
Tue Aug 25 14:19:01 UTC 2015
Git commit 750f3c9c5d048e08db36520c0ba2509e7a013962 by Wolthera van Hovell.
Committed on 25/08/2015 at 14:18.
Pushed by woltherav into branch 'calligra/2.9'.
Add snap-single checkbox under assistant snapping.
This adds a checkbox to assistant snapping that will make the snapping happen
to only the first snapped-to-assistant. This removes snapping issues on
infinite assistants while keeping the ability to snap to chained assistants
while the checkbox is unticked.
BUG: 331788
CCMAIL:kimageshop at kde.org
M +9 -1 krita/plugins/tools/defaulttools/kis_tool_brush.cc
M +1 -0 krita/plugins/tools/defaulttools/kis_tool_brush.h
M +42 -9 krita/ui/kis_painting_assistants_decoration.cpp
M +2 -0 krita/ui/kis_painting_assistants_decoration.h
M +7 -0 krita/ui/tool/kis_tool_freehand.cc
M +2 -0 krita/ui/tool/kis_tool_freehand.h
http://commits.kde.org/calligra/750f3c9c5d048e08db36520c0ba2509e7a013962
diff --git a/krita/plugins/tools/defaulttools/kis_tool_brush.cc b/krita/plugins/tools/defaulttools/kis_tool_brush.cc
index 85ff008..87b9183 100644
--- a/krita/plugins/tools/defaulttools/kis_tool_brush.cc
+++ b/krita/plugins/tools/defaulttools/kis_tool_brush.cc
@@ -421,6 +421,7 @@ QWidget * KisToolBrush::createOptionWidget()
assistantWidget->setToolTip(i18n("You need to add Ruler Assistants before this tool will work."));
connect(m_chkAssistant, SIGNAL(toggled(bool)), this, SLOT(setAssistant(bool)));
assistantLayout->addWidget(m_chkAssistant);
+
m_sliderMagnetism = new KisSliderSpinBox(optionsWidget);
m_sliderMagnetism->setToolTip(i18n("Assistant Magnetism"));
m_sliderMagnetism->setRange(0, MAXIMUM_MAGNETISM);
@@ -428,13 +429,20 @@ QWidget * KisToolBrush::createOptionWidget()
connect(m_chkAssistant, SIGNAL(toggled(bool)), m_sliderMagnetism, SLOT(setEnabled(bool)));
m_sliderMagnetism->setValue(m_magnetism * MAXIMUM_MAGNETISM);
connect(m_sliderMagnetism, SIGNAL(valueChanged(int)), SLOT(slotSetMagnetism(int)));
-
+
KAction *toggleaction = new KAction(i18n("Toggle Assistant"), this);
addAction("toggle_assistant", toggleaction);
toggleaction->setShortcut(KShortcut(Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_L));
connect(toggleaction, SIGNAL(triggered(bool)), m_chkAssistant, SLOT(toggle()));
addOptionWidgetOption(m_sliderMagnetism, assistantWidget);
+
+ m_chkOnlyOneAssistant = new QCheckBox(optionsWidget);
+ m_chkOnlyOneAssistant->setToolTip(i18nc("@info:tooltip","Make it only snap to a single assistant, prevents snapping mess while using the infinite assistants."));
+ m_chkOnlyOneAssistant->setCheckState(Qt::Checked);//turn on by default.
+ connect(m_chkOnlyOneAssistant, SIGNAL(toggled(bool)), this, SLOT(setOnlyOneAssistantSnap(bool)));
+ addOptionWidgetOption(m_chkOnlyOneAssistant, new QLabel(i18n("Snap single:")));
+
//load settings from configuration kritarc file
slotSetSmoothingType((int)m_configGroup.readEntry("smoothingType", 0));
diff --git a/krita/plugins/tools/defaulttools/kis_tool_brush.h b/krita/plugins/tools/defaulttools/kis_tool_brush.h
index c30c0cd..c0d5ff7 100644
--- a/krita/plugins/tools/defaulttools/kis_tool_brush.h
+++ b/krita/plugins/tools/defaulttools/kis_tool_brush.h
@@ -120,6 +120,7 @@ private:
QCheckBox *m_chkAssistant;
KisSliderSpinBox *m_sliderMagnetism;
+ QCheckBox *m_chkOnlyOneAssistant;
KisDoubleSliderSpinBox *m_sliderSmoothnessDistance;
KisDoubleSliderSpinBox *m_sliderTailAggressiveness;
QCheckBox *m_chkSmoothPressure;
diff --git a/krita/ui/kis_painting_assistants_decoration.cpp b/krita/ui/kis_painting_assistants_decoration.cpp
index bcd1e1b..545f412 100644
--- a/krita/ui/kis_painting_assistants_decoration.cpp
+++ b/krita/ui/kis_painting_assistants_decoration.cpp
@@ -34,6 +34,9 @@ struct KisPaintingAssistantsDecoration::Private {
QList<KisPaintingAssistant*> assistants;
bool assistantVisible;
bool outlineVisible;
+ bool snapOnlyOneAssistant;
+ KisPaintingAssistant* firstAssistant;
+ bool aFirstStroke;
};
KisPaintingAssistantsDecoration::KisPaintingAssistantsDecoration(QPointer<KisView> parent) :
@@ -42,6 +45,7 @@ KisPaintingAssistantsDecoration::KisPaintingAssistantsDecoration(QPointer<KisVie
{
setAssistantVisible(true);
setOutlineVisible(true);
+ d->snapOnlyOneAssistant=true;//turn on by default.
}
KisPaintingAssistantsDecoration::~KisPaintingAssistantsDecoration()
@@ -87,22 +91,46 @@ QPointF KisPaintingAssistantsDecoration::adjustPosition(const QPointF& point, co
QPointF best = point;
double distance = DBL_MAX;
//the following tries to find the closest point to stroke-begin. It checks all assistants for the closest point//
- foreach(KisPaintingAssistant* assistant, d->assistants) {
- if(assistant->snapping()==true){//this checks if the assistant in question has it's snapping boolean turned on//
- QPointF pt = assistant->adjustPosition(point, strokeBegin);
- if (pt.x() != pt.x()) continue;
- double d = qAbs(pt.x() - point.x()) + qAbs(pt.y() - point.y());
- if (d < distance) {
- best = pt;
- distance = d;
+ if(!d->snapOnlyOneAssistant){
+ foreach(KisPaintingAssistant* assistant, d->assistants) {
+ if(assistant->snapping()==true){//this checks if the assistant in question has it's snapping boolean turned on//
+ QPointF pt = assistant->adjustPosition(point, strokeBegin);
+ if (pt.x() != pt.x()) continue;
+ double dist = qAbs(pt.x() - point.x()) + qAbs(pt.y() - point.y());
+ if (dist < distance) {
+ best = pt;
+ distance = dist;
+ }
+ }
+ }
+ } else if (d->aFirstStroke==false) {
+ foreach(KisPaintingAssistant* assistant, d->assistants) {
+ if(assistant->snapping()==true){//this checks if the assistant in question has it's snapping boolean turned on//
+ QPointF pt = assistant->adjustPosition(point, strokeBegin);
+ if (pt.x() != pt.x()) continue;
+ double dist = qAbs(pt.x() - point.x()) + qAbs(pt.y() - point.y());
+ if (dist < distance) {
+ best = pt;
+ distance = dist;
+ d->firstAssistant = assistant;
+ }
}
}
+ } else {
+ best = d->firstAssistant->adjustPosition(point, strokeBegin);
}
+ //this is here to be compatible with the movement in the perspective tool.
+ qreal dx = point.x() - strokeBegin.x(), dy = point.y() - strokeBegin.y();
+ if (dx * dx + dy * dy >= 4.0) {
+ // allow some movement before snapping
+ d->aFirstStroke=true;
+ }
return best;
}
void KisPaintingAssistantsDecoration::endStroke()
{
+ d->aFirstStroke=false;
foreach(KisPaintingAssistant* assistant, d->assistants) {
assistant->endStroke();
}
@@ -153,6 +181,12 @@ void KisPaintingAssistantsDecoration::setOutlineVisible(bool set)
{
d->outlineVisible=set;
}
+
+void KisPaintingAssistantsDecoration::setOnlyOneAssistantSnap(bool assistant)
+{
+ d->snapOnlyOneAssistant = assistant;
+}
+
bool KisPaintingAssistantsDecoration::assistantVisibility()
{
return d->assistantVisible;
@@ -161,7 +195,6 @@ bool KisPaintingAssistantsDecoration::outlineVisibility()
{
return d->outlineVisible;
}
-
void KisPaintingAssistantsDecoration::uncache()
{
foreach(KisPaintingAssistant* assistant, d->assistants) {
diff --git a/krita/ui/kis_painting_assistants_decoration.h b/krita/ui/kis_painting_assistants_decoration.h
index 78ebfed..0138c0f 100644
--- a/krita/ui/kis_painting_assistants_decoration.h
+++ b/krita/ui/kis_painting_assistants_decoration.h
@@ -48,6 +48,8 @@ public:
void setAssistantVisible(bool set);
/*sets whether the preview is visible*/
void setOutlineVisible(bool set);
+ /*sets whether we snap to only one assistant*/
+ void setOnlyOneAssistantSnap(bool assistant);
/*returns assistant visibility*/
bool assistantVisibility();
/*returns preview visibility*/
diff --git a/krita/ui/tool/kis_tool_freehand.cc b/krita/ui/tool/kis_tool_freehand.cc
index 6f5b7b9..bdfd9f1 100644
--- a/krita/ui/tool/kis_tool_freehand.cc
+++ b/krita/ui/tool/kis_tool_freehand.cc
@@ -62,6 +62,7 @@ KisToolFreehand::KisToolFreehand(KoCanvasBase * canvas, const QCursor & cursor,
{
m_assistant = false;
m_magnetism = 1.0;
+ m_only_one_assistant = true;
setSupportOutline(true);
@@ -359,9 +360,15 @@ void KisToolFreehand::setAssistant(bool assistant)
m_assistant = assistant;
}
+void KisToolFreehand::setOnlyOneAssistantSnap(bool assistant)
+{
+ m_only_one_assistant = assistant;
+}
+
QPointF KisToolFreehand::adjustPosition(const QPointF& point, const QPointF& strokeBegin)
{
if (m_assistant && static_cast<KisCanvas2*>(canvas())->paintingAssistantsDecoration()) {
+ static_cast<KisCanvas2*>(canvas())->paintingAssistantsDecoration()->setOnlyOneAssistantSnap(m_only_one_assistant);
QPointF ap = static_cast<KisCanvas2*>(canvas())->paintingAssistantsDecoration()->adjustPosition(point, strokeBegin);
return (1.0 - m_magnetism) * point + m_magnetism * ap;
}
diff --git a/krita/ui/tool/kis_tool_freehand.h b/krita/ui/tool/kis_tool_freehand.h
index d4a189e..36a1578 100644
--- a/krita/ui/tool/kis_tool_freehand.h
+++ b/krita/ui/tool/kis_tool_freehand.h
@@ -91,6 +91,7 @@ protected Q_SLOTS:
void explicitUpdateOutline();
virtual void resetCursorStyle();
void setAssistant(bool assistant);
+ void setOnlyOneAssistantSnap(bool assistant);
private:
friend class KisToolFreehandPaintingInformationBuilder;
@@ -114,6 +115,7 @@ protected:
KisSmoothingOptionsSP smoothingOptions() const;
bool m_assistant;
double m_magnetism;
+ bool m_only_one_assistant;
private:
KisPaintingInformationBuilder *m_infoBuilder;
More information about the kimageshop
mailing list