Show a circular crop preview in the desktop avatar editor
This commit is contained in:
1 parent
ce260d308d
commit
342b2f2387
3 files changed
+8
-5
No files matched your search
@@ -44,9 +44,10 @@ protected:
|
||||
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);
|
||||
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);
|
||||
QPainterPath mask; mask.addRect(rect()); mask.addRect(frame()); p.fillPath(mask, QColor(0,0,0,150));
|
||||
p.setPen(QPen(Qt::white, 2)); p.drawRect(frame());
|
||||
QPainterPath mask; mask.addRect(rect()); mask.addEllipse(frame()); p.fillPath(mask, QColor(0,0,0,150));
|
||||
p.setPen(QPen(Qt::white, 2)); p.drawEllipse(frame());
|
||||
}
|
||||
void wheelEvent(QWheelEvent* e) override {
|
||||
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);
|
||||
auto* layout = new QVBoxLayout(&dialog); auto* view = new CropView(&dialog); layout->addWidget(view, 1);
|
||||
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);
|
||||
buttons->button(QDialogButtonBox::Ok)->setText(QCoreApplication::translate("ChatGui", "Upload avatar"));
|
||||
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;
|
||||
}
|
||||
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);
|
||||
}));
|
||||
const int result=dialog.exec(); pool.waitForDone();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Модальный выбор квадрата: рамка неподвижна, фото перемещается и масштабируется. */
|
||||
/* Выбор области аватара: круглая рамка неподвижна, фото перемещается и масштабируется. */
|
||||
#pragma once
|
||||
#include <QRectF>
|
||||
#include <QString>
|
||||
|
||||
@@ -2100,7 +2100,7 @@ Directories: %5</source>
|
||||
<message><source>No avatar</source><translation>Нет аватарки</translation></message>
|
||||
<message><source>Choose avatar</source><translation>Выбор аватарки</translation></message>
|
||||
<message><source>Crop avatar</source><translation>Выбор области аватарки</translation></message>
|
||||
<message><source>Drag photo and use the wheel to select a square</source><translation>Перемещайте фото мышью и масштабируйте колесом, чтобы выбрать квадрат</translation></message>
|
||||
<message><source>Drag photo and use the wheel to fit the circle</source><translation>Перемещайте фото мышью и масштабируйте колесом, чтобы вписать его в круг</translation></message>
|
||||
<message><source>Cannot load avatar image</source><translation>Не удалось открыть изображение аватарки</translation></message>
|
||||
<message><source>Avatars</source><translation>Аватарки</translation></message>
|
||||
<message><source>Loading original…</source><translation>Загрузка оригинала…</translation></message>
|
||||
|
||||
Reference in new issue
Block a user