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
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2016-11-11 19:51:59 +00:00
|
|
|
namespace Window {
|
|
|
|
class MainMenu;
|
|
|
|
} // namespace Window
|
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
class LayerWidget : public TWidget {
|
2014-05-30 08:53:19 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2016-11-04 08:23:50 +00:00
|
|
|
using TWidget::TWidget;
|
|
|
|
|
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
|
|
|
|
2017-02-26 11:32:13 +00:00
|
|
|
void setClosedCallback(base::lambda<void()> callback) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_closedCallback = std::move(callback);
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
2017-02-26 11:32:13 +00:00
|
|
|
void setResizedCallback(base::lambda<void()> callback) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_resizedCallback = std::move(callback);
|
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() {
|
|
|
|
if (_closedCallback) {
|
|
|
|
_closedCallback();
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
base::lambda<void()> _closedCallback;
|
|
|
|
base::lambda<void()> _resizedCallback;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
class LayerStackWidget : public TWidget {
|
2014-05-30 08:53:19 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2016-08-16 16:53:10 +00:00
|
|
|
LayerStackWidget(QWidget *parent);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
void finishAnimation();
|
2014-12-12 16:27:03 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void showBox(object_ptr<BoxContent> box);
|
|
|
|
void showSpecialLayer(object_ptr<LayerWidget> layer);
|
2016-11-11 19:51:59 +00:00
|
|
|
void showMainMenu();
|
2016-12-13 17:07:56 +00:00
|
|
|
void appendBox(object_ptr<BoxContent> box);
|
|
|
|
void prependBox(object_ptr<BoxContent> box);
|
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);
|
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
void hideLayers();
|
|
|
|
void hideAll();
|
2016-12-13 17:07:56 +00:00
|
|
|
void hideTopLayer();
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void onLayerDestroyed(QObject *obj);
|
2016-11-18 13:34:58 +00:00
|
|
|
void onLayerClosed(LayerWidget *layer);
|
2016-08-16 16:53:10 +00:00
|
|
|
void onLayerResized();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
private:
|
2016-12-13 17:07:56 +00:00
|
|
|
LayerWidget *pushBox(object_ptr<BoxContent> box);
|
2016-11-18 13:34:58 +00:00
|
|
|
void showFinished();
|
|
|
|
void hideCurrent();
|
|
|
|
|
|
|
|
enum class Action {
|
|
|
|
ShowMainMenu,
|
|
|
|
ShowSpecialLayer,
|
|
|
|
ShowLayer,
|
|
|
|
HideLayer,
|
|
|
|
HideAll,
|
|
|
|
};
|
|
|
|
template <typename SetupNew, typename ClearOld>
|
|
|
|
void startAnimation(SetupNew setupNewWidgets, ClearOld clearOldWidgets, Action action);
|
|
|
|
|
|
|
|
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();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
LayerWidget *currentLayer() {
|
2016-08-16 16:53:10 +00:00
|
|
|
return _layers.empty() ? nullptr : _layers.back();
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
using Layers = QList<LayerWidget*>;
|
|
|
|
Layers _layers;
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<LayerWidget> _specialLayer = { nullptr };
|
|
|
|
object_ptr<Window::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;
|
2016-08-16 16:53:10 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
};
|
2015-12-07 13:05:00 +00:00
|
|
|
|
2016-09-26 13:57:08 +00:00
|
|
|
class MediaPreviewWidget : public TWidget, private base::Subscriber {
|
2015-12-07 13:05:00 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2016-04-10 18:18:26 +00:00
|
|
|
MediaPreviewWidget(QWidget *parent);
|
2015-12-07 13:05:00 +00:00
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
void showPreview(DocumentData *document);
|
|
|
|
void showPreview(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
|
|
|
|
2016-12-07 13:32:25 +00:00
|
|
|
Animation _a_shown;
|
2016-12-05 11:01:08 +00:00
|
|
|
bool _hiding = false;
|
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;
|
|
|
|
QList<EmojiPtr> _emojiList;
|
|
|
|
|
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
|
|
|
}
|