MenuBaseItem.h
1 /* Copyright (C) 2015 Marc Boris Duerner
2  Copyright (C) 2015 Laurentiu-Gheorghe Crisan
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  As a special exception, you may use this file as part of a free
10  software library without restriction. Specifically, if other files
11  instantiate templates or use macros or inline functions from this
12  file, or you compile this file and link it with other files to
13  produce an executable, this file does not by itself cause the
14  resulting executable to be covered by the GNU General Public
15  License. This exception does not however invalidate any other
16  reasons why the executable file might be covered by the GNU Library
17  General Public License.
18 
19  This library is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  Lesser General Public License for more details.
23 
24  You should have received a copy of the GNU Lesser General Public
25  License along with this library; if not, write to the Free Software
26  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27  MA 02110-1301 USA
28 */
29 #ifndef PT_FORMS_MENUITEMBASE_H
30 #define PT_FORMS_MENUITEMBASE_H
31 
32 #include <Pt/Forms/Api.h>
33 #include <Pt/Forms/Control.h>
34 #include <Pt/Forms/PixmapSurface.h>
35 
36 namespace Pt {
37 
38 namespace Forms {
39 
40 class PT_FORMS_API MenuBaseItem : public Control
41 {
42  public:
43  typedef Control Base;
44 
45  public:
46 
47  MenuBaseItem();
48 
49  virtual ~MenuBaseItem();
50 
51  const Pt::String& text() const;
52 
53  void setText(const Pt::String& t);
54 
55  const Pt::Gfx::Image& icon() const;
56 
57  void setIcon(const Pt::Gfx::Image& img);
58 
59  double iconPadding() const;
60 
61  void setIconPadding(double left);
62 
63  void setSeperator(bool v)
64  {
65  _hasSeparator = v;
66  }
67 
68  bool hasSeperator() const
69  {
70  return _hasSeparator;
71  }
72 
73  bool isHighlighted() const
74  {
75  return _isHighlighted;
76  }
77 
78  Pt::Signal<MenuBaseItem&>& triggered();
79 
80 
81  public:
82  const Pt::Gfx::Brush& background() const;
83 
84  void setBackground(const Pt::Gfx::Brush& b);
85 
86  const Pt::Gfx::Pen& contour() const;
87 
88  void setContour(const Pt::Gfx::Pen& p);
89 
90  const Pt::Gfx::Color& textColor() const;
91 
92  void setTextColor(const Pt::Gfx::Color& color);
93 
94  const Pt::Gfx::Font& font() const;
95 
96  void setFont(const Pt::Gfx::Font& font);
97 
98  void setFontSize(std::size_t size);
99 
100  void setFontWeight(Pt::Gfx::Font::Weight weight);
101 
102  void setFontSlant(Pt::Gfx::Font::Slant slant);
103 
104  protected:
105  static Pt::String shortcutText(const Pt::Forms::Key& key);
106 
107  virtual void onTriggered();
108 
109  virtual void onShortcut(const Pt::Forms::Key& key);
110 
111  virtual void onInvalidate();
112 
113  virtual Pt::Gfx::SizeF onMeasure(const Pt::Forms::SizePolicy& policy);
114 
115  virtual void onPaint(PaintSurface& surface, const Pt::Gfx::RectF& updateRect);
116 
117  virtual bool onMouseEvent(const Pt::Forms::MouseEvent& ev);
118 
119  virtual bool onTouchEvent(const Pt::Forms::TouchEvent& ev);
120 
121  virtual bool onEnterEvent(const Pt::Forms::EnterEvent& ev);
122 
123  virtual bool onLeaveEvent(const Pt::Forms::LeaveEvent& ev);
124 
125  private:
126  Pt::Gfx::Font getFont() const;
127 
128  private:
129  enum FontOverride : unsigned
130  {
131  OverrideSize = 0x01,
132  OverrideWeight = 0x02,
133  OverrideSlant = 0x04,
134  OverrideAll = 0xFF
135  };
136 
137  protected:
138  Pt::Signal<MenuBaseItem&> _triggered;
139  double _iconWidth;
140  Pt::Gfx::Image _icon;
141  Pt::String _text;
142 
143  Pt::AutoPtr<Pt::Gfx::Brush> _background;
144  Pt::AutoPtr<Pt::Gfx::Pen> _contour;
145  Pt::AutoPtr<Pt::Gfx::Color> _textColor;
146  Pt::Gfx::Font _customFont;
147  unsigned _fontOverride;
148 
149  Pt::Forms::PixmapSurface _picture;
150  Pt::Gfx::Brush _brush;
151  Pt::Gfx::Pen _pen;
152  Pt::Gfx::Pen _textPen;
153  Pt::Gfx::Font _font;
154  bool _hasSeparator;
155  bool _isHighlighted;
156 };
157 
158 }}
159 
160 #endif
Back buffer drawing surface.
Definition: Pixmap.h:50
Rect with floating-point coordinates.
Definition: Rect.h:44
Basic image.
Definition: Api.h:81
Standard color type.
Definition: Color.h:46
Attributes for the drawing of outlines.
Definition: Pen.h:52
Size with floating-point width and height.
Definition: Size.h:44
Unicode capable basic_string.
Definition: String.h:42