lib

KoImportStyleDia.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002 Montel Laurent <lmontel@mandrakesoft.com>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#include <tdelocale.h>
21#include <tqvbox.h>
22#include <tqlayout.h>
23#include <tqlineedit.h>
24#include <tqpushbutton.h>
25#include <tqlistbox.h>
26#include "KoImportStyleDia.h"
27
28#include <kdebug.h>
29#include <tqlabel.h>
30
31KoImportStyleDia::KoImportStyleDia( KoStyleCollection* currentCollection, TQWidget *parent, const char *name )
32 : KDialogBase( parent, name , true, "", Ok|Cancel|User1, Ok, true )
33{
34 setCaption( i18n("Import Styles") );
35 m_currentCollection = currentCollection;
36 TQVBox *page = makeVBoxMainWidget();
37 new TQLabel(i18n("Select styles to import:"), page);
38 m_listStyleName = new TQListBox( page );
39 m_listStyleName->setSelectionMode( TQListBox::Multi );
40 enableButtonOK( m_listStyleName->count() != 0 );
41 setButtonText( KDialogBase::User1, i18n("Load...") );
42 connect( this, TQ_SIGNAL( user1Clicked() ), this, TQ_SLOT(slotLoadFile()));
43 setInitialSize( TQSize( 300, 400 ) );
44 setFocus();
45}
46
47KoImportStyleDia::~KoImportStyleDia()
48{
49}
50
51void KoImportStyleDia::generateStyleList()
52{
53 for (uint i = 0; i< m_listStyleName->count();i++)
54 {
55 if ( !m_listStyleName->isSelected( i ) )
56 {
57 //remove this style from list
58 KoParagStyle* style = m_styleList.styleAt( i );
59 updateFollowingStyle( style );
60 m_styleList.removeStyle( style );
61 break;
62 }
63 }
64}
65
66void KoImportStyleDia::updateFollowingStyle( KoParagStyle* removedStyle )
67{
68 TQValueList<KoUserStyle *> lst = m_styleList.styleList();
69 for( TQValueList<KoUserStyle *>::Iterator it = lst.begin(); it != lst.end(); ++it ) {
70 KoParagStyle* style = static_cast<KoParagStyle *>( *it );
71 if ( style->followingStyle() == removedStyle )
72 {
73 style->setFollowingStyle( style );
74 }
75 }
76}
77
78void KoImportStyleDia::slotLoadFile()
79{
80 loadFile();
81 enableButtonOK( m_listStyleName->count() != 0 );
82}
83
84void KoImportStyleDia::initList()
85{
86 m_listStyleName->insertStringList( m_styleList.displayNameList() );
87}
88
90{
91 generateStyleList();
93}
94
95TQString KoImportStyleDia::generateStyleName( const TQString & templateName ) const
96{
97 TQString name;
98 int num = 1;
99 bool exists;
100 do {
101 name = templateName.arg( num );
102 exists = m_currentCollection->findStyle( name ) != 0;
103 ++num;
104 } while ( exists );
105 return name;
106}
107
108TQString KoImportStyleDia::generateStyleDisplayName( const TQString & templateName ) const
109{
110 TQString name;
111 int num = 1;
112 bool exists;
113 do {
114 name = templateName.arg( num );
115 exists = m_currentCollection->findStyleByDisplayName( name ) != 0;
116 ++num;
117 } while ( exists );
118 return name;
119}
120
121void KoImportStyleDia::clear()
122{
123 m_styleList.clear();
124}
125
126#include "KoImportStyleDia.moc"
void enableButtonOK(bool state)
virtual void slotOk()
A paragraph style is a combination of a character style and paragraph-layout attributes,...
TODO rename to KoParagStyleCollection - or should char styles be part of it too?
const char * name(StdAction id)