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@105
|
27 ConfirmCommentDialog::ConfirmCommentDialog(QWidget *parent,
|
Chris@105
|
28 QString title,
|
Chris@105
|
29 QString introText,
|
Chris@105
|
30 QString initialComment) :
|
Chris@105
|
31 QDialog(parent)
|
Chris@105
|
32 {
|
Chris@105
|
33 setWindowTitle(title);
|
Chris@105
|
34
|
Chris@105
|
35 QGridLayout *layout = new QGridLayout;
|
Chris@105
|
36 setLayout(layout);
|
Chris@105
|
37 QLabel *label = new QLabel(introText);
|
Chris@105
|
38 layout->addWidget(label, 0, 0);
|
Chris@105
|
39
|
Chris@105
|
40 m_textEdit = new QTextEdit;
|
Chris@105
|
41 m_textEdit->setAcceptRichText(false);
|
Chris@105
|
42 m_textEdit->document()->setPlainText(initialComment);
|
Chris@105
|
43 m_textEdit->setMinimumWidth(360);
|
Chris@105
|
44 connect(m_textEdit, SIGNAL(textChanged()), this, SLOT(commentChanged()));
|
Chris@105
|
45 layout->addWidget(m_textEdit, 1, 0);
|
Chris@105
|
46
|
Chris@105
|
47 QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok |
|
Chris@105
|
48 QDialogButtonBox::Cancel);
|
Chris@105
|
49 layout->addWidget(bbox, 2, 0);
|
Chris@105
|
50 m_ok = bbox->button(QDialogButtonBox::Ok);
|
Chris@105
|
51 m_ok->setEnabled(initialComment != "");
|
Chris@105
|
52
|
Chris@105
|
53 connect(bbox, SIGNAL(accepted()), this, SLOT(accept()));
|
Chris@105
|
54 connect(bbox, SIGNAL(rejected()), this, SLOT(reject()));
|
Chris@105
|
55 }
|
Chris@105
|
56
|
Chris@105
|
57 void ConfirmCommentDialog::commentChanged()
|
Chris@105
|
58 {
|
Chris@105
|
59 m_ok->setEnabled(getComment() != "");
|
Chris@105
|
60 }
|
Chris@105
|
61
|
Chris@105
|
62 QString ConfirmCommentDialog::getComment() const
|
Chris@105
|
63 {
|
Chris@105
|
64 return m_textEdit->document()->toPlainText();
|
Chris@105
|
65 }
|
Chris@105
|
66
|
Chris@102
|
67 bool ConfirmCommentDialog::confirmFilesAction(QWidget *parent,
|
Chris@102
|
68 QString title,
|
Chris@102
|
69 QString introText,
|
Chris@102
|
70 QString introTextWithCount,
|
Chris@102
|
71 QStringList files)
|
Chris@102
|
72 {
|
Chris@102
|
73 QString text;
|
Chris@102
|
74 if (files.size() <= 10) {
|
Chris@102
|
75 text = "<qt>" + introText;
|
Chris@102
|
76 text += "<code>";
|
Chris@102
|
77 foreach (QString file, files) {
|
Chris@102
|
78 text += file + "<br>";
|
Chris@102
|
79 }
|
Chris@102
|
80 text += "</code></qt>";
|
Chris@102
|
81 } else {
|
Chris@102
|
82 text = "<qt>" + introText.arg(files.size());
|
Chris@102
|
83 }
|
Chris@102
|
84 return (QMessageBox::information(parent,
|
Chris@102
|
85 title,
|
Chris@102
|
86 text,
|
Chris@102
|
87 QMessageBox::Ok | QMessageBox::Cancel,
|
Chris@102
|
88 QMessageBox::Ok)
|
Chris@102
|
89 == QMessageBox::Ok);
|
Chris@102
|
90 }
|
Chris@102
|
91
|
Chris@102
|
92 bool ConfirmCommentDialog::confirmAndComment(QWidget *parent,
|
Chris@102
|
93 QString title,
|
Chris@102
|
94 QString introText,
|
Chris@102
|
95 QString introTextWithCount,
|
Chris@102
|
96 QStringList files,
|
Chris@104
|
97 QString &comment,
|
Chris@104
|
98 bool longComment)
|
Chris@102
|
99 {
|
Chris@102
|
100 QString text;
|
Chris@102
|
101 if (files.size() <= 10) {
|
Chris@102
|
102 text = "<qt>" + introText;
|
Chris@103
|
103 text += "<p><ul>";
|
Chris@102
|
104 foreach (QString file, files) {
|
Chris@103
|
105 text += "<li>" + file + "</li>";
|
Chris@102
|
106 }
|
Chris@103
|
107 text += "</ul><p>Please enter your comment:</qt>";
|
Chris@102
|
108 } else {
|
Chris@102
|
109 text = "<qt>" + introText.arg(files.size());
|
Chris@102
|
110 }
|
Chris@104
|
111 return confirmAndComment(parent, title, text, comment, longComment);
|
Chris@102
|
112 }
|
Chris@102
|
113
|
Chris@102
|
114 bool ConfirmCommentDialog::confirmAndComment(QWidget *parent,
|
Chris@102
|
115 QString title,
|
Chris@102
|
116 QString introText,
|
Chris@104
|
117 QString &comment,
|
Chris@104
|
118 bool longComment)
|
Chris@102
|
119 {
|
Chris@102
|
120 bool ok = false;
|
Chris@104
|
121 if (!longComment) {
|
Chris@104
|
122 comment = QInputDialog::getText(parent, title, introText,
|
Chris@104
|
123 QLineEdit::Normal, comment, &ok);
|
Chris@104
|
124 } else {
|
Chris@105
|
125 ConfirmCommentDialog *d = new ConfirmCommentDialog(parent,
|
Chris@105
|
126 title,
|
Chris@105
|
127 introText,
|
Chris@105
|
128 comment);
|
Chris@104
|
129 if (d->exec() == QDialog::Accepted) {
|
Chris@105
|
130 comment = d->getComment();
|
Chris@104
|
131 ok = true;
|
Chris@104
|
132 }
|
Chris@104
|
133 }
|
Chris@102
|
134 return ok;
|
Chris@102
|
135 }
|