annotate widgets/ListInputDialog.cpp @ 183:5f86ae638b04

* Omit translucent blue fill for selection rectangles that are superimposed over layers that use colours for meaningful purposes such as the spectrogram (CHARM change request)
author Chris Cannam
date Fri, 24 Nov 2006 16:56:15 +0000
parents 0e95c127bb53
children 387f2f6fc333
rev   line source
Chris@126 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@126 2
Chris@126 3 /*
Chris@126 4 Sonic Visualiser
Chris@126 5 An audio file viewer and annotation editor.
Chris@126 6 Centre for Digital Music, Queen Mary, University of London.
Chris@126 7
Chris@126 8 This program is free software; you can redistribute it and/or
Chris@126 9 modify it under the terms of the GNU General Public License as
Chris@126 10 published by the Free Software Foundation; either version 2 of the
Chris@126 11 License, or (at your option) any later version. See the file
Chris@126 12 COPYING included with this distribution for more information.
Chris@126 13 */
Chris@126 14
Chris@126 15 #include "ListInputDialog.h"
Chris@126 16
Chris@126 17 #include <QVBoxLayout>
Chris@126 18 #include <QHBoxLayout>
Chris@126 19 #include <QLabel>
Chris@126 20 #include <QStringList>
Chris@126 21 #include <QRadioButton>
Chris@126 22 #include <QPushButton>
Chris@126 23
Chris@126 24 ListInputDialog::ListInputDialog(QWidget *parent, const QString &title,
Chris@126 25 const QString &labelText, const QStringList &list,
Chris@126 26 int current, Qt::WFlags f) :
Chris@126 27 QDialog(parent, f),
Chris@126 28 m_strings(list)
Chris@126 29 {
Chris@126 30 setWindowTitle(title);
Chris@126 31
Chris@126 32 QVBoxLayout *vbox = new QVBoxLayout(this);
Chris@126 33
Chris@126 34 QLabel *label = new QLabel(labelText, this);
Chris@126 35 vbox->addWidget(label);
Chris@126 36 vbox->addStretch(1);
Chris@126 37
Chris@126 38 int count = 0;
Chris@126 39 for (QStringList::const_iterator i = list.begin(); i != list.end(); ++i) {
Chris@126 40 QRadioButton *radio = new QRadioButton(*i);
Chris@126 41 if (current == count++) radio->setChecked(true);
Chris@126 42 m_radioButtons.push_back(radio);
Chris@126 43 vbox->addWidget(radio);
Chris@126 44 }
Chris@126 45
Chris@126 46 vbox->addStretch(1);
Chris@126 47
Chris@126 48 QHBoxLayout *hbox = new QHBoxLayout;
Chris@126 49 vbox->addLayout(hbox, Qt::AlignRight);
Chris@126 50
Chris@126 51 QPushButton *ok = new QPushButton(tr("OK"), this);
Chris@126 52 ok->setDefault(true);
Chris@126 53
Chris@126 54 QPushButton *cancel = new QPushButton(tr("Cancel"), this);
Chris@126 55
Chris@126 56 QSize bs = ok->sizeHint().expandedTo(cancel->sizeHint());
Chris@126 57 ok->setFixedSize(bs);
Chris@126 58 cancel->setFixedSize(bs);
Chris@126 59
Chris@126 60 hbox->addStretch();
Chris@126 61 hbox->addWidget(ok);
Chris@126 62 hbox->addWidget(cancel);
Chris@126 63
Chris@126 64 QObject::connect(ok, SIGNAL(clicked()), this, SLOT(accept()));
Chris@126 65 QObject::connect(cancel, SIGNAL(clicked()), this, SLOT(reject()));
Chris@126 66 }
Chris@126 67
Chris@126 68 ListInputDialog::~ListInputDialog()
Chris@126 69 {
Chris@126 70 }
Chris@126 71
Chris@126 72 QString
Chris@126 73 ListInputDialog::getCurrentString() const
Chris@126 74 {
Chris@126 75 for (int i = 0; i < m_radioButtons.size(); ++i) {
Chris@126 76 if (m_radioButtons[i]->isChecked()) {
Chris@126 77 return m_strings[i];
Chris@126 78 }
Chris@126 79 }
Chris@126 80 return "";
Chris@126 81 }
Chris@126 82
Chris@126 83 QString
Chris@126 84 ListInputDialog::getItem(QWidget *parent, const QString &title,
Chris@126 85 const QString &label, const QStringList &list,
Chris@126 86 int current, bool *ok, Qt::WFlags f)
Chris@126 87 {
Chris@126 88 ListInputDialog dialog(parent, title, label, list, current, f);
Chris@126 89
Chris@126 90 bool accepted = (dialog.exec() == QDialog::Accepted);
Chris@126 91 if (ok) *ok = accepted;
Chris@126 92
Chris@126 93 return dialog.getCurrentString();
Chris@126 94 }
Chris@126 95