comparison confirmcommentdialog.cpp @ 193:ef5feb0d648f

* Give all of the substantial confirmation dialogs meaningful labels for their OK buttons
author Chris Cannam
date Mon, 20 Dec 2010 22:37:42 +0000
parents edab92f3ea0b
children 5ca49523892f
comparison
equal deleted inserted replaced
192:702ca6dafcbe 193:ef5feb0d648f
26 #include <QDialogButtonBox> 26 #include <QDialogButtonBox>
27 27
28 ConfirmCommentDialog::ConfirmCommentDialog(QWidget *parent, 28 ConfirmCommentDialog::ConfirmCommentDialog(QWidget *parent,
29 QString title, 29 QString title,
30 QString introText, 30 QString introText,
31 QString initialComment) : 31 QString initialComment,
32 QString okButtonText) :
32 QDialog(parent) 33 QDialog(parent)
33 { 34 {
34 setWindowTitle(title); 35 setWindowTitle(title);
35 36
36 QGridLayout *layout = new QGridLayout; 37 QGridLayout *layout = new QGridLayout;
48 QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok | 49 QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok |
49 QDialogButtonBox::Cancel); 50 QDialogButtonBox::Cancel);
50 layout->addWidget(bbox, 2, 0); 51 layout->addWidget(bbox, 2, 0);
51 m_ok = bbox->button(QDialogButtonBox::Ok); 52 m_ok = bbox->button(QDialogButtonBox::Ok);
52 m_ok->setEnabled(initialComment != ""); 53 m_ok->setEnabled(initialComment != "");
54 m_ok->setText(okButtonText);
53 55
54 connect(bbox, SIGNAL(accepted()), this, SLOT(accept())); 56 connect(bbox, SIGNAL(accepted()), this, SLOT(accept()));
55 connect(bbox, SIGNAL(rejected()), this, SLOT(reject())); 57 connect(bbox, SIGNAL(rejected()), this, SLOT(reject()));
56 } 58 }
57 59
75 } 77 }
76 text += "</code></qt>"; 78 text += "</code></qt>";
77 return text; 79 return text;
78 } 80 }
79 81
82 bool ConfirmCommentDialog::confirm(QWidget *parent,
83 QString title,
84 QString text,
85 QString okButtonText)
86 {
87 QMessageBox box(QMessageBox::Question,
88 title,
89 text,
90 QMessageBox::Cancel,
91 parent);
92
93 QPushButton *ok = box.addButton(QMessageBox::Ok);
94 ok->setText(okButtonText);
95 if (box.exec() == -1) return QMessageBox::Cancel;
96 return box.standardButton(box.clickedButton());
97 }
98
99 bool ConfirmCommentDialog::confirmDangerous(QWidget *parent,
100 QString title,
101 QString text,
102 QString okButtonText)
103 {
104 QMessageBox box(QMessageBox::Warning,
105 title,
106 text,
107 QMessageBox::Cancel,
108 parent);
109
110 QPushButton *ok = box.addButton(QMessageBox::Ok);
111 ok->setText(okButtonText);
112 if (box.exec() == -1) return QMessageBox::Cancel;
113 return box.standardButton(box.clickedButton());
114 }
115
80 bool ConfirmCommentDialog::confirmFilesAction(QWidget *parent, 116 bool ConfirmCommentDialog::confirmFilesAction(QWidget *parent,
81 QString title, 117 QString title,
82 QString introText, 118 QString introText,
83 QString introTextWithCount, 119 QString introTextWithCount,
84 QStringList files) 120 QStringList files,
121 QString okButtonText)
85 { 122 {
86 QString text; 123 QString text;
87 if (files.size() <= 10) { 124 if (files.size() <= 10) {
88 text = buildFilesText(introText, files); 125 text = buildFilesText(introText, files);
89 } else { 126 } else {
90 text = "<qt>" + introTextWithCount + "</qt>"; 127 text = "<qt>" + introTextWithCount + "</qt>";
91 } 128 }
92 return (QMessageBox::information(parent, 129 return confirm(parent, title, text, okButtonText);
93 title,
94 text,
95 QMessageBox::Ok | QMessageBox::Cancel,
96 QMessageBox::Ok)
97 == QMessageBox::Ok);
98 } 130 }
99 131
100 bool ConfirmCommentDialog::confirmDangerousFilesAction(QWidget *parent, 132 bool ConfirmCommentDialog::confirmDangerousFilesAction(QWidget *parent,
101 QString title, 133 QString title,
102 QString introText, 134 QString introText,
103 QString introTextWithCount, 135 QString introTextWithCount,
104 QStringList files) 136 QStringList files,
137 QString okButtonText)
105 { 138 {
106 QString text; 139 QString text;
107 if (files.size() <= 10) { 140 if (files.size() <= 10) {
108 text = buildFilesText(introText, files); 141 text = buildFilesText(introText, files);
109 } else { 142 } else {
110 text = "<qt>" + introTextWithCount + "</qt>"; 143 text = "<qt>" + introTextWithCount + "</qt>";
111 } 144 }
112 return (QMessageBox::warning(parent, 145 return confirmDangerous(parent, title, text, okButtonText);
113 title,
114 text,
115 QMessageBox::Ok | QMessageBox::Cancel,
116 QMessageBox::Cancel)
117 == QMessageBox::Ok);
118 } 146 }
119 147
120 bool ConfirmCommentDialog::confirmAndGetShortComment(QWidget *parent, 148 bool ConfirmCommentDialog::confirmAndGetShortComment(QWidget *parent,
121 QString title, 149 QString title,
122 QString introText, 150 QString introText,
123 QString introTextWithCount, 151 QString introTextWithCount,
124 QStringList files, 152 QStringList files,
125 QString &comment) 153 QString &comment,
154 QString okButtonText)
126 { 155 {
127 return confirmAndComment(parent, title, introText, 156 return confirmAndComment(parent, title, introText,
128 introTextWithCount, files, comment, false); 157 introTextWithCount, files, comment, false,
158 okButtonText);
129 } 159 }
130 160
131 bool ConfirmCommentDialog::confirmAndGetLongComment(QWidget *parent, 161 bool ConfirmCommentDialog::confirmAndGetLongComment(QWidget *parent,
132 QString title, 162 QString title,
133 QString introText, 163 QString introText,
134 QString introTextWithCount, 164 QString introTextWithCount,
135 QStringList files, 165 QStringList files,
136 QString &comment) 166 QString &comment,
167 QString okButtonText)
137 { 168 {
138 return confirmAndComment(parent, title, introText, 169 return confirmAndComment(parent, title, introText,
139 introTextWithCount, files, comment, true); 170 introTextWithCount, files, comment, true,
171 okButtonText);
140 } 172 }
141 173
142 bool ConfirmCommentDialog::confirmAndComment(QWidget *parent, 174 bool ConfirmCommentDialog::confirmAndComment(QWidget *parent,
143 QString title, 175 QString title,
144 QString introText, 176 QString introText,
145 QString introTextWithCount, 177 QString introTextWithCount,
146 QStringList files, 178 QStringList files,
147 QString &comment, 179 QString &comment,
148 bool longComment) 180 bool longComment,
181 QString okButtonText)
149 { 182 {
150 QString text; 183 QString text;
151 if (files.size() <= 10) { 184 if (files.size() <= 10) {
152 text = buildFilesText(introText, files); 185 text = buildFilesText(introText, files);
153 } else { 186 } else {
154 text = "<qt>" + introTextWithCount; 187 text = "<qt>" + introTextWithCount;
155 } 188 }
156 text += tr("<p>Please enter your comment:</qt>"); 189 text += tr("<p>Please enter your comment:</qt>");
157 return confirmAndComment(parent, title, text, comment, longComment); 190 return confirmAndComment(parent, title, text, comment, longComment,
191 okButtonText);
158 } 192 }
159 193
160 bool ConfirmCommentDialog::confirmAndGetShortComment(QWidget *parent, 194 bool ConfirmCommentDialog::confirmAndGetShortComment(QWidget *parent,
161 QString title, 195 QString title,
162 QString introText, 196 QString introText,
163 QString &comment) 197 QString &comment,
164 { 198 QString okButtonText)
165 return confirmAndComment(parent, title, introText, comment, false); 199 {
200 return confirmAndComment(parent, title, introText, comment, false,
201 okButtonText);
166 } 202 }
167 203
168 bool ConfirmCommentDialog::confirmAndGetLongComment(QWidget *parent, 204 bool ConfirmCommentDialog::confirmAndGetLongComment(QWidget *parent,
169 QString title, 205 QString title,
170 QString introText, 206 QString introText,
171 QString &comment) 207 QString &comment,
172 { 208 QString okButtonText)
173 return confirmAndComment(parent, title, introText, comment, true); 209 {
210 return confirmAndComment(parent, title, introText, comment, true,
211 okButtonText);
174 } 212 }
175 213
176 bool ConfirmCommentDialog::confirmAndComment(QWidget *parent, 214 bool ConfirmCommentDialog::confirmAndComment(QWidget *parent,
177 QString title, 215 QString title,
178 QString introText, 216 QString introText,
179 QString &comment, 217 QString &comment,
180 bool longComment) 218 bool longComment,
219 QString okButtonText)
181 { 220 {
182 bool ok = false; 221 bool ok = false;
183 if (!longComment) { 222 if (!longComment) {
184 comment = QInputDialog::getText(parent, title, introText, 223 QInputDialog d(parent);
185 QLineEdit::Normal, comment, &ok); 224 d.setWindowTitle(title);
186 } else { 225 d.setLabelText(introText);
187 ConfirmCommentDialog *d = new ConfirmCommentDialog(parent, 226 d.setTextValue(comment);
188 title, 227 d.setOkButtonText(okButtonText);
189 introText, 228 d.setTextEchoMode(QLineEdit::Normal);
190 comment); 229 if (d.exec() == QDialog::Accepted) {
191 if (d->exec() == QDialog::Accepted) { 230 comment = d.textValue();
192 comment = d->getComment();
193 ok = true; 231 ok = true;
194 } 232 }
195 } 233 } else {
234 ConfirmCommentDialog d(parent, title, introText, comment, okButtonText);
235 if (d.exec() == QDialog::Accepted) {
236 comment = d.getComment();
237 ok = true;
238 }
239 }
240
196 return ok; 241 return ok;
197 } 242 }