Handle click on the reaction once again.

This commit is contained in:
John Preston 2021-12-16 16:35:07 +04:00
parent b108e93092
commit 35378e717a
3 changed files with 24 additions and 8 deletions

View File

@ -2987,8 +2987,8 @@ void HistoryInner::mouseActionUpdate() {
QPoint m; QPoint m;
adjustCurrent(point.y()); adjustCurrent(point.y());
const auto reactionItemId = _reactionsManager->lookupButtonId(point); const auto reactionState = _reactionsManager->buttonTextState(point);
const auto reactionItem = session().data().message(reactionItemId); const auto reactionItem = session().data().message(reactionState.itemId);
const auto reactionView = reactionItem const auto reactionView = reactionItem
? reactionItem->mainView() ? reactionItem->mainView()
: nullptr; : nullptr;
@ -3034,7 +3034,13 @@ void HistoryInner::mouseActionUpdate() {
&& (view == App::hoveredItem()) && (view == App::hoveredItem())
&& !_selected.empty() && !_selected.empty()
&& (_selected.cbegin()->second != FullSelection); && (_selected.cbegin()->second != FullSelection);
if (point.y() < _historyPaddingTop) { if (reactionView && reactionState.link) {
dragState = reactionState;
lnkhost = reactionView;
_reactionsManager->showSelector([=](QPoint local) {
return mapToGlobal(local);
});
} else if (point.y() < _historyPaddingTop) {
if (_botAbout && !_botAbout->info->text.isEmpty() && _botAbout->height > 0) { if (_botAbout && !_botAbout->info->text.isEmpty() && _botAbout->height > 0) {
dragState = TextState(nullptr, _botAbout->info->text.getState( dragState = TextState(nullptr, _botAbout->info->text.getState(
point - _botAbout->rect.topLeft() - QPoint(st::msgPadding.left(), st::msgPadding.top() + st::botDescSkip + st::msgNameFont->height), point - _botAbout->rect.topLeft() - QPoint(st::msgPadding.left(), st::msgPadding.top() + st::botDescSkip + st::msgNameFont->height),

View File

@ -376,6 +376,14 @@ Manager::Manager(QWidget *selectorParent, Fn<void(QRect)> buttonUpdate)
st::reactionCornerSize.width(), st::reactionCornerSize.width(),
st::reactionCornerSize.height())) st::reactionCornerSize.height()))
, _buttonUpdate(std::move(buttonUpdate)) , _buttonUpdate(std::move(buttonUpdate))
, _buttonLink(std::make_shared<LambdaClickHandler>(crl::guard(this, [=] {
if (_buttonContext && !_list.empty()) {
_chosen.fire({
.context = _buttonContext,
.emoji = _list.front().emoji,
});
}
})))
, _selectorParent(selectorParent) { , _selectorParent(selectorParent) {
const auto ratio = style::DevicePixelRatio(); const auto ratio = style::DevicePixelRatio();
_cacheInOut = QImage( _cacheInOut = QImage(
@ -468,14 +476,16 @@ void Manager::paintButtons(Painter &p, const PaintContext &context) {
} }
} }
FullMsgId Manager::lookupButtonId(QPoint position) const { TextState Manager::buttonTextState(QPoint position) const {
if (const auto current = _button.get()) { if (const auto current = _button.get()) {
const auto geometry = current->geometry(); const auto geometry = current->geometry();
if (geometry.contains(position)) { if (geometry.contains(position)) {
const auto maxInner = QRect({}, CountMaxSizeWithMargins({})); const auto maxInner = QRect({}, CountMaxSizeWithMargins({}));
const auto shift = geometry.center() - maxInner.center(); const auto shift = geometry.center() - maxInner.center();
if (maxInner.translated(shift).contains(position)) { if (maxInner.translated(shift).contains(position)) {
return _buttonContext; auto result = TextState(nullptr, _buttonLink);
result.itemId = _buttonContext;
return result;
} }
} }
} }

View File

@ -28,7 +28,6 @@ namespace HistoryView {
using PaintContext = Ui::ChatPaintContext; using PaintContext = Ui::ChatPaintContext;
enum class PointState : char; enum class PointState : char;
struct TextState; struct TextState;
struct StateRequest;
class Message; class Message;
} // namespace HistoryView } // namespace HistoryView
@ -149,7 +148,7 @@ private:
}; };
class Manager final { class Manager final : public base::has_weak_ptr {
public: public:
Manager(QWidget *selectorParent, Fn<void(QRect)> buttonUpdate); Manager(QWidget *selectorParent, Fn<void(QRect)> buttonUpdate);
~Manager(); ~Manager();
@ -158,7 +157,7 @@ public:
void showButton(ButtonParameters parameters); void showButton(ButtonParameters parameters);
void paintButtons(Painter &p, const PaintContext &context); void paintButtons(Painter &p, const PaintContext &context);
[[nodiscard]] FullMsgId lookupButtonId(QPoint position) const; [[nodiscard]] TextState buttonTextState(QPoint position) const;
void showSelector(Fn<QPoint(QPoint)> mapToGlobal); void showSelector(Fn<QPoint(QPoint)> mapToGlobal);
void showSelector(FullMsgId context, QRect globalButtonArea); void showSelector(FullMsgId context, QRect globalButtonArea);
@ -227,6 +226,7 @@ private:
std::unique_ptr<Button> _button; std::unique_ptr<Button> _button;
std::vector<std::unique_ptr<Button>> _buttonHiding; std::vector<std::unique_ptr<Button>> _buttonHiding;
FullMsgId _buttonContext; FullMsgId _buttonContext;
ClickHandlerPtr _buttonLink;
QWidget *_selectorParent = nullptr; QWidget *_selectorParent = nullptr;
std::unique_ptr<Selector> _selector; std::unique_ptr<Selector> _selector;