koimportstyledia.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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 m_styleList.setAutoDelete(true);
00050 m_styleList.clear();
00051 }
00052
00053 void KoImportStyleDia::generateStyleList()
00054 {
00055 for (uint i = 0; i< m_listStyleName->count();i++)
00056 {
00057 if ( !m_listStyleName->isSelected( i ))
00058 {
00059 QString name = m_listStyleName->text( i );
00060
00061 QPtrListIterator<KoParagStyle> styleIt( m_styleList );
00062 for ( ; styleIt.current(); ++styleIt )
00063 {
00064 if ( styleIt.current()->displayName() == name )
00065 {
00066 updateFollowingStyle( styleIt.current()->displayName() );
00067 m_styleList.remove(styleIt.current());
00068 break;
00069 }
00070 }
00071 }
00072 }
00073 }
00074
00075 void KoImportStyleDia::updateFollowingStyle(const QString & _name)
00076 {
00077 QPtrListIterator<KoParagStyle> styleIt( m_styleList );
00078 for ( ; styleIt.current(); ++styleIt )
00079 {
00080 if ( styleIt.current()->followingStyle()->displayName() == _name )
00081 {
00082 styleIt.current()->setFollowingStyle(styleIt.current());
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 QStringList lst;
00096 QPtrListIterator<KoParagStyle> styleIt( m_styleList );
00097 for ( ; styleIt.current(); ++styleIt )
00098 lst << styleIt.current()->displayName();
00099 m_listStyleName->insertStringList(lst);
00100 }
00101
00102 void KoImportStyleDia::slotOk()
00103 {
00104 generateStyleList();
00105 KDialogBase::slotOk();
00106 }
00107
00108 QString KoImportStyleDia::generateStyleName( 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->findStyle( name ) != 0;
00116 ++num;
00117 } while ( exists );
00118 return name;
00119 }
00120
00121 QString KoImportStyleDia::generateStyleDisplayName( const QString & templateName ) const
00122 {
00123 QString name;
00124 int num = 1;
00125 bool exists;
00126 do {
00127 name = templateName.arg( num );
00128 exists = m_currentCollection->findTranslatedStyle( name ) != 0;
00129 ++num;
00130 } while ( exists );
00131 return name;
00132 }
00133
00134 KoParagStyle *KoImportStyleDia::findStyle( const QString & name ) const
00135 {
00136 QPtrListIterator<KoParagStyle> styleIt( m_styleList );
00137 for ( ; styleIt.current(); ++styleIt )
00138 {
00139 if ( styleIt.current()->name() == name ) {
00140 return styleIt.current();
00141 }
00142 }
00143 return 0;
00144 }
00145
00146 KoParagStyle * KoImportStyleDia::findTranslatedStyle( const QString & name ) const
00147 {
00148 QPtrListIterator<KoParagStyle> styleIt( m_styleList );
00149 for ( ; styleIt.current(); ++styleIt )
00150 {
00151 if ( styleIt.current()->displayName() == name ) {
00152 return styleIt.current();
00153 }
00154 }
00155 return 0;
00156 }
00157
00158 void KoImportStyleDia::clear()
00159 {
00160 m_styleList.setAutoDelete(true);
00161 m_styleList.clear();
00162 }
00163
00164 #include "koimportstyledia.moc"
This file is part of the documentation for lib Library Version 1.4.2.