1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
/**************************************************************************
* *
* SPDX-FileCopyrightText: 2017 Kitsune Ral <kitsune-ral@users.sf.net>
* *
* SPDX-License-Identifier: GPL-3.0-or-later
* *
**************************************************************************/
#pragma once
#include "kchatedit.h"
#include <QtGui/QTextCursor>
class ChatRoomWidget;
class ChatEdit : public KChatEdit
{
Q_OBJECT
public:
using completions_t = QVector<QPair<QString, QUrl>>;
ChatEdit(ChatRoomWidget* c);
void triggerCompletion();
void cancelCompletion();
bool isCompletionActive();
void insertMention(QString author, QUrl url);
bool acceptMimeData(const QMimeData* source);
// NB: the following virtual functions are protected in QTextEdit but
// ChatRoomWidget delegates to them
bool canInsertFromMimeData(const QMimeData* source) const override;
public slots:
void switchContext(QObject* contextKey) override;
void alternatePaste();
signals:
void cancelledCompletion();
private:
ChatRoomWidget* chatRoomWidget;
QTextCursor completionCursor;
/// Text/href pairs for completion
completions_t completionMatches;
int matchesListPosition;
bool pickingMentions = false;
bool m_pastePlaintext;
/// \brief Initialise a new completion
///
/// \return true if completion matches exist for the current entry;
/// false otherwise
bool initCompletion();
void appendMentionAt(QTextCursor& cursor, QString mention,
QUrl mentionUrl, bool select);
void keyPressEvent(QKeyEvent* event) override;
void contextMenuEvent(QContextMenuEvent* event) override;
void insertFromMimeData(const QMimeData* source) override;
void dragEnterEvent(QDragEnterEvent* event) override;
static bool pastePlaintextByDefault();
};
|