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@644
|
8 Copyright (c) 2013 Chris Cannam
|
Chris@644
|
9 Copyright (c) 2013 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@674
|
38 m_layout = new QGridLayout;
|
Chris@674
|
39 m_layout->setSpacing(10);
|
Chris@674
|
40 setLayout(m_layout);
|
Chris@290
|
41
|
Chris@290
|
42 m_iconLabel = new QLabel;
|
Chris@674
|
43 m_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@674
|
46 m_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@674
|
51 m_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@674
|
55 m_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@298
|
59 m_moreButton->setAutoDefault(false);
|
Chris@291
|
60 m_moreButton->setDefault(false);
|
Chris@290
|
61
|
Chris@290
|
62 connect(m_moreButton, SIGNAL(clicked()), this, SLOT(moreClicked()));
|
Chris@290
|
63
|
Chris@291
|
64 bb->button(QDialogButtonBox::Ok)->setDefault(true);
|
Chris@291
|
65
|
Chris@290
|
66 m_moreText = new QTextEdit();
|
Chris@290
|
67 m_moreText->setAcceptRichText(false);
|
Chris@290
|
68 m_moreText->document()->setPlainText(more);
|
Chris@290
|
69 m_moreText->setMinimumWidth(360);
|
Chris@290
|
70 m_moreText->setReadOnly(true);
|
Chris@290
|
71 m_moreText->setLineWrapMode(QTextEdit::NoWrap);
|
Chris@290
|
72
|
Chris@290
|
73 QFont font("Monospace");
|
Chris@290
|
74 font.setStyleHint(QFont::TypeWriter);
|
Chris@290
|
75 m_moreText->setFont(font);
|
Chris@290
|
76
|
Chris@674
|
77 m_layout->addWidget(m_moreText, 3, 0, 1, 2);
|
Chris@290
|
78
|
Chris@290
|
79 m_moreText->hide();
|
Chris@291
|
80 if (more == "") m_moreButton->hide();
|
Chris@290
|
81
|
Chris@674
|
82 m_layout->setRowStretch(1, 10);
|
Chris@674
|
83 m_layout->setColumnStretch(1, 20);
|
Chris@290
|
84 setMinimumWidth(400);
|
Chris@290
|
85 }
|
Chris@290
|
86
|
Chris@290
|
87 MoreInformationDialog::~MoreInformationDialog()
|
Chris@290
|
88 {
|
Chris@275
|
89 }
|
Chris@275
|
90
|
Chris@275
|
91 void
|
Chris@290
|
92 MoreInformationDialog::moreClicked()
|
Chris@275
|
93 {
|
Chris@290
|
94 if (m_moreText->isVisible()) {
|
Chris@290
|
95 m_moreText->hide();
|
Chris@674
|
96 m_layout->setRowStretch(3, 0);
|
Chris@290
|
97 m_moreButton->setText(tr("Show Details..."));
|
Chris@290
|
98 } else {
|
Chris@290
|
99 m_moreText->show();
|
Chris@674
|
100 m_layout->setRowStretch(3, 30);
|
Chris@290
|
101 m_moreButton->setText(tr("Hide Details..."));
|
Chris@290
|
102 }
|
Chris@290
|
103 adjustSize();
|
Chris@290
|
104 }
|
Chris@290
|
105
|
Chris@290
|
106 void
|
Chris@290
|
107 MoreInformationDialog::setIcon(QIcon icon)
|
Chris@290
|
108 {
|
Chris@290
|
109 QStyle *style = qApp->style();
|
Chris@290
|
110 int iconSize = style->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, this);
|
Chris@290
|
111 m_iconLabel->setPixmap(icon.pixmap(iconSize, iconSize));
|
Chris@275
|
112 }
|
Chris@275
|
113
|
Chris@275
|
114 void
|
Chris@290
|
115 MoreInformationDialog::critical(QWidget *parent, QString title, QString head,
|
Chris@290
|
116 QString text, QString more)
|
Chris@275
|
117 {
|
Chris@290
|
118 MoreInformationDialog d(title, head, text, more, parent);
|
Chris@290
|
119 QStyle *style = qApp->style();
|
Chris@290
|
120 d.setIcon(style->standardIcon(QStyle::SP_MessageBoxCritical, 0, &d));
|
Chris@290
|
121 d.exec();
|
Chris@275
|
122 }
|
Chris@275
|
123
|
Chris@290
|
124 void
|
Chris@290
|
125 MoreInformationDialog::information(QWidget *parent, QString title, QString head,
|
Chris@290
|
126 QString text, QString more)
|
Chris@290
|
127 {
|
Chris@290
|
128 MoreInformationDialog d(title, head, text, more, parent);
|
Chris@290
|
129 QStyle *style = qApp->style();
|
Chris@290
|
130 d.setIcon(style->standardIcon(QStyle::SP_MessageBoxInformation, 0, &d));
|
Chris@290
|
131 d.exec();
|
Chris@290
|
132 }
|
Chris@290
|
133
|
Chris@290
|
134 void
|
Chris@290
|
135 MoreInformationDialog::warning(QWidget *parent, QString title, QString head,
|
Chris@290
|
136 QString text, QString more)
|
Chris@290
|
137 {
|
Chris@290
|
138 MoreInformationDialog d(title, head, text, more, parent);
|
Chris@290
|
139 QStyle *style = qApp->style();
|
Chris@290
|
140 d.setIcon(style->standardIcon(QStyle::SP_MessageBoxWarning, 0, &d));
|
Chris@290
|
141 d.exec();
|
Chris@290
|
142 }
|
Chris@290
|
143
|