添加【可能存在问题的】拖拽和旋转
parent
ed4c3c0064
commit
de9d7143b6
|
@ -14,6 +14,7 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
|
||||||
elementInfoDisplayWidget = dynamic_cast<ElementPoolWidget *>(tabWidget->widget(1));
|
elementInfoDisplayWidget = dynamic_cast<ElementPoolWidget *>(tabWidget->widget(1));
|
||||||
qDebug() << layerInfoDisplayWidget;
|
qDebug() << layerInfoDisplayWidget;
|
||||||
qDebug() << elementInfoDisplayWidget;
|
qDebug() << elementInfoDisplayWidget;
|
||||||
|
connect(previewWindow, &PreviewWindow::layerInfoChanged, layerInfoDisplayWidget, &InfoDisplayWidget::triggerSelfRefresh);
|
||||||
connect(treeWidget, &LayerTreeWidget::displayLayerChange, previewWindow, &PreviewWindow::currentLayerChanged);
|
connect(treeWidget, &LayerTreeWidget::displayLayerChange, previewWindow, &PreviewWindow::currentLayerChanged);
|
||||||
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);
|
||||||
|
|
|
@ -75,4 +75,40 @@ void PreviewWindow::currentLayerChanged(LayerWrapper* layer)
|
||||||
void PreviewWindow::refresh()
|
void PreviewWindow::refresh()
|
||||||
{
|
{
|
||||||
this->repaint();
|
this->repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PreviewWindow::mousePressEvent(QMouseEvent* event)
|
||||||
|
{
|
||||||
|
// 当鼠标按下时,记录当前的位置
|
||||||
|
m_lastPos = event->pos();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PreviewWindow::mouseMoveEvent(QMouseEvent* event)
|
||||||
|
{
|
||||||
|
// 当鼠标移动时,计算移动的距离,并根据需要更新图形的状态
|
||||||
|
int dx = event->x() - m_lastPos.x();
|
||||||
|
int dy = event->y() - m_lastPos.y();
|
||||||
|
if (currentLayer != nullptr) {
|
||||||
|
if (event->buttons() & Qt::LeftButton) {
|
||||||
|
// 如果按下的是左键,那么平移图形
|
||||||
|
currentLayer->property.offset.setX(currentLayer->property.offset.x() + dx);
|
||||||
|
currentLayer->property.offset.setY(currentLayer->property.offset.y() + dy);
|
||||||
|
qDebug() << dx << "----" << dy;
|
||||||
|
emit layerInfoChanged();
|
||||||
|
}
|
||||||
|
else if (event->buttons() & Qt::RightButton) {
|
||||||
|
// 如果按下的是右键,那么旋转图形
|
||||||
|
qreal angle = -sqrt(dx * dx + dy * dy) / 1.0;
|
||||||
|
currentLayer->property.rotation += angle;
|
||||||
|
emit layerInfoChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 更新上一次的位置
|
||||||
|
m_lastPos = event->pos();
|
||||||
|
this->repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PreviewWindow::mouseReleaseEvent(QMouseEvent* event)
|
||||||
|
{
|
||||||
|
// 当鼠标释放时,不做任何操作
|
||||||
}
|
}
|
|
@ -7,6 +7,7 @@
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonValue>
|
#include <QJsonValue>
|
||||||
#include <QOpenGLFunctions>
|
#include <QOpenGLFunctions>
|
||||||
|
#include <QMouseEvent>
|
||||||
#include <QOpenGLWidget>
|
#include <QOpenGLWidget>
|
||||||
#include "../Renderer/Preview/ElementRenderer.h"
|
#include "../Renderer/Preview/ElementRenderer.h"
|
||||||
|
|
||||||
|
@ -21,7 +22,11 @@ class PreviewWindow : public QOpenGLWidget, protected QOpenGLFunctions
|
||||||
QSize logicalSize;
|
QSize logicalSize;
|
||||||
QRectF viewportRect;
|
QRectF viewportRect;
|
||||||
LayerWrapper* currentLayer;
|
LayerWrapper* currentLayer;
|
||||||
|
QPointF m_lastPos;
|
||||||
|
void mousePressEvent(QMouseEvent* event) override;
|
||||||
|
void mouseMoveEvent(QMouseEvent* event) override;
|
||||||
|
void mouseReleaseEvent(QMouseEvent* event) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PreviewWindow(QWidget *parent = nullptr);
|
PreviewWindow(QWidget *parent = nullptr);
|
||||||
void initialize(LayerManager *layerManager, QSize windowSize = QSize(1920, 1080));
|
void initialize(LayerManager *layerManager, QSize windowSize = QSize(1920, 1080));
|
||||||
|
@ -34,4 +39,7 @@ class PreviewWindow : public QOpenGLWidget, protected QOpenGLFunctions
|
||||||
public slots:
|
public slots:
|
||||||
void currentLayerChanged(LayerWrapper*);
|
void currentLayerChanged(LayerWrapper*);
|
||||||
void refresh();
|
void refresh();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void layerInfoChanged();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue