| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388 |
- /*
- 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
- */
- #include "boxes/peer_list_widgets.h"
- #include "ui/painter.h"
- #include "ui/widgets/buttons.h"
- #include "ui/wrap/vertical_layout.h"
- #include "styles/style_boxes.h"
- namespace {
- using State = std::unique_ptr<PeerListState>;
- } // namespace
- PeerListWidgets::PeerListWidgets(
- not_null<Ui::RpWidget*> parent,
- not_null<PeerListController*> controller)
- : Ui::RpWidget(parent)
- , _controller(controller)
- , _st(controller->computeListSt()) {
- _content = base::make_unique_q<Ui::VerticalLayout>(this);
- parent->sizeValue() | rpl::start_with_next([this](const QSize &size) {
- _content->resizeToWidth(size.width());
- resize(size.width(), _content->height());
- }, lifetime());
- }
- crl::time PeerListWidgets::paintRow(
- Painter &p,
- crl::time now,
- bool selected,
- not_null<PeerListRow*> row) {
- const auto &st = row->computeSt(_st.item);
- row->lazyInitialize(st);
- const auto outerWidth = _content->width();
- const auto w = outerWidth;
- auto refreshStatusAt = row->refreshStatusTime();
- if (refreshStatusAt > 0 && now >= refreshStatusAt) {
- row->refreshStatus();
- refreshStatusAt = row->refreshStatusTime();
- }
- const auto refreshStatusIn = (refreshStatusAt > 0)
- ? std::max(refreshStatusAt - now, crl::time(1))
- : 0;
- row->paintUserpic(
- p,
- st,
- st.photoPosition.x(),
- st.photoPosition.y(),
- outerWidth);
- p.setPen(st::contactsNameFg);
- const auto skipRight = st.photoPosition.x();
- const auto rightActionSize = row->rightActionSize();
- const auto rightActionMargins = rightActionSize.isEmpty()
- ? QMargins()
- : row->rightActionMargins();
- const auto &name = row->name();
- const auto namePosition = st.namePosition;
- const auto namex = namePosition.x();
- const auto namey = namePosition.y();
- auto namew = outerWidth - namex - skipRight;
- if (!rightActionSize.isEmpty()
- && (namey < rightActionMargins.top() + rightActionSize.height())
- && (namey + st.nameStyle.font->height
- > rightActionMargins.top())) {
- namew -= rightActionMargins.left()
- + rightActionSize.width()
- + rightActionMargins.right()
- - skipRight;
- }
- const auto statusx = st.statusPosition.x();
- const auto statusy = st.statusPosition.y();
- auto statusw = outerWidth - statusx - skipRight;
- if (!rightActionSize.isEmpty()
- && (statusy < rightActionMargins.top() + rightActionSize.height())
- && (statusy + st::contactsStatusFont->height
- > rightActionMargins.top())) {
- statusw -= rightActionMargins.left()
- + rightActionSize.width()
- + rightActionMargins.right()
- - skipRight;
- }
- namew -= row->paintNameIconGetWidth(
- p,
- [=] { updateRow(row); },
- now,
- namex,
- namey,
- name.maxWidth(),
- namew,
- w,
- selected);
- auto nameCheckedRatio = row->disabled() ? 0. : row->checkedRatio();
- p.setPen(anim::pen(st.nameFg, st.nameFgChecked, nameCheckedRatio));
- name.drawLeftElided(p, namex, namey, namew, w);
- p.setFont(st::contactsStatusFont);
- row->paintStatusText(p, st, statusx, statusy, statusw, w, selected);
- row->elementsPaint(p, outerWidth, selected, 0);
- return refreshStatusIn;
- }
- void PeerListWidgets::appendRow(std::unique_ptr<PeerListRow> row) {
- Expects(row != nullptr);
- if (_rowsById.find(row->id()) == _rowsById.cend()) {
- const auto raw = row.get();
- const auto &st = raw->computeSt(_st.item);
- raw->setAbsoluteIndex(_rows.size());
- _rows.push_back(std::move(row));
- const auto widget = _content->add(
- object_ptr<Ui::AbstractButton>::fromRaw(
- Ui::CreateSimpleSettingsButton(
- _content.get(),
- st.button.ripple,
- st.button.textBgOver)));
- widget->resize(widget->width(), st.height);
- widget->paintRequest() | rpl::start_with_next([=, this] {
- auto p = Painter(widget);
- const auto selected = widget->isOver() || widget->isDown();
- paintRow(p, crl::now(), selected, raw);
- }, widget->lifetime());
- widget->setClickedCallback([this, raw] {
- _controller->rowClicked(raw);
- });
- }
- }
- PeerListRow *PeerListWidgets::findRow(PeerListRowId id) {
- const auto it = _rowsById.find(id);
- return (it == _rowsById.cend()) ? nullptr : it->second.get();
- }
- void PeerListWidgets::updateRow(not_null<PeerListRow*> row) {
- const auto it = ranges::find_if(
- _rows,
- [row](const auto &r) { return r.get() == row; });
- if (it != _rows.end()) {
- const auto index = std::distance(_rows.begin(), it);
- if (const auto widget = _content->widgetAt(index)) {
- widget->update();
- }
- }
- }
- int PeerListWidgets::fullRowsCount() {
- return _rows.size();
- }
- [[nodiscard]] not_null<PeerListRow*> PeerListWidgets::rowAt(int index) {
- Expects(index >= 0 && index < _rows.size());
- return _rows[index].get();
- }
- void PeerListWidgets::refreshRows() {
- _content->resizeToWidth(width());
- resize(width(), _content->height());
- }
- void PeerListWidgetsDelegate::setContent(PeerListWidgets *content) {
- _content = content;
- }
- void PeerListWidgetsDelegate::setUiShow(
- std::shared_ptr<Main::SessionShow> uiShow) {
- _uiShow = std::move(uiShow);
- }
- void PeerListWidgetsDelegate::peerListSetHideEmpty(bool hide) {
- Unexpected("...PeerListWidgetsDelegate::peerListSetHideEmpty");
- }
- void PeerListWidgetsDelegate::peerListAppendRow(
- std::unique_ptr<PeerListRow> row) {
- _content->appendRow(std::move(row));
- }
- void PeerListWidgetsDelegate::peerListAppendSearchRow(
- std::unique_ptr<PeerListRow> row) {
- Unexpected("...PeerListWidgetsDelegate::peerListAppendSearchRow");
- }
- void PeerListWidgetsDelegate::peerListAppendFoundRow(
- not_null<PeerListRow*> row) {
- Unexpected("...PeerListWidgetsDelegate::peerListAppendFoundRow");
- }
- void PeerListWidgetsDelegate::peerListPrependRow(
- std::unique_ptr<PeerListRow> row) {
- Unexpected("...PeerListWidgetsDelegate::peerListPrependRow");
- }
- void PeerListWidgetsDelegate::peerListPrependRowFromSearchResult(
- not_null<PeerListRow*> row) {
- Unexpected(
- "...PeerListWidgetsDelegate::peerListPrependRowFromSearchResult");
- }
- PeerListRow* PeerListWidgetsDelegate::peerListFindRow(PeerListRowId id) {
- return _content->findRow(id);
- }
- auto PeerListWidgetsDelegate::peerListLastRowMousePosition()
- -> std::optional<QPoint> {
- Unexpected("...PeerListWidgetsDelegate::peerListLastRowMousePosition");
- }
- void PeerListWidgetsDelegate::peerListUpdateRow(not_null<PeerListRow*> row) {
- _content->updateRow(row);
- }
- void PeerListWidgetsDelegate::peerListRemoveRow(not_null<PeerListRow*> row) {
- Unexpected("...PeerListWidgetsDelegate::peerListRemoveRow");
- }
- void PeerListWidgetsDelegate::peerListConvertRowToSearchResult(
- not_null<PeerListRow*> row) {
- Unexpected(
- "...PeerListWidgetsDelegate::peerListConvertRowToSearchResult");
- }
- void PeerListWidgetsDelegate::peerListSetRowChecked(
- not_null<PeerListRow*> row,
- bool checked) {
- Unexpected("...PeerListWidgetsDelegate::peerListSetRowChecked");
- }
- void PeerListWidgetsDelegate::peerListSetRowHidden(
- not_null<PeerListRow*> row,
- bool hidden) {
- Unexpected("...PeerListWidgetsDelegate::peerListSetRowHidden");
- }
- void PeerListWidgetsDelegate::peerListSetForeignRowChecked(
- not_null<PeerListRow*> row,
- bool checked,
- anim::type animated) {
- }
- int PeerListWidgetsDelegate::peerListFullRowsCount() {
- return _content->fullRowsCount();
- }
- not_null<PeerListRow*> PeerListWidgetsDelegate::peerListRowAt(int index) {
- return _content->rowAt(index);
- }
- int PeerListWidgetsDelegate::peerListSearchRowsCount() {
- Unexpected("...PeerListWidgetsDelegate::peerListSearchRowsCount");
- }
- not_null<PeerListRow*> PeerListWidgetsDelegate::peerListSearchRowAt(int) {
- Unexpected("...PeerListWidgetsDelegate::peerListSearchRowAt");
- }
- void PeerListWidgetsDelegate::peerListRefreshRows() {
- _content->refreshRows();
- }
- void PeerListWidgetsDelegate::peerListSetDescription(
- object_ptr<Ui::FlatLabel>) {
- Unexpected("...PeerListWidgetsDelegate::peerListSetDescription");
- }
- void PeerListWidgetsDelegate::peerListSetSearchNoResults(
- object_ptr<Ui::FlatLabel>) {
- Unexpected("...PeerListWidgetsDelegate::peerListSetSearchNoResults");
- }
- void PeerListWidgetsDelegate::peerListSetAboveWidget(
- object_ptr<Ui::RpWidget>) {
- Unexpected("...PeerListWidgetsDelegate::peerListSetAboveWidget");
- }
- void PeerListWidgetsDelegate::peerListSetAboveSearchWidget(
- object_ptr<Ui::RpWidget>) {
- Unexpected("...PeerListWidgetsDelegate::peerListSetAboveSearchWidget");
- }
- void PeerListWidgetsDelegate::peerListSetBelowWidget(
- object_ptr<Ui::RpWidget>) {
- Unexpected("...PeerListWidgetsDelegate::peerListSetBelowWidget");
- }
- void PeerListWidgetsDelegate::peerListSetSearchMode(PeerListSearchMode mode) {
- Unexpected("...PeerListWidgetsDelegate::peerListSetSearchMode");
- }
- void PeerListWidgetsDelegate::peerListMouseLeftGeometry() {
- Unexpected("...PeerListWidgetsDelegate::peerListMouseLeftGeometry");
- }
- void PeerListWidgetsDelegate::peerListSortRows(
- Fn<bool(const PeerListRow &, const PeerListRow &)>) {
- Unexpected("...PeerListWidgetsDelegate::peerListSortRows");
- }
- int PeerListWidgetsDelegate::peerListPartitionRows(
- Fn<bool(const PeerListRow &a)> border) {
- Unexpected("...PeerListWidgetsDelegate::peerListPartitionRows");
- }
- State PeerListWidgetsDelegate::peerListSaveState() const {
- Unexpected("...PeerListWidgetsDelegate::peerListSaveState");
- return nullptr;
- }
- void PeerListWidgetsDelegate::peerListRestoreState(
- std::unique_ptr<PeerListState> state) {
- Unexpected("...PeerListWidgetsDelegate::peerListRestoreState");
- }
- void PeerListWidgetsDelegate::peerListShowRowMenu(
- not_null<PeerListRow*> row,
- bool highlightRow,
- Fn<void(not_null<Ui::PopupMenu*>)> destroyed) {
- }
- void PeerListWidgetsDelegate::peerListSelectSkip(int direction) {
- // _content->selectSkip(direction);
- }
- void PeerListWidgetsDelegate::peerListPressLeftToContextMenu(bool shown) {
- Unexpected("...PeerListWidgetsDelegate::peerListPressLeftToContextMenu");
- }
- bool PeerListWidgetsDelegate::peerListTrackRowPressFromGlobal(QPoint) {
- return false;
- }
- std::shared_ptr<Main::SessionShow> PeerListWidgetsDelegate::peerListUiShow() {
- Expects(_uiShow != nullptr);
- return _uiShow;
- }
- void PeerListWidgetsDelegate::peerListAddSelectedPeerInBunch(
- not_null<PeerData*> peer) {
- Unexpected("...PeerListWidgetsDelegate::peerListAddSelectedPeerInBunch");
- }
- void PeerListWidgetsDelegate::peerListAddSelectedRowInBunch(
- not_null<PeerListRow*> row) {
- Unexpected("...PeerListWidgetsDelegate::peerListAddSelectedRowInBunch");
- }
- void PeerListWidgetsDelegate::peerListFinishSelectedRowsBunch() {
- Unexpected("...PeerListWidgetsDelegate::peerListFinishSelectedRowsBunch");
- }
- void PeerListWidgetsDelegate::peerListSetTitle(rpl::producer<QString> title) {
- Unexpected("...PeerListWidgetsDelegate::peerListSetTitle");
- }
- void PeerListWidgetsDelegate::peerListSetAdditionalTitle(
- rpl::producer<QString> title) {
- Unexpected("...PeerListWidgetsDelegate::peerListSetAdditionalTitle");
- }
- bool PeerListWidgetsDelegate::peerListIsRowChecked(
- not_null<PeerListRow*> row) {
- Unexpected("...PeerListWidgetsDelegate::peerListIsRowChecked");
- return false;
- }
- void PeerListWidgetsDelegate::peerListScrollToTop() {
- Unexpected("...PeerListWidgetsDelegate::peerListScrollToTop");
- }
- int PeerListWidgetsDelegate::peerListSelectedRowsCount() {
- Unexpected("...PeerListWidgetsDelegate::peerListSelectedRowsCount");
- return 0;
- }
|