comparison src/moreinformationdialog.cpp @ 370:b9c153e00e84

Move source files to src/
author Chris Cannam
date Thu, 24 Mar 2011 10:27:51 +0000
parents moreinformationdialog.cpp@fd9dc5a457d8
children 66ec8b2ee946
comparison
equal deleted inserted replaced
369:19cce6d2c470 370:b9c153e00e84
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) 2011 Chris Cannam
9 Copyright (c) 2011 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 "moreinformationdialog.h"
19
20 #include <QMessageBox>
21 #include <QLabel>
22 #include <QGridLayout>
23 #include <QTextEdit>
24 #include <QDialogButtonBox>
25 #include <QPushButton>
26 #include <QApplication>
27 #include <QStyle>
28
29 MoreInformationDialog::MoreInformationDialog(QString title,
30 QString head,
31 QString text,
32 QString more,
33 QWidget *parent) :
34 QDialog(parent)
35 {
36 setWindowTitle(title);
37
38 QGridLayout *layout = new QGridLayout;
39 layout->setSpacing(10);
40 setLayout(layout);
41
42 m_iconLabel = new QLabel;
43 layout->addWidget(m_iconLabel, 0, 0, 2, 1, Qt::AlignTop);
44
45 QLabel *headLabel = new QLabel(QString("<qt><h3>%1</h3></qt>").arg(head));
46 layout->addWidget(headLabel, 0, 1);
47
48 QLabel *textLabel = new QLabel(text);
49 textLabel->setTextFormat(Qt::RichText);
50 textLabel->setWordWrap(true);
51 layout->addWidget(textLabel, 1, 1, Qt::AlignTop);
52
53 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok);
54 connect(bb, SIGNAL(accepted()), this, SLOT(accept()));
55 layout->addWidget(bb, 2, 0, 1, 2);
56
57 m_moreButton = bb->addButton(tr("More Details..."),
58 QDialogButtonBox::ActionRole);
59 m_moreButton->setAutoDefault(false);
60 m_moreButton->setDefault(false);
61
62 connect(m_moreButton, SIGNAL(clicked()), this, SLOT(moreClicked()));
63
64 bb->button(QDialogButtonBox::Ok)->setDefault(true);
65
66 m_moreText = new QTextEdit();
67 m_moreText->setAcceptRichText(false);
68 m_moreText->document()->setPlainText(more);
69 m_moreText->setMinimumWidth(360);
70 m_moreText->setReadOnly(true);
71 m_moreText->setLineWrapMode(QTextEdit::NoWrap);
72
73 QFont font("Monospace");
74 font.setStyleHint(QFont::TypeWriter);
75 m_moreText->setFont(font);
76
77 layout->addWidget(m_moreText, 3, 0, 1, 2);
78
79 m_moreText->hide();
80 if (more == "") m_moreButton->hide();
81
82 layout->setRowStretch(1, 20);
83 layout->setColumnStretch(1, 20);
84 setMinimumWidth(400);
85 }
86
87 MoreInformationDialog::~MoreInformationDialog()
88 {
89 }
90
91 void
92 MoreInformationDialog::moreClicked()
93 {
94 if (m_moreText->isVisible()) {
95 m_moreText->hide();
96 m_moreButton->setText(tr("Show Details..."));
97 } else {
98 m_moreText->show();
99 m_moreButton->setText(tr("Hide Details..."));
100 }
101 adjustSize();
102 }
103
104 void
105 MoreInformationDialog::setIcon(QIcon icon)
106 {
107 QStyle *style = qApp->style();
108 int iconSize = style->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, this);
109 m_iconLabel->setPixmap(icon.pixmap(iconSize, iconSize));
110 }
111
112 void
113 MoreInformationDialog::critical(QWidget *parent, QString title, QString head,
114 QString text, QString more)
115 {
116 MoreInformationDialog d(title, head, text, more, parent);
117 QStyle *style = qApp->style();
118 d.setIcon(style->standardIcon(QStyle::SP_MessageBoxCritical, 0, &d));
119 d.exec();
120 }
121
122 void
123 MoreInformationDialog::information(QWidget *parent, QString title, QString head,
124 QString text, QString more)
125 {
126 MoreInformationDialog d(title, head, text, more, parent);
127 QStyle *style = qApp->style();
128 d.setIcon(style->standardIcon(QStyle::SP_MessageBoxInformation, 0, &d));
129 d.exec();
130 }
131
132 void
133 MoreInformationDialog::warning(QWidget *parent, QString title, QString head,
134 QString text, QString more)
135 {
136 MoreInformationDialog d(title, head, text, more, parent);
137 QStyle *style = qApp->style();
138 d.setIcon(style->standardIcon(QStyle::SP_MessageBoxWarning, 0, &d));
139 d.exec();
140 }
141