mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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 {
|
} else {
|
||||||
_pressed = _selected;
|
_pressed = _selected;
|
||||||
_iconsMouseDown = _iconsMousePos;
|
_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();
|
_iconsMousePos = e ? e->globalPos() : QCursor::pos();
|
||||||
updateSelected();
|
updateSelected();
|
||||||
|
|
||||||
if (!_iconsDragging
|
if (!_iconState.dragging
|
||||||
&& !_icons.empty()
|
&& !_icons.empty()
|
||||||
&& v::is<IconId>(_pressed)) {
|
&& v::is<IconId>(_pressed)) {
|
||||||
if ((_iconsMousePos - _iconsMouseDown).manhattanLength() >= QApplication::startDragDistance()) {
|
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) {
|
checkDragging(_iconState, _iconsAnimation);
|
||||||
auto newX = std::clamp(
|
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())
|
(rtl() ? -1 : 1) * (_iconsMouseDown.x() - _iconsMousePos.x())
|
||||||
+ _iconsStartX,
|
+ state.draggingStartX,
|
||||||
0,
|
0,
|
||||||
_iconState.max);
|
state.max);
|
||||||
if (newX != qRound(_iconState.x.current())) {
|
if (newX != qRound(state.x.current())) {
|
||||||
_iconState.x = anim::value(newX, newX);
|
state.x = anim::value(newX, newX);
|
||||||
_iconState.animationStart = 0;
|
state.animationStart = 0;
|
||||||
_iconsAnimation.stop();
|
animation.stop();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -687,8 +698,7 @@ void StickersListFooter::mouseReleaseEvent(QMouseEvent *e) {
|
||||||
const auto wasDown = std::exchange(_pressed, SpecialOver::None);
|
const auto wasDown = std::exchange(_pressed, SpecialOver::None);
|
||||||
|
|
||||||
_iconsMousePos = e ? e->globalPos() : QCursor::pos();
|
_iconsMousePos = e ? e->globalPos() : QCursor::pos();
|
||||||
if (_iconsDragging) {
|
if (finishDragging()) {
|
||||||
finishDragging();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -714,19 +724,31 @@ void StickersListFooter::mouseReleaseEvent(QMouseEvent *e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StickersListFooter::finishDragging() {
|
bool StickersListFooter::finishDragging() {
|
||||||
auto newX = std::clamp(
|
const auto icon = finishDragging(_iconState, _iconsAnimation);
|
||||||
_iconsStartX + _iconsMouseDown.x() - _iconsMousePos.x(),
|
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,
|
0,
|
||||||
_iconState.max);
|
state.max);
|
||||||
if (newX != qRound(_iconState.x.current())) {
|
if (newX != qRound(state.x.current())) {
|
||||||
_iconState.x = anim::value(newX, newX);
|
state.x = anim::value(newX, newX);
|
||||||
_iconState.animationStart = 0;
|
state.animationStart = 0;
|
||||||
_iconsAnimation.stop();
|
animation.stop();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
_iconsDragging = false;
|
state.dragging = false;
|
||||||
updateSelected();
|
updateSelected();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StickersListFooter::eventHook(QEvent *e) {
|
bool StickersListFooter::eventHook(QEvent *e) {
|
||||||
|
|
|
@ -145,6 +145,8 @@ private:
|
||||||
struct ScrollState {
|
struct ScrollState {
|
||||||
int selected = 0;
|
int selected = 0;
|
||||||
int max = 0;
|
int max = 0;
|
||||||
|
int draggingStartX = 0;
|
||||||
|
bool dragging = false;
|
||||||
anim::value x;
|
anim::value x;
|
||||||
anim::value selectionX;
|
anim::value selectionX;
|
||||||
anim::value selectionWidth;
|
anim::value selectionWidth;
|
||||||
|
@ -174,7 +176,11 @@ private:
|
||||||
void updateSelected();
|
void updateSelected();
|
||||||
void updateSetIcon(uint64 setId);
|
void updateSetIcon(uint64 setId);
|
||||||
void updateSetIconAt(int left);
|
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 paintStickerSettingsIcon(Painter &p) const;
|
||||||
void paintSearchIcon(Painter &p) const;
|
void paintSearchIcon(Painter &p) const;
|
||||||
void paintSetIcon(
|
void paintSetIcon(
|
||||||
|
@ -216,9 +222,6 @@ private:
|
||||||
int _iconsRight = 0;
|
int _iconsRight = 0;
|
||||||
int _iconsTop = 0;
|
int _iconsTop = 0;
|
||||||
|
|
||||||
int _iconsStartX = 0;
|
|
||||||
bool _iconsDragging = false;
|
|
||||||
|
|
||||||
ScrollState _iconState;
|
ScrollState _iconState;
|
||||||
Ui::Animations::Basic _iconsAnimation;
|
Ui::Animations::Basic _iconsAnimation;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue