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 SeExprEdShortEdit.h 00011 * @brief This provides an exression editor for SeExpr syntax with auto ui features 00012 * @author aselle 00013 */ 00014 00015 00016 #ifndef SeExprEdShortEditor_h 00017 #define SeExprEdShortEditor_h 00018 00019 #include <vector> 00020 #include <string> 00021 00022 #include <QtGui/QWidget> 00023 #include <QtGui/QTextEdit> 00024 #include <QtGui/QWheelEvent> 00025 00026 class SeExprEdControlCollection; 00027 class QToolButton; 00028 class QVBoxLayout; 00029 class QHBoxLayout; 00030 class QTextEdit; 00031 class SeExprEdHighlighter; 00032 class QCompleter; 00033 class SeExprEdCompletionModel; 00034 class SeExprEdShortTextEdit; 00035 class QLabel; 00036 class SeExprEdPopupDocumentation; 00037 00038 class SeExprEdShortEdit : public QWidget 00039 { 00040 Q_OBJECT 00041 00042 protected: 00043 QTimer* controlRebuildTimer; 00044 QToolButton* editDetail; 00045 SeExprEdControlCollection* controls; 00046 QVBoxLayout* vboxlayout; 00047 QHBoxLayout* hboxlayout; 00048 QLabel* error; 00049 std::string _context; 00050 std::string _searchPath; 00051 public: 00052 SeExprEdShortEdit(QWidget* parent, bool expanded = true); 00053 virtual ~SeExprEdShortEdit(); 00054 00055 // Gets the string that is in the edit widget 00056 std::string getExpressionString() const; 00057 QString getExpression() const; 00058 // Sets the string that is in the edit widget 00059 void setExpressionString(const std::string& expression); 00060 // Removes all extra completion symbols 00061 void clearExtraCompleters(); 00062 // Registers an extra function and associated do cstring 00063 void registerExtraFunction(const std::string& name,const std::string& docString); 00064 // Register an extra variable (i.e. $P, or $u, something provided by resolveVar) 00065 void registerExtraVariable(const std::string& name,const std::string& docString); 00066 // Updates the completion widget, must call after registering any new functions/variables 00067 void updateCompleter(); 00068 // Hides the expression part of the interface 00069 void setSimple(bool enabled); 00070 // Set a menu on the "details" button 00071 void setDetailsMenu(QMenu *menu); 00072 // Set a colon-delimited path variable for finding expressions 00073 void setSearchPath(const QString& context, const QString& path); 00074 // Set the vertical scrollbar policy -- set to Qt::ScrollBarAlwaysOff to 00075 // disable it 00076 void setVerticalScrollBarPolicy(Qt::ScrollBarPolicy policy); 00077 // Open the details window and open the Nth editor 00078 // Pass -1 to not show the editor 00079 int showDetails(int idx); 00080 00081 virtual QSize sizeHint() const{return QSize(400, 50);} 00082 virtual void hideErrors(bool hidden, const std::string &err); 00083 00084 // Exposed via Python 00085 QToolButton* expandButton; 00086 SeExprEdShortTextEdit* edit; 00087 00088 protected: 00089 void checkErrors(); 00090 00091 protected slots: 00092 virtual void detailPressed(); 00093 virtual void expandPressed(); 00094 virtual void textFinished(); 00095 virtual void handleTextEdited(); 00096 virtual void controlChanged(int id); 00097 virtual void rebuildControls(); 00098 00099 signals: 00100 void exprChanged(); 00101 }; 00102 00103 00104 class SeExprEdShortTextEdit:public QTextEdit 00105 { 00106 Q_OBJECT; 00107 00108 SeExprEdHighlighter* highlighter; 00109 00110 bool editing; 00111 QString savedText; 00112 SeExprEdPopupDocumentation* _tip; 00113 QStyle* lastStyleForHighlighter; 00114 00115 public: 00116 QCompleter* completer; 00117 SeExprEdCompletionModel* completionModel; 00118 00119 00120 SeExprEdShortTextEdit(QWidget* parent); 00121 protected: 00122 void showTip(const QString& string); 00123 void hideTip(); 00124 00125 void paintEvent(QPaintEvent* e); 00126 virtual void keyPressEvent(QKeyEvent* e); 00127 virtual void focusInEvent(QFocusEvent* e); 00128 virtual void focusOutEvent(QFocusEvent* e); 00129 virtual void mousePressEvent(QMouseEvent* event); 00130 virtual void mouseDoubleClickEvent(QMouseEvent* event); 00131 virtual void wheelEvent(QWheelEvent* e) { e->ignore(); } 00132 00133 void setColor(bool editing); 00134 void finishEdit(); 00135 signals: 00136 void editingFinished(); 00137 private slots: 00138 void insertCompletion(const QString& completion); 00139 00140 }; 00141 00142 #endif