Mercurial > hg > svgui
comparison widgets/PluginPathConfigurator.cpp @ 1290:050eca637c19 plugin-path-config
More work on plugin path configuration layout &c
author | Chris Cannam |
---|---|
date | Wed, 23 May 2018 11:52:19 +0100 |
parents | ed04d3666d33 |
children | b5c71304286e |
comparison
equal
deleted
inserted
replaced
1289:ed04d3666d33 | 1290:050eca637c19 |
---|---|
17 #include <QPushButton> | 17 #include <QPushButton> |
18 #include <QListWidget> | 18 #include <QListWidget> |
19 #include <QGridLayout> | 19 #include <QGridLayout> |
20 #include <QComboBox> | 20 #include <QComboBox> |
21 #include <QLabel> | 21 #include <QLabel> |
22 #include <QCheckBox> | |
22 | 23 |
23 #include "IconLoader.h" | 24 #include "IconLoader.h" |
24 #include "WidgetScale.h" | 25 #include "WidgetScale.h" |
25 | 26 |
26 PluginPathConfigurator::PluginPathConfigurator(QWidget *parent) : | 27 PluginPathConfigurator::PluginPathConfigurator(QWidget *parent) : |
30 setLayout(m_layout); | 31 setLayout(m_layout); |
31 | 32 |
32 int row = 0; | 33 int row = 0; |
33 | 34 |
34 m_header = new QLabel; | 35 m_header = new QLabel; |
35 m_header->setText(tr("Plugin locations")); | 36 m_header->setText(tr("Plugin locations for plugin type:")); |
36 m_layout->addWidget(m_header, row, 0); | 37 m_layout->addWidget(m_header, row, 0); |
37 | 38 |
38 m_pluginTypeSelector = new QComboBox; | 39 m_pluginTypeSelector = new QComboBox; |
39 m_layout->addWidget(m_pluginTypeSelector, row, 1); | 40 m_layout->addWidget(m_pluginTypeSelector, row, 1, Qt::AlignLeft); |
40 connect(m_pluginTypeSelector, SIGNAL(currentTextChanged(QString)), | 41 connect(m_pluginTypeSelector, SIGNAL(currentTextChanged(QString)), |
41 this, SLOT(currentTypeChanged(QString))); | 42 this, SLOT(currentTypeChanged(QString))); |
42 | 43 |
44 m_layout->setColumnStretch(1, 10); | |
45 | |
43 ++row; | 46 ++row; |
44 | 47 |
45 m_list = new QListWidget; | 48 m_list = new QListWidget; |
46 m_layout->addWidget(m_list, row, 0, 1, 2); | 49 m_layout->addWidget(m_list, row, 0, 1, 3); |
47 m_layout->setRowStretch(row, 10); | 50 m_layout->setRowStretch(row, 20); |
48 m_layout->setColumnStretch(0, 10); | |
49 connect(m_list, SIGNAL(currentRowChanged(int)), | 51 connect(m_list, SIGNAL(currentRowChanged(int)), |
50 this, SLOT(currentLocationChanged(int))); | 52 this, SLOT(currentLocationChanged(int))); |
51 ++row; | 53 ++row; |
52 | 54 |
53 QHBoxLayout *buttons = new QHBoxLayout; | 55 QHBoxLayout *buttons = new QHBoxLayout; |
54 | 56 |
55 m_down = new QPushButton; | 57 m_down = new QPushButton; |
56 m_down->setIcon(IconLoader().load("down")); | 58 m_down->setIcon(IconLoader().load("down")); |
57 m_down->setToolTip(tr("Move the selected location later in the list")); | 59 m_down->setToolTip(tr("Move the selected location later in the list")); |
58 m_down->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16))); | |
59 connect(m_down, SIGNAL(clicked()), this, SLOT(downClicked())); | 60 connect(m_down, SIGNAL(clicked()), this, SLOT(downClicked())); |
60 buttons->addWidget(m_down); | 61 buttons->addWidget(m_down); |
61 | 62 |
62 m_up = new QPushButton; | 63 m_up = new QPushButton; |
63 m_up->setIcon(IconLoader().load("up")); | 64 m_up->setIcon(IconLoader().load("up")); |
64 m_up->setToolTip(tr("Move the selected location earlier in the list")); | 65 m_up->setToolTip(tr("Move the selected location earlier in the list")); |
65 m_up->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16))); | |
66 connect(m_up, SIGNAL(clicked()), this, SLOT(upClicked())); | 66 connect(m_up, SIGNAL(clicked()), this, SLOT(upClicked())); |
67 buttons->addWidget(m_up); | 67 buttons->addWidget(m_up); |
68 | 68 |
69 m_delete = new QPushButton; | 69 m_delete = new QPushButton; |
70 m_delete->setIcon(IconLoader().load("datadelete")); | 70 m_delete->setIcon(IconLoader().load("datadelete")); |
71 m_delete->setToolTip(tr("Remove the selected location from the list")); | 71 m_delete->setToolTip(tr("Remove the selected location from the list")); |
72 m_delete->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16))); | |
73 connect(m_delete, SIGNAL(clicked()), this, SLOT(deleteClicked())); | 72 connect(m_delete, SIGNAL(clicked()), this, SLOT(deleteClicked())); |
74 buttons->addWidget(m_delete); | 73 buttons->addWidget(m_delete); |
75 | 74 |
76 m_layout->addLayout(buttons, row, 1); | 75 m_reset = new QPushButton; |
76 m_reset->setText(tr("Reset")); | |
77 m_reset->setToolTip(tr("Reset the list for this plugin type to its default")); | |
78 connect(m_reset, SIGNAL(clicked()), this, SLOT(resetClicked())); | |
79 buttons->addWidget(m_reset); | |
80 | |
81 m_layout->addLayout(buttons, row, 2); | |
77 ++row; | 82 ++row; |
83 | |
84 m_envOverride = new QCheckBox; | |
85 connect(m_envOverride, SIGNAL(stateChanged(int)), | |
86 this, SLOT(envOverrideChanged(int))); | |
87 m_layout->addWidget(m_envOverride, row, 0, 1, 3); | |
78 } | 88 } |
79 | 89 |
80 PluginPathConfigurator::~PluginPathConfigurator() | 90 PluginPathConfigurator::~PluginPathConfigurator() |
81 { | 91 { |
82 } | 92 } |
83 | 93 |
84 void | 94 void |
85 PluginPathConfigurator::setPaths(Paths paths) | 95 PluginPathConfigurator::setPaths(Paths paths) |
86 { | 96 { |
87 m_paths = paths; | 97 m_paths = paths; |
98 if (m_originalPaths.empty()) { | |
99 m_originalPaths = paths; | |
100 } | |
88 | 101 |
89 m_pluginTypeSelector->clear(); | 102 m_pluginTypeSelector->clear(); |
90 for (const auto &p: paths) { | 103 for (const auto &p: paths) { |
91 m_pluginTypeSelector->addItem(p.first); | 104 m_pluginTypeSelector->addItem(p.first); |
92 } | 105 } |
99 { | 112 { |
100 m_list->clear(); | 113 m_list->clear(); |
101 | 114 |
102 if (m_paths.empty()) return; | 115 if (m_paths.empty()) return; |
103 | 116 |
104 populateFor(m_paths.begin()->first, 0); | 117 populateFor(m_paths.begin()->first, -1); |
105 } | 118 } |
106 | 119 |
107 void | 120 void |
108 PluginPathConfigurator::populateFor(QString type, int makeCurrent) | 121 PluginPathConfigurator::populateFor(QString type, int makeCurrent) |
109 { | 122 { |
123 QString envVariable = m_paths.at(type).envVariable; | |
124 bool useEnvVariable = m_paths.at(type).useEnvVariable; | |
125 m_envOverride->setText | |
126 (tr("Allow the %1 environment variable to override this") | |
127 .arg(envVariable)); | |
128 m_envOverride->setCheckState(useEnvVariable ? Qt::Checked : Qt::Unchecked); | |
129 | |
110 m_list->clear(); | 130 m_list->clear(); |
111 | 131 |
112 for (int i = 0; i < m_pluginTypeSelector->count(); ++i) { | 132 for (int i = 0; i < m_pluginTypeSelector->count(); ++i) { |
113 if (type == m_pluginTypeSelector->itemText(i)) { | 133 if (type == m_pluginTypeSelector->itemText(i)) { |
114 m_pluginTypeSelector->setCurrentIndex(i); | 134 m_pluginTypeSelector->setCurrentIndex(i); |
119 | 139 |
120 for (int i = 0; i < path.size(); ++i) { | 140 for (int i = 0; i < path.size(); ++i) { |
121 m_list->addItem(path[i]); | 141 m_list->addItem(path[i]); |
122 } | 142 } |
123 | 143 |
124 if (makeCurrent >= 0 && makeCurrent < path.size()) { | 144 if (makeCurrent < path.size()) { |
125 m_list->setCurrentRow(makeCurrent); | 145 m_list->setCurrentRow(makeCurrent); |
146 currentLocationChanged(makeCurrent); | |
126 } | 147 } |
127 } | 148 } |
128 | 149 |
129 void | 150 void |
130 PluginPathConfigurator::currentLocationChanged(int i) | 151 PluginPathConfigurator::currentLocationChanged(int i) |
131 { | 152 { |
132 QString type = m_pluginTypeSelector->currentText(); | 153 QString type = m_pluginTypeSelector->currentText(); |
133 QStringList path = m_paths.at(type).directories; | 154 QStringList path = m_paths.at(type).directories; |
134 m_up->setEnabled(i > 0); | 155 m_up->setEnabled(i > 0); |
135 m_down->setEnabled(i + 1 < path.size()); | 156 m_down->setEnabled(i >= 0 && i + 1 < path.size()); |
136 m_delete->setEnabled(i < path.size()); | 157 m_delete->setEnabled(i >= 0 && i < path.size()); |
158 m_reset->setEnabled(path != m_originalPaths.at(type).directories); | |
137 } | 159 } |
138 | 160 |
139 void | 161 void |
140 PluginPathConfigurator::currentTypeChanged(QString type) | 162 PluginPathConfigurator::currentTypeChanged(QString type) |
141 { | 163 { |
142 populateFor(type, 0); | 164 populateFor(type, -1); |
165 } | |
166 | |
167 void | |
168 PluginPathConfigurator::envOverrideChanged(int ) | |
169 { | |
170 //!!! | |
143 } | 171 } |
144 | 172 |
145 void | 173 void |
146 PluginPathConfigurator::upClicked() | 174 PluginPathConfigurator::upClicked() |
147 { | 175 { |
148 QString type = m_pluginTypeSelector->currentText(); | 176 QString type = m_pluginTypeSelector->currentText(); |
149 QStringList path = m_paths.at(type).directories; | 177 QStringList path = m_paths.at(type).directories; |
150 QString variable = m_paths.at(type).envVariable; | |
151 | 178 |
152 int current = m_list->currentRow(); | 179 int current = m_list->currentRow(); |
153 if (current <= 0) return; | 180 if (current <= 0) return; |
154 | 181 |
155 QStringList newPath; | 182 QStringList newPath; |
160 ++i; | 187 ++i; |
161 } else { | 188 } else { |
162 newPath.push_back(path[i]); | 189 newPath.push_back(path[i]); |
163 } | 190 } |
164 } | 191 } |
165 m_paths[type] = { newPath, variable }; | 192 |
193 auto newEntry = m_paths.at(type); | |
194 newEntry.directories = newPath; | |
195 m_paths[type] = newEntry; | |
166 | 196 |
167 populateFor(type, current - 1); | 197 populateFor(type, current - 1); |
168 } | 198 } |
169 | 199 |
170 void | 200 void |
171 PluginPathConfigurator::downClicked() | 201 PluginPathConfigurator::downClicked() |
172 { | 202 { |
173 QString type = m_pluginTypeSelector->currentText(); | 203 QString type = m_pluginTypeSelector->currentText(); |
174 QStringList path = m_paths.at(type).directories; | 204 QStringList path = m_paths.at(type).directories; |
175 QString variable = m_paths.at(type).envVariable; | |
176 | 205 |
177 int current = m_list->currentRow(); | 206 int current = m_list->currentRow(); |
178 if (current < 0 || current + 1 >= path.size()) return; | 207 if (current < 0 || current + 1 >= path.size()) return; |
179 | 208 |
180 QStringList newPath; | 209 QStringList newPath; |
185 ++i; | 214 ++i; |
186 } else { | 215 } else { |
187 newPath.push_back(path[i]); | 216 newPath.push_back(path[i]); |
188 } | 217 } |
189 } | 218 } |
190 m_paths[type] = { newPath, variable }; | 219 |
220 auto newEntry = m_paths.at(type); | |
221 newEntry.directories = newPath; | |
222 m_paths[type] = newEntry; | |
191 | 223 |
192 populateFor(type, current + 1); | 224 populateFor(type, current + 1); |
193 } | 225 } |
194 | 226 |
195 void | 227 void |
196 PluginPathConfigurator::deleteClicked() | 228 PluginPathConfigurator::deleteClicked() |
197 { | 229 { |
198 QString type = m_pluginTypeSelector->currentText(); | 230 QString type = m_pluginTypeSelector->currentText(); |
199 QStringList path = m_paths.at(type).directories; | 231 QStringList path = m_paths.at(type).directories; |
200 QString variable = m_paths.at(type).envVariable; | |
201 | 232 |
202 int current = m_list->currentRow(); | 233 int current = m_list->currentRow(); |
234 if (current < 0) return; | |
203 | 235 |
204 QStringList newPath; | 236 QStringList newPath; |
205 for (int i = 0; i < path.size(); ++i) { | 237 for (int i = 0; i < path.size(); ++i) { |
206 if (i != current) { | 238 if (i != current) { |
207 newPath.push_back(path[i]); | 239 newPath.push_back(path[i]); |
208 } | 240 } |
209 } | 241 } |
210 m_paths[type] = { newPath, variable }; | 242 |
243 auto newEntry = m_paths.at(type); | |
244 newEntry.directories = newPath; | |
245 m_paths[type] = newEntry; | |
211 | 246 |
212 populateFor(type, current < newPath.size() ? current : current-1); | 247 populateFor(type, current < newPath.size() ? current : current-1); |
213 } | 248 } |
249 | |
250 void | |
251 PluginPathConfigurator::resetClicked() | |
252 { | |
253 QString type = m_pluginTypeSelector->currentText(); | |
254 m_paths[type] = m_originalPaths[type]; | |
255 populateFor(type, -1); | |
256 } |