summaryrefslogtreecommitdiffstats
path: root/bibletime/frontend/cinputdialog.cpp
blob: 9274acf14c043abd5a0c173474d6fae4821d3711 (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
96
/*********
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2006 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/



//own includes
#include "cinputdialog.h"

//TQt includes
#include <tqwidget.h>
#include <tqlabel.h>
#include <tqtextedit.h>
#include <tqpushbutton.h>
#include <tqlayout.h>

//KDE includes
#include <tdelocale.h>
#include <kseparator.h>

CInputDialog::CInputDialog(const TQString& caption, const TQString& description, const TQString& text, TQWidget *parent, const char *name, const bool modal ) : KDialog(parent,name,modal) {
	setPlainCaption(caption);

	TQVBoxLayout* topLayout = new TQVBoxLayout(this, 5,5);

	TQLabel* l = new TQLabel(description, this);
	topLayout->addWidget(l);

	topLayout->addSpacing(10);

	m_editWidget = new TQTextEdit(this, "edit widget");
	m_editWidget->setWordWrap( TQTextEdit::WidgetWidth );
	m_editWidget->setText(text);
	if (!text.isEmpty())
		m_editWidget->selectAll();

	topLayout->addWidget(m_editWidget);

	KSeparator* separator = new KSeparator(KSeparator::HLine, this);
	topLayout->addWidget(separator);

	TQHBoxLayout* buttonLayout = new TQHBoxLayout(topLayout);

	buttonLayout->addStretch(2);

	TQPushButton* cancel = new TQPushButton(this);
	cancel->setText(i18n("&Cancel"));
	connect(cancel, TQT_SIGNAL(clicked()), TQT_SLOT(reject()));
	buttonLayout->addWidget(cancel,1);

	buttonLayout->addSpacing(15);

	TQPushButton* clear = new TQPushButton(this);
	clear->setText(i18n("C&lear"));
	connect(clear, TQT_SIGNAL(clicked()),m_editWidget, TQT_SLOT(clear()));
	buttonLayout->addWidget(clear,1);

	buttonLayout->addSpacing(15);

	TQPushButton* ok = new TQPushButton(this);
	ok->setText(i18n("&Ok"));
	connect(ok, TQT_SIGNAL(clicked()), TQT_SLOT(accept()));
	buttonLayout->addWidget(ok,1);

	m_editWidget->setFocus();
}

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

/** A static function to get some using CInputDialog. */
const TQString CInputDialog::getText( const TQString& caption, const TQString& description, const TQString& text, bool* ok, TQWidget* parent, bool modal) {
	CInputDialog* dlg = new CInputDialog(caption, description, text, parent, "", modal);
	TQString ret = TQString();

	const bool isOk = (dlg->exec() == CInputDialog::Accepted);
	if (isOk) {
		ret = dlg->text();
	}

	if (ok) { //change the ok param to return the value
		*ok = isOk;
	}

	delete dlg;
	return ret;
}

#include "cinputdialog.moc"