void AbstractSelection::mouseReleaseEvent(QMouseEvent *event, ImageArea &imageArea) { int right = mTopLeftPoint.x() > mBottomRightPoint.x() ? mTopLeftPoint.x() : mBottomRightPoint.x(); int bottom = mTopLeftPoint.y() > mBottomRightPoint.y() ? mTopLeftPoint.y() : mBottomRightPoint.y(); int left = mTopLeftPoint.x() < mBottomRightPoint.x() ? mTopLeftPoint.x() : mBottomRightPoint.x(); int top = mTopLeftPoint.y() < mBottomRightPoint.y() ? mTopLeftPoint.y() : mBottomRightPoint.y(); mBottomRightPoint = QPoint(right, bottom); mTopLeftPoint = QPoint(left, top); if (mIsSelectionExists) { updateCursor(event, imageArea); if (mButton == Qt::RightButton && !mIsMouseMoved) { showMenu(imageArea); paint(imageArea); drawBorder(imageArea); mIsPaint = false; mIsSelectionMoving = mIsImageSelected = false; } else if (mIsSelectionMoving) { imageArea.setImage(mImageCopy); completeMoving(imageArea); paint(imageArea); drawBorder(imageArea); mIsPaint = false; mIsSelectionMoving = false; } else if (mIsSelectionResizing) { imageArea.setImage(mImageCopy); paint(imageArea); completeResizing(imageArea); paint(imageArea); drawBorder(imageArea); mIsPaint = false; mIsSelectionResizing = false; } } if (mIsPaint) { if (event->button() == Qt::LeftButton) { imageArea.setImage(mImageCopy); if (mTopLeftPoint != mBottomRightPoint) { imageArea.setImage(mImageCopy); paint(imageArea); completeSelection(imageArea); paint(imageArea); mIsSelectionExists = true; } drawBorder(imageArea); mIsPaint = false; } } mIsSelectionAdjusting = false; }
void CurveLineInstrument::mouseMoveEvent(QMouseEvent *event, ImageArea &imageArea) { if(imageArea.isPaint()) { switch(mPointsCount) { //draw linear Bezier curve case 1: mEndPoint = event->pos(); break; //draw square Bezier curve case 2: mFirstControlPoint = mSecondControlPoint = event->pos(); break; //draw cubic Bezier curve case 0: mSecondControlPoint = event->pos(); break; } imageArea.setImage(mImageCopy); if(event->buttons() & Qt::LeftButton) paint(imageArea, false); else if(event->buttons() & Qt::RightButton) paint(imageArea, true); } }
void CurveLineInstrument::mouseReleaseEvent(QMouseEvent *event, ImageArea &imageArea) { if(imageArea.isPaint()) { imageArea.setImage(mImageCopy); if(event->button() == Qt::LeftButton) paint(imageArea, false); else if(event->button() == Qt::RightButton) paint(imageArea, true); imageArea.setIsPaint(false); } }
void AbstractSelection::mouseMoveEvent(QMouseEvent *event, ImageArea &imageArea) { mIsMouseMoved = true; if (mIsSelectionExists) { if (mIsSelectionMoving) { mBottomRightPoint = event->pos() + mMoveDiffPoint; mTopLeftPoint = event->pos() + mMoveDiffPoint - QPoint(mWidth - 1, mHeight - 1); imageArea.setImage(mImageCopy); move(imageArea); drawBorder(imageArea); mIsPaint = false; } else if (mIsSelectionResizing) { mBottomRightPoint = event->pos(); mHeight = fabs(mTopLeftPoint.y() - mBottomRightPoint.y()) + 1; mWidth = fabs(mTopLeftPoint.x() - mBottomRightPoint.x()) + 1; imageArea.setImage(mImageCopy); resize(imageArea); drawBorder(imageArea); mIsPaint = false; } } if (mIsPaint) { mBottomRightPoint = event->pos(); mHeight = fabs(mTopLeftPoint.y() - mBottomRightPoint.y()) + 1; mWidth = fabs(mTopLeftPoint.x() - mBottomRightPoint.x()) + 1; imageArea.setImage(mImageCopy); drawBorder(imageArea); select(imageArea); } updateCursor(event, imageArea); }
void AbstractSelection::clearSelection(ImageArea &imageArea) { if (mIsSelectionExists) { imageArea.setImage(mImageCopy); paint(imageArea); mImageCopy = *imageArea.getImage(); mIsSelectionExists = mIsSelectionMoving = mIsSelectionResizing = mIsPaint = mIsImageSelected = false; imageArea.update(); imageArea.restoreCursor(); clear(); } }
void LineInstrument::mouseMoveEvent(QMouseEvent *event, ImageArea &imageArea) { if(imageArea.isPaint()) { mEndPoint = event->pos(); imageArea.setImage(mImageCopy); if(event->buttons() & Qt::LeftButton) { paint(imageArea, false); } else if(event->buttons() & Qt::RightButton) { paint(imageArea, true); } } }
void AbstractSelection::mousePressEvent(QMouseEvent *event, ImageArea &imageArea) { mButton = event->button(); mIsMouseMoved = false; if (mIsSelectionExists) { imageArea.setImage(mImageCopy); paint(imageArea); if (mButton == Qt::RightButton) { mIsSelectionAdjusting = true; startAdjusting(imageArea); } if (event->pos().x() > mTopLeftPoint.x() && event->pos().x() < mBottomRightPoint.x() && event->pos().y() > mTopLeftPoint.y() && event->pos().y() < mBottomRightPoint.y()) { if (!mIsSelectionAdjusting) { makeUndoCommand(imageArea); } if (!mIsImageSelected) { startMoving(imageArea); if (!mIsSelectionAdjusting) { mIsImageSelected = true; } } else { drawBorder(imageArea); } mIsSelectionMoving = true; mMoveDiffPoint = mBottomRightPoint - event->pos(); return; } else if (event->pos().x() >= mBottomRightPoint.x() && event->pos().x() <= mBottomRightPoint.x() + 6 && event->pos().y() >= mBottomRightPoint.y() && event->pos().y() <= mBottomRightPoint.y() + 6) { if (!mIsSelectionAdjusting) { makeUndoCommand(imageArea); } startResizing(imageArea); mIsSelectionResizing = true; return; } else { clearSelection(imageArea); } } if (event->button() == Qt::LeftButton) { mBottomRightPoint = mTopLeftPoint = event->pos(); mHeight = mWidth = 0; mImageCopy = *imageArea.getImage(); startSelection(imageArea); mIsPaint = true; } }