Chris@102
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@102
|
2
|
Chris@102
|
3 /*
|
Chris@102
|
4 EasyMercurial
|
Chris@102
|
5
|
Chris@102
|
6 Based on hgExplorer by Jari Korhonen
|
Chris@102
|
7 Copyright (c) 2010 Jari Korhonen
|
Chris@102
|
8 Copyright (c) 2010 Chris Cannam
|
Chris@102
|
9 Copyright (c) 2010 Queen Mary, University of London
|
Chris@102
|
10
|
Chris@102
|
11 This program is free software; you can redistribute it and/or
|
Chris@102
|
12 modify it under the terms of the GNU General Public License as
|
Chris@102
|
13 published by the Free Software Foundation; either version 2 of the
|
Chris@102
|
14 License, or (at your option) any later version. See the file
|
Chris@102
|
15 COPYING included with this distribution for more information.
|
Chris@102
|
16 */
|
Chris@102
|
17
|
Chris@102
|
18 #include "confirmcommentdialog.h"
|
Chris@102
|
19
|
Chris@102
|
20 #include <QMessageBox>
|
Chris@102
|
21 #include <QInputDialog>
|
Chris@104
|
22 #include <QGridLayout>
|
Chris@104
|
23 #include <QLabel>
|
Chris@104
|
24 #include <QTextEdit>
|
Chris@104
|
25 #include <QDialogButtonBox>
|
Chris@102
|
26
|
Chris@102
|
27 bool ConfirmCommentDialog::confirmFilesAction(QWidget *parent,
|
Chris@102
|
28 QString title,
|
Chris@102
|
29 QString introText,
|
Chris@102
|
30 QString introTextWithCount,
|
Chris@102
|
31 QStringList files)
|
Chris@102
|
32 {
|
Chris@102
|
33 QString text;
|
Chris@102
|
34 if (files.size() <= 10) {
|
Chris@102
|
35 text = "<qt>" + introText;
|
Chris@102
|
36 text += "<code>";
|
Chris@102
|
37 foreach (QString file, files) {
|
Chris@102
|
38 text += file + "<br>";
|
Chris@102
|
39 }
|
Chris@102
|
40 text += "</code></qt>";
|
Chris@102
|
41 } else {
|
Chris@102
|
42 text = "<qt>" + introText.arg(files.size());
|
Chris@102
|
43 }
|
Chris@102
|
44 return (QMessageBox::information(parent,
|
Chris@102
|
45 title,
|
Chris@102
|
46 text,
|
Chris@102
|
47 QMessageBox::Ok | QMessageBox::Cancel,
|
Chris@102
|
48 QMessageBox::Ok)
|
Chris@102
|
49 == QMessageBox::Ok);
|
Chris@102
|
50 }
|
Chris@102
|
51
|
Chris@102
|
52 bool ConfirmCommentDialog::confirmAndComment(QWidget *parent,
|
Chris@102
|
53 QString title,
|
Chris@102
|
54 QString introText,
|
Chris@102
|
55 QString introTextWithCount,
|
Chris@102
|
56 QStringList files,
|
Chris@104
|
57 QString &comment,
|
Chris@104
|
58 bool longComment)
|
Chris@102
|
59 {
|
Chris@102
|
60 QString text;
|
Chris@102
|
61 if (files.size() <= 10) {
|
Chris@102
|
62 text = "<qt>" + introText;
|
Chris@103
|
63 text += "<p><ul>";
|
Chris@102
|
64 foreach (QString file, files) {
|
Chris@103
|
65 text += "<li>" + file + "</li>";
|
Chris@102
|
66 }
|
Chris@103
|
67 text += "</ul><p>Please enter your comment:</qt>";
|
Chris@102
|
68 } else {
|
Chris@102
|
69 text = "<qt>" + introText.arg(files.size());
|
Chris@102
|
70 }
|
Chris@104
|
71 return confirmAndComment(parent, title, text, comment, longComment);
|
Chris@102
|
72 }
|
Chris@102
|
73
|
Chris@102
|
74 bool ConfirmCommentDialog::confirmAndComment(QWidget *parent,
|
Chris@102
|
75 QString title,
|
Chris@102
|
76 QString introText,
|
Chris@104
|
77 QString &comment,
|
Chris@104
|
78 bool longComment)
|
Chris@102
|
79 {
|
Chris@102
|
80 bool ok = false;
|
Chris@104
|
81 if (!longComment) {
|
Chris@104
|
82 comment = QInputDialog::getText(parent, title, introText,
|
Chris@104
|
83 QLineEdit::Normal, comment, &ok);
|
Chris@104
|
84 } else {
|
Chris@104
|
85 QDialog *d = new QDialog(parent);
|
Chris@104
|
86 d->setWindowTitle(title);
|
Chris@104
|
87 QGridLayout *layout = new QGridLayout;
|
Chris@104
|
88 d->setLayout(layout);
|
Chris@104
|
89 QLabel *label = new QLabel(introText);
|
Chris@104
|
90 layout->addWidget(label, 0, 0);
|
Chris@104
|
91 QTextEdit *textEdit = new QTextEdit;
|
Chris@104
|
92 textEdit->setAcceptRichText(false);
|
Chris@104
|
93 layout->addWidget(textEdit, 1, 0);
|
Chris@104
|
94 QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok |
|
Chris@104
|
95 QDialogButtonBox::Cancel);
|
Chris@104
|
96 layout->addWidget(bbox, 2, 0);
|
Chris@104
|
97 QObject::connect(bbox, SIGNAL(accepted()), d, SLOT(accept()));
|
Chris@104
|
98 QObject::connect(bbox, SIGNAL(rejected()), d, SLOT(reject()));
|
Chris@104
|
99 if (d->exec() == QDialog::Accepted) {
|
Chris@104
|
100 comment = textEdit->document()->toPlainText();
|
Chris@104
|
101 ok = true;
|
Chris@104
|
102 }
|
Chris@104
|
103 }
|
Chris@102
|
104 return ok;
|
Chris@102
|
105 }
|