2014-08-06 14:40:21 +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-08-06 14:40:21 +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-08-06 14:40:21 +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-08-06 14:40:21 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
#include "dropdown.h"
|
2016-09-28 10:15:03 +00:00
|
|
|
#include "ui/effects/radial_animation.h"
|
2015-04-11 10:04:10 +00:00
|
|
|
|
2016-07-11 18:05:46 +00:00
|
|
|
namespace Media {
|
|
|
|
namespace Clip {
|
|
|
|
class Controller;
|
|
|
|
} // namespace Clip
|
|
|
|
} // namespace Media
|
|
|
|
|
2016-10-01 12:34:23 +00:00
|
|
|
class PopupMenu;
|
|
|
|
|
2016-07-12 12:28:07 +00:00
|
|
|
struct AudioPlaybackState;
|
|
|
|
|
2016-10-02 13:54:27 +00:00
|
|
|
class MediaView : public TWidget, private base::Subscriber, public RPCSender, public ClickHandlerHost {
|
2014-08-06 14:40:21 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
MediaView();
|
|
|
|
|
2016-07-24 08:53:09 +00:00
|
|
|
void setVisible(bool visible) override;
|
2014-08-15 11:19:32 +00:00
|
|
|
|
2015-04-19 19:01:45 +00:00
|
|
|
void updateOver(QPoint mpos);
|
2014-08-11 09:03:45 +00:00
|
|
|
|
|
|
|
void showPhoto(PhotoData *photo, HistoryItem *context);
|
|
|
|
void showPhoto(PhotoData *photo, PeerData *context);
|
2015-04-11 10:04:10 +00:00
|
|
|
void showDocument(DocumentData *doc, HistoryItem *context);
|
2014-08-06 14:40:21 +00:00
|
|
|
void moveToScreen();
|
2016-05-20 16:01:06 +00:00
|
|
|
bool moveToNext(int32 delta);
|
2015-04-11 10:04:10 +00:00
|
|
|
void preloadData(int32 delta);
|
|
|
|
|
2016-06-17 18:18:01 +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);
|
|
|
|
}
|
2016-06-17 18:18:01 +00:00
|
|
|
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()));
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
|
2015-07-03 08:47:16 +00:00
|
|
|
void mediaOverviewUpdated(PeerData *peer, MediaOverviewType type);
|
2015-04-19 10:29:19 +00:00
|
|
|
void documentUpdated(DocumentData *doc);
|
2014-08-11 09:03:45 +00:00
|
|
|
void changingMsgId(HistoryItem *row, MsgId newId);
|
2015-04-19 10:29:19 +00:00
|
|
|
void updateDocSize();
|
2014-08-11 09:03:45 +00:00
|
|
|
void updateControls();
|
2015-04-11 10:04:10 +00:00
|
|
|
void updateDropdown();
|
2014-08-11 09:03:45 +00:00
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
void showSaveMsgFile();
|
2015-04-11 10:04:10 +00:00
|
|
|
void close();
|
|
|
|
|
|
|
|
void activateControls();
|
2015-04-19 10:29:19 +00:00
|
|
|
void onDocClick();
|
2014-10-17 12:57:14 +00:00
|
|
|
|
2016-06-24 10:37:29 +00:00
|
|
|
void clipCallback(Media::Clip::Notification notification);
|
2016-03-29 17:17:00 +00:00
|
|
|
PeerData *ui_getPeerForMouseAction();
|
2015-12-22 08:01:02 +00:00
|
|
|
|
2016-06-26 15:37:47 +00:00
|
|
|
void clearData();
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
~MediaView();
|
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
// ClickHandlerHost interface
|
|
|
|
void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override;
|
|
|
|
void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override;
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
public slots:
|
2015-04-11 10:04:10 +00:00
|
|
|
void onHideControls(bool force = false);
|
|
|
|
void onDropdownHiding();
|
|
|
|
|
2016-06-22 13:39:54 +00:00
|
|
|
void onScreenResized(int screen);
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
void onToMessage();
|
2015-04-19 10:29:19 +00:00
|
|
|
void onSaveAs();
|
2014-10-17 12:57:14 +00:00
|
|
|
void onDownload();
|
2015-04-19 10:29:19 +00:00
|
|
|
void onSaveCancel();
|
2014-10-07 17:57:57 +00:00
|
|
|
void onShowInFolder();
|
2014-08-11 09:03:45 +00:00
|
|
|
void onForward();
|
|
|
|
void onDelete();
|
2014-10-17 12:57:14 +00:00
|
|
|
void onOverview();
|
2014-08-11 09:03:45 +00:00
|
|
|
void onCopy();
|
|
|
|
void onMenuDestroy(QObject *obj);
|
|
|
|
void receiveMouse();
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
void onDropdown();
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
void onCheckActive();
|
|
|
|
void onTouchTimer();
|
2014-08-06 14:40:21 +00:00
|
|
|
|
2014-09-30 14:11:09 +00:00
|
|
|
void updateImage();
|
|
|
|
|
2016-07-11 18:05:46 +00:00
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
void keyPressEvent(QKeyEvent *e) override;
|
2016-08-18 15:35:39 +00:00
|
|
|
void wheelEvent(QWheelEvent *e) override;
|
2016-07-11 18:05:46 +00:00
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
2016-07-14 11:20:46 +00:00
|
|
|
void mouseDoubleClickEvent(QMouseEvent *e) override;
|
2016-07-11 18:05:46 +00:00
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
|
|
|
void contextMenuEvent(QContextMenuEvent *e) override;
|
|
|
|
void touchEvent(QTouchEvent *e);
|
|
|
|
|
|
|
|
bool event(QEvent *e) override;
|
|
|
|
bool eventFilter(QObject *obj, QEvent *e) override;
|
|
|
|
|
|
|
|
private slots:
|
2016-07-13 11:24:31 +00:00
|
|
|
void onVideoPauseResume();
|
2016-07-13 17:34:57 +00:00
|
|
|
void onVideoSeekProgress(int64 positionMs);
|
|
|
|
void onVideoSeekFinished(int64 positionMs);
|
2016-07-11 18:05:46 +00:00
|
|
|
void onVideoVolumeChanged(float64 volume);
|
2016-07-14 11:20:46 +00:00
|
|
|
void onVideoToggleFullScreen();
|
2016-07-12 11:38:16 +00:00
|
|
|
void onVideoPlayProgress(const AudioMsgId &audioId);
|
2016-07-11 18:05:46 +00:00
|
|
|
|
2014-08-06 14:40:21 +00:00
|
|
|
private:
|
2015-05-20 19:28:24 +00:00
|
|
|
void displayPhoto(PhotoData *photo, HistoryItem *item);
|
2015-04-11 10:04:10 +00:00
|
|
|
void displayDocument(DocumentData *doc, HistoryItem *item);
|
|
|
|
void findCurrent();
|
|
|
|
void loadBack();
|
2014-08-11 09:03:45 +00:00
|
|
|
|
2016-07-24 08:53:09 +00:00
|
|
|
void updateCursor();
|
2016-07-14 11:20:46 +00:00
|
|
|
void setZoomLevel(int newZoom);
|
|
|
|
|
2016-09-23 16:04:26 +00:00
|
|
|
void updateVideoPlaybackState(const AudioPlaybackState &state);
|
2016-07-12 12:28:07 +00:00
|
|
|
void updateSilentVideoPlaybackState();
|
2016-07-13 17:34:57 +00:00
|
|
|
void restartVideoAtSeekPosition(int64 positionMs);
|
2016-07-12 12:28:07 +00:00
|
|
|
|
2016-07-11 18:05:46 +00:00
|
|
|
void createClipController();
|
|
|
|
void setClipControllerGeometry();
|
|
|
|
|
|
|
|
void initAnimation();
|
|
|
|
void createClipReader();
|
|
|
|
|
2016-06-21 18:09:48 +00:00
|
|
|
// Radial animation interface.
|
|
|
|
float64 radialProgress() const;
|
|
|
|
bool radialLoading() const;
|
|
|
|
QRect radialRect() const;
|
|
|
|
void radialStart();
|
|
|
|
uint64 radialTimeShift() const;
|
|
|
|
|
2016-05-20 16:01:06 +00:00
|
|
|
// Computes the last OverviewChatPhotos PhotoData* from _history or _migrated.
|
|
|
|
struct LastChatPhoto {
|
|
|
|
HistoryItem *item;
|
|
|
|
PhotoData *photo;
|
|
|
|
};
|
|
|
|
LastChatPhoto computeLastOverviewChatPhoto();
|
|
|
|
void computeAdditionalChatPhoto(PeerData *peer, PhotoData *lastOverviewPhoto);
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
void userPhotosLoaded(UserData *u, const MTPphotos_Photos &photos, mtpRequestId req);
|
2016-02-26 09:29:07 +00:00
|
|
|
|
|
|
|
void deletePhotosDone(const MTPVector<MTPlong> &result);
|
|
|
|
bool deletePhotosFail(const RPCError &error);
|
2014-08-11 09:03:45 +00:00
|
|
|
|
|
|
|
void updateHeader();
|
2014-10-07 17:57:57 +00:00
|
|
|
void snapXY();
|
2014-08-11 09:03:45 +00:00
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
void step_state(uint64 ms, bool timer);
|
|
|
|
void step_radial(uint64 ms, bool timer);
|
|
|
|
|
2016-08-18 15:35:39 +00:00
|
|
|
void zoomIn();
|
|
|
|
void zoomOut();
|
|
|
|
void zoomReset();
|
|
|
|
void zoomUpdate(int32 &newZoom);
|
|
|
|
|
2016-07-19 10:54:43 +00:00
|
|
|
void paintDocRadialLoading(Painter &p, bool radial, float64 radialOpacity);
|
|
|
|
|
2014-12-15 15:55:45 +00:00
|
|
|
QBrush _transparentBrush;
|
|
|
|
|
2016-05-20 16:01:06 +00:00
|
|
|
PhotoData *_photo = nullptr;
|
|
|
|
DocumentData *_doc = nullptr;
|
|
|
|
MediaOverviewType _overview = OverviewCount;
|
2015-04-19 19:01:45 +00:00
|
|
|
QRect _closeNav, _closeNavIcon;
|
|
|
|
QRect _leftNav, _leftNavIcon, _rightNav, _rightNavIcon;
|
|
|
|
QRect _headerNav, _nameNav, _dateNav;
|
|
|
|
QRect _saveNav, _saveNavIcon, _moreNav, _moreNavIcon;
|
2016-05-20 16:01:06 +00:00
|
|
|
bool _leftNavVisible = false;
|
|
|
|
bool _rightNavVisible = false;
|
|
|
|
bool _saveVisible = false;
|
|
|
|
bool _headerHasLink = false;
|
2014-08-11 09:03:45 +00:00
|
|
|
QString _dateText;
|
2015-04-11 10:04:10 +00:00
|
|
|
QString _headerText;
|
2014-08-06 14:40:21 +00:00
|
|
|
|
2016-07-11 18:05:46 +00:00
|
|
|
ChildWidget<Media::Clip::Controller> _clipController = { nullptr };
|
2016-07-13 11:24:31 +00:00
|
|
|
DocumentData *_autoplayVideoDocument = nullptr;
|
2016-07-14 11:20:46 +00:00
|
|
|
bool _fullScreenVideo = false;
|
|
|
|
int _fullScreenZoomCache = 0;
|
2016-07-11 18:05:46 +00:00
|
|
|
|
2015-05-20 19:28:24 +00:00
|
|
|
Text _caption;
|
|
|
|
QRect _captionRect;
|
|
|
|
|
2014-09-30 14:11:09 +00:00
|
|
|
uint64 _animStarted;
|
|
|
|
|
2016-05-20 16:01:06 +00:00
|
|
|
int _width = 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
|
2014-10-07 17:57:57 +00:00
|
|
|
QPoint _mStart;
|
2016-05-20 16:01:06 +00:00
|
|
|
bool _pressed = false;
|
|
|
|
int32 _dragging = 0;
|
2014-08-11 09:03:45 +00:00
|
|
|
QPixmap _current;
|
2016-07-11 18:05:46 +00:00
|
|
|
std_::unique_ptr<Media::Clip::Reader> _gif;
|
2016-05-20 16:01:06 +00:00
|
|
|
int32 _full = -1; // -1 - thumb, 0 - medium, 1 - full
|
2014-08-11 09:03:45 +00:00
|
|
|
|
2016-07-12 12:28:07 +00:00
|
|
|
// Video without audio stream playback information.
|
|
|
|
bool _videoIsSilent = false;
|
|
|
|
bool _videoPaused = false;
|
2016-07-14 11:20:46 +00:00
|
|
|
bool _videoStopped = false;
|
2016-07-12 12:28:07 +00:00
|
|
|
int64 _videoPositionMs = 0;
|
|
|
|
int64 _videoDurationMs = 0;
|
|
|
|
int32 _videoFrequencyMs = 1000; // 1000 ms per second.
|
|
|
|
|
2015-12-22 08:01:02 +00:00
|
|
|
bool fileShown() const;
|
|
|
|
bool gifShown() const;
|
2015-12-23 19:23:14 +00:00
|
|
|
void stopGif();
|
2015-12-22 08:01:02 +00:00
|
|
|
|
2016-09-30 16:40:00 +00:00
|
|
|
const style::icon *_docIcon = nullptr;
|
2015-06-02 11:22:00 +00:00
|
|
|
style::color _docIconColor;
|
2015-04-19 10:29:19 +00:00
|
|
|
QString _docName, _docSize, _docExt;
|
2016-05-20 16:01:06 +00:00
|
|
|
int _docNameWidth = 0, _docSizeWidth = 0, _docExtWidth = 0;
|
2015-04-19 10:29:19 +00:00
|
|
|
QRect _docRect, _docIconRect;
|
2016-05-20 16:01:06 +00:00
|
|
|
int _docThumbx = 0, _docThumby = 0, _docThumbw = 0;
|
2015-04-19 10:29:19 +00:00
|
|
|
LinkButton _docDownload, _docSaveAs, _docCancel;
|
2015-04-11 10:04:10 +00:00
|
|
|
|
2016-06-21 18:09:48 +00:00
|
|
|
QRect _photoRadialRect;
|
2016-09-28 10:15:03 +00:00
|
|
|
Ui::RadialAnimation _radial;
|
2016-06-21 18:09:48 +00:00
|
|
|
|
2016-05-20 16:01:06 +00:00
|
|
|
History *_migrated = nullptr;
|
|
|
|
History *_history = nullptr; // if conversation photos or files overview
|
|
|
|
PeerData *_peer = nullptr;
|
|
|
|
UserData *_user = nullptr; // if user profile photos overview
|
|
|
|
|
|
|
|
// There can be additional first photo in chat photos overview, that is not
|
|
|
|
// in the _history->overview[OverviewChatPhotos] (if the item was deleted).
|
|
|
|
PhotoData *_additionalChatPhoto = nullptr;
|
2016-03-29 17:17:00 +00:00
|
|
|
|
2016-06-22 13:39:54 +00:00
|
|
|
// 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;
|
|
|
|
|
2016-05-20 16:01:06 +00:00
|
|
|
PeerData *_from = nullptr;
|
2014-10-17 12:57:14 +00:00
|
|
|
Text _fromName;
|
2014-08-11 09:03:45 +00:00
|
|
|
|
2016-05-20 16:01:06 +00:00
|
|
|
int _index = -1; // index in photos or files array, -1 if just photo
|
|
|
|
MsgId _msgid = 0; // msgId of current photo or file
|
|
|
|
bool _msgmigrated = false; // msgId is from _migrated history
|
|
|
|
ChannelId _channel = NoChannel;
|
|
|
|
bool _canForward = false;
|
|
|
|
bool _canDelete = false;
|
2014-08-11 09:03:45 +00:00
|
|
|
|
2016-05-20 16:01:06 +00:00
|
|
|
mtpRequestId _loadRequest = 0;
|
2014-08-11 09:03:45 +00:00
|
|
|
|
|
|
|
enum OverState {
|
|
|
|
OverNone,
|
|
|
|
OverLeftNav,
|
|
|
|
OverRightNav,
|
2015-04-11 10:04:10 +00:00
|
|
|
OverClose,
|
|
|
|
OverHeader,
|
2014-08-11 09:03:45 +00:00
|
|
|
OverName,
|
2015-04-11 10:04:10 +00:00
|
|
|
OverDate,
|
|
|
|
OverSave,
|
|
|
|
OverMore,
|
2015-04-19 10:29:19 +00:00
|
|
|
OverIcon,
|
2016-07-14 11:20:46 +00:00
|
|
|
OverVideo,
|
2014-08-11 09:03:45 +00:00
|
|
|
};
|
2016-05-20 16:01:06 +00:00
|
|
|
OverState _over = OverNone;
|
|
|
|
OverState _down = OverNone;
|
2015-04-11 10:04:10 +00:00
|
|
|
QPoint _lastAction, _lastMouseMovePos;
|
2016-05-20 16:01:06 +00:00
|
|
|
bool _ignoringDropdown = false;
|
2015-04-11 10:04:10 +00:00
|
|
|
|
2015-12-08 12:33:37 +00:00
|
|
|
Animation _a_state;
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
enum ControlsState {
|
|
|
|
ControlsShowing,
|
|
|
|
ControlsShown,
|
|
|
|
ControlsHiding,
|
|
|
|
ControlsHidden,
|
|
|
|
};
|
2016-05-20 16:01:06 +00:00
|
|
|
ControlsState _controlsState = ControlsShown;
|
|
|
|
uint64 _controlsAnimStarted = 0;
|
2015-04-11 10:04:10 +00:00
|
|
|
QTimer _controlsHideTimer;
|
|
|
|
anim::fvalue a_cOpacity;
|
2016-07-12 14:11:59 +00:00
|
|
|
bool _mousePressed = false;
|
2014-08-11 09:03:45 +00:00
|
|
|
|
2016-05-20 16:01:06 +00:00
|
|
|
PopupMenu *_menu = nullptr;
|
2015-04-11 10:04:10 +00:00
|
|
|
Dropdown _dropdown;
|
2015-04-19 10:29:19 +00:00
|
|
|
IconedButton *_btnSaveCancel, *_btnToMessage, *_btnShowInFolder, *_btnSaveAs, *_btnCopy, *_btnForward, *_btnDelete, *_btnViewAll;
|
2015-04-11 10:04:10 +00:00
|
|
|
QList<IconedButton*> _btns;
|
|
|
|
|
2016-05-20 16:01:06 +00:00
|
|
|
bool _receiveMouse = true;
|
2014-08-11 09:03:45 +00:00
|
|
|
|
2016-05-20 16:01:06 +00:00
|
|
|
bool _touchPress = false, _touchMove = false, _touchRightButton = false;
|
2014-08-11 09:03:45 +00:00
|
|
|
QTimer _touchTimer;
|
|
|
|
QPoint _touchStart;
|
2014-12-17 17:55:32 +00:00
|
|
|
QPoint _accumScroll;
|
2014-08-11 09:03:45 +00:00
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
QString _saveMsgFilename;
|
2016-05-20 16:01:06 +00:00
|
|
|
uint64 _saveMsgStarted = 0;
|
2016-06-23 12:02:40 +00:00
|
|
|
anim::fvalue _saveMsgOpacity = { 0 };
|
2014-10-17 12:57:14 +00:00
|
|
|
QRect _saveMsg;
|
|
|
|
QTimer _saveMsgUpdater;
|
|
|
|
Text _saveMsgText;
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
typedef QMap<OverState, uint64> Showing;
|
|
|
|
Showing _animations;
|
|
|
|
typedef QMap<OverState, anim::fvalue> ShowingOpacities;
|
|
|
|
ShowingOpacities _animOpacities;
|
2014-08-06 14:40:21 +00:00
|
|
|
|
2016-09-14 16:05:40 +00:00
|
|
|
int _verticalWheelDelta = 0;
|
|
|
|
|
2015-04-19 19:01:45 +00:00
|
|
|
void updateOverRect(OverState state);
|
2014-08-11 09:03:45 +00:00
|
|
|
bool updateOverState(OverState newState);
|
2016-07-19 10:54:43 +00:00
|
|
|
float64 overLevel(OverState control) const;
|
2014-10-17 12:57:14 +00:00
|
|
|
|
2014-08-06 14:40:21 +00:00
|
|
|
};
|