Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 : #include "preferencepageitem.h"
23 :
24 : #include "translation.h"
25 :
26 : using namespace mu::preferences;
27 :
28 0 : PreferencePageItem::PreferencePageItem(QObject* parent)
29 0 : : QObject(parent)
30 : {
31 0 : }
32 :
33 0 : PreferencePageItem::~PreferencePageItem()
34 : {
35 0 : for (PreferencePageItem* child : m_children) {
36 0 : child->deleteLater();
37 : }
38 0 : }
39 :
40 0 : QString PreferencePageItem::id() const
41 : {
42 0 : return m_id;
43 : }
44 :
45 0 : QString PreferencePageItem::title() const
46 : {
47 0 : return muse::qtrc("preferences", m_title.toUtf8());
48 : }
49 :
50 0 : int PreferencePageItem::icon() const
51 : {
52 0 : return static_cast<int>(m_icon);
53 : }
54 :
55 0 : QString PreferencePageItem::path() const
56 : {
57 0 : return m_path;
58 : }
59 :
60 0 : bool PreferencePageItem::expanded() const
61 : {
62 0 : return m_expanded;
63 : }
64 :
65 0 : PreferencePageItem* PreferencePageItem::parentItem() const
66 : {
67 0 : return m_parent;
68 : }
69 :
70 0 : void PreferencePageItem::setParentItem(PreferencePageItem* parent)
71 : {
72 0 : m_parent = parent;
73 0 : }
74 :
75 0 : QList<PreferencePageItem*> PreferencePageItem::childrenItems() const
76 : {
77 0 : return m_children;
78 : }
79 :
80 0 : bool PreferencePageItem::isEmpty() const
81 : {
82 0 : return m_children.isEmpty();
83 : }
84 :
85 0 : PreferencePageItem* PreferencePageItem::childAtRow(const int row) const
86 : {
87 0 : if (row < 0 || row >= childCount()) {
88 0 : return nullptr;
89 : }
90 :
91 0 : return m_children.at(row);
92 : }
93 :
94 0 : void PreferencePageItem::appendChild(PreferencePageItem* child)
95 : {
96 0 : if (!child) {
97 0 : return;
98 : }
99 :
100 0 : child->setParentItem(this);
101 :
102 0 : m_children.append(child);
103 : }
104 :
105 0 : int PreferencePageItem::childCount() const
106 : {
107 0 : return m_children.size();
108 : }
109 :
110 0 : int PreferencePageItem::row() const
111 : {
112 0 : if (!parentItem()) {
113 0 : return 0;
114 : }
115 :
116 0 : return parentItem()->childrenItems().indexOf(const_cast<PreferencePageItem*>(this));
117 : }
118 :
119 0 : void PreferencePageItem::setId(QString id)
120 : {
121 0 : if (m_id == id) {
122 0 : return;
123 : }
124 :
125 0 : m_id = id;
126 0 : emit idChanged(m_id);
127 : }
128 :
129 0 : void PreferencePageItem::setTitle(QString title)
130 : {
131 0 : if (m_title == title) {
132 0 : return;
133 : }
134 :
135 0 : m_title = title;
136 0 : emit titleChanged(m_title);
137 : }
138 :
139 0 : void PreferencePageItem::setIcon(muse::ui::IconCode::Code icon)
140 : {
141 0 : if (m_icon == icon) {
142 0 : return;
143 : }
144 :
145 0 : m_icon = icon;
146 0 : emit iconChanged(this->icon());
147 : }
148 :
149 0 : void PreferencePageItem::setPath(QString path)
150 : {
151 0 : if (m_path == path) {
152 0 : return;
153 : }
154 :
155 0 : m_path = path;
156 0 : emit pathChanged(m_path);
157 : }
158 :
159 0 : void PreferencePageItem::setExpanded(bool expanded)
160 : {
161 0 : if (m_expanded == expanded) {
162 0 : return;
163 : }
164 :
165 0 : m_expanded = expanded;
166 0 : emit expandedChanged(m_expanded);
167 : }
|