File indexing completed on 2024-05-12 16:35:19
0001 /* This file is part of the KDE project 0002 Copyright (C) 2002-2003 Ariya Hidayat <ariya@kde.org> 0003 (C) 2002-2003 Norbert Andres <nandres@web.de> 0004 (C) 1999-2003 Laurent Montel <montel@kde.org> 0005 (C) 2002 Philipp Mueller <philipp.mueller@gmx.de> 0006 (C) 2002 John Dailey <dailey@vt.edu> 0007 (C) 2002 Daniel Herring <herring@eecs.ku.edu> 0008 (C) 2000-2001 Werner Trobin <trobin@kde.org> 0009 (C) 1998-2000 Torben Weis <weis@kde.org> 0010 0011 This library is free software; you can redistribute it and/or 0012 modify it under the terms of the GNU Library General Public 0013 License as published by the Free Software Foundation; either 0014 version 2 of the License, or (at your option) any later version. 0015 0016 This library is distributed in the hope that it will be useful, 0017 but WITHOUT ANY WARRANTY; without even the implied warranty of 0018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0019 Library General Public License for more details. 0020 0021 You should have received a copy of the GNU Library General Public License 0022 along with this library; see the file COPYING.LIB. If not, write to 0023 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0024 Boston, MA 02110-1301, USA. 0025 */ 0026 0027 #ifndef CALLIGRA_SHEETS_FORMULA_DIALOG 0028 #define CALLIGRA_SHEETS_FORMULA_DIALOG 0029 0030 #include <QCloseEvent> 0031 #include <QLabel> 0032 #include <QEvent> 0033 #include <QListView> 0034 0035 #include <kcompletion.h> 0036 #include <KoDialog.h> 0037 0038 class QUrl; 0039 class QLabel; 0040 class QPushButton; 0041 class QTabWidget; 0042 class QTextBrowser; 0043 class QStringListModel; 0044 class QSortFilterProxyModel; 0045 class KComboBox; 0046 class KLineEdit; 0047 0048 namespace Calligra 0049 { 0050 namespace Sheets 0051 { 0052 class CellEditorBase; 0053 class FunctionDescription; 0054 class Selection; 0055 0056 /** 0057 * \ingroup UI 0058 * Dialog to compose a formula. 0059 */ 0060 class FormulaDialog : public KoDialog 0061 { 0062 Q_OBJECT 0063 public: 0064 FormulaDialog(QWidget* parent, Selection* selection, CellEditorBase* editor, const QString& expression = QString()); 0065 ~FormulaDialog() override; 0066 private: 0067 /** 0068 * Turns the @p text into a parameter that koscript can understand. The type 0069 * of this parameter is extracted by looking at parameter number @p param in @ref #m_desc. 0070 */ 0071 QString createParameter(const QString& _text, int param); 0072 /** 0073 * Reads the text out of @ref #firstElement and friends and creates a parameter 0074 * list for the function. 0075 */ 0076 QString createFormula(); 0077 0078 private Q_SLOTS: 0079 /** 0080 * Called by the Ok button. 0081 */ 0082 void slotOk(); 0083 /** 0084 * Called by the Close button. 0085 */ 0086 void slotClose(); 0087 /** 0088 * Called if a function name was selected but not double clicked. 0089 * This will just show the help page for the function. 0090 */ 0091 void slotSelected(const QString& function = QString()); 0092 /** 0093 * Called if a function name was selected but not double clicked. 0094 * This will just show the help page for the function. 0095 */ 0096 void slotIndexSelected(const QModelIndex& index); 0097 /** 0098 * Called if the user clicked on one of the "related function" 0099 * This will switch the active function and show help page 0100 * of the function as well. 0101 */ 0102 void slotShowFunction(const QUrl& functionUrl); 0103 /** 0104 * Called if the user double clicked on some method name. 0105 * That will switch into editing mode, allowing the user 0106 * to enter the parameters for the function. 0107 */ 0108 void slotDoubleClicked(QModelIndex item = QModelIndex()); 0109 /** 0110 * Called if a category of methods has been selected. 0111 */ 0112 void slotActivated(const QString& category); 0113 /** 0114 * Called if the text of @ref #firstElement, @ref #secondElement etc. changes. 0115 */ 0116 void slotChangeText(const QString& text); 0117 /** 0118 * Connected to @ref View to get notified if the selection in the 0119 * sheet changes. 0120 */ 0121 void slotSelectionChanged(); 0122 /** 0123 * Called if the button @ref #selectFunction was clicked. That 0124 * inserts a new function call to the result. 0125 */ 0126 void slotSelectButton(); 0127 /** 0128 * Called if the user changes some character in @ref #searchFunct. 0129 */ 0130 void slotSearchText(const QString& text); 0131 /** 0132 * Called if the user pressed return in @ref #searchFunct. 0133 */ 0134 void slotPressReturn(); 0135 0136 public: 0137 /** 0138 * Find out which widget got focus. 0139 */ 0140 bool eventFilter(QObject* obj, QEvent* ev) override; 0141 protected: 0142 void closeEvent(QCloseEvent *) override; 0143 private: 0144 Selection* m_selection; 0145 CellEditorBase* m_editor; 0146 0147 QTabWidget* m_tabwidget; 0148 QTextBrowser* m_browser; 0149 QWidget* m_input; 0150 0151 QPushButton *selectFunction; 0152 KComboBox *typeFunction; 0153 QListView *functions; 0154 QStringListModel *functionsModel; 0155 QSortFilterProxyModel *proxyModel; 0156 KLineEdit *result; 0157 0158 KLineEdit *searchFunct; 0159 KCompletion listFunct; 0160 0161 QLabel* label1; 0162 QLabel* label2; 0163 QLabel* label3; 0164 QLabel* label4; 0165 QLabel* label5; 0166 KLineEdit *firstElement; 0167 KLineEdit *secondElement; 0168 KLineEdit *thirdElement; 0169 KLineEdit *fourElement; 0170 KLineEdit *fiveElement; 0171 /** 0172 * Tells which of the lineedits has the logical focus currently. 0173 * It may happen that a lineedit does not have qt focus but 0174 * logical focus but not the other way round. 0175 */ 0176 KLineEdit* m_focus; 0177 0178 int m_column; 0179 int m_row; 0180 QString m_oldText; 0181 0182 QString m_funcName; 0183 QString m_sheetName; 0184 0185 QString m_rightText; 0186 QString m_leftText; 0187 /** 0188 * A lock for @ref #slotChangeText. 0189 */ 0190 bool refresh_result; 0191 0192 Calligra::Sheets::FunctionDescription* m_desc; 0193 }; 0194 0195 } // namespace Sheets 0196 } // namespace Calligra 0197 0198 #endif // CALLIGRA_SHEETS_FORMULA_DIALOG