添加项目信息管理器
parent
0543a02dfb
commit
b944572204
|
@ -104,6 +104,7 @@
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="src\Editor\DataManager\ProjectDataManager.cpp" />
|
||||||
<ClCompile Include="src\Editor\EditorWidgetComponent\FillStyleWidget.cpp" />
|
<ClCompile Include="src\Editor\EditorWidgetComponent\FillStyleWidget.cpp" />
|
||||||
<ClCompile Include="src\Editor\RightBar\EditorSettingWidget.cpp" />
|
<ClCompile Include="src\Editor\RightBar\EditorSettingWidget.cpp" />
|
||||||
<ClCompile Include="src\Editor\EditorWidgetComponent\ColorPicker.cpp" />
|
<ClCompile Include="src\Editor\EditorWidgetComponent\ColorPicker.cpp" />
|
||||||
|
@ -202,6 +203,7 @@
|
||||||
<QtMoc Include="src\Editor\EditorWidgetComponent\ColorPicker.h" />
|
<QtMoc Include="src\Editor\EditorWidgetComponent\ColorPicker.h" />
|
||||||
<QtMoc Include="src\Editor\RightBar\EditorSettingWidget.h" />
|
<QtMoc Include="src\Editor\RightBar\EditorSettingWidget.h" />
|
||||||
<QtMoc Include="src\Editor\EditorWidgetComponent\FillStyleWidget.h" />
|
<QtMoc Include="src\Editor\EditorWidgetComponent\FillStyleWidget.h" />
|
||||||
|
<ClInclude Include="src\Editor\DataManager\ProjectDataManager.h" />
|
||||||
<ClInclude Include="src\ColorHelper.hpp" />
|
<ClInclude Include="src\ColorHelper.hpp" />
|
||||||
<ClInclude Include="src\Editor\LayerWrapper.h" />
|
<ClInclude Include="src\Editor\LayerWrapper.h" />
|
||||||
<ClInclude Include="src\Editor\util\EncodeUtil.hpp" />
|
<ClInclude Include="src\Editor\util\EncodeUtil.hpp" />
|
||||||
|
|
|
@ -258,6 +258,9 @@
|
||||||
<ClCompile Include="src\Editor\EditorWidgetComponent\FillStyleWidget.cpp">
|
<ClCompile Include="src\Editor\EditorWidgetComponent\FillStyleWidget.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\Editor\DataManager\ProjectDataManager.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<QtMoc Include="src\Renderer\RendererGLWidget.h">
|
<QtMoc Include="src\Renderer\RendererGLWidget.h">
|
||||||
|
@ -522,6 +525,9 @@
|
||||||
<ClInclude Include="src\ColorHelper.hpp">
|
<ClInclude Include="src\ColorHelper.hpp">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="src\Editor\DataManager\ProjectDataManager.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<QtRcc Include="res\MainWindow.qrc">
|
<QtRcc Include="res\MainWindow.qrc">
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
#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);
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
#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);
|
||||||
|
};
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#include "EditorWidgetItem.h"
|
#include "EditorWidgetItem.h"
|
||||||
#include "EditorWidget.h"
|
#include "EditorWidget.h"
|
||||||
|
#include "DataManager/ProjectDataManager.h"
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QFileInfo>
|
||||||
|
|
||||||
EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(parent)
|
EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(parent)
|
||||||
{
|
{
|
||||||
|
@ -54,6 +56,14 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
|
||||||
QJsonDocument jsonDoc(QJsonDocument::fromJson(setting, &jError));
|
QJsonDocument jsonDoc(QJsonDocument::fromJson(setting, &jError));
|
||||||
qDebug() << jsonDoc.object().value("height").toDouble();
|
qDebug() << jsonDoc.object().value("height").toDouble();
|
||||||
qDebug() << jError.errorString();
|
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
|
// end test
|
||||||
QJsonObject source = jsonDoc.object();
|
QJsonObject source = jsonDoc.object();
|
||||||
elementManager = new ElementManager(source,Renderer::ElementRenderer::instance());
|
elementManager = new ElementManager(source,Renderer::ElementRenderer::instance());
|
||||||
|
@ -79,7 +89,6 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
|
||||||
handleProjectNameChange(this->projectName);
|
handleProjectNameChange(this->projectName);
|
||||||
centralRefresh();
|
centralRefresh();
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorWidgetItem::~EditorWidgetItem()
|
EditorWidgetItem::~EditorWidgetItem()
|
||||||
|
|
|
@ -16,7 +16,7 @@ class EditorWidgetItem : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
private:
|
public:
|
||||||
// DATA PART
|
// DATA PART
|
||||||
PreviewWindow *previewWindow;
|
PreviewWindow *previewWindow;
|
||||||
ElementManager *elementManager;
|
ElementManager *elementManager;
|
||||||
|
|
|
@ -14,6 +14,7 @@ PreviewWindow::PreviewWindow(QWidget *parent) : QOpenGLWidget(parent)
|
||||||
painter->setRenderHint(QPainter::HighQualityAntialiasing);
|
painter->setRenderHint(QPainter::HighQualityAntialiasing);
|
||||||
layerManager = nullptr;
|
layerManager = nullptr;
|
||||||
currentLayer = nullptr;
|
currentLayer = nullptr;
|
||||||
|
zoomStep = 0;
|
||||||
backgroundColor = QColor(255, 255, 255, 255);
|
backgroundColor = QColor(255, 255, 255, 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +22,7 @@ void PreviewWindow::initialize(LayerManager *layerManager,QSize windowSize)
|
||||||
{
|
{
|
||||||
this->logicalSize = windowSize;
|
this->logicalSize = windowSize;
|
||||||
this->layerManager = layerManager;
|
this->layerManager = layerManager;
|
||||||
|
this->setFixedSize(windowSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewWindow::show()
|
void PreviewWindow::show()
|
||||||
|
@ -49,6 +51,7 @@ void PreviewWindow::paintGL()
|
||||||
glClearColor(backgroundColor.redF(), backgroundColor.greenF(), backgroundColor.blueF(), backgroundColor.alphaF());
|
glClearColor(backgroundColor.redF(), backgroundColor.greenF(), backgroundColor.blueF(), backgroundColor.alphaF());
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
painter->begin(this);
|
painter->begin(this);
|
||||||
|
painter->setWindow(0, 0, logicalSize.width(), logicalSize.height());
|
||||||
painter->setRenderHint(QPainter::Antialiasing);
|
painter->setRenderHint(QPainter::Antialiasing);
|
||||||
painter->setRenderHint(QPainter::HighQualityAntialiasing);
|
painter->setRenderHint(QPainter::HighQualityAntialiasing);
|
||||||
layerManager->paint(painter,this->size(),currentLayer);
|
layerManager->paint(painter,this->size(),currentLayer);
|
||||||
|
@ -130,3 +133,21 @@ void PreviewWindow::setBackgroundColor(QColor color)
|
||||||
this->backgroundColor = color;
|
this->backgroundColor = color;
|
||||||
this->repaint();
|
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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,6 +16,14 @@ class PreviewWindow : public QOpenGLWidget, protected QOpenGLFunctions
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
private:
|
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;
|
QPainter *painter;
|
||||||
LayerManager *layerManager;
|
LayerManager *layerManager;
|
||||||
Renderer::ElementRenderer* renderer;
|
Renderer::ElementRenderer* renderer;
|
||||||
|
@ -27,6 +35,7 @@ class PreviewWindow : public QOpenGLWidget, protected QOpenGLFunctions
|
||||||
void mousePressEvent(QMouseEvent* event) override;
|
void mousePressEvent(QMouseEvent* event) override;
|
||||||
void mouseMoveEvent(QMouseEvent* event) override;
|
void mouseMoveEvent(QMouseEvent* event) override;
|
||||||
void mouseReleaseEvent(QMouseEvent* event) override;
|
void mouseReleaseEvent(QMouseEvent* event) override;
|
||||||
|
void wheelEvent(QWheelEvent* event) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PreviewWindow(QWidget *parent = nullptr);
|
PreviewWindow(QWidget *parent = nullptr);
|
||||||
|
|
Loading…
Reference in New Issue