tdesktop/Telegram/SourceFiles/window/layer_widget.h

252 lines
5.5 KiB
C
Raw Normal View History

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
2017-09-13 16:57:44 +00:00
#include "ui/rp_widget.h"
#include "data/data_file_origin.h"
2017-09-13 16:57:44 +00:00
2016-11-11 19:51:59 +00:00
namespace Window {
2016-11-11 19:51:59 +00:00
class MainMenu;
class Controller;
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 {
public:
2017-09-13 16:57:44 +00:00
using RpWidget::RpWidget;
virtual void parentResized() = 0;
virtual void showFinished() {
}
void setInnerFocus();
bool setClosing() {
if (!_closing) {
_closing = true;
closeHook();
return true;
}
return false;
}
bool overlaps(const QRect &globalRect);
void setClosedCallback(Fn<void()> callback) {
_closedCallback = std::move(callback);
}
void setResizedCallback(Fn<void()> callback) {
_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;
}
virtual bool showSectionInternal(
not_null<SectionMemento*> memento,
const SectionShow &params) {
return false;
}
virtual bool closeByOutsideClick() const {
return true;
}
2015-10-01 14:05:05 +00:00
protected:
void closeLayer() {
2018-11-26 11:00:31 +00:00
if (const auto callback = base::take(_closedCallback)) {
callback();
}
}
void mousePressEvent(QMouseEvent *e) override {
e->accept();
}
void resizeEvent(QResizeEvent *e) override {
if (_resizedCallback) {
_resizedCallback();
}
}
virtual void doSetInnerFocus() {
setFocus();
}
virtual void closeHook() {
}
private:
bool _closing = false;
Fn<void()> _closedCallback;
Fn<void()> _resizedCallback;
};
2018-04-06 16:23:09 +00:00
class LayerStackWidget : public Ui::RpWidget {
public:
2018-04-06 16:23:09 +00:00
LayerStackWidget(QWidget *parent);
void finishAnimating();
2018-04-06 16:23:09 +00:00
rpl::producer<> hideFinishEvents() const;
void showBox(
object_ptr<BoxContent> box,
2018-04-06 16:23:09 +00:00
LayerOptions options,
anim::type animated);
void showSpecialLayer(
object_ptr<LayerWidget> layer,
anim::type animated);
2018-04-06 16:23:09 +00:00
void showMainMenu(
not_null<Window::Controller*> controller,
anim::type animated);
2017-09-19 10:32:34 +00:00
bool takeToThirdSection();
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);
void hideSpecialLayer(anim::type animated);
void hideLayers(anim::type animated);
void hideAll(anim::type animated);
void hideTopLayer(anim::type animated);
void setHideByBackgroundClick(bool hide);
void removeBodyCache();
bool showSectionInternal(
not_null<SectionMemento*> memento,
const SectionShow &params);
bool layerShown() const;
~LayerStackWidget();
protected:
void keyPressEvent(QKeyEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
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);
void backgroundClicked();
2018-04-06 16:23:09 +00:00
LayerWidget *pushBox(
object_ptr<BoxContent> box,
anim::type animated);
void showFinished();
void hideCurrent(anim::type animated);
2018-11-26 11:00:31 +00:00
void closeLayer(not_null<LayerWidget*> layer);
enum class Action {
ShowMainMenu,
ShowSpecialLayer,
ShowLayer,
HideSpecialLayer,
HideLayer,
HideAll,
};
template <typename SetupNew, typename ClearOld>
2017-09-19 10:32:34 +00:00
void startAnimation(
SetupNew setupNewWidgets,
ClearOld clearOldWidgets,
Action action,
anim::type animated);
void prepareForAnimation();
void animationDone();
void setCacheImages();
void clearLayers();
void clearSpecialLayer();
void initChildLayer(LayerWidget *layer);
void updateLayerBoxes();
void fixOrder();
void sendFakeMouseEvent();
void clearClosingLayers();
LayerWidget *currentLayer() {
2018-11-26 11:00:31 +00:00
return _layers.empty() ? nullptr : _layers.back().get();
}
const LayerWidget *currentLayer() const {
return const_cast<LayerStackWidget*>(this)->currentLayer();
}
2018-11-26 11:00:31 +00:00
std::vector<std::unique_ptr<LayerWidget>> _layers;
std::vector<std::unique_ptr<LayerWidget>> _closingLayers;
object_ptr<LayerWidget> _specialLayer = { nullptr };
object_ptr<MainMenu> _mainMenu = { nullptr };
class BackgroundWidget;
object_ptr<BackgroundWidget> _background;
bool _hideByBackgroundClick = true;
2018-04-06 16:23:09 +00:00
rpl::event_stream<> _hideFinishStream;
};
2015-12-07 13:05:00 +00:00
} // namespace Window
class MediaPreviewWidget : public TWidget, private base::Subscriber {
2015-12-07 13:05:00 +00:00
public:
MediaPreviewWidget(QWidget *parent, not_null<Window::Controller*> 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();
~MediaPreviewWidget();
2015-12-07 13:05:00 +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;
void startShow();
void fillEmojiString();
void resetGifAndCache();
2015-12-07 13:05:00 +00:00
not_null<Window::Controller*> _controller;
Animation _a_shown;
bool _hiding = false;
2018-07-13 21:25:47 +00:00
Data::FileOrigin _origin;
DocumentData *_document = nullptr;
PhotoData *_photo = nullptr;
Media::Clip::ReaderPointer _gif;
2015-12-27 21:37:48 +00:00
int _emojiSize;
std::vector<not_null<EmojiPtr>> _emojiList;
void clipCallback(Media::Clip::Notification notification);
2015-12-07 13:05:00 +00:00
enum CacheStatus {
CacheNotLoaded,
CacheThumbLoaded,
CacheLoaded,
};
mutable CacheStatus _cacheStatus = CacheNotLoaded;
2015-12-07 13:05:00 +00:00
mutable QPixmap _cache;
mutable QSize _cachedSize;
2015-12-07 13:05:00 +00:00
};
template <typename BoxType, typename ...Args>
inline object_ptr<BoxType> Box(Args&&... args) {
auto parent = static_cast<QWidget*>(nullptr);
return object_ptr<BoxType>(parent, std::forward<Args>(args)...);
}