2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-30 22:25:12 +00:00

new image / file confirm / send codepath made by Task / TaskQueue, sending single file paste and image paste / drop with that new code

This commit is contained in:
John Preston
2015-10-26 22:39:02 -04:00
parent c606d6b459
commit 31b1ecb11c
18 changed files with 778 additions and 135 deletions

View File

@@ -27,6 +27,92 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org
#include "mainwidget.h"
#include "photosendbox.h"
PhotoSendBox::PhotoSendBox(const FileLoadResultPtr &file) : AbstractBox(st::boxWideWidth)
, _file(file)
, _img(0)
, _thumbx(0)
, _thumby(0)
, _thumbw(0)
, _thumbh(0)
, _namew(0)
, _textw(0)
, _caption(this, st::confirmCaptionArea, lang(lng_photo_caption))
, _compressed(this, lang(lng_send_image_compressed), cCompressPastedImage())
, _send(this, lang(lng_send_button), st::defaultBoxButton)
, _cancel(this, lang(lng_cancel), st::cancelBoxButton)
, _replyTo(_file->to.replyTo) {
connect(&_send, SIGNAL(clicked()), this, SLOT(onSend()));
connect(&_cancel, SIGNAL(clicked()), this, SLOT(onClose()));
if (_file->photo.type() != mtpc_photoEmpty) {
_file->type = PreparePhoto;
}
if (_file->type == PreparePhoto) {
int32 maxW = 0, maxH = 0;
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();
if (!tw || !th) {
tw = th = 1;
}
_thumbw = width() - st::boxPhotoPadding.left() - st::boxPhotoPadding.right();
if (_thumb.width() < _thumbw) {
_thumbw = (_thumb.width() > 20) ? _thumb.width() : 20;
}
int32 maxthumbh = qMin(qRound(1.5 * _thumbw), int(st::confirmMaxHeight));
_thumbh = qRound(th * float64(_thumbw) / tw);
if (_thumbh > maxthumbh) {
_thumbw = qRound(_thumbw * float64(maxthumbh) / _thumbh);
_thumbh = maxthumbh;
if (_thumbw < 10) {
_thumbw = 10;
}
}
_thumbx = (width() - _thumbw) / 2;
_thumb = QPixmap::fromImage(_thumb.toImage().scaled(_thumbw * cIntRetinaFactor(), _thumbh * cIntRetinaFactor(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation), Qt::ColorOnly);
_thumb.setDevicePixelRatio(cRetinaFactor());
} else {
_compressed.hide();
if (!_file->thumb.isNull()) {
_thumb = _file->thumb;
int32 tw = _thumb.width(), th = _thumb.height();
if (_thumb.isNull() || !tw || !th) {
_thumbw = _thumbx = _thumby = 0;
} else if (tw > th) {
_thumbw = (tw * st::mediaThumbSize) / th;
_thumbx = (_thumbw - st::mediaThumbSize) / 2;
_thumby = 0;
} else {
_thumbw = st::mediaThumbSize;
_thumbx = 0;
_thumby = ((th * _thumbw) / tw - st::mediaThumbSize) / 2;
}
}
if (_thumbw) {
_thumb = QPixmap::fromImage(_thumb.toImage().scaledToWidth(_thumbw * cIntRetinaFactor(), Qt::SmoothTransformation), Qt::ColorOnly);
_thumb.setDevicePixelRatio(cRetinaFactor());
}
_name = _file->filename;
_namew = st::mediaFont->width(_name);
_size = formatSizeText(_file->filesize);
_textw = qMax(_namew, st::mediaFont->width(_size));
}
updateBoxSize();
_caption.setMaxLength(MaxPhotoCaption);
_caption.setCtrlEnterSubmit(CtrlEnterSubmitBoth);
connect(&_compressed, SIGNAL(changed()), this, SLOT(onCompressedChange()));
connect(&_caption, SIGNAL(resized()), this, SLOT(onCaptionResized()));
connect(&_caption, SIGNAL(submitted(bool)), this, SLOT(onSend(bool)));
connect(&_caption, SIGNAL(cancelled()), this, SLOT(onClose()));
prepare();
}
PhotoSendBox::PhotoSendBox(const ReadyLocalMedia &img) : AbstractBox(st::boxWideWidth)
, _img(new ReadyLocalMedia(img))
, _thumbx(0)
@@ -43,7 +129,7 @@ PhotoSendBox::PhotoSendBox(const ReadyLocalMedia &img) : AbstractBox(st::boxWide
connect(&_send, SIGNAL(clicked()), this, SLOT(onSend()));
connect(&_cancel, SIGNAL(clicked()), this, SLOT(onClose()));
if (_img->type == ToPreparePhoto) {
if (_img->type == PreparePhoto) {
int32 maxW = 0, maxH = 0;
for (PreparedPhotoThumbs::const_iterator i = _img->photoThumbs.cbegin(), e = _img->photoThumbs.cend(); i != e; ++i) {
if (i->width() >= maxW && i->height() >= maxH) {
@@ -156,7 +242,7 @@ void PhotoSendBox::onCaptionResized() {
}
void PhotoSendBox::updateBoxSize() {
if (_img && _img->type == ToPreparePhoto) {
if ((_file && _file->type == PreparePhoto) || (_img && _img->type == PreparePhoto)) {
setMaxHeight(st::boxPhotoPadding.top() + _thumbh + st::boxPhotoPadding.bottom() + st::boxPhotoCompressedPadding.top() + _compressed.height() + (_compressed.checked() ? (st::boxPhotoCompressedPadding.bottom() + _caption.height()) : 0) + st::boxButtonPadding.top() + _send.height() + st::boxButtonPadding.bottom());
} else {
setMaxHeight(st::boxPhotoPadding.top() + st::mediaPadding.top() + st::mediaThumbSize + st::mediaPadding.bottom() + st::boxPhotoPadding.bottom() + st::boxButtonPadding.top() + _send.height() + st::boxButtonPadding.bottom());
@@ -175,7 +261,7 @@ void PhotoSendBox::paintEvent(QPaintEvent *e) {
Painter p(this);
if (paint(p)) return;
if (_img && _img->type == ToPreparePhoto) {
if ((_file && _file->type == PreparePhoto) || (_img && _img->type == PreparePhoto)) {
if (_thumbx > st::boxPhotoPadding.left()) {
p.fillRect(st::boxPhotoPadding.left(), st::boxPhotoPadding.top(), _thumbx - st::boxPhotoPadding.left(), _thumbh, st::confirmBg->b);
}
@@ -197,7 +283,7 @@ void PhotoSendBox::paintEvent(QPaintEvent *e) {
if (_thumbw) {
int32 rf(cIntRetinaFactor());
p.drawPixmap(QPoint(x + st::mediaPadding.left(), y + st::mediaPadding.top()), _thumb, QRect(_thumbx * rf, _thumby * rf, st::mediaThumbSize * rf, st::mediaThumbSize * rf));
} else if (_img) {
} else if (_file || _img) {
p.drawPixmap(QPoint(x + st::mediaPadding.left(), y + st::mediaPadding.top()), App::sprite(), st::mediaDocOutImg);
} else {
p.drawPixmap(x + st::mediaPadding.left(), y + st::mediaPadding.top(), userDefPhoto(1)->pix(st::mediaThumbSize));
@@ -225,7 +311,13 @@ void PhotoSendBox::resizeEvent(QResizeEvent *e) {
}
void PhotoSendBox::closePressed() {
if (App::main()) App::main()->cancelSendImage();
if (App::main()) {
if (_file) {
App::main()->onSendFileCancel(_file);
} else {
App::main()->cancelSendImage();
}
}
}
void PhotoSendBox::hideAll() {
@@ -238,7 +330,7 @@ void PhotoSendBox::hideAll() {
void PhotoSendBox::showAll() {
_send.show();
_cancel.show();
if (_img && _img->type == ToPreparePhoto) {
if ((_file && _file->type == PreparePhoto) || (_img && _img->type == PreparePhoto)) {
_compressed.show();
if (_compressed.checked()) {
_caption.show();
@@ -256,6 +348,30 @@ void PhotoSendBox::showDone() {
}
void PhotoSendBox::onSend(bool ctrlShiftEnter) {
if (_file) {
if (_compressed.isHidden()) {
if (_file->type == PrepareAuto) {
_file->type = PrepareDocument;
}
} else {
if (_compressed.checked() != cCompressPastedImage()) {
cSetCompressPastedImage(_compressed.checked());
Local::writeUserSettings();
}
if (_compressed.checked()) {
_file->type = PreparePhoto;
} else {
_file->type = PrepareDocument;
}
}
if (!_caption.isHidden()) {
_file->photoCaption = prepareText(_caption.getLastText(), true);
}
if (App::main()) App::main()->onSendFileConfirm(_file, ctrlShiftEnter);
onClose();
return;
}
if (!_img) {
if (App::main()) App::main()->confirmShareContact(ctrlShiftEnter, _phone, _fname, _lname, _replyTo);
} else {