2016-09-27 14:20:49 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
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
|
2016-09-27 14:20:49 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2016-09-28 10:15:03 +00:00
|
|
|
enum class MediaInBubbleState {
|
|
|
|
None,
|
|
|
|
Top,
|
|
|
|
Middle,
|
|
|
|
Bottom,
|
2016-09-27 14:20:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class HistoryMedia : public HistoryElement {
|
|
|
|
public:
|
|
|
|
HistoryMedia(HistoryItem *parent) : _parent(parent) {
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual HistoryMediaType type() const = 0;
|
|
|
|
|
|
|
|
virtual QString notificationText() const {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns text with link-start and link-end commands for service-color highlighting.
|
|
|
|
// Example: "[link1-start]You:[link1-end] [link1-start]Photo,[link1-end] caption text"
|
2016-09-28 10:15:03 +00:00
|
|
|
virtual QString inDialogsText() const {
|
|
|
|
auto result = notificationText();
|
|
|
|
return result.isEmpty() ? QString() : textcmdLink(1, textClean(result));
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
virtual TextWithEntities selectedText(TextSelection selection) const = 0;
|
|
|
|
|
|
|
|
bool hasPoint(int x, int y) const {
|
|
|
|
return (x >= 0 && y >= 0 && x < _width && y < _height);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool isDisplayed() const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
virtual bool isAboveMessage() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
virtual bool hasTextForCopy() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
virtual void initDimensions() = 0;
|
|
|
|
virtual int resizeGetHeight(int width) {
|
|
|
|
_width = qMin(width, _maxw);
|
|
|
|
return _height;
|
|
|
|
}
|
2016-12-01 19:20:33 +00:00
|
|
|
virtual void draw(Painter &p, const QRect &r, TextSelection selection, TimeMs ms) const = 0;
|
2016-09-27 14:20:49 +00:00
|
|
|
virtual HistoryTextState getState(int x, int y, HistoryStateRequest request) const = 0;
|
|
|
|
|
|
|
|
// if we are in selecting items mode perhaps we want to
|
|
|
|
// toggle selection instead of activating the pressed link
|
|
|
|
virtual bool toggleSelectionByHandlerClick(const ClickHandlerPtr &p) const = 0;
|
|
|
|
|
|
|
|
// if we press and drag on this media should we drag the item
|
|
|
|
virtual bool dragItem() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual TextSelection adjustSelection(TextSelection selection, TextSelectType type) const {
|
|
|
|
return selection;
|
|
|
|
}
|
2016-09-28 11:38:35 +00:00
|
|
|
virtual bool consumeMessageText(const TextWithEntities &textWithEntities) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
|
|
|
|
// if we press and drag this link should we drag the item
|
|
|
|
virtual bool dragItemByHandler(const ClickHandlerPtr &p) const = 0;
|
|
|
|
|
|
|
|
virtual void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) {
|
|
|
|
}
|
|
|
|
virtual void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) {
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool uploading() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
virtual HistoryMedia *clone(HistoryItem *newParent) const = 0;
|
|
|
|
|
|
|
|
virtual DocumentData *getDocument() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
virtual Media::Clip::Reader *getClipReader() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool playInline(/*bool autoplay = false*/) {
|
|
|
|
return playInline(false);
|
|
|
|
}
|
|
|
|
virtual bool playInline(bool autoplay) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
virtual void stopInline() {
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void attachToParent() {
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void detachFromParent() {
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void updateSentMedia(const MTPMessageMedia &media) {
|
|
|
|
}
|
|
|
|
|
|
|
|
// After sending an inline result we may want to completely recreate
|
|
|
|
// the media (all media that was generated on client side, for example)
|
|
|
|
virtual bool needReSetInlineResultMedia(const MTPMessageMedia &media) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool animating() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool hasReplyPreview() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
virtual ImagePtr replyPreview() {
|
|
|
|
return ImagePtr();
|
|
|
|
}
|
|
|
|
virtual TextWithEntities getCaption() const {
|
|
|
|
return TextWithEntities();
|
|
|
|
}
|
|
|
|
virtual bool needsBubble() const = 0;
|
|
|
|
virtual bool customInfoLayout() const = 0;
|
|
|
|
virtual QMargins bubbleMargins() const {
|
|
|
|
return QMargins();
|
|
|
|
}
|
|
|
|
virtual bool hideFromName() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
virtual bool hideForwardedFrom() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int currentWidth() const {
|
|
|
|
return _width;
|
|
|
|
}
|
|
|
|
|
2016-09-28 10:15:03 +00:00
|
|
|
void setInBubbleState(MediaInBubbleState state) {
|
|
|
|
_inBubbleState = state;
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2016-09-28 10:15:03 +00:00
|
|
|
MediaInBubbleState inBubbleState() const {
|
|
|
|
return _inBubbleState;
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2016-09-28 10:15:03 +00:00
|
|
|
bool isBubbleTop() const {
|
|
|
|
return (_inBubbleState == MediaInBubbleState::Top) || (_inBubbleState == MediaInBubbleState::None);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2016-09-28 10:15:03 +00:00
|
|
|
bool isBubbleBottom() const {
|
|
|
|
return (_inBubbleState == MediaInBubbleState::Bottom) || (_inBubbleState == MediaInBubbleState::None);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2016-11-18 16:27:47 +00:00
|
|
|
virtual bool skipBubbleTail() const {
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2016-09-29 19:42:14 +00:00
|
|
|
// Sometimes click on media in message is overloaded by the messsage:
|
|
|
|
// (for example it can open a link or a game instead of opening media)
|
|
|
|
// But the overloading click handler should be used only when media
|
|
|
|
// is already loaded (not a photo or gif waiting for load with auto
|
|
|
|
// load being disabled - in such case media should handle the click).
|
|
|
|
virtual bool isReadyForOpen() const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
protected:
|
2016-09-28 10:15:03 +00:00
|
|
|
HistoryItem *_parent;
|
|
|
|
int _width = 0;
|
|
|
|
MediaInBubbleState _inBubbleState = MediaInBubbleState::None;
|
2016-09-27 14:20:49 +00:00
|
|
|
|
|
|
|
};
|