File indexing completed on 2024-05-12 16:36:02
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_CELL_EDITOR 0023 #define CALLIGRA_SHEETS_CELL_EDITOR 0024 0025 #include <KCompletion> 0026 #include <ktextedit.h> 0027 0028 #include "sheets_common_export.h" 0029 #include "CellEditorBase.h" 0030 0031 #include <QCompleter> 0032 #include <QAbstractItemModel> 0033 #include <QThread> 0034 #include <QHash> 0035 class KoViewConverter; 0036 0037 namespace Calligra 0038 { 0039 namespace Sheets 0040 { 0041 class CellToolBase; 0042 class Selection; 0043 0044 /** 0045 * class CellEditor 0046 */ 0047 class CellEditor : public KTextEdit, public CellEditorBase 0048 { 0049 Q_OBJECT 0050 public: 0051 /** 0052 * Creates a new CellEditor. 0053 * \param cellTool the cell tool 0054 * \param wordList the word list 0055 * \param parent the parent widget 0056 */ 0057 explicit CellEditor(CellToolBase *cellTool, QHash<int, QString> &wordList, QWidget *parent = 0); 0058 ~CellEditor() override; 0059 0060 Selection* selection() const; 0061 0062 void setEditorFont(QFont const & font, bool updateSize, const KoViewConverter *viewConverter) override; 0063 0064 int cursorPosition() const override; 0065 void setCursorPosition(int pos) override; 0066 0067 bool captureArrowKeys() const override; 0068 void setCaptureArrowKeys(bool capture) override; 0069 0070 QPoint globalCursorPosition() const; 0071 QAbstractItemModel *model(); 0072 0073 /** 0074 * Replaces the current formula token(/reference) with the name of the 0075 * selection's active sub-region name. 0076 * This is called after selection changes to sync the formula expression. 0077 */ 0078 void selectionChanged() override; 0079 0080 /** 0081 * Activates the sub-region belonging to the \p index 'th range. 0082 */ 0083 void setActiveSubRegion(int index) override; 0084 0085 // CellEditorBase interface 0086 QWidget* widget() override { return this; } 0087 void cut() override { KTextEdit::cut(); } 0088 void copy() override { KTextEdit::copy(); } 0089 void paste() override { KTextEdit::paste(); } 0090 QString toPlainText() const override { return KTextEdit::toPlainText(); } 0091 Q_SIGNALS: 0092 void textChanged(const QString &text); 0093 0094 public Q_SLOTS: 0095 void setText(const QString& text, int cursorPos = -1) override; 0096 0097 /** 0098 * Permutes the fixation of the reference, at which the editor's cursor 0099 * is placed. It is only active, if a formula is edited. 0100 */ 0101 void permuteFixation(); 0102 void setCompleter(QCompleter *c); 0103 QCompleter *completer() const; 0104 0105 private Q_SLOTS: 0106 void slotTextChanged(); 0107 void slotCompletionModeChanged(KCompletion::CompletionMode _completion); 0108 void slotCursorPositionChanged(); 0109 void insertCompletion(const QString &completion); 0110 0111 protected: // reimplementations 0112 void keyPressEvent(QKeyEvent *event) override; 0113 void focusInEvent(QFocusEvent *event) override; 0114 void focusOutEvent(QFocusEvent *event) override; 0115 0116 private: 0117 Q_DISABLE_COPY(CellEditor) 0118 QString textUnderCursor() const; 0119 0120 class Private; 0121 Private * const d; 0122 }; 0123 0124 } // namespace Sheets 0125 } // namespace Calligra 0126 0127 #endif // CALLIGRA_SHEETS_CELL_EDITOR