From f42dce36389f8ea7eb583f83d594cf488e02c9f4 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Mon, 8 Feb 2021 19:20:16 +0000 Subject: added syntax highlighter for cue editor git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@9705 90c681e8-e032-0410-971d-27865f9a5e38 --- src/qmmpui/cueeditor.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) 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 #include #include +#include +#include +#include +#include #include #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() -- cgit v1.2.3-13-gbd6f