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
|
|
|
#include "ui/widgets/popup_menu.h"
|
|
|
|
|
2016-11-09 13:40:51 +00:00
|
|
|
#include "ui/widgets/shadow.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "platform/platform_specific.h"
|
2016-10-26 16:43:13 +00:00
|
|
|
#include "application.h"
|
2017-02-25 18:17:50 +00:00
|
|
|
#include "mainwindow.h"
|
2017-11-24 16:06:35 +00:00
|
|
|
#include "messenger.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2016-10-26 16:43:13 +00:00
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
|
2017-01-11 05:30:51 +00:00
|
|
|
PopupMenu::PopupMenu(QWidget*, const style::PopupMenu &st) : TWidget(nullptr)
|
2016-10-26 16:43:13 +00:00
|
|
|
, _st(st)
|
2016-11-09 13:40:51 +00:00
|
|
|
, _menu(this, _st.menu) {
|
2016-10-26 16:43:13 +00:00
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
2017-01-11 05:30:51 +00:00
|
|
|
PopupMenu::PopupMenu(QWidget*, QMenu *menu, const style::PopupMenu &st) : TWidget(nullptr)
|
2016-10-26 16:43:13 +00:00
|
|
|
, _st(st)
|
2016-11-09 13:40:51 +00:00
|
|
|
, _menu(this, menu, _st.menu) {
|
2016-10-26 16:43:13 +00:00
|
|
|
init();
|
|
|
|
|
|
|
|
for (auto action : actions()) {
|
|
|
|
if (auto submenu = action->menu()) {
|
2017-02-09 14:20:49 +00:00
|
|
|
auto it = _submenus.insert(action, new PopupMenu(nullptr, submenu, st));
|
2016-10-26 16:43:13 +00:00
|
|
|
it.value()->deleteOnHide(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupMenu::init() {
|
2017-11-24 16:06:35 +00:00
|
|
|
subscribe(Messenger::Instance().passcodedChanged(), [this] {
|
|
|
|
if (App::passcoded()) {
|
|
|
|
hideMenu(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
_menu->setResizedCallback([this] { handleMenuResize(); });
|
|
|
|
_menu->setActivatedCallback([this](QAction *action, int actionTop, TriggeredSource source) {
|
|
|
|
handleActivated(action, actionTop, source);
|
|
|
|
});
|
|
|
|
_menu->setTriggeredCallback([this](QAction *action, int actionTop, TriggeredSource source) {
|
|
|
|
handleTriggered(action, actionTop, source);
|
|
|
|
});
|
|
|
|
_menu->setKeyPressDelegate([this](int key) { return handleKeyPress(key); });
|
|
|
|
_menu->setMouseMoveDelegate([this](QPoint globalPosition) { handleMouseMove(globalPosition); });
|
|
|
|
_menu->setMousePressDelegate([this](QPoint globalPosition) { handleMousePress(globalPosition); });
|
2016-11-16 16:04:25 +00:00
|
|
|
_menu->setMouseReleaseDelegate([this](QPoint globalPosition) { handleMouseRelease(globalPosition); });
|
2016-10-26 16:43:13 +00:00
|
|
|
|
2016-11-09 13:40:51 +00:00
|
|
|
handleCompositingUpdate();
|
2016-10-26 16:43:13 +00:00
|
|
|
|
|
|
|
setWindowFlags(Qt::WindowFlags(Qt::FramelessWindowHint) | Qt::BypassWindowManagerHint | Qt::Popup | Qt::NoDropShadowWindowHint);
|
|
|
|
setMouseTracking(true);
|
|
|
|
|
|
|
|
hide();
|
|
|
|
|
|
|
|
setAttribute(Qt::WA_NoSystemBackground, true);
|
|
|
|
setAttribute(Qt::WA_TranslucentBackground, true);
|
|
|
|
}
|
|
|
|
|
2016-11-09 13:40:51 +00:00
|
|
|
void PopupMenu::handleCompositingUpdate() {
|
2016-11-11 08:59:55 +00:00
|
|
|
_padding = _useTransparency ? _st.shadow.extend : style::margins(st::lineWidth, st::lineWidth, st::lineWidth, st::lineWidth);
|
2016-11-09 13:40:51 +00:00
|
|
|
_menu->moveToLeft(_padding.left() + _st.scrollPadding.left(), _padding.top() + _st.scrollPadding.top());
|
|
|
|
handleMenuResize();
|
|
|
|
}
|
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
void PopupMenu::handleMenuResize() {
|
2016-11-09 13:40:51 +00:00
|
|
|
auto newWidth = _padding.left() + _st.scrollPadding.left() + _menu->width() + _st.scrollPadding.right() + _padding.right();
|
|
|
|
auto newHeight = _padding.top() + _st.scrollPadding.top() + _menu->height() + _st.scrollPadding.bottom() + _padding.bottom();
|
|
|
|
resize(newWidth, newHeight);
|
|
|
|
_inner = rect().marginsRemoved(_padding);
|
2016-10-26 16:43:13 +00:00
|
|
|
}
|
|
|
|
|
2016-11-01 12:46:34 +00:00
|
|
|
QAction *PopupMenu::addAction(const QString &text, const QObject *receiver, const char* member, const style::icon *icon, const style::icon *iconOver) {
|
|
|
|
return _menu->addAction(text, receiver, member, icon, iconOver);
|
2016-10-26 16:43:13 +00:00
|
|
|
}
|
|
|
|
|
2017-02-26 11:32:13 +00:00
|
|
|
QAction *PopupMenu::addAction(const QString &text, base::lambda<void()> callback, const style::icon *icon, const style::icon *iconOver) {
|
2017-02-21 13:45:56 +00:00
|
|
|
return _menu->addAction(text, std::move(callback), icon, iconOver);
|
2016-11-04 11:14:47 +00:00
|
|
|
}
|
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
QAction *PopupMenu::addSeparator() {
|
|
|
|
return _menu->addSeparator();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupMenu::clearActions() {
|
|
|
|
for (auto submenu : base::take(_submenus)) {
|
|
|
|
delete submenu;
|
|
|
|
}
|
|
|
|
return _menu->clearActions();
|
|
|
|
}
|
|
|
|
|
|
|
|
PopupMenu::Actions &PopupMenu::actions() {
|
|
|
|
return _menu->actions();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupMenu::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
2017-05-02 09:08:08 +00:00
|
|
|
if (_useTransparency) {
|
|
|
|
Platform::StartTranslucentPaint(p, e);
|
|
|
|
}
|
2017-01-15 13:12:35 +00:00
|
|
|
|
2016-11-09 13:40:51 +00:00
|
|
|
auto ms = getms();
|
|
|
|
if (_a_show.animating(ms)) {
|
|
|
|
if (auto opacity = _a_opacity.current(ms, _hiding ? 0. : 1.)) {
|
2016-11-12 15:02:19 +00:00
|
|
|
_showAnimation->paintFrame(p, 0, 0, width(), _a_show.current(1.), opacity);
|
2016-11-09 13:40:51 +00:00
|
|
|
}
|
|
|
|
} else if (_a_opacity.animating(ms)) {
|
|
|
|
p.setOpacity(_a_opacity.current(0.));
|
2016-10-26 16:43:13 +00:00
|
|
|
p.drawPixmap(0, 0, _cache);
|
2016-11-09 13:40:51 +00:00
|
|
|
} else if (_hiding || isHidden()) {
|
|
|
|
hideFinished();
|
|
|
|
} else if (_showAnimation) {
|
2016-11-12 15:02:19 +00:00
|
|
|
_showAnimation->paintFrame(p, 0, 0, width(), 1., 1.);
|
2016-11-09 13:40:51 +00:00
|
|
|
_showAnimation.reset();
|
|
|
|
showChildren();
|
|
|
|
} else {
|
|
|
|
paintBg(p);
|
2016-10-26 16:43:13 +00:00
|
|
|
}
|
2016-11-09 13:40:51 +00:00
|
|
|
}
|
2016-10-26 16:43:13 +00:00
|
|
|
|
2016-11-09 13:40:51 +00:00
|
|
|
void PopupMenu::paintBg(Painter &p) {
|
2016-11-11 08:59:55 +00:00
|
|
|
if (_useTransparency) {
|
2016-11-09 13:40:51 +00:00
|
|
|
Shadow::paint(p, _inner, width(), _st.shadow);
|
|
|
|
App::roundRect(p, _inner, _st.menu.itemBg, ImageRoundRadius::Small);
|
|
|
|
} else {
|
|
|
|
p.fillRect(0, 0, width() - _padding.right(), _padding.top(), _st.shadow.fallback);
|
|
|
|
p.fillRect(width() - _padding.right(), 0, _padding.right(), height() - _padding.bottom(), _st.shadow.fallback);
|
|
|
|
p.fillRect(_padding.left(), height() - _padding.bottom(), width() - _padding.left(), _padding.bottom(), _st.shadow.fallback);
|
|
|
|
p.fillRect(0, _padding.top(), _padding.left(), height() - _padding.top(), _st.shadow.fallback);
|
|
|
|
p.fillRect(_inner, _st.menu.itemBg);
|
|
|
|
}
|
2016-10-26 16:43:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PopupMenu::handleActivated(QAction *action, int actionTop, TriggeredSource source) {
|
|
|
|
if (source == TriggeredSource::Mouse) {
|
|
|
|
if (!popupSubmenuFromAction(action, actionTop, source)) {
|
|
|
|
if (auto currentSubmenu = base::take(_activeSubmenu)) {
|
|
|
|
currentSubmenu->hideMenu(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupMenu::handleTriggered(QAction *action, int actionTop, TriggeredSource source) {
|
|
|
|
if (!popupSubmenuFromAction(action, actionTop, source)) {
|
|
|
|
_triggering = true;
|
2017-01-02 17:11:49 +00:00
|
|
|
hideMenu();
|
2016-10-26 16:43:13 +00:00
|
|
|
emit action->trigger();
|
|
|
|
_triggering = false;
|
|
|
|
if (_deleteLater) {
|
|
|
|
_deleteLater = false;
|
|
|
|
deleteLater();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PopupMenu::popupSubmenuFromAction(QAction *action, int actionTop, TriggeredSource source) {
|
|
|
|
if (auto submenu = _submenus.value(action)) {
|
|
|
|
if (_activeSubmenu == submenu) {
|
|
|
|
submenu->hideMenu(true);
|
|
|
|
} else {
|
|
|
|
popupSubmenu(submenu, actionTop, source);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupMenu::popupSubmenu(SubmenuPointer submenu, int actionTop, TriggeredSource source) {
|
|
|
|
if (auto currentSubmenu = base::take(_activeSubmenu)) {
|
|
|
|
currentSubmenu->hideMenu(true);
|
|
|
|
}
|
|
|
|
if (submenu) {
|
|
|
|
QPoint p(_inner.x() + (rtl() ? _padding.right() : _inner.width() - _padding.left()), _inner.y() + actionTop);
|
|
|
|
_activeSubmenu = submenu;
|
|
|
|
_activeSubmenu->showMenu(geometry().topLeft() + p, this, source);
|
|
|
|
|
|
|
|
_menu->setChildShown(true);
|
|
|
|
} else {
|
|
|
|
_menu->setChildShown(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupMenu::forwardKeyPress(int key) {
|
|
|
|
if (!handleKeyPress(key)) {
|
|
|
|
_menu->handleKeyPress(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PopupMenu::handleKeyPress(int key) {
|
|
|
|
if (_activeSubmenu) {
|
|
|
|
_activeSubmenu->handleKeyPress(key);
|
|
|
|
return true;
|
|
|
|
} else if (key == Qt::Key_Escape) {
|
|
|
|
hideMenu(_parent ? true : false);
|
|
|
|
return true;
|
|
|
|
} else if (key == (rtl() ? Qt::Key_Right : Qt::Key_Left)) {
|
|
|
|
if (_parent) {
|
|
|
|
hideMenu(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupMenu::handleMouseMove(QPoint globalPosition) {
|
|
|
|
if (_parent) {
|
|
|
|
_parent->forwardMouseMove(globalPosition);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupMenu::handleMousePress(QPoint globalPosition) {
|
|
|
|
if (_parent) {
|
|
|
|
_parent->forwardMousePress(globalPosition);
|
|
|
|
} else {
|
|
|
|
hideMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-16 16:04:25 +00:00
|
|
|
void PopupMenu::handleMouseRelease(QPoint globalPosition) {
|
|
|
|
if (_parent) {
|
|
|
|
_parent->forwardMouseRelease(globalPosition);
|
|
|
|
} else {
|
|
|
|
hideMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
void PopupMenu::focusOutEvent(QFocusEvent *e) {
|
|
|
|
hideMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupMenu::hideEvent(QHideEvent *e) {
|
|
|
|
if (_deleteOnHide) {
|
|
|
|
if (_triggering) {
|
|
|
|
_deleteLater = true;
|
|
|
|
} else {
|
|
|
|
deleteLater();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupMenu::hideMenu(bool fast) {
|
|
|
|
if (isHidden()) return;
|
2016-11-09 13:40:51 +00:00
|
|
|
if (_parent && !_a_opacity.animating()) {
|
2016-10-26 16:43:13 +00:00
|
|
|
_parent->childHiding(this);
|
|
|
|
}
|
|
|
|
if (fast) {
|
2016-11-09 13:40:51 +00:00
|
|
|
hideFast();
|
2016-10-26 16:43:13 +00:00
|
|
|
} else {
|
2016-11-09 13:40:51 +00:00
|
|
|
hideAnimated();
|
2016-10-26 16:43:13 +00:00
|
|
|
if (_parent) {
|
|
|
|
_parent->hideMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_activeSubmenu) {
|
|
|
|
_activeSubmenu->hideMenu(fast);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupMenu::childHiding(PopupMenu *child) {
|
|
|
|
if (_activeSubmenu && _activeSubmenu == child) {
|
|
|
|
_activeSubmenu = SubmenuPointer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-09 13:40:51 +00:00
|
|
|
void PopupMenu::setOrigin(PanelAnimation::Origin origin) {
|
|
|
|
_origin = origin;
|
2016-10-26 16:43:13 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 13:40:51 +00:00
|
|
|
void PopupMenu::showAnimated(PanelAnimation::Origin origin) {
|
|
|
|
setOrigin(origin);
|
|
|
|
showStarted();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupMenu::hideAnimated() {
|
|
|
|
if (isHidden()) return;
|
|
|
|
if (_hiding) return;
|
|
|
|
|
|
|
|
startOpacityAnimation(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupMenu::hideFast() {
|
|
|
|
if (isHidden()) return;
|
|
|
|
|
|
|
|
_hiding = false;
|
|
|
|
_a_opacity.finish();
|
|
|
|
hideFinished();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupMenu::hideFinished() {
|
|
|
|
_a_show.finish();
|
|
|
|
_cache = QPixmap();
|
|
|
|
if (!isHidden()) {
|
|
|
|
hide();
|
2016-10-26 16:43:13 +00:00
|
|
|
}
|
2016-11-09 13:40:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PopupMenu::prepareCache() {
|
|
|
|
if (_a_opacity.animating()) return;
|
|
|
|
|
|
|
|
auto showAnimation = base::take(_a_show);
|
|
|
|
auto showAnimationData = base::take(_showAnimation);
|
|
|
|
showChildren();
|
2017-12-26 12:41:48 +00:00
|
|
|
_cache = GrabWidget(this);
|
2016-11-09 13:40:51 +00:00
|
|
|
_showAnimation = base::take(showAnimationData);
|
|
|
|
_a_show = base::take(showAnimation);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupMenu::startOpacityAnimation(bool hiding) {
|
|
|
|
_hiding = false;
|
2016-11-11 08:59:55 +00:00
|
|
|
if (!_useTransparency) {
|
2016-11-09 13:40:51 +00:00
|
|
|
_a_opacity.finish();
|
|
|
|
if (hiding) {
|
|
|
|
hideFinished();
|
|
|
|
} else {
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
prepareCache();
|
|
|
|
_hiding = hiding;
|
|
|
|
hideChildren();
|
|
|
|
_a_opacity.start([this] { opacityAnimationCallback(); }, _hiding ? 1. : 0., _hiding ? 0. : 1., _st.duration);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupMenu::showStarted() {
|
|
|
|
if (isHidden()) {
|
|
|
|
show();
|
|
|
|
startShowAnimation();
|
|
|
|
return;
|
|
|
|
} else if (!_hiding) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
startOpacityAnimation(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupMenu::startShowAnimation() {
|
2016-11-11 08:59:55 +00:00
|
|
|
if (!_useTransparency) {
|
2016-11-09 13:40:51 +00:00
|
|
|
_a_show.finish();
|
|
|
|
update();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!_a_show.animating()) {
|
|
|
|
auto opacityAnimation = base::take(_a_opacity);
|
|
|
|
showChildren();
|
|
|
|
auto cache = grabForPanelAnimation();
|
|
|
|
_a_opacity = base::take(opacityAnimation);
|
|
|
|
|
2017-02-21 13:45:56 +00:00
|
|
|
_showAnimation = std::make_unique<PanelAnimation>(_st.animation, _origin);
|
|
|
|
_showAnimation->setFinalImage(std::move(cache), QRect(_inner.topLeft() * cIntRetinaFactor(), _inner.size() * cIntRetinaFactor()));
|
2016-11-11 08:59:55 +00:00
|
|
|
if (_useTransparency) {
|
2016-11-09 13:40:51 +00:00
|
|
|
auto corners = App::cornersMask(ImageRoundRadius::Small);
|
2017-07-13 14:42:46 +00:00
|
|
|
_showAnimation->setCornerMasks(corners[0], corners[1], corners[2], corners[3]);
|
2016-11-09 13:40:51 +00:00
|
|
|
} else {
|
|
|
|
_showAnimation->setSkipShadow(true);
|
|
|
|
}
|
|
|
|
_showAnimation->start();
|
|
|
|
}
|
|
|
|
hideChildren();
|
|
|
|
_a_show.start([this] { showAnimationCallback(); }, 0., 1., _st.showDuration);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupMenu::opacityAnimationCallback() {
|
|
|
|
update();
|
2016-11-10 18:10:31 +00:00
|
|
|
if (!_a_opacity.animating()) {
|
|
|
|
if (_hiding) {
|
|
|
|
_hiding = false;
|
|
|
|
hideFinished();
|
|
|
|
} else {
|
|
|
|
showChildren();
|
|
|
|
}
|
2016-11-09 13:40:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupMenu::showAnimationCallback() {
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage PopupMenu::grabForPanelAnimation() {
|
2017-12-26 12:41:48 +00:00
|
|
|
SendPendingMoveResizeEvents(this);
|
2016-11-09 13:40:51 +00:00
|
|
|
auto result = QImage(size() * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
result.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
result.fill(Qt::transparent);
|
|
|
|
{
|
|
|
|
Painter p(&result);
|
2016-11-11 08:59:55 +00:00
|
|
|
if (_useTransparency) {
|
2016-11-09 13:40:51 +00:00
|
|
|
App::roundRect(p, _inner, _st.menu.itemBg, ImageRoundRadius::Small);
|
|
|
|
} else {
|
|
|
|
p.fillRect(_inner, _st.menu.itemBg);
|
|
|
|
}
|
|
|
|
for (auto child : children()) {
|
|
|
|
if (auto widget = qobject_cast<QWidget*>(child)) {
|
|
|
|
widget->render(&p, widget->pos(), widget->rect(), QWidget::DrawChildren | QWidget::IgnoreMask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-21 14:37:53 +00:00
|
|
|
return result;
|
2016-10-26 16:43:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PopupMenu::deleteOnHide(bool del) {
|
|
|
|
_deleteOnHide = del;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupMenu::popup(const QPoint &p) {
|
|
|
|
showMenu(p, nullptr, TriggeredSource::Mouse);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupMenu::showMenu(const QPoint &p, PopupMenu *parent, TriggeredSource source) {
|
|
|
|
_parent = parent;
|
|
|
|
|
2016-11-09 13:40:51 +00:00
|
|
|
auto origin = PanelAnimation::Origin::TopLeft;
|
|
|
|
auto w = p - QPoint(0, _padding.top());
|
|
|
|
auto r = Sandbox::screenGeometry(p);
|
2017-05-02 09:08:08 +00:00
|
|
|
_useTransparency = Platform::TranslucentWindowsSupported(p);
|
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent, !_useTransparency);
|
2016-11-09 13:40:51 +00:00
|
|
|
handleCompositingUpdate();
|
2016-10-26 16:43:13 +00:00
|
|
|
if (rtl()) {
|
|
|
|
if (w.x() - width() < r.x() - _padding.left()) {
|
|
|
|
if (_parent && w.x() + _parent->width() - _padding.left() - _padding.right() + width() - _padding.right() <= r.x() + r.width()) {
|
|
|
|
w.setX(w.x() + _parent->width() - _padding.left() - _padding.right());
|
|
|
|
} else {
|
|
|
|
w.setX(r.x() - _padding.left());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
w.setX(w.x() - width());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (w.x() + width() - _padding.right() > r.x() + r.width()) {
|
|
|
|
if (_parent && w.x() - _parent->width() + _padding.left() + _padding.right() - width() + _padding.right() >= r.x() - _padding.left()) {
|
|
|
|
w.setX(w.x() + _padding.left() + _padding.right() - _parent->width() - width() + _padding.left() + _padding.right());
|
|
|
|
} else {
|
2016-11-09 13:40:51 +00:00
|
|
|
w.setX(p.x() - width() + _padding.right());
|
2016-10-26 16:43:13 +00:00
|
|
|
}
|
2016-11-09 13:40:51 +00:00
|
|
|
origin = PanelAnimation::Origin::TopRight;
|
2016-10-26 16:43:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (w.y() + height() - _padding.bottom() > r.y() + r.height()) {
|
|
|
|
if (_parent) {
|
|
|
|
w.setY(r.y() + r.height() - height() + _padding.bottom());
|
|
|
|
} else {
|
|
|
|
w.setY(p.y() - height() + _padding.bottom());
|
2016-11-09 13:40:51 +00:00
|
|
|
origin = (origin == PanelAnimation::Origin::TopRight) ? PanelAnimation::Origin::BottomRight : PanelAnimation::Origin::BottomLeft;
|
2016-10-26 16:43:13 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-09 13:40:51 +00:00
|
|
|
if (w.x() < r.x()) {
|
|
|
|
w.setX(r.x());
|
|
|
|
}
|
2016-10-26 16:43:13 +00:00
|
|
|
if (w.y() < r.y()) {
|
|
|
|
w.setY(r.y());
|
|
|
|
}
|
|
|
|
move(w);
|
|
|
|
|
2016-11-09 13:40:51 +00:00
|
|
|
setOrigin(origin);
|
2016-10-26 16:43:13 +00:00
|
|
|
_menu->setShowSource(source);
|
|
|
|
|
2016-11-10 19:03:56 +00:00
|
|
|
startShowAnimation();
|
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
psUpdateOverlayed(this);
|
|
|
|
show();
|
|
|
|
psShowOverAll(this);
|
|
|
|
windowHandle()->requestActivate();
|
|
|
|
activateWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
PopupMenu::~PopupMenu() {
|
|
|
|
for (auto submenu : base::take(_submenus)) {
|
|
|
|
delete submenu;
|
|
|
|
}
|
|
|
|
if (auto w = App::wnd()) {
|
2017-01-01 17:49:44 +00:00
|
|
|
w->reActivateWindow();
|
2016-10-26 16:43:13 +00:00
|
|
|
}
|
2017-01-11 05:30:51 +00:00
|
|
|
if (_destroyedCallback) {
|
|
|
|
_destroyedCallback();
|
|
|
|
}
|
2016-10-26 16:43:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Ui
|