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/LineEditStyler.h>
35#include <Pt/Forms/LineEditor.h>
36#include <Pt/Forms/Adjustment.h>
37#include <Pt/SmartPtr.h>
38#include <Pt/String.h>
39
40namespace Pt {
41
42namespace Forms {
43
80class PT_FORMS_API LineEdit : public Control
81{
82 public:
83 typedef Control Base;
84
88 {
91 Normal = 0,
92
95 Hidden = 1,
96
100 };
101
102 public:
106
110
113 bool isEditable() const;
114
119 void setEditable(bool e);
120
123 const Pt::String& text() const;
124
127 void setText(const Pt::String& str);
128
131 bool isEmpty() const;
132
138 const Pt::String& displayText() const;
139
143
147
151
155
159
163
166 std::size_t cursorPosition() const;
167
170 void setCursorPosition(std::size_t n);
171
174 bool isAccepted() const;
175
178 void setAccepted(bool a);
179
182 bool isHighlighted() const;
183
187
191
195
196 public:
199 const Gfx::Brush& background() const;
200
203 void setBackground(const Gfx::Brush& b);
204
207 const Gfx::Pen& contour() const;
208
211 void setContour(const Gfx::Pen& p);
212
215 const Gfx::Color& textColor() const;
216
219 void setTextColor(const Gfx::Color& color);
220
224
227 void setFont(const Gfx::Font& font);
228
231 void setFontSize(std::size_t size);
232
236
240
246
250
251 protected:
254 virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
255
258 virtual void onLayout(const Gfx::RectF& rect);
259
262 virtual void onInvalidate();
263
266 virtual void onPaint(PaintContext& context, const Gfx::RectF& rect);
267
270 virtual void onPaintChrome(PaintContext& context,
271 const Gfx::RectF& rect,
272 const Gfx::RectF& textRect,
273 const String& text,
274 const Gfx::PointF& textPos,
275 const Gfx::RectF& cursor,
276 const Gfx::RectF& selection,
277 const LineEditState& state);
278
279 protected:
282 virtual bool onEnterEvent(const EnterEvent& ev);
283
286 virtual bool onLeaveEvent(const LeaveEvent& ev);
287
290 virtual bool onKeyEvent(const KeyEvent& ev);
291
294 virtual bool onMouseEvent(const MouseEvent& ev);
295
298 virtual bool onTouchEvent(const TouchEvent& ev);
299
302 virtual void onResizeEvent(const ResizeEvent& ev);
303
306 virtual void onFocusEvent(const FocusEvent& ev);
307
308 private:
310 Pt::Signal<const Pt::String&> _returnPressed;
311 Pt::Signal<const Pt::String&> _editingFinished;
312
313 LineEditor _editor;
314 TextLine _line;
315 Pt::String _placeholderText;
316 bool _isEditable;
317 bool _isAccepted;
318 bool _isTextChanged;
319 bool _isHighlighted;
320 double _pendingCursorX;
321 EchoMode _echoMode;
322 double _spacing;
323
324 LineEditStyler _styler;
325
326 Gfx::RectF _textRect;
327 Gfx::RectF _cursorRect;
328};
329
330} // namespace
331
332} // namespace
333
334#endif
Aligns content along one axis.
Definition Adjustment.h:60
Control()
Creates an unparented control.
Pointer entered a widget.
Definition EnterEvent.h:49
Reports that a widget gained or lost focus.
Definition FocusEvent.h:48
Key press or release.
Definition KeyEvent.h:50
Pointer left a widget.
Definition LeaveEvent.h:49
Renders the look of a line edit.
Definition LineEditStyler.h:117
Transient visual state of a line edit.
Definition LineEditStyler.h:48
Binds a line edit to the current style renderer.
Definition LineEditStyler.h:265
virtual bool onMouseEvent(const MouseEvent &ev)
Places the caret from a pointer press when the field is editable.
bool isEditable() const
Returns true if the user can change the text.
Pt::Signal< const Pt::String & > & returnPressed()
Returns the signal emitted when Return completes an edit.
Adjustment textAdjustment() const
Returns the horizontal adjustment of the text.
LineEdit()
Creates an empty line edit.
virtual void onFocusEvent(const FocusEvent &ev)
Begins text input on focus, or emits editingFinished() on loss.
const Gfx::Color & textColor() const
Returns the effective text color.
virtual bool onTouchEvent(const TouchEvent &ev)
Places the caret from a touch press when the field is editable.
void setCursorPosition(std::size_t n)
Sets the caret index in the entered text to n.
Pt::Signal< const Pt::String & > & editingFinished()
Returns the signal emitted when focus loss completes an edit.
virtual void onPaintChrome(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &textRect, const String &text, const Gfx::PointF &textPos, const Gfx::RectF &cursor, const Gfx::RectF &selection, const LineEditState &state)
Paints the line-edit chrome for state.
virtual void onPaint(PaintContext &context, const Gfx::RectF &rect)
Paints the entry, text, selection, and caret.
virtual bool onEnterEvent(const EnterEvent &ev)
Highlights the field when the pointer enters.
const Pt::String & text() const
Returns the entered text.
virtual void onResizeEvent(const ResizeEvent &ev)
Forwards the resize to the base control.
const Gfx::Brush & background() const
Returns the effective background brush.
Gfx::Font font() const
Returns the effective font.
Pt::Signal< const Pt::String & > & textEdited()
Returns the signal emitted when the entered text changes.
virtual void onLayout(const Gfx::RectF &rect)
Places the entry, caret, and text in rect.
bool isHighlighted() const
Returns true if the pointer is over the field.
void setEditable(bool e)
Sets whether the user can change the text.
void setBackground(const Gfx::Brush &b)
Sets the widget-local background brush to b.
void setContour(const Gfx::Pen &p)
Sets the widget-local contour pen to p.
const Pt::String & displayText() const
Returns the text shown in the entry.
LineEditState lineEditState() const
Returns the transient visual state for the current paint pass.
virtual Gfx::SizeF onMeasure(const SizePolicy &policy)
Measures the entry and frame.
~LineEdit()
Destroys the line edit.
virtual bool onLeaveEvent(const LeaveEvent &ev)
Clears the highlight when the pointer leaves.
void setAccepted(bool a)
Sets whether Return and focus loss complete an edit.
virtual bool onKeyEvent(const KeyEvent &ev)
Inserts, deletes, or moves the caret, or completes an edit.
void setText(const Pt::String &str)
Sets the entered text to str and emits textEdited().
void setRenderer(LineEditRenderer *renderer)
Assigns renderer as the family renderer.
void setTextColor(const Gfx::Color &color)
Sets the widget-local text color to color.
void setFont(const Gfx::Font &font)
Sets the widget-local font to font.
const Gfx::Pen & contour() const
Returns the effective contour pen.
bool isAccepted() const
Returns true if Return and focus loss complete an edit.
bool isEmpty() const
Returns true if the entered text is empty.
void setEchoMode(EchoMode mode)
Sets how entered text is shown to mode.
const Pt::String & placeholderText() const
Returns the placeholder shown while the field is empty.
void setFontWeight(Gfx::Font::Weight weight)
Sets the widget-local font weight to weight.
void setTextAdjustment(Adjustment a)
Sets the horizontal adjustment of the text to a.
std::size_t cursorPosition() const
Returns the caret index in the entered text.
virtual void onInvalidate()
Binds the styler.
EchoMode
How entered text is shown.
Definition LineEdit.h:88
@ Masked
Shows a mask character for each entered character.
Definition LineEdit.h:99
@ Normal
Shows the entered text.
Definition LineEdit.h:91
@ Hidden
Does not show the entered text.
Definition LineEdit.h:95
EchoMode echoMode() const
Returns how entered text is shown.
void setFontSize(std::size_t size)
Sets the widget-local font size to size.
void setFontSlant(Gfx::Font::Slant slant)
Sets the widget-local font slant to slant.
void setPlaceholderText(const Pt::String &s)
Sets the placeholder shown while the field is empty to s.
Single-line text, caret, and scroll helper.
Definition LineEditor.h:57
Pointer movement or button change.
Definition MouseEvent.h:134
Active painting session on a Forms paint surface.
Definition PaintContext.h:51
Reports that a widget was resized.
Definition ResizeEvent.h:50
Constraint used when measuring a control.
Definition SizePolicy.h:48
Represents one laid-out line in a TextBlock.
Definition TextBlock.h:58
Touch press, move, or release.
Definition TouchEvent.h:51
const Gfx::SizeF & size() const
Returns the size in local logical coordinates.
const Cursor * cursor() const
Returns this widget's cursor or the default cursor.
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