Now you can change the thickness of the drawing tools!

This commit is contained in:
lupoDharkael
2017-08-17 14:47:27 +02:00
parent 321ec1b555
commit b966a10c09
40 changed files with 244 additions and 62 deletions

View File

@@ -23,14 +23,13 @@ namespace {
const int ArrowWidth = 10;
const int ArrowHeight = 18;
QPainterPath getArrowHead(QPoint p1, QPoint p2) {
QPainterPath getArrowHead(QPoint p1, QPoint p2, const int thickness) {
QLineF body(p1, p2);
int originalLength = body.length();
body.setLength(ArrowWidth);
body.setLength(ArrowWidth + thickness*2);
// move across the line up to the head
//QPointF =;
QLineF temp(QPoint(0,0), p2-p1);
temp.setLength(originalLength-ArrowHeight);
temp.setLength(originalLength - ArrowHeight - thickness*2);
QPointF bottonTranslation(temp.p2());
// generates the transformation to center of the arrowhead
@@ -50,9 +49,9 @@ QPainterPath getArrowHead(QPoint p1, QPoint p2) {
}
// gets a shorter line to prevent overlap in the point of the arrow
QLine getShorterLine(QPoint p1, QPoint p2) {
QLine getShorterLine(QPoint p1, QPoint p2, const int thickness) {
QLineF l(p1, p2);
l.setLength(l.length()-ArrowHeight);
l.setLength(l.length() - ArrowHeight - thickness*2);
return l.toLine();
}
@@ -89,11 +88,12 @@ CaptureTool::ToolWorkType ArrowTool::toolType() const {
void ArrowTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
painter.setPen(QPen(color, 2));
painter.drawLine(getShorterLine(points[0], points[1]));
painter.fillPath(getArrowHead(points[0], points[1]), QBrush(color));
painter.setPen(QPen(color, 2 + thickness));
painter.drawLine(getShorterLine(points[0], points[1], thickness));
painter.fillPath(getArrowHead(points[0], points[1], thickness), QBrush(color));
}
void ArrowTool::onPressed() {

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;

View File

@@ -60,7 +60,8 @@ public:
virtual void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) = 0;
const QColor &color,
const int thickness) = 0;
signals:
void requestAction(Request r);

View File

@@ -49,9 +49,10 @@ CaptureTool::ToolWorkType CircleTool::toolType() const {
void CircleTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
painter.setPen(QPen(color, 2));
painter.setPen(QPen(color, 2 + thickness));
painter.drawEllipse(QRect(points[0], points[1]));
}

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;

View File

@@ -49,11 +49,13 @@ CaptureTool::ToolWorkType CopyTool::toolType() const {
void CopyTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
Q_UNUSED(painter);
Q_UNUSED(points);
Q_UNUSED(color);
Q_UNUSED(thickness);
}
void CopyTool::onPressed() {

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;

View File

@@ -49,11 +49,13 @@ CaptureTool::ToolWorkType ExitTool::toolType() const {
void ExitTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
Q_UNUSED(painter);
Q_UNUSED(points);
Q_UNUSED(color);
Q_UNUSED(thickness);
}
void ExitTool::onPressed() {

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;

View File

@@ -49,11 +49,13 @@ CaptureTool::ToolWorkType ImgurUploaderTool::toolType() const {
void ImgurUploaderTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
Q_UNUSED(painter);
Q_UNUSED(points);
Q_UNUSED(color);
Q_UNUSED(thickness);
}
void ImgurUploaderTool::onPressed() {

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;

View File

@@ -51,14 +51,15 @@ CaptureTool::ToolWorkType LineTool::toolType() const {
void LineTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
QPoint p0 = points[0];
QPoint p1 = points[1];
if (needsAdjustment(p0, p1)) {
p1.setY(p0.y());
}
painter.setPen(QPen(color, 2));
painter.setPen(QPen(color, 2 + thickness));
painter.drawLine(p0, p1);
}

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;

View File

@@ -51,7 +51,8 @@ CaptureTool::ToolWorkType MarkerTool::toolType() const {
void MarkerTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
QPoint p0 = points[0];
QPoint p1 = points[1];
@@ -59,7 +60,7 @@ void MarkerTool::processImage(
p1.setY(p0.y());
}
painter.setOpacity(0.35);
painter.setPen(QPen(color, 14));
painter.setPen(QPen(color, 14 + thickness));
painter.drawLine(p0, p1);
painter.setOpacity(1);
}

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;

View File

@@ -49,11 +49,13 @@ CaptureTool::ToolWorkType MoveTool::toolType() const {
void MoveTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
Q_UNUSED(painter);
Q_UNUSED(points);
Q_UNUSED(color);
Q_UNUSED(thickness);
}
void MoveTool::onPressed() {

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;

View File

@@ -49,9 +49,10 @@ CaptureTool::ToolWorkType PencilTool::toolType() const {
void PencilTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
painter.setPen(QPen(color, 2));
painter.setPen(QPen(color, 2 + thickness));
painter.drawPolyline(points.data(), points.size());
}

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;

View File

@@ -49,9 +49,10 @@ CaptureTool::ToolWorkType RectangleTool::toolType() const {
void RectangleTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
painter.setPen(QPen(color, 2));
painter.setPen(QPen(color, 2 + thickness));
painter.setBrush(QBrush(color));
painter.drawRect(QRect(points[0], points[1]));
painter.setBrush(QBrush());

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;

View File

@@ -49,11 +49,13 @@ CaptureTool::ToolWorkType SaveTool::toolType() const {
void SaveTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
Q_UNUSED(painter);
Q_UNUSED(points);
Q_UNUSED(color);
Q_UNUSED(thickness);
}
void SaveTool::onPressed() {

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;

View File

@@ -49,9 +49,10 @@ CaptureTool::ToolWorkType SelectionTool::toolType() const {
void SelectionTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
painter.setPen(QPen(color, 2));
painter.setPen(QPen(color, 2 + thickness));
painter.drawRect(QRect(points[0], points[1]));
}

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;

View File

@@ -49,11 +49,13 @@ CaptureTool::ToolWorkType SizeIndicatorTool::toolType() const {
void SizeIndicatorTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
Q_UNUSED(painter);
Q_UNUSED(points);
Q_UNUSED(color);
Q_UNUSED(thickness);
}
void SizeIndicatorTool::onPressed() {

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;

View File

@@ -49,11 +49,13 @@ CaptureTool::ToolWorkType UndoTool::toolType() const {
void UndoTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
Q_UNUSED(painter);
Q_UNUSED(points);
Q_UNUSED(color);
Q_UNUSED(thickness);
}
void UndoTool::onPressed() {

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;