LineEdit.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 
30 #ifndef PT_FORMS_LINEEDIT_H
31 #define PT_FORMS_LINEEDIT_H
32 
33 #include <Pt/Forms/Control.h>
34 #include <Pt/Forms/LineEditor.h>
35 #include <Pt/Forms/Adjustment.h>
36 #include <Pt/SmartPtr.h>
37 #include <Pt/String.h>
38 
39 namespace Pt {
40 
41 namespace Forms {
42 
43 class PT_FORMS_API LineEdit : public Control
44 {
45  public:
46  typedef Control Base;
47 
48  enum EchoMode
49  {
50  Normal = 0,
51  Hidden = 1,
52  Masked = 2
53  };
54 
55  public:
56  LineEdit();
57 
58  ~LineEdit();
59 
60  bool isEditable() const;
61 
62  void setEditable(bool e);
63 
64  const Pt::String& text() const;
65 
66  void setText(const Pt::String& str);
67 
68  bool isEmpty() const;
69 
70  const Pt::String& displayText() const;
71 
72  const Pt::String& placeholderText() const;
73 
74  void setPlaceholderText(const Pt::String& s);
75 
76  EchoMode echoMode() const;
77 
78  void setEchoMode(EchoMode mode);
79 
80  Adjustment textAdjustment() const;
81 
82  void setTextAdjustment(Adjustment a);
83 
84  std::size_t cursorPosition() const;
85 
86  void setCursorPosition(std::size_t n);
87 
88  bool isAccepted() const;
89 
90  void setAccepted(bool a);
91 
92  bool isHighlighted() const;
93 
94  Pt::Signal<const Pt::String&>& textEdited();
95 
96  Pt::Signal<const Pt::String&>& returnPressed();
97 
98  Pt::Signal<const Pt::String&>& editingFinished();
99 
100  public:
101  const Gfx::Brush& background() const;
102 
103  void setBackground(const Gfx::Brush& b);
104 
105  const Gfx::Pen& contour() const;
106 
107  void setContour(const Gfx::Pen& p);
108 
109  const Gfx::Color& textColor() const;
110 
111  void setTextColor(const Gfx::Color& color);
112 
113  const Gfx::Font& font() const;
114 
115  void setFont(const Gfx::Font& font);
116 
117  void setFontSize(std::size_t size);
118 
119  void setFontWeight(Gfx::Font::Weight weight);
120 
121  void setFontSlant(Gfx::Font::Slant slant);
122 
123  void setRenderer(LineEditRenderer* renderer);
124 
125  protected:
126  virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
127 
128  virtual void onInvalidate();
129 
130  virtual void onPaint(PaintSurface& surface, const Gfx::RectF& rect);
131 
132  protected:
133  virtual bool onEnterEvent(const EnterEvent& ev);
134 
135  virtual bool onLeaveEvent(const LeaveEvent& ev);
136 
137  virtual bool onKeyEvent(const KeyEvent& ev);
138 
139  virtual bool onMouseEvent(const MouseEvent& ev);
140 
141  virtual bool onTouchEvent(const TouchEvent& ev);
142 
143  virtual void onResizeEvent(const ResizeEvent& ev);
144 
145  virtual void onFocusEvent(const FocusEvent& ev);
146 
147  private:
148  Gfx::Font getFont() const;
149 
150  private:
151  enum FontOverride : unsigned
152  {
153  OverrideSize = 0x01,
154  OverrideWeight = 0x02,
155  OverrideSlant = 0x04,
156  OverrideAll = 0xFF
157  };
158 
159  Pt::Signal<const Pt::String&> _textEdited;
160  Pt::Signal<const Pt::String&> _returnPressed;
161  Pt::Signal<const Pt::String&> _editingFinished;
162 
163  LineEditor _editor;
164  TextLine _line;
165  Pt::String _placeholderText;
166  bool _isEditable;
167  bool _isAccepted;
168  bool _isTextChanged;
169  bool _isHighlighted;
170  EchoMode _echoMode;
171  double _spacing;
172 
173  FacetPtr<LineEditRenderer> _renderer;
174  bool _hasRenderer;
175 
176  AutoPtr<Gfx::Brush> _background;
177  AutoPtr<Gfx::Pen> _contour;
178  AutoPtr<Gfx::Color> _textColor;
179  Gfx::Font _customFont;
180  unsigned _fontOverride;
181 
182  Gfx::Brush _brush;
183  Gfx::Pen _pen;
184  Gfx::Pen _textPen;
185  Gfx::Font _font;
186 };
187 
188 } // namespace
189 
190 } // namespace
191 
192 #endif
Multicast Signal to call multiple slots.
Definition: Signal.h:109
Unicode capable basic_string.
Definition: String.h:42