1/*
2 * Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#ifndef FORMATTERGENERALWIDGET_H
18#define FORMATTERGENERALWIDGET_H
19
20#include <QAbstractListModel>
21#include <QWidget>
22#include "settingswidget.h"
23#include "../utils.h"
24#include "../settings.h"
25
26namespace Ui {
27class FormatterGeneralWidget;
28}
29
30struct FormatterStyleItem {
31 QString name;
32 QString description;
33 FormatterBraceStyle style;
34 explicit FormatterStyleItem(const QString& name,
35 const QString& description,
36 FormatterBraceStyle style);
37};
38using PFormatterStyleItem = std::shared_ptr<FormatterStyleItem>;
39
40class FormatterStyleModel : public QAbstractListModel{
41 Q_OBJECT
42 // QAbstractItemModel interface
43public:
44 explicit FormatterStyleModel(QObject *parent=nullptr);
45 int rowCount(const QModelIndex &parent) const override;
46 QVariant data(const QModelIndex &index, int role) const override;
47 PFormatterStyleItem getStyle(const QModelIndex &index);
48 PFormatterStyleItem getStyle(int index);
49private:
50 QList<PFormatterStyleItem> mStyles;
51};
52
53
54class FormatterGeneralWidget : public SettingsWidget
55{
56 Q_OBJECT
57
58public:
59 explicit FormatterGeneralWidget(const QString& name, const QString& group, QWidget *parent = nullptr);
60 ~FormatterGeneralWidget();
61private slots:
62 void onBraceStyleChanged();
63
64 void on_chkBreakMaxCodeLength_stateChanged(int arg1);
65
66 void updateDemo();
67private:
68 void updateCodeFormatter(Settings::CodeFormatter& format);
69
70private:
71 Ui::FormatterGeneralWidget *ui;
72 FormatterStyleModel mStylesModel;
73
74 // SettingsWidget interface
75protected:
76 void doLoad() override;
77 void doSave() override;
78};
79
80#endif // FORMATTERGENERALWIDGET_H
81