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 <QtGui/QTextBrowser>
27 #include <QtGui/QPlainTextEdit>
28 #include <QtGui/QDialog>
29 #include <QtCore/QTimer>
30 #include <QtCore/QRegExp>
31 #include <QtGui/QLineEdit>
32 #include <QtGui/QCheckBox>
33 #include <QtGui/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;
46 class ExprControl;
48 
49 
50 class ExprEditor;
52 class ExprHighlighter;
53 class ExprPopupDoc;
54 
55 class ExprTextEdit : public QTextEdit
56 {
57  Q_OBJECT
58 
59  QToolTip* functionTip;
60  std::map<std::string,std::string> functionTooltips;
65  public:
66  QCompleter* completer;
68 
69 
70  public:
71  ExprTextEdit(QWidget* parent = 0);
72  ~ExprTextEdit();
73  void updateStyle();
74 
75  protected:
76  void showTip(const QString& string);
77  void hideTip();
78 
79  virtual void keyPressEvent(QKeyEvent* e);
80  void focusInEvent(QFocusEvent* e);
81  void focusOutEvent(QFocusEvent* e);
82  void mousePressEvent(QMouseEvent* event);
83  void mouseDoubleClickEvent(QMouseEvent* event);
84  void paintEvent(QPaintEvent* e);
85  void wheelEvent(QWheelEvent* e);
86  void contextMenuEvent(QContextMenuEvent* event);
87 
88  private slots:
89  void insertCompletion(const QString& completion);
90  signals:
91  void applyShortcut();
92  void nextError();
93 
94 };
95 
96 
97 class ExprEditor : public QWidget
98 {
99  Q_OBJECT
100 
101  public:
102  ExprEditor(QWidget* parent,ExprControlCollection* controls);
103  virtual ~ExprEditor();
104 
105  public slots:
106  void exprChanged();
107  void rebuildControls();
108  void controlChanged(int id);
109  void nextError();
110  void selectError();
111  void sendApply();
112  void sendPreview();
113  //void handlePreviewTimer();
114  signals:
115  void apply();
116  void preview();
117  public:
118  // Get the expression that is in the editor
119  std::string getExpr();
120  // Sets the expression that is in the editor
121  void setExpr(const std::string& expression,const bool apply=false);
122  // Append string
123  void appendStr(const std::string& str);
124  public slots:
125  // Insert string
126  void insertStr(const std::string& str);
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  private:
147  QListWidget* errorWidget;
148 
150  QTimer* previewTimer;
151 
152 
155 
156 };
157 
158 #endif
void insertCompletion(const QString &completion)
Definition: ExprEditor.cpp:388
QListWidget * errorWidget
Definition: ExprEditor.h:147
void updateCompleter()
Definition: ExprEditor.cpp:478
void apply()
void preview()
ExprPopupDoc * _tip
Definition: ExprEditor.h:63
void clearErrors()
Definition: ExprEditor.cpp:450
void mousePressEvent(QMouseEvent *event)
Definition: ExprEditor.cpp:238
ExprCompletionModel * completionModel
Definition: ExprEditor.h:67
void addError(const int startPos, const int endPos, const std::string &error)
Definition: ExprEditor.cpp:425
void showTip(const QString &string)
Definition: ExprEditor.cpp:369
void hideTip()
Definition: ExprEditor.cpp:383
void nextError()
ExprControlCollection * controls
Definition: ExprEditor.h:146
void wheelEvent(QWheelEvent *e)
Definition: ExprEditor.cpp:260
void applyShortcut()
void replaceExtras(const ExprCompletionModel &completer)
Definition: ExprEditor.cpp:473
void mouseDoubleClickEvent(QMouseEvent *event)
Definition: ExprEditor.cpp:244
For a multi line expression
Definition: userdoc.txt:571
std::map< std::string, std::string > functionTooltips
Definition: ExprEditor.h:60
QTimer * controlRebuildTimer
Definition: ExprEditor.h:149
void controlChanged(int id)
Definition: ExprEditor.cpp:75
void appendStr(const std::string &str)
Definition: ExprEditor.cpp:420
void exprChanged()
Definition: ExprEditor.cpp:174
void updateStyle()
Definition: ExprEditor.cpp:483
void nextError()
Definition: ExprEditor.cpp:443
virtual void keyPressEvent(QKeyEvent *e)
Definition: ExprEditor.cpp:269
virtual ~ExprEditor()
Definition: ExprEditor.cpp:90
void paintEvent(QPaintEvent *e)
Definition: ExprEditor.cpp:250
void sendPreview()
Definition: ExprEditor.cpp:169
QCompleter * completer
Definition: ExprEditor.h:66
void focusOutEvent(QFocusEvent *e)
Definition: ExprEditor.cpp:232
ExprEditor(QWidget *parent, ExprControlCollection *controls)
Definition: ExprEditor.cpp:99
QToolTip * functionTip
Definition: ExprEditor.h:59
bool _updatingText
Definition: ExprEditor.h:153
QTimer * previewTimer
Definition: ExprEditor.h:150
void sendApply()
Definition: ExprEditor.cpp:164
Base class for all controls for Expressions.
Definition: ExprControl.h:53
void clearExtraCompleters()
Definition: ExprEditor.cpp:457
void selectError()
Definition: ExprEditor.cpp:151
ExprHighlighter * highlighter
Definition: ExprEditor.h:61
ExprTextEdit * exprTe
Definition: ExprEditor.h:145
std::string getExpr()
Definition: ExprEditor.cpp:400
void registerExtraVariable(const std::string &name, const std::string &docString)
Definition: ExprEditor.cpp:468
ExprTextEdit(QWidget *parent=0)
Definition: ExprEditor.cpp:199
QStyle * lastStyleForHighlighter
Definition: ExprEditor.h:62
int errorHeight
Definition: ExprEditor.h:154
void rebuildControls()
Definition: ExprEditor.cpp:183
QAction * _popupEnabledAction
Definition: ExprEditor.h:64
void insertStr(const std::string &str)
Definition: ExprEditor.cpp:415
void contextMenuEvent(QContextMenuEvent *event)
Definition: ExprEditor.cpp:354
void focusInEvent(QFocusEvent *e)
Definition: ExprEditor.cpp:226
void registerExtraFunction(const std::string &name, const std::string &docString)
Definition: ExprEditor.cpp:463
void setExpr(const std::string &expression, const bool apply=false)
Definition: ExprEditor.cpp:405
void updateStyle()
Definition: ExprEditor.cpp:191