You need a space here
[kdepim.git] / kaddressbook / addviewdialog.cpp
blob7ccd4d40a54b01e7106b4c775acf0e4738876c8f
1 /*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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.
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.
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.
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
24 #include <QtGui/QButtonGroup>
25 #include <QtGui/QGridLayout>
26 #include <QtGui/QGroupBox>
27 #include <QtGui/QLabel>
28 #include <QtGui/QLineEdit>
29 #include <QtGui/QRadioButton>
31 #include <KLocale>
33 #include "kaddressbookview.h"
35 #include "addviewdialog.h"
37 AddViewDialog::AddViewDialog( QHash<QString, ViewFactory*> *viewFactoryDict,
38 QWidget *parent )
39 : KDialog( parent),
40 mViewFactoryDict( viewFactoryDict )
42 setCaption( i18n( "Add View" ) );
43 setButtons( KDialog::Ok | KDialog::Cancel );
44 setDefaultButton( KDialog::Ok );
46 mTypeId = 0;
48 QWidget *page = new QWidget(this);
49 setMainWidget( page );
51 QGridLayout *layout = new QGridLayout( page );
52 layout->setMargin( 0 );
53 layout->setSpacing( spacingHint() );
54 layout->setRowStretch( 1, 1 );
55 layout->setColumnStretch( 1, 1 );
57 QLabel *label = new QLabel( i18n( "View name:" ), page );
58 layout->addWidget( label, 0, 0 );
60 mViewNameEdit = new QLineEdit( page );
61 connect( mViewNameEdit, SIGNAL( textChanged( const QString& ) ),
62 SLOT( textChanged( const QString& ) ) );
63 layout->addWidget( mViewNameEdit, 0, 1 );
65 QGroupBox *group = new QGroupBox( i18n( "View Type" ), page );
66 mTypeGroup = new QButtonGroup;
67 mTypeGroup->setExclusive( true );
68 connect( mTypeGroup, SIGNAL( buttonClicked( int ) ),
69 this, SLOT( clicked( int ) ) );
70 layout->addWidget( group, 1, 0, 1, 2 );
71 QGridLayout *groupLayout = new QGridLayout();
72 groupLayout->setMargin( KDialog::marginHint() );
73 groupLayout->setSpacing( KDialog::spacingHint() );
74 group->setLayout( groupLayout );
76 int row = 0;
77 QHashIterator<QString, ViewFactory*> iter( *mViewFactoryDict );
78 while ( iter.hasNext() ) {
79 iter.next();
80 QRadioButton *button = new QRadioButton( i18n( iter.value()->type().toUtf8() ),
81 group );
82 button->setObjectName( iter.value()->type().toLatin1() );
83 mTypeGroup->addButton( button, row );
84 label = new QLabel( iter.value()->description(), group );
85 label->setWordWrap( true );
87 groupLayout->addWidget( button, row, 0, Qt::AlignTop );
88 groupLayout->addWidget( label, row, 1, Qt::AlignTop );
90 row++;
93 mTypeGroup->button( 0 )->setChecked( true );
94 mViewNameEdit->setFocus();
95 enableButton( KDialog::Ok, false );
98 AddViewDialog::~AddViewDialog()
102 QString AddViewDialog::viewName()const
104 return mViewNameEdit->text();
107 QString AddViewDialog::viewType()const
109 // we missuse the name property for storing the type
110 return mTypeGroup->button( mTypeId )->objectName();
113 void AddViewDialog::clicked( int id )
115 mTypeId = id;
118 void AddViewDialog::textChanged( const QString &text )
120 enableButton( KDialog::Ok, !text.isEmpty() );
123 #include "addviewdialog.moc"