|
|
|
|
@ -67,25 +67,24 @@ bool selectAvatarCrop(const QString& source, QRectF& crop, QWidget* parent) {
|
|
|
|
|
buttons->button(QDialogButtonBox::Ok)->setEnabled(false); layout->addWidget(buttons); |
|
|
|
|
QObject::connect(buttons, &QDialogButtonBox::accepted, &dialog, &QDialog::accept); |
|
|
|
|
QObject::connect(buttons, &QDialogButtonBox::rejected, &dialog, &QDialog::reject); |
|
|
|
|
QPointer<CropView> guard(view); QPointer<QDialog> owner(&dialog); |
|
|
|
|
QThreadPool::globalInstance()->start(QRunnable::create([source, guard, owner, status, buttons] { |
|
|
|
|
QThreadPool pool; pool.setMaxThreadCount(1); |
|
|
|
|
pool.start(QRunnable::create([source, &dialog, view, status, buttons] { |
|
|
|
|
QImageReader reader(source); reader.setAutoTransform(true); const QSize size = reader.size(); QImage image; |
|
|
|
|
if (QFileInfo(source).size() <= AvatarCache::OriginalMaxBytes && size.isValid() && |
|
|
|
|
qint64(size.width())*size.height() <= 16*1024*1024 && |
|
|
|
|
(reader.format()=="jpeg" || reader.format()=="png" || reader.format()=="webp")) { |
|
|
|
|
reader.setScaledSize(size.scaled(1600,1600,Qt::KeepAspectRatio)); image = reader.read(); |
|
|
|
|
} |
|
|
|
|
if (!owner) return; |
|
|
|
|
QMetaObject::invokeMethod(owner, [guard, image, status, buttons] { |
|
|
|
|
if (!guard) return; |
|
|
|
|
QMetaObject::invokeMethod(&dialog, [view, image, status, buttons] { |
|
|
|
|
if (image.isNull()) { |
|
|
|
|
DEBUG_WARN(DEBUG_CATEGORY_MEDIA, "avatar: editor cannot decode selected source"); |
|
|
|
|
status->setText(QCoreApplication::translate("ChatGui", "Cannot load avatar image")); return; |
|
|
|
|
} |
|
|
|
|
guard->image=image; guard->update(); buttons->button(QDialogButtonBox::Ok)->setEnabled(true); |
|
|
|
|
view->image=image; view->update(); buttons->button(QDialogButtonBox::Ok)->setEnabled(true); |
|
|
|
|
}, Qt::QueuedConnection); |
|
|
|
|
})); |
|
|
|
|
if (dialog.exec()!=QDialog::Accepted) { DEBUG_DEBUG(DEBUG_CATEGORY_MEDIA, "avatar: crop cancelled"); return false; } |
|
|
|
|
const int result=dialog.exec(); pool.waitForDone(); |
|
|
|
|
if (result!=QDialog::Accepted) { DEBUG_DEBUG(DEBUG_CATEGORY_MEDIA, "avatar: crop cancelled"); return false; } |
|
|
|
|
crop=view->selection(); DEBUG_INFO(DEBUG_CATEGORY_MEDIA, "avatar: crop selected x=%.5f y=%.5f w=%.5f h=%.5f", |
|
|
|
|
crop.x(), crop.y(), crop.width(), crop.height()); return true; |
|
|
|
|
} |
|
|
|
|
|