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@126: Chris@126: ListInputDialog::ListInputDialog(QWidget *parent, const QString &title, Chris@126: const QString &labelText, const QStringList &list, Chris@126: int current, Qt::WFlags f) : Chris@126: QDialog(parent, f), 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@231: Chris@126: QHBoxLayout *hbox = new QHBoxLayout; Chris@126: vbox->addLayout(hbox, Qt::AlignRight); Chris@126: Chris@126: QPushButton *ok = new QPushButton(tr("OK"), this); Chris@126: ok->setDefault(true); Chris@126: Chris@126: QPushButton *cancel = new QPushButton(tr("Cancel"), this); Chris@126: Chris@126: QSize bs = ok->sizeHint().expandedTo(cancel->sizeHint()); Chris@126: ok->setFixedSize(bs); Chris@126: cancel->setFixedSize(bs); Chris@126: Chris@126: hbox->addStretch(); Chris@126: hbox->addWidget(ok); Chris@126: hbox->addWidget(cancel); Chris@126: Chris@126: QObject::connect(ok, SIGNAL(clicked()), this, SLOT(accept())); Chris@126: QObject::connect(cancel, SIGNAL(clicked()), 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@126: for (int 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@126: int current, bool *ok, Qt::WFlags f) Chris@126: { Chris@126: ListInputDialog dialog(parent, title, label, list, current, f); 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: