lib
KoImportStyleDia.cpp00001
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 }
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
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"
|