lib

KoImportStyleDia.cpp

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 <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( KoStyleCollection* currentCollection, QWidget *parent, const char *name )
00032     : KDialogBase( parent, name , true, "", Ok|Cancel|User1, Ok, true )
00033 {
00034     setCaption( i18n("Import Styles") );
00035     m_currentCollection = currentCollection;
00036     QVBox *page = makeVBoxMainWidget();
00037     new QLabel(i18n("Select styles 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     setInitialSize( QSize( 300, 400 ) );
00044     setFocus();
00045 }
00046 
00047 KoImportStyleDia::~KoImportStyleDia()
00048 {
00049 }
00050 
00051 void KoImportStyleDia::generateStyleList()
00052 {
00053     for (uint i = 0; i< m_listStyleName->count();i++)
00054     {
00055         if ( !m_listStyleName->isSelected( i ) )
00056         {
00057             //remove this style from list
00058             KoParagStyle* style = m_styleList.styleAt( i );
00059             updateFollowingStyle( style );
00060             m_styleList.removeStyle( style );
00061             break;
00062         }
00063     }
00064 }
00065 
00066 void KoImportStyleDia::updateFollowingStyle( KoParagStyle* removedStyle )
00067 {
00068     QValueList<KoUserStyle *> lst = m_styleList.styleList();
00069     for( QValueList<KoUserStyle *>::Iterator it = lst.begin(); it != lst.end(); ++it ) {
00070         KoParagStyle* style = static_cast<KoParagStyle *>( *it );
00071         if ( style->followingStyle() == removedStyle )
00072         {
00073             style->setFollowingStyle( style );
00074         }
00075     }
00076 }
00077 
00078 void KoImportStyleDia::slotLoadFile()
00079 {
00080     loadFile();
00081     enableButtonOK( m_listStyleName->count() != 0 );
00082 }
00083 
00084 void KoImportStyleDia::initList()
00085 {
00086     m_listStyleName->insertStringList( m_styleList.displayNameList() );
00087 }
00088 
00089 void KoImportStyleDia::slotOk()
00090 {
00091     generateStyleList();
00092     KDialogBase::slotOk();
00093 }
00094 
00095 QString KoImportStyleDia::generateStyleName( const QString & templateName ) const
00096 {
00097     QString name;
00098     int num = 1;
00099     bool exists;
00100     do {
00101         name = templateName.arg( num );
00102         exists = m_currentCollection->findStyle( name ) != 0;
00103         ++num;
00104     } while ( exists );
00105     return name;
00106 }
00107 
00108 QString KoImportStyleDia::generateStyleDisplayName( const QString & templateName ) const
00109 {
00110     QString name;
00111     int num = 1;
00112     bool exists;
00113     do {
00114         name = templateName.arg( num );
00115         exists = m_currentCollection->findStyleByDisplayName( name ) != 0;
00116         ++num;
00117     } while ( exists );
00118     return name;
00119 }
00120 
00121 void KoImportStyleDia::clear()
00122 {
00123     m_styleList.clear();
00124 }
00125 
00126 #include "KoImportStyleDia.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys