这是indexloc提供的服务,不要输入任何密码
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions app/src/tooloptionwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,12 @@ void ToolOptionWidget::makeConnectionToEditor(Editor* editor)

connect(ui->showInfoBox, &QCheckBox::clicked, toolManager, &ToolManager::setShowSelectionInfo);

connect(ui->snapAngleBox, &QCheckBox::clicked, toolManager, &ToolManager::setSnapAngleBox);
connect(ui->snapAngleDegrees, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), toolManager, &ToolManager::setSnapAngleDegrees);

connect(toolManager, &ToolManager::toolChanged, this, &ToolOptionWidget::onToolChanged);
connect(toolManager, &ToolManager::toolPropertyChanged, this, &ToolOptionWidget::onToolPropertyChanged);

}

void ToolOptionWidget::onToolPropertyChanged(ToolType, ToolPropertyType ePropertyType)
Expand Down Expand Up @@ -158,6 +162,7 @@ void ToolOptionWidget::onToolPropertyChanged(ToolType, ToolPropertyType ePropert
case USEBUCKETFILLEXPAND: break;
case BUCKETFILLLAYERREFERENCEMODE: break;
case FILL_MODE: break;
case SNAPTOANGLE: (p.snapAngleState); break;
default:
Q_ASSERT(false);
break;
Expand Down Expand Up @@ -201,6 +206,8 @@ void ToolOptionWidget::setVisibility(BaseTool* tool)
ui->inpolLevelsCombo->setVisible(tool->isPropertyEnabled(STABILIZATION));
ui->fillContourBox->setVisible(tool->isPropertyEnabled(FILLCONTOUR));
ui->showInfoBox->setVisible(tool->isPropertyEnabled(SHOWSELECTIONINFO));
ui->snapAngleBox->setVisible(tool->isPropertyEnabled(SNAPTOANGLE));
ui->snapAngleDegrees->setVisible(tool->isPropertyEnabled(SNAPTOANGLE));

auto currentLayerType = editor()->layers()->currentLayer()->type();
auto propertyType = editor()->tools()->currentTool()->type();
Expand Down Expand Up @@ -370,6 +377,18 @@ void ToolOptionWidget::setShowSelectionInfo(bool showSelectionInfo)
ui->showInfoBox->setChecked(showSelectionInfo);
}

void ToolOptionWidget::setSnapAngleBox(bool enabled)
{
QSignalBlocker blocker(ui->snapAngleBox);
ui->snapAngleBox->setChecked(enabled);
}

void ToolOptionWidget::setSnapAngleDegrees(int degrees)
{
QSignalBlocker blocker(ui->snapAngleDegrees);
ui->snapAngleDegrees->setValue(degrees);
}

void ToolOptionWidget::disableAllOptions()
{
ui->sizeSlider->hide();
Expand All @@ -379,6 +398,8 @@ void ToolOptionWidget::disableAllOptions()
ui->useFeatherBox->hide();
ui->useBezierBox->hide();
ui->useClosedPathBox->hide();
ui->snapAngleBox->hide();
ui->snapAngleDegrees->hide();
ui->usePressureBox->hide();
ui->makeInvisibleBox->hide();
ui->preserveAlphaBox->hide();
Expand Down
2 changes: 2 additions & 0 deletions app/src/tooloptionwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public slots:
void setBezier(bool);
void setClosedPath(bool);
void setShowSelectionInfo(bool);
void setSnapAngleBox(bool);
void setSnapAngleDegrees(int);

void disableAllOptions();
void setVisibility(BaseTool*);
Expand Down
38 changes: 29 additions & 9 deletions app/ui/tooloptions.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>140</width>
<height>355</height>
<width>375</width>
<height>569</height>
</rect>
</property>
<property name="minimumSize">
Expand Down Expand Up @@ -35,10 +35,10 @@
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
<enum>QFrame::Shape::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
<enum>QFrame::Shadow::Plain</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
Expand All @@ -48,8 +48,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>153</width>
<height>340</height>
<width>375</width>
<height>569</height>
</rect>
</property>
<property name="autoFillBackground">
Expand Down Expand Up @@ -245,12 +245,32 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="snapAngleBox">
<property name="text">
<string>Snap To Angle:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="snapAngleDegrees">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>90</number>
</property>
<property name="value">
<number>45</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -305,10 +325,10 @@
<item>
<spacer name="verticalSpacer1">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
<enum>QSizePolicy::Policy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down
6 changes: 4 additions & 2 deletions core_lib/src/interface/scribblearea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ void ScribbleArea::onTileCreated(TiledBuffer* tiledBuffer, Tile* tile)

void ScribbleArea::updateFrame()
{
if (currentTool()->isActive() && currentTool()->isDrawingTool()) {
if (currentTool()->type() == POLYLINE) { update();}
else if (currentTool()->isActive() && currentTool()->isDrawingTool()) {
return;
}

Expand Down Expand Up @@ -259,7 +260,8 @@ void ScribbleArea::invalidateOnionSkinsCacheAround(int frameNumber)

void ScribbleArea::invalidateAllCache()
{
if (currentTool()->isDrawingTool() && currentTool()->isActive()) { return; }
if (currentTool()->type() == POLYLINE) { update(); }
else if (currentTool()->isDrawingTool() && currentTool()->isActive()) { return; }

QPixmapCache::clear();
mPixmapCacheKeys.clear();
Expand Down
15 changes: 15 additions & 0 deletions core_lib/src/managers/toolmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,3 +434,18 @@ void ToolManager::clearTemporaryTool()
mTemporaryTriggerMouseButtons = Qt::NoButton;
emit toolChanged(currentTool()->type());
}

void ToolManager::setSnapAngleBox(bool enabled)
{
if (currentTool() == nullptr) return;
currentTool()->properties.snapAngleState = enabled;
emit toolPropertyChanged(currentTool()->type(), SNAPTOANGLE);
}

void ToolManager::setSnapAngleDegrees(int degrees)
{
if (currentTool() == nullptr) return;
currentTool()->properties.snapAngleDegrees = degrees;
emit toolPropertyChanged(currentTool()->type(), SNAPDEGREE);
}

2 changes: 2 additions & 0 deletions core_lib/src/managers/toolmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public slots:
void resetCameraPath();
void setCameraPathDotColor(int);
void resetCameraTransform(CameraFieldOption option);
void setSnapAngleBox(bool);
void setSnapAngleDegrees(int);

/// Layer mode will be enforced by the the choice the reference mode selected.
/// @return Returns true if reference mode is ``current layer`, otherwise false.
Expand Down
2 changes: 2 additions & 0 deletions core_lib/src/tool/basetool.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class Properties
bool showSelectionInfo = true;
bool cameraShowPath = true;
DotColorType cameraPathDotColorType = DotColorType::RED;
bool snapAngleState = false;
double snapAngleDegrees = 45;
};

const int ON = 1;
Expand Down
31 changes: 29 additions & 2 deletions core_lib/src/tool/polylinetool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void PolylineTool::loadSettings()
mPropertyEnabled[BEZIER] = true;
mPropertyEnabled[CLOSEDPATH] = true;
mPropertyEnabled[ANTI_ALIASING] = true;
mPropertyEnabled[SNAPTOANGLE] = true;

QSettings settings(PENCIL2D, PENCIL2D);

Expand Down Expand Up @@ -163,7 +164,13 @@ void PolylineTool::pointerPressEvent(PointerEvent* event)
mScribbleArea->toggleThinLines();
}
}
mPoints << getCurrentPoint();

QPointF currentPoint = getCurrentPoint();
if (properties.snapAngleState && !mPoints.isEmpty()) {
currentPoint = getSnappedPoint(mPoints.last(), currentPoint);
}

mPoints << currentPoint;
emit isActiveChanged(POLYLINE, true);
}
}
Expand All @@ -181,7 +188,12 @@ void PolylineTool::pointerMoveEvent(PointerEvent* event)
Layer* layer = mEditor->layers()->currentLayer();
if (layer->type() == Layer::BITMAP || layer->type() == Layer::VECTOR)
{
drawPolyline(mPoints, getCurrentPoint());
QPointF currentPoint = getCurrentPoint();
if (properties.snapAngleState && !mPoints.isEmpty()) {
currentPoint = getSnappedPoint(mPoints.last(), currentPoint);
}
drawPolyline(mPoints, currentPoint);

}

StrokeTool::pointerMoveEvent(event);
Expand Down Expand Up @@ -281,10 +293,25 @@ bool PolylineTool::keyReleaseEvent(QKeyEvent* event)
return BaseTool::keyReleaseEvent(event);
}


QPointF PolylineTool::getSnappedPoint(const QPointF& lastPoint, const QPointF& currentPoint)
{
QPointF delta = currentPoint - lastPoint;
qreal angle = qAtan2(delta.y(), delta.x());
qreal snapAngle = qDegreesToRadians(properties.snapAngleDegrees);
angle = qRound(angle / snapAngle) * snapAngle;
qreal length = qSqrt(delta.x() * delta.x() + delta.y() * delta.y());
return lastPoint + QPointF(qCos(angle) * length, qSin(angle) * length);
}

void PolylineTool::drawPolyline(QList<QPointF> points, QPointF endPoint)
{
if (points.size() > 0)
{
if (properties.snapAngleState && !points.isEmpty()) {
endPoint = getSnappedPoint(points.last(), endPoint);
}

QPen pen(mEditor->color()->frontColor(),
properties.width,
Qt::SolidLine,
Expand Down
6 changes: 4 additions & 2 deletions core_lib/src/tool/polylinetool.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ class PolylineTool : public StrokeTool
private:
QList<QPointF> mPoints;
bool mClosedPathOverrideEnabled = false;

bool snapAngleEnabled = false;
int snapAngleDegrees;
QPointF getSnappedPoint(const QPointF& lastPoint, const QPointF& currentPoint);
void drawPolyline(QList<QPointF> points, QPointF endPoint);
void removeLastPolylineSegment();
void cancelPolyline();
void endPolyline(QList<QPointF> points);
void endPolyline(QList<QPointF> points);
};

#endif // POLYLINETOOL_H
2 changes: 2 additions & 0 deletions core_lib/src/util/pencildef.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ enum ToolPropertyType
USEBUCKETFILLEXPAND,
BUCKETFILLLAYERREFERENCEMODE,
CAMERAPATH,
SNAPTOANGLE,
SNAPDEGREE,
};

enum class DotColorType {
Expand Down
Loading