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.
|
2016-10-26 16:43:13 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
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"
|
2018-06-03 13:30:40 +00:00
|
|
|
#include "ui/rp_widget.h"
|
2016-10-26 16:43:13 +00:00
|
|
|
#include "ui/widgets/menu.h"
|
2016-11-09 13:40:51 +00:00
|
|
|
#include "ui/effects/panel_animation.h"
|
2016-10-26 16:43:13 +00:00
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
|
2018-06-03 13:30:40 +00:00
|
|
|
class PopupMenu : public Ui::RpWidget, private base::Subscriber {
|
2016-10-26 16:43:13 +00:00
|
|
|
public:
|
2017-01-11 05:30:51 +00:00
|
|
|
PopupMenu(QWidget*, const style::PopupMenu &st = st::defaultPopupMenu);
|
|
|
|
PopupMenu(QWidget*, QMenu *menu, const style::PopupMenu &st = st::defaultPopupMenu);
|
2016-10-26 16:43:13 +00:00
|
|
|
|
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();
|
|
|
|
|
|
|
|
using Actions = Ui::Menu::Actions;
|
|
|
|
Actions &actions();
|
|
|
|
|
|
|
|
void deleteOnHide(bool del);
|
|
|
|
void popup(const QPoint &p);
|
|
|
|
void hideMenu(bool fast = false);
|
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
void setDestroyedCallback(Fn<void()> callback) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_destroyedCallback = std::move(callback);
|
2017-01-11 05:30:51 +00:00
|
|
|
}
|
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
~PopupMenu();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
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:
|
2016-11-09 13:40:51 +00:00
|
|
|
void paintBg(Painter &p);
|
|
|
|
void hideFast();
|
|
|
|
void setOrigin(PanelAnimation::Origin origin);
|
|
|
|
void showAnimated(PanelAnimation::Origin origin);
|
|
|
|
void hideAnimated();
|
|
|
|
|
|
|
|
QImage grabForPanelAnimation();
|
|
|
|
void startShowAnimation();
|
|
|
|
void startOpacityAnimation(bool hiding);
|
|
|
|
void prepareCache();
|
2016-10-26 16:43:13 +00:00
|
|
|
void childHiding(PopupMenu *child);
|
|
|
|
|
2016-11-09 13:40:51 +00:00
|
|
|
void showAnimationCallback();
|
|
|
|
void opacityAnimationCallback();
|
2016-10-26 16:43:13 +00:00
|
|
|
|
|
|
|
void init();
|
2016-11-09 13:40:51 +00:00
|
|
|
|
|
|
|
void hideFinished();
|
|
|
|
void showStarted();
|
2016-10-26 16:43:13 +00:00
|
|
|
|
|
|
|
using TriggeredSource = Ui::Menu::TriggeredSource;
|
2016-11-09 13:40:51 +00:00
|
|
|
void handleCompositingUpdate();
|
2016-10-26 16:43:13 +00:00
|
|
|
void handleMenuResize();
|
|
|
|
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<PopupMenu>;
|
|
|
|
bool popupSubmenuFromAction(QAction *action, int actionTop, TriggeredSource source);
|
|
|
|
void popupSubmenu(SubmenuPointer submenu, int actionTop, TriggeredSource source);
|
|
|
|
void showMenu(const QPoint &p, PopupMenu *parent, TriggeredSource source);
|
|
|
|
|
|
|
|
const style::PopupMenu &_st;
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<Ui::Menu> _menu;
|
2016-10-26 16:43:13 +00:00
|
|
|
|
|
|
|
using Submenus = QMap<QAction*, SubmenuPointer>;
|
|
|
|
Submenus _submenus;
|
|
|
|
|
|
|
|
PopupMenu *_parent = nullptr;
|
|
|
|
|
|
|
|
QRect _inner;
|
|
|
|
style::margins _padding;
|
|
|
|
|
|
|
|
SubmenuPointer _activeSubmenu;
|
|
|
|
|
2016-11-09 13:40:51 +00:00
|
|
|
PanelAnimation::Origin _origin = PanelAnimation::Origin::TopLeft;
|
2017-02-21 13:45:56 +00:00
|
|
|
std::unique_ptr<PanelAnimation> _showAnimation;
|
2016-12-07 13:32:25 +00:00
|
|
|
Animation _a_show;
|
2016-11-09 13:40:51 +00:00
|
|
|
|
2016-11-11 08:59:55 +00:00
|
|
|
bool _useTransparency = true;
|
2016-11-09 13:40:51 +00:00
|
|
|
bool _hiding = false;
|
2016-10-26 16:43:13 +00:00
|
|
|
QPixmap _cache;
|
2016-12-07 13:32:25 +00:00
|
|
|
Animation _a_opacity;
|
2016-10-26 16:43:13 +00:00
|
|
|
|
|
|
|
bool _deleteOnHide = true;
|
|
|
|
bool _triggering = false;
|
|
|
|
bool _deleteLater = false;
|
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void()> _destroyedCallback;
|
2017-01-11 05:30:51 +00:00
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Ui
|