kaddressbook Library API Documentation

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., 675 Mass Ave, Cambridge, MA 02139, USA.           
00018                                                                         
00019     As a special exception, permission is given to link this program    
00020     with any edition of Qt, and distribute the resulting executable,    
00021     without including the source code for Qt in the source distribution.
00022 */                                                                      
00023 
00024 #include <qlayout.h>
00025 #include <qbuttongroup.h>
00026 #include <qlineedit.h>
00027 #include <qradiobutton.h>
00028 #include <qlabel.h>
00029 
00030 #include <klocale.h>
00031 
00032 #include "addviewdialog.h"
00033 #include "viewwrapper.h"
00034 
00035 AddViewDialog::AddViewDialog(QDict<ViewWrapper> *viewWrapperDict, 
00036                              QWidget *parent, const char *name)
00037     : KDialogBase(KDialogBase::Plain, i18n("Add View"),
00038                   KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
00039                   parent, name/*, true, true*/),
00040                   mViewWrapperDict(viewWrapperDict)
00041 {
00042     mTypeId = 0;
00043     
00044     QWidget *page = plainPage();
00045     
00046     QGridLayout *layout = new QGridLayout(page, 2, 2);
00047     layout->setSpacing( spacingHint() );
00048     layout->setRowStretch(1, 1);
00049     layout->setColStretch(1, 1);
00050     
00051     QLabel *label = new QLabel(i18n("View name:"), page);
00052     layout->addWidget(label, 0, 0);
00053     
00054     mViewNameEdit = new QLineEdit(page, "mViewNameEdit");
00055     connect(mViewNameEdit, SIGNAL(textChanged(const QString &)),
00056             this, SLOT(textChanged(const QString &)));
00057     layout->addWidget(mViewNameEdit, 0, 1);
00058     
00059     mTypeGroup = new QButtonGroup(2, Qt::Horizontal, 
00060                                         i18n("View Type"), page);
00061     connect(mTypeGroup, SIGNAL(clicked(int)), this, SLOT(clicked(int)));
00062     layout->addMultiCellWidget(mTypeGroup, 1, 1, 0, 1);
00063     
00064     // Now create the radio buttons. This needs some layout work.
00065     QRadioButton *rb;
00066     QDictIterator<ViewWrapper> iter(*mViewWrapperDict);
00067     ViewWrapper *wrapper;
00068     for (iter.toFirst(); iter.current(); ++iter)
00069     {
00070       wrapper = *iter;
00071       
00072       rb = new QRadioButton(wrapper->type(), mTypeGroup);
00073       label = new QLabel(wrapper->description(), mTypeGroup);
00074       label->setAlignment(Qt::AlignLeft | Qt::AlignTop | Qt::WordBreak);
00075     }
00076     
00077     mTypeGroup->setButton(0);
00078     mViewNameEdit->setFocus();
00079     enableButton(KDialogBase::Ok, false);
00080 }
00081 
00082 AddViewDialog::~AddViewDialog()
00083 {
00084 }
00085     
00086 QString AddViewDialog::viewName()
00087 {
00088     return mViewNameEdit->text();
00089 }
00090     
00091 QString AddViewDialog::viewType()
00092 {
00093     return mTypeGroup->find(mTypeId)->text();
00094 }
00095 
00096 void AddViewDialog::clicked(int id)
00097 {
00098     mTypeId = id;
00099 }
00100 
00101 void AddViewDialog::textChanged(const QString &text)
00102 {
00103     enableButton(KDialogBase::Ok, !text.isEmpty());
00104 }
00105 
00106 #include "addviewdialog.moc"
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sat Oct 18 02:47:09 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001