aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/qmmpui/cueeditor.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/qmmpui/cueeditor.cpp b/src/qmmpui/cueeditor.cpp
index 451fa6a77..60a3c9b4a 100644
--- a/src/qmmpui/cueeditor.cpp
+++ b/src/qmmpui/cueeditor.cpp
@@ -22,11 +22,47 @@
#include <QSettings>
#include <QFileInfo>
#include <QDir>
+#include <QSyntaxHighlighter>
+#include <QRegularExpression>
+#include <QRegularExpressionMatch>
+#include <QRegularExpressionMatchIterator>
#include <qmmp/metadatamodel.h>
#include "cueeditor_p.h"
#include "filedialog.h"
#include "ui_cueeditor.h"
+class CueSyntaxHighlighter : public QSyntaxHighlighter
+{
+public:
+ CueSyntaxHighlighter(QTextDocument *parent) : QSyntaxHighlighter(parent) {}
+
+private:
+ void highlightBlock(const QString &text) override
+ {
+ QTextCharFormat textFormat;
+ textFormat.setForeground(Qt::darkGreen);
+
+ QRegularExpression textExpr("\\\".*\\\"");
+ QRegularExpressionMatchIterator i = textExpr.globalMatch(text);
+ while(i.hasNext())
+ {
+ QRegularExpressionMatch match = i.next();
+ setFormat(match.capturedStart(), match.capturedLength(), textFormat);
+ }
+
+ QTextCharFormat trackFormat;
+ trackFormat.setFontWeight(QFont::Bold);
+
+ QRegularExpression trackExpr("TRACK\\s+\\d+\\s*\\D*");
+ i = trackExpr.globalMatch(text);
+ while(i.hasNext())
+ {
+ QRegularExpressionMatch match = i.next();
+ setFormat(match.capturedStart(), match.capturedLength(), trackFormat);
+ }
+ }
+};
+
CueEditor::CueEditor(MetaDataModel *model, const TrackInfo &info, QWidget *parent) :
QWidget(parent),
m_ui(new Ui::CueEditor),
@@ -39,6 +75,7 @@ CueEditor::CueEditor(MetaDataModel *model, const TrackInfo &info, QWidget *paren
QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
m_lastDir = settings.value("CueEditor/last_dir", QDir::homePath()).toString();
m_editable = m_model && (m_model->dialogHints() & MetaDataModel::IsCueEditable) && !m_model->isReadOnly();
+ new CueSyntaxHighlighter(m_ui->plainTextEdit->document());
}
CueEditor::~CueEditor()