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(
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
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"