Chris@275
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@275
|
2
|
Chris@275
|
3 /*
|
Chris@275
|
4 EasyMercurial
|
Chris@275
|
5
|
Chris@275
|
6 Based on hgExplorer by Jari Korhonen
|
Chris@275
|
7 Copyright (c) 2010 Jari Korhonen
|
Chris@275
|
8 Copyright (c) 2011 Chris Cannam
|
Chris@275
|
9 Copyright (c) 2011 Queen Mary, University of London
|
Chris@275
|
10
|
Chris@275
|
11 This program is free software; you can redistribute it and/or
|
Chris@275
|
12 modify it under the terms of the GNU General Public License as
|
Chris@275
|
13 published by the Free Software Foundation; either version 2 of the
|
Chris@275
|
14 License, or (at your option) any later version. See the file
|
Chris@275
|
15 COPYING included with this distribution for more information.
|
Chris@275
|
16 */
|
Chris@275
|
17
|
Chris@275
|
18 #include "moreinformationdialog.h"
|
Chris@275
|
19
|
Chris@275
|
20 #include <QMessageBox>
|
Chris@290
|
21 #include <QLabel>
|
Chris@290
|
22 #include <QGridLayout>
|
Chris@290
|
23 #include <QTextEdit>
|
Chris@290
|
24 #include <QDialogButtonBox>
|
Chris@290
|
25 #include <QPushButton>
|
Chris@290
|
26 #include <QApplication>
|
Chris@290
|
27 #include <QStyle>
|
Chris@275
|
28
|
Chris@290
|
29 MoreInformationDialog::MoreInformationDialog(QString title,
|
Chris@290
|
30 QString head,
|
Chris@290
|
31 QString text,
|
Chris@290
|
32 QString more,
|
Chris@290
|
33 QWidget *parent) :
|
Chris@290
|
34 QDialog(parent)
|
Chris@275
|
35 {
|
Chris@290
|
36 setWindowTitle(title);
|
Chris@290
|
37
|
Chris@290
|
38 QGridLayout *layout = new QGridLayout;
|
Chris@290
|
39 layout->setSpacing(10);
|
Chris@290
|
40 setLayout(layout);
|
Chris@290
|
41
|
Chris@290
|
42 m_iconLabel = new QLabel;
|
Chris@291
|
43 layout->addWidget(m_iconLabel, 0, 0, 2, 1, Qt::AlignTop);
|
Chris@290
|
44
|
Chris@290
|
45 QLabel *headLabel = new QLabel(QString("<qt><h3>%1</h3></qt>").arg(head));
|
Chris@290
|
46 layout->addWidget(headLabel, 0, 1);
|
Chris@290
|
47
|
Chris@290
|
48 QLabel *textLabel = new QLabel(text);
|
Chris@290
|
49 textLabel->setTextFormat(Qt::RichText);
|
Chris@291
|
50 textLabel->setWordWrap(true);
|
Chris@291
|
51 layout->addWidget(textLabel, 1, 1, Qt::AlignTop);
|
Chris@290
|
52
|
Chris@290
|
53 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok);
|
Chris@290
|
54 connect(bb, SIGNAL(accepted()), this, SLOT(accept()));
|
Chris@290
|
55 layout->addWidget(bb, 2, 0, 1, 2);
|
Chris@290
|
56
|
Chris@290
|
57 m_moreButton = bb->addButton(tr("More Details..."),
|
Chris@290
|
58 QDialogButtonBox::ActionRole);
|
Chris@291
|
59 m_moreButton->setDefault(false);
|
Chris@290
|
60
|
Chris@290
|
61 connect(m_moreButton, SIGNAL(clicked()), this, SLOT(moreClicked()));
|
Chris@290
|
62
|
Chris@291
|
63 bb->button(QDialogButtonBox::Ok)->setDefault(true);
|
Chris@291
|
64
|
Chris@290
|
65 m_moreText = new QTextEdit();
|
Chris@290
|
66 m_moreText->setAcceptRichText(false);
|
Chris@290
|
67 m_moreText->document()->setPlainText(more);
|
Chris@290
|
68 m_moreText->setMinimumWidth(360);
|
Chris@290
|
69 m_moreText->setReadOnly(true);
|
Chris@290
|
70 m_moreText->setLineWrapMode(QTextEdit::NoWrap);
|
Chris@290
|
71
|
Chris@290
|
72 QFont font("Monospace");
|
Chris@290
|
73 font.setStyleHint(QFont::TypeWriter);
|
Chris@290
|
74 m_moreText->setFont(font);
|
Chris@290
|
75
|
Chris@290
|
76 layout->addWidget(m_moreText, 3, 0, 1, 2);
|
Chris@290
|
77
|
Chris@290
|
78 m_moreText->hide();
|
Chris@291
|
79 if (more == "") m_moreButton->hide();
|
Chris@290
|
80
|
Chris@291
|
81 layout->setRowStretch(1, 20);
|
Chris@290
|
82 layout->setColumnStretch(1, 20);
|
Chris@290
|
83 setMinimumWidth(400);
|
Chris@290
|
84 }
|
Chris@290
|
85
|
Chris@290
|
86 MoreInformationDialog::~MoreInformationDialog()
|
Chris@290
|
87 {
|
Chris@275
|
88 }
|
Chris@275
|
89
|
Chris@275
|
90 void
|
Chris@290
|
91 MoreInformationDialog::moreClicked()
|
Chris@275
|
92 {
|
Chris@290
|
93 if (m_moreText->isVisible()) {
|
Chris@290
|
94 m_moreText->hide();
|
Chris@290
|
95 m_moreButton->setText(tr("Show Details..."));
|
Chris@290
|
96 } else {
|
Chris@290
|
97 m_moreText->show();
|
Chris@290
|
98 m_moreButton->setText(tr("Hide Details..."));
|
Chris@290
|
99 }
|
Chris@290
|
100 adjustSize();
|
Chris@290
|
101 }
|
Chris@290
|
102
|
Chris@290
|
103 void
|
Chris@290
|
104 MoreInformationDialog::setIcon(QIcon icon)
|
Chris@290
|
105 {
|
Chris@290
|
106 QStyle *style = qApp->style();
|
Chris@290
|
107 int iconSize = style->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, this);
|
Chris@290
|
108 m_iconLabel->setPixmap(icon.pixmap(iconSize, iconSize));
|
Chris@275
|
109 }
|
Chris@275
|
110
|
Chris@275
|
111 void
|
Chris@290
|
112 MoreInformationDialog::critical(QWidget *parent, QString title, QString head,
|
Chris@290
|
113 QString text, QString more)
|
Chris@275
|
114 {
|
Chris@290
|
115 MoreInformationDialog d(title, head, text, more, parent);
|
Chris@290
|
116 QStyle *style = qApp->style();
|
Chris@290
|
117 d.setIcon(style->standardIcon(QStyle::SP_MessageBoxCritical, 0, &d));
|
Chris@290
|
118 d.exec();
|
Chris@275
|
119 }
|
Chris@275
|
120
|
Chris@290
|
121 void
|
Chris@290
|
122 MoreInformationDialog::information(QWidget *parent, QString title, QString head,
|
Chris@290
|
123 QString text, QString more)
|
Chris@290
|
124 {
|
Chris@290
|
125 MoreInformationDialog d(title, head, text, more, parent);
|
Chris@290
|
126 QStyle *style = qApp->style();
|
Chris@290
|
127 d.setIcon(style->standardIcon(QStyle::SP_MessageBoxInformation, 0, &d));
|
Chris@290
|
128 d.exec();
|
Chris@290
|
129 }
|
Chris@290
|
130
|
Chris@290
|
131 void
|
Chris@290
|
132 MoreInformationDialog::warning(QWidget *parent, QString title, QString head,
|
Chris@290
|
133 QString text, QString more)
|
Chris@290
|
134 {
|
Chris@290
|
135 MoreInformationDialog d(title, head, text, more, parent);
|
Chris@290
|
136 QStyle *style = qApp->style();
|
Chris@290
|
137 d.setIcon(style->standardIcon(QStyle::SP_MessageBoxWarning, 0, &d));
|
Chris@290
|
138 d.exec();
|
Chris@290
|
139 }
|
Chris@290
|
140
|