Chris@126: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@126: Chris@126: /* Chris@126: Sonic Visualiser Chris@126: An audio file viewer and annotation editor. Chris@126: Centre for Digital Music, Queen Mary, University of London. Chris@229: This file copyright 2006 Chris Cannam. Chris@126: Chris@126: This program is free software; you can redistribute it and/or Chris@126: modify it under the terms of the GNU General Public License as Chris@126: published by the Free Software Foundation; either version 2 of the Chris@126: License, or (at your option) any later version. See the file Chris@126: COPYING included with this distribution for more information. Chris@126: */ Chris@126: Chris@126: #include "ListInputDialog.h" Chris@126: Chris@126: #include Chris@126: #include Chris@126: #include Chris@126: #include Chris@126: #include Chris@126: #include Chris@282: #include Chris@126: Chris@126: ListInputDialog::ListInputDialog(QWidget *parent, const QString &title, Chris@126: const QString &labelText, const QStringList &list, Chris@616: int current) : Chris@616: QDialog(parent), Chris@126: m_strings(list) Chris@126: { Chris@126: setWindowTitle(title); Chris@126: Chris@126: QVBoxLayout *vbox = new QVBoxLayout(this); Chris@126: Chris@126: QLabel *label = new QLabel(labelText, this); Chris@126: vbox->addWidget(label); Chris@126: vbox->addStretch(1); Chris@126: Chris@126: int count = 0; Chris@126: for (QStringList::const_iterator i = list.begin(); i != list.end(); ++i) { Chris@126: QRadioButton *radio = new QRadioButton(*i); Chris@126: if (current == count++) radio->setChecked(true); Chris@126: m_radioButtons.push_back(radio); Chris@126: vbox->addWidget(radio); Chris@126: } Chris@126: Chris@126: vbox->addStretch(1); Chris@126: Chris@231: m_footnote = new QLabel; Chris@231: vbox->addWidget(m_footnote); Chris@231: m_footnote->hide(); Chris@282: Chris@282: QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok | Chris@282: QDialogButtonBox::Cancel); Chris@282: vbox->addWidget(bb); Chris@282: connect(bb, SIGNAL(accepted()), this, SLOT(accept())); Chris@282: connect(bb, SIGNAL(rejected()), this, SLOT(reject())); Chris@126: } Chris@126: Chris@126: ListInputDialog::~ListInputDialog() Chris@126: { Chris@126: } Chris@126: Chris@126: QString Chris@126: ListInputDialog::getCurrentString() const Chris@126: { Chris@249: for (size_t i = 0; i < m_radioButtons.size(); ++i) { Chris@126: if (m_radioButtons[i]->isChecked()) { Chris@126: return m_strings[i]; Chris@126: } Chris@126: } Chris@126: return ""; Chris@126: } Chris@126: Chris@231: void Chris@231: ListInputDialog::setItemAvailability(int item, bool available) Chris@231: { Chris@231: m_radioButtons[item]->setEnabled(available); Chris@231: } Chris@231: Chris@231: void Chris@231: ListInputDialog::setFootnote(QString footnote) Chris@231: { Chris@231: m_footnote->setText(footnote); Chris@231: m_footnote->show(); Chris@231: } Chris@231: Chris@126: QString Chris@126: ListInputDialog::getItem(QWidget *parent, const QString &title, Chris@126: const QString &label, const QStringList &list, Chris@616: int current, bool *ok) Chris@126: { Chris@616: ListInputDialog dialog(parent, title, label, list, current); Chris@126: Chris@126: bool accepted = (dialog.exec() == QDialog::Accepted); Chris@126: if (ok) *ok = accepted; Chris@126: Chris@126: return dialog.getCurrentString(); Chris@126: } Chris@126: