/
codeinput.h
84 lines (68 loc) · 2.33 KB
/
codeinput.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* Copyright (C) 2011 - 2012 Thomas Gahr <thomas.gahr@physik.uni-muenchen.de>
This file is part of qling, a Qt Interface to cling, the llvm-based
C++ interpreter.
cling: http://root.cern.ch/drupal/content/cling
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or the version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef CODEINPUT_H
#define CODEINPUT_H
#include <QTextEdit>
#include <QStringList>
/** LineEdit that keeps a history of stuff entered
*
* history is saved via the QSettings interface so use
* QApplication::setApplicationName and QApplication::setOrganizationName
* to uniquely identify the settings
*/
class CodeInput : public QTextEdit
{
Q_OBJECT
public:
explicit CodeInput(QWidget *parent = 0);
~CodeInput();
bool eventFilter(QObject *, QEvent *);
/** set maximum number of entries in history.
*
* Default: 50
* Note: The current history - if longer than s - will not be truncated
* until the next entry is added
*/
void setMaxHistorySize(unsigned s);
int maxHistorySize()const;
QString text()const;
bool isEmpty()const;
protected:
void showEvent(QShowEvent *);
signals:
void entered(const QString& str);
public slots:
void fitSizeToText();
void enableMultiLineMode(bool e);
void disallowInput();
void allowInput();
private:
void submit();
void addToHistory(const QString& str);
void moveInHistory(int dir);
QStringList m_history;
int m_historyPos;
unsigned m_maxHistorySize;
//cache to save text that has neither been submitted nor committed to
//history
QString m_unsubmittedText;
int m_yMargin;
bool m_multiLineEnabled;
int m_indent;
};
#endif // CODEINPUT_H