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