annotate widgets/PluginPathConfigurator.cpp @ 1288:4683b6ffb76a plugin-path-config

Grey-out meaningless buttons
author Chris Cannam
date Tue, 15 May 2018 15:25:04 +0100
parents 2dd7f764c3a6
children ed04d3666d33
rev   line source
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@1288 19 #include <QGridLayout>
Chris@1285 20 #include <QLabel>
Chris@1285 21
Chris@1285 22 #include "IconLoader.h"
Chris@1285 23 #include "WidgetScale.h"
Chris@1285 24
Chris@1285 25 PluginPathConfigurator::PluginPathConfigurator(QWidget *parent) :
Chris@1287 26 QFrame(parent)
Chris@1285 27 {
Chris@1285 28 m_layout = new QGridLayout;
Chris@1285 29 setLayout(m_layout);
Chris@1287 30
Chris@1287 31 int row = 0;
Chris@1287 32
Chris@1287 33 QLabel *header = new QLabel;
Chris@1287 34 header->setText(tr("Plugin locations"));
Chris@1287 35 m_layout->addWidget(header, row, 0);
Chris@1287 36 ++row;
Chris@1287 37
Chris@1287 38 m_list = new QListWidget;
Chris@1287 39 m_layout->addWidget(m_list, row, 0, 1, 2);
Chris@1287 40 m_layout->setRowStretch(row, 10);
Chris@1287 41 m_layout->setColumnStretch(0, 10);
Chris@1288 42 connect(m_list, SIGNAL(currentRowChanged(int)),
Chris@1288 43 this, SLOT(currentLocationChanged(int)));
Chris@1287 44 ++row;
Chris@1287 45
Chris@1287 46 QHBoxLayout *buttons = new QHBoxLayout;
Chris@1287 47
Chris@1288 48 m_down = new QPushButton;
Chris@1288 49 m_down->setIcon(IconLoader().load("down"));
Chris@1288 50 m_down->setToolTip(tr("Move the selected location later in the list"));
Chris@1288 51 m_down->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16)));
Chris@1288 52 connect(m_down, SIGNAL(clicked()), this, SLOT(downClicked()));
Chris@1288 53 buttons->addWidget(m_down);
Chris@1287 54
Chris@1288 55 m_up = new QPushButton;
Chris@1288 56 m_up->setIcon(IconLoader().load("up"));
Chris@1288 57 m_up->setToolTip(tr("Move the selected location earlier in the list"));
Chris@1288 58 m_up->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16)));
Chris@1288 59 connect(m_up, SIGNAL(clicked()), this, SLOT(upClicked()));
Chris@1288 60 buttons->addWidget(m_up);
Chris@1287 61
Chris@1288 62 m_delete = new QPushButton;
Chris@1288 63 m_delete->setIcon(IconLoader().load("datadelete"));
Chris@1288 64 m_delete->setToolTip(tr("Remove the selected location from the list"));
Chris@1288 65 m_delete->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16)));
Chris@1288 66 connect(m_delete, SIGNAL(clicked()), this, SLOT(deleteClicked()));
Chris@1288 67 buttons->addWidget(m_delete);
Chris@1287 68
Chris@1287 69 m_layout->addLayout(buttons, row, 1);
Chris@1287 70 ++row;
Chris@1285 71 }
Chris@1285 72
Chris@1285 73 PluginPathConfigurator::~PluginPathConfigurator()
Chris@1285 74 {
Chris@1285 75 }
Chris@1285 76
Chris@1285 77 void
Chris@1285 78 PluginPathConfigurator::setPath(QStringList directories, QString envVariable)
Chris@1285 79 {
Chris@1285 80 m_path = directories;
Chris@1285 81 m_var = envVariable;
Chris@1285 82 populate();
Chris@1285 83 }
Chris@1285 84
Chris@1285 85 void
Chris@1287 86 PluginPathConfigurator::populate(int makeCurrent)
Chris@1285 87 {
Chris@1287 88 m_list->clear();
Chris@1286 89
Chris@1285 90 for (int i = 0; i < m_path.size(); ++i) {
Chris@1287 91 m_list->addItem(m_path[i]);
Chris@1287 92 }
Chris@1285 93
Chris@1287 94 if (makeCurrent >= 0 && makeCurrent < m_path.size()) {
Chris@1287 95 m_list->setCurrentRow(makeCurrent);
Chris@1286 96 }
Chris@1285 97 }
Chris@1285 98
Chris@1285 99 void
Chris@1288 100 PluginPathConfigurator::currentLocationChanged(int i)
Chris@1288 101 {
Chris@1288 102 m_up->setEnabled(i > 0);
Chris@1288 103 m_down->setEnabled(i + 1 < m_path.size());
Chris@1288 104 m_delete->setEnabled(i < m_path.size());
Chris@1288 105 }
Chris@1288 106
Chris@1288 107 void
Chris@1285 108 PluginPathConfigurator::upClicked()
Chris@1285 109 {
Chris@1287 110 int current = m_list->currentRow();
Chris@1287 111 if (current <= 0) return;
Chris@1287 112
Chris@1286 113 QStringList newPath;
Chris@1286 114 for (int i = 0; i < m_path.size(); ++i) {
Chris@1287 115 if (i + 1 == current) {
Chris@1286 116 newPath.push_back(m_path[i+1]);
Chris@1286 117 newPath.push_back(m_path[i]);
Chris@1286 118 ++i;
Chris@1286 119 } else {
Chris@1286 120 newPath.push_back(m_path[i]);
Chris@1286 121 }
Chris@1286 122 }
Chris@1286 123 m_path = newPath;
Chris@1287 124
Chris@1287 125 populate(current - 1);
Chris@1285 126 }
Chris@1285 127
Chris@1285 128 void
Chris@1285 129 PluginPathConfigurator::downClicked()
Chris@1285 130 {
Chris@1287 131 int current = m_list->currentRow();
Chris@1287 132 if (current < 0 || current + 1 >= m_path.size()) return;
Chris@1287 133
Chris@1286 134 QStringList newPath;
Chris@1286 135 for (int i = 0; i < m_path.size(); ++i) {
Chris@1287 136 if (i == current) {
Chris@1286 137 newPath.push_back(m_path[i+1]);
Chris@1286 138 newPath.push_back(m_path[i]);
Chris@1286 139 ++i;
Chris@1286 140 } else {
Chris@1286 141 newPath.push_back(m_path[i]);
Chris@1286 142 }
Chris@1286 143 }
Chris@1286 144 m_path = newPath;
Chris@1287 145
Chris@1287 146 populate(current + 1);
Chris@1285 147 }
Chris@1285 148
Chris@1285 149 void
Chris@1285 150 PluginPathConfigurator::deleteClicked()
Chris@1285 151 {
Chris@1287 152 int current = m_list->currentRow();
Chris@1287 153
Chris@1286 154 QStringList newPath;
Chris@1286 155 for (int i = 0; i < m_path.size(); ++i) {
Chris@1287 156 if (i != current) {
Chris@1286 157 newPath.push_back(m_path[i]);
Chris@1286 158 }
Chris@1286 159 }
Chris@1286 160 m_path = newPath;
Chris@1287 161
Chris@1287 162 populate(current < m_path.size() ? current : current-1);
Chris@1285 163 }