Changeset View
Changeset View
Standalone View
Standalone View
kcms/keyboard/layoutmodel/fcitx_im_config_model.h
- This file was added.
1 | #ifndef FCITXIMCONFIGMODEL_H | ||||
---|---|---|---|---|---|
2 | #define FCITXIMCONFIGMODEL_H | ||||
3 | | ||||
4 | #include <QAbstractListModel> | ||||
5 | #include "layout_list_sort_filter_proxy_model.h" | ||||
6 | | ||||
7 | class FcitxIMListModel : public LayoutListSortFilterProxyModel | ||||
8 | { | ||||
9 | Q_OBJECT | ||||
10 | | ||||
11 | public: | ||||
12 | FcitxIMListModel(QObject* parent); | ||||
13 | QHash<int, QByteArray> roleNames() const override; | ||||
14 | | ||||
15 | bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; | ||||
16 | }; | ||||
17 | | ||||
18 | class FcitxIMConfigModel : public QAbstractListModel | ||||
19 | { | ||||
20 | Q_OBJECT | ||||
21 | Q_PROPERTY(bool isRealIM READ isRealIM NOTIFY isRealIMChanged) | ||||
22 | Q_PROPERTY(bool isLatinSwitchingEnabled READ isLatinSwitchingEnabled WRITE setIsLatinSwitchingEnabled NOTIFY isLatinSwitchingEnabledChanged) | ||||
23 | Q_PROPERTY(FcitxIMListModel* latinModeLayoutList READ latinModeLayoutList NOTIFY latinModeLayoutListChanged) | ||||
24 | Q_PROPERTY(int selectedLatinLayoutIndex READ selectedLatinLayoutIndex WRITE setSelectedLatinLayoutIndex NOTIFY selectedLatinLayoutIndexChanged) | ||||
25 | | ||||
26 | public: | ||||
27 | explicit FcitxIMConfigModel(QString imName, QObject *parent = nullptr); | ||||
28 | | ||||
29 | // Basic functionality: | ||||
30 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; | ||||
31 | | ||||
32 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | ||||
33 | bool setData(const QModelIndex &index, const QVariant &value, int role) override; | ||||
34 | | ||||
35 | struct Roles { | ||||
36 | enum { | ||||
37 | NameRole = Qt::UserRole + 1, | ||||
38 | GroupRole, | ||||
39 | TypeRole, | ||||
40 | DescriptionRole, | ||||
41 | DataRole, | ||||
42 | CurrentValueRole | ||||
43 | }; | ||||
44 | }; | ||||
45 | | ||||
46 | QHash<int, QByteArray> roleNames() const override; | ||||
47 | | ||||
48 | Q_INVOKABLE void save() const; | ||||
49 | | ||||
50 | enum ConfigType { | ||||
51 | IntegerType, | ||||
52 | ColorType, | ||||
53 | CharType, | ||||
54 | StringType, | ||||
55 | I18NStringType, | ||||
56 | BooleanType, | ||||
57 | FileType, | ||||
58 | FontType, | ||||
59 | HotkeyType, | ||||
60 | EnumType | ||||
61 | }; | ||||
62 | Q_ENUM(ConfigType) | ||||
63 | | ||||
64 | FcitxIMListModel* latinModeLayoutList() const; | ||||
65 | | ||||
66 | bool isLatinSwitchingEnabled() const; | ||||
67 | void setIsLatinSwitchingEnabled(bool isLatinSwitchingEnabled); | ||||
68 | | ||||
69 | int selectedLatinLayoutIndex() const; | ||||
70 | void setSelectedLatinLayoutIndex(int selectedLatinLayoutIndex); | ||||
71 | | ||||
72 | QString selectedLatinLayoutId() const; | ||||
73 | void setSelectedLatinLayoutId(const QString &selectedLatinLayoutId); | ||||
74 | | ||||
75 | bool isRealIM() const; | ||||
76 | | ||||
77 | Q_SIGNALS: | ||||
78 | void isLatinSwitchingEnabledChanged(); | ||||
79 | void selectedLatinLayoutIndexChanged(); | ||||
80 | void latinModeLayoutListChanged(); | ||||
81 | void isRealIMChanged(); | ||||
82 | | ||||
83 | private: | ||||
84 | | ||||
85 | QString m_imName; | ||||
86 | QString m_addonName; | ||||
87 | | ||||
88 | struct ConfigItem { | ||||
89 | QString group; | ||||
90 | QString name; | ||||
91 | ConfigType type; | ||||
92 | QString description; | ||||
93 | QVariant default_value; | ||||
94 | QVariant current_value; | ||||
95 | QVariant data; | ||||
96 | }; | ||||
97 | | ||||
98 | QList<ConfigItem> m_configs; | ||||
99 | | ||||
100 | FcitxIMListModel* m_latinModeLayoutList; | ||||
101 | QString m_selectedLatinLayoutId; | ||||
102 | bool m_isLatinSwitchingEnabled; | ||||
103 | }; | ||||
104 | | ||||
105 | Q_DECLARE_METATYPE(FcitxIMConfigModel*) | ||||
106 | | ||||
107 | #endif // FCITXIMCONFIGMODEL_H |