~ubuntu-branches/ubuntu/trusty/kalgebra/trusty-updates

« back to all changes in this revision

Viewing changes to analitzagui/expressionedit.h

  • Committer: Bazaar Package Importer
  • Author(s): Philip Muškovac
  • Date: 2011-07-08 20:10:34 UTC
  • Revision ID: james.westby@ubuntu.com-20110708201034-0cqpagx7uz4pu82n
Tags: upstream-4.6.90+repack1
Import upstream version 4.6.90+repack1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*************************************************************************************
 
2
 *  Copyright (C) 2007 by Aleix Pol <aleixpol@kde.org>                               *
 
3
 *                                                                                   *
 
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.                           *
 
8
 *                                                                                   *
 
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.                                     *
 
13
 *                                                                                   *
 
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
 *************************************************************************************/
 
18
 
 
19
#ifndef EXPRESSIONEDIT_H
 
20
#define EXPRESSIONEDIT_H
 
21
 
 
22
#include <QPlainTextEdit>
 
23
#include <QCompleter>
 
24
#include <QLabel>
 
25
#include <QTreeView>
 
26
#include <analitzagui/algebrahighlighter.h>
 
27
 
 
28
#include "analitzaguiexport.h"
 
29
 
 
30
namespace Analitza
 
31
{
 
32
class Variables;
 
33
class Analyzer;
 
34
class Expression;
 
35
}
 
36
 
 
37
class OperatorsModel;
 
38
class QKeyEvent;
 
39
 
 
40
/**
 
41
*       The expression edit widget is the one where we will input our expressions.
 
42
*       
 
43
*       @author Aleix Pol i Gonzalez <aleixpol@kde.org>  
 
44
*/
 
45
 
 
46
class ANALITZAGUI_EXPORT ExpressionEdit : public QPlainTextEdit
 
47
{
 
48
        Q_OBJECT
 
49
        public:
 
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.
 
53
                */
 
54
                explicit ExpressionEdit(QWidget *parent = 0, AlgebraHighlighter::Mode ini=AlgebraHighlighter::Autodetect);
 
55
                
 
56
                /** Destructor. */
 
57
                ~ExpressionEdit();
 
58
                
 
59
                /** Returns the ExpressionEdit input mode. */
 
60
                AlgebraHighlighter::Mode mode() { return m_highlight->mode(); }
 
61
                
 
62
                /** Sets the ExpressionEdit input mode. */
 
63
                void setMode(AlgebraHighlighter::Mode en);
 
64
                
 
65
                /** Sets whether autocompletion will be used. */
 
66
                void setAutocomplete(bool a);
 
67
                
 
68
                /** Returns whether autocompletion will be used. */
 
69
                bool autocomplete();
 
70
                
 
71
                /** Returns whether there is MathML on the widget. */
 
72
                bool isMathML() const;
 
73
                
 
74
                /** Sets an Analyzer @p in module associated to the ExpressionEdit. It is used to autocomplete variables. */
 
75
                void setAnalitza(Analitza::Analyzer* in);
 
76
                
 
77
                /** Returns the expression string that we have. */
 
78
                QString text() const { return this->toPlainText();}
 
79
                
 
80
                /** Sets the expression string @p str we have. */
 
81
                void setText(const QString &str) { setPlainText(str);}
 
82
                
 
83
                /** Sets whether it is correct. Changes the background color. */
 
84
                void setCorrect(bool cor);
 
85
                
 
86
                /** Checks whether it has been set to correct. */
 
87
                bool isCorrect() const { return m_correct; }
 
88
                
 
89
                /** Sets the string @p ans that will be entered when an operator is pressed. */
 
90
                void setAns(const QString &ans) { m_ans=ans; }
 
91
                
 
92
                /** Returns the string that will be entered when the first operator is pressed. */
 
93
                QString ans() const { return m_ans; }
 
94
                
 
95
                /** Sets an expression to the input box. */
 
96
                void setExpression(const Analitza::Expression& e);
 
97
                
 
98
                /** Returns the expression we have in the text. */
 
99
                Analitza::Expression expression() const;
 
100
                
 
101
                /** Sets the @p examples to be shown in the context menu */
 
102
                void setExamples(const QStringList& ex) { m_examples=ex; }
 
103
        public slots:
 
104
                
 
105
                /** Inserts @p text text where the cursor is and selects it */
 
106
                void insertText(const QString& text);
 
107
                
 
108
        private slots:
 
109
                void showSimplified();
 
110
                void cursorMov();
 
111
                void updateCompleter();
 
112
                void setActionText(QAction* text);
 
113
                
 
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);
 
116
                
 
117
                /** Tries to complete the currently edited word with the @p word. */
 
118
                void completed(const QString &word);
 
119
                
 
120
                /** Sets the Mode to MathML */
 
121
                void toMathML() { setMode(AlgebraHighlighter::MathML); }
 
122
                
 
123
                /** Sets the Mode to Expression */
 
124
                void toExpression() { setMode(AlgebraHighlighter::Expression); }
 
125
                
 
126
                /** Simplify the current expression. */
 
127
                void simplify();
 
128
                
 
129
                /** Is the execution function, when return is pressed. */
 
130
                void returnP(); //FIXME: Change my name please
 
131
                
 
132
        signals:
 
133
                /** Emits that a return has been pressed. */
 
134
                void returnPressed();
 
135
                
 
136
                /** Deprecated. */
 
137
                void signalHelper(QString);
 
138
                
 
139
        protected:
 
140
                /** Inherited from QTextEdit, just deals with the menu. */
 
141
                void contextMenuEvent(QContextMenuEvent * e);
 
142
        
 
143
        private:
 
144
                bool returnPress();
 
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 );
 
150
                
 
151
                void removenl();
 
152
                void keyPressEvent(QKeyEvent * e);
 
153
                
 
154
                QLabel *m_helptip;
 
155
                AlgebraHighlighter *m_highlight;
 
156
                
 
157
                int m_histPos;
 
158
                QStringList m_history;
 
159
                
 
160
                Analitza::Analyzer *a;
 
161
                bool m_correct;
 
162
                QString m_ans;
 
163
                QCompleter *m_completer;
 
164
                OperatorsModel *m_ops;
 
165
                
 
166
                QStringList m_examples;
 
167
                QTimer* m_hideHelpTip;
 
168
                int m_lineHeight;
 
169
};
 
170
 
 
171
#endif