diff --git a/CMakeLists.txt b/CMakeLists.txt index b580363..e319652 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -151,6 +151,8 @@ PRIVATE ui/widgets/menu/menu_common.h ui/widgets/menu/menu_item_base.cpp ui/widgets/menu/menu_item_base.h + ui/widgets/menu/menu_separator.cpp + ui/widgets/menu/menu_separator.h ui/widgets/popup_menu.cpp ui/widgets/popup_menu.h ui/widgets/scroll_area.cpp diff --git a/ui/widgets/menu.cpp b/ui/widgets/menu.cpp index b6a1b85..2cb18eb 100644 --- a/ui/widgets/menu.cpp +++ b/ui/widgets/menu.cpp @@ -10,6 +10,7 @@ #include "ui/widgets/buttons.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/menu/menu_item_base.h" +#include "ui/widgets/menu/menu_separator.h" #include "ui/text/text.h" #include @@ -51,55 +52,6 @@ TextParseOptions MenuTextOptions = { } // namespace -class Menu::Separator : public ItemBase { -public: - Separator(not_null parent, const style::Menu &st, int index) - : ItemBase(parent, st, index) - , _lineWidth(st.separatorWidth) - , _padding(st.separatorPadding) - , _fg(st.separatorFg) - , _bg(st.itemBg) - , _height(_padding.top() + _lineWidth + _padding.bottom()) { - - initResizeHook(parent->sizeValue()); - // setAttribute(Qt::WA_TransparentForMouseEvents, true); - paintRequest( - ) | rpl::start_with_next([=] { - Painter p(this); - - p.fillRect(0, 0, width(), _height, _bg); - p.fillRect( - _padding.left(), - _padding.top(), - width() - _padding.left() - _padding.right(), - _lineWidth, - _fg); - }, lifetime()); - - } - - QAction *action() const override { - return nullptr; - } - - bool isEnabled() const override { - return false; - } - -protected: - int contentHeight() const override { - return _height; - } - -private: - const int _lineWidth; - const style::margins &_padding; - const style::color &_fg; - const style::color &_bg; - const int _height; - -}; - class Menu::Action : public ItemBase { public: Action( @@ -329,7 +281,7 @@ not_null Menu::addAction(not_null action, const style::icon : _actionWidgets.back()->y() + _actionWidgets.back()->height(); const auto index = _actionWidgets.size(); if (action->isSeparator()) { - auto widget = base::make_unique_q(this, _st, index); + auto widget = base::make_unique_q(this, _st, index); widget->moveToLeft(0, top); widget->show(); _actionWidgets.push_back(std::move(widget)); diff --git a/ui/widgets/menu.h b/ui/widgets/menu.h index 0e14241..9e2f3e5 100644 --- a/ui/widgets/menu.h +++ b/ui/widgets/menu.h @@ -76,7 +76,6 @@ protected: void mouseReleaseEvent(QMouseEvent *e) override; private: - class Separator; class Action; void updateSelected(QPoint globalPosition); diff --git a/ui/widgets/menu/menu_separator.cpp b/ui/widgets/menu/menu_separator.cpp new file mode 100644 index 0000000..c00b96d --- /dev/null +++ b/ui/widgets/menu/menu_separator.cpp @@ -0,0 +1,51 @@ +// This file is part of Desktop App Toolkit, +// a set of libraries for developing nice desktop applications. +// +// For license and copyright information please follow this link: +// https://github.com/desktop-app/legal/blob/master/LEGAL +// +#include "ui/widgets/menu/menu_separator.h" + +#include "ui/painter.h" + +namespace Ui { + +Separator::Separator( + not_null parent, + const style::Menu &st, + int index) +: ItemBase(parent, st, index) +, _lineWidth(st.separatorWidth) +, _padding(st.separatorPadding) +, _fg(st.separatorFg) +, _bg(st.itemBg) +, _height(_padding.top() + _lineWidth + _padding.bottom()) { + + initResizeHook(parent->sizeValue()); + paintRequest( + ) | rpl::start_with_next([=] { + Painter p(this); + + p.fillRect(0, 0, width(), _height, _bg); + p.fillRect( + _padding.left(), + _padding.top(), + width() - _padding.left() - _padding.right(), + _lineWidth, + _fg); + }, lifetime()); +} + +QAction *Separator::action() const { + return nullptr; +} + +bool Separator::isEnabled() const { + return false; +} + +int Separator::contentHeight() const { + return _height; +} + +} // namespace Ui diff --git a/ui/widgets/menu/menu_separator.h b/ui/widgets/menu/menu_separator.h new file mode 100644 index 0000000..e2bae7f --- /dev/null +++ b/ui/widgets/menu/menu_separator.h @@ -0,0 +1,35 @@ +// This file is part of Desktop App Toolkit, +// a set of libraries for developing nice desktop applications. +// +// For license and copyright information please follow this link: +// https://github.com/desktop-app/legal/blob/master/LEGAL +// +#pragma once + +#include "ui/widgets/menu/menu_item_base.h" +#include "styles/style_widgets.h" + +class Painter; + +namespace Ui { + +class Separator : public ItemBase { +public: + Separator(not_null parent, const style::Menu &st, int index); + + QAction *action() const override; + bool isEnabled() const override; + +protected: + int contentHeight() const override; + +private: + const int _lineWidth; + const style::margins &_padding; + const style::color &_fg; + const style::color &_bg; + const int _height; + +}; + +} // namespace Ui