ColourNameDialog.cpp
Go to the documentation of this file.
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 2007 QMUL.
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 "ColourNameDialog.h"
17 
18 #include <QGridLayout>
19 #include <QLabel>
20 #include <QDialogButtonBox>
21 #include <QLineEdit>
22 #include <QIcon>
23 #include <QCheckBox>
24 #include <QPainter>
25 #include <QPushButton>
26 
27 ColourNameDialog::ColourNameDialog(QString title, QString message,
28  QColor colour, QString defaultName,
29  QWidget *parent) :
30  QDialog(parent),
31  m_colour(colour)
32 {
33  setWindowTitle(title);
34 
35  QGridLayout *layout = new QGridLayout(this);
36 
37  QLabel *label = new QLabel(message, this);
38  layout->addWidget(label, 0, 0, 1, 2);
39 
40  m_colourLabel = new QLabel(this);
41  layout->addWidget(m_colourLabel, 1, 1);
42 
43  m_textField = new QLineEdit(defaultName, this);
44  layout->addWidget(m_textField, 1, 0);
45 
46  connect(m_textField, SIGNAL(textChanged(const QString &)),
47  this, SLOT(textChanged(const QString &)));
48 
49  m_darkBackground = new QCheckBox(this);
50  layout->addWidget(m_darkBackground, 2, 0);
51  m_darkBackground->setChecked
52  (colour.red() + colour.green() + colour.blue() > 384);
54 
55  connect(m_darkBackground, SIGNAL(stateChanged(int)),
56  this, SLOT(darkBackgroundChanged(int)));
57 
58  QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok |
59  QDialogButtonBox::Cancel);
60  layout->addWidget(bb, 3, 0, 1, 2);
61  connect(bb, SIGNAL(accepted()), this, SLOT(accept()));
62  connect(bb, SIGNAL(rejected()), this, SLOT(reject()));
63  m_okButton = bb->button(QDialogButtonBox::Ok);
64  m_okButton->setEnabled(defaultName != "");
65 }
66 
67 void
69 {
70  m_darkBackground->setText(text);
71  m_darkBackground->show();
72 }
73 
74 bool
76 {
77  return m_darkBackground->isChecked();
78 }
79 
80 void
82 {
84 }
85 
86 void
87 ColourNameDialog::textChanged(const QString &text)
88 {
89  m_okButton->setEnabled(text != "");
90 }
91 
92 void
94 {
95  QPixmap pmap(20, 20);
96  pmap.fill(m_darkBackground->isChecked() ? Qt::black : Qt::white);
97  QPainter paint(&pmap);
98  paint.setPen(m_colour);
99  paint.setBrush(m_colour);
100  paint.drawRect(2, 2, 15, 15);
101  m_colourLabel->setPixmap(pmap);
102 }
103 
104 QString
106 {
107  return m_textField->text();
108 }
QLineEdit * m_textField
bool isDarkBackgroundChecked() const
ColourNameDialog(QString title, QString message, QColor colour, QString defaultName, QWidget *parent=0)
QPushButton * m_okButton
QCheckBox * m_darkBackground
void showDarkBackgroundCheckbox(QString text)
void darkBackgroundChanged(int)
QString getColourName() const
void textChanged(const QString &)