diff options
-rw-r--r-- | editorpage.cpp | 32 | ||||
-rw-r--r-- | editorpage.h | 5 |
2 files changed, 37 insertions, 0 deletions
diff --git a/editorpage.cpp b/editorpage.cpp index acf1dcd..4679bfe 100644 --- a/editorpage.cpp +++ b/editorpage.cpp @@ -33,6 +33,9 @@ EditorPage::EditorPage(const QString &filePath, QWidget *parent) : QWidget(paren setLayout(mainLayout); setAttribute(Qt::WA_DeleteOnClose); textPage->setFocus(); + + connect(textPage, SIGNAL(textChanged()), this, SLOT(formatGpgHeader())); + } const QString& EditorPage::getFilePath() const @@ -66,3 +69,32 @@ void EditorPage::closeNoteByClass(const char *className) } } } + +void EditorPage::formatGpgHeader() { + + QString content = textPage->toPlainText(); + int start = content.indexOf(GpgConstants::PGP_SIGNED_BEGIN); + int startSig = content.indexOf(GpgConstants::PGP_SIGNATURE_BEGIN); + int endSig = content.indexOf(GpgConstants::PGP_SIGNATURE_END); + + if(start < 0 || startSig < 0 || endSig < 0 || signMarked) { + return; + } + + signMarked = true; + + QTextCharFormat signFormat; + signFormat.setForeground(QBrush(QColor::fromRgb(80,80,80))); + signFormat.setFontPointSize(9); + + QTextCursor cursor(textPage->document()); + cursor.setPosition(startSig, QTextCursor::MoveAnchor); + cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, endSig); + cursor.setCharFormat(signFormat); + + int headEnd = content.indexOf("\n\n", start); + cursor.setPosition(start, QTextCursor::MoveAnchor); + cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, headEnd); + cursor.setCharFormat(signFormat); + +} diff --git a/editorpage.h b/editorpage.h index ef8928f..52513b4 100644 --- a/editorpage.h +++ b/editorpage.h @@ -22,6 +22,7 @@ #ifndef __EDITORPAGE_H__ #define __EDITORPAGE_H__ +#include "gpgconstants.h" #include <QTextEdit> #include <QtGui> @@ -89,6 +90,10 @@ private: QMenu *verifyMenu; /** The menu in the notifiaction widget */ QString fullFilePath; /** The path to the file handled in the tab */ QLabel *verifyLabel; /** The label of the verify-notification widget */ + bool signMarked; + +private slots: + void formatGpgHeader(); }; #endif // __TEXTPAGE_H__ |