mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 06:35:14 +00:00
ClickHandler, TopBarWidget and Overview layouts moved to separate files.
Xcode and QtCreator builds are currently broken.
This commit is contained in:
@@ -91,12 +91,13 @@ public:
|
||||
|
||||
};
|
||||
|
||||
class LayoutMediaItemBase;
|
||||
class LayoutItemBase : public Composer, public ClickHandlerHost {
|
||||
public:
|
||||
LayoutItemBase() {
|
||||
}
|
||||
LayoutItemBase &operator=(const LayoutItemBase &) = delete;
|
||||
|
||||
LayoutItemBase(const LayoutItemBase &other) = delete;
|
||||
LayoutItemBase &operator=(const LayoutItemBase &other) = delete;
|
||||
|
||||
int32 maxWidth() const {
|
||||
return _maxw;
|
||||
@@ -142,311 +143,3 @@ protected:
|
||||
int _minh = 0;
|
||||
|
||||
};
|
||||
|
||||
class PaintContextOverview : public PaintContextBase {
|
||||
public:
|
||||
PaintContextOverview(uint64 ms, bool selecting) : PaintContextBase(ms, selecting), isAfterDate(false) {
|
||||
}
|
||||
bool isAfterDate;
|
||||
|
||||
};
|
||||
|
||||
class LayoutOverviewItemBase : public LayoutItemBase {
|
||||
public:
|
||||
|
||||
virtual void paint(Painter &p, const QRect &clip, uint32 selection, const PaintContextOverview *context) const = 0;
|
||||
|
||||
virtual LayoutMediaItemBase *toLayoutMediaItem() {
|
||||
return nullptr;
|
||||
}
|
||||
virtual const LayoutMediaItemBase *toLayoutMediaItem() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
virtual HistoryItem *getItem() const {
|
||||
return nullptr;
|
||||
}
|
||||
virtual DocumentData *getDocument() const {
|
||||
return nullptr;
|
||||
}
|
||||
MsgId msgId() const {
|
||||
const HistoryItem *item = getItem();
|
||||
return item ? item->id : 0;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class LayoutMediaItemBase : public LayoutOverviewItemBase {
|
||||
public:
|
||||
LayoutMediaItemBase(HistoryItem *parent) : _parent(parent) {
|
||||
}
|
||||
|
||||
LayoutMediaItemBase *toLayoutMediaItem() override {
|
||||
return this;
|
||||
}
|
||||
const LayoutMediaItemBase *toLayoutMediaItem() const override {
|
||||
return this;
|
||||
}
|
||||
HistoryItem *getItem() const override {
|
||||
return _parent;
|
||||
}
|
||||
|
||||
void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override;
|
||||
void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool active) override;
|
||||
|
||||
protected:
|
||||
HistoryItem *_parent;
|
||||
|
||||
};
|
||||
|
||||
class LayoutRadialProgressItem : public LayoutMediaItemBase {
|
||||
public:
|
||||
LayoutRadialProgressItem(HistoryItem *parent) : LayoutMediaItemBase(parent)
|
||||
, _radial(0)
|
||||
, a_iconOver(0, 0)
|
||||
, _a_iconOver(animation(this, &LayoutRadialProgressItem::step_iconOver)) {
|
||||
}
|
||||
|
||||
void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override;
|
||||
void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool active) override;
|
||||
|
||||
~LayoutRadialProgressItem();
|
||||
|
||||
protected:
|
||||
ClickHandlerPtr _openl, _savel, _cancell;
|
||||
void setLinks(ClickHandlerPtr &&openl, ClickHandlerPtr &&savel, ClickHandlerPtr &&cancell);
|
||||
void setDocumentLinks(DocumentData *document) {
|
||||
ClickHandlerPtr save;
|
||||
if (document->voice()) {
|
||||
save.reset(new DocumentOpenClickHandler(document));
|
||||
} else {
|
||||
save.reset(new DocumentSaveClickHandler(document));
|
||||
}
|
||||
setLinks(MakeShared<DocumentOpenClickHandler>(document), std_::move(save), MakeShared<DocumentCancelClickHandler>(document));
|
||||
}
|
||||
|
||||
void step_iconOver(float64 ms, bool timer);
|
||||
void step_radial(uint64 ms, bool timer);
|
||||
|
||||
void ensureRadial() const;
|
||||
void checkRadialFinished();
|
||||
|
||||
bool isRadialAnimation(uint64 ms) const {
|
||||
if (!_radial || !_radial->animating()) return false;
|
||||
|
||||
_radial->step(ms);
|
||||
return _radial && _radial->animating();
|
||||
}
|
||||
|
||||
virtual float64 dataProgress() const = 0;
|
||||
virtual bool dataFinished() const = 0;
|
||||
virtual bool dataLoaded() const = 0;
|
||||
virtual bool iconAnimated() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
mutable RadialAnimation *_radial;
|
||||
anim::fvalue a_iconOver;
|
||||
mutable Animation _a_iconOver;
|
||||
|
||||
private:
|
||||
LayoutRadialProgressItem(const LayoutRadialProgressItem &other);
|
||||
|
||||
};
|
||||
|
||||
class LayoutAbstractFileItem : public LayoutRadialProgressItem {
|
||||
public:
|
||||
LayoutAbstractFileItem(HistoryItem *parent) : LayoutRadialProgressItem(parent) {
|
||||
}
|
||||
|
||||
protected:
|
||||
// >= 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;
|
||||
|
||||
};
|
||||
|
||||
struct OverviewItemInfo : public BaseComponent<OverviewItemInfo> {
|
||||
int top = 0;
|
||||
};
|
||||
|
||||
class LayoutOverviewDate : public LayoutOverviewItemBase {
|
||||
public:
|
||||
LayoutOverviewDate(const QDate &date, bool month);
|
||||
|
||||
void initDimensions() override;
|
||||
void paint(Painter &p, const QRect &clip, uint32 selection, const PaintContextOverview *context) const override;
|
||||
|
||||
private:
|
||||
QDate _date;
|
||||
QString _text;
|
||||
|
||||
};
|
||||
|
||||
class LayoutOverviewPhoto : public LayoutMediaItemBase {
|
||||
public:
|
||||
LayoutOverviewPhoto(PhotoData *photo, HistoryItem *parent);
|
||||
|
||||
void initDimensions() override;
|
||||
int32 resizeGetHeight(int32 width) override;
|
||||
void paint(Painter &p, const QRect &clip, uint32 selection, const PaintContextOverview *context) const override;
|
||||
void getState(ClickHandlerPtr &link, HistoryCursorState &cursor, int x, int y) const override;
|
||||
|
||||
private:
|
||||
PhotoData *_data;
|
||||
ClickHandlerPtr _link;
|
||||
|
||||
mutable QPixmap _pix;
|
||||
mutable bool _goodLoaded;
|
||||
|
||||
};
|
||||
|
||||
class LayoutOverviewVideo : public LayoutAbstractFileItem {
|
||||
public:
|
||||
LayoutOverviewVideo(DocumentData *video, HistoryItem *parent);
|
||||
|
||||
void initDimensions() override;
|
||||
int32 resizeGetHeight(int32 width) override;
|
||||
void paint(Painter &p, const QRect &clip, uint32 selection, const PaintContextOverview *context) const override;
|
||||
void getState(ClickHandlerPtr &link, HistoryCursorState &cursor, int x, int y) const override;
|
||||
|
||||
protected:
|
||||
float64 dataProgress() const override {
|
||||
return _data->progress();
|
||||
}
|
||||
bool dataFinished() const override {
|
||||
return !_data->loading();
|
||||
}
|
||||
bool dataLoaded() const override {
|
||||
return _data->loaded();
|
||||
}
|
||||
bool iconAnimated() const override {
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
DocumentData *_data;
|
||||
|
||||
QString _duration;
|
||||
mutable QPixmap _pix;
|
||||
mutable bool _thumbLoaded;
|
||||
|
||||
void updateStatusText() const;
|
||||
|
||||
};
|
||||
|
||||
class LayoutOverviewVoice : public LayoutAbstractFileItem {
|
||||
public:
|
||||
LayoutOverviewVoice(DocumentData *voice, HistoryItem *parent);
|
||||
|
||||
void initDimensions() override;
|
||||
void paint(Painter &p, const QRect &clip, uint32 selection, const PaintContextOverview *context) const override;
|
||||
void getState(ClickHandlerPtr &link, HistoryCursorState &cursor, int x, int y) const override;
|
||||
|
||||
protected:
|
||||
float64 dataProgress() const override {
|
||||
return _data->progress();
|
||||
}
|
||||
bool dataFinished() const override {
|
||||
return !_data->loading();
|
||||
}
|
||||
bool dataLoaded() const override {
|
||||
return _data->loaded();
|
||||
}
|
||||
bool iconAnimated() const override {
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
DocumentData *_data;
|
||||
ClickHandlerPtr _namel;
|
||||
|
||||
mutable Text _name, _details;
|
||||
mutable int32 _nameVersion;
|
||||
|
||||
void updateName() const;
|
||||
bool updateStatusText() const;
|
||||
|
||||
};
|
||||
|
||||
class LayoutOverviewDocument : public LayoutAbstractFileItem {
|
||||
public:
|
||||
LayoutOverviewDocument(DocumentData *document, HistoryItem *parent);
|
||||
|
||||
void initDimensions() override;
|
||||
void paint(Painter &p, const QRect &clip, uint32 selection, const PaintContextOverview *context) const override;
|
||||
void getState(ClickHandlerPtr &link, HistoryCursorState &cursor, int x, int y) const override;
|
||||
|
||||
virtual DocumentData *getDocument() const override {
|
||||
return _data;
|
||||
}
|
||||
|
||||
protected:
|
||||
float64 dataProgress() const override {
|
||||
return _data->progress();
|
||||
}
|
||||
bool dataFinished() const override {
|
||||
return !_data->loading();
|
||||
}
|
||||
bool dataLoaded() const override {
|
||||
return _data->loaded();
|
||||
}
|
||||
bool iconAnimated() const override {
|
||||
return _data->song() || !_data->loaded() || (_radial && _radial->animating());
|
||||
}
|
||||
|
||||
private:
|
||||
DocumentData *_data;
|
||||
ClickHandlerPtr _msgl, _namel;
|
||||
|
||||
mutable bool _thumbForLoaded;
|
||||
mutable QPixmap _thumb;
|
||||
|
||||
QString _name, _date, _ext;
|
||||
int32 _namew, _datew, _extw;
|
||||
int32 _thumbw, _colorIndex;
|
||||
|
||||
bool withThumb() const {
|
||||
return !_data->thumb->isNull() && _data->thumb->width() && _data->thumb->height();
|
||||
}
|
||||
bool updateStatusText() const;
|
||||
|
||||
};
|
||||
|
||||
class LayoutOverviewLink : public LayoutMediaItemBase {
|
||||
public:
|
||||
LayoutOverviewLink(HistoryMedia *media, HistoryItem *parent);
|
||||
|
||||
void initDimensions() override;
|
||||
int32 resizeGetHeight(int32 width) override;
|
||||
void paint(Painter &p, const QRect &clip, uint32 selection, const PaintContextOverview *context) const override;
|
||||
void getState(ClickHandlerPtr &link, HistoryCursorState &cursor, int x, int y) const override;
|
||||
|
||||
private:
|
||||
ClickHandlerPtr _photol;
|
||||
|
||||
QString _title, _letter;
|
||||
int _titlew = 0;
|
||||
WebPageData *_page = nullptr;
|
||||
int _pixw = 0;
|
||||
int _pixh = 0;
|
||||
Text _text = { int(st::msgMinWidth) };
|
||||
|
||||
struct Link {
|
||||
Link() : width(0) {
|
||||
}
|
||||
Link(const QString &url, const QString &text);
|
||||
QString text;
|
||||
int32 width;
|
||||
TextClickHandlerPtr lnk;
|
||||
};
|
||||
QVector<Link> _links;
|
||||
|
||||
};
|
||||
|
Reference in New Issue
Block a user