comparison widgets/ListInputDialog.cpp @ 0:fc9323a41f5a

start base : Sonic Visualiser sv1-1.0rc1
author lbajardsilogic
date Fri, 11 May 2007 09:08:14 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:fc9323a41f5a
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Sonic Visualiser
5 An audio file viewer and annotation editor.
6 Centre for Digital Music, Queen Mary, University of London.
7 This file copyright 2006 Chris Cannam.
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information.
14 */
15
16 #include "ListInputDialog.h"
17
18 #include <QVBoxLayout>
19 #include <QHBoxLayout>
20 #include <QLabel>
21 #include <QStringList>
22 #include <QRadioButton>
23 #include <QPushButton>
24
25 ListInputDialog::ListInputDialog(QWidget *parent, const QString &title,
26 const QString &labelText, const QStringList &list,
27 int current, Qt::WFlags f) :
28 QDialog(parent, f),
29 m_strings(list)
30 {
31 setWindowTitle(title);
32
33 QVBoxLayout *vbox = new QVBoxLayout(this);
34
35 QLabel *label = new QLabel(labelText, this);
36 vbox->addWidget(label);
37 vbox->addStretch(1);
38
39 int count = 0;
40 for (QStringList::const_iterator i = list.begin(); i != list.end(); ++i) {
41 QRadioButton *radio = new QRadioButton(*i);
42 if (current == count++) radio->setChecked(true);
43 m_radioButtons.push_back(radio);
44 vbox->addWidget(radio);
45 }
46
47 vbox->addStretch(1);
48
49 m_footnote = new QLabel;
50 vbox->addWidget(m_footnote);
51 m_footnote->hide();
52
53 QHBoxLayout *hbox = new QHBoxLayout;
54 vbox->addLayout(hbox, Qt::AlignRight);
55
56 QPushButton *ok = new QPushButton(tr("OK"), this);
57 ok->setDefault(true);
58
59 QPushButton *cancel = new QPushButton(tr("Cancel"), this);
60
61 QSize bs = ok->sizeHint().expandedTo(cancel->sizeHint());
62 ok->setFixedSize(bs);
63 cancel->setFixedSize(bs);
64
65 hbox->addStretch();
66 hbox->addWidget(ok);
67 hbox->addWidget(cancel);
68
69 QObject::connect(ok, SIGNAL(clicked()), this, SLOT(accept()));
70 QObject::connect(cancel, SIGNAL(clicked()), this, SLOT(reject()));
71 }
72
73 ListInputDialog::~ListInputDialog()
74 {
75 }
76
77 QString
78 ListInputDialog::getCurrentString() const
79 {
80 for (size_t i = 0; i < m_radioButtons.size(); ++i) {
81 if (m_radioButtons[i]->isChecked()) {
82 return m_strings[i];
83 }
84 }
85 return "";
86 }
87
88 void
89 ListInputDialog::setItemAvailability(int item, bool available)
90 {
91 m_radioButtons[item]->setEnabled(available);
92 }
93
94 void
95 ListInputDialog::setFootnote(QString footnote)
96 {
97 m_footnote->setText(footnote);
98 m_footnote->show();
99 }
100
101 QString
102 ListInputDialog::getItem(QWidget *parent, const QString &title,
103 const QString &label, const QStringList &list,
104 int current, bool *ok, Qt::WFlags f)
105 {
106 ListInputDialog dialog(parent, title, label, list, current, f);
107
108 bool accepted = (dialog.exec() == QDialog::Accepted);
109 if (ok) *ok = accepted;
110
111 return dialog.getCurrentString();
112 }
113