mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Keep reaction visible if mouse is over it.
This commit is contained in:
parent
371c9c1bfe
commit
b108e93092
4 changed files with 45 additions and 19 deletions
|
@ -2984,17 +2984,21 @@ void HistoryInner::mouseActionUpdate() {
|
|||
auto mousePos = mapFromGlobal(_mousePosition);
|
||||
auto point = _widget->clampMousePosition(mousePos);
|
||||
|
||||
auto block = (HistoryBlock*)nullptr;
|
||||
auto item = (HistoryItem*)nullptr;
|
||||
auto view = (Element*)nullptr;
|
||||
QPoint m;
|
||||
|
||||
adjustCurrent(point.y());
|
||||
if (_curHistory && !_curHistory->isEmpty()) {
|
||||
block = _curHistory->blocks[_curBlock].get();
|
||||
view = block->messages[_curItem].get();
|
||||
item = view->data();
|
||||
|
||||
const auto reactionItemId = _reactionsManager->lookupButtonId(point);
|
||||
const auto reactionItem = session().data().message(reactionItemId);
|
||||
const auto reactionView = reactionItem
|
||||
? reactionItem->mainView()
|
||||
: nullptr;
|
||||
const auto view = reactionView
|
||||
? reactionView
|
||||
: (_curHistory && !_curHistory->isEmpty())
|
||||
? _curHistory->blocks[_curBlock]->messages[_curItem].get()
|
||||
: nullptr;
|
||||
const auto item = view ? view->data().get() : nullptr;
|
||||
if (view) {
|
||||
const auto was = App::mousedItem();
|
||||
if (was != view) {
|
||||
if (!_reactions.empty()) {
|
||||
|
|
|
@ -1790,10 +1790,6 @@ TextSelection Message::adjustSelection(
|
|||
|
||||
Reactions::ButtonParameters Message::reactionButtonParameters(
|
||||
QPoint position) const {
|
||||
const auto top = marginTop();
|
||||
if (!QRect(0, top, width(), height() - top).contains(position)) {
|
||||
return {};
|
||||
}
|
||||
auto result = Reactions::ButtonParameters{ .context = data()->fullId() };
|
||||
result.outbg = hasOutLayout();
|
||||
const auto geometry = countGeometry();
|
||||
|
@ -1807,6 +1803,12 @@ Reactions::ButtonParameters Message::reactionButtonParameters(
|
|||
result.active = button.marginsAdded(
|
||||
st::reactionCornerActiveAreaPadding
|
||||
).contains(position);
|
||||
if (!result.active) {
|
||||
const auto top = marginTop();
|
||||
if (!QRect(0, top, width(), height() - top).contains(position)) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,17 +36,21 @@ constexpr auto kEmojiCacheIndex = 1;
|
|||
constexpr auto kMaskCacheIndex = 2;
|
||||
constexpr auto kCacheColumsCount = 3;
|
||||
|
||||
[[nodiscard]] QSize CountOuterSize() {
|
||||
[[nodiscard]] QSize CountMaxSizeWithMargins(style::margins margins) {
|
||||
const auto extended = QRect(
|
||||
QPoint(),
|
||||
st::reactionCornerSize
|
||||
).marginsAdded(st::reactionCornerShadow);
|
||||
).marginsAdded(margins);
|
||||
const auto scale = Button::ScaleForState(ButtonState::Active);
|
||||
return QSize(
|
||||
int(base::SafeRound(extended.width() * scale)),
|
||||
int(base::SafeRound(extended.height() * scale)));
|
||||
}
|
||||
|
||||
[[nodiscard]] QSize CountOuterSize() {
|
||||
return CountMaxSizeWithMargins(st::reactionCornerShadow);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
InlineList::InlineList(Data &&data)
|
||||
|
@ -140,8 +144,10 @@ Button::Button(
|
|||
Fn<void(QRect)> update,
|
||||
ButtonParameters parameters)
|
||||
: _update(std::move(update)) {
|
||||
_geometry = QRect(QPoint(), CountOuterSize());
|
||||
const auto initial = QRect(QPoint(), CountOuterSize());
|
||||
_geometry = initial.translated(parameters.center - initial.center());
|
||||
_outbg = parameters.outbg;
|
||||
applyState(parameters.active ? State::Active : State::Shown);
|
||||
}
|
||||
|
||||
Button::~Button() = default;
|
||||
|
@ -159,10 +165,8 @@ QRect Button::geometry() const {
|
|||
}
|
||||
|
||||
void Button::applyParameters(ButtonParameters parameters) {
|
||||
const auto size = _geometry.size();
|
||||
const auto geometry = QRect(
|
||||
parameters.center - QPoint(size.width(), size.height()) / 2,
|
||||
size);
|
||||
const auto geometry = _geometry.translated(
|
||||
parameters.center - _geometry.center());
|
||||
if (_outbg != parameters.outbg) {
|
||||
_outbg = parameters.outbg;
|
||||
_update(_geometry);
|
||||
|
@ -464,6 +468,20 @@ void Manager::paintButtons(Painter &p, const PaintContext &context) {
|
|||
}
|
||||
}
|
||||
|
||||
FullMsgId Manager::lookupButtonId(QPoint position) const {
|
||||
if (const auto current = _button.get()) {
|
||||
const auto geometry = current->geometry();
|
||||
if (geometry.contains(position)) {
|
||||
const auto maxInner = QRect({}, CountMaxSizeWithMargins({}));
|
||||
const auto shift = geometry.center() - maxInner.center();
|
||||
if (maxInner.translated(shift).contains(position)) {
|
||||
return _buttonContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void Manager::paintButton(
|
||||
Painter &p,
|
||||
const PaintContext &context,
|
||||
|
|
|
@ -84,6 +84,7 @@ struct ButtonParameters {
|
|||
FullMsgId context;
|
||||
QPoint center;
|
||||
ButtonStyle style = ButtonStyle::Bubble;
|
||||
bool inside = false;
|
||||
bool active = false;
|
||||
bool outbg = false;
|
||||
};
|
||||
|
@ -157,6 +158,7 @@ public:
|
|||
|
||||
void showButton(ButtonParameters parameters);
|
||||
void paintButtons(Painter &p, const PaintContext &context);
|
||||
[[nodiscard]] FullMsgId lookupButtonId(QPoint position) const;
|
||||
|
||||
void showSelector(Fn<QPoint(QPoint)> mapToGlobal);
|
||||
void showSelector(FullMsgId context, QRect globalButtonArea);
|
||||
|
|
Loading…
Add table
Reference in a new issue