Chris@1285: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@1285: Chris@1285: /* Chris@1285: Sonic Visualiser Chris@1285: An audio file viewer and annotation editor. Chris@1285: Centre for Digital Music, Queen Mary, University of London. Chris@1285: Chris@1285: This program is free software; you can redistribute it and/or Chris@1285: modify it under the terms of the GNU General Public License as Chris@1285: published by the Free Software Foundation; either version 2 of the Chris@1285: License, or (at your option) any later version. See the file Chris@1285: COPYING included with this distribution for more information. Chris@1285: */ Chris@1285: Chris@1285: #include "PluginPathConfigurator.h" Chris@1285: Chris@1285: #include Chris@1285: #include Chris@1285: Chris@1285: #include "IconLoader.h" Chris@1285: #include "WidgetScale.h" Chris@1285: Chris@1285: PluginPathConfigurator::PluginPathConfigurator(QWidget *parent) : Chris@1286: QFrame(parent), Chris@1286: m_innerFrame(0) Chris@1285: { Chris@1285: setFrameStyle(StyledPanel | Sunken); Chris@1285: m_layout = new QGridLayout; Chris@1285: setLayout(m_layout); Chris@1285: } Chris@1285: Chris@1285: PluginPathConfigurator::~PluginPathConfigurator() Chris@1285: { Chris@1285: } Chris@1285: Chris@1285: void Chris@1285: PluginPathConfigurator::setPath(QStringList directories, QString envVariable) Chris@1285: { Chris@1285: m_path = directories; Chris@1285: m_var = envVariable; Chris@1285: populate(); Chris@1285: } Chris@1285: Chris@1285: void Chris@1285: PluginPathConfigurator::populate() Chris@1285: { Chris@1286: delete m_innerFrame; Chris@1286: m_innerFrame = new QWidget; Chris@1286: m_layout->addWidget(m_innerFrame, 0, 0); Chris@1286: Chris@1286: QGridLayout *innerLayout = new QGridLayout; Chris@1286: m_innerFrame->setLayout(innerLayout); Chris@1286: Chris@1286: QLabel *header = new QLabel(m_innerFrame); Chris@1285: header->setText(QString("%1").arg(tr("Location"))); Chris@1286: innerLayout->addWidget(header, 0, 3); Chris@1285: Chris@1285: for (int i = 0; i < m_path.size(); ++i) { Chris@1285: Chris@1285: int col = 0; Chris@1285: int row = i + 1; Chris@1285: QString dir = m_path[i]; Chris@1285: Chris@1285: if (i > 0) { Chris@1286: QPushButton *up = new QPushButton(m_innerFrame); Chris@1286: up->setObjectName(QString("%1").arg(i)); Chris@1285: up->setIcon(IconLoader().load("up")); Chris@1285: up->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16))); Chris@1285: connect(up, SIGNAL(clicked()), this, SLOT(upClicked())); Chris@1286: innerLayout->addWidget(up, row, col); Chris@1285: } Chris@1285: ++col; Chris@1285: Chris@1285: if (i + 1 < m_path.size()) { Chris@1286: QPushButton *down = new QPushButton(m_innerFrame); Chris@1286: down->setObjectName(QString("%1").arg(i)); Chris@1285: down->setIcon(IconLoader().load("down")); Chris@1285: down->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16))); Chris@1285: connect(down, SIGNAL(clicked()), this, SLOT(downClicked())); Chris@1286: innerLayout->addWidget(down, row, col); Chris@1285: } Chris@1285: ++col; Chris@1285: Chris@1286: QPushButton *del = new QPushButton(m_innerFrame); Chris@1286: del->setObjectName(QString("%1").arg(i)); Chris@1285: del->setIcon(IconLoader().load("datadelete")); Chris@1285: del->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16))); Chris@1285: connect(del, SIGNAL(clicked()), this, SLOT(deleteClicked())); Chris@1286: innerLayout->addWidget(del, row, col); Chris@1285: ++col; Chris@1285: Chris@1286: QLabel *dirLabel = new QLabel(m_innerFrame); Chris@1286: dirLabel->setObjectName(QString("%1").arg(i)); Chris@1285: dirLabel->setText(dir); Chris@1286: innerLayout->addWidget(dirLabel, row, col); Chris@1286: innerLayout->setColumnStretch(col, 10); Chris@1285: ++col; Chris@1286: } Chris@1285: } Chris@1285: Chris@1285: void Chris@1285: PluginPathConfigurator::upClicked() Chris@1285: { Chris@1286: bool ok = false; Chris@1286: int n = sender()->objectName().toInt(&ok); Chris@1286: if (!ok) { Chris@1286: SVCERR << "upClicked: unable to find index" << endl; Chris@1286: return; Chris@1286: } Chris@1286: QStringList newPath; Chris@1286: for (int i = 0; i < m_path.size(); ++i) { Chris@1286: if (i + 1 == n) { Chris@1286: newPath.push_back(m_path[i+1]); Chris@1286: newPath.push_back(m_path[i]); Chris@1286: ++i; Chris@1286: } else { Chris@1286: newPath.push_back(m_path[i]); Chris@1286: } Chris@1286: } Chris@1286: m_path = newPath; Chris@1286: populate(); Chris@1285: } Chris@1285: Chris@1285: void Chris@1285: PluginPathConfigurator::downClicked() Chris@1285: { Chris@1286: bool ok = false; Chris@1286: int n = sender()->objectName().toInt(&ok); Chris@1286: if (!ok) { Chris@1286: SVCERR << "downClicked: unable to find index" << endl; Chris@1286: return; Chris@1286: } Chris@1286: QStringList newPath; Chris@1286: for (int i = 0; i < m_path.size(); ++i) { Chris@1286: if (i == n) { Chris@1286: newPath.push_back(m_path[i+1]); Chris@1286: newPath.push_back(m_path[i]); Chris@1286: ++i; Chris@1286: } else { Chris@1286: newPath.push_back(m_path[i]); Chris@1286: } Chris@1286: } Chris@1286: m_path = newPath; Chris@1286: populate(); Chris@1285: } Chris@1285: Chris@1285: void Chris@1285: PluginPathConfigurator::deleteClicked() Chris@1285: { Chris@1286: bool ok = false; Chris@1286: int n = sender()->objectName().toInt(&ok); Chris@1286: if (!ok) { Chris@1286: SVCERR << "deleteClicked: unable to find index" << endl; Chris@1286: return; Chris@1286: } Chris@1286: QStringList newPath; Chris@1286: for (int i = 0; i < m_path.size(); ++i) { Chris@1286: if (i != n) { Chris@1286: newPath.push_back(m_path[i]); Chris@1286: } Chris@1286: } Chris@1286: m_path = newPath; Chris@1286: populate(); Chris@1285: }