summaryrefslogtreecommitdiff
path: root/src/frontend/cinputdialog.cpp
blob: 59b178da7ba4925c95cb3f27f632ef3d95229f04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*********
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2008 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/



//own includes
#include "cinputdialog.h"
#include "util/dialogutil.h"

//Qt includes
#include <QDialog>
#include <QWidget>
#include <QLabel>
#include <QTextEdit>
#include <QPushButton>
#include <QDialogButtonBox>
#include <QVBoxLayout>
#include <QHBoxLayout>

#include <QDebug>


CInputDialog::CInputDialog
	(const QString& caption, const QString& description, const QString& text, QWidget *parent, Qt::WindowFlags wflags )
	: QDialog(parent, wflags)
{
	QVBoxLayout *vboxLayout;
	QLabel *label;
	QHBoxLayout *hboxLayout;
	QPushButton *clearButton;
	QSpacerItem *spacerItem;
	QDialogButtonBox *buttonBox;
	
	setWindowTitle(caption);

	resize(400, 300);
	vboxLayout = new QVBoxLayout(this);
	label = new QLabel(description, this);
	vboxLayout->addWidget(label);

	m_textEdit = new QTextEdit(this);
	vboxLayout->addWidget(m_textEdit);
	m_textEdit->setWordWrapMode( QTextOption::WordWrap );
	m_textEdit->setText(text);
	if (!text.isEmpty())
		m_textEdit->selectAll();

	hboxLayout = new QHBoxLayout();
	clearButton = new QPushButton(this);
	clearButton->setText(tr("Clear"));
	hboxLayout->addWidget(clearButton);
	spacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
	hboxLayout->addItem(spacerItem);
	buttonBox = new QDialogButtonBox(this);
	buttonBox->setOrientation(Qt::Horizontal);
	buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok);
	util::prepareDialogBox(buttonBox);
	hboxLayout->addWidget(buttonBox);

	vboxLayout->addLayout(hboxLayout);

	QObject::connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
	QObject::connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
	QObject::connect(clearButton, SIGNAL(clicked()), m_textEdit, SLOT(clear()));

	m_textEdit->setFocus();
}

/** Returns the text entered at the moment. */
const QString CInputDialog::text() {
	return m_textEdit->toPlainText();
}

/** A static function to get some using CInputDialog. */
const QString CInputDialog::getText
	( const QString& caption, const QString& description, const QString& text, bool* ok, QWidget* parent, Qt::WindowFlags wflags)
{
	CInputDialog* dlg = new CInputDialog(caption, description, text, parent, wflags);

	QString ret = QString::null;
	*ok = (dlg->exec() == QDialog::Accepted)?true:false;
	if (*ok) {
		//qDebug() << "dialog was accepted, return text: " << dlg->text();
		ret = dlg->text();
	}

	delete dlg;
	return ret;
}