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@229
|
7 This file copyright 2006 Chris Cannam.
|
Chris@126
|
8
|
Chris@126
|
9 This program is free software; you can redistribute it and/or
|
Chris@126
|
10 modify it under the terms of the GNU General Public License as
|
Chris@126
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@126
|
12 License, or (at your option) any later version. See the file
|
Chris@126
|
13 COPYING included with this distribution for more information.
|
Chris@126
|
14 */
|
Chris@126
|
15
|
Chris@126
|
16 #include "ListInputDialog.h"
|
Chris@126
|
17
|
Chris@126
|
18 #include <QVBoxLayout>
|
Chris@126
|
19 #include <QHBoxLayout>
|
Chris@126
|
20 #include <QLabel>
|
Chris@126
|
21 #include <QStringList>
|
Chris@126
|
22 #include <QRadioButton>
|
Chris@126
|
23 #include <QPushButton>
|
Chris@126
|
24
|
Chris@126
|
25 ListInputDialog::ListInputDialog(QWidget *parent, const QString &title,
|
Chris@126
|
26 const QString &labelText, const QStringList &list,
|
Chris@126
|
27 int current, Qt::WFlags f) :
|
Chris@126
|
28 QDialog(parent, f),
|
Chris@126
|
29 m_strings(list)
|
Chris@126
|
30 {
|
Chris@126
|
31 setWindowTitle(title);
|
Chris@126
|
32
|
Chris@126
|
33 QVBoxLayout *vbox = new QVBoxLayout(this);
|
Chris@126
|
34
|
Chris@126
|
35 QLabel *label = new QLabel(labelText, this);
|
Chris@126
|
36 vbox->addWidget(label);
|
Chris@126
|
37 vbox->addStretch(1);
|
Chris@126
|
38
|
Chris@126
|
39 int count = 0;
|
Chris@126
|
40 for (QStringList::const_iterator i = list.begin(); i != list.end(); ++i) {
|
Chris@126
|
41 QRadioButton *radio = new QRadioButton(*i);
|
Chris@126
|
42 if (current == count++) radio->setChecked(true);
|
Chris@126
|
43 m_radioButtons.push_back(radio);
|
Chris@126
|
44 vbox->addWidget(radio);
|
Chris@126
|
45 }
|
Chris@126
|
46
|
Chris@126
|
47 vbox->addStretch(1);
|
Chris@126
|
48
|
Chris@126
|
49 QHBoxLayout *hbox = new QHBoxLayout;
|
Chris@126
|
50 vbox->addLayout(hbox, Qt::AlignRight);
|
Chris@126
|
51
|
Chris@126
|
52 QPushButton *ok = new QPushButton(tr("OK"), this);
|
Chris@126
|
53 ok->setDefault(true);
|
Chris@126
|
54
|
Chris@126
|
55 QPushButton *cancel = new QPushButton(tr("Cancel"), this);
|
Chris@126
|
56
|
Chris@126
|
57 QSize bs = ok->sizeHint().expandedTo(cancel->sizeHint());
|
Chris@126
|
58 ok->setFixedSize(bs);
|
Chris@126
|
59 cancel->setFixedSize(bs);
|
Chris@126
|
60
|
Chris@126
|
61 hbox->addStretch();
|
Chris@126
|
62 hbox->addWidget(ok);
|
Chris@126
|
63 hbox->addWidget(cancel);
|
Chris@126
|
64
|
Chris@126
|
65 QObject::connect(ok, SIGNAL(clicked()), this, SLOT(accept()));
|
Chris@126
|
66 QObject::connect(cancel, SIGNAL(clicked()), this, SLOT(reject()));
|
Chris@126
|
67 }
|
Chris@126
|
68
|
Chris@126
|
69 ListInputDialog::~ListInputDialog()
|
Chris@126
|
70 {
|
Chris@126
|
71 }
|
Chris@126
|
72
|
Chris@126
|
73 QString
|
Chris@126
|
74 ListInputDialog::getCurrentString() const
|
Chris@126
|
75 {
|
Chris@126
|
76 for (int i = 0; i < m_radioButtons.size(); ++i) {
|
Chris@126
|
77 if (m_radioButtons[i]->isChecked()) {
|
Chris@126
|
78 return m_strings[i];
|
Chris@126
|
79 }
|
Chris@126
|
80 }
|
Chris@126
|
81 return "";
|
Chris@126
|
82 }
|
Chris@126
|
83
|
Chris@126
|
84 QString
|
Chris@126
|
85 ListInputDialog::getItem(QWidget *parent, const QString &title,
|
Chris@126
|
86 const QString &label, const QStringList &list,
|
Chris@126
|
87 int current, bool *ok, Qt::WFlags f)
|
Chris@126
|
88 {
|
Chris@126
|
89 ListInputDialog dialog(parent, title, label, list, current, f);
|
Chris@126
|
90
|
Chris@126
|
91 bool accepted = (dialog.exec() == QDialog::Accepted);
|
Chris@126
|
92 if (ok) *ok = accepted;
|
Chris@126
|
93
|
Chris@126
|
94 return dialog.getCurrentString();
|
Chris@126
|
95 }
|
Chris@126
|
96
|