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 
00368         if ( m_inheritCombo->currentItem() == 0 )  //<None> selected
00369           m_currentStyle->setParentStyle(0);
00370         else
00371         {
00372           int indexParentStyle=styleIndex( m_inheritCombo->currentItem()-1 );
00373           KoParagStyle *parent=m_origStyles.at(indexParentStyle);
00374           if( parent==0L )  //If not found in the orig list (means its a new Style) look in the changeStyles list
00375             parent=m_changedStyles.at(indexParentStyle);
00376 
00377             m_currentStyle->setParentStyle( parent );
00378         }
00379 
00380         if ( d->cbIncludeInTOC )
00381             m_currentStyle->setOutline( d->cbIncludeInTOC->isChecked() );
00382     }
00383 }
00384 
00385 KoParagStyle * KoStyleManager::style( const QString & _name )
00386 {
00387     for(unsigned int i=0; i < m_changedStyles.count(); i++) {
00388         // Skip deleted styles, they're no in m_stylesList anymore
00389         KoParagStyle * style = m_changedStyles.at(i);
00390         if ( !style ) continue;
00391         if ( style->name() == _name)
00392             return style;
00393     }
00394     return 0;
00395 }
00396 
00397 QString KoStyleManager::generateUniqueName()
00398 {
00399     int count = 1;
00400     QString name;
00401     do {
00402         name = "new" + QString::number( count++ );
00403     } while ( style( name ) );
00404     return name;
00405 }
00406 
00407 
00408 void KoStyleManager::addStyle() {
00409     save();
00410 
00411     QString str = i18n( "New Style Template (%1)" ).arg(numStyles++);
00412     if ( m_currentStyle )
00413     {
00414         m_currentStyle = new KoParagStyle( *m_currentStyle ); // Create a new style, initializing from the current one
00415         m_currentStyle->setDisplayName( str );
00416         m_currentStyle->setName( generateUniqueName() );
00417     }
00418     else
00419         m_currentStyle = new KoParagStyle( str );
00420     m_currentStyle->setFollowingStyle( m_currentStyle ); // #45868
00421 
00422     noSignals=true;
00423     m_origStyles.append(0L);
00424     m_changedStyles.append(m_currentStyle);
00425     m_stylesList->insertItem( str );
00426     m_styleCombo->insertItem( str );
00427     m_inheritCombo->insertItem( str );
00428     m_stylesList->setCurrentItem( m_stylesList->count() - 1 );
00429     noSignals=false;
00430     m_styleOrder << m_currentStyle->name();
00431 
00432     updateGUI();
00433 }
00434 
00435 void KoStyleManager::updateFollowingStyle( KoParagStyle *s )
00436 {
00437     for ( KoParagStyle* p = m_changedStyles.first(); p != 0L; p = m_changedStyles.next() )
00438     {
00439         if ( p->followingStyle() == s)
00440             p->setFollowingStyle(p);
00441     }
00442 
00443 }
00444 
00445 void KoStyleManager::updateInheritStyle( KoParagStyle *s )
00446 {
00447     for ( KoParagStyle* p = m_changedStyles.first(); p != 0L; p = m_changedStyles.next() )
00448     {
00449         //when we remove style, we must replace inherite style to 0L
00450         //when parent style was removed.
00451         //##########Laurent change inherited style attribute
00452         if ( p->parentStyle() == s)
00453             p->setParentStyle(0L);
00454     }
00455 
00456 }
00457 
00458 void KoStyleManager::deleteStyle() {
00459 
00460     unsigned int cur = styleIndex( m_stylesList->currentItem() );
00461     unsigned int curItem = m_stylesList->currentItem();
00462     QString name = m_stylesList->currentText();
00463     KoParagStyle *s = m_changedStyles.at(cur);
00464     m_styleOrder.remove( s->name());
00465     updateFollowingStyle( s );
00466     updateInheritStyle( s );
00467     Q_ASSERT( s == m_currentStyle );
00468     delete s;
00469     m_currentStyle = 0L;
00470     m_changedStyles.remove(cur);
00471     m_changedStyles.insert(cur,0L);
00472 
00473     // Done with noSignals still false, so that when m_stylesList changes the current item
00474     // we display it automatically
00475     m_stylesList->removeItem(curItem);
00476     m_styleCombo->removeItem(curItem);
00477 
00478     m_inheritCombo->listBox()->removeItem( m_inheritCombo->listBox()->index(m_inheritCombo->listBox()->findItem(name )));
00479 
00480     numStyles--;
00481     m_stylesList->setSelected( m_stylesList->currentItem(), true );
00482 }
00483 
00484 void KoStyleManager::moveUpStyle()
00485 {
00486     Q_ASSERT( m_currentStyle );
00487     if ( m_currentStyle )
00488         save();
00489     const QString currentStyleName = m_currentStyle->name();
00490     const QString currentStyleDisplayName = m_stylesList->currentText();
00491     int pos2 = m_styleOrder.findIndex( currentStyleName );
00492     if ( pos2 != -1 )
00493     {
00494         m_styleOrder.remove( m_styleOrder.at(pos2));
00495         m_styleOrder.insert( m_styleOrder.at(pos2-1), currentStyleName);
00496     }
00497 
00498     int pos = m_stylesList->currentItem();
00499     noSignals=true;
00500     m_stylesList->changeItem( m_stylesList->text( pos-1 ), pos );
00501     m_styleCombo->changeItem( m_stylesList->text( pos-1 ), pos );
00502 
00503     m_stylesList->changeItem( currentStyleDisplayName, pos-1 );
00504     m_styleCombo->changeItem( currentStyleDisplayName, pos-1 );
00505 
00506     m_stylesList->setCurrentItem( m_stylesList->currentItem() );
00507     noSignals=false;
00508 
00509     updateGUI();
00510 }
00511 
00512 void KoStyleManager::moveDownStyle()
00513 {
00514     Q_ASSERT( m_currentStyle );
00515     if ( m_currentStyle )
00516         save();
00517     const QString currentStyleName = m_currentStyle->name();
00518     const QString currentStyleDisplayName = m_stylesList->currentText();
00519     int pos2 = m_styleOrder.findIndex( currentStyleName );
00520     if ( pos2 != -1 )
00521     {
00522         m_styleOrder.remove( m_styleOrder.at(pos2));
00523         m_styleOrder.insert( m_styleOrder.at(pos2+1), currentStyleName);
00524     }
00525 
00526     int pos = m_stylesList->currentItem();
00527     noSignals=true;
00528     m_stylesList->changeItem( m_stylesList->text( pos+1 ), pos );
00529     m_styleCombo->changeItem( m_stylesList->text( pos+1 ), pos );
00530     m_stylesList->changeItem( currentStyleDisplayName, pos+1 );
00531     m_styleCombo->changeItem( currentStyleDisplayName, pos+1 );
00532     m_stylesList->setCurrentItem( m_stylesList->currentItem() );
00533     noSignals=false;
00534 
00535     updateGUI();
00536 }
00537 
00538 void KoStyleManager::slotOk() {
00539     save();
00540     apply();
00541     KDialogBase::slotOk();
00542 }
00543 
00544 void KoStyleManager::slotApply() {
00545     save();
00546     apply();
00547     KDialogBase::slotApply();
00548 }
00549 
00550 void KoStyleManager::apply() {
00551     noSignals=true;
00552     KoStyleChangeDefMap styleChanged;
00553     QPtrList<KoParagStyle> removeStyle;
00554     for (unsigned int i =0 ; m_origStyles.count() > i ; i++) {
00555         if(m_origStyles.at(i) == 0L && m_changedStyles.at(i)!=0L) {           // newly added style
00556             kdDebug(32500) << "adding new " << m_changedStyles.at(i)->name() << " (" << i << ")" << endl;
00557             KoParagStyle *tmp = addStyleTemplate(m_changedStyles.take(i));
00558             m_changedStyles.insert(i, tmp);
00559         } else if(m_changedStyles.at(i) == 0L && m_origStyles.at(i) != 0L) { // deleted style
00560             kdDebug(32500) << "deleting orig " << m_origStyles.at(i)->name() << " (" << i << ")" << endl;
00561 
00562             KoParagStyle *orig = m_origStyles.at(i);
00563             //applyStyleChange( orig, -1, -1 );
00564             KoStyleChangeDef tmp( -1,-1);
00565             styleChanged.insert( orig, tmp);
00566 
00567             removeStyle.append( orig );
00568             // Note that the style is never deleted (we'll need it for undo/redo purposes)
00569 
00570         } else if(m_changedStyles.at(i) != 0L && m_origStyles.at(i)!=0L) { // simply updated style
00571             kdDebug(32500) << "update style " << m_changedStyles.at(i)->name() << " (" << i << ")" << endl;
00572             KoParagStyle *orig = m_origStyles.at(i);
00573             KoParagStyle *changed = m_changedStyles.at(i);
00574             if ( orig != changed )
00575             {
00576                 int paragLayoutChanged = orig->paragLayout().compare( changed->paragLayout() );
00577                 int formatChanged = orig->format().compare( changed->format() );
00578                 //kdDebug(32500) << "old format " << orig->format().key() << " pointsize " << orig->format().pointSizeFloat() << endl;
00579                 //kdDebug(32500) << "new format " << changed->format().key() << " pointsize " << changed->format().pointSizeFloat() << endl;
00580 
00581                 // Copy everything from changed to orig
00582                 *orig = *changed;
00583 
00584                 // Apply the change selectively - i.e. only what changed
00585                 //applyStyleChange( orig, paragLayoutChanged, formatChanged );
00586                 if ( formatChanged != 0 || paragLayoutChanged != 0 ) {
00587                     KoStyleChangeDef tmp(paragLayoutChanged, formatChanged);
00588                     styleChanged.insert( orig, tmp );
00589                 }
00590 
00591             }
00592 
00593         }// else
00594          //     kdDebug(32500) << "has not changed " <<  m_changedStyles.at(i)->name() << " (" << i << ")" <<  endl;
00595     }
00596 
00597     applyStyleChange( styleChanged );
00598 
00599     KoParagStyle *tmp = 0L;
00600     for ( tmp = removeStyle.first(); tmp ;tmp = removeStyle.next() )
00601         removeStyleTemplate( tmp );
00602 
00603     updateStyleListOrder( m_styleOrder );
00604     updateAllStyleLists();
00605     noSignals=false;
00606 }
00607 
00608 void KoStyleManager::renameStyle(const QString &theText) {
00609     if(noSignals) return;
00610     noSignals=true;
00611 
00612     int index = m_stylesList->currentItem();
00613     kdDebug(32500) << "KoStyleManager::renameStyle " << index << " to " << theText << endl;
00614 
00615     // rename only in the GUI, not even in the underlying objects (save() does it).
00616     kdDebug(32500) << "KoStyleManager::renameStyle before " << m_styleCombo->currentText() << endl;
00617     m_styleCombo->changeItem( theText, index );
00618     m_inheritCombo->changeItem( theText, index+1 );
00619     //m_styleOrder[index]=theText; // not needed anymore, we use internal names
00620     kdDebug(32500) << "KoStyleManager::renameStyle after " << m_styleCombo->currentText() << endl;
00621     m_stylesList->changeItem( theText, index );
00622 
00623     // Check how many styles with that name we have now
00624     int synonyms = 0;
00625     for ( int i = 0; i < m_styleCombo->count(); i++ ) {
00626         if ( m_styleCombo->text( i ) == m_stylesList->currentText() )
00627             ++synonyms;
00628     }
00629     Q_ASSERT( synonyms > 0 ); // should have found 'index' at least !
00630     noSignals=false;
00631     // Can't close the dialog if two styles have the same name
00632     bool state=!theText.isEmpty() && (synonyms == 1);
00633     enableButtonOK(state );
00634     enableButtonApply(state);
00635     m_deleteButton->setEnabled(state&&(m_stylesList->currentItem() != 0));
00636     m_newButton->setEnabled(state);
00637     m_stylesList->setEnabled( state );
00638     if ( state )
00639     {
00640         m_moveUpButton->setEnabled(m_stylesList->currentItem() != 0);
00641         m_moveDownButton->setEnabled(m_stylesList->currentItem()!=(int)m_stylesList->count()-1);
00642     }
00643     else
00644     {
00645         m_moveUpButton->setEnabled(false);
00646         m_moveDownButton->setEnabled(false);
00647     }
00648 }
00649 
00651 
00652 KoStyleParagTab::KoStyleParagTab( QWidget * parent )
00653     : KoStyleManagerTab( parent )
00654 {
00655     ( new QVBoxLayout( this ) )->setAutoAdd( true );
00656     m_widget = 0L;
00657 }
00658 
00659 void KoStyleParagTab::update()
00660 {
00661      m_widget->display( m_style->paragLayout() );
00662 }
00663 
00664 void KoStyleParagTab::save()
00665 {
00666      m_widget->save( m_style->paragLayout() );
00667 }
00668 
00669 void KoStyleParagTab::setWidget( KoParagLayoutWidget * widget )
00670 {
00671     m_widget = widget;
00672 }
00673 
00674 void KoStyleParagTab::resizeEvent( QResizeEvent *e )
00675 {
00676     QWidget::resizeEvent( e );
00677     if ( m_widget ) m_widget->resize( size() );
00678 }
00679 
00680 KoStyleFontTab::KoStyleFontTab( QWidget * parent )
00681     : KoStyleManagerTab( parent )
00682 {
00683     ( new QVBoxLayout( this ) )->setAutoAdd( true );
00684     QTabWidget *fontTabContainer = new QTabWidget( this );
00685 
00686     m_fontTab = new KoFontTab( KFontChooser::SmoothScalableFonts, this );
00687     m_decorationTab = new KoDecorationTab( this );
00688     m_highlightingTab = new KoHighlightingTab( this );
00689     m_layoutTab = new KoLayoutTab( true, this );
00690     m_languageTab = new KoLanguageTab( 0, this );
00691 
00692     fontTabContainer->addTab( m_fontTab, i18n( "Font" ) );
00693     fontTabContainer->addTab( m_decorationTab, i18n( "Decoration" ) );
00694     fontTabContainer->addTab( m_highlightingTab, i18n( "Highlighting" ) );
00695     fontTabContainer->addTab( m_layoutTab, i18n( "Layout" ) );
00696     fontTabContainer->addTab( m_languageTab, i18n( "Language" ) );
00697 }
00698 
00699 KoStyleFontTab::~KoStyleFontTab()
00700 {
00701 }
00702 
00703 void KoStyleFontTab::update()
00704 {
00705     m_fontTab->setSelection( m_style->format().font() );
00706     m_highlightingTab->setUnderline( m_style->format().underlineType() );
00707     m_highlightingTab->setUnderlineStyle( m_style->format().underlineStyle() );
00708     m_highlightingTab->setUnderlineColor( m_style->format().textUnderlineColor() );
00709     m_highlightingTab->setStrikethrough( m_style->format().strikeOutType() );
00710     m_highlightingTab->setStrikethroughStyle( m_style->format().strikeOutStyle() );
00711     m_highlightingTab->setWordByWord( m_style->format().wordByWord() );
00712     m_highlightingTab->setCapitalisation( m_style->format().attributeFont() );
00713     m_decorationTab->setTextColor( m_style->format().color() );
00714     m_decorationTab->setBackgroundColor( m_style->format().textBackgroundColor() );
00715     m_decorationTab->setShadow( m_style->format().shadowDistanceX(), m_style->format().shadowDistanceY(), m_style->format().shadowColor() );
00716     m_layoutTab->setSubSuperScript( m_style->format().vAlign(), m_style->format().offsetFromBaseLine(), m_style->format().relativeTextSize() );
00717     m_layoutTab->setAutoHyphenation( m_style->format().hyphenation() );
00718     m_languageTab->setLanguage( m_style->format().language() );
00719 /*
00720 #if 0
00721     bool subScript = m_style->format().vAlign() == KoTextFormat::AlignSubScript;
00722     bool superScript = m_style->format().vAlign() == KoTextFormat::AlignSuperScript;
00723     QFont fn = m_style->format().font();
00724     kdDebug()<<" fn.bold() :"<<fn.bold()<<" fn.italic():"<<fn.italic()<<endl;
00725     kdDebug()<<" fn.family() :"<<fn.family()<<endl;
00726     m_chooser->setFont( fn, subScript, superScript );
00727     m_chooser->setColor( m_style->format().color() );
00728     QColor col=m_style->format().textBackgroundColor();
00729     col=col.isValid() ? col : QApplication::palette().color( QPalette::Active, QColorGroup::Base );
00730     m_chooser->setBackGroundColor(col);
00731 
00732     m_chooser->setUnderlineColor( m_style->format().textUnderlineColor());
00733 
00734     m_chooser->setUnderlineType(m_style->format().underlineType());
00735     m_chooser->setUnderlineStyle(m_style->format().underlineStyle());
00736     m_chooser->setStrikeOutStyle(m_style->format().strikeOutStyle());
00737     m_chooser->setStrikeOutlineType(m_style->format().strikeOutType());
00738     m_chooser->setShadowText( m_style->format().shadowText());
00739     m_chooser->setFontAttribute( m_style->format().attributeFont());
00740     m_chooser->setWordByWord( m_style->format().wordByWord());
00741     m_chooser->setRelativeTextSize( m_style->format().relativeTextSize());
00742     m_chooser->setOffsetFromBaseLine( m_style->format().offsetFromBaseLine());
00743     m_chooser->setLanguage( m_style->format().language());
00744     m_chooser->setHyphenation( m_style->format().hyphenation());
00745 #endif
00746 */}
00747 
00748 void KoStyleFontTab::save()
00749 {
00750     m_style->format() = KoTextFormat( m_fontTab->getSelection(),
00751                          m_layoutTab->getSubSuperScript(),
00752                          m_decorationTab->getTextColor(),
00753                          m_decorationTab->getBackgroundColor(),
00754                          m_highlightingTab->getUnderlineColor(),
00755                          m_highlightingTab->getUnderline(),
00756                          m_highlightingTab->getUnderlineStyle(),
00757                          m_highlightingTab->getStrikethrough(),
00758                          m_highlightingTab->getStrikethroughStyle(),
00759                          m_highlightingTab->getCapitalisation(),
00760                          m_languageTab->getLanguage(),
00761                          m_layoutTab->getRelativeTextSize(),
00762                          m_layoutTab->getOffsetFromBaseline(),
00763                          m_highlightingTab->getWordByWord(),
00764                          m_layoutTab->getAutoHyphenation(),
00765                          m_decorationTab->getShadowDistanceX(),
00766                          m_decorationTab->getShadowDistanceY(),
00767                          m_decorationTab->getShadowColor()
00768             );
00769 /*
00770     m_style->format().setFont( m_fontTab->getSelection() );
00771     m_style->format().setColor( m_decorationTab->getTextColor() );
00772     if( m_decorationTab->getBackGroundColor()!=QApplication::palette().color( QPalette::Active, QColorGroup::Base ))
00773         m_style->format().setTextBackgroundColor( m_decorationTab->getBackGroundColor() );
00774 
00775     m_style->format().setTextUnderlineColor(m_chooser->underlineColor());
00776     m_style->format().setUnderlineType (m_chooser->getUnderlineType());
00777     m_style->format().setUnderlineStyle (m_chooser->getUnderlineStyle());
00778     m_style->format().setStrikeOutStyle( m_chooser->getStrikeOutStyle() );
00779     m_style->format().setStrikeOutType (m_chooser->getStrikeOutType());
00780     m_style->format().setShadowText(m_chooser->getShadowText());
00781     m_style->format().setWordByWord( m_chooser->getWordByWord());
00782     m_style->format().setRelativeTextSize( m_chooser->getRelativeTextSize());
00783     m_style->format().setAttributeFont( m_chooser->getFontAttribute());
00784     m_style->format().setOffsetFromBaseLine( m_chooser->getOffsetFromBaseLine());
00785     m_style->format().setVAlign( m_layoutTab->getSubSuperScript() );
00786 
00787     m_style->format().setLanguage( m_chooser->getLanguage());
00788     m_style->format().setHyphenation( m_chooser->getHyphenation());
00789 */}
00790 
00791 QString KoStyleFontTab::tabName()
00792 {
00793     return i18n("Font");
00794 }
KDE Home | KDE Accessibility Home | Description of Access Keys