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