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 "layout.h"
|
|
|
|
#include "structs.h"
|
2016-04-14 11:00:23 +00:00
|
|
|
#include "ui/text/text.h"
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
namespace InlineBots {
|
|
|
|
class Result;
|
|
|
|
|
|
|
|
namespace Layout {
|
|
|
|
|
|
|
|
class PaintContext : public PaintContextBase {
|
|
|
|
public:
|
2016-12-01 19:20:33 +00:00
|
|
|
PaintContext(TimeMs ms, bool selecting, bool paused, bool lastRow)
|
2016-04-04 21:09:46 +00:00
|
|
|
: PaintContextBase(ms, selecting)
|
|
|
|
, paused(paused)
|
|
|
|
, lastRow(lastRow) {
|
|
|
|
}
|
|
|
|
bool paused, lastRow;
|
2016-04-10 18:18:26 +00:00
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// this type used as a flag, we dynamic_cast<> to it
|
|
|
|
class SendClickHandler : public ClickHandler {
|
|
|
|
public:
|
|
|
|
void onClick(Qt::MouseButton) const override {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-27 18:11:51 +00:00
|
|
|
class Context {
|
2016-04-04 21:09:46 +00:00
|
|
|
public:
|
2017-03-27 18:11:51 +00:00
|
|
|
virtual void inlineItemLayoutChanged(const ItemBase *layout) = 0;
|
|
|
|
virtual bool inlineItemVisible(const ItemBase *item) = 0;
|
|
|
|
virtual void inlineItemRepaint(const ItemBase *item) = 0;
|
|
|
|
};
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2017-03-27 18:11:51 +00:00
|
|
|
class ItemBase : public LayoutItemBase {
|
|
|
|
public:
|
2017-08-17 08:31:24 +00:00
|
|
|
ItemBase(not_null<Context*> context, Result *result) : _result(result), _context(context) {
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
2017-08-17 08:31:24 +00:00
|
|
|
ItemBase(not_null<Context*> context, DocumentData *doc) : _doc(doc), _context(context) {
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
// Not used anywhere currently.
|
2017-08-17 08:31:24 +00:00
|
|
|
//ItemBase(not_null<Context*> context, PhotoData *photo) : _photo(photo), _context(context) {
|
2016-04-04 21:09:46 +00:00
|
|
|
//}
|
|
|
|
|
2016-04-13 18:29:32 +00:00
|
|
|
virtual void paint(Painter &p, const QRect &clip, const PaintContext *context) const = 0;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
virtual void setPosition(int32 position);
|
|
|
|
int32 position() const;
|
|
|
|
|
|
|
|
virtual bool isFullLine() const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
virtual bool hasRightSkip() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Result *getResult() const;
|
|
|
|
DocumentData *getDocument() const;
|
|
|
|
PhotoData *getPhoto() const;
|
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
// Get document or photo (possibly from InlineBots::Result) for
|
|
|
|
// showing sticker / GIF / photo preview by long mouse press.
|
2016-04-06 15:32:05 +00:00
|
|
|
DocumentData *getPreviewDocument() const;
|
2016-04-10 18:18:26 +00:00
|
|
|
PhotoData *getPreviewPhoto() const;
|
2016-04-06 15:32:05 +00:00
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
virtual void preload() const;
|
|
|
|
|
|
|
|
void update();
|
2017-03-27 18:11:51 +00:00
|
|
|
void layoutChanged();
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
// ClickHandlerHost interface
|
|
|
|
void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override {
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override {
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
static std::unique_ptr<ItemBase> createLayout(not_null<Context*> context, Result *result, bool forceThumb);
|
|
|
|
static std::unique_ptr<ItemBase> createLayoutGif(not_null<Context*> context, DocumentData *document);
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
protected:
|
2016-04-05 20:24:27 +00:00
|
|
|
DocumentData *getResultDocument() const;
|
|
|
|
PhotoData *getResultPhoto() const;
|
|
|
|
ImagePtr getResultThumb() const;
|
|
|
|
QPixmap getResultContactAvatar(int width, int height) const;
|
|
|
|
int getResultDuration() const;
|
|
|
|
QString getResultUrl() const;
|
|
|
|
ClickHandlerPtr getResultUrlHandler() const;
|
|
|
|
ClickHandlerPtr getResultContentUrlHandler() const;
|
|
|
|
QString getResultThumbLetter() const;
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<Context*> context() const {
|
2017-03-27 18:11:51 +00:00
|
|
|
return _context;
|
|
|
|
}
|
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
Result *_result = nullptr;
|
|
|
|
DocumentData *_doc = nullptr;
|
|
|
|
PhotoData *_photo = nullptr;
|
|
|
|
|
|
|
|
ClickHandlerPtr _send = ClickHandlerPtr{ new SendClickHandler() };
|
|
|
|
|
|
|
|
int _position = 0; // < 0 means removed from layout
|
|
|
|
|
2017-03-27 18:11:51 +00:00
|
|
|
private:
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<Context*> _context;
|
2017-03-27 18:11:51 +00:00
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
};
|
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
using DocumentItems = QMap<DocumentData*, OrderedSet<ItemBase*>>;
|
|
|
|
const DocumentItems *documentItems();
|
|
|
|
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
void regDocumentItem(DocumentData *document, ItemBase *item);
|
|
|
|
void unregDocumentItem(DocumentData *document, ItemBase *item);
|
|
|
|
|
|
|
|
} // namespace internal
|
2016-04-04 21:09:46 +00:00
|
|
|
} // namespace Layout
|
|
|
|
} // namespace InlineBots
|