|
|
|
@ -44,9 +44,10 @@ protected: |
|
|
|
QPainter p(this); p.fillRect(rect(), QColor(20,20,22)); if (image.isNull()) return; |
|
|
|
QPainter p(this); p.fillRect(rect(), QColor(20,20,22)); if (image.isNull()) return; |
|
|
|
clamp(); const double s = scale(); const QSizeF size(originalSize.width()*s, originalSize.height()*s); |
|
|
|
clamp(); const double s = scale(); const QSizeF size(originalSize.width()*s, originalSize.height()*s); |
|
|
|
p.setRenderHint(QPainter::SmoothPixmapTransform); |
|
|
|
p.setRenderHint(QPainter::SmoothPixmapTransform); |
|
|
|
|
|
|
|
p.setRenderHint(QPainter::Antialiasing); |
|
|
|
p.drawImage(QRectF(QPointF(width()/2.0,height()/2.0)+offset-QPointF(size.width()/2,size.height()/2), size), image); |
|
|
|
p.drawImage(QRectF(QPointF(width()/2.0,height()/2.0)+offset-QPointF(size.width()/2,size.height()/2), size), image); |
|
|
|
QPainterPath mask; mask.addRect(rect()); mask.addRect(frame()); p.fillPath(mask, QColor(0,0,0,150)); |
|
|
|
QPainterPath mask; mask.addRect(rect()); mask.addEllipse(frame()); p.fillPath(mask, QColor(0,0,0,150)); |
|
|
|
p.setPen(QPen(Qt::white, 2)); p.drawRect(frame()); |
|
|
|
p.setPen(QPen(Qt::white, 2)); p.drawEllipse(frame()); |
|
|
|
} |
|
|
|
} |
|
|
|
void wheelEvent(QWheelEvent* e) override { |
|
|
|
void wheelEvent(QWheelEvent* e) override { |
|
|
|
if (image.isNull()) return; |
|
|
|
if (image.isNull()) return; |
|
|
|
@ -65,7 +66,7 @@ bool selectAvatarCrop(const QString& source, QRectF& crop, QWidget* parent) { |
|
|
|
QDialog dialog(parent); dialog.setWindowTitle(QCoreApplication::translate("ChatGui", "Crop avatar")); dialog.resize(620,650); |
|
|
|
QDialog dialog(parent); dialog.setWindowTitle(QCoreApplication::translate("ChatGui", "Crop avatar")); dialog.resize(620,650); |
|
|
|
auto* layout = new QVBoxLayout(&dialog); auto* view = new CropView(&dialog); layout->addWidget(view, 1); |
|
|
|
auto* layout = new QVBoxLayout(&dialog); auto* view = new CropView(&dialog); layout->addWidget(view, 1); |
|
|
|
view->setObjectName("avatarCropView"); |
|
|
|
view->setObjectName("avatarCropView"); |
|
|
|
auto* status = new QLabel(QCoreApplication::translate("ChatGui", "Drag photo and use the wheel to select a square"), &dialog); |
|
|
|
auto* status = new QLabel(QCoreApplication::translate("ChatGui", "Drag photo and use the wheel to fit the circle"), &dialog); |
|
|
|
layout->addWidget(status); auto* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, &dialog); |
|
|
|
layout->addWidget(status); auto* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, &dialog); |
|
|
|
buttons->button(QDialogButtonBox::Ok)->setText(QCoreApplication::translate("ChatGui", "Upload avatar")); |
|
|
|
buttons->button(QDialogButtonBox::Ok)->setText(QCoreApplication::translate("ChatGui", "Upload avatar")); |
|
|
|
buttons->button(QDialogButtonBox::Ok)->setObjectName("avatarCropUpload"); |
|
|
|
buttons->button(QDialogButtonBox::Ok)->setObjectName("avatarCropUpload"); |
|
|
|
@ -88,6 +89,8 @@ bool selectAvatarCrop(const QString& source, QRectF& crop, QWidget* parent) { |
|
|
|
status->setText(QCoreApplication::translate("ChatGui", "Cannot load avatar image")); return; |
|
|
|
status->setText(QCoreApplication::translate("ChatGui", "Cannot load avatar image")); return; |
|
|
|
} |
|
|
|
} |
|
|
|
view->image=image; view->originalSize=orientedSize; view->update(); buttons->button(QDialogButtonBox::Ok)->setEnabled(true); |
|
|
|
view->image=image; view->originalSize=orientedSize; view->update(); buttons->button(QDialogButtonBox::Ok)->setEnabled(true); |
|
|
|
|
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_MEDIA, "avatar: editor loaded original=%dx%d preview=%dx%d mask=circle", |
|
|
|
|
|
|
|
orientedSize.width(), orientedSize.height(), image.width(), image.height()); |
|
|
|
}, Qt::QueuedConnection); |
|
|
|
}, Qt::QueuedConnection); |
|
|
|
})); |
|
|
|
})); |
|
|
|
const int result=dialog.exec(); pool.waitForDone(); |
|
|
|
const int result=dialog.exec(); pool.waitForDone(); |
|
|
|
|