void CurveLineInstrument::mouseMoveEvent(QMouseEvent *event, ImageArea &imageArea) { if(imageArea.isPaint()) { switch(mPointsCount) { //draw linear Bezier curve case 1: mEndPoint = QPoint(event->pos().x()/imageArea.getZoomFactor(), event->pos().y()/imageArea.getZoomFactor()); break; //draw square Bezier curve case 2: mFirstControlPoint = mSecondControlPoint = QPoint(event->pos().x()/imageArea.getZoomFactor(), event->pos().y()/imageArea.getZoomFactor()); break; //draw cubic Bezier curve case 0: mSecondControlPoint = QPoint(event->pos().x()/imageArea.getZoomFactor(), event->pos().y()/imageArea.getZoomFactor()); break; } imageArea.setImage(mImageCopy); if(event->buttons() & Qt::LeftButton) paint(imageArea, false); else if(event->buttons() & Qt::RightButton) paint(imageArea, true); } }
void CurveLineInstrument::mousePressEvent(QMouseEvent *event, ImageArea &imageArea) { if(event->button() == Qt::LeftButton || event->button() == Qt::RightButton) { if(DataSingleton::Instance()->isResetCurve()) { mPointsCount = 0; DataSingleton::Instance()->setResetCurve(false); } switch(mPointsCount) { //draw linear Bezier curve case 0: mImageCopy = *imageArea.getImage(); mStartPoint = mEndPoint = mFirstControlPoint = mSecondControlPoint = QPoint(event->pos().x()/imageArea.getZoomFactor(), event->pos().y()/imageArea.getZoomFactor()); ++mPointsCount; break; //draw square Bezier curve case 1: mFirstControlPoint = mSecondControlPoint = QPoint(event->pos().x()/imageArea.getZoomFactor(), event->pos().y()/imageArea.getZoomFactor()); ++mPointsCount; break; //draw cubic Bezier curve case 2: mSecondControlPoint = QPoint(event->pos().x()/imageArea.getZoomFactor(), event->pos().y()/imageArea.getZoomFactor()); mPointsCount = 0; break; } imageArea.setIsPaint(true); makeUndoCommand(imageArea); } }
void EraserInstrument::paint(ImageArea &imageArea, bool, bool) { QPainter painter(imageArea.getImage()); painter.setPen(QPen(Qt::white, DataSingleton::Instance()->getPenSize() * imageArea.getZoomFactor(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); if(mStartPoint != mEndPoint) { painter.drawLine(mStartPoint, mEndPoint); } if(mStartPoint == mEndPoint) { painter.drawPoint(mStartPoint); } imageArea.setEdited(true); // int rad(DataSingleton::Instance()->getPenSize() + round(sqrt((mStartPoint.x() - mEndPoint.x()) * // (mStartPoint.x() - mEndPoint.x()) + // (mStartPoint.y() - mEndPoint.y()) * // (mStartPoint.y() - mEndPoint.y())))); // mPImageArea->update(QRect(mStartPoint, mEndPoint).normalized().adjusted(-rad, -rad, +rad, +rad)); painter.end(); imageArea.update(); }
void CurveLineInstrument::paint(ImageArea &imageArea, bool isSecondaryColor, bool) { QPainter painter(imageArea.getImage()); //make Bezier curve path QPainterPath path; path.moveTo(mStartPoint); path.cubicTo(mFirstControlPoint, mSecondControlPoint, mEndPoint); //choose color painter.setPen(QPen(isSecondaryColor ? DataSingleton::Instance()->getSecondaryColor() : DataSingleton::Instance()->getPrimaryColor(), DataSingleton::Instance()->getPenSize() * imageArea.getZoomFactor(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); //draw Bezier curve with given path painter.strokePath(path, painter.pen()); imageArea.setEdited(true); painter.end(); imageArea.update(); }
void RectangleInstrument::paint(ImageArea &imageArea, bool isSecondaryColor, bool) { QPainter painter(imageArea.getImage()); painter.setPen(QPen(DataSingleton::Instance()->getPrimaryColor(), DataSingleton::Instance()->getPenSize() * imageArea.getZoomFactor(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); if(isSecondaryColor) { painter.setBrush(QBrush(DataSingleton::Instance()->getSecondaryColor())); } if(mStartPoint != mEndPoint) { painter.drawRect(QRect(mStartPoint, mEndPoint)); } imageArea.setEdited(true); // int rad(DataSingleton::Instance()->getPenSize() + round(sqrt((mStartPoint.x() - mEndPoint.x()) * // (mStartPoint.x() - mEndPoint.x()) + // (mStartPoint.y() - mEndPoint.y()) * // (mStartPoint.y() - mEndPoint.y())))); // mPImageArea->update(QRect(mStartPoint, mEndPoint).normalized().adjusted(-rad, -rad, +rad, +rad)); painter.end(); imageArea.update(); }