Пример #1
0
void Canvas::drawPoint(const QPoint &point)
{
    LayerPointer l = layers.selectedLayer();
    if(l.isNull() || l->isLocked() || l->isHided()){
        setCursor(Qt::ForbiddenCursor);
        return;
    }
    //    setCursor(Qt::CrossCursor);
    updateCursor(brush_->width());
    brush_->setSurface(l->imagePtr());
    brush_->start(point);

    int rad = (brush_->width() / 2) + 2;
    update(QRect(lastPoint, point).normalized()
           .adjusted(-rad, -rad, +rad, +rad));

    QVariantMap point_j;
    point_j.insert("x", point.x());
    point_j.insert("y", point.y());

    QVariantMap map;
    map.insert("brush", QVariant(brushInfo()));
    map.insert("layer", QVariant(currentLayer()));
    map.insert("point", QVariant(point_j));
    map.insert("userid", QVariant(userId()));

    QVariantMap bigMap;
    bigMap.insert("info", map);
    bigMap.insert("action", "drawpoint");

    QByteArray tmp = toJson(QVariant(bigMap));
    emit sendData(tmp);
}
Пример #2
0
void Canvas::drawLineTo(const QPoint &endPoint)
{
    LayerPointer l = layers.selectedLayer();
    if(l.isNull() || l->isLocked() || l->isHided()){
        setCursor(Qt::ForbiddenCursor);
        return;
    }
    //    setCursor(Qt::CrossCursor);
    updateCursor(brush_->width());
    brush_->setSurface(l->imagePtr());
    brush_->lineTo(endPoint);

    update();

    QVariantMap start_j;
    start_j.insert("x", this->lastPoint.x());
    start_j.insert("y", this->lastPoint.y());
    QVariantMap end_j;
    end_j.insert("x", endPoint.x());
    end_j.insert("y", endPoint.y());

    QVariantMap map;
    map.insert("brush", QVariant(brushInfo()));
    map.insert("start", QVariant(start_j));
    map.insert("end", QVariant(end_j));
    map.insert("layer", QVariant(currentLayer()));
    map.insert("userid", QVariant(userId()));

    QVariantMap bigMap;
    bigMap.insert("info", map);
    bigMap.insert("action", "drawline");

    QByteArray tmp = toJson(QVariant(bigMap));
    emit sendData(tmp);
}
Пример #3
0
void Canvas::remoteDrawLine(const QPoint &start, const QPoint &end,
                            const QVariantMap &brushInfo,
                            const QString &layer,
                            const quint64 userid)
{
    if(!layers.exists(layer)){
        return;
    }
    LayerPointer l = layers.layerFrom(layer);

    QString brushName = brushInfo["name"].toString();
    int width = brushInfo["width"].toInt();
    QVariantMap colorMap = brushInfo["color"].toMap();
    QColor color(colorMap["red"].toInt(),
            colorMap["green"].toInt(),
            colorMap["blue"].toInt(),
            colorMap["alpha"].toInt());

    if(remoteBrush.contains(userid)){
        BrushPointer t = remoteBrush[userid];
        if(brushName != t->brushInfo()["name"].toString()){
            BrushPointer newOne = brushFactory(brushName);
            newOne->setSurface(l->imagePtr());
            newOne->setWidth(width);
            newOne->setColor(color);
            newOne->lineTo(end);
            remoteBrush[userid] = newOne;
            t.clear();
        }else{
            BrushPointer original = remoteBrush[userid];
            original->setSurface(l->imagePtr());
            original->setWidth(width);
            original->setColor(color);
            original->lineTo(end);
        }
    }else{
        BrushPointer newOne = brushFactory(brushName);
        newOne->setSurface(l->imagePtr());
        newOne->setWidth(width);
        newOne->setColor(color);
        newOne->lineTo(end);
        remoteBrush[userid] = newOne;
    }

    update();
}
Пример #4
0
void Canvas::remoteDrawPoint(const QPoint &point, const QVariantMap &brushInfo,
                             const QString &layer,
                             const quint64 userid)
{
    if(!layers.exists(layer)) return;
    LayerPointer l = layers.layerFrom(layer);

    QString brushName = brushInfo["name"].toString();
    int width = brushInfo["width"].toInt();
    QColor color = brushInfo["color"].value<QColor>();

    if(remoteBrush.contains(userid)){
        BrushPointer t = remoteBrush[userid];
        if(brushInfo != t->brushInfo()){
            BrushPointer newOne = brushFactory(brushName);
            newOne->setDirectDraw(true);
            newOne->setSurface(l->imagePtr());
            newOne->setWidth(width);
            newOne->setColor(color);
            newOne->start(point);
            remoteBrush[userid] = newOne;
            t.clear();
        }else{
            BrushPointer original = remoteBrush[userid];
            original->setSurface(l->imagePtr());
            original->setWidth(width);
            original->setColor(color);
            original->start(point);
        }
    }else{
        BrushPointer newOne = brushFactory(brushName);
        newOne->setDirectDraw(true);
        newOne->setSurface(l->imagePtr());
        newOne->setWidth(width);
        newOne->setColor(color);
        newOne->start(point);
        remoteBrush[userid] = newOne;
    }

    update();
}
Пример #5
0
QPixmap Canvas::allCanvas()
{
    QPixmap exp(canvasSize);
    exp.fill();
    QPainter painter(&exp);
    int count = layers.count();
    QPixmap * im = 0;
    for(int i=0;i<count;++i){
        LayerPointer l = layers.layerFrom(i);
        im = l->imagePtr();
        painter.drawPixmap(0, 0, *im);
    }
    return exp;
}
Пример #6
0
void Canvas::combineLayers(const QRect &rec)
{
    QPainter painter(&image);
    image.fill(Qt::white);
    int count = layers.count();
    QPixmap * im = 0;
    for(int i=0;i<count;++i){
        LayerPointer l = layers.layerFrom(i);
        if(l->isHided()){
            continue;
        }
        im = l->imagePtr();
        painter.drawPixmap(QRectF(rec), *im, QRectF(rec));
    }
}
Пример #7
0
QPixmap Canvas::combineLayers()
{
    QPainter painter(&image);
    image.fill(Qt::white);
    int count = layers.count();
    QPixmap * im = 0;
    for(int i=0;i<count;++i){
        LayerPointer l = layers.layerFrom(i);
        if(l->isHided()){
            continue;
        }
        im = l->imagePtr();
        painter.drawPixmap(0, 0, *im);
    }
    return image;
}