67 lines
1.7 KiB
C++
67 lines
1.7 KiB
C++
#include "diagramEditor/diagramEditorPreviewDlg.h"
|
|
#include "diagramEditor/editView.h"
|
|
#include "diagramEditor/editScene.h"
|
|
#include "graphicsDataModel/diagramEditorModel.h"
|
|
#include "diagramEditor/editPanel.h"
|
|
#include "global.h"
|
|
#include <QGuiApplication>
|
|
#include <QScreen>
|
|
|
|
DiagramEditorPreviewDlg::DiagramEditorPreviewDlg(QWidget *parent)
|
|
: QDialog(parent)
|
|
,_pView(nullptr)
|
|
,_pScene(nullptr)
|
|
,_pMainLayout(nullptr)
|
|
,_pParent(nullptr)
|
|
{
|
|
setWindowTitle("预览");
|
|
auto pParent = dynamic_cast<EditPanel*>(parent);
|
|
if(pParent)
|
|
setParent(pParent);
|
|
QRect recParent = parent->geometry();
|
|
setGeometry(recParent.right(),recParent.y(),recParent.width(),recParent.height());
|
|
initial();
|
|
}
|
|
|
|
DiagramEditorPreviewDlg::~DiagramEditorPreviewDlg()
|
|
{
|
|
|
|
}
|
|
|
|
void DiagramEditorPreviewDlg::initial()
|
|
{
|
|
_pMainLayout = new QVBoxLayout(this);
|
|
_pView = new EditView(this);
|
|
_pView->scale(0.5, 0.5);
|
|
_pMainLayout->addWidget(_pView);
|
|
_pScene = new EditPreviewScene(this);
|
|
_pScene->setSceneRect(_pParent->getScene()->sceneRect()); //使用父窗口scene大小
|
|
_pView->setScene(_pScene);
|
|
_pView->centerOn(QPointF(0,0));
|
|
}
|
|
|
|
void DiagramEditorPreviewDlg::showDlg()
|
|
{
|
|
if(_pParent){
|
|
_pScene->clear();
|
|
_pParent->getModel()->setCurPreviewScene(_pScene);
|
|
}
|
|
|
|
show();
|
|
// 设置大小为屏幕的1/3
|
|
QScreen *screen = QGuiApplication::primaryScreen();
|
|
QRect rec = screen->availableGeometry();
|
|
int w = rec.width() / 3;
|
|
int h = rec.height() / 3;
|
|
// 确保最小尺寸
|
|
w = qMax(w, 400);
|
|
h = qMax(h, 300);
|
|
resize(w, h);
|
|
|
|
QRect mainRect = screen->availableGeometry();
|
|
int x = mainRect.right() - width();
|
|
int y = mainRect.bottom() - height();
|
|
move(x, y);
|
|
}
|
|
|