mirror of https://github.com/procxx/kepka.git
Jump to date by date click in feed.
This commit is contained in:
parent
f066f3f139
commit
a1be63f890
|
@ -2756,6 +2756,7 @@ void ApiWrap::requestMessageAfterDate(
|
||||||
|
|
||||||
void ApiWrap::jumpToFeedDate(not_null<Data::Feed*> feed, const QDate &date) {
|
void ApiWrap::jumpToFeedDate(not_null<Data::Feed*> feed, const QDate &date) {
|
||||||
requestMessageAfterDate(feed, date, [=](Data::MessagePosition result) {
|
requestMessageAfterDate(feed, date, [=](Data::MessagePosition result) {
|
||||||
|
Ui::hideLayer();
|
||||||
App::wnd()->controller()->showSection(
|
App::wnd()->controller()->showSection(
|
||||||
HistoryFeed::Memento(feed, result));
|
HistoryFeed::Memento(feed, result));
|
||||||
});
|
});
|
||||||
|
|
|
@ -437,6 +437,15 @@ void Widget::listContentRefreshed() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClickHandlerPtr Widget::listDateLink(not_null<Element*> view) {
|
||||||
|
if (!_dateLink) {
|
||||||
|
_dateLink = std::make_shared<Window::DateClickHandler>(_feed, view->dateTime().date());
|
||||||
|
} else {
|
||||||
|
_dateLink->setDate(view->dateTime().date());
|
||||||
|
}
|
||||||
|
return _dateLink;
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<Window::SectionMemento> Widget::createMemento() {
|
std::unique_ptr<Window::SectionMemento> Widget::createMemento() {
|
||||||
auto result = std::make_unique<Memento>(_feed);
|
auto result = std::make_unique<Memento>(_feed);
|
||||||
saveState(result.get());
|
saveState(result.get());
|
||||||
|
|
|
@ -27,6 +27,10 @@ class TopBarWidget;
|
||||||
class Element;
|
class Element;
|
||||||
} // namespace HistoryView
|
} // namespace HistoryView
|
||||||
|
|
||||||
|
namespace Window {
|
||||||
|
class DateClickHandler;
|
||||||
|
} // namespace Window
|
||||||
|
|
||||||
namespace HistoryFeed {
|
namespace HistoryFeed {
|
||||||
|
|
||||||
class Memento;
|
class Memento;
|
||||||
|
@ -85,6 +89,7 @@ public:
|
||||||
base::optional<int> listUnreadBarView(
|
base::optional<int> listUnreadBarView(
|
||||||
const std::vector<not_null<Element*>> &elements) override;
|
const std::vector<not_null<Element*>> &elements) override;
|
||||||
void listContentRefreshed() override;
|
void listContentRefreshed() override;
|
||||||
|
ClickHandlerPtr listDateLink(not_null<Element*> view) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *e) override;
|
void resizeEvent(QResizeEvent *e) override;
|
||||||
|
@ -136,7 +141,7 @@ private:
|
||||||
Animation _scrollDownShown;
|
Animation _scrollDownShown;
|
||||||
bool _scrollDownIsShown = false;
|
bool _scrollDownIsShown = false;
|
||||||
object_ptr<Ui::HistoryDownButton> _scrollDown;
|
object_ptr<Ui::HistoryDownButton> _scrollDown;
|
||||||
|
std::shared_ptr<Window::DateClickHandler> _dateLink;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -621,7 +621,9 @@ void ListWidget::scrollDateCheck() {
|
||||||
|
|
||||||
void ListWidget::scrollDateHideByTimer() {
|
void ListWidget::scrollDateHideByTimer() {
|
||||||
_scrollDateHideTimer.cancel();
|
_scrollDateHideTimer.cancel();
|
||||||
scrollDateHide();
|
if (!_scrollDateLink || ClickHandler::getPressed() != _scrollDateLink) {
|
||||||
|
scrollDateHide();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ListWidget::scrollDateHide() {
|
void ListWidget::scrollDateHide() {
|
||||||
|
@ -630,6 +632,15 @@ void ListWidget::scrollDateHide() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ListWidget::keepScrollDateForNow() {
|
||||||
|
if (!_scrollDateShown
|
||||||
|
&& _scrollDateLastItem
|
||||||
|
&& _scrollDateOpacity.animating()) {
|
||||||
|
toggleScrollDateShown();
|
||||||
|
}
|
||||||
|
_scrollDateHideTimer.callOnce(kScrollDateHideTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
void ListWidget::toggleScrollDateShown() {
|
void ListWidget::toggleScrollDateShown() {
|
||||||
_scrollDateShown = !_scrollDateShown;
|
_scrollDateShown = !_scrollDateShown;
|
||||||
auto from = _scrollDateShown ? 0. : 1.;
|
auto from = _scrollDateShown ? 0. : 1.;
|
||||||
|
@ -1602,10 +1613,20 @@ void ListWidget::mousePressEvent(QMouseEvent *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ListWidget::mouseMoveEvent(QMouseEvent *e) {
|
void ListWidget::mouseMoveEvent(QMouseEvent *e) {
|
||||||
|
static auto lastGlobalPosition = e->globalPos();
|
||||||
|
auto reallyMoved = (lastGlobalPosition != e->globalPos());
|
||||||
auto buttonsPressed = (e->buttons() & (Qt::LeftButton | Qt::MiddleButton));
|
auto buttonsPressed = (e->buttons() & (Qt::LeftButton | Qt::MiddleButton));
|
||||||
if (!buttonsPressed && _mouseAction != MouseAction::None) {
|
if (!buttonsPressed && _mouseAction != MouseAction::None) {
|
||||||
mouseReleaseEvent(e);
|
mouseReleaseEvent(e);
|
||||||
}
|
}
|
||||||
|
if (reallyMoved) {
|
||||||
|
lastGlobalPosition = e->globalPos();
|
||||||
|
if (!buttonsPressed
|
||||||
|
|| (_scrollDateLink
|
||||||
|
&& ClickHandler::getPressed() == _scrollDateLink)) {
|
||||||
|
keepScrollDateForNow();
|
||||||
|
}
|
||||||
|
}
|
||||||
mouseActionUpdate(e->globalPos());
|
mouseActionUpdate(e->globalPos());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2047,34 +2068,87 @@ void ListWidget::mouseActionUpdate() {
|
||||||
} else {
|
} else {
|
||||||
inTextSelection = false;
|
inTextSelection = false;
|
||||||
}
|
}
|
||||||
// #TODO enumerate dates like HistoryInner
|
|
||||||
dragState = view->textState(itemPoint, request);
|
const auto dateHeight = st::msgServicePadding.bottom()
|
||||||
_overItemExact = App::histItemById(dragState.itemId);
|
+ st::msgServiceFont->height
|
||||||
lnkhost = view;
|
+ st::msgServicePadding.top();
|
||||||
if (!dragState.link
|
const auto scrollDateOpacity = _scrollDateOpacity.current(_scrollDateShown ? 1. : 0.);
|
||||||
&& itemPoint.x() >= st::historyPhotoLeft
|
enumerateDates([&](not_null<Element*> view, int itemtop, int dateTop) {
|
||||||
&& itemPoint.x() < st::historyPhotoLeft + st::msgPhotoSize) {
|
// stop enumeration if the date is above our point
|
||||||
if (view->hasFromPhoto()) {
|
if (dateTop + dateHeight <= point.y()) {
|
||||||
enumerateUserpics([&](not_null<Element*> view, int userpicTop) {
|
return false;
|
||||||
// stop enumeration if the userpic is below our point
|
}
|
||||||
if (userpicTop > point.y()) {
|
|
||||||
return false;
|
const auto displayDate = view->displayDate();
|
||||||
|
auto dateInPlace = displayDate;
|
||||||
|
if (dateInPlace) {
|
||||||
|
const auto correctDateTop = itemtop + st::msgServiceMargin.top();
|
||||||
|
dateInPlace = (dateTop < correctDateTop + dateHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
// stop enumeration if we've found a date under the cursor
|
||||||
|
if (dateTop <= point.y()) {
|
||||||
|
auto opacity = (dateInPlace/* || noFloatingDate*/) ? 1. : scrollDateOpacity;
|
||||||
|
if (opacity > 0.) {
|
||||||
|
const auto item = view->data();
|
||||||
|
auto dateWidth = 0;
|
||||||
|
if (const auto date = view->Get<HistoryView::DateBadge>()) {
|
||||||
|
dateWidth = date->width;
|
||||||
|
} else {
|
||||||
|
dateWidth = st::msgServiceFont->width(langDayOfMonthFull(view->dateTime().date()));
|
||||||
}
|
}
|
||||||
|
dateWidth += st::msgServicePadding.left() + st::msgServicePadding.right();
|
||||||
|
auto dateLeft = st::msgServiceMargin.left();
|
||||||
|
auto maxwidth = view->width();
|
||||||
|
if (Adaptive::ChatWide()) {
|
||||||
|
maxwidth = qMin(maxwidth, int32(st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left()));
|
||||||
|
}
|
||||||
|
auto widthForDate = maxwidth - st::msgServiceMargin.left() - st::msgServiceMargin.left();
|
||||||
|
|
||||||
// stop enumeration if we've found a userpic under the cursor
|
dateLeft += (widthForDate - dateWidth) / 2;
|
||||||
if (point.y() >= userpicTop && point.y() < userpicTop + st::msgPhotoSize) {
|
|
||||||
const auto message = view->data()->toHistoryMessage();
|
|
||||||
Assert(message != nullptr);
|
|
||||||
|
|
||||||
|
if (point.x() >= dateLeft && point.x() < dateLeft + dateWidth) {
|
||||||
|
_scrollDateLink = _delegate->listDateLink(view);
|
||||||
dragState = TextState(
|
dragState = TextState(
|
||||||
nullptr,
|
nullptr,
|
||||||
message->displayFrom()->openLink());
|
_scrollDateLink);
|
||||||
_overItemExact = App::histItemById(dragState.itemId);
|
_overItemExact = App::histItemById(dragState.itemId);
|
||||||
lnkhost = view;
|
lnkhost = view;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
}
|
||||||
});
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
if (!dragState.link) {
|
||||||
|
dragState = view->textState(itemPoint, request);
|
||||||
|
_overItemExact = App::histItemById(dragState.itemId);
|
||||||
|
lnkhost = view;
|
||||||
|
if (!dragState.link
|
||||||
|
&& itemPoint.x() >= st::historyPhotoLeft
|
||||||
|
&& itemPoint.x() < st::historyPhotoLeft + st::msgPhotoSize) {
|
||||||
|
if (view->hasFromPhoto()) {
|
||||||
|
enumerateUserpics([&](not_null<Element*> view, int userpicTop) {
|
||||||
|
// stop enumeration if the userpic is below our point
|
||||||
|
if (userpicTop > point.y()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// stop enumeration if we've found a userpic under the cursor
|
||||||
|
if (point.y() >= userpicTop && point.y() < userpicTop + st::msgPhotoSize) {
|
||||||
|
const auto message = view->data()->toHistoryMessage();
|
||||||
|
Assert(message != nullptr);
|
||||||
|
|
||||||
|
dragState = TextState(
|
||||||
|
nullptr,
|
||||||
|
message->displayFrom()->openLink());
|
||||||
|
_overItemExact = App::histItemById(dragState.itemId);
|
||||||
|
lnkhost = view;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,7 @@ public:
|
||||||
virtual base::optional<int> listUnreadBarView(
|
virtual base::optional<int> listUnreadBarView(
|
||||||
const std::vector<not_null<Element*>> &elements) = 0;
|
const std::vector<not_null<Element*>> &elements) = 0;
|
||||||
virtual void listContentRefreshed() = 0;
|
virtual void listContentRefreshed() = 0;
|
||||||
|
virtual ClickHandlerPtr listDateLink(not_null<Element*> view) = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -302,6 +303,7 @@ private:
|
||||||
void scrollDateHide();
|
void scrollDateHide();
|
||||||
void scrollDateCheck();
|
void scrollDateCheck();
|
||||||
void scrollDateHideByTimer();
|
void scrollDateHideByTimer();
|
||||||
|
void keepScrollDateForNow();
|
||||||
|
|
||||||
void trySwitchToWordSelection();
|
void trySwitchToWordSelection();
|
||||||
void switchToWordSelection();
|
void switchToWordSelection();
|
||||||
|
@ -440,6 +442,7 @@ private:
|
||||||
base::Timer _scrollDateHideTimer;
|
base::Timer _scrollDateHideTimer;
|
||||||
Element *_scrollDateLastItem = nullptr;
|
Element *_scrollDateLastItem = nullptr;
|
||||||
int _scrollDateLastItemTop = 0;
|
int _scrollDateLastItemTop = 0;
|
||||||
|
ClickHandlerPtr _scrollDateLink;
|
||||||
SingleQueuedInvokation _applyUpdatedScrollState;
|
SingleQueuedInvokation _applyUpdatedScrollState;
|
||||||
|
|
||||||
Element *_unreadBarElement = nullptr;
|
Element *_unreadBarElement = nullptr;
|
||||||
|
|
|
@ -337,7 +337,7 @@ void Controller::showJumpToDate(Dialogs::Key chat, QDate requestedDate) {
|
||||||
return history->chatsListDate().date();
|
return history->chatsListDate().date();
|
||||||
}
|
}
|
||||||
} else if (const auto feed = chat.feed()) {
|
} else if (const auto feed = chat.feed()) {
|
||||||
/*if (chatScrollPosition(feed)) {
|
/*if (chatScrollPosition(feed)) { // #TODO feeds save position
|
||||||
|
|
||||||
} else */if (!feed->chatsListDate().isNull()) {
|
} else */if (!feed->chatsListDate().isNull()) {
|
||||||
return feed->chatsListDate().date();
|
return feed->chatsListDate().date();
|
||||||
|
|
Loading…
Reference in New Issue