tdesktop/Telegram/SourceFiles/dialogs/dialogs_row.h

150 lines
2.9 KiB
C
Raw Normal View History

/*
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 "ui/text/text.h"
2019-06-17 14:37:29 +00:00
#include "ui/effects/animations.h"
#include "dialogs/dialogs_key.h"
class History;
class HistoryItem;
2020-05-28 14:32:10 +00:00
namespace Data {
class CloudImageView;
} // namespace Data
namespace Ui {
class RippleAnimation;
} // namespace Ui
namespace Dialogs {
namespace Layout {
class RowPainter;
} // namespace Layout
enum class SortMode;
2019-06-17 14:37:29 +00:00
class BasicRow {
public:
2019-06-17 14:37:29 +00:00
BasicRow();
~BasicRow();
void setOnline(bool online, Fn<void()> updateCallback = nullptr) const;
void paintUserpic(
Painter &p,
not_null<PeerData*> peer,
bool allowOnline,
bool active,
int fullWidth) const;
void addRipple(QPoint origin, QSize size, Fn<void()> updateCallback);
void stopLastRipple();
2019-06-17 14:37:29 +00:00
void paintRipple(
Painter &p,
int x,
int y,
int outerWidth,
const QColor *colorOverride = nullptr) const;
2020-05-28 14:32:10 +00:00
std::shared_ptr<Data::CloudImageView> &userpicView() const {
return _userpic;
}
private:
2019-06-17 14:37:29 +00:00
struct OnlineUserpic {
InMemoryKey key;
float64 online = 0.;
bool active = false;
QImage frame;
Ui::Animations::Simple animation;
};
void ensureOnlineUserpic() const;
static void PaintOnlineFrame(
not_null<OnlineUserpic*> data,
2020-05-28 14:32:10 +00:00
not_null<PeerData*> peer,
std::shared_ptr<Data::CloudImageView> &view);
2019-06-17 14:37:29 +00:00
2020-05-28 14:32:10 +00:00
mutable std::shared_ptr<Data::CloudImageView> _userpic;
mutable std::unique_ptr<Ui::RippleAnimation> _ripple;
2019-06-17 14:37:29 +00:00
mutable std::unique_ptr<OnlineUserpic> _onlineUserpic;
mutable bool _online = false;
};
class List;
2019-06-17 14:37:29 +00:00
class Row : public BasicRow {
public:
explicit Row(std::nullptr_t) {
}
2019-06-17 14:37:29 +00:00
Row(Key key, int pos);
Key key() const {
return _id;
}
History *history() const {
return _id.history();
}
2019-04-15 11:54:03 +00:00
Data::Folder *folder() const {
return _id.folder();
}
not_null<Entry*> entry() const {
return _id.entry();
}
int pos() const {
return _pos;
}
2020-03-17 13:04:30 +00:00
uint64 sortKey(FilterId filterId) const;
void validateListEntryCache() const;
2019-06-12 13:26:04 +00:00
const Ui::Text::String &listEntryCache() const {
return _listEntryCache;
}
// for any attached data, for example View in contacts list
void *attached = nullptr;
private:
friend class List;
Key _id;
int _pos = 0;
mutable uint32 _listEntryCacheVersion = 0;
2019-06-12 13:26:04 +00:00
mutable Ui::Text::String _listEntryCache;
};
2019-06-17 14:37:29 +00:00
class FakeRow : public BasicRow {
public:
FakeRow(Key searchInChat, not_null<HistoryItem*> item);
Key searchInChat() const {
return _searchInChat;
}
not_null<HistoryItem*> item() const {
return _item;
}
void invalidateCache() {
_cacheFor = nullptr;
_cache = Ui::Text::String();
}
private:
friend class Layout::RowPainter;
Key _searchInChat;
not_null<HistoryItem*> _item;
mutable const HistoryItem *_cacheFor = nullptr;
2019-06-12 13:26:04 +00:00
mutable Ui::Text::String _cache;
};
} // namespace Dialogs