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/Pixmap.h>
35
36namespace Pt {
37
38namespace Forms {
39
54class 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:
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
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
189 virtual Pt::Gfx::SizeF onMeasure(const Pt::Forms::SizePolicy& policy);
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;
227 Pt::Gfx::Font _customFont;
228 unsigned _overrides;
229
230 Pt::Forms::Pixmap _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
Policy based Auto pointer.
Definition SmartPtr.h:291
Control()
Creates an unparented control.
Pointer entered a widget.
Definition EnterEvent.h:49
Key code and modifiers.
Definition Key.h:23
Pointer left a widget.
Definition LeaveEvent.h:49
Pt::Signal< MenuItemBase & > & triggered()
Returns the signal emitted when this item is activated.
virtual bool onTouchEvent(const Pt::Forms::TouchEvent &ev)
Handles touch input in local coordinates.
Control Base
Defines the inherited control type.
Definition MenuItemBase.h:59
virtual void onPaint(PaintContext &context, const Pt::Gfx::RectF &updateRect)
Paints custom content in local coordinates.
void setText(const Pt::String &t)
Sets the item text.
virtual ~MenuItemBase()
Destroys the menu item.
bool hasSeperator() const
Returns true if a separator is drawn below this item.
Definition MenuItemBase.h:106
virtual bool onEnterEvent(const Pt::Forms::EnterEvent &ev)
Handles pointer entry or continues responder dispatch.
const Pt::String & text() const
Returns the item text.
const Pt::Gfx::Font & font() const
Returns the item font.
double iconPadding() const
Returns the space reserved before the item icon.
void setContour(const Pt::Gfx::Pen &p)
Sets a local contour pen.
bool isHighlighted() const
Returns true while the pointer is over this item.
Definition MenuItemBase.h:113
void setIconPadding(double left)
Sets the space reserved before the item icon.
void setIcon(const Pt::Gfx::Image &img)
Sets the item icon.
virtual void onShortcut(const Pt::Forms::Key &key)
Handles an activated form shortcut.
void setBackground(const Pt::Gfx::Brush &b)
Sets a local background brush.
void setFontSlant(Pt::Gfx::Font::Slant slant)
Sets a local font slant.
const Pt::Gfx::Brush & background() const
Returns the background brush.
void setFont(const Pt::Gfx::Font &font)
Sets a local font.
void setSeperator(bool v)
Sets whether a separator is drawn below this item.
Definition MenuItemBase.h:99
const Pt::Gfx::Color & textColor() const
Returns the text color.
const Pt::Gfx::Pen & contour() const
Returns the contour pen.
void setFontWeight(Pt::Gfx::Font::Weight weight)
Sets a local font weight.
void setTextColor(const Pt::Gfx::Color &color)
Sets a local text color.
virtual Pt::Gfx::SizeF onMeasure(const Pt::Forms::SizePolicy &policy)
Measures intrinsic content for effective policy policy.
virtual bool onLeaveEvent(const Pt::Forms::LeaveEvent &ev)
Handles pointer leave or continues responder dispatch.
virtual bool onMouseEvent(const Pt::Forms::MouseEvent &ev)
Handles mouse input in local coordinates.
const Pt::Gfx::Image & icon() const
Returns the item icon.
MenuItemBase()
Creates a menu item with empty content.
virtual void onInvalidate()
Updates derived state after invalidation.
void setFontSize(std::size_t size)
Sets a local font size.
Pointer movement or button change.
Definition MouseEvent.h:134
Active painting session on a Forms paint surface.
Definition PaintContext.h:51
Off-screen Forms paint surface.
Definition Pixmap.h:130
Constraint used when measuring a control.
Definition SizePolicy.h:48
Touch press, move, or release.
Definition TouchEvent.h:51
const Gfx::SizeF & size() const
Returns the size in local logical coordinates.
Fill color, gradient or texture.
Definition Brush.h:151
8-bit ARGB color.
Definition Color.h:65
Font family, size and style.
Definition Font.h:63
Slant
Describes the requested font slant.
Definition Font.h:83
Weight
Describes the requested font weight.
Definition Font.h:68
Outline color, width and style.
Definition Pen.h:59
Multicast Signal to call multiple slots.
Definition Signal.h:190
Unicode capable basic_string.
Definition Api-String.h:67
Graphical user interfaces.
Definition ActivateEvent.h:40
Core module.
Definition Allocator.h:33