lib

KoStyleManager.cpp
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
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
21#include "KoStyleCollection.h"
22#include "KoStyleManager.h"
23#include "KoStyleManager.moc"
24#include <KoFontDia.h>
25#include <KoGlobal.h>
26
27#include <tdelocale.h>
28#include <kiconloader.h>
29#include <kdebug.h>
30
31#include <tqtabwidget.h>
32#include <tqpushbutton.h>
33#include <tqlabel.h>
34#include <tqcombobox.h>
35#include <tqcheckbox.h>
36#include <tqlayout.h>
37
38/******************************************************************/
39/* Class: KoStyleManager */
40/******************************************************************/
41
42/* keep 2 qlists with the styles.
43 1 of the origs, another with the changed ones (in order of the stylesList)
44 When an orig entry is empty and the other is not, a new one has to be made,
45 when the orig is present and the other is not, the orig has to be deleted.
46 Otherwise all changes are copied from the changed ones to the origs on OK.
47 OK updates the doc if styles are deleted.
48 The dtor frees all the changed ones.
49*/
50/* Months later the above seems SOO stupid.. Just should have created a small class
51 containing the orig and the copy and an enum plus some simple methods..
52 Well; just keep that for those loonly uninspiring days :) (Thomas Z)
53*/
54class KoStyleManagerPrivate
55{
56public:
57 KoStylePreview* preview;
58 TQCheckBox* cbIncludeInTOC;
59};
60
61KoStyleManager::KoStyleManager( TQWidget *_parent, KoUnit::Unit unit,
62 const KoStyleCollection& styles, const TQString & activeStyleName,
63 int flags )
64 : KDialogBase( _parent, "Stylist", true,
65 i18n("Style Manager"),
66 KDialogBase::Ok | KDialogBase::Cancel | KDialogBase::Apply )
67{
68 d = new KoStyleManagerPrivate;
69 //setWFlags(getWFlags() || WDestructiveClose);
70 m_currentStyle =0L;
71 noSignals=true;
72 m_origStyles.setAutoDelete(false);
73 m_changedStyles.setAutoDelete(false);
74 setupWidget(styles); // build the widget with the buttons and the list selector.
75 addGeneralTab( flags );
76 KoStyleFontTab * fontTab = new KoStyleFontTab( m_tabs );
77 addTab( fontTab );
78
79 KoStyleParagTab *newTab = new KoStyleParagTab( m_tabs );
80 newTab->setWidget( new KoIndentSpacingWidget( unit, -1/*no limit*/,newTab ) );
81 addTab( newTab );
82
83 newTab = new KoStyleParagTab( m_tabs );
84 newTab->setWidget( new KoParagAlignWidget( true, newTab ) );
85 addTab( newTab );
86
87 newTab = new KoStyleParagTab( m_tabs );
88 KoParagLayoutWidget *decorations = new KoParagDecorationWidget( newTab );
89 decorations->layout()->setMargin(KDialog::marginHint());
90 newTab->setWidget( decorations );
91 addTab( newTab );
92
93 newTab = new KoStyleParagTab( m_tabs );
94 newTab->setWidget( new KoParagCounterWidget( false , newTab ) );
95 addTab( newTab );
96
97 newTab = new KoStyleParagTab( m_tabs );
98 newTab->setWidget( new KoParagTabulatorsWidget( unit, -1, newTab ) );
99 addTab( newTab );
100
101 TQListBoxItem * item = m_stylesList->findItem( activeStyleName );
102 m_stylesList->setCurrentItem( item ? m_stylesList->index(item) : 0 );
103
104 noSignals=false;
105 switchStyle();
106 setInitialSize( TQSize( 600, 570 ) );
107}
108
109KoStyleManager::~KoStyleManager()
110{
111 for (unsigned int i =0 ; m_origStyles.count() > i ; i++) {
112 KoParagStyle *orig = m_origStyles.at(i);
113 KoParagStyle *changed = m_changedStyles.at(i);
114 if( orig && changed && orig != changed ) // modified style, we can delete the changed one now that changes have been applied
115 delete changed;
116 }
117
118 delete d;
119}
120
121void KoStyleManager::addTab( KoStyleManagerTab * tab )
122{
123 m_tabsList.append( tab );
124 m_tabs->insertTab( tab, tab->tabName() );
125 tab->layout()->activate();
126}
127
128void KoStyleManager::setupWidget(const KoStyleCollection& styleCollection)
129{
130 TQFrame * frame1 = makeMainWidget();
131 TQGridLayout *frame1Layout = new TQGridLayout( frame1, 0, 0, // auto
133 numStyles = styleCollection.count();
134 m_stylesList = new TQListBox( frame1, "stylesList" );
135 m_stylesList->insertStringList( styleCollection.displayNameList() );
136
137 const TQValueList<KoUserStyle*> styleList = styleCollection.styleList();
138 for ( TQValueList<KoUserStyle *>::const_iterator it = styleList.begin(), end = styleList.end();
139 it != end ; ++it )
140 {
141 KoParagStyle* style = static_cast<KoParagStyle *>( *it );
142 m_origStyles.append( style );
143 m_changedStyles.append( style );
144 m_styleOrder<< style->name();
145 }
146
147 frame1Layout->addMultiCellWidget( m_stylesList, 0, 0, 0, 1 );
148
149
150 m_moveUpButton = new TQPushButton( frame1, "moveUpButton" );
151 m_moveUpButton->setIconSet( SmallIconSet( "go-up" ) );
152 connect( m_moveUpButton, TQ_SIGNAL( clicked() ), this, TQ_SLOT( moveUpStyle() ) );
153 frame1Layout->addWidget( m_moveUpButton, 1, 1 );
154
155 m_moveDownButton = new TQPushButton( frame1, "moveDownButton" );
156 m_moveDownButton->setIconSet( SmallIconSet( "go-down" ) );
157 connect( m_moveDownButton, TQ_SIGNAL( clicked() ), this, TQ_SLOT( moveDownStyle() ) );
158 frame1Layout->addWidget( m_moveDownButton, 1, 0 );
159
160
161 m_deleteButton = new TQPushButton( frame1, "deleteButton" );
162 m_deleteButton->setText( i18n( "&Delete" ) );
163 connect( m_deleteButton, TQ_SIGNAL( clicked() ), this, TQ_SLOT( deleteStyle() ) );
164
165 frame1Layout->addWidget( m_deleteButton, 2, 1 );
166
167 m_newButton = new TQPushButton( frame1, "newButton" );
168 m_newButton->setText( i18n( "New" ) );
169 connect( m_newButton, TQ_SIGNAL( clicked() ), this, TQ_SLOT( addStyle() ) );
170
171 frame1Layout->addWidget( m_newButton, 2, 0 );
172
173 m_tabs = new TQTabWidget( frame1 );
174 frame1Layout->addMultiCellWidget( m_tabs, 0, 2, 2, 2 );
175
176 connect( m_stylesList, TQ_SIGNAL( selectionChanged() ), this, TQ_SLOT( switchStyle() ) );
177 connect( m_tabs, TQ_SIGNAL( currentChanged ( TQWidget * ) ), this, TQ_SLOT( switchTabs() ) );
178}
179
180void KoStyleManager::addGeneralTab( int flags ) {
181 TQWidget *tab = new TQWidget( m_tabs );
182
183 TQGridLayout *tabLayout = new TQGridLayout( tab );
184 tabLayout->setSpacing( KDialog::spacingHint() );
185 tabLayout->setMargin( KDialog::marginHint() );
186
187 m_nameString = new TQLineEdit( tab );
188 m_nameString->resize(m_nameString->sizeHint() );
189 connect( m_nameString, TQ_SIGNAL( textChanged( const TQString &) ), this, TQ_SLOT( renameStyle(const TQString &) ) );
190
191 tabLayout->addWidget( m_nameString, 0, 1 );
192
193 TQLabel *nameLabel = new TQLabel( tab );
194 nameLabel->setText( i18n( "Name:" ) );
195 nameLabel->resize(nameLabel->sizeHint());
196 nameLabel->setAlignment( AlignRight | AlignVCenter );
197
198 tabLayout->addWidget( nameLabel, 0, 0 );
199
200 m_styleCombo = new TQComboBox( false, tab, "styleCombo" );
201
202 tabLayout->addWidget( m_styleCombo, 1, 1 );
203
204 TQLabel *nextStyleLabel = new TQLabel( tab );
205 nextStyleLabel->setText( i18n( "Next style:" ) );
206 nextStyleLabel->setAlignment( AlignRight | AlignVCenter );
207
208 tabLayout->addWidget( nextStyleLabel, 1, 0 );
209
210 m_inheritCombo = new TQComboBox( false, tab, "inheritCombo" );
211 tabLayout->addWidget( m_inheritCombo, 2, 1 );
212
213 TQLabel *inheritStyleLabel = new TQLabel( tab );
214 inheritStyleLabel->setText( i18n( "Inherit style:" ) );
215 inheritStyleLabel->setAlignment( AlignRight | AlignVCenter );
216
217 tabLayout->addWidget( inheritStyleLabel, 2, 0 );
218
219 int row = 3;
220
221 if ( flags & ShowIncludeInToc ) {
222 d->cbIncludeInTOC = new TQCheckBox( i18n("Include in table of contents"), tab );
223 tabLayout->addMultiCellWidget( d->cbIncludeInTOC, row, row, 0, 1 );
224 ++row;
225 } else {
226 d->cbIncludeInTOC = 0;
227 }
228
229 d->preview = new KoStylePreview( i18n( "Preview" ), i18n( "The quick brown fox jumps over the lazy dog. And, what about the cat, one may ask? Well, the cat is playing cards with the mouse, the bird and the fish. It is, to say the least a hell of a party!" ), tab, "stylepreview" );
230
231 tabLayout->addMultiCellWidget( d->preview, row, row, 0, 1 );
232
233 m_tabs->insertTab( tab, i18n( "General" ) );
234
235 m_inheritCombo->insertItem( i18n("<None>"));
236
237 for ( unsigned int i = 0; i < m_stylesList->count(); i++ ) {
238 m_styleCombo->insertItem( m_stylesList->text(i));
239 m_inheritCombo->insertItem( m_stylesList->text(i));
240 }
241
242}
243
244void KoStyleManager::switchStyle() {
245 kdDebug(32500) << "KoStyleManager::switchStyle noSignals=" << noSignals << endl;
246 if(noSignals) return;
247 noSignals=true;
248
249 if(m_currentStyle !=0L)
250 save();
251
252 m_currentStyle = 0L;
253 int num = styleIndex( m_stylesList->currentItem() );
254 kdDebug(32500) << "KoStyleManager::switchStyle switching to " << num << endl;
255 if(m_origStyles.at(num) == m_changedStyles.at(num)) {
256 m_currentStyle = new KoParagStyle( *m_origStyles.at(num) );
257 m_changedStyles.take(num);
258 m_changedStyles.insert(num, m_currentStyle);
259 } else {
260 m_currentStyle = m_changedStyles.at(num);
261 }
262 updateGUI();
263
264 noSignals=false;
265}
266
267void KoStyleManager::switchTabs()
268{
269 // Called when the user switches tabs
270 // We call save() to update our style, for the preview on the 1st tab
271 save();
272 updatePreview();
273}
274
275// Return the index of the a style from its position in the GUI
276// (e.g. in m_stylesList or m_styleCombo). This index is used in
277// the m_origStyles and m_changedStyles lists.
278// The reason for the difference is that a deleted style is removed
279// from the GUI but not from the internal lists.
280int KoStyleManager::styleIndex( int pos ) {
281 int p = 0;
282 for(unsigned int i=0; i < m_changedStyles.count(); i++) {
283 // Skip deleted styles, they're no in m_stylesList anymore
284 KoParagStyle * style = m_changedStyles.at(i);
285 if ( !style ) continue;
286 if ( p == pos )
287 return i;
288 ++p;
289 }
290 kdWarning() << "KoStyleManager::styleIndex no style found at pos " << pos << endl;
291
292#ifdef __GNUC_
293#warning implement undo/redo
294#endif
295
296 return 0;
297}
298
299// Update the GUI so that it shows m_currentStyle
300void KoStyleManager::updateGUI() {
301 kdDebug(32500) << "KoStyleManager::updateGUI m_currentStyle=" << m_currentStyle << " " << m_currentStyle->name() << endl;
302 TQPtrListIterator<KoStyleManagerTab> it( m_tabsList );
303 for ( ; it.current() ; ++it )
304 {
305 it.current()->setStyle( m_currentStyle );
306 it.current()->update();
307 }
308
309 m_nameString->setText(m_currentStyle->displayName());
310
311 TQString followingName = m_currentStyle->followingStyle() ? m_currentStyle->followingStyle()->displayName() : TQString();
312 kdDebug(32500) << "KoStyleManager::updateGUI updating combo to " << followingName << endl;
313 for ( int i = 0; i < m_styleCombo->count(); i++ ) {
314 if ( m_styleCombo->text( i ) == followingName ) {
315 m_styleCombo->setCurrentItem( i );
316 kdDebug(32500) << "found at " << i << endl;
317 break;
318 }
319 }
320
321 TQString inheritName = m_currentStyle->parentStyle() ? m_currentStyle->parentStyle()->displayName() : TQString();
322 kdDebug(32500) << "KoStyleManager::updateGUI updating combo to " << inheritName << endl;
323 for ( int i = 0; i < m_inheritCombo->count(); i++ ) {
324 if ( m_inheritCombo->text( i ) == inheritName ) {
325 m_inheritCombo->setCurrentItem( i );
326 kdDebug(32500) << "found at " << i << endl;
327 break;
328 }
329 else
330 m_inheritCombo->setCurrentItem( 0 );//none !!!
331 }
332
333 if ( d->cbIncludeInTOC )
334 d->cbIncludeInTOC->setChecked( m_currentStyle->isOutline() );
335
336 // update delete button (can't delete first style);
337 m_deleteButton->setEnabled(m_stylesList->currentItem() != 0);
338
339 m_moveUpButton->setEnabled(m_stylesList->currentItem() != 0);
340 m_moveDownButton->setEnabled(m_stylesList->currentItem()!=(int)m_stylesList->count()-1);
341
342 updatePreview();
343}
344
345void KoStyleManager::updatePreview()
346{
347 d->preview->setStyle(m_currentStyle);
348 d->preview->repaint(true);
349}
350
351void KoStyleManager::save() {
352 if(m_currentStyle) {
353 // save changes from UI to object.
354 TQPtrListIterator<KoStyleManagerTab> it( m_tabsList );
355 for ( ; it.current() ; ++it )
356 it.current()->save();
357
358 // Rename the style - only if it's actually been renamed.
359 if ( m_currentStyle->name() != m_nameString->text() &&
360 m_currentStyle->displayName() != m_nameString->text() )
361 {
362 m_currentStyle->setDisplayName( m_nameString->text() );
363 }
364
365 int indexNextStyle = styleIndex( m_styleCombo->currentItem() );
366 m_currentStyle->setFollowingStyle( m_origStyles.at( indexNextStyle ) ); // point to orig, not changed! (#47377)
367
368 if ( m_inheritCombo->currentItem() == 0 ) //<None> selected
369 m_currentStyle->setParentStyle(0);
370 else
371 {
372 int indexParentStyle=styleIndex( m_inheritCombo->currentItem()-1 );
373 KoParagStyle *parent=m_origStyles.at(indexParentStyle);
374 if( parent==0L ) //If not found in the orig list (means its a new Style) look in the changeStyles list
375 parent=m_changedStyles.at(indexParentStyle);
376
377 m_currentStyle->setParentStyle( parent );
378 }
379
380 if ( d->cbIncludeInTOC )
381 m_currentStyle->setOutline( d->cbIncludeInTOC->isChecked() );
382 }
383}
384
385KoParagStyle * KoStyleManager::style( const TQString & _name )
386{
387 for(unsigned int i=0; i < m_changedStyles.count(); i++) {
388 // Skip deleted styles, they're no in m_stylesList anymore
389 KoParagStyle * style = m_changedStyles.at(i);
390 if ( !style ) continue;
391 if ( style->name() == _name)
392 return style;
393 }
394 return 0;
395}
396
397TQString KoStyleManager::generateUniqueName()
398{
399 int count = 1;
400 TQString name;
401 do {
402 name = "new" + TQString::number( count++ );
403 } while ( style( name ) );
404 return name;
405}
406
407
408void KoStyleManager::addStyle() {
409 save();
410
411 TQString str = i18n( "New Style Template (%1)" ).arg(numStyles++);
412 if ( m_currentStyle )
413 {
414 m_currentStyle = new KoParagStyle( *m_currentStyle ); // Create a new style, initializing from the current one
415 m_currentStyle->setDisplayName( str );
416 m_currentStyle->setName( generateUniqueName() );
417 }
418 else
419 m_currentStyle = new KoParagStyle( str );
420 m_currentStyle->setFollowingStyle( m_currentStyle ); // #45868
421
422 noSignals=true;
423 m_origStyles.append(0L);
424 m_changedStyles.append(m_currentStyle);
425 m_stylesList->insertItem( str );
426 m_styleCombo->insertItem( str );
427 m_inheritCombo->insertItem( str );
428 m_stylesList->setCurrentItem( m_stylesList->count() - 1 );
429 noSignals=false;
430 m_styleOrder << m_currentStyle->name();
431
432 updateGUI();
433}
434
435void KoStyleManager::updateFollowingStyle( KoParagStyle *s )
436{
437 for ( KoParagStyle* p = m_changedStyles.first(); p != 0L; p = m_changedStyles.next() )
438 {
439 if ( p->followingStyle() == s)
440 p->setFollowingStyle(p);
441 }
442
443}
444
445void KoStyleManager::updateInheritStyle( KoParagStyle *s )
446{
447 for ( KoParagStyle* p = m_changedStyles.first(); p != 0L; p = m_changedStyles.next() )
448 {
449 //when we remove style, we must replace inherite style to 0L
450 //when parent style was removed.
451 //##########Laurent change inherited style attribute
452 if ( p->parentStyle() == s)
453 p->setParentStyle(0L);
454 }
455
456}
457
458void KoStyleManager::deleteStyle() {
459
460 unsigned int cur = styleIndex( m_stylesList->currentItem() );
461 unsigned int curItem = m_stylesList->currentItem();
462 TQString name = m_stylesList->currentText();
463 KoParagStyle *s = m_changedStyles.at(cur);
464 m_styleOrder.remove( s->name());
465 updateFollowingStyle( s );
466 updateInheritStyle( s );
467 Q_ASSERT( s == m_currentStyle );
468 delete s;
469 m_currentStyle = 0L;
470 m_changedStyles.remove(cur);
471 m_changedStyles.insert(cur,0L);
472
473 // Done with noSignals still false, so that when m_stylesList changes the current item
474 // we display it automatically
475 m_stylesList->removeItem(curItem);
476 m_styleCombo->removeItem(curItem);
477
478 m_inheritCombo->listBox()->removeItem( m_inheritCombo->listBox()->index(m_inheritCombo->listBox()->findItem(name )));
479
480 numStyles--;
481 m_stylesList->setSelected( m_stylesList->currentItem(), true );
482}
483
484void KoStyleManager::moveUpStyle()
485{
486 Q_ASSERT( m_currentStyle );
487 if ( m_currentStyle )
488 save();
489 const TQString currentStyleName = m_currentStyle->name();
490 const TQString currentStyleDisplayName = m_stylesList->currentText();
491 int pos2 = m_styleOrder.findIndex( currentStyleName );
492 if ( pos2 != -1 )
493 {
494 m_styleOrder.remove( m_styleOrder.at(pos2));
495 m_styleOrder.insert( m_styleOrder.at(pos2-1), currentStyleName);
496 }
497
498 int pos = m_stylesList->currentItem();
499 noSignals=true;
500 m_stylesList->changeItem( m_stylesList->text( pos-1 ), pos );
501 m_styleCombo->changeItem( m_stylesList->text( pos-1 ), pos );
502
503 m_stylesList->changeItem( currentStyleDisplayName, pos-1 );
504 m_styleCombo->changeItem( currentStyleDisplayName, pos-1 );
505
506 m_stylesList->setCurrentItem( m_stylesList->currentItem() );
507 noSignals=false;
508
509 updateGUI();
510}
511
512void KoStyleManager::moveDownStyle()
513{
514 Q_ASSERT( m_currentStyle );
515 if ( m_currentStyle )
516 save();
517 const TQString currentStyleName = m_currentStyle->name();
518 const TQString currentStyleDisplayName = m_stylesList->currentText();
519 int pos2 = m_styleOrder.findIndex( currentStyleName );
520 if ( pos2 != -1 )
521 {
522 m_styleOrder.remove( m_styleOrder.at(pos2));
523 m_styleOrder.insert( m_styleOrder.at(pos2+1), currentStyleName);
524 }
525
526 int pos = m_stylesList->currentItem();
527 noSignals=true;
528 m_stylesList->changeItem( m_stylesList->text( pos+1 ), pos );
529 m_styleCombo->changeItem( m_stylesList->text( pos+1 ), pos );
530 m_stylesList->changeItem( currentStyleDisplayName, pos+1 );
531 m_styleCombo->changeItem( currentStyleDisplayName, pos+1 );
532 m_stylesList->setCurrentItem( m_stylesList->currentItem() );
533 noSignals=false;
534
535 updateGUI();
536}
537
538void KoStyleManager::slotOk() {
539 save();
540 apply();
542}
543
544void KoStyleManager::slotApply() {
545 save();
546 apply();
548}
549
550void KoStyleManager::apply() {
551 noSignals=true;
552 KoStyleChangeDefMap styleChanged;
553 TQPtrList<KoParagStyle> removeStyle;
554 for (unsigned int i =0 ; m_origStyles.count() > i ; i++) {
555 if(m_origStyles.at(i) == 0L && m_changedStyles.at(i)!=0L) { // newly added style
556 kdDebug(32500) << "adding new " << m_changedStyles.at(i)->name() << " (" << i << ")" << endl;
557 KoParagStyle *tmp = addStyleTemplate(m_changedStyles.take(i));
558 m_changedStyles.insert(i, tmp);
559 } else if(m_changedStyles.at(i) == 0L && m_origStyles.at(i) != 0L) { // deleted style
560 kdDebug(32500) << "deleting orig " << m_origStyles.at(i)->name() << " (" << i << ")" << endl;
561
562 KoParagStyle *orig = m_origStyles.at(i);
563 //applyStyleChange( orig, -1, -1 );
564 KoStyleChangeDef tmp( -1,-1);
565 styleChanged.insert( orig, tmp);
566
567 removeStyle.append( orig );
568 // Note that the style is never deleted (we'll need it for undo/redo purposes)
569
570 } else if(m_changedStyles.at(i) != 0L && m_origStyles.at(i)!=0L) { // simply updated style
571 kdDebug(32500) << "update style " << m_changedStyles.at(i)->name() << " (" << i << ")" << endl;
572 KoParagStyle *orig = m_origStyles.at(i);
573 KoParagStyle *changed = m_changedStyles.at(i);
574 if ( orig != changed )
575 {
576 int paragLayoutChanged = orig->paragLayout().compare( changed->paragLayout() );
577 int formatChanged = orig->format().compare( changed->format() );
578 //kdDebug(32500) << "old format " << orig->format().key() << " pointsize " << orig->format().pointSizeFloat() << endl;
579 //kdDebug(32500) << "new format " << changed->format().key() << " pointsize " << changed->format().pointSizeFloat() << endl;
580
581 // Copy everything from changed to orig
582 *orig = *changed;
583
584 // Apply the change selectively - i.e. only what changed
585 //applyStyleChange( orig, paragLayoutChanged, formatChanged );
586 if ( formatChanged != 0 || paragLayoutChanged != 0 ) {
587 KoStyleChangeDef tmp(paragLayoutChanged, formatChanged);
588 styleChanged.insert( orig, tmp );
589 }
590
591 }
592
593 }// else
594 // kdDebug(32500) << "has not changed " << m_changedStyles.at(i)->name() << " (" << i << ")" << endl;
595 }
596
597 applyStyleChange( styleChanged );
598
599 KoParagStyle *tmp = 0L;
600 for ( tmp = removeStyle.first(); tmp ;tmp = removeStyle.next() )
601 removeStyleTemplate( tmp );
602
603 updateStyleListOrder( m_styleOrder );
604 updateAllStyleLists();
605 noSignals=false;
606}
607
608void KoStyleManager::renameStyle(const TQString &theText) {
609 if(noSignals) return;
610 noSignals=true;
611
612 int index = m_stylesList->currentItem();
613 kdDebug(32500) << "KoStyleManager::renameStyle " << index << " to " << theText << endl;
614
615 // rename only in the GUI, not even in the underlying objects (save() does it).
616 kdDebug(32500) << "KoStyleManager::renameStyle before " << m_styleCombo->currentText() << endl;
617 m_styleCombo->changeItem( theText, index );
618 m_inheritCombo->changeItem( theText, index+1 );
619 //m_styleOrder[index]=theText; // not needed anymore, we use internal names
620 kdDebug(32500) << "KoStyleManager::renameStyle after " << m_styleCombo->currentText() << endl;
621 m_stylesList->changeItem( theText, index );
622
623 // Check how many styles with that name we have now
624 int synonyms = 0;
625 for ( int i = 0; i < m_styleCombo->count(); i++ ) {
626 if ( m_styleCombo->text( i ) == m_stylesList->currentText() )
627 ++synonyms;
628 }
629 Q_ASSERT( synonyms > 0 ); // should have found 'index' at least !
630 noSignals=false;
631 // Can't close the dialog if two styles have the same name
632 bool state=!theText.isEmpty() && (synonyms == 1);
633 enableButtonOK(state );
634 enableButtonApply(state);
635 m_deleteButton->setEnabled(state&&(m_stylesList->currentItem() != 0));
636 m_newButton->setEnabled(state);
637 m_stylesList->setEnabled( state );
638 if ( state )
639 {
640 m_moveUpButton->setEnabled(m_stylesList->currentItem() != 0);
641 m_moveDownButton->setEnabled(m_stylesList->currentItem()!=(int)m_stylesList->count()-1);
642 }
643 else
644 {
645 m_moveUpButton->setEnabled(false);
646 m_moveDownButton->setEnabled(false);
647 }
648}
649
651
652KoStyleParagTab::KoStyleParagTab( TQWidget * parent )
653 : KoStyleManagerTab( parent )
654{
655 ( new TQVBoxLayout( this ) )->setAutoAdd( true );
656 m_widget = 0L;
657}
658
659void KoStyleParagTab::update()
660{
661 m_widget->display( m_style->paragLayout() );
662}
663
664void KoStyleParagTab::save()
665{
666 m_widget->save( m_style->paragLayout() );
667}
668
669void KoStyleParagTab::setWidget( KoParagLayoutWidget * widget )
670{
671 m_widget = widget;
672}
673
674void KoStyleParagTab::resizeEvent( TQResizeEvent *e )
675{
676 TQWidget::resizeEvent( e );
677 if ( m_widget ) m_widget->resize( size() );
678}
679
680KoStyleFontTab::KoStyleFontTab( TQWidget * parent )
681 : KoStyleManagerTab( parent )
682{
683 ( new TQVBoxLayout( this ) )->setAutoAdd( true );
684 TQTabWidget *fontTabContainer = new TQTabWidget( this );
685
686 m_fontTab = new KoFontTab( TDEFontChooser::SmoothScalableFonts, this );
687 m_decorationTab = new KoDecorationTab( this );
688 m_highlightingTab = new KoHighlightingTab( this );
689 m_layoutTab = new KoLayoutTab( true, this );
690 m_languageTab = new KoLanguageTab( 0, this );
691
692 fontTabContainer->addTab( m_fontTab, i18n( "Font" ) );
693 fontTabContainer->addTab( m_decorationTab, i18n( "Decoration" ) );
694 fontTabContainer->addTab( m_highlightingTab, i18n( "Highlighting" ) );
695 fontTabContainer->addTab( m_layoutTab, i18n( "Layout" ) );
696 fontTabContainer->addTab( m_languageTab, i18n( "Language" ) );
697}
698
699KoStyleFontTab::~KoStyleFontTab()
700{
701}
702
703void KoStyleFontTab::update()
704{
705 m_fontTab->setSelection( m_style->format().font() );
706 m_highlightingTab->setUnderline( m_style->format().underlineType() );
707 m_highlightingTab->setUnderlineStyle( m_style->format().underlineStyle() );
708 m_highlightingTab->setUnderlineColor( m_style->format().textUnderlineColor() );
709 m_highlightingTab->setStrikethrough( m_style->format().strikeOutType() );
710 m_highlightingTab->setStrikethroughStyle( m_style->format().strikeOutStyle() );
711 m_highlightingTab->setWordByWord( m_style->format().wordByWord() );
712 m_highlightingTab->setCapitalisation( m_style->format().attributeFont() );
713 m_decorationTab->setTextColor( m_style->format().color() );
714 m_decorationTab->setBackgroundColor( m_style->format().textBackgroundColor() );
715 m_decorationTab->setShadow( m_style->format().shadowDistanceX(), m_style->format().shadowDistanceY(), m_style->format().shadowColor() );
716 m_layoutTab->setSubSuperScript( m_style->format().vAlign(), m_style->format().offsetFromBaseLine(), m_style->format().relativeTextSize() );
717 m_layoutTab->setAutoHyphenation( m_style->format().hyphenation() );
718 m_languageTab->setLanguage( m_style->format().language() );
719/*
720#if 0
721 bool subScript = m_style->format().vAlign() == KoTextFormat::AlignSubScript;
722 bool superScript = m_style->format().vAlign() == KoTextFormat::AlignSuperScript;
723 TQFont fn = m_style->format().font();
724 kdDebug()<<" fn.bold() :"<<fn.bold()<<" fn.italic():"<<fn.italic()<<endl;
725 kdDebug()<<" fn.family() :"<<fn.family()<<endl;
726 m_chooser->setFont( fn, subScript, superScript );
727 m_chooser->setColor( m_style->format().color() );
728 TQColor col=m_style->format().textBackgroundColor();
729 col=col.isValid() ? col : TQApplication::palette().color( TQPalette::Active, TQColorGroup::Base );
730 m_chooser->setBackGroundColor(col);
731
732 m_chooser->setUnderlineColor( m_style->format().textUnderlineColor());
733
734 m_chooser->setUnderlineType(m_style->format().underlineType());
735 m_chooser->setUnderlineStyle(m_style->format().underlineStyle());
736 m_chooser->setStrikeOutStyle(m_style->format().strikeOutStyle());
737 m_chooser->setStrikeOutlineType(m_style->format().strikeOutType());
738 m_chooser->setShadowText( m_style->format().shadowText());
739 m_chooser->setFontAttribute( m_style->format().attributeFont());
740 m_chooser->setWordByWord( m_style->format().wordByWord());
741 m_chooser->setRelativeTextSize( m_style->format().relativeTextSize());
742 m_chooser->setOffsetFromBaseLine( m_style->format().offsetFromBaseLine());
743 m_chooser->setLanguage( m_style->format().language());
744 m_chooser->setHyphenation( m_style->format().hyphenation());
745#endif
746*/}
747
748void KoStyleFontTab::save()
749{
750 m_style->format() = KoTextFormat( m_fontTab->getSelection(),
751 m_layoutTab->getSubSuperScript(),
752 m_decorationTab->getTextColor(),
753 m_decorationTab->getBackgroundColor(),
754 m_highlightingTab->getUnderlineColor(),
755 m_highlightingTab->getUnderline(),
756 m_highlightingTab->getUnderlineStyle(),
757 m_highlightingTab->getStrikethrough(),
758 m_highlightingTab->getStrikethroughStyle(),
759 m_highlightingTab->getCapitalisation(),
760 m_languageTab->getLanguage(),
761 m_layoutTab->getRelativeTextSize(),
762 m_layoutTab->getOffsetFromBaseline(),
763 m_highlightingTab->getWordByWord(),
764 m_layoutTab->getAutoHyphenation(),
765 m_decorationTab->getShadowDistanceX(),
766 m_decorationTab->getShadowDistanceY(),
767 m_decorationTab->getShadowColor()
768 );
769/*
770 m_style->format().setFont( m_fontTab->getSelection() );
771 m_style->format().setColor( m_decorationTab->getTextColor() );
772 if( m_decorationTab->getBackGroundColor()!=TQApplication::palette().color( TQPalette::Active, TQColorGroup::Base ))
773 m_style->format().setTextBackgroundColor( m_decorationTab->getBackGroundColor() );
774
775 m_style->format().setTextUnderlineColor(m_chooser->underlineColor());
776 m_style->format().setUnderlineType (m_chooser->getUnderlineType());
777 m_style->format().setUnderlineStyle (m_chooser->getUnderlineStyle());
778 m_style->format().setStrikeOutStyle( m_chooser->getStrikeOutStyle() );
779 m_style->format().setStrikeOutType (m_chooser->getStrikeOutType());
780 m_style->format().setShadowText(m_chooser->getShadowText());
781 m_style->format().setWordByWord( m_chooser->getWordByWord());
782 m_style->format().setRelativeTextSize( m_chooser->getRelativeTextSize());
783 m_style->format().setAttributeFont( m_chooser->getFontAttribute());
784 m_style->format().setOffsetFromBaseLine( m_chooser->getOffsetFromBaseLine());
785 m_style->format().setVAlign( m_layoutTab->getSubSuperScript() );
786
787 m_style->format().setLanguage( m_chooser->getLanguage());
788 m_style->format().setHyphenation( m_chooser->getHyphenation());
789*/}
790
791TQString KoStyleFontTab::tabName()
792{
793 return i18n("Font");
794}
virtual void slotApply()
void enableButtonApply(bool state)
void enableButtonOK(bool state)
TQFrame * makeMainWidget()
virtual void slotOk()
static int marginHint()
static int spacingHint()
const KoTextFormat & format() const
Return a format.
The widget for editing idents and spacings (tab 1)
Definition KoParagDia.h:109
The widget for editing paragraph alignment (tab 2)
Definition KoParagDia.h:153
The widget for editing counters (bullets & numbering) (tab 4)
Definition KoParagDia.h:346
The widget for editing paragraph borders (tab 3)
Definition KoParagDia.h:187
This is the base class for any widget [usually used in a tab] that handles modifying a part of a KoPa...
Definition KoParagDia.h:73
int compare(const KoParagLayout &layout) const
Return a set of flags showing the differences between this and 'layout'.
A paragraph style is a combination of a character style and paragraph-layout attributes,...
The widget for editing tabulators (tab 5)
Definition KoParagDia.h:408
TODO rename to KoParagStyleCollection - or should char styles be part of it too?
KoStylePreview.
Definition KoParagDia.h:469
Each character (KoTextStringChar) points to a KoTextFormat that defines the formatting of that charac...
int compare(const KoTextFormat &format) const
Return a set of flags showing the differences between this and 'format'.
Unit
Length units supported by KOffice.
Definition KoUnit.h:63
TQValueList< KoUserStyle * > styleList() const
Return the list of all styles in the collection.
TQStringList displayNameList() const
Return the list composed of the display-name of each style in the collection.
void setName(const TQString &name)
Set the internal name - see generateUniqueName() if needed Should be unique in a given style collecti...
Definition KoUserStyle.h:43
TQString displayName() const
The user-visible name (e.g. translated, or set by the user)
void setDisplayName(const TQString &name)
Set the user-visible name.
TQString name() const
The internal name (used for loading/saving, but not shown to the user) Should be unique in a given st...
Definition KoUserStyle.h:40
const char * name(StdAction id)