FIX: GraphicElement中pixelRatio计算错误
parent
2569b07233
commit
6a09bdd32c
|
@ -92,7 +92,7 @@ QJsonObject GroupElement::toJson() const
|
|||
return result;
|
||||
}
|
||||
|
||||
void SimpleElement::paint(QPainter* painter, QTransform transform, const vector<std::shared_ptr<LayerStyle>> &styles)
|
||||
void SimpleElement::paint(QPainter* painter, QTransform transform, const vector<std::shared_ptr<LayerStyle>>& styles)
|
||||
{
|
||||
painter->save();
|
||||
painter->setTransform(transform);
|
||||
|
@ -102,12 +102,15 @@ void SimpleElement::paint(QPainter* painter, QTransform transform, const vector<
|
|||
}
|
||||
else
|
||||
{
|
||||
Renderer::ElementStyleStrokeDemo demo(2);
|
||||
std::shared_ptr<Renderer::ElementStyle> style;
|
||||
style = styles[0];
|
||||
QVector2D scale(transform.m11(), transform.m22());
|
||||
scale /= transform.m33();
|
||||
double maxScale = std::max(scale.x(), scale.y());
|
||||
|
||||
double angle = atan(transform.m12() / transform.m11());
|
||||
double maxScale;
|
||||
if (fabs(cos(angle))>1e-5)
|
||||
maxScale = std::max(fabs(transform.m11() / cos(angle)), fabs(transform.m22() / cos(angle)));
|
||||
else
|
||||
maxScale = std::max(fabs(transform.m12() / sin(angle)), fabs(transform.m21() / sin(angle)));
|
||||
double pixelRatio = maxScale * QGuiApplication::primaryScreen()->devicePixelRatio();
|
||||
auto [img, mov] = Renderer::ElementRenderer::instance()->drawElement(painterPath, *style, pixelRatio);
|
||||
transform.translate(mov.x(), mov.y());
|
||||
|
@ -117,7 +120,7 @@ void SimpleElement::paint(QPainter* painter, QTransform transform, const vector<
|
|||
painter->restore();
|
||||
}
|
||||
|
||||
void GroupElement::paint(QPainter* painter, QTransform transform, const vector<std::shared_ptr<LayerStyle>> &styles)
|
||||
void GroupElement::paint(QPainter* painter, QTransform transform, const vector<std::shared_ptr<LayerStyle>>& styles)
|
||||
{
|
||||
sourceLayer->paint(painter, transform);
|
||||
}
|
||||
|
@ -125,7 +128,7 @@ void GroupElement::paint(QPainter* painter, QTransform transform, const vector<s
|
|||
|
||||
QPixmap SimpleElement::getPreview(QSize size)
|
||||
{
|
||||
QPixmap result(size + QSize(5,5));
|
||||
QPixmap result(size + QSize(5, 5));
|
||||
QPainter painter(&result);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
|
@ -143,7 +146,7 @@ QPixmap GroupElement::getPreview(QSize size)
|
|||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
sourceLayer->paint(&painter, QTransform(), true);
|
||||
painter.end();
|
||||
QRect rect (cache.getBoundingRect().toRect());
|
||||
QRect rect(cache.getBoundingRect().toRect());
|
||||
rect.setTopLeft(rect.topLeft() - QPoint(5, 5));
|
||||
rect.setBottomRight(rect.bottomRight() + QPoint(5, 5));
|
||||
result = result.copy(rect);
|
||||
|
|
Loading…
Reference in New Issue