21#include "KoStyleCollection.h"
22#include "KoStyleManager.h"
23#include "KoStyleManager.moc"
28#include <kiconloader.h>
31#include <tqtabwidget.h>
32#include <tqpushbutton.h>
34#include <tqcombobox.h>
35#include <tqcheckbox.h>
54class KoStyleManagerPrivate
57 KoStylePreview* preview;
58 TQCheckBox* cbIncludeInTOC;
61KoStyleManager::KoStyleManager( TQWidget *_parent,
KoUnit::Unit unit,
65 i18n(
"Style Manager"),
68 d =
new KoStyleManagerPrivate;
72 m_origStyles.setAutoDelete(
false);
73 m_changedStyles.setAutoDelete(
false);
75 addGeneralTab( flags );
76 KoStyleFontTab * fontTab =
new KoStyleFontTab( m_tabs );
79 KoStyleParagTab *newTab =
new KoStyleParagTab( m_tabs );
83 newTab =
new KoStyleParagTab( m_tabs );
87 newTab =
new KoStyleParagTab( m_tabs );
90 newTab->setWidget( decorations );
93 newTab =
new KoStyleParagTab( m_tabs );
97 newTab =
new KoStyleParagTab( m_tabs );
101 TQListBoxItem * item = m_stylesList->findItem( activeStyleName );
102 m_stylesList->setCurrentItem( item ? m_stylesList->index(item) : 0 );
106 setInitialSize( TQSize( 600, 570 ) );
109KoStyleManager::~KoStyleManager()
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 )
121void KoStyleManager::addTab( KoStyleManagerTab * tab )
123 m_tabsList.append( tab );
124 m_tabs->insertTab( tab, tab->tabName() );
125 tab->layout()->activate();
131 TQGridLayout *frame1Layout =
new TQGridLayout( frame1, 0, 0,
133 numStyles = styleCollection.
count();
134 m_stylesList =
new TQListBox( frame1,
"stylesList" );
137 const TQValueList<KoUserStyle*> styleList = styleCollection.
styleList();
138 for ( TQValueList<KoUserStyle *>::const_iterator it = styleList.begin(), end = styleList.end();
141 KoParagStyle* style =
static_cast<KoParagStyle *
>( *it );
142 m_origStyles.append( style );
143 m_changedStyles.append( style );
144 m_styleOrder<< style->name();
147 frame1Layout->addMultiCellWidget( m_stylesList, 0, 0, 0, 1 );
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 );
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 );
161 m_deleteButton =
new TQPushButton( frame1,
"deleteButton" );
162 m_deleteButton->setText( i18n(
"&Delete" ) );
163 connect( m_deleteButton, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( deleteStyle() ) );
165 frame1Layout->addWidget( m_deleteButton, 2, 1 );
167 m_newButton =
new TQPushButton( frame1,
"newButton" );
168 m_newButton->setText( i18n(
"New" ) );
169 connect( m_newButton, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( addStyle() ) );
171 frame1Layout->addWidget( m_newButton, 2, 0 );
173 m_tabs =
new TQTabWidget( frame1 );
174 frame1Layout->addMultiCellWidget( m_tabs, 0, 2, 2, 2 );
176 connect( m_stylesList, TQ_SIGNAL( selectionChanged() ),
this, TQ_SLOT( switchStyle() ) );
177 connect( m_tabs, TQ_SIGNAL( currentChanged ( TQWidget * ) ),
this, TQ_SLOT( switchTabs() ) );
180void KoStyleManager::addGeneralTab(
int flags ) {
181 TQWidget *tab =
new TQWidget( m_tabs );
183 TQGridLayout *tabLayout =
new TQGridLayout( tab );
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 &) ) );
191 tabLayout->addWidget( m_nameString, 0, 1 );
193 TQLabel *nameLabel =
new TQLabel( tab );
194 nameLabel->setText( i18n(
"Name:" ) );
195 nameLabel->resize(nameLabel->sizeHint());
196 nameLabel->setAlignment( AlignRight | AlignVCenter );
198 tabLayout->addWidget( nameLabel, 0, 0 );
200 m_styleCombo =
new TQComboBox(
false, tab,
"styleCombo" );
202 tabLayout->addWidget( m_styleCombo, 1, 1 );
204 TQLabel *nextStyleLabel =
new TQLabel( tab );
205 nextStyleLabel->setText( i18n(
"Next style:" ) );
206 nextStyleLabel->setAlignment( AlignRight | AlignVCenter );
208 tabLayout->addWidget( nextStyleLabel, 1, 0 );
210 m_inheritCombo =
new TQComboBox(
false, tab,
"inheritCombo" );
211 tabLayout->addWidget( m_inheritCombo, 2, 1 );
213 TQLabel *inheritStyleLabel =
new TQLabel( tab );
214 inheritStyleLabel->setText( i18n(
"Inherit style:" ) );
215 inheritStyleLabel->setAlignment( AlignRight | AlignVCenter );
217 tabLayout->addWidget( inheritStyleLabel, 2, 0 );
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 );
226 d->cbIncludeInTOC = 0;
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" );
231 tabLayout->addMultiCellWidget( d->preview, row, row, 0, 1 );
233 m_tabs->insertTab( tab, i18n(
"General" ) );
235 m_inheritCombo->insertItem( i18n(
"<None>"));
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));
244void KoStyleManager::switchStyle() {
245 kdDebug(32500) <<
"KoStyleManager::switchStyle noSignals=" << noSignals << endl;
246 if(noSignals)
return;
249 if(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);
260 m_currentStyle = m_changedStyles.at(num);
267void KoStyleManager::switchTabs()
280int KoStyleManager::styleIndex(
int pos ) {
282 for(
unsigned int i=0; i < m_changedStyles.count(); i++) {
284 KoParagStyle * style = m_changedStyles.at(i);
285 if ( !style )
continue;
290 kdWarning() <<
"KoStyleManager::styleIndex no style found at pos " << pos << endl;
293#warning implement undo/redo
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 )
305 it.current()->setStyle( m_currentStyle );
306 it.current()->update();
309 m_nameString->setText(m_currentStyle->displayName());
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;
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;
330 m_inheritCombo->setCurrentItem( 0 );
333 if ( d->cbIncludeInTOC )
334 d->cbIncludeInTOC->setChecked( m_currentStyle->isOutline() );
337 m_deleteButton->setEnabled(m_stylesList->currentItem() != 0);
339 m_moveUpButton->setEnabled(m_stylesList->currentItem() != 0);
340 m_moveDownButton->setEnabled(m_stylesList->currentItem()!=(
int)m_stylesList->count()-1);
345void KoStyleManager::updatePreview()
347 d->preview->setStyle(m_currentStyle);
348 d->preview->repaint(
true);
351void KoStyleManager::save() {
354 TQPtrListIterator<KoStyleManagerTab> it( m_tabsList );
355 for ( ; it.current() ; ++it )
356 it.current()->save();
359 if ( m_currentStyle->name() != m_nameString->text() &&
360 m_currentStyle->displayName() != m_nameString->text() )
362 m_currentStyle->setDisplayName( m_nameString->text() );
365 int indexNextStyle = styleIndex( m_styleCombo->currentItem() );
366 m_currentStyle->setFollowingStyle( m_origStyles.at( indexNextStyle ) );
368 if ( m_inheritCombo->currentItem() == 0 )
369 m_currentStyle->setParentStyle(0);
372 int indexParentStyle=styleIndex( m_inheritCombo->currentItem()-1 );
373 KoParagStyle *parent=m_origStyles.at(indexParentStyle);
375 parent=m_changedStyles.at(indexParentStyle);
377 m_currentStyle->setParentStyle( parent );
380 if ( d->cbIncludeInTOC )
381 m_currentStyle->setOutline( d->cbIncludeInTOC->isChecked() );
385KoParagStyle * KoStyleManager::style(
const TQString & _name )
387 for(
unsigned int i=0; i < m_changedStyles.count(); i++) {
389 KoParagStyle * style = m_changedStyles.at(i);
390 if ( !style )
continue;
391 if ( style->name() == _name)
397TQString KoStyleManager::generateUniqueName()
402 name =
"new" + TQString::number( count++ );
403 }
while ( style( name ) );
408void KoStyleManager::addStyle() {
411 TQString str = i18n(
"New Style Template (%1)" ).arg(numStyles++);
412 if ( m_currentStyle )
414 m_currentStyle =
new KoParagStyle( *m_currentStyle );
415 m_currentStyle->setDisplayName( str );
416 m_currentStyle->setName( generateUniqueName() );
419 m_currentStyle =
new KoParagStyle( str );
420 m_currentStyle->setFollowingStyle( m_currentStyle );
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 );
430 m_styleOrder << m_currentStyle->name();
435void KoStyleManager::updateFollowingStyle(
KoParagStyle *s )
437 for ( KoParagStyle* p = m_changedStyles.first(); p != 0L; p = m_changedStyles.next() )
439 if ( p->followingStyle() == s)
440 p->setFollowingStyle(p);
445void KoStyleManager::updateInheritStyle(
KoParagStyle *s )
447 for ( KoParagStyle* p = m_changedStyles.first(); p != 0L; p = m_changedStyles.next() )
452 if ( p->parentStyle() == s)
453 p->setParentStyle(0L);
458void KoStyleManager::deleteStyle() {
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 );
470 m_changedStyles.remove(cur);
471 m_changedStyles.insert(cur,0L);
475 m_stylesList->removeItem(curItem);
476 m_styleCombo->removeItem(curItem);
478 m_inheritCombo->listBox()->removeItem( m_inheritCombo->listBox()->index(m_inheritCombo->listBox()->findItem(name )));
481 m_stylesList->setSelected( m_stylesList->currentItem(),
true );
484void KoStyleManager::moveUpStyle()
486 Q_ASSERT( m_currentStyle );
487 if ( m_currentStyle )
489 const TQString currentStyleName = m_currentStyle->name();
490 const TQString currentStyleDisplayName = m_stylesList->currentText();
491 int pos2 = m_styleOrder.findIndex( currentStyleName );
494 m_styleOrder.remove( m_styleOrder.at(pos2));
495 m_styleOrder.insert( m_styleOrder.at(pos2-1), currentStyleName);
498 int pos = m_stylesList->currentItem();
500 m_stylesList->changeItem( m_stylesList->text( pos-1 ), pos );
501 m_styleCombo->changeItem( m_stylesList->text( pos-1 ), pos );
503 m_stylesList->changeItem( currentStyleDisplayName, pos-1 );
504 m_styleCombo->changeItem( currentStyleDisplayName, pos-1 );
506 m_stylesList->setCurrentItem( m_stylesList->currentItem() );
512void KoStyleManager::moveDownStyle()
514 Q_ASSERT( m_currentStyle );
515 if ( m_currentStyle )
517 const TQString currentStyleName = m_currentStyle->name();
518 const TQString currentStyleDisplayName = m_stylesList->currentText();
519 int pos2 = m_styleOrder.findIndex( currentStyleName );
522 m_styleOrder.remove( m_styleOrder.at(pos2));
523 m_styleOrder.insert( m_styleOrder.at(pos2+1), currentStyleName);
526 int pos = m_stylesList->currentItem();
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() );
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) {
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) {
560 kdDebug(32500) <<
"deleting orig " << m_origStyles.at(i)->name() <<
" (" << i <<
")" << endl;
562 KoParagStyle *orig = m_origStyles.at(i);
564 KoStyleChangeDef tmp( -1,-1);
565 styleChanged.insert( orig, tmp);
567 removeStyle.append( orig );
570 }
else if(m_changedStyles.at(i) != 0L && m_origStyles.at(i)!=0L) {
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 )
576 int paragLayoutChanged = orig->paragLayout().
compare( changed->paragLayout() );
586 if ( formatChanged != 0 || paragLayoutChanged != 0 ) {
587 KoStyleChangeDef tmp(paragLayoutChanged, formatChanged);
588 styleChanged.insert( orig, tmp );
597 applyStyleChange( styleChanged );
599 KoParagStyle *tmp = 0L;
600 for ( tmp = removeStyle.first(); tmp ;tmp = removeStyle.next() )
601 removeStyleTemplate( tmp );
603 updateStyleListOrder( m_styleOrder );
604 updateAllStyleLists();
608void KoStyleManager::renameStyle(
const TQString &theText) {
609 if(noSignals)
return;
612 int index = m_stylesList->currentItem();
613 kdDebug(32500) <<
"KoStyleManager::renameStyle " << index <<
" to " << theText << endl;
616 kdDebug(32500) <<
"KoStyleManager::renameStyle before " << m_styleCombo->currentText() << endl;
617 m_styleCombo->changeItem( theText, index );
618 m_inheritCombo->changeItem( theText, index+1 );
620 kdDebug(32500) <<
"KoStyleManager::renameStyle after " << m_styleCombo->currentText() << endl;
621 m_stylesList->changeItem( theText, index );
625 for (
int i = 0; i < m_styleCombo->count(); i++ ) {
626 if ( m_styleCombo->text( i ) == m_stylesList->currentText() )
629 Q_ASSERT( synonyms > 0 );
632 bool state=!theText.isEmpty() && (synonyms == 1);
635 m_deleteButton->setEnabled(state&&(m_stylesList->currentItem() != 0));
636 m_newButton->setEnabled(state);
637 m_stylesList->setEnabled( state );
640 m_moveUpButton->setEnabled(m_stylesList->currentItem() != 0);
641 m_moveDownButton->setEnabled(m_stylesList->currentItem()!=(
int)m_stylesList->count()-1);
645 m_moveUpButton->setEnabled(
false);
646 m_moveDownButton->setEnabled(
false);
652KoStyleParagTab::KoStyleParagTab( TQWidget * parent )
653 : KoStyleManagerTab( parent )
655 (
new TQVBoxLayout(
this ) )->setAutoAdd(
true );
659void KoStyleParagTab::update()
661 m_widget->display( m_style->paragLayout() );
664void KoStyleParagTab::save()
666 m_widget->save( m_style->paragLayout() );
674void KoStyleParagTab::resizeEvent( TQResizeEvent *e )
676 TQWidget::resizeEvent( e );
677 if ( m_widget ) m_widget->resize( size() );
680KoStyleFontTab::KoStyleFontTab( TQWidget * parent )
681 : KoStyleManagerTab( parent )
683 (
new TQVBoxLayout(
this ) )->setAutoAdd(
true );
684 TQTabWidget *fontTabContainer =
new TQTabWidget(
this );
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 );
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" ) );
699KoStyleFontTab::~KoStyleFontTab()
703void KoStyleFontTab::update()
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() );
748void KoStyleFontTab::save()
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()
791TQString KoStyleFontTab::tabName()
void enableButtonApply(bool state)
void enableButtonOK(bool state)
TQFrame * makeMainWidget()
const KoTextFormat & format() const
Return a format.
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,...
TODO rename to KoParagStyleCollection - or should char styles be part of it too?
int compare(const KoTextFormat &format) const
Return a set of flags showing the differences between this and 'format'.
Unit
Length units supported by KOffice.
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.
TQString name() const
The internal name (used for loading/saving, but not shown to the user) Should be unique in a given st...
const char * name(StdAction id)