Chris@285: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@285: Chris@285: /* Chris@285: Sonic Visualiser Chris@285: An audio file viewer and annotation editor. Chris@285: Centre for Digital Music, Queen Mary, University of London. Chris@285: This file copyright 2007 QMUL. Chris@285: Chris@285: This program is free software; you can redistribute it and/or Chris@285: modify it under the terms of the GNU General Public License as Chris@285: published by the Free Software Foundation; either version 2 of the Chris@285: License, or (at your option) any later version. See the file Chris@285: COPYING included with this distribution for more information. Chris@285: */ Chris@285: Chris@285: #include "ColourNameDialog.h" Chris@285: Chris@285: #include Chris@285: #include Chris@285: #include Chris@285: #include Chris@285: #include Chris@285: #include Chris@285: #include Chris@285: #include Chris@285: Chris@285: ColourNameDialog::ColourNameDialog(QString title, QString message, Chris@1266: QColor colour, QString defaultName, Chris@1266: QWidget *parent) : Chris@285: QDialog(parent), Chris@285: m_colour(colour) Chris@285: { Chris@285: setWindowTitle(title); Chris@285: Chris@285: QGridLayout *layout = new QGridLayout(this); Chris@285: Chris@285: QLabel *label = new QLabel(message, this); Chris@285: layout->addWidget(label, 0, 0, 1, 2); Chris@285: Chris@285: m_colourLabel = new QLabel(this); Chris@285: layout->addWidget(m_colourLabel, 1, 1); Chris@285: Chris@285: m_textField = new QLineEdit(defaultName, this); Chris@285: layout->addWidget(m_textField, 1, 0); Chris@285: Chris@285: connect(m_textField, SIGNAL(textChanged(const QString &)), Chris@285: this, SLOT(textChanged(const QString &))); Chris@285: Chris@285: m_darkBackground = new QCheckBox(this); Chris@285: layout->addWidget(m_darkBackground, 2, 0); Chris@285: m_darkBackground->setChecked Chris@285: (colour.red() + colour.green() + colour.blue() > 384); Chris@285: fillColourLabel(); Chris@285: Chris@285: connect(m_darkBackground, SIGNAL(stateChanged(int)), Chris@285: this, SLOT(darkBackgroundChanged(int))); Chris@285: Chris@285: QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok | Chris@285: QDialogButtonBox::Cancel); Chris@285: layout->addWidget(bb, 3, 0, 1, 2); Chris@285: connect(bb, SIGNAL(accepted()), this, SLOT(accept())); Chris@285: connect(bb, SIGNAL(rejected()), this, SLOT(reject())); Chris@285: m_okButton = bb->button(QDialogButtonBox::Ok); Chris@285: m_okButton->setEnabled(defaultName != ""); Chris@285: } Chris@285: Chris@285: void Chris@285: ColourNameDialog::showDarkBackgroundCheckbox(QString text) Chris@285: { Chris@285: m_darkBackground->setText(text); Chris@285: m_darkBackground->show(); Chris@285: } Chris@285: Chris@285: bool Chris@285: ColourNameDialog::isDarkBackgroundChecked() const Chris@285: { Chris@285: return m_darkBackground->isChecked(); Chris@285: } Chris@285: Chris@285: void Chris@285: ColourNameDialog::darkBackgroundChanged(int) Chris@285: { Chris@285: fillColourLabel(); Chris@285: } Chris@285: Chris@285: void Chris@285: ColourNameDialog::textChanged(const QString &text) Chris@285: { Chris@285: m_okButton->setEnabled(text != ""); Chris@285: } Chris@285: Chris@285: void Chris@285: ColourNameDialog::fillColourLabel() Chris@285: { Chris@285: QPixmap pmap(20, 20); Chris@285: pmap.fill(m_darkBackground->isChecked() ? Qt::black : Qt::white); Chris@285: QPainter paint(&pmap); Chris@285: paint.setPen(m_colour); Chris@285: paint.setBrush(m_colour); Chris@285: paint.drawRect(2, 2, 15, 15); Chris@285: m_colourLabel->setPixmap(pmap); Chris@285: } Chris@285: Chris@285: QString Chris@285: ColourNameDialog::getColourName() const Chris@285: { Chris@285: return m_textField->text(); Chris@285: }