Need to store config when changing units, if not very bad things happen
[kdepim.git] / kaddressbook / addviewdialog.cpp
blob68046359dee0009e432724166ef5ccbcc80a8be7
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 <qbuttongroup.h>
25 #include <qlabel.h>
26 #include <qlayout.h>
27 #include <qlineedit.h>
28 #include <qradiobutton.h>
30 #include <klocale.h>
32 #include "kaddressbookview.h"
34 #include "addviewdialog.h"
36 AddViewDialog::AddViewDialog( QDict<ViewFactory> *viewFactoryDict,
37 QWidget *parent, const char *name )
38 : KDialogBase( KDialogBase::Plain, i18n( "Add View" ),
39 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
40 parent, name ),
41 mViewFactoryDict( viewFactoryDict )
43 mTypeId = 0;
45 QWidget *page = plainPage();
47 QGridLayout *layout = new QGridLayout( page, 2, 2 );
48 layout->setSpacing( spacingHint() );
49 layout->setRowStretch( 1, 1 );
50 layout->setColStretch( 1, 1 );
52 QLabel *label = new QLabel( i18n( "View name:" ), page );
53 layout->addWidget( label, 0, 0 );
55 mViewNameEdit = new QLineEdit( page );
56 connect( mViewNameEdit, SIGNAL( textChanged( const QString& ) ),
57 SLOT( textChanged( const QString& ) ) );
58 layout->addWidget( mViewNameEdit, 0, 1 );
60 mTypeGroup = new QButtonGroup( 0, Qt::Horizontal, i18n( "View Type" ), page );
61 connect( mTypeGroup, SIGNAL( clicked( int ) ), this, SLOT( clicked( int ) ) );
62 layout->addMultiCellWidget( mTypeGroup, 1, 1, 0, 1 );
63 QGridLayout *groupLayout = new QGridLayout( mTypeGroup->layout(), 3, 2 );
64 groupLayout->setSpacing( spacingHint() );
66 int row = 0;
67 QDictIterator<ViewFactory> iter( *mViewFactoryDict );
68 for ( iter.toFirst(); iter.current(); ++iter ) {
69 QRadioButton *button = new QRadioButton( i18n((*iter)->type().utf8()),
70 mTypeGroup, (*iter)->type().latin1() );
71 label = new QLabel( (*iter)->description(), mTypeGroup );
72 label->setAlignment( Qt::WordBreak );
74 groupLayout->addWidget( button, row, 0, Qt::AlignTop );
75 groupLayout->addWidget( label, row, 1, Qt::AlignTop );
77 row++;
80 mTypeGroup->setButton( 0 );
81 mViewNameEdit->setFocus();
82 enableButton( KDialogBase::Ok, false );
85 AddViewDialog::~AddViewDialog()
89 QString AddViewDialog::viewName()const
91 return mViewNameEdit->text();
94 QString AddViewDialog::viewType()const
96 // we missuse the name property for storing the type
97 return mTypeGroup->find( mTypeId )->name();
100 void AddViewDialog::clicked( int id )
102 mTypeId = id;
105 void AddViewDialog::textChanged( const QString &text )
107 enableButton( KDialogBase::Ok, !text.isEmpty() );
110 #include "addviewdialog.moc"