menu_action.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #pragma once
  8. #include "ui/text/text.h"
  9. #include "ui/widgets/menu/menu_item_base.h"
  10. #include "styles/style_widgets.h"
  11. class Painter;
  12. namespace Ui::Menu {
  13. class Action : public ItemBase {
  14. public:
  15. Action(
  16. not_null<RpWidget*> parent,
  17. const style::Menu &st,
  18. not_null<QAction*> action,
  19. const style::icon *icon,
  20. const style::icon *iconOver);
  21. bool isEnabled() const override;
  22. not_null<QAction*> action() const override;
  23. void handleKeyPress(not_null<QKeyEvent*> e) override;
  24. void setIcon(
  25. const style::icon *icon,
  26. const style::icon *iconOver = nullptr);
  27. void setMarkedText(
  28. TextWithEntities text,
  29. QString shortcut,
  30. const Text::MarkedContext &context = {});
  31. protected:
  32. void paintEvent(QPaintEvent *e) override;
  33. QPoint prepareRippleStartPosition() const override;
  34. QImage prepareRippleMask() const override;
  35. int contentHeight() const override;
  36. void paintBackground(QPainter &p, bool selected);
  37. void paintText(Painter &p);
  38. private:
  39. void processAction();
  40. void paint(Painter &p);
  41. bool hasSubmenu() const;
  42. Text::String _text;
  43. QString _shortcut;
  44. const not_null<QAction*> _action;
  45. const style::Menu &_st;
  46. const style::icon *_icon;
  47. const style::icon *_iconOver;
  48. // std::unique_ptr<ToggleView> _toggle;
  49. int _textWidth = 0;
  50. const int _height;
  51. };
  52. } // namespace Ui::Menu