kexi

kexinamedialog.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004 Jaroslaw Staniek <js@iidea.pl>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "kexinamedialog.h"
21
22KexiNameDialog::KexiNameDialog(const TQString& message,
23 TQWidget * parent, const char * name)
24 : KDialogBase(KDialogBase::Plain, TQString(),
25 KDialogBase::Ok|KDialogBase::Cancel|KDialogBase::Help,
26 KDialogBase::Ok,
27 parent, name)
28{
29// TQHBox ( TQWidget * parent = 0, const char * name = 0, WFlags f = 0 )
30 m_widget= new KexiNameWidget(message, plainPage(), "KexiNameWidget");
31 init();
32}
33
34KexiNameDialog::KexiNameDialog(const TQString& message,
35 const TQString& nameLabel, const TQString& nameText,
36 const TQString& captionLabel, const TQString& captionText,
37 TQWidget * parent, const char * name)
38 : KDialogBase(KDialogBase::Plain, TQString(),
39 KDialogBase::Ok|KDialogBase::Cancel,
40 KDialogBase::Ok,
41 parent, name)
42{
43 m_widget= new KexiNameWidget(message, nameLabel, nameText,
44 captionLabel, captionText, plainPage(), "KexiNameWidget");
45 init();
46}
47
48KexiNameDialog::~KexiNameDialog()
49{
50}
51
52void KexiNameDialog::init()
53{
54 TQGridLayout *lyr = new TQGridLayout(plainPage(), 2, 3);
55 m_icon = new TQLabel( plainPage(), "icon" );
56 m_icon->setAlignment( int( AlignTop | AlignLeft ) );
57 m_icon->setSizePolicy(TQSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Preferred,1,0));
58 m_icon->setFixedWidth(50);
59 lyr->addWidget(m_icon,0,0);
60
61 m_widget->setSizePolicy(TQSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Preferred,1,0));
62 lyr->addWidget(m_widget,0,1);
63 lyr->addItem(new TQSpacerItem( 25, 10, TQSizePolicy::Expanding, TQSizePolicy::Minimum ), 0, 2);
64 lyr->addItem(new TQSpacerItem( 5, 10, TQSizePolicy::Minimum, TQSizePolicy::Expanding ), 1, 1);
65// m_widget->captionLineEdit()->selectAll();
66// m_widget->captionLineEdit()->setFocus();
67 connect(m_widget,TQ_SIGNAL(messageChanged()),this, TQ_SLOT(updateSize()));
68 updateSize();
69 enableButtonOK( true );
70 slotTextChanged();
71 connect(m_widget, TQ_SIGNAL(textChanged()), this, TQ_SLOT(slotTextChanged()));
72}
73
74void KexiNameDialog::updateSize()
75{
76// resize( TQSize(400, 140 + (m_widget->lbl_message->isVisible()?m_widget->lbl_message->height():0) )
77 resize( TQSize(400, 140 + (!m_widget->lbl_message->text().isEmpty()?m_widget->lbl_message->height():0) )
78 .expandedTo(minimumSizeHint()) );
79// updateGeometry();
80}
81
82void KexiNameDialog::slotTextChanged()
83{
84 bool enable = true;
85 if (m_widget->isNameRequired() && m_widget->nameText().isEmpty()
86 || m_widget->isCaptionRequired() && m_widget->captionText().isEmpty())
87 enable = false;
88 enableButtonOK( enable );
89}
90
91void KexiNameDialog::accept()
92{
93 if (!m_widget->checkValidity())
94 return;
95 KDialogBase::accept();
96}
97
98void KexiNameDialog::setDialogIcon(const TQPixmap& icon)
99{
100 m_icon->setPixmap(icon);
101}
102
103void KexiNameDialog::show()
104{
105 m_widget->captionLineEdit()->selectAll();
106 m_widget->captionLineEdit()->setFocus();
107 KDialogBase::show();
108}
109
110#include "kexinamedialog.moc"
111