lib Library API Documentation

koimportstyledia.cc

00001 /* This file is part of the KDE project
00002    Copyright (C)  2002 Montel Laurent <lmontel@mandrakesoft.com>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #include <klocale.h>
00021 #include <qvbox.h>
00022 #include <qlayout.h>
00023 #include <qlineedit.h>
00024 #include <qpushbutton.h>
00025 #include <qlistbox.h>
00026 #include "koimportstyledia.h"
00027 
00028 #include <kdebug.h>
00029 #include <qlabel.h>
00030 
00031 KoImportStyleDia::KoImportStyleDia( const QStringList &_list, QWidget *parent, const char *name )
00032     : KDialogBase( parent, name , true, "", Ok|Cancel|User1, Ok, true )
00033 {
00034     setCaption( i18n("Import Style") );
00035     m_list =_list;
00036     QVBox *page = makeVBoxMainWidget();
00037     new QLabel(i18n("Select style to import:"), page);
00038     m_listStyleName = new QListBox( page );
00039     m_listStyleName->setSelectionMode( QListBox::Multi );
00040     enableButtonOK( (m_listStyleName->count()!=0) );
00041     setButtonText( KDialogBase::User1, i18n("Load...") );
00042     connect( this, SIGNAL( user1Clicked() ), this, SLOT(slotLoadFile()));
00043     resize (300, 400);
00044     setFocus();
00045 }
00046 
00047 KoImportStyleDia::~KoImportStyleDia()
00048 {
00049     m_styleList.setAutoDelete(true);
00050     m_styleList.clear();
00051 
00052 }
00053 
00054 void KoImportStyleDia::generateStyleList()
00055 {
00056     for (uint i = 0; i< m_listStyleName->count();i++)
00057     {
00058         if ( !m_listStyleName->isSelected( i ))
00059         {
00060             QString name = m_listStyleName->text(i );
00061             //remove this style from list
00062             QPtrListIterator<KoStyle> styleIt( m_styleList );
00063             for ( ; styleIt.current(); ++styleIt )
00064             {
00065                 if ( styleIt.current()->name() == name )
00066                 {
00067                     updateFollowingStyle( styleIt.current()->translatedName() );
00068                     m_styleList.remove(styleIt.current());
00069                     break;
00070                 }
00071             }
00072         }
00073     }
00074 }
00075 
00076 void KoImportStyleDia::updateFollowingStyle(const QString & _name)
00077 {
00078     QPtrListIterator<KoStyle> styleIt( m_styleList );
00079     for ( ; styleIt.current(); ++styleIt )
00080     {
00081         if ( styleIt.current()->followingStyle()->translatedName() == _name )
00082         {
00083             styleIt.current()->setFollowingStyle(styleIt.current());
00084         }
00085     }
00086 }
00087 
00088 void KoImportStyleDia::slotLoadFile()
00089 {
00090     loadFile();
00091     enableButtonOK( (m_listStyleName->count()!=0) );
00092 }
00093 
00094 void KoImportStyleDia::initList()
00095 {
00096     QStringList lst;
00097     for ( KoStyle * p = m_styleList.first(); p != 0L; p = m_styleList.next() )
00098     {
00099         lst<<p->translatedName();
00100     }
00101     m_listStyleName->insertStringList(lst);
00102 }
00103 
00104 void KoImportStyleDia::slotOk()
00105 {
00106     generateStyleList();
00107     KDialogBase::slotOk();
00108 }
00109 
00110 QString KoImportStyleDia::generateStyleName( const QString & templateName )
00111 {
00112     QString name;
00113     int num = 1;
00114     bool exists;
00115     do {
00116         name = templateName.arg( num );
00117         exists = (m_list.findIndex( name )!=-1);
00118         ++num;
00119     } while ( exists );
00120     return name;
00121 }
00122 
00123 KoStyle *KoImportStyleDia::findStyle( const QString & _name)
00124 {
00125     QPtrListIterator<KoStyle> styleIt( m_styleList );
00126     for ( ; styleIt.current(); ++styleIt )
00127     {
00128         if ( styleIt.current()->name() == _name ) {
00129             return styleIt.current();
00130         }
00131     }
00132     return 0L;
00133 }
00134 
00135 #include "koimportstyledia.moc"
KDE Logo
This file is part of the documentation for lib Library Version 1.3.5.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Mar 20 14:25:25 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003