MenuItemBase.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 
54 class PT_FORMS_API MenuItemBase : public Control
55 {
56  public:
59  typedef Control Base;
60 
61  public:
62 
66 
69  virtual ~MenuItemBase();
70 
73  const Pt::String& text() const;
74 
77  void setText(const Pt::String& t);
78 
81  const Pt::Gfx::Image& icon() const;
82 
85  void setIcon(const Pt::Gfx::Image& img);
86 
89  double iconPadding() const;
90 
95  void setIconPadding(double left);
96 
99  void setSeperator(bool v)
100  {
101  _hasSeparator = v;
102  }
103 
106  bool hasSeperator() const
107  {
108  return _hasSeparator;
109  }
110 
113  bool isHighlighted() const
114  {
115  return _isHighlighted;
116  }
117 
121 
122 
123  public:
129  const Pt::Gfx::Brush& background() const;
130 
134 
140  const Pt::Gfx::Pen& contour() const;
141 
144  void setContour(const Pt::Gfx::Pen& p);
145 
151  const Pt::Gfx::Color& textColor() const;
152 
155  void setTextColor(const Pt::Gfx::Color& color);
156 
162  const Pt::Gfx::Font& font() const;
163 
166  void setFont(const Pt::Gfx::Font& font);
167 
170  void setFontSize(std::size_t size);
171 
175 
179 
180  protected:
181  static Pt::String shortcutText(const Pt::Forms::Key& key);
182 
183  virtual void onTriggered();
184 
185  virtual void onShortcut(const Pt::Forms::Key& key);
186 
187  virtual void onInvalidate();
188 
190 
191  virtual void onPaint(PaintContext& context, const Pt::Gfx::RectF& updateRect);
192 
193  virtual bool onMouseEvent(const Pt::Forms::MouseEvent& ev);
194 
195  virtual bool onTouchEvent(const Pt::Forms::TouchEvent& ev);
196 
197  virtual bool onEnterEvent(const Pt::Forms::EnterEvent& ev);
198 
199  virtual bool onLeaveEvent(const Pt::Forms::LeaveEvent& ev);
200 
201  private:
202  Pt::Gfx::Font getFont() const;
203 
204  private:
205  enum OverrideFlags : unsigned
206  {
207  OverrideBackground = 0x01,
208  OverrideContour = 0x02,
209  OverrideTextColor = 0x04,
210  OverrideFontAll = 0x08,
211  OverrideFontSize = 0x10,
212  OverrideFontWeight = 0x20,
213  OverrideFontSlant = 0x40,
214  OverrideFontAny = OverrideFontAll | OverrideFontSize
215  | OverrideFontWeight | OverrideFontSlant
216  };
217 
218  protected:
219  Pt::Signal<MenuItemBase&> _triggered;
220  double _iconWidth;
221  Pt::Gfx::Image _icon;
222  Pt::String _text;
223 
224  Pt::AutoPtr<Pt::Gfx::Brush> _background;
225  Pt::AutoPtr<Pt::Gfx::Pen> _contour;
226  Pt::AutoPtr<Pt::Gfx::Color> _textColor;
227  Pt::Gfx::Font _customFont;
228  unsigned _overrides;
229 
230  Pt::Forms::PixmapSurface _picture;
231  Pt::Gfx::Brush _brush;
232  Pt::Gfx::Pen _pen;
233  Pt::Gfx::Pen _textPen;
234  Pt::Gfx::Font _font;
235  bool _hasSeparator;
236  bool _isHighlighted;
237 };
238 
239 }}
240 
241 #endif
Pt::Signal< MenuItemBase & > & triggered()
Returns the signal emitted when this item is activated.
Core module.
Definition: Allocator.h:33
double iconPadding() const
Returns the space reserved before the item icon.
const Pt::Gfx::Color & textColor() const
Returns the text color.
Touch press, move, or release.
Definition: TouchEvent.h:51
const Pt::Gfx::Pen & contour() const
Returns the contour pen.
Pointer entered a widget.
Definition: EnterEvent.h:49
Attributes for the drawing of outlines.
Definition: Pen.h:54
void setFont(const Pt::Gfx::Font &font)
Sets a local font.
void setText(const Pt::String &t)
Sets the item text.
const Pt::String & text() const
Returns the item text.
virtual void onShortcut(const Pt::Forms::Key &key)
Handles an activated form shortcut.
Multicast Signal to call multiple slots.
Definition: Signal.h:190
void setFontWeight(Pt::Gfx::Font::Weight weight)
Sets a local font weight.
void setBackground(const Pt::Gfx::Brush &b)
Sets a local background brush.
Slant
Describes the requested font slant.
Definition: Font.h:76
virtual bool onTouchEvent(const Pt::Forms::TouchEvent &ev)
Handles touch input in local coordinates.
void setFontSlant(Pt::Gfx::Font::Slant slant)
Sets a local font slant.
const Pt::Gfx::Brush & background() const
Returns the background brush.
Active painting session on a Forms paint surface.
Definition: PaintContext.h:51
void setContour(const Pt::Gfx::Pen &p)
Sets a local contour pen.
void setTextColor(const Pt::Gfx::Color &color)
Sets a local text color.
virtual void onPaint(PaintContext &context, const Pt::Gfx::RectF &updateRect)
Paints custom content in local coordinates.
Size with floating-point width and height.
Definition: Size.h:47
Reusable view used as application content.
Definition: Control.h:107
MenuItemBase()
Creates a menu item with empty content.
virtual Pt::Gfx::SizeF onMeasure(const Pt::Forms::SizePolicy &policy)
Measures intrinsic content for effective policy policy.
virtual bool onEnterEvent(const Pt::Forms::EnterEvent &ev)
Handles pointer entry or continues responder dispatch.
Weight
Describes the requested font weight.
Definition: Font.h:61
void setIcon(const Pt::Gfx::Image &img)
Sets the item icon.
virtual bool onLeaveEvent(const Pt::Forms::LeaveEvent &ev)
Handles pointer leave or continues responder dispatch.
bool isHighlighted() const
Returns true while the pointer is over this item.
Definition: MenuItemBase.h:113
const Pt::Gfx::Font & font() const
Returns the item font.
void setFontSize(std::size_t size)
Sets a local font size.
Font request used for text drawing and measurement.
Definition: Font.h:56
Basic image.
Definition: Image.h:52
Key code and modifiers.
Definition: Key.h:23
Pointer left a widget.
Definition: LeaveEvent.h:49
Constraint used when measuring a control.
Definition: SizePolicy.h:48
Standard color type.
Definition: Color.h:47
Control Base
Defines the inherited control type.
Definition: MenuItemBase.h:59
virtual void onInvalidate()
Updates derived state after invalidation.
bool hasSeperator() const
Returns true if a separator is drawn below this item.
Definition: MenuItemBase.h:106
Unicode capable basic_string.
Definition: Api-String.h:44
Fill description for shapes and text.
Definition: Brush.h:145
Rect with floating-point coordinates.
Definition: Rect.h:47
virtual bool onMouseEvent(const Pt::Forms::MouseEvent &ev)
Handles mouse input in local coordinates.
Off-screen Forms paint surface.
Definition: Pixmap.h:130
Represents the common content and activation behavior of a menu item.
Definition: MenuItemBase.h:55
const Pt::Gfx::Image & icon() const
Returns the item icon.
virtual ~MenuItemBase()
Destroys the menu item.
Pointer movement or button change.
Definition: MouseEvent.h:134
void setIconPadding(double left)
Sets the space reserved before the item icon.
void setSeperator(bool v)
Sets whether a separator is drawn below this item.
Definition: MenuItemBase.h:99