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
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
#include "ui/rp_widget.h"
|
2019-04-02 09:13:30 +00:00
|
|
|
#include "ui/effects/animations.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_file_origin.h"
|
2017-09-13 16:57:44 +00:00
|
|
|
|
2016-11-11 19:51:59 +00:00
|
|
|
namespace Window {
|
2017-09-30 18:26:45 +00:00
|
|
|
|
2016-11-11 19:51:59 +00:00
|
|
|
class MainMenu;
|
2019-06-06 10:21:40 +00:00
|
|
|
class SessionController;
|
2017-10-03 13:05:58 +00:00
|
|
|
class SectionMemento;
|
|
|
|
struct SectionShow;
|
2016-11-11 19:51:59 +00:00
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
class LayerWidget : public Ui::RpWidget {
|
2014-05-30 08:53:19 +00:00
|
|
|
public:
|
2017-09-13 16:57:44 +00:00
|
|
|
using RpWidget::RpWidget;
|
2016-11-04 08:23:50 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
virtual void parentResized() = 0;
|
2016-11-18 13:34:58 +00:00
|
|
|
virtual void showFinished() {
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-08-16 16:53:10 +00:00
|
|
|
void setInnerFocus();
|
2016-12-20 13:03:51 +00:00
|
|
|
bool setClosing() {
|
2016-12-13 17:07:56 +00:00
|
|
|
if (!_closing) {
|
|
|
|
_closing = true;
|
|
|
|
closeHook();
|
2016-12-20 13:03:51 +00:00
|
|
|
return true;
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
2016-12-20 13:03:51 +00:00
|
|
|
return false;
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool overlaps(const QRect &globalRect);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
void setClosedCallback(Fn<void()> callback) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_closedCallback = std::move(callback);
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
2018-06-04 15:35:11 +00:00
|
|
|
void setResizedCallback(Fn<void()> callback) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_resizedCallback = std::move(callback);
|
2015-10-01 14:05:05 +00:00
|
|
|
}
|
2017-09-19 10:32:34 +00:00
|
|
|
virtual bool takeToThirdSection() {
|
|
|
|
return false;
|
|
|
|
}
|
2017-10-03 13:05:58 +00:00
|
|
|
virtual bool showSectionInternal(
|
|
|
|
not_null<SectionMemento*> memento,
|
|
|
|
const SectionShow ¶ms) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-06-06 11:51:27 +00:00
|
|
|
virtual bool closeByOutsideClick() const {
|
|
|
|
return true;
|
|
|
|
}
|
2015-10-01 14:05:05 +00:00
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
protected:
|
2016-12-13 17:07:56 +00:00
|
|
|
void closeLayer() {
|
2018-11-26 11:00:31 +00:00
|
|
|
if (const auto callback = base::take(_closedCallback)) {
|
|
|
|
callback();
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-17 15:14:08 +00:00
|
|
|
void mousePressEvent(QMouseEvent *e) override {
|
|
|
|
e->accept();
|
|
|
|
}
|
2016-08-16 16:53:10 +00:00
|
|
|
void resizeEvent(QResizeEvent *e) override {
|
2016-12-13 17:07:56 +00:00
|
|
|
if (_resizedCallback) {
|
|
|
|
_resizedCallback();
|
|
|
|
}
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
|
|
|
virtual void doSetInnerFocus() {
|
|
|
|
setFocus();
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
virtual void closeHook() {
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
private:
|
|
|
|
bool _closing = false;
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void()> _closedCallback;
|
|
|
|
Fn<void()> _resizedCallback;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-04-06 16:23:09 +00:00
|
|
|
class LayerStackWidget : public Ui::RpWidget {
|
2014-05-30 08:53:19 +00:00
|
|
|
public:
|
2018-04-06 16:23:09 +00:00
|
|
|
LayerStackWidget(QWidget *parent);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-09-30 19:20:40 +00:00
|
|
|
void finishAnimating();
|
2018-04-06 16:23:09 +00:00
|
|
|
rpl::producer<> hideFinishEvents() const;
|
2014-12-12 16:27:03 +00:00
|
|
|
|
2017-09-20 10:23:57 +00:00
|
|
|
void showBox(
|
|
|
|
object_ptr<BoxContent> box,
|
2018-04-06 16:23:09 +00:00
|
|
|
LayerOptions options,
|
2017-09-20 10:23:57 +00:00
|
|
|
anim::type animated);
|
|
|
|
void showSpecialLayer(
|
|
|
|
object_ptr<LayerWidget> layer,
|
|
|
|
anim::type animated);
|
2018-04-06 16:23:09 +00:00
|
|
|
void showMainMenu(
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2017-09-20 10:23:57 +00:00
|
|
|
anim::type animated);
|
2017-09-19 10:32:34 +00:00
|
|
|
bool takeToThirdSection();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-09-16 13:04:08 +00:00
|
|
|
bool canSetFocus() const;
|
|
|
|
void setInnerFocus();
|
|
|
|
|
2015-10-01 14:05:05 +00:00
|
|
|
bool contentOverlapped(const QRect &globalRect);
|
|
|
|
|
2017-09-20 10:23:57 +00:00
|
|
|
void hideSpecialLayer(anim::type animated);
|
|
|
|
void hideLayers(anim::type animated);
|
|
|
|
void hideAll(anim::type animated);
|
|
|
|
void hideTopLayer(anim::type animated);
|
2018-04-17 15:41:52 +00:00
|
|
|
void setHideByBackgroundClick(bool hide);
|
2018-09-06 14:58:43 +00:00
|
|
|
void removeBodyCache();
|
2016-12-13 17:07:56 +00:00
|
|
|
|
2017-10-03 13:05:58 +00:00
|
|
|
bool showSectionInternal(
|
|
|
|
not_null<SectionMemento*> memento,
|
|
|
|
const SectionShow ¶ms);
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
bool layerShown() const;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
~LayerStackWidget();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
protected:
|
|
|
|
void keyPressEvent(QKeyEvent *e) override;
|
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
private:
|
2018-04-06 16:23:09 +00:00
|
|
|
void appendBox(
|
|
|
|
object_ptr<BoxContent> box,
|
|
|
|
anim::type animated);
|
|
|
|
void prependBox(
|
|
|
|
object_ptr<BoxContent> box,
|
|
|
|
anim::type animated);
|
|
|
|
void replaceBox(
|
|
|
|
object_ptr<BoxContent> box,
|
|
|
|
anim::type animated);
|
2018-12-12 05:47:24 +00:00
|
|
|
void backgroundClicked();
|
2018-04-06 16:23:09 +00:00
|
|
|
|
2017-09-20 10:23:57 +00:00
|
|
|
LayerWidget *pushBox(
|
|
|
|
object_ptr<BoxContent> box,
|
|
|
|
anim::type animated);
|
2016-11-18 13:34:58 +00:00
|
|
|
void showFinished();
|
2017-09-20 10:23:57 +00:00
|
|
|
void hideCurrent(anim::type animated);
|
2018-11-26 11:00:31 +00:00
|
|
|
void closeLayer(not_null<LayerWidget*> layer);
|
2016-11-18 13:34:58 +00:00
|
|
|
|
|
|
|
enum class Action {
|
|
|
|
ShowMainMenu,
|
|
|
|
ShowSpecialLayer,
|
|
|
|
ShowLayer,
|
2017-09-20 10:23:57 +00:00
|
|
|
HideSpecialLayer,
|
2016-11-18 13:34:58 +00:00
|
|
|
HideLayer,
|
|
|
|
HideAll,
|
|
|
|
};
|
|
|
|
template <typename SetupNew, typename ClearOld>
|
2017-09-19 10:32:34 +00:00
|
|
|
void 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
|
|
|
|
|
|
|
void prepareForAnimation();
|
|
|
|
void animationDone();
|
|
|
|
|
|
|
|
void setCacheImages();
|
2016-08-16 16:53:10 +00:00
|
|
|
void clearLayers();
|
2016-12-13 17:07:56 +00:00
|
|
|
void clearSpecialLayer();
|
2016-11-18 13:34:58 +00:00
|
|
|
void initChildLayer(LayerWidget *layer);
|
|
|
|
void updateLayerBoxes();
|
2016-08-16 16:53:10 +00:00
|
|
|
void fixOrder();
|
2016-08-19 17:26:31 +00:00
|
|
|
void sendFakeMouseEvent();
|
2019-02-17 06:36:44 +00:00
|
|
|
void clearClosingLayers();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
LayerWidget *currentLayer() {
|
2018-11-26 11:00:31 +00:00
|
|
|
return _layers.empty() ? nullptr : _layers.back().get();
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
2016-11-18 13:34:58 +00:00
|
|
|
const LayerWidget *currentLayer() const {
|
|
|
|
return const_cast<LayerStackWidget*>(this)->currentLayer();
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 11:00:31 +00:00
|
|
|
std::vector<std::unique_ptr<LayerWidget>> _layers;
|
2019-02-17 06:36:44 +00:00
|
|
|
std::vector<std::unique_ptr<LayerWidget>> _closingLayers;
|
2016-08-16 16:53:10 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<LayerWidget> _specialLayer = { nullptr };
|
2017-09-30 18:26:45 +00:00
|
|
|
object_ptr<MainMenu> _mainMenu = { nullptr };
|
2016-08-16 16:53:10 +00:00
|
|
|
|
|
|
|
class BackgroundWidget;
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<BackgroundWidget> _background;
|
2018-04-17 15:41:52 +00:00
|
|
|
bool _hideByBackgroundClick = true;
|
2016-08-16 16:53:10 +00:00
|
|
|
|
2018-04-06 16:23:09 +00:00
|
|
|
rpl::event_stream<> _hideFinishStream;
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
};
|
2015-12-07 13:05:00 +00:00
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
} // namespace Window
|
|
|
|
|
2016-09-26 13:57:08 +00:00
|
|
|
class MediaPreviewWidget : public TWidget, private base::Subscriber {
|
2015-12-07 13:05:00 +00:00
|
|
|
public:
|
2019-06-06 10:21:40 +00:00
|
|
|
MediaPreviewWidget(QWidget *parent, not_null<Window::SessionController*> controller);
|
2015-12-07 13:05:00 +00:00
|
|
|
|
2018-07-13 21:25:47 +00:00
|
|
|
void showPreview(
|
|
|
|
Data::FileOrigin origin,
|
|
|
|
not_null<DocumentData*> document);
|
|
|
|
void showPreview(
|
|
|
|
Data::FileOrigin origin,
|
|
|
|
not_null<PhotoData*> photo);
|
2015-12-07 13:05:00 +00:00
|
|
|
void hidePreview();
|
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
~MediaPreviewWidget();
|
2015-12-07 13:05:00 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
|
2015-12-07 13:05:00 +00:00
|
|
|
private:
|
|
|
|
QSize currentDimensions() const;
|
|
|
|
QPixmap currentImage() const;
|
2016-04-10 18:18:26 +00:00
|
|
|
void startShow();
|
2016-09-10 20:54:59 +00:00
|
|
|
void fillEmojiString();
|
2016-04-10 18:18:26 +00:00
|
|
|
void resetGifAndCache();
|
2015-12-07 13:05:00 +00:00
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionController*> _controller;
|
2017-04-07 18:10:49 +00:00
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
Ui::Animations::Simple _a_shown;
|
2016-12-05 11:01:08 +00:00
|
|
|
bool _hiding = false;
|
2018-07-13 21:25:47 +00:00
|
|
|
Data::FileOrigin _origin;
|
2016-04-10 18:18:26 +00:00
|
|
|
DocumentData *_document = nullptr;
|
|
|
|
PhotoData *_photo = nullptr;
|
2016-09-28 20:28:53 +00:00
|
|
|
Media::Clip::ReaderPointer _gif;
|
2015-12-27 21:37:48 +00:00
|
|
|
|
2016-09-10 20:54:59 +00:00
|
|
|
int _emojiSize;
|
2017-08-17 08:31:24 +00:00
|
|
|
std::vector<not_null<EmojiPtr>> _emojiList;
|
2016-09-10 20:54:59 +00:00
|
|
|
|
2016-06-24 10:37:29 +00:00
|
|
|
void clipCallback(Media::Clip::Notification notification);
|
2015-12-07 13:05:00 +00:00
|
|
|
|
|
|
|
enum CacheStatus {
|
|
|
|
CacheNotLoaded,
|
|
|
|
CacheThumbLoaded,
|
|
|
|
CacheLoaded,
|
|
|
|
};
|
2016-04-10 18:18:26 +00:00
|
|
|
mutable CacheStatus _cacheStatus = CacheNotLoaded;
|
2015-12-07 13:05:00 +00:00
|
|
|
mutable QPixmap _cache;
|
2016-04-10 18:18:26 +00:00
|
|
|
mutable QSize _cachedSize;
|
2015-12-07 13:05:00 +00:00
|
|
|
|
|
|
|
};
|
2017-02-03 20:07:26 +00:00
|
|
|
|
|
|
|
template <typename BoxType, typename ...Args>
|
|
|
|
inline object_ptr<BoxType> Box(Args&&... args) {
|
|
|
|
auto parent = static_cast<QWidget*>(nullptr);
|
2017-02-21 13:45:56 +00:00
|
|
|
return object_ptr<BoxType>(parent, std::forward<Args>(args)...);
|
2017-02-03 20:07:26 +00:00
|
|
|
}
|