annotate widgets/ColourNameDialog.cpp @ 786:c58569bd952e tonioni

Play pointer: don't seek playback when scrolling, except in ScrollContinuous mode
author Chris Cannam
date Thu, 12 Jun 2014 11:10:21 +0100
parents 9dd432665059
children a34a2a25907c
rev   line source
Chris@285 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@285 2
Chris@285 3 /*
Chris@285 4 Sonic Visualiser
Chris@285 5 An audio file viewer and annotation editor.
Chris@285 6 Centre for Digital Music, Queen Mary, University of London.
Chris@285 7 This file copyright 2007 QMUL.
Chris@285 8
Chris@285 9 This program is free software; you can redistribute it and/or
Chris@285 10 modify it under the terms of the GNU General Public License as
Chris@285 11 published by the Free Software Foundation; either version 2 of the
Chris@285 12 License, or (at your option) any later version. See the file
Chris@285 13 COPYING included with this distribution for more information.
Chris@285 14 */
Chris@285 15
Chris@285 16 #include "ColourNameDialog.h"
Chris@285 17
Chris@285 18 #include <QGridLayout>
Chris@285 19 #include <QLabel>
Chris@285 20 #include <QDialogButtonBox>
Chris@285 21 #include <QLineEdit>
Chris@285 22 #include <QIcon>
Chris@285 23 #include <QCheckBox>
Chris@285 24 #include <QPainter>
Chris@285 25 #include <QPushButton>
Chris@285 26
Chris@285 27 ColourNameDialog::ColourNameDialog(QString title, QString message,
Chris@285 28 QColor colour, QString defaultName,
Chris@285 29 QWidget *parent) :
Chris@285 30 QDialog(parent),
Chris@285 31 m_colour(colour)
Chris@285 32 {
Chris@285 33 setWindowTitle(title);
Chris@285 34
Chris@285 35 QGridLayout *layout = new QGridLayout(this);
Chris@285 36
Chris@285 37 QLabel *label = new QLabel(message, this);
Chris@285 38 layout->addWidget(label, 0, 0, 1, 2);
Chris@285 39
Chris@285 40 m_colourLabel = new QLabel(this);
Chris@285 41 layout->addWidget(m_colourLabel, 1, 1);
Chris@285 42
Chris@285 43 m_textField = new QLineEdit(defaultName, this);
Chris@285 44 layout->addWidget(m_textField, 1, 0);
Chris@285 45
Chris@285 46 connect(m_textField, SIGNAL(textChanged(const QString &)),
Chris@285 47 this, SLOT(textChanged(const QString &)));
Chris@285 48
Chris@285 49 m_darkBackground = new QCheckBox(this);
Chris@285 50 layout->addWidget(m_darkBackground, 2, 0);
Chris@285 51 m_darkBackground->setChecked
Chris@285 52 (colour.red() + colour.green() + colour.blue() > 384);
Chris@285 53 fillColourLabel();
Chris@285 54
Chris@285 55 connect(m_darkBackground, SIGNAL(stateChanged(int)),
Chris@285 56 this, SLOT(darkBackgroundChanged(int)));
Chris@285 57
Chris@285 58 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok |
Chris@285 59 QDialogButtonBox::Cancel);
Chris@285 60 layout->addWidget(bb, 3, 0, 1, 2);
Chris@285 61 connect(bb, SIGNAL(accepted()), this, SLOT(accept()));
Chris@285 62 connect(bb, SIGNAL(rejected()), this, SLOT(reject()));
Chris@285 63 m_okButton = bb->button(QDialogButtonBox::Ok);
Chris@285 64 m_okButton->setEnabled(defaultName != "");
Chris@285 65 }
Chris@285 66
Chris@285 67 void
Chris@285 68 ColourNameDialog::showDarkBackgroundCheckbox(QString text)
Chris@285 69 {
Chris@285 70 m_darkBackground->setText(text);
Chris@285 71 m_darkBackground->show();
Chris@285 72 }
Chris@285 73
Chris@285 74 bool
Chris@285 75 ColourNameDialog::isDarkBackgroundChecked() const
Chris@285 76 {
Chris@285 77 return m_darkBackground->isChecked();
Chris@285 78 }
Chris@285 79
Chris@285 80 void
Chris@285 81 ColourNameDialog::darkBackgroundChanged(int)
Chris@285 82 {
Chris@285 83 fillColourLabel();
Chris@285 84 }
Chris@285 85
Chris@285 86 void
Chris@285 87 ColourNameDialog::textChanged(const QString &text)
Chris@285 88 {
Chris@285 89 m_okButton->setEnabled(text != "");
Chris@285 90 }
Chris@285 91
Chris@285 92 void
Chris@285 93 ColourNameDialog::fillColourLabel()
Chris@285 94 {
Chris@285 95 QPixmap pmap(20, 20);
Chris@285 96 pmap.fill(m_darkBackground->isChecked() ? Qt::black : Qt::white);
Chris@285 97 QPainter paint(&pmap);
Chris@285 98 paint.setPen(m_colour);
Chris@285 99 paint.setBrush(m_colour);
Chris@285 100 paint.drawRect(2, 2, 15, 15);
Chris@285 101 m_colourLabel->setPixmap(pmap);
Chris@285 102 }
Chris@285 103
Chris@285 104 QString
Chris@285 105 ColourNameDialog::getColourName() const
Chris@285 106 {
Chris@285 107 return m_textField->text();
Chris@285 108 }