Chris@275: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@275: Chris@275: /* Chris@275: EasyMercurial Chris@275: Chris@275: Based on hgExplorer by Jari Korhonen Chris@275: Copyright (c) 2010 Jari Korhonen Chris@275: Copyright (c) 2011 Chris Cannam Chris@275: Copyright (c) 2011 Queen Mary, University of London Chris@275: Chris@275: This program is free software; you can redistribute it and/or Chris@275: modify it under the terms of the GNU General Public License as Chris@275: published by the Free Software Foundation; either version 2 of the Chris@275: License, or (at your option) any later version. See the file Chris@275: COPYING included with this distribution for more information. Chris@275: */ Chris@275: Chris@275: #include "moreinformationdialog.h" Chris@275: Chris@275: #include Chris@290: #include Chris@290: #include Chris@290: #include Chris@290: #include Chris@290: #include Chris@290: #include Chris@290: #include Chris@275: Chris@290: MoreInformationDialog::MoreInformationDialog(QString title, Chris@290: QString head, Chris@290: QString text, Chris@290: QString more, Chris@290: QWidget *parent) : Chris@290: QDialog(parent) Chris@275: { Chris@290: setWindowTitle(title); Chris@290: Chris@290: QGridLayout *layout = new QGridLayout; Chris@290: layout->setSpacing(10); Chris@290: setLayout(layout); Chris@290: Chris@290: m_iconLabel = new QLabel; Chris@291: layout->addWidget(m_iconLabel, 0, 0, 2, 1, Qt::AlignTop); Chris@290: Chris@290: QLabel *headLabel = new QLabel(QString("

%1

").arg(head)); Chris@290: layout->addWidget(headLabel, 0, 1); Chris@290: Chris@290: QLabel *textLabel = new QLabel(text); Chris@290: textLabel->setTextFormat(Qt::RichText); Chris@291: textLabel->setWordWrap(true); Chris@291: layout->addWidget(textLabel, 1, 1, Qt::AlignTop); Chris@290: Chris@290: QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok); Chris@290: connect(bb, SIGNAL(accepted()), this, SLOT(accept())); Chris@290: layout->addWidget(bb, 2, 0, 1, 2); Chris@290: Chris@290: m_moreButton = bb->addButton(tr("More Details..."), Chris@290: QDialogButtonBox::ActionRole); Chris@298: m_moreButton->setAutoDefault(false); Chris@291: m_moreButton->setDefault(false); Chris@290: Chris@290: connect(m_moreButton, SIGNAL(clicked()), this, SLOT(moreClicked())); Chris@290: Chris@291: bb->button(QDialogButtonBox::Ok)->setDefault(true); Chris@291: Chris@290: m_moreText = new QTextEdit(); Chris@290: m_moreText->setAcceptRichText(false); Chris@290: m_moreText->document()->setPlainText(more); Chris@290: m_moreText->setMinimumWidth(360); Chris@290: m_moreText->setReadOnly(true); Chris@290: m_moreText->setLineWrapMode(QTextEdit::NoWrap); Chris@290: Chris@290: QFont font("Monospace"); Chris@290: font.setStyleHint(QFont::TypeWriter); Chris@290: m_moreText->setFont(font); Chris@290: Chris@290: layout->addWidget(m_moreText, 3, 0, 1, 2); Chris@290: Chris@290: m_moreText->hide(); Chris@291: if (more == "") m_moreButton->hide(); Chris@290: Chris@291: layout->setRowStretch(1, 20); Chris@290: layout->setColumnStretch(1, 20); Chris@290: setMinimumWidth(400); Chris@290: } Chris@290: Chris@290: MoreInformationDialog::~MoreInformationDialog() Chris@290: { Chris@275: } Chris@275: Chris@275: void Chris@290: MoreInformationDialog::moreClicked() Chris@275: { Chris@290: if (m_moreText->isVisible()) { Chris@290: m_moreText->hide(); Chris@290: m_moreButton->setText(tr("Show Details...")); Chris@290: } else { Chris@290: m_moreText->show(); Chris@290: m_moreButton->setText(tr("Hide Details...")); Chris@290: } Chris@290: adjustSize(); Chris@290: } Chris@290: Chris@290: void Chris@290: MoreInformationDialog::setIcon(QIcon icon) Chris@290: { Chris@290: QStyle *style = qApp->style(); Chris@290: int iconSize = style->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, this); Chris@290: m_iconLabel->setPixmap(icon.pixmap(iconSize, iconSize)); Chris@275: } Chris@275: Chris@275: void Chris@290: MoreInformationDialog::critical(QWidget *parent, QString title, QString head, Chris@290: QString text, QString more) Chris@275: { Chris@290: MoreInformationDialog d(title, head, text, more, parent); Chris@290: QStyle *style = qApp->style(); Chris@290: d.setIcon(style->standardIcon(QStyle::SP_MessageBoxCritical, 0, &d)); Chris@290: d.exec(); Chris@275: } Chris@275: Chris@290: void Chris@290: MoreInformationDialog::information(QWidget *parent, QString title, QString head, Chris@290: QString text, QString more) Chris@290: { Chris@290: MoreInformationDialog d(title, head, text, more, parent); Chris@290: QStyle *style = qApp->style(); Chris@290: d.setIcon(style->standardIcon(QStyle::SP_MessageBoxInformation, 0, &d)); Chris@290: d.exec(); Chris@290: } Chris@290: Chris@290: void Chris@290: MoreInformationDialog::warning(QWidget *parent, QString title, QString head, Chris@290: QString text, QString more) Chris@290: { Chris@290: MoreInformationDialog d(title, head, text, more, parent); Chris@290: QStyle *style = qApp->style(); Chris@290: d.setIcon(style->standardIcon(QStyle::SP_MessageBoxWarning, 0, &d)); Chris@290: d.exec(); Chris@290: } Chris@290: