diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp index fe71bc7..3e5eff5 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp @@ -14,6 +14,7 @@ EditorWidget::EditorWidget(QWidget *parent) : QWidget(parent) connect(treeWidget, &LayerTreeWidget::displayLayerChange, this, &EditorWidget::onLayerChange); connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireRefreshPreview, this, &EditorWidget::triggerRefreshPreview); + connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireSelfRefresh, layerInfoDisplayWidget, &InfoDisplayWidget::triggerSelfRefresh); // &EditorWidget::triggerRefreshPreview); // test QFile settingFile; @@ -28,7 +29,7 @@ EditorWidget::EditorWidget(QWidget *parent) : QWidget(parent) QJsonObject source = jsonDoc.object(); elementManager = new ElementManager(source,previewWindow->getRenderer()); layerManager = new LayerManager(source, elementManager); - previewWindow->initialize(layerManager); + previewWindow->initialize(layerManager,QSize(jsonDoc.object().value("width").toDouble(),jsonDoc.object().value("height").toDouble())); if (layerManager->getRoot() != nullptr) { treeWidget->addTopLevelItem(layerManager->getRoot()->qTreeItem); diff --git a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp index ec42d82..9381eee 100644 --- a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp +++ b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp @@ -46,7 +46,6 @@ PixelPath GroupElement::getPaintObject() const PixelPath SimpleElement::getPaintObject(std::vector styles) const { PixelPath result; Renderer::ElementStyleStrokeDemo demo(2); - qDebug() << (renderer == nullptr) << "------------"; auto [img, mov] = renderer->drawElement(painterPath, demo, 1.0, false); //qDebug() << img << " ------"; result.addImage(img, mov); diff --git a/ArchitectureColoredPainting/src/Editor/LayerManager.cpp b/ArchitectureColoredPainting/src/Editor/LayerManager.cpp index 13de1bc..3634c10 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerManager.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerManager.cpp @@ -11,9 +11,9 @@ LayerWrapper *LayerManager::getRoot() const { return root; } -void LayerManager::paint(QPainter *painter) const +void LayerManager::paint(QPainter *painter, QSize size) const { - auto p = root->getCache().getPixmap(); + auto p = root->getCache().resizedPixel(size); painter->drawPixmap(0, 0, p); } bool LayerManager::singleSelectedCheck() const diff --git a/ArchitectureColoredPainting/src/Editor/LayerManager.h b/ArchitectureColoredPainting/src/Editor/LayerManager.h index a3a9742..b484047 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerManager.h +++ b/ArchitectureColoredPainting/src/Editor/LayerManager.h @@ -30,8 +30,8 @@ class LayerManager void removeLayer(LayerWrapper *layer); LayerWrapper *getRoot() const; LayerManager() = default; - LayerManager(QJsonObject source, ElementManager *elementManager); - void paint(QPainter *painter) const; + LayerManager(QJsonObject source, ElementManager* elementManager); + void paint(QPainter *painter, QSize size) const; bool rename(QString newName) const; bool combine() const; // bool seperate() const; diff --git a/ArchitectureColoredPainting/src/Editor/PixelPath.cpp b/ArchitectureColoredPainting/src/Editor/PixelPath.cpp index b729882..bb36fcd 100644 --- a/ArchitectureColoredPainting/src/Editor/PixelPath.cpp +++ b/ArchitectureColoredPainting/src/Editor/PixelPath.cpp @@ -21,9 +21,15 @@ QRectF PixelPath::getBoundingRect() const { return boundingRect; } - +#include QPixmap PixelPath::getPixmap() const { + auto k = pixmap; + QPainter pt(&k); + qDebug() << this->boundingRect; + //pt.fillRect(this->boundingRect, Qt::red); + //pt.fillRect(QRectF(1013.35 - 1000, 768.327 - 700,58.0887,41.5352), Qt::blue); + return k; return pixmap; } @@ -67,4 +73,16 @@ PixelPath PixelPath::trans(QTransform& mat)const painter.drawPixmap(0, 0, pixmap); result.boundingRect = mat.mapRect(boundingRect); return result; +} + +QPixmap PixelPath::resizedPixel(QSize size)const +{ + QPixmap result(size); + result.fill(Qt::transparent); + QPainter painter(&result); + + painter.setRenderHint(QPainter::SmoothPixmapTransform); + painter.setRenderHint(QPainter::HighQualityAntialiasing); + painter.drawPixmap(0, 0, pixmap.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + return result; } \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/PixelPath.h b/ArchitectureColoredPainting/src/Editor/PixelPath.h index 204b74f..785887c 100644 --- a/ArchitectureColoredPainting/src/Editor/PixelPath.h +++ b/ArchitectureColoredPainting/src/Editor/PixelPath.h @@ -12,8 +12,8 @@ private: QPixmap pixmap; int w,h; public: - PixelPath(int w=1280, int h=720); - PixelPath(QPainterPath painterPath,int w = 1280, int h = 720); + PixelPath(int w=1920, int h= 1080); + PixelPath(QPainterPath painterPath,int w = 1920, int h = 1080); ~PixelPath() = default; QRectF getBoundingRect() const; QPixmap getPixmap() const; @@ -22,4 +22,5 @@ public: void addImage(const QImage& image,const QPointF& pos); void clear(); PixelPath trans(QTransform& mat)const; + QPixmap resizedPixel(QSize size)const; }; \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp b/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp index 2c7767c..53e894c 100644 --- a/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp +++ b/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp @@ -12,8 +12,9 @@ PreviewWindow::PreviewWindow(QWidget *parent) : QOpenGLWidget(parent) layerManager = nullptr; } -void PreviewWindow::initialize(LayerManager *layerManager) +void PreviewWindow::initialize(LayerManager *layerManager,QSize windowSize) { + this->logicalSize = windowSize; this->layerManager = layerManager; } @@ -46,7 +47,7 @@ void PreviewWindow::paintGL() painter->begin(this); painter->setRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::HighQualityAntialiasing); - layerManager->paint(painter); + layerManager->paint(painter,this->size()); painter->end(); } diff --git a/ArchitectureColoredPainting/src/Editor/PreviewWindow.h b/ArchitectureColoredPainting/src/Editor/PreviewWindow.h index 0dea51b..9a0a4bc 100644 --- a/ArchitectureColoredPainting/src/Editor/PreviewWindow.h +++ b/ArchitectureColoredPainting/src/Editor/PreviewWindow.h @@ -18,10 +18,11 @@ class PreviewWindow : public QOpenGLWidget, protected QOpenGLFunctions QPainter *painter; LayerManager *layerManager; Renderer::ElementRenderer* renderer; + QSize logicalSize; public: PreviewWindow(QWidget *parent = nullptr); - void initialize(LayerManager *layerManager); + void initialize(LayerManager *layerManager, QSize windowSize = QSize(1920, 1080)); void show(); void initializeGL() override; void paintGL() override; diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp index f197005..d069285 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp @@ -44,27 +44,27 @@ void InfoDisplayWidget::generateLayerForm() QLineEdit *scaleX = new QLineEdit(QString::number(this->displayLayer->property.scale.x()), this); QLineEdit *scaleY = new QLineEdit(QString::number(this->displayLayer->property.scale.y()), this); name->setDisabled(true); - rotation->setValidator(new QIntValidator(-1000, 1000, this)); + rotation->setValidator(new QIntValidator(-10000, 10000, this)); connect(rotation, &QLineEdit::textChanged, [=](QString content) { this->displayLayer->property.rotation = content.toDouble(); emit requireRefreshPreview(); }); - offsetX->setValidator(new QIntValidator(-1000, 1000, this)); + offsetX->setValidator(new QIntValidator(-10000, 10000, this)); connect(offsetX, &QLineEdit::textChanged, [=](QString content) { this->displayLayer->property.offset = {content.toDouble(), this->displayLayer->property.offset.y()}; emit requireRefreshPreview(); }); - offsetY->setValidator(new QIntValidator(-1000, 1000, this)); + offsetY->setValidator(new QIntValidator(-10000, 10000, this)); connect(offsetY, &QLineEdit::textChanged, [=](QString content) { this->displayLayer->property.offset = {this->displayLayer->property.offset.x(), content.toDouble()}; emit requireRefreshPreview(); }); - scaleX->setValidator(new QDoubleValidator(0.01, 100, 4, this)); + scaleX->setValidator(new QDoubleValidator(0.001, 1000, 4, this)); connect(scaleX, &QLineEdit::textChanged, [=](QString content) { this->displayLayer->property.scale = {content.toDouble(), this->displayLayer->property.scale.y()}; emit requireRefreshPreview(); }); - scaleY->setValidator(new QDoubleValidator(0.01, 100, 4, this)); + scaleY->setValidator(new QDoubleValidator(0.001, 1000, 4, this)); connect(scaleY, &QLineEdit::textChanged, [=](QString content) { this->displayLayer->property.scale = {this->displayLayer->property.scale.x(), content.toDouble()}; emit requireRefreshPreview(); @@ -98,16 +98,23 @@ void InfoDisplayWidget::generateLayerForm() detailButton->setFixedSize(QSize(20, 20)); deleteButton->setText("×"); deleteButton->setFixedSize(QSize(20, 20)); - connect(detailButton, &QPushButton::clicked, [styleList, item, this]() { + connect(detailButton, &QPushButton::clicked, [styleList, item, this, index]() { QDialog dlg(this); dlg.setWindowTitle("样式详情"); dlg.resize(400, 200); - auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Cancel, &dlg); + QGridLayout *contentLayout = new QGridLayout(&dlg); + QLineEdit* name = new QLineEdit(styleNames[index], &dlg); + auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Cancel); + contentLayout->addWidget(buttonBox); connect(buttonBox, &QDialogButtonBox::accepted, &dlg, &QDialog::accept); connect(buttonBox, &QDialogButtonBox::rejected, &dlg, &QDialog::reject); bool updateStyle = dlg.exec(); if (updateStyle) { + styleNames[index] = name->text(); + qDebug() << name->text(); // 在此处修改新样式信息至内存 + emit requireRefreshPreview(); + emit requireSelfRefresh(); } }); connect(deleteButton, &QPushButton::clicked, [styleList,item,this]() { @@ -115,6 +122,7 @@ void InfoDisplayWidget::generateLayerForm() delete item; // 删除layer对应样式 emit requireRefreshPreview(); + emit requireSelfRefresh(); }); layout->addWidget(name); layout->addWidget(detailButton); @@ -137,3 +145,11 @@ void InfoDisplayWidget::generateLayerForm() void InfoDisplayWidget::generateElementForm() { } + +void InfoDisplayWidget::triggerSelfRefresh() +{ + if (this->displayLayer != nullptr) + this->generateLayerForm(); + else + this->generateElementForm(); +} \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.h b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.h index c95586d..5426425 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.h +++ b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.h @@ -17,7 +17,13 @@ class InfoDisplayWidget : public QWidget void setElement(GraphicElement *element); void generateLayerForm(); void generateElementForm(); + + public slots: + void triggerSelfRefresh(); signals: void requireRefreshPreview(); + void requireSelfRefresh(); + + }; diff --git a/UnitTest/ElementRendererTest.cpp b/UnitTest/ElementRendererTest.cpp index 859f4a3..88aed8d 100644 --- a/UnitTest/ElementRendererTest.cpp +++ b/UnitTest/ElementRendererTest.cpp @@ -15,6 +15,8 @@ namespace UnitTest public: TEST_METHOD(TestBothSidesRound) { + Logger::WriteMessage("In Class1"); + Assert::AreEqual(1 ,2); QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); diff --git a/data.json b/data.json index 20889e6..e8a7a0c 100644 --- a/data.json +++ b/data.json @@ -1,109 +1,38 @@ { - "height": 1080, - "width": 1080, - "elements": [ - { - "name": "ababa", - "type": "svg-file", - "data": { - "include": "./svg/2.svg" - } - }, - { - "name": "ababa-group", - "type": "group", - "data": { - "reference-layer": "0.0" - } - } - ], - "root-layer": { - "name": "root", - "transform": { - "offset": { - "x": 0, - "y": 0 - }, - "scale": { - "x": 1.0, - "y": 1.0 - }, + "height": 1080, + "width": 1920, + "elements": [ + { + "name": "ababa", + "type": "svg-file", + "data": { + "include": "./svg/12(1).svg" + } + }, + { + "name": "ababa-group", + "type": "group", + "data": { + "reference-layer": "0.0" + } + } + ], + "root-layer": { + "name": "root", + "transform": { + "offset": { + "x": 0, + "y": 0 + }, + "scale": { + "x": 0.5, + "y": 0.5 + }, "rotation": 0.0 - }, - "effects": [], - "is-folder": true, - "referenced-by": null, - "children": [ - { - "name": "GroupFolderExample", - "transform": { - "offset": { - "x": 50, - "y": 50 - }, - "scale": { - "x": 1.0, - "y": 1.0 - }, - "rotation": 0.0 - }, - "effects": [], - "is-folder": true, - "referenced-by": 1, - "children": [ - { - "name": "Leaf1", - "transform": { - "offset": { - "x": 0, - "y": 0 - }, - "scale": { - "x": 1.0, - "y": 1.0 - }, - "rotation": 0.0 - }, - "effects": [], - "is-folder": false, - "element": 0 - }, - { - "name": "Leaf2", - "transform": { - "offset": { - "x": 150, - "y": 0 - }, - "scale": { - "x": 1.5, - "y": 1.5 - }, - "rotation": 0.0 - }, - "effects": [], - "is-folder": false, - "element": 0 - } - ] - }, - { - "name": "ReferencingGroupLayer", - "transform": { - "offset": { - "x": 100, - "y": 0 - }, - "scale": { - "x": 1, - "y": 1 - }, - "rotation": 45 - }, - "effects": [], - "is-folder": false, - "element": 1 - } - ] - } -} \ No newline at end of file + }, + "effects": [], + "is-folder": false, + "element": 0 + } + +} diff --git a/svg/12(1).svg b/svg/12(1).svg new file mode 100644 index 0000000..d7ebd10 --- /dev/null +++ b/svg/12(1).svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/svg/12.svg b/svg/12.svg new file mode 100644 index 0000000..d16fc67 --- /dev/null +++ b/svg/12.svg @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file