2014-05-30 08:53:19 +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.
|
2014-05-30 08:53:19 +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
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
2017-09-30 18:26:45 +00:00
|
|
|
#include "window/layer_widget.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2017-09-26 11:49:16 +00:00
|
|
|
#include "data/data_photo.h"
|
|
|
|
#include "data/data_document.h"
|
2019-02-13 12:36:59 +00:00
|
|
|
#include "media/clip/media_clip_reader.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/abstract_box.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "mainwindow.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
#include "mainwidget.h"
|
2017-02-28 14:05:30 +00:00
|
|
|
#include "core/file_utilities.h"
|
2016-12-13 17:07:56 +00:00
|
|
|
#include "ui/widgets/shadow.h"
|
2018-10-23 09:44:42 +00:00
|
|
|
#include "ui/image/image.h"
|
2018-10-13 17:35:30 +00:00
|
|
|
#include "ui/emoji_config.h"
|
2016-11-11 19:51:59 +00:00
|
|
|
#include "window/window_main_menu.h"
|
2017-03-04 19:36:59 +00:00
|
|
|
#include "auth_session.h"
|
2017-08-03 11:15:57 +00:00
|
|
|
#include "chat_helpers/stickers.h"
|
2017-04-07 18:10:49 +00:00
|
|
|
#include "window/window_controller.h"
|
2018-10-25 13:22:44 +00:00
|
|
|
#include "styles/style_boxes.h"
|
|
|
|
#include "styles/style_widgets.h"
|
|
|
|
#include "styles/style_chat_helpers.h"
|
|
|
|
#include "styles/style_history.h"
|
2016-09-10 20:54:59 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr int kStickerPreviewEmojiLimit = 10;
|
|
|
|
|
|
|
|
} // namespace
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
namespace Window {
|
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
class LayerStackWidget::BackgroundWidget : public TWidget {
|
|
|
|
public:
|
2016-12-13 17:07:56 +00:00
|
|
|
BackgroundWidget(QWidget *parent) : TWidget(parent) {
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
void setDoneCallback(Fn<void()> callback) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_doneCallback = std::move(callback);
|
2016-11-11 19:51:59 +00:00
|
|
|
}
|
2016-11-18 13:34:58 +00:00
|
|
|
|
|
|
|
void setLayerBoxes(const QRect &specialLayerBox, const QRect &layerBox);
|
2018-09-06 14:58:43 +00:00
|
|
|
void setCacheImages(
|
|
|
|
QPixmap &&bodyCache,
|
|
|
|
QPixmap &&mainMenuCache,
|
|
|
|
QPixmap &&specialLayerCache,
|
|
|
|
QPixmap &&layerCache);
|
|
|
|
void removeBodyCache();
|
2016-11-18 13:34:58 +00:00
|
|
|
void startAnimation(Action action);
|
2017-09-19 10:32:34 +00:00
|
|
|
void skipAnimation(Action action);
|
2017-09-30 19:20:40 +00:00
|
|
|
void finishAnimating();
|
2016-11-18 13:34:58 +00:00
|
|
|
|
|
|
|
bool animating() const {
|
|
|
|
return _a_mainMenuShown.animating() || _a_specialLayerShown.animating() || _a_layerShown.animating();
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
2014-12-12 16:27:03 +00:00
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
protected:
|
2016-11-18 13:34:58 +00:00
|
|
|
void paintEvent(QPaintEvent *e) override;
|
2016-11-11 19:51:59 +00:00
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
private:
|
|
|
|
bool isShown() const {
|
|
|
|
return _mainMenuShown || _specialLayerShown || _layerShown;
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
2016-11-18 13:34:58 +00:00
|
|
|
void checkIfDone();
|
|
|
|
void setMainMenuShown(bool shown);
|
|
|
|
void setSpecialLayerShown(bool shown);
|
|
|
|
void setLayerShown(bool shown);
|
|
|
|
void checkWasShown(bool wasShown);
|
|
|
|
void animationCallback();
|
2016-08-16 16:53:10 +00:00
|
|
|
|
2016-11-11 19:51:59 +00:00
|
|
|
QPixmap _bodyCache;
|
|
|
|
QPixmap _mainMenuCache;
|
2016-12-13 17:07:56 +00:00
|
|
|
int _mainMenuCacheWidth = 0;
|
2016-11-18 13:34:58 +00:00
|
|
|
QPixmap _specialLayerCache;
|
|
|
|
QPixmap _layerCache;
|
2016-11-11 19:51:59 +00:00
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void()> _doneCallback;
|
2016-11-18 13:34:58 +00:00
|
|
|
|
|
|
|
bool _wasAnimating = false;
|
|
|
|
bool _inPaintEvent = false;
|
2016-12-07 13:32:25 +00:00
|
|
|
Animation _a_shown;
|
|
|
|
Animation _a_mainMenuShown;
|
|
|
|
Animation _a_specialLayerShown;
|
|
|
|
Animation _a_layerShown;
|
2016-08-16 16:53:10 +00:00
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
QRect _specialLayerBox, _specialLayerCacheBox;
|
|
|
|
QRect _layerBox, _layerCacheBox;
|
|
|
|
int _mainMenuRight = 0;
|
|
|
|
|
|
|
|
bool _mainMenuShown = false;
|
|
|
|
bool _specialLayerShown = false;
|
|
|
|
bool _layerShown = false;
|
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
};
|
|
|
|
|
2018-09-06 14:58:43 +00:00
|
|
|
void LayerStackWidget::BackgroundWidget::setCacheImages(
|
|
|
|
QPixmap &&bodyCache,
|
|
|
|
QPixmap &&mainMenuCache,
|
|
|
|
QPixmap &&specialLayerCache,
|
|
|
|
QPixmap &&layerCache) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_bodyCache = std::move(bodyCache);
|
|
|
|
_mainMenuCache = std::move(mainMenuCache);
|
|
|
|
_specialLayerCache = std::move(specialLayerCache);
|
|
|
|
_layerCache = std::move(layerCache);
|
2016-11-18 13:34:58 +00:00
|
|
|
_specialLayerCacheBox = _specialLayerBox;
|
|
|
|
_layerCacheBox = _layerBox;
|
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent, !_bodyCache.isNull());
|
|
|
|
}
|
|
|
|
|
2018-09-06 14:58:43 +00:00
|
|
|
void LayerStackWidget::BackgroundWidget::removeBodyCache() {
|
|
|
|
if (!_bodyCache.isNull()) {
|
|
|
|
_bodyCache = {};
|
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
void LayerStackWidget::BackgroundWidget::startAnimation(Action action) {
|
|
|
|
if (action == Action::ShowMainMenu) {
|
|
|
|
setMainMenuShown(true);
|
2017-09-20 10:23:57 +00:00
|
|
|
} else if (action != Action::HideLayer
|
|
|
|
&& action != Action::HideSpecialLayer) {
|
2016-11-18 13:34:58 +00:00
|
|
|
setMainMenuShown(false);
|
|
|
|
}
|
|
|
|
if (action == Action::ShowSpecialLayer) {
|
|
|
|
setSpecialLayerShown(true);
|
2017-09-20 10:23:57 +00:00
|
|
|
} else if (action == Action::ShowMainMenu
|
|
|
|
|| action == Action::HideAll
|
|
|
|
|| action == Action::HideSpecialLayer) {
|
2016-11-18 13:34:58 +00:00
|
|
|
setSpecialLayerShown(false);
|
|
|
|
}
|
|
|
|
if (action == Action::ShowLayer) {
|
|
|
|
setLayerShown(true);
|
2017-09-20 10:23:57 +00:00
|
|
|
} else if (action != Action::ShowSpecialLayer
|
|
|
|
&& action != Action::HideSpecialLayer) {
|
2016-11-18 13:34:58 +00:00
|
|
|
setLayerShown(false);
|
|
|
|
}
|
|
|
|
_wasAnimating = true;
|
|
|
|
checkIfDone();
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
|
|
|
|
2017-09-19 10:32:34 +00:00
|
|
|
void LayerStackWidget::BackgroundWidget::skipAnimation(Action action) {
|
|
|
|
startAnimation(action);
|
2017-09-30 19:20:40 +00:00
|
|
|
finishAnimating();
|
2017-09-19 10:32:34 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
void LayerStackWidget::BackgroundWidget::checkIfDone() {
|
|
|
|
if (!_wasAnimating || _inPaintEvent || animating()) {
|
2016-08-16 16:53:10 +00:00
|
|
|
return;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-11-18 13:34:58 +00:00
|
|
|
_wasAnimating = false;
|
2018-09-06 14:58:43 +00:00
|
|
|
_mainMenuCache = _specialLayerCache = _layerCache = QPixmap();
|
|
|
|
removeBodyCache();
|
2016-11-18 13:34:58 +00:00
|
|
|
if (_doneCallback) {
|
|
|
|
_doneCallback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerStackWidget::BackgroundWidget::setMainMenuShown(bool shown) {
|
|
|
|
auto wasShown = isShown();
|
|
|
|
if (_mainMenuShown != shown) {
|
|
|
|
_mainMenuShown = shown;
|
|
|
|
_a_mainMenuShown.start([this] { animationCallback(); }, _mainMenuShown ? 0. : 1., _mainMenuShown ? 1. : 0., st::boxDuration, anim::easeOutCirc);
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
_mainMenuCacheWidth = (_mainMenuCache.width() / cIntRetinaFactor()) - st::boxRoundShadow.extend.right();
|
|
|
|
_mainMenuRight = _mainMenuShown ? _mainMenuCacheWidth : 0;
|
2016-11-18 13:34:58 +00:00
|
|
|
checkWasShown(wasShown);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerStackWidget::BackgroundWidget::setSpecialLayerShown(bool shown) {
|
|
|
|
auto wasShown = isShown();
|
|
|
|
if (_specialLayerShown != shown) {
|
|
|
|
_specialLayerShown = shown;
|
|
|
|
_a_specialLayerShown.start([this] { animationCallback(); }, _specialLayerShown ? 0. : 1., _specialLayerShown ? 1. : 0., st::boxDuration);
|
|
|
|
}
|
|
|
|
checkWasShown(wasShown);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerStackWidget::BackgroundWidget::setLayerShown(bool shown) {
|
|
|
|
auto wasShown = isShown();
|
|
|
|
if (_layerShown != shown) {
|
|
|
|
_layerShown = shown;
|
|
|
|
_a_layerShown.start([this] { animationCallback(); }, _layerShown ? 0. : 1., _layerShown ? 1. : 0., st::boxDuration);
|
|
|
|
}
|
|
|
|
checkWasShown(wasShown);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerStackWidget::BackgroundWidget::checkWasShown(bool wasShown) {
|
|
|
|
if (isShown() != wasShown) {
|
|
|
|
_a_shown.start([this] { animationCallback(); }, wasShown ? 1. : 0., wasShown ? 0. : 1., st::boxDuration, anim::easeOutCirc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerStackWidget::BackgroundWidget::setLayerBoxes(const QRect &specialLayerBox, const QRect &layerBox) {
|
|
|
|
_specialLayerBox = specialLayerBox;
|
|
|
|
_layerBox = layerBox;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerStackWidget::BackgroundWidget::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
_inPaintEvent = true;
|
2017-08-13 16:16:48 +00:00
|
|
|
auto guard = gsl::finally([this] {
|
2016-11-18 13:34:58 +00:00
|
|
|
_inPaintEvent = false;
|
2018-11-23 11:05:06 +00:00
|
|
|
crl::on_main(this, [=] { checkIfDone(); });
|
2016-11-18 13:34:58 +00:00
|
|
|
});
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
if (!_bodyCache.isNull()) {
|
|
|
|
p.drawPixmap(0, 0, _bodyCache);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto specialLayerBox = _specialLayerCache.isNull() ? _specialLayerBox : _specialLayerCacheBox;
|
|
|
|
auto layerBox = _layerCache.isNull() ? _layerBox : _layerCacheBox;
|
|
|
|
|
|
|
|
auto ms = getms();
|
|
|
|
auto mainMenuProgress = _a_mainMenuShown.current(ms, -1);
|
2016-12-13 17:07:56 +00:00
|
|
|
auto mainMenuRight = (_mainMenuCache.isNull() || mainMenuProgress < 0) ? _mainMenuRight : (mainMenuProgress < 0) ? _mainMenuRight : anim::interpolate(0, _mainMenuCacheWidth, mainMenuProgress);
|
2016-11-18 13:34:58 +00:00
|
|
|
if (mainMenuRight) {
|
2016-12-13 17:07:56 +00:00
|
|
|
// Move showing boxes to the right while main menu is hiding.
|
2016-11-18 13:34:58 +00:00
|
|
|
if (!_specialLayerCache.isNull()) {
|
2016-12-13 17:07:56 +00:00
|
|
|
specialLayerBox.moveLeft(specialLayerBox.left() + mainMenuRight / 2);
|
2016-08-19 17:26:31 +00:00
|
|
|
}
|
2016-11-18 13:34:58 +00:00
|
|
|
if (!_layerCache.isNull()) {
|
2016-12-13 17:07:56 +00:00
|
|
|
layerBox.moveLeft(layerBox.left() + mainMenuRight / 2);
|
2016-11-18 13:34:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
auto bgOpacity = _a_shown.current(ms, isShown() ? 1. : 0.);
|
|
|
|
auto specialLayerOpacity = _a_specialLayerShown.current(ms, _specialLayerShown ? 1. : 0.);
|
|
|
|
auto layerOpacity = _a_layerShown.current(ms, _layerShown ? 1. : 0.);
|
|
|
|
if (bgOpacity == 0.) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
p.setOpacity(bgOpacity);
|
2016-12-13 17:07:56 +00:00
|
|
|
auto overSpecialOpacity = (layerOpacity * specialLayerOpacity);
|
2016-11-18 13:34:58 +00:00
|
|
|
auto bg = myrtlrect(mainMenuRight, 0, width() - mainMenuRight, height());
|
2016-12-13 17:07:56 +00:00
|
|
|
|
|
|
|
if (_mainMenuCache.isNull() && mainMenuRight > 0) {
|
|
|
|
// All cache images are taken together with their shadows,
|
|
|
|
// so we paint shadow only when there is no cache.
|
2017-05-24 12:20:50 +00:00
|
|
|
Ui::Shadow::paint(p, myrtlrect(0, 0, mainMenuRight, height()), width(), st::boxRoundShadow, RectPart::Right);
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_specialLayerCache.isNull() && !specialLayerBox.isEmpty()) {
|
|
|
|
// All cache images are taken together with their shadows,
|
|
|
|
// so we paint shadow only when there is no cache.
|
2017-05-24 12:20:50 +00:00
|
|
|
auto sides = RectPart::Left | RectPart::Right;
|
2016-12-13 17:07:56 +00:00
|
|
|
auto topCorners = (specialLayerBox.y() > 0);
|
|
|
|
auto bottomCorners = (specialLayerBox.y() + specialLayerBox.height() < height());
|
|
|
|
if (topCorners) {
|
2017-05-24 12:20:50 +00:00
|
|
|
sides |= RectPart::Top;
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
if (bottomCorners) {
|
2017-05-24 12:20:50 +00:00
|
|
|
sides |= RectPart::Bottom;
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
if (topCorners || bottomCorners) {
|
|
|
|
p.setClipRegion(QRegion(rect()) - specialLayerBox.marginsRemoved(QMargins(st::boxRadius, 0, st::boxRadius, 0)) - specialLayerBox.marginsRemoved(QMargins(0, st::boxRadius, 0, st::boxRadius)));
|
|
|
|
}
|
|
|
|
Ui::Shadow::paint(p, specialLayerBox, width(), st::boxRoundShadow, sides);
|
|
|
|
|
|
|
|
if (topCorners || bottomCorners) {
|
|
|
|
// In case of painting the shadow above the special layer we get
|
|
|
|
// glitches in the corners, so we need to paint the corners once more.
|
|
|
|
p.setClipping(false);
|
2017-05-24 12:20:50 +00:00
|
|
|
auto parts = (topCorners ? (RectPart::TopLeft | RectPart::TopRight) : RectPart::None)
|
|
|
|
| (bottomCorners ? (RectPart::BottomLeft | RectPart::BottomRight) : RectPart::None);
|
2016-12-13 17:07:56 +00:00
|
|
|
App::roundRect(p, specialLayerBox, st::boxBg, BoxCorners, nullptr, parts);
|
|
|
|
}
|
2016-11-18 13:34:58 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
|
|
|
|
if (!layerBox.isEmpty() && !_specialLayerCache.isNull() && overSpecialOpacity < bgOpacity) {
|
|
|
|
// In case of moving special layer below the background while showing a box
|
|
|
|
// we need to fill special layer rect below its cache with a complex opacity
|
|
|
|
// (alpha_final - alpha_current) / (1 - alpha_current) so we won't get glitches
|
|
|
|
// in the transparent special layer cache corners after filling special layer
|
|
|
|
// rect above its cache with alpha_current opacity.
|
|
|
|
auto region = QRegion(bg) - specialLayerBox;
|
2017-02-21 13:45:56 +00:00
|
|
|
for (auto rect : region.rects()) {
|
2016-12-13 17:07:56 +00:00
|
|
|
p.fillRect(rect, st::layerBg);
|
|
|
|
}
|
|
|
|
p.setOpacity((bgOpacity - overSpecialOpacity) / (1. - (overSpecialOpacity * st::layerBg->c.alphaF())));
|
|
|
|
p.fillRect(specialLayerBox, st::layerBg);
|
|
|
|
p.setOpacity(bgOpacity);
|
|
|
|
} else {
|
|
|
|
p.fillRect(bg, st::layerBg);
|
2016-11-18 13:34:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!_specialLayerCache.isNull() && specialLayerOpacity > 0) {
|
|
|
|
p.setOpacity(specialLayerOpacity);
|
2016-12-13 17:07:56 +00:00
|
|
|
auto cacheLeft = specialLayerBox.x() - st::boxRoundShadow.extend.left();
|
|
|
|
auto cacheTop = specialLayerBox.y() - (specialLayerBox.y() > 0 ? st::boxRoundShadow.extend.top() : 0);
|
|
|
|
p.drawPixmapLeft(cacheLeft, cacheTop, width(), _specialLayerCache);
|
2016-11-18 13:34:58 +00:00
|
|
|
}
|
|
|
|
if (!layerBox.isEmpty()) {
|
|
|
|
if (!_specialLayerCache.isNull()) {
|
2016-12-13 17:07:56 +00:00
|
|
|
p.setOpacity(overSpecialOpacity);
|
2016-11-18 13:34:58 +00:00
|
|
|
p.fillRect(specialLayerBox, st::layerBg);
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
if (_layerCache.isNull()) {
|
|
|
|
p.setOpacity(layerOpacity);
|
|
|
|
Ui::Shadow::paint(p, layerBox, width(), st::boxRoundShadow);
|
|
|
|
}
|
2016-11-18 13:34:58 +00:00
|
|
|
}
|
|
|
|
if (!_layerCache.isNull() && layerOpacity > 0) {
|
|
|
|
p.setOpacity(layerOpacity);
|
2016-12-13 17:07:56 +00:00
|
|
|
p.drawPixmapLeft(layerBox.topLeft() - QPoint(st::boxRoundShadow.extend.left(), st::boxRoundShadow.extend.top()), width(), _layerCache);
|
2016-11-18 13:34:58 +00:00
|
|
|
}
|
|
|
|
if (!_mainMenuCache.isNull() && mainMenuRight > 0) {
|
|
|
|
p.setOpacity(1.);
|
2016-12-13 17:07:56 +00:00
|
|
|
auto shownWidth = mainMenuRight + st::boxRoundShadow.extend.right();
|
|
|
|
auto sourceWidth = shownWidth * cIntRetinaFactor();
|
|
|
|
auto sourceRect = rtlrect(_mainMenuCache.width() - sourceWidth, 0, sourceWidth, _mainMenuCache.height(), _mainMenuCache.width());
|
|
|
|
p.drawPixmapLeft(0, 0, shownWidth, height(), width(), _mainMenuCache, sourceRect);
|
2016-11-18 13:34:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-30 19:20:40 +00:00
|
|
|
void LayerStackWidget::BackgroundWidget::finishAnimating() {
|
2016-11-18 13:34:58 +00:00
|
|
|
_a_shown.finish();
|
|
|
|
_a_mainMenuShown.finish();
|
|
|
|
_a_specialLayerShown.finish();
|
|
|
|
_a_layerShown.finish();
|
|
|
|
checkIfDone();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerStackWidget::BackgroundWidget::animationCallback() {
|
|
|
|
update();
|
|
|
|
checkIfDone();
|
|
|
|
}
|
|
|
|
|
2018-04-06 16:23:09 +00:00
|
|
|
LayerStackWidget::LayerStackWidget(QWidget *parent)
|
|
|
|
: RpWidget(parent)
|
2016-11-18 13:34:58 +00:00
|
|
|
, _background(this) {
|
|
|
|
setGeometry(parentWidget()->rect());
|
|
|
|
hide();
|
|
|
|
_background->setDoneCallback([this] { animationDone(); });
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerWidget::setInnerFocus() {
|
2018-04-06 16:23:09 +00:00
|
|
|
if (!isAncestorOf(window()->focusWidget())) {
|
2016-11-18 13:34:58 +00:00
|
|
|
doSetInnerFocus();
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
bool LayerWidget::overlaps(const QRect &globalRect) {
|
|
|
|
if (isHidden()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto testRect = QRect(mapFromGlobal(globalRect.topLeft()), globalRect.size());
|
|
|
|
if (testAttribute(Qt::WA_OpaquePaintEvent)) {
|
|
|
|
return rect().contains(testRect);
|
|
|
|
}
|
|
|
|
if (QRect(0, st::boxRadius, width(), height() - 2 * st::boxRadius).contains(testRect)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (QRect(st::boxRadius, 0, width() - 2 * st::boxRadius, height()).contains(testRect)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-17 15:41:52 +00:00
|
|
|
void LayerStackWidget::setHideByBackgroundClick(bool hide) {
|
|
|
|
_hideByBackgroundClick = hide;
|
|
|
|
}
|
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
void LayerStackWidget::keyPressEvent(QKeyEvent *e) {
|
2014-05-30 08:53:19 +00:00
|
|
|
if (e->key() == Qt::Key_Escape) {
|
2017-09-20 10:23:57 +00:00
|
|
|
hideCurrent(anim::type::normal);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
void LayerStackWidget::mousePressEvent(QMouseEvent *e) {
|
2018-12-12 08:59:51 +00:00
|
|
|
Ui::PostponeCall(this, [=] { backgroundClicked(); });
|
2018-12-12 05:47:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LayerStackWidget::backgroundClicked() {
|
|
|
|
if (!_hideByBackgroundClick) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (const auto layer = currentLayer()) {
|
|
|
|
if (!layer->closeByOutsideClick()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (const auto special = _specialLayer.data()) {
|
|
|
|
if (!special->closeByOutsideClick()) {
|
|
|
|
return;
|
2018-06-06 11:51:27 +00:00
|
|
|
}
|
2018-04-17 15:41:52 +00:00
|
|
|
}
|
2018-12-12 05:47:24 +00:00
|
|
|
hideCurrent(anim::type::normal);
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 10:23:57 +00:00
|
|
|
void LayerStackWidget::hideCurrent(anim::type animated) {
|
|
|
|
return currentLayer() ? hideLayers(animated) : hideAll(animated);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 10:23:57 +00:00
|
|
|
void LayerStackWidget::hideLayers(anim::type animated) {
|
2016-11-18 13:34:58 +00:00
|
|
|
startAnimation([] {}, [this] {
|
2016-08-17 15:14:08 +00:00
|
|
|
clearLayers();
|
2017-09-20 10:23:57 +00:00
|
|
|
}, Action::HideLayer, animated);
|
2016-08-17 15:14:08 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 10:23:57 +00:00
|
|
|
void LayerStackWidget::hideAll(anim::type animated) {
|
2018-11-23 11:05:06 +00:00
|
|
|
startAnimation([] {}, [&] {
|
2016-11-18 13:34:58 +00:00
|
|
|
clearLayers();
|
2016-12-13 17:07:56 +00:00
|
|
|
clearSpecialLayer();
|
2018-11-23 11:05:06 +00:00
|
|
|
_mainMenu.destroy();
|
2018-11-10 08:06:44 +00:00
|
|
|
}, Action::HideAll, animated);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 10:23:57 +00:00
|
|
|
void LayerStackWidget::hideTopLayer(anim::type animated) {
|
2018-09-06 13:59:47 +00:00
|
|
|
if (_specialLayer || _mainMenu) {
|
2017-09-20 10:23:57 +00:00
|
|
|
hideLayers(animated);
|
2016-12-13 17:07:56 +00:00
|
|
|
} else {
|
2017-09-20 10:23:57 +00:00
|
|
|
hideAll(animated);
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-06 14:58:43 +00:00
|
|
|
void LayerStackWidget::removeBodyCache() {
|
|
|
|
_background->removeBodyCache();
|
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent, false);
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
bool LayerStackWidget::layerShown() const {
|
2018-09-06 13:59:47 +00:00
|
|
|
return _specialLayer || currentLayer() || _mainMenu;
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
void LayerStackWidget::setCacheImages() {
|
|
|
|
auto bodyCache = QPixmap(), mainMenuCache = QPixmap();
|
2016-12-13 17:07:56 +00:00
|
|
|
auto specialLayerCache = QPixmap();
|
|
|
|
if (_specialLayer) {
|
2017-12-26 12:41:48 +00:00
|
|
|
Ui::SendPendingMoveResizeEvents(_specialLayer);
|
2017-05-24 12:20:50 +00:00
|
|
|
auto sides = RectPart::Left | RectPart::Right;
|
2016-12-13 17:07:56 +00:00
|
|
|
if (_specialLayer->y() > 0) {
|
2017-05-24 12:20:50 +00:00
|
|
|
sides |= RectPart::Top;
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
if (_specialLayer->y() + _specialLayer->height() < height()) {
|
2017-05-24 12:20:50 +00:00
|
|
|
sides |= RectPart::Bottom;
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
specialLayerCache = Ui::Shadow::grab(_specialLayer, st::boxRoundShadow, sides);
|
2016-11-18 13:34:58 +00:00
|
|
|
}
|
|
|
|
auto layerCache = QPixmap();
|
|
|
|
if (auto layer = currentLayer()) {
|
2016-12-13 17:07:56 +00:00
|
|
|
layerCache = Ui::Shadow::grab(layer, st::boxRoundShadow);
|
2016-11-18 13:34:58 +00:00
|
|
|
}
|
2018-04-06 16:23:09 +00:00
|
|
|
if (isAncestorOf(window()->focusWidget())) {
|
2016-12-23 13:21:01 +00:00
|
|
|
setFocus();
|
|
|
|
}
|
|
|
|
if (_mainMenu) {
|
2018-09-06 14:58:43 +00:00
|
|
|
removeBodyCache();
|
2016-12-23 13:21:01 +00:00
|
|
|
hideChildren();
|
2018-04-06 16:23:09 +00:00
|
|
|
bodyCache = Ui::GrabWidget(parentWidget());
|
2016-12-23 13:21:01 +00:00
|
|
|
showChildren();
|
2017-05-24 12:20:50 +00:00
|
|
|
mainMenuCache = Ui::Shadow::grab(_mainMenu, st::boxRoundShadow, RectPart::Right);
|
2016-12-23 13:21:01 +00:00
|
|
|
}
|
2016-11-18 13:34:58 +00:00
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent, !bodyCache.isNull());
|
|
|
|
updateLayerBoxes();
|
2017-02-21 13:45:56 +00:00
|
|
|
_background->setCacheImages(std::move(bodyCache), std::move(mainMenuCache), std::move(specialLayerCache), std::move(layerCache));
|
2016-11-18 13:34:58 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 11:00:31 +00:00
|
|
|
void LayerStackWidget::closeLayer(not_null<LayerWidget*> layer) {
|
|
|
|
const auto weak = make_weak(layer.get());
|
|
|
|
if (weak->inFocusChain()) {
|
|
|
|
setFocus();
|
|
|
|
}
|
|
|
|
if (!weak || !weak->setClosing()) {
|
2016-12-20 13:03:51 +00:00
|
|
|
// This layer is already closing.
|
|
|
|
return;
|
2018-11-26 11:00:31 +00:00
|
|
|
} else if (!weak) {
|
|
|
|
// setClosing() could've killed the layer.
|
|
|
|
return;
|
2016-12-20 13:03:51 +00:00
|
|
|
}
|
2018-11-26 11:00:31 +00:00
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
if (layer == _specialLayer) {
|
2017-09-20 10:23:57 +00:00
|
|
|
hideAll(anim::type::normal);
|
2016-11-18 13:34:58 +00:00
|
|
|
} else if (layer == currentLayer()) {
|
|
|
|
if (_layers.size() == 1) {
|
2017-09-20 10:23:57 +00:00
|
|
|
hideCurrent(anim::type::normal);
|
2016-08-16 16:53:10 +00:00
|
|
|
} else {
|
2018-11-26 11:00:31 +00:00
|
|
|
auto taken = std::move(_layers.back());
|
2016-08-16 16:53:10 +00:00
|
|
|
_layers.pop_back();
|
2018-11-26 11:00:31 +00:00
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
layer = currentLayer();
|
|
|
|
layer->parentResized();
|
|
|
|
if (!_background->animating()) {
|
|
|
|
layer->show();
|
|
|
|
showFinished();
|
|
|
|
}
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (auto i = _layers.begin(), e = _layers.end(); i != e; ++i) {
|
2018-11-26 11:00:31 +00:00
|
|
|
if (layer == i->get()) {
|
2016-08-16 16:53:10 +00:00
|
|
|
_layers.erase(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
void LayerStackWidget::updateLayerBoxes() {
|
2018-12-04 07:19:28 +00:00
|
|
|
const auto layerBox = [&] {
|
|
|
|
if (const auto layer = currentLayer()) {
|
2016-11-18 13:34:58 +00:00
|
|
|
return layer->geometry();
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
|
|
|
return QRect();
|
2018-12-04 07:19:28 +00:00
|
|
|
}();
|
|
|
|
const auto specialLayerBox = _specialLayer
|
|
|
|
? _specialLayer->geometry()
|
|
|
|
: QRect();
|
|
|
|
_background->setLayerBoxes(specialLayerBox, layerBox);
|
2014-11-25 12:15:29 +00:00
|
|
|
update();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2017-09-30 19:20:40 +00:00
|
|
|
void LayerStackWidget::finishAnimating() {
|
|
|
|
_background->finishAnimating();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
bool LayerStackWidget::canSetFocus() const {
|
2016-11-18 13:34:58 +00:00
|
|
|
return (currentLayer() || _specialLayer || _mainMenu);
|
2015-09-16 13:04:08 +00:00
|
|
|
}
|
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
void LayerStackWidget::setInnerFocus() {
|
2016-11-18 13:34:58 +00:00
|
|
|
if (_background->animating()) {
|
2016-08-16 16:53:10 +00:00
|
|
|
setFocus();
|
2016-11-18 13:34:58 +00:00
|
|
|
} else if (auto l = currentLayer()) {
|
2016-08-16 16:53:10 +00:00
|
|
|
l->setInnerFocus();
|
|
|
|
} else if (_specialLayer) {
|
|
|
|
_specialLayer->setInnerFocus();
|
2016-11-17 11:03:49 +00:00
|
|
|
} else if (_mainMenu) {
|
|
|
|
_mainMenu->setInnerFocus();
|
2015-09-16 13:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
bool LayerStackWidget::contentOverlapped(const QRect &globalRect) {
|
|
|
|
if (isHidden()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (_specialLayer && _specialLayer->overlaps(globalRect)) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-11-18 13:34:58 +00:00
|
|
|
if (auto layer = currentLayer()) {
|
|
|
|
return layer->overlaps(globalRect);
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
|
|
|
return false;
|
2015-10-01 14:05:05 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
template <typename SetupNew, typename ClearOld>
|
2017-09-19 10:32:34 +00:00
|
|
|
void LayerStackWidget::startAnimation(
|
|
|
|
SetupNew setupNewWidgets,
|
|
|
|
ClearOld clearOldWidgets,
|
|
|
|
Action action,
|
2017-09-20 10:23:57 +00:00
|
|
|
anim::type animated) {
|
2016-11-18 13:34:58 +00:00
|
|
|
if (App::quitting()) return;
|
|
|
|
|
2017-09-20 10:23:57 +00:00
|
|
|
if (animated == anim::type::instant) {
|
2017-09-19 10:32:34 +00:00
|
|
|
setupNewWidgets();
|
|
|
|
clearOldWidgets();
|
|
|
|
prepareForAnimation();
|
|
|
|
_background->skipAnimation(action);
|
|
|
|
} else {
|
|
|
|
setupNewWidgets();
|
|
|
|
setCacheImages();
|
2018-12-11 13:12:35 +00:00
|
|
|
const auto weak = make_weak(this);
|
2017-09-19 10:32:34 +00:00
|
|
|
clearOldWidgets();
|
2018-12-11 13:12:35 +00:00
|
|
|
if (weak) {
|
|
|
|
prepareForAnimation();
|
|
|
|
_background->startAnimation(action);
|
|
|
|
}
|
2017-09-19 10:32:34 +00:00
|
|
|
}
|
2016-11-18 13:34:58 +00:00
|
|
|
}
|
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
void LayerStackWidget::resizeEvent(QResizeEvent *e) {
|
2018-12-04 07:19:28 +00:00
|
|
|
const auto weak = make_weak(this);
|
2016-08-16 16:53:10 +00:00
|
|
|
_background->setGeometry(rect());
|
2018-12-04 07:19:28 +00:00
|
|
|
if (!weak) {
|
|
|
|
return;
|
|
|
|
}
|
2016-08-16 16:53:10 +00:00
|
|
|
if (_specialLayer) {
|
|
|
|
_specialLayer->parentResized();
|
2018-12-04 07:19:28 +00:00
|
|
|
if (!weak) {
|
|
|
|
return;
|
|
|
|
}
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
2018-12-04 07:19:28 +00:00
|
|
|
if (const auto layer = currentLayer()) {
|
2016-11-18 13:34:58 +00:00
|
|
|
layer->parentResized();
|
2018-12-04 07:19:28 +00:00
|
|
|
if (!weak) {
|
|
|
|
return;
|
|
|
|
}
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
2016-11-11 19:51:59 +00:00
|
|
|
if (_mainMenu) {
|
|
|
|
_mainMenu->resize(_mainMenu->width(), height());
|
2018-12-04 07:19:28 +00:00
|
|
|
if (!weak) {
|
|
|
|
return;
|
|
|
|
}
|
2016-11-11 19:51:59 +00:00
|
|
|
}
|
2016-11-18 13:34:58 +00:00
|
|
|
updateLayerBoxes();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 10:23:57 +00:00
|
|
|
void LayerStackWidget::showBox(
|
2018-04-06 16:23:09 +00:00
|
|
|
object_ptr<BoxContent> box,
|
|
|
|
LayerOptions options,
|
|
|
|
anim::type animated) {
|
|
|
|
if (options & LayerOption::KeepOther) {
|
|
|
|
if (options & LayerOption::ShowAfterOther) {
|
|
|
|
prependBox(std::move(box), animated);
|
|
|
|
} else {
|
|
|
|
appendBox(std::move(box), animated);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
replaceBox(std::move(box), animated);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerStackWidget::replaceBox(
|
2017-09-20 10:23:57 +00:00
|
|
|
object_ptr<BoxContent> box,
|
|
|
|
anim::type animated) {
|
2018-11-26 11:00:31 +00:00
|
|
|
const auto pointer = pushBox(std::move(box), animated);
|
2019-02-17 06:36:44 +00:00
|
|
|
const auto removeTill = ranges::find(
|
|
|
|
_layers,
|
|
|
|
pointer,
|
|
|
|
&std::unique_ptr<LayerWidget>::get);
|
|
|
|
_closingLayers.insert(
|
|
|
|
end(_closingLayers),
|
|
|
|
std::make_move_iterator(begin(_layers)),
|
|
|
|
std::make_move_iterator(removeTill));
|
|
|
|
_layers.erase(begin(_layers), removeTill);
|
|
|
|
clearClosingLayers();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
void LayerStackWidget::prepareForAnimation() {
|
|
|
|
if (isHidden()) {
|
|
|
|
show();
|
|
|
|
}
|
|
|
|
if (_mainMenu) {
|
|
|
|
_mainMenu->hide();
|
|
|
|
}
|
2016-08-16 16:53:10 +00:00
|
|
|
if (_specialLayer) {
|
2016-11-18 13:34:58 +00:00
|
|
|
_specialLayer->hide();
|
|
|
|
}
|
2018-11-26 11:00:31 +00:00
|
|
|
if (const auto layer = currentLayer()) {
|
2016-11-18 13:34:58 +00:00
|
|
|
layer->hide();
|
|
|
|
}
|
2015-10-27 02:39:02 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
void LayerStackWidget::animationDone() {
|
|
|
|
bool hidden = true;
|
|
|
|
if (_mainMenu) {
|
|
|
|
_mainMenu->show();
|
|
|
|
hidden = false;
|
|
|
|
}
|
2016-11-11 19:51:59 +00:00
|
|
|
if (_specialLayer) {
|
2016-11-18 13:34:58 +00:00
|
|
|
_specialLayer->show();
|
|
|
|
hidden = false;
|
2016-11-11 19:51:59 +00:00
|
|
|
}
|
2016-11-18 13:34:58 +00:00
|
|
|
if (auto layer = currentLayer()) {
|
|
|
|
layer->show();
|
|
|
|
hidden = false;
|
|
|
|
}
|
2018-11-23 11:05:06 +00:00
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent, false);
|
2016-11-18 13:34:58 +00:00
|
|
|
if (hidden) {
|
2018-04-06 16:23:09 +00:00
|
|
|
_hideFinishStream.fire({});
|
2016-11-11 19:51:59 +00:00
|
|
|
} else {
|
2016-11-18 13:34:58 +00:00
|
|
|
showFinished();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-06 16:23:09 +00:00
|
|
|
rpl::producer<> LayerStackWidget::hideFinishEvents() const {
|
|
|
|
return _hideFinishStream.events();
|
|
|
|
}
|
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
void LayerStackWidget::showFinished() {
|
2016-11-11 19:51:59 +00:00
|
|
|
fixOrder();
|
|
|
|
sendFakeMouseEvent();
|
2016-11-18 13:34:58 +00:00
|
|
|
updateLayerBoxes();
|
|
|
|
if (_specialLayer) {
|
|
|
|
_specialLayer->showFinished();
|
|
|
|
}
|
|
|
|
if (auto layer = currentLayer()) {
|
|
|
|
layer->showFinished();
|
|
|
|
}
|
2018-04-06 16:23:09 +00:00
|
|
|
if (canSetFocus()) {
|
|
|
|
setInnerFocus();
|
2016-11-18 13:34:58 +00:00
|
|
|
}
|
2016-11-11 19:51:59 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 10:23:57 +00:00
|
|
|
void LayerStackWidget::showSpecialLayer(
|
|
|
|
object_ptr<LayerWidget> layer,
|
|
|
|
anim::type animated) {
|
2018-11-23 11:05:06 +00:00
|
|
|
startAnimation([&] {
|
2018-11-09 15:16:27 +00:00
|
|
|
_specialLayer.destroy();
|
2017-02-21 13:45:56 +00:00
|
|
|
_specialLayer = std::move(layer);
|
2016-11-18 13:34:58 +00:00
|
|
|
initChildLayer(_specialLayer);
|
2018-11-23 11:05:06 +00:00
|
|
|
}, [&] {
|
|
|
|
_mainMenu.destroy();
|
2017-09-20 10:23:57 +00:00
|
|
|
}, Action::ShowSpecialLayer, animated);
|
|
|
|
}
|
|
|
|
|
2017-10-03 13:05:58 +00:00
|
|
|
bool LayerStackWidget::showSectionInternal(
|
|
|
|
not_null<Window::SectionMemento *> memento,
|
|
|
|
const SectionShow ¶ms) {
|
|
|
|
if (_specialLayer) {
|
|
|
|
return _specialLayer->showSectionInternal(memento, params);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-20 10:23:57 +00:00
|
|
|
void LayerStackWidget::hideSpecialLayer(anim::type animated) {
|
2018-11-23 11:05:06 +00:00
|
|
|
startAnimation([] {}, [&] {
|
2017-09-20 10:23:57 +00:00
|
|
|
clearSpecialLayer();
|
2018-11-23 11:05:06 +00:00
|
|
|
_mainMenu.destroy();
|
2017-09-20 10:23:57 +00:00
|
|
|
}, Action::HideSpecialLayer, animated);
|
2016-11-18 13:34:58 +00:00
|
|
|
}
|
|
|
|
|
2018-04-06 16:23:09 +00:00
|
|
|
void LayerStackWidget::showMainMenu(
|
|
|
|
not_null<Window::Controller*> controller,
|
|
|
|
anim::type animated) {
|
|
|
|
startAnimation([&] {
|
|
|
|
_mainMenu.create(this, controller);
|
2016-11-18 13:34:58 +00:00
|
|
|
_mainMenu->setGeometryToLeft(0, 0, _mainMenu->width(), height());
|
|
|
|
_mainMenu->setParent(this);
|
2018-11-23 11:05:06 +00:00
|
|
|
}, [&] {
|
2016-11-18 13:34:58 +00:00
|
|
|
clearLayers();
|
2018-11-09 15:16:27 +00:00
|
|
|
_specialLayer.destroy();
|
2017-09-20 10:23:57 +00:00
|
|
|
}, Action::ShowMainMenu, animated);
|
2016-11-18 13:34:58 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 10:23:57 +00:00
|
|
|
void LayerStackWidget::appendBox(
|
|
|
|
object_ptr<BoxContent> box,
|
|
|
|
anim::type animated) {
|
|
|
|
pushBox(std::move(box), animated);
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 10:23:57 +00:00
|
|
|
LayerWidget *LayerStackWidget::pushBox(
|
|
|
|
object_ptr<BoxContent> box,
|
|
|
|
anim::type animated) {
|
2016-11-18 13:34:58 +00:00
|
|
|
auto oldLayer = currentLayer();
|
|
|
|
if (oldLayer) {
|
2017-01-16 13:27:11 +00:00
|
|
|
if (oldLayer->inFocusChain()) setFocus();
|
2016-08-16 16:53:10 +00:00
|
|
|
oldLayer->hide();
|
|
|
|
}
|
2018-11-26 11:00:31 +00:00
|
|
|
_layers.push_back(std::make_unique<AbstractBox>(this, std::move(box)));
|
|
|
|
const auto raw = _layers.back().get();
|
|
|
|
initChildLayer(raw);
|
2016-08-16 16:53:10 +00:00
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
if (_layers.size() > 1) {
|
|
|
|
if (!_background->animating()) {
|
2018-11-26 11:00:31 +00:00
|
|
|
raw->setVisible(true);
|
2016-11-18 13:34:58 +00:00
|
|
|
showFinished();
|
|
|
|
}
|
2016-08-16 16:53:10 +00:00
|
|
|
} else {
|
2018-11-23 11:05:06 +00:00
|
|
|
startAnimation([] {}, [&] {
|
|
|
|
_mainMenu.destroy();
|
2017-09-20 10:23:57 +00:00
|
|
|
}, Action::ShowLayer, animated);
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
|
2018-11-26 11:00:31 +00:00
|
|
|
return raw;
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 10:23:57 +00:00
|
|
|
void LayerStackWidget::prependBox(
|
|
|
|
object_ptr<BoxContent> box,
|
|
|
|
anim::type animated) {
|
2016-11-18 13:34:58 +00:00
|
|
|
if (_layers.empty()) {
|
2018-04-06 16:23:09 +00:00
|
|
|
replaceBox(std::move(box), animated);
|
|
|
|
return;
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
2018-11-26 11:00:31 +00:00
|
|
|
_layers.insert(
|
|
|
|
begin(_layers),
|
|
|
|
std::make_unique<AbstractBox>(this, std::move(box)));
|
|
|
|
const auto raw = _layers.front().get();
|
|
|
|
raw->hide();
|
|
|
|
initChildLayer(raw);
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
|
|
|
|
2017-09-19 10:32:34 +00:00
|
|
|
bool LayerStackWidget::takeToThirdSection() {
|
|
|
|
return _specialLayer
|
|
|
|
? _specialLayer->takeToThirdSection()
|
|
|
|
: false;
|
|
|
|
}
|
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
void LayerStackWidget::clearLayers() {
|
2019-02-17 06:36:44 +00:00
|
|
|
_closingLayers.insert(
|
|
|
|
end(_closingLayers),
|
|
|
|
std::make_move_iterator(begin(_layers)),
|
|
|
|
std::make_move_iterator(end(_layers)));
|
|
|
|
_layers.clear();
|
|
|
|
clearClosingLayers();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerStackWidget::clearClosingLayers() {
|
|
|
|
const auto weak = make_weak(this);
|
|
|
|
while (!_closingLayers.empty()) {
|
|
|
|
const auto index = _closingLayers.size() - 1;
|
|
|
|
const auto layer = _closingLayers.back().get();
|
2018-11-26 11:00:31 +00:00
|
|
|
if (layer->inFocusChain()) {
|
|
|
|
setFocus();
|
|
|
|
}
|
2019-02-17 06:36:44 +00:00
|
|
|
|
|
|
|
// This may destroy LayerStackWidget (by calling Ui::hideLayer).
|
|
|
|
// So each time we check a weak pointer (if we are still alive).
|
2016-12-20 13:03:51 +00:00
|
|
|
layer->setClosing();
|
2019-02-17 06:36:44 +00:00
|
|
|
if (weak) {
|
|
|
|
// We could enqueue more closing layers, so we remove by index.
|
|
|
|
Assert(index < _closingLayers.size());
|
|
|
|
Assert(_closingLayers[index].get() == layer);
|
|
|
|
_closingLayers.erase(begin(_closingLayers) + index);
|
|
|
|
} else {
|
|
|
|
// All layers were already destroyed in ~LayerStackWidget.
|
|
|
|
break;
|
|
|
|
}
|
2016-11-18 13:34:58 +00:00
|
|
|
}
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void LayerStackWidget::clearSpecialLayer() {
|
|
|
|
if (_specialLayer) {
|
2016-12-20 13:03:51 +00:00
|
|
|
_specialLayer->setClosing();
|
2018-11-23 11:05:06 +00:00
|
|
|
_specialLayer.destroy();
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
void LayerStackWidget::initChildLayer(LayerWidget *layer) {
|
|
|
|
layer->setParent(this);
|
2018-11-26 11:00:31 +00:00
|
|
|
layer->setClosedCallback([=] { closeLayer(layer); });
|
|
|
|
layer->setResizedCallback([=] { updateLayerBoxes(); });
|
2017-12-26 12:41:48 +00:00
|
|
|
Ui::SendPendingMoveResizeEvents(layer);
|
2016-11-18 13:34:58 +00:00
|
|
|
layer->parentResized();
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LayerStackWidget::fixOrder() {
|
2016-11-18 13:34:58 +00:00
|
|
|
if (auto layer = currentLayer()) {
|
2016-08-16 16:53:10 +00:00
|
|
|
_background->raise();
|
2016-11-18 13:34:58 +00:00
|
|
|
layer->raise();
|
2016-08-16 16:53:10 +00:00
|
|
|
} else if (_specialLayer) {
|
|
|
|
_specialLayer->raise();
|
|
|
|
}
|
2016-11-11 19:51:59 +00:00
|
|
|
if (_mainMenu) {
|
|
|
|
_mainMenu->raise();
|
|
|
|
}
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
|
|
|
|
2016-08-19 17:26:31 +00:00
|
|
|
void LayerStackWidget::sendFakeMouseEvent() {
|
|
|
|
sendSynteticMouseEvent(this, QEvent::MouseMove, Qt::NoButton);
|
|
|
|
}
|
|
|
|
|
2018-11-26 11:00:31 +00:00
|
|
|
LayerStackWidget::~LayerStackWidget() = default;
|
2015-12-07 13:05:00 +00:00
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
} // namespace Window
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
MediaPreviewWidget::MediaPreviewWidget(QWidget *parent, not_null<Window::Controller*> controller) : TWidget(parent)
|
2017-04-07 18:10:49 +00:00
|
|
|
, _controller(controller)
|
2018-10-13 17:35:30 +00:00
|
|
|
, _emojiSize(Ui::Emoji::GetSizeLarge() / cIntRetinaFactor()) {
|
2015-12-07 13:05:00 +00:00
|
|
|
setAttribute(Qt::WA_TransparentForMouseEvents);
|
2017-08-04 14:54:32 +00:00
|
|
|
subscribe(Auth().downloaderTaskFinished(), [this] { update(); });
|
2015-12-07 13:05:00 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
void MediaPreviewWidget::paintEvent(QPaintEvent *e) {
|
2015-12-07 13:05:00 +00:00
|
|
|
Painter p(this);
|
|
|
|
QRect r(e->rect());
|
|
|
|
|
2016-09-20 13:03:42 +00:00
|
|
|
auto image = currentImage();
|
2016-09-10 20:54:59 +00:00
|
|
|
int w = image.width() / cIntRetinaFactor(), h = image.height() / cIntRetinaFactor();
|
2016-12-05 11:01:08 +00:00
|
|
|
auto shown = _a_shown.current(getms(), _hiding ? 0. : 1.);
|
|
|
|
if (!_a_shown.animating()) {
|
|
|
|
if (_hiding) {
|
|
|
|
hide();
|
2017-04-07 18:10:49 +00:00
|
|
|
_controller->disableGifPauseReason(Window::GifPauseReason::MediaPreview);
|
2016-12-05 11:01:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2015-12-07 13:05:00 +00:00
|
|
|
p.setOpacity(shown);
|
|
|
|
// w = qMax(qRound(w * (st::stickerPreviewMin + ((1. - st::stickerPreviewMin) * shown)) / 2.) * 2 + int(w % 2), 1);
|
|
|
|
// h = qMax(qRound(h * (st::stickerPreviewMin + ((1. - st::stickerPreviewMin) * shown)) / 2.) * 2 + int(h % 2), 1);
|
|
|
|
}
|
|
|
|
p.fillRect(r, st::stickerPreviewBg);
|
2016-09-10 20:54:59 +00:00
|
|
|
p.drawPixmap((width() - w) / 2, (height() - h) / 2, image);
|
2017-08-03 11:15:57 +00:00
|
|
|
if (!_emojiList.empty()) {
|
2018-10-13 17:35:30 +00:00
|
|
|
const auto emojiCount = _emojiList.size();
|
|
|
|
const auto emojiWidth = (emojiCount * _emojiSize) + (emojiCount - 1) * st::stickerEmojiSkip;
|
2017-02-15 08:50:11 +00:00
|
|
|
auto emojiLeft = (width() - emojiWidth) / 2;
|
2018-10-13 17:35:30 +00:00
|
|
|
const auto esize = Ui::Emoji::GetSizeLarge();
|
|
|
|
for (const auto emoji : _emojiList) {
|
|
|
|
Ui::Emoji::Draw(
|
|
|
|
p,
|
|
|
|
emoji,
|
|
|
|
esize,
|
|
|
|
emojiLeft,
|
|
|
|
(height() - h) / 2 - (_emojiSize * 2));
|
2016-09-10 20:54:59 +00:00
|
|
|
emojiLeft += _emojiSize + st::stickerEmojiSkip;
|
|
|
|
}
|
|
|
|
}
|
2015-12-07 13:05:00 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
void MediaPreviewWidget::resizeEvent(QResizeEvent *e) {
|
2015-12-07 13:05:00 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2018-07-13 21:25:47 +00:00
|
|
|
void MediaPreviewWidget::showPreview(
|
|
|
|
Data::FileOrigin origin,
|
|
|
|
not_null<DocumentData*> document) {
|
2017-12-10 10:26:58 +00:00
|
|
|
if (!document
|
|
|
|
|| (!document->isAnimation() && !document->sticker())
|
|
|
|
|| document->isVideoMessage()) {
|
2016-04-10 18:18:26 +00:00
|
|
|
hidePreview();
|
2015-12-07 13:05:00 +00:00
|
|
|
return;
|
2016-04-10 18:18:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
startShow();
|
2018-07-13 21:25:47 +00:00
|
|
|
_origin = origin;
|
2016-04-10 18:18:26 +00:00
|
|
|
_photo = nullptr;
|
|
|
|
_document = document;
|
2016-09-10 20:54:59 +00:00
|
|
|
fillEmojiString();
|
2016-04-10 18:18:26 +00:00
|
|
|
resetGifAndCache();
|
|
|
|
}
|
|
|
|
|
2018-07-13 21:25:47 +00:00
|
|
|
void MediaPreviewWidget::showPreview(
|
|
|
|
Data::FileOrigin origin,
|
|
|
|
not_null<PhotoData*> photo) {
|
2016-04-10 18:18:26 +00:00
|
|
|
startShow();
|
2018-07-13 21:25:47 +00:00
|
|
|
_origin = origin;
|
2016-04-10 18:18:26 +00:00
|
|
|
_photo = photo;
|
|
|
|
_document = nullptr;
|
2016-11-06 18:08:52 +00:00
|
|
|
fillEmojiString();
|
2016-04-10 18:18:26 +00:00
|
|
|
resetGifAndCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaPreviewWidget::startShow() {
|
|
|
|
_cache = QPixmap();
|
|
|
|
if (isHidden() || _a_shown.animating()) {
|
2017-04-03 14:13:55 +00:00
|
|
|
if (isHidden()) {
|
|
|
|
show();
|
2017-04-07 18:10:49 +00:00
|
|
|
_controller->enableGifPauseReason(Window::GifPauseReason::MediaPreview);
|
2017-04-03 14:13:55 +00:00
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
_hiding = false;
|
|
|
|
_a_shown.start([this] { update(); }, 0., 1., st::stickerPreviewDuration);
|
2016-04-10 18:18:26 +00:00
|
|
|
} else {
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaPreviewWidget::hidePreview() {
|
|
|
|
if (isHidden()) {
|
|
|
|
return;
|
2015-12-07 13:05:00 +00:00
|
|
|
}
|
2016-04-10 18:18:26 +00:00
|
|
|
if (_gif) _cache = currentImage();
|
2016-12-05 11:01:08 +00:00
|
|
|
_hiding = true;
|
|
|
|
_a_shown.start([this] { update(); }, 1., 0., st::stickerPreviewDuration);
|
2016-04-10 18:18:26 +00:00
|
|
|
_photo = nullptr;
|
|
|
|
_document = nullptr;
|
|
|
|
resetGifAndCache();
|
|
|
|
}
|
|
|
|
|
2016-09-10 20:54:59 +00:00
|
|
|
void MediaPreviewWidget::fillEmojiString() {
|
2017-08-15 14:34:30 +00:00
|
|
|
_emojiList.clear();
|
2016-11-06 18:08:52 +00:00
|
|
|
if (_photo) {
|
2017-08-15 14:34:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (auto sticker = _document->sticker()) {
|
|
|
|
if (auto list = Stickers::GetEmojiListFromSet(_document)) {
|
|
|
|
_emojiList = std::move(*list);
|
2017-08-03 11:15:57 +00:00
|
|
|
while (_emojiList.size() > kStickerPreviewEmojiLimit) {
|
|
|
|
_emojiList.pop_back();
|
2016-09-10 20:54:59 +00:00
|
|
|
}
|
2017-08-15 14:34:30 +00:00
|
|
|
} else if (auto emoji = Ui::Emoji::Find(sticker->alt)) {
|
|
|
|
_emojiList.push_back(emoji);
|
2016-09-10 20:54:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
void MediaPreviewWidget::resetGifAndCache() {
|
2016-09-28 20:28:53 +00:00
|
|
|
_gif.reset();
|
2015-12-07 13:05:00 +00:00
|
|
|
_cacheStatus = CacheNotLoaded;
|
2016-04-10 18:18:26 +00:00
|
|
|
_cachedSize = QSize();
|
2015-12-07 13:05:00 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
QSize MediaPreviewWidget::currentDimensions() const {
|
|
|
|
if (!_cachedSize.isEmpty()) {
|
|
|
|
return _cachedSize;
|
|
|
|
}
|
|
|
|
if (!_document && !_photo) {
|
|
|
|
_cachedSize = QSize(_cache.width() / cIntRetinaFactor(), _cache.height() / cIntRetinaFactor());
|
|
|
|
return _cachedSize;
|
|
|
|
}
|
2015-12-07 13:05:00 +00:00
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
QSize result, box;
|
|
|
|
if (_photo) {
|
2019-01-25 14:37:28 +00:00
|
|
|
result = QSize(_photo->width(), _photo->height());
|
2016-04-10 18:18:26 +00:00
|
|
|
box = QSize(width() - 2 * st::boxVerticalMargin, height() - 2 * st::boxVerticalMargin);
|
|
|
|
} else {
|
|
|
|
result = _document->dimensions;
|
2016-09-28 20:28:53 +00:00
|
|
|
if (_gif && _gif->ready()) {
|
2016-04-10 18:18:26 +00:00
|
|
|
result = QSize(_gif->width(), _gif->height());
|
|
|
|
}
|
|
|
|
if (_document->sticker()) {
|
|
|
|
box = QSize(st::maxStickerSize, st::maxStickerSize);
|
|
|
|
} else {
|
|
|
|
box = QSize(2 * st::maxStickerSize, 2 * st::maxStickerSize);
|
|
|
|
}
|
|
|
|
}
|
2018-10-15 11:44:48 +00:00
|
|
|
result = QSize(qMax(ConvertScale(result.width()), 1), qMax(ConvertScale(result.height()), 1));
|
2016-04-10 18:18:26 +00:00
|
|
|
if (result.width() > box.width()) {
|
|
|
|
result.setHeight(qMax((box.width() * result.height()) / result.width(), 1));
|
|
|
|
result.setWidth(box.width());
|
2015-12-27 21:37:48 +00:00
|
|
|
}
|
2016-04-10 18:18:26 +00:00
|
|
|
if (result.height() > box.height()) {
|
|
|
|
result.setWidth(qMax((box.height() * result.width()) / result.height(), 1));
|
|
|
|
result.setHeight(box.height());
|
2015-12-07 13:05:00 +00:00
|
|
|
}
|
2016-04-10 18:18:26 +00:00
|
|
|
if (_photo) {
|
|
|
|
_cachedSize = result;
|
2015-12-07 13:05:00 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
QPixmap MediaPreviewWidget::currentImage() const {
|
|
|
|
if (_document) {
|
|
|
|
if (_document->sticker()) {
|
2015-12-27 21:37:48 +00:00
|
|
|
if (_cacheStatus != CacheLoaded) {
|
2019-01-25 14:37:28 +00:00
|
|
|
if (const auto image = _document->getStickerLarge()) {
|
2015-12-27 21:37:48 +00:00
|
|
|
QSize s = currentDimensions();
|
2018-11-09 15:16:47 +00:00
|
|
|
_cache = image->pix(_origin, s.width(), s.height());
|
2015-12-27 21:37:48 +00:00
|
|
|
_cacheStatus = CacheLoaded;
|
2019-01-25 14:37:28 +00:00
|
|
|
} else if (_cacheStatus != CacheThumbLoaded
|
|
|
|
&& _document->hasThumbnail()
|
|
|
|
&& _document->thumbnail()->loaded()) {
|
2018-11-09 15:16:47 +00:00
|
|
|
QSize s = currentDimensions();
|
2019-01-25 14:37:28 +00:00
|
|
|
_cache = _document->thumbnail()->pixBlurred(_origin, s.width(), s.height());
|
2018-11-09 15:16:47 +00:00
|
|
|
_cacheStatus = CacheThumbLoaded;
|
2015-12-27 21:37:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2018-07-13 21:25:47 +00:00
|
|
|
_document->automaticLoad(_origin, nullptr);
|
2016-04-10 18:18:26 +00:00
|
|
|
if (_document->loaded()) {
|
2016-09-28 20:28:53 +00:00
|
|
|
if (!_gif && !_gif.isBad()) {
|
2016-06-24 10:37:29 +00:00
|
|
|
auto that = const_cast<MediaPreviewWidget*>(this);
|
2018-04-07 08:47:08 +00:00
|
|
|
that->_gif = Media::Clip::MakeReader(_document, FullMsgId(), [=](Media::Clip::Notification notification) {
|
2016-09-26 12:09:59 +00:00
|
|
|
that->clipCallback(notification);
|
|
|
|
});
|
2016-09-28 20:28:53 +00:00
|
|
|
if (_gif) _gif->setAutoplay();
|
2015-12-27 21:37:48 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-28 20:28:53 +00:00
|
|
|
if (_gif && _gif->started()) {
|
2017-04-03 14:13:55 +00:00
|
|
|
auto s = currentDimensions();
|
2017-04-07 18:10:49 +00:00
|
|
|
auto paused = _controller->isGifPausedAtLeastFor(Window::GifPauseReason::MediaPreview);
|
2017-12-18 17:50:25 +00:00
|
|
|
return _gif->current(s.width(), s.height(), s.width(), s.height(), ImageRoundRadius::None, RectPart::None, paused ? 0 : getms());
|
2015-12-27 21:37:48 +00:00
|
|
|
}
|
2019-01-25 14:37:28 +00:00
|
|
|
if (_cacheStatus != CacheThumbLoaded
|
|
|
|
&& _document->hasThumbnail()) {
|
2015-12-07 13:05:00 +00:00
|
|
|
QSize s = currentDimensions();
|
2019-01-25 14:37:28 +00:00
|
|
|
if (_document->thumbnail()->loaded()) {
|
|
|
|
_cache = _document->thumbnail()->pixBlurred(_origin, s.width(), s.height());
|
|
|
|
_cacheStatus = CacheThumbLoaded;
|
|
|
|
} else if (const auto blurred = _document->thumbnailInline()) {
|
|
|
|
_cache = _document->thumbnail()->pixBlurred(_origin, s.width(), s.height());
|
|
|
|
_cacheStatus = CacheThumbLoaded;
|
|
|
|
} else {
|
|
|
|
_document->thumbnail()->load(_origin);
|
|
|
|
}
|
2015-12-07 13:05:00 +00:00
|
|
|
}
|
|
|
|
}
|
2016-04-10 18:18:26 +00:00
|
|
|
} else if (_photo) {
|
|
|
|
if (_cacheStatus != CacheLoaded) {
|
2019-01-25 14:37:28 +00:00
|
|
|
if (_photo->loaded()) {
|
2016-04-10 18:18:26 +00:00
|
|
|
QSize s = currentDimensions();
|
2019-01-25 14:37:28 +00:00
|
|
|
_cache = _photo->large()->pix(_origin, s.width(), s.height());
|
2016-04-10 18:18:26 +00:00
|
|
|
_cacheStatus = CacheLoaded;
|
|
|
|
} else {
|
2019-01-25 14:37:28 +00:00
|
|
|
_photo->load(_origin);
|
|
|
|
if (_cacheStatus != CacheThumbLoaded) {
|
2016-04-10 18:18:26 +00:00
|
|
|
QSize s = currentDimensions();
|
2019-01-25 14:37:28 +00:00
|
|
|
if (_photo->thumbnail()->loaded()) {
|
|
|
|
_cache = _photo->thumbnail()->pixBlurred(_origin, s.width(), s.height());
|
|
|
|
_cacheStatus = CacheThumbLoaded;
|
|
|
|
} else if (_photo->thumbnailSmall()->loaded()) {
|
|
|
|
_cache = _photo->thumbnailSmall()->pixBlurred(_origin, s.width(), s.height());
|
|
|
|
_cacheStatus = CacheThumbLoaded;
|
|
|
|
} else if (const auto blurred = _photo->thumbnailInline()) {
|
|
|
|
_cache = blurred->pixBlurred(_origin, s.width(), s.height());
|
|
|
|
_cacheStatus = CacheThumbLoaded;
|
|
|
|
} else {
|
|
|
|
_photo->thumbnailSmall()->load(_origin);
|
|
|
|
}
|
2016-04-10 18:18:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-07 13:05:00 +00:00
|
|
|
}
|
|
|
|
return _cache;
|
|
|
|
}
|
|
|
|
|
2016-06-24 10:37:29 +00:00
|
|
|
void MediaPreviewWidget::clipCallback(Media::Clip::Notification notification) {
|
|
|
|
using namespace Media::Clip;
|
2015-12-27 21:37:48 +00:00
|
|
|
switch (notification) {
|
2016-06-24 10:37:29 +00:00
|
|
|
case NotificationReinit: {
|
2016-09-28 20:28:53 +00:00
|
|
|
if (_gif && _gif->state() == State::Error) {
|
|
|
|
_gif.setBad();
|
2015-12-27 21:37:48 +00:00
|
|
|
}
|
|
|
|
|
2016-09-28 20:28:53 +00:00
|
|
|
if (_gif && _gif->ready() && !_gif->started()) {
|
2015-12-27 21:37:48 +00:00
|
|
|
QSize s = currentDimensions();
|
2017-12-18 17:50:25 +00:00
|
|
|
_gif->start(s.width(), s.height(), s.width(), s.height(), ImageRoundRadius::None, RectPart::None);
|
2015-12-27 21:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
update();
|
|
|
|
} break;
|
|
|
|
|
2016-06-24 10:37:29 +00:00
|
|
|
case NotificationRepaint: {
|
2016-09-28 20:28:53 +00:00
|
|
|
if (_gif && !_gif->currentDisplayed()) {
|
2015-12-28 21:20:04 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
} break;
|
2015-12-27 21:37:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
MediaPreviewWidget::~MediaPreviewWidget() {
|
2015-12-07 13:05:00 +00:00
|
|
|
}
|