mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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 mousePos = mapFromGlobal(_mousePosition);
|
||||||
auto point = _widget->clampMousePosition(mousePos);
|
auto point = _widget->clampMousePosition(mousePos);
|
||||||
|
|
||||||
auto block = (HistoryBlock*)nullptr;
|
|
||||||
auto item = (HistoryItem*)nullptr;
|
|
||||||
auto view = (Element*)nullptr;
|
|
||||||
QPoint m;
|
QPoint m;
|
||||||
|
|
||||||
adjustCurrent(point.y());
|
adjustCurrent(point.y());
|
||||||
if (_curHistory && !_curHistory->isEmpty()) {
|
const auto reactionItemId = _reactionsManager->lookupButtonId(point);
|
||||||
block = _curHistory->blocks[_curBlock].get();
|
const auto reactionItem = session().data().message(reactionItemId);
|
||||||
view = block->messages[_curItem].get();
|
const auto reactionView = reactionItem
|
||||||
item = view->data();
|
? 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();
|
const auto was = App::mousedItem();
|
||||||
if (was != view) {
|
if (was != view) {
|
||||||
if (!_reactions.empty()) {
|
if (!_reactions.empty()) {
|
||||||
|
|
|
@ -1790,10 +1790,6 @@ TextSelection Message::adjustSelection(
|
||||||
|
|
||||||
Reactions::ButtonParameters Message::reactionButtonParameters(
|
Reactions::ButtonParameters Message::reactionButtonParameters(
|
||||||
QPoint position) const {
|
QPoint position) const {
|
||||||
const auto top = marginTop();
|
|
||||||
if (!QRect(0, top, width(), height() - top).contains(position)) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
auto result = Reactions::ButtonParameters{ .context = data()->fullId() };
|
auto result = Reactions::ButtonParameters{ .context = data()->fullId() };
|
||||||
result.outbg = hasOutLayout();
|
result.outbg = hasOutLayout();
|
||||||
const auto geometry = countGeometry();
|
const auto geometry = countGeometry();
|
||||||
|
@ -1807,6 +1803,12 @@ Reactions::ButtonParameters Message::reactionButtonParameters(
|
||||||
result.active = button.marginsAdded(
|
result.active = button.marginsAdded(
|
||||||
st::reactionCornerActiveAreaPadding
|
st::reactionCornerActiveAreaPadding
|
||||||
).contains(position);
|
).contains(position);
|
||||||
|
if (!result.active) {
|
||||||
|
const auto top = marginTop();
|
||||||
|
if (!QRect(0, top, width(), height() - top).contains(position)) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,17 +36,21 @@ constexpr auto kEmojiCacheIndex = 1;
|
||||||
constexpr auto kMaskCacheIndex = 2;
|
constexpr auto kMaskCacheIndex = 2;
|
||||||
constexpr auto kCacheColumsCount = 3;
|
constexpr auto kCacheColumsCount = 3;
|
||||||
|
|
||||||
[[nodiscard]] QSize CountOuterSize() {
|
[[nodiscard]] QSize CountMaxSizeWithMargins(style::margins margins) {
|
||||||
const auto extended = QRect(
|
const auto extended = QRect(
|
||||||
QPoint(),
|
QPoint(),
|
||||||
st::reactionCornerSize
|
st::reactionCornerSize
|
||||||
).marginsAdded(st::reactionCornerShadow);
|
).marginsAdded(margins);
|
||||||
const auto scale = Button::ScaleForState(ButtonState::Active);
|
const auto scale = Button::ScaleForState(ButtonState::Active);
|
||||||
return QSize(
|
return QSize(
|
||||||
int(base::SafeRound(extended.width() * scale)),
|
int(base::SafeRound(extended.width() * scale)),
|
||||||
int(base::SafeRound(extended.height() * scale)));
|
int(base::SafeRound(extended.height() * scale)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] QSize CountOuterSize() {
|
||||||
|
return CountMaxSizeWithMargins(st::reactionCornerShadow);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
InlineList::InlineList(Data &&data)
|
InlineList::InlineList(Data &&data)
|
||||||
|
@ -140,8 +144,10 @@ Button::Button(
|
||||||
Fn<void(QRect)> update,
|
Fn<void(QRect)> update,
|
||||||
ButtonParameters parameters)
|
ButtonParameters parameters)
|
||||||
: _update(std::move(update)) {
|
: _update(std::move(update)) {
|
||||||
_geometry = QRect(QPoint(), CountOuterSize());
|
const auto initial = QRect(QPoint(), CountOuterSize());
|
||||||
|
_geometry = initial.translated(parameters.center - initial.center());
|
||||||
_outbg = parameters.outbg;
|
_outbg = parameters.outbg;
|
||||||
|
applyState(parameters.active ? State::Active : State::Shown);
|
||||||
}
|
}
|
||||||
|
|
||||||
Button::~Button() = default;
|
Button::~Button() = default;
|
||||||
|
@ -159,10 +165,8 @@ QRect Button::geometry() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::applyParameters(ButtonParameters parameters) {
|
void Button::applyParameters(ButtonParameters parameters) {
|
||||||
const auto size = _geometry.size();
|
const auto geometry = _geometry.translated(
|
||||||
const auto geometry = QRect(
|
parameters.center - _geometry.center());
|
||||||
parameters.center - QPoint(size.width(), size.height()) / 2,
|
|
||||||
size);
|
|
||||||
if (_outbg != parameters.outbg) {
|
if (_outbg != parameters.outbg) {
|
||||||
_outbg = parameters.outbg;
|
_outbg = parameters.outbg;
|
||||||
_update(_geometry);
|
_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(
|
void Manager::paintButton(
|
||||||
Painter &p,
|
Painter &p,
|
||||||
const PaintContext &context,
|
const PaintContext &context,
|
||||||
|
|
|
@ -84,6 +84,7 @@ struct ButtonParameters {
|
||||||
FullMsgId context;
|
FullMsgId context;
|
||||||
QPoint center;
|
QPoint center;
|
||||||
ButtonStyle style = ButtonStyle::Bubble;
|
ButtonStyle style = ButtonStyle::Bubble;
|
||||||
|
bool inside = false;
|
||||||
bool active = false;
|
bool active = false;
|
||||||
bool outbg = false;
|
bool outbg = false;
|
||||||
};
|
};
|
||||||
|
@ -157,6 +158,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;
|
||||||
|
|
||||||
void showSelector(Fn<QPoint(QPoint)> mapToGlobal);
|
void showSelector(Fn<QPoint(QPoint)> mapToGlobal);
|
||||||
void showSelector(FullMsgId context, QRect globalButtonArea);
|
void showSelector(FullMsgId context, QRect globalButtonArea);
|
||||||
|
|
Loading…
Add table
Reference in a new issue