File indexing completed on 2024-05-12 16:36:08
0001 /* This file is part of the KDE project 0002 0003 Copyright 1999-2006 The KSpread Team <calligra-devel@kde.org> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 Boston, MA 02110-1301, USA. 0019 */ 0020 0021 0022 #ifndef CALLIGRA_SHEETS_FORMULA_EDITOR_HIGHLIGHTER 0023 #define CALLIGRA_SHEETS_FORMULA_EDITOR_HIGHLIGHTER 0024 0025 #include <QSyntaxHighlighter> 0026 0027 class QTextEdit; 0028 0029 namespace Calligra 0030 { 0031 namespace Sheets 0032 { 0033 class Selection; 0034 class Tokens; 0035 0036 /** 0037 * Colors cell references in formulas. Installed by CellEditor instances in 0038 * the constructor. 0039 */ 0040 class FormulaEditorHighlighter : public QSyntaxHighlighter 0041 { 0042 public: 0043 /** 0044 * Constructs a FormulaHighlighter to color-code cell references in a QTextEdit. 0045 * 0046 * @param textEdit The QTextEdit widget which the highlighter should operate on 0047 * @param selection The Selection object 0048 */ 0049 FormulaEditorHighlighter(QTextEdit* textEdit, Selection* selection); 0050 ~FormulaEditorHighlighter() override; 0051 0052 0053 /** 0054 * Called automatically by KTextEditor to highlight text when modified. 0055 */ 0056 void highlightBlock(const QString& text) override; 0057 /** 0058 * 0059 */ 0060 const Tokens& formulaTokens() const; 0061 /** 0062 * 0063 */ 0064 uint rangeCount() const; 0065 /** 0066 * Returns true if any of the ranges or cells in the Formula.have changed since the 0067 * last call to @ref FormulaEditorHighlighter::rangeChanged() 0068 */ 0069 bool rangeChanged() const; 0070 0071 /** 0072 * Sets the highlighter's range changed flag to false. 0073 */ 0074 void resetRangeChanged(); 0075 0076 0077 0078 protected: 0079 /** 0080 * Returns the position of the brace matching the one found at position pos 0081 */ 0082 int findMatchingBrace(int pos); 0083 /** 0084 * Examines the brace (Token::LeftPar or Token::RightPar) operator token at the given index in the token vector 0085 * ( as returned by formulaTokens() ) and if the cursor is next to it, the token plus any matching brace will be highlighted 0086 */ 0087 void handleBrace(uint index); 0088 0089 private: 0090 Q_DISABLE_COPY(FormulaEditorHighlighter) 0091 0092 class Private; 0093 Private * const d; 0094 }; 0095 0096 } // namespace Sheets 0097 } // namespace Calligra 0098 0099 #endif // CALLIGRA_SHEETS_FORMULA_EDITOR_HIGHLIGHTER