00001 /* 00002 * (c) Disney Enterprises, Inc. All rights reserved. 00003 * 00004 * This file is licensed under the terms of the Microsoft Public License (MS-PL) 00005 * as defined at: http://opensource.org/licenses/MS-PL. 00006 * 00007 * A complete copy of this license is included in this distribution as the file 00008 * LICENSE. 00009 * 00010 * @file SeExprEditor.h 00011 * @brief This provides an expression editor for SeExpr syntax with auto ui features 00012 * @author aselle 00013 */ 00014 #ifndef SeExprEditor_h 00015 #define SeExprEditor_h 00016 00017 #include <vector> 00018 00019 #include <QtGui/QTextBrowser> 00020 #include <QtGui/QPlainTextEdit> 00021 #include <QtGui/QDialog> 00022 #include <QtCore/QTimer> 00023 #include <QtCore/QRegExp> 00024 #include <QtGui/QLineEdit> 00025 #include <QtGui/QCheckBox> 00026 #include <QtGui/QSlider> 00027 00028 class QLabel; 00029 class QPushButton; 00030 class QLineEdit; 00031 class QMouseEvent; 00032 class QPaintEvent; 00033 class QKeyEvent; 00034 class QCompleter; 00035 class QToolTip; 00036 class QListWidget; 00037 class QListWidgetItem; 00038 class SeExprEdCompletionModel; 00039 class SeExprEdControl; 00040 class SeExprEdControlCollection; 00041 00042 00043 class SeExprEditor; 00044 class SeExprCompletionModel; 00045 class SeExprEdHighlighter; 00046 class SeExprEdPopupDocumentation; 00047 00048 class SeExprEdExpressionTextEdit : public QTextEdit 00049 { 00050 Q_OBJECT 00051 00052 QToolTip* functionTip; 00053 std::map<std::string,std::string> functionTooltips; 00054 SeExprEdHighlighter* highlighter; 00055 QStyle* lastStyleForHighlighter; 00056 SeExprEdPopupDocumentation* _tip; 00057 QAction* _popupEnabledAction; 00058 public: 00059 QCompleter* completer; 00060 SeExprEdCompletionModel* completionModel; 00061 00062 00063 public: 00064 SeExprEdExpressionTextEdit(QWidget* parent = 0); 00065 ~SeExprEdExpressionTextEdit(); 00066 void updateStyle(); 00067 00068 protected: 00069 void showTip(const QString& string); 00070 void hideTip(); 00071 00072 virtual void keyPressEvent(QKeyEvent* e); 00073 void focusInEvent(QFocusEvent* e); 00074 void focusOutEvent(QFocusEvent* e); 00075 void mousePressEvent(QMouseEvent* event); 00076 void mouseDoubleClickEvent(QMouseEvent* event); 00077 void paintEvent(QPaintEvent* e); 00078 void wheelEvent(QWheelEvent* e); 00079 void contextMenuEvent(QContextMenuEvent* event); 00080 00081 private slots: 00082 void insertCompletion(const QString& completion); 00083 signals: 00084 void applyShortcut(); 00085 void nextError(); 00086 00087 }; 00088 00089 00090 class SeExprEditor : public QWidget 00091 { 00092 Q_OBJECT 00093 00094 public: 00095 SeExprEditor(QWidget* parent,SeExprEdControlCollection* controls); 00096 virtual ~SeExprEditor(); 00097 00098 public slots: 00099 void exprChanged(); 00100 void rebuildControls(); 00101 void controlChanged(int id); 00102 void nextError(); 00103 void selectError(); 00104 void sendApply(); 00105 void sendPreview(); 00106 //void handlePreviewTimer(); 00107 signals: 00108 void apply(); 00109 void preview(); 00110 public: 00111 // Get the expression that is in the editor 00112 std::string getExpr(); 00113 // Sets the expression that is in the editor 00114 void setExpr(const std::string& expression,const bool apply=false); 00115 // Append string 00116 void appendStr(const std::string& str); 00117 public slots: 00118 // Insert string 00119 void insertStr(const std::string& str); 00120 public: 00121 // Adds an error and its associated position 00122 void addError(const int startPos,const int endPos,const std::string& error); 00123 // Removes all errors and hides the completion widget 00124 void clearErrors(); 00125 // Removes all extra completion symbols 00126 void clearExtraCompleters(); 00127 // Registers an extra function and associated do cstring 00128 void registerExtraFunction(const std::string& name,const std::string& docString); 00129 // Register an extra variable (i.e. $P, or $u, something provided by resolveVar) 00130 void registerExtraVariable(const std::string& name,const std::string& docString); 00131 // Replace extras 00132 void replaceExtras(const SeExprEdCompletionModel& completer); 00133 // Updates the completion widget, must call after registering any new functions/variables 00134 void updateCompleter(); 00135 // Updates style 00136 void updateStyle(); 00137 private: 00138 SeExprEdExpressionTextEdit* exprTe; 00139 SeExprEdControlCollection* controls; 00140 QListWidget* errorWidget; 00141 00142 QTimer* controlRebuildTimer; 00143 QTimer* previewTimer; 00144 00145 00146 bool _updatingText; 00147 int errorHeight; 00148 00149 }; 00150 00151 #endif