Move Ui::Menu::MenuCallback and st::menuWithIcons here.
This commit is contained in:
parent
b802516ca7
commit
6ae122f1b2
9 changed files with 250 additions and 6 deletions
|
|
@ -188,6 +188,10 @@ PRIVATE
|
||||||
ui/widgets/menu/menu.h
|
ui/widgets/menu/menu.h
|
||||||
ui/widgets/menu/menu_action.cpp
|
ui/widgets/menu/menu_action.cpp
|
||||||
ui/widgets/menu/menu_action.h
|
ui/widgets/menu/menu_action.h
|
||||||
|
ui/widgets/menu/menu_add_action_callback.cpp
|
||||||
|
ui/widgets/menu/menu_add_action_callback.h
|
||||||
|
ui/widgets/menu/menu_add_action_callback_factory.cpp
|
||||||
|
ui/widgets/menu/menu_add_action_callback_factory.h
|
||||||
ui/widgets/menu/menu_common.cpp
|
ui/widgets/menu/menu_common.cpp
|
||||||
ui/widgets/menu/menu_common.h
|
ui/widgets/menu/menu_common.h
|
||||||
ui/widgets/menu/menu_item_base.cpp
|
ui/widgets/menu/menu_item_base.cpp
|
||||||
|
|
|
||||||
|
|
@ -170,6 +170,15 @@ separatePanelClose: IconButton(boxTitleClose) {
|
||||||
color: windowBgOver;
|
color: windowBgOver;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
separatePanelMenu: IconButton(separatePanelClose) {
|
||||||
|
width: 44px;
|
||||||
|
|
||||||
|
icon: icon {{ "title_menu_dots", boxTitleCloseFg }};
|
||||||
|
iconOver: icon {{ "title_menu_dots", boxTitleCloseFgOver }};
|
||||||
|
|
||||||
|
rippleAreaPosition: point(0px, 8px);
|
||||||
|
}
|
||||||
|
separatePanelMenuPosition: point(0px, 52px);
|
||||||
separatePanelTitleFont: font(18px semibold);
|
separatePanelTitleFont: font(18px semibold);
|
||||||
separatePanelTitle: FlatLabel(defaultFlatLabel) {
|
separatePanelTitle: FlatLabel(defaultFlatLabel) {
|
||||||
textFg: boxTitleFg;
|
textFg: boxTitleFg;
|
||||||
|
|
|
||||||
29
ui/widgets/menu/menu_add_action_callback.cpp
Normal file
29
ui/widgets/menu/menu_add_action_callback.cpp
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
#include "ui/widgets/menu/menu_add_action_callback.h"
|
||||||
|
|
||||||
|
#include "ui/style/style_core.h"
|
||||||
|
|
||||||
|
namespace Ui::Menu {
|
||||||
|
|
||||||
|
MenuCallback::MenuCallback(MenuCallback::Callback callback)
|
||||||
|
: _callback(std::move(callback)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
QAction *MenuCallback::operator()(Args &&args) const {
|
||||||
|
return _callback(std::move(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
QAction *MenuCallback::operator()(
|
||||||
|
const QString &text,
|
||||||
|
Fn<void()> handler,
|
||||||
|
const style::icon *icon) const {
|
||||||
|
return _callback({ text, std::move(handler), icon, nullptr });
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Ui::Menu
|
||||||
41
ui/widgets/menu/menu_add_action_callback.h
Normal file
41
ui/widgets/menu/menu_add_action_callback.h
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ui/style/style_core.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class PopupMenu;
|
||||||
|
} // namespace Ui
|
||||||
|
|
||||||
|
namespace Ui::Menu {
|
||||||
|
|
||||||
|
struct MenuCallback final {
|
||||||
|
public:
|
||||||
|
struct Args {
|
||||||
|
QString text;
|
||||||
|
Fn<void()> handler;
|
||||||
|
const style::icon *icon;
|
||||||
|
Fn<void(not_null<Ui::PopupMenu*>)> fillSubmenu;
|
||||||
|
bool isSeparator = false;
|
||||||
|
bool isAttention = false;
|
||||||
|
};
|
||||||
|
using Callback = Fn<QAction*(Args&&)>;
|
||||||
|
|
||||||
|
explicit MenuCallback(Callback callback);
|
||||||
|
|
||||||
|
QAction *operator()(Args &&args) const;
|
||||||
|
QAction *operator()(
|
||||||
|
const QString &text,
|
||||||
|
Fn<void()> handler,
|
||||||
|
const style::icon *icon) const;
|
||||||
|
private:
|
||||||
|
Callback _callback;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Ui::Menu
|
||||||
46
ui/widgets/menu/menu_add_action_callback_factory.cpp
Normal file
46
ui/widgets/menu/menu_add_action_callback_factory.cpp
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
#include "ui/widgets/menu/menu_add_action_callback_factory.h"
|
||||||
|
|
||||||
|
#include "ui/widgets/menu/menu_add_action_callback.h"
|
||||||
|
#include "ui/widgets/menu/menu_action.h"
|
||||||
|
#include "ui/widgets/popup_menu.h"
|
||||||
|
#include "styles/style_widgets.h"
|
||||||
|
|
||||||
|
namespace Ui::Menu {
|
||||||
|
|
||||||
|
MenuCallback CreateAddActionCallback(
|
||||||
|
const base::unique_qptr<Ui::PopupMenu> &menu) {
|
||||||
|
return MenuCallback([&](MenuCallback::Args a) {
|
||||||
|
if (a.fillSubmenu) {
|
||||||
|
const auto action = menu->addAction(
|
||||||
|
a.text,
|
||||||
|
std::move(a.handler),
|
||||||
|
a.icon);
|
||||||
|
// Dummy menu.
|
||||||
|
action->setMenu(Ui::CreateChild<QMenu>(menu->menu().get()));
|
||||||
|
a.fillSubmenu(menu->ensureSubmenu(action));
|
||||||
|
return action;
|
||||||
|
} else if (a.isSeparator) {
|
||||||
|
return menu->addSeparator();
|
||||||
|
} else if (a.isAttention) {
|
||||||
|
return menu->addAction(base::make_unique_q<Ui::Menu::Action>(
|
||||||
|
menu,
|
||||||
|
st::menuWithIconsAttention,
|
||||||
|
Ui::Menu::CreateAction(
|
||||||
|
menu->menu().get(),
|
||||||
|
a.text,
|
||||||
|
std::move(a.handler)),
|
||||||
|
a.icon,
|
||||||
|
a.icon));
|
||||||
|
}
|
||||||
|
return menu->addAction(a.text, std::move(a.handler), a.icon);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Ui::Menu
|
||||||
23
ui/widgets/menu/menu_add_action_callback_factory.h
Normal file
23
ui/widgets/menu/menu_add_action_callback_factory.h
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "base/unique_qptr.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class PopupMenu;
|
||||||
|
} // namespace Ui
|
||||||
|
|
||||||
|
namespace Ui::Menu {
|
||||||
|
|
||||||
|
struct MenuCallback;
|
||||||
|
|
||||||
|
[[nodiscard]] MenuCallback CreateAddActionCallback(
|
||||||
|
const base::unique_qptr<Ui::PopupMenu> &menu);
|
||||||
|
|
||||||
|
} // namespace Ui::Menu
|
||||||
|
|
@ -10,16 +10,19 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/widgets/shadow.h"
|
#include "ui/widgets/shadow.h"
|
||||||
#include "ui/widgets/buttons.h"
|
#include "ui/widgets/buttons.h"
|
||||||
#include "ui/widgets/labels.h"
|
#include "ui/widgets/labels.h"
|
||||||
|
#include "ui/widgets/tooltip.h"
|
||||||
|
#include "ui/widgets/popup_menu.h"
|
||||||
|
#include "ui/widgets/menu/menu_add_action_callback.h"
|
||||||
|
#include "ui/widgets/menu/menu_add_action_callback_factory.h"
|
||||||
#include "ui/wrap/padding_wrap.h"
|
#include "ui/wrap/padding_wrap.h"
|
||||||
#include "ui/wrap/fade_wrap.h"
|
#include "ui/wrap/fade_wrap.h"
|
||||||
#include "ui/toasts/common_toasts.h"
|
#include "ui/toasts/common_toasts.h"
|
||||||
#include "ui/widgets/tooltip.h"
|
|
||||||
#include "ui/platform/ui_platform_utility.h"
|
#include "ui/platform/ui_platform_utility.h"
|
||||||
#include "ui/layers/layer_widget.h"
|
#include "ui/layers/layer_widget.h"
|
||||||
|
#include "base/debug_log.h"
|
||||||
#include "styles/style_widgets.h"
|
#include "styles/style_widgets.h"
|
||||||
#include "styles/style_layers.h"
|
#include "styles/style_layers.h"
|
||||||
#include "styles/palette.h"
|
#include "styles/palette.h"
|
||||||
#include "base/debug_log.h"
|
|
||||||
|
|
||||||
#include <QtGui/QWindow>
|
#include <QtGui/QWindow>
|
||||||
#include <QtGui/QScreen>
|
#include <QtGui/QScreen>
|
||||||
|
|
@ -70,7 +73,8 @@ void SeparatePanel::initControls() {
|
||||||
void SeparatePanel::updateTitleGeometry(int newWidth) {
|
void SeparatePanel::updateTitleGeometry(int newWidth) {
|
||||||
_title->resizeToWidth(newWidth
|
_title->resizeToWidth(newWidth
|
||||||
- _padding.left() - _back->width()
|
- _padding.left() - _back->width()
|
||||||
- _padding.right() - _close->width());
|
- _padding.right() - _close->width()
|
||||||
|
- (_menuToggle ? _menuToggle->width() : 0));
|
||||||
updateTitlePosition();
|
updateTitlePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,6 +114,58 @@ void SeparatePanel::setBackAllowed(bool allowed) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SeparatePanel::setMenuAllowed(
|
||||||
|
Fn<void(const Menu::MenuCallback&)> fill) {
|
||||||
|
_menuToggle.create(this, st::separatePanelMenu);
|
||||||
|
_menuToggle->show();
|
||||||
|
_menuToggle->setClickedCallback([=] { showMenu(fill); });
|
||||||
|
|
||||||
|
widthValue(
|
||||||
|
) | rpl::start_with_next([=](int width) {
|
||||||
|
_menuToggle->moveToRight(
|
||||||
|
_padding.right() + _close->width(),
|
||||||
|
_padding.top());
|
||||||
|
}, _menuToggle->lifetime());
|
||||||
|
}
|
||||||
|
|
||||||
|
void SeparatePanel::showMenu(Fn<void(const Menu::MenuCallback&)> fill) {
|
||||||
|
const auto created = createMenu(_menuToggle);
|
||||||
|
if (!created) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fill(Menu::CreateAddActionCallback(_menu));
|
||||||
|
if (_menu->empty()) {
|
||||||
|
_menu = nullptr;
|
||||||
|
} else {
|
||||||
|
_menu->setForcedOrigin(PanelAnimation::Origin::TopRight);
|
||||||
|
_menu->popup(mapToGlobal(QPoint(
|
||||||
|
(width()
|
||||||
|
- _padding.right()
|
||||||
|
- _close->width()
|
||||||
|
+ st::separatePanelMenuPosition.x()),
|
||||||
|
st::separatePanelMenuPosition.y())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SeparatePanel::createMenu(not_null<IconButton*> button) {
|
||||||
|
if (_menu) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_menu = base::make_unique_q<PopupMenu>(this, st::popupMenuWithIcons);
|
||||||
|
_menu->setDestroyedCallback([
|
||||||
|
weak = Ui::MakeWeak(this),
|
||||||
|
weakButton = Ui::MakeWeak(button),
|
||||||
|
menu = _menu.get()]{
|
||||||
|
if (weak && weak->_menu == menu) {
|
||||||
|
if (weakButton) {
|
||||||
|
weakButton->setForceRippled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
button->setForceRippled(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void SeparatePanel::setHideOnDeactivate(bool hideOnDeactivate) {
|
void SeparatePanel::setHideOnDeactivate(bool hideOnDeactivate) {
|
||||||
_hideOnDeactivate = hideOnDeactivate;
|
_hideOnDeactivate = hideOnDeactivate;
|
||||||
if (!_hideOnDeactivate) {
|
if (!_hideOnDeactivate) {
|
||||||
|
|
|
||||||
|
|
@ -14,16 +14,19 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
class Painter;
|
class Painter;
|
||||||
|
|
||||||
|
namespace Ui::Menu {
|
||||||
|
struct MenuCallback;
|
||||||
|
} // namespace Ui::Menu
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
|
||||||
class BoxContent;
|
class BoxContent;
|
||||||
class IconButton;
|
class IconButton;
|
||||||
|
class PopupMenu;
|
||||||
class LayerStackWidget;
|
class LayerStackWidget;
|
||||||
class FlatLabel;
|
class FlatLabel;
|
||||||
template <typename Widget>
|
template <typename Widget>
|
||||||
class FadeWrapScaled;
|
class FadeWrapScaled;
|
||||||
} // namespace Ui
|
|
||||||
|
|
||||||
namespace Ui {
|
|
||||||
|
|
||||||
class SeparatePanel final : public RpWidget {
|
class SeparatePanel final : public RpWidget {
|
||||||
public:
|
public:
|
||||||
|
|
@ -50,6 +53,8 @@ public:
|
||||||
[[nodiscard]] rpl::producer<> closeEvents() const;
|
[[nodiscard]] rpl::producer<> closeEvents() const;
|
||||||
void setBackAllowed(bool allowed);
|
void setBackAllowed(bool allowed);
|
||||||
|
|
||||||
|
void setMenuAllowed(Fn<void(const Menu::MenuCallback&)> fill);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *e) override;
|
void paintEvent(QPaintEvent *e) override;
|
||||||
void closeEvent(QCloseEvent *e) override;
|
void closeEvent(QCloseEvent *e) override;
|
||||||
|
|
@ -83,12 +88,17 @@ private:
|
||||||
void finishAnimating();
|
void finishAnimating();
|
||||||
void finishClose();
|
void finishClose();
|
||||||
|
|
||||||
|
void showMenu(Fn<void(const Menu::MenuCallback&)> fill);
|
||||||
|
[[nodiscard]] bool createMenu(not_null<IconButton*> button);
|
||||||
|
|
||||||
object_ptr<IconButton> _close;
|
object_ptr<IconButton> _close;
|
||||||
|
object_ptr<IconButton> _menuToggle = { nullptr };
|
||||||
object_ptr<FlatLabel> _title = { nullptr };
|
object_ptr<FlatLabel> _title = { nullptr };
|
||||||
object_ptr<FadeWrapScaled<IconButton>> _back;
|
object_ptr<FadeWrapScaled<IconButton>> _back;
|
||||||
object_ptr<RpWidget> _body;
|
object_ptr<RpWidget> _body;
|
||||||
base::unique_qptr<RpWidget> _inner;
|
base::unique_qptr<RpWidget> _inner;
|
||||||
base::unique_qptr<LayerStackWidget> _layer = { nullptr };
|
base::unique_qptr<LayerStackWidget> _layer = { nullptr };
|
||||||
|
base::unique_qptr<PopupMenu> _menu;
|
||||||
rpl::event_stream<> _synteticBackRequests;
|
rpl::event_stream<> _synteticBackRequests;
|
||||||
rpl::event_stream<> _userCloseRequests;
|
rpl::event_stream<> _userCloseRequests;
|
||||||
rpl::event_stream<> _closeEvents;
|
rpl::event_stream<> _closeEvents;
|
||||||
|
|
|
||||||
|
|
@ -1567,3 +1567,29 @@ sideBarButtonLockBlockHeight: 5px;
|
||||||
sideBarButtonLockLineHeight: 1px;
|
sideBarButtonLockLineHeight: 1px;
|
||||||
sideBarButtonLockPenWidth: 3px;
|
sideBarButtonLockPenWidth: 3px;
|
||||||
sideBarButtonLockPenWidthDivider: 2;
|
sideBarButtonLockPenWidthDivider: 2;
|
||||||
|
|
||||||
|
menuIconColor: windowBoldFg;
|
||||||
|
menuIconAttentionColor: attentionButtonFg;
|
||||||
|
|
||||||
|
menuIconSubmenuArrow: icon {{ "menu/submenu_arrow", menuIconColor }};
|
||||||
|
|
||||||
|
menuWithIcons: Menu(defaultMenu) {
|
||||||
|
itemIconPosition: point(15px, 5px);
|
||||||
|
itemPadding: margins(54px, 8px, 17px, 8px);
|
||||||
|
|
||||||
|
arrow: menuIconSubmenuArrow;
|
||||||
|
}
|
||||||
|
menuWithIconsAttention: Menu(menuWithIcons) {
|
||||||
|
itemFg: attentionButtonFg;
|
||||||
|
itemFgOver: attentionButtonFgOver;
|
||||||
|
}
|
||||||
|
popupMenuWithIcons: PopupMenu(defaultPopupMenu) {
|
||||||
|
scrollPadding: margins(0px, 5px, 0px, 5px);
|
||||||
|
menu: menuWithIcons;
|
||||||
|
}
|
||||||
|
dropdownMenuWithIcons: DropdownMenu(defaultDropdownMenu) {
|
||||||
|
wrap: InnerDropdown(defaultInnerDropdown) {
|
||||||
|
scrollPadding: margins(0px, 5px, 0px, 5px);
|
||||||
|
}
|
||||||
|
menu: menuWithIcons;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue