Compare commits

..

No commits in common. "826a8d3e2e3b3d471f21e9f09ac992f64938bf7c" and "a07bf3bcedf189c5506c74e859186804c53c4918" have entirely different histories.

16 changed files with 19 additions and 165 deletions

View File

@ -104,7 +104,6 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="src\Editor\DataManager\ProjectDataManager.cpp" />
<ClCompile Include="src\Editor\EditorWidgetComponent\FillStyleWidget.cpp" />
<ClCompile Include="src\Editor\RightBar\EditorSettingWidget.cpp" />
<ClCompile Include="src\Editor\EditorWidgetComponent\ColorPicker.cpp" />
@ -203,7 +202,6 @@
<QtMoc Include="src\Editor\EditorWidgetComponent\ColorPicker.h" />
<QtMoc Include="src\Editor\RightBar\EditorSettingWidget.h" />
<QtMoc Include="src\Editor\EditorWidgetComponent\FillStyleWidget.h" />
<ClInclude Include="src\Editor\DataManager\ProjectDataManager.h" />
<ClInclude Include="src\ColorHelper.hpp" />
<ClInclude Include="src\Editor\LayerWrapper.h" />
<ClInclude Include="src\Editor\util\EncodeUtil.hpp" />

View File

@ -258,9 +258,6 @@
<ClCompile Include="src\Editor\EditorWidgetComponent\FillStyleWidget.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Editor\DataManager\ProjectDataManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<QtMoc Include="src\Renderer\RendererGLWidget.h">
@ -525,9 +522,6 @@
<ClInclude Include="src\ColorHelper.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\Editor\DataManager\ProjectDataManager.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<QtRcc Include="res\MainWindow.qrc">

View File

@ -1,38 +0,0 @@
#include "ProjectDataManager.h"
using namespace std;
ProjectDataManager* ProjectDataManager::instance = nullptr;
ProjectDataManager* ProjectDataManager::Instance()
{
if (instance == nullptr)
instance = new ProjectDataManager();
return instance;
}
void ProjectDataManager::addProjectData(ProjectData data)
{
projectDataList.push_back(data);
}
void ProjectDataManager::setZoom(double x, double y, EditorWidgetItem* item)
{
for (auto& data : projectDataList) {
if (data.item == item) {
data.zoomX = x;
data.zoomY = y;
return;
}
}
}
QPointF ProjectDataManager::getZoomByPainterDeivce(QPaintDevice* device)
{
for (auto& data : projectDataList) {
if (data.item->previewWindow == device) {
return QPointF(data.zoomX, data.zoomY);
}
}
return QPointF(1, 1);
}

View File

@ -1,30 +0,0 @@
#pragma once
#include <map>
#include <QPaintDevice>
#include <QFile>
#include <vector>
#include "EditorWidgetItem.h"
struct ProjectData
{
int width, height;
double zoomX, zoomY;
QString fileHome;
EditorWidgetItem* item;
};
class ProjectDataManager
{
private:
std::vector<ProjectData> projectDataList;
ProjectDataManager() = default;
~ProjectDataManager() = default;
static ProjectDataManager* instance;
public:
static ProjectDataManager* Instance();
void addProjectData(ProjectData data);
void setZoom(double x, double y, EditorWidgetItem* item);
QPointF getZoomByPainterDeivce(QPaintDevice* device);
};

View File

@ -1,10 +1,6 @@
#include "EditorWidgetItem.h"
#include "EditorWidget.h"
#include "DataManager/ProjectDataManager.h"
#include <QTimer>
#include <QFileInfo>
#include <QFile>
#include <QDir>
EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(parent)
{
@ -58,17 +54,9 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
QJsonDocument jsonDoc(QJsonDocument::fromJson(setting, &jError));
qDebug() << jsonDoc.object().value("height").toDouble();
qDebug() << jError.errorString();
ProjectData data;
data.fileHome = QFileInfo(filePath).absolutePath();
data.width = jsonDoc.object().value("height").toInt();
data.height = jsonDoc.object().value("width").toInt();
data.zoomX = 1.0;
data.zoomY = 1.0;
data.item = this;
ProjectDataManager::Instance()->addProjectData(data);
// end test
QJsonObject source = jsonDoc.object();
elementManager = new ElementManager(source, QFileInfo(filePath).absolutePath());
elementManager = new ElementManager(source,Renderer::ElementRenderer::instance());
layerManager = new LayerManager(source, elementManager);
elementInfoDisplayWidget->setElementManager(elementManager);
treeWidget->elementManager = elementManager;
@ -91,6 +79,7 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
handleProjectNameChange(this->projectName);
centralRefresh();
});
}
EditorWidgetItem::~EditorWidgetItem()
@ -127,23 +116,6 @@ void EditorWidgetItem::save() const
void EditorWidgetItem::saveAs(QString filePath) const
{
saveImpl(filePath);
QString srcHome = QFileInfo(this->filePath).absolutePath();
if (!QDir(QFileInfo(filePath).absolutePath() + "/svg").exists())
{
QDir().mkdir(QFileInfo(filePath).absolutePath() + "/svg");
}
for (auto& ele : elementManager->elements)
{
auto e = dynamic_cast<SimpleElement*>(ele);
if (e != nullptr)
{
QString fileName = e->jsonSource["data"].toObject()["include"].toString();
QString src = srcHome + fileName;
QString dst = QFileInfo(filePath).absolutePath() + fileName;
QFile::copy(src, dst);
}
}
}
void EditorWidgetItem::saveImpl(QString filePath) const

View File

@ -16,7 +16,7 @@ class EditorWidgetItem : public QWidget
{
Q_OBJECT
public:
private:
// DATA PART
PreviewWindow *previewWindow;
ElementManager *elementManager;

View File

@ -1,20 +1,16 @@
#include "ElementManager.h"
#include <QFileInfo>
#include <QDir>
#include <QFile>
ElementManager::ElementManager(QJsonObject source, QString fileHome)
ElementManager::ElementManager(QJsonObject source,Renderer::ElementRenderer* renderer)
{
auto elementsJson = source.value("elements").toArray();
this->fileHome = fileHome;
int index = 0;
for (auto elementJson : elementsJson)
{
if (elementJson.toObject().value("type").toString() == "group")
elements.push_back(new GroupElement());
else
elements.push_back(new SimpleElement(elementJson.toObject(), fileHome));
elements.push_back(new SimpleElement(elementJson.toObject()));
(*elements.rbegin())->name = elementJson.toObject().value("name").toString();
(*elements.rbegin())->renderer = renderer;
}
for (auto element : elements)
element->index = index++;
@ -94,11 +90,9 @@ void ElementManager::createGroupElement(QString name, FolderLayerWrapper* source
void ElementManager::createSimpleElement(QString name, QString filePath) {
QJsonObject json;
QJsonObject data;
QFile fileSrc(filePath);
QFile::copy(filePath, QDir::cleanPath(fileHome + "/svg/" + QFileInfo(filePath).fileName()));
data.insert("include", "/svg/"+QFileInfo(filePath).fileName());
data.insert("include", filePath);
json.insert("data", data);
auto element = new SimpleElement(json, fileHome);
auto element = new SimpleElement(json);
element->name = name;
addElement(element);
}

View File

@ -14,10 +14,9 @@ class ElementManager
{
public:
vector<GraphicElement *> elements;
QString fileHome;
public:
ElementManager(QJsonObject source, QString fileHome);
ElementManager(QJsonObject source,Renderer::ElementRenderer *renderer);
~ElementManager();
void addElement(GraphicElement *element);
void removeElement(GraphicElement *pElement);

View File

@ -2,8 +2,6 @@
#include "util/SvgFileLoader.h"
#include <QGuiApplication>
#include <QScreen>
#include <QDir>
using namespace std;
PixelPath SimpleElement::getPaintObject() const
@ -25,13 +23,13 @@ void SimpleElement::loadSvgFile(const QString& filePath)
qDebug() << "load svg file success " << painterPath.elementCount() << (isClosed() ? "is" : "not") << "closed";
}
SimpleElement::SimpleElement(QJsonObject jsonSource, QString fileHome) : jsonSource(jsonSource)
SimpleElement::SimpleElement(QJsonObject jsonSource) : jsonSource(jsonSource)
{
painterPath.clear();
filePath = jsonSource["data"].toObject()["include"].toString();
//loadSvgFile("D:\\Projects\\BigC\\svg\\3.svg");
QFileInfo info(QDir::cleanPath(fileHome + "/" + filePath));
loadSvgFile(info.absoluteFilePath());
QFileInfo info(filePath);
loadSvgFile(filePath);
}
GroupElement::GroupElement(FolderLayerWrapper* sourceLayer)

View File

@ -46,7 +46,7 @@ public:
public:
QJsonObject toJson() const override;
SimpleElement(QJsonObject jsonSource, QString fileHome);
SimpleElement(QJsonObject jsonSource);
SimpleElement(QString filePath);
~SimpleElement() = default;
PixelPath getPaintObject() const override;

View File

@ -75,7 +75,7 @@ FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *element
}
LeafLayerWrapper::LeafLayerWrapper(QJsonObject json, ElementManager* elementManager, FolderLayerWrapper* parent)
: LayerWrapper(json, parent, elementManager),
: LayerWrapper(json, parent),
wrappedElement(elementManager->getElementById(json.value("element").toInt())),
styles(LayerStyleContainer::fromJson(wrappedElement->isClosed(), json.value("styles").toArray()))
{
@ -255,8 +255,7 @@ QJsonObject FolderLayerWrapper::toJson() const
QJsonObject json = LayerWrapper::toJson();
QJsonArray childrenJson;
for (auto& child : children)
if(child != nullptr)
childrenJson.push_back(child->toJson());
childrenJson.push_back(child->toJson());
json.insert("children", childrenJson);
json.insert("is-folder", true);
if(this->getReferencedBy() != -1)
@ -269,7 +268,7 @@ QJsonObject FolderLayerWrapper::toJson() const
QJsonObject LeafLayerWrapper::toJson() const
{
QJsonObject json = LayerWrapper::toJson();
json.insert("element", elementManager->getElementIndex(wrappedElement));
json.insert("element", wrappedElement->index);
json.insert("is-folder", false);
json.insert("styles", styles.toJson());
return json;

View File

@ -14,7 +14,6 @@ PreviewWindow::PreviewWindow(QWidget *parent) : QOpenGLWidget(parent)
painter->setRenderHint(QPainter::HighQualityAntialiasing);
layerManager = nullptr;
currentLayer = nullptr;
zoomStep = 0;
backgroundColor = QColor(255, 255, 255, 255);
}
@ -22,7 +21,6 @@ void PreviewWindow::initialize(LayerManager *layerManager,QSize windowSize)
{
this->logicalSize = windowSize;
this->layerManager = layerManager;
this->setFixedSize(windowSize);
}
void PreviewWindow::show()
@ -51,7 +49,6 @@ void PreviewWindow::paintGL()
glClearColor(backgroundColor.redF(), backgroundColor.greenF(), backgroundColor.blueF(), backgroundColor.alphaF());
glClear(GL_COLOR_BUFFER_BIT);
painter->begin(this);
painter->setWindow(0, 0, logicalSize.width(), logicalSize.height());
painter->setRenderHint(QPainter::Antialiasing);
painter->setRenderHint(QPainter::HighQualityAntialiasing);
layerManager->paint(painter,this->size(),currentLayer);
@ -133,21 +130,3 @@ void PreviewWindow::setBackgroundColor(QColor color)
this->backgroundColor = color;
this->repaint();
}
void PreviewWindow::wheelEvent(QWheelEvent* event)
{
if (QApplication::keyboardModifiers() == Qt::ControlModifier)
{
if (event->delta() > 0 && zoomStep < ZOOM_STEP_MAX)
{
zoomStep++;
this->setFixedSize(logicalSize * (1 + zoomStep * ZOOM_RATE));
}
else if(event->delta() < 0 && zoomStep > ZOOM_STEP_MIN)
{
zoomStep--;
this->setFixedSize(logicalSize * (1 + zoomStep * ZOOM_RATE));
}
this->repaint();
}
}

View File

@ -16,14 +16,6 @@ class PreviewWindow : public QOpenGLWidget, protected QOpenGLFunctions
Q_OBJECT
private:
constexpr static double ZOOM_RATE = 0.25;
constexpr static double ZOOM_DEFAULT = 1.0;
constexpr static int ZOOM_STEP_MIN = -2;
constexpr static int ZOOM_STEP_MAX = 4;
private:
int zoomStep;
QPainter *painter;
LayerManager *layerManager;
Renderer::ElementRenderer* renderer;
@ -35,7 +27,6 @@ class PreviewWindow : public QOpenGLWidget, protected QOpenGLFunctions
void mousePressEvent(QMouseEvent* event) override;
void mouseMoveEvent(QMouseEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override;
void wheelEvent(QWheelEvent* event) override;
public:
PreviewWindow(QWidget *parent = nullptr);

View File

@ -59,7 +59,6 @@ void LayerTreeWidget::popMenu(const QPoint &pos)
connect(dialog, &LayerCreateWidget::LayerInfoReturned, this, [this, layer](QJsonObject jsonObj) {
auto folderLayer = dynamic_cast<FolderLayerWrapper*>(layer);
LayerWrapper* newLayer;
qDebug() << this->elementManager;
if(jsonObj.value("is-folder").toBool())
newLayer = new FolderLayerWrapper(jsonObj, this->elementManager, folderLayer);
else

View File

@ -3,7 +3,6 @@
#include <QJsondocument>
#include "PainterPathUtil.h"
#include <queue>
#include <QFileInfo>
using Renderer::Painting;
using Renderer::BaseElement;
@ -36,7 +35,7 @@ Painting PaintingUtil::transfromToPainting(QString jsonFilePath) {
glm::bvec2 flip(0, 0);
QJsonObject jsonObj = readJsonFile(jsonFilePath);
qDebug() << jsonObj;
shared_ptr<ElementManager> elementManager = make_shared<ElementManager>(jsonObj, QFileInfo(jsonFilePath).absolutePath());
shared_ptr<ElementManager> elementManager = make_shared<ElementManager>(jsonObj, Renderer::ElementRenderer::instance());
shared_ptr<LayerManager> layerManager = make_shared<LayerManager>(jsonObj, elementManager.get());
//qDebug() << elementManager->toJson();
//qDebug() << layerManager->toJson();

View File

@ -8,7 +8,7 @@
"name": "ababa",
"type": "svg-file",
"data": {
"include": "/svg/2.svg"
"include": "../svg/2.svg"
}
},
{
@ -22,7 +22,7 @@
"name": "ababa2",
"type": "svg-file",
"data": {
"include": "/svg/0.svg"
"include": "../svg/0.svg"
}
}
],