summaryrefslogtreecommitdiffstats
path: root/kexi/main/kexinamedialog.cpp
blob: c9b78f364dcfbb5396af69eaae529f1f2996ada4 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* This file is part of the KDE project
   Copyright (C) 2004 Jaroslaw Staniek <js@iidea.pl>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#include "kexinamedialog.h"

KexiNameDialog::KexiNameDialog(const TQString& message, 
	TQWidget * tqparent, const char * name)
 : KDialogBase(KDialogBase::Plain, TQString(),
	KDialogBase::Ok|KDialogBase::Cancel|KDialogBase::Help,
	KDialogBase::Ok,
	tqparent, name)
{
//	TQHBox ( TQWidget * tqparent = 0, const char * name = 0, WFlags f = 0 )
	m_widget= new KexiNameWidget(message, plainPage(), "KexiNameWidget");
	init();
}

KexiNameDialog::KexiNameDialog(const TQString& message, 
	const TQString& nameLabel, const TQString& nameText, 
	const TQString& captionLabel, const TQString& captionText, 
	TQWidget * tqparent, const char * name)
 : KDialogBase(KDialogBase::Plain, TQString(),
	KDialogBase::Ok|KDialogBase::Cancel,
	KDialogBase::Ok,
	tqparent, name)
{
	m_widget= new KexiNameWidget(message, nameLabel, nameText,
		captionLabel, captionText, plainPage(), "KexiNameWidget");
	init();
}

KexiNameDialog::~KexiNameDialog()
{
}

void KexiNameDialog::init()
{
	TQGridLayout *lyr = new TQGridLayout(plainPage(), 2, 3);
	m_icon = new TQLabel( plainPage(), "icon" );
	m_icon->tqsetAlignment( int( AlignTop | AlignLeft ) );
	m_icon->tqsetSizePolicy(TQSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Preferred,1,0));
	m_icon->setFixedWidth(50);
	lyr->addWidget(m_icon,0,0);

	m_widget->tqsetSizePolicy(TQSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Preferred,1,0));
	lyr->addWidget(m_widget,0,1);
	lyr->addItem(new TQSpacerItem( 25, 10, TQSizePolicy::Expanding, TQSizePolicy::Minimum ), 0, 2);
	lyr->addItem(new TQSpacerItem( 5, 10, TQSizePolicy::Minimum, TQSizePolicy::Expanding ), 1, 1);
//	m_widget->captionLineEdit()->selectAll();
//	m_widget->captionLineEdit()->setFocus();
	connect(m_widget,TQT_SIGNAL(messageChanged()),this, TQT_SLOT(updateSize()));
	updateSize();
	enableButtonOK( true );
	slotTextChanged();
	connect(m_widget, TQT_SIGNAL(textChanged()), this, TQT_SLOT(slotTextChanged()));
}

void KexiNameDialog::updateSize()
{
//	resize( TQSize(400, 140 + (m_widget->lbl_message->isVisible()?m_widget->lbl_message->height():0) )
	resize( TQSize(400, 140 + (!m_widget->lbl_message->text().isEmpty()?m_widget->lbl_message->height():0) )
		.expandedTo(tqminimumSizeHint()) );
//	updateGeometry();
}

void KexiNameDialog::slotTextChanged()
{
	bool enable = true;
	if (m_widget->isNameRequired() && m_widget->nameText().isEmpty()
		|| m_widget->isCaptionRequired() && m_widget->captionText().isEmpty())
		enable = false;
	enableButtonOK( enable );
}

void KexiNameDialog::accept()
{
	if (!m_widget->checkValidity())
		return;
	KDialogBase::accept();
}

void KexiNameDialog::setDialogIcon(const TQPixmap& icon)
{
	m_icon->setPixmap(icon);
}

void KexiNameDialog::show()
{
	m_widget->captionLineEdit()->selectAll();
	m_widget->captionLineEdit()->setFocus();
	KDialogBase::show();
}

#include "kexinamedialog.moc"