Mercurial > hg > easyhg
comparison src/confirmcommentdialog.cpp @ 370:b9c153e00e84
Move source files to src/
author | Chris Cannam |
---|---|
date | Thu, 24 Mar 2011 10:27:51 +0000 |
parents | confirmcommentdialog.cpp@fd9dc5a457d8 |
children | 69b2338c06e1 |
comparison
equal
deleted
inserted
replaced
369:19cce6d2c470 | 370:b9c153e00e84 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 EasyMercurial | |
5 | |
6 Based on hgExplorer by Jari Korhonen | |
7 Copyright (c) 2010 Jari Korhonen | |
8 Copyright (c) 2011 Chris Cannam | |
9 Copyright (c) 2011 Queen Mary, University of London | |
10 | |
11 This program is free software; you can redistribute it and/or | |
12 modify it under the terms of the GNU General Public License as | |
13 published by the Free Software Foundation; either version 2 of the | |
14 License, or (at your option) any later version. See the file | |
15 COPYING included with this distribution for more information. | |
16 */ | |
17 | |
18 #include "confirmcommentdialog.h" | |
19 #include "common.h" | |
20 | |
21 #include <QMessageBox> | |
22 #include <QInputDialog> | |
23 #include <QGridLayout> | |
24 #include <QLabel> | |
25 #include <QTextEdit> | |
26 #include <QDialogButtonBox> | |
27 | |
28 ConfirmCommentDialog::ConfirmCommentDialog(QWidget *parent, | |
29 QString title, | |
30 QString introText, | |
31 QString initialComment, | |
32 QString okButtonText) : | |
33 QDialog(parent) | |
34 { | |
35 setWindowTitle(title); | |
36 | |
37 QGridLayout *layout = new QGridLayout; | |
38 setLayout(layout); | |
39 QLabel *label = new QLabel(introText); | |
40 label->setWordWrap(true); | |
41 layout->addWidget(label, 0, 0); | |
42 | |
43 m_textEdit = new QTextEdit; | |
44 m_textEdit->setAcceptRichText(false); | |
45 m_textEdit->document()->setPlainText(initialComment); | |
46 m_textEdit->setMinimumWidth(360); | |
47 connect(m_textEdit, SIGNAL(textChanged()), this, SLOT(commentChanged())); | |
48 layout->addWidget(m_textEdit, 1, 0); | |
49 | |
50 QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok | | |
51 QDialogButtonBox::Cancel); | |
52 layout->addWidget(bbox, 2, 0); | |
53 m_ok = bbox->button(QDialogButtonBox::Ok); | |
54 m_ok->setDefault(true); | |
55 m_ok->setEnabled(initialComment != ""); | |
56 m_ok->setText(okButtonText); | |
57 bbox->button(QDialogButtonBox::Cancel)->setAutoDefault(false); | |
58 | |
59 connect(bbox, SIGNAL(accepted()), this, SLOT(accept())); | |
60 connect(bbox, SIGNAL(rejected()), this, SLOT(reject())); | |
61 } | |
62 | |
63 void ConfirmCommentDialog::commentChanged() | |
64 { | |
65 m_ok->setEnabled(getComment() != ""); | |
66 } | |
67 | |
68 QString ConfirmCommentDialog::getComment() const | |
69 { | |
70 return m_textEdit->document()->toPlainText(); | |
71 } | |
72 | |
73 QString ConfirmCommentDialog::buildFilesText(QString intro, QStringList files) | |
74 { | |
75 QString text; | |
76 | |
77 if (intro == "") text = "<qt>"; | |
78 else text = "<qt>" + intro + "<p>"; | |
79 | |
80 text += "<code>"; | |
81 foreach (QString file, files) { | |
82 text += " " + xmlEncode(file) + "<br>"; | |
83 } | |
84 text += "</code></qt>"; | |
85 | |
86 return text; | |
87 } | |
88 | |
89 bool ConfirmCommentDialog::confirm(QWidget *parent, | |
90 QString title, | |
91 QString head, | |
92 QString text, | |
93 QString okButtonText) | |
94 { | |
95 QMessageBox box(QMessageBox::Question, | |
96 title, | |
97 head, | |
98 QMessageBox::Cancel, | |
99 parent); | |
100 | |
101 box.setInformativeText(text); | |
102 | |
103 QPushButton *ok = box.addButton(QMessageBox::Ok); | |
104 ok->setText(okButtonText); | |
105 box.setDefaultButton(QMessageBox::Ok); | |
106 if (box.exec() == -1) return false; | |
107 return box.standardButton(box.clickedButton()) == QMessageBox::Ok; | |
108 } | |
109 | |
110 bool ConfirmCommentDialog::confirmDangerous(QWidget *parent, | |
111 QString title, | |
112 QString head, | |
113 QString text, | |
114 QString okButtonText) | |
115 { | |
116 QMessageBox box(QMessageBox::Warning, | |
117 title, | |
118 head, | |
119 QMessageBox::Cancel, | |
120 parent); | |
121 | |
122 box.setInformativeText(text); | |
123 | |
124 QPushButton *ok = box.addButton(QMessageBox::Ok); | |
125 ok->setText(okButtonText); | |
126 box.setDefaultButton(QMessageBox::Cancel); | |
127 if (box.exec() == -1) return false; | |
128 return box.standardButton(box.clickedButton()) == QMessageBox::Ok; | |
129 } | |
130 | |
131 bool ConfirmCommentDialog::confirmFilesAction(QWidget *parent, | |
132 QString title, | |
133 QString introText, | |
134 QString introTextWithCount, | |
135 QStringList files, | |
136 QString okButtonText) | |
137 { | |
138 QString text; | |
139 if (files.size() <= 10) { | |
140 text = buildFilesText(introText, files); | |
141 } else { | |
142 text = "<qt>" + introTextWithCount + "</qt>"; | |
143 } | |
144 return confirm(parent, title, text, "", okButtonText); | |
145 } | |
146 | |
147 bool ConfirmCommentDialog::confirmDangerousFilesAction(QWidget *parent, | |
148 QString title, | |
149 QString introText, | |
150 QString introTextWithCount, | |
151 QStringList files, | |
152 QString okButtonText) | |
153 { | |
154 QString text; | |
155 if (files.size() <= 10) { | |
156 text = buildFilesText(introText, files); | |
157 } else { | |
158 text = "<qt>" + introTextWithCount + "</qt>"; | |
159 } | |
160 return confirmDangerous(parent, title, text, "", okButtonText); | |
161 } | |
162 | |
163 bool ConfirmCommentDialog::confirmAndGetShortComment(QWidget *parent, | |
164 QString title, | |
165 QString introText, | |
166 QString introTextWithCount, | |
167 QStringList files, | |
168 QString &comment, | |
169 QString okButtonText) | |
170 { | |
171 return confirmAndComment(parent, title, introText, | |
172 introTextWithCount, files, comment, false, | |
173 okButtonText); | |
174 } | |
175 | |
176 bool ConfirmCommentDialog::confirmAndGetLongComment(QWidget *parent, | |
177 QString title, | |
178 QString introText, | |
179 QString introTextWithCount, | |
180 QStringList files, | |
181 QString &comment, | |
182 QString okButtonText) | |
183 { | |
184 return confirmAndComment(parent, title, introText, | |
185 introTextWithCount, files, comment, true, | |
186 okButtonText); | |
187 } | |
188 | |
189 bool ConfirmCommentDialog::confirmAndComment(QWidget *parent, | |
190 QString title, | |
191 QString introText, | |
192 QString introTextWithCount, | |
193 QStringList files, | |
194 QString &comment, | |
195 bool longComment, | |
196 QString okButtonText) | |
197 { | |
198 QString text; | |
199 if (files.size() <= 10) { | |
200 text = buildFilesText(introText, files); | |
201 } else { | |
202 text = "<qt>" + introTextWithCount; | |
203 } | |
204 text += tr("<p>Please enter your comment:</qt>"); | |
205 return confirmAndComment(parent, title, text, comment, longComment, | |
206 okButtonText); | |
207 } | |
208 | |
209 bool ConfirmCommentDialog::confirmAndGetShortComment(QWidget *parent, | |
210 QString title, | |
211 QString introText, | |
212 QString &comment, | |
213 QString okButtonText) | |
214 { | |
215 return confirmAndComment(parent, title, introText, comment, false, | |
216 okButtonText); | |
217 } | |
218 | |
219 bool ConfirmCommentDialog::confirmAndGetLongComment(QWidget *parent, | |
220 QString title, | |
221 QString introText, | |
222 QString &comment, | |
223 QString okButtonText) | |
224 { | |
225 return confirmAndComment(parent, title, introText, comment, true, | |
226 okButtonText); | |
227 } | |
228 | |
229 bool ConfirmCommentDialog::confirmAndComment(QWidget *parent, | |
230 QString title, | |
231 QString introText, | |
232 QString &comment, | |
233 bool longComment, | |
234 QString okButtonText) | |
235 { | |
236 bool ok = false; | |
237 if (!longComment) { | |
238 QInputDialog d(parent); | |
239 d.setWindowTitle(title); | |
240 d.setLabelText(introText); | |
241 d.setTextValue(comment); | |
242 d.setOkButtonText(okButtonText); | |
243 d.setTextEchoMode(QLineEdit::Normal); | |
244 if (d.exec() == QDialog::Accepted) { | |
245 comment = d.textValue(); | |
246 ok = true; | |
247 } | |
248 } else { | |
249 ConfirmCommentDialog d(parent, title, introText, comment, okButtonText); | |
250 if (d.exec() == QDialog::Accepted) { | |
251 comment = d.getComment(); | |
252 ok = true; | |
253 } | |
254 } | |
255 | |
256 return ok; | |
257 } |