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