Browse Source

Show a circular crop preview in the desktop avatar editor

master
evgeny 6 days ago
parent
commit
1f026baf45
  1. 9
      tools/chatgui/src/avatars/avatarcrop.cpp
  2. 2
      tools/chatgui/src/avatars/avatarcrop.h
  3. 2
      tools/chatgui/translations/chatgui_ru.ts

9
tools/chatgui/src/avatars/avatarcrop.cpp

@ -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();

2
tools/chatgui/src/avatars/avatarcrop.h

@ -1,4 +1,4 @@
/* Модальный выбор квадрата: рамка неподвижна, фото перемещается и масштабируется. */ /* Выбор области аватара: круглая рамка неподвижна, фото перемещается и масштабируется. */
#pragma once #pragma once
#include <QRectF> #include <QRectF>
#include <QString> #include <QString>

2
tools/chatgui/translations/chatgui_ru.ts

@ -2100,7 +2100,7 @@ Directories: %5</source>
<message><source>No avatar</source><translation>Нет аватарки</translation></message> <message><source>No avatar</source><translation>Нет аватарки</translation></message>
<message><source>Choose avatar</source><translation>Выбор аватарки</translation></message> <message><source>Choose avatar</source><translation>Выбор аватарки</translation></message>
<message><source>Crop 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>Cannot load avatar image</source><translation>Не удалось открыть изображение аватарки</translation></message>
<message><source>Avatars</source><translation>Аватарки</translation></message> <message><source>Avatars</source><translation>Аватарки</translation></message>
<message><source>Loading original…</source><translation>Загрузка оригинала…</translation></message> <message><source>Loading original…</source><translation>Загрузка оригинала…</translation></message>

Loading…
Cancel
Save