#include <qwidget.h>
#include <qlayout.h>
#include <qdialog.h>
#include <qlabel.h>
#include <qtextview.h>
#include <qpushbutton.h>

#include "textviewdialog.h"

TextViewDialog::TextViewDialog(const QString &caption, const QString &msg, const QString &text, QWidget *parent, const char *name)
	:	QDialog(parent, name, true, 0)
{
	setCaption(caption);
	setSizeGripEnabled(false);
	
	QVBoxLayout *mainLayout = new QVBoxLayout(this);
	QVBoxLayout *contentLayout = new QVBoxLayout(this, 8);

	QLabel *messageLabel = new QLabel(msg, this);
	QTextView *errorMessageView = new QTextView(text, QString::null, this);
	QFont font = errorMessageView->font();
	font.setPixelSize(10);
	errorMessageView->setFont(font);
	errorMessageView->setFixedHeight(150);
	
	contentLayout->addWidget(messageLabel);
	contentLayout->addWidget(errorMessageView);
					
	QPushButton *okButton = new QPushButton(tr("OK"), this);
	connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
	
	QPushButton *cancelButton = new QPushButton(tr("Cancel"), this);
	connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));

	QHBoxLayout *buttonsLayout = new QHBoxLayout(this, 8);
	buttonsLayout->setDirection(QBoxLayout::RightToLeft);
	buttonsLayout->addWidget(okButton, 0);
	buttonsLayout->addWidget(cancelButton, 0);
	
	mainLayout->addLayout(contentLayout);
	mainLayout->addLayout(buttonsLayout);
}

bool TextViewDialog::exec()
{
	return QDialog::exec() == QDialog::Accepted;
}