tdesktop/Telegram/SourceFiles/mediaview.h

219 lines
5.5 KiB
C
Raw Normal View History

2014-08-06 14:40:21 +00:00
/*
This file is part of Telegram Desktop,
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.
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
Copyright (c) 2014 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"
class MediaView : public TWidget, public RPCSender, public Animated {
2014-08-06 14:40:21 +00:00
Q_OBJECT
public:
MediaView();
void paintEvent(QPaintEvent *e);
void keyPressEvent(QKeyEvent *e);
void mousePressEvent(QMouseEvent *e);
void mouseMoveEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
void contextMenuEvent(QContextMenuEvent *e);
void touchEvent(QTouchEvent *e);
2014-08-06 14:40:21 +00:00
bool event(QEvent *e);
2014-08-15 11:19:32 +00:00
void hide();
void updateOver(QPoint mpos);
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();
2015-04-11 10:04:10 +00:00
void moveToNext(int32 delta);
void preloadData(int32 delta);
void leaveToChildEvent(QEvent *e) { // e -- from enterEvent() of child TWidget
updateOverState(OverNone);
}
void enterFromChildEvent(QEvent *e) { // e -- from leaveEvent() of child TWidget
updateOver(mapFromGlobal(QCursor::pos()));
}
void mediaOverviewUpdated(PeerData *peer);
2015-04-19 10:29:19 +00:00
void documentUpdated(DocumentData *doc);
void changingMsgId(HistoryItem *row, MsgId newId);
2015-04-19 10:29:19 +00:00
void updateDocSize();
void updateControls();
2015-04-11 10:04:10 +00:00
void updateDropdown();
bool animStep(float64 dt);
void showSaveMsgFile();
2015-04-11 10:04:10 +00:00
void close();
void activateControls();
2015-04-19 10:29:19 +00:00
void onDocClick();
~MediaView();
public slots:
2015-04-11 10:04:10 +00:00
void onHideControls(bool force = false);
void onDropdownHiding();
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();
2015-04-11 10:04:10 +00:00
void onDropdown();
void onCheckActive();
void onTouchTimer();
2014-08-06 14:40:21 +00:00
void updateImage();
2015-04-19 10:29:19 +00:00
void onGifUpdated();
2014-08-06 14:40:21 +00:00
private:
2015-04-11 10:04:10 +00:00
void displayPhoto(PhotoData *photo);
void displayDocument(DocumentData *doc, HistoryItem *item);
void findCurrent();
void loadBack();
void photosLoaded(History *h, const MTPmessages_Messages &msgs, mtpRequestId req);
void userPhotosLoaded(UserData *u, const MTPphotos_Photos &photos, mtpRequestId req);
2015-04-11 10:04:10 +00:00
void filesLoaded(History *h, const MTPmessages_Messages &msgs, mtpRequestId req);
void updateHeader();
void snapXY();
QBrush _transparentBrush;
2014-08-06 14:40:21 +00:00
PhotoData *_photo;
DocumentData *_doc;
2015-04-11 10:04:10 +00:00
MediaOverviewType _overview;
QRect _closeNav, _closeNavIcon;
QRect _leftNav, _leftNavIcon, _rightNav, _rightNavIcon;
QRect _headerNav, _nameNav, _dateNav;
QRect _saveNav, _saveNavIcon, _moreNav, _moreNavIcon;
2015-04-11 10:04:10 +00:00
bool _leftNavVisible, _rightNavVisible, _saveVisible, _headerHasLink;
QString _dateText;
2015-04-11 10:04:10 +00:00
QString _headerText;
2014-08-06 14:40:21 +00:00
uint64 _animStarted;
2015-04-11 10:04:10 +00:00
int32 _width, _x, _y, _w, _h, _xStart, _yStart;
int32 _zoom; // < 0 - out, 0 - none, > 0 - in
float64 _zoomToScreen; // for documents
QPoint _mStart;
bool _pressed;
int32 _dragging;
QPixmap _current;
2015-04-19 10:29:19 +00:00
AnimatedGif _currentGif;
2014-08-17 07:37:24 +00:00
int32 _full; // -1 - thumb, 0 - medium, 1 - full
2015-04-11 10:04:10 +00:00
style::sprite _docIcon;
2015-04-19 10:29:19 +00:00
QString _docName, _docSize, _docExt;
int32 _docNameWidth, _docSizeWidth, _docExtWidth;
QRect _docRect, _docIconRect;
2015-04-11 10:04:10 +00:00
int32 _docThumbx, _docThumby, _docThumbw;
uint64 _docRadialFirst, _docRadialStart, _docRadialLast;
2015-04-19 10:29:19 +00:00
float64 _docRadialOpacity;
2015-04-11 10:04:10 +00:00
QPen _docRadialPen;
anim::fvalue a_docRadial, a_docRadialStart;
2015-04-19 10:29:19 +00:00
LinkButton _docDownload, _docSaveAs, _docCancel;
2015-04-11 10:04:10 +00:00
History *_history; // if conversation photos or files overview
PeerData *_peer;
2015-04-11 10:04:10 +00:00
UserData *_user; // if user profile photos overview
UserData *_from;
Text _fromName;
2015-04-11 10:04:10 +00:00
int32 _index; // index in photos or files array, -1 if just photo
MsgId _msgid; // msgId of current photo or file
mtpRequestId _loadRequest;
enum OverState {
OverNone,
OverLeftNav,
OverRightNav,
2015-04-11 10:04:10 +00:00
OverClose,
OverHeader,
OverName,
2015-04-11 10:04:10 +00:00
OverDate,
OverSave,
OverMore,
2015-04-19 10:29:19 +00:00
OverIcon,
};
OverState _over, _down;
2015-04-11 10:04:10 +00:00
QPoint _lastAction, _lastMouseMovePos;
bool _ignoringDropdown;
enum ControlsState {
ControlsShowing,
ControlsShown,
ControlsHiding,
ControlsHidden,
};
ControlsState _controlsState;
uint64 _controlsAnimStarted;
QTimer _controlsHideTimer;
anim::fvalue a_cOpacity;
ContextMenu *_menu;
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;
bool _receiveMouse;
bool _touchPress, _touchMove, _touchRightButton;
QTimer _touchTimer;
QPoint _touchStart;
QPoint _accumScroll;
QString _saveMsgFilename;
uint64 _saveMsgStarted;
anim::fvalue _saveMsgOpacity;
QRect _saveMsg;
QTimer _saveMsgUpdater;
Text _saveMsgText;
typedef QMap<OverState, uint64> Showing;
Showing _animations;
typedef QMap<OverState, anim::fvalue> ShowingOpacities;
ShowingOpacities _animOpacities;
2014-08-06 14:40:21 +00:00
void updateOverRect(OverState state);
bool updateOverState(OverState newState);
float64 overLevel(OverState control);
QColor overColor(const QColor &a, float64 ca, const QColor &b, float64 cb);
2014-08-06 14:40:21 +00:00
};