annotate widgets/ListInputDialog.cpp @ 235:efadb9d2b2c6

* Experiment with sizing the property stacks and using a frame on the overview widget with an eye to making the default empty window look a bit nicer
author Chris Cannam
date Mon, 16 Apr 2007 12:20:27 +0000
parents 512ead25e842
children e6d0b097d102
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@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@231 49 m_footnote = new QLabel;
Chris@231 50 vbox->addWidget(m_footnote);
Chris@231 51 m_footnote->hide();
Chris@231 52
Chris@126 53 QHBoxLayout *hbox = new QHBoxLayout;
Chris@126 54 vbox->addLayout(hbox, Qt::AlignRight);
Chris@126 55
Chris@126 56 QPushButton *ok = new QPushButton(tr("OK"), this);
Chris@126 57 ok->setDefault(true);
Chris@126 58
Chris@126 59 QPushButton *cancel = new QPushButton(tr("Cancel"), this);
Chris@126 60
Chris@126 61 QSize bs = ok->sizeHint().expandedTo(cancel->sizeHint());
Chris@126 62 ok->setFixedSize(bs);
Chris@126 63 cancel->setFixedSize(bs);
Chris@126 64
Chris@126 65 hbox->addStretch();
Chris@126 66 hbox->addWidget(ok);
Chris@126 67 hbox->addWidget(cancel);
Chris@126 68
Chris@126 69 QObject::connect(ok, SIGNAL(clicked()), this, SLOT(accept()));
Chris@126 70 QObject::connect(cancel, SIGNAL(clicked()), this, SLOT(reject()));
Chris@126 71 }
Chris@126 72
Chris@126 73 ListInputDialog::~ListInputDialog()
Chris@126 74 {
Chris@126 75 }
Chris@126 76
Chris@126 77 QString
Chris@126 78 ListInputDialog::getCurrentString() const
Chris@126 79 {
Chris@126 80 for (int i = 0; i < m_radioButtons.size(); ++i) {
Chris@126 81 if (m_radioButtons[i]->isChecked()) {
Chris@126 82 return m_strings[i];
Chris@126 83 }
Chris@126 84 }
Chris@126 85 return "";
Chris@126 86 }
Chris@126 87
Chris@231 88 void
Chris@231 89 ListInputDialog::setItemAvailability(int item, bool available)
Chris@231 90 {
Chris@231 91 m_radioButtons[item]->setEnabled(available);
Chris@231 92 }
Chris@231 93
Chris@231 94 void
Chris@231 95 ListInputDialog::setFootnote(QString footnote)
Chris@231 96 {
Chris@231 97 m_footnote->setText(footnote);
Chris@231 98 m_footnote->show();
Chris@231 99 }
Chris@231 100
Chris@126 101 QString
Chris@126 102 ListInputDialog::getItem(QWidget *parent, const QString &title,
Chris@126 103 const QString &label, const QStringList &list,
Chris@126 104 int current, bool *ok, Qt::WFlags f)
Chris@126 105 {
Chris@126 106 ListInputDialog dialog(parent, title, label, list, current, f);
Chris@126 107
Chris@126 108 bool accepted = (dialog.exec() == QDialog::Accepted);
Chris@126 109 if (ok) *ok = accepted;
Chris@126 110
Chris@126 111 return dialog.getCurrentString();
Chris@126 112 }
Chris@126 113