21 #include <QtGui/QLineEdit>
22 #include <QtGui/QPushButton>
23 #include <QtGui/QToolButton>
24 #include <QtGui/QHBoxLayout>
25 #include <QtGui/QIcon>
26 #include <QtGui/QCompleter>
27 #include <QtGui/QTreeView>
28 #include <QtGui/QScrollBar>
29 #include <QtGui/QToolTip>
30 #include <QtGui/QLabel>
100 , _applyOnSelect(applyOnSelect)
112 error =
new QLabel();
114 error->setHidden(
true );
119 if (expanded)
expandButton->setArrowType( Qt::DownArrow );
123 QToolButton* button =
new QToolButton();
125 button->setIcon( QIcon(QPixmap(
sum_xpm)) );
240 edit->setText(QString(expression.c_str()));
249 return edit->toPlainText();
262 edit->setText(newText);
308 error->setHidden(hidden);
310 error->setToolTip(QString::fromStdString(err));
317 edit->setHidden(enabled);
329 edit->setVerticalScrollBarPolicy(policy);
334 edit->setHorizontalScrollBarPolicy( policy );
339 edit->setLineWrapMode( mode );
343 :QTextEdit(parent),editing(false),_tip(0)
346 setMaximumHeight(25);
356 QTreeView* treePopup=
new QTreeView;
358 treePopup->setRootIsDecorated(
false);
359 treePopup->setMinimumWidth(300);
360 treePopup->setMinimumHeight(50);
361 treePopup->setItemsExpandable(
true);
364 completer->setCompletionMode(QCompleter::PopupCompletion);
365 completer->setCaseSensitivity(Qt::CaseInsensitive);
366 QObject::connect(
completer,SIGNAL(activated(
const QString&)),
this,
375 QTextEdit::focusInEvent(e);
382 QTextCursor newCursor=textCursor();
383 newCursor.clearSelection();
384 setTextCursor(newCursor);
387 QTextEdit::focusOutEvent(e);
393 QTextEdit::mousePressEvent(event);
399 QTextEdit::mouseDoubleClickEvent(event);
408 QTextEdit::paintEvent(e);
419 case Qt::Key_Enter:
case Qt::Key_Return:
case Qt::Key_Escape:
420 case Qt::Key_Tab:
case Qt::Key_Backtab:
428 if (e->key()==Qt::Key_Return || e->key()==Qt::Key_Enter){
432 }
else if (e->key()==Qt::Key_Escape){
437 }
else if(e->key()==Qt::Key_Tab){
438 QWidget::keyPressEvent(e);
449 bool isShortcut = ((e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_E);
451 QTextEdit::keyPressEvent(e);
454 const bool ctrlOrShift = e->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier);
455 if (!
completer || (ctrlOrShift && e->text().isEmpty()))
458 bool hasModifier=(e->modifiers()!=Qt::NoModifier) && !ctrlOrShift;
461 QTextCursor tc=textCursor();
462 tc.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor);
463 QString line=tc.selectedText();
466 static QRegExp completion(
"^(?:.*[^A-Za-z0-9_$])?((?:\\$[A-Za-z0-9_]*)|[A-Za-z]+[A-Za-z0-9_]*)$");
467 int index=completion.indexIn(line);
468 QString completionPrefix;
469 if(index != -1 && !line.contains(
'#')){
470 completionPrefix=completion.cap(1);
475 if(!isShortcut && (hasModifier || e->text().isEmpty() || completionPrefix.length()<1 || index==-1)){
480 if(completionPrefix!=
completer->completionPrefix()){
481 completer->setCompletionPrefix(completionPrefix);
486 QRect cr=cursorRect();
487 cr.setWidth(2*(
completer->popup()->sizeHintForColumn(0)+
completer->popup()->sizeHintForColumn(1)
488 +
completer->popup()->verticalScrollBar()->sizeHint().width()));
495 static QRegExp inFunction(
"^(?:.*[^A-Za-z0-9_$])?([A-Za-z0-9_]+)\\([^()]*$");
496 int index2=inFunction.indexIn(line);
498 QString functionName=inFunction.cap(1);
500 QString tip=
"<b>"+tips[0]+
"</b>";
501 for(
int i=1;i<tips.size();i++){
514 if(
string==
"")
return;
518 QRect cr=cursorRect();
520 cr.setWidth(cr.width()*3);
533 QTextCursor tc = textCursor();
534 int extra = completion.length() -
completer->completionPrefix().length();
535 tc.movePosition(QTextCursor::Left);
536 tc.movePosition(QTextCursor::EndOfWord);
537 tc.insertText(completion.right(extra));
538 if(completion[0]!=
'$') tc.insertText(
"(");
void setSearchPath(const QString &context, const QString &path)
virtual void expandPressed()
virtual void hideErrors(bool hidden, const std::string &err)
void setApplyOnSelect(bool on)
</pre >< h2 > Evaluating expressions</h2 > Evaluating an expression is pretty easy But before we can do that we need to make an instance< pre > GrapherExpr expr("x+x^2")
void addVariable(const QString &str, const QString &comment)
void showDetails(int idx)
void showTip(const QString &string)
QTimer * controlRebuildTimer
int numControls()
Number of controls.
std::vector< QString > local_variables
void paintEvent(QPaintEvent *e)
void clearExtraCompleters()
virtual void textFinished()
void setExpressionString(const std::string &str)
ExprShortTextEdit(QWidget *parent)
virtual void rebuildControls()
const std::string & parseError() const
virtual void detailPressed()
void addFunction(const QString &function, const QString &docString)
void setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy policy)
void setSimple(bool enabled)
void registerExtraFunction(const std::string &name, const std::string &docString)
ExprHighlighter * highlighter
std::string getExpressionString()
void replaceExtras(const ExprCompletionModel &completer)
void setDetailsMenu(QMenu *menu)
For a multi line expression
void setVerticalScrollBarPolicy(Qt::ScrollBarPolicy policy)
static const char * sum_xpm[]
void insertCompletion(const QString &completion)
The result is computed int int< br >< divstyle="margin-left:40px;"> Picks values randomly between loRange and hiRange based on supplied index(which is automatically hashed). 
bool rebuildControls(const QString &expressionText, std::vector< QString > &variables)
Rebuild the controls given the new expressionText. Return any local variables found.
ExprControlCollection * controls
void setLineWrapMode(QTextEdit::LineWrapMode mode)
virtual void mousePressEvent(QMouseEvent *event)
void updateText(const int id, QString &text)
Request new text, given taking into account control id's new values.
void registerExtraVariable(const std::string &name, const std::string &docString)
virtual void focusInEvent(QFocusEvent *e)
void setColor(bool editing)
virtual void mouseDoubleClickEvent(QMouseEvent *event)
ExprCompletionModel * completionModel
If a scalar is used in a vector context
virtual void dialogClosed()
void setExpressionString(const std::string &expression)
static const char * stop_xpm[]
std::string getExpressionString() const
virtual void keyPressEvent(QKeyEvent *e)
QToolButton * expandButton
ExprShortEdit(QWidget *parent, bool expanded=true, bool applyOnSelect=true)
QString getExpression() const
virtual void handleTextEdited()
void fixStyle(const QPalette &palette)
virtual void controlChanged(int id)
virtual void expressionApplied()
QString getDocString(const QString &s)
QStyle * lastStyleForHighlighter
virtual void focusOutEvent(QFocusEvent *e)
void setSearchPath(const QString &context, const QString &path)