1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "layout/layout_item_base.h"
#include "ui/text/text.h"
class Image;
namespace Ui {
class PathShiftGradient;
} // namespace Ui
namespace InlineBots {
class Result;
namespace Layout {
class ItemBase;
class PaintContext : public PaintContextBase {
public:
PaintContext(crl::time ms, bool selecting, bool paused, bool lastRow)
: PaintContextBase(ms, selecting)
, paused(paused)
, lastRow(lastRow) {
}
bool paused, lastRow;
Ui::PathShiftGradient *pathGradient = nullptr;
};
// this type used as a flag, we dynamic_cast<> to it
class SendClickHandler : public ClickHandler {
public:
void onClick(ClickContext context) const override {
}
};
class OpenFileClickHandler : public ClickHandler {
public:
void onClick(ClickContext context) const override {
}
};
class Context {
public:
virtual void inlineItemLayoutChanged(const ItemBase *layout) = 0;
virtual bool inlineItemVisible(const ItemBase *item) = 0;
virtual void inlineItemRepaint(const ItemBase *item) = 0;
virtual Data::FileOrigin inlineItemFileOrigin() = 0;
};
class ItemBase : public LayoutItemBase {
public:
ItemBase(not_null<Context*> context, not_null<Result*> result)
: _result(result)
, _context(context) {
}
ItemBase(not_null<Context*> context, not_null<DocumentData*> document)
: _document(document)
, _context(context) {
}
// Not used anywhere currently.
//ItemBase(not_null<Context*> context, PhotoData *photo) : _photo(photo), _context(context) {
//}
virtual void paint(Painter &p, const QRect &clip, const PaintContext *context) const = 0;
virtual bool isFullLine() const {
return true;
}
virtual bool hasRightSkip() const {
return false;
}
Result *getResult() const;
DocumentData *getDocument() const;
PhotoData *getPhoto() const;
// Get document or photo (possibly from InlineBots::Result) for
// showing sticker / GIF / photo preview by long mouse press.
DocumentData *getPreviewDocument() const;
PhotoData *getPreviewPhoto() const;
virtual void preload() const;
virtual void unloadHeavyPart() {
_thumbnail = nullptr;
}
void update() const;
void layoutChanged();
// ClickHandlerHost interface
void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override {
update();
}
void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override {
update();
}
virtual QRect innerContentRect() const {
// Only stickers are supported for now.
Unexpected("Unsupported type to get a rect of inner content.");
}
static std::unique_ptr<ItemBase> createLayout(
not_null<Context*> context,
not_null<Result*> result,
bool forceThumb);
static std::unique_ptr<ItemBase> createLayoutGif(
not_null<Context*> context,
not_null<DocumentData*> document);
protected:
DocumentData *getResultDocument() const;
PhotoData *getResultPhoto() const;
bool hasResultThumb() const;
QImage *getResultThumb(Data::FileOrigin origin) const;
QPixmap getResultContactAvatar(int width, int height) const;
int getResultDuration() const;
QString getResultUrl() const;
ClickHandlerPtr getResultUrlHandler() const;
ClickHandlerPtr getResultPreviewHandler() const;
QString getResultThumbLetter() const;
not_null<Context*> context() const {
return _context;
}
Data::FileOrigin fileOrigin() const;
Result *_result = nullptr;
DocumentData *_document = nullptr;
PhotoData *_photo = nullptr;
ClickHandlerPtr _send = ClickHandlerPtr{ new SendClickHandler() };
ClickHandlerPtr _open = ClickHandlerPtr{ new OpenFileClickHandler() };
private:
not_null<Context*> _context;
mutable std::shared_ptr<QImage> _thumbnail;
};
using DocumentItems = std::map<
not_null<const DocumentData*>,
base::flat_set<not_null<ItemBase*>>>;
const DocumentItems *documentItems();
namespace internal {
void regDocumentItem(
not_null<const DocumentData*> document,
not_null<ItemBase*> item);
void unregDocumentItem(
not_null<const DocumentData*> document,
not_null<ItemBase*> item);
} // namespace internal
} // namespace Layout
} // namespace InlineBots
|