mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Allow dragging the expanded emoji categories.
This commit is contained in:
parent
57d5ec4513
commit
007cb9d156
2 changed files with 51 additions and 26 deletions
|
@ -649,7 +649,8 @@ void StickersListFooter::mousePressEvent(QMouseEvent *e) {
|
|||
} else {
|
||||
_pressed = _selected;
|
||||
_iconsMouseDown = _iconsMousePos;
|
||||
_iconsStartX = qRound(_iconState.x.current());
|
||||
_iconState.draggingStartX = qRound(_iconState.x.current());
|
||||
_subiconState.draggingStartX = qRound(_subiconState.x.current());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -657,23 +658,33 @@ void StickersListFooter::mouseMoveEvent(QMouseEvent *e) {
|
|||
_iconsMousePos = e ? e->globalPos() : QCursor::pos();
|
||||
updateSelected();
|
||||
|
||||
if (!_iconsDragging
|
||||
if (!_iconState.dragging
|
||||
&& !_icons.empty()
|
||||
&& v::is<IconId>(_pressed)) {
|
||||
if ((_iconsMousePos - _iconsMouseDown).manhattanLength() >= QApplication::startDragDistance()) {
|
||||
_iconsDragging = true;
|
||||
const auto &icon = _icons[v::get<IconId>(_pressed).index];
|
||||
(icon.setId == AllEmojiSectionSetId()
|
||||
? _subiconState
|
||||
: _iconState).dragging = true;
|
||||
}
|
||||
}
|
||||
if (_iconsDragging) {
|
||||
auto newX = std::clamp(
|
||||
checkDragging(_iconState, _iconsAnimation);
|
||||
checkDragging(_subiconState, _subiconsAnimation);
|
||||
}
|
||||
|
||||
void StickersListFooter::checkDragging(
|
||||
ScrollState &state,
|
||||
Ui::Animations::Basic &animation) {
|
||||
if (state.dragging) {
|
||||
const auto newX = std::clamp(
|
||||
(rtl() ? -1 : 1) * (_iconsMouseDown.x() - _iconsMousePos.x())
|
||||
+ _iconsStartX,
|
||||
+ state.draggingStartX,
|
||||
0,
|
||||
_iconState.max);
|
||||
if (newX != qRound(_iconState.x.current())) {
|
||||
_iconState.x = anim::value(newX, newX);
|
||||
_iconState.animationStart = 0;
|
||||
_iconsAnimation.stop();
|
||||
state.max);
|
||||
if (newX != qRound(state.x.current())) {
|
||||
state.x = anim::value(newX, newX);
|
||||
state.animationStart = 0;
|
||||
animation.stop();
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
@ -687,8 +698,7 @@ void StickersListFooter::mouseReleaseEvent(QMouseEvent *e) {
|
|||
const auto wasDown = std::exchange(_pressed, SpecialOver::None);
|
||||
|
||||
_iconsMousePos = e ? e->globalPos() : QCursor::pos();
|
||||
if (_iconsDragging) {
|
||||
finishDragging();
|
||||
if (finishDragging()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -714,19 +724,31 @@ void StickersListFooter::mouseReleaseEvent(QMouseEvent *e) {
|
|||
}
|
||||
}
|
||||
|
||||
void StickersListFooter::finishDragging() {
|
||||
auto newX = std::clamp(
|
||||
_iconsStartX + _iconsMouseDown.x() - _iconsMousePos.x(),
|
||||
bool StickersListFooter::finishDragging() {
|
||||
const auto icon = finishDragging(_iconState, _iconsAnimation);
|
||||
const auto subicon = finishDragging(_subiconState, _subiconsAnimation);
|
||||
return icon || subicon;
|
||||
}
|
||||
|
||||
bool StickersListFooter::finishDragging(
|
||||
ScrollState &state,
|
||||
Ui::Animations::Basic &animation) {
|
||||
if (!state.dragging) {
|
||||
return false;
|
||||
}
|
||||
const auto newX = std::clamp(
|
||||
state.draggingStartX + _iconsMouseDown.x() - _iconsMousePos.x(),
|
||||
0,
|
||||
_iconState.max);
|
||||
if (newX != qRound(_iconState.x.current())) {
|
||||
_iconState.x = anim::value(newX, newX);
|
||||
_iconState.animationStart = 0;
|
||||
_iconsAnimation.stop();
|
||||
state.max);
|
||||
if (newX != qRound(state.x.current())) {
|
||||
state.x = anim::value(newX, newX);
|
||||
state.animationStart = 0;
|
||||
animation.stop();
|
||||
update();
|
||||
}
|
||||
_iconsDragging = false;
|
||||
state.dragging = false;
|
||||
updateSelected();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool StickersListFooter::eventHook(QEvent *e) {
|
||||
|
|
|
@ -145,6 +145,8 @@ private:
|
|||
struct ScrollState {
|
||||
int selected = 0;
|
||||
int max = 0;
|
||||
int draggingStartX = 0;
|
||||
bool dragging = false;
|
||||
anim::value x;
|
||||
anim::value selectionX;
|
||||
anim::value selectionWidth;
|
||||
|
@ -174,7 +176,11 @@ private:
|
|||
void updateSelected();
|
||||
void updateSetIcon(uint64 setId);
|
||||
void updateSetIconAt(int left);
|
||||
void finishDragging();
|
||||
void checkDragging(ScrollState &state, Ui::Animations::Basic &animation);
|
||||
bool finishDragging(
|
||||
ScrollState &state,
|
||||
Ui::Animations::Basic &animation);
|
||||
bool finishDragging();
|
||||
void paintStickerSettingsIcon(Painter &p) const;
|
||||
void paintSearchIcon(Painter &p) const;
|
||||
void paintSetIcon(
|
||||
|
@ -216,9 +222,6 @@ private:
|
|||
int _iconsRight = 0;
|
||||
int _iconsTop = 0;
|
||||
|
||||
int _iconsStartX = 0;
|
||||
bool _iconsDragging = false;
|
||||
|
||||
ScrollState _iconState;
|
||||
Ui::Animations::Basic _iconsAnimation;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue