Example #1
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();
}
Example #2
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);
    }
}
Example #3
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();
}
Example #4
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();
    }
}
Example #5
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);
        }
    }
}
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();
}
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();
    }
}
Example #8
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();
    }
}
Example #9
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();
    }
}
Example #10
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();
}
Example #11
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();
}
Example #12
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;
    }
}