DtkWidget
DTK Widget module
载入中...
搜索中...
未找到
dtitlebarsettingsimpl.h
1// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#pragma once
6
7#include "dtkwidget_global.h"
8#include "dtitlebarsettings.h"
9#include <DObjectPrivate>
10#include <DObject>
11#include <QSharedPointer>
12#include <QVector>
13
14QT_BEGIN_NAMESPACE
15class QWidget;
16QT_END_NAMESPACE
17
18DWIDGET_BEGIN_NAMESPACE
19
20class DTitlebarToolBaseInterface;
21
23{
24 QString key;
25 QString toolId;
26 bool isFixed = false;
27};
28class DTitlebarDataStore : public QObject
29{
30 Q_OBJECT
31
32public:
33 explicit DTitlebarDataStore(QObject *parent = nullptr);
34 virtual ~DTitlebarDataStore() override;
35
36 static DTitlebarDataStore *instance();
37 bool load(const QString &path);
38 void save();
39 void clear();
40 void reset();
41 bool isValid() const;
42
43 QString findKeyByPos(const int pos) const;
44 QStringList defaultIds() const;
45 QStringList keys() const;
46 QString key(const int pos);
47 QStringList toolIds() const;
48 QString toolId(const QString &key) const;
49 void removeAllNotExistIds(const QStringList &ids);
50 int position(const QString &key) const;
51 bool contains(const QString &key) const;
52 bool isExistTheId(const QString &id) const;
53 int spacingSize() const;
54
55 void move(const QString &key, const int pos);
56 QString add(const QString &id);
57 QString insert(const QString &id, const int pos);
58 void remove(const QString &key);
59 void remove(const int pos);
60
61 bool isFixed(const QString &key) const;
62 bool isFixed(const int pos) const;
63
64private:
65 bool load();
66 ToolInstance *createInstance(const QString &id);
67 ToolInstance *createInstance(const QString &id, const QString &key);
68 ToolInstance *getInstance(const QString &key) const;
69 bool isInvalid() const;
70 QStringList positionsFromToolMeta(const QJsonObject &root) const;
71 QList<ToolInstance> toolInstancesFromToolMeta(const QJsonObject &root) const;
72 bool fixedFromToolMeta(const QJsonObject &root, const int index) const;
73 int countFromToolMeta(const QJsonObject &root, const int index) const;
74 QString alignmentFromToolMeta(const QJsonObject &root) const;
75 QStringList positionsFromToolMeta() const;
76 QJsonObject metaRoot() const;
77 QVariantList positionsFromCache();
78 void savePositionsToCache();
79 void clearCache();
80 bool acceptCountField(const QString &id) const;
81
82private:
83 QString m_settingsGroupName;
84 QString m_settingsGroupNameSubGroup;
85 QVector<ToolInstance *> m_instances;
86 int m_spacingSize = -1;
87 bool m_isValid = false;
88 QString m_filePath;
89};
90
92{
93 explicit ToolWrapper(DTitlebarToolBaseInterface *t = nullptr)
94 : tool(t)
95 {
96 }
97 QSharedPointer<DTitlebarToolBaseInterface> tool = nullptr;
98};
99
100class DTitlebarToolFactory : public QObject
101{
102 Q_OBJECT
103public:
104 explicit DTitlebarToolFactory(QObject *parent = nullptr);
105 virtual ~DTitlebarToolFactory() override;
106
107 void add(DTitlebarToolBaseInterface *tool);
108 void remove(const QString &id);
109 void setTools(const QList<DTitlebarToolBaseInterface *> &tools);
110 DTitlebarToolBaseInterface *tool(const QString &id) const;
111 QList<DTitlebarToolBaseInterface *> tools() const;
112 bool contains(const QString &id) const;
113
114 QStringList toolIds() const;
115
116private:
117 QMap<QString, ToolWrapper> m_tools;
118};
119
120class ReloadSignal : public QObject
121{
122 Q_OBJECT
123public:
124 static ReloadSignal *instance();
125Q_SIGNALS:
126 void reload();
127private:
128 ReloadSignal() = default;
129 ~ReloadSignal() = default;
130};
131
133
134class DTitlebarSettingsImpl : public QObject, public DCORE_NAMESPACE::DObject
135{
136 Q_OBJECT
137public:
138 explicit DTitlebarSettingsImpl(QObject *parent = nullptr);
139 virtual ~DTitlebarSettingsImpl() override;
140
141 void setTools(const QList<DTitlebarToolBaseInterface *> &tools);
142 void addTool(DTitlebarToolBaseInterface *tool);
143 DTitlebarToolBaseInterface *tool(const QString &key) const;
144 DTitlebarToolBaseInterface *toolById(const QString &id) const;
145 QStringList keys() const;
146 QString findKeyByPos(const int pos) const;
147 QString toolId(const QString &key) const;
148 void removeTool(const QString &key);
149 static bool isSpacerTool(const DTitlebarToolBaseInterface *tool);
150 bool isSpacerTool(const QString &key) const;
151 bool isStrecherTool(const QString &key) const;
152 bool isSpacerToolById(const QString &id) const;
153 bool isFixedTool(const QString &key) const;
154 bool isFixedTool(const int pos) const;
155 bool load(const QString &path);
156
157 QWidget *toolsView() const;
158 QWidget *toolsEditPanel() const;
159 bool hasEditPanel() const;
160 void adjustDisplayView();
161 void showEditPanel();
162 bool isValid() const;
163 void clearCache();
164
165private:
166 D_DECLARE_PRIVATE(DTitlebarSettingsImpl)
167
168 D_PRIVATE_SLOT(void _q_addingToolView(const QString &, const int))
169 D_PRIVATE_SLOT(void _q_removedToolView(const QString &, const int))
170 D_PRIVATE_SLOT(void _q_movedToolView(const QString &, const int))
171 D_PRIVATE_SLOT(void _q_resetToolView())
172 D_PRIVATE_SLOT(void _q_confirmBtnClicked())
173 D_PRIVATE_SLOT(void _q_onReload())
174};
175
176DWIDGET_END_NAMESPACE
Definition dtitlebarsettingsimpl.h:29
Definition dtitlebarsettingsimpl.cpp:679
Definition dtitlebarsettingsimpl.h:135
Definition dtitlebarsettings.h:13
Definition dtitlebarsettingsimpl.h:101
Definition dtitlebarsettingsimpl.h:121
Definition dtitlebarsettingsimpl.h:23
Definition dtitlebarsettingsimpl.h:92