2019-09-21 15:24:05 -04:00
|
|
|
#ifndef TRANSMITTEXTEDIT_H
|
|
|
|
#define TRANSMITTEXTEDIT_H
|
|
|
|
|
2019-09-25 20:26:41 -04:00
|
|
|
#include "qt_helpers.hpp"
|
|
|
|
|
2019-09-21 15:24:05 -04:00
|
|
|
#include <QTextEdit>
|
2019-09-25 20:26:41 -04:00
|
|
|
#include <QTextBlock>
|
|
|
|
#include <QTextCursor>
|
|
|
|
#include <QBrush>
|
|
|
|
#include <QColor>
|
|
|
|
#include <QFont>
|
|
|
|
|
|
|
|
void setTextEditFont(QTextEdit *edit, QFont font);
|
|
|
|
void setTextEditStyle(QTextEdit *edit, QColor fg, QColor bg, QFont font);
|
|
|
|
void highlightBlock(QTextBlock block, QFont font, QColor foreground, QColor background);
|
2019-09-21 15:24:05 -04:00
|
|
|
|
|
|
|
class TransmitTextEdit : public QTextEdit
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TransmitTextEdit(QWidget *parent);
|
|
|
|
|
2019-11-07 14:20:06 -05:00
|
|
|
static QPair<int,int> relativeTextCursorPosition(QTextCursor cursor){
|
|
|
|
auto c = QTextCursor(cursor);
|
|
|
|
c.movePosition(QTextCursor::End);
|
|
|
|
int last = c.position();
|
|
|
|
|
|
|
|
auto cc = QTextCursor(cursor);
|
|
|
|
int relstart = last - qMin(cc.selectionStart(), cc.selectionEnd());
|
|
|
|
int relend = last - qMax(cc.selectionStart(), cc.selectionEnd());
|
|
|
|
|
|
|
|
return {relstart, relend};
|
|
|
|
}
|
|
|
|
|
2019-09-25 20:26:41 -04:00
|
|
|
int charsSent() const {
|
|
|
|
return m_sent;
|
|
|
|
}
|
|
|
|
void setCharsSent(int n);
|
|
|
|
|
2019-09-26 17:00:41 -04:00
|
|
|
QString sentText() const {
|
|
|
|
return m_textSent;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString unsentText() const {
|
|
|
|
return toPlainText().mid(charsSent());
|
|
|
|
}
|
|
|
|
|
2019-09-25 20:26:41 -04:00
|
|
|
QString toPlainText() const;
|
2019-09-21 15:24:05 -04:00
|
|
|
void setPlainText(const QString &text);
|
2019-11-07 14:20:06 -05:00
|
|
|
void replaceUnsentText(const QString &text, bool keepCursor);
|
|
|
|
void replacePlainText(const QString &text, bool keepCursor);
|
2019-09-26 23:19:00 -04:00
|
|
|
|
2019-09-25 20:26:41 -04:00
|
|
|
void setFont(QFont f);
|
|
|
|
void setFont(QFont f, QColor fg, QColor bg);
|
2019-09-21 15:24:05 -04:00
|
|
|
void clear();
|
|
|
|
|
2019-09-25 20:26:41 -04:00
|
|
|
bool isProtected() const {
|
|
|
|
return m_protected;
|
|
|
|
}
|
|
|
|
void setProtected(bool protect);
|
2019-09-26 17:00:41 -04:00
|
|
|
bool cursorShouldBeProtected(QTextCursor c);
|
2019-09-27 22:44:27 -04:00
|
|
|
|
|
|
|
bool isEmpty() const {
|
|
|
|
return toPlainText().isEmpty();
|
|
|
|
}
|
|
|
|
bool isDirty() const {
|
|
|
|
return m_dirty;
|
|
|
|
}
|
|
|
|
void setClean(){
|
|
|
|
m_dirty = false;
|
|
|
|
}
|
|
|
|
|
2019-09-25 20:26:41 -04:00
|
|
|
void highlightBase();
|
|
|
|
void highlightCharsSent();
|
|
|
|
void highlight();
|
|
|
|
|
2019-09-26 17:00:41 -04:00
|
|
|
bool eventFilter(QObject */*o*/, QEvent *e);
|
|
|
|
|
2019-09-21 15:24:05 -04:00
|
|
|
public slots:
|
|
|
|
void on_selectionChanged();
|
2019-09-25 20:26:41 -04:00
|
|
|
void on_textContentsChanged(int pos, int rem, int add);
|
2019-09-21 15:24:05 -04:00
|
|
|
|
|
|
|
private:
|
2019-09-25 20:26:41 -04:00
|
|
|
QString m_lastText;
|
2019-09-21 15:24:05 -04:00
|
|
|
int m_sent;
|
2019-09-26 20:46:33 -04:00
|
|
|
QString m_textSent;
|
2019-09-25 20:26:41 -04:00
|
|
|
bool m_protected;
|
2019-09-27 22:44:27 -04:00
|
|
|
bool m_dirty;
|
2019-09-25 20:26:41 -04:00
|
|
|
QFont m_font;
|
|
|
|
QColor m_fg;
|
|
|
|
QColor m_bg;
|
2019-09-21 15:24:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // TRANSMITTEXTEDIT_H
|