Esempio n. 1
0
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();
}
Esempio n. 2
0
void LineInstrument::paint(ImageArea &imageArea, bool isSecondaryColor, bool)
{
    QPainter painter(imageArea.getImage());
    if(isSecondaryColor)
    {
        painter.setPen(QPen(Data::Instance()->getSecondaryColor(),
                            Data::Instance()->getPenSize(),
                            Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
    }
    else
    {
        painter.setPen(QPen(Data::Instance()->getPrimaryColor(),
                            Data::Instance()->getPenSize(),
                            Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
    }

    if(mStartPoint != mEndPoint)
    {
        painter.drawLine(mStartPoint, mEndPoint);
    }

    if(mStartPoint == mEndPoint)
    {
        painter.drawPoint(mStartPoint);
    }
    imageArea.setEdited(true);
    painter.end();
    imageArea.update();
}
Esempio n. 3
0
void AbstractSelection::updateCursor(QMouseEvent *event, ImageArea &imageArea)
{
    if (mIsSelectionExists)
    {
        if (event->pos().x() > mTopLeftPoint.x() &&
            event->pos().x() < mBottomRightPoint.x() &&
            event->pos().y() > mTopLeftPoint.y() &&
            event->pos().y() < mBottomRightPoint.y())
        { 
            imageArea.setCursor(Qt::SizeAllCursor);
        }
        else if (event->pos().x() >= mBottomRightPoint.x() &&
                 event->pos().x() <= mBottomRightPoint.x() + 6 &&
                 event->pos().y() >= mBottomRightPoint.y() &&
                 event->pos().y() <= mBottomRightPoint.y() + 6)
        {
            imageArea.setCursor(Qt::SizeFDiagCursor);
        }
        else
        {
            imageArea.restoreCursor();
        }
    }
    else
    {
        imageArea.restoreCursor();
    }
}
Esempio n. 4
0
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 = event->pos();
            ++mPointsCount;
            break;
        //draw square Bezier curve
        case 1:
            mFirstControlPoint = mSecondControlPoint = event->pos();
            ++mPointsCount;
            break;
        //draw cubic Bezier curve
        case 2:
            mSecondControlPoint = event->pos();
            mPointsCount = 0;
            break;
        }
        imageArea.setIsPaint(true);
        makeUndoCommand(imageArea);
    }
}
Esempio n. 5
0
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);
    }
}
Esempio n. 6
0
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;
}
Esempio n. 7
0
void LineInstrument::mousePressEvent(QMouseEvent *event, ImageArea &imageArea)
{
    if(event->button() == Qt::LeftButton || event->button() == Qt::RightButton)
    {
        mStartPoint = mEndPoint = event->pos();
        imageArea.setIsPaint(true);
        mImageCopy = *imageArea.getImage();
    }
}
Esempio n. 8
0
void EraserInstrument::mouseReleaseEvent(QMouseEvent *event, ImageArea &imageArea)
{
    if(imageArea.isPaint())
    {
        mEndPoint = event->pos();
        paint(imageArea);
        imageArea.setIsPaint(false);
    }
}
Esempio n. 9
0
void BinarizationEffect::applyEffect(ImageArea &imageArea)
{
    makeUndoCommand(imageArea);

    // TODO: add dialog for setting parameters
    makeBinarization(imageArea, 200, 100);

    imageArea.setEdited(true);
    imageArea.update();
}
Esempio n. 10
0
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);
    }
}
Esempio n. 11
0
void TextInstrument::paint(ImageArea &imageArea, bool, bool)
{
    if(mTopLeftPoint != mBottomRightPoint)
    {
        QPainter painter(imageArea.getImage());
        painter.setPen(QPen(DataSingleton::Instance()->getPrimaryColor()));
        painter.setFont(DataSingleton::Instance()->getTextFont());
        painter.drawText(QRect(mTopLeftPoint, mBottomRightPoint), mText);
        painter.end();
        imageArea.setEdited(true);
        imageArea.update();
    }
}
Esempio n. 12
0
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();
    }
}
Esempio n. 13
0
void FillInstrument::mouseReleaseEvent(QMouseEvent *event, ImageArea &imageArea)
{
    if(imageArea.isPaint())
    {
        if(event->button() == Qt::LeftButton)
        {
            paint(imageArea, false);
        }
        else if(event->button() == Qt::RightButton)
        {
            paint(imageArea, true);
        }
        imageArea.setIsPaint(false);
    }
}
Esempio n. 14
0
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);
        }
    }
}
Esempio n. 15
0
void AbstractSelection::drawBorder(ImageArea &imageArea)
{
    if (mWidth > 1 && mHeight > 1)
    {
        QPainter painter(imageArea.getImage());
        painter.setPen(QPen(Qt::blue, 1, Qt::DashLine, Qt::RoundCap, Qt::RoundJoin));
        painter.setBackgroundMode(Qt::TransparentMode);
        if(mTopLeftPoint != mBottomRightPoint)
        {
            painter.drawRect(QRect(mTopLeftPoint, mBottomRightPoint - QPoint(1, 1)));
        }
        imageArea.setEdited(true);
        painter.end();
        imageArea.update();
    }
}
Esempio n. 16
0
void FillInstrument::mousePressEvent(QMouseEvent *event, ImageArea &imageArea)
{
    if(event->button() == Qt::LeftButton || event->button() == Qt::RightButton)
    {
        mStartPoint = mEndPoint = event->pos();
        imageArea.setIsPaint(true);
        makeUndoCommand(imageArea);
    }
}
Esempio n. 17
0
void EraserInstrument::mouseMoveEvent(QMouseEvent *event, ImageArea &imageArea)
{
    if(imageArea.isPaint())
    {
        mEndPoint = event->pos();
        paint(imageArea, false);
        mStartPoint = event->pos();
    }
}
Esempio n. 18
0
void BinarizationEffect::makeBinarization(ImageArea &imageArea, int coeff1, int coeff2)
{
    for (int x(0); x < imageArea.getImage()->width(); x++)
    {
        for (int y(0); y < imageArea.getImage()->height(); y++)
        {
            QRgb pixel = imageArea.getImage()->pixel(x, y);
            int r = (int)qRed(pixel);
            if (r >= coeff1)
                r = 0;
            else if (r >= coeff2 && r < coeff1)
                    r = 255;
            else
                r = 0;
            pixel = qRgb(r, r, r);
            imageArea.getImage()->setPixel(x, y, pixel);
        }
    }
}
Esempio n. 19
0
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();
}
Esempio n. 20
0
void FillInstrument::paint(ImageArea &imageArea, bool isSecondaryColor, bool)
{
    QColor switchColor;
    if(!isSecondaryColor)
        switchColor = DataSingleton::Instance()->getPrimaryColor();
    else
        switchColor = DataSingleton::Instance()->getSecondaryColor();

    QRgb pixel(imageArea.getImage()->pixel(mStartPoint));
    QColor oldColor(pixel);

    if(switchColor != oldColor)
    {
        fillRecurs(mStartPoint.x(), mStartPoint.y(),
                   switchColor.rgb(), oldColor.rgb(),
                   *imageArea.getImage());
    }
    imageArea.setEdited(true);
    imageArea.update();
}
Esempio n. 21
0
void MainWindow::initializeNewTab(const bool &isOpen, const QString &filePath)
{
    ImageArea *imageArea;
    QString fileName(tr("Untitled Image"));
    if(isOpen && filePath.isEmpty())
    {
        imageArea = new ImageArea(isOpen, "", this);
        fileName = imageArea->getFileName();
    }
    else if(isOpen && !filePath.isEmpty())
    {
        imageArea = new ImageArea(isOpen, filePath, this);
        fileName = imageArea->getFileName();
    }
    else
    {
        imageArea = new ImageArea(false, "", this);
    }
    if (!imageArea->getFileName().isNull())
    {
        QScrollArea *scrollArea = new QScrollArea();
        scrollArea->setAttribute(Qt::WA_DeleteOnClose);
        scrollArea->setBackgroundRole(QPalette::Dark);
        scrollArea->setWidget(imageArea);

        mTabWidget->addTab(scrollArea, fileName);
        mTabWidget->setCurrentIndex(mTabWidget->count()-1);

        mUndoStackGroup->addStack(imageArea->getUndoStack());
        connect(imageArea, SIGNAL(sendPrimaryColorView()), mToolbar, SLOT(setPrimaryColorView()));
        connect(imageArea, SIGNAL(sendSecondaryColorView()), mToolbar, SLOT(setSecondaryColorView()));
        connect(imageArea, SIGNAL(sendRestorePreviousInstrument()), this, SLOT(restorePreviousInstrument()));
        connect(imageArea, SIGNAL(sendSetInstrument(InstrumentsEnum)), this, SLOT(setInstrument(InstrumentsEnum)));
        connect(imageArea, SIGNAL(sendNewImageSize(QSize)), this, SLOT(setNewSizeToSizeLabel(QSize)));
        connect(imageArea, SIGNAL(sendCursorPos(QPoint)), this, SLOT(setNewPosToPosLabel(QPoint)));
        connect(imageArea, SIGNAL(sendColor(QColor)), this, SLOT(setCurrentPipetteColor(QColor)));
        connect(imageArea, SIGNAL(sendEnableCopyCutActions(bool)), this, SLOT(enableCopyCutActions(bool)));
        connect(imageArea, SIGNAL(sendEnableSelectionInstrument(bool)), this, SLOT(instumentsAct(bool)));

        setWindowTitle(QString("%1 - EasyPaint").arg(fileName));
    }
Esempio n. 22
0
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);
}
Esempio n. 23
0
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();
}
Esempio n. 24
0
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;
    }
}