Merge branch 'main' of http://101.34.228.45:3000/BigC/ArchitectureColoredPainting
commit
16bfba76e4
|
@ -361,3 +361,4 @@ MigrationBackup/
|
||||||
|
|
||||||
# Fody - auto-generated XML schema
|
# Fody - auto-generated XML schema
|
||||||
FodyWeavers.xsd
|
FodyWeavers.xsd
|
||||||
|
/UnitTest/Qt.x64.runsettings
|
||||||
|
|
|
@ -105,6 +105,7 @@
|
||||||
<ClCompile Include="src\Editor\GraphicElement.cpp" />
|
<ClCompile Include="src\Editor\GraphicElement.cpp" />
|
||||||
<ClCompile Include="src\Editor\LayerManager.cpp" />
|
<ClCompile Include="src\Editor\LayerManager.cpp" />
|
||||||
<ClCompile Include="src\Editor\LayerWrapper.cpp" />
|
<ClCompile Include="src\Editor\LayerWrapper.cpp" />
|
||||||
|
<ClCompile Include="src\Editor\PixelPath.cpp" />
|
||||||
<ClCompile Include="src\Editor\PreviewWindow.cpp" />
|
<ClCompile Include="src\Editor\PreviewWindow.cpp" />
|
||||||
<ClCompile Include="src\Editor\RightBar\InfoDisplayWidget.cpp" />
|
<ClCompile Include="src\Editor\RightBar\InfoDisplayWidget.cpp" />
|
||||||
<ClCompile Include="src\Editor\RightBar\LayerTreeWidget.cpp" />
|
<ClCompile Include="src\Editor\RightBar\LayerTreeWidget.cpp" />
|
||||||
|
@ -181,6 +182,7 @@
|
||||||
<ClInclude Include="src\Editor\LayerManager.h" />
|
<ClInclude Include="src\Editor\LayerManager.h" />
|
||||||
<ClInclude Include="src\Editor\LayerStyle.h" />
|
<ClInclude Include="src\Editor\LayerStyle.h" />
|
||||||
<QtMoc Include="src\Editor\PreviewWindow.h" />
|
<QtMoc Include="src\Editor\PreviewWindow.h" />
|
||||||
|
<ClInclude Include="src\Editor\PixelPath.h" />
|
||||||
<ClInclude Include="src\Editor\ThirdPartyLib\qquick\qquicksvgparser_p.h" />
|
<ClInclude Include="src\Editor\ThirdPartyLib\qquick\qquicksvgparser_p.h" />
|
||||||
<ClInclude Include="src\Editor\ThirdPartyLib\qquick\qtquickglobal.h" />
|
<ClInclude Include="src\Editor\ThirdPartyLib\qquick\qtquickglobal.h" />
|
||||||
<ClInclude Include="src\Editor\ThirdPartyLib\qquick\qtquickglobal_p.h" />
|
<ClInclude Include="src\Editor\ThirdPartyLib\qquick\qtquickglobal_p.h" />
|
||||||
|
|
|
@ -204,6 +204,9 @@
|
||||||
<ClCompile Include="src\Renderer\Preview\ElementRenderer.cpp">
|
<ClCompile Include="src\Renderer\Preview\ElementRenderer.cpp">
|
||||||
<Filter>Source Files\Renderer\Preview</Filter>
|
<Filter>Source Files\Renderer\Preview</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\Editor\PixelPath.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<QtMoc Include="src\Renderer\RendererGLWidget.h">
|
<QtMoc Include="src\Renderer\RendererGLWidget.h">
|
||||||
|
@ -408,6 +411,9 @@
|
||||||
<ClInclude Include="src\Renderer\Preview\ElementRenderer.h">
|
<ClInclude Include="src\Renderer\Preview\ElementRenderer.h">
|
||||||
<Filter>Header Files\Renderer\Preview</Filter>
|
<Filter>Header Files\Renderer\Preview</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="src\Editor\PixelPath.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<QtRcc Include="MainWindow.qrc">
|
<QtRcc Include="MainWindow.qrc">
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
EditorWidget::EditorWidget(QWidget *parent) : QWidget(parent)
|
EditorWidget::EditorWidget(QWidget *parent) : QWidget(parent)
|
||||||
{
|
{
|
||||||
|
QImage x;
|
||||||
displayLayer = nullptr;
|
displayLayer = nullptr;
|
||||||
displayElement = nullptr;
|
displayElement = nullptr;
|
||||||
ui.setupUi(this);
|
ui.setupUi(this);
|
||||||
|
@ -25,7 +26,7 @@ EditorWidget::EditorWidget(QWidget *parent) : QWidget(parent)
|
||||||
qDebug() << jError.errorString();
|
qDebug() << jError.errorString();
|
||||||
// end test
|
// end test
|
||||||
QJsonObject source = jsonDoc.object();
|
QJsonObject source = jsonDoc.object();
|
||||||
elementManager = new ElementManager(source);
|
elementManager = new ElementManager(source,previewWindow->getRenderer());
|
||||||
layerManager = new LayerManager(source, elementManager);
|
layerManager = new LayerManager(source, elementManager);
|
||||||
previewWindow->initialize(layerManager);
|
previewWindow->initialize(layerManager);
|
||||||
if (layerManager->getRoot() != nullptr)
|
if (layerManager->getRoot() != nullptr)
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QTreeWidget>
|
#include <QTreeWidget>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
class EditorWidget : public QWidget
|
class EditorWidget : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include "ElementManager.h"
|
#include "ElementManager.h"
|
||||||
ElementManager::ElementManager(QJsonObject source)
|
ElementManager::ElementManager(QJsonObject source,Renderer::ElementRenderer* renderer)
|
||||||
{
|
{
|
||||||
auto elementsJson = source.value("elements").toArray();
|
auto elementsJson = source.value("elements").toArray();
|
||||||
qDebug() << elementsJson.size();
|
qDebug() << elementsJson.size();
|
||||||
|
@ -9,6 +9,8 @@ ElementManager::ElementManager(QJsonObject source)
|
||||||
elements.push_back(new GroupElement());
|
elements.push_back(new GroupElement());
|
||||||
else
|
else
|
||||||
elements.push_back(new SimpleElement(elementJson.toObject()));
|
elements.push_back(new SimpleElement(elementJson.toObject()));
|
||||||
|
|
||||||
|
(*elements.rbegin())->renderer = renderer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,12 @@
|
||||||
#include "GraphicElement.h"
|
#include "GraphicElement.h"
|
||||||
#include "LayerManager.h"
|
#include "LayerManager.h"
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
|
#include "../Renderer/Preview/ElementRenderer.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
using std::vector;
|
using std::vector;
|
||||||
class LayerManager;
|
class LayerManager;
|
||||||
class GraphicElement;
|
class GraphicElement;
|
||||||
|
class Renderer::ElementRenderer;
|
||||||
|
|
||||||
class ElementManager
|
class ElementManager
|
||||||
{
|
{
|
||||||
|
@ -13,7 +15,7 @@ class ElementManager
|
||||||
vector<GraphicElement *> elements;
|
vector<GraphicElement *> elements;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ElementManager(QJsonObject source);
|
ElementManager(QJsonObject source,Renderer::ElementRenderer *renderer);
|
||||||
~ElementManager();
|
~ElementManager();
|
||||||
void addElement(GraphicElement *element);
|
void addElement(GraphicElement *element);
|
||||||
void removeElement(GraphicElement *pElement);
|
void removeElement(GraphicElement *pElement);
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
#include "GraphicElement.h"
|
#include "GraphicElement.h"
|
||||||
#include "util/SvgFileLoader.h"
|
#include "util/SvgFileLoader.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
QPainterPath SimpleElement::getPaintObject() const
|
|
||||||
|
PixelPath SimpleElement::getPaintObject() const
|
||||||
{
|
{
|
||||||
return painterPath;
|
PixelPath result;
|
||||||
|
result.addPath(painterPath);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleElement::loadSvgFile(const QString& filePath)
|
void SimpleElement::loadSvgFile(const QString& filePath)
|
||||||
|
@ -29,26 +32,48 @@ void GroupElement::setSourceLayer(FolderLayerWrapper *sourceLayer)
|
||||||
{
|
{
|
||||||
this->sourceLayer = sourceLayer;
|
this->sourceLayer = sourceLayer;
|
||||||
}
|
}
|
||||||
QPainterPath GroupElement::getPaintObject() const
|
PixelPath GroupElement::getPaintObject() const
|
||||||
{
|
{
|
||||||
if (sourceLayer != nullptr) {
|
if (sourceLayer != nullptr) {
|
||||||
sourceLayer->refresh();
|
sourceLayer->refresh();
|
||||||
return sourceLayer->getCache();
|
return sourceLayer->getCache();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return QPainterPath();
|
return PixelPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitmapPath::applyTransformation(QTransform& transformation)
|
//TODO: apply styles and send back
|
||||||
{
|
PixelPath SimpleElement::getPaintObject(std::vector<Renderer::ElementStyleStrokeDemo> styles) const {
|
||||||
|
PixelPath result;
|
||||||
|
Renderer::ElementStyleStrokeDemo demo;
|
||||||
|
qDebug() << (renderer==nullptr)<<"------------";
|
||||||
|
//auto [img, mov] = renderer->drawElement(painterPath,demo,1.0,false);
|
||||||
|
//qDebug() << img << " ------";
|
||||||
|
//result.addImage(img, mov);
|
||||||
|
result.addPath(painterPath);
|
||||||
|
// QImage img(80,80,QImage::Format_ARGB32);
|
||||||
|
// QPainter pt(&img);
|
||||||
|
//pt.setPen(QPen(Qt::red, 2));
|
||||||
|
//pt.drawLine(0, 0, 80, 80);
|
||||||
|
//pt.end();
|
||||||
|
//result.addImage(img, QPoint(0, 0));
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage FolderBitmapPath::getStylesAppliedCache() const
|
PixelPath GroupElement::getPaintObject(std::vector<Renderer::ElementStyleStrokeDemo> styles) const {
|
||||||
{
|
return getPaintObject();
|
||||||
return QImage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage ComposedPainterPath::getStylesAppliedCache() const
|
//BitmapPath::BitmapPath() {
|
||||||
{
|
// pathCount = 0u;
|
||||||
return QImage();
|
//}
|
||||||
}
|
//
|
||||||
|
//void BitmapPath::initialize(vector<QPainterPath>& paths) {
|
||||||
|
// cache.clear();
|
||||||
|
// rawPath.clear();
|
||||||
|
// pathCount = 1u;
|
||||||
|
// bound
|
||||||
|
// for (auto& path : paths) {
|
||||||
|
// rawPath.addPath(path);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "LayerWrapper.h"
|
#include "LayerWrapper.h"
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QPainterPath>
|
#include <QPainterPath>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "../Renderer/Preview/ElementRenderer.h"
|
||||||
#include "../Renderer/Painting/ElementStyle.h"
|
#include "../Renderer/Painting/ElementStyle.h"
|
||||||
|
#include "PixelPath.h"
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
class LayerWrapper;
|
class LayerWrapper;
|
||||||
class LeafLayerWrapper;
|
class LeafLayerWrapper;
|
||||||
|
@ -16,9 +20,11 @@ class ComposedPainterPath;
|
||||||
class GraphicElement
|
class GraphicElement
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Renderer::ElementRenderer *renderer;
|
||||||
QString name = "";
|
QString name = "";
|
||||||
// TODO: ¸ÄΪBitmapPath
|
// TODO: ¸ÄΪBitmapPath
|
||||||
virtual QPainterPath getPaintObject() const = 0;
|
virtual PixelPath getPaintObject() const = 0;
|
||||||
|
virtual PixelPath getPaintObject(std::vector<Renderer::ElementStyleStrokeDemo>) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SimpleElement : public GraphicElement
|
class SimpleElement : public GraphicElement
|
||||||
|
@ -32,7 +38,8 @@ private:
|
||||||
public:
|
public:
|
||||||
SimpleElement(QJsonObject jsonSource);
|
SimpleElement(QJsonObject jsonSource);
|
||||||
~SimpleElement() = default;
|
~SimpleElement() = default;
|
||||||
QPainterPath getPaintObject() const override;
|
PixelPath getPaintObject() const override;
|
||||||
|
PixelPath getPaintObject(std::vector<Renderer::ElementStyleStrokeDemo>) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GroupElement : public GraphicElement
|
class GroupElement : public GraphicElement
|
||||||
|
@ -44,51 +51,31 @@ public:
|
||||||
GroupElement() = default;
|
GroupElement() = default;
|
||||||
GroupElement(FolderLayerWrapper* mSourceLayer);
|
GroupElement(FolderLayerWrapper* mSourceLayer);
|
||||||
~GroupElement() = default;
|
~GroupElement() = default;
|
||||||
QPainterPath getPaintObject() const override;
|
PixelPath getPaintObject() const override;
|
||||||
|
PixelPath getPaintObject(std::vector<Renderer::ElementStyleStrokeDemo>) const override;
|
||||||
void setSourceLayer(FolderLayerWrapper* sourceLayer);
|
void setSourceLayer(FolderLayerWrapper* sourceLayer);
|
||||||
};
|
};
|
||||||
|
|
||||||
//******************************** BitmapPath ********************************//
|
//******************************** BitmapPath ********************************//
|
||||||
|
|
||||||
using std::vector;
|
//using std::vector;
|
||||||
using std::shared_ptr;
|
//using std::shared_ptr;
|
||||||
|
//
|
||||||
class BitmapPath
|
//class BitmapPath
|
||||||
{
|
//{
|
||||||
protected:
|
//private:
|
||||||
QRectF boundingRect;
|
// QRectF *boundingRect;
|
||||||
QImage stylesAppliedCache;
|
// QPainterPath cache;
|
||||||
void applyTransformation(QTransform &transformation);
|
// QPainterPath rawPath;
|
||||||
|
// size_t pathCount;
|
||||||
public:
|
//
|
||||||
/**
|
//public:
|
||||||
* 用painter的引用将它的QImage画到画布上
|
// BitmapPath();
|
||||||
*/
|
// void initialize(std::vector<QPainterPath>& paths);
|
||||||
virtual void paint(QPainter* painter) const = 0;
|
// void styles(Renderer::ElementStyle* style);
|
||||||
virtual QImage getStylesAppliedCache() const = 0;
|
// void trans(QTransform& transform);
|
||||||
};
|
// QPainterPath getPainterPath() const;
|
||||||
|
// void addBitmapPath(BitmapPath& path);
|
||||||
class FolderBitmapPath : public BitmapPath
|
// QRectF boundingRect()const;
|
||||||
{
|
// void clear();
|
||||||
public:
|
//};
|
||||||
const vector<BitmapPath*> children;
|
|
||||||
virtual QImage getStylesAppliedCache() const override;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 当获取cache的时候应该调用Render的接口
|
|
||||||
*/
|
|
||||||
class ComposedPainterPath : public BitmapPath
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* 因为ElementStyle应该被应用至整个叶子图层节点,所以它应该只用zealed来确定某些Style是否应该被作用于该Path
|
|
||||||
*/
|
|
||||||
struct SinglePath {
|
|
||||||
shared_ptr<QPainterPath> path;
|
|
||||||
bool zealed;
|
|
||||||
};
|
|
||||||
|
|
||||||
const vector<SinglePath> paths;
|
|
||||||
virtual QImage getStylesAppliedCache() const override;
|
|
||||||
};
|
|
||||||
|
|
|
@ -13,7 +13,8 @@ LayerWrapper *LayerManager::getRoot() const
|
||||||
}
|
}
|
||||||
void LayerManager::paint(QPainter *painter) const
|
void LayerManager::paint(QPainter *painter) const
|
||||||
{
|
{
|
||||||
painter->drawPath(root->getCache());
|
auto p = root->getCache().getPixmap();
|
||||||
|
painter->drawPixmap(0, 0, p);
|
||||||
}
|
}
|
||||||
bool LayerManager::singleSelectedCheck() const
|
bool LayerManager::singleSelectedCheck() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,11 +23,12 @@ LayerWrapper *LayerWrapper::getParent() const
|
||||||
return this == nullptr ? nullptr : this->parent.get();
|
return this == nullptr ? nullptr : this->parent.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
QPainterPath LayerWrapper::getCache()
|
PixelPath LayerWrapper::getCache()
|
||||||
{
|
{
|
||||||
this->refresh();
|
this->refresh();
|
||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: undone
|
// TODO: undone
|
||||||
LayerWrapper::LayerWrapper(QJsonObject json, LayerWrapper *parent)
|
LayerWrapper::LayerWrapper(QJsonObject json, LayerWrapper *parent)
|
||||||
{
|
{
|
||||||
|
@ -76,19 +77,19 @@ LeafLayerWrapper::LeafLayerWrapper(QJsonObject json, ElementManager *elementMana
|
||||||
int elementIndex = json.value("element").toInt();
|
int elementIndex = json.value("element").toInt();
|
||||||
wrappedElement = elementManager->getElementById(elementIndex);
|
wrappedElement = elementManager->getElementById(elementIndex);
|
||||||
}
|
}
|
||||||
void LayerWrapper::SimpleProperty::apply(QPainterPath &cache) const
|
void LayerWrapper::SimpleProperty::apply(PixelPath&cache) const
|
||||||
{
|
{
|
||||||
QTransform trans;
|
QTransform trans;
|
||||||
double centerX = cache.boundingRect().center().x();
|
double centerX = cache.getBoundingRect().center().x();
|
||||||
double centerY = cache.boundingRect().center().y();
|
double centerY = cache.getBoundingRect().center().y();
|
||||||
qDebug() << name << " " << cache.boundingRect().center();
|
//qDebug() << name << " " << cache.boundingRect().center();
|
||||||
qDebug() << name << " " << cache.boundingRect();
|
//qDebug() << name << " " << cache.boundingRect();
|
||||||
trans.translate(centerX, centerY);
|
trans.translate(centerX, centerY);
|
||||||
trans.scale(scale.x(), scale.y());
|
trans.scale(scale.x(), scale.y());
|
||||||
trans.rotate(rotation);
|
trans.rotate(rotation);
|
||||||
trans.translate(-centerX, -centerY);
|
trans.translate(-centerX, -centerY);
|
||||||
trans.translate(offset.x(), offset.y());
|
trans.translate(offset.x(), offset.y());
|
||||||
cache = trans.map(cache);
|
cache = cache.trans(trans);
|
||||||
}
|
}
|
||||||
void LayerWrapper::refresh()
|
void LayerWrapper::refresh()
|
||||||
{
|
{
|
||||||
|
@ -108,7 +109,7 @@ void LeafLayerWrapper::refresh()
|
||||||
cache.clear();
|
cache.clear();
|
||||||
if (wrappedElement != nullptr)
|
if (wrappedElement != nullptr)
|
||||||
{
|
{
|
||||||
cache.addPath(wrappedElement->getPaintObject());
|
cache.addPath(wrappedElement->getPaintObject(this->styles));
|
||||||
}
|
}
|
||||||
LayerWrapper::refresh();
|
LayerWrapper::refresh();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include <QTreeWidget>
|
#include <QTreeWidget>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "PixelPath.h"
|
||||||
#include "../Renderer/Painting/ElementStyle.h"
|
#include "../Renderer/Painting/ElementStyle.h"
|
||||||
using std::shared_ptr;
|
using std::shared_ptr;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
@ -29,7 +29,7 @@ class LayerWrapper
|
||||||
QPointF referencePoint;
|
QPointF referencePoint;
|
||||||
// vector<LayerStyle> styles;
|
// vector<LayerStyle> styles;
|
||||||
// TODO: 将cache移到子类,对Leaf用ComposedPainterPath,对Folder用FolderBitmapPath
|
// TODO: 将cache移到子类,对Leaf用ComposedPainterPath,对Folder用FolderBitmapPath
|
||||||
QPainterPath cache;
|
PixelPath cache;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QTreeWidgetItem *qTreeItem;
|
QTreeWidgetItem *qTreeItem;
|
||||||
|
@ -42,12 +42,12 @@ class LayerWrapper
|
||||||
bool flipHorizontally = 0;
|
bool flipHorizontally = 0;
|
||||||
bool flipVertically = 0;
|
bool flipVertically = 0;
|
||||||
// TODO: 将QPainterPath改为BitmapPath
|
// TODO: 将QPainterPath改为BitmapPath
|
||||||
void apply(QPainterPath &cache) const;
|
void apply(PixelPath&cache) const;
|
||||||
} property;
|
} property;
|
||||||
void setParent(LayerWrapper *newParent);
|
void setParent(LayerWrapper *newParent);
|
||||||
virtual void refresh();
|
virtual void refresh();
|
||||||
// TODO: 将QPainterPath改为BitmapPath/QImage,或者直接将其删除,绘制时直接使用BitmapPath的paint方法
|
// TODO: 将QPainterPath改为BitmapPath/QImage,或者直接将其删除,绘制时直接使用BitmapPath的paint方法
|
||||||
QPainterPath getCache();
|
virtual PixelPath getCache();
|
||||||
LayerWrapper *getParent() const; // invoke by manager, then invoke parent's applyStyles
|
LayerWrapper *getParent() const; // invoke by manager, then invoke parent's applyStyles
|
||||||
LayerWrapper(QJsonObject json, LayerWrapper *parent);
|
LayerWrapper(QJsonObject json, LayerWrapper *parent);
|
||||||
LayerWrapper() = default;
|
LayerWrapper() = default;
|
||||||
|
@ -76,7 +76,7 @@ class LeafLayerWrapper : public LayerWrapper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GraphicElement *wrappedElement;
|
GraphicElement *wrappedElement;
|
||||||
const vector<Renderer::ElementStyle> styles;
|
const vector<Renderer::ElementStyleStrokeDemo> styles;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void refresh() override;
|
void refresh() override;
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
#include "PixelPath.h"
|
||||||
|
#include <QPainter>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
PixelPath::PixelPath(int w, int h) :w(w), h(h)
|
||||||
|
{
|
||||||
|
pixmap = QPixmap(w, h);
|
||||||
|
pixmap.fill(Qt::transparent);
|
||||||
|
boundingRect = QRectF(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
PixelPath::PixelPath(QPainterPath painterPath, int w, int h) :w(w), h(h)
|
||||||
|
{
|
||||||
|
pixmap = QPixmap(w, h);
|
||||||
|
pixmap.fill(Qt::transparent);
|
||||||
|
boundingRect = QRectF(0, 0, 0, 0);
|
||||||
|
addPath(painterPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
QRectF PixelPath::getBoundingRect() const
|
||||||
|
{
|
||||||
|
return boundingRect;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPixmap PixelPath::getPixmap() const
|
||||||
|
{
|
||||||
|
return pixmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PixelPath::addPath(const PixelPath& path)
|
||||||
|
{
|
||||||
|
QPainter painter(&pixmap);
|
||||||
|
painter.drawPixmap(0, 0, path.getPixmap());
|
||||||
|
boundingRect = boundingRect.united(path.getBoundingRect());
|
||||||
|
}
|
||||||
|
|
||||||
|
void PixelPath::addPath(const QPainterPath& path)
|
||||||
|
{
|
||||||
|
QPainter painter(&pixmap);
|
||||||
|
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||||
|
painter.setRenderHint(QPainter::HighQualityAntialiasing);
|
||||||
|
painter.setPen(QPen(Qt::black,1));
|
||||||
|
painter.drawPath(path);
|
||||||
|
boundingRect = boundingRect.united(path.boundingRect());
|
||||||
|
}
|
||||||
|
|
||||||
|
void PixelPath::addImage(const QImage& image,const QPointF& pos)
|
||||||
|
{
|
||||||
|
QPainter painter(&pixmap);
|
||||||
|
painter.drawImage(pos, image);
|
||||||
|
boundingRect = boundingRect.united(QRectF(pos, image.size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void PixelPath::clear()
|
||||||
|
{
|
||||||
|
pixmap.fill(Qt::transparent);
|
||||||
|
boundingRect = QRectF(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
PixelPath PixelPath::trans(QTransform& mat)const
|
||||||
|
{
|
||||||
|
PixelPath result(w, h);
|
||||||
|
QPainter painter(&result.pixmap);
|
||||||
|
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||||
|
painter.setRenderHint(QPainter::HighQualityAntialiasing);
|
||||||
|
painter.setTransform(mat);
|
||||||
|
painter.drawPixmap(0, 0, pixmap);
|
||||||
|
result.boundingRect = mat.mapRect(boundingRect);
|
||||||
|
return result;
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QImage>
|
||||||
|
#include <QPixmap>
|
||||||
|
#include <QTransform>
|
||||||
|
#include <QPainterPath>
|
||||||
|
|
||||||
|
class PixelPath
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
QRectF boundingRect;
|
||||||
|
QPixmap pixmap;
|
||||||
|
int w,h;
|
||||||
|
public:
|
||||||
|
PixelPath(int w=1280, int h=720);
|
||||||
|
PixelPath(QPainterPath painterPath,int w = 1280, int h = 720);
|
||||||
|
~PixelPath() = default;
|
||||||
|
QRectF getBoundingRect() const;
|
||||||
|
QPixmap getPixmap() const;
|
||||||
|
void addPath(const PixelPath& path);
|
||||||
|
void addPath(const QPainterPath& path);
|
||||||
|
void addImage(const QImage& image,const QPointF& pos);
|
||||||
|
void clear();
|
||||||
|
PixelPath trans(QTransform& mat)const;
|
||||||
|
};
|
|
@ -2,10 +2,13 @@
|
||||||
|
|
||||||
PreviewWindow::PreviewWindow(QWidget *parent) : QOpenGLWidget(parent)
|
PreviewWindow::PreviewWindow(QWidget *parent) : QOpenGLWidget(parent)
|
||||||
{
|
{
|
||||||
|
this->renderer = new Renderer::ElementRenderer(this);
|
||||||
QSurfaceFormat surfaceFormat;
|
QSurfaceFormat surfaceFormat;
|
||||||
surfaceFormat.setSamples(16);
|
surfaceFormat.setSamples(16);
|
||||||
setFormat(surfaceFormat);
|
setFormat(surfaceFormat);
|
||||||
painter = new QPainter(this);
|
painter = new QPainter(this);
|
||||||
|
painter->setRenderHint(QPainter::SmoothPixmapTransform);
|
||||||
|
painter->setRenderHint(QPainter::HighQualityAntialiasing);
|
||||||
layerManager = nullptr;
|
layerManager = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,28 +19,29 @@ void PreviewWindow::initialize(LayerManager *layerManager)
|
||||||
|
|
||||||
void PreviewWindow::show()
|
void PreviewWindow::show()
|
||||||
{
|
{
|
||||||
QFile settingFile;
|
//QFile settingFile;
|
||||||
settingFile.setFileName("../data.json");
|
//settingFile.setFileName("../data.json");
|
||||||
settingFile.open(QFile::ReadOnly);
|
//settingFile.open(QFile::ReadOnly);
|
||||||
QByteArray setting = settingFile.readAll().trimmed();
|
//QByteArray setting = settingFile.readAll().trimmed();
|
||||||
QJsonDocument jsonDoc(QJsonDocument::fromJson(setting));
|
//QJsonDocument jsonDoc(QJsonDocument::fromJson(setting));
|
||||||
auto jElements = jsonDoc.object().value("elements").toArray();
|
//auto jElements = jsonDoc.object().value("elements").toArray();
|
||||||
|
|
||||||
for (auto &&ele : jElements)
|
//for (auto &&ele : jElements)
|
||||||
{
|
//{
|
||||||
SimpleElement element(ele.toObject());
|
// SimpleElement element(ele.toObject());
|
||||||
painter->drawPath(element.getPaintObject());
|
// painter->drawPath(element.getPaintObject());
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewWindow::initializeGL()
|
void PreviewWindow::initializeGL()
|
||||||
{
|
{
|
||||||
|
this->renderer->initialize();
|
||||||
initializeOpenGLFunctions();
|
initializeOpenGLFunctions();
|
||||||
glClearColor(1.0, 1.0, 1.0, 1.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewWindow::paintGL()
|
void PreviewWindow::paintGL()
|
||||||
{
|
{
|
||||||
|
glClearColor(1.0, 1.0, 1.0, 1.0);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
painter->begin(this);
|
painter->begin(this);
|
||||||
painter->setRenderHint(QPainter::Antialiasing);
|
painter->setRenderHint(QPainter::Antialiasing);
|
||||||
|
@ -49,3 +53,7 @@ void PreviewWindow::paintGL()
|
||||||
void PreviewWindow::resizeGL(int w, int h)
|
void PreviewWindow::resizeGL(int w, int h)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Renderer::ElementRenderer* const PreviewWindow::getRenderer()const {
|
||||||
|
return this->renderer;
|
||||||
|
}
|
|
@ -8,6 +8,8 @@
|
||||||
#include <QJsonValue>
|
#include <QJsonValue>
|
||||||
#include <QOpenGLFunctions>
|
#include <QOpenGLFunctions>
|
||||||
#include <QOpenGLWidget>
|
#include <QOpenGLWidget>
|
||||||
|
#include "../Renderer/Preview/ElementRenderer.h"
|
||||||
|
|
||||||
class PreviewWindow : public QOpenGLWidget, protected QOpenGLFunctions
|
class PreviewWindow : public QOpenGLWidget, protected QOpenGLFunctions
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -15,6 +17,7 @@ class PreviewWindow : public QOpenGLWidget, protected QOpenGLFunctions
|
||||||
private:
|
private:
|
||||||
QPainter *painter;
|
QPainter *painter;
|
||||||
LayerManager *layerManager;
|
LayerManager *layerManager;
|
||||||
|
Renderer::ElementRenderer* renderer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PreviewWindow(QWidget *parent = nullptr);
|
PreviewWindow(QWidget *parent = nullptr);
|
||||||
|
@ -23,4 +26,5 @@ class PreviewWindow : public QOpenGLWidget, protected QOpenGLFunctions
|
||||||
void initializeGL() override;
|
void initializeGL() override;
|
||||||
void paintGL() override;
|
void paintGL() override;
|
||||||
void resizeGL(int w, int h) override;
|
void resizeGL(int w, int h) override;
|
||||||
|
Renderer::ElementRenderer* const getRenderer()const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<RunSettings>
|
|
||||||
<RunConfiguration>
|
|
||||||
<EnvironmentVariables>
|
|
||||||
<PATH>%PATH%;E:/Qt/5.15.2/msvc2019_64/bin</PATH>
|
|
||||||
</EnvironmentVariables>
|
|
||||||
</RunConfiguration>
|
|
||||||
</RunSettings>
|
|
Loading…
Reference in New Issue