窗口缩放

TaoZhang-Branch
karlis 2023-02-24 20:07:56 +08:00
parent ab402955cd
commit 28ea0dd394
6 changed files with 22 additions and 8 deletions

View File

@ -11,9 +11,9 @@ LayerWrapper *LayerManager::getRoot() const
{ {
return root; return root;
} }
void LayerManager::paint(QPainter *painter) const void LayerManager::paint(QPainter *painter, QSize size) const
{ {
auto p = root->getCache().getPixmap(); auto p = root->getCache().resizedPixel(size);
painter->drawPixmap(0, 0, p); painter->drawPixmap(0, 0, p);
} }
bool LayerManager::singleSelectedCheck() const bool LayerManager::singleSelectedCheck() const

View File

@ -31,7 +31,7 @@ class LayerManager
LayerWrapper *getRoot() const; LayerWrapper *getRoot() const;
LayerManager() = default; LayerManager() = default;
LayerManager(QJsonObject source, ElementManager* elementManager); LayerManager(QJsonObject source, ElementManager* elementManager);
void paint(QPainter *painter) const; void paint(QPainter *painter, QSize size) const;
bool rename(QString newName) const; bool rename(QString newName) const;
bool combine() const; bool combine() const;
// bool seperate() const; // bool seperate() const;

View File

@ -74,3 +74,15 @@ PixelPath PixelPath::trans(QTransform& mat)const
result.boundingRect = mat.mapRect(boundingRect); result.boundingRect = mat.mapRect(boundingRect);
return result; return result;
} }
QPixmap PixelPath::resizedPixel(QSize size)const
{
QPixmap result(size);
result.fill(Qt::transparent);
QPainter painter(&result);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
painter.setRenderHint(QPainter::HighQualityAntialiasing);
painter.drawPixmap(0, 0, pixmap.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
return result;
}

View File

@ -12,8 +12,8 @@ private:
QPixmap pixmap; QPixmap pixmap;
int w,h; int w,h;
public: public:
PixelPath(int w=2400, int h= 2400); PixelPath(int w=1920, int h= 1080);
PixelPath(QPainterPath painterPath,int w = 2400, int h = 2400); PixelPath(QPainterPath painterPath,int w = 1920, int h = 1080);
~PixelPath() = default; ~PixelPath() = default;
QRectF getBoundingRect() const; QRectF getBoundingRect() const;
QPixmap getPixmap() const; QPixmap getPixmap() const;
@ -22,4 +22,5 @@ public:
void addImage(const QImage& image,const QPointF& pos); void addImage(const QImage& image,const QPointF& pos);
void clear(); void clear();
PixelPath trans(QTransform& mat)const; PixelPath trans(QTransform& mat)const;
QPixmap resizedPixel(QSize size)const;
}; };

View File

@ -14,7 +14,7 @@ PreviewWindow::PreviewWindow(QWidget *parent) : QOpenGLWidget(parent)
void PreviewWindow::initialize(LayerManager *layerManager,QSize windowSize) void PreviewWindow::initialize(LayerManager *layerManager,QSize windowSize)
{ {
this->setFixedSize(windowSize); this->logicalSize = windowSize;
this->layerManager = layerManager; this->layerManager = layerManager;
} }
@ -47,7 +47,7 @@ void PreviewWindow::paintGL()
painter->begin(this); painter->begin(this);
painter->setRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::Antialiasing);
painter->setRenderHint(QPainter::HighQualityAntialiasing); painter->setRenderHint(QPainter::HighQualityAntialiasing);
layerManager->paint(painter); layerManager->paint(painter,this->size());
painter->end(); painter->end();
} }

View File

@ -18,6 +18,7 @@ class PreviewWindow : public QOpenGLWidget, protected QOpenGLFunctions
QPainter *painter; QPainter *painter;
LayerManager *layerManager; LayerManager *layerManager;
Renderer::ElementRenderer* renderer; Renderer::ElementRenderer* renderer;
QSize logicalSize;
public: public:
PreviewWindow(QWidget *parent = nullptr); PreviewWindow(QWidget *parent = nullptr);