From 7aa23a0e5867eeda3135254eb3b394ee78a0b769 Mon Sep 17 00:00:00 2001 From: sirius Date: Tue, 28 Jan 2020 00:52:29 +0800 Subject: [PATCH 01/16] find the line, rect and ellipse draw way --- PaintPlugin/src/DkPaintPlugin.cpp | 17 +++++++++++++++++ PaintPlugin/src/DkPaintPlugin.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/PaintPlugin/src/DkPaintPlugin.cpp b/PaintPlugin/src/DkPaintPlugin.cpp index 4a85d5c..7a4e313 100644 --- a/PaintPlugin/src/DkPaintPlugin.cpp +++ b/PaintPlugin/src/DkPaintPlugin.cpp @@ -219,6 +219,7 @@ void DkPaintViewPort::mousePressEvent(QMouseEvent *event) { paths.append(QPainterPath()); paths.last().moveTo(mapToImage(event->pos())); paths.last().lineTo(mapToImage(event->pos())+QPointF(0.1,0)); + begin = mapToImage(event->pos()); pathsPen.append(pen); update(); } @@ -260,7 +261,23 @@ void DkPaintViewPort::mouseMoveEvent(QMouseEvent *event) { } else { QPointF point = mapToImage(event->pos()); + // pencil paths.last().lineTo(point); + //paths.last().clear(); // comment to pencil + // line + //paths.last().moveTo(begin); + //paths.last().lineTo(point); + // ellipse + //paths.last().addEllipse(QRectF(begin, point)); + // rect + //paths.last().addRect(QRectF(begin, point)); + // blur (not implement) + //QRectF selected = QRectF(begin, point); + //QRectF scaled = QRectF(begin*10, point*10).normalized(); + //QGraphicsBlurEffect *blur = new QGraphicsBlurEffect; + //blur->setBlurRadius(10); + //QGraphicsPixmapItem *item = new QGraphicsPixmapItem(); + //item->setGraphicsEffect(blur); update(); } isOutside = false; diff --git a/PaintPlugin/src/DkPaintPlugin.h b/PaintPlugin/src/DkPaintPlugin.h index 34c7f6f..7200b7b 100644 --- a/PaintPlugin/src/DkPaintPlugin.h +++ b/PaintPlugin/src/DkPaintPlugin.h @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -116,6 +117,7 @@ public slots: QVector paths; QVector pathsPen; + QPointF begin; bool cancelTriggered; bool isOutside; From 021466845447b933bac61b6d4614051e4a5dead3 Mon Sep 17 00:00:00 2001 From: sirius Date: Tue, 28 Jan 2020 12:39:06 +0800 Subject: [PATCH 02/16] add buttons to different mode, pencil, line, circle, and square works --- PaintPlugin/src/DkPaintPlugin.cpp | 89 +++++++++++++++++++++++++- PaintPlugin/src/DkPaintPlugin.h | 28 ++++++++ PaintPlugin/src/DkPaintPlugin.json | 2 +- PaintPlugin/src/img/circle-outline.svg | 3 + PaintPlugin/src/img/line.svg | 3 + PaintPlugin/src/img/pencil.svg | 3 + PaintPlugin/src/img/square-outline.svg | 3 + PaintPlugin/src/nomacsPlugin.qrc | 4 ++ 8 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 PaintPlugin/src/img/circle-outline.svg create mode 100644 PaintPlugin/src/img/line.svg create mode 100644 PaintPlugin/src/img/pencil.svg create mode 100644 PaintPlugin/src/img/square-outline.svg diff --git a/PaintPlugin/src/DkPaintPlugin.cpp b/PaintPlugin/src/DkPaintPlugin.cpp index 7a4e313..fd2be2d 100644 --- a/PaintPlugin/src/DkPaintPlugin.cpp +++ b/PaintPlugin/src/DkPaintPlugin.cpp @@ -180,6 +180,7 @@ void DkPaintViewPort::init() { connect(paintToolbar, SIGNAL(panSignal(bool)), this, SLOT(setPanning(bool)), Qt::UniqueConnection); connect(paintToolbar, SIGNAL(cancelSignal()), this, SLOT(discardChangesAndClose()), Qt::UniqueConnection); connect(paintToolbar, SIGNAL(undoSignal()), this, SLOT(undoLastPaint()), Qt::UniqueConnection); + connect(paintToolbar, SIGNAL(modeChangeSignal(int)), this, SLOT(setMode(int)), Qt::UniqueConnection); connect(paintToolbar, SIGNAL(applySignal()), this, SLOT(applyChangesAndClose()), Qt::UniqueConnection); loadSettings(); @@ -261,8 +262,34 @@ void DkPaintViewPort::mouseMoveEvent(QMouseEvent *event) { } else { QPointF point = mapToImage(event->pos()); + switch (selectedMode) + { + case mode_pencil: + paths.last().lineTo(point); + break; + + case mode_line: + paths.last().clear(); + paths.last().moveTo(begin); + paths.last().lineTo(point); + break; + + case mode_circle: + paths.last().clear(); + paths.last().addEllipse(QRectF(begin, point)); + break; + + case mode_square: + paths.last().clear(); + paths.last().addRect(QRectF(begin, point)); + break; + + default: + paths.last().lineTo(point); + break; + } // pencil - paths.last().lineTo(point); + //paths.last().lineTo(point); //paths.last().clear(); // comment to pencil // line //paths.last().moveTo(begin); @@ -352,6 +379,13 @@ QImage DkPaintViewPort::getPaintedImage() { return QImage(); } +void DkPaintViewPort::setMode(int mode){ + selectedMode = mode; + setCursor(defaultCursor); + + this->repaint(); +} + void DkPaintViewPort::clear() { paths.clear(); pathsPen.clear(); @@ -443,6 +477,11 @@ void DkPaintToolBar::createIcons() { icons[pan_icon] = nmc::DkImage::loadIcon(":/nomacs/img/pan.svg"); icons[pan_icon].addPixmap(nmc::DkImage::loadIcon(":/nomacs/img/pan-checked.svg"), QIcon::Normal, QIcon::On); icons[undo_icon] = nmc::DkImage::loadIcon(":/nomacs/img/rotate-cc.svg"); + + icons[pencil_icon] = nmc::DkImage::loadIcon(":/nomacsPluginPaint/img/pencil.svg"); + icons[line_icon] = nmc::DkImage::loadIcon(":/nomacsPluginPaint/img/line.svg"); + icons[circle_icon] = nmc::DkImage::loadIcon(":/nomacsPluginPaint/img/circle-outline.svg"); + icons[square_icon] = nmc::DkImage::loadIcon(":/nomacsPluginPaint/img/square-outline.svg"); } void DkPaintToolBar::createLayout() { @@ -465,6 +504,27 @@ void DkPaintToolBar::createLayout() { panAction->setCheckable(true); panAction->setChecked(false); + // brush modes + pencilAction = new QAction(icons[pencil_icon], tr("Pencil"), this); + pencilAction->setObjectName("pencilAction"); + pencilAction->setCheckable(true); + pencilAction->setChecked(true); + + lineAction = new QAction(icons[line_icon], tr("Line"), this); + lineAction->setObjectName("lineAction"); + lineAction->setCheckable(true); + lineAction->setChecked(false); + + circleAction = new QAction(icons[circle_icon], tr("Circle"), this); + circleAction->setObjectName("circleAction"); + circleAction->setCheckable(true); + circleAction->setChecked(false); + + squareAction = new QAction(icons[square_icon], tr("Square"), this); + squareAction->setObjectName("squareAction"); + squareAction->setCheckable(true); + squareAction->setChecked(false); + // pen color penCol = QColor(0,0,0); penColButton = new QPushButton(this); @@ -495,12 +555,23 @@ void DkPaintToolBar::createLayout() { alphaBox->setMinimum(0); alphaBox->setMaximum(100); + QActionGroup *modesGroup = new QActionGroup(this); + modesGroup->addAction(pencilAction); + modesGroup->addAction(lineAction); + modesGroup->addAction(circleAction); + modesGroup->addAction(squareAction); + addAction(applyAction); addAction(cancelAction); addSeparator(); addAction(panAction); addAction(undoAction); addSeparator(); + addAction(pencilAction); + addAction(lineAction); + addAction(circleAction); + addAction(squareAction); + addSeparator(); addWidget(widthBox); addWidget(penColButton); addWidget(alphaBox); @@ -552,6 +623,22 @@ void DkPaintToolBar::on_panAction_toggled(bool checked) { emit panSignal(checked); } +void DkPaintToolBar::on_pencilAction_toggled(bool checked){ + emit modeChangeSignal(mode_pencil); +} + +void DkPaintToolBar::on_lineAction_toggled(bool checked){ + emit modeChangeSignal(mode_line); +} + +void DkPaintToolBar::on_circleAction_toggled(bool checked){ + emit modeChangeSignal(mode_circle); +} + +void DkPaintToolBar::on_squareAction_toggled(bool checked){ + emit modeChangeSignal(mode_square); +} + void DkPaintToolBar::on_widthBox_valueChanged(int val) { emit widthSignal(val); diff --git a/PaintPlugin/src/DkPaintPlugin.h b/PaintPlugin/src/DkPaintPlugin.h index 7200b7b..70cbe27 100644 --- a/PaintPlugin/src/DkPaintPlugin.h +++ b/PaintPlugin/src/DkPaintPlugin.h @@ -56,6 +56,13 @@ namespace nmp { class DkPaintViewPort; class DkPaintToolBar; +enum { + mode_pencil = 0, + mode_line, + mode_circle, + mode_square, +}; + class DkPaintPlugin : public QObject, nmc::DkViewPortInterface { Q_OBJECT Q_INTERFACES(nmc::DkViewPortInterface) @@ -105,6 +112,9 @@ public slots: virtual void setVisible(bool visible); void undoLastPaint(); +protected slots: + void setMode(int mode); + protected: void mouseMoveEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event); @@ -119,6 +129,8 @@ public slots: QVector pathsPen; QPointF begin; + int selectedMode; + bool cancelTriggered; bool isOutside; QBrush brush; @@ -142,9 +154,15 @@ class DkPaintToolBar : public QToolBar { pan_icon, undo_icon, + pencil_icon, + line_icon, + circle_icon, + square_icon, + icons_end, }; + DkPaintToolBar(const QString & title, QWidget * parent = 0); virtual ~DkPaintToolBar(); @@ -156,6 +174,10 @@ public slots: void on_applyAction_triggered(); void on_cancelAction_triggered(); void on_panAction_toggled(bool checked); + void on_pencilAction_toggled(bool checked); + void on_lineAction_toggled(bool checked); + void on_circleAction_toggled(bool checked); + void on_squareAction_toggled(bool checked); void on_penColButton_clicked(); void on_widthBox_valueChanged(int val); void on_alphaBox_valueChanged(int val); @@ -171,6 +193,7 @@ public slots: void shadingHint(bool invert); void panSignal(bool checked); void undoSignal(); + void modeChangeSignal(int mode); protected: void createLayout(); @@ -185,6 +208,11 @@ public slots: QAction* panAction; QAction* undoAction; + QAction* pencilAction; + QAction* lineAction; + QAction* circleAction; + QAction* squareAction; + QVector icons; // needed for colorizing }; diff --git a/PaintPlugin/src/DkPaintPlugin.json b/PaintPlugin/src/DkPaintPlugin.json index 4409bca..24b0fb7 100644 --- a/PaintPlugin/src/DkPaintPlugin.json +++ b/PaintPlugin/src/DkPaintPlugin.json @@ -3,7 +3,7 @@ "AuthorName" : "Tim Jerman", "Company" : "", "DateCreated" : "2014-05-01", - "DateModified" : "2018-11-30", + "DateModified" : "2020-01-28", "Description" : "Paint on an image. The color, size and opacity of the brush can be changed.", "Tagline" : "Draw with adjustable brushes to an image.", "PluginId" : "ad970ef36cc24737afd2b53ad015ff0d", diff --git a/PaintPlugin/src/img/circle-outline.svg b/PaintPlugin/src/img/circle-outline.svg new file mode 100644 index 0000000..01ff3ee --- /dev/null +++ b/PaintPlugin/src/img/circle-outline.svg @@ -0,0 +1,3 @@ + + + diff --git a/PaintPlugin/src/img/line.svg b/PaintPlugin/src/img/line.svg new file mode 100644 index 0000000..c65c1d5 --- /dev/null +++ b/PaintPlugin/src/img/line.svg @@ -0,0 +1,3 @@ + + + diff --git a/PaintPlugin/src/img/pencil.svg b/PaintPlugin/src/img/pencil.svg new file mode 100644 index 0000000..30320d2 --- /dev/null +++ b/PaintPlugin/src/img/pencil.svg @@ -0,0 +1,3 @@ + + + diff --git a/PaintPlugin/src/img/square-outline.svg b/PaintPlugin/src/img/square-outline.svg new file mode 100644 index 0000000..63fbf2e --- /dev/null +++ b/PaintPlugin/src/img/square-outline.svg @@ -0,0 +1,3 @@ + + + diff --git a/PaintPlugin/src/nomacsPlugin.qrc b/PaintPlugin/src/nomacsPlugin.qrc index ea610cd..318f37a 100644 --- a/PaintPlugin/src/nomacsPlugin.qrc +++ b/PaintPlugin/src/nomacsPlugin.qrc @@ -1,5 +1,9 @@ img/description.png + img/pencil.svg + img/line.svg + img/circle-outline.svg + img/square-outline.svg From 8df3c8d602e5db1bf2867d01eb2c05b6e1839f4d Mon Sep 17 00:00:00 2001 From: sirius Date: Tue, 28 Jan 2020 14:29:06 +0800 Subject: [PATCH 03/16] add arrow function --- PaintPlugin/src/DkPaintPlugin.cpp | 78 ++++++++++++++++++++++++++++++- PaintPlugin/src/DkPaintPlugin.h | 6 +++ PaintPlugin/src/nomacsPlugin.qrc | 1 + 3 files changed, 83 insertions(+), 2 deletions(-) diff --git a/PaintPlugin/src/DkPaintPlugin.cpp b/PaintPlugin/src/DkPaintPlugin.cpp index fd2be2d..c64e039 100644 --- a/PaintPlugin/src/DkPaintPlugin.cpp +++ b/PaintPlugin/src/DkPaintPlugin.cpp @@ -67,6 +67,55 @@ bool DkPaintPlugin::hideHUD() const { * @param run ID * @param current image in the Nomacs viewport **/ +const int ArrowWidth = 10; +const int ArrowHeight = 18; +QPainterPath getArrowHead(QPainterPath line, const int thickness) { + QPointF p1 = line.pointAtPercent(0.0); + QPointF p2 = line.pointAtPercent(1.0); + QLineF base(p1, p2); + // Create the vector for the position of the base of the arrowhead + QLineF temp(QPoint(0,0), p2-p1); + int val = ArrowHeight + thickness*4; + if (base.length() < val) { + val = (base.length() + thickness*2); + } + temp.setLength(base.length() + thickness*2 - val); + // Move across the line up to the head + QPointF bottonTranslation(temp.p2()); + + // Rotate base of the arrowhead + base.setLength(ArrowWidth + thickness*2); + base.setAngle(base.angle() + 90); + // Move to the correct point + QPointF temp2 = p1 - base.p2(); + // Center it + QPointF centerTranslation((temp2.x()/2), (temp2.y()/2)); + + base.translate(bottonTranslation); + base.translate(centerTranslation); + + QPainterPath path; + path.moveTo(p2); + path.lineTo(base.p1()); + path.lineTo(base.p2()); + path.lineTo(p2); + path.closeSubpath(); + return path; +} + +// gets a shorter line to prevent overlap in the point of the arrow +QLineF getShorterLine(QPainterPath line, const int thickness) { + QPointF p1 = line.pointAtPercent(0.0); + QPointF p2 = line.pointAtPercent(1.0); + QLineF l(p1, p2); + int val = ArrowHeight + thickness*4; + if (l.length() < val) { + val = (l.length() + thickness*2); + } + l.setLength(l.length() + thickness*2 - val); + return l.toLine(); +} + QSharedPointer DkPaintPlugin::runPlugin(const QString &runID, QSharedPointer image) const { if (!image) @@ -222,6 +271,7 @@ void DkPaintViewPort::mousePressEvent(QMouseEvent *event) { paths.last().lineTo(mapToImage(event->pos())+QPointF(0.1,0)); begin = mapToImage(event->pos()); pathsPen.append(pen); + pathsMode.append(selectedMode); update(); } else @@ -259,6 +309,7 @@ void DkPaintViewPort::mouseMoveEvent(QMouseEvent *event) { paths.append(QPainterPath()); paths.last().moveTo(mapToImage(event->pos())); pathsPen.append(pen); + pathsMode.append(selectedMode); } else { QPointF point = mapToImage(event->pos()); @@ -269,6 +320,7 @@ void DkPaintViewPort::mouseMoveEvent(QMouseEvent *event) { break; case mode_line: + case mode_arrow: paths.last().clear(); paths.last().moveTo(begin); paths.last().lineTo(point); @@ -338,7 +390,12 @@ void DkPaintViewPort::paintEvent(QPaintEvent *event) { for (int idx = 0; idx < paths.size(); idx++) { painter.setPen(pathsPen.at(idx)); - painter.drawPath(paths.at(idx)); + if(pathsMode.at(idx) == mode_arrow){ + painter.fillPath(getArrowHead(paths.at(idx), pathsPen.at(idx).width()), QBrush(pathsPen.at(idx).color())); + painter.drawLine(getShorterLine(paths.at(idx), pathsPen.at(idx).width())); + } + else + painter.drawPath(paths.at(idx)); } painter.end(); @@ -367,7 +424,12 @@ QImage DkPaintViewPort::getPaintedImage() { for (int idx = 0; idx < paths.size(); idx++) { painter.setPen(pathsPen.at(idx)); - painter.drawPath(paths.at(idx)); + if(pathsMode.at(idx) == mode_arrow){ + painter.fillPath(getArrowHead(paths.at(idx), pathsPen.at(idx).width()), QBrush(pathsPen.at(idx).color())); + painter.drawLine(getShorterLine(paths.at(idx), pathsPen.at(idx).width())); + } + else + painter.drawPath(paths.at(idx)); } painter.end(); @@ -480,6 +542,7 @@ void DkPaintToolBar::createIcons() { icons[pencil_icon] = nmc::DkImage::loadIcon(":/nomacsPluginPaint/img/pencil.svg"); icons[line_icon] = nmc::DkImage::loadIcon(":/nomacsPluginPaint/img/line.svg"); + icons[arrow_icon] = nmc::DkImage::loadIcon(":/nomacsPluginPaint/img/arrow.svg"); icons[circle_icon] = nmc::DkImage::loadIcon(":/nomacsPluginPaint/img/circle-outline.svg"); icons[square_icon] = nmc::DkImage::loadIcon(":/nomacsPluginPaint/img/square-outline.svg"); } @@ -515,6 +578,11 @@ void DkPaintToolBar::createLayout() { lineAction->setCheckable(true); lineAction->setChecked(false); + arrowAction = new QAction(icons[arrow_icon], tr("Arrow"), this); + arrowAction->setObjectName("arrowAction"); + arrowAction->setCheckable(true); + arrowAction->setChecked(false); + circleAction = new QAction(icons[circle_icon], tr("Circle"), this); circleAction->setObjectName("circleAction"); circleAction->setCheckable(true); @@ -558,6 +626,7 @@ void DkPaintToolBar::createLayout() { QActionGroup *modesGroup = new QActionGroup(this); modesGroup->addAction(pencilAction); modesGroup->addAction(lineAction); + modesGroup->addAction(arrowAction); modesGroup->addAction(circleAction); modesGroup->addAction(squareAction); @@ -569,6 +638,7 @@ void DkPaintToolBar::createLayout() { addSeparator(); addAction(pencilAction); addAction(lineAction); + addAction(arrowAction); addAction(circleAction); addAction(squareAction); addSeparator(); @@ -631,6 +701,10 @@ void DkPaintToolBar::on_lineAction_toggled(bool checked){ emit modeChangeSignal(mode_line); } +void DkPaintToolBar::on_arrowAction_toggled(bool checked){ + emit modeChangeSignal(mode_arrow); +} + void DkPaintToolBar::on_circleAction_toggled(bool checked){ emit modeChangeSignal(mode_circle); } diff --git a/PaintPlugin/src/DkPaintPlugin.h b/PaintPlugin/src/DkPaintPlugin.h index 70cbe27..20c398b 100644 --- a/PaintPlugin/src/DkPaintPlugin.h +++ b/PaintPlugin/src/DkPaintPlugin.h @@ -59,6 +59,7 @@ class DkPaintToolBar; enum { mode_pencil = 0, mode_line, + mode_arrow, mode_circle, mode_square, }; @@ -127,9 +128,11 @@ protected slots: QVector paths; QVector pathsPen; + QVector pathsMode; QPointF begin; int selectedMode; + QPainterPath ArrowHead; bool cancelTriggered; bool isOutside; @@ -156,6 +159,7 @@ class DkPaintToolBar : public QToolBar { pencil_icon, line_icon, + arrow_icon, circle_icon, square_icon, @@ -176,6 +180,7 @@ public slots: void on_panAction_toggled(bool checked); void on_pencilAction_toggled(bool checked); void on_lineAction_toggled(bool checked); + void on_arrowAction_toggled(bool checked); void on_circleAction_toggled(bool checked); void on_squareAction_toggled(bool checked); void on_penColButton_clicked(); @@ -210,6 +215,7 @@ public slots: QAction* pencilAction; QAction* lineAction; + QAction* arrowAction; QAction* circleAction; QAction* squareAction; diff --git a/PaintPlugin/src/nomacsPlugin.qrc b/PaintPlugin/src/nomacsPlugin.qrc index 318f37a..763e5d9 100644 --- a/PaintPlugin/src/nomacsPlugin.qrc +++ b/PaintPlugin/src/nomacsPlugin.qrc @@ -3,6 +3,7 @@ img/description.png img/pencil.svg img/line.svg + img/arrow.svg img/circle-outline.svg img/square-outline.svg From a33370d305111d07050d06dd69cde3560ab64364 Mon Sep 17 00:00:00 2001 From: sirius Date: Tue, 28 Jan 2020 14:43:57 +0800 Subject: [PATCH 04/16] add filled square function --- PaintPlugin/src/DkPaintPlugin.cpp | 17 +++++++++++++++++ PaintPlugin/src/DkPaintPlugin.h | 4 ++++ PaintPlugin/src/img/arrow.svg | 3 +++ PaintPlugin/src/img/square.svg | 3 +++ PaintPlugin/src/nomacsPlugin.qrc | 1 + 5 files changed, 28 insertions(+) create mode 100644 PaintPlugin/src/img/arrow.svg create mode 100644 PaintPlugin/src/img/square.svg diff --git a/PaintPlugin/src/DkPaintPlugin.cpp b/PaintPlugin/src/DkPaintPlugin.cpp index c64e039..3b66fa6 100644 --- a/PaintPlugin/src/DkPaintPlugin.cpp +++ b/PaintPlugin/src/DkPaintPlugin.cpp @@ -332,6 +332,7 @@ void DkPaintViewPort::mouseMoveEvent(QMouseEvent *event) { break; case mode_square: + case mode_square_fill: paths.last().clear(); paths.last().addRect(QRectF(begin, point)); break; @@ -394,6 +395,8 @@ void DkPaintViewPort::paintEvent(QPaintEvent *event) { painter.fillPath(getArrowHead(paths.at(idx), pathsPen.at(idx).width()), QBrush(pathsPen.at(idx).color())); painter.drawLine(getShorterLine(paths.at(idx), pathsPen.at(idx).width())); } + else if(pathsMode.at(idx) == mode_square_fill) + painter.fillPath(paths.at(idx), QBrush(pathsPen.at(idx).color())); else painter.drawPath(paths.at(idx)); } @@ -428,6 +431,8 @@ QImage DkPaintViewPort::getPaintedImage() { painter.fillPath(getArrowHead(paths.at(idx), pathsPen.at(idx).width()), QBrush(pathsPen.at(idx).color())); painter.drawLine(getShorterLine(paths.at(idx), pathsPen.at(idx).width())); } + else if(pathsMode.at(idx) == mode_arrow) + painter.fillPath(paths.at(idx), QBrush(pathsPen.at(idx).color())); else painter.drawPath(paths.at(idx)); } @@ -545,6 +550,7 @@ void DkPaintToolBar::createIcons() { icons[arrow_icon] = nmc::DkImage::loadIcon(":/nomacsPluginPaint/img/arrow.svg"); icons[circle_icon] = nmc::DkImage::loadIcon(":/nomacsPluginPaint/img/circle-outline.svg"); icons[square_icon] = nmc::DkImage::loadIcon(":/nomacsPluginPaint/img/square-outline.svg"); + icons[square_fill_icon] = nmc::DkImage::loadIcon(":/nomacsPluginPaint/img/square.svg"); } void DkPaintToolBar::createLayout() { @@ -593,6 +599,11 @@ void DkPaintToolBar::createLayout() { squareAction->setCheckable(true); squareAction->setChecked(false); + squarefillAction = new QAction(icons[square_fill_icon], tr("Filled Square"), this); + squarefillAction->setObjectName("squarefillAction"); + squarefillAction->setCheckable(true); + squarefillAction->setChecked(false); + // pen color penCol = QColor(0,0,0); penColButton = new QPushButton(this); @@ -629,6 +640,7 @@ void DkPaintToolBar::createLayout() { modesGroup->addAction(arrowAction); modesGroup->addAction(circleAction); modesGroup->addAction(squareAction); + modesGroup->addAction(squarefillAction); addAction(applyAction); addAction(cancelAction); @@ -641,6 +653,7 @@ void DkPaintToolBar::createLayout() { addAction(arrowAction); addAction(circleAction); addAction(squareAction); + addAction(squarefillAction); addSeparator(); addWidget(widthBox); addWidget(penColButton); @@ -713,6 +726,10 @@ void DkPaintToolBar::on_squareAction_toggled(bool checked){ emit modeChangeSignal(mode_square); } +void DkPaintToolBar::on_squarefillAction_toggled(bool checked){ + emit modeChangeSignal(mode_square_fill); +} + void DkPaintToolBar::on_widthBox_valueChanged(int val) { emit widthSignal(val); diff --git a/PaintPlugin/src/DkPaintPlugin.h b/PaintPlugin/src/DkPaintPlugin.h index 20c398b..986645d 100644 --- a/PaintPlugin/src/DkPaintPlugin.h +++ b/PaintPlugin/src/DkPaintPlugin.h @@ -62,6 +62,7 @@ enum { mode_arrow, mode_circle, mode_square, + mode_square_fill, }; class DkPaintPlugin : public QObject, nmc::DkViewPortInterface { @@ -162,6 +163,7 @@ class DkPaintToolBar : public QToolBar { arrow_icon, circle_icon, square_icon, + square_fill_icon, icons_end, }; @@ -183,6 +185,7 @@ public slots: void on_arrowAction_toggled(bool checked); void on_circleAction_toggled(bool checked); void on_squareAction_toggled(bool checked); + void on_squarefillAction_toggled(bool checked); void on_penColButton_clicked(); void on_widthBox_valueChanged(int val); void on_alphaBox_valueChanged(int val); @@ -218,6 +221,7 @@ public slots: QAction* arrowAction; QAction* circleAction; QAction* squareAction; + QAction* squarefillAction; QVector icons; // needed for colorizing diff --git a/PaintPlugin/src/img/arrow.svg b/PaintPlugin/src/img/arrow.svg new file mode 100644 index 0000000..048a0d3 --- /dev/null +++ b/PaintPlugin/src/img/arrow.svg @@ -0,0 +1,3 @@ + + + diff --git a/PaintPlugin/src/img/square.svg b/PaintPlugin/src/img/square.svg new file mode 100644 index 0000000..31b8298 --- /dev/null +++ b/PaintPlugin/src/img/square.svg @@ -0,0 +1,3 @@ + + + diff --git a/PaintPlugin/src/nomacsPlugin.qrc b/PaintPlugin/src/nomacsPlugin.qrc index 763e5d9..52179c1 100644 --- a/PaintPlugin/src/nomacsPlugin.qrc +++ b/PaintPlugin/src/nomacsPlugin.qrc @@ -6,5 +6,6 @@ img/arrow.svg img/circle-outline.svg img/square-outline.svg + img/square.svg From e7354f89173ff18f3699b9550114cb1970d5326b Mon Sep 17 00:00:00 2001 From: sirius Date: Tue, 28 Jan 2020 18:40:40 +0800 Subject: [PATCH 05/16] add blur function --- PaintPlugin/src/DkPaintPlugin.cpp | 52 +++++++++++++++++++++++++++++++ PaintPlugin/src/DkPaintPlugin.h | 4 +++ PaintPlugin/src/img/blur.svg | 4 +++ PaintPlugin/src/nomacsPlugin.qrc | 1 + 4 files changed, 61 insertions(+) create mode 100644 PaintPlugin/src/img/blur.svg diff --git a/PaintPlugin/src/DkPaintPlugin.cpp b/PaintPlugin/src/DkPaintPlugin.cpp index 3b66fa6..0cda3db 100644 --- a/PaintPlugin/src/DkPaintPlugin.cpp +++ b/PaintPlugin/src/DkPaintPlugin.cpp @@ -116,6 +116,28 @@ QLineF getShorterLine(QPainterPath line, const int thickness) { return l.toLine(); } +void getBlur(QPainterPath rect, QPainter *painter, QPixmap &pixmap){ + auto pixelRatio = pixmap.devicePixelRatio(); + QRectF selection = rect.boundingRect(); + QRect selectionScaled = selection.toRect(); + //QRectF selection = QRectF(p1, p2).normalized(); + //QRect selectionScaled = QRect(p1.toPoint()*pixelRatio, p2.toPoint()*pixelRatio).normalized(); + + QGraphicsBlurEffect *blur = new QGraphicsBlurEffect; + blur->setBlurRadius(10); + QGraphicsPixmapItem *item = new QGraphicsPixmapItem ( + pixmap.copy(selectionScaled)); + item->setGraphicsEffect(blur); + + QGraphicsScene scene; + scene.addItem(item); + + scene.render(painter, selection, QRectF()); + blur->setBlurRadius(12); + scene.render(painter, selection, QRectF()); + scene.render(painter, selection, QRectF()); +} + QSharedPointer DkPaintPlugin::runPlugin(const QString &runID, QSharedPointer image) const { if (!image) @@ -333,6 +355,7 @@ void DkPaintViewPort::mouseMoveEvent(QMouseEvent *event) { case mode_square: case mode_square_fill: + case mode_blur: paths.last().clear(); paths.last().addRect(QRectF(begin, point)); break; @@ -397,6 +420,19 @@ void DkPaintViewPort::paintEvent(QPaintEvent *event) { } else if(pathsMode.at(idx) == mode_square_fill) painter.fillPath(paths.at(idx), QBrush(pathsPen.at(idx).color())); + else if(pathsMode.at(idx) == mode_blur){ + /* + painter.setPen(QPen(QBrush(QColor(0,0,0,180)),1,Qt::DashLine)); + painter.setBrush(QBrush(QColor(255,255,255,120))); + painter.drawPath(paths.at(idx)); + */ + if(parent()){ + nmc::DkBaseViewPort* viewport = dynamic_cast(parent()); + QImage img = viewport->getImage(); + QPixmap pixmap = QPixmap::fromImage(img).copy(); + getBlur(paths.at(idx), &painter, pixmap); + } + } else painter.drawPath(paths.at(idx)); } @@ -433,6 +469,10 @@ QImage DkPaintViewPort::getPaintedImage() { } else if(pathsMode.at(idx) == mode_arrow) painter.fillPath(paths.at(idx), QBrush(pathsPen.at(idx).color())); + else if(pathsMode.at(idx) == mode_blur){ + QPixmap pixmap = QPixmap::fromImage(img).copy(); + getBlur(paths.at(idx), &painter, pixmap); + } else painter.drawPath(paths.at(idx)); } @@ -551,6 +591,7 @@ void DkPaintToolBar::createIcons() { icons[circle_icon] = nmc::DkImage::loadIcon(":/nomacsPluginPaint/img/circle-outline.svg"); icons[square_icon] = nmc::DkImage::loadIcon(":/nomacsPluginPaint/img/square-outline.svg"); icons[square_fill_icon] = nmc::DkImage::loadIcon(":/nomacsPluginPaint/img/square.svg"); + icons[blur_icon] = nmc::DkImage::loadIcon(":/nomacsPluginPaint/img/blur.svg"); } void DkPaintToolBar::createLayout() { @@ -604,6 +645,11 @@ void DkPaintToolBar::createLayout() { squarefillAction->setCheckable(true); squarefillAction->setChecked(false); + blurAction = new QAction(icons[blur_icon], tr("Blur"), this); + blurAction->setObjectName("blurAction"); + blurAction->setCheckable(true); + blurAction->setChecked(false); + // pen color penCol = QColor(0,0,0); penColButton = new QPushButton(this); @@ -641,6 +687,7 @@ void DkPaintToolBar::createLayout() { modesGroup->addAction(circleAction); modesGroup->addAction(squareAction); modesGroup->addAction(squarefillAction); + modesGroup->addAction(blurAction); addAction(applyAction); addAction(cancelAction); @@ -654,6 +701,7 @@ void DkPaintToolBar::createLayout() { addAction(circleAction); addAction(squareAction); addAction(squarefillAction); + addAction(blurAction); addSeparator(); addWidget(widthBox); addWidget(penColButton); @@ -730,6 +778,10 @@ void DkPaintToolBar::on_squarefillAction_toggled(bool checked){ emit modeChangeSignal(mode_square_fill); } +void DkPaintToolBar::on_blurAction_toggled(bool checked){ + emit modeChangeSignal(mode_blur); +} + void DkPaintToolBar::on_widthBox_valueChanged(int val) { emit widthSignal(val); diff --git a/PaintPlugin/src/DkPaintPlugin.h b/PaintPlugin/src/DkPaintPlugin.h index 986645d..0f5773e 100644 --- a/PaintPlugin/src/DkPaintPlugin.h +++ b/PaintPlugin/src/DkPaintPlugin.h @@ -63,6 +63,7 @@ enum { mode_circle, mode_square, mode_square_fill, + mode_blur, }; class DkPaintPlugin : public QObject, nmc::DkViewPortInterface { @@ -164,6 +165,7 @@ class DkPaintToolBar : public QToolBar { circle_icon, square_icon, square_fill_icon, + blur_icon, icons_end, }; @@ -186,6 +188,7 @@ public slots: void on_circleAction_toggled(bool checked); void on_squareAction_toggled(bool checked); void on_squarefillAction_toggled(bool checked); + void on_blurAction_toggled(bool checked); void on_penColButton_clicked(); void on_widthBox_valueChanged(int val); void on_alphaBox_valueChanged(int val); @@ -222,6 +225,7 @@ public slots: QAction* circleAction; QAction* squareAction; QAction* squarefillAction; + QAction* blurAction; QVector icons; // needed for colorizing diff --git a/PaintPlugin/src/img/blur.svg b/PaintPlugin/src/img/blur.svg new file mode 100644 index 0000000..3cb0b2d --- /dev/null +++ b/PaintPlugin/src/img/blur.svg @@ -0,0 +1,4 @@ + + + + diff --git a/PaintPlugin/src/nomacsPlugin.qrc b/PaintPlugin/src/nomacsPlugin.qrc index 52179c1..bd2ccbf 100644 --- a/PaintPlugin/src/nomacsPlugin.qrc +++ b/PaintPlugin/src/nomacsPlugin.qrc @@ -7,5 +7,6 @@ img/circle-outline.svg img/square-outline.svg img/square.svg + img/blur.svg From 92bd907915b23460e3dd0fabbd0952c5aef75823 Mon Sep 17 00:00:00 2001 From: sirius Date: Tue, 28 Jan 2020 19:01:11 +0800 Subject: [PATCH 06/16] fix bug caused by forgot clear mode vector when undo and finish, use penwidth as radius of blur --- PaintPlugin/src/DkPaintPlugin.cpp | 37 +++++++------------------------ PaintPlugin/src/DkPaintPlugin.h | 4 ++++ 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/PaintPlugin/src/DkPaintPlugin.cpp b/PaintPlugin/src/DkPaintPlugin.cpp index 0cda3db..67011f3 100644 --- a/PaintPlugin/src/DkPaintPlugin.cpp +++ b/PaintPlugin/src/DkPaintPlugin.cpp @@ -116,15 +116,14 @@ QLineF getShorterLine(QPainterPath line, const int thickness) { return l.toLine(); } -void getBlur(QPainterPath rect, QPainter *painter, QPixmap &pixmap){ +// blur selected rectangle region +void getBlur(QPainterPath rect, QPainter *painter, QPixmap &pixmap, int radius){ auto pixelRatio = pixmap.devicePixelRatio(); QRectF selection = rect.boundingRect(); QRect selectionScaled = selection.toRect(); - //QRectF selection = QRectF(p1, p2).normalized(); - //QRect selectionScaled = QRect(p1.toPoint()*pixelRatio, p2.toPoint()*pixelRatio).normalized(); QGraphicsBlurEffect *blur = new QGraphicsBlurEffect; - blur->setBlurRadius(10); + blur->setBlurRadius(radius); QGraphicsPixmapItem *item = new QGraphicsPixmapItem ( pixmap.copy(selectionScaled)); item->setGraphicsEffect(blur); @@ -133,7 +132,7 @@ void getBlur(QPainterPath rect, QPainter *painter, QPixmap &pixmap){ scene.addItem(item); scene.render(painter, selection, QRectF()); - blur->setBlurRadius(12); + blur->setBlurRadius(radius+2); scene.render(painter, selection, QRectF()); scene.render(painter, selection, QRectF()); } @@ -266,6 +265,7 @@ void DkPaintViewPort::undoLastPaint() { paths.pop_back(); pathsPen.pop_back(); + pathsMode.pop_back(); update(); } @@ -364,23 +364,6 @@ void DkPaintViewPort::mouseMoveEvent(QMouseEvent *event) { paths.last().lineTo(point); break; } - // pencil - //paths.last().lineTo(point); - //paths.last().clear(); // comment to pencil - // line - //paths.last().moveTo(begin); - //paths.last().lineTo(point); - // ellipse - //paths.last().addEllipse(QRectF(begin, point)); - // rect - //paths.last().addRect(QRectF(begin, point)); - // blur (not implement) - //QRectF selected = QRectF(begin, point); - //QRectF scaled = QRectF(begin*10, point*10).normalized(); - //QGraphicsBlurEffect *blur = new QGraphicsBlurEffect; - //blur->setBlurRadius(10); - //QGraphicsPixmapItem *item = new QGraphicsPixmapItem(); - //item->setGraphicsEffect(blur); update(); } isOutside = false; @@ -421,16 +404,11 @@ void DkPaintViewPort::paintEvent(QPaintEvent *event) { else if(pathsMode.at(idx) == mode_square_fill) painter.fillPath(paths.at(idx), QBrush(pathsPen.at(idx).color())); else if(pathsMode.at(idx) == mode_blur){ - /* - painter.setPen(QPen(QBrush(QColor(0,0,0,180)),1,Qt::DashLine)); - painter.setBrush(QBrush(QColor(255,255,255,120))); - painter.drawPath(paths.at(idx)); - */ if(parent()){ nmc::DkBaseViewPort* viewport = dynamic_cast(parent()); QImage img = viewport->getImage(); QPixmap pixmap = QPixmap::fromImage(img).copy(); - getBlur(paths.at(idx), &painter, pixmap); + getBlur(paths.at(idx), &painter, pixmap, pathsPen.at(idx).width()); } } else @@ -471,7 +449,7 @@ QImage DkPaintViewPort::getPaintedImage() { painter.fillPath(paths.at(idx), QBrush(pathsPen.at(idx).color())); else if(pathsMode.at(idx) == mode_blur){ QPixmap pixmap = QPixmap::fromImage(img).copy(); - getBlur(paths.at(idx), &painter, pixmap); + getBlur(paths.at(idx), &painter, pixmap, pathsPen.at(idx).width()); } else painter.drawPath(paths.at(idx)); @@ -496,6 +474,7 @@ void DkPaintViewPort::setMode(int mode){ void DkPaintViewPort::clear() { paths.clear(); pathsPen.clear(); + pathsMode.clear(); } void DkPaintViewPort::setBrush(const QBrush& brush) { diff --git a/PaintPlugin/src/DkPaintPlugin.h b/PaintPlugin/src/DkPaintPlugin.h index 0f5773e..bf05d9e 100644 --- a/PaintPlugin/src/DkPaintPlugin.h +++ b/PaintPlugin/src/DkPaintPlugin.h @@ -79,6 +79,10 @@ class DkPaintPlugin : public QObject, nmc::DkViewPortInterface { QImage image() const override; bool hideHUD() const override; + QPainterPath getArrowHead(QPainterPath line, const int thickness); + QLineF getShorterLine(QPainterPath line, const int thickness); + void getBlur(QPainterPath rect, QPainter *painter, QPixmap &pixmap, int radius); + QSharedPointer runPlugin(const QString &runID = QString(), QSharedPointer image = QSharedPointer()) const override; nmc::DkPluginViewPort* getViewPort() override; bool createViewPort(QWidget* parent) override; From b6c7a5baefefbc01eefa982426b1bc545cafacc9 Mon Sep 17 00:00:00 2001 From: sirius Date: Tue, 28 Jan 2020 19:46:41 +0800 Subject: [PATCH 07/16] fix bug that filled square become square frame when saving --- PaintPlugin/src/DkPaintPlugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PaintPlugin/src/DkPaintPlugin.cpp b/PaintPlugin/src/DkPaintPlugin.cpp index 67011f3..be509ed 100644 --- a/PaintPlugin/src/DkPaintPlugin.cpp +++ b/PaintPlugin/src/DkPaintPlugin.cpp @@ -445,7 +445,7 @@ QImage DkPaintViewPort::getPaintedImage() { painter.fillPath(getArrowHead(paths.at(idx), pathsPen.at(idx).width()), QBrush(pathsPen.at(idx).color())); painter.drawLine(getShorterLine(paths.at(idx), pathsPen.at(idx).width())); } - else if(pathsMode.at(idx) == mode_arrow) + else if(pathsMode.at(idx) == mode_square_fill) painter.fillPath(paths.at(idx), QBrush(pathsPen.at(idx).color())); else if(pathsMode.at(idx) == mode_blur){ QPixmap pixmap = QPixmap::fromImage(img).copy(); From 3e140082c3c1957f82e7c44a2ef153ad230dfe94 Mon Sep 17 00:00:00 2001 From: sirius Date: Wed, 29 Jan 2020 00:31:44 +0800 Subject: [PATCH 08/16] not use QPainterPath::clear() because of Qt version --- PaintPlugin/src/DkPaintPlugin.cpp | 9 ++++++--- PaintPlugin/src/DkPaintPlugin.json | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/PaintPlugin/src/DkPaintPlugin.cpp b/PaintPlugin/src/DkPaintPlugin.cpp index be509ed..ba92187 100644 --- a/PaintPlugin/src/DkPaintPlugin.cpp +++ b/PaintPlugin/src/DkPaintPlugin.cpp @@ -343,20 +343,23 @@ void DkPaintViewPort::mouseMoveEvent(QMouseEvent *event) { case mode_line: case mode_arrow: - paths.last().clear(); + //paths.last().clear(); + paths.last() = QPainterPath(); paths.last().moveTo(begin); paths.last().lineTo(point); break; case mode_circle: - paths.last().clear(); + //paths.last().clear(); + paths.last() = QPainterPath(); paths.last().addEllipse(QRectF(begin, point)); break; case mode_square: case mode_square_fill: case mode_blur: - paths.last().clear(); + //paths.last().clear(); + paths.last() = QPainterPath(); paths.last().addRect(QRectF(begin, point)); break; diff --git a/PaintPlugin/src/DkPaintPlugin.json b/PaintPlugin/src/DkPaintPlugin.json index 24b0fb7..e92d0d4 100644 --- a/PaintPlugin/src/DkPaintPlugin.json +++ b/PaintPlugin/src/DkPaintPlugin.json @@ -3,7 +3,7 @@ "AuthorName" : "Tim Jerman", "Company" : "", "DateCreated" : "2014-05-01", - "DateModified" : "2020-01-28", + "DateModified" : "2020-01-29", "Description" : "Paint on an image. The color, size and opacity of the brush can be changed.", "Tagline" : "Draw with adjustable brushes to an image.", "PluginId" : "ad970ef36cc24737afd2b53ad015ff0d", From 6984da7fab4ebb57e3c2089e2135c90f42ece827 Mon Sep 17 00:00:00 2001 From: sirius Date: Wed, 29 Jan 2020 13:03:28 +0800 Subject: [PATCH 09/16] add test text function --- PaintPlugin/src/DkPaintPlugin.cpp | 27 +++++++++++++++++++++++++-- PaintPlugin/src/DkPaintPlugin.h | 4 ++++ PaintPlugin/src/img/text.svg | 4 ++++ PaintPlugin/src/nomacsPlugin.qrc | 1 + 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 PaintPlugin/src/img/text.svg diff --git a/PaintPlugin/src/DkPaintPlugin.cpp b/PaintPlugin/src/DkPaintPlugin.cpp index ba92187..909cfce 100644 --- a/PaintPlugin/src/DkPaintPlugin.cpp +++ b/PaintPlugin/src/DkPaintPlugin.cpp @@ -294,6 +294,14 @@ void DkPaintViewPort::mousePressEvent(QMouseEvent *event) { begin = mapToImage(event->pos()); pathsPen.append(pen); pathsMode.append(selectedMode); + if(selectedMode == mode_text) + { + QFont font; + font.setFamily(font.defaultFamily()); + font.setPixelSize(pen.width()*15); + paths.last() = QPainterPath(); + paths.last().addText(begin, font, "Qt text test"); + } update(); } else @@ -363,6 +371,9 @@ void DkPaintViewPort::mouseMoveEvent(QMouseEvent *event) { paths.last().addRect(QRectF(begin, point)); break; + case mode_text: + break; + default: paths.last().lineTo(point); break; @@ -404,7 +415,7 @@ void DkPaintViewPort::paintEvent(QPaintEvent *event) { painter.fillPath(getArrowHead(paths.at(idx), pathsPen.at(idx).width()), QBrush(pathsPen.at(idx).color())); painter.drawLine(getShorterLine(paths.at(idx), pathsPen.at(idx).width())); } - else if(pathsMode.at(idx) == mode_square_fill) + else if(pathsMode.at(idx) == mode_square_fill || pathsMode.at(idx) == mode_text) painter.fillPath(paths.at(idx), QBrush(pathsPen.at(idx).color())); else if(pathsMode.at(idx) == mode_blur){ if(parent()){ @@ -448,7 +459,7 @@ QImage DkPaintViewPort::getPaintedImage() { painter.fillPath(getArrowHead(paths.at(idx), pathsPen.at(idx).width()), QBrush(pathsPen.at(idx).color())); painter.drawLine(getShorterLine(paths.at(idx), pathsPen.at(idx).width())); } - else if(pathsMode.at(idx) == mode_square_fill) + else if(pathsMode.at(idx) == mode_square_fill || pathsMode.at(idx) == mode_text) painter.fillPath(paths.at(idx), QBrush(pathsPen.at(idx).color())); else if(pathsMode.at(idx) == mode_blur){ QPixmap pixmap = QPixmap::fromImage(img).copy(); @@ -574,6 +585,7 @@ void DkPaintToolBar::createIcons() { icons[square_icon] = nmc::DkImage::loadIcon(":/nomacsPluginPaint/img/square-outline.svg"); icons[square_fill_icon] = nmc::DkImage::loadIcon(":/nomacsPluginPaint/img/square.svg"); icons[blur_icon] = nmc::DkImage::loadIcon(":/nomacsPluginPaint/img/blur.svg"); + icons[text_icon] = nmc::DkImage::loadIcon(":/nomacsPluginPaint/img/text.svg"); } void DkPaintToolBar::createLayout() { @@ -632,6 +644,11 @@ void DkPaintToolBar::createLayout() { blurAction->setCheckable(true); blurAction->setChecked(false); + textAction = new QAction(icons[text_icon], tr("Text"), this); + textAction->setObjectName("textAction"); + textAction->setCheckable(true); + textAction->setChecked(false); + // pen color penCol = QColor(0,0,0); penColButton = new QPushButton(this); @@ -670,6 +687,7 @@ void DkPaintToolBar::createLayout() { modesGroup->addAction(squareAction); modesGroup->addAction(squarefillAction); modesGroup->addAction(blurAction); + modesGroup->addAction(textAction); addAction(applyAction); addAction(cancelAction); @@ -684,6 +702,7 @@ void DkPaintToolBar::createLayout() { addAction(squareAction); addAction(squarefillAction); addAction(blurAction); + addAction(textAction); addSeparator(); addWidget(widthBox); addWidget(penColButton); @@ -764,6 +783,10 @@ void DkPaintToolBar::on_blurAction_toggled(bool checked){ emit modeChangeSignal(mode_blur); } +void DkPaintToolBar::on_textAction_toggled(bool checked){ + emit modeChangeSignal(mode_text); +} + void DkPaintToolBar::on_widthBox_valueChanged(int val) { emit widthSignal(val); diff --git a/PaintPlugin/src/DkPaintPlugin.h b/PaintPlugin/src/DkPaintPlugin.h index bf05d9e..339338a 100644 --- a/PaintPlugin/src/DkPaintPlugin.h +++ b/PaintPlugin/src/DkPaintPlugin.h @@ -64,6 +64,7 @@ enum { mode_square, mode_square_fill, mode_blur, + mode_text, }; class DkPaintPlugin : public QObject, nmc::DkViewPortInterface { @@ -170,6 +171,7 @@ class DkPaintToolBar : public QToolBar { square_icon, square_fill_icon, blur_icon, + text_icon, icons_end, }; @@ -193,6 +195,7 @@ public slots: void on_squareAction_toggled(bool checked); void on_squarefillAction_toggled(bool checked); void on_blurAction_toggled(bool checked); + void on_textAction_toggled(bool checked); void on_penColButton_clicked(); void on_widthBox_valueChanged(int val); void on_alphaBox_valueChanged(int val); @@ -230,6 +233,7 @@ public slots: QAction* squareAction; QAction* squarefillAction; QAction* blurAction; + QAction* textAction; QVector icons; // needed for colorizing diff --git a/PaintPlugin/src/img/text.svg b/PaintPlugin/src/img/text.svg new file mode 100644 index 0000000..19024ee --- /dev/null +++ b/PaintPlugin/src/img/text.svg @@ -0,0 +1,4 @@ + + + + diff --git a/PaintPlugin/src/nomacsPlugin.qrc b/PaintPlugin/src/nomacsPlugin.qrc index bd2ccbf..c70d8e9 100644 --- a/PaintPlugin/src/nomacsPlugin.qrc +++ b/PaintPlugin/src/nomacsPlugin.qrc @@ -8,5 +8,6 @@ img/square-outline.svg img/square.svg img/blur.svg + img/text.svg From f65b4f426748ae12f19ea4d3a4f78b0028ec3c97 Mon Sep 17 00:00:00 2001 From: sirius Date: Wed, 29 Jan 2020 17:19:54 +0800 Subject: [PATCH 10/16] can enter text in text tool now --- PaintPlugin/src/DkPaintPlugin.cpp | 8 +++++--- PaintPlugin/src/DkPaintPlugin.h | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/PaintPlugin/src/DkPaintPlugin.cpp b/PaintPlugin/src/DkPaintPlugin.cpp index 909cfce..8e5d16f 100644 --- a/PaintPlugin/src/DkPaintPlugin.cpp +++ b/PaintPlugin/src/DkPaintPlugin.cpp @@ -290,7 +290,7 @@ void DkPaintViewPort::mousePressEvent(QMouseEvent *event) { isOutside = false; paths.append(QPainterPath()); paths.last().moveTo(mapToImage(event->pos())); - paths.last().lineTo(mapToImage(event->pos())+QPointF(0.1,0)); + //paths.last().lineTo(mapToImage(event->pos())+QPointF(0.1,0)); begin = mapToImage(event->pos()); pathsPen.append(pen); pathsMode.append(selectedMode); @@ -299,8 +299,10 @@ void DkPaintViewPort::mousePressEvent(QMouseEvent *event) { QFont font; font.setFamily(font.defaultFamily()); font.setPixelSize(pen.width()*15); - paths.last() = QPainterPath(); - paths.last().addText(begin, font, "Qt text test"); + QString text; + text = QInputDialog::getText(this, "Text Input", tr("string"), QLineEdit::Normal); + paths.last().addText(begin, font, text); + text.clear(); } update(); } diff --git a/PaintPlugin/src/DkPaintPlugin.h b/PaintPlugin/src/DkPaintPlugin.h index 339338a..0fc6a0a 100644 --- a/PaintPlugin/src/DkPaintPlugin.h +++ b/PaintPlugin/src/DkPaintPlugin.h @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include From 132bf3b9f268525a2a834eb093c04eaeceed0db1 Mon Sep 17 00:00:00 2001 From: sirius Date: Wed, 29 Jan 2020 22:13:01 +0800 Subject: [PATCH 11/16] use qlineedit to edit text --- PaintPlugin/src/DkPaintPlugin.cpp | 52 +++++++++++++++++++++++++++++++ PaintPlugin/src/DkPaintPlugin.h | 11 +++++++ 2 files changed, 63 insertions(+) diff --git a/PaintPlugin/src/DkPaintPlugin.cpp b/PaintPlugin/src/DkPaintPlugin.cpp index 8e5d16f..2f2bbbe 100644 --- a/PaintPlugin/src/DkPaintPlugin.cpp +++ b/PaintPlugin/src/DkPaintPlugin.cpp @@ -252,6 +252,8 @@ void DkPaintViewPort::init() { connect(paintToolbar, SIGNAL(undoSignal()), this, SLOT(undoLastPaint()), Qt::UniqueConnection); connect(paintToolbar, SIGNAL(modeChangeSignal(int)), this, SLOT(setMode(int)), Qt::UniqueConnection); connect(paintToolbar, SIGNAL(applySignal()), this, SLOT(applyChangesAndClose()), Qt::UniqueConnection); + connect(paintToolbar, SIGNAL(textChangeSignal(const QString&)), this, SLOT(textChange(const QString&)), Qt::UniqueConnection); + connect(paintToolbar, SIGNAL(editFinishSignal()), this, SLOT(textEditFinsh()), Qt::UniqueConnection); loadSettings(); paintToolbar->setPenColor(pen.color()); @@ -296,6 +298,9 @@ void DkPaintViewPort::mousePressEvent(QMouseEvent *event) { pathsMode.append(selectedMode); if(selectedMode == mode_text) { + //QLineEdit *textInput = new QLineEdit(this); + //connect (textInput, SIGNAL(textChanged(const QString &text)), this, SLOT(textChange(const QString &text))); + /* QFont font; font.setFamily(font.defaultFamily()); font.setPixelSize(pen.width()*15); @@ -303,6 +308,7 @@ void DkPaintViewPort::mousePressEvent(QMouseEvent *event) { text = QInputDialog::getText(this, "Text Input", tr("string"), QLineEdit::Normal); paths.last().addText(begin, font, text); text.clear(); + */ } update(); } @@ -487,6 +493,18 @@ void DkPaintViewPort::setMode(int mode){ this->repaint(); } +void DkPaintViewPort::textChange(const QString &text){ + paths.last() = QPainterPath(); + QFont font; + font.setFamily(font.defaultFamily()); + font.setPixelSize(pen.width()*15); + paths.last().addText(begin, font, text); + update(); +} + +void DkPaintViewPort::textEditFinsh(){ +} + void DkPaintViewPort::clear() { paths.clear(); pathsPen.clear(); @@ -651,6 +669,9 @@ void DkPaintToolBar::createLayout() { textAction->setCheckable(true); textAction->setChecked(false); + textInput = new QLineEdit(this); + textInput->setObjectName("textInput"); + // pen color penCol = QColor(0,0,0); penColButton = new QPushButton(this); @@ -691,6 +712,8 @@ void DkPaintToolBar::createLayout() { modesGroup->addAction(blurAction); modesGroup->addAction(textAction); + toolbarWidgetList = QMap(); + addAction(applyAction); addAction(cancelAction); addSeparator(); @@ -709,6 +732,18 @@ void DkPaintToolBar::createLayout() { addWidget(widthBox); addWidget(penColButton); addWidget(alphaBox); + addSeparator(); + //addWidget(textInput); + toolbarWidgetList.insert(textInput->objectName(), this->addWidget(textInput)); + + modifyLayout(mode_pencil); +} + +void DkPaintToolBar::modifyLayout(int mode) { + //if(mode == mode_text) + // toolbarWidgetList.value(textInput->objectName())->setVisible(true); + //else + toolbarWidgetList.value(textInput->objectName())->setVisible(false); } void DkPaintToolBar::setVisible(bool visible) { @@ -758,34 +793,42 @@ void DkPaintToolBar::on_panAction_toggled(bool checked) { } void DkPaintToolBar::on_pencilAction_toggled(bool checked){ + modifyLayout(mode_pencil); emit modeChangeSignal(mode_pencil); } void DkPaintToolBar::on_lineAction_toggled(bool checked){ + modifyLayout(mode_line); emit modeChangeSignal(mode_line); } void DkPaintToolBar::on_arrowAction_toggled(bool checked){ + modifyLayout(mode_arrow); emit modeChangeSignal(mode_arrow); } void DkPaintToolBar::on_circleAction_toggled(bool checked){ + modifyLayout(mode_circle); emit modeChangeSignal(mode_circle); } void DkPaintToolBar::on_squareAction_toggled(bool checked){ + modifyLayout(mode_square); emit modeChangeSignal(mode_square); } void DkPaintToolBar::on_squarefillAction_toggled(bool checked){ + modifyLayout(mode_square_fill); emit modeChangeSignal(mode_square_fill); } void DkPaintToolBar::on_blurAction_toggled(bool checked){ + modifyLayout(mode_blur); emit modeChangeSignal(mode_blur); } void DkPaintToolBar::on_textAction_toggled(bool checked){ + modifyLayout(mode_text); emit modeChangeSignal(mode_text); } @@ -794,6 +837,15 @@ void DkPaintToolBar::on_widthBox_valueChanged(int val) { emit widthSignal(val); } +void DkPaintToolBar::on_textInput_textChanged(const QString &text){ + emit textChangeSignal(text); +} + +void DkPaintToolBar::on_textInput_editingFinished() +{ + emit editFinishSignal(); +} + void DkPaintToolBar::on_alphaBox_valueChanged(int val) { penAlpha = val; diff --git a/PaintPlugin/src/DkPaintPlugin.h b/PaintPlugin/src/DkPaintPlugin.h index 0fc6a0a..06069c7 100644 --- a/PaintPlugin/src/DkPaintPlugin.h +++ b/PaintPlugin/src/DkPaintPlugin.h @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -123,6 +124,8 @@ public slots: protected slots: void setMode(int mode); + void textChange(const QString &text); + void textEditFinsh(); protected: void mouseMoveEvent(QMouseEvent *event); @@ -200,6 +203,8 @@ public slots: void on_penColButton_clicked(); void on_widthBox_valueChanged(int val); void on_alphaBox_valueChanged(int val); + void on_textInput_textChanged(const QString &text); + void on_textInput_editingFinished(); void on_undoAction_triggered(); virtual void setVisible(bool visible); @@ -213,10 +218,13 @@ public slots: void panSignal(bool checked); void undoSignal(); void modeChangeSignal(int mode); + void textChangeSignal(const QString &text); + void editFinishSignal(); protected: void createLayout(); void createIcons(); + void modifyLayout(int mode); QPushButton* penColButton; QColorDialog* colorDialog; @@ -224,6 +232,7 @@ public slots: QSpinBox* alphaBox; QColor penCol; int penAlpha; + QMap toolbarWidgetList; QAction* panAction; QAction* undoAction; @@ -236,6 +245,8 @@ public slots: QAction* blurAction; QAction* textAction; + QLineEdit* textInput; + QVector icons; // needed for colorizing }; From 957abe74a7d7f81b4c7af495c8fde402b757a8ae Mon Sep 17 00:00:00 2001 From: sirius Date: Thu, 30 Jan 2020 00:20:50 +0800 Subject: [PATCH 12/16] deal with empty input and input end for text tool --- PaintPlugin/src/DkPaintPlugin.cpp | 25 +++++++++++++++++-------- PaintPlugin/src/DkPaintPlugin.h | 2 ++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/PaintPlugin/src/DkPaintPlugin.cpp b/PaintPlugin/src/DkPaintPlugin.cpp index 2f2bbbe..68480d9 100644 --- a/PaintPlugin/src/DkPaintPlugin.cpp +++ b/PaintPlugin/src/DkPaintPlugin.cpp @@ -258,6 +258,7 @@ void DkPaintViewPort::init() { loadSettings(); paintToolbar->setPenColor(pen.color()); paintToolbar->setPenWidth(pen.width()); + textinputenable = false; } void DkPaintViewPort::undoLastPaint() { @@ -298,6 +299,7 @@ void DkPaintViewPort::mousePressEvent(QMouseEvent *event) { pathsMode.append(selectedMode); if(selectedMode == mode_text) { + textinputenable = true; //QLineEdit *textInput = new QLineEdit(this); //connect (textInput, SIGNAL(textChanged(const QString &text)), this, SLOT(textChange(const QString &text))); /* @@ -494,15 +496,22 @@ void DkPaintViewPort::setMode(int mode){ } void DkPaintViewPort::textChange(const QString &text){ - paths.last() = QPainterPath(); QFont font; font.setFamily(font.defaultFamily()); font.setPixelSize(pen.width()*15); - paths.last().addText(begin, font, text); - update(); + if(textinputenable) + { + sbuffer = text; + paths.last() = QPainterPath(); + paths.last().addText(begin, font, text); + update(); + } } void DkPaintViewPort::textEditFinsh(){ + if(sbuffer.isEmpty()) + undoLastPaint(); + textinputenable = false; } void DkPaintViewPort::clear() { @@ -740,9 +749,9 @@ void DkPaintToolBar::createLayout() { } void DkPaintToolBar::modifyLayout(int mode) { - //if(mode == mode_text) - // toolbarWidgetList.value(textInput->objectName())->setVisible(true); - //else + if(mode == mode_text) + toolbarWidgetList.value(textInput->objectName())->setVisible(true); + else toolbarWidgetList.value(textInput->objectName())->setVisible(false); } @@ -841,9 +850,9 @@ void DkPaintToolBar::on_textInput_textChanged(const QString &text){ emit textChangeSignal(text); } -void DkPaintToolBar::on_textInput_editingFinished() -{ +void DkPaintToolBar::on_textInput_editingFinished(){ emit editFinishSignal(); + textInput->clear(); } void DkPaintToolBar::on_alphaBox_valueChanged(int val) { diff --git a/PaintPlugin/src/DkPaintPlugin.h b/PaintPlugin/src/DkPaintPlugin.h index 06069c7..a3bf925 100644 --- a/PaintPlugin/src/DkPaintPlugin.h +++ b/PaintPlugin/src/DkPaintPlugin.h @@ -141,8 +141,10 @@ protected slots: QVector pathsPen; QVector pathsMode; QPointF begin; + QString sbuffer; int selectedMode; + bool textinputenable; QPainterPath ArrowHead; bool cancelTriggered; From d3c780da23d817758ff3930da048750b459669df Mon Sep 17 00:00:00 2001 From: sirius Date: Thu, 30 Jan 2020 01:03:33 +0800 Subject: [PATCH 13/16] show cursor when preview --- PaintPlugin/src/DkPaintPlugin.cpp | 15 ++++++++++++++- PaintPlugin/src/DkPaintPlugin.h | 1 - 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/PaintPlugin/src/DkPaintPlugin.cpp b/PaintPlugin/src/DkPaintPlugin.cpp index 68480d9..8e820c1 100644 --- a/PaintPlugin/src/DkPaintPlugin.cpp +++ b/PaintPlugin/src/DkPaintPlugin.cpp @@ -425,8 +425,20 @@ void DkPaintViewPort::paintEvent(QPaintEvent *event) { painter.fillPath(getArrowHead(paths.at(idx), pathsPen.at(idx).width()), QBrush(pathsPen.at(idx).color())); painter.drawLine(getShorterLine(paths.at(idx), pathsPen.at(idx).width())); } - else if(pathsMode.at(idx) == mode_square_fill || pathsMode.at(idx) == mode_text) + //else if(pathsMode.at(idx) == mode_square_fill || pathsMode.at(idx) == mode_text) + else if(pathsMode.at(idx) == mode_square_fill) painter.fillPath(paths.at(idx), QBrush(pathsPen.at(idx).color())); + else if(pathsMode.at(idx) == mode_text){ + painter.fillPath(paths.at(idx), QBrush(pathsPen.at(idx).color())); + //painter.setPen(QPen(QBrush(QColor(0,0,0,180)),1,Qt::DashLine)); + //painter.setBrush(QBrush(QColor(255,255,255,120))); + //painter.drawRect(paths.at(idx).boundingRect()); + //painter.setPen(pathsPen.at(idx)); + QPointF p = paths.at(idx).boundingRect().bottomRight(); + painter.setPen(QPen(QBrush(QColor(0,0,0,180)),3,Qt::DotLine)); + painter.drawLine(QLineF(p, p-QPoint(0, pathsPen.at(idx).width()*10))); + //painter.drawPoint(paths.at(idx).boundingRect().bottomRight()); + } else if(pathsMode.at(idx) == mode_blur){ if(parent()){ nmc::DkBaseViewPort* viewport = dynamic_cast(parent()); @@ -680,6 +692,7 @@ void DkPaintToolBar::createLayout() { textInput = new QLineEdit(this); textInput->setObjectName("textInput"); + textInput->setFixedWidth(100); // pen color penCol = QColor(0,0,0); diff --git a/PaintPlugin/src/DkPaintPlugin.h b/PaintPlugin/src/DkPaintPlugin.h index a3bf925..c1d885a 100644 --- a/PaintPlugin/src/DkPaintPlugin.h +++ b/PaintPlugin/src/DkPaintPlugin.h @@ -37,7 +37,6 @@ #include #include #include -#include #include #include #include From 6d7f58771f47c92fe951b494fe638362e73e3337 Mon Sep 17 00:00:00 2001 From: sirius Date: Thu, 30 Jan 2020 13:05:51 +0800 Subject: [PATCH 14/16] show cursor only when text editing --- PaintPlugin/src/DkPaintPlugin.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/PaintPlugin/src/DkPaintPlugin.cpp b/PaintPlugin/src/DkPaintPlugin.cpp index 8e820c1..9f6e060 100644 --- a/PaintPlugin/src/DkPaintPlugin.cpp +++ b/PaintPlugin/src/DkPaintPlugin.cpp @@ -435,8 +435,14 @@ void DkPaintViewPort::paintEvent(QPaintEvent *event) { //painter.drawRect(paths.at(idx).boundingRect()); //painter.setPen(pathsPen.at(idx)); QPointF p = paths.at(idx).boundingRect().bottomRight(); - painter.setPen(QPen(QBrush(QColor(0,0,0,180)),3,Qt::DotLine)); - painter.drawLine(QLineF(p, p-QPoint(0, pathsPen.at(idx).width()*10))); + if((idx == paths.size()-1) && (textinputenable)) + { + painter.setPen(QPen(QBrush(QColor(0,0,0,180)),3,Qt::DotLine)); + if(sbuffer.isEmpty()) + painter.drawLine(QLineF(begin, begin-QPoint(0, pathsPen.at(idx).width()*10))); + else + painter.drawLine(QLineF(p, p-QPoint(0, pathsPen.at(idx).width()*10))); + } //painter.drawPoint(paths.at(idx).boundingRect().bottomRight()); } else if(pathsMode.at(idx) == mode_blur){ From 4bb735b9931d03931dcd1edfd9ad1a754480aa67 Mon Sep 17 00:00:00 2001 From: sirius Date: Thu, 30 Jan 2020 13:39:02 +0800 Subject: [PATCH 15/16] lineedit show only when in text mode and mouse click --- PaintPlugin/src/DkPaintPlugin.cpp | 38 ++++++++++++------------------- PaintPlugin/src/DkPaintPlugin.h | 5 +++- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/PaintPlugin/src/DkPaintPlugin.cpp b/PaintPlugin/src/DkPaintPlugin.cpp index 9f6e060..50c269f 100644 --- a/PaintPlugin/src/DkPaintPlugin.cpp +++ b/PaintPlugin/src/DkPaintPlugin.cpp @@ -69,6 +69,7 @@ bool DkPaintPlugin::hideHUD() const { **/ const int ArrowWidth = 10; const int ArrowHeight = 18; +const int TextEnlarge = 15; QPainterPath getArrowHead(QPainterPath line, const int thickness) { QPointF p1 = line.pointAtPercent(0.0); QPointF p2 = line.pointAtPercent(1.0); @@ -254,6 +255,7 @@ void DkPaintViewPort::init() { connect(paintToolbar, SIGNAL(applySignal()), this, SLOT(applyChangesAndClose()), Qt::UniqueConnection); connect(paintToolbar, SIGNAL(textChangeSignal(const QString&)), this, SLOT(textChange(const QString&)), Qt::UniqueConnection); connect(paintToolbar, SIGNAL(editFinishSignal()), this, SLOT(textEditFinsh()), Qt::UniqueConnection); + connect(this, SIGNAL(editShowSignal(bool)), paintToolbar, SLOT(showLineEdit(bool)), Qt::UniqueConnection); loadSettings(); paintToolbar->setPenColor(pen.color()); @@ -300,17 +302,8 @@ void DkPaintViewPort::mousePressEvent(QMouseEvent *event) { if(selectedMode == mode_text) { textinputenable = true; - //QLineEdit *textInput = new QLineEdit(this); - //connect (textInput, SIGNAL(textChanged(const QString &text)), this, SLOT(textChange(const QString &text))); - /* - QFont font; - font.setFamily(font.defaultFamily()); - font.setPixelSize(pen.width()*15); - QString text; - text = QInputDialog::getText(this, "Text Input", tr("string"), QLineEdit::Normal); - paths.last().addText(begin, font, text); - text.clear(); - */ + // lineedit show only when in text mode and mouse click + emit editShowSignal(true); } update(); } @@ -437,7 +430,7 @@ void DkPaintViewPort::paintEvent(QPaintEvent *event) { QPointF p = paths.at(idx).boundingRect().bottomRight(); if((idx == paths.size()-1) && (textinputenable)) { - painter.setPen(QPen(QBrush(QColor(0,0,0,180)),3,Qt::DotLine)); + painter.setPen(QPen(QBrush(QColor(0,0,0,180)),pathsPen.at(idx).width(),Qt::DotLine)); if(sbuffer.isEmpty()) painter.drawLine(QLineF(begin, begin-QPoint(0, pathsPen.at(idx).width()*10))); else @@ -509,6 +502,7 @@ QImage DkPaintViewPort::getPaintedImage() { void DkPaintViewPort::setMode(int mode){ selectedMode = mode; setCursor(defaultCursor); + emit editShowSignal(false); this->repaint(); } @@ -516,7 +510,7 @@ void DkPaintViewPort::setMode(int mode){ void DkPaintViewPort::textChange(const QString &text){ QFont font; font.setFamily(font.defaultFamily()); - font.setPixelSize(pen.width()*15); + font.setPixelSize(pen.width()*TextEnlarge); if(textinputenable) { sbuffer = text; @@ -530,6 +524,7 @@ void DkPaintViewPort::textEditFinsh(){ if(sbuffer.isEmpty()) undoLastPaint(); textinputenable = false; + emit editShowSignal(false); } void DkPaintViewPort::clear() { @@ -764,12 +759,15 @@ void DkPaintToolBar::createLayout() { //addWidget(textInput); toolbarWidgetList.insert(textInput->objectName(), this->addWidget(textInput)); - modifyLayout(mode_pencil); + showLineEdit(false); } -void DkPaintToolBar::modifyLayout(int mode) { - if(mode == mode_text) +void DkPaintToolBar::showLineEdit(bool show) { + if(show) + { toolbarWidgetList.value(textInput->objectName())->setVisible(true); + textInput->setFocus(); + } else toolbarWidgetList.value(textInput->objectName())->setVisible(false); } @@ -821,42 +819,34 @@ void DkPaintToolBar::on_panAction_toggled(bool checked) { } void DkPaintToolBar::on_pencilAction_toggled(bool checked){ - modifyLayout(mode_pencil); emit modeChangeSignal(mode_pencil); } void DkPaintToolBar::on_lineAction_toggled(bool checked){ - modifyLayout(mode_line); emit modeChangeSignal(mode_line); } void DkPaintToolBar::on_arrowAction_toggled(bool checked){ - modifyLayout(mode_arrow); emit modeChangeSignal(mode_arrow); } void DkPaintToolBar::on_circleAction_toggled(bool checked){ - modifyLayout(mode_circle); emit modeChangeSignal(mode_circle); } void DkPaintToolBar::on_squareAction_toggled(bool checked){ - modifyLayout(mode_square); emit modeChangeSignal(mode_square); } void DkPaintToolBar::on_squarefillAction_toggled(bool checked){ - modifyLayout(mode_square_fill); emit modeChangeSignal(mode_square_fill); } void DkPaintToolBar::on_blurAction_toggled(bool checked){ - modifyLayout(mode_blur); emit modeChangeSignal(mode_blur); } void DkPaintToolBar::on_textAction_toggled(bool checked){ - modifyLayout(mode_text); emit modeChangeSignal(mode_text); } diff --git a/PaintPlugin/src/DkPaintPlugin.h b/PaintPlugin/src/DkPaintPlugin.h index c1d885a..e8784fe 100644 --- a/PaintPlugin/src/DkPaintPlugin.h +++ b/PaintPlugin/src/DkPaintPlugin.h @@ -121,6 +121,9 @@ public slots: virtual void setVisible(bool visible); void undoLastPaint(); +signals: + void editShowSignal(bool show); + protected slots: void setMode(int mode); void textChange(const QString &text); @@ -207,6 +210,7 @@ public slots: void on_textInput_textChanged(const QString &text); void on_textInput_editingFinished(); void on_undoAction_triggered(); + void showLineEdit(bool show); virtual void setVisible(bool visible); signals: @@ -225,7 +229,6 @@ public slots: protected: void createLayout(); void createIcons(); - void modifyLayout(int mode); QPushButton* penColButton; QColorDialog* colorDialog; From b79c9876ea6468eb6ab8f4b861ace5d1a51a400a Mon Sep 17 00:00:00 2001 From: sirius Date: Thu, 30 Jan 2020 14:02:50 +0800 Subject: [PATCH 16/16] roll back the empty painterpath generated by click mouse --- PaintPlugin/src/DkPaintPlugin.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/PaintPlugin/src/DkPaintPlugin.cpp b/PaintPlugin/src/DkPaintPlugin.cpp index 50c269f..a7ca787 100644 --- a/PaintPlugin/src/DkPaintPlugin.cpp +++ b/PaintPlugin/src/DkPaintPlugin.cpp @@ -293,6 +293,13 @@ void DkPaintViewPort::mousePressEvent(QMouseEvent *event) { if(QRectF(QPointF(), viewport->getImage().size()).contains(mapToImage(event->pos()))) { isOutside = false; + + // roll back the empty painterpath generated by click mouse + if(!paths.empty()) + if(paths.last().isEmpty()) + undoLastPaint(); + + // create new painterpath paths.append(QPainterPath()); paths.last().moveTo(mapToImage(event->pos())); //paths.last().lineTo(mapToImage(event->pos())+QPointF(0.1,0));