comparison confirmcommentdialog.cpp @ 105:1928f9b408e6

* Better-behaved comment dialog; avoid empty comments. Also ignore signals from closing ptys
author Chris Cannam
date Thu, 25 Nov 2010 17:21:32 +0000
parents af314dd436d5
children 1721c580c10e
comparison
equal deleted inserted replaced
104:af314dd436d5 105:1928f9b408e6
21 #include <QInputDialog> 21 #include <QInputDialog>
22 #include <QGridLayout> 22 #include <QGridLayout>
23 #include <QLabel> 23 #include <QLabel>
24 #include <QTextEdit> 24 #include <QTextEdit>
25 #include <QDialogButtonBox> 25 #include <QDialogButtonBox>
26
27 ConfirmCommentDialog::ConfirmCommentDialog(QWidget *parent,
28 QString title,
29 QString introText,
30 QString initialComment) :
31 QDialog(parent)
32 {
33 setWindowTitle(title);
34
35 QGridLayout *layout = new QGridLayout;
36 setLayout(layout);
37 QLabel *label = new QLabel(introText);
38 layout->addWidget(label, 0, 0);
39
40 m_textEdit = new QTextEdit;
41 m_textEdit->setAcceptRichText(false);
42 m_textEdit->document()->setPlainText(initialComment);
43 m_textEdit->setMinimumWidth(360);
44 connect(m_textEdit, SIGNAL(textChanged()), this, SLOT(commentChanged()));
45 layout->addWidget(m_textEdit, 1, 0);
46
47 QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok |
48 QDialogButtonBox::Cancel);
49 layout->addWidget(bbox, 2, 0);
50 m_ok = bbox->button(QDialogButtonBox::Ok);
51 m_ok->setEnabled(initialComment != "");
52
53 connect(bbox, SIGNAL(accepted()), this, SLOT(accept()));
54 connect(bbox, SIGNAL(rejected()), this, SLOT(reject()));
55 }
56
57 void ConfirmCommentDialog::commentChanged()
58 {
59 m_ok->setEnabled(getComment() != "");
60 }
61
62 QString ConfirmCommentDialog::getComment() const
63 {
64 return m_textEdit->document()->toPlainText();
65 }
26 66
27 bool ConfirmCommentDialog::confirmFilesAction(QWidget *parent, 67 bool ConfirmCommentDialog::confirmFilesAction(QWidget *parent,
28 QString title, 68 QString title,
29 QString introText, 69 QString introText,
30 QString introTextWithCount, 70 QString introTextWithCount,
80 bool ok = false; 120 bool ok = false;
81 if (!longComment) { 121 if (!longComment) {
82 comment = QInputDialog::getText(parent, title, introText, 122 comment = QInputDialog::getText(parent, title, introText,
83 QLineEdit::Normal, comment, &ok); 123 QLineEdit::Normal, comment, &ok);
84 } else { 124 } else {
85 QDialog *d = new QDialog(parent); 125 ConfirmCommentDialog *d = new ConfirmCommentDialog(parent,
86 d->setWindowTitle(title); 126 title,
87 QGridLayout *layout = new QGridLayout; 127 introText,
88 d->setLayout(layout); 128 comment);
89 QLabel *label = new QLabel(introText);
90 layout->addWidget(label, 0, 0);
91 QTextEdit *textEdit = new QTextEdit;
92 textEdit->setAcceptRichText(false);
93 layout->addWidget(textEdit, 1, 0);
94 QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok |
95 QDialogButtonBox::Cancel);
96 layout->addWidget(bbox, 2, 0);
97 QObject::connect(bbox, SIGNAL(accepted()), d, SLOT(accept()));
98 QObject::connect(bbox, SIGNAL(rejected()), d, SLOT(reject()));
99 if (d->exec() == QDialog::Accepted) { 129 if (d->exec() == QDialog::Accepted) {
100 comment = textEdit->document()->toPlainText(); 130 comment = d->getComment();
101 ok = true; 131 ok = true;
102 } 132 }
103 } 133 }
104 return ok; 134 return ok;
105 } 135 }