2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2014-12-01 10:47:38 +00:00
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2015-10-03 13:16:42 +00:00
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
2016-11-28 15:45:07 +00:00
|
|
|
#include "boxes/send_files_box.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-04-21 17:57:29 +00:00
|
|
|
#include "lang.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
#include "mainwidget.h"
|
2016-09-28 10:15:03 +00:00
|
|
|
#include "history/history_media_types.h"
|
2017-02-28 14:05:30 +00:00
|
|
|
#include "core/file_utilities.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/checkbox.h"
|
|
|
|
#include "ui/widgets/buttons.h"
|
2016-11-15 11:56:49 +00:00
|
|
|
#include "ui/widgets/input_fields.h"
|
2016-09-30 12:52:03 +00:00
|
|
|
#include "styles/style_history.h"
|
2016-11-15 11:56:49 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2017-03-10 14:14:10 +00:00
|
|
|
#include "media/media_clip_reader.h"
|
2017-04-07 18:10:49 +00:00
|
|
|
#include "window/window_controller.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-28 15:45:07 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr auto kMinPreviewWidth = 20;
|
|
|
|
|
2017-03-10 14:14:10 +00:00
|
|
|
bool ValidatePhotoDimensions(int width, int height) {
|
|
|
|
return (width > 0) && (height > 0) && (width < 20 * height) && (height < 20 * width);
|
|
|
|
}
|
|
|
|
|
2016-11-28 15:45:07 +00:00
|
|
|
} // namespace
|
|
|
|
|
2017-03-10 14:14:10 +00:00
|
|
|
SendFilesBox::SendFilesBox(QWidget*, QImage image, CompressConfirm compressed)
|
|
|
|
: _image(image)
|
2016-11-28 15:45:07 +00:00
|
|
|
, _compressConfirm(compressed)
|
2016-12-13 17:07:56 +00:00
|
|
|
, _caption(this, st::confirmCaptionArea, lang(lng_photo_caption)) {
|
2017-03-10 14:14:10 +00:00
|
|
|
_files.push_back(QString());
|
|
|
|
prepareSingleFileLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
SendFilesBox::SendFilesBox(QWidget*, const QStringList &files, CompressConfirm compressed)
|
|
|
|
: _files(files)
|
|
|
|
, _compressConfirm(compressed)
|
|
|
|
, _caption(this, st::confirmCaptionArea, lang(_files.size() > 1 ? lng_photos_comment : lng_photo_caption)) {
|
|
|
|
if (_files.size() == 1) {
|
|
|
|
prepareSingleFileLayout();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendFilesBox::prepareSingleFileLayout() {
|
2017-04-07 18:10:49 +00:00
|
|
|
Expects(_files.size() == 1);
|
2017-03-10 14:14:10 +00:00
|
|
|
if (!_files.front().isEmpty()) {
|
|
|
|
tryToReadSingleFile();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_image.isNull() || !ValidatePhotoDimensions(_image.width(), _image.height()) || _animated) {
|
|
|
|
_compressConfirm = CompressConfirm::None;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_image.isNull()) {
|
|
|
|
auto image = _image;
|
2016-11-28 15:45:07 +00:00
|
|
|
if (!_animated && _compressConfirm == CompressConfirm::None) {
|
|
|
|
auto originalWidth = image.width();
|
|
|
|
auto originalHeight = image.height();
|
|
|
|
auto thumbWidth = st::msgFileThumbSize;
|
|
|
|
if (originalWidth > originalHeight) {
|
|
|
|
thumbWidth = (originalWidth * st::msgFileThumbSize) / originalHeight;
|
2015-12-28 15:58:38 +00:00
|
|
|
}
|
2016-11-28 15:45:07 +00:00
|
|
|
auto options = Images::Option::Smooth | Images::Option::RoundedSmall | Images::Option::RoundedTopLeft | Images::Option::RoundedTopRight | Images::Option::RoundedBottomLeft | Images::Option::RoundedBottomRight;
|
|
|
|
_fileThumb = Images::pixmap(image, thumbWidth * cIntRetinaFactor(), 0, options, st::msgFileThumbSize, st::msgFileThumbSize);
|
2015-12-28 15:58:38 +00:00
|
|
|
} else {
|
2016-11-28 15:45:07 +00:00
|
|
|
auto maxW = 0;
|
|
|
|
auto maxH = 0;
|
|
|
|
if (_animated) {
|
2016-12-13 17:07:56 +00:00
|
|
|
auto limitW = st::boxWideWidth - st::boxPhotoPadding.left() - st::boxPhotoPadding.right();
|
2016-11-28 15:45:07 +00:00
|
|
|
auto limitH = st::confirmMaxHeight;
|
|
|
|
maxW = qMax(image.width(), 1);
|
|
|
|
maxH = qMax(image.height(), 1);
|
|
|
|
if (maxW * limitH > maxH * limitW) {
|
|
|
|
if (maxW < limitW) {
|
|
|
|
maxH = maxH * limitW / maxW;
|
|
|
|
maxW = limitW;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (maxH < limitH) {
|
|
|
|
maxW = maxW * limitH / maxH;
|
|
|
|
maxH = limitH;
|
|
|
|
}
|
2015-12-28 15:58:38 +00:00
|
|
|
}
|
2016-11-28 15:45:07 +00:00
|
|
|
image = Images::prepare(image, maxW * cIntRetinaFactor(), maxH * cIntRetinaFactor(), Images::Option::Smooth | Images::Option::Blurred, maxW, maxH);
|
2015-10-27 02:39:02 +00:00
|
|
|
}
|
2016-11-28 15:45:07 +00:00
|
|
|
auto originalWidth = image.width();
|
|
|
|
auto originalHeight = image.height();
|
|
|
|
if (!originalWidth || !originalHeight) {
|
|
|
|
originalWidth = originalHeight = 1;
|
2015-10-27 02:39:02 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
_previewWidth = st::boxWideWidth - st::boxPhotoPadding.left() - st::boxPhotoPadding.right();
|
2016-11-28 15:45:07 +00:00
|
|
|
if (image.width() < _previewWidth) {
|
|
|
|
_previewWidth = qMax(image.width(), kMinPreviewWidth);
|
2015-10-27 02:39:02 +00:00
|
|
|
}
|
2016-11-28 15:45:07 +00:00
|
|
|
auto maxthumbh = qMin(qRound(1.5 * _previewWidth), st::confirmMaxHeight);
|
|
|
|
_previewHeight = qRound(originalHeight * float64(_previewWidth) / originalWidth);
|
|
|
|
if (_previewHeight > maxthumbh) {
|
|
|
|
_previewWidth = qRound(_previewWidth * float64(maxthumbh) / _previewHeight);
|
|
|
|
accumulate_max(_previewWidth, kMinPreviewWidth);
|
|
|
|
_previewHeight = maxthumbh;
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
_previewLeft = (st::boxWideWidth - _previewWidth) / 2;
|
2015-10-27 02:39:02 +00:00
|
|
|
|
2017-02-21 13:45:56 +00:00
|
|
|
image = std::move(image).scaled(_previewWidth * cIntRetinaFactor(), _previewHeight * cIntRetinaFactor(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
|
|
|
image = Images::prepareOpaque(std::move(image));
|
|
|
|
_preview = App::pixmapFromImageInPlace(std::move(image));
|
2016-11-28 15:45:07 +00:00
|
|
|
_preview.setDevicePixelRatio(cRetinaFactor());
|
2017-03-10 14:43:26 +00:00
|
|
|
|
|
|
|
prepareGifPreview();
|
2016-11-28 15:45:07 +00:00
|
|
|
}
|
2015-10-27 02:39:02 +00:00
|
|
|
}
|
2016-11-28 15:45:07 +00:00
|
|
|
if (_preview.isNull()) {
|
2017-03-10 14:14:10 +00:00
|
|
|
prepareDocumentLayout();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-10 14:43:26 +00:00
|
|
|
void SendFilesBox::prepareGifPreview() {
|
|
|
|
auto createGifPreview = [this] {
|
|
|
|
if (!_information) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (auto video = base::get_if<FileLoadTask::Video>(&_information->media)) {
|
|
|
|
return video->isGifv;
|
|
|
|
}
|
|
|
|
// Plain old .gif animation.
|
|
|
|
return _animated;
|
|
|
|
};
|
|
|
|
if (createGifPreview()) {
|
|
|
|
_gifPreview = Media::Clip::MakeReader(FileLocation(_files.front()), QByteArray(), [this](Media::Clip::Notification notification) {
|
|
|
|
clipCallback(notification);
|
|
|
|
});
|
|
|
|
if (_gifPreview) _gifPreview->setAutoplay();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendFilesBox::clipCallback(Media::Clip::Notification notification) {
|
|
|
|
using namespace Media::Clip;
|
|
|
|
switch (notification) {
|
|
|
|
case NotificationReinit: {
|
|
|
|
if (_gifPreview && _gifPreview->state() == State::Error) {
|
|
|
|
_gifPreview.setBad();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_gifPreview && _gifPreview->ready() && !_gifPreview->started()) {
|
|
|
|
auto s = QSize(_previewWidth, _previewHeight);
|
|
|
|
_gifPreview->start(s.width(), s.height(), s.width(), s.height(), ImageRoundRadius::None, ImageRoundCorner::None);
|
|
|
|
}
|
|
|
|
|
|
|
|
update();
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case NotificationRepaint: {
|
|
|
|
if (_gifPreview && !_gifPreview->currentDisplayed()) {
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-10 14:14:10 +00:00
|
|
|
void SendFilesBox::prepareDocumentLayout() {
|
|
|
|
auto filepath = _files.front();
|
|
|
|
if (filepath.isEmpty()) {
|
|
|
|
auto filename = filedialogDefaultName(qsl("image"), qsl(".png"), QString(), true);
|
|
|
|
_nameText.setText(st::semiboldTextStyle, filename, _textNameOptions);
|
|
|
|
_statusText = qsl("%1x%2").arg(_image.width()).arg(_image.height());
|
|
|
|
_statusWidth = qMax(_nameText.maxWidth(), st::normalFont->width(_statusText));
|
|
|
|
_fileIsImage = true;
|
|
|
|
} else {
|
|
|
|
auto fileinfo = QFileInfo(filepath);
|
|
|
|
auto filename = fileinfo.fileName();
|
|
|
|
_fileIsImage = fileIsImage(filename, mimeTypeForFile(fileinfo).name());
|
|
|
|
|
|
|
|
auto songTitle = QString();
|
|
|
|
auto songPerformer = QString();
|
|
|
|
if (_information) {
|
|
|
|
if (auto song = base::get_if<FileLoadTask::Song>(&_information->media)) {
|
|
|
|
songTitle = song->title;
|
|
|
|
songPerformer = song->performer;
|
|
|
|
_fileIsAudio = true;
|
|
|
|
}
|
2016-11-28 15:45:07 +00:00
|
|
|
}
|
2017-03-10 14:14:10 +00:00
|
|
|
|
|
|
|
auto nameString = DocumentData::composeNameString(filename, songTitle, songPerformer);
|
|
|
|
_nameText.setText(st::semiboldTextStyle, nameString, _textNameOptions);
|
|
|
|
_statusText = formatSizeText(fileinfo.size());
|
|
|
|
_statusWidth = qMax(_nameText.maxWidth(), st::normalFont->width(_statusText));
|
2015-12-28 15:58:38 +00:00
|
|
|
}
|
2015-10-27 02:39:02 +00:00
|
|
|
}
|
|
|
|
|
2017-03-10 14:14:10 +00:00
|
|
|
void SendFilesBox::tryToReadSingleFile() {
|
|
|
|
auto filepath = _files.front();
|
|
|
|
auto filemime = mimeTypeForFile(QFileInfo(filepath)).name();
|
|
|
|
_information = FileLoadTask::ReadMediaInformation(_files.front(), QByteArray(), filemime);
|
|
|
|
if (auto image = base::get_if<FileLoadTask::Image>(&_information->media)) {
|
|
|
|
_image = image->data;
|
|
|
|
_animated = image->animated;
|
|
|
|
} else if (auto video = base::get_if<FileLoadTask::Video>(&_information->media)) {
|
|
|
|
_image = video->thumbnail;
|
|
|
|
_animated = true;
|
|
|
|
}
|
2016-11-28 15:45:07 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
SendFilesBox::SendFilesBox(QWidget*, const QString &phone, const QString &firstname, const QString &lastname)
|
|
|
|
: _contactPhone(phone)
|
2016-11-28 15:45:07 +00:00
|
|
|
, _contactFirstName(firstname)
|
2016-12-13 17:07:56 +00:00
|
|
|
, _contactLastName(lastname) {
|
2016-12-29 09:03:51 +00:00
|
|
|
auto name = lng_full_name(lt_first_name, _contactFirstName, lt_last_name, _contactLastName);
|
|
|
|
_nameText.setText(st::semiboldTextStyle, name, _textNameOptions);
|
2016-11-28 15:45:07 +00:00
|
|
|
_statusText = _contactPhone;
|
|
|
|
_statusWidth = qMax(_nameText.maxWidth(), st::normalFont->width(_statusText));
|
2016-12-29 09:03:51 +00:00
|
|
|
_contactPhotoEmpty.set(0, name);
|
2016-11-28 15:45:07 +00:00
|
|
|
}
|
2014-08-22 14:55:23 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void SendFilesBox::prepare() {
|
2017-04-07 18:10:49 +00:00
|
|
|
Expects(controller() != nullptr);
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
if (_files.size() > 1) {
|
|
|
|
updateTitleText();
|
|
|
|
}
|
|
|
|
|
|
|
|
_send = addButton(lang(lng_send_button), [this] { onSend(); });
|
|
|
|
addButton(lang(lng_cancel), [this] { closeBox(); });
|
2014-08-22 14:55:23 +00:00
|
|
|
|
2016-11-28 15:45:07 +00:00
|
|
|
if (_compressConfirm != CompressConfirm::None) {
|
|
|
|
auto compressed = (_compressConfirm == CompressConfirm::Auto) ? cCompressPastedImage() : (_compressConfirm == CompressConfirm::Yes);
|
|
|
|
auto text = lng_send_images_compress(lt_count, _files.size());
|
|
|
|
_compressed.create(this, text, compressed, st::defaultBoxCheckbox);
|
|
|
|
connect(_compressed, SIGNAL(changed()), this, SLOT(onCompressedChange()));
|
|
|
|
}
|
|
|
|
if (_caption) {
|
|
|
|
_caption->setMaxLength(MaxPhotoCaption);
|
2016-12-09 18:56:01 +00:00
|
|
|
_caption->setCtrlEnterSubmit(Ui::CtrlEnterSubmit::Both);
|
2016-11-28 15:45:07 +00:00
|
|
|
connect(_caption, SIGNAL(resized()), this, SLOT(onCaptionResized()));
|
|
|
|
connect(_caption, SIGNAL(submitted(bool)), this, SLOT(onSend(bool)));
|
|
|
|
connect(_caption, SIGNAL(cancelled()), this, SLOT(onClose()));
|
|
|
|
}
|
|
|
|
_send->setText(getSendButtonText());
|
2016-12-13 17:07:56 +00:00
|
|
|
updateButtonsGeometry();
|
2015-10-11 08:37:24 +00:00
|
|
|
updateBoxSize();
|
2014-08-22 14:55:23 +00:00
|
|
|
}
|
|
|
|
|
2016-11-28 15:45:07 +00:00
|
|
|
QString SendFilesBox::getSendButtonText() const {
|
|
|
|
if (!_contactPhone.isEmpty()) {
|
|
|
|
return lang(lng_send_button);
|
|
|
|
} else if (_compressed && _compressed->checked()) {
|
|
|
|
return lng_send_photos(lt_count, _files.size());
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
2016-11-28 15:45:07 +00:00
|
|
|
return lng_send_files(lt_count, _files.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendFilesBox::onCompressedChange() {
|
2016-12-13 17:07:56 +00:00
|
|
|
setInnerFocus();
|
2016-11-28 15:45:07 +00:00
|
|
|
_send->setText(getSendButtonText());
|
2016-12-13 17:07:56 +00:00
|
|
|
updateButtonsGeometry();
|
2016-11-28 15:45:07 +00:00
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendFilesBox::onCaptionResized() {
|
2015-10-11 08:37:24 +00:00
|
|
|
updateBoxSize();
|
2016-11-28 15:45:07 +00:00
|
|
|
updateControlsGeometry();
|
2015-10-11 08:37:24 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2016-11-28 15:45:07 +00:00
|
|
|
void SendFilesBox::updateTitleText() {
|
2016-12-20 13:03:51 +00:00
|
|
|
_titleText = (_compressConfirm == CompressConfirm::None) ? lng_send_files_selected(lt_count, _files.size()) : lng_send_images_selected(lt_count, _files.size());
|
2015-10-11 08:37:24 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2016-11-28 15:45:07 +00:00
|
|
|
void SendFilesBox::updateBoxSize() {
|
2016-12-20 13:03:51 +00:00
|
|
|
auto newHeight = _titleText.isEmpty() ? 0 : st::boxTitleHeight;
|
2016-11-28 15:45:07 +00:00
|
|
|
if (!_preview.isNull()) {
|
|
|
|
newHeight += st::boxPhotoPadding.top() + _previewHeight;
|
|
|
|
} else if (!_fileThumb.isNull()) {
|
|
|
|
newHeight += st::boxPhotoPadding.top() + st::msgFileThumbPadding.top() + st::msgFileThumbSize + st::msgFileThumbPadding.bottom();
|
|
|
|
} else if (_files.size() > 1) {
|
2016-12-13 17:07:56 +00:00
|
|
|
newHeight += 0;
|
2015-10-11 08:37:24 +00:00
|
|
|
} else {
|
2016-11-28 15:45:07 +00:00
|
|
|
newHeight += st::boxPhotoPadding.top() + st::msgFilePadding.top() + st::msgFileSize + st::msgFilePadding.bottom();
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
2016-11-28 15:45:07 +00:00
|
|
|
if (_compressed) {
|
2016-12-02 19:16:35 +00:00
|
|
|
newHeight += st::boxPhotoCompressedSkip + _compressed->heightNoMargins();
|
2016-11-28 15:45:07 +00:00
|
|
|
}
|
|
|
|
if (_caption) {
|
|
|
|
newHeight += st::boxPhotoCaptionSkip + _caption->height();
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
setDimensions(st::boxWideWidth, newHeight);
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
2014-08-22 14:55:23 +00:00
|
|
|
|
2016-11-28 15:45:07 +00:00
|
|
|
void SendFilesBox::keyPressEvent(QKeyEvent *e) {
|
2014-05-30 08:53:19 +00:00
|
|
|
if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
|
2014-10-17 18:32:34 +00:00
|
|
|
onSend((e->modifiers().testFlag(Qt::ControlModifier) || e->modifiers().testFlag(Qt::MetaModifier)) && e->modifiers().testFlag(Qt::ShiftModifier));
|
2015-04-02 10:33:19 +00:00
|
|
|
} else {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::keyPressEvent(e);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 15:45:07 +00:00
|
|
|
void SendFilesBox::paintEvent(QPaintEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::paintEvent(e);
|
2016-11-19 14:47:28 +00:00
|
|
|
|
2015-09-19 09:13:21 +00:00
|
|
|
Painter p(this);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-28 15:45:07 +00:00
|
|
|
if (!_titleText.isEmpty()) {
|
|
|
|
p.setFont(st::boxPhotoTitleFont);
|
|
|
|
p.setPen(st::boxTitleFg);
|
|
|
|
p.drawTextLeft(st::boxPhotoTitlePosition.x(), st::boxPhotoTitlePosition.y(), width(), _titleText);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_preview.isNull()) {
|
|
|
|
if (_previewLeft > st::boxPhotoPadding.left()) {
|
|
|
|
p.fillRect(st::boxPhotoPadding.left(), st::boxPhotoPadding.top(), _previewLeft - st::boxPhotoPadding.left(), _previewHeight, st::confirmBg);
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
2016-11-28 15:45:07 +00:00
|
|
|
if (_previewLeft + _previewWidth < width() - st::boxPhotoPadding.right()) {
|
|
|
|
p.fillRect(_previewLeft + _previewWidth, st::boxPhotoPadding.top(), width() - st::boxPhotoPadding.right() - _previewLeft - _previewWidth, _previewHeight, st::confirmBg);
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
2017-03-10 14:43:26 +00:00
|
|
|
if (_gifPreview && _gifPreview->started()) {
|
|
|
|
auto s = QSize(_previewWidth, _previewHeight);
|
2017-04-07 18:10:49 +00:00
|
|
|
auto paused = controller()->isGifPausedAtLeastFor(Window::GifPauseReason::Layer);
|
2017-04-03 14:13:55 +00:00
|
|
|
auto frame = _gifPreview->current(s.width(), s.height(), s.width(), s.height(), ImageRoundRadius::None, ImageRoundCorner::None, paused ? 0 : getms());
|
2017-03-10 14:43:26 +00:00
|
|
|
p.drawPixmap(_previewLeft, st::boxPhotoPadding.top(), frame);
|
|
|
|
} else {
|
|
|
|
p.drawPixmap(_previewLeft, st::boxPhotoPadding.top(), _preview);
|
|
|
|
}
|
|
|
|
if (_animated && !_gifPreview) {
|
2016-11-28 15:45:07 +00:00
|
|
|
auto inner = QRect(_previewLeft + (_previewWidth - st::msgFileSize) / 2, st::boxPhotoPadding.top() + (_previewHeight - st::msgFileSize) / 2, st::msgFileSize, st::msgFileSize);
|
2015-12-28 15:58:38 +00:00
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setBrush(st::msgDateImgBg);
|
|
|
|
|
2016-12-03 12:10:35 +00:00
|
|
|
{
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.drawEllipse(inner);
|
|
|
|
}
|
2015-12-28 15:58:38 +00:00
|
|
|
|
2016-09-30 12:52:03 +00:00
|
|
|
auto icon = &st::historyFileInPlay;
|
2016-09-29 19:42:14 +00:00
|
|
|
icon->paintInCenter(p, inner);
|
2015-12-28 15:58:38 +00:00
|
|
|
}
|
2016-11-28 15:45:07 +00:00
|
|
|
} else if (_files.size() < 2) {
|
|
|
|
auto w = width() - st::boxPhotoPadding.left() - st::boxPhotoPadding.right();
|
|
|
|
auto h = _fileThumb.isNull() ? (st::msgFilePadding.top() + st::msgFileSize + st::msgFilePadding.bottom()) : (st::msgFileThumbPadding.top() + st::msgFileThumbSize + st::msgFileThumbPadding.bottom());
|
|
|
|
auto nameleft = 0, nametop = 0, nameright = 0, statustop = 0, linktop = 0;
|
|
|
|
if (_fileThumb.isNull()) {
|
|
|
|
nameleft = st::msgFilePadding.left() + st::msgFileSize + st::msgFilePadding.right();
|
|
|
|
nametop = st::msgFileNameTop;
|
|
|
|
nameright = st::msgFilePadding.left();
|
|
|
|
statustop = st::msgFileStatusTop;
|
|
|
|
} else {
|
2015-12-19 14:37:28 +00:00
|
|
|
nameleft = st::msgFileThumbPadding.left() + st::msgFileThumbSize + st::msgFileThumbPadding.right();
|
|
|
|
nametop = st::msgFileThumbNameTop;
|
|
|
|
nameright = st::msgFileThumbPadding.left();
|
|
|
|
statustop = st::msgFileThumbStatusTop;
|
|
|
|
linktop = st::msgFileThumbLinkTop;
|
2014-08-22 09:35:22 +00:00
|
|
|
}
|
2016-11-28 15:45:07 +00:00
|
|
|
auto namewidth = w - nameleft - (_fileThumb.isNull() ? st::msgFilePadding.left() : st::msgFileThumbPadding.left());
|
2015-10-11 08:37:24 +00:00
|
|
|
int32 x = (width() - w) / 2, y = st::boxPhotoPadding.top();
|
2014-08-22 09:35:22 +00:00
|
|
|
|
2015-05-20 19:28:24 +00:00
|
|
|
App::roundRect(p, x, y, w, h, st::msgOutBg, MessageOutCorners, &st::msgOutShadow);
|
2015-12-19 14:37:28 +00:00
|
|
|
|
2016-11-28 15:45:07 +00:00
|
|
|
if (_fileThumb.isNull()) {
|
|
|
|
if (_contactPhone.isNull()) {
|
|
|
|
QRect inner(rtlrect(x + st::msgFilePadding.left(), y + st::msgFilePadding.top(), st::msgFileSize, st::msgFileSize, width()));
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setBrush(st::msgFileOutBg);
|
2014-08-22 09:35:22 +00:00
|
|
|
|
2016-12-03 12:10:35 +00:00
|
|
|
{
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.drawEllipse(inner);
|
|
|
|
}
|
2015-12-19 14:37:28 +00:00
|
|
|
|
2017-03-10 14:14:10 +00:00
|
|
|
auto &icon = _fileIsAudio ? st::historyFileOutPlay : _fileIsImage ? st::historyFileOutImage : st::historyFileOutDocument;
|
2016-11-28 15:45:07 +00:00
|
|
|
icon.paintInCenter(p, inner);
|
|
|
|
} else {
|
2016-12-29 09:03:51 +00:00
|
|
|
_contactPhotoEmpty.paint(p, x + st::msgFilePadding.left(), y + st::msgFilePadding.top(), width(), st::msgFileSize);
|
2016-11-28 15:45:07 +00:00
|
|
|
}
|
2014-08-22 09:35:22 +00:00
|
|
|
} else {
|
2016-11-28 15:45:07 +00:00
|
|
|
QRect rthumb(rtlrect(x + st::msgFileThumbPadding.left(), y + st::msgFileThumbPadding.top(), st::msgFileThumbSize, st::msgFileThumbSize, width()));
|
|
|
|
p.drawPixmap(rthumb.topLeft(), _fileThumb);
|
2014-08-22 09:35:22 +00:00
|
|
|
}
|
2015-12-19 14:37:28 +00:00
|
|
|
p.setFont(st::semiboldFont);
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::historyFileNameOutFg);
|
2016-11-28 15:45:07 +00:00
|
|
|
_nameText.drawLeftElided(p, x + nameleft, y + nametop, namewidth, width());
|
2014-08-22 09:35:22 +00:00
|
|
|
|
2016-11-03 10:33:57 +00:00
|
|
|
auto &status = st::mediaOutFg;
|
2015-12-19 14:37:28 +00:00
|
|
|
p.setFont(st::normalFont);
|
|
|
|
p.setPen(status);
|
2016-11-28 15:45:07 +00:00
|
|
|
p.drawTextLeft(x + nameleft, y + statustop, width(), _statusText);
|
2014-08-22 09:35:22 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-28 15:45:07 +00:00
|
|
|
void SendFilesBox::resizeEvent(QResizeEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::resizeEvent(e);
|
2016-11-28 15:45:07 +00:00
|
|
|
updateControlsGeometry();
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-28 15:45:07 +00:00
|
|
|
void SendFilesBox::updateControlsGeometry() {
|
2016-12-13 17:07:56 +00:00
|
|
|
auto bottom = height();
|
2016-11-28 15:45:07 +00:00
|
|
|
if (_caption) {
|
|
|
|
_caption->resize(st::boxWideWidth - st::boxPhotoPadding.left() - st::boxPhotoPadding.right(), _caption->height());
|
|
|
|
_caption->moveToLeft(st::boxPhotoPadding.left(), bottom - _caption->height());
|
|
|
|
bottom -= st::boxPhotoCaptionSkip + _caption->height();
|
|
|
|
}
|
|
|
|
if (_compressed) {
|
2016-12-02 19:16:35 +00:00
|
|
|
_compressed->moveToLeft(st::boxPhotoPadding.left(), bottom - _compressed->heightNoMargins());
|
|
|
|
bottom -= st::boxPhotoCompressedSkip + _compressed->heightNoMargins();
|
2015-10-27 02:39:02 +00:00
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void SendFilesBox::setInnerFocus() {
|
2016-11-28 15:45:07 +00:00
|
|
|
if (!_caption || _caption->isHidden()) {
|
2016-08-16 16:53:10 +00:00
|
|
|
setFocus();
|
|
|
|
} else {
|
2016-12-20 13:03:51 +00:00
|
|
|
_caption->setFocusFast();
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
|
|
|
|
2016-11-28 15:45:07 +00:00
|
|
|
void SendFilesBox::onSend(bool ctrlShiftEnter) {
|
|
|
|
if (_compressed && _compressConfirm == CompressConfirm::Auto && _compressed->checked() != cCompressPastedImage()) {
|
|
|
|
cSetCompressPastedImage(_compressed->checked());
|
|
|
|
Local::writeUserSettings();
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
2015-10-28 02:41:13 +00:00
|
|
|
_confirmed = true;
|
2016-11-28 15:45:07 +00:00
|
|
|
if (_confirmedCallback) {
|
|
|
|
auto compressed = _compressed ? _compressed->checked() : false;
|
|
|
|
auto caption = _caption ? prepareText(_caption->getLastText(), true) : QString();
|
2017-03-10 14:14:10 +00:00
|
|
|
_confirmedCallback(_files, _animated ? QImage() : _image, std::move(_information), compressed, caption, ctrlShiftEnter);
|
2016-11-28 15:45:07 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
closeBox();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-02-21 12:30:16 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void SendFilesBox::closeHook() {
|
2016-11-28 15:45:07 +00:00
|
|
|
if (!_confirmed && _cancelledCallback) {
|
|
|
|
_cancelledCallback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-02 10:25:54 +00:00
|
|
|
EditCaptionBox::EditCaptionBox(QWidget*, HistoryMedia *media, FullMsgId msgId) : _msgId(msgId) {
|
|
|
|
Expects(media->canEditCaption());
|
|
|
|
|
2016-02-21 12:30:16 +00:00
|
|
|
QSize dimensions;
|
|
|
|
ImagePtr image;
|
|
|
|
QString caption;
|
2017-03-10 14:43:26 +00:00
|
|
|
DocumentData *doc = nullptr;
|
2017-04-02 10:25:54 +00:00
|
|
|
|
|
|
|
switch (media->type()) {
|
|
|
|
case MediaTypeGif: {
|
|
|
|
_animated = true;
|
|
|
|
doc = static_cast<HistoryGif*>(media)->getDocument();
|
|
|
|
dimensions = doc->dimensions;
|
|
|
|
image = doc->thumb;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case MediaTypePhoto: {
|
|
|
|
_photo = true;
|
|
|
|
auto photo = static_cast<HistoryPhoto*>(media)->photo();
|
|
|
|
dimensions = QSize(photo->full->width(), photo->full->height());
|
|
|
|
image = photo->full;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case MediaTypeVideo: {
|
|
|
|
_animated = true;
|
|
|
|
doc = static_cast<HistoryVideo*>(media)->getDocument();
|
|
|
|
dimensions = doc->dimensions;
|
|
|
|
image = doc->thumb;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case MediaTypeFile:
|
|
|
|
case MediaTypeMusicFile:
|
|
|
|
case MediaTypeVoiceFile: {
|
|
|
|
_doc = true;
|
|
|
|
doc = static_cast<HistoryDocument*>(media)->getDocument();
|
|
|
|
image = doc->thumb;
|
|
|
|
} break;
|
2016-02-21 12:30:16 +00:00
|
|
|
}
|
2017-04-02 10:25:54 +00:00
|
|
|
caption = media->getCaption().text;
|
|
|
|
|
2016-02-25 16:19:54 +00:00
|
|
|
if ((!_animated && (dimensions.isEmpty() || doc)) || image->isNull()) {
|
2016-02-21 12:30:16 +00:00
|
|
|
_animated = false;
|
|
|
|
if (image->isNull()) {
|
|
|
|
_thumbw = 0;
|
|
|
|
} else {
|
|
|
|
int32 tw = image->width(), th = image->height();
|
|
|
|
if (tw > th) {
|
|
|
|
_thumbw = (tw * st::msgFileThumbSize) / th;
|
|
|
|
} else {
|
|
|
|
_thumbw = st::msgFileThumbSize;
|
|
|
|
}
|
2016-11-28 15:45:07 +00:00
|
|
|
auto options = Images::Option::Smooth | Images::Option::RoundedSmall | Images::Option::RoundedTopLeft | Images::Option::RoundedTopRight | Images::Option::RoundedBottomLeft | Images::Option::RoundedBottomRight;
|
|
|
|
_thumb = Images::pixmap(image->pix().toImage(), _thumbw * cIntRetinaFactor(), 0, options, st::msgFileThumbSize, st::msgFileThumbSize);
|
2016-02-21 12:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (doc) {
|
|
|
|
if (doc->voice()) {
|
2016-12-23 13:21:01 +00:00
|
|
|
_name.setText(st::semiboldTextStyle, lang(lng_media_audio), _textNameOptions);
|
2016-02-21 12:30:16 +00:00
|
|
|
} else {
|
2017-03-10 14:14:10 +00:00
|
|
|
_name.setText(st::semiboldTextStyle, doc->composeNameString(), _textNameOptions);
|
2016-02-21 12:30:16 +00:00
|
|
|
}
|
|
|
|
_status = formatSizeText(doc->size);
|
|
|
|
_statusw = qMax(_name.maxWidth(), st::normalFont->width(_status));
|
|
|
|
_isImage = doc->isImage();
|
2017-03-10 14:14:10 +00:00
|
|
|
_isAudio = (doc->voice() || doc->song());
|
2016-02-21 12:30:16 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int32 maxW = 0, maxH = 0;
|
|
|
|
if (_animated) {
|
2016-12-13 17:07:56 +00:00
|
|
|
int32 limitW = st::boxWideWidth - st::boxPhotoPadding.left() - st::boxPhotoPadding.right();
|
2016-02-21 12:30:16 +00:00
|
|
|
int32 limitH = st::confirmMaxHeight;
|
2016-03-16 13:29:44 +00:00
|
|
|
maxW = qMax(dimensions.width(), 1);
|
|
|
|
maxH = qMax(dimensions.height(), 1);
|
2016-02-21 12:30:16 +00:00
|
|
|
if (maxW * limitH > maxH * limitW) {
|
|
|
|
if (maxW < limitW) {
|
|
|
|
maxH = maxH * limitW / maxW;
|
|
|
|
maxW = limitW;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (maxH < limitH) {
|
|
|
|
maxW = maxW * limitH / maxH;
|
|
|
|
maxH = limitH;
|
|
|
|
}
|
|
|
|
}
|
2016-11-28 15:45:07 +00:00
|
|
|
_thumb = image->pixNoCache(maxW * cIntRetinaFactor(), maxH * cIntRetinaFactor(), Images::Option::Smooth | Images::Option::Blurred, maxW, maxH);
|
2017-03-10 14:43:26 +00:00
|
|
|
prepareGifPreview(doc);
|
2016-02-21 12:30:16 +00:00
|
|
|
} else {
|
|
|
|
maxW = dimensions.width();
|
|
|
|
maxH = dimensions.height();
|
2016-11-28 15:45:07 +00:00
|
|
|
_thumb = image->pixNoCache(maxW * cIntRetinaFactor(), maxH * cIntRetinaFactor(), Images::Option::Smooth, maxW, maxH);
|
2016-02-21 12:30:16 +00:00
|
|
|
}
|
|
|
|
int32 tw = _thumb.width(), th = _thumb.height();
|
|
|
|
if (!tw || !th) {
|
|
|
|
tw = th = 1;
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
_thumbw = st::boxWideWidth - st::boxPhotoPadding.left() - st::boxPhotoPadding.right();
|
2016-02-21 12:30:16 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
_thumbx = (st::boxWideWidth - _thumbw) / 2;
|
2016-02-21 12:30:16 +00:00
|
|
|
|
2016-07-13 17:34:57 +00:00
|
|
|
_thumb = App::pixmapFromImageInPlace(_thumb.toImage().scaled(_thumbw * cIntRetinaFactor(), _thumbh * cIntRetinaFactor(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
2016-02-21 12:30:16 +00:00
|
|
|
_thumb.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
}
|
2017-04-02 10:25:54 +00:00
|
|
|
t_assert(_animated || _photo || _doc);
|
|
|
|
|
|
|
|
_field.create(this, st::confirmCaptionArea, lang(lng_photo_caption), caption);
|
|
|
|
_field->setMaxLength(MaxPhotoCaption);
|
|
|
|
_field->setCtrlEnterSubmit(Ui::CtrlEnterSubmit::Both);
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
2017-03-10 14:43:26 +00:00
|
|
|
void EditCaptionBox::prepareGifPreview(DocumentData *document) {
|
|
|
|
auto createGifPreview = [document] {
|
|
|
|
return (document && document->isAnimation());
|
|
|
|
};
|
2017-03-30 12:00:02 +00:00
|
|
|
auto createGifPreviewResult = createGifPreview(); // Clang freeze workaround.
|
|
|
|
if (createGifPreviewResult) {
|
2017-03-10 14:43:26 +00:00
|
|
|
_gifPreview = Media::Clip::MakeReader(document->location(), document->data(), [this](Media::Clip::Notification notification) {
|
|
|
|
clipCallback(notification);
|
|
|
|
});
|
|
|
|
if (_gifPreview) _gifPreview->setAutoplay();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditCaptionBox::clipCallback(Media::Clip::Notification notification) {
|
|
|
|
using namespace Media::Clip;
|
|
|
|
switch (notification) {
|
|
|
|
case NotificationReinit: {
|
|
|
|
if (_gifPreview && _gifPreview->state() == State::Error) {
|
|
|
|
_gifPreview.setBad();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_gifPreview && _gifPreview->ready() && !_gifPreview->started()) {
|
|
|
|
auto s = QSize(_thumbw, _thumbh);
|
|
|
|
_gifPreview->start(s.width(), s.height(), s.width(), s.height(), ImageRoundRadius::None, ImageRoundCorner::None);
|
|
|
|
}
|
|
|
|
|
|
|
|
update();
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case NotificationRepaint: {
|
|
|
|
if (_gifPreview && !_gifPreview->currentDisplayed()) {
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void EditCaptionBox::prepare() {
|
|
|
|
addButton(lang(lng_settings_save), [this] { onSave(); });
|
|
|
|
addButton(lang(lng_cancel), [this] { closeBox(); });
|
|
|
|
|
2016-02-21 12:30:16 +00:00
|
|
|
updateBoxSize();
|
2016-02-23 14:31:06 +00:00
|
|
|
connect(_field, SIGNAL(submitted(bool)), this, SLOT(onSave(bool)));
|
|
|
|
connect(_field, SIGNAL(cancelled()), this, SLOT(onClose()));
|
|
|
|
connect(_field, SIGNAL(resized()), this, SLOT(onCaptionResized()));
|
2016-02-21 12:30:16 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
auto cursor = _field->textCursor();
|
|
|
|
cursor.movePosition(QTextCursor::End);
|
|
|
|
_field->setTextCursor(cursor);
|
2016-02-23 14:31:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditCaptionBox::onCaptionResized() {
|
2016-02-21 12:30:16 +00:00
|
|
|
updateBoxSize();
|
|
|
|
resizeEvent(0);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2016-02-23 14:31:06 +00:00
|
|
|
void EditCaptionBox::updateBoxSize() {
|
2016-12-13 17:07:56 +00:00
|
|
|
auto newHeight = st::boxPhotoPadding.top() + st::boxPhotoCaptionSkip + _field->height() + st::normalFont->height;
|
2016-02-21 12:30:16 +00:00
|
|
|
if (_photo || _animated) {
|
2016-12-13 17:07:56 +00:00
|
|
|
newHeight += _thumbh;
|
2016-02-21 12:30:16 +00:00
|
|
|
} else if (_thumbw) {
|
2016-12-13 17:07:56 +00:00
|
|
|
newHeight += 0 + st::msgFileThumbSize + 0;
|
2016-02-21 12:30:16 +00:00
|
|
|
} else if (_doc) {
|
2016-12-13 17:07:56 +00:00
|
|
|
newHeight += 0 + st::msgFileSize + 0;
|
2016-02-21 12:30:16 +00:00
|
|
|
} else {
|
2016-12-13 17:07:56 +00:00
|
|
|
newHeight += st::boxTitleFont->height;
|
2016-02-21 12:30:16 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
setDimensions(st::boxWideWidth, newHeight);
|
2016-02-21 12:30:16 +00:00
|
|
|
}
|
|
|
|
|
2016-02-23 14:31:06 +00:00
|
|
|
void EditCaptionBox::paintEvent(QPaintEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::paintEvent(e);
|
2016-11-19 14:47:28 +00:00
|
|
|
|
2016-02-21 12:30:16 +00:00
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
if (_photo || _animated) {
|
|
|
|
if (_thumbx > st::boxPhotoPadding.left()) {
|
2016-12-13 17:07:56 +00:00
|
|
|
p.fillRect(st::boxPhotoPadding.left(), st::boxPhotoPadding.top(), _thumbx - st::boxPhotoPadding.left(), _thumbh, st::confirmBg);
|
2016-02-21 12:30:16 +00:00
|
|
|
}
|
|
|
|
if (_thumbx + _thumbw < width() - st::boxPhotoPadding.right()) {
|
2016-12-13 17:07:56 +00:00
|
|
|
p.fillRect(_thumbx + _thumbw, st::boxPhotoPadding.top(), width() - st::boxPhotoPadding.right() - _thumbx - _thumbw, _thumbh, st::confirmBg);
|
2016-02-21 12:30:16 +00:00
|
|
|
}
|
2017-03-10 14:43:26 +00:00
|
|
|
if (_gifPreview && _gifPreview->started()) {
|
|
|
|
auto s = QSize(_thumbw, _thumbh);
|
2017-04-07 18:10:49 +00:00
|
|
|
auto paused = controller()->isGifPausedAtLeastFor(Window::GifPauseReason::Layer);
|
2017-04-03 14:13:55 +00:00
|
|
|
auto frame = _gifPreview->current(s.width(), s.height(), s.width(), s.height(), ImageRoundRadius::None, ImageRoundCorner::None, paused ? 0 : getms());
|
2017-03-10 14:43:26 +00:00
|
|
|
p.drawPixmap(_thumbx, st::boxPhotoPadding.top(), frame);
|
|
|
|
} else {
|
|
|
|
p.drawPixmap(_thumbx, st::boxPhotoPadding.top(), _thumb);
|
|
|
|
}
|
|
|
|
if (_animated && !_gifPreview) {
|
2016-02-21 12:30:16 +00:00
|
|
|
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);
|
|
|
|
|
2016-12-03 12:10:35 +00:00
|
|
|
{
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.drawEllipse(inner);
|
|
|
|
}
|
2016-12-09 18:56:01 +00:00
|
|
|
|
2016-09-30 12:52:03 +00:00
|
|
|
auto icon = &st::historyFileInPlay;
|
2016-09-29 19:42:14 +00:00
|
|
|
icon->paintInCenter(p, inner);
|
2016-02-21 12:30:16 +00:00
|
|
|
}
|
|
|
|
} else if (_doc) {
|
|
|
|
int32 w = width() - st::boxPhotoPadding.left() - st::boxPhotoPadding.right();
|
2016-02-23 14:31:06 +00:00
|
|
|
int32 h = _thumbw ? (0 + st::msgFileThumbSize + 0) : (0 + st::msgFileSize + 0);
|
|
|
|
int32 nameleft = 0, nametop = 0, nameright = 0, statustop = 0;
|
2016-02-21 12:30:16 +00:00
|
|
|
if (_thumbw) {
|
2016-02-23 14:31:06 +00:00
|
|
|
nameleft = 0 + st::msgFileThumbSize + st::msgFileThumbPadding.right();
|
|
|
|
nametop = st::msgFileThumbNameTop - st::msgFileThumbPadding.top();
|
|
|
|
nameright = 0;
|
|
|
|
statustop = st::msgFileThumbStatusTop - st::msgFileThumbPadding.top();
|
2016-02-21 12:30:16 +00:00
|
|
|
} else {
|
2016-02-23 14:31:06 +00:00
|
|
|
nameleft = 0 + st::msgFileSize + st::msgFilePadding.right();
|
|
|
|
nametop = st::msgFileNameTop - st::msgFilePadding.top();
|
|
|
|
nameright = 0;
|
|
|
|
statustop = st::msgFileStatusTop - st::msgFilePadding.top();
|
2016-02-21 12:30:16 +00:00
|
|
|
}
|
2016-02-23 14:31:06 +00:00
|
|
|
int32 namewidth = w - nameleft - 0;
|
2016-02-21 12:30:16 +00:00
|
|
|
if (namewidth > _statusw) {
|
2016-02-23 14:31:06 +00:00
|
|
|
//w -= (namewidth - _statusw);
|
|
|
|
//namewidth = _statusw;
|
2016-02-21 12:30:16 +00:00
|
|
|
}
|
|
|
|
int32 x = (width() - w) / 2, y = st::boxPhotoPadding.top();
|
|
|
|
|
2016-02-23 14:31:06 +00:00
|
|
|
// App::roundRect(p, x, y, w, h, st::msgInBg, MessageInCorners, &st::msgInShadow);
|
2016-02-21 12:30:16 +00:00
|
|
|
|
|
|
|
if (_thumbw) {
|
2016-02-23 14:31:06 +00:00
|
|
|
QRect rthumb(rtlrect(x + 0, y + 0, st::msgFileThumbSize, st::msgFileThumbSize, width()));
|
2016-02-21 12:30:16 +00:00
|
|
|
p.drawPixmap(rthumb.topLeft(), _thumb);
|
|
|
|
} else {
|
2016-02-23 14:31:06 +00:00
|
|
|
QRect inner(rtlrect(x + 0, y + 0, st::msgFileSize, st::msgFileSize, width()));
|
2016-02-21 12:30:16 +00:00
|
|
|
p.setPen(Qt::NoPen);
|
2016-02-23 14:31:06 +00:00
|
|
|
p.setBrush(st::msgFileInBg);
|
2016-02-21 12:30:16 +00:00
|
|
|
|
2016-12-03 12:10:35 +00:00
|
|
|
{
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.drawEllipse(inner);
|
|
|
|
}
|
2016-02-21 12:30:16 +00:00
|
|
|
|
2017-03-10 14:14:10 +00:00
|
|
|
auto icon = &(_isAudio ? st::historyFileInPlay : _isImage ? st::historyFileInImage : st::historyFileInDocument);
|
2016-09-29 19:42:14 +00:00
|
|
|
icon->paintInCenter(p, inner);
|
2016-02-21 12:30:16 +00:00
|
|
|
}
|
|
|
|
p.setFont(st::semiboldFont);
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::historyFileNameInFg);
|
2016-02-21 12:30:16 +00:00
|
|
|
_name.drawLeftElided(p, x + nameleft, y + nametop, namewidth, width());
|
|
|
|
|
2016-11-03 10:33:57 +00:00
|
|
|
auto &status = st::mediaInFg;
|
2016-02-21 12:30:16 +00:00
|
|
|
p.setFont(st::normalFont);
|
|
|
|
p.setPen(status);
|
|
|
|
p.drawTextLeft(x + nameleft, y + statustop, width(), _status);
|
2016-02-23 14:31:06 +00:00
|
|
|
} else {
|
|
|
|
p.setFont(st::boxTitleFont);
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::boxTextFg);
|
2016-02-23 14:31:06 +00:00
|
|
|
p.drawTextLeft(_field->x(), st::boxPhotoPadding.top(), width(), lang(lng_edit_message));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_error.isEmpty()) {
|
|
|
|
p.setFont(st::normalFont);
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::boxTextFgError);
|
2016-02-23 14:31:06 +00:00
|
|
|
p.drawTextLeft(_field->x(), _field->y() + _field->height() + (st::boxButtonPadding.top() / 2), width(), _error);
|
2016-02-21 12:30:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-23 14:31:06 +00:00
|
|
|
void EditCaptionBox::resizeEvent(QResizeEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::resizeEvent(e);
|
2016-02-23 14:31:06 +00:00
|
|
|
_field->resize(st::boxWideWidth - st::boxPhotoPadding.left() - st::boxPhotoPadding.right(), _field->height());
|
2016-12-13 17:07:56 +00:00
|
|
|
_field->moveToLeft(st::boxPhotoPadding.left(), height() - st::normalFont->height - _field->height());
|
2016-02-21 12:30:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void EditCaptionBox::setInnerFocus() {
|
2016-12-20 13:03:51 +00:00
|
|
|
_field->setFocusFast();
|
2016-02-21 12:30:16 +00:00
|
|
|
}
|
|
|
|
|
2016-02-23 14:31:06 +00:00
|
|
|
void EditCaptionBox::onSave(bool ctrlShiftEnter) {
|
2016-02-21 12:30:16 +00:00
|
|
|
if (_saveRequestId) return;
|
|
|
|
|
2016-02-23 14:31:06 +00:00
|
|
|
HistoryItem *item = App::histItemById(_msgId);
|
|
|
|
if (!item) {
|
|
|
|
_error = lang(lng_edit_deleted);
|
|
|
|
update();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-25 15:42:01 +00:00
|
|
|
auto flags = qFlags(MTPmessages_EditMessage::Flag::f_message);
|
2016-02-21 12:30:16 +00:00
|
|
|
if (_previewCancelled) {
|
2016-03-30 17:13:07 +00:00
|
|
|
flags |= MTPmessages_EditMessage::Flag::f_no_webpage;
|
2016-02-21 12:30:16 +00:00
|
|
|
}
|
2016-02-23 14:31:06 +00:00
|
|
|
MTPVector<MTPMessageEntity> sentEntities;
|
2017-03-10 19:46:28 +00:00
|
|
|
if (!sentEntities.v.isEmpty()) {
|
2016-03-30 17:13:07 +00:00
|
|
|
flags |= MTPmessages_EditMessage::Flag::f_entities;
|
2016-02-21 12:30:16 +00:00
|
|
|
}
|
2016-06-07 19:59:39 +00:00
|
|
|
auto text = prepareText(_field->getLastText(), true);
|
|
|
|
_saveRequestId = MTP::send(MTPmessages_EditMessage(MTP_flags(flags), item->history()->peer->input, MTP_int(item->id), MTP_string(text), MTPnullMarkup, sentEntities), rpcDone(&EditCaptionBox::saveDone), rpcFail(&EditCaptionBox::saveFail));
|
2016-02-21 12:30:16 +00:00
|
|
|
}
|
|
|
|
|
2016-02-23 14:31:06 +00:00
|
|
|
void EditCaptionBox::saveDone(const MTPUpdates &updates) {
|
2016-02-21 12:30:16 +00:00
|
|
|
_saveRequestId = 0;
|
2016-12-13 17:07:56 +00:00
|
|
|
closeBox();
|
2016-02-21 12:30:16 +00:00
|
|
|
if (App::main()) {
|
|
|
|
App::main()->sentUpdatesReceived(updates);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-23 14:31:06 +00:00
|
|
|
bool EditCaptionBox::saveFail(const RPCError &error) {
|
2016-04-08 10:44:35 +00:00
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
2016-02-21 12:30:16 +00:00
|
|
|
|
|
|
|
_saveRequestId = 0;
|
|
|
|
QString err = error.type();
|
|
|
|
if (err == qstr("MESSAGE_ID_INVALID") || err == qstr("CHAT_ADMIN_REQUIRED") || err == qstr("MESSAGE_EDIT_TIME_EXPIRED")) {
|
|
|
|
_error = lang(lng_edit_error);
|
|
|
|
} else if (err == qstr("MESSAGE_NOT_MODIFIED")) {
|
2016-12-13 17:07:56 +00:00
|
|
|
closeBox();
|
2016-02-21 12:30:16 +00:00
|
|
|
return true;
|
|
|
|
} else if (err == qstr("MESSAGE_EMPTY")) {
|
2016-02-23 14:31:06 +00:00
|
|
|
_field->setFocus();
|
|
|
|
_field->showError();
|
2016-02-21 12:30:16 +00:00
|
|
|
} else {
|
|
|
|
_error = lang(lng_edit_error);
|
|
|
|
}
|
|
|
|
update();
|
|
|
|
return true;
|
|
|
|
}
|