annotate moreinformationdialog.cpp @ 328:ea62eb083ed4 filelist_right_button_menu

Merge fixes: primarily, handle failed merges better
author Chris Cannam
date Fri, 11 Mar 2011 18:08:22 +0000
parents fd9dc5a457d8
children
rev   line source
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@275 8 Copyright (c) 2011 Chris Cannam
Chris@275 9 Copyright (c) 2011 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@290 38 QGridLayout *layout = new QGridLayout;
Chris@290 39 layout->setSpacing(10);
Chris@290 40 setLayout(layout);
Chris@290 41
Chris@290 42 m_iconLabel = new QLabel;
Chris@291 43 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@290 46 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@291 51 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@290 55 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@290 77 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@291 82 layout->setRowStretch(1, 20);
Chris@290 83 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@290 96 m_moreButton->setText(tr("Show Details..."));
Chris@290 97 } else {
Chris@290 98 m_moreText->show();
Chris@290 99 m_moreButton->setText(tr("Hide Details..."));
Chris@290 100 }
Chris@290 101 adjustSize();
Chris@290 102 }
Chris@290 103
Chris@290 104 void
Chris@290 105 MoreInformationDialog::setIcon(QIcon icon)
Chris@290 106 {
Chris@290 107 QStyle *style = qApp->style();
Chris@290 108 int iconSize = style->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, this);
Chris@290 109 m_iconLabel->setPixmap(icon.pixmap(iconSize, iconSize));
Chris@275 110 }
Chris@275 111
Chris@275 112 void
Chris@290 113 MoreInformationDialog::critical(QWidget *parent, QString title, QString head,
Chris@290 114 QString text, QString more)
Chris@275 115 {
Chris@290 116 MoreInformationDialog d(title, head, text, more, parent);
Chris@290 117 QStyle *style = qApp->style();
Chris@290 118 d.setIcon(style->standardIcon(QStyle::SP_MessageBoxCritical, 0, &d));
Chris@290 119 d.exec();
Chris@275 120 }
Chris@275 121
Chris@290 122 void
Chris@290 123 MoreInformationDialog::information(QWidget *parent, QString title, QString head,
Chris@290 124 QString text, QString more)
Chris@290 125 {
Chris@290 126 MoreInformationDialog d(title, head, text, more, parent);
Chris@290 127 QStyle *style = qApp->style();
Chris@290 128 d.setIcon(style->standardIcon(QStyle::SP_MessageBoxInformation, 0, &d));
Chris@290 129 d.exec();
Chris@290 130 }
Chris@290 131
Chris@290 132 void
Chris@290 133 MoreInformationDialog::warning(QWidget *parent, QString title, QString head,
Chris@290 134 QString text, QString more)
Chris@290 135 {
Chris@290 136 MoreInformationDialog d(title, head, text, more, parent);
Chris@290 137 QStyle *style = qApp->style();
Chris@290 138 d.setIcon(style->standardIcon(QStyle::SP_MessageBoxWarning, 0, &d));
Chris@290 139 d.exec();
Chris@290 140 }
Chris@290 141