comparison incomingdialog.cpp @ 125:63c2f3f61c79

* Add Incoming dialog and better layouts for dialogs generally
author Chris Cannam
date Mon, 29 Nov 2010 17:03:17 +0000
parents
children 8fd71f570884
comparison
equal deleted inserted replaced
124:1f27f71a7034 125:63c2f3f61c79
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) 2010 Chris Cannam
9 Copyright (c) 2010 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 "incomingdialog.h"
19 #include "changeset.h"
20 #include "common.h"
21
22 #include <QScrollArea>
23 #include <QApplication>
24 #include <QDialogButtonBox>
25 #include <QLabel>
26 #include <QGridLayout>
27 #include <QStyle>
28
29 IncomingDialog::IncomingDialog(QWidget *w, QString text) :
30 QDialog(w)
31 {
32 QString head;
33 QString body;
34 bool scroll;
35
36 Changesets csets = Changeset::parseChangesets(text);
37 if (csets.empty()) {
38 head = tr("No changes waiting to pull");
39 if (text.trimmed() != "") {
40 body = QString("<p>%1</p><code>%2</code>")
41 .arg(tr("The command output was:"))
42 .arg(xmlEncode(text).replace("\n", "<br>"));
43 }
44 scroll = false;
45 } else {
46 head = tr("There are %n change(s) ready to pull", "", csets.size());
47 foreach (Changeset *cs, csets) {
48 body += cs->formatHtml() + "<p>";
49 delete cs;
50 }
51 scroll = true;
52 }
53
54 QGridLayout *layout = new QGridLayout;
55 setLayout(layout);
56
57 QLabel *info = new QLabel;
58 QStyle *style = qApp->style();
59 int iconSize = style->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, this);
60 info->setPixmap(style->standardIcon(QStyle::SP_MessageBoxInformation, 0, this)
61 .pixmap(iconSize, iconSize));
62 layout->addWidget(info, 0, 0);
63
64 QLabel *headLabel = new QLabel(QString("<qt><h3>%1</h3></qt>").arg(head));
65 layout->addWidget(headLabel, 0, 1);
66
67 QLabel *textLabel = new QLabel(body);
68
69 if (scroll) {
70 QScrollArea *sa = new QScrollArea;
71 layout->addWidget(sa, 1, 1);
72 layout->setRowStretch(1, 20);
73 sa->setWidget(textLabel);
74 } else {
75 layout->addWidget(textLabel, 1, 1);
76 }
77
78 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok);
79 connect(bb, SIGNAL(accepted()), this, SLOT(accept()));
80 layout->addWidget(bb, 2, 0, 1, 2);
81 }
82
83