comparison widgets/PluginPathConfigurator.cpp @ 1291:b5c71304286e plugin-path-config

Add "Add"
author Chris Cannam
date Wed, 23 May 2018 16:24:35 +0100
parents 050eca637c19
children 41824255ddf2
comparison
equal deleted inserted replaced
1290:050eca637c19 1291:b5c71304286e
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 #include <QCheckBox>
23 #include <QFileDialog>
23 24
24 #include "IconLoader.h" 25 #include "IconLoader.h"
25 #include "WidgetScale.h" 26 #include "WidgetScale.h"
26 27
27 PluginPathConfigurator::PluginPathConfigurator(QWidget *parent) : 28 PluginPathConfigurator::PluginPathConfigurator(QWidget *parent) :
28 QFrame(parent) 29 QFrame(parent)
29 { 30 {
30 m_layout = new QGridLayout; 31 m_layout = new QGridLayout;
31 setLayout(m_layout); 32 setLayout(m_layout);
33
34 QHBoxLayout *buttons = new QHBoxLayout;
35
36 m_down = new QPushButton;
37 m_down->setIcon(IconLoader().load("down"));
38 m_down->setToolTip(tr("Move the selected location later in the list"));
39 connect(m_down, SIGNAL(clicked()), this, SLOT(downClicked()));
40 buttons->addWidget(m_down);
41
42 m_up = new QPushButton;
43 m_up->setIcon(IconLoader().load("up"));
44 m_up->setToolTip(tr("Move the selected location earlier in the list"));
45 connect(m_up, SIGNAL(clicked()), this, SLOT(upClicked()));
46 buttons->addWidget(m_up);
47
48 m_add = new QPushButton;
49 m_add->setIcon(IconLoader().load("plus"));
50 m_add->setToolTip(tr("Move the selected location earlier in the list"));
51 connect(m_add, SIGNAL(clicked()), this, SLOT(addClicked()));
52 buttons->addWidget(m_add);
53
54 m_delete = new QPushButton;
55 m_delete->setIcon(IconLoader().load("datadelete"));
56 m_delete->setToolTip(tr("Remove the selected location from the list"));
57 connect(m_delete, SIGNAL(clicked()), this, SLOT(deleteClicked()));
58 buttons->addWidget(m_delete);
59
60 m_reset = new QPushButton;
61 m_reset->setText(tr("Reset"));
62 m_reset->setToolTip(tr("Reset the list for this plugin type to its default"));
63 connect(m_reset, SIGNAL(clicked()), this, SLOT(resetClicked()));
64 buttons->addWidget(m_reset);
32 65
33 int row = 0; 66 int row = 0;
34 67
35 m_header = new QLabel; 68 m_header = new QLabel;
36 m_header->setText(tr("Plugin locations for plugin type:")); 69 m_header->setText(tr("Plugin locations for plugin type:"));
40 m_layout->addWidget(m_pluginTypeSelector, row, 1, Qt::AlignLeft); 73 m_layout->addWidget(m_pluginTypeSelector, row, 1, Qt::AlignLeft);
41 connect(m_pluginTypeSelector, SIGNAL(currentTextChanged(QString)), 74 connect(m_pluginTypeSelector, SIGNAL(currentTextChanged(QString)),
42 this, SLOT(currentTypeChanged(QString))); 75 this, SLOT(currentTypeChanged(QString)));
43 76
44 m_layout->setColumnStretch(1, 10); 77 m_layout->setColumnStretch(1, 10);
45
46 ++row; 78 ++row;
47 79
48 m_list = new QListWidget; 80 m_list = new QListWidget;
49 m_layout->addWidget(m_list, row, 0, 1, 3); 81 m_layout->addWidget(m_list, row, 0, 1, 3);
50 m_layout->setRowStretch(row, 20); 82 m_layout->setRowStretch(row, 20);
51 connect(m_list, SIGNAL(currentRowChanged(int)), 83 connect(m_list, SIGNAL(currentRowChanged(int)),
52 this, SLOT(currentLocationChanged(int))); 84 this, SLOT(currentLocationChanged(int)));
53 ++row; 85 ++row;
54
55 QHBoxLayout *buttons = new QHBoxLayout;
56
57 m_down = new QPushButton;
58 m_down->setIcon(IconLoader().load("down"));
59 m_down->setToolTip(tr("Move the selected location later in the list"));
60 connect(m_down, SIGNAL(clicked()), this, SLOT(downClicked()));
61 buttons->addWidget(m_down);
62
63 m_up = new QPushButton;
64 m_up->setIcon(IconLoader().load("up"));
65 m_up->setToolTip(tr("Move the selected location earlier in the list"));
66 connect(m_up, SIGNAL(clicked()), this, SLOT(upClicked()));
67 buttons->addWidget(m_up);
68
69 m_delete = new QPushButton;
70 m_delete->setIcon(IconLoader().load("datadelete"));
71 m_delete->setToolTip(tr("Remove the selected location from the list"));
72 connect(m_delete, SIGNAL(clicked()), this, SLOT(deleteClicked()));
73 buttons->addWidget(m_delete);
74
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 86
81 m_layout->addLayout(buttons, row, 2); 87 m_layout->addLayout(buttons, row, 2);
82 ++row; 88 ++row;
83 89
84 m_envOverride = new QCheckBox; 90 m_envOverride = new QCheckBox;
85 connect(m_envOverride, SIGNAL(stateChanged(int)), 91 connect(m_envOverride, SIGNAL(stateChanged(int)),
86 this, SLOT(envOverrideChanged(int))); 92 this, SLOT(envOverrideChanged(int)));
87 m_layout->addWidget(m_envOverride, row, 0, 1, 3); 93 m_layout->addWidget(m_envOverride, row, 0, 1, 3);
94 ++row;
88 } 95 }
89 96
90 PluginPathConfigurator::~PluginPathConfigurator() 97 PluginPathConfigurator::~PluginPathConfigurator()
91 { 98 {
92 } 99 }
121 PluginPathConfigurator::populateFor(QString type, int makeCurrent) 128 PluginPathConfigurator::populateFor(QString type, int makeCurrent)
122 { 129 {
123 QString envVariable = m_paths.at(type).envVariable; 130 QString envVariable = m_paths.at(type).envVariable;
124 bool useEnvVariable = m_paths.at(type).useEnvVariable; 131 bool useEnvVariable = m_paths.at(type).useEnvVariable;
125 m_envOverride->setText 132 m_envOverride->setText
126 (tr("Allow the %1 environment variable to override this") 133 (tr("Allow the %1 environment variable to take priority over this")
127 .arg(envVariable)); 134 .arg(envVariable));
128 m_envOverride->setCheckState(useEnvVariable ? Qt::Checked : Qt::Unchecked); 135 m_envOverride->setCheckState(useEnvVariable ? Qt::Checked : Qt::Unchecked);
129 136
130 m_list->clear(); 137 m_list->clear();
131 138
223 230
224 populateFor(type, current + 1); 231 populateFor(type, current + 1);
225 } 232 }
226 233
227 void 234 void
235 PluginPathConfigurator::addClicked()
236 {
237 QString type = m_pluginTypeSelector->currentText();
238
239 QString newDir = QFileDialog::getExistingDirectory
240 (this, tr("Choose directory to add"));
241
242 if (newDir == QString()) return;
243
244 auto newEntry = m_paths.at(type);
245 newEntry.directories.push_back(newDir);
246 m_paths[type] = newEntry;
247
248 populateFor(type, newEntry.directories.size() - 1);
249 }
250
251 void
228 PluginPathConfigurator::deleteClicked() 252 PluginPathConfigurator::deleteClicked()
229 { 253 {
230 QString type = m_pluginTypeSelector->currentText(); 254 QString type = m_pluginTypeSelector->currentText();
231 QStringList path = m_paths.at(type).directories; 255 QStringList path = m_paths.at(type).directories;
232 256