Compare commits

...

2 Commits

7 changed files with 60 additions and 17 deletions

View File

@ -54,6 +54,19 @@
</property>
</widget>
</item>
<item alignment="Qt::AlignHCenter">
<widget class="QPushButton" name="resizeButton">
<property name="maximumSize">
<size>
<width>120</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>设置画布尺寸</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>

View File

@ -70,9 +70,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-17</y>
<width>1024</width>
<height>1024</height>
<y>0</y>
<width>0</width>
<height>0</height>
</rect>
</property>
<property name="sizePolicy">
@ -83,14 +83,14 @@
</property>
<property name="minimumSize">
<size>
<width>1024</width>
<height>1024</height>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>1024</width>
<height>1024</height>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
</widget>

View File

@ -40,6 +40,7 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
//connect(treeWidget, &LayerTreeWidget::requireRefreshElementWidget, elementInfoDisplayWidget, &ElementPoolWidget::refresh);
// connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireRefreshElementWidget, elementInfoDisplayWidget, &ElementPoolWidget::refresh);
connect(treeWidget, &LayerTreeWidget::displayLayerChange, this, &EditorWidgetItem::onLayerChange);
connect(editorSettingWidget, &EditorSettingWidget::canvasSizeChanged, previewWindow, &PreviewWindow::resize);
// connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireRefreshPreview, this,
// &EditorWidgetItem::triggerRefreshPreview);
// connect(treeWidget, &LayerTreeWidget::requireRefreshPreview, this,
@ -72,7 +73,7 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
elementInfoDisplayWidget->setElementManager(elementManager);
treeWidget->elementManager = elementManager;
//qDebug() << layerManager->toJson();
previewWindow->initialize(layerManager,QSize(jsonDoc.object().value("width").toDouble(),jsonDoc.object().value("height").toDouble()));
previewWindow->initialize(layerManager,QSize(jsonDoc.object().value("width").toInt(),jsonDoc.object().value("height").toInt()));
if (layerManager->getRoot() != nullptr)
@ -151,8 +152,8 @@ void EditorWidgetItem::saveImpl(QString filePath) const
QJsonObject source1 = layerManager->toJson();
QJsonObject source2 = elementManager->toJson();
QJsonObject json;
json.insert("width", 1080);
json.insert("height", 1080);
json.insert("width", previewWindow->referSize.width());
json.insert("height", previewWindow->referSize.height());
json.insert("root-layer", source1.value("root-layer"));
json.insert("elements", source2.value("elements"));
json.insert("project-name", this->projectName);

View File

@ -18,11 +18,32 @@ PreviewWindow::PreviewWindow(QWidget* parent) : QOpenGLWidget(parent)
backgroundColor = QColor(255, 255, 255, 255);
}
void PreviewWindow::initialize(LayerManager* layerManager, QSize windowSize)
void PreviewWindow::initialize(LayerManager* layerManager, QSize referSize, QSize windowSize)
{
this->logicalSize = windowSize;
this->layerManager = layerManager;
this->setFixedSize(windowSize);
this->resize(referSize);
}
void PreviewWindow::resize(QSize _referSize)
{
if (!_referSize.isValid())
return;
if (_referSize.width() == 0 || _referSize.height() == 0)
return;
this->referSize = _referSize;
if (referSize.width() > referSize.height())
{
actualSize.setWidth(logicalSize.width());
actualSize.setHeight(logicalSize.width() * referSize.height() / referSize.width());
}
else
{
actualSize.setHeight(logicalSize.height());
actualSize.setWidth(logicalSize.height() * referSize.width() / referSize.height());
}
this->setFixedSize(actualSize);
this->viewportRect = QRectF(QPointF(0, 0), actualSize);
}
void PreviewWindow::show()
@ -51,7 +72,7 @@ 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() * devicePixelRatioF(), logicalSize.height() * devicePixelRatioF());
painter->setWindow(0, 0, actualSize.width() * devicePixelRatioF(), actualSize.height() * devicePixelRatioF());
painter->setRenderHint(QPainter::Antialiasing);
painter->setRenderHint(QPainter::HighQualityAntialiasing);
layerManager->paint(painter, this->size(), currentLayer);
@ -141,12 +162,12 @@ void PreviewWindow::wheelEvent(QWheelEvent* event)
if (event->delta() > 0 && zoomStep < ZOOM_STEP_MAX)
{
zoomStep++;
this->setFixedSize(logicalSize * (1 + zoomStep * ZOOM_RATE));
this->setFixedSize(actualSize * (1 + zoomStep * ZOOM_RATE));
}
else if (event->delta() < 0 && zoomStep > ZOOM_STEP_MIN)
{
zoomStep--;
this->setFixedSize(logicalSize * (1 + zoomStep * ZOOM_RATE));
this->setFixedSize(actualSize * (1 + zoomStep * ZOOM_RATE));
}
this->repaint();
}

View File

@ -28,6 +28,7 @@ class PreviewWindow : public QOpenGLWidget, protected QOpenGLFunctions
LayerManager *layerManager;
Renderer::ElementRenderer* renderer;
QSize logicalSize;
QSize actualSize;
QRectF viewportRect;
LayerWrapper* currentLayer;
QPointF m_lastPos;
@ -38,8 +39,10 @@ class PreviewWindow : public QOpenGLWidget, protected QOpenGLFunctions
void wheelEvent(QWheelEvent* event) override;
public:
QSize referSize;
PreviewWindow(QWidget *parent = nullptr);
void initialize(LayerManager *layerManager, QSize windowSize = QSize(1920, 1080));
void initialize(LayerManager *layerManager,QSize referSize, QSize windowSize = QSize(720, 720));
void resize(QSize _referSize);
void show();
void initializeGL() override;
void paintGL() override;

View File

@ -18,4 +18,9 @@ EditorSettingWidget::EditorSettingWidget(QWidget* parent)
QString name = QInputDialog::getText(this, QString::fromLocal8Bit("重命名"), QString::fromLocal8Bit("请输入新的项目名称"));
emit projectNameChanged(name);
});
connect(ui.resizeButton, &QPushButton::clicked, this, [this]() {
int width = QInputDialog::getInt(this, QString::fromLocal8Bit("重设画布大小"), QString::fromLocal8Bit("请输入新的画布宽度"));
int height = QInputDialog::getInt(this, QString::fromLocal8Bit("重设画布大小"), QString::fromLocal8Bit("请输入新的画布高度"));
emit canvasSizeChanged(QSize(width, height));
});
}

View File

@ -16,6 +16,6 @@ class EditorSettingWidget :
signals:
void backgroundColorChanged(QColor);
void projectNameChanged(QString);
void canvasSizeChanged(QSize);
};