menu_separator.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #include "ui/widgets/menu/menu_separator.h"
  8. #include "ui/painter.h"
  9. #include "styles/style_widgets.h"
  10. namespace Ui::Menu {
  11. Separator::Separator(
  12. not_null<RpWidget*> parent,
  13. const style::Menu &st,
  14. const style::MenuSeparator &separator,
  15. not_null<QAction*> action)
  16. : ItemBase(parent, st)
  17. , _lineWidth(separator.width)
  18. , _padding(separator.padding)
  19. , _fg(separator.fg)
  20. , _bg(st.itemBg)
  21. , _height(_padding.top() + _lineWidth + _padding.bottom())
  22. , _action(action) {
  23. initResizeHook(parent->sizeValue());
  24. paintRequest(
  25. ) | rpl::start_with_next([=] {
  26. Painter p(this);
  27. p.fillRect(0, 0, width(), _height, _bg);
  28. p.fillRect(
  29. _padding.left(),
  30. _padding.top(),
  31. width() - _padding.left() - _padding.right(),
  32. _lineWidth,
  33. _fg);
  34. }, lifetime());
  35. }
  36. not_null<QAction*> Separator::action() const {
  37. return _action;
  38. }
  39. bool Separator::isEnabled() const {
  40. return false;
  41. }
  42. int Separator::contentHeight() const {
  43. return _height;
  44. }
  45. } // namespace Ui::Menu