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@1285
|
18 #include <QLabel>
|
Chris@1285
|
19
|
Chris@1285
|
20 #include "IconLoader.h"
|
Chris@1285
|
21 #include "WidgetScale.h"
|
Chris@1285
|
22
|
Chris@1285
|
23 PluginPathConfigurator::PluginPathConfigurator(QWidget *parent) :
|
Chris@1286
|
24 QFrame(parent),
|
Chris@1286
|
25 m_innerFrame(0)
|
Chris@1285
|
26 {
|
Chris@1285
|
27 setFrameStyle(StyledPanel | Sunken);
|
Chris@1285
|
28 m_layout = new QGridLayout;
|
Chris@1285
|
29 setLayout(m_layout);
|
Chris@1285
|
30 }
|
Chris@1285
|
31
|
Chris@1285
|
32 PluginPathConfigurator::~PluginPathConfigurator()
|
Chris@1285
|
33 {
|
Chris@1285
|
34 }
|
Chris@1285
|
35
|
Chris@1285
|
36 void
|
Chris@1285
|
37 PluginPathConfigurator::setPath(QStringList directories, QString envVariable)
|
Chris@1285
|
38 {
|
Chris@1285
|
39 m_path = directories;
|
Chris@1285
|
40 m_var = envVariable;
|
Chris@1285
|
41 populate();
|
Chris@1285
|
42 }
|
Chris@1285
|
43
|
Chris@1285
|
44 void
|
Chris@1285
|
45 PluginPathConfigurator::populate()
|
Chris@1285
|
46 {
|
Chris@1286
|
47 delete m_innerFrame;
|
Chris@1286
|
48 m_innerFrame = new QWidget;
|
Chris@1286
|
49 m_layout->addWidget(m_innerFrame, 0, 0);
|
Chris@1286
|
50
|
Chris@1286
|
51 QGridLayout *innerLayout = new QGridLayout;
|
Chris@1286
|
52 m_innerFrame->setLayout(innerLayout);
|
Chris@1286
|
53
|
Chris@1286
|
54 QLabel *header = new QLabel(m_innerFrame);
|
Chris@1285
|
55 header->setText(QString("<b>%1</b>").arg(tr("Location")));
|
Chris@1286
|
56 innerLayout->addWidget(header, 0, 3);
|
Chris@1285
|
57
|
Chris@1285
|
58 for (int i = 0; i < m_path.size(); ++i) {
|
Chris@1285
|
59
|
Chris@1285
|
60 int col = 0;
|
Chris@1285
|
61 int row = i + 1;
|
Chris@1285
|
62 QString dir = m_path[i];
|
Chris@1285
|
63
|
Chris@1285
|
64 if (i > 0) {
|
Chris@1286
|
65 QPushButton *up = new QPushButton(m_innerFrame);
|
Chris@1286
|
66 up->setObjectName(QString("%1").arg(i));
|
Chris@1285
|
67 up->setIcon(IconLoader().load("up"));
|
Chris@1285
|
68 up->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16)));
|
Chris@1285
|
69 connect(up, SIGNAL(clicked()), this, SLOT(upClicked()));
|
Chris@1286
|
70 innerLayout->addWidget(up, row, col);
|
Chris@1285
|
71 }
|
Chris@1285
|
72 ++col;
|
Chris@1285
|
73
|
Chris@1285
|
74 if (i + 1 < m_path.size()) {
|
Chris@1286
|
75 QPushButton *down = new QPushButton(m_innerFrame);
|
Chris@1286
|
76 down->setObjectName(QString("%1").arg(i));
|
Chris@1285
|
77 down->setIcon(IconLoader().load("down"));
|
Chris@1285
|
78 down->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16)));
|
Chris@1285
|
79 connect(down, SIGNAL(clicked()), this, SLOT(downClicked()));
|
Chris@1286
|
80 innerLayout->addWidget(down, row, col);
|
Chris@1285
|
81 }
|
Chris@1285
|
82 ++col;
|
Chris@1285
|
83
|
Chris@1286
|
84 QPushButton *del = new QPushButton(m_innerFrame);
|
Chris@1286
|
85 del->setObjectName(QString("%1").arg(i));
|
Chris@1285
|
86 del->setIcon(IconLoader().load("datadelete"));
|
Chris@1285
|
87 del->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16)));
|
Chris@1285
|
88 connect(del, SIGNAL(clicked()), this, SLOT(deleteClicked()));
|
Chris@1286
|
89 innerLayout->addWidget(del, row, col);
|
Chris@1285
|
90 ++col;
|
Chris@1285
|
91
|
Chris@1286
|
92 QLabel *dirLabel = new QLabel(m_innerFrame);
|
Chris@1286
|
93 dirLabel->setObjectName(QString("%1").arg(i));
|
Chris@1285
|
94 dirLabel->setText(dir);
|
Chris@1286
|
95 innerLayout->addWidget(dirLabel, row, col);
|
Chris@1286
|
96 innerLayout->setColumnStretch(col, 10);
|
Chris@1285
|
97 ++col;
|
Chris@1286
|
98 }
|
Chris@1285
|
99 }
|
Chris@1285
|
100
|
Chris@1285
|
101 void
|
Chris@1285
|
102 PluginPathConfigurator::upClicked()
|
Chris@1285
|
103 {
|
Chris@1286
|
104 bool ok = false;
|
Chris@1286
|
105 int n = sender()->objectName().toInt(&ok);
|
Chris@1286
|
106 if (!ok) {
|
Chris@1286
|
107 SVCERR << "upClicked: unable to find index" << endl;
|
Chris@1286
|
108 return;
|
Chris@1286
|
109 }
|
Chris@1286
|
110 QStringList newPath;
|
Chris@1286
|
111 for (int i = 0; i < m_path.size(); ++i) {
|
Chris@1286
|
112 if (i + 1 == n) {
|
Chris@1286
|
113 newPath.push_back(m_path[i+1]);
|
Chris@1286
|
114 newPath.push_back(m_path[i]);
|
Chris@1286
|
115 ++i;
|
Chris@1286
|
116 } else {
|
Chris@1286
|
117 newPath.push_back(m_path[i]);
|
Chris@1286
|
118 }
|
Chris@1286
|
119 }
|
Chris@1286
|
120 m_path = newPath;
|
Chris@1286
|
121 populate();
|
Chris@1285
|
122 }
|
Chris@1285
|
123
|
Chris@1285
|
124 void
|
Chris@1285
|
125 PluginPathConfigurator::downClicked()
|
Chris@1285
|
126 {
|
Chris@1286
|
127 bool ok = false;
|
Chris@1286
|
128 int n = sender()->objectName().toInt(&ok);
|
Chris@1286
|
129 if (!ok) {
|
Chris@1286
|
130 SVCERR << "downClicked: unable to find index" << endl;
|
Chris@1286
|
131 return;
|
Chris@1286
|
132 }
|
Chris@1286
|
133 QStringList newPath;
|
Chris@1286
|
134 for (int i = 0; i < m_path.size(); ++i) {
|
Chris@1286
|
135 if (i == n) {
|
Chris@1286
|
136 newPath.push_back(m_path[i+1]);
|
Chris@1286
|
137 newPath.push_back(m_path[i]);
|
Chris@1286
|
138 ++i;
|
Chris@1286
|
139 } else {
|
Chris@1286
|
140 newPath.push_back(m_path[i]);
|
Chris@1286
|
141 }
|
Chris@1286
|
142 }
|
Chris@1286
|
143 m_path = newPath;
|
Chris@1286
|
144 populate();
|
Chris@1285
|
145 }
|
Chris@1285
|
146
|
Chris@1285
|
147 void
|
Chris@1285
|
148 PluginPathConfigurator::deleteClicked()
|
Chris@1285
|
149 {
|
Chris@1286
|
150 bool ok = false;
|
Chris@1286
|
151 int n = sender()->objectName().toInt(&ok);
|
Chris@1286
|
152 if (!ok) {
|
Chris@1286
|
153 SVCERR << "deleteClicked: unable to find index" << endl;
|
Chris@1286
|
154 return;
|
Chris@1286
|
155 }
|
Chris@1286
|
156 QStringList newPath;
|
Chris@1286
|
157 for (int i = 0; i < m_path.size(); ++i) {
|
Chris@1286
|
158 if (i != n) {
|
Chris@1286
|
159 newPath.push_back(m_path[i]);
|
Chris@1286
|
160 }
|
Chris@1286
|
161 }
|
Chris@1286
|
162 m_path = newPath;
|
Chris@1286
|
163 populate();
|
Chris@1285
|
164 }
|