Added support of drag events to filters menu.

This commit is contained in:
23rd 2022-12-06 03:25:59 +03:00
parent 0310d9902c
commit 1b364f2621
2 changed files with 39 additions and 10 deletions

View File

@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_premium_limits.h"
#include "lang/lang_keys.h"
#include "ui/filter_icons.h"
#include "ui/wrap/vertical_layout.h"
#include "ui/wrap/vertical_layout_reorder.h"
#include "ui/widgets/popup_menu.h"
#include "ui/boxes/confirm_box.h"
@ -28,6 +29,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/premium_limits_box.h"
#include "settings/settings_common.h"
#include "settings/settings_folders.h"
#include "storage/storage_media_prepare.h"
#include "api/api_chat_filters.h"
#include "apiwrap.h"
#include "styles/style_widgets.h"
@ -77,6 +79,11 @@ FiltersMenu::FiltersMenu(
, _container(
_scroll.setOwnedWidget(
object_ptr<Ui::VerticalLayout>(&_scroll))) {
_drag.timer.setCallback([=] {
if (_drag.filterId >= 0) {
_session->setActiveChatsFilter(_drag.filterId);
}
});
setup();
}
@ -324,15 +331,36 @@ base::unique_qptr<Ui::SideBarButton> FiltersMenu::prepareButton(
}
}
});
if (id > 0) {
if (id >= 0) {
raw->setAcceptDrops(true);
raw->events(
) | rpl::filter([](not_null<QEvent*> e) {
return e->type() == QEvent::ContextMenu;
}) | rpl::start_with_next([=] {
) | rpl::filter([=](not_null<QEvent*> e) {
return ((e->type() == QEvent::ContextMenu) && (id > 0))
|| e->type() == QEvent::DragEnter
|| e->type() == QEvent::DragMove
|| e->type() == QEvent::DragLeave;
}) | rpl::start_with_next([=](not_null<QEvent*> e) {
if (raw->locked()) {
return;
}
showMenu(QCursor::pos(), id);
if (e->type() == QEvent::ContextMenu) {
showMenu(QCursor::pos(), id);
} else if (e->type() == QEvent::DragEnter) {
using namespace Storage;
const auto d = static_cast<QDragEnterEvent*>(e.get());
const auto data = d->mimeData();
if (ComputeMimeDataState(data) != MimeDataState::None) {
_drag.timer.callOnce(ChoosePeerByDragTimeout);
_drag.filterId = id;
d->setDropAction(Qt::CopyAction);
d->accept();
}
} else if (e->type() == QEvent::DragMove) {
_drag.timer.callOnce(ChoosePeerByDragTimeout);
} else if (e->type() == QEvent::DragLeave) {
_drag.filterId = FilterId(-1);
_drag.timer.cancel();
}
}, raw->lifetime());
}
return button;

View File

@ -7,21 +7,18 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "base/timer.h"
#include "ui/effects/animations.h"
#include "ui/widgets/side_bar_button.h"
#include "ui/widgets/scroll_area.h"
#include "ui/wrap/vertical_layout.h"
namespace Ui {
class VerticalLayout;
class VerticalLayoutReorder;
enum class FilterIcon : uchar;
class PopupMenu;
} // namespace Ui
namespace Data {
class ChatFilter;
} // namespace Data
namespace Window {
class SessionController;
@ -72,6 +69,10 @@ private:
bool _waitingSuggested = false;
base::unique_qptr<Ui::PopupMenu> _popupMenu;
struct {
base::Timer timer;
FilterId filterId = FilterId(-1);
} _drag;
Ui::Animations::Simple _scrollToAnimation;