1
/*************************************************************************************
2
* Copyright (C) 2007 by Aleix Pol <aleixpol@kde.org> *
4
* This program is free software; you can redistribute it and/or *
5
* modify it under the terms of the GNU General Public License *
6
* as published by the Free Software Foundation; either version 2 *
7
* of the License, or (at your option) any later version. *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License for more details. *
14
* You should have received a copy of the GNU General Public License *
15
* along with this program; if not, write to the Free Software *
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
17
*************************************************************************************/
19
#ifndef EXPRESSIONEDIT_H
20
#define EXPRESSIONEDIT_H
22
#include <QPlainTextEdit>
26
#include <analitzagui/algebrahighlighter.h>
28
#include "analitzaguiexport.h"
41
* The expression edit widget is the one where we will input our expressions.
43
* @author Aleix Pol i Gonzalez <aleixpol@kde.org>
46
class ANALITZAGUI_EXPORT ExpressionEdit : public QPlainTextEdit
50
/** Constructor. Creates a new ExpressionEdit.
51
* @param parent is the widget parent.
52
* @param ini specifies what input format is going to expect the highlighting.
54
explicit ExpressionEdit(QWidget *parent = 0, AlgebraHighlighter::Mode ini=AlgebraHighlighter::Autodetect);
59
/** Returns the ExpressionEdit input mode. */
60
AlgebraHighlighter::Mode mode() { return m_highlight->mode(); }
62
/** Sets the ExpressionEdit input mode. */
63
void setMode(AlgebraHighlighter::Mode en);
65
/** Sets whether autocompletion will be used. */
66
void setAutocomplete(bool a);
68
/** Returns whether autocompletion will be used. */
71
/** Returns whether there is MathML on the widget. */
72
bool isMathML() const;
74
/** Sets an Analyzer @p in module associated to the ExpressionEdit. It is used to autocomplete variables. */
75
void setAnalitza(Analitza::Analyzer* in);
77
/** Returns the expression string that we have. */
78
QString text() const { return this->toPlainText();}
80
/** Sets the expression string @p str we have. */
81
void setText(const QString &str) { setPlainText(str);}
83
/** Sets whether it is correct. Changes the background color. */
84
void setCorrect(bool cor);
86
/** Checks whether it has been set to correct. */
87
bool isCorrect() const { return m_correct; }
89
/** Sets the string @p ans that will be entered when an operator is pressed. */
90
void setAns(const QString &ans) { m_ans=ans; }
92
/** Returns the string that will be entered when the first operator is pressed. */
93
QString ans() const { return m_ans; }
95
/** Sets an expression to the input box. */
96
void setExpression(const Analitza::Expression& e);
98
/** Returns the expression we have in the text. */
99
Analitza::Expression expression() const;
101
/** Sets the @p examples to be shown in the context menu */
102
void setExamples(const QStringList& ex) { m_examples=ex; }
105
/** Inserts @p text text where the cursor is and selects it */
106
void insertText(const QString& text);
109
void showSimplified();
111
void updateCompleter();
112
void setActionText(QAction* text);
114
/** Shows a little tip widget containing the string @p str. If @p str is empty the widget is hidden. */
115
void helper(const QString& str);
117
/** Tries to complete the currently edited word with the @p word. */
118
void completed(const QString &word);
120
/** Sets the Mode to MathML */
121
void toMathML() { setMode(AlgebraHighlighter::MathML); }
123
/** Sets the Mode to Expression */
124
void toExpression() { setMode(AlgebraHighlighter::Expression); }
126
/** Simplify the current expression. */
129
/** Is the execution function, when return is pressed. */
130
void returnP(); //FIXME: Change my name please
133
/** Emits that a return has been pressed. */
134
void returnPressed();
137
void signalHelper(QString);
140
/** Inherited from QTextEdit, just deals with the menu. */
141
void contextMenuEvent(QContextMenuEvent * e);
145
QString helpShow(const QString& funcname, int param, bool bounds, const Analitza::Variables* v) const;
146
void helper(const QString&, const QPoint& p);
147
QString lastWord(int);
148
void focusInEvent (QFocusEvent * event);
149
void focusOutEvent ( QFocusEvent * event );
152
void keyPressEvent(QKeyEvent * e);
155
AlgebraHighlighter *m_highlight;
158
QStringList m_history;
160
Analitza::Analyzer *a;
163
QCompleter *m_completer;
164
OperatorsModel *m_ops;
166
QStringList m_examples;
167
QTimer* m_hideHelpTip;