SeExpr

ExprEditor.h
Go to the documentation of this file.
1 /*
2 * Copyright Disney Enterprises, Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License
6 * and the following modification to it: Section 6 Trademarks.
7 * deleted and replaced with:
8 *
9 * 6. Trademarks. This License does not grant permission to use the
10 * trade names, trademarks, service marks, or product names of the
11 * Licensor and its affiliates, except as required for reproducing
12 * the content of the NOTICE file.
13 *
14 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * @file ExprEditor.h
18 * @brief This provides an expression editor for SeExpr syntax with auto ui features
19 * @author aselle
20 */
21 #ifndef ExprEditor_h
22 #define ExprEditor_h
23
24 #include <vector>
25
26 #include <QTextBrowser>
27 #include <QPlainTextEdit>
28 #include <QDialog>
29 #include <QTimer>
30 #include <QRegExp>
31 #include <QLineEdit>
32 #include <QCheckBox>
33 #include <QSlider>
34
35 class QLabel;
36 class QPushButton;
37 class QLineEdit;
38 class QMouseEvent;
39 class QPaintEvent;
40 class QKeyEvent;
41 class QCompleter;
42 class QToolTip;
43 class QListWidget;
44 class QListWidgetItem;
45 class ExprCompletionModel;
46 class ExprControl;
47 class ExprControlCollection;
48
49 class ExprEditor;
50 class ExprCompletionModel;
51 class ExprHighlighter;
52 class ExprPopupDoc;
53
54 class ExprTextEdit : public QTextEdit {
55 Q_OBJECT
56
57 QToolTip* functionTip;
58 std::map<std::string, std::string> functionTooltips;
59 ExprHighlighter* highlighter;
60 QStyle* lastStyleForHighlighter;
61 ExprPopupDoc* _tip;
62 QAction* _popupEnabledAction;
63
64 public:
65 QCompleter* completer;
66 ExprCompletionModel* completionModel;
67
68 public:
69 ExprTextEdit(QWidget* parent = 0);
70 ~ExprTextEdit();
71 void updateStyle();
72
73 protected:
74 void showTip(const QString& string);
75 void hideTip();
76
77 virtual void keyPressEvent(QKeyEvent* e);
78 void focusInEvent(QFocusEvent* e);
79 void focusOutEvent(QFocusEvent* e);
80 void mousePressEvent(QMouseEvent* event);
81 void mouseDoubleClickEvent(QMouseEvent* event);
82 void paintEvent(QPaintEvent* e);
83 void wheelEvent(QWheelEvent* e);
84 void contextMenuEvent(QContextMenuEvent* event);
85
86 private
87 slots:
88 void insertCompletion(const QString& completion);
89 signals:
90 void applyShortcut();
91 void nextError();
92 };
93
94 class ExprEditor : public QWidget {
95 Q_OBJECT
96
97 public:
98 ExprEditor(QWidget* parent, ExprControlCollection* controls);
99 virtual ~ExprEditor();
100
101 public
102 slots:
103 void exprChanged();
104 void rebuildControls();
105 void controlChanged(int id);
106 void nextError();
107 void selectError();
108 void sendApply();
109 void sendPreview();
110 // void handlePreviewTimer();
111 signals:
112 void apply();
113 void preview();
114
115 public:
116 // Get the expression that is in the editor
117 std::string getExpr();
118 // Sets the expression that is in the editor
119 void setExpr(const std::string& expression, const bool apply = false);
120 // Append string
121 void appendStr(const std::string& str);
122 public
123 slots:
124 // Insert string
125 void insertStr(const std::string& str);
126
127 public:
128 // Adds an error and its associated position
129 void addError(const int startPos, const int endPos, const std::string& error);
130 // Removes all errors and hides the completion widget
131 void clearErrors();
132 // Removes all extra completion symbols
133 void clearExtraCompleters();
134 // Registers an extra function and associated do cstring
135 void registerExtraFunction(const std::string& name, const std::string& docString);
136 // Register an extra variable (i.e. $P, or $u, something provided by resolveVar)
137 void registerExtraVariable(const std::string& name, const std::string& docString);
138 // Replace extras
139 void replaceExtras(const ExprCompletionModel& completer);
140 // Updates the completion widget, must call after registering any new functions/variables
141 void updateCompleter();
142 // Updates style
143 void updateStyle();
144
145 private:
146 ExprTextEdit* exprTe;
147 ExprControlCollection* controls;
148 QListWidget* errorWidget;
149
150 QTimer* controlRebuildTimer;
151 QTimer* previewTimer;
152
153 bool _updatingText;
154 int errorHeight;
155 };
156
157 #endif
ExprEditor::clearErrors
void clearErrors()
Definition: ExprEditor.cpp:411
ExprTextEdit::~ExprTextEdit
~ExprTextEdit()
Definition: ExprEditor.cpp:90
ExprEditor
Definition: ExprEditor.h:94
ExprEditor::selectError
void selectError()
Definition: ExprEditor.cpp:141
ExprEditor::replaceExtras
void replaceExtras(const ExprCompletionModel &completer)
Definition: ExprEditor.cpp:430
ExprTextEdit::hideTip
void hideTip()
Definition: ExprEditor.cpp:358
ExprEditor::controlRebuildTimer
QTimer * controlRebuildTimer
Definition: ExprEditor.h:150
ExprEditor::~ExprEditor
virtual ~ExprEditor()
Definition: ExprEditor.cpp:85
ExprEditor::registerExtraVariable
void registerExtraVariable(const std::string &name, const std::string &docString)
Definition: ExprEditor.cpp:426
ExprEditor::errorHeight
int errorHeight
Definition: ExprEditor.h:154
ExprEditor::appendStr
void appendStr(const std::string &str)
Definition: ExprEditor.cpp:386
ExprEditor::exprChanged
void exprChanged()
Definition: ExprEditor.cpp:157
ExprEditor::nextError
void nextError()
Definition: ExprEditor.cpp:405
ExprTextEdit::highlighter
ExprHighlighter * highlighter
Definition: ExprEditor.h:59
ExprTextEdit::lastStyleForHighlighter
QStyle * lastStyleForHighlighter
Definition: ExprEditor.h:60
ExprEditor::sendApply
void sendApply()
Definition: ExprEditor.cpp:153
ExprEditor::sendPreview
void sendPreview()
Definition: ExprEditor.cpp:155
ExprControlCollection
Definition: ExprControlCollection.h:81
ExprTextEdit::_popupEnabledAction
QAction * _popupEnabledAction
Definition: ExprEditor.h:62
ExprTextEdit::contextMenuEvent
void contextMenuEvent(QContextMenuEvent *event)
Definition: ExprEditor.cpp:329
ExprEditor::apply
void apply()
ExprEditor::ExprEditor
ExprEditor(QWidget *parent, ExprControlCollection *controls)
Definition: ExprEditor.cpp:92
ExprTextEdit::updateStyle
void updateStyle()
Definition: ExprEditor.cpp:172
ExprTextEdit
Definition: ExprEditor.h:54
ExprEditor::previewTimer
QTimer * previewTimer
Definition: ExprEditor.h:151
ExprEditor::exprTe
ExprTextEdit * exprTe
Definition: ExprEditor.h:146
ExprEditor::clearExtraCompleters
void clearExtraCompleters()
Definition: ExprEditor.cpp:417
ExprTextEdit::completionModel
ExprCompletionModel * completionModel
Definition: ExprEditor.h:66
ExprEditor::preview
void preview()
ExprEditor::rebuildControls
void rebuildControls()
Definition: ExprEditor.cpp:165
ExprTextEdit::wheelEvent
void wheelEvent(QWheelEvent *e)
Definition: ExprEditor.cpp:232
ExprEditor::addError
void addError(const int startPos, const int endPos, const std::string &error)
Definition: ExprEditor.cpp:388
ExprEditor::insertStr
void insertStr(const std::string &str)
Definition: ExprEditor.cpp:384
ExprEditor::getExpr
std::string getExpr()
Definition: ExprEditor.cpp:373
ExprEditor::registerExtraFunction
void registerExtraFunction(const std::string &name, const std::string &docString)
Definition: ExprEditor.cpp:422
ExprTextEdit::insertCompletion
void insertCompletion(const QString &completion)
Definition: ExprEditor.cpp:362
ExprTextEdit::functionTooltips
std::map< std::string, std::string > functionTooltips
Definition: ExprEditor.h:58
ExprPopupDoc
Definition: ExprPopupDoc.h:23
ExprTextEdit::ExprTextEdit
ExprTextEdit(QWidget *parent=0)
Definition: ExprEditor.cpp:179
ExprTextEdit::keyPressEvent
virtual void keyPressEvent(QKeyEvent *e)
Definition: ExprEditor.cpp:242
ExprEditor::controls
ExprControlCollection * controls
Definition: ExprEditor.h:147
ExprEditor::setExpr
void setExpr(const std::string &expression, const bool apply=false)
Definition: ExprEditor.cpp:375
ExprTextEdit::paintEvent
void paintEvent(QPaintEvent *e)
Definition: ExprEditor.cpp:223
ExprEditor::controlChanged
void controlChanged(int id)
Definition: ExprEditor.cpp:71
ExprCompletionModel
Definition: ExprCompletionModel.h:30
ExprEditor::updateStyle
void updateStyle()
Definition: ExprEditor.cpp:434
ExprEditor::errorWidget
QListWidget * errorWidget
Definition: ExprEditor.h:148
ExprEditor::updateCompleter
void updateCompleter()
Definition: ExprEditor.cpp:432
ExprHighlighter
Definition: ExprHighlighter.h:27
ExprTextEdit::focusInEvent
void focusInEvent(QFocusEvent *e)
Definition: ExprEditor.cpp:203
ExprTextEdit::showTip
void showTip(const QString &string)
Definition: ExprEditor.cpp:342
ExprTextEdit::_tip
ExprPopupDoc * _tip
Definition: ExprEditor.h:61
ExprTextEdit::focusOutEvent
void focusOutEvent(QFocusEvent *e)
Definition: ExprEditor.cpp:208
ExprTextEdit::functionTip
QToolTip * functionTip
Definition: ExprEditor.h:57
ExprTextEdit::completer
QCompleter * completer
Definition: ExprEditor.h:65
ExprControl
Base class for all controls for Expressions.
Definition: ExprControl.h:54
ExprTextEdit::mousePressEvent
void mousePressEvent(QMouseEvent *event)
Definition: ExprEditor.cpp:213
ExprTextEdit::nextError
void nextError()
ExprTextEdit::applyShortcut
void applyShortcut()
ExprEditor::_updatingText
bool _updatingText
Definition: ExprEditor.h:153
ExprTextEdit::mouseDoubleClickEvent
void mouseDoubleClickEvent(QMouseEvent *event)
Definition: ExprEditor.cpp:218
expression
For a multi line expression
Definition: userdoc.txt:551