kaddressbook

addviewdialog.cpp
00001 /*
00002     This file is part of KAddressBook.
00003     Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018 
00019     As a special exception, permission is given to link this program
00020     with any edition of TQt, and distribute the resulting executable,
00021     without including the source code for TQt in the source distribution.
00022 */
00023 
00024 #include <tqbuttongroup.h>
00025 #include <tqlabel.h>
00026 #include <tqlayout.h>
00027 #include <tqlineedit.h>
00028 #include <tqradiobutton.h>
00029 
00030 #include <tdelocale.h>
00031 
00032 #include "kaddressbookview.h"
00033 
00034 #include "addviewdialog.h"
00035 
00036 AddViewDialog::AddViewDialog( TQDict<ViewFactory> *viewFactoryDict,
00037                               TQWidget *parent, const char *name )
00038   : KDialogBase( KDialogBase::Plain, i18n( "Add View" ),
00039                  KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
00040                  parent, name ),
00041    mViewFactoryDict( viewFactoryDict )
00042 {
00043   mTypeId = 0;
00044 
00045   TQWidget *page = plainPage();
00046 
00047   TQGridLayout *layout = new TQGridLayout( page, 2, 2 );
00048   layout->setSpacing( spacingHint() );
00049   layout->setRowStretch( 1, 1 );
00050   layout->setColStretch( 1, 1 );
00051 
00052   TQLabel *label = new TQLabel( i18n( "View name:" ), page );
00053   layout->addWidget( label, 0, 0 );
00054 
00055   mViewNameEdit = new TQLineEdit( page );
00056   connect( mViewNameEdit, TQT_SIGNAL( textChanged( const TQString& ) ),
00057            TQT_SLOT( textChanged( const TQString& ) ) );
00058   layout->addWidget( mViewNameEdit, 0, 1 );
00059 
00060   mTypeGroup = new TQButtonGroup( 0, Qt::Horizontal, i18n( "View Type" ), page );
00061   connect( mTypeGroup, TQT_SIGNAL( clicked( int ) ), this, TQT_SLOT( clicked( int ) ) );
00062   layout->addMultiCellWidget( mTypeGroup, 1, 1, 0, 1 );
00063   TQGridLayout *groupLayout = new TQGridLayout( mTypeGroup->layout(), 3, 2 );
00064   groupLayout->setSpacing( spacingHint() );
00065 
00066   int row = 0;
00067   TQDictIterator<ViewFactory> iter( *mViewFactoryDict );
00068   for ( iter.toFirst(); iter.current(); ++iter ) {
00069     TQRadioButton *button = new TQRadioButton( i18n((*iter)->type().utf8()),
00070                                              mTypeGroup, (*iter)->type().latin1() );
00071     label = new TQLabel( (*iter)->description(), mTypeGroup );
00072     label->setAlignment( TQt::WordBreak );
00073 
00074     groupLayout->addWidget( button, row, 0, TQt::AlignTop );
00075     groupLayout->addWidget( label, row, 1, TQt::AlignTop );
00076 
00077     row++;
00078   }
00079 
00080   mTypeGroup->setButton( 0 );
00081   mViewNameEdit->setFocus();
00082   enableButton( KDialogBase::Ok, false );
00083 }
00084 
00085 AddViewDialog::~AddViewDialog()
00086 {
00087 }
00088 
00089 TQString AddViewDialog::viewName()const
00090 {
00091   return mViewNameEdit->text();
00092 }
00093 
00094 TQString AddViewDialog::viewType()const
00095 {
00096   // we missuse the name property for storing the type
00097   return mTypeGroup->find( mTypeId )->name();
00098 }
00099 
00100 void AddViewDialog::clicked( int id )
00101 {
00102   mTypeId = id;
00103 }
00104 
00105 void AddViewDialog::textChanged( const TQString &text )
00106 {
00107   enableButton( KDialogBase::Ok, !text.isEmpty() );
00108 }
00109 
00110 #include "addviewdialog.moc"