JS8Call-Improved master
Loading...
Searching...
No Matches
TransmitTextEdit.h
1#ifndef TRANSMITTEXTEDIT_H
2#define TRANSMITTEXTEDIT_H
3
4#include "JS8_Include/pimpl_h.h"
5#include "qt_helpers.h"
6
7#include <QBrush>
8#include <QColor>
9#include <QFont>
10#include <QTextBlock>
11#include <QTextCursor>
12#include <QTextEdit>
13
14class PillRenderer;
16
17void setTextEditFont(QTextEdit *edit, QFont font);
18void setTextEditStyle(QTextEdit *edit, QColor fg, QColor bg, QFont font);
19void highlightBlock(QTextBlock block, QFont font, QColor foreground,
20 QColor background);
21
22class TransmitTextEdit : public QTextEdit {
23 friend class PillRenderer;
24 friend class ScopedDocumentMutation;
25
26 public:
27 explicit TransmitTextEdit(QWidget *parent);
28 ~TransmitTextEdit();
29
30 static QPair<int, int> relativeTextCursorPosition(QTextCursor cursor) {
31 auto c = QTextCursor(cursor);
32 c.movePosition(QTextCursor::End);
33 int last = c.position();
34
35 auto cc = QTextCursor(cursor);
36 int relstart = last - qMin(cc.selectionStart(), cc.selectionEnd());
37 int relend = last - qMax(cc.selectionStart(), cc.selectionEnd());
38
39 return {relstart, relend};
40 }
41
42 int charsSent() const { return m_sent; }
43 void setCharsSent(int n);
44
45 QString sentText() const { return m_textSent; }
46
47 QString unsentText() const { return toPlainText().mid(charsSent()); }
48
49 QString toPlainText() const;
50 void setPlainText(const QString &text);
51 void replaceUnsentText(const QString &text, bool keepCursor);
52 void replacePlainText(const QString &text, bool keepCursor);
53 void undo();
54 void redo();
55
56 void setFont(QFont f);
57 void setFont(QFont f, QColor fg, QColor bg);
58 void clear();
59
60 bool isProtected() const { return m_protected; }
61 void setProtected(bool protect);
62 bool cursorShouldBeProtected(QTextCursor c);
63
64 bool isEmpty() const { return toPlainText().isEmpty(); }
65 bool isDirty() const { return m_dirty; }
66 void setClean() { m_dirty = false; }
67
68 PillRenderer *pillRenderer() const { return m_pillRenderer; }
69
70 void highlightBase();
71 void highlightCharsSent();
72 void highlight();
73
74 void paintEvent(QPaintEvent *event) override;
75 bool event(QEvent *e) override;
76 bool eventFilter(QObject * /*o*/, QEvent *e) override;
77 void keyPressEvent(QKeyEvent *e) override;
78
79 public slots:
80 void on_selectionChanged();
81 void on_textContentsChanged(int pos, int rem, int add);
82
83 private:
84 class source_mirror;
85
86 void beginInternalDocumentMutation();
87 void endInternalDocumentMutation();
88 bool isInternalDocumentMutationActive() const;
89
90 QString m_lastText;
91 int m_sent;
92 QString m_textSent;
93 bool m_protected;
94 bool m_dirty = false;
95 QFont m_font;
96 QColor m_fg;
97 QColor m_bg;
98 PillRenderer *m_pillRenderer;
99 bool m_isHighlighting = false;
100 pimpl<source_mirror> m_sourceMirror;
101};
102
103#endif // TRANSMITTEXTEDIT_H
Renders pill-shaped backgrounds for a QTextEdit host.
Definition PillRenderer.h:27
Definition TransmitTextEdit.cpp:61
Definition TransmitTextSourceMirror.h:8
Definition pimpl_h.h:16