2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2014-12-01 10:47:38 +00:00
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2015-10-03 13:16:42 +00:00
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2016-02-08 10:56:18 +00:00
|
|
|
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "lang.h"
|
|
|
|
|
2016-06-24 10:37:29 +00:00
|
|
|
#include "media/media_clip_reader.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
#include "layerwidget.h"
|
|
|
|
#include "application.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "mainwindow.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
#include "mainwidget.h"
|
2016-04-07 18:05:28 +00:00
|
|
|
#include "ui/filedialog.h"
|
2016-11-16 10:44:06 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2016-09-10 20:54:59 +00:00
|
|
|
#include "styles/style_stickers.h"
|
2016-11-11 19:51:59 +00:00
|
|
|
#include "window/window_main_menu.h"
|
2016-09-10 20:54:59 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr int kStickerPreviewEmojiLimit = 10;
|
|
|
|
|
|
|
|
} // namespace
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
class LayerStackWidget::BackgroundWidget : public TWidget {
|
|
|
|
public:
|
|
|
|
BackgroundWidget(QWidget *parent) : TWidget(parent)
|
|
|
|
, _shadow(st::boxShadow) {
|
|
|
|
}
|
|
|
|
|
2016-11-20 12:54:07 +00:00
|
|
|
void setDoneCallback(base::lambda<void()> &&callback) {
|
2016-11-18 13:34:58 +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);
|
|
|
|
void setCacheImages(QPixmap &&bodyCache, QPixmap &&mainMenuCache, QPixmap &&specialLayerCache, QPixmap &&layerCache);
|
|
|
|
void startAnimation(Action action);
|
|
|
|
void finishAnimation();
|
|
|
|
|
|
|
|
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-11-18 13:34:58 +00:00
|
|
|
QPixmap _specialLayerCache;
|
|
|
|
QPixmap _layerCache;
|
2016-11-11 19:51:59 +00:00
|
|
|
|
2016-11-20 12:54:07 +00:00
|
|
|
base::lambda<void()> _doneCallback;
|
2016-11-18 13:34:58 +00:00
|
|
|
|
|
|
|
bool _wasAnimating = false;
|
|
|
|
bool _inPaintEvent = false;
|
|
|
|
FloatAnimation _a_shown;
|
|
|
|
FloatAnimation _a_mainMenuShown;
|
|
|
|
FloatAnimation _a_specialLayerShown;
|
|
|
|
FloatAnimation _a_layerShown;
|
2016-08-16 16:53:10 +00:00
|
|
|
|
2016-10-01 12:34:23 +00:00
|
|
|
Ui::RectShadow _shadow;
|
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
|
|
|
};
|
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
void LayerStackWidget::BackgroundWidget::setCacheImages(QPixmap &&bodyCache, QPixmap &&mainMenuCache, QPixmap &&specialLayerCache, QPixmap &&layerCache) {
|
|
|
|
_bodyCache = std_::move(bodyCache);
|
|
|
|
_mainMenuCache = std_::move(mainMenuCache);
|
|
|
|
_specialLayerCache = std_::move(specialLayerCache);
|
|
|
|
_layerCache = std_::move(layerCache);
|
|
|
|
_specialLayerCacheBox = _specialLayerBox;
|
|
|
|
_layerCacheBox = _layerBox;
|
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent, !_bodyCache.isNull());
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerStackWidget::BackgroundWidget::startAnimation(Action action) {
|
|
|
|
if (action == Action::ShowMainMenu) {
|
|
|
|
setMainMenuShown(true);
|
|
|
|
} else if (action != Action::HideLayer) {
|
|
|
|
setMainMenuShown(false);
|
|
|
|
}
|
|
|
|
if (action == Action::ShowSpecialLayer) {
|
|
|
|
setSpecialLayerShown(true);
|
|
|
|
} else if (action == Action::ShowMainMenu || action == Action::HideAll) {
|
|
|
|
setSpecialLayerShown(false);
|
|
|
|
}
|
|
|
|
if (action == Action::ShowLayer) {
|
|
|
|
setLayerShown(true);
|
|
|
|
} else {
|
|
|
|
setLayerShown(false);
|
|
|
|
}
|
|
|
|
_wasAnimating = true;
|
|
|
|
checkIfDone();
|
2016-08-16 16:53:10 +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;
|
|
|
|
_bodyCache = _mainMenuCache = _specialLayerCache = _layerCache = QPixmap();
|
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent, false);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
_mainMenuRight = _mainMenuShown ? (_mainMenuCache.width() / cIntRetinaFactor()) : 0;
|
|
|
|
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;
|
|
|
|
auto guard = base::scope_guard([this] {
|
|
|
|
_inPaintEvent = false;
|
|
|
|
checkIfDone();
|
|
|
|
});
|
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);
|
|
|
|
auto mainMenuRight = (_mainMenuCache.isNull() || mainMenuProgress < 0) ? _mainMenuRight : (mainMenuProgress < 0) ? _mainMenuRight : anim::interpolate(0, _mainMenuCache.width() / cIntRetinaFactor(), mainMenuProgress);
|
|
|
|
if (mainMenuRight) {
|
|
|
|
if (!_specialLayerCache.isNull()) {
|
|
|
|
specialLayerBox.setX(specialLayerBox.x() + mainMenuRight / 2);
|
2016-08-19 17:26:31 +00:00
|
|
|
}
|
2016-11-18 13:34:58 +00:00
|
|
|
if (!_layerCache.isNull()) {
|
|
|
|
layerBox.setX(layerBox.x() + mainMenuRight / 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
auto bg = myrtlrect(mainMenuRight, 0, width() - mainMenuRight, height());
|
|
|
|
p.fillRect(bg, st::layerBg);
|
|
|
|
if (mainMenuRight > 0) {
|
|
|
|
_shadow.paint(p, myrtlrect(0, 0, mainMenuRight, height()), 0, Ui::RectShadow::Side::Right);
|
|
|
|
}
|
|
|
|
if (!specialLayerBox.isEmpty()) {
|
|
|
|
p.setClipRegion(QRegion(bg) - specialLayerBox);
|
|
|
|
_shadow.paint(p, specialLayerBox, st::boxShadowShift);
|
|
|
|
}
|
|
|
|
|
|
|
|
p.setClipping(false);
|
|
|
|
if (!_specialLayerCache.isNull() && specialLayerOpacity > 0) {
|
|
|
|
p.setOpacity(specialLayerOpacity);
|
|
|
|
p.drawPixmap(specialLayerBox.topLeft(), _specialLayerCache);
|
|
|
|
}
|
|
|
|
if (!layerBox.isEmpty()) {
|
|
|
|
if (!_specialLayerCache.isNull()) {
|
|
|
|
p.setOpacity(layerOpacity * specialLayerOpacity);
|
|
|
|
p.setClipRegion(QRegion(specialLayerBox) - layerBox);
|
|
|
|
p.fillRect(specialLayerBox, st::layerBg);
|
|
|
|
}
|
|
|
|
p.setOpacity(layerOpacity);
|
|
|
|
p.setClipRegion(QRegion(bg) - layerBox);
|
|
|
|
_shadow.paint(p, layerBox, st::boxShadowShift);
|
|
|
|
p.setClipping(false);
|
|
|
|
}
|
|
|
|
if (!_layerCache.isNull() && layerOpacity > 0) {
|
|
|
|
p.setOpacity(layerOpacity);
|
|
|
|
p.drawPixmap(layerBox.topLeft(), _layerCache);
|
|
|
|
}
|
|
|
|
if (!_mainMenuCache.isNull() && mainMenuRight > 0) {
|
|
|
|
p.setOpacity(1.);
|
|
|
|
auto shownWidth = mainMenuRight * cIntRetinaFactor();
|
|
|
|
auto shownRect = rtlrect(_mainMenuCache.width() - shownWidth, 0, shownWidth, _mainMenuCache.height(), _mainMenuCache.width());
|
|
|
|
p.drawPixmapLeft(0, 0, mainMenuRight, height(), width(), _mainMenuCache, shownRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerStackWidget::BackgroundWidget::finishAnimation() {
|
|
|
|
_a_shown.finish();
|
|
|
|
_a_mainMenuShown.finish();
|
|
|
|
_a_specialLayerShown.finish();
|
|
|
|
_a_layerShown.finish();
|
|
|
|
checkIfDone();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerStackWidget::BackgroundWidget::animationCallback() {
|
|
|
|
update();
|
|
|
|
checkIfDone();
|
|
|
|
}
|
|
|
|
|
|
|
|
LayerStackWidget::LayerStackWidget(QWidget *parent) : TWidget(parent)
|
|
|
|
, _background(this) {
|
|
|
|
setGeometry(parentWidget()->rect());
|
|
|
|
hide();
|
|
|
|
_background->setDoneCallback([this] { animationDone(); });
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerWidget::setInnerFocus() {
|
|
|
|
if (!isAncestorOf(App::wnd()->focusWidget())) {
|
|
|
|
doSetInnerFocus();
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2016-11-18 13:34:58 +00:00
|
|
|
hideCurrent();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
void LayerStackWidget::mousePressEvent(QMouseEvent *e) {
|
2016-11-18 13:34:58 +00:00
|
|
|
hideCurrent();
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
void LayerStackWidget::hideCurrent() {
|
|
|
|
return currentLayer() ? hideLayers() : hideAll();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
void LayerStackWidget::hideLayers() {
|
|
|
|
startAnimation([] {}, [this] {
|
2016-08-17 15:14:08 +00:00
|
|
|
clearLayers();
|
2016-11-18 13:34:58 +00:00
|
|
|
}, Action::HideLayer);
|
2016-08-17 15:14:08 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
void LayerStackWidget::hideAll() {
|
|
|
|
startAnimation([] {}, [this] {
|
|
|
|
clearLayers();
|
|
|
|
_specialLayer.destroyDelayed();
|
|
|
|
_mainMenu.destroyDelayed();
|
|
|
|
}, Action::HideAll);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
void LayerStackWidget::setCacheImages() {
|
|
|
|
auto bodyCache = QPixmap(), mainMenuCache = QPixmap();
|
|
|
|
if (isAncestorOf(App::wnd()->focusWidget())) {
|
|
|
|
setFocus();
|
|
|
|
}
|
|
|
|
if (_mainMenu) {
|
|
|
|
hideChildren();
|
|
|
|
bodyCache = myGrab(App::wnd()->bodyWidget());
|
|
|
|
showChildren();
|
|
|
|
mainMenuCache = myGrab(_mainMenu);
|
|
|
|
}
|
|
|
|
auto specialLayerCache = _specialLayer ? myGrab(_specialLayer) : QPixmap();
|
|
|
|
auto layerCache = QPixmap();
|
|
|
|
if (auto layer = currentLayer()) {
|
|
|
|
layerCache = myGrab(layer);
|
|
|
|
}
|
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent, !bodyCache.isNull());
|
|
|
|
updateLayerBoxes();
|
|
|
|
_background->setCacheImages(std_::move(bodyCache), std_::move(mainMenuCache), std_::move(specialLayerCache), std_::move(layerCache));
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerStackWidget::onLayerClosed(LayerWidget *layer) {
|
|
|
|
layer->deleteLater();
|
|
|
|
if (layer == _specialLayer) {
|
|
|
|
hideAll();
|
|
|
|
} else if (layer == currentLayer()) {
|
|
|
|
if (_layers.size() == 1) {
|
|
|
|
hideCurrent();
|
2016-08-16 16:53:10 +00:00
|
|
|
} else {
|
2016-11-18 13:34:58 +00:00
|
|
|
layer->hide();
|
2016-08-16 16:53:10 +00:00
|
|
|
_layers.pop_back();
|
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) {
|
2016-11-18 13:34:58 +00:00
|
|
|
if (layer == *i) {
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void LayerStackWidget::onLayerResized() {
|
2016-11-18 13:34:58 +00:00
|
|
|
updateLayerBoxes();
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
void LayerStackWidget::updateLayerBoxes() {
|
2016-08-16 16:53:10 +00:00
|
|
|
auto getLayerBox = [this]() {
|
2016-11-18 13:34:58 +00:00
|
|
|
if (auto layer = currentLayer()) {
|
|
|
|
return layer->geometry();
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
|
|
|
return QRect();
|
|
|
|
};
|
2016-08-19 17:26:31 +00:00
|
|
|
auto getSpecialLayerBox = [this]() {
|
2016-11-18 13:34:58 +00:00
|
|
|
return _specialLayer ? _specialLayer->geometry() : QRect();
|
2016-08-19 17:26:31 +00:00
|
|
|
};
|
2016-11-18 13:34:58 +00:00
|
|
|
_background->setLayerBoxes(getSpecialLayerBox(), getLayerBox());
|
2014-11-25 12:15:29 +00:00
|
|
|
update();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
void LayerStackWidget::finishAnimation() {
|
|
|
|
_background->finishAnimation();
|
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>
|
|
|
|
void LayerStackWidget::startAnimation(SetupNew setupNewWidgets, ClearOld clearOldWidgets, Action action) {
|
|
|
|
if (App::quitting()) return;
|
|
|
|
|
|
|
|
setupNewWidgets();
|
|
|
|
setCacheImages();
|
|
|
|
clearOldWidgets();
|
|
|
|
prepareForAnimation();
|
|
|
|
_background->startAnimation(action);
|
|
|
|
}
|
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
void LayerStackWidget::resizeEvent(QResizeEvent *e) {
|
|
|
|
_background->setGeometry(rect());
|
|
|
|
if (_specialLayer) {
|
|
|
|
_specialLayer->parentResized();
|
|
|
|
}
|
2016-11-18 13:34:58 +00:00
|
|
|
if (auto layer = currentLayer()) {
|
|
|
|
layer->parentResized();
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
2016-11-11 19:51:59 +00:00
|
|
|
if (_mainMenu) {
|
|
|
|
_mainMenu->resize(_mainMenu->width(), height());
|
|
|
|
}
|
2016-11-18 13:34:58 +00:00
|
|
|
updateLayerBoxes();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
void LayerStackWidget::showLayer(LayerWidget *layer) {
|
|
|
|
appendLayer(layer);
|
|
|
|
while (!_layers.isEmpty() && _layers.front() != layer) {
|
|
|
|
auto removingLayer = _layers.front();
|
|
|
|
_layers.pop_front();
|
|
|
|
|
|
|
|
removingLayer->hide();
|
|
|
|
removingLayer->deleteLater();
|
|
|
|
}
|
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();
|
|
|
|
}
|
|
|
|
if (auto layer = currentLayer()) {
|
|
|
|
layer->hide();
|
|
|
|
}
|
|
|
|
if (auto app = App::app()) {
|
|
|
|
app->mtpPause();
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
if (hidden) {
|
|
|
|
App::wnd()->layerFinishedHide(this);
|
2016-11-11 19:51:59 +00:00
|
|
|
} else {
|
2016-11-18 13:34:58 +00:00
|
|
|
showFinished();
|
|
|
|
}
|
|
|
|
if (auto app = App::app()) {
|
|
|
|
app->mtpUnpause();
|
2016-11-11 19:51:59 +00:00
|
|
|
}
|
2016-11-18 13:34:58 +00:00
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerStackWidget::showFinished() {
|
2016-11-11 19:51:59 +00:00
|
|
|
fixOrder();
|
|
|
|
sendFakeMouseEvent();
|
2016-11-18 13:34:58 +00:00
|
|
|
updateLayerBoxes();
|
|
|
|
if (_mainMenu) {
|
|
|
|
_mainMenu->showFinished();
|
|
|
|
}
|
|
|
|
if (_specialLayer) {
|
|
|
|
_specialLayer->showFinished();
|
|
|
|
}
|
|
|
|
if (auto layer = currentLayer()) {
|
|
|
|
layer->showFinished();
|
|
|
|
}
|
|
|
|
if (auto window = App::wnd()) {
|
|
|
|
window->setInnerFocus();
|
|
|
|
}
|
2016-11-11 19:51:59 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
void LayerStackWidget::showSpecialLayer(LayerWidget *layer) {
|
|
|
|
startAnimation([this, layer] {
|
|
|
|
_specialLayer.destroyDelayed();
|
|
|
|
_specialLayer = layer;
|
|
|
|
initChildLayer(_specialLayer);
|
|
|
|
}, [this] {
|
|
|
|
clearLayers();
|
|
|
|
_mainMenu.destroyDelayed();
|
|
|
|
}, Action::ShowSpecialLayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerStackWidget::showMainMenu() {
|
|
|
|
startAnimation([this] {
|
|
|
|
_mainMenu.create(this);
|
|
|
|
_mainMenu->setGeometryToLeft(0, 0, _mainMenu->width(), height());
|
|
|
|
_mainMenu->setParent(this);
|
|
|
|
}, [this] {
|
|
|
|
clearLayers();
|
|
|
|
_specialLayer.destroyDelayed();
|
|
|
|
}, Action::ShowMainMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerStackWidget::appendLayer(LayerWidget *layer) {
|
|
|
|
auto oldLayer = currentLayer();
|
|
|
|
if (oldLayer) {
|
2016-08-16 16:53:10 +00:00
|
|
|
oldLayer->hide();
|
|
|
|
}
|
2016-11-18 13:34:58 +00:00
|
|
|
_layers.push_back(layer);
|
|
|
|
initChildLayer(layer);
|
2016-08-16 16:53:10 +00:00
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
if (_layers.size() > 1) {
|
|
|
|
if (!_background->animating()) {
|
|
|
|
layer->show();
|
|
|
|
showFinished();
|
|
|
|
}
|
2016-08-16 16:53:10 +00:00
|
|
|
} else {
|
2016-11-18 13:34:58 +00:00
|
|
|
startAnimation([] {}, [this] {
|
|
|
|
_mainMenu.destroyDelayed();
|
|
|
|
}, Action::ShowLayer);
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
void LayerStackWidget::prependLayer(LayerWidget *layer) {
|
|
|
|
if (_layers.empty()) {
|
|
|
|
return showLayer(layer);
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
2016-11-18 13:34:58 +00:00
|
|
|
layer->hide();
|
|
|
|
_layers.push_front(layer);
|
|
|
|
initChildLayer(layer);
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
void LayerStackWidget::clearLayers() {
|
|
|
|
for (auto layer : base::take(_layers)) {
|
|
|
|
layer->hide();
|
|
|
|
layer->deleteLater();
|
|
|
|
}
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
void LayerStackWidget::initChildLayer(LayerWidget *layer) {
|
|
|
|
layer->setParent(this);
|
|
|
|
connect(layer, SIGNAL(closed(LayerWidget*)), this, SLOT(onLayerClosed(LayerWidget*)));
|
|
|
|
connect(layer, SIGNAL(resized()), this, SLOT(onLayerResized()));
|
|
|
|
connect(layer, SIGNAL(destroyed(QObject*)), this, SLOT(onLayerDestroyed(QObject*)));
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
void LayerStackWidget::onLayerDestroyed(QObject *obj) {
|
|
|
|
if (obj == _specialLayer) {
|
|
|
|
_specialLayer = nullptr;
|
2016-11-18 13:34:58 +00:00
|
|
|
hideAll();
|
|
|
|
} else if (obj == currentLayer()) {
|
2016-08-16 16:53:10 +00:00
|
|
|
_layers.pop_back();
|
2016-11-18 13:34:58 +00:00
|
|
|
if (auto newLayer = currentLayer()) {
|
2016-08-16 16:53:10 +00:00
|
|
|
newLayer->parentResized();
|
2016-11-18 13:34:58 +00:00
|
|
|
if (!_background->animating()) {
|
2016-08-16 16:53:10 +00:00
|
|
|
newLayer->show();
|
2016-11-18 13:34:58 +00:00
|
|
|
showFinished();
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
|
|
|
} else if (!_specialLayer) {
|
2016-11-18 13:34:58 +00:00
|
|
|
hideAll();
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
2015-09-16 13:04:08 +00:00
|
|
|
} else {
|
2016-08-16 16:53:10 +00:00
|
|
|
for (auto i = _layers.begin(), e = _layers.end(); i != e; ++i) {
|
|
|
|
if (obj == *i) {
|
|
|
|
_layers.erase(i);
|
|
|
|
break;
|
|
|
|
}
|
2015-09-16 13:04:08 +00:00
|
|
|
}
|
2014-12-12 16:27:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
LayerStackWidget::~LayerStackWidget() {
|
|
|
|
if (App::wnd()) App::wnd()->noLayerStack(this);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-12-07 13:05:00 +00:00
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
MediaPreviewWidget::MediaPreviewWidget(QWidget *parent) : TWidget(parent)
|
2015-12-07 13:05:00 +00:00
|
|
|
, a_shown(0, 0)
|
2016-09-10 20:54:59 +00:00
|
|
|
, _a_shown(animation(this, &MediaPreviewWidget::step_shown))
|
|
|
|
, _emojiSize(EmojiSizes[EIndex + 1] / cIntRetinaFactor()) {
|
2015-12-07 13:05:00 +00:00
|
|
|
setAttribute(Qt::WA_TransparentForMouseEvents);
|
2016-09-26 13:57:08 +00:00
|
|
|
subscribe(FileDownload::ImageLoaded(), [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();
|
2015-12-07 13:05:00 +00:00
|
|
|
if (_a_shown.animating()) {
|
|
|
|
float64 shown = a_shown.current();
|
|
|
|
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);
|
|
|
|
if (!_emojiList.isEmpty()) {
|
|
|
|
int emojiCount = _emojiList.size();
|
2016-09-25 19:52:11 +00:00
|
|
|
int emojiWidth = (emojiCount * _emojiSize) + (emojiCount - 1) * st::stickerEmojiSkip;
|
2016-09-10 20:54:59 +00:00
|
|
|
int emojiLeft = (width() - emojiWidth) / 2;
|
2016-09-25 19:52:11 +00:00
|
|
|
int esize = EmojiSizes[EIndex + 1];
|
2016-09-10 20:54:59 +00:00
|
|
|
for_const (auto emoji, _emojiList) {
|
2016-09-25 19:52:11 +00:00
|
|
|
p.drawPixmapLeft(emojiLeft, (height() - h) / 2 - (_emojiSize * 2), width(), App::emojiLarge(), QRect(emoji->x * esize, emoji->y * esize, esize, esize));
|
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();
|
|
|
|
}
|
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
void MediaPreviewWidget::step_shown(float64 ms, bool timer) {
|
2015-12-07 13:05:00 +00:00
|
|
|
float64 dt = ms / st::stickerPreviewDuration;
|
|
|
|
if (dt >= 1) {
|
|
|
|
_a_shown.stop();
|
2015-12-08 12:33:37 +00:00
|
|
|
a_shown.finish();
|
2015-12-07 13:05:00 +00:00
|
|
|
if (a_shown.current() < 0.5) hide();
|
|
|
|
} else {
|
|
|
|
a_shown.update(dt, anim::linear);
|
|
|
|
}
|
2015-12-08 12:33:37 +00:00
|
|
|
if (timer) update();
|
2015-12-07 13:05:00 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
void MediaPreviewWidget::showPreview(DocumentData *document) {
|
|
|
|
if (!document || (!document->isAnimation() && !document->sticker())) {
|
|
|
|
hidePreview();
|
2015-12-07 13:05:00 +00:00
|
|
|
return;
|
2016-04-10 18:18:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
startShow();
|
|
|
|
_photo = nullptr;
|
|
|
|
_document = document;
|
2016-09-10 20:54:59 +00:00
|
|
|
fillEmojiString();
|
2016-04-10 18:18:26 +00:00
|
|
|
resetGifAndCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaPreviewWidget::showPreview(PhotoData *photo) {
|
|
|
|
if (!photo || photo->full->isNull()) {
|
|
|
|
hidePreview();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
startShow();
|
|
|
|
_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()) {
|
|
|
|
if (isHidden()) show();
|
|
|
|
a_shown.start(1);
|
2015-12-07 13:05:00 +00:00
|
|
|
_a_shown.start();
|
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();
|
|
|
|
a_shown.start(0);
|
|
|
|
_a_shown.start();
|
|
|
|
_photo = nullptr;
|
|
|
|
_document = nullptr;
|
|
|
|
resetGifAndCache();
|
|
|
|
}
|
|
|
|
|
2016-09-10 20:54:59 +00:00
|
|
|
void MediaPreviewWidget::fillEmojiString() {
|
|
|
|
auto getStickerEmojiList = [this](uint64 setId) {
|
|
|
|
QList<EmojiPtr> result;
|
|
|
|
auto &sets = Global::StickerSets();
|
|
|
|
auto it = sets.constFind(setId);
|
|
|
|
if (it == sets.cend()) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
for (auto i = it->emoji.cbegin(), e = it->emoji.cend(); i != e; ++i) {
|
|
|
|
for_const (auto document, *i) {
|
|
|
|
if (document == _document) {
|
|
|
|
result.append(i.key());
|
|
|
|
if (result.size() >= kStickerPreviewEmojiLimit) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
2016-11-06 18:08:52 +00:00
|
|
|
if (_photo) {
|
|
|
|
_emojiList.clear();
|
|
|
|
} else if (auto sticker = _document->sticker()) {
|
2016-09-10 20:54:59 +00:00
|
|
|
auto &inputSet = sticker->set;
|
|
|
|
if (inputSet.type() == mtpc_inputStickerSetID) {
|
|
|
|
_emojiList = getStickerEmojiList(inputSet.c_inputStickerSetID().vid.v);
|
|
|
|
} else {
|
|
|
|
_emojiList.clear();
|
|
|
|
if (auto emoji = emojiFromText(sticker->alt)) {
|
|
|
|
_emojiList.append(emoji);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_emojiList.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
result = QSize(_photo->full->width(), _photo->full->height());
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = QSize(qMax(convertScale(result.width()), 1), qMax(convertScale(result.height()), 1));
|
|
|
|
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) {
|
2016-04-10 18:18:26 +00:00
|
|
|
_document->checkSticker();
|
|
|
|
if (_document->sticker()->img->isNull()) {
|
|
|
|
if (_cacheStatus != CacheThumbLoaded && _document->thumb->loaded()) {
|
2015-12-27 21:37:48 +00:00
|
|
|
QSize s = currentDimensions();
|
2016-04-10 18:18:26 +00:00
|
|
|
_cache = _document->thumb->pixBlurred(s.width(), s.height());
|
2015-12-27 21:37:48 +00:00
|
|
|
_cacheStatus = CacheThumbLoaded;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
QSize s = currentDimensions();
|
2016-04-10 18:18:26 +00:00
|
|
|
_cache = _document->sticker()->img->pix(s.width(), s.height());
|
2015-12-27 21:37:48 +00:00
|
|
|
_cacheStatus = CacheLoaded;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2016-04-10 18:18:26 +00:00
|
|
|
_document->automaticLoad(nullptr);
|
|
|
|
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);
|
2016-09-28 20:28:53 +00:00
|
|
|
that->_gif = Media::Clip::MakeReader(_document->location(), _document->data(), [this, that](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()) {
|
2015-12-27 21:37:48 +00:00
|
|
|
QSize s = currentDimensions();
|
|
|
|
return _gif->current(s.width(), s.height(), s.width(), s.height(), getms());
|
|
|
|
}
|
2016-04-10 18:18:26 +00:00
|
|
|
if (_cacheStatus != CacheThumbLoaded && _document->thumb->loaded()) {
|
2015-12-07 13:05:00 +00:00
|
|
|
QSize s = currentDimensions();
|
2016-04-10 18:18:26 +00:00
|
|
|
_cache = _document->thumb->pixBlurred(s.width(), s.height());
|
2015-12-07 13:05:00 +00:00
|
|
|
_cacheStatus = CacheThumbLoaded;
|
|
|
|
}
|
|
|
|
}
|
2016-04-10 18:18:26 +00:00
|
|
|
} else if (_photo) {
|
|
|
|
if (_cacheStatus != CacheLoaded) {
|
|
|
|
if (_photo->full->loaded()) {
|
|
|
|
QSize s = currentDimensions();
|
|
|
|
_cache = _photo->full->pix(s.width(), s.height());
|
|
|
|
_cacheStatus = CacheLoaded;
|
|
|
|
} else {
|
|
|
|
if (_cacheStatus != CacheThumbLoaded && _photo->thumb->loaded()) {
|
|
|
|
QSize s = currentDimensions();
|
|
|
|
_cache = _photo->thumb->pixBlurred(s.width(), s.height());
|
|
|
|
_cacheStatus = CacheThumbLoaded;
|
|
|
|
}
|
|
|
|
_photo->thumb->load();
|
|
|
|
_photo->full->load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
2016-07-19 10:54:43 +00:00
|
|
|
_gif->start(s.width(), s.height(), s.width(), s.height(), ImageRoundRadius::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
|
|
|
}
|