tahoma2d/toonz/sources/include/toonzqt/expressionfield.h

90 lines
2.1 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef EXPRESSIONFIELD_H
#define EXPRESSIONFIELD_H
#include "tgrammar.h"
#include <QWidget>
#include <QTextEdit>
#undef DVAPI
#undef DVVAR
#ifdef TOONZQT_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif
// forward declaration
class QPushButton;
class QCompleter;
class QListView;
class QModelIndex;
//=============================================================================
2016-06-15 18:43:10 +12:00
namespace DVGui {
2016-03-19 06:57:51 +13:00
//=============================================================================
/*! \class DVGui::ExpressionField
2016-06-15 18:43:10 +12:00
\brief The ExpressionField allows to edit expressions (i.e.
formulas as '34*(5-2)')
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
Inherits \b QWidget.
2016-03-19 06:57:51 +13:00
*/
class DVAPI ExpressionField final : public QTextEdit {
2016-06-15 18:43:10 +12:00
Q_OBJECT
bool m_editing;
const TSyntax::Grammar *m_grammar;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
class SyntaxHighlighter;
SyntaxHighlighter *m_syntaxHighlighter;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QListView *m_completerPopup;
int m_completerStartPos;
TSyntax::Grammar::Suggestions m_suggestions;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
ExpressionField(QWidget *parent = 0);
~ExpressionField();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setExpression(std::string expression);
std::string getExpression() const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setGrammar(const TSyntax::Grammar *grammar);
const TSyntax::Grammar *getGrammar() const { return m_grammar; }
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
void openCompleterPopup();
bool updateCompleterPopup();
void insertCompletion();
int computeSuggestions();
2016-03-19 06:57:51 +13:00
protected:
2016-06-19 20:06:29 +12:00
bool event(QEvent *e) override;
void keyPressEvent(QKeyEvent *e) override;
void focusInEvent(QFocusEvent *e) override;
void focusOutEvent(QFocusEvent *e) override;
void showEvent(QShowEvent *) override;
void hideEvent(QHideEvent *) override;
bool eventFilter(QObject *obj, QEvent *e) override;
2016-03-19 06:57:51 +13:00
private slots:
2016-06-15 18:43:10 +12:00
void onTextChanged();
void onCursorPositionChanged();
void insertCompletion(const QModelIndex &index);
2016-03-19 06:57:51 +13:00
signals:
2016-06-15 18:43:10 +12:00
void expressionChanged();
2016-03-19 06:57:51 +13:00
};
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
} // namespace DVGui
2016-03-19 06:57:51 +13:00
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
#endif // FILEFIELD_H