Compare commits

..

No commits in common. "c81c7d69d4317a1f8663f16869b3b3e3ffef0582" and "e0813ba364d5b346f236ca5e390559ea5c96d1ca" have entirely different histories.

7 changed files with 17 additions and 60 deletions

View File

@ -54,19 +54,6 @@
</property> </property>
</widget> </widget>
</item> </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> </layout>
</item> </item>
</layout> </layout>

View File

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

View File

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

View File

@ -18,32 +18,11 @@ PreviewWindow::PreviewWindow(QWidget* parent) : QOpenGLWidget(parent)
backgroundColor = QColor(255, 255, 255, 255); backgroundColor = QColor(255, 255, 255, 255);
} }
void PreviewWindow::initialize(LayerManager* layerManager, QSize referSize, QSize windowSize) void PreviewWindow::initialize(LayerManager* layerManager, QSize windowSize)
{ {
this->logicalSize = windowSize; this->logicalSize = windowSize;
this->layerManager = layerManager; this->layerManager = layerManager;
this->resize(referSize); this->setFixedSize(windowSize);
}
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() void PreviewWindow::show()
@ -72,7 +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, actualSize.width() * devicePixelRatioF(), actualSize.height() * devicePixelRatioF()); painter->setWindow(0, 0, logicalSize.width() * devicePixelRatioF(), logicalSize.height() * devicePixelRatioF());
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);
@ -162,12 +141,12 @@ void PreviewWindow::wheelEvent(QWheelEvent* event)
if (event->delta() > 0 && zoomStep < ZOOM_STEP_MAX) if (event->delta() > 0 && zoomStep < ZOOM_STEP_MAX)
{ {
zoomStep++; zoomStep++;
this->setFixedSize(actualSize * (1 + zoomStep * ZOOM_RATE)); this->setFixedSize(logicalSize * (1 + zoomStep * ZOOM_RATE));
} }
else if (event->delta() < 0 && zoomStep > ZOOM_STEP_MIN) else if (event->delta() < 0 && zoomStep > ZOOM_STEP_MIN)
{ {
zoomStep--; zoomStep--;
this->setFixedSize(actualSize * (1 + zoomStep * ZOOM_RATE)); this->setFixedSize(logicalSize * (1 + zoomStep * ZOOM_RATE));
} }
this->repaint(); this->repaint();
} }

View File

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

View File

@ -18,9 +18,4 @@ EditorSettingWidget::EditorSettingWidget(QWidget* parent)
QString name = QInputDialog::getText(this, QString::fromLocal8Bit("重命名"), QString::fromLocal8Bit("请输入新的项目名称")); QString name = QInputDialog::getText(this, QString::fromLocal8Bit("重命名"), QString::fromLocal8Bit("请输入新的项目名称"));
emit projectNameChanged(name); 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: signals:
void backgroundColorChanged(QColor); void backgroundColorChanged(QColor);
void projectNameChanged(QString); void projectNameChanged(QString);
void canvasSizeChanged(QSize);
}; };