aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/mesonprojectmanager/project/buildoptions/optionsmodel/arrayoptionlineedit.h
blob: c37d0acf2688fe3ae6e5eb3365071ab78ff28d57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (C) 2020 Alexis Jeandet.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0

#pragma once

#include <QColor>
#include <QPlainTextEdit>
#include <QRegularExpression>
#include <QSyntaxHighlighter>

namespace MesonProjectManager {
namespace Internal {

class RegexHighlighter : public QSyntaxHighlighter
{
    Q_OBJECT
    const QRegularExpression m_regex{R"('([^']+)'+|([^', ]+)[, ]*)"};
    QTextCharFormat m_format;

public:
    RegexHighlighter(QWidget *parent);
    void highlightBlock(const QString &text) override;
    QStringList options(const QString &text);
};

class ArrayOptionLineEdit : public QPlainTextEdit
{
    Q_OBJECT
    RegexHighlighter *m_highLighter;

public:
    ArrayOptionLineEdit(QWidget *parent = nullptr);
    QStringList options();

protected:
    void keyPressEvent(QKeyEvent *e) override;
};

} // namespace Internal
} // namespace MesonProjectManager