mirror of https://github.com/procxx/kepka.git
pasting .gif or .mp4 file send confirm box design improved
This commit is contained in:
parent
2e853f9338
commit
9a3489694e
|
@ -29,6 +29,7 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org
|
||||||
|
|
||||||
PhotoSendBox::PhotoSendBox(const FileLoadResultPtr &file) : AbstractBox(st::boxWideWidth)
|
PhotoSendBox::PhotoSendBox(const FileLoadResultPtr &file) : AbstractBox(st::boxWideWidth)
|
||||||
, _file(file)
|
, _file(file)
|
||||||
|
, _animated(false)
|
||||||
, _caption(this, st::confirmCaptionArea, lang(lng_photo_caption))
|
, _caption(this, st::confirmCaptionArea, lang(lng_photo_caption))
|
||||||
, _compressedFromSettings(_file->type == PrepareAuto)
|
, _compressedFromSettings(_file->type == PrepareAuto)
|
||||||
, _compressed(this, lang(lng_send_image_compressed), _compressedFromSettings ? cCompressPastedImage() : true)
|
, _compressed(this, lang(lng_send_image_compressed), _compressedFromSettings ? cCompressPastedImage() : true)
|
||||||
|
@ -44,16 +45,51 @@ PhotoSendBox::PhotoSendBox(const FileLoadResultPtr &file) : AbstractBox(st::boxW
|
||||||
, _confirmed(false) {
|
, _confirmed(false) {
|
||||||
connect(&_send, SIGNAL(clicked()), this, SLOT(onSend()));
|
connect(&_send, SIGNAL(clicked()), this, SLOT(onSend()));
|
||||||
connect(&_cancel, SIGNAL(clicked()), this, SLOT(onClose()));
|
connect(&_cancel, SIGNAL(clicked()), this, SLOT(onClose()));
|
||||||
|
|
||||||
|
_animated = false;
|
||||||
|
QSize dimensions;
|
||||||
if (_file->photo.type() != mtpc_photoEmpty) {
|
if (_file->photo.type() != mtpc_photoEmpty) {
|
||||||
_file->type = PreparePhoto;
|
_file->type = PreparePhoto;
|
||||||
|
} else if (_file->document.type() == mtpc_document) {
|
||||||
|
const MTPDdocument &document(_file->document.c_document());
|
||||||
|
const QVector<MTPDocumentAttribute> &attributes(document.vattributes.c_vector().v);
|
||||||
|
for (int32 i = 0, l = attributes.size(); i < l; ++i) {
|
||||||
|
if (attributes.at(i).type() == mtpc_documentAttributeAnimated) {
|
||||||
|
_animated = true;
|
||||||
|
} else if (attributes.at(i).type() == mtpc_documentAttributeImageSize) {
|
||||||
|
dimensions = QSize(attributes.at(i).c_documentAttributeImageSize().vw.v, attributes.at(i).c_documentAttributeImageSize().vh.v);
|
||||||
|
} else if (attributes.at(i).type() == mtpc_documentAttributeVideo) {
|
||||||
|
dimensions = QSize(attributes.at(i).c_documentAttributeVideo().vw.v, attributes.at(i).c_documentAttributeVideo().vh.v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (dimensions.isEmpty()) _animated = false;
|
||||||
}
|
}
|
||||||
if (_file->type == PreparePhoto) {
|
if (_file->type == PreparePhoto || _animated) {
|
||||||
int32 maxW = 0, maxH = 0;
|
int32 maxW = 0, maxH = 0;
|
||||||
for (PreparedPhotoThumbs::const_iterator i = _file->photoThumbs.cbegin(), e = _file->photoThumbs.cend(); i != e; ++i) {
|
if (_animated) {
|
||||||
if (i->width() >= maxW && i->height() >= maxH) {
|
int32 limitW = width() - st::boxPhotoPadding.left() - st::boxPhotoPadding.right();
|
||||||
_thumb = *i;
|
int32 limitH = st::confirmMaxHeight;
|
||||||
maxW = _thumb.width();
|
maxW = dimensions.width();
|
||||||
maxH = _thumb.height();
|
maxH = dimensions.height();
|
||||||
|
if (maxW * limitH > maxH * limitW) {
|
||||||
|
if (maxW < limitW) {
|
||||||
|
maxH = maxH * limitW / maxW;
|
||||||
|
maxW = limitW;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (maxH < limitH) {
|
||||||
|
maxW = maxW * limitH / maxH;
|
||||||
|
maxH = limitH;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_thumb = imagePix(_file->thumb.toImage(), maxW * cIntRetinaFactor(), maxH * cIntRetinaFactor(), true, true, false, maxW, maxH);
|
||||||
|
} else {
|
||||||
|
for (PreparedPhotoThumbs::const_iterator i = _file->photoThumbs.cbegin(), e = _file->photoThumbs.cend(); i != e; ++i) {
|
||||||
|
if (i->width() >= maxW && i->height() >= maxH) {
|
||||||
|
_thumb = *i;
|
||||||
|
maxW = _thumb.width();
|
||||||
|
maxH = _thumb.height();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int32 tw = _thumb.width(), th = _thumb.height();
|
int32 tw = _thumb.width(), th = _thumb.height();
|
||||||
|
@ -78,7 +114,6 @@ PhotoSendBox::PhotoSendBox(const FileLoadResultPtr &file) : AbstractBox(st::boxW
|
||||||
_thumb = QPixmap::fromImage(_thumb.toImage().scaled(_thumbw * cIntRetinaFactor(), _thumbh * cIntRetinaFactor(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation), Qt::ColorOnly);
|
_thumb = QPixmap::fromImage(_thumb.toImage().scaled(_thumbw * cIntRetinaFactor(), _thumbh * cIntRetinaFactor(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation), Qt::ColorOnly);
|
||||||
_thumb.setDevicePixelRatio(cRetinaFactor());
|
_thumb.setDevicePixelRatio(cRetinaFactor());
|
||||||
} else {
|
} else {
|
||||||
_compressed.hide();
|
|
||||||
if (_file->thumb.isNull()) {
|
if (_file->thumb.isNull()) {
|
||||||
_thumbw = 0;
|
_thumbw = 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -89,7 +124,7 @@ PhotoSendBox::PhotoSendBox(const FileLoadResultPtr &file) : AbstractBox(st::boxW
|
||||||
} else {
|
} else {
|
||||||
_thumbw = st::msgFileThumbSize;
|
_thumbw = st::msgFileThumbSize;
|
||||||
}
|
}
|
||||||
_thumb = imagePix(_thumb.toImage(), _thumbw, 0, true, false, true, st::msgFileThumbSize, st::msgFileThumbSize);
|
_thumb = imagePix(_thumb.toImage(), _thumbw * cIntRetinaFactor(), 0, true, false, true, st::msgFileThumbSize, st::msgFileThumbSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
_name.setText(st::semiboldFont, _file->filename, _textNameOptions);
|
_name.setText(st::semiboldFont, _file->filename, _textNameOptions);
|
||||||
|
@ -97,6 +132,10 @@ PhotoSendBox::PhotoSendBox(const FileLoadResultPtr &file) : AbstractBox(st::boxW
|
||||||
_statusw = qMax(_name.maxWidth(), st::normalFont->width(_status));
|
_statusw = qMax(_name.maxWidth(), st::normalFont->width(_status));
|
||||||
_isImage = fileIsImage(_file->filename, _file->filemime);
|
_isImage = fileIsImage(_file->filename, _file->filemime);
|
||||||
}
|
}
|
||||||
|
if (_file->type != PreparePhoto) {
|
||||||
|
_compressed.hide();
|
||||||
|
}
|
||||||
|
|
||||||
updateBoxSize();
|
updateBoxSize();
|
||||||
_caption.setMaxLength(MaxPhotoCaption);
|
_caption.setMaxLength(MaxPhotoCaption);
|
||||||
_caption.setCtrlEnterSubmit(CtrlEnterSubmitBoth);
|
_caption.setCtrlEnterSubmit(CtrlEnterSubmitBoth);
|
||||||
|
@ -104,6 +143,7 @@ PhotoSendBox::PhotoSendBox(const FileLoadResultPtr &file) : AbstractBox(st::boxW
|
||||||
connect(&_caption, SIGNAL(resized()), this, SLOT(onCaptionResized()));
|
connect(&_caption, SIGNAL(resized()), this, SLOT(onCaptionResized()));
|
||||||
connect(&_caption, SIGNAL(submitted(bool)), this, SLOT(onSend(bool)));
|
connect(&_caption, SIGNAL(submitted(bool)), this, SLOT(onSend(bool)));
|
||||||
connect(&_caption, SIGNAL(cancelled()), this, SLOT(onClose()));
|
connect(&_caption, SIGNAL(cancelled()), this, SLOT(onClose()));
|
||||||
|
|
||||||
prepare();
|
prepare();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,8 +195,8 @@ void PhotoSendBox::onCaptionResized() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhotoSendBox::updateBoxSize() {
|
void PhotoSendBox::updateBoxSize() {
|
||||||
if (_file && _file->type == PreparePhoto) {
|
if (_file && (_file->type == PreparePhoto || _animated)) {
|
||||||
setMaxHeight(st::boxPhotoPadding.top() + _thumbh + st::boxPhotoPadding.bottom() + st::boxPhotoCompressedPadding.top() + _compressed.height() + st::boxPhotoCompressedPadding.bottom() + _caption.height() + st::boxButtonPadding.top() + _send.height() + st::boxButtonPadding.bottom());
|
setMaxHeight(st::boxPhotoPadding.top() + _thumbh + st::boxPhotoPadding.bottom() + (_animated ? 0 : (st::boxPhotoCompressedPadding.top() + _compressed.height())) + st::boxPhotoCompressedPadding.bottom() + _caption.height() + st::boxButtonPadding.top() + _send.height() + st::boxButtonPadding.bottom());
|
||||||
} else if (_thumbw) {
|
} else if (_thumbw) {
|
||||||
setMaxHeight(st::boxPhotoPadding.top() + st::msgFileThumbPadding.top() + st::msgFileThumbSize + st::msgFileThumbPadding.bottom() + (_file ? (st::boxPhotoCompressedPadding.bottom() + _caption.height()) : 0) + st::boxPhotoPadding.bottom() + st::boxButtonPadding.top() + _send.height() + st::boxButtonPadding.bottom());
|
setMaxHeight(st::boxPhotoPadding.top() + st::msgFileThumbPadding.top() + st::msgFileThumbSize + st::msgFileThumbPadding.bottom() + (_file ? (st::boxPhotoCompressedPadding.bottom() + _caption.height()) : 0) + st::boxPhotoPadding.bottom() + st::boxButtonPadding.top() + _send.height() + st::boxButtonPadding.bottom());
|
||||||
} else {
|
} else {
|
||||||
|
@ -176,7 +216,7 @@ void PhotoSendBox::paintEvent(QPaintEvent *e) {
|
||||||
Painter p(this);
|
Painter p(this);
|
||||||
if (paint(p)) return;
|
if (paint(p)) return;
|
||||||
|
|
||||||
if (_file && _file->type == PreparePhoto) {
|
if (_file && (_file->type == PreparePhoto || _animated)) {
|
||||||
if (_thumbx > st::boxPhotoPadding.left()) {
|
if (_thumbx > st::boxPhotoPadding.left()) {
|
||||||
p.fillRect(st::boxPhotoPadding.left(), st::boxPhotoPadding.top(), _thumbx - st::boxPhotoPadding.left(), _thumbh, st::confirmBg->b);
|
p.fillRect(st::boxPhotoPadding.left(), st::boxPhotoPadding.top(), _thumbx - st::boxPhotoPadding.left(), _thumbh, st::confirmBg->b);
|
||||||
}
|
}
|
||||||
|
@ -184,6 +224,17 @@ void PhotoSendBox::paintEvent(QPaintEvent *e) {
|
||||||
p.fillRect(_thumbx + _thumbw, st::boxPhotoPadding.top(), width() - st::boxPhotoPadding.right() - _thumbx - _thumbw, _thumbh, st::confirmBg->b);
|
p.fillRect(_thumbx + _thumbw, st::boxPhotoPadding.top(), width() - st::boxPhotoPadding.right() - _thumbx - _thumbw, _thumbh, st::confirmBg->b);
|
||||||
}
|
}
|
||||||
p.drawPixmap(_thumbx, st::boxPhotoPadding.top(), _thumb);
|
p.drawPixmap(_thumbx, st::boxPhotoPadding.top(), _thumb);
|
||||||
|
if (_animated) {
|
||||||
|
QRect inner(_thumbx + (_thumbw - st::msgFileSize) / 2, st::boxPhotoPadding.top() + (_thumbh - st::msgFileSize) / 2, st::msgFileSize, st::msgFileSize);
|
||||||
|
p.setPen(Qt::NoPen);
|
||||||
|
p.setBrush(st::msgDateImgBg);
|
||||||
|
|
||||||
|
p.setRenderHint(QPainter::HighQualityAntialiasing);
|
||||||
|
p.drawEllipse(inner);
|
||||||
|
p.setRenderHint(QPainter::HighQualityAntialiasing, false);
|
||||||
|
|
||||||
|
p.drawSpriteCenter(inner, st::msgFileInPlay);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
int32 w = width() - st::boxPhotoPadding.left() - st::boxPhotoPadding.right();
|
int32 w = width() - st::boxPhotoPadding.left() - st::boxPhotoPadding.right();
|
||||||
int32 h = _thumbw ? (st::msgFileThumbPadding.top() + st::msgFileThumbSize + st::msgFileThumbPadding.bottom()) : (st::msgFilePadding.top() + st::msgFileSize + st::msgFilePadding.bottom());
|
int32 h = _thumbw ? (st::msgFileThumbPadding.top() + st::msgFileThumbSize + st::msgFileThumbPadding.bottom()) : (st::msgFilePadding.top() + st::msgFileSize + st::msgFilePadding.bottom());
|
||||||
|
|
|
@ -65,6 +65,7 @@ private:
|
||||||
void updateBoxSize();
|
void updateBoxSize();
|
||||||
|
|
||||||
FileLoadResultPtr _file;
|
FileLoadResultPtr _file;
|
||||||
|
bool _animated;
|
||||||
|
|
||||||
QPixmap _thumb;
|
QPixmap _thumb;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue