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@290
|
43 layout->addWidget(m_iconLabel, 0, 0);
|
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@290
|
50 layout->addWidget(textLabel, 1, 1);
|
Chris@290
|
51
|
Chris@290
|
52 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok);
|
Chris@290
|
53 connect(bb, SIGNAL(accepted()), this, SLOT(accept()));
|
Chris@290
|
54 layout->addWidget(bb, 2, 0, 1, 2);
|
Chris@290
|
55
|
Chris@290
|
56 m_moreButton = bb->addButton(tr("More Details..."),
|
Chris@290
|
57 QDialogButtonBox::ActionRole);
|
Chris@290
|
58
|
Chris@290
|
59 connect(m_moreButton, SIGNAL(clicked()), this, SLOT(moreClicked()));
|
Chris@290
|
60
|
Chris@290
|
61 m_moreText = new QTextEdit();
|
Chris@290
|
62 m_moreText->setAcceptRichText(false);
|
Chris@290
|
63 m_moreText->document()->setPlainText(more);
|
Chris@290
|
64 m_moreText->setMinimumWidth(360);
|
Chris@290
|
65 m_moreText->setReadOnly(true);
|
Chris@290
|
66 m_moreText->setLineWrapMode(QTextEdit::NoWrap);
|
Chris@290
|
67
|
Chris@290
|
68 QFont font("Monospace");
|
Chris@290
|
69 font.setStyleHint(QFont::TypeWriter);
|
Chris@290
|
70 m_moreText->setFont(font);
|
Chris@290
|
71
|
Chris@290
|
72 layout->addWidget(m_moreText, 3, 0, 1, 2);
|
Chris@290
|
73
|
Chris@290
|
74 m_moreText->hide();
|
Chris@290
|
75
|
Chris@290
|
76 layout->setColumnStretch(1, 20);
|
Chris@290
|
77 setMinimumWidth(400);
|
Chris@290
|
78 }
|
Chris@290
|
79
|
Chris@290
|
80 MoreInformationDialog::~MoreInformationDialog()
|
Chris@290
|
81 {
|
Chris@275
|
82 }
|
Chris@275
|
83
|
Chris@275
|
84 void
|
Chris@290
|
85 MoreInformationDialog::moreClicked()
|
Chris@275
|
86 {
|
Chris@290
|
87 if (m_moreText->isVisible()) {
|
Chris@290
|
88 m_moreText->hide();
|
Chris@290
|
89 m_moreButton->setText(tr("Show Details..."));
|
Chris@290
|
90 } else {
|
Chris@290
|
91 m_moreText->show();
|
Chris@290
|
92 m_moreButton->setText(tr("Hide Details..."));
|
Chris@290
|
93 }
|
Chris@290
|
94 adjustSize();
|
Chris@290
|
95 }
|
Chris@290
|
96
|
Chris@290
|
97 void
|
Chris@290
|
98 MoreInformationDialog::setIcon(QIcon icon)
|
Chris@290
|
99 {
|
Chris@290
|
100 QStyle *style = qApp->style();
|
Chris@290
|
101 int iconSize = style->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, this);
|
Chris@290
|
102 m_iconLabel->setPixmap(icon.pixmap(iconSize, iconSize));
|
Chris@275
|
103 }
|
Chris@275
|
104
|
Chris@275
|
105 void
|
Chris@290
|
106 MoreInformationDialog::critical(QWidget *parent, QString title, QString head,
|
Chris@290
|
107 QString text, QString more)
|
Chris@275
|
108 {
|
Chris@290
|
109 MoreInformationDialog d(title, head, text, more, parent);
|
Chris@290
|
110 QStyle *style = qApp->style();
|
Chris@290
|
111 d.setIcon(style->standardIcon(QStyle::SP_MessageBoxCritical, 0, &d));
|
Chris@290
|
112 d.exec();
|
Chris@275
|
113 }
|
Chris@275
|
114
|
Chris@290
|
115 void
|
Chris@290
|
116 MoreInformationDialog::information(QWidget *parent, QString title, QString head,
|
Chris@290
|
117 QString text, QString more)
|
Chris@290
|
118 {
|
Chris@290
|
119 MoreInformationDialog d(title, head, text, more, parent);
|
Chris@290
|
120 QStyle *style = qApp->style();
|
Chris@290
|
121 d.setIcon(style->standardIcon(QStyle::SP_MessageBoxInformation, 0, &d));
|
Chris@290
|
122 d.exec();
|
Chris@290
|
123 }
|
Chris@290
|
124
|
Chris@290
|
125 void
|
Chris@290
|
126 MoreInformationDialog::warning(QWidget *parent, QString title, QString head,
|
Chris@290
|
127 QString text, QString more)
|
Chris@290
|
128 {
|
Chris@290
|
129 MoreInformationDialog d(title, head, text, more, parent);
|
Chris@290
|
130 QStyle *style = qApp->style();
|
Chris@290
|
131 d.setIcon(style->standardIcon(QStyle::SP_MessageBoxWarning, 0, &d));
|
Chris@290
|
132 d.exec();
|
Chris@290
|
133 }
|
Chris@290
|
134
|