1 /** @file shell/lineeditwidget.h  Widget for word-wrapped text editing.
2  *
3  * @authors Copyright © 2013-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
4  *
5  * @par License
6  * LGPL: http://www.gnu.org/licenses/lgpl.html
7  *
8  * <small>This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or (at your
11  * option) any later version. This program is distributed in the hope that it
12  * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
14  * General Public License for more details. You should have received a copy of
15  * the GNU Lesser General Public License along with this program; if not, see:
16  * http://www.gnu.org/licenses</small>
17  */
18 
19 #ifndef LIBSHELL_LINEEDITWIDGET_H
20 #define LIBSHELL_LINEEDITWIDGET_H
21 
22 #include "libshell.h"
23 #include "TextWidget"
24 #include "AbstractLineEditor"
25 
26 namespace de { namespace shell {
27 
28 /**
29  * Widget for word-wrapped text editing.
30  *
31  * The widget adjusts its height automatically to fit to the full contents of
32  * the edited, wrapped lines.
33  *
34  * @ingroup textUi
35  */
36 class LIBSHELL_PUBLIC LineEditWidget
37     : public TextWidget
38     , public AbstractLineEditor
39 {
40     Q_OBJECT
41 
42 public:
43     /**
44      * The height rule of the widget is set up during construction.
45      *
46      * @param name  Widget name.
47      */
48     LineEditWidget(String const &name = String());
49 
50     /**
51      * Enables or disables the signal emitted when the edit widget receives an
52      * Enter key. By default, a signal is emitted.
53      *
54      * @param enterSignal  @c true to enable signal, @c false to disable.
55      */
56     void setSignalOnEnter(int enterSignal);
57 
58     Vector2i cursorPosition() const;
59 
60     bool handleControlKey(int qtKey, KeyModifiers const &mods = Unmodified);
61 
62     // Events.
63     void viewResized();
64     void update();
65     void draw();
66     bool handleEvent(Event const &event);
67 
68 signals:
69     void enterPressed(de::String text);
70 
71 protected:
72     virtual int  maximumWidth() const;
73     virtual void numberOfLinesChanged(int lineCount);
74     virtual void cursorMoved();
75     virtual void contentChanged();
76 
77 private:
78     DENG2_PRIVATE(d)
79 };
80 
81 }} // namespace de::shell
82 
83 #endif // LIBSHELL_LINEEDITWIDGET_H
84