comparison src/hgignoredialog.cpp @ 415:6d7dad48b13c ignore

Make HgIgnoreDialog _look_ plausible (still doesn't do anything though!)
author Chris Cannam
date Thu, 16 Jun 2011 14:32:35 +0100
parents 939701b848e5
children 8df07172d6da
comparison
equal deleted inserted replaced
414:939701b848e5 415:6d7dad48b13c
17 17
18 #include "hgignoredialog.h" 18 #include "hgignoredialog.h"
19 #include "common.h" 19 #include "common.h"
20 #include "debug.h" 20 #include "debug.h"
21 21
22 #include <QGridLayout>
23 #include <QRadioButton>
24 #include <QLabel>
25 #include <QDialogButtonBox>
26 #include <QPushButton>
27
28 HgIgnoreDialog::HgIgnoreDialog(QWidget *parent,
29 QString title,
30 QString introText,
31 QString question,
32 QStringList options,
33 QString okButtonText) :
34 QDialog(parent)
35 {
36 setWindowTitle(title);
37
38 QGridLayout *layout = new QGridLayout;
39 setLayout(layout);
40
41 int row = 0;
42
43 QLabel *label = new QLabel(QString("%1%2").arg(introText).arg(question));
44 label->setWordWrap(true);
45 layout->addWidget(label, row++, 0, 1, 2);
46
47 if (!options.empty()) {
48 layout->addWidget(new QLabel(" "), row, 0);
49 layout->setColumnStretch(1, 10);
50 bool first = true;
51 foreach (QString option, options) {
52 QRadioButton *b = new QRadioButton(option);
53 layout->addWidget(b, row++, 1);
54 b->setChecked(first);
55 first = false;
56 }
57 }
58
59 QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok |
60 QDialogButtonBox::Cancel);
61 layout->addWidget(bbox, row++, 0, 1, 2);
62 bbox->button(QDialogButtonBox::Ok)->setDefault(true);
63 bbox->button(QDialogButtonBox::Ok)->setText(okButtonText);
64 bbox->button(QDialogButtonBox::Cancel)->setAutoDefault(false);
65
66 connect(bbox, SIGNAL(accepted()), this, SLOT(accept()));
67 connect(bbox, SIGNAL(rejected()), this, SLOT(reject()));
68 }
69
22 HgIgnoreDialog::IgnoreType 70 HgIgnoreDialog::IgnoreType
23 HgIgnoreDialog::confirmIgnore(QStringList files, QStringList suffixes) 71 HgIgnoreDialog::confirmIgnore(QWidget *parent,
72 QStringList files, QStringList suffixes)
24 { 73 {
25 QString text = "<qt>"; 74 QString intro = "<qt><h3>";
75 intro += tr("Ignore files");
76 intro += "</h3><p>";
26 77
27 if (files.size() < 10) { 78 if (files.size() < 10) {
28 text += tr("You have asked to ignore the following files:"); 79 intro += tr("You have asked to ignore the following files:</p><p>");
29 text += "<p><code>"; 80 intro += "<code>&nbsp;&nbsp;&nbsp;"
30 foreach (QString f, files) { 81 + files.join("<br>&nbsp;&nbsp;&nbsp;") + "</code>";
31 text += "&nbsp;&nbsp;&nbsp;" + xmlEncode(f) + "<br>";
32 }
33 text += "</code>";
34 } else { 82 } else {
35 text += "<p>"; 83 intro += tr("You have asked to ignore %n file(s).", "", files.size());
36 text += tr("You have asked to ignore %1 file(s).", "", files.size());
37 text += "</p>";
38 } 84 }
85
86 intro += "</p></qt>";
39 87
40 if (suffixes.size() > 0) { 88 if (suffixes.size() > 0) {
41 89
42 text += "<p>"; 90 QStringList options;
43 text += tr("Would you like to:"); 91 options << tr("Ignore these files only");
44 text += "<ul>"; 92 options << tr("Ignore files with these names in any subdirectory");
45 93
94 if (suffixes.size() > 1) {
95 options << tr("Ignore all files with these extensions:\n%1")
96 .arg(suffixes.join(", "));
97 } else {
98 options << tr("Ignore all files with the extension \"%1\"")
99 .arg(suffixes[0]);
100 }
46 101
47 //... 102 HgIgnoreDialog d(parent, tr("Ignore files"),
103 intro, tr("<p>Please choose whether to:</p>"),
104 options, tr("Ignore"));
105
106 if (d.exec() == QDialog::Accepted) {
107
108 //...
109
110 }
48 111
49 } 112 } else {
113
114 QStringList options;
115 options << tr("Ignore these files only");
116 options << tr("Ignore files with these names in any subdirectory");
117
118 HgIgnoreDialog d(parent, tr("Ignore files"),
119 intro, tr("<p>Please choose whether to:</p>"),
120 options, tr("Ignore"));
121
122 if (d.exec() == QDialog::Accepted) {
123
124 //...
125
126 }
127 }
50 128
51 129
52 return IgnoreNothing; 130 return IgnoreNothing;
53 } 131 }
54 132