IOWidget.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
3 
4  This file is part of the TerraLib - a Framework for building GIS enabled
5  applications.
6 
7  TerraLib is free software: you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation, either version 3 of the License,
10  or (at your option) any later version.
11 
12  TerraLib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with TerraLib. See COPYING. If not, write to
19  TerraLib Team at <terralib-team@terralib.org>.
20  */
21 
22 /*!
23  \file terralib/qt/widgets/ceditor/IOWidget.h
24 
25  \brief A widget that can be used to do input and out
26 */
27 
28 #ifndef __TERRALIB_QTWIDGETS_CEDITOR_IOWIDGET_H__
29 #define __TERRALIB_QTWIDGETS_CEDITOR_IOWIDGET_H__
30 
31 // TerraLib
32 #include "../Config.h"
33 
34 // QT
35 #include <QPlainTextEdit>
36 
37 class QKeyEvent;
38 class QTextCursor;
39 
40 namespace te
41 {
42  namespace qt
43  {
44  namespace widgets
45  {
46  class TEQTWIDGETSEXPORT IOWidget : public QPlainTextEdit
47  {
48  Q_OBJECT
49 
50  public:
51  IOWidget(QWidget *parent = 0);
52 
53  /*!
54  \brief prompt Retrieves the current prompt.
55  */
56  QString prompt() const;
57 
58  /*!
59  \brief setPrompt Sets a new prompt from a given string.
60  \param prompt String of the new prompt
61  */
62  void setPrompt(const QString &prompt);
63 
64  protected:
65  void keyPressEvent(QKeyEvent *e);
66 
67  private:
68  /*!
69  \brief handleLeft Handles Left arrow key press.
70  \param event The received event.
71  */
72  void handleLeft(QKeyEvent *event);
73 
74  /*!
75  \brief handleEnter Handles Enter and Return key press.
76  */
77  void handleEnter();
78 
79  /*!
80  \brief handleHome Handles Home key press.
81  */
82  void handleHome();
83 
84  /*!
85  \brief clearLine Clears the line under the cursor.
86  */
87  void clearLine();
88 
89  /*!
90  \brief getCommand Gets the input from the user.
91  */
92  QString getCommand() const;
93 
94  /*!
95  \brief isWritable Checks if a given cursor is at a writable position.
96  \param cursor Cursor that will be checked.
97  */
98  bool isWritable(const QTextCursor &cursor);
99 
100  /*!
101  \brief getIndex Gets the index of a given cursor.
102  \param cursor Cursor used to retrieve the index.
103  */
104  int getIndex(const QTextCursor &cursor);
105 
106  /*!
107  \brief userPrompt prompt to indicate that the text edit is waiting
108  for input
109  */
110  QString userPrompt;
111 
112  /*!
113  \brief locked False if the text edit can receive input, true
114  otherwise.
115  */
116  bool locked;
117 
118  /*!
119  \brief lastIndex The index of the last character.
120  */
122 
123  signals:
124  /*!
125  \brief command Signal emitted when input is entered.
126  \param command String to be emitted.
127  */
128  void command(QString command);
129 
130  public slots:
131  /*!
132  \brief addPrompt Adds the prompt to the text edit and unlocks the
133  widget for input
134  */
135  void addPrompt();
136 
137  /*!
138  \brief append Appends the given text to the text edit and locks the
139  widget for input
140  \param text String to be appended
141  */
142  void append(QString text);
143  };
144  } // end namespace widgets
145  } // end namespace qt
146 } // end namespace te
147 #endif // __TERRALIB_QTWIDGETS_CEDITOR_IOWIDGET_H__
void handleEnter()
handleEnter Handles Enter and Return key press.
bool isWritable(const QTextCursor &cursor)
isWritable Checks if a given cursor is at a writable position.
void handleHome()
handleHome Handles Home key press.
void command(QString command)
command Signal emitted when input is entered.
void setPrompt(const QString &prompt)
setPrompt Sets a new prompt from a given string.
void handleLeft(QKeyEvent *event)
handleLeft Handles Left arrow key press.
int lastIndex
lastIndex The index of the last character.
Definition: IOWidget.h:121
QString prompt() const
prompt Retrieves the current prompt.
QString getCommand() const
getCommand Gets the input from the user.
int getIndex(const QTextCursor &cursor)
getIndex Gets the index of a given cursor.
QString userPrompt
userPrompt prompt to indicate that the text edit is waiting for input
Definition: IOWidget.h:110
IOWidget(QWidget *parent=0)
void clearLine()
clearLine Clears the line under the cursor.
void keyPressEvent(QKeyEvent *e)
void addPrompt()
addPrompt Adds the prompt to the text edit and unlocks the widget for input
void append(QString text)
append Appends the given text to the text edit and locks the widget for input
bool locked
locked False if the text edit can receive input, true otherwise.
Definition: IOWidget.h:116
TerraLib.
#define slots
#define TEQTWIDGETSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:63