lib

KoStyleManager.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 
00021 #include "KoStyleCollection.h"
00022 #include "KoStyleManager.h"
00023 #include "KoStyleManager.moc"
00024 #include <KoFontDia.h>
00025 #include <KoGlobal.h>
00026 
00027 #include <klocale.h>
00028 #include <kiconloader.h>
00029 #include <kdebug.h>
00030 
00031 #include <qtabwidget.h>
00032 #include <qpushbutton.h>
00033 #include <qlabel.h>
00034 #include <qcombobox.h>
00035 #include <qcheckbox.h>
00036 #include <qlayout.h>
00037 
00038 /******************************************************************/
00039 /* Class: KoStyleManager                                          */
00040 /******************************************************************/
00041 
00042 /* keep 2 qlists with the styles.
00043    1 of the origs, another with the changed ones (in order of the stylesList)
00044    When an orig entry is empty and the other is not, a new one has to be made,
00045    when the orig is present and the other is not, the orig has to be deleted.
00046    Otherwise all changes are copied from the changed ones to the origs on OK.
00047    OK updates the doc if styles are deleted.
00048    The dtor frees all the changed ones.
00049 */
00050 /* Months later the above seems SOO stupid.. Just should have created a small class
00051    containing the orig and the copy and an enum plus some simple methods..
00052    Well; just keep that for those loonly uninspiring days :) (Thomas Z)
00053 */
00054 class KoStyleManagerPrivate
00055 {
00056 public:
00057     KoStylePreview* preview;
00058     QCheckBox* cbIncludeInTOC;
00059 };
00060 
00061 KoStyleManager::KoStyleManager( QWidget *_parent, KoUnit::Unit unit,
00062                                 const KoStyleCollection& styles, const QString & activeStyleName,
00063                                 int flags )
00064     : KDialogBase( _parent, "Stylist", true,
00065                    i18n("Style Manager"),
00066                    KDialogBase::Ok | KDialogBase::Cancel | KDialogBase::Apply )
00067 {
00068     d = new KoStyleManagerPrivate;
00069     //setWFlags(getWFlags() || WDestructiveClose);
00070     m_currentStyle =0L;
00071     noSignals=true;
00072     m_origStyles.setAutoDelete(false);
00073     m_changedStyles.setAutoDelete(false);
00074     setupWidget(styles); // build the widget with the buttons and the list selector.
00075     addGeneralTab( flags );
00076     KoStyleFontTab * fontTab = new KoStyleFontTab( m_tabs );
00077     addTab( fontTab );
00078 
00079     KoStyleParagTab *newTab = new KoStyleParagTab( m_tabs );
00080     newTab->setWidget( new KoIndentSpacingWidget( unit, -1/*no limit*/,newTab ) );
00081     addTab( newTab );
00082 
00083     newTab = new KoStyleParagTab( m_tabs );
00084     newTab->setWidget( new KoParagAlignWidget( true, newTab ) );
00085     addTab( newTab );
00086 
00087     newTab = new KoStyleParagTab( m_tabs );
00088     KoParagLayoutWidget *decorations = new KoParagDecorationWidget( newTab );
00089     decorations->layout()->setMargin(KDialog::marginHint());
00090     newTab->setWidget( decorations );
00091     addTab( newTab );
00092 
00093     newTab = new KoStyleParagTab( m_tabs );
00094     newTab->setWidget( new KoParagCounterWidget( false , newTab ) );
00095     addTab( newTab );
00096 
00097     newTab = new KoStyleParagTab( m_tabs );
00098     newTab->setWidget( new KoParagTabulatorsWidget( unit, -1, newTab ) );
00099     addTab( newTab );
00100 
00101     QListBoxItem * item = m_stylesList->findItem( activeStyleName );
00102     m_stylesList->setCurrentItem( item ? m_stylesList->index(item) : 0 );
00103 
00104     noSignals=false;
00105     switchStyle();
00106     setInitialSize( QSize( 600, 570 ) );
00107 }
00108 
00109 KoStyleManager::~KoStyleManager()
00110 {
00111     for (unsigned int i =0 ; m_origStyles.count() > i ; i++) {
00112         KoParagStyle *orig = m_origStyles.at(i);
00113         KoParagStyle *changed = m_changedStyles.at(i);
00114         if( orig && changed && orig != changed ) // modified style, we can delete the changed one now that changes have been applied
00115             delete changed;
00116     }
00117 
00118     delete d;
00119 }
00120 
00121 void KoStyleManager::addTab( KoStyleManagerTab * tab )
00122 {
00123     m_tabsList.append( tab );
00124     m_tabs->insertTab( tab, tab->tabName() );
00125     tab->layout()->activate();
00126 }
00127 
00128 void KoStyleManager::setupWidget(const KoStyleCollection& styleCollection)
00129 {
00130     QFrame * frame1 = makeMainWidget();
00131     QGridLayout *frame1Layout = new QGridLayout( frame1, 0, 0, // auto
00132                                                  0, KDialog::spacingHint() );
00133     numStyles = styleCollection.count();
00134     m_stylesList = new QListBox( frame1, "stylesList" );
00135     m_stylesList->insertStringList( styleCollection.displayNameList() );
00136 
00137     const QValueList<KoUserStyle*> styleList = styleCollection.styleList();
00138     for ( QValueList<KoUserStyle *>::const_iterator it = styleList.begin(), end = styleList.end();
00139           it != end ; ++it )
00140     {
00141         KoParagStyle* style = static_cast<KoParagStyle *>( *it );
00142         m_origStyles.append( style );
00143         m_changedStyles.append( style );
00144         m_styleOrder<< style->name();
00145     }
00146 
00147     frame1Layout->addMultiCellWidget( m_stylesList, 0, 0, 0, 1 );
00148 
00149 
00150     m_moveUpButton = new QPushButton( frame1, "moveUpButton" );
00151     m_moveUpButton->setIconSet( SmallIconSet( "up" ) );
00152     connect( m_moveUpButton, SIGNAL( clicked() ), this, SLOT( moveUpStyle() ) );
00153     frame1Layout->addWidget( m_moveUpButton, 1, 1 );
00154 
00155     m_moveDownButton = new QPushButton( frame1, "moveDownButton" );
00156     m_moveDownButton->setIconSet( SmallIconSet( "down" ) );
00157     connect( m_moveDownButton, SIGNAL( clicked() ), this, SLOT( moveDownStyle() ) );
00158     frame1Layout->addWidget( m_moveDownButton, 1, 0 );
00159 
00160 
00161     m_deleteButton = new QPushButton( frame1, "deleteButton" );
00162     m_deleteButton->setText( i18n( "&Delete" ) );
00163     connect( m_deleteButton, SIGNAL( clicked() ), this, SLOT( deleteStyle() ) );
00164 
00165     frame1Layout->addWidget( m_deleteButton, 2, 1 );
00166 
00167     m_newButton = new QPushButton( frame1, "newButton" );
00168     m_newButton->setText( i18n( "New" ) );
00169     connect( m_newButton, SIGNAL( clicked() ), this, SLOT( addStyle() ) );
00170 
00171     frame1Layout->addWidget( m_newButton, 2, 0 );
00172 
00173     m_tabs = new QTabWidget( frame1 );
00174     frame1Layout->addMultiCellWidget( m_tabs, 0, 2, 2, 2 );
00175 
00176     connect( m_stylesList, SIGNAL( selectionChanged() ), this, SLOT( switchStyle() ) );
00177     connect( m_tabs, SIGNAL( currentChanged ( QWidget * ) ), this, SLOT( switchTabs() ) );
00178 }
00179 
00180 void KoStyleManager::addGeneralTab( int flags ) {
00181     QWidget *tab = new QWidget( m_tabs );
00182 
00183     QGridLayout *tabLayout = new QGridLayout( tab );
00184     tabLayout->setSpacing( KDialog::spacingHint() );
00185     tabLayout->setMargin( KDialog::marginHint() );
00186 
00187     m_nameString = new QLineEdit( tab );
00188     m_nameString->resize(m_nameString->sizeHint() );
00189     connect( m_nameString, SIGNAL( textChanged( const QString &) ), this, SLOT( renameStyle(const QString &) ) );
00190 
00191     tabLayout->addWidget( m_nameString, 0, 1 );
00192 
00193     QLabel *nameLabel = new QLabel( tab );
00194     nameLabel->setText( i18n( "Name:" ) );
00195     nameLabel->resize(nameLabel->sizeHint());
00196     nameLabel->setAlignment( AlignRight | AlignVCenter );
00197 
00198     tabLayout->addWidget( nameLabel, 0, 0 );
00199 
00200     m_styleCombo = new QComboBox( FALSE, tab, "styleCombo" );
00201 
00202     tabLayout->addWidget( m_styleCombo, 1, 1 );
00203 
00204     QLabel *nextStyleLabel = new QLabel( tab );
00205     nextStyleLabel->setText( i18n( "Next style:" ) );
00206     nextStyleLabel->setAlignment( AlignRight | AlignVCenter );
00207 
00208     tabLayout->addWidget( nextStyleLabel, 1, 0 );
00209 
00210     m_inheritCombo = new QComboBox( FALSE, tab, "inheritCombo" );
00211     tabLayout->addWidget( m_inheritCombo, 2, 1 );
00212 
00213     QLabel *inheritStyleLabel = new QLabel( tab );
00214     inheritStyleLabel->setText( i18n( "Inherit style:" ) );
00215     inheritStyleLabel->setAlignment( AlignRight | AlignVCenter );
00216 
00217     tabLayout->addWidget( inheritStyleLabel, 2, 0 );
00218 
00219     int row = 3;
00220 
00221     if ( flags & ShowIncludeInToc ) {
00222         d->cbIncludeInTOC = new QCheckBox( i18n("Include in table of contents"), tab );
00223         tabLayout->addMultiCellWidget( d->cbIncludeInTOC, row, row, 0, 1 );
00224         ++row;
00225     } else {
00226         d->cbIncludeInTOC = 0;
00227     }
00228 
00229     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" );
00230 
00231     tabLayout->addMultiCellWidget( d->preview, row, row, 0, 1 );
00232 
00233     m_tabs->insertTab( tab, i18n( "General" ) );
00234 
00235     m_inheritCombo->insertItem( i18n("<None>"));
00236 
00237     for ( unsigned int i = 0; i < m_stylesList->count(); i++ ) {
00238         m_styleCombo->insertItem( m_stylesList->text(i));
00239         m_inheritCombo->insertItem( m_stylesList->text(i));
00240     }
00241 
00242 }
00243 
00244 void KoStyleManager::switchStyle() {
00245     kdDebug(32500) << "KoStyleManager::switchStyle noSignals=" << noSignals << endl;
00246     if(noSignals) return;
00247     noSignals=true;
00248 
00249     if(m_currentStyle !=0L)
00250         save();
00251 
00252     m_currentStyle = 0L;
00253     int num = styleIndex( m_stylesList->currentItem() );
00254     kdDebug(32500) << "KoStyleManager::switchStyle switching to " << num << endl;
00255     if(m_origStyles.at(num) == m_changedStyles.at(num)) {
00256         m_currentStyle = new KoParagStyle( *m_origStyles.at(num) );
00257         m_changedStyles.take(num);
00258         m_changedStyles.insert(num, m_currentStyle);
00259     } else {
00260         m_currentStyle = m_changedStyles.at(num);
00261     }
00262     updateGUI();
00263 
00264     noSignals=false;
00265 }
00266 
00267 void KoStyleManager::switchTabs()
00268 {
00269     // Called when the user switches tabs
00270     // We call save() to update our style, for the preview on the 1st tab
00271     save();
00272     updatePreview();
00273 }
00274 
00275 // Return the index of the a style from its position in the GUI
00276 // (e.g. in m_stylesList or m_styleCombo). This index is used in
00277 // the m_origStyles and m_changedStyles lists.
00278 // The reason for the difference is that a deleted style is removed
00279 // from the GUI but not from the internal lists.
00280 int KoStyleManager::styleIndex( int pos ) {
00281     int p = 0;
00282     for(unsigned int i=0; i < m_changedStyles.count(); i++) {
00283         // Skip deleted styles, they're no in m_stylesList anymore
00284         KoParagStyle * style = m_changedStyles.at(i);
00285         if ( !style ) continue;
00286         if ( p == pos )
00287             return i;
00288         ++p;
00289     }
00290     kdWarning() << "KoStyleManager::styleIndex no style found at pos " << pos << endl;
00291 
00292 #ifdef __GNUC_
00293 #warning implement undo/redo
00294 #endif
00295 
00296     return 0;
00297 }
00298 
00299 // Update the GUI so that it shows m_currentStyle
00300 void KoStyleManager::updateGUI() {
00301     kdDebug(32500) << "KoStyleManager::updateGUI m_currentStyle=" << m_currentStyle << " " << m_currentStyle->name() << endl;
00302     QPtrListIterator<KoStyleManagerTab> it( m_tabsList );
00303     for ( ; it.current() ; ++it )
00304     {
00305         it.current()->setStyle( m_currentStyle );
00306         it.current()->update();
00307     }
00308 
00309     m_nameString->setText(m_currentStyle->displayName());
00310 
00311     QString followingName = m_currentStyle->followingStyle() ? m_currentStyle->followingStyle()->displayName() : QString::null;
00312     kdDebug(32500) << "KoStyleManager::updateGUI updating combo to " << followingName << endl;
00313     for ( int i = 0; i < m_styleCombo->count(); i++ ) {
00314         if ( m_styleCombo->text( i ) == followingName ) {
00315             m_styleCombo->setCurrentItem( i );
00316             kdDebug(32500) << "found at " << i << endl;
00317             break;
00318         }
00319     }
00320 
00321     QString inheritName = m_currentStyle->parentStyle() ? m_currentStyle->parentStyle()->displayName() : QString::null;
00322     kdDebug(32500) << "KoStyleManager::updateGUI updating combo to " << inheritName << endl;
00323     for ( int i = 0; i < m_inheritCombo->count(); i++ ) {
00324         if ( m_inheritCombo->text( i ) == inheritName ) {
00325             m_inheritCombo->setCurrentItem( i );
00326             kdDebug(32500) << "found at " << i << endl;
00327             break;
00328         }
00329         else
00330             m_inheritCombo->setCurrentItem( 0 );//none !!!
00331     }
00332 
00333     if ( d->cbIncludeInTOC )
00334         d->cbIncludeInTOC->setChecked( m_currentStyle->isOutline() );
00335 
00336     // update delete button (can't delete first style);
00337     m_deleteButton->setEnabled(m_stylesList->currentItem() != 0);
00338 
00339     m_moveUpButton->setEnabled(m_stylesList->currentItem() != 0);
00340     m_moveDownButton->setEnabled(m_stylesList->currentItem()!=(int)m_stylesList->count()-1);
00341 
00342     updatePreview();
00343 }
00344 
00345 void KoStyleManager::updatePreview()
00346 {
00347     d->preview->setStyle(m_currentStyle);
00348     d->preview->repaint(true);
00349 }
00350 
00351 void KoStyleManager::save() {
00352     if(m_currentStyle) {
00353         // save changes from UI to object.
00354         QPtrListIterator<KoStyleManagerTab> it( m_tabsList );
00355         for ( ; it.current() ; ++it )
00356             it.current()->save();
00357 
00358     // Rename the style - only if it's actually been renamed.
00359         if ( m_currentStyle->name() != m_nameString->text() &&
00360             m_currentStyle->displayName() != m_nameString->text() )
00361         {
00362             m_currentStyle->setDisplayName( m_nameString->text() );
00363         }
00364 
00365         int indexNextStyle = styleIndex( m_styleCombo->currentItem() );
00366         m_currentStyle->setFollowingStyle( m_origStyles.at( indexNextStyle ) ); // point to orig, not changed! (#47377)
00367         m_currentStyle->setParentStyle( style( m_inheritCombo->currentText() ) );
00368         if ( d->cbIncludeInTOC )
00369             m_currentStyle->setOutline( d->cbIncludeInTOC->isChecked() );
00370     }
00371 }
00372 
00373 KoParagStyle * KoStyleManager::style( const QString & _name )
00374 {
00375     for(unsigned int i=0; i < m_changedStyles.count(); i++) {
00376         // Skip deleted styles, they're no in m_stylesList anymore
00377         KoParagStyle * style = m_changedStyles.at(i);
00378         if ( !style ) continue;
00379         if ( style->name() == _name)
00380             return style;
00381     }
00382     return 0;
00383 }
00384 
00385 QString KoStyleManager::generateUniqueName()
00386 {
00387     int count = 1;
00388     QString name;
00389     do {
00390         name = "new" + QString::number( count++ );
00391     } while ( style( name ) );
00392     return name;
00393 }
00394 
00395 
00396 void KoStyleManager::addStyle() {
00397     save();
00398 
00399     QString str = i18n( "New Style Template (%1)" ).arg(numStyles++);
00400     if ( m_currentStyle )
00401     {
00402         m_currentStyle = new KoParagStyle( *m_currentStyle ); // Create a new style, initializing from the current one
00403         m_currentStyle->setDisplayName( str );
00404         m_currentStyle->setName( generateUniqueName() );
00405     }
00406     else
00407         m_currentStyle = new KoParagStyle( str );
00408     m_currentStyle->setFollowingStyle( m_currentStyle ); // #45868
00409 
00410     noSignals=true;
00411     m_origStyles.append(0L);
00412     m_changedStyles.append(m_currentStyle);
00413     m_stylesList->insertItem( str );
00414     m_styleCombo->insertItem( str );
00415     m_inheritCombo->insertItem( str );
00416     m_stylesList->setCurrentItem( m_stylesList->count() - 1 );
00417     noSignals=false;
00418     m_styleOrder << m_currentStyle->name();
00419 
00420     updateGUI();
00421 }
00422 
00423 void KoStyleManager::updateFollowingStyle( KoParagStyle *s )
00424 {
00425     for ( KoParagStyle* p = m_changedStyles.first(); p != 0L; p = m_changedStyles.next() )
00426     {
00427         if ( p->followingStyle() == s)
00428             p->setFollowingStyle(p);
00429     }
00430 
00431 }
00432 
00433 void KoStyleManager::updateInheritStyle( KoParagStyle *s )
00434 {
00435     for ( KoParagStyle* p = m_changedStyles.first(); p != 0L; p = m_changedStyles.next() )
00436     {
00437         //when we remove style, we must replace inherite style to 0L
00438         //when parent style was removed.
00439         //##########Laurent change inherited style attribute
00440         if ( p->parentStyle() == s)
00441             p->setParentStyle(0L);
00442     }
00443 
00444 }
00445 
00446 void KoStyleManager::deleteStyle() {
00447 
00448     unsigned int cur = styleIndex( m_stylesList->currentItem() );
00449     unsigned int curItem = m_stylesList->currentItem();
00450     QString name = m_stylesList->currentText();
00451     KoParagStyle *s = m_changedStyles.at(cur);
00452     m_styleOrder.remove( s->name());
00453     updateFollowingStyle( s );
00454     updateInheritStyle( s );
00455     Q_ASSERT( s == m_currentStyle );
00456     delete s;
00457     m_currentStyle = 0L;
00458     m_changedStyles.remove(cur);
00459     m_changedStyles.insert(cur,0L);
00460 
00461     // Done with noSignals still false, so that when m_stylesList changes the current item
00462     // we display it automatically
00463     m_stylesList->removeItem(curItem);
00464     m_styleCombo->removeItem(curItem);
00465 
00466     m_inheritCombo->listBox()->removeItem( m_inheritCombo->listBox()->index(m_inheritCombo->listBox()->findItem(name )));
00467 
00468     numStyles--;
00469     m_stylesList->setSelected( m_stylesList->currentItem(), true );
00470 }
00471 
00472 void KoStyleManager::moveUpStyle()
00473 {
00474     Q_ASSERT( m_currentStyle );
00475     if ( m_currentStyle )
00476         save();
00477     const QString currentStyleName = m_currentStyle->name();
00478     const QString currentStyleDisplayName = m_stylesList->currentText();
00479     int pos2 = m_styleOrder.findIndex( currentStyleName );
00480     if ( pos2 != -1 )
00481     {
00482         m_styleOrder.remove( m_styleOrder.at(pos2));
00483         m_styleOrder.insert( m_styleOrder.at(pos2-1), currentStyleName);
00484     }
00485 
00486     int pos = m_stylesList->currentItem();
00487     noSignals=true;
00488     m_stylesList->changeItem( m_stylesList->text( pos-1 ), pos );
00489     m_styleCombo->changeItem( m_stylesList->text( pos-1 ), pos );
00490 
00491     m_stylesList->changeItem( currentStyleDisplayName, pos-1 );
00492     m_styleCombo->changeItem( currentStyleDisplayName, pos-1 );
00493 
00494     m_stylesList->setCurrentItem( m_stylesList->currentItem() );
00495     noSignals=false;
00496 
00497     updateGUI();
00498 }
00499 
00500 void KoStyleManager::moveDownStyle()
00501 {
00502     Q_ASSERT( m_currentStyle );
00503     if ( m_currentStyle )
00504         save();
00505     const QString currentStyleName = m_currentStyle->name();
00506     const QString currentStyleDisplayName = m_stylesList->currentText();
00507     int pos2 = m_styleOrder.findIndex( currentStyleName );
00508     if ( pos2 != -1 )
00509     {
00510         m_styleOrder.remove( m_styleOrder.at(pos2));
00511         m_styleOrder.insert( m_styleOrder.at(pos2+1), currentStyleName);
00512     }
00513 
00514     int pos = m_stylesList->currentItem();
00515     noSignals=true;
00516     m_stylesList->changeItem( m_stylesList->text( pos+1 ), pos );
00517     m_styleCombo->changeItem( m_stylesList->text( pos+1 ), pos );
00518     m_stylesList->changeItem( currentStyleDisplayName, pos+1 );
00519     m_styleCombo->changeItem( currentStyleDisplayName, pos+1 );
00520     m_stylesList->setCurrentItem( m_stylesList->currentItem() );
00521     noSignals=false;
00522 
00523     updateGUI();
00524 }
00525 
00526 void KoStyleManager::slotOk() {
00527     save();
00528     apply();
00529     KDialogBase::slotOk();
00530 }
00531 
00532 void KoStyleManager::slotApply() {
00533     save();
00534     apply();
00535     KDialogBase::slotApply();
00536 }
00537 
00538 void KoStyleManager::apply() {
00539     noSignals=true;
00540     KoStyleChangeDefMap styleChanged;
00541     QPtrList<KoParagStyle> removeStyle;
00542     for (unsigned int i =0 ; m_origStyles.count() > i ; i++) {
00543         if(m_origStyles.at(i) == 0L && m_changedStyles.at(i)!=0L) {           // newly added style
00544             kdDebug(32500) << "adding new " << m_changedStyles.at(i)->name() << " (" << i << ")" << endl;
00545             KoParagStyle *tmp = addStyleTemplate(m_changedStyles.take(i));
00546             m_changedStyles.insert(i, tmp);
00547         } else if(m_changedStyles.at(i) == 0L && m_origStyles.at(i) != 0L) { // deleted style
00548             kdDebug(32500) << "deleting orig " << m_origStyles.at(i)->name() << " (" << i << ")" << endl;
00549 
00550             KoParagStyle *orig = m_origStyles.at(i);
00551             //applyStyleChange( orig, -1, -1 );
00552             KoStyleChangeDef tmp( -1,-1);
00553             styleChanged.insert( orig, tmp);
00554 
00555             removeStyle.append( orig );
00556             // Note that the style is never deleted (we'll need it for undo/redo purposes)
00557 
00558         } else if(m_changedStyles.at(i) != 0L && m_origStyles.at(i)!=0L) { // simply updated style
00559             kdDebug(32500) << "update style " << m_changedStyles.at(i)->name() << " (" << i << ")" << endl;
00560             KoParagStyle *orig = m_origStyles.at(i);
00561             KoParagStyle *changed = m_changedStyles.at(i);
00562             if ( orig != changed )
00563             {
00564                 int paragLayoutChanged = orig->paragLayout().compare( changed->paragLayout() );
00565                 int formatChanged = orig->format().compare( changed->format() );
00566                 //kdDebug(32500) << "old format " << orig->format().key() << " pointsize " << orig->format().pointSizeFloat() << endl;
00567                 //kdDebug(32500) << "new format " << changed->format().key() << " pointsize " << changed->format().pointSizeFloat() << endl;
00568 
00569                 // Copy everything from changed to orig
00570                 *orig = *changed;
00571 
00572                 // Apply the change selectively - i.e. only what changed
00573                 //applyStyleChange( orig, paragLayoutChanged, formatChanged );
00574                 if ( formatChanged != 0 || paragLayoutChanged != 0 ) {
00575                     KoStyleChangeDef tmp(paragLayoutChanged, formatChanged);
00576                     styleChanged.insert( orig, tmp );
00577                 }
00578 
00579             }
00580 
00581         }// else
00582          //     kdDebug(32500) << "has not changed " <<  m_changedStyles.at(i)->name() << " (" << i << ")" <<  endl;
00583     }
00584 
00585     applyStyleChange( styleChanged );
00586 
00587     KoParagStyle *tmp = 0L;
00588     for ( tmp = removeStyle.first(); tmp ;tmp = removeStyle.next() )
00589         removeStyleTemplate( tmp );
00590 
00591     updateStyleListOrder( m_styleOrder );
00592     updateAllStyleLists();
00593     noSignals=false;
00594 }
00595 
00596 void KoStyleManager::renameStyle(const QString &theText) {
00597     if(noSignals) return;
00598     noSignals=true;
00599 
00600     int index = m_stylesList->currentItem();
00601     kdDebug(32500) << "KoStyleManager::renameStyle " << index << " to " << theText << endl;
00602 
00603     // rename only in the GUI, not even in the underlying objects (save() does it).
00604     kdDebug(32500) << "KoStyleManager::renameStyle before " << m_styleCombo->currentText() << endl;
00605     m_styleCombo->changeItem( theText, index );
00606     m_inheritCombo->changeItem( theText, index+1 );
00607     //m_styleOrder[index]=theText; // not needed anymore, we use internal names
00608     kdDebug(32500) << "KoStyleManager::renameStyle after " << m_styleCombo->currentText() << endl;
00609     m_stylesList->changeItem( theText, index );
00610 
00611     // Check how many styles with that name we have now
00612     int synonyms = 0;
00613     for ( int i = 0; i < m_styleCombo->count(); i++ ) {
00614         if ( m_styleCombo->text( i ) == m_stylesList->currentText() )
00615             ++synonyms;
00616     }
00617     Q_ASSERT( synonyms > 0 ); // should have found 'index' at least !
00618     noSignals=false;
00619     // Can't close the dialog if two styles have the same name
00620     bool state=!theText.isEmpty() && (synonyms == 1);
00621     enableButtonOK(state );
00622     enableButtonApply(state);
00623     m_deleteButton->setEnabled(state&&(m_stylesList->currentItem() != 0));
00624     m_newButton->setEnabled(state);
00625     m_stylesList->setEnabled( state );
00626     if ( state )
00627     {
00628         m_moveUpButton->setEnabled(m_stylesList->currentItem() != 0);
00629         m_moveDownButton->setEnabled(m_stylesList->currentItem()!=(int)m_stylesList->count()-1);
00630     }
00631     else
00632     {
00633         m_moveUpButton->setEnabled(false);
00634         m_moveDownButton->setEnabled(false);
00635     }
00636 }
00637 
00639 
00640 KoStyleParagTab::KoStyleParagTab( QWidget * parent )
00641     : KoStyleManagerTab( parent )
00642 {
00643     ( new QVBoxLayout( this ) )->setAutoAdd( true );
00644     m_widget = 0L;
00645 }
00646 
00647 void KoStyleParagTab::update()
00648 {
00649      m_widget->display( m_style->paragLayout() );
00650 }
00651 
00652 void KoStyleParagTab::save()
00653 {
00654      m_widget->save( m_style->paragLayout() );
00655 }
00656 
00657 void KoStyleParagTab::setWidget( KoParagLayoutWidget * widget )
00658 {
00659     m_widget = widget;
00660 }
00661 
00662 void KoStyleParagTab::resizeEvent( QResizeEvent *e )
00663 {
00664     QWidget::resizeEvent( e );
00665     if ( m_widget ) m_widget->resize( size() );
00666 }
00667 
00668 KoStyleFontTab::KoStyleFontTab( QWidget * parent )
00669     : KoStyleManagerTab( parent )
00670 {
00671     ( new QVBoxLayout( this ) )->setAutoAdd( true );
00672     QTabWidget *fontTabContainer = new QTabWidget( this );
00673 
00674     m_fontTab = new KoFontTab( KFontChooser::SmoothScalableFonts, this );
00675     m_decorationTab = new KoDecorationTab( this );
00676     m_highlightingTab = new KoHighlightingTab( this );
00677     m_layoutTab = new KoLayoutTab( true, this );
00678     m_languageTab = new KoLanguageTab( 0, this );
00679 
00680     fontTabContainer->addTab( m_fontTab, i18n( "Font" ) );
00681     fontTabContainer->addTab( m_decorationTab, i18n( "Decoration" ) );
00682     fontTabContainer->addTab( m_highlightingTab, i18n( "Highlighting" ) );
00683     fontTabContainer->addTab( m_layoutTab, i18n( "Layout" ) );
00684     fontTabContainer->addTab( m_languageTab, i18n( "Language" ) );
00685 }
00686 
00687 KoStyleFontTab::~KoStyleFontTab()
00688 {
00689 }
00690 
00691 void KoStyleFontTab::update()
00692 {
00693     m_fontTab->setSelection( m_style->format().font() );
00694     m_highlightingTab->setUnderline( m_style->format().underlineType() );
00695     m_highlightingTab->setUnderlineStyle( m_style->format().underlineStyle() );
00696     m_highlightingTab->setUnderlineColor( m_style->format().textUnderlineColor() );
00697     m_highlightingTab->setStrikethrough( m_style->format().strikeOutType() );
00698     m_highlightingTab->setStrikethroughStyle( m_style->format().strikeOutStyle() );
00699     m_highlightingTab->setWordByWord( m_style->format().wordByWord() );
00700     m_highlightingTab->setCapitalisation( m_style->format().attributeFont() );
00701     m_decorationTab->setTextColor( m_style->format().color() );
00702     m_decorationTab->setBackgroundColor( m_style->format().textBackgroundColor() );
00703     m_decorationTab->setShadow( m_style->format().shadowDistanceX(), m_style->format().shadowDistanceY(), m_style->format().shadowColor() );
00704     m_layoutTab->setSubSuperScript( m_style->format().vAlign(), m_style->format().offsetFromBaseLine(), m_style->format().relativeTextSize() );
00705     m_layoutTab->setAutoHyphenation( m_style->format().hyphenation() );
00706     m_languageTab->setLanguage( m_style->format().language() );
00707 /*
00708 #if 0
00709     bool subScript = m_style->format().vAlign() == KoTextFormat::AlignSubScript;
00710     bool superScript = m_style->format().vAlign() == KoTextFormat::AlignSuperScript;
00711     QFont fn = m_style->format().font();
00712     kdDebug()<<" fn.bold() :"<<fn.bold()<<" fn.italic():"<<fn.italic()<<endl;
00713     kdDebug()<<" fn.family() :"<<fn.family()<<endl;
00714     m_chooser->setFont( fn, subScript, superScript );
00715     m_chooser->setColor( m_style->format().color() );
00716     QColor col=m_style->format().textBackgroundColor();
00717     col=col.isValid() ? col : QApplication::palette().color( QPalette::Active, QColorGroup::Base );
00718     m_chooser->setBackGroundColor(col);
00719 
00720     m_chooser->setUnderlineColor( m_style->format().textUnderlineColor());
00721 
00722     m_chooser->setUnderlineType(m_style->format().underlineType());
00723     m_chooser->setUnderlineStyle(m_style->format().underlineStyle());
00724     m_chooser->setStrikeOutStyle(m_style->format().strikeOutStyle());
00725     m_chooser->setStrikeOutlineType(m_style->format().strikeOutType());
00726     m_chooser->setShadowText( m_style->format().shadowText());
00727     m_chooser->setFontAttribute( m_style->format().attributeFont());
00728     m_chooser->setWordByWord( m_style->format().wordByWord());
00729     m_chooser->setRelativeTextSize( m_style->format().relativeTextSize());
00730     m_chooser->setOffsetFromBaseLine( m_style->format().offsetFromBaseLine());
00731     m_chooser->setLanguage( m_style->format().language());
00732     m_chooser->setHyphenation( m_style->format().hyphenation());
00733 #endif
00734 */}
00735 
00736 void KoStyleFontTab::save()
00737 {
00738     m_style->format() = KoTextFormat( m_fontTab->getSelection(),
00739                          m_layoutTab->getSubSuperScript(),
00740                          m_decorationTab->getTextColor(),
00741                          m_decorationTab->getBackgroundColor(),
00742                          m_highlightingTab->getUnderlineColor(),
00743                          m_highlightingTab->getUnderline(),
00744                          m_highlightingTab->getUnderlineStyle(),
00745                          m_highlightingTab->getStrikethrough(),
00746                          m_highlightingTab->getStrikethroughStyle(),
00747                          m_highlightingTab->getCapitalisation(),
00748                          m_languageTab->getLanguage(),
00749                          m_layoutTab->getRelativeTextSize(),
00750                          m_layoutTab->getOffsetFromBaseline(),
00751                          m_highlightingTab->getWordByWord(),
00752                          m_layoutTab->getAutoHyphenation(),
00753                          m_decorationTab->getShadowDistanceX(),
00754                          m_decorationTab->getShadowDistanceY(),
00755                          m_decorationTab->getShadowColor()
00756             );
00757 /*
00758     m_style->format().setFont( m_fontTab->getSelection() );
00759     m_style->format().setColor( m_decorationTab->getTextColor() );
00760     if( m_decorationTab->getBackGroundColor()!=QApplication::palette().color( QPalette::Active, QColorGroup::Base ))
00761         m_style->format().setTextBackgroundColor( m_decorationTab->getBackGroundColor() );
00762 
00763     m_style->format().setTextUnderlineColor(m_chooser->underlineColor());
00764     m_style->format().setUnderlineType (m_chooser->getUnderlineType());
00765     m_style->format().setUnderlineStyle (m_chooser->getUnderlineStyle());
00766     m_style->format().setStrikeOutStyle( m_chooser->getStrikeOutStyle() );
00767     m_style->format().setStrikeOutType (m_chooser->getStrikeOutType());
00768     m_style->format().setShadowText(m_chooser->getShadowText());
00769     m_style->format().setWordByWord( m_chooser->getWordByWord());
00770     m_style->format().setRelativeTextSize( m_chooser->getRelativeTextSize());
00771     m_style->format().setAttributeFont( m_chooser->getFontAttribute());
00772     m_style->format().setOffsetFromBaseLine( m_chooser->getOffsetFromBaseLine());
00773     m_style->format().setVAlign( m_layoutTab->getSubSuperScript() );
00774 
00775     m_style->format().setLanguage( m_chooser->getLanguage());
00776     m_style->format().setHyphenation( m_chooser->getHyphenation());
00777 */}
00778 
00779 QString KoStyleFontTab::tabName()
00780 {
00781     return i18n("Font");
00782 }
KDE Home | KDE Accessibility Home | Description of Access Keys