Ejemplo n.º 1
0
QColor Core::pickColor(const QPointF& point, const QVariantList& canvasItems) {
    QPixmap pixmap;
    for (int i = canvasItems.count() - 1; i >= 0; i--) {
        QObject* obj = qvariant_cast<QObject*>(canvasItems.at(i));
        CanvasItem* canvasItem = qobject_cast<CanvasItem*>(obj);
        QPixmap* canvasPixmap = canvasItem->pixmap();
        if (pixmap.isNull()) {
            pixmap = QPixmap(canvasPixmap->width(), canvasPixmap->height());
            pixmap.fill(Qt::white);
        }
        QPainter painter(&pixmap);
        painter.drawPixmap(0, 0, *canvasPixmap);
    }

    return QColor(pixmap.toImage().pixel(qRound(point.x()), qRound(point.y())));
}
Ejemplo n.º 2
0
void Core::writePng(const QString& pngPath, const QVariantList& canvasItems) {
    QPixmap pixmap;
    for (int i = canvasItems.count() - 1; i >= 0; i--)
    {
        QObject* obj = qvariant_cast<QObject*>(canvasItems.at(i));
        CanvasItem* canvasItem = qobject_cast<CanvasItem*>(obj);
        QPixmap* canvasPixmap = canvasItem->pixmap();
        if (pixmap.isNull()) {
            pixmap = QPixmap(canvasPixmap->width(), canvasPixmap->height());
            pixmap.fill(Qt::white);
        }
        QPainter painter(&pixmap);
        painter.drawPixmap(0, 0, *canvasPixmap);
    }
    pixmap.save(pngPath);
}
Ejemplo n.º 3
0
void Core::writeOra(const QString& oraPath, const QSize& canvasSize, const QVariantList layerList) {
    QZipWriter zipWriter(oraPath);
    zipWriter.setCompressionPolicy(QZipWriter::AutoCompress);

    QByteArray xmlByteArray;

    // mimetype file
    xmlByteArray.append("image/openraster");
    zipWriter.addFile("mimetype", xmlByteArray);

    // stack.xml file
    QXmlStreamWriter stream(&xmlByteArray);
    stream.setAutoFormatting(true);

    stream.writeStartDocument();

    stream.writeStartElement("image");
    stream.writeAttribute("w", QString::number(canvasSize.width()));
    stream.writeAttribute("h",QString::number(canvasSize.height()));
    stream.writeStartElement("stack");

    QByteArray ba;
    QBuffer buffer(&ba);

    for (int i = 0; i < layerList.count(); i++) {
        QMap<QString, QVariant> map = layerList.at(i).toMap();
        QString name = map.value("name").toString();
        QString isVisible = map.value("isVisible").toString();
        QString isLock = map.value("isLock").toString();
        QString isSelected = map.value("isSelected").toString();

        buffer.open(QIODevice::WriteOnly);
        QObject* obj = qvariant_cast<QObject*>(map.value("canvasItem"));
        CanvasItem* canvasItem = qobject_cast<CanvasItem*>(obj);
        QPixmap* pixmap = canvasItem->pixmap();
        pixmap->save(&buffer, "PNG");
        buffer.close();

        QString src = "data/" + name + ".png";
        zipWriter.addFile(src, ba);

        // layer
        stream.writeStartElement("layer");
        stream.writeAttribute("name", name);
        stream.writeAttribute("composite-op", "svg:src-over");
        stream.writeAttribute("visibility", isVisible == "true" ? "visible" : "hidden");
        stream.writeAttribute("edit-locked", isLock);
        stream.writeAttribute("selected", isSelected);
        stream.writeAttribute("src", src);
        stream.writeAttribute("x", "0");
        stream.writeAttribute("y", "0");
        stream.writeAttribute("opacity", "1.0");
        stream.writeEndElement(); // layer
    }

    stream.writeEndElement(); // stack
    stream.writeEndElement(); // image
    stream.writeEndDocument(); // document
    zipWriter.addFile("stack.xml", xmlByteArray);

    zipWriter.close();
}