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"
|
2016-12-13 17:07:56 +00:00
|
|
|
#include "boxes/abstractbox.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-12-13 17:07:56 +00:00
|
|
|
#include "styles/style_widgets.h"
|
2016-09-10 20:54:59 +00:00
|
|
|
#include "styles/style_stickers.h"
|
2016-12-13 17:07:56 +00:00
|
|
|
#include "ui/widgets/shadow.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:
|
2016-12-13 17:07:56 +00:00
|
|
|
BackgroundWidget(QWidget *parent) : TWidget(parent) {
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
|
|
|
|
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-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
|
|
|
|
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;
|
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
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
}
|
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;
|
|
|
|
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);
|
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.
|
|
|
|
Ui::Shadow::paint(p, myrtlrect(0, 0, mainMenuRight, height()), width(), st::boxRoundShadow, Ui::Shadow::Side::Right);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_specialLayerCache.isNull() && !specialLayerBox.isEmpty()) {
|
|
|
|
// All cache images are taken together with their shadows,
|
|
|
|
// so we paint shadow only when there is no cache.
|
|
|
|
auto sides = Ui::Shadow::Side::Left | Ui::Shadow::Side::Right;
|
|
|
|
auto topCorners = (specialLayerBox.y() > 0);
|
|
|
|
auto bottomCorners = (specialLayerBox.y() + specialLayerBox.height() < height());
|
|
|
|
if (topCorners) {
|
|
|
|
sides |= Ui::Shadow::Side::Top;
|
|
|
|
}
|
|
|
|
if (bottomCorners) {
|
|
|
|
sides |= Ui::Shadow::Side::Bottom;
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
auto parts = (topCorners ? (App::RectPart::TopLeft | App::RectPart::TopRight) : App::RectPart::None)
|
|
|
|
| (bottomCorners ? (App::RectPart::BottomLeft | App::RectPart::BottomRight) : App::RectPart::None);
|
|
|
|
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;
|
|
|
|
for_const (auto rect, region.rects()) {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-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;
|
|
|
|
}
|
|
|
|
|
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();
|
2016-12-13 17:07:56 +00:00
|
|
|
clearSpecialLayer();
|
2016-11-18 13:34:58 +00:00
|
|
|
_mainMenu.destroyDelayed();
|
|
|
|
}, Action::HideAll);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void LayerStackWidget::hideTopLayer() {
|
|
|
|
if (_specialLayer) {
|
|
|
|
hideLayers();
|
|
|
|
} else {
|
|
|
|
hideAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LayerStackWidget::layerShown() const {
|
|
|
|
return _specialLayer || currentLayer();
|
|
|
|
}
|
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
void LayerStackWidget::setCacheImages() {
|
|
|
|
auto bodyCache = QPixmap(), mainMenuCache = QPixmap();
|
|
|
|
if (isAncestorOf(App::wnd()->focusWidget())) {
|
|
|
|
setFocus();
|
|
|
|
}
|
|
|
|
if (_mainMenu) {
|
2016-12-09 18:56:01 +00:00
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent, false);
|
2016-11-18 13:34:58 +00:00
|
|
|
hideChildren();
|
|
|
|
bodyCache = myGrab(App::wnd()->bodyWidget());
|
|
|
|
showChildren();
|
2016-12-13 17:07:56 +00:00
|
|
|
mainMenuCache = Ui::Shadow::grab(_mainMenu, st::boxRoundShadow, Ui::Shadow::Side::Right);
|
|
|
|
}
|
|
|
|
auto specialLayerCache = QPixmap();
|
|
|
|
if (_specialLayer) {
|
|
|
|
auto sides = Ui::Shadow::Side::Left | Ui::Shadow::Side::Right;
|
|
|
|
if (_specialLayer->y() > 0) {
|
|
|
|
sides |= Ui::Shadow::Side::Top;
|
|
|
|
}
|
|
|
|
if (_specialLayer->y() + _specialLayer->height() < height()) {
|
|
|
|
sides |= Ui::Shadow::Side::Bottom;
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
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) {
|
2016-12-13 17:07:56 +00:00
|
|
|
layer->closing();
|
2016-11-18 13:34:58 +00:00
|
|
|
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-12-13 17:07:56 +00:00
|
|
|
void LayerStackWidget::showBox(object_ptr<BoxContent> box) {
|
|
|
|
auto pointer = pushBox(std_::move(box));
|
|
|
|
while (!_layers.isEmpty() && _layers.front() != pointer) {
|
2016-11-18 13:34:58 +00:00
|
|
|
auto removingLayer = _layers.front();
|
|
|
|
_layers.pop_front();
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
removingLayer->closing();
|
2016-11-18 13:34:58 +00:00
|
|
|
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();
|
|
|
|
}
|
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();
|
|
|
|
}
|
|
|
|
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-12-13 17:07:56 +00:00
|
|
|
void LayerStackWidget::showSpecialLayer(object_ptr<LayerWidget> layer) {
|
|
|
|
startAnimation([this, layer = std_::move(layer)]() mutable {
|
2016-11-18 13:34:58 +00:00
|
|
|
_specialLayer.destroyDelayed();
|
2016-12-13 17:07:56 +00:00
|
|
|
_specialLayer = std_::move(layer);
|
2016-11-18 13:34:58 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void LayerStackWidget::appendBox(object_ptr<BoxContent> box) {
|
|
|
|
pushBox(std_::move(box));
|
|
|
|
}
|
|
|
|
|
|
|
|
LayerWidget *LayerStackWidget::pushBox(object_ptr<BoxContent> box) {
|
2016-11-18 13:34:58 +00:00
|
|
|
auto oldLayer = currentLayer();
|
|
|
|
if (oldLayer) {
|
2016-08-16 16:53:10 +00:00
|
|
|
oldLayer->hide();
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
auto layer = object_ptr<AbstractBox>(std_::move(box));
|
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-12-13 17:07:56 +00:00
|
|
|
|
|
|
|
return layer.data();
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void LayerStackWidget::prependBox(object_ptr<BoxContent> box) {
|
2016-11-18 13:34:58 +00:00
|
|
|
if (_layers.empty()) {
|
2016-12-13 17:07:56 +00:00
|
|
|
return showBox(std_::move(box));
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
auto layer = object_ptr<AbstractBox>(std_::move(box));
|
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)) {
|
2016-12-13 17:07:56 +00:00
|
|
|
layer->closing();
|
2016-11-18 13:34:58 +00:00
|
|
|
layer->hide();
|
|
|
|
layer->deleteLater();
|
|
|
|
}
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void LayerStackWidget::clearSpecialLayer() {
|
|
|
|
if (_specialLayer) {
|
|
|
|
_specialLayer->closing();
|
|
|
|
_specialLayer.destroyDelayed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
void LayerStackWidget::initChildLayer(LayerWidget *layer) {
|
|
|
|
layer->setParent(this);
|
2016-12-13 17:07:56 +00:00
|
|
|
layer->setClosedCallback([this, layer] { onLayerClosed(layer); });
|
|
|
|
layer->setResizedCallback([this] { onLayerResized(); });
|
2016-11-18 13:34:58 +00:00
|
|
|
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)
|
2016-09-10 20:54:59 +00:00
|
|
|
, _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();
|
2016-12-05 11:01:08 +00:00
|
|
|
auto shown = _a_shown.current(getms(), _hiding ? 0. : 1.);
|
|
|
|
if (!_a_shown.animating()) {
|
|
|
|
if (_hiding) {
|
|
|
|
hide();
|
|
|
|
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);
|
|
|
|
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::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();
|
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() {
|
|
|
|
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();
|
2016-11-21 20:26:54 +00:00
|
|
|
return _gif->current(s.width(), s.height(), s.width(), s.height(), ImageRoundRadius::None, ImageRoundCorner::None, getms());
|
2015-12-27 21:37:48 +00:00
|
|
|
}
|
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-11-21 20:26:54 +00:00
|
|
|
_gif->start(s.width(), s.height(), s.width(), s.height(), ImageRoundRadius::None, ImageRoundCorner::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
|
|
|
}
|