Chris@1285
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@1285
|
2
|
Chris@1285
|
3 /*
|
Chris@1285
|
4 Sonic Visualiser
|
Chris@1285
|
5 An audio file viewer and annotation editor.
|
Chris@1285
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@1285
|
7
|
Chris@1285
|
8 This program is free software; you can redistribute it and/or
|
Chris@1285
|
9 modify it under the terms of the GNU General Public License as
|
Chris@1285
|
10 published by the Free Software Foundation; either version 2 of the
|
Chris@1285
|
11 License, or (at your option) any later version. See the file
|
Chris@1285
|
12 COPYING included with this distribution for more information.
|
Chris@1285
|
13 */
|
Chris@1285
|
14
|
Chris@1285
|
15 #include "PluginPathConfigurator.h"
|
Chris@1285
|
16
|
Chris@1285
|
17 #include <QPushButton>
|
Chris@1287
|
18 #include <QListWidget>
|
Chris@1285
|
19 #include <QLabel>
|
Chris@1285
|
20
|
Chris@1285
|
21 #include "IconLoader.h"
|
Chris@1285
|
22 #include "WidgetScale.h"
|
Chris@1285
|
23
|
Chris@1285
|
24 PluginPathConfigurator::PluginPathConfigurator(QWidget *parent) :
|
Chris@1287
|
25 QFrame(parent)
|
Chris@1285
|
26 {
|
Chris@1285
|
27 m_layout = new QGridLayout;
|
Chris@1285
|
28 setLayout(m_layout);
|
Chris@1287
|
29
|
Chris@1287
|
30 int row = 0;
|
Chris@1287
|
31
|
Chris@1287
|
32 QLabel *header = new QLabel;
|
Chris@1287
|
33 header->setText(tr("Plugin locations"));
|
Chris@1287
|
34 m_layout->addWidget(header, row, 0);
|
Chris@1287
|
35 ++row;
|
Chris@1287
|
36
|
Chris@1287
|
37 m_list = new QListWidget;
|
Chris@1287
|
38 m_layout->addWidget(m_list, row, 0, 1, 2);
|
Chris@1287
|
39 m_layout->setRowStretch(row, 10);
|
Chris@1287
|
40 m_layout->setColumnStretch(0, 10);
|
Chris@1287
|
41 ++row;
|
Chris@1287
|
42
|
Chris@1287
|
43 QHBoxLayout *buttons = new QHBoxLayout;
|
Chris@1287
|
44
|
Chris@1287
|
45 QPushButton *down = new QPushButton;
|
Chris@1287
|
46 down->setIcon(IconLoader().load("down"));
|
Chris@1287
|
47 down->setToolTip(tr("Move the selected location down in the list"));
|
Chris@1287
|
48 down->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16)));
|
Chris@1287
|
49 connect(down, SIGNAL(clicked()), this, SLOT(downClicked()));
|
Chris@1287
|
50 buttons->addWidget(down);
|
Chris@1287
|
51
|
Chris@1287
|
52 QPushButton *up = new QPushButton;
|
Chris@1287
|
53 up->setIcon(IconLoader().load("up"));
|
Chris@1287
|
54 up->setToolTip(tr("Move the selected location up in the list"));
|
Chris@1287
|
55 up->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16)));
|
Chris@1287
|
56 connect(up, SIGNAL(clicked()), this, SLOT(upClicked()));
|
Chris@1287
|
57 buttons->addWidget(up);
|
Chris@1287
|
58
|
Chris@1287
|
59 QPushButton *del = new QPushButton;
|
Chris@1287
|
60 del->setIcon(IconLoader().load("datadelete"));
|
Chris@1287
|
61 del->setToolTip(tr("Remove the selected location from the list"));
|
Chris@1287
|
62 del->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16)));
|
Chris@1287
|
63 connect(del, SIGNAL(clicked()), this, SLOT(deleteClicked()));
|
Chris@1287
|
64 buttons->addWidget(del);
|
Chris@1287
|
65
|
Chris@1287
|
66 m_layout->addLayout(buttons, row, 1);
|
Chris@1287
|
67 ++row;
|
Chris@1285
|
68 }
|
Chris@1285
|
69
|
Chris@1285
|
70 PluginPathConfigurator::~PluginPathConfigurator()
|
Chris@1285
|
71 {
|
Chris@1285
|
72 }
|
Chris@1285
|
73
|
Chris@1285
|
74 void
|
Chris@1285
|
75 PluginPathConfigurator::setPath(QStringList directories, QString envVariable)
|
Chris@1285
|
76 {
|
Chris@1285
|
77 m_path = directories;
|
Chris@1285
|
78 m_var = envVariable;
|
Chris@1285
|
79 populate();
|
Chris@1285
|
80 }
|
Chris@1285
|
81
|
Chris@1285
|
82 void
|
Chris@1287
|
83 PluginPathConfigurator::populate(int makeCurrent)
|
Chris@1285
|
84 {
|
Chris@1287
|
85 m_list->clear();
|
Chris@1286
|
86
|
Chris@1285
|
87 for (int i = 0; i < m_path.size(); ++i) {
|
Chris@1287
|
88 m_list->addItem(m_path[i]);
|
Chris@1287
|
89 }
|
Chris@1285
|
90
|
Chris@1287
|
91 if (makeCurrent >= 0 && makeCurrent < m_path.size()) {
|
Chris@1287
|
92 m_list->setCurrentRow(makeCurrent);
|
Chris@1286
|
93 }
|
Chris@1285
|
94 }
|
Chris@1285
|
95
|
Chris@1285
|
96 void
|
Chris@1285
|
97 PluginPathConfigurator::upClicked()
|
Chris@1285
|
98 {
|
Chris@1287
|
99 int current = m_list->currentRow();
|
Chris@1287
|
100 if (current <= 0) return;
|
Chris@1287
|
101
|
Chris@1286
|
102 QStringList newPath;
|
Chris@1286
|
103 for (int i = 0; i < m_path.size(); ++i) {
|
Chris@1287
|
104 if (i + 1 == current) {
|
Chris@1286
|
105 newPath.push_back(m_path[i+1]);
|
Chris@1286
|
106 newPath.push_back(m_path[i]);
|
Chris@1286
|
107 ++i;
|
Chris@1286
|
108 } else {
|
Chris@1286
|
109 newPath.push_back(m_path[i]);
|
Chris@1286
|
110 }
|
Chris@1286
|
111 }
|
Chris@1286
|
112 m_path = newPath;
|
Chris@1287
|
113
|
Chris@1287
|
114 populate(current - 1);
|
Chris@1285
|
115 }
|
Chris@1285
|
116
|
Chris@1285
|
117 void
|
Chris@1285
|
118 PluginPathConfigurator::downClicked()
|
Chris@1285
|
119 {
|
Chris@1287
|
120 int current = m_list->currentRow();
|
Chris@1287
|
121 if (current < 0 || current + 1 >= m_path.size()) return;
|
Chris@1287
|
122
|
Chris@1286
|
123 QStringList newPath;
|
Chris@1286
|
124 for (int i = 0; i < m_path.size(); ++i) {
|
Chris@1287
|
125 if (i == current) {
|
Chris@1286
|
126 newPath.push_back(m_path[i+1]);
|
Chris@1286
|
127 newPath.push_back(m_path[i]);
|
Chris@1286
|
128 ++i;
|
Chris@1286
|
129 } else {
|
Chris@1286
|
130 newPath.push_back(m_path[i]);
|
Chris@1286
|
131 }
|
Chris@1286
|
132 }
|
Chris@1286
|
133 m_path = newPath;
|
Chris@1287
|
134
|
Chris@1287
|
135 populate(current + 1);
|
Chris@1285
|
136 }
|
Chris@1285
|
137
|
Chris@1285
|
138 void
|
Chris@1285
|
139 PluginPathConfigurator::deleteClicked()
|
Chris@1285
|
140 {
|
Chris@1287
|
141 int current = m_list->currentRow();
|
Chris@1287
|
142
|
Chris@1286
|
143 QStringList newPath;
|
Chris@1286
|
144 for (int i = 0; i < m_path.size(); ++i) {
|
Chris@1287
|
145 if (i != current) {
|
Chris@1286
|
146 newPath.push_back(m_path[i]);
|
Chris@1286
|
147 }
|
Chris@1286
|
148 }
|
Chris@1286
|
149 m_path = newPath;
|
Chris@1287
|
150
|
Chris@1287
|
151 populate(current < m_path.size() ? current : current-1);
|
Chris@1285
|
152 }
|