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@1287: #include Chris@1288: #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@1287: QFrame(parent) Chris@1285: { Chris@1285: m_layout = new QGridLayout; Chris@1285: setLayout(m_layout); Chris@1287: Chris@1287: int row = 0; Chris@1287: Chris@1287: QLabel *header = new QLabel; Chris@1287: header->setText(tr("Plugin locations")); Chris@1287: m_layout->addWidget(header, row, 0); Chris@1287: ++row; Chris@1287: Chris@1287: m_list = new QListWidget; Chris@1287: m_layout->addWidget(m_list, row, 0, 1, 2); Chris@1287: m_layout->setRowStretch(row, 10); Chris@1287: m_layout->setColumnStretch(0, 10); Chris@1288: connect(m_list, SIGNAL(currentRowChanged(int)), Chris@1288: this, SLOT(currentLocationChanged(int))); Chris@1287: ++row; Chris@1287: Chris@1287: QHBoxLayout *buttons = new QHBoxLayout; Chris@1287: Chris@1288: m_down = new QPushButton; Chris@1288: m_down->setIcon(IconLoader().load("down")); Chris@1288: m_down->setToolTip(tr("Move the selected location later in the list")); Chris@1288: m_down->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16))); Chris@1288: connect(m_down, SIGNAL(clicked()), this, SLOT(downClicked())); Chris@1288: buttons->addWidget(m_down); Chris@1287: Chris@1288: m_up = new QPushButton; Chris@1288: m_up->setIcon(IconLoader().load("up")); Chris@1288: m_up->setToolTip(tr("Move the selected location earlier in the list")); Chris@1288: m_up->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16))); Chris@1288: connect(m_up, SIGNAL(clicked()), this, SLOT(upClicked())); Chris@1288: buttons->addWidget(m_up); Chris@1287: Chris@1288: m_delete = new QPushButton; Chris@1288: m_delete->setIcon(IconLoader().load("datadelete")); Chris@1288: m_delete->setToolTip(tr("Remove the selected location from the list")); Chris@1288: m_delete->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16))); Chris@1288: connect(m_delete, SIGNAL(clicked()), this, SLOT(deleteClicked())); Chris@1288: buttons->addWidget(m_delete); Chris@1287: Chris@1287: m_layout->addLayout(buttons, row, 1); Chris@1287: ++row; 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@1287: PluginPathConfigurator::populate(int makeCurrent) Chris@1285: { Chris@1287: m_list->clear(); Chris@1286: Chris@1285: for (int i = 0; i < m_path.size(); ++i) { Chris@1287: m_list->addItem(m_path[i]); Chris@1287: } Chris@1285: Chris@1287: if (makeCurrent >= 0 && makeCurrent < m_path.size()) { Chris@1287: m_list->setCurrentRow(makeCurrent); Chris@1286: } Chris@1285: } Chris@1285: Chris@1285: void Chris@1288: PluginPathConfigurator::currentLocationChanged(int i) Chris@1288: { Chris@1288: m_up->setEnabled(i > 0); Chris@1288: m_down->setEnabled(i + 1 < m_path.size()); Chris@1288: m_delete->setEnabled(i < m_path.size()); Chris@1288: } Chris@1288: Chris@1288: void Chris@1285: PluginPathConfigurator::upClicked() Chris@1285: { Chris@1287: int current = m_list->currentRow(); Chris@1287: if (current <= 0) return; Chris@1287: Chris@1286: QStringList newPath; Chris@1286: for (int i = 0; i < m_path.size(); ++i) { Chris@1287: if (i + 1 == current) { 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@1287: Chris@1287: populate(current - 1); Chris@1285: } Chris@1285: Chris@1285: void Chris@1285: PluginPathConfigurator::downClicked() Chris@1285: { Chris@1287: int current = m_list->currentRow(); Chris@1287: if (current < 0 || current + 1 >= m_path.size()) return; Chris@1287: Chris@1286: QStringList newPath; Chris@1286: for (int i = 0; i < m_path.size(); ++i) { Chris@1287: if (i == current) { 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@1287: Chris@1287: populate(current + 1); Chris@1285: } Chris@1285: Chris@1285: void Chris@1285: PluginPathConfigurator::deleteClicked() Chris@1285: { Chris@1287: int current = m_list->currentRow(); Chris@1287: Chris@1286: QStringList newPath; Chris@1286: for (int i = 0; i < m_path.size(); ++i) { Chris@1287: if (i != current) { Chris@1286: newPath.push_back(m_path[i]); Chris@1286: } Chris@1286: } Chris@1286: m_path = newPath; Chris@1287: Chris@1287: populate(current < m_path.size() ? current : current-1); Chris@1285: }