parent
468bab5e5b
commit
31b9244957
1 changed files with 11 additions and 4 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
#include "cutils.hpp"
|
#include "cutils.hpp"
|
||||||
|
|
||||||
#include <qobject.h>
|
#include <qobject.h>
|
||||||
|
#include <QtQuick/QQuickWindow>
|
||||||
#include <QtQuick/QQuickItem>
|
#include <QtQuick/QQuickItem>
|
||||||
#include <QtQuick/QQuickItemGrabResult>
|
#include <QtQuick/QQuickItemGrabResult>
|
||||||
#include <QThreadPool>
|
#include <QThreadPool>
|
||||||
|
|
@ -38,15 +39,21 @@ void CUtils::saveItem(QQuickItem* target, const QUrl& path, const QRect& rect, Q
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto scaledRect = rect;
|
||||||
|
if (rect.isValid()) {
|
||||||
|
qreal scale = target->window()->devicePixelRatio();
|
||||||
|
scaledRect = QRect(rect.left() * scale, rect.top() * scale, rect.width() * scale, rect.height() * scale);
|
||||||
|
}
|
||||||
|
|
||||||
QSharedPointer<QQuickItemGrabResult> grabResult = target->grabToImage();
|
QSharedPointer<QQuickItemGrabResult> grabResult = target->grabToImage();
|
||||||
|
|
||||||
QObject::connect(grabResult.data(), &QQuickItemGrabResult::ready, this,
|
QObject::connect(grabResult.data(), &QQuickItemGrabResult::ready, this,
|
||||||
[grabResult, rect, path, onSaved, onFailed, this]() {
|
[grabResult, scaledRect, path, onSaved, onFailed, this]() {
|
||||||
QThreadPool::globalInstance()->start([grabResult, rect, path, onSaved, onFailed, this] {
|
QThreadPool::globalInstance()->start([grabResult, scaledRect, path, onSaved, onFailed, this] {
|
||||||
QImage image = grabResult->image();
|
QImage image = grabResult->image();
|
||||||
|
|
||||||
if (!rect.isEmpty()) {
|
if (scaledRect.isValid()) {
|
||||||
image = image.copy(rect);
|
image = image.copy(scaledRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString file = path.toLocalFile();
|
const QString file = path.toLocalFile();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue