F:/KPlato/koffice/libs/kotext/KoStyleDialog.cpp

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

Généré le Wed Nov 22 23:41:09 2006 pour KPlato par  doxygen 1.5.1-p1