tdesktop/Telegram/SourceFiles/media/view/media_view_overlay_widget.h

468 lines
12 KiB
C
Raw Normal View History

2014-08-06 14:40:21 +00:00
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
2014-08-06 14:40:21 +00:00
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
2014-08-06 14:40:21 +00:00
*/
#pragma once
#include "ui/rp_widget.h"
#include "ui/widgets/dropdown_menu.h"
2019-03-07 11:35:28 +00:00
#include "ui/effects/animations.h"
#include "ui/effects/radial_animation.h"
#include "data/data_shared_media.h"
#include "data/data_user_photos.h"
#include "data/data_web_page.h"
2019-02-27 11:36:19 +00:00
#include "media/view/media_view_playback_controls.h"
2015-04-11 10:04:10 +00:00
namespace Ui {
class PopupMenu;
class LinkButton;
class RoundButton;
} // namespace Ui
namespace Window {
namespace Theme {
struct Preview;
} // namespace Theme
} // namespace Window
namespace Notify {
struct PeerUpdate;
} // namespace Notify
namespace Media {
namespace Player {
struct TrackState;
} // namespace Player
2019-02-27 11:36:19 +00:00
namespace Streaming {
struct Information;
2019-02-27 11:36:19 +00:00
struct Update;
2019-03-05 13:56:27 +00:00
enum class Error;
2019-02-27 11:36:19 +00:00
} // namespace Streaming
} // namespace Media
namespace Media {
namespace View {
class GroupThumbs;
#if defined Q_OS_MAC && !defined OS_MAC_OLD
#define USE_OPENGL_OVERLAY_WIDGET
#endif // Q_OS_MAC && !OS_MAC_OLD
#ifdef USE_OPENGL_OVERLAY_WIDGET
using OverlayParent = Ui::RpWidgetWrap<QOpenGLWidget>;
#else // USE_OPENGL_OVERLAY_WIDGET
using OverlayParent = Ui::RpWidget;
#endif // USE_OPENGL_OVERLAY_WIDGET
2019-02-27 11:36:19 +00:00
class OverlayWidget final
: public OverlayParent
, private base::Subscriber
, public ClickHandlerHost
, private PlaybackControls::Delegate {
2014-08-06 14:40:21 +00:00
Q_OBJECT
public:
OverlayWidget();
2014-08-15 11:19:32 +00:00
void showPhoto(not_null<PhotoData*> photo, HistoryItem *context);
void showPhoto(not_null<PhotoData*> photo, not_null<PeerData*> context);
void showDocument(not_null<DocumentData*> document, HistoryItem *context);
2015-04-11 10:04:10 +00:00
void leaveToChildEvent(QEvent *e, QWidget *child) override { // e -- from enterEvent() of child TWidget
2015-04-11 10:04:10 +00:00
updateOverState(OverNone);
}
void enterFromChildEvent(QEvent *e, QWidget *child) override { // e -- from leaveEvent() of child TWidget
2015-04-11 10:04:10 +00:00
updateOver(mapFromGlobal(QCursor::pos()));
}
2015-04-11 10:04:10 +00:00
void close();
void activateControls();
2015-04-19 10:29:19 +00:00
void onDocClick();
PeerData *ui_getPeerForMouseAction();
void clearData();
~OverlayWidget();
// ClickHandlerHost interface
void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override;
void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override;
private slots:
2015-04-11 10:04:10 +00:00
void onHideControls(bool force = false);
void onScreenResized(int screen);
2015-04-11 10:04:10 +00:00
void onToMessage();
2015-04-19 10:29:19 +00:00
void onSaveAs();
void onDownload();
2015-04-19 10:29:19 +00:00
void onSaveCancel();
void onShowInFolder();
void onForward();
void onDelete();
void onOverview();
void onCopy();
void onMenuDestroy(QObject *obj);
void receiveMouse();
void onAttachedStickers();
2015-04-11 10:04:10 +00:00
void onDropdown();
void onTouchTimer();
2014-08-06 14:40:21 +00:00
void updateImage();
2014-08-06 14:40:21 +00:00
private:
2019-02-27 11:36:19 +00:00
struct Streamed;
enum OverState {
OverNone,
OverLeftNav,
OverRightNav,
OverClose,
OverHeader,
OverName,
OverDate,
OverSave,
OverMore,
OverIcon,
OverVideo,
};
struct Entity {
base::optional_variant<
not_null<PhotoData*>,
not_null<DocumentData*>> data;
HistoryItem *item;
};
void paintEvent(QPaintEvent *e) override;
void keyPressEvent(QKeyEvent *e) override;
void wheelEvent(QWheelEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void mouseDoubleClickEvent(QMouseEvent *e) override;
void mouseMoveEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
void contextMenuEvent(QContextMenuEvent *e) override;
void touchEvent(QTouchEvent *e);
bool eventHook(QEvent *e) override;
bool eventFilter(QObject *obj, QEvent *e) override;
void setVisibleHook(bool visible) override;
2019-02-27 11:36:19 +00:00
void playbackControlsPlay() override;
void playbackControlsPause() override;
void playbackControlsSeekProgress(crl::time position) override;
void playbackControlsSeekFinished(crl::time position) override;
void playbackControlsVolumeChanged(float64 volume) override;
2019-03-12 05:09:53 +00:00
float64 playbackControlsCurrentVolume() override;
2019-02-27 11:36:19 +00:00
void playbackControlsToFullScreen() override;
void playbackControlsFromFullScreen() override;
void playbackPauseResume();
void playbackToggleFullScreen();
2019-03-01 11:16:55 +00:00
void playbackPauseOnCall();
void playbackResumeOnCall();
void playbackPauseMusic();
2019-03-01 11:16:55 +00:00
void playbackWaitingChange(bool waiting);
2019-02-27 11:36:19 +00:00
void updateOver(QPoint mpos);
void moveToScreen(bool force = false);
bool moveToNext(int delta);
void preloadData(int delta);
Entity entityForUserPhotos(int index) const;
Entity entityForSharedMedia(int index) const;
Entity entityForCollage(int index) const;
Entity entityByIndex(int index) const;
Entity entityForItemId(const FullMsgId &itemId) const;
bool moveToEntity(const Entity &entity, int preloadDelta = 0);
void setContext(base::optional_variant<
not_null<HistoryItem*>,
not_null<PeerData*>> context);
void refreshLang();
void showSaveMsgFile();
void updateMixerVideoVolume() const;
struct SharedMedia;
using SharedMediaType = SharedMediaWithLastSlice::Type;
using SharedMediaKey = SharedMediaWithLastSlice::Key;
2018-09-21 16:28:46 +00:00
std::optional<SharedMediaType> sharedMediaType() const;
std::optional<SharedMediaKey> sharedMediaKey() const;
std::optional<SharedMediaType> computeOverviewType() const;
bool validSharedMedia() const;
void validateSharedMedia();
void handleSharedMediaUpdate(SharedMediaWithLastSlice &&update);
struct UserPhotos;
2017-09-06 14:50:11 +00:00
using UserPhotosKey = UserPhotosSlice::Key;
2018-09-21 16:28:46 +00:00
std::optional<UserPhotosKey> userPhotosKey() const;
bool validUserPhotos() const;
void validateUserPhotos();
2017-09-06 14:50:11 +00:00
void handleUserPhotosUpdate(UserPhotosSlice &&update);
struct Collage;
using CollageKey = WebPageCollage::Item;
std::optional<CollageKey> collageKey() const;
bool validCollage() const;
void validateCollage();
2018-07-13 21:25:47 +00:00
Data::FileOrigin fileOrigin() const;
void refreshFromLabel(HistoryItem *item);
void refreshCaption(HistoryItem *item);
void refreshMediaViewer();
void refreshNavVisibility();
void refreshGroupThumbs();
void dropdownHidden();
void updateDocSize();
void updateControls();
void updateActions();
void resizeCenteredControls();
void resizeContentByScreenSize();
void checkLoadingWhileStreaming();
void displayPhoto(not_null<PhotoData*> photo, HistoryItem *item);
void displayDocument(DocumentData *document, HistoryItem *item);
void displayFinished();
void redisplayContent();
2015-04-11 10:04:10 +00:00
void findCurrent();
void updateCursor();
void setZoomLevel(int newZoom);
2019-02-27 11:36:19 +00:00
void updatePlaybackState();
void restartAtSeekPosition(crl::time position);
void refreshClipControllerGeometry();
void refreshCaptionGeometry();
2016-07-11 18:05:46 +00:00
2019-02-27 11:36:19 +00:00
void initStreaming();
void initStreamingThumbnail();
void streamingReady(Streaming::Information &&info);
2019-02-27 11:36:19 +00:00
void createStreamingObjects();
void handleStreamingUpdate(Streaming::Update &&update);
void handleStreamingError(Streaming::Error &&error);
2019-03-01 11:16:55 +00:00
void validateStreamedGoodThumbnail();
2016-07-11 18:05:46 +00:00
void initThemePreview();
void destroyThemePreview();
void updateThemePreviewGeometry();
void documentUpdated(DocumentData *doc);
void changingMsgId(not_null<HistoryItem*> row, MsgId newId);
2019-02-27 11:36:19 +00:00
QRect contentRect() const;
void contentSizeChanged();
2019-02-27 11:36:19 +00:00
// Radial animation interface.
float64 radialProgress() const;
bool radialLoading() const;
QRect radialRect() const;
void radialStart();
crl::time radialTimeShift() const;
void updateHeader();
void snapXY();
2019-04-01 14:53:18 +00:00
void clearControlsState();
bool stateAnimationCallback(crl::time ms);
bool radialAnimationCallback(crl::time now);
void waitingAnimationCallback();
2019-04-01 14:53:18 +00:00
bool updateControlsAnimation(crl::time now);
void zoomIn();
void zoomOut();
void zoomReset();
void zoomUpdate(int32 &newZoom);
void paintRadialLoading(Painter &p, bool radial, float64 radialOpacity);
void paintRadialLoadingContent(
Painter &p,
QRect inner,
bool radial,
float64 radialOpacity) const;
void paintThemePreview(Painter &p, QRect clip);
void updateOverRect(OverState state);
bool updateOverState(OverState newState);
float64 overLevel(OverState control) const;
void checkGroupThumbsAnimation();
void initGroupThumbs();
void validatePhotoImage(Image *image, bool blurred);
void validatePhotoCurrentImage();
2019-02-27 11:36:19 +00:00
[[nodiscard]] bool videoShown() const;
[[nodiscard]] QSize videoSize() const;
[[nodiscard]] bool videoIsGifv() const;
[[nodiscard]] QImage videoFrame() const;
2019-03-10 07:48:40 +00:00
[[nodiscard]] QImage videoFrameForDirectPaint() const;
2019-03-06 14:48:42 +00:00
[[nodiscard]] QImage transformVideoFrame(QImage frame) const;
2019-02-27 11:36:19 +00:00
[[nodiscard]] bool documentContentShown() const;
[[nodiscard]] bool documentBubbleShown() const;
2019-03-06 14:48:42 +00:00
void paintTransformedVideoFrame(Painter &p);
2019-02-27 11:36:19 +00:00
void clearStreaming();
QBrush _transparentBrush;
PhotoData *_photo = nullptr;
DocumentData *_doc = nullptr;
std::unique_ptr<SharedMedia> _sharedMedia;
2018-09-21 16:28:46 +00:00
std::optional<SharedMediaWithLastSlice> _sharedMediaData;
std::optional<SharedMediaWithLastSlice::Key> _sharedMediaDataKey;
std::unique_ptr<UserPhotos> _userPhotos;
2018-09-21 16:28:46 +00:00
std::optional<UserPhotosSlice> _userPhotosData;
std::unique_ptr<Collage> _collage;
std::optional<WebPageCollage> _collageData;
QRect _closeNav, _closeNavIcon;
QRect _leftNav, _leftNavIcon, _rightNav, _rightNavIcon;
QRect _headerNav, _nameNav, _dateNav;
QRect _saveNav, _saveNavIcon, _moreNav, _moreNavIcon;
bool _leftNavVisible = false;
bool _rightNavVisible = false;
bool _saveVisible = false;
bool _headerHasLink = false;
QString _dateText;
2015-04-11 10:04:10 +00:00
QString _headerText;
2014-08-06 14:40:21 +00:00
bool _streamingStartPaused = false;
bool _streamingPauseMusic = false;
bool _fullScreenVideo = false;
int _fullScreenZoomCache = 0;
2016-07-11 18:05:46 +00:00
2019-02-27 11:36:19 +00:00
std::unique_ptr<GroupThumbs> _groupThumbs;
QRect _groupThumbsRect;
int _groupThumbsAvailableWidth = 0;
int _groupThumbsLeft = 0;
int _groupThumbsTop = 0;
Text _caption;
QRect _captionRect;
int _width = 0;
2019-02-27 11:36:19 +00:00
int _height = 0;
int _x = 0, _y = 0, _w = 0, _h = 0;
int _xStart = 0, _yStart = 0;
int _zoom = 0; // < 0 - out, 0 - none, > 0 - in
float64 _zoomToScreen = 0.; // for documents
QPoint _mStart;
bool _pressed = false;
int32 _dragging = 0;
QPixmap _current;
bool _blurred = true;
2019-02-27 11:36:19 +00:00
std::unique_ptr<Streamed> _streamed;
const style::icon *_docIcon = nullptr;
style::color _docIconColor;
2015-04-19 10:29:19 +00:00
QString _docName, _docSize, _docExt;
int _docNameWidth = 0, _docSizeWidth = 0, _docExtWidth = 0;
2015-04-19 10:29:19 +00:00
QRect _docRect, _docIconRect;
int _docThumbx = 0, _docThumby = 0, _docThumbw = 0;
object_ptr<Ui::LinkButton> _docDownload;
object_ptr<Ui::LinkButton> _docSaveAs;
object_ptr<Ui::LinkButton> _docCancel;
2015-04-11 10:04:10 +00:00
QRect _photoRadialRect;
Ui::RadialAnimation _radial;
QImage _radialCache;
History *_migrated = nullptr;
History *_history = nullptr; // if conversation photos or files overview
PeerData *_peer = nullptr;
UserData *_user = nullptr; // if user profile photos overview
// We save the information about the reason of the current mediaview show:
// did we open a peer profile photo or a photo from some message.
// We use it when trying to delete a photo: if we've opened a peer photo,
// then we'll delete group photo instead of the corresponding message.
bool _firstOpenedPeerPhoto = false;
PeerData *_from = nullptr;
QString _fromName;
Text _fromNameLabel;
2018-09-21 16:28:46 +00:00
std::optional<int> _index; // Index in current _sharedMedia data.
std::optional<int> _fullIndex; // Index in full shared media.
std::optional<int> _fullCount;
FullMsgId _msgid;
bool _canForwardItem = false;
bool _canDeleteItem = false;
mtpRequestId _loadRequest = 0;
OverState _over = OverNone;
OverState _down = OverNone;
2015-04-11 10:04:10 +00:00
QPoint _lastAction, _lastMouseMovePos;
bool _ignoringDropdown = false;
2015-04-11 10:04:10 +00:00
2019-04-01 14:53:18 +00:00
Ui::Animations::Basic _stateAnimation;
2015-12-08 12:33:37 +00:00
2015-04-11 10:04:10 +00:00
enum ControlsState {
ControlsShowing,
ControlsShown,
ControlsHiding,
ControlsHidden,
};
ControlsState _controlsState = ControlsShown;
crl::time _controlsAnimStarted = 0;
2015-04-11 10:04:10 +00:00
QTimer _controlsHideTimer;
2019-04-01 14:53:18 +00:00
anim::value _controlsOpacity;
bool _mousePressed = false;
Ui::PopupMenu *_menu = nullptr;
object_ptr<Ui::DropdownMenu> _dropdown;
object_ptr<QTimer> _dropdownShowTimer;
struct ActionData {
QString text;
const char *member;
};
QList<ActionData> _actions;
2015-04-11 10:04:10 +00:00
bool _receiveMouse = true;
2019-04-01 14:53:18 +00:00
bool _touchPress = false;
bool _touchMove = false;
bool _touchRightButton = false;
QTimer _touchTimer;
QPoint _touchStart;
QPoint _accumScroll;
QString _saveMsgFilename;
crl::time _saveMsgStarted = 0;
anim::value _saveMsgOpacity;
QRect _saveMsg;
QTimer _saveMsgUpdater;
Text _saveMsgText;
2019-04-01 14:53:18 +00:00
base::flat_map<OverState, crl::time> _animations;
base::flat_map<OverState, anim::value> _animationOpacities;
2014-08-06 14:40:21 +00:00
int _verticalWheelDelta = 0;
bool _themePreviewShown = false;
uint64 _themePreviewId = 0;
QRect _themePreviewRect;
std::unique_ptr<Window::Theme::Preview> _themePreview;
object_ptr<Ui::RoundButton> _themeApply = { nullptr };
object_ptr<Ui::RoundButton> _themeCancel = { nullptr };
bool _wasRepainted = false;
2014-08-06 14:40:21 +00:00
};
} // namespace View
} // namespace Media