SeExpr
ExprShortEdit.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 ExprShortEdit.h
18 * @brief This provides an expression editor for SeExpr syntax with auto ui features
19 * @author aselle
20 */
21 
22 
23 #ifndef ExprShortEditUI_h
24 #define ExprShortEditUI_h
25 
26 #include <vector>
27 #include <string>
28 
29 #include <QtGui/QWidget>
30 #include <QtGui/QTextEdit>
31 #include <QtGui/QWheelEvent>
32 
34 class QToolButton;
35 class QVBoxLayout;
36 class QHBoxLayout;
37 class QTextEdit;
38 class ExprHighlighter;
39 class QCompleter;
41 class ExprShortTextEdit;
42 class QLabel;
43 class ExprPopupDoc;
44 class ExprDialog;
45 
46 class ExprShortEdit : public QWidget
47 {
48  Q_OBJECT
49 
50 protected:
52  QToolButton* editDetail;
55  QVBoxLayout* vboxlayout;
56  QHBoxLayout* hboxlayout;
57  QLabel* error;
58  std::string _context;
59  std::string _searchPath;
61 public:
62  ExprShortEdit(QWidget* parent, bool expanded = true, bool applyOnSelect = true);
63  virtual ~ExprShortEdit();
64 
65  // Gets the string that is in the edit widget
66  std::string getExpressionString() const;
67  QString getExpression() const;
68  // Sets the string that is in the edit widget
69  void setExpressionString(const std::string& expression);
70  // Removes all extra completion symbols
71  void clearExtraCompleters();
72  // Registers an extra function and associated do cstring
73  void registerExtraFunction(const std::string& name,const std::string& docString);
74  // Register an extra variable (i.e. $P, or $u, something provided by resolveVar)
75  void registerExtraVariable(const std::string& name,const std::string& docString);
76  // Updates the completion widget, must call after registering any new functions/variables
77  void updateCompleter();
78  // Hides the expression part of the interface
79  void setSimple(bool enabled);
80  // Set a menu on the "details" button
81  void setDetailsMenu(QMenu *menu);
82  // Set a colon-delimited path variable for finding expressions
83  void setSearchPath(const QString& context, const QString& path);
84  // Set line wrap mode on the text edit
85  void setLineWrapMode(QTextEdit::LineWrapMode mode);
86  // Set the vertical scrollbar policy -- set to Qt::ScrollBarAlwaysOff to
87  // disable it
88  void setVerticalScrollBarPolicy(Qt::ScrollBarPolicy policy);
89  // Set the horizontal scrollbar policy -- set to Qt::ScrollBarAlwaysOff to
90  // disable it
91  void setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy policy);
92  // Open the details window and open the Nth editor
93  // Pass -1 to not show the editor
94  void showDetails(int idx);
95 
96  virtual QSize sizeHint() const{return QSize(400, 50);}
97  virtual void hideErrors(bool hidden, const std::string &err);
98 
99  // Exposed via Python
100  QToolButton* expandButton;
102 
103 protected:
104  void checkErrors();
105 
106 protected slots:
107  virtual void detailPressed();
108  virtual void expandPressed();
109  virtual void textFinished();
110  virtual void handleTextEdited();
111  virtual void controlChanged(int id);
112  virtual void rebuildControls();
113  virtual void expressionApplied();
114  virtual void dialogClosed();
115 
116 signals:
117  void exprChanged();
118 };
119 
120 
121 class ExprShortTextEdit:public QTextEdit
122 {
123  Q_OBJECT;
124 
126 
127  bool editing;
128  QString savedText;
131 
132 public:
133  QCompleter* completer;
135 
136 
137  ExprShortTextEdit(QWidget* parent);
138 protected:
139  void showTip(const QString& string);
140  void hideTip();
141 
142  void paintEvent(QPaintEvent* e);
143  virtual void keyPressEvent(QKeyEvent* e);
144  virtual void focusInEvent(QFocusEvent* e);
145  virtual void focusOutEvent(QFocusEvent* e);
146  virtual void mousePressEvent(QMouseEvent* event);
147  virtual void mouseDoubleClickEvent(QMouseEvent* event);
148  virtual void wheelEvent(QWheelEvent* e) { e->ignore(); }
149 
150  void setColor(bool editing);
151  void finishEdit();
152 signals:
153  void editingFinished();
154 private slots:
155  void insertCompletion(const QString& completion);
156 
157 };
158 
159 #endif
QCompleter * completer
void exprChanged()
virtual void expandPressed()
virtual void hideErrors(bool hidden, const std::string &err)
std::string _searchPath
Definition: ExprShortEdit.h:59
void showDetails(int idx)
void showTip(const QString &string)
QTimer * controlRebuildTimer
Definition: ExprShortEdit.h:51
void paintEvent(QPaintEvent *e)
void updateCompleter()
virtual void wheelEvent(QWheelEvent *e)
void clearExtraCompleters()
virtual void textFinished()
ExprShortTextEdit(QWidget *parent)
virtual void rebuildControls()
virtual void detailPressed()
void setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy policy)
void setSimple(bool enabled)
void registerExtraFunction(const std::string &name, const std::string &docString)
QHBoxLayout * hboxlayout
Definition: ExprShortEdit.h:56
ExprHighlighter * highlighter
void setDetailsMenu(QMenu *menu)
For a multi line expression
Definition: userdoc.txt:571
void setVerticalScrollBarPolicy(Qt::ScrollBarPolicy policy)
std::string _context
Definition: ExprShortEdit.h:58
void insertCompletion(const QString &completion)
QVBoxLayout * vboxlayout
Definition: ExprShortEdit.h:55
virtual QSize sizeHint() const
Definition: ExprShortEdit.h:96
ExprPopupDoc * _tip
ExprControlCollection * controls
Definition: ExprShortEdit.h:53
void setLineWrapMode(QTextEdit::LineWrapMode mode)
virtual void mousePressEvent(QMouseEvent *event)
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
Definition: userdoc.txt:456
virtual void dialogClosed()
void setExpressionString(const std::string &expression)
std::string getExpressionString() const
virtual void keyPressEvent(QKeyEvent *e)
ExprDialog * _dialog
Definition: ExprShortEdit.h:54
QToolButton * expandButton
ExprShortEdit(QWidget *parent, bool expanded=true, bool applyOnSelect=true)
QString getExpression() const
virtual void handleTextEdited()
virtual ~ExprShortEdit()
QLabel * error
Definition: ExprShortEdit.h:57
virtual void controlChanged(int id)
virtual void expressionApplied()
QToolButton * editDetail
Definition: ExprShortEdit.h:52
QStyle * lastStyleForHighlighter
virtual void focusOutEvent(QFocusEvent *e)
ExprShortTextEdit * edit
void setSearchPath(const QString &context, const QString &path)