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_FUNCTION_COMPLETION
0023 #define CALLIGRA_SHEETS_FUNCTION_COMPLETION
0024 
0025 #include <QObject>
0026 
0027 #include "sheets_common_export.h"
0028 
0029 class QListWidgetItem;
0030 
0031 namespace Calligra
0032 {
0033 namespace Sheets
0034 {
0035 class CellEditor;
0036 
0037 /**
0038 * Provides autocompletion facilities in formula editors.
0039 * When the user types in the first few characters of a
0040 * function name in a CellEditor which has a FunctionCompletion
0041 * object installed on it, the FunctionCompletion object
0042 * creates and displays a list of possible names which the user
0043 * can select from. If the user selects a function name from the list,
0044 * the @ref FunctionCompletion::selectedCompletion() signal is emitted
0045 */
0046 class FunctionCompletion : public QObject
0047 {
0048     Q_OBJECT
0049 
0050 public:
0051 
0052     explicit FunctionCompletion(CellEditor *editor);
0053     ~FunctionCompletion() override;
0054 
0055     /**
0056     * Handles various keyboard and mouse actions which may occur on the autocompletion popup list
0057     */
0058     bool eventFilter(QObject *o, QEvent *e) override;
0059 
0060     /**
0061     * Populates the autocompletion list box with the specified choices and shows it so that the user can view and select a function name.
0062     * @param choices A list of possible function names which match the characters that the user has already entered.
0063     */
0064     void showCompletion(const QStringList &choices);
0065 
0066 public Q_SLOTS:
0067     /**
0068     * Hides the autocompletion list box if it is visible and emits the @ref selectedCompletion signal.
0069     */
0070     void doneCompletion();
0071 
0072 private Q_SLOTS:
0073     void itemSelected(QListWidgetItem* item = 0);
0074 
0075 Q_SIGNALS:
0076     /**
0077     * Emitted, if the user selects a function name from the list.
0078     */
0079     void selectedCompletion(const QString& item);
0080 
0081 private:
0082     class Private;
0083     Private * const d;
0084     FunctionCompletion(const FunctionCompletion&);
0085     FunctionCompletion& operator=(const FunctionCompletion&);
0086 };
0087 
0088 } // namespace Sheets
0089 } // namespace Calligra
0090 
0091 #endif // CALLIGRA_SHEETS_FUNCTION_COMPLETION