2016-10-26 16:43:13 +00:00
|
|
|
/*
|
2018-01-03 10:23:14 +00:00
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
2016-10-26 16:43:13 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "styles/style_widgets.h"
|
|
|
|
#include "ui/widgets/inner_dropdown.h"
|
|
|
|
#include "ui/widgets/menu.h"
|
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
|
|
|
|
class DropdownMenu : public InnerDropdown {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
DropdownMenu(QWidget *parent, const style::DropdownMenu &st = st::defaultDropdownMenu);
|
|
|
|
|
2016-11-01 12:46:34 +00:00
|
|
|
QAction *addAction(const QString &text, const QObject *receiver, const char* member, const style::icon *icon = nullptr, const style::icon *iconOver = nullptr);
|
2018-06-04 15:35:11 +00:00
|
|
|
QAction *addAction(const QString &text, Fn<void()> callback, const style::icon *icon = nullptr, const style::icon *iconOver = nullptr);
|
2016-10-26 16:43:13 +00:00
|
|
|
QAction *addSeparator();
|
|
|
|
void clearActions();
|
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
void setHiddenCallback(Fn<void()> callback) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_hiddenCallback = std::move(callback);
|
2016-11-05 08:36:24 +00:00
|
|
|
}
|
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
using Actions = Ui::Menu::Actions;
|
|
|
|
Actions &actions();
|
|
|
|
|
|
|
|
~DropdownMenu();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void focusOutEvent(QFocusEvent *e) override;
|
|
|
|
void hideEvent(QHideEvent *e) override;
|
|
|
|
|
|
|
|
void keyPressEvent(QKeyEvent *e) override {
|
|
|
|
forwardKeyPress(e->key());
|
|
|
|
}
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override {
|
|
|
|
forwardMouseMove(e->globalPos());
|
|
|
|
}
|
|
|
|
void mousePressEvent(QMouseEvent *e) override {
|
|
|
|
forwardMousePress(e->globalPos());
|
|
|
|
}
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void onHidden() {
|
|
|
|
hideFinish();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Not ready with submenus yet.
|
|
|
|
DropdownMenu(QWidget *parent, QMenu *menu, const style::DropdownMenu &st = st::defaultDropdownMenu);
|
|
|
|
void deleteOnHide(bool del);
|
|
|
|
void popup(const QPoint &p);
|
|
|
|
void hideMenu(bool fast = false);
|
|
|
|
|
|
|
|
void childHiding(DropdownMenu *child);
|
|
|
|
|
|
|
|
void init();
|
|
|
|
void hideFinish();
|
|
|
|
|
|
|
|
using TriggeredSource = Ui::Menu::TriggeredSource;
|
|
|
|
void handleActivated(QAction *action, int actionTop, TriggeredSource source);
|
|
|
|
void handleTriggered(QAction *action, int actionTop, TriggeredSource source);
|
|
|
|
void forwardKeyPress(int key);
|
|
|
|
bool handleKeyPress(int key);
|
|
|
|
void forwardMouseMove(QPoint globalPosition) {
|
|
|
|
_menu->handleMouseMove(globalPosition);
|
|
|
|
}
|
|
|
|
void handleMouseMove(QPoint globalPosition);
|
|
|
|
void forwardMousePress(QPoint globalPosition) {
|
|
|
|
_menu->handleMousePress(globalPosition);
|
|
|
|
}
|
|
|
|
void handleMousePress(QPoint globalPosition);
|
2016-11-16 16:04:25 +00:00
|
|
|
void forwardMouseRelease(QPoint globalPosition) {
|
|
|
|
_menu->handleMouseRelease(globalPosition);
|
|
|
|
}
|
|
|
|
void handleMouseRelease(QPoint globalPosition);
|
2016-10-26 16:43:13 +00:00
|
|
|
|
|
|
|
using SubmenuPointer = QPointer<DropdownMenu>;
|
|
|
|
bool popupSubmenuFromAction(QAction *action, int actionTop, TriggeredSource source);
|
|
|
|
void popupSubmenu(SubmenuPointer submenu, int actionTop, TriggeredSource source);
|
|
|
|
void showMenu(const QPoint &p, DropdownMenu *parent, TriggeredSource source);
|
|
|
|
|
|
|
|
const style::DropdownMenu &_st;
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void()> _hiddenCallback;
|
2016-10-26 16:43:13 +00:00
|
|
|
|
2017-05-26 14:36:59 +00:00
|
|
|
QPointer<Ui::Menu> _menu;
|
2016-10-26 16:43:13 +00:00
|
|
|
|
|
|
|
// Not ready with submenus yet.
|
|
|
|
//using Submenus = QMap<QAction*, SubmenuPointer>;
|
|
|
|
//Submenus _submenus;
|
|
|
|
|
|
|
|
DropdownMenu *_parent = nullptr;
|
|
|
|
|
|
|
|
SubmenuPointer _activeSubmenu;
|
|
|
|
|
|
|
|
bool _deleteOnHide = false;
|
|
|
|
bool _triggering = false;
|
|
|
|
bool _deleteLater = false;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Ui
|