F:/KPlato/koffice/libs/kotext/KoImportStyleDia.cpp

Aller à la documentation de ce fichier.
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., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include <klocale.h>
00021 #include <kvbox.h>
00022 #include <QLayout>
00023 #include <QLineEdit>
00024 #include <QPushButton>
00025 #include <q3listbox.h>
00026 //Added by qt3to4:
00027 #include <Q3ValueList>
00028 #include "KoImportStyleDia.h"
00029 
00030 #include <kdebug.h>
00031 #include <QLabel>
00032 
00033 KoImportStyleDia::KoImportStyleDia( KoStyleCollection* currentCollection, QWidget *parent, const char *name )
00034     : KDialog( parent )
00035 {
00036     setModal( true );
00037     setObjectName( name );
00038     setButtons( Ok|Cancel|User1 );
00039     setDefaultButton( Ok );
00040     showButtonSeparator( true );
00041 
00042     setCaption( i18n("Import Styles") );
00043     m_currentCollection = currentCollection;
00044     KVBox *page = new KVBox();
00045     setMainWidget(page);
00046     new QLabel(i18n("Select styles to import:"), page);
00047     m_listStyleName = new Q3ListBox( page );
00048     m_listStyleName->setSelectionMode( Q3ListBox::Multi );
00049     enableButtonOk( m_listStyleName->count() != 0 );
00050     setButtonText( KDialog::User1, i18n("Load...") );
00051     connect( this, SIGNAL( user1Clicked() ), this, SLOT(slotLoadFile()));
00052     setInitialSize( QSize( 300, 400 ) );
00053     setFocus();
00054 }
00055 
00056 KoImportStyleDia::~KoImportStyleDia()
00057 {
00058 }
00059 
00060 void KoImportStyleDia::generateStyleList()
00061 {
00062     for (uint i = 0; i< m_listStyleName->count();i++)
00063     {
00064         if ( !m_listStyleName->isSelected( i ) )
00065         {
00066             //remove this style from list
00067             KoParagStyle* style = m_styleList.styleAt( i );
00068             updateFollowingStyle( style );
00069             m_styleList.removeStyle( style );
00070             break;
00071         }
00072     }
00073 }
00074 
00075 void KoImportStyleDia::updateFollowingStyle( KoParagStyle* removedStyle )
00076 {
00077     Q3ValueList<KoUserStyle *> lst = m_styleList.styleList();
00078     for( Q3ValueList<KoUserStyle *>::Iterator it = lst.begin(); it != lst.end(); ++it ) {
00079         KoParagStyle* style = static_cast<KoParagStyle *>( *it );
00080         if ( style->followingStyle() == removedStyle )
00081         {
00082             style->setFollowingStyle( style );
00083         }
00084     }
00085 }
00086 
00087 void KoImportStyleDia::slotLoadFile()
00088 {
00089     loadFile();
00090     enableButtonOk( m_listStyleName->count() != 0 );
00091 }
00092 
00093 void KoImportStyleDia::initList()
00094 {
00095     m_listStyleName->insertStringList( m_styleList.displayNameList() );
00096 }
00097 
00098 void KoImportStyleDia::slotOk()
00099 {
00100     generateStyleList();
00101     slotButtonClicked( Ok );
00102 }
00103 
00104 QString KoImportStyleDia::generateStyleName( const QString & templateName ) const
00105 {
00106     QString name;
00107     int num = 1;
00108     bool exists;
00109     do {
00110         name = templateName.arg( num );
00111         exists = m_currentCollection->findStyle( name ) != 0;
00112         ++num;
00113     } while ( exists );
00114     return name;
00115 }
00116 
00117 QString KoImportStyleDia::generateStyleDisplayName( const QString & templateName ) const
00118 {
00119     QString name;
00120     int num = 1;
00121     bool exists;
00122     do {
00123         name = templateName.arg( num );
00124         exists = m_currentCollection->findStyleByDisplayName( name ) != 0;
00125         ++num;
00126     } while ( exists );
00127     return name;
00128 }
00129 
00130 void KoImportStyleDia::clear()
00131 {
00132     m_styleList.clear();
00133 }
00134 
00135 #include "KoImportStyleDia.moc"

Généré le Wed Nov 22 23:41:08 2006 pour KPlato par  doxygen 1.5.1-p1