File indexing completed on 2024-12-08 10:25:49
0001 /* 0002 SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QObject> 0010 0011 #include "model/inputcompletermodel.h" 0012 0013 #include "libruqolacore_export.h" 0014 0015 class QAbstractItemModel; 0016 class RocketChatAccount; 0017 class CommandsModelFilterProxyModel; 0018 class EmoticonFilterProxyModel; 0019 class LIBRUQOLACORE_EXPORT InputTextManager : public QObject 0020 { 0021 Q_OBJECT 0022 public: 0023 enum CompletionForType { 0024 Channel = 0, 0025 User, 0026 Emoji, 0027 Command, 0028 None, 0029 }; 0030 explicit InputTextManager(RocketChatAccount *account, QObject *parent = nullptr); 0031 ~InputTextManager() override; 0032 0033 void setEmoticonModel(QAbstractItemModel *model); 0034 0035 [[nodiscard]] InputCompleterModel *inputCompleterModel() const; 0036 [[nodiscard]] QAbstractItemModel *emojiCompleterModel() const; 0037 0038 void inputTextCompleter(const QJsonObject &obj); 0039 0040 [[nodiscard]] QString applyCompletion(const QString &newWord, const QString &str, int *pPosition); 0041 0042 void setInputTextChanged(const QString &roomId, const QString &str, int position); 0043 0044 void clearCompleter(); 0045 0046 // Only for autotests 0047 [[nodiscard]] QString searchWord(const QString &text, int position, int &start); 0048 0049 void setCommandModel(QAbstractItemModel *model); 0050 [[nodiscard]] QAbstractItemModel *commandModel() const; 0051 0052 Q_SIGNALS: 0053 // Trigger autocompletion request in DDPClient (via RocketChatAccount) 0054 // Emitted with Channel and User, never Emoji or None 0055 void completionRequested(const QString &roomId, const QString &pattern, const QString &exceptions, InputTextManager::CompletionForType type); 0056 void completionTypeChanged(InputTextManager::CompletionForType type); 0057 void selectFirstTextCompleter(); 0058 0059 private: 0060 LIBRUQOLACORE_NO_EXPORT void setCompletionType(CompletionForType type); 0061 0062 InputCompleterModel *const mInputCompleterModel; 0063 EmoticonFilterProxyModel *const mEmoticonFilterProxyModel; 0064 CommandsModelFilterProxyModel *const mCommandFilterProxyModel; 0065 RocketChatAccount *const mRocketChatAccount; 0066 CompletionForType mCurrentCompletionType = None; 0067 QString mCurrentCompletionPattern; 0068 }; 0069 0070 Q_DECLARE_METATYPE(InputTextManager::CompletionForType)