lib Library API Documentation

koStylist.cc

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