kexi

kexinamedialog.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "kexinamedialog.h"
00021 
00022 KexiNameDialog::KexiNameDialog(const QString& message, 
00023     QWidget * parent, const char * name)
00024  : KDialogBase(KDialogBase::Plain, QString::null,
00025     KDialogBase::Ok|KDialogBase::Cancel|KDialogBase::Help,
00026     KDialogBase::Ok,
00027     parent, name)
00028 {
00029 //  QHBox ( QWidget * parent = 0, const char * name = 0, WFlags f = 0 )
00030     m_widget= new KexiNameWidget(message, plainPage(), "KexiNameWidget");
00031     init();
00032 }
00033 
00034 KexiNameDialog::KexiNameDialog(const QString& message, 
00035     const QString& nameLabel, const QString& nameText, 
00036     const QString& captionLabel, const QString& captionText, 
00037     QWidget * parent, const char * name)
00038  : KDialogBase(KDialogBase::Plain, QString::null,
00039     KDialogBase::Ok|KDialogBase::Cancel,
00040     KDialogBase::Ok,
00041     parent, name)
00042 {
00043     m_widget= new KexiNameWidget(message, nameLabel, nameText,
00044         captionLabel, captionText, plainPage(), "KexiNameWidget");
00045     init();
00046 }
00047 
00048 KexiNameDialog::~KexiNameDialog()
00049 {
00050 }
00051 
00052 void KexiNameDialog::init()
00053 {
00054     QGridLayout *lyr = new QGridLayout(plainPage(), 2, 3);
00055     m_icon = new QLabel( plainPage(), "icon" );
00056     m_icon->setAlignment( int( AlignTop | AlignLeft ) );
00057     m_icon->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred,1,0));
00058     m_icon->setFixedWidth(50);
00059     lyr->addWidget(m_icon,0,0);
00060 
00061     m_widget->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred,1,0));
00062     lyr->addWidget(m_widget,0,1);
00063     lyr->addItem(new QSpacerItem( 25, 10, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 2);
00064     lyr->addItem(new QSpacerItem( 5, 10, QSizePolicy::Minimum, QSizePolicy::Expanding ), 1, 1);
00065 //  m_widget->captionLineEdit()->selectAll();
00066 //  m_widget->captionLineEdit()->setFocus();
00067     connect(m_widget,SIGNAL(messageChanged()),this, SLOT(updateSize()));
00068     updateSize();
00069     enableButtonOK( true );
00070     slotTextChanged();
00071     connect(m_widget, SIGNAL(textChanged()), this, SLOT(slotTextChanged()));
00072 }
00073 
00074 void KexiNameDialog::updateSize()
00075 {
00076 //  resize( QSize(400, 140 + (m_widget->lbl_message->isVisible()?m_widget->lbl_message->height():0) )
00077     resize( QSize(400, 140 + (!m_widget->lbl_message->text().isEmpty()?m_widget->lbl_message->height():0) )
00078         .expandedTo(minimumSizeHint()) );
00079 //  updateGeometry();
00080 }
00081 
00082 void KexiNameDialog::slotTextChanged()
00083 {
00084     bool enable = true;
00085     if (m_widget->isNameRequired() && m_widget->nameText().isEmpty()
00086         || m_widget->isCaptionRequired() && m_widget->captionText().isEmpty())
00087         enable = false;
00088     enableButtonOK( enable );
00089 }
00090 
00091 void KexiNameDialog::accept()
00092 {
00093     if (!m_widget->checkValidity())
00094         return;
00095     KDialogBase::accept();
00096 }
00097 
00098 void KexiNameDialog::setDialogIcon(const QPixmap& icon)
00099 {
00100     m_icon->setPixmap(icon);
00101 }
00102 
00103 void KexiNameDialog::show()
00104 {
00105     m_widget->captionLineEdit()->selectAll();
00106     m_widget->captionLineEdit()->setFocus();
00107     KDialogBase::show();
00108 }
00109 
00110 #include "kexinamedialog.moc"
00111 
KDE Home | KDE Accessibility Home | Description of Access Keys