Exemplo n.º 1
0
void SelectionTool::mouseMoveEvent(MouseState mouse, QImage *layer, QImage *hud, QImage *selection, bool *useSelection)
{
    if(m_moving){
        hud->fill(Qt::transparent);

        QPainter painter(hud);
        painter.setOpacity(.6);
        painter.drawImage(mouse.delta(), m_movingSelection);
    }
    else if(m_drawing){
        hud->fill(Qt::transparent);

        QPixmap temp(hud->size());
        temp.fill(Qt::transparent);

        QPainter painter(&temp);
        painter.setPen(Qt::NoPen);
        painter.setBrush(QBrush(GREEN_SELECTION));

        this->paintSelection(mouse, &painter);

        painter.end();
        painter.begin(hud);
        painter.setOpacity(.6);
        painter.drawPixmap(0, 0, temp);
    }
    else{
        if(*useSelection && m_selectionMode == "only" && QColor(selection->pixel(mouse.getPos())) == Qt::white)
            this->setCursor(Selection);
        else
            this->setCorrectCursor();
    }
}
Exemplo n.º 2
0
void SelectionTool::mouseReleaseEvent(MouseState mouse, QImage *layer, QImage *hud, QImage *selection, bool *useSelection)
{
    if(m_moving){
        m_moving = false;

        selection->fill(Qt::transparent);
        hud->fill(Qt::transparent);

        QPainter painter(selection);
        painter.drawImage(mouse.delta(), m_movingSelection);
        painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
        painter.setPen(Qt::NoPen);
        painter.setBrush(QBrush(Qt::white));
        painter.drawRect(0, 0, layer->width(), layer->height());
    }
    else if(m_drawing){
        m_drawing = false;

        if(m_selectionMode == "only" || *useSelection == false)
            selection->fill(Qt::transparent);

        *useSelection = true;
        hud->fill(Qt::transparent);

        QPixmap temp(layer->size());
        temp.fill(Qt::transparent);

        QPainter painter(&temp);
        painter.setPen(Qt::NoPen);
        painter.setBrush(QBrush(Qt::white));

        this->paintSelection(mouse, &painter);

        painter.end();
        painter.begin(selection);

        if(m_selectionMode == "not")
            painter.setCompositionMode(QPainter::CompositionMode_DestinationOut);

        if(m_selectionMode == "and")
            painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);

        painter.drawPixmap(0, 0, temp);

        if(m_noKeyReleased && m_unmodifiedMode != 0){
            if(m_selectionMode == "or" || m_selectionMode == "and")
                m_keysDown.insert(Qt::Key_Shift);
            if(m_selectionMode == "not" || m_selectionMode == "and")
                m_keysDown.insert(Qt::Key_Alt);
        }

        this->updateMode();
    }

    emit selectionChanged(true);
}