# HG changeset patch # User Chris Cannam # Date 1298298182 0 # Node ID c0c254f67346b89b3768b5c74675e3406e7c61ee # Parent 1244dc3107cb041ad47c45d280f4b26c107f03bf Make our own message box with a more useful "more information" section than the Qt one diff -r 1244dc3107cb -r c0c254f67346 mainwindow.cpp --- a/mainwindow.cpp Mon Jan 31 17:23:10 2011 +0000 +++ b/mainwindow.cpp Mon Feb 21 14:23:02 2011 +0000 @@ -1606,7 +1606,7 @@ runner->hide(); MoreInformationDialog::information(this, tr("Pull complete"), - format1(report), output); + report, "", output); /*!!! report = format3(report, tr("The pull command output was:"), output); diff -r 1244dc3107cb -r c0c254f67346 moreinformationdialog.cpp --- a/moreinformationdialog.cpp Mon Jan 31 17:23:10 2011 +0000 +++ b/moreinformationdialog.cpp Mon Feb 21 14:23:02 2011 +0000 @@ -18,47 +18,117 @@ #include "moreinformationdialog.h" #include +#include +#include +#include +#include +#include +#include +#include -void -MoreInformationDialog::critical(QWidget *parent, QString title, - QString text, QString more) +MoreInformationDialog::MoreInformationDialog(QString title, + QString head, + QString text, + QString more, + QWidget *parent) : + QDialog(parent) { - QMessageBox mb(QMessageBox::Critical, - title, - text, - QMessageBox::Ok, - parent, - Qt::Dialog); - mb.setDetailedText(more); - mb.exec(); + setWindowTitle(title); + + QGridLayout *layout = new QGridLayout; + layout->setSpacing(10); + setLayout(layout); + + m_iconLabel = new QLabel; + layout->addWidget(m_iconLabel, 0, 0); + + QLabel *headLabel = new QLabel(QString("

%1

").arg(head)); + layout->addWidget(headLabel, 0, 1); + + QLabel *textLabel = new QLabel(text); + textLabel->setTextFormat(Qt::RichText); + layout->addWidget(textLabel, 1, 1); + + QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok); + connect(bb, SIGNAL(accepted()), this, SLOT(accept())); + layout->addWidget(bb, 2, 0, 1, 2); + + m_moreButton = bb->addButton(tr("More Details..."), + QDialogButtonBox::ActionRole); + + connect(m_moreButton, SIGNAL(clicked()), this, SLOT(moreClicked())); + + m_moreText = new QTextEdit(); + m_moreText->setAcceptRichText(false); + m_moreText->document()->setPlainText(more); + m_moreText->setMinimumWidth(360); + m_moreText->setReadOnly(true); + m_moreText->setLineWrapMode(QTextEdit::NoWrap); + + QFont font("Monospace"); + font.setStyleHint(QFont::TypeWriter); + m_moreText->setFont(font); + + layout->addWidget(m_moreText, 3, 0, 1, 2); + + m_moreText->hide(); + + layout->setColumnStretch(1, 20); + setMinimumWidth(400); +} + +MoreInformationDialog::~MoreInformationDialog() +{ } void -MoreInformationDialog::information(QWidget *parent, QString title, - QString text, QString more) +MoreInformationDialog::moreClicked() { - QMessageBox mb(QMessageBox::Information, - title, - text, - QMessageBox::Ok, - parent, - Qt::Dialog); - mb.setDefaultButton(QMessageBox::Ok); - mb.setDetailedText(more); - mb.exec(); + if (m_moreText->isVisible()) { + m_moreText->hide(); + m_moreButton->setText(tr("Show Details...")); + } else { + m_moreText->show(); + m_moreButton->setText(tr("Hide Details...")); + } + adjustSize(); +} + +void +MoreInformationDialog::setIcon(QIcon icon) +{ + QStyle *style = qApp->style(); + int iconSize = style->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, this); + m_iconLabel->setPixmap(icon.pixmap(iconSize, iconSize)); } void -MoreInformationDialog::warning(QWidget *parent, QString title, - QString text, QString more) +MoreInformationDialog::critical(QWidget *parent, QString title, QString head, + QString text, QString more) { - QMessageBox mb(QMessageBox::Warning, - title, - text, - QMessageBox::Ok, - parent, - Qt::Dialog); - mb.setDetailedText(more); - mb.exec(); + MoreInformationDialog d(title, head, text, more, parent); + QStyle *style = qApp->style(); + d.setIcon(style->standardIcon(QStyle::SP_MessageBoxCritical, 0, &d)); + d.exec(); } +void +MoreInformationDialog::information(QWidget *parent, QString title, QString head, + QString text, QString more) +{ + MoreInformationDialog d(title, head, text, more, parent); + QStyle *style = qApp->style(); + d.setIcon(style->standardIcon(QStyle::SP_MessageBoxInformation, 0, &d)); + d.exec(); +} + +void +MoreInformationDialog::warning(QWidget *parent, QString title, QString head, + QString text, QString more) +{ + MoreInformationDialog d(title, head, text, more, parent); + QStyle *style = qApp->style(); + d.setIcon(style->standardIcon(QStyle::SP_MessageBoxWarning, 0, &d)); + d.exec(); +} + diff -r 1244dc3107cb -r c0c254f67346 moreinformationdialog.h --- a/moreinformationdialog.h Mon Jan 31 17:23:10 2011 +0000 +++ b/moreinformationdialog.h Mon Feb 21 14:23:02 2011 +0000 @@ -19,20 +19,45 @@ #define MORE_INFORMATION_DIALOG_H #include +#include -class QWidget; +class QLabel; +class QTextEdit; +class QPushButton; /** * Provide methods like the QMessageBox static methods, to call up - * dialogs with "More information" buttons in them + * dialogs with "More information" buttons in them. QMessageBox does + * have an optional additional-details field, but it doesn't behave + * quite as we'd like with regard to layout */ -class MoreInformationDialog +class MoreInformationDialog : public QDialog { + Q_OBJECT + public: - static void critical(QWidget *parent, QString title, QString text, QString more); - static void information(QWidget *parent, QString title, QString text, QString more); - static void warning(QWidget *parent, QString title, QString text, QString more); + MoreInformationDialog(QString title, + QString head, + QString text, + QString more, + QWidget *parent = 0); + + ~MoreInformationDialog(); + + void setIcon(QIcon); + + static void critical(QWidget *parent, QString title, QString head, QString text, QString more); + static void information(QWidget *parent, QString title, QString head, QString text, QString more); + static void warning(QWidget *parent, QString title, QString head, QString text, QString more); + +private slots: + void moreClicked(); + +private: + QLabel *m_iconLabel; + QPushButton *m_moreButton; + QTextEdit *m_moreText; }; #endif