kaddressbook

addviewdialog.cpp
1 /*
2  This file is part of KAddressBook.
3  Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 
19  As a special exception, permission is given to link this program
20  with any edition of TQt, and distribute the resulting executable,
21  without including the source code for TQt in the source distribution.
22 */
23 
24 #include <tqbuttongroup.h>
25 #include <tqlabel.h>
26 #include <tqlayout.h>
27 #include <tqlineedit.h>
28 #include <tqradiobutton.h>
29 
30 #include <tdelocale.h>
31 
32 #include "kaddressbookview.h"
33 
34 #include "addviewdialog.h"
35 
36 AddViewDialog::AddViewDialog( TQDict<ViewFactory> *viewFactoryDict,
37  TQWidget *parent, const char *name )
38  : KDialogBase( KDialogBase::Plain, i18n( "Add View" ),
39  KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
40  parent, name ),
41  mViewFactoryDict( viewFactoryDict )
42 {
43  mTypeId = 0;
44 
45  TQWidget *page = plainPage();
46 
47  TQGridLayout *layout = new TQGridLayout( page, 2, 2 );
48  layout->setSpacing( spacingHint() );
49  layout->setRowStretch( 1, 1 );
50  layout->setColStretch( 1, 1 );
51 
52  TQLabel *label = new TQLabel( i18n( "View name:" ), page );
53  layout->addWidget( label, 0, 0 );
54 
55  mViewNameEdit = new TQLineEdit( page );
56  connect( mViewNameEdit, TQ_SIGNAL( textChanged( const TQString& ) ),
57  TQ_SLOT( textChanged( const TQString& ) ) );
58  layout->addWidget( mViewNameEdit, 0, 1 );
59 
60  mTypeGroup = new TQButtonGroup( 0, TQt::Horizontal, i18n( "View Type" ), page );
61  connect( mTypeGroup, TQ_SIGNAL( clicked( int ) ), this, TQ_SLOT( clicked( int ) ) );
62  layout->addMultiCellWidget( mTypeGroup, 1, 1, 0, 1 );
63  TQGridLayout *groupLayout = new TQGridLayout( mTypeGroup->layout(), 3, 2 );
64  groupLayout->setSpacing( spacingHint() );
65 
66  int row = 0;
67  TQDictIterator<ViewFactory> iter( *mViewFactoryDict );
68  for ( iter.toFirst(); iter.current(); ++iter ) {
69  TQRadioButton *button = new TQRadioButton( i18n((*iter)->type().utf8()),
70  mTypeGroup, (*iter)->type().latin1() );
71  label = new TQLabel( (*iter)->description(), mTypeGroup );
72  label->setAlignment( TQt::WordBreak );
73 
74  groupLayout->addWidget( button, row, 0, TQt::AlignTop );
75  groupLayout->addWidget( label, row, 1, TQt::AlignTop );
76 
77  row++;
78  }
79 
80  mTypeGroup->setButton( 0 );
81  mViewNameEdit->setFocus();
82  enableButton( KDialogBase::Ok, false );
83 }
84 
85 AddViewDialog::~AddViewDialog()
86 {
87 }
88 
89 TQString AddViewDialog::viewName()const
90 {
91  return mViewNameEdit->text();
92 }
93 
94 TQString AddViewDialog::viewType()const
95 {
96  // we missuse the name property for storing the type
97  return mTypeGroup->find( mTypeId )->name();
98 }
99 
101 {
102  mTypeId = id;
103 }
104 
105 void AddViewDialog::textChanged( const TQString &text )
106 {
107  enableButton( KDialogBase::Ok, !text.isEmpty() );
108 }
109 
110 #include "addviewdialog.moc"
void textChanged(const TQString &text)
Called when the user changes the text in the name of the view.
void clicked(int id)
Called when the user selects a type radio button.