diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2021-02-08 19:20:16 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2021-02-08 19:20:16 +0000 |
| commit | f42dce36389f8ea7eb583f83d594cf488e02c9f4 (patch) | |
| tree | c98b0075149c90aa7bf39c5af3a50634a66cd0d6 /src/qmmpui | |
| parent | 86f6a3667a69b63fbc475b9f47360a9ce7c017cc (diff) | |
| download | qmmp-f42dce36389f8ea7eb583f83d594cf488e02c9f4.tar.gz qmmp-f42dce36389f8ea7eb583f83d594cf488e02c9f4.tar.bz2 qmmp-f42dce36389f8ea7eb583f83d594cf488e02c9f4.zip | |
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
Diffstat (limited to 'src/qmmpui')
| -rw-r--r-- | src/qmmpui/cueeditor.cpp | 37 |
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() |
