2016-04-12 21:31:28 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-04-12 21:31:28 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-04-12 21:31:28 +00:00
|
|
|
*/
|
|
|
|
#include "overview/overview_layout.h"
|
|
|
|
|
2020-05-21 12:27:04 +00:00
|
|
|
#include "overview/overview_layout_delegate.h"
|
2017-09-26 11:49:16 +00:00
|
|
|
#include "data/data_document.h"
|
2018-01-04 10:22:53 +00:00
|
|
|
#include "data/data_session.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "data/data_web_page.h"
|
2018-01-14 16:02:25 +00:00
|
|
|
#include "data/data_media_types.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_peer.h"
|
2019-12-05 08:32:33 +00:00
|
|
|
#include "data/data_file_origin.h"
|
2020-05-25 14:16:04 +00:00
|
|
|
#include "data/data_photo_media.h"
|
2020-03-27 11:40:50 +00:00
|
|
|
#include "data/data_document_media.h"
|
2016-04-21 17:57:29 +00:00
|
|
|
#include "styles/style_overview.h"
|
2016-09-30 12:52:03 +00:00
|
|
|
#include "styles/style_history.h"
|
2017-02-28 14:05:30 +00:00
|
|
|
#include "core/file_utilities.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/add_contact_box.h"
|
|
|
|
#include "boxes/confirm_box.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "mainwidget.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/file_upload.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "mainwindow.h"
|
2020-06-18 12:47:09 +00:00
|
|
|
#include "main/main_session.h"
|
2019-02-13 12:36:59 +00:00
|
|
|
#include "media/audio/media_audio.h"
|
2016-09-23 16:04:26 +00:00
|
|
|
#include "media/player/media_player_instance.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2019-08-06 16:40:08 +00:00
|
|
|
#include "history/history.h"
|
2018-01-11 19:33:26 +00:00
|
|
|
#include "history/history_item.h"
|
2017-12-18 15:44:50 +00:00
|
|
|
#include "history/history_item_components.h"
|
2018-01-27 13:59:24 +00:00
|
|
|
#include "history/view/history_view_cursor_state.h"
|
2019-07-10 17:28:33 +00:00
|
|
|
#include "base/unixtime.h"
|
2016-11-21 17:46:29 +00:00
|
|
|
#include "ui/effects/round_checkbox.h"
|
2018-10-23 09:44:42 +00:00
|
|
|
#include "ui/image/image.h"
|
2017-12-28 13:06:06 +00:00
|
|
|
#include "ui/text_options.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "app.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
|
|
|
|
namespace Overview {
|
|
|
|
namespace Layout {
|
2016-10-13 15:04:40 +00:00
|
|
|
namespace {
|
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
using TextState = HistoryView::TextState;
|
|
|
|
|
2016-10-13 15:04:40 +00:00
|
|
|
TextParseOptions _documentNameOptions = {
|
2017-08-08 09:31:48 +00:00
|
|
|
TextParseMultiline | TextParseRichText | TextParseLinks | TextParseMarkdown, // flags
|
2016-10-13 15:04:40 +00:00
|
|
|
0, // maxw
|
|
|
|
0, // maxh
|
|
|
|
Qt::LayoutDirectionAuto, // dir
|
|
|
|
};
|
|
|
|
|
2017-03-10 14:14:10 +00:00
|
|
|
TextWithEntities ComposeNameWithEntities(DocumentData *document) {
|
|
|
|
TextWithEntities result;
|
2017-12-10 10:26:58 +00:00
|
|
|
const auto song = document->song();
|
2017-03-10 14:14:10 +00:00
|
|
|
if (!song || (song->title.isEmpty() && song->performer.isEmpty())) {
|
2017-11-05 11:00:48 +00:00
|
|
|
result.text = document->filename().isEmpty()
|
|
|
|
? qsl("Unknown File")
|
|
|
|
: document->filename();
|
2020-05-08 08:12:43 +00:00
|
|
|
result.entities.push_back({
|
|
|
|
EntityType::Semibold,
|
|
|
|
0,
|
|
|
|
result.text.size()
|
|
|
|
});
|
2017-03-10 14:14:10 +00:00
|
|
|
} else if (song->performer.isEmpty()) {
|
|
|
|
result.text = song->title;
|
2020-05-08 08:12:43 +00:00
|
|
|
result.entities.push_back({
|
|
|
|
EntityType::Semibold,
|
|
|
|
0,
|
|
|
|
result.text.size()
|
|
|
|
});
|
2017-03-10 14:14:10 +00:00
|
|
|
} else {
|
2020-05-08 08:12:43 +00:00
|
|
|
result.text = song->performer
|
|
|
|
+ QString::fromUtf8(" \xe2\x80\x93 ")
|
|
|
|
+ (song->title.isEmpty() ? qsl("Unknown Track") : song->title);
|
|
|
|
result.entities.push_back({
|
|
|
|
EntityType::Semibold,
|
|
|
|
0,
|
|
|
|
song->performer.size()
|
|
|
|
});
|
2017-03-10 14:14:10 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-10-13 15:04:40 +00:00
|
|
|
} // namespace
|
2016-04-12 21:31:28 +00:00
|
|
|
|
2017-11-23 14:58:00 +00:00
|
|
|
class Checkbox {
|
|
|
|
public:
|
|
|
|
template <typename UpdateCallback>
|
|
|
|
Checkbox(UpdateCallback callback, const style::RoundCheckbox &st)
|
|
|
|
: _updateCallback(callback)
|
|
|
|
, _check(st, _updateCallback) {
|
|
|
|
}
|
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
void paint(Painter &p, QPoint position, int outerWidth, bool selected, bool selecting);
|
2017-11-23 14:58:00 +00:00
|
|
|
|
|
|
|
void setActive(bool active);
|
|
|
|
void setPressed(bool pressed);
|
|
|
|
|
|
|
|
void invalidateCache() {
|
|
|
|
_check.invalidateCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void startAnimation();
|
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void()> _updateCallback;
|
2017-11-23 14:58:00 +00:00
|
|
|
Ui::RoundCheckbox _check;
|
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
Ui::Animations::Simple _pression;
|
2017-11-23 14:58:00 +00:00
|
|
|
bool _active = false;
|
|
|
|
bool _pressed = false;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
void Checkbox::paint(Painter &p, QPoint position, int outerWidth, bool selected, bool selecting) {
|
2017-11-23 14:58:00 +00:00
|
|
|
_check.setDisplayInactive(selecting);
|
|
|
|
_check.setChecked(selected);
|
2019-04-02 09:13:30 +00:00
|
|
|
const auto pression = _pression.value((_active && _pressed) ? 1. : 0.);
|
2017-11-23 14:58:00 +00:00
|
|
|
const auto masterScale = 1. - (1. - st::overviewCheckPressedSize) * pression;
|
2019-04-02 09:13:30 +00:00
|
|
|
_check.paint(p, position.x(), position.y(), outerWidth, masterScale);
|
2017-11-23 14:58:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Checkbox::setActive(bool active) {
|
|
|
|
_active = active;
|
|
|
|
if (_pressed) {
|
|
|
|
startAnimation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Checkbox::setPressed(bool pressed) {
|
|
|
|
_pressed = pressed;
|
|
|
|
if (_active) {
|
|
|
|
startAnimation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Checkbox::startAnimation() {
|
|
|
|
auto showPressed = (_pressed && _active);
|
|
|
|
_pression.start(_updateCallback, showPressed ? 0. : 1., showPressed ? 1. : 0., st::overviewCheck.duration);
|
|
|
|
}
|
|
|
|
|
2020-05-21 12:27:04 +00:00
|
|
|
ItemBase::ItemBase(
|
|
|
|
not_null<Delegate*> delegate,
|
|
|
|
not_null<HistoryItem*> parent)
|
|
|
|
: _delegate(delegate)
|
|
|
|
, _parent(parent)
|
2018-02-03 19:52:35 +00:00
|
|
|
, _dateTime(ItemDateTime(parent)) {
|
|
|
|
}
|
|
|
|
|
2020-05-21 12:27:04 +00:00
|
|
|
ItemBase::~ItemBase() = default;
|
|
|
|
|
2018-02-03 19:52:35 +00:00
|
|
|
QDateTime ItemBase::dateTime() const {
|
|
|
|
return _dateTime;
|
2017-11-23 14:58:00 +00:00
|
|
|
}
|
|
|
|
|
2017-10-13 19:07:04 +00:00
|
|
|
void ItemBase::clickHandlerActiveChanged(
|
|
|
|
const ClickHandlerPtr &action,
|
|
|
|
bool active) {
|
2019-08-06 16:40:08 +00:00
|
|
|
_parent->history()->session().data().requestItemRepaint(_parent);
|
2017-11-23 14:58:00 +00:00
|
|
|
if (_check) {
|
|
|
|
_check->setActive(active);
|
|
|
|
}
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2017-10-13 19:07:04 +00:00
|
|
|
void ItemBase::clickHandlerPressedChanged(
|
|
|
|
const ClickHandlerPtr &action,
|
|
|
|
bool pressed) {
|
2019-08-06 16:40:08 +00:00
|
|
|
_parent->history()->session().data().requestItemRepaint(_parent);
|
2017-11-23 14:58:00 +00:00
|
|
|
if (_check) {
|
|
|
|
_check->setPressed(pressed);
|
|
|
|
}
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2017-11-23 14:58:00 +00:00
|
|
|
void ItemBase::invalidateCache() {
|
|
|
|
if (_check) {
|
|
|
|
_check->invalidateCache();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemBase::paintCheckbox(
|
|
|
|
Painter &p,
|
|
|
|
QPoint position,
|
|
|
|
bool selected,
|
|
|
|
const PaintContext *context) {
|
|
|
|
if (selected || context->selecting) {
|
|
|
|
ensureCheckboxCreated();
|
|
|
|
}
|
|
|
|
if (_check) {
|
2019-04-02 09:13:30 +00:00
|
|
|
_check->paint(p, position, _width, selected, context->selecting);
|
2017-11-23 14:58:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const style::RoundCheckbox &ItemBase::checkboxStyle() const {
|
|
|
|
return st::overviewCheck;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemBase::ensureCheckboxCreated() {
|
2020-04-15 14:06:34 +00:00
|
|
|
if (_check) {
|
|
|
|
return;
|
2017-11-23 14:58:00 +00:00
|
|
|
}
|
2020-04-15 14:06:34 +00:00
|
|
|
const auto repaint = [=] {
|
|
|
|
_parent->history()->session().data().requestItemRepaint(_parent);
|
|
|
|
};
|
|
|
|
_check = std::make_unique<Checkbox>(repaint, checkboxStyle());
|
2017-11-23 14:58:00 +00:00
|
|
|
}
|
|
|
|
|
2017-10-05 15:35:52 +00:00
|
|
|
void RadialProgressItem::setDocumentLinks(
|
|
|
|
not_null<DocumentData*> document) {
|
2018-01-11 13:07:29 +00:00
|
|
|
const auto context = parent()->fullId();
|
2017-10-05 15:35:52 +00:00
|
|
|
setLinks(
|
2019-03-11 14:35:11 +00:00
|
|
|
std::make_shared<DocumentOpenClickHandler>(document, context),
|
|
|
|
std::make_shared<DocumentSaveClickHandler>(document, context),
|
|
|
|
std::make_shared<DocumentCancelClickHandler>(document, context));
|
|
|
|
}
|
|
|
|
|
|
|
|
void RadialProgressItem::clickHandlerActiveChanged(
|
|
|
|
const ClickHandlerPtr &action,
|
|
|
|
bool active) {
|
2016-12-09 18:56:01 +00:00
|
|
|
ItemBase::clickHandlerActiveChanged(action, active);
|
|
|
|
if (action == _openl || action == _savel || action == _cancell) {
|
2016-12-07 13:32:25 +00:00
|
|
|
if (iconAnimated()) {
|
2019-08-06 16:40:08 +00:00
|
|
|
const auto repaint = [=] {
|
|
|
|
parent()->history()->session().data().requestItemRepaint(
|
|
|
|
parent());
|
|
|
|
};
|
2017-10-05 15:35:52 +00:00
|
|
|
_a_iconOver.start(
|
2019-08-06 16:40:08 +00:00
|
|
|
repaint,
|
2017-10-05 15:35:52 +00:00
|
|
|
active ? 0. : 1.,
|
|
|
|
active ? 1. : 0.,
|
|
|
|
st::msgFileOverDuration);
|
2016-12-07 13:32:25 +00:00
|
|
|
}
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-11 14:35:11 +00:00
|
|
|
void RadialProgressItem::setLinks(
|
|
|
|
ClickHandlerPtr &&openl,
|
|
|
|
ClickHandlerPtr &&savel,
|
|
|
|
ClickHandlerPtr &&cancell) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_openl = std::move(openl);
|
|
|
|
_savel = std::move(savel);
|
|
|
|
_cancell = std::move(cancell);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2019-04-04 15:24:13 +00:00
|
|
|
void RadialProgressItem::radialAnimationCallback(crl::time now) const {
|
|
|
|
const auto updated = [&] {
|
2019-04-01 17:44:54 +00:00
|
|
|
return _radial->update(dataProgress(), dataFinished(), now);
|
|
|
|
}();
|
2019-04-04 15:24:13 +00:00
|
|
|
if (!anim::Disabled() || updated) {
|
2019-08-06 16:40:08 +00:00
|
|
|
parent()->history()->session().data().requestItemRepaint(parent());
|
2019-04-01 17:44:54 +00:00
|
|
|
}
|
|
|
|
if (!_radial->animating()) {
|
|
|
|
checkRadialFinished();
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-21 16:24:23 +00:00
|
|
|
void RadialProgressItem::ensureRadial() {
|
2020-04-15 14:06:34 +00:00
|
|
|
if (_radial) {
|
|
|
|
return;
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
2020-04-15 14:06:34 +00:00
|
|
|
_radial = std::make_unique<Ui::RadialAnimation>([=](crl::time now) {
|
|
|
|
radialAnimationCallback(now);
|
|
|
|
});
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2019-04-01 17:44:54 +00:00
|
|
|
void RadialProgressItem::checkRadialFinished() const {
|
2016-04-12 21:31:28 +00:00
|
|
|
if (_radial && !_radial->animating() && dataLoaded()) {
|
2016-12-07 13:32:25 +00:00
|
|
|
_radial.reset();
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-07 13:32:25 +00:00
|
|
|
RadialProgressItem::~RadialProgressItem() = default;
|
2016-04-12 21:31:28 +00:00
|
|
|
|
2019-02-19 06:57:53 +00:00
|
|
|
void StatusText::update(int newSize, int fullSize, int duration, crl::time realDuration) {
|
2016-11-21 16:24:23 +00:00
|
|
|
setSize(newSize);
|
|
|
|
if (_size == FileStatusSizeReady) {
|
|
|
|
_text = (duration >= 0) ? formatDurationAndSizeText(duration, fullSize) : (duration < -1 ? formatGifAndSizeText(fullSize) : formatSizeText(fullSize));
|
|
|
|
} else if (_size == FileStatusSizeLoaded) {
|
|
|
|
_text = (duration >= 0) ? formatDurationText(duration) : (duration < -1 ? qsl("GIF") : formatSizeText(fullSize));
|
|
|
|
} else if (_size == FileStatusSizeFailed) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_text = tr::lng_attach_failed(tr::now);
|
2016-11-21 16:24:23 +00:00
|
|
|
} else if (_size >= 0) {
|
|
|
|
_text = formatDownloadText(_size, fullSize);
|
2016-04-12 21:31:28 +00:00
|
|
|
} else {
|
2016-11-21 16:24:23 +00:00
|
|
|
_text = formatPlayedText(-_size - 1, realDuration);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-21 16:24:23 +00:00
|
|
|
void StatusText::setSize(int newSize) {
|
|
|
|
_size = newSize;
|
|
|
|
}
|
|
|
|
|
2017-10-05 15:35:52 +00:00
|
|
|
Photo::Photo(
|
2020-05-21 12:27:04 +00:00
|
|
|
not_null<Delegate*> delegate,
|
2017-10-05 15:35:52 +00:00
|
|
|
not_null<HistoryItem*> parent,
|
|
|
|
not_null<PhotoData*> photo)
|
2020-05-21 12:27:04 +00:00
|
|
|
: ItemBase(delegate, parent)
|
2016-04-12 21:31:28 +00:00
|
|
|
, _data(photo)
|
2017-12-18 09:07:18 +00:00
|
|
|
, _link(std::make_shared<PhotoOpenClickHandler>(photo, parent->fullId())) {
|
2020-05-26 10:13:32 +00:00
|
|
|
if (_data->inlineThumbnailBytes().isEmpty()
|
|
|
|
&& (_data->hasExact(Data::PhotoSize::Small)
|
|
|
|
|| _data->hasExact(Data::PhotoSize::Thumbnail))) {
|
2020-05-25 14:16:04 +00:00
|
|
|
_data->load(Data::PhotoSize::Small, parent->fullId());
|
2019-03-12 08:53:19 +00:00
|
|
|
}
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Photo::initDimensions() {
|
|
|
|
_maxw = 2 * st::overviewPhotoMinSize;
|
|
|
|
_minh = _maxw;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 Photo::resizeGetHeight(int32 width) {
|
|
|
|
width = qMin(width, _maxw);
|
|
|
|
if (width != _width || width != _height) {
|
|
|
|
_width = qMin(width, _maxw);
|
|
|
|
_height = _width;
|
|
|
|
}
|
|
|
|
return _height;
|
|
|
|
}
|
|
|
|
|
2016-11-21 16:24:23 +00:00
|
|
|
void Photo::paint(Painter &p, const QRect &clip, TextSelection selection, const PaintContext *context) {
|
2020-05-25 14:16:04 +00:00
|
|
|
const auto selected = (selection == FullSelection);
|
|
|
|
const auto widthChanged = _pix.width() != _width * cIntRetinaFactor();
|
|
|
|
if (!_goodLoaded || widthChanged) {
|
|
|
|
ensureDataMediaCreated();
|
|
|
|
const auto good = _dataMedia->loaded()
|
|
|
|
|| (_dataMedia->image(Data::PhotoSize::Thumbnail) != nullptr);
|
|
|
|
if ((good && !_goodLoaded) || widthChanged) {
|
|
|
|
_goodLoaded = good;
|
|
|
|
_pix = QPixmap();
|
|
|
|
if (_goodLoaded) {
|
|
|
|
setPixFrom(_dataMedia->image(Data::PhotoSize::Large)
|
|
|
|
? _dataMedia->image(Data::PhotoSize::Large)
|
|
|
|
: _dataMedia->image(Data::PhotoSize::Thumbnail));
|
|
|
|
} else if (const auto small = _dataMedia->image(
|
|
|
|
Data::PhotoSize::Small)) {
|
|
|
|
setPixFrom(small);
|
|
|
|
} else if (const auto blurred = _dataMedia->thumbnailInline()) {
|
2019-01-25 14:37:28 +00:00
|
|
|
setPixFrom(blurred);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_pix.isNull()) {
|
|
|
|
p.fillRect(0, 0, _width, _height, st::overviewPhotoBg);
|
|
|
|
} else {
|
|
|
|
p.drawPixmap(0, 0, _pix);
|
|
|
|
}
|
2016-11-21 16:24:23 +00:00
|
|
|
|
2017-11-23 14:58:00 +00:00
|
|
|
if (selected) {
|
|
|
|
p.fillRect(0, 0, _width, _height, st::overviewPhotoSelectOverlay);
|
2016-11-21 16:24:23 +00:00
|
|
|
}
|
2017-11-23 14:58:00 +00:00
|
|
|
const auto checkDelta = st::overviewCheckSkip + st::overviewCheck.size;
|
|
|
|
const auto checkLeft = _width - checkDelta;
|
|
|
|
const auto checkTop = _height - checkDelta;
|
|
|
|
paintCheckbox(p, { checkLeft, checkTop }, selected, context);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2019-01-25 14:37:28 +00:00
|
|
|
void Photo::setPixFrom(not_null<Image*> image) {
|
|
|
|
const auto size = _width * cIntRetinaFactor();
|
|
|
|
auto img = image->original();
|
|
|
|
if (!_goodLoaded) {
|
|
|
|
img = Images::prepareBlur(std::move(img));
|
|
|
|
}
|
|
|
|
if (img.width() == img.height()) {
|
|
|
|
if (img.width() != size) {
|
|
|
|
img = img.scaled(size, size, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
|
|
|
|
}
|
|
|
|
} else if (img.width() > img.height()) {
|
|
|
|
img = img.copy((img.width() - img.height()) / 2, 0, img.height(), img.height()).scaled(size, size, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
|
|
|
|
} else {
|
|
|
|
img = img.copy(0, (img.height() - img.width()) / 2, img.width(), img.width()).scaled(size, size, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
|
|
|
|
}
|
|
|
|
img.setDevicePixelRatio(cRetinaFactor());
|
2019-03-12 08:53:19 +00:00
|
|
|
|
|
|
|
// In case we have inline thumbnail we can unload all images and we still
|
|
|
|
// won't get a blank image in the media viewer when the photo is opened.
|
2020-05-25 14:16:04 +00:00
|
|
|
if (!_data->inlineThumbnailBytes().isEmpty()) {
|
|
|
|
_dataMedia = nullptr;
|
|
|
|
delegate()->unregisterHeavyItem(this);
|
2019-03-12 08:53:19 +00:00
|
|
|
}
|
2019-01-25 14:37:28 +00:00
|
|
|
|
|
|
|
_pix = App::pixmapFromImageInPlace(std::move(img));
|
|
|
|
}
|
|
|
|
|
2020-05-25 14:16:04 +00:00
|
|
|
void Photo::ensureDataMediaCreated() const {
|
|
|
|
if (_dataMedia) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_dataMedia = _data->createMediaView();
|
|
|
|
if (_data->inlineThumbnailBytes().isEmpty()) {
|
|
|
|
_dataMedia->wanted(Data::PhotoSize::Small, parent()->fullId());
|
|
|
|
}
|
|
|
|
_dataMedia->wanted(Data::PhotoSize::Thumbnail, parent()->fullId());
|
|
|
|
delegate()->registerHeavyItem(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Photo::clearHeavyPart() {
|
|
|
|
_dataMedia = nullptr;
|
|
|
|
}
|
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
TextState Photo::getState(
|
2017-10-13 19:07:04 +00:00
|
|
|
QPoint point,
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request) const {
|
2017-06-21 21:38:31 +00:00
|
|
|
if (hasPoint(point)) {
|
2017-12-15 16:25:47 +00:00
|
|
|
return { parent(), _link };
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
2017-10-13 19:07:04 +00:00
|
|
|
return {};
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2017-10-05 15:35:52 +00:00
|
|
|
Video::Video(
|
2020-05-21 12:27:04 +00:00
|
|
|
not_null<Delegate*> delegate,
|
2017-10-05 15:35:52 +00:00
|
|
|
not_null<HistoryItem*> parent,
|
|
|
|
not_null<DocumentData*> video)
|
2020-05-21 12:27:04 +00:00
|
|
|
: RadialProgressItem(delegate, parent)
|
2016-04-12 21:31:28 +00:00
|
|
|
, _data(video)
|
2019-03-06 08:21:42 +00:00
|
|
|
, _duration(formatDurationText(_data->getDuration())) {
|
2016-04-12 21:31:28 +00:00
|
|
|
setDocumentLinks(_data);
|
2019-01-25 14:37:28 +00:00
|
|
|
_data->loadThumbnail(parent->fullId());
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2020-03-27 11:40:50 +00:00
|
|
|
Video::~Video() = default;
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
void Video::initDimensions() {
|
2018-10-25 13:22:44 +00:00
|
|
|
_maxw = 2 * st::overviewPhotoMinSize;
|
2016-04-12 21:31:28 +00:00
|
|
|
_minh = _maxw;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 Video::resizeGetHeight(int32 width) {
|
|
|
|
_width = qMin(width, _maxw);
|
|
|
|
_height = _width;
|
|
|
|
return _height;
|
|
|
|
}
|
|
|
|
|
2016-11-21 16:24:23 +00:00
|
|
|
void Video::paint(Painter &p, const QRect &clip, TextSelection selection, const PaintContext *context) {
|
2020-03-27 11:40:50 +00:00
|
|
|
ensureDataMediaCreated();
|
|
|
|
|
2019-01-25 14:37:28 +00:00
|
|
|
const auto selected = (selection == FullSelection);
|
2020-04-08 15:09:29 +00:00
|
|
|
const auto blurred = _dataMedia->thumbnailInline();
|
2020-04-15 14:06:34 +00:00
|
|
|
const auto thumbnail = _dataMedia->thumbnail();
|
2020-05-29 15:10:25 +00:00
|
|
|
const auto good = _dataMedia->goodThumbnail();
|
2016-04-12 21:31:28 +00:00
|
|
|
|
2020-04-09 14:02:09 +00:00
|
|
|
bool loaded = dataLoaded(), displayLoading = _data->displayLoading();
|
2016-04-12 21:31:28 +00:00
|
|
|
if (displayLoading) {
|
|
|
|
ensureRadial();
|
|
|
|
if (!_radial->animating()) {
|
2020-04-10 13:18:51 +00:00
|
|
|
_radial->start(dataProgress());
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
updateStatusText();
|
2019-04-04 15:24:13 +00:00
|
|
|
const auto radial = isRadialAnimation();
|
2019-03-14 20:00:24 +00:00
|
|
|
const auto radialOpacity = radial ? _radial->opacity() : 0.;
|
2016-04-12 21:31:28 +00:00
|
|
|
|
2020-05-29 15:10:25 +00:00
|
|
|
if ((blurred || thumbnail || good)
|
2019-04-08 10:35:25 +00:00
|
|
|
&& ((_pix.width() != _width * cIntRetinaFactor())
|
2020-05-29 15:10:25 +00:00
|
|
|
|| (_pixBlurred && (thumbnail || good)))) {
|
2019-01-25 14:37:28 +00:00
|
|
|
auto size = _width * cIntRetinaFactor();
|
2020-05-29 15:10:25 +00:00
|
|
|
auto img = good
|
|
|
|
? good->original()
|
2020-04-15 14:06:34 +00:00
|
|
|
: thumbnail
|
|
|
|
? thumbnail->original()
|
2019-01-25 14:37:28 +00:00
|
|
|
: Images::prepareBlur(blurred->original());
|
|
|
|
if (img.width() == img.height()) {
|
|
|
|
if (img.width() != size) {
|
|
|
|
img = img.scaled(size, size, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
2019-01-25 14:37:28 +00:00
|
|
|
} else if (img.width() > img.height()) {
|
|
|
|
img = img.copy((img.width() - img.height()) / 2, 0, img.height(), img.height()).scaled(size, size, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
|
|
|
|
} else {
|
|
|
|
img = img.copy(0, (img.height() - img.width()) / 2, img.width(), img.width()).scaled(size, size, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
2019-01-25 14:37:28 +00:00
|
|
|
img.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
|
|
|
|
_pix = App::pixmapFromImageInPlace(std::move(img));
|
2020-05-29 15:10:25 +00:00
|
|
|
_pixBlurred = !(thumbnail || good);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_pix.isNull()) {
|
|
|
|
p.fillRect(0, 0, _width, _height, st::overviewPhotoBg);
|
|
|
|
} else {
|
|
|
|
p.drawPixmap(0, 0, _pix);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selected) {
|
|
|
|
p.fillRect(QRect(0, 0, _width, _height), st::overviewPhotoSelectOverlay);
|
|
|
|
}
|
|
|
|
|
2019-03-14 20:00:24 +00:00
|
|
|
if (!selected && !context->selecting && radialOpacity < 1.) {
|
2016-04-12 21:31:28 +00:00
|
|
|
if (clip.intersects(QRect(0, _height - st::normalFont->height, _width, st::normalFont->height))) {
|
2020-04-10 13:18:51 +00:00
|
|
|
const auto download = !loaded && !_dataMedia->canBePlayed();
|
2019-03-14 20:00:24 +00:00
|
|
|
const auto &icon = download
|
|
|
|
? (selected ? st::overviewVideoDownloadSelected : st::overviewVideoDownload)
|
|
|
|
: (selected ? st::overviewVideoPlaySelected : st::overviewVideoPlay);
|
|
|
|
const auto text = download ? _status.text() : _duration;
|
|
|
|
const auto margin = st::overviewVideoStatusMargin;
|
|
|
|
const auto padding = st::overviewVideoStatusPadding;
|
|
|
|
const auto statusX = margin + padding.x(), statusY = _height - margin - padding.y() - st::normalFont->height;
|
|
|
|
const auto statusW = icon.width() + padding.x() + st::normalFont->width(text) + 2 * padding.x();
|
|
|
|
const auto statusH = st::normalFont->height + 2 * padding.y();
|
|
|
|
p.setOpacity(1. - radialOpacity);
|
|
|
|
App::roundRect(p, statusX - padding.x(), statusY - padding.y(), statusW, statusH, selected ? st::msgDateImgBgSelected : st::msgDateImgBg, selected ? OverviewVideoSelectedCorners : OverviewVideoCorners);
|
2016-04-12 21:31:28 +00:00
|
|
|
p.setFont(st::normalFont);
|
2016-12-21 15:05:58 +00:00
|
|
|
p.setPen(st::msgDateImgFg);
|
2019-03-14 20:00:24 +00:00
|
|
|
icon.paint(p, statusX, statusY + (st::normalFont->height - icon.height()) / 2, _width);
|
|
|
|
p.drawTextLeft(statusX + icon.width() + padding.x(), statusY, _width, text, statusW - 2 * padding.x());
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-14 20:00:24 +00:00
|
|
|
QRect inner((_width - st::overviewVideoRadialSize) / 2, (_height - st::overviewVideoRadialSize) / 2, st::overviewVideoRadialSize, st::overviewVideoRadialSize);
|
|
|
|
if (radial && clip.intersects(inner)) {
|
|
|
|
p.setOpacity(radialOpacity);
|
2016-04-12 21:31:28 +00:00
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
if (selected) {
|
|
|
|
p.setBrush(st::msgDateImgBgSelected);
|
|
|
|
} else {
|
2020-04-10 13:18:51 +00:00
|
|
|
auto over = ClickHandler::showAsActive((_data->loading() || _data->uploading()) ? _cancell : (loaded || _dataMedia->canBePlayed()) ? _openl : _savel);
|
2019-04-02 09:13:30 +00:00
|
|
|
p.setBrush(anim::brush(st::msgDateImgBg, st::msgDateImgBgOver, _a_iconOver.value(over ? 1. : 0.)));
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2016-12-03 12:10:35 +00:00
|
|
|
{
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.drawEllipse(inner);
|
|
|
|
}
|
2016-04-12 21:31:28 +00:00
|
|
|
|
2019-03-06 06:49:41 +00:00
|
|
|
const auto icon = [&] {
|
2019-03-14 20:00:24 +00:00
|
|
|
return &(selected ? st::historyFileThumbCancelSelected : st::historyFileThumbCancel);
|
2019-03-06 06:49:41 +00:00
|
|
|
}();
|
2016-09-29 19:42:14 +00:00
|
|
|
icon->paintInCenter(p, inner);
|
2016-04-12 21:31:28 +00:00
|
|
|
if (radial) {
|
|
|
|
p.setOpacity(1);
|
|
|
|
QRect rinner(inner.marginsRemoved(QMargins(st::msgFileRadialLine, st::msgFileRadialLine, st::msgFileRadialLine, st::msgFileRadialLine)));
|
2017-01-11 08:16:44 +00:00
|
|
|
_radial->draw(p, rinner, st::msgFileRadialLine, selected ? st::historyFileThumbRadialFgSelected : st::historyFileThumbRadialFg);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-14 20:00:24 +00:00
|
|
|
p.setOpacity(1);
|
2016-11-21 16:24:23 +00:00
|
|
|
|
2017-11-23 14:58:00 +00:00
|
|
|
const auto checkDelta = st::overviewCheckSkip + st::overviewCheck.size;
|
|
|
|
const auto checkLeft = _width - checkDelta;
|
|
|
|
const auto checkTop = _height - checkDelta;
|
|
|
|
paintCheckbox(p, { checkLeft, checkTop }, selected, context);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2020-03-27 11:40:50 +00:00
|
|
|
void Video::ensureDataMediaCreated() const {
|
|
|
|
if (_dataMedia) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_dataMedia = _data->createMediaView();
|
|
|
|
_dataMedia->goodThumbnailWanted();
|
2020-04-15 14:06:34 +00:00
|
|
|
_dataMedia->thumbnailWanted(parent()->fullId());
|
2020-05-21 13:13:29 +00:00
|
|
|
delegate()->registerHeavyItem(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Video::clearHeavyPart() {
|
|
|
|
_dataMedia = nullptr;
|
2020-03-27 11:40:50 +00:00
|
|
|
}
|
|
|
|
|
2017-09-26 11:49:16 +00:00
|
|
|
float64 Video::dataProgress() const {
|
2020-04-10 13:18:51 +00:00
|
|
|
ensureDataMediaCreated();
|
|
|
|
return _dataMedia->progress();
|
2017-09-26 11:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Video::dataFinished() const {
|
|
|
|
return !_data->loading();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Video::dataLoaded() const {
|
2020-04-10 13:18:51 +00:00
|
|
|
ensureDataMediaCreated();
|
|
|
|
return _dataMedia->loaded();
|
2017-09-26 11:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Video::iconAnimated() const {
|
|
|
|
return true;
|
|
|
|
}
|
2016-12-20 13:03:51 +00:00
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
TextState Video::getState(
|
2017-10-13 19:07:04 +00:00
|
|
|
QPoint point,
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request) const {
|
2017-06-21 21:38:31 +00:00
|
|
|
if (hasPoint(point)) {
|
2020-04-10 13:18:51 +00:00
|
|
|
ensureDataMediaCreated();
|
2019-03-06 06:49:41 +00:00
|
|
|
const auto link = (_data->loading() || _data->uploading())
|
2017-12-15 16:25:47 +00:00
|
|
|
? _cancell
|
2020-04-10 13:18:51 +00:00
|
|
|
: (dataLoaded() || _dataMedia->canBePlayed())
|
2019-03-06 06:49:41 +00:00
|
|
|
? _openl
|
2017-12-15 16:25:47 +00:00
|
|
|
: _savel;
|
|
|
|
return { parent(), link };
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
2017-10-13 19:07:04 +00:00
|
|
|
return {};
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 16:24:23 +00:00
|
|
|
void Video::updateStatusText() {
|
2016-04-12 21:31:28 +00:00
|
|
|
bool showPause = false;
|
2016-11-21 16:24:23 +00:00
|
|
|
int statusSize = 0;
|
2016-04-12 21:31:28 +00:00
|
|
|
if (_data->status == FileDownloadFailed || _data->status == FileUploadFailed) {
|
|
|
|
statusSize = FileStatusSizeFailed;
|
2017-12-25 14:17:00 +00:00
|
|
|
} else if (_data->uploading()) {
|
|
|
|
statusSize = _data->uploadingData->offset;
|
2020-04-09 14:02:09 +00:00
|
|
|
} else if (dataLoaded()) {
|
2016-04-12 21:31:28 +00:00
|
|
|
statusSize = FileStatusSizeLoaded;
|
|
|
|
} else {
|
|
|
|
statusSize = FileStatusSizeReady;
|
|
|
|
}
|
2016-11-21 16:24:23 +00:00
|
|
|
if (statusSize != _status.size()) {
|
|
|
|
int status = statusSize, size = _data->size;
|
2016-04-12 21:31:28 +00:00
|
|
|
if (statusSize >= 0 && statusSize < 0x7F000000) {
|
|
|
|
size = status;
|
|
|
|
status = FileStatusSizeReady;
|
|
|
|
}
|
2016-11-21 16:24:23 +00:00
|
|
|
_status.update(status, size, -1, 0);
|
|
|
|
_status.setSize(statusSize);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-05 15:35:52 +00:00
|
|
|
Voice::Voice(
|
2020-05-21 12:27:04 +00:00
|
|
|
not_null<Delegate*> delegate,
|
2017-10-05 15:35:52 +00:00
|
|
|
not_null<HistoryItem*> parent,
|
|
|
|
not_null<DocumentData*> voice,
|
|
|
|
const style::OverviewFileLayout &st)
|
2020-05-21 12:27:04 +00:00
|
|
|
: RadialProgressItem(delegate, parent)
|
2016-04-12 21:31:28 +00:00
|
|
|
, _data(voice)
|
2019-03-11 14:35:11 +00:00
|
|
|
, _namel(std::make_shared<DocumentOpenClickHandler>(_data, parent->fullId()))
|
2016-12-08 14:08:54 +00:00
|
|
|
, _st(st) {
|
2016-04-12 21:31:28 +00:00
|
|
|
AddComponents(Info::Bit());
|
|
|
|
|
|
|
|
setDocumentLinks(_data);
|
2019-01-25 14:37:28 +00:00
|
|
|
_data->loadThumbnail(parent->fullId());
|
2016-04-12 21:31:28 +00:00
|
|
|
|
|
|
|
updateName();
|
2018-02-03 19:52:35 +00:00
|
|
|
const auto dateText = textcmdLink(
|
|
|
|
1,
|
|
|
|
TextUtilities::EscapeForRichParsing(
|
2019-07-10 17:28:33 +00:00
|
|
|
langDateTime(base::unixtime::parse(_data->date))));
|
2016-04-12 21:31:28 +00:00
|
|
|
TextParseOptions opts = { TextParseRichText, 0, 0, Qt::LayoutDirectionAuto };
|
2018-02-03 19:52:35 +00:00
|
|
|
_details.setText(
|
|
|
|
st::defaultTextStyle,
|
2019-06-19 16:39:25 +00:00
|
|
|
tr::lng_date_and_duration(
|
|
|
|
tr::now,
|
2018-02-03 19:52:35 +00:00
|
|
|
lt_date,
|
|
|
|
dateText,
|
|
|
|
lt_duration,
|
2018-11-05 08:22:05 +00:00
|
|
|
formatDurationText(duration())),
|
2018-02-03 19:52:35 +00:00
|
|
|
opts);
|
2016-11-16 10:44:06 +00:00
|
|
|
_details.setLink(1, goToMessageClickHandler(parent));
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Voice::initDimensions() {
|
2016-12-08 14:08:54 +00:00
|
|
|
_maxw = _st.maxWidth;
|
|
|
|
_minh = _st.songPadding.top() + _st.songThumbSize + _st.songPadding.bottom() + st::lineWidth;
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 16:24:23 +00:00
|
|
|
void Voice::paint(Painter &p, const QRect &clip, TextSelection selection, const PaintContext *context) {
|
2020-04-10 13:18:51 +00:00
|
|
|
ensureDataMediaCreated();
|
2016-04-12 21:31:28 +00:00
|
|
|
bool selected = (selection == FullSelection);
|
2020-04-09 14:02:09 +00:00
|
|
|
bool loaded = dataLoaded(), displayLoading = _data->displayLoading();
|
2016-04-12 21:31:28 +00:00
|
|
|
|
|
|
|
if (displayLoading) {
|
|
|
|
ensureRadial();
|
|
|
|
if (!_radial->animating()) {
|
2020-04-10 13:18:51 +00:00
|
|
|
_radial->start(dataProgress());
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-04 15:24:13 +00:00
|
|
|
const auto showPause = updateStatusText();
|
|
|
|
const auto nameVersion = parent()->fromOriginal()->nameVersion;
|
2016-04-12 21:31:28 +00:00
|
|
|
if (nameVersion > _nameVersion) {
|
|
|
|
updateName();
|
|
|
|
}
|
2019-04-04 15:24:13 +00:00
|
|
|
const auto radial = isRadialAnimation();
|
2016-04-12 21:31:28 +00:00
|
|
|
|
2017-11-23 14:58:00 +00:00
|
|
|
const auto nameleft = _st.songPadding.left()
|
|
|
|
+ _st.songThumbSize
|
|
|
|
+ _st.songPadding.right();
|
|
|
|
const auto nameright = _st.songPadding.left();
|
|
|
|
const auto nametop = _st.songNameTop;
|
|
|
|
const auto statustop = _st.songStatusTop;
|
|
|
|
const auto namewidth = _width - nameleft - nameright;
|
|
|
|
|
2019-09-13 12:22:54 +00:00
|
|
|
const auto inner = style::rtlrect(
|
2017-11-23 14:58:00 +00:00
|
|
|
_st.songPadding.left(),
|
|
|
|
_st.songPadding.top(),
|
|
|
|
_st.songThumbSize,
|
|
|
|
_st.songThumbSize,
|
|
|
|
_width);
|
2016-04-12 21:31:28 +00:00
|
|
|
if (clip.intersects(inner)) {
|
2020-04-08 15:09:29 +00:00
|
|
|
if (_data->hasThumbnail()) {
|
|
|
|
ensureDataMediaCreated();
|
|
|
|
}
|
2020-04-15 14:06:34 +00:00
|
|
|
const auto thumbnail = _dataMedia
|
|
|
|
? _dataMedia->thumbnail()
|
|
|
|
: nullptr;
|
2020-04-08 15:09:29 +00:00
|
|
|
const auto blurred = _dataMedia
|
|
|
|
? _dataMedia->thumbnailInline()
|
|
|
|
: nullptr;
|
2020-04-15 14:06:34 +00:00
|
|
|
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
if (thumbnail || blurred) {
|
|
|
|
const auto thumb = thumbnail
|
2020-05-29 15:10:25 +00:00
|
|
|
? thumbnail->pixCircled(inner.width(), inner.height())
|
|
|
|
: blurred->pixBlurredCircled(inner.width(), inner.height());
|
2018-11-05 08:22:05 +00:00
|
|
|
p.drawPixmap(inner.topLeft(), thumb);
|
2019-01-25 14:37:28 +00:00
|
|
|
} else if (_data->hasThumbnail()) {
|
2018-11-05 08:22:05 +00:00
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.setBrush(st::imageBg);
|
|
|
|
p.drawEllipse(inner);
|
|
|
|
}
|
2019-03-11 14:35:11 +00:00
|
|
|
const auto &checkLink = (_data->loading() || _data->uploading())
|
|
|
|
? _cancell
|
2020-04-10 13:18:51 +00:00
|
|
|
: (_dataMedia->canBePlayed() || loaded)
|
2019-03-11 14:35:11 +00:00
|
|
|
? _openl
|
|
|
|
: _savel;
|
2016-04-12 21:31:28 +00:00
|
|
|
if (selected) {
|
2020-04-15 14:06:34 +00:00
|
|
|
p.setBrush((thumbnail || blurred) ? st::msgDateImgBgSelected : st::msgFileInBgSelected);
|
2019-01-25 14:37:28 +00:00
|
|
|
} else if (_data->hasThumbnail()) {
|
2019-03-11 14:35:11 +00:00
|
|
|
auto over = ClickHandler::showAsActive(checkLink);
|
2019-04-02 09:13:30 +00:00
|
|
|
p.setBrush(anim::brush(st::msgDateImgBg, st::msgDateImgBgOver, _a_iconOver.value(over ? 1. : 0.)));
|
2016-04-12 21:31:28 +00:00
|
|
|
} else {
|
2019-03-11 14:35:11 +00:00
|
|
|
auto over = ClickHandler::showAsActive(checkLink);
|
2019-04-02 09:13:30 +00:00
|
|
|
p.setBrush(anim::brush(st::msgFileInBg, st::msgFileInBgOver, _a_iconOver.value(over ? 1. : 0.)));
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
2016-12-03 12:10:35 +00:00
|
|
|
{
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.drawEllipse(inner);
|
|
|
|
}
|
2016-04-12 21:31:28 +00:00
|
|
|
|
|
|
|
if (radial) {
|
|
|
|
QRect rinner(inner.marginsRemoved(QMargins(st::msgFileRadialLine, st::msgFileRadialLine, st::msgFileRadialLine, st::msgFileRadialLine)));
|
2017-12-30 22:28:25 +00:00
|
|
|
auto &bg = selected ? st::historyFileInRadialFgSelected : st::historyFileInRadialFg;
|
2016-04-12 21:31:28 +00:00
|
|
|
_radial->draw(p, rinner, st::msgFileRadialLine, bg);
|
|
|
|
}
|
|
|
|
|
2019-03-11 14:35:11 +00:00
|
|
|
const auto icon = [&] {
|
2019-03-01 11:16:55 +00:00
|
|
|
if (_data->loading() || _data->uploading()) {
|
|
|
|
return &(selected ? _st.songCancelSelected : _st.songCancel);
|
|
|
|
} else if (showPause) {
|
2016-12-08 14:08:54 +00:00
|
|
|
return &(selected ? _st.songPauseSelected : _st.songPause);
|
2020-04-10 13:18:51 +00:00
|
|
|
} else if (_dataMedia->canBePlayed()) {
|
2016-12-08 14:08:54 +00:00
|
|
|
return &(selected ? _st.songPlaySelected : _st.songPlay);
|
2016-09-29 19:42:14 +00:00
|
|
|
}
|
2016-12-08 14:08:54 +00:00
|
|
|
return &(selected ? _st.songDownloadSelected : _st.songDownload);
|
2018-11-05 08:22:05 +00:00
|
|
|
}();
|
2016-09-29 19:42:14 +00:00
|
|
|
icon->paintInCenter(p, inner);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2019-09-13 12:22:54 +00:00
|
|
|
if (clip.intersects(style::rtlrect(nameleft, nametop, namewidth, st::semiboldFont->height, _width))) {
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::historyFileNameInFg);
|
2016-04-12 21:31:28 +00:00
|
|
|
_name.drawLeftElided(p, nameleft, nametop, namewidth, _width);
|
|
|
|
}
|
|
|
|
|
2019-09-13 12:22:54 +00:00
|
|
|
if (clip.intersects(style::rtlrect(nameleft, statustop, namewidth, st::normalFont->height, _width))) {
|
2016-04-12 21:31:28 +00:00
|
|
|
p.setFont(st::normalFont);
|
|
|
|
p.setPen(selected ? st::mediaInFgSelected : st::mediaInFg);
|
|
|
|
int32 unreadx = nameleft;
|
2016-11-21 16:24:23 +00:00
|
|
|
if (_status.size() == FileStatusSizeLoaded || _status.size() == FileStatusSizeReady) {
|
2016-12-23 13:21:01 +00:00
|
|
|
p.setTextPalette(selected ? st::mediaInPaletteSelected : st::mediaInPalette);
|
2016-04-12 21:31:28 +00:00
|
|
|
_details.drawLeftElided(p, nameleft, statustop, namewidth, _width);
|
2016-12-23 13:21:01 +00:00
|
|
|
p.restoreTextPalette();
|
2016-04-12 21:31:28 +00:00
|
|
|
unreadx += _details.maxWidth();
|
|
|
|
} else {
|
2016-11-21 16:24:23 +00:00
|
|
|
int32 statusw = st::normalFont->width(_status.text());
|
|
|
|
p.drawTextLeft(nameleft, statustop, _width, _status.text(), statusw);
|
2016-04-12 21:31:28 +00:00
|
|
|
unreadx += statusw;
|
|
|
|
}
|
2018-12-26 10:28:24 +00:00
|
|
|
if (parent()->hasUnreadMediaFlag() && unreadx + st::mediaUnreadSkip + st::mediaUnreadSize <= _width) {
|
2016-04-12 21:31:28 +00:00
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setBrush(selected ? st::msgFileInBgSelected : st::msgFileInBg);
|
|
|
|
|
2016-12-03 12:10:35 +00:00
|
|
|
{
|
|
|
|
PainterHighQualityEnabler hq(p);
|
2019-09-13 12:22:54 +00:00
|
|
|
p.drawEllipse(style::rtlrect(unreadx + st::mediaUnreadSkip, statustop + st::mediaUnreadTop, st::mediaUnreadSize, st::mediaUnreadSize, _width));
|
2016-12-03 12:10:35 +00:00
|
|
|
}
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-23 14:58:00 +00:00
|
|
|
|
|
|
|
const auto checkDelta = _st.songThumbSize
|
|
|
|
+ st::overviewCheckSkip
|
|
|
|
- st::overviewSmallCheck.size;
|
|
|
|
const auto checkLeft = _st.songPadding.left() + checkDelta;
|
|
|
|
const auto checkTop = _st.songPadding.top() + checkDelta;
|
|
|
|
paintCheckbox(p, { checkLeft, checkTop }, selected, context);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
TextState Voice::getState(
|
2017-10-13 19:07:04 +00:00
|
|
|
QPoint point,
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request) const {
|
2020-04-10 13:18:51 +00:00
|
|
|
ensureDataMediaCreated();
|
2020-04-09 14:02:09 +00:00
|
|
|
const auto loaded = dataLoaded();
|
2017-11-23 14:58:00 +00:00
|
|
|
|
|
|
|
const auto nameleft = _st.songPadding.left()
|
|
|
|
+ _st.songThumbSize
|
|
|
|
+ _st.songPadding.right();
|
|
|
|
const auto nameright = _st.songPadding.left();
|
|
|
|
const auto nametop = _st.songNameTop;
|
|
|
|
const auto statustop = _st.songStatusTop;
|
|
|
|
|
2019-09-13 12:22:54 +00:00
|
|
|
const auto inner = style::rtlrect(
|
2017-11-23 14:58:00 +00:00
|
|
|
_st.songPadding.left(),
|
|
|
|
_st.songPadding.top(),
|
|
|
|
_st.songThumbSize,
|
|
|
|
_st.songThumbSize,
|
|
|
|
_width);
|
2017-06-21 21:38:31 +00:00
|
|
|
if (inner.contains(point)) {
|
2019-03-11 14:35:11 +00:00
|
|
|
const auto link = (_data->loading() || _data->uploading())
|
2017-12-15 16:25:47 +00:00
|
|
|
? _cancell
|
2020-04-10 13:18:51 +00:00
|
|
|
: (_dataMedia->canBePlayed() || loaded)
|
2019-03-11 14:35:11 +00:00
|
|
|
? _openl
|
|
|
|
: _savel;
|
2017-12-15 16:25:47 +00:00
|
|
|
return { parent(), link };
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
2018-01-27 13:59:24 +00:00
|
|
|
auto result = TextState(parent());
|
2017-11-23 14:58:00 +00:00
|
|
|
const auto statusmaxwidth = _width - nameleft - nameright;
|
2019-09-13 12:22:54 +00:00
|
|
|
const auto statusrect = style::rtlrect(
|
2017-11-23 14:58:00 +00:00
|
|
|
nameleft,
|
|
|
|
statustop,
|
|
|
|
statusmaxwidth,
|
|
|
|
st::normalFont->height,
|
|
|
|
_width);
|
|
|
|
if (statusrect.contains(point)) {
|
2016-11-21 16:24:23 +00:00
|
|
|
if (_status.size() == FileStatusSizeLoaded || _status.size() == FileStatusSizeReady) {
|
2017-06-21 21:38:31 +00:00
|
|
|
auto textState = _details.getStateLeft(point - QPoint(nameleft, statustop), _width, _width);
|
2017-10-13 19:07:04 +00:00
|
|
|
result.link = textState.link;
|
2018-01-27 13:59:24 +00:00
|
|
|
result.cursor = textState.uponSymbol
|
|
|
|
? HistoryView::CursorState::Text
|
|
|
|
: HistoryView::CursorState::None;
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-23 14:58:00 +00:00
|
|
|
const auto namewidth = std::min(
|
|
|
|
_width - nameleft - nameright,
|
|
|
|
_name.maxWidth());
|
2019-09-13 12:22:54 +00:00
|
|
|
const auto namerect = style::rtlrect(
|
2017-11-23 14:58:00 +00:00
|
|
|
nameleft,
|
|
|
|
nametop,
|
|
|
|
namewidth,
|
|
|
|
st::normalFont->height,
|
|
|
|
_width);
|
|
|
|
if (namerect.contains(point) && !result.link && !_data->loading()) {
|
2017-12-15 16:25:47 +00:00
|
|
|
return { parent(), _namel };
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
2017-10-13 19:07:04 +00:00
|
|
|
return result;
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2020-04-08 15:09:29 +00:00
|
|
|
void Voice::ensureDataMediaCreated() const {
|
|
|
|
if (_dataMedia) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_dataMedia = _data->createMediaView();
|
2020-05-21 13:13:29 +00:00
|
|
|
delegate()->registerHeavyItem(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Voice::clearHeavyPart() {
|
|
|
|
_dataMedia = nullptr;
|
2020-04-08 15:09:29 +00:00
|
|
|
}
|
|
|
|
|
2017-09-26 11:49:16 +00:00
|
|
|
float64 Voice::dataProgress() const {
|
2020-04-10 13:18:51 +00:00
|
|
|
ensureDataMediaCreated();
|
|
|
|
return _dataMedia->progress();
|
2017-09-26 11:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Voice::dataFinished() const {
|
|
|
|
return !_data->loading();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Voice::dataLoaded() const {
|
2020-04-10 13:18:51 +00:00
|
|
|
ensureDataMediaCreated();
|
|
|
|
return _dataMedia->loaded();
|
2017-09-26 11:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Voice::iconAnimated() const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-23 14:58:00 +00:00
|
|
|
const style::RoundCheckbox &Voice::checkboxStyle() const {
|
|
|
|
return st::overviewSmallCheck;
|
|
|
|
}
|
|
|
|
|
2016-11-21 16:24:23 +00:00
|
|
|
void Voice::updateName() {
|
2017-04-30 12:44:17 +00:00
|
|
|
auto version = 0;
|
2017-12-18 15:44:50 +00:00
|
|
|
if (const auto forwarded = parent()->Get<HistoryMessageForwarded>()) {
|
2017-11-23 14:58:00 +00:00
|
|
|
if (parent()->fromOriginal()->isChannel()) {
|
2019-09-13 06:06:02 +00:00
|
|
|
_name.setText(st::semiboldTextStyle, tr::lng_forwarded_channel(tr::now, lt_channel, parent()->fromOriginal()->name), Ui::NameTextOptions());
|
2016-04-12 21:31:28 +00:00
|
|
|
} else {
|
2019-09-13 06:06:02 +00:00
|
|
|
_name.setText(st::semiboldTextStyle, tr::lng_forwarded(tr::now, lt_user, parent()->fromOriginal()->name), Ui::NameTextOptions());
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
} else {
|
2019-09-13 06:06:02 +00:00
|
|
|
_name.setText(st::semiboldTextStyle, parent()->from()->name, Ui::NameTextOptions());
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
2017-11-23 14:58:00 +00:00
|
|
|
version = parent()->fromOriginal()->nameVersion;
|
2016-04-12 21:31:28 +00:00
|
|
|
_nameVersion = version;
|
|
|
|
}
|
|
|
|
|
2018-11-05 08:22:05 +00:00
|
|
|
int Voice::duration() const {
|
2019-03-06 08:21:42 +00:00
|
|
|
return std::max(_data->getDuration(), 0);
|
2018-11-05 08:22:05 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 16:24:23 +00:00
|
|
|
bool Voice::updateStatusText() {
|
2016-04-12 21:31:28 +00:00
|
|
|
bool showPause = false;
|
|
|
|
int32 statusSize = 0, realDuration = 0;
|
|
|
|
if (_data->status == FileDownloadFailed || _data->status == FileUploadFailed) {
|
|
|
|
statusSize = FileStatusSizeFailed;
|
2020-04-09 14:02:09 +00:00
|
|
|
} else if (dataLoaded()) {
|
2016-07-10 13:02:22 +00:00
|
|
|
statusSize = FileStatusSizeLoaded;
|
2016-04-12 21:31:28 +00:00
|
|
|
} else {
|
|
|
|
statusSize = FileStatusSizeReady;
|
|
|
|
}
|
2019-02-28 21:03:25 +00:00
|
|
|
|
|
|
|
const auto state = Media::Player::instance()->getState(AudioMsgId::Type::Voice);
|
|
|
|
if (state.id == AudioMsgId(_data, parent()->fullId(), state.id.externalPlayId())
|
|
|
|
&& !Media::Player::IsStoppedOrStopping(state.state)) {
|
|
|
|
statusSize = -1 - (state.position / state.frequency);
|
|
|
|
realDuration = (state.length / state.frequency);
|
|
|
|
showPause = Media::Player::ShowPauseIcon(state.state);
|
|
|
|
}
|
|
|
|
|
2016-11-21 16:24:23 +00:00
|
|
|
if (statusSize != _status.size()) {
|
2018-11-05 08:22:05 +00:00
|
|
|
_status.update(statusSize, _data->size, duration(), realDuration);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
return showPause;
|
|
|
|
}
|
|
|
|
|
2017-10-05 15:35:52 +00:00
|
|
|
Document::Document(
|
2020-05-21 12:27:04 +00:00
|
|
|
not_null<Delegate*> delegate,
|
2017-10-05 15:35:52 +00:00
|
|
|
not_null<HistoryItem*> parent,
|
|
|
|
not_null<DocumentData*> document,
|
|
|
|
const style::OverviewFileLayout &st)
|
2020-05-21 12:27:04 +00:00
|
|
|
: RadialProgressItem(delegate, parent)
|
2016-04-12 21:31:28 +00:00
|
|
|
, _data(document)
|
2016-11-16 10:44:06 +00:00
|
|
|
, _msgl(goToMessageClickHandler(parent))
|
2018-01-11 13:07:29 +00:00
|
|
|
, _namel(std::make_shared<DocumentOpenClickHandler>(_data, parent->fullId()))
|
2016-10-13 15:04:40 +00:00
|
|
|
, _st(st)
|
2019-07-10 17:28:33 +00:00
|
|
|
, _date(langDateTime(base::unixtime::parse(_data->date)))
|
2016-04-12 21:31:28 +00:00
|
|
|
, _datew(st::normalFont->width(_date))
|
|
|
|
, _colorIndex(documentColorIndex(_data, _ext)) {
|
2017-03-10 14:14:10 +00:00
|
|
|
_name.setMarkedText(st::defaultTextStyle, ComposeNameWithEntities(_data), _documentNameOptions);
|
2016-10-13 15:04:40 +00:00
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
AddComponents(Info::Bit());
|
|
|
|
|
|
|
|
setDocumentLinks(_data);
|
|
|
|
|
2017-12-10 10:26:58 +00:00
|
|
|
_status.update(FileStatusSizeReady, _data->size, _data->isSong() ? _data->song()->duration : -1, 0);
|
2016-04-12 21:31:28 +00:00
|
|
|
|
|
|
|
if (withThumb()) {
|
2019-01-25 14:37:28 +00:00
|
|
|
_data->loadThumbnail(parent->fullId());
|
2020-04-15 14:06:34 +00:00
|
|
|
auto tw = style::ConvertScale(_data->thumbnailLocation().width());
|
|
|
|
auto th = style::ConvertScale(_data->thumbnailLocation().height());
|
2016-04-12 21:31:28 +00:00
|
|
|
if (tw > th) {
|
2016-10-13 15:04:40 +00:00
|
|
|
_thumbw = (tw * _st.fileThumbSize) / th;
|
2016-04-12 21:31:28 +00:00
|
|
|
} else {
|
2016-10-13 15:04:40 +00:00
|
|
|
_thumbw = _st.fileThumbSize;
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_thumbw = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
_extw = st::overviewFileExtFont->width(_ext);
|
2016-10-13 15:04:40 +00:00
|
|
|
if (_extw > _st.fileThumbSize - st::overviewFileExtPadding * 2) {
|
|
|
|
_ext = st::overviewFileExtFont->elided(_ext, _st.fileThumbSize - st::overviewFileExtPadding * 2, Qt::ElideMiddle);
|
2016-04-12 21:31:28 +00:00
|
|
|
_extw = st::overviewFileExtFont->width(_ext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-15 12:09:05 +00:00
|
|
|
bool Document::downloadInCorner() const {
|
|
|
|
return _data->isAudioFile()
|
|
|
|
&& _data->canBeStreamed()
|
|
|
|
&& !_data->inappPlaybackFailed()
|
|
|
|
&& IsServerMsgId(parent()->id);
|
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
void Document::initDimensions() {
|
2016-10-13 15:04:40 +00:00
|
|
|
_maxw = _st.maxWidth;
|
2018-11-13 17:14:41 +00:00
|
|
|
if (_data->isSong()) {
|
2016-10-13 15:04:40 +00:00
|
|
|
_minh = _st.songPadding.top() + _st.songThumbSize + _st.songPadding.bottom();
|
2016-04-12 21:31:28 +00:00
|
|
|
} else {
|
2016-10-13 15:04:40 +00:00
|
|
|
_minh = _st.filePadding.top() + _st.fileThumbSize + _st.filePadding.bottom() + st::lineWidth;
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-21 16:24:23 +00:00
|
|
|
void Document::paint(Painter &p, const QRect &clip, TextSelection selection, const PaintContext *context) {
|
2020-04-10 13:18:51 +00:00
|
|
|
ensureDataMediaCreated();
|
|
|
|
|
2019-04-04 15:24:13 +00:00
|
|
|
const auto selected = (selection == FullSelection);
|
2016-04-12 21:31:28 +00:00
|
|
|
|
2019-03-15 12:09:05 +00:00
|
|
|
const auto cornerDownload = downloadInCorner();
|
|
|
|
|
2020-04-10 14:19:43 +00:00
|
|
|
_dataMedia->automaticLoad(parent()->fullId(), parent());
|
2020-04-09 14:02:09 +00:00
|
|
|
const auto loaded = dataLoaded();
|
2019-04-04 15:24:13 +00:00
|
|
|
const auto displayLoading = _data->displayLoading();
|
2016-04-12 21:31:28 +00:00
|
|
|
|
|
|
|
if (displayLoading) {
|
|
|
|
ensureRadial();
|
|
|
|
if (!_radial->animating()) {
|
2020-04-10 13:18:51 +00:00
|
|
|
_radial->start(dataProgress());
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-04 15:24:13 +00:00
|
|
|
const auto showPause = updateStatusText();
|
|
|
|
const auto radial = isRadialAnimation();
|
2016-04-12 21:31:28 +00:00
|
|
|
|
|
|
|
int32 nameleft = 0, nametop = 0, nameright = 0, statustop = 0, datetop = -1;
|
2019-04-04 15:24:13 +00:00
|
|
|
const auto wthumb = withThumb();
|
2016-04-12 21:31:28 +00:00
|
|
|
|
2019-04-04 15:24:13 +00:00
|
|
|
const auto isSong = _data->isSong();
|
2017-06-28 06:37:49 +00:00
|
|
|
if (isSong) {
|
2016-10-13 15:04:40 +00:00
|
|
|
nameleft = _st.songPadding.left() + _st.songThumbSize + _st.songPadding.right();
|
|
|
|
nameright = _st.songPadding.left();
|
|
|
|
nametop = _st.songNameTop;
|
|
|
|
statustop = _st.songStatusTop;
|
2016-04-12 21:31:28 +00:00
|
|
|
|
2019-09-13 12:22:54 +00:00
|
|
|
auto inner = style::rtlrect(_st.songPadding.left(), _st.songPadding.top(), _st.songThumbSize, _st.songThumbSize, _width);
|
2016-04-12 21:31:28 +00:00
|
|
|
if (clip.intersects(inner)) {
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
if (selected) {
|
|
|
|
p.setBrush(st::msgFileInBgSelected);
|
|
|
|
} else {
|
2020-04-10 13:18:51 +00:00
|
|
|
auto over = ClickHandler::showAsActive((!cornerDownload && (_data->loading() || _data->uploading())) ? _cancell : (loaded || _dataMedia->canBePlayed()) ? _openl : _savel);
|
2019-04-02 09:13:30 +00:00
|
|
|
p.setBrush(anim::brush(_st.songIconBg, _st.songOverBg, _a_iconOver.value(over ? 1. : 0.)));
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2016-12-03 12:10:35 +00:00
|
|
|
{
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.drawEllipse(inner);
|
|
|
|
}
|
2016-04-12 21:31:28 +00:00
|
|
|
|
2019-03-15 12:09:05 +00:00
|
|
|
const auto icon = [&] {
|
|
|
|
if (!cornerDownload && (_data->loading() || _data->uploading())) {
|
2016-12-08 14:08:54 +00:00
|
|
|
return &(selected ? _st.songCancelSelected : _st.songCancel);
|
2019-03-01 11:16:55 +00:00
|
|
|
} else if (showPause) {
|
|
|
|
return &(selected ? _st.songPauseSelected : _st.songPause);
|
2020-04-10 13:18:51 +00:00
|
|
|
} else if (loaded || _dataMedia->canBePlayed()) {
|
2019-02-28 21:03:25 +00:00
|
|
|
return &(selected ? _st.songPlaySelected : _st.songPlay);
|
2016-09-29 19:42:14 +00:00
|
|
|
}
|
2016-12-08 14:08:54 +00:00
|
|
|
return &(selected ? _st.songDownloadSelected : _st.songDownload);
|
2018-11-05 08:22:05 +00:00
|
|
|
}();
|
2016-09-29 19:42:14 +00:00
|
|
|
icon->paintInCenter(p, inner);
|
2019-03-15 12:09:05 +00:00
|
|
|
|
|
|
|
if (radial && !cornerDownload) {
|
|
|
|
auto rinner = inner.marginsRemoved(QMargins(st::msgFileRadialLine, st::msgFileRadialLine, st::msgFileRadialLine, st::msgFileRadialLine));
|
|
|
|
auto &bg = selected ? st::historyFileInRadialFgSelected : st::historyFileInRadialFg;
|
|
|
|
_radial->draw(p, rinner, st::msgFileRadialLine, bg);
|
|
|
|
}
|
|
|
|
|
|
|
|
drawCornerDownload(p, selected, context);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-10-13 15:04:40 +00:00
|
|
|
nameleft = _st.fileThumbSize + _st.filePadding.right();
|
|
|
|
nametop = st::linksBorder + _st.fileNameTop;
|
|
|
|
statustop = st::linksBorder + _st.fileStatusTop;
|
|
|
|
datetop = st::linksBorder + _st.fileDateTop;
|
2016-04-12 21:31:28 +00:00
|
|
|
|
2019-09-13 12:22:54 +00:00
|
|
|
QRect border(style::rtlrect(nameleft, 0, _width - nameleft, st::linksBorder, _width));
|
2016-04-12 21:31:28 +00:00
|
|
|
if (!context->isAfterDate && clip.intersects(border)) {
|
|
|
|
p.fillRect(clip.intersected(border), st::linksBorderFg);
|
|
|
|
}
|
|
|
|
|
2019-09-13 12:22:54 +00:00
|
|
|
QRect rthumb(style::rtlrect(0, st::linksBorder + _st.filePadding.top(), _st.fileThumbSize, _st.fileThumbSize, _width));
|
2016-04-12 21:31:28 +00:00
|
|
|
if (clip.intersects(rthumb)) {
|
|
|
|
if (wthumb) {
|
2020-04-08 15:09:29 +00:00
|
|
|
ensureDataMediaCreated();
|
2020-04-15 14:06:34 +00:00
|
|
|
const auto thumbnail = _dataMedia->thumbnail();
|
|
|
|
const auto thumbLoaded = (thumbnail != nullptr);
|
2020-04-08 15:09:29 +00:00
|
|
|
const auto blurred = _dataMedia->thumbnailInline();
|
2020-04-15 14:06:34 +00:00
|
|
|
if (thumbnail || blurred) {
|
|
|
|
if (_thumb.isNull() || (thumbnail && !_thumbLoaded)) {
|
|
|
|
_thumbLoaded = (thumbnail != nullptr);
|
|
|
|
auto options = Images::Option::Smooth
|
|
|
|
| (_thumbLoaded
|
|
|
|
? Images::Option::None
|
|
|
|
: Images::Option::Blurred);
|
|
|
|
const auto image = thumbnail ? thumbnail : blurred;
|
2020-05-29 15:10:25 +00:00
|
|
|
_thumb = image->pixNoCache(_thumbw * cIntRetinaFactor(), 0, options, _st.fileThumbSize, _st.fileThumbSize);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
p.drawPixmap(rthumb.topLeft(), _thumb);
|
|
|
|
} else {
|
2016-10-31 12:29:26 +00:00
|
|
|
p.fillRect(rthumb, st::overviewFileThumbBg);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
p.fillRect(rthumb, documentColor(_colorIndex));
|
|
|
|
if (!radial && loaded && !_ext.isEmpty()) {
|
|
|
|
p.setFont(st::overviewFileExtFont);
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::overviewFileExtFg);
|
2016-04-12 21:31:28 +00:00
|
|
|
p.drawText(rthumb.left() + (rthumb.width() - _extw) / 2, rthumb.top() + st::overviewFileExtTop + st::overviewFileExtFont->ascent, _ext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (selected) {
|
2016-12-23 13:21:01 +00:00
|
|
|
p.fillRect(rthumb, st::defaultTextPalette.selectOverlay);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (radial || (!loaded && !_data->loading())) {
|
2016-10-13 15:04:40 +00:00
|
|
|
QRect inner(rthumb.x() + (rthumb.width() - _st.songThumbSize) / 2, rthumb.y() + (rthumb.height() - _st.songThumbSize) / 2, _st.songThumbSize, _st.songThumbSize);
|
2016-04-12 21:31:28 +00:00
|
|
|
if (clip.intersects(inner)) {
|
2016-10-31 12:29:26 +00:00
|
|
|
auto radialOpacity = (radial && loaded && !_data->uploading()) ? _radial->opacity() : 1;
|
2016-04-12 21:31:28 +00:00
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
if (selected) {
|
|
|
|
p.setBrush(wthumb ? st::msgDateImgBgSelected : documentSelectedColor(_colorIndex));
|
|
|
|
} else {
|
2016-10-31 12:29:26 +00:00
|
|
|
auto over = ClickHandler::showAsActive(_data->loading() ? _cancell : _savel);
|
2019-04-02 09:13:30 +00:00
|
|
|
p.setBrush(anim::brush(wthumb ? st::msgDateImgBg : documentDarkColor(_colorIndex), wthumb ? st::msgDateImgBgOver : documentOverColor(_colorIndex), _a_iconOver.value(over ? 1. : 0.)));
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
p.setOpacity(radialOpacity * p.opacity());
|
|
|
|
|
2016-12-03 12:10:35 +00:00
|
|
|
{
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.drawEllipse(inner);
|
|
|
|
}
|
2016-04-12 21:31:28 +00:00
|
|
|
|
|
|
|
p.setOpacity(radialOpacity);
|
2016-09-29 19:42:14 +00:00
|
|
|
auto icon = ([loaded, this, selected] {
|
|
|
|
if (loaded || _data->loading()) {
|
2017-01-11 08:16:44 +00:00
|
|
|
return &(selected ? st::historyFileThumbCancelSelected : st::historyFileThumbCancel);
|
2016-09-29 19:42:14 +00:00
|
|
|
}
|
2017-01-11 08:16:44 +00:00
|
|
|
return &(selected ? st::historyFileThumbDownloadSelected : st::historyFileThumbDownload);
|
2016-09-29 19:42:14 +00:00
|
|
|
})();
|
|
|
|
icon->paintInCenter(p, inner);
|
2016-04-12 21:31:28 +00:00
|
|
|
if (radial) {
|
|
|
|
p.setOpacity(1);
|
|
|
|
|
|
|
|
QRect rinner(inner.marginsRemoved(QMargins(st::msgFileRadialLine, st::msgFileRadialLine, st::msgFileRadialLine, st::msgFileRadialLine)));
|
2017-01-11 08:16:44 +00:00
|
|
|
_radial->draw(p, rinner, st::msgFileRadialLine, selected ? st::historyFileThumbRadialFgSelected : st::historyFileThumbRadialFg);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-23 14:58:00 +00:00
|
|
|
const auto availwidth = _width - nameleft - nameright;
|
|
|
|
const auto namewidth = std::min(availwidth, _name.maxWidth());
|
2019-09-13 12:22:54 +00:00
|
|
|
if (clip.intersects(style::rtlrect(nameleft, nametop, namewidth, st::semiboldFont->height, _width))) {
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::historyFileNameInFg);
|
2016-10-13 15:04:40 +00:00
|
|
|
_name.drawLeftElided(p, nameleft, nametop, namewidth, _width);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2019-09-13 12:22:54 +00:00
|
|
|
if (clip.intersects(style::rtlrect(nameleft, statustop, availwidth, st::normalFont->height, _width))) {
|
2016-04-12 21:31:28 +00:00
|
|
|
p.setFont(st::normalFont);
|
2017-06-28 06:37:49 +00:00
|
|
|
p.setPen((isSong && selected) ? st::mediaInFgSelected : st::mediaInFg);
|
2016-11-21 16:24:23 +00:00
|
|
|
p.drawTextLeft(nameleft, statustop, _width, _status.text());
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
2019-09-13 12:22:54 +00:00
|
|
|
if (datetop >= 0 && clip.intersects(style::rtlrect(nameleft, datetop, _datew, st::normalFont->height, _width))) {
|
2016-04-12 21:31:28 +00:00
|
|
|
p.setFont(ClickHandler::showAsActive(_msgl) ? st::normalFont->underline() : st::normalFont);
|
|
|
|
p.setPen(st::mediaInFg);
|
|
|
|
p.drawTextLeft(nameleft, datetop, _width, _date, _datew);
|
|
|
|
}
|
2017-11-23 14:58:00 +00:00
|
|
|
|
|
|
|
const auto checkDelta = (isSong ? _st.songThumbSize : _st.fileThumbSize)
|
|
|
|
+ (isSong ? st::overviewCheckSkip : -st::overviewCheckSkip)
|
|
|
|
- st::overviewSmallCheck.size;
|
|
|
|
const auto checkLeft = (isSong
|
|
|
|
? _st.songPadding.left()
|
|
|
|
: 0) + checkDelta;
|
|
|
|
const auto checkTop = (isSong
|
|
|
|
? _st.songPadding.top()
|
|
|
|
: (st::linksBorder + _st.filePadding.top())) + checkDelta;
|
|
|
|
paintCheckbox(p, { checkLeft, checkTop }, selected, context);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2019-03-15 12:09:05 +00:00
|
|
|
void Document::drawCornerDownload(Painter &p, bool selected, const PaintContext *context) const {
|
2020-04-09 14:02:09 +00:00
|
|
|
if (dataLoaded()
|
2019-06-04 15:59:26 +00:00
|
|
|
|| _data->loadedInMediaCache()
|
|
|
|
|| !downloadInCorner()) {
|
2019-03-15 12:09:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto size = st::overviewSmallCheck.size;
|
|
|
|
const auto shift = _st.songThumbSize + st::overviewCheckSkip - size;
|
2019-09-13 12:22:54 +00:00
|
|
|
const auto inner = style::rtlrect(_st.songPadding.left() + shift, _st.songPadding.top() + shift, size, size, _width);
|
2019-03-15 12:09:05 +00:00
|
|
|
auto pen = st::windowBg->p;
|
|
|
|
pen.setWidth(st::lineWidth);
|
|
|
|
p.setPen(pen);
|
|
|
|
if (selected) {
|
|
|
|
p.setBrush(st::msgFileInBgSelected);
|
|
|
|
} else {
|
|
|
|
p.setBrush(_st.songIconBg);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.drawEllipse(inner);
|
|
|
|
}
|
|
|
|
const auto icon = [&] {
|
|
|
|
if (_data->loading()) {
|
|
|
|
return &(selected ? st::overviewSmallCancelSelected : st::overviewSmallCancel);
|
|
|
|
}
|
|
|
|
return &(selected ? st::overviewSmallDownloadSelected : st::overviewSmallDownload);
|
|
|
|
}();
|
|
|
|
icon->paintInCenter(p, inner);
|
|
|
|
if (_radial && _radial->animating()) {
|
|
|
|
const auto rinner = inner.marginsRemoved(QMargins(st::historyAudioRadialLine, st::historyAudioRadialLine, st::historyAudioRadialLine, st::historyAudioRadialLine));
|
|
|
|
auto fg = selected ? st::historyFileThumbRadialFgSelected : st::historyFileThumbRadialFg;
|
|
|
|
_radial->draw(p, rinner, st::historyAudioRadialLine, fg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TextState Document::cornerDownloadTextState(
|
|
|
|
QPoint point,
|
|
|
|
StateRequest request) const {
|
|
|
|
auto result = TextState(parent());
|
2019-06-04 15:59:26 +00:00
|
|
|
if (!downloadInCorner()
|
2020-04-09 14:02:09 +00:00
|
|
|
|| dataLoaded()
|
2019-06-04 15:59:26 +00:00
|
|
|
|| _data->loadedInMediaCache()) {
|
2019-03-15 12:09:05 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
const auto size = st::overviewSmallCheck.size;
|
|
|
|
const auto shift = _st.songThumbSize + st::overviewCheckSkip - size;
|
2019-09-13 12:22:54 +00:00
|
|
|
const auto inner = style::rtlrect(_st.songPadding.left() + shift, _st.songPadding.top() + shift, size, size, _width);
|
2019-03-15 12:09:05 +00:00
|
|
|
if (inner.contains(point)) {
|
|
|
|
result.link = _data->loading() ? _cancell : _savel;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
TextState Document::getState(
|
2017-10-13 19:07:04 +00:00
|
|
|
QPoint point,
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request) const {
|
2020-04-10 13:18:51 +00:00
|
|
|
ensureDataMediaCreated();
|
2020-04-09 14:02:09 +00:00
|
|
|
const auto loaded = dataLoaded();
|
2017-11-23 14:58:00 +00:00
|
|
|
const auto wthumb = withThumb();
|
2016-04-12 21:31:28 +00:00
|
|
|
|
2018-11-13 17:14:41 +00:00
|
|
|
if (_data->isSong()) {
|
2017-11-23 14:58:00 +00:00
|
|
|
const auto nameleft = _st.songPadding.left() + _st.songThumbSize + _st.songPadding.right();
|
|
|
|
const auto nameright = _st.songPadding.left();
|
|
|
|
const auto namewidth = std::min(
|
|
|
|
_width - nameleft - nameright,
|
|
|
|
_name.maxWidth());
|
|
|
|
const auto nametop = _st.songNameTop;
|
|
|
|
const auto statustop = _st.songStatusTop;
|
|
|
|
|
2019-03-15 12:09:05 +00:00
|
|
|
if (const auto state = cornerDownloadTextState(point, request); state.link) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2019-09-13 12:22:54 +00:00
|
|
|
const auto inner = style::rtlrect(
|
2017-11-23 14:58:00 +00:00
|
|
|
_st.songPadding.left(),
|
|
|
|
_st.songPadding.top(),
|
|
|
|
_st.songThumbSize,
|
|
|
|
_st.songThumbSize,
|
|
|
|
_width);
|
2017-06-21 21:38:31 +00:00
|
|
|
if (inner.contains(point)) {
|
2019-06-04 15:59:26 +00:00
|
|
|
const auto link = (!downloadInCorner()
|
|
|
|
&& (_data->loading() || _data->uploading()))
|
2017-12-15 16:25:47 +00:00
|
|
|
? _cancell
|
2020-04-10 13:18:51 +00:00
|
|
|
: (loaded || _dataMedia->canBePlayed())
|
2019-02-28 21:03:25 +00:00
|
|
|
? _openl
|
2019-03-01 11:16:55 +00:00
|
|
|
: _savel;
|
2017-12-15 16:25:47 +00:00
|
|
|
return { parent(), link };
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
2019-09-13 12:22:54 +00:00
|
|
|
const auto namerect = style::rtlrect(
|
2017-11-23 14:58:00 +00:00
|
|
|
nameleft,
|
|
|
|
nametop,
|
|
|
|
namewidth,
|
|
|
|
st::semiboldFont->height,
|
|
|
|
_width);
|
|
|
|
if (namerect.contains(point) && !_data->loading()) {
|
2017-12-15 16:25:47 +00:00
|
|
|
return { parent(), _namel };
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
} else {
|
2017-11-23 14:58:00 +00:00
|
|
|
const auto nameleft = _st.fileThumbSize + _st.filePadding.right();
|
|
|
|
const auto nameright = 0;
|
|
|
|
const auto nametop = st::linksBorder + _st.fileNameTop;
|
|
|
|
const auto namewidth = std::min(
|
|
|
|
_width - nameleft - nameright,
|
|
|
|
_name.maxWidth());
|
|
|
|
const auto statustop = st::linksBorder + _st.fileStatusTop;
|
|
|
|
const auto datetop = st::linksBorder + _st.fileDateTop;
|
|
|
|
|
2019-09-13 12:22:54 +00:00
|
|
|
const auto rthumb = style::rtlrect(
|
2017-11-23 14:58:00 +00:00
|
|
|
0,
|
|
|
|
st::linksBorder + _st.filePadding.top(),
|
|
|
|
_st.fileThumbSize,
|
|
|
|
_st.fileThumbSize,
|
|
|
|
_width);
|
2016-04-12 21:31:28 +00:00
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
if (rthumb.contains(point)) {
|
2019-03-01 11:16:55 +00:00
|
|
|
const auto link = (_data->loading() || _data->uploading())
|
2017-12-15 16:25:47 +00:00
|
|
|
? _cancell
|
2019-03-01 11:16:55 +00:00
|
|
|
: loaded
|
|
|
|
? _openl
|
2017-12-15 16:25:47 +00:00
|
|
|
: _savel;
|
|
|
|
return { parent(), link };
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_data->status != FileUploadFailed) {
|
2019-09-13 12:22:54 +00:00
|
|
|
auto daterect = style::rtlrect(
|
2017-11-23 14:58:00 +00:00
|
|
|
nameleft,
|
|
|
|
datetop,
|
|
|
|
_datew,
|
|
|
|
st::normalFont->height,
|
|
|
|
_width);
|
|
|
|
if (daterect.contains(point)) {
|
2017-12-15 16:25:47 +00:00
|
|
|
return { parent(), _msgl };
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-25 14:37:28 +00:00
|
|
|
if (!_data->loading() && !_data->isNull()) {
|
2019-09-13 12:22:54 +00:00
|
|
|
auto leftofnamerect = style::rtlrect(
|
2017-11-23 14:58:00 +00:00
|
|
|
0,
|
|
|
|
st::linksBorder,
|
|
|
|
nameleft,
|
|
|
|
_height - st::linksBorder,
|
|
|
|
_width);
|
|
|
|
if (loaded && leftofnamerect.contains(point)) {
|
2017-12-15 16:25:47 +00:00
|
|
|
return { parent(), _namel };
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
2019-09-13 12:22:54 +00:00
|
|
|
const auto namerect = style::rtlrect(
|
2017-11-23 14:58:00 +00:00
|
|
|
nameleft,
|
|
|
|
nametop,
|
|
|
|
namewidth,
|
|
|
|
st::semiboldFont->height,
|
|
|
|
_width);
|
|
|
|
if (namerect.contains(point)) {
|
2017-12-15 16:25:47 +00:00
|
|
|
return { parent(), _namel };
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-10-13 19:07:04 +00:00
|
|
|
return {};
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2017-11-23 14:58:00 +00:00
|
|
|
const style::RoundCheckbox &Document::checkboxStyle() const {
|
|
|
|
return st::overviewSmallCheck;
|
|
|
|
}
|
|
|
|
|
2020-04-08 15:09:29 +00:00
|
|
|
void Document::ensureDataMediaCreated() const {
|
|
|
|
if (_dataMedia) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_dataMedia = _data->createMediaView();
|
2020-04-15 14:06:34 +00:00
|
|
|
_dataMedia->thumbnailWanted(parent()->fullId());
|
2020-05-21 13:13:29 +00:00
|
|
|
delegate()->registerHeavyItem(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Document::clearHeavyPart() {
|
|
|
|
_dataMedia = nullptr;
|
2020-04-08 15:09:29 +00:00
|
|
|
}
|
|
|
|
|
2017-09-26 11:49:16 +00:00
|
|
|
float64 Document::dataProgress() const {
|
2020-04-10 13:18:51 +00:00
|
|
|
ensureDataMediaCreated();
|
|
|
|
return _dataMedia->progress();
|
2017-09-26 11:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Document::dataFinished() const {
|
|
|
|
return !_data->loading();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Document::dataLoaded() const {
|
2020-04-10 13:18:51 +00:00
|
|
|
ensureDataMediaCreated();
|
|
|
|
return _dataMedia->loaded();
|
2017-09-26 11:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Document::iconAnimated() const {
|
2018-11-13 17:14:41 +00:00
|
|
|
return _data->isSong()
|
2020-04-09 14:02:09 +00:00
|
|
|
|| !dataLoaded()
|
2017-12-10 10:26:58 +00:00
|
|
|
|| (_radial && _radial->animating());
|
2017-09-26 11:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Document::withThumb() const {
|
2018-11-13 17:14:41 +00:00
|
|
|
return !_data->isSong()
|
2019-01-25 14:37:28 +00:00
|
|
|
&& _data->hasThumbnail()
|
2018-12-05 08:07:17 +00:00
|
|
|
&& !Data::IsExecutableName(_data->filename());
|
2017-09-26 11:49:16 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 16:24:23 +00:00
|
|
|
bool Document::updateStatusText() {
|
2016-04-12 21:31:28 +00:00
|
|
|
bool showPause = false;
|
|
|
|
int32 statusSize = 0, realDuration = 0;
|
2020-04-09 14:02:09 +00:00
|
|
|
if (_data->status == FileDownloadFailed
|
|
|
|
|| _data->status == FileUploadFailed) {
|
2016-04-12 21:31:28 +00:00
|
|
|
statusSize = FileStatusSizeFailed;
|
2017-12-25 14:17:00 +00:00
|
|
|
} else if (_data->uploading()) {
|
|
|
|
statusSize = _data->uploadingData->offset;
|
2016-04-12 21:31:28 +00:00
|
|
|
} else if (_data->loading()) {
|
|
|
|
statusSize = _data->loadOffset();
|
2020-04-09 14:02:09 +00:00
|
|
|
} else if (dataLoaded()) {
|
2019-02-28 21:03:25 +00:00
|
|
|
statusSize = FileStatusSizeLoaded;
|
2016-04-12 21:31:28 +00:00
|
|
|
} else {
|
|
|
|
statusSize = FileStatusSizeReady;
|
|
|
|
}
|
2019-02-28 21:03:25 +00:00
|
|
|
|
|
|
|
if (_data->isSong()) {
|
|
|
|
const auto state = Media::Player::instance()->getState(AudioMsgId::Type::Song);
|
|
|
|
if (state.id == AudioMsgId(_data, parent()->fullId(), state.id.externalPlayId()) && !Media::Player::IsStoppedOrStopping(state.state)) {
|
|
|
|
statusSize = -1 - (state.position / state.frequency);
|
|
|
|
realDuration = (state.length / state.frequency);
|
|
|
|
showPause = Media::Player::ShowPauseIcon(state.state);
|
|
|
|
}
|
|
|
|
if (!showPause && (state.id == AudioMsgId(_data, parent()->fullId(), state.id.externalPlayId())) && Media::Player::instance()->isSeeking(AudioMsgId::Type::Song)) {
|
|
|
|
showPause = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-21 16:24:23 +00:00
|
|
|
if (statusSize != _status.size()) {
|
2017-12-10 10:26:58 +00:00
|
|
|
_status.update(statusSize, _data->size, _data->isSong() ? _data->song()->duration : -1, realDuration);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
return showPause;
|
|
|
|
}
|
|
|
|
|
2017-10-05 15:35:52 +00:00
|
|
|
Link::Link(
|
2020-05-21 12:27:04 +00:00
|
|
|
not_null<Delegate*> delegate,
|
2017-10-05 15:35:52 +00:00
|
|
|
not_null<HistoryItem*> parent,
|
2018-01-14 16:02:25 +00:00
|
|
|
Data::Media *media)
|
2020-05-21 12:27:04 +00:00
|
|
|
: ItemBase(delegate, parent) {
|
2016-04-12 21:31:28 +00:00
|
|
|
AddComponents(Info::Bit());
|
|
|
|
|
2017-11-23 14:58:00 +00:00
|
|
|
auto textWithEntities = parent->originalText();
|
2016-05-06 17:33:48 +00:00
|
|
|
QString mainUrl;
|
2016-04-12 21:31:28 +00:00
|
|
|
|
2016-05-06 17:33:48 +00:00
|
|
|
auto text = textWithEntities.text;
|
2017-11-23 14:58:00 +00:00
|
|
|
const auto &entities = textWithEntities.entities;
|
2016-04-12 21:31:28 +00:00
|
|
|
int32 from = 0, till = text.size(), lnk = entities.size();
|
2017-11-23 14:58:00 +00:00
|
|
|
for (const auto &entity : entities) {
|
2016-04-29 12:00:48 +00:00
|
|
|
auto type = entity.type();
|
2019-04-08 15:10:06 +00:00
|
|
|
if (type != EntityType::Url && type != EntityType::CustomUrl && type != EntityType::Email) {
|
2016-04-12 21:31:28 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-11-23 14:58:00 +00:00
|
|
|
const auto customUrl = entity.data();
|
|
|
|
const auto entityText = text.mid(entity.offset(), entity.length());
|
|
|
|
const auto url = customUrl.isEmpty() ? entityText : customUrl;
|
2016-04-29 12:00:48 +00:00
|
|
|
if (_links.isEmpty()) {
|
|
|
|
mainUrl = url;
|
|
|
|
}
|
|
|
|
_links.push_back(LinkEntry(url, entityText));
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
while (lnk > 0 && till > from) {
|
|
|
|
--lnk;
|
2016-09-27 13:37:18 +00:00
|
|
|
auto &entity = entities.at(lnk);
|
2016-04-29 12:00:48 +00:00
|
|
|
auto type = entity.type();
|
2019-04-08 15:10:06 +00:00
|
|
|
if (type != EntityType::Url && type != EntityType::CustomUrl && type != EntityType::Email) {
|
2016-04-12 21:31:28 +00:00
|
|
|
++lnk;
|
|
|
|
break;
|
|
|
|
}
|
2016-04-29 12:00:48 +00:00
|
|
|
int32 afterLinkStart = entity.offset() + entity.length();
|
2016-04-12 21:31:28 +00:00
|
|
|
if (till > afterLinkStart) {
|
|
|
|
if (!QRegularExpression(qsl("^[,.\\s_=+\\-;:`'\"\\(\\)\\[\\]\\{\\}<>*&^%\\$#@!\\\\/]+$")).match(text.mid(afterLinkStart, till - afterLinkStart)).hasMatch()) {
|
|
|
|
++lnk;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-04-29 12:00:48 +00:00
|
|
|
till = entity.offset();
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
if (!lnk) {
|
|
|
|
if (QRegularExpression(qsl("^[,.\\s\\-;:`'\"\\(\\)\\[\\]\\{\\}<>*&^%\\$#@!\\\\/]+$")).match(text.mid(from, till - from)).hasMatch()) {
|
|
|
|
till = from;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-03 08:44:46 +00:00
|
|
|
const auto createHandler = [](const QString &url) {
|
|
|
|
return UrlClickHandler::IsSuspicious(url)
|
|
|
|
? std::make_shared<HiddenUrlClickHandler>(url)
|
|
|
|
: std::make_shared<UrlClickHandler>(url);
|
|
|
|
};
|
2018-03-13 10:29:56 +00:00
|
|
|
_page = media ? media->webpage() : nullptr;
|
2016-04-12 21:31:28 +00:00
|
|
|
if (_page) {
|
2016-04-29 12:00:48 +00:00
|
|
|
mainUrl = _page->url;
|
2016-04-12 21:31:28 +00:00
|
|
|
if (_page->document) {
|
2018-01-11 13:07:29 +00:00
|
|
|
_photol = std::make_shared<DocumentOpenClickHandler>(
|
|
|
|
_page->document,
|
|
|
|
parent->fullId());
|
2016-04-12 21:31:28 +00:00
|
|
|
} else if (_page->photo) {
|
2018-10-31 10:11:01 +00:00
|
|
|
if (_page->type == WebPageType::Profile || _page->type == WebPageType::Video) {
|
2020-06-03 08:44:46 +00:00
|
|
|
_photol = createHandler(_page->url);
|
2018-10-31 10:11:01 +00:00
|
|
|
} else if (_page->type == WebPageType::Photo
|
|
|
|
|| _page->siteName == qstr("Twitter")
|
|
|
|
|| _page->siteName == qstr("Facebook")) {
|
2017-12-18 09:07:18 +00:00
|
|
|
_photol = std::make_shared<PhotoOpenClickHandler>(
|
2017-12-15 16:25:47 +00:00
|
|
|
_page->photo,
|
|
|
|
parent->fullId());
|
2016-04-12 21:31:28 +00:00
|
|
|
} else {
|
2020-06-03 08:44:46 +00:00
|
|
|
_photol = createHandler(_page->url);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
} else {
|
2020-06-03 08:44:46 +00:00
|
|
|
_photol = createHandler(_page->url);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
2016-04-29 12:00:48 +00:00
|
|
|
} else if (!mainUrl.isEmpty()) {
|
2020-06-03 08:44:46 +00:00
|
|
|
_photol = createHandler(mainUrl);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
if (from >= till && _page) {
|
2017-06-20 19:48:53 +00:00
|
|
|
text = _page->description.text;
|
2016-04-12 21:31:28 +00:00
|
|
|
from = 0;
|
|
|
|
till = text.size();
|
|
|
|
}
|
|
|
|
if (till > from) {
|
|
|
|
TextParseOptions opts = { TextParseMultiline, int32(st::linksMaxWidth), 3 * st::normalFont->height, Qt::LayoutDirectionAuto };
|
2016-12-23 13:21:01 +00:00
|
|
|
_text.setText(st::defaultTextStyle, text.mid(from, till - from), opts);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
int32 tw = 0, th = 0;
|
|
|
|
if (_page && _page->photo) {
|
2020-05-26 10:13:32 +00:00
|
|
|
const auto photo = _page->photo;
|
|
|
|
if (photo->inlineThumbnailBytes().isEmpty()
|
|
|
|
&& (photo->hasExact(Data::PhotoSize::Small)
|
|
|
|
|| photo->hasExact(Data::PhotoSize::Thumbnail))) {
|
|
|
|
photo->load(Data::PhotoSize::Small, parent->fullId());
|
|
|
|
}
|
|
|
|
tw = style::ConvertScale(photo->width());
|
|
|
|
th = style::ConvertScale(photo->height());
|
2019-01-25 14:37:28 +00:00
|
|
|
} else if (_page && _page->document && _page->document->hasThumbnail()) {
|
|
|
|
_page->document->loadThumbnail(parent->fullId());
|
2020-04-15 14:06:34 +00:00
|
|
|
const auto &location = _page->document->thumbnailLocation();
|
|
|
|
tw = style::ConvertScale(location.width());
|
|
|
|
th = style::ConvertScale(location.height());
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
2016-06-07 19:59:39 +00:00
|
|
|
if (tw > st::linksPhotoSize) {
|
2016-04-12 21:31:28 +00:00
|
|
|
if (th > tw) {
|
2016-06-07 19:59:39 +00:00
|
|
|
th = th * st::linksPhotoSize / tw;
|
|
|
|
tw = st::linksPhotoSize;
|
|
|
|
} else if (th > st::linksPhotoSize) {
|
|
|
|
tw = tw * st::linksPhotoSize / th;
|
|
|
|
th = st::linksPhotoSize;
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_pixw = qMax(tw, 1);
|
|
|
|
_pixh = qMax(th, 1);
|
|
|
|
|
|
|
|
if (_page) {
|
|
|
|
_title = _page->title;
|
|
|
|
}
|
2016-08-30 05:24:16 +00:00
|
|
|
|
|
|
|
#ifndef OS_MAC_OLD
|
|
|
|
auto parts = mainUrl.splitRef('/');
|
|
|
|
#else // OS_MAC_OLD
|
|
|
|
auto parts = mainUrl.split('/');
|
|
|
|
#endif // OS_MAC_OLD
|
2016-04-12 21:31:28 +00:00
|
|
|
if (!parts.isEmpty()) {
|
2016-08-30 05:24:16 +00:00
|
|
|
auto domain = parts.at(0);
|
2016-04-12 21:31:28 +00:00
|
|
|
if (parts.size() > 2 && domain.endsWith(':') && parts.at(1).isEmpty()) { // http:// and others
|
|
|
|
domain = parts.at(2);
|
|
|
|
}
|
|
|
|
|
2019-04-05 18:45:57 +00:00
|
|
|
parts = domain.split('@').back().split('.', QString::SkipEmptyParts);
|
2016-04-12 21:31:28 +00:00
|
|
|
if (parts.size() > 1) {
|
|
|
|
_letter = parts.at(parts.size() - 2).at(0).toUpper();
|
|
|
|
if (_title.isEmpty()) {
|
|
|
|
_title.reserve(parts.at(parts.size() - 2).size());
|
|
|
|
_title.append(_letter).append(parts.at(parts.size() - 2).mid(1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_titlew = st::semiboldFont->width(_title);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Link::initDimensions() {
|
|
|
|
_maxw = st::linksMaxWidth;
|
|
|
|
_minh = 0;
|
|
|
|
if (!_title.isEmpty()) {
|
|
|
|
_minh += st::semiboldFont->height;
|
|
|
|
}
|
|
|
|
if (!_text.isEmpty()) {
|
2016-06-07 19:59:39 +00:00
|
|
|
_minh += qMin(3 * st::normalFont->height, _text.countHeight(_maxw - st::linksPhotoSize - st::linksPhotoPadding));
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
_minh += _links.size() * st::normalFont->height;
|
2016-06-07 19:59:39 +00:00
|
|
|
_minh = qMax(_minh, int32(st::linksPhotoSize)) + st::linksMargin.top() + st::linksMargin.bottom() + st::linksBorder;
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int32 Link::resizeGetHeight(int32 width) {
|
|
|
|
_width = qMin(width, _maxw);
|
2016-06-07 19:59:39 +00:00
|
|
|
int32 w = _width - st::linksPhotoSize - st::linksPhotoPadding;
|
2019-04-04 15:24:13 +00:00
|
|
|
for (const auto &link : _links) {
|
|
|
|
link.lnk->setFullDisplayed(w >= link.width);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_height = 0;
|
|
|
|
if (!_title.isEmpty()) {
|
|
|
|
_height += st::semiboldFont->height;
|
|
|
|
}
|
|
|
|
if (!_text.isEmpty()) {
|
2016-06-07 19:59:39 +00:00
|
|
|
_height += qMin(3 * st::normalFont->height, _text.countHeight(_width - st::linksPhotoSize - st::linksPhotoPadding));
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
_height += _links.size() * st::normalFont->height;
|
2016-06-07 19:59:39 +00:00
|
|
|
_height = qMax(_height, int32(st::linksPhotoSize)) + st::linksMargin.top() + st::linksMargin.bottom() + st::linksBorder;
|
2016-04-12 21:31:28 +00:00
|
|
|
return _height;
|
|
|
|
}
|
|
|
|
|
2016-11-21 16:24:23 +00:00
|
|
|
void Link::paint(Painter &p, const QRect &clip, TextSelection selection, const PaintContext *context) {
|
2017-11-23 14:58:00 +00:00
|
|
|
auto selected = (selection == FullSelection);
|
|
|
|
|
|
|
|
const auto pixLeft = 0;
|
|
|
|
const auto pixTop = st::linksMargin.top() + st::linksBorder;
|
2019-09-13 12:22:54 +00:00
|
|
|
if (clip.intersects(style::rtlrect(0, pixTop, st::linksPhotoSize, st::linksPhotoSize, _width))) {
|
2020-05-21 10:59:55 +00:00
|
|
|
validateThumbnail();
|
|
|
|
if (!_thumbnail.isNull()) {
|
|
|
|
p.drawPixmap(pixLeft, pixTop, _thumbnail);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-23 14:58:00 +00:00
|
|
|
const auto left = st::linksPhotoSize + st::linksPhotoPadding;
|
|
|
|
const auto w = _width - left;
|
|
|
|
auto top = [&] {
|
|
|
|
if (!_title.isEmpty() && _text.isEmpty() && _links.size() == 1) {
|
|
|
|
return pixTop + (st::linksPhotoSize - st::semiboldFont->height - st::normalFont->height) / 2;
|
|
|
|
}
|
|
|
|
return st::linksTextTop;
|
|
|
|
}();
|
2016-04-12 21:31:28 +00:00
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::linksTextFg);
|
2016-04-12 21:31:28 +00:00
|
|
|
p.setFont(st::semiboldFont);
|
|
|
|
if (!_title.isEmpty()) {
|
2019-09-13 12:22:54 +00:00
|
|
|
if (clip.intersects(style::rtlrect(left, top, qMin(w, _titlew), st::semiboldFont->height, _width))) {
|
2016-04-12 21:31:28 +00:00
|
|
|
p.drawTextLeft(left, top, _width, (w < _titlew) ? st::semiboldFont->elided(_title, w) : _title);
|
|
|
|
}
|
|
|
|
top += st::semiboldFont->height;
|
|
|
|
}
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setFont(st::msgFont);
|
2016-04-12 21:31:28 +00:00
|
|
|
if (!_text.isEmpty()) {
|
|
|
|
int32 h = qMin(st::normalFont->height * 3, _text.countHeight(w));
|
2019-09-13 12:22:54 +00:00
|
|
|
if (clip.intersects(style::rtlrect(left, top, w, h, _width))) {
|
2016-04-12 21:31:28 +00:00
|
|
|
_text.drawLeftElided(p, left, top, w, _width, 3);
|
|
|
|
}
|
|
|
|
top += h;
|
|
|
|
}
|
|
|
|
|
2016-12-03 12:10:35 +00:00
|
|
|
p.setPen(st::windowActiveTextFg);
|
2019-04-04 15:24:13 +00:00
|
|
|
for (const auto &link : _links) {
|
2019-09-13 12:22:54 +00:00
|
|
|
if (clip.intersects(style::rtlrect(left, top, qMin(w, link.width), st::normalFont->height, _width))) {
|
2019-04-04 15:24:13 +00:00
|
|
|
p.setFont(ClickHandler::showAsActive(link.lnk) ? st::normalFont->underline() : st::normalFont);
|
|
|
|
p.drawTextLeft(left, top, _width, (w < link.width) ? st::normalFont->elided(link.text, w) : link.text);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
top += st::normalFont->height;
|
|
|
|
}
|
|
|
|
|
2019-09-13 12:22:54 +00:00
|
|
|
QRect border(style::rtlrect(left, 0, w, st::linksBorder, _width));
|
2016-04-12 21:31:28 +00:00
|
|
|
if (!context->isAfterDate && clip.intersects(border)) {
|
|
|
|
p.fillRect(clip.intersected(border), st::linksBorderFg);
|
|
|
|
}
|
2017-11-23 14:58:00 +00:00
|
|
|
|
|
|
|
const auto checkDelta = st::linksPhotoSize + st::overviewCheckSkip
|
|
|
|
- st::overviewSmallCheck.size;
|
|
|
|
const auto checkLeft = pixLeft + checkDelta;
|
|
|
|
const auto checkTop = pixTop + checkDelta;
|
|
|
|
paintCheckbox(p, { checkLeft, checkTop }, selected, context);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2020-05-21 10:59:55 +00:00
|
|
|
void Link::validateThumbnail() {
|
|
|
|
if (!_thumbnail.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_page && _page->photo) {
|
2020-05-25 14:16:04 +00:00
|
|
|
using Data::PhotoSize;
|
|
|
|
ensurePhotoMediaCreated();
|
|
|
|
if (const auto thumbnail = _photoMedia->image(PhotoSize::Thumbnail)) {
|
2020-05-29 15:10:25 +00:00
|
|
|
_thumbnail = thumbnail->pixSingle(_pixw, _pixh, st::linksPhotoSize, st::linksPhotoSize, ImageRoundRadius::Small);
|
2020-05-25 14:16:04 +00:00
|
|
|
} else if (const auto large = _photoMedia->image(PhotoSize::Large)) {
|
2020-05-29 15:10:25 +00:00
|
|
|
_thumbnail = large->pixSingle(_pixw, _pixh, st::linksPhotoSize, st::linksPhotoSize, ImageRoundRadius::Small);
|
2020-05-25 14:16:04 +00:00
|
|
|
} else if (const auto small = _photoMedia->image(PhotoSize::Small)) {
|
2020-05-29 15:10:25 +00:00
|
|
|
_thumbnail = small->pixSingle(_pixw, _pixh, st::linksPhotoSize, st::linksPhotoSize, ImageRoundRadius::Small);
|
2020-05-25 14:16:04 +00:00
|
|
|
} else if (const auto blurred = _photoMedia->thumbnailInline()) {
|
2020-05-29 15:10:25 +00:00
|
|
|
_thumbnail = blurred->pixBlurredSingle(_pixw, _pixh, st::linksPhotoSize, st::linksPhotoSize, ImageRoundRadius::Small);
|
2020-05-21 10:59:55 +00:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
2020-05-25 14:16:04 +00:00
|
|
|
_photoMedia = nullptr;
|
|
|
|
delegate()->unregisterHeavyItem(this);
|
2020-05-21 10:59:55 +00:00
|
|
|
} else if (_page && _page->document && _page->document->hasThumbnail()) {
|
|
|
|
ensureDocumentMediaCreated();
|
|
|
|
if (const auto thumbnail = _documentMedia->thumbnail()) {
|
|
|
|
auto roundRadius = _page->document->isVideoMessage()
|
|
|
|
? ImageRoundRadius::Ellipse
|
|
|
|
: ImageRoundRadius::Small;
|
2020-05-29 15:10:25 +00:00
|
|
|
_thumbnail = thumbnail->pixSingle(_pixw, _pixh, st::linksPhotoSize, st::linksPhotoSize, roundRadius);
|
2020-05-21 10:59:55 +00:00
|
|
|
_documentMedia = nullptr;
|
2020-05-21 13:13:29 +00:00
|
|
|
delegate()->unregisterHeavyItem(this);
|
2020-05-21 10:59:55 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const auto size = QSize(st::linksPhotoSize, st::linksPhotoSize);
|
|
|
|
_thumbnail = QPixmap(size * cIntRetinaFactor());
|
|
|
|
_thumbnail.fill(Qt::transparent);
|
|
|
|
auto p = Painter(&_thumbnail);
|
|
|
|
const auto index = _letter.isEmpty()
|
|
|
|
? 0
|
|
|
|
: (_letter[0].unicode() % 4);
|
|
|
|
const auto fill = [&](style::color color, RoundCorners corners) {
|
|
|
|
auto pixRect = QRect(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
st::linksPhotoSize,
|
|
|
|
st::linksPhotoSize);
|
|
|
|
App::roundRect(p, pixRect, color, corners);
|
|
|
|
};
|
|
|
|
switch (index) {
|
|
|
|
case 0: fill(st::msgFile1Bg, Doc1Corners); break;
|
|
|
|
case 1: fill(st::msgFile2Bg, Doc2Corners); break;
|
|
|
|
case 2: fill(st::msgFile3Bg, Doc3Corners); break;
|
|
|
|
case 3: fill(st::msgFile4Bg, Doc4Corners); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_letter.isEmpty()) {
|
|
|
|
p.setFont(st::linksLetterFont);
|
|
|
|
p.setPen(st::linksLetterFg);
|
|
|
|
p.drawText(
|
|
|
|
QRect(0, 0, st::linksPhotoSize, st::linksPhotoSize),
|
|
|
|
_letter,
|
|
|
|
style::al_center);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-25 14:16:04 +00:00
|
|
|
void Link::ensurePhotoMediaCreated() {
|
|
|
|
if (_photoMedia) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_photoMedia = _page->photo->createMediaView();
|
|
|
|
_photoMedia->wanted(Data::PhotoSize::Small, parent()->fullId());
|
|
|
|
delegate()->registerHeavyItem(this);
|
|
|
|
}
|
|
|
|
|
2020-04-15 14:06:34 +00:00
|
|
|
void Link::ensureDocumentMediaCreated() {
|
|
|
|
if (_documentMedia) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_documentMedia = _page->document->createMediaView();
|
|
|
|
_documentMedia->thumbnailWanted(parent()->fullId());
|
2020-05-21 13:13:29 +00:00
|
|
|
delegate()->registerHeavyItem(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Link::clearHeavyPart() {
|
2020-05-25 14:16:04 +00:00
|
|
|
_photoMedia = nullptr;
|
2020-05-21 13:13:29 +00:00
|
|
|
_documentMedia = nullptr;
|
2020-04-15 14:06:34 +00:00
|
|
|
}
|
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
TextState Link::getState(
|
2017-10-13 19:07:04 +00:00
|
|
|
QPoint point,
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request) const {
|
2016-06-07 19:59:39 +00:00
|
|
|
int32 left = st::linksPhotoSize + st::linksPhotoPadding, top = st::linksMargin.top() + st::linksBorder, w = _width - left;
|
2019-09-13 12:22:54 +00:00
|
|
|
if (style::rtlrect(0, top, st::linksPhotoSize, st::linksPhotoSize, _width).contains(point)) {
|
2017-12-15 16:25:47 +00:00
|
|
|
return { parent(), _photol };
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!_title.isEmpty() && _text.isEmpty() && _links.size() == 1) {
|
2016-06-07 19:59:39 +00:00
|
|
|
top += (st::linksPhotoSize - st::semiboldFont->height - st::normalFont->height) / 2;
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
if (!_title.isEmpty()) {
|
2019-09-13 12:22:54 +00:00
|
|
|
if (style::rtlrect(left, top, qMin(w, _titlew), st::semiboldFont->height, _width).contains(point)) {
|
2017-12-15 16:25:47 +00:00
|
|
|
return { parent(), _photol };
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
top += st::webPageTitleFont->height;
|
|
|
|
}
|
|
|
|
if (!_text.isEmpty()) {
|
|
|
|
top += qMin(st::normalFont->height * 3, _text.countHeight(w));
|
|
|
|
}
|
2019-04-04 15:24:13 +00:00
|
|
|
for (const auto &link : _links) {
|
2019-09-13 12:22:54 +00:00
|
|
|
if (style::rtlrect(left, top, qMin(w, link.width), st::normalFont->height, _width).contains(point)) {
|
2019-04-04 15:24:13 +00:00
|
|
|
return { parent(), ClickHandlerPtr(link.lnk) };
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
top += st::normalFont->height;
|
|
|
|
}
|
2017-10-13 19:07:04 +00:00
|
|
|
return {};
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2017-11-23 14:58:00 +00:00
|
|
|
const style::RoundCheckbox &Link::checkboxStyle() const {
|
|
|
|
return st::overviewSmallCheck;
|
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
Link::LinkEntry::LinkEntry(const QString &url, const QString &text)
|
|
|
|
: text(text)
|
|
|
|
, width(st::normalFont->width(text))
|
2020-04-23 13:56:50 +00:00
|
|
|
, lnk(UrlClickHandler::IsSuspicious(url)
|
|
|
|
? std::make_shared<HiddenUrlClickHandler>(url)
|
|
|
|
: std::make_shared<UrlClickHandler>(url)) {
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Layout
|
|
|
|
} // namespace Overview
|