2016-04-04 21:09:46 +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-04-04 21:09:46 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "inline_bots/inline_bot_layout_item.h"
|
2016-09-28 10:15:03 +00:00
|
|
|
#include "ui/effects/radial_animation.h"
|
2016-04-14 11:00:23 +00:00
|
|
|
#include "ui/text/text.h"
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
namespace InlineBots {
|
|
|
|
namespace Layout {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
class FileBase : public ItemBase {
|
|
|
|
public:
|
|
|
|
FileBase(Result *result);
|
|
|
|
// for saved gif layouts
|
|
|
|
FileBase(DocumentData *doc);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
DocumentData *getShownDocument() const;
|
|
|
|
|
|
|
|
int content_width() const;
|
|
|
|
int content_height() const;
|
|
|
|
int content_duration() const;
|
2016-04-10 18:18:26 +00:00
|
|
|
ImagePtr content_thumb() const;
|
2016-04-04 21:09:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class DeleteSavedGifClickHandler : public LeftButtonClickHandler {
|
|
|
|
public:
|
|
|
|
DeleteSavedGifClickHandler(DocumentData *data) : _data(data) {
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void onClickImpl() const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DocumentData *_data;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class Gif : public FileBase {
|
|
|
|
public:
|
|
|
|
Gif(Result *result);
|
|
|
|
Gif(DocumentData *doc, bool hasDeleteButton);
|
|
|
|
|
|
|
|
void setPosition(int32 position) override;
|
|
|
|
void initDimensions() override;
|
|
|
|
|
|
|
|
bool isFullLine() const override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool hasRightSkip() const override {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-13 18:29:32 +00:00
|
|
|
void paint(Painter &p, const QRect &clip, const PaintContext *context) const override;
|
2016-04-08 15:37:14 +00:00
|
|
|
void getState(ClickHandlerPtr &link, HistoryCursorState &cursor, int x, int y) const override;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
// ClickHandlerHost interface
|
|
|
|
void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
QSize countFrameSize() const;
|
|
|
|
|
|
|
|
enum class StateFlag {
|
|
|
|
Over = 0x01,
|
|
|
|
DeleteOver = 0x02,
|
|
|
|
};
|
|
|
|
Q_DECLARE_FLAGS(StateFlags, StateFlag);
|
|
|
|
StateFlags _state;
|
|
|
|
friend inline StateFlags operator~(StateFlag flag) {
|
|
|
|
return ~StateFlags(flag);
|
|
|
|
}
|
|
|
|
|
2016-09-28 20:28:53 +00:00
|
|
|
Media::Clip::ReaderPointer _gif;
|
2016-04-04 21:09:46 +00:00
|
|
|
ClickHandlerPtr _delete;
|
|
|
|
mutable QPixmap _thumb;
|
|
|
|
void prepareThumb(int32 width, int32 height, const QSize &frame) const;
|
|
|
|
|
|
|
|
void ensureAnimation() const;
|
2016-12-01 19:20:33 +00:00
|
|
|
bool isRadialAnimation(TimeMs ms) const;
|
|
|
|
void step_radial(TimeMs ms, bool timer);
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2016-06-24 10:37:29 +00:00
|
|
|
void clipCallback(Media::Clip::Notification notification);
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
struct AnimationData {
|
2016-05-12 16:05:20 +00:00
|
|
|
AnimationData(AnimationCallbacks &&callbacks)
|
2016-04-04 21:09:46 +00:00
|
|
|
: over(false)
|
2016-05-12 16:05:20 +00:00
|
|
|
, radial(std_::move(callbacks)) {
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
bool over;
|
2016-12-07 13:32:25 +00:00
|
|
|
Animation _a_over;
|
2016-09-28 10:15:03 +00:00
|
|
|
Ui::RadialAnimation radial;
|
2016-04-04 21:09:46 +00:00
|
|
|
};
|
2016-09-28 16:23:25 +00:00
|
|
|
mutable std_::unique_ptr<AnimationData> _animation;
|
2016-12-07 13:32:25 +00:00
|
|
|
mutable Animation _a_deleteOver;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class Photo : public ItemBase {
|
|
|
|
public:
|
|
|
|
Photo(Result *result);
|
|
|
|
// Not used anywhere currently.
|
|
|
|
//LayoutInlinePhoto(PhotoData *photo);
|
|
|
|
|
|
|
|
void initDimensions() override;
|
|
|
|
|
|
|
|
bool isFullLine() const override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool hasRightSkip() const override {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-13 18:29:32 +00:00
|
|
|
void paint(Painter &p, const QRect &clip, const PaintContext *context) const override;
|
2016-04-08 15:37:14 +00:00
|
|
|
void getState(ClickHandlerPtr &link, HistoryCursorState &cursor, int x, int y) const override;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
PhotoData *getShownPhoto() const;
|
|
|
|
|
|
|
|
QSize countFrameSize() const;
|
|
|
|
|
|
|
|
mutable QPixmap _thumb;
|
|
|
|
mutable bool _thumbLoaded = false;
|
|
|
|
void prepareThumb(int32 width, int32 height, const QSize &frame) const;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class Sticker : public FileBase {
|
|
|
|
public:
|
|
|
|
Sticker(Result *result);
|
|
|
|
// Not used anywhere currently.
|
|
|
|
//LayoutInlineSticker(DocumentData *document);
|
|
|
|
|
|
|
|
void initDimensions() override;
|
|
|
|
|
|
|
|
bool isFullLine() const override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool hasRightSkip() const override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
void preload() const override;
|
|
|
|
|
2016-04-13 18:29:32 +00:00
|
|
|
void paint(Painter &p, const QRect &clip, const PaintContext *context) const override;
|
2016-04-08 15:37:14 +00:00
|
|
|
void getState(ClickHandlerPtr &link, HistoryCursorState &cursor, int x, int y) const override;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
// ClickHandlerHost interface
|
|
|
|
void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
QSize getThumbSize() const;
|
|
|
|
|
2016-12-07 13:32:25 +00:00
|
|
|
mutable Animation _a_over;
|
2016-04-04 21:09:46 +00:00
|
|
|
mutable bool _active = false;
|
|
|
|
|
|
|
|
mutable QPixmap _thumb;
|
|
|
|
mutable bool _thumbLoaded = false;
|
|
|
|
void prepareThumb() const;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class Video : public FileBase {
|
|
|
|
public:
|
|
|
|
Video(Result *result);
|
|
|
|
|
|
|
|
void initDimensions() override;
|
|
|
|
|
2016-04-13 18:29:32 +00:00
|
|
|
void paint(Painter &p, const QRect &clip, const PaintContext *context) const override;
|
2016-04-08 15:37:14 +00:00
|
|
|
void getState(ClickHandlerPtr &link, HistoryCursorState &cursor, int x, int y) const override;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
ClickHandlerPtr _link;
|
|
|
|
|
|
|
|
mutable QPixmap _thumb;
|
|
|
|
Text _title, _description;
|
|
|
|
QString _duration;
|
2016-04-08 15:37:14 +00:00
|
|
|
int _durationWidth = 0;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
void prepareThumb(int32 width, int32 height) const;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class OpenFileClickHandler : public LeftButtonClickHandler {
|
|
|
|
public:
|
|
|
|
OpenFileClickHandler(Result *result) : _result(result) {
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void onClickImpl() const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Result *_result;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class CancelFileClickHandler : public LeftButtonClickHandler {
|
|
|
|
public:
|
|
|
|
CancelFileClickHandler(Result *result) : _result(result) {
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void onClickImpl() const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Result *_result;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class File : public FileBase {
|
|
|
|
public:
|
|
|
|
File(Result *result);
|
|
|
|
|
|
|
|
void initDimensions() override;
|
|
|
|
|
2016-04-13 18:29:32 +00:00
|
|
|
void paint(Painter &p, const QRect &clip, const PaintContext *context) const override;
|
2016-04-08 15:37:14 +00:00
|
|
|
void getState(ClickHandlerPtr &link, HistoryCursorState &cursor, int x, int y) const override;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
// ClickHandlerHost interface
|
|
|
|
void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override;
|
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
~File();
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
private:
|
2016-12-07 13:32:25 +00:00
|
|
|
void thumbAnimationCallback();
|
2016-12-01 19:20:33 +00:00
|
|
|
void step_radial(TimeMs ms, bool timer);
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
void ensureAnimation() const;
|
2016-12-09 06:19:55 +00:00
|
|
|
void checkAnimationFinished() const;
|
2016-04-10 18:18:26 +00:00
|
|
|
bool updateStatusText() const;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
bool isRadialAnimation(TimeMs ms) const {
|
2016-04-04 21:09:46 +00:00
|
|
|
if (!_animation || !_animation->radial.animating()) return false;
|
|
|
|
|
|
|
|
_animation->radial.step(ms);
|
|
|
|
return _animation && _animation->radial.animating();
|
|
|
|
}
|
2016-12-01 19:20:33 +00:00
|
|
|
bool isThumbAnimation(TimeMs ms) const {
|
2016-12-07 13:32:25 +00:00
|
|
|
if (_animation) {
|
2016-12-09 06:19:55 +00:00
|
|
|
if (_animation->a_thumbOver.animating(ms)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
checkAnimationFinished();
|
2016-12-07 13:32:25 +00:00
|
|
|
}
|
|
|
|
return false;
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct AnimationData {
|
2016-12-07 13:32:25 +00:00
|
|
|
AnimationData(AnimationCallbacks &&radialCallbacks) : radial(std_::move(radialCallbacks)) {
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
2016-12-07 13:32:25 +00:00
|
|
|
Animation a_thumbOver;
|
2016-09-28 10:15:03 +00:00
|
|
|
Ui::RadialAnimation radial;
|
2016-04-04 21:09:46 +00:00
|
|
|
};
|
2016-04-10 19:20:48 +00:00
|
|
|
mutable std_::unique_ptr<AnimationData> _animation;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
Text _title, _description;
|
|
|
|
ClickHandlerPtr _open, _cancel;
|
|
|
|
|
|
|
|
// >= 0 will contain download / upload string, _statusSize = loaded bytes
|
|
|
|
// < 0 will contain played string, _statusSize = -(seconds + 1) played
|
|
|
|
// 0x7FFFFFF0 will contain status for not yet downloaded file
|
|
|
|
// 0x7FFFFFF1 will contain status for already downloaded file
|
|
|
|
// 0x7FFFFFF2 will contain status for failed to download / upload file
|
|
|
|
mutable int32 _statusSize;
|
|
|
|
mutable QString _statusText;
|
|
|
|
|
|
|
|
// duration = -1 - no duration, duration = -2 - "GIF" duration
|
|
|
|
void setStatusSize(int32 newSize, int32 fullSize, int32 duration, qint64 realDuration) const;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-04-08 15:37:14 +00:00
|
|
|
class Contact : public ItemBase {
|
|
|
|
public:
|
|
|
|
Contact(Result *result);
|
|
|
|
|
|
|
|
void initDimensions() override;
|
|
|
|
int resizeGetHeight(int width) override;
|
|
|
|
|
2016-04-13 18:29:32 +00:00
|
|
|
void paint(Painter &p, const QRect &clip, const PaintContext *context) const override;
|
2016-04-08 15:37:14 +00:00
|
|
|
void getState(ClickHandlerPtr &link, HistoryCursorState &cursor, int x, int y) const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
mutable QPixmap _thumb;
|
|
|
|
Text _title, _description;
|
|
|
|
|
|
|
|
void prepareThumb(int width, int height) const;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
class Article : public ItemBase {
|
|
|
|
public:
|
|
|
|
Article(Result *result, bool withThumb);
|
|
|
|
|
|
|
|
void initDimensions() override;
|
2016-04-08 15:37:14 +00:00
|
|
|
int resizeGetHeight(int width) override;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2016-04-13 18:29:32 +00:00
|
|
|
void paint(Painter &p, const QRect &clip, const PaintContext *context) const override;
|
2016-04-08 15:37:14 +00:00
|
|
|
void getState(ClickHandlerPtr &link, HistoryCursorState &cursor, int x, int y) const override;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
ClickHandlerPtr _url, _link;
|
|
|
|
|
|
|
|
bool _withThumb;
|
|
|
|
mutable QPixmap _thumb;
|
|
|
|
Text _title, _description;
|
2016-04-05 20:24:27 +00:00
|
|
|
QString _thumbLetter, _urlText;
|
2016-04-04 21:09:46 +00:00
|
|
|
int32 _urlWidth;
|
|
|
|
|
2016-04-08 15:37:14 +00:00
|
|
|
void prepareThumb(int width, int height) const;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-09-28 16:23:25 +00:00
|
|
|
class Game : public ItemBase {
|
|
|
|
public:
|
|
|
|
Game(Result *result);
|
|
|
|
|
|
|
|
void setPosition(int32 position) override;
|
|
|
|
void initDimensions() override;
|
|
|
|
|
|
|
|
void paint(Painter &p, const QRect &clip, const PaintContext *context) const override;
|
|
|
|
void getState(ClickHandlerPtr &link, HistoryCursorState &cursor, int x, int y) const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void countFrameSize();
|
|
|
|
|
|
|
|
void prepareThumb(int32 width, int32 height) const;
|
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
bool isRadialAnimation(TimeMs ms) const;
|
|
|
|
void step_radial(TimeMs ms, bool timer);
|
2016-09-28 16:23:25 +00:00
|
|
|
|
|
|
|
void clipCallback(Media::Clip::Notification notification);
|
|
|
|
|
2016-09-28 20:28:53 +00:00
|
|
|
Media::Clip::ReaderPointer _gif;
|
2016-09-28 16:23:25 +00:00
|
|
|
mutable QPixmap _thumb;
|
|
|
|
mutable std_::unique_ptr<Ui::RadialAnimation> _radial;
|
|
|
|
Text _title, _description;
|
|
|
|
|
|
|
|
QSize _frameSize;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace Layout
|
|
|
|
} // namespace InlineBots
|