Mercurial > hg > easyhg
comparison moreinformationdialog.cpp @ 293:7b4f42cfc596
Merge from branch "more_information_dialog"
author | Chris Cannam |
---|---|
date | Mon, 21 Feb 2011 18:17:18 +0000 |
parents | 2e34e7ee7baf |
children | fd9dc5a457d8 |
comparison
equal
deleted
inserted
replaced
292:a1c8630a0057 | 293:7b4f42cfc596 |
---|---|
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->setDefault(false); | |
60 | |
61 connect(m_moreButton, SIGNAL(clicked()), this, SLOT(moreClicked())); | |
62 | |
63 bb->button(QDialogButtonBox::Ok)->setDefault(true); | |
64 | |
65 m_moreText = new QTextEdit(); | |
66 m_moreText->setAcceptRichText(false); | |
67 m_moreText->document()->setPlainText(more); | |
68 m_moreText->setMinimumWidth(360); | |
69 m_moreText->setReadOnly(true); | |
70 m_moreText->setLineWrapMode(QTextEdit::NoWrap); | |
71 | |
72 QFont font("Monospace"); | |
73 font.setStyleHint(QFont::TypeWriter); | |
74 m_moreText->setFont(font); | |
75 | |
76 layout->addWidget(m_moreText, 3, 0, 1, 2); | |
77 | |
78 m_moreText->hide(); | |
79 if (more == "") m_moreButton->hide(); | |
80 | |
81 layout->setRowStretch(1, 20); | |
82 layout->setColumnStretch(1, 20); | |
83 setMinimumWidth(400); | |
84 } | |
85 | |
86 MoreInformationDialog::~MoreInformationDialog() | |
87 { | |
88 } | |
89 | |
90 void | |
91 MoreInformationDialog::moreClicked() | |
92 { | |
93 if (m_moreText->isVisible()) { | |
94 m_moreText->hide(); | |
95 m_moreButton->setText(tr("Show Details...")); | |
96 } else { | |
97 m_moreText->show(); | |
98 m_moreButton->setText(tr("Hide Details...")); | |
99 } | |
100 adjustSize(); | |
101 } | |
102 | |
103 void | |
104 MoreInformationDialog::setIcon(QIcon icon) | |
105 { | |
106 QStyle *style = qApp->style(); | |
107 int iconSize = style->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, this); | |
108 m_iconLabel->setPixmap(icon.pixmap(iconSize, iconSize)); | |
109 } | |
110 | |
111 void | |
112 MoreInformationDialog::critical(QWidget *parent, QString title, QString head, | |
113 QString text, QString more) | |
114 { | |
115 MoreInformationDialog d(title, head, text, more, parent); | |
116 QStyle *style = qApp->style(); | |
117 d.setIcon(style->standardIcon(QStyle::SP_MessageBoxCritical, 0, &d)); | |
118 d.exec(); | |
119 } | |
120 | |
121 void | |
122 MoreInformationDialog::information(QWidget *parent, QString title, QString head, | |
123 QString text, QString more) | |
124 { | |
125 MoreInformationDialog d(title, head, text, more, parent); | |
126 QStyle *style = qApp->style(); | |
127 d.setIcon(style->standardIcon(QStyle::SP_MessageBoxInformation, 0, &d)); | |
128 d.exec(); | |
129 } | |
130 | |
131 void | |
132 MoreInformationDialog::warning(QWidget *parent, QString title, QString head, | |
133 QString text, QString more) | |
134 { | |
135 MoreInformationDialog d(title, head, text, more, parent); | |
136 QStyle *style = qApp->style(); | |
137 d.setIcon(style->standardIcon(QStyle::SP_MessageBoxWarning, 0, &d)); | |
138 d.exec(); | |
139 } | |
140 |