kword

KWTableStyleManager.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002 Nash Hoogwater <nrhoogwater@wanadoo.nl>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; using
7 version 2 of the License.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "KWTableStyleManager.h"
21#include "KWTableStyleManager.moc"
22#include "KWImportStyleDia.h"
23
24#include "KWDocument.h"
25
26#include <KoParagCounter.h>
27#include <KoTextDocument.h>
28
29#include "KoParagStyle.h"
30#include "KWFrameStyleManager.h"
31#include "KWStyleManager.h"
32
33#include <tdelocale.h>
34#include <kiconloader.h>
35#include <kdebug.h>
36
37#include <tqpushbutton.h>
38#include <tqlabel.h>
39#include <tqgroupbox.h>
40#include <tqpainter.h>
41#include <tqlineedit.h>
42#include <tqlayout.h>
43#include <tqcombobox.h>
44#include <tqframe.h>
45
46
47/******************************************************************/
48/* Class: KWTableStylePreview */
49/******************************************************************/
50
51KWTableStylePreview::KWTableStylePreview( const TQString& title, const TQString& text, TQWidget* parent, const char* name )
52 : TQGroupBox( title, parent, name )
53{
54 m_zoomHandler = new KoTextZoomHandler;
55 TQFont font = KoGlobal::defaultFont();
56 m_textdoc = new KoTextDocument( m_zoomHandler, new KoTextFormatCollection( font, TQColor(),TDEGlobal::locale()->language(), false ) );
57 KoTextParag * parag = m_textdoc->firstParag();
58 parag->insert( 0, text );
59}
60
61KWTableStylePreview::~KWTableStylePreview()
62{
63 delete m_textdoc;
64 delete m_zoomHandler;
65}
66
67#undef ptToPx
68#define ptToPx tqRound
69
70void KWTableStylePreview::drawContents( TQPainter *p )
71{
72 p->save();
73 TQRect r = contentsRect();
74
75 int wid = ( r.width() - 40 );
76 int hei = ( r.height() - 40 );
77
78
79 // 1: create document background = white
80
81 p->fillRect( TQRect( 10, 20, r.width()-20, r.height() - 20 ), TQColor("white") );
82
83 // 2: create borders (KWFrameStyle)
84
85 if (tableStyle->frameStyle()->topBorder().width()>0) {
86 p->setPen( KoBorder::borderPen(tableStyle->frameStyle()->topBorder(), ptToPx( tableStyle->frameStyle()->topBorder().width() ), black) ); // Top border
87 p->drawLine( 20 - int(tableStyle->frameStyle()->leftBorder().width()/2), 30,
88 20 + wid + int(tableStyle->frameStyle()->rightBorder().width()/2), 30 );
89 }
90 if (tableStyle->frameStyle()->leftBorder().width()>0) {
91 p->setPen( KoBorder::borderPen(tableStyle->frameStyle()->leftBorder(), ptToPx( tableStyle->frameStyle()->leftBorder().width() ), black) ); // Left border
92 p->drawLine( 20, 30 - int(tableStyle->frameStyle()->topBorder().width()/2),
93 20 , 30 + hei + int(tableStyle->frameStyle()->bottomBorder().width()/2) );
94 }
95 if (tableStyle->frameStyle()->bottomBorder().width()>0) {
96 p->setPen( KoBorder::borderPen(tableStyle->frameStyle()->bottomBorder(), ptToPx( tableStyle->frameStyle()->bottomBorder().width() ), black) ); // Bottom border
97 p->drawLine( 20 + wid + int(ceil(tableStyle->frameStyle()->rightBorder().width()/2)), 30 + hei,
98 20 - int(tableStyle->frameStyle()->leftBorder().width()/2), 30 + hei );
99 }
100 if (tableStyle->frameStyle()->rightBorder().width()>0) {
101 p->setPen( KoBorder::borderPen(tableStyle->frameStyle()->rightBorder(), ptToPx( tableStyle->frameStyle()->rightBorder().width() ), black) ); // Right border
102 p->drawLine( 20 + wid, 30 - int(tableStyle->frameStyle()->topBorder().width()/2) ,
103 20 + wid, 30 + hei + int(tableStyle->frameStyle()->bottomBorder().width()/2) );
104 }
105
106 // 3: create background whithin "frame"
107
108 TQRect fr( TQPoint(20 + int(ceil(tableStyle->frameStyle()->leftBorder().width()/2)), 30 + int(ceil(tableStyle->frameStyle()->topBorder().width()/2))),
109 TQPoint(20 + wid - int(floor(tableStyle->frameStyle()->rightBorder().width()/2)+1), 30 + hei - int(floor(tableStyle->frameStyle()->bottomBorder().width()/2)+1)) );
110
111 p->fillRect( fr, tableStyle->frameStyle()->backgroundColor() );
112
113 // 4: create text (KoParagStyle)
114
115 KoTextParag * parag = m_textdoc->firstParag();
116 int widthLU = m_zoomHandler->pixelToLayoutUnitX( fr.width() - 2 ); // keep one pixel border horizontally
117 if ( m_textdoc->width() != widthLU )
118 {
119 // For centering to work, and to even get word wrapping when the thing is too big :)
120 m_textdoc->setWidth( widthLU );
121 parag->invalidate(0);
122 }
123
124 parag->format();
125 TQRect textRect = parag->pixelRect( m_zoomHandler );
126
127 // Center vertically, but not horizontally, to keep the parag alignment working,
128 textRect.moveTopLeft( TQPoint( fr.x(), fr.y() + ( fr.height() - textRect.height() ) / 2 ) );
129
130 p->setClipRect( textRect.intersect( fr ) );
131 p->translate( textRect.x(), textRect.y() );
132
133 TQColorGroup cg = TQApplication::palette().active();
134 cg.setBrush( TQColorGroup::Base, tableStyle->frameStyle()->backgroundColor() );
135
136 m_textdoc->drawWYSIWYG( p, 1, 0, textRect.width() - 1, textRect.height(), cg, m_zoomHandler );
137
138 p->restore();
139}
140
141void KWTableStylePreview::setTableStyle( KWTableStyle *_tableStyle )
142{
143 tableStyle = _tableStyle;
144
145 KoTextParag * parag = m_textdoc->firstParag();
146 parag->applyStyle( tableStyle->paragraphStyle() );
147
148 repaint(true);
149}
150
151/******************************************************************/
152/* Class: KWTableStyleListItem */
153/******************************************************************/
154
155KWTableStyleListItem::~KWTableStyleListItem()
156{
157}
158
159void KWTableStyleListItem::switchStyle()
160{
161 delete m_changedTableStyle;
162
163 if ( m_origTableStyle )
164 m_changedTableStyle = new KWTableStyle( *m_origTableStyle );
165}
166
167void KWTableStyleListItem::deleteStyle( KWTableStyle *current )
168{
169 Q_ASSERT( m_changedTableStyle == current );
170 delete m_changedTableStyle;
171 m_changedTableStyle = 0L;
172}
173
174void KWTableStyleListItem::apply()
175{
176 *m_origTableStyle = *m_changedTableStyle;
177}
178
179/******************************************************************/
180/* Class: KWTableStyleManager */
181/******************************************************************/
182
183// Proof reader comment: stylist sounds like a hair dresser
184
185KWTableStyleManager::KWTableStyleManager( TQWidget *_parent, KWDocument *_doc )
186 : KDialogBase( _parent, "Tablestylist", true,
187 i18n("Table Style Manager"),
188 KDialogBase::Ok | KDialogBase::Cancel | KDialogBase::Apply | KDialogBase::User1 )
189{
190 m_doc = _doc;
191
192 m_currentTableStyle = 0L;
193 noSignals=true;
194
195 m_tableStyles.setAutoDelete(false);
196
197 setupWidget(); // build the widget with the buttons and the list selector.
198
199 m_stylesList->setCurrentItem( 0 );
200 noSignals=false;
201 switchStyle();
202 setInitialSize( TQSize( 450, 450 ) );
203 setButtonText( KDialogBase::User1, i18n("Import From File...") );
204 connect(this, TQ_SIGNAL(user1Clicked()), this, TQ_SLOT(importFromFile()));
205
206}
207
208KWTableStyleManager::~KWTableStyleManager()
209{
210 m_tableStyles.setAutoDelete( true );
211 m_tableStyles.clear();
212}
213
214void KWTableStyleManager::setupWidget()
215{
216 TQFrame * frame1 = makeMainWidget();
217 TQGridLayout *frame1Layout = new TQGridLayout( frame1, 0, 0, // auto
218 0, KDialog::spacingHint() );
219
220
221 KWTableStyleCollection* collection = m_doc->tableStyleCollection();
222 numTableStyles = collection->count();
223 m_stylesList = new TQListBox( frame1, "stylesList" );
224 m_stylesList->insertStringList( collection->displayNameList() );
225 const TQValueList<KoUserStyle*> styleList = collection->styleList();
226 Q_ASSERT( !styleList.isEmpty() );
227 for ( TQValueList<KoUserStyle *>::const_iterator it = styleList.begin(), end = styleList.end();
228 it != end ; ++it )
229 {
230 KWTableStyle* style = static_cast<KWTableStyle *>( *it );
231 m_tableStyles.append( new KWTableStyleListItem(style,new KWTableStyle(*style) ) );
232 m_styleOrder << style->name();
233 }
234 Q_ASSERT( m_stylesList->count() == m_styleOrder.count() );
235 Q_ASSERT( m_styleOrder.count() == m_tableStyles.count() );
236
237 frame1Layout->addMultiCellWidget( m_stylesList, 0, 0, 0, 1 );
238
239
240 m_moveUpButton = new TQPushButton( frame1, "moveUpButton" );
241 m_moveUpButton->setIconSet( SmallIconSet( "go-up" ) );
242 connect( m_moveUpButton, TQ_SIGNAL( clicked() ), this, TQ_SLOT( moveUpStyle() ) );
243 frame1Layout->addWidget( m_moveUpButton, 1, 1 );
244
245 m_moveDownButton = new TQPushButton( frame1, "moveDownButton" );
246 m_moveDownButton->setIconSet( SmallIconSet( "go-down" ) );
247 connect( m_moveDownButton, TQ_SIGNAL( clicked() ), this, TQ_SLOT( moveDownStyle() ) );
248 frame1Layout->addWidget( m_moveDownButton, 1, 0 );
249
250
251 m_deleteButton = new TQPushButton( frame1, "deleteButton" );
252 m_deleteButton->setText( i18n( "&Delete" ) );
253 connect( m_deleteButton, TQ_SIGNAL( clicked() ), this, TQ_SLOT( deleteStyle() ) );
254
255 frame1Layout->addWidget( m_deleteButton, 2, 1 );
256
257 m_newButton = new TQPushButton( frame1, "newButton" );
258 m_newButton->setText( i18n( "New" ) );
259 connect( m_newButton, TQ_SIGNAL( clicked() ), this, TQ_SLOT( addStyle() ) );
260
261 frame1Layout->addWidget( m_newButton, 2, 0 );
262
263 main = new TQWidget( frame1 );
264
265 setupMain();
266
267 frame1Layout->addMultiCellWidget( main, 0, 2, 2, 2 );
268
269 connect( m_stylesList, TQ_SIGNAL( selectionChanged() ), this, TQ_SLOT( switchStyle() ) );
270}
271
272void KWTableStyleManager::setupMain()
273{
274 TQGridLayout *mainLayout = new TQGridLayout( main );
275 mainLayout->setSpacing( KDialog::spacingHint() );
276
277 preview = new KWTableStylePreview( i18n("Preview"), i18n("Tablestyles preview"), main );
278 preview->resize(preview->sizeHint());
279
280 mainLayout->addMultiCellWidget( preview, 1, 1, 0, 1 );
281
282 m_nameString = new TQLineEdit( main );
283 m_nameString->resize(m_nameString->sizeHint() );
284 connect( m_nameString, TQ_SIGNAL( textChanged( const TQString &) ), this, TQ_SLOT( renameStyle(const TQString &) ) );
285
286 mainLayout->addWidget( m_nameString, 0, 1 );
287
288 TQLabel *nameLabel = new TQLabel( main );
289 nameLabel->setText( i18n( "Name:" ) );
290 nameLabel->resize(nameLabel->sizeHint());
291 nameLabel->setAlignment( AlignRight | AlignVCenter );
292
293 mainLayout->addWidget( nameLabel, 0, 0 );
294
295 TQGroupBox *adjustBox = new TQGroupBox( 0, TQt::Vertical, i18n("Adjust"), main);
296 adjustBox->layout()->setSpacing(KDialog::spacingHint());
297 adjustBox->layout()->setMargin(KDialog::marginHint());
298 TQGridLayout *adjustLayout = new TQGridLayout( adjustBox->layout() );
299
300 TQLabel *frameStyleLabel = new TQLabel( adjustBox );
301 frameStyleLabel->setText( i18n( "Framestyle:" ) );
302 frameStyleLabel->setAlignment( AlignRight | AlignVCenter );
303
304 TQLabel *styleLabel = new TQLabel( adjustBox );
305 styleLabel->setText( i18n( "Textstyle:" ) );
306 styleLabel->setAlignment( AlignRight | AlignVCenter );
307
308 m_frameStyle = new TQComboBox( adjustBox );
309 m_style = new TQComboBox( adjustBox );
310 updateAllStyleCombos();
311
312 connect( m_frameStyle, TQ_SIGNAL( activated(int) ), this, TQ_SLOT( selectFrameStyle(int) ) );
313 connect( m_style, TQ_SIGNAL( activated(int) ), this, TQ_SLOT( selectStyle(int) ) );
314
315 m_changeFrameStyleButton = new TQPushButton( adjustBox );
316 m_changeFrameStyleButton->setText( i18n( "Change..." ) );
317 connect( m_changeFrameStyleButton, TQ_SIGNAL( clicked() ), this, TQ_SLOT( changeFrameStyle() ) );
318
319 m_changeStyleButton = new TQPushButton( adjustBox );
320 m_changeStyleButton->setText( i18n( "Change..." ) );
321 connect( m_changeStyleButton, TQ_SIGNAL( clicked() ), this, TQ_SLOT( changeStyle() ) );
322
323 adjustLayout->addWidget( frameStyleLabel, 0, 0 );
324 adjustLayout->addWidget( styleLabel, 1, 0 );
325
326 adjustLayout->addWidget( m_frameStyle, 0, 1 );
327 adjustLayout->addWidget( m_style, 1, 1 );
328
329 adjustLayout->addWidget( m_changeFrameStyleButton, 0, 2 );
330 adjustLayout->addWidget( m_changeStyleButton, 1, 2 );
331
332 adjustBox->setMaximumHeight(120);
333 mainLayout->addMultiCellWidget( adjustBox, 2, 2, 0, 1);
334}
335
336void KWTableStyleManager::switchStyle()
337{
338 kdDebug() << "KWTableStyleManager::switchStyle noSignals=" << noSignals << endl;
339 if(noSignals) return;
340 noSignals=true;
341
342 if(m_currentTableStyle !=0L)
343 save();
344
345 m_currentTableStyle = 0L;
346 int num = tableStyleIndex( m_stylesList->currentItem() );
347
348 kdDebug() << "KWTableStyleManager::switchStyle switching to " << num << endl;
349 if( m_tableStyles.at(num)->origTableStyle() == m_tableStyles.at(num)->changedTableStyle() )
350 m_tableStyles.at(num)->switchStyle();
351 else
352 m_currentTableStyle = m_tableStyles.at(num)->changedTableStyle();
353
354 updateGUI();
355
356 noSignals=false;
357}
358
359int KWTableStyleManager::tableStyleIndex( int pos )
360{
361 int p = 0;
362 for(unsigned int i=0; i < m_tableStyles.count(); i++) {
363 // Skip deleted styles, they're no in m_stylesList anymore
364 KWTableStyle * style = m_tableStyles.at(i)->changedTableStyle();
365 if ( !style ) continue;
366 if ( p == pos )
367 return i;
368 ++p;
369 }
370 kdWarning() << "KWTableStyleManager::tableStyleIndex no style found at pos " << pos << endl;
371
372#ifdef __GNUC_
373#warning implement undo/redo
374#endif
375
376 return 0;
377}
378
379void KWTableStyleManager::updateGUI()
380{
381 kdDebug() << "KWTableStyleManager::updateGUI m_currentTableStyle=" << m_currentTableStyle << " " << m_currentTableStyle->name() << endl;
382
383 // Update name
384 m_nameString->setText(m_currentTableStyle->displayName());
385 // Update style and framestyle
386 if ( m_doc->styleCollection()->findStyle( m_currentTableStyle->paragraphStyle()->name() ) )
387 m_style->setCurrentText(m_currentTableStyle->paragraphStyle()->displayName());
388 if ( m_doc->frameStyleCollection()->findStyle( m_currentTableStyle->frameStyle()->name() ) )
389 m_frameStyle->setCurrentText(m_currentTableStyle->frameStyle()->displayName());
390
391 // update delete button (can't delete first style);
392 m_deleteButton->setEnabled(m_stylesList->currentItem() != 0);
393
394 m_moveUpButton->setEnabled(m_stylesList->currentItem() != 0);
395 m_moveDownButton->setEnabled(m_stylesList->currentItem()!=(int)m_stylesList->count()-1);
396
397 updatePreview();
398}
399
400void KWTableStyleManager::updatePreview()
401{
402 preview->setTableStyle(m_currentTableStyle);
403}
404
405void KWTableStyleManager::save()
406{
407 m_currentTableStyle->setDisplayName( m_nameString->text() );
408}
409
410void KWTableStyleManager::addStyle()
411{
412 save();
413 KWTableStyleCollection* collection = m_doc->tableStyleCollection();
414
415 TQString str = i18n( "New Tablestyle Template (%1)" ).arg(numTableStyles++);
416 if ( m_currentTableStyle )
417 {
418 m_currentTableStyle = new KWTableStyle( *m_currentTableStyle );
419 m_currentTableStyle->setDisplayName( str );
420 }
421 else
422 {
423 KWTableStyle* defaultTableStyle = collection->findStyle( collection->defaultStyleName() );
424 Q_ASSERT( defaultTableStyle ); // can't be 0 except if there are no styles at all
425
426 KWFrameStyle *defaultFrameStyle = defaultTableStyle->frameStyle();
427 KoParagStyle *defaultParagraphStyle = defaultTableStyle->paragraphStyle();
428
429 m_currentTableStyle = new KWTableStyle( str, defaultParagraphStyle, defaultFrameStyle );
430 }
431 m_currentTableStyle->setName( collection->generateUniqueName() );
432
433 noSignals=true;
434 m_tableStyles.append(new KWTableStyleListItem(0L,m_currentTableStyle));
435 m_stylesList->insertItem( str );
436 m_styleOrder << m_currentTableStyle->name();
437 m_stylesList->setCurrentItem( m_stylesList->count() - 1 );
438 noSignals=false;
439
440 updateGUI();
441}
442
443void KWTableStyleManager::importFromFile()
444{
445 TQStringList lst;
446 for (unsigned int i = 0; i<m_stylesList->count();i++)
447 {
448 lst << m_stylesList->text(i );
449 }
450
451 KWImportFrameTableStyleDia dia( m_doc, lst, KWImportFrameTableStyleDia::TableStyle, this, 0 );
452 if ( dia.listOfTableStyleImported().count() > 0 && dia.exec() ) {
453 TQPtrList<KWTableStyle> list = dia.listOfTableStyleImported();
454 addStyles( list);
455 }
456}
457
458void KWTableStyleManager::addStyles(const TQPtrList<KWTableStyle> &listStyle )
459{
460 save();
461
462 TQPtrListIterator<KWTableStyle> style( listStyle );
463 for ( ; style.current() ; ++style )
464 {
465 noSignals=true;
466 m_stylesList->insertItem( style.current()->displayName() );
467 m_styleOrder << style.current()->name();
468 m_tableStyles.append( new KWTableStyleListItem( 0L,new KWTableStyle(*style.current())) );
469 noSignals=false;
470
471 }
472
473 updateGUI();
474}
475
476
477void KWTableStyleManager::deleteStyle()
478{
479 Q_ASSERT( m_currentTableStyle );
480
481 unsigned int cur = tableStyleIndex( m_stylesList->currentItem() );
482 m_styleOrder.remove( m_currentTableStyle->name() );
483 if ( !m_tableStyles.at(cur)->origTableStyle() )
484 m_tableStyles.take( cur );
485 else {
486 m_tableStyles.at(cur)->deleteStyle( m_currentTableStyle );
487 m_currentTableStyle = 0L;
488 }
489
490 // Update GUI
491 m_stylesList->removeItem( m_stylesList->currentItem() );
492 numTableStyles--;
493 m_stylesList->setSelected( m_stylesList->currentItem(), true );
494}
495
496void KWTableStyleManager::moveUpStyle()
497{
498 Q_ASSERT( m_currentTableStyle );
499 if ( m_currentTableStyle )
500 save();
501
502 const TQString currentStyleName = m_currentTableStyle->name();
503 const TQString currentStyleDisplayName = m_stylesList->currentText();
504 int pos2 = m_styleOrder.findIndex( currentStyleName );
505 if ( pos2 != -1 )
506 {
507 m_styleOrder.remove( m_styleOrder.at(pos2) );
508 m_styleOrder.insert( m_styleOrder.at(pos2-1), currentStyleName );
509 }
510
511
512 int pos = m_stylesList->currentItem();
513 noSignals=true;
514 m_stylesList->changeItem( m_stylesList->text( pos-1 ), pos );
515
516 m_stylesList->changeItem( currentStyleDisplayName, pos-1 );
517
518 m_stylesList->setCurrentItem( m_stylesList->currentItem() );
519 noSignals=false;
520
521 updateGUI();
522}
523
524void KWTableStyleManager::moveDownStyle()
525{
526 Q_ASSERT( m_currentTableStyle );
527 if ( m_currentTableStyle )
528 save();
529
530 const TQString currentStyleName = m_currentTableStyle->name();
531 const TQString currentStyleDisplayName = m_stylesList->currentText();
532 int pos2 = m_styleOrder.findIndex( currentStyleName );
533 if ( pos2 != -1 )
534 {
535 m_styleOrder.remove( m_styleOrder.at(pos2) );
536 m_styleOrder.insert( m_styleOrder.at(pos2+1), currentStyleName );
537 }
538
539 int pos = m_stylesList->currentItem();
540 noSignals=true;
541 m_stylesList->changeItem( m_stylesList->text( pos+1 ), pos );
542 m_stylesList->changeItem( currentStyleDisplayName, pos+1 );
543 m_stylesList->setCurrentItem( m_stylesList->currentItem() );
544 noSignals=false;
545
546 updateGUI();
547}
548
549void KWTableStyleManager::slotOk() {
550 save();
551 apply();
552 KDialogBase::slotOk();
553}
554
555void KWTableStyleManager::slotApply() {
556 save();
557 apply();
558 KDialogBase::slotApply();
559}
560
561void KWTableStyleManager::apply() {
562 noSignals=true;
563 for (unsigned int i =0 ; i < m_tableStyles.count() ; i++) {
564 if(m_tableStyles.at(i)->origTableStyle() == 0) { // newly added style
565 kdDebug() << "adding new tablestyle" << m_tableStyles.at(i)->changedTableStyle()->name() << " (" << i << ")" << endl;
566 KWTableStyle *tmp = m_doc->tableStyleCollection()->addStyle( m_tableStyles.take(i)->changedTableStyle() );
567 m_tableStyles.insert(i, new KWTableStyleListItem(0, tmp) );
568 } else if(m_tableStyles.at(i)->changedTableStyle() == 0) { // deleted style
569 kdDebug() << "deleting orig tablestyle " << m_tableStyles.at(i)->origTableStyle()->name() << " (" << i << ")" << endl;
570
571 KWTableStyle *orig = m_tableStyles.at(i)->origTableStyle();
572 m_doc->tableStyleCollection()->removeStyle( orig );
573 } else {
574 kdDebug() << "update tablestyle " << m_tableStyles.at(i)->changedTableStyle()->name() << " (" << i << ")" << endl;
575
576 m_tableStyles.at(i)->apply();
577 }
578 }
579 m_doc->tableStyleCollection()->updateStyleListOrder( m_styleOrder );
580 m_doc->updateAllTableStyleLists();
581 m_doc->setModified( true );
582 noSignals=false;
583}
584
585void KWTableStyleManager::renameStyle(const TQString &theText) {
586 if(noSignals) return;
587 noSignals=true;
588
589 int index = m_stylesList->currentItem();
590 kdDebug() << "KWTableStyleManager::renameStyle " << index << " to " << theText << endl;
591
592 // rename only in the GUI, not even in the underlying objects (save() does it).
593 m_stylesList->changeItem( theText, index );
594 //m_styleOrder[index]=theText; // not needed anymore, we use internal names
595 // Check how many styles with that name we have now
596 int synonyms = 0;
597 for ( unsigned int i = 0; i < m_stylesList->count(); i++ ) {
598 if ( m_stylesList->text( i ) == m_stylesList->currentText() )
599 ++synonyms;
600 }
601 Q_ASSERT( synonyms > 0 ); // should have found 'index' at least !
602 noSignals=false;
603 // Can't close the dialog if two styles have the same name
604 bool state=!theText.isEmpty() && (synonyms == 1);
605 enableButtonOK(state );
606 enableButtonApply(state);
607 enableButton( KDialogBase::User1, state );
608 m_deleteButton->setEnabled(state&&(m_stylesList->currentItem() != 0));
609 m_newButton->setEnabled(state);
610 m_stylesList->setEnabled( state );
611 if ( state )
612 {
613 m_moveUpButton->setEnabled(m_stylesList->currentItem() != 0);
614 m_moveDownButton->setEnabled(m_stylesList->currentItem()!=(int)m_stylesList->count()-1);
615 }
616 else
617 {
618 m_moveUpButton->setEnabled(false);
619 m_moveDownButton->setEnabled(false);
620 }
621
622}
623
626void KWTableStyleManager::changeFrameStyle()
627{
628// 0. Save name, otherwise it will be gone when you return
629 save();
630
631// 1. Execute frame style manager
632 KWFrameStyleManager frameStylist( this, m_doc, m_currentTableStyle->frameStyle()->name() );
633 frameStylist.exec();
634
635// 2. Apply changes
636 updateAllStyleCombos();
637 updateGUI();
638}
639
642void KWTableStyleManager::changeStyle()
643{
644// 0. Save name, otherwise it will be gone when you return
645 save();
646
647// 1. Execute stylist
648 KWStyleManager styleManager( this, m_doc->unit(), m_doc, *m_doc->styleCollection());
649 styleManager.exec();
650
651// 2. Apply changes
652 updateAllStyleCombos();
653 updateGUI();
654}
655
656void KWTableStyleManager::updateAllStyleCombos()
657{
658 unsigned int oldSindex = 0;
659 unsigned int oldFSindex = 0;
660 TQString oldS = "";
661 TQString oldFS = "";
662
663 if (m_style->currentItem()>=0) {
664 oldSindex = m_style->currentItem();
665 oldS = m_style->currentText();
666 }
667 if (m_frameStyle->currentItem()>=0) {
668 oldFSindex = m_frameStyle->currentItem();
669 oldFS = m_frameStyle->currentText();
670 }
671
672 // Let's check if there were deleted framestyles or styles.
673 // If that is the case than we search for the old name
674 // If it exists then we use that index, else we use
675 // the old index.
676 // Problems:
677 // - 1. Count is the same, but the user has delete the same number as he added
678 // - 2. Old name is not in new list, old index is wrong index in new list
679 if ( ( static_cast<unsigned int>(m_style->count())!=m_doc->styleCollection()->styleList().count() ) &&
680 ( m_style->listBox()->findItem( oldS ) ) ) {
681 oldSindex = m_style->listBox()->index( m_style->listBox()->findItem( oldS ) );
682 }
683 if ( ( m_frameStyle->count() != m_doc->frameStyleCollection()->count() ) &&
684 ( m_frameStyle->listBox()->findItem( oldFS ) ) ) {
685 oldFSindex = m_frameStyle->listBox()->index( m_frameStyle->listBox()->findItem( oldFS ) );
686 }
687
688 // Update the comboboxes
689
690 m_frameStyle->clear();
691 m_frameStyle->insertStringList( m_doc->frameStyleCollection()->displayNameList() );
692 m_frameStyle->setCurrentItem( oldFSindex );
693
694 m_style->clear();
695 m_style->insertStringList( m_doc->styleCollection()->displayNameList() );
696 m_style->setCurrentItem( oldSindex );
697}
698
699void KWTableStyleManager::selectFrameStyle(int index)
700{
701 kdDebug() << "KWTableStyleManager::selectFrameStyle index " << index << endl;
702
703 if ( (index>=0) && ( index < (int)m_doc->frameStyleCollection()->count() ) )
704 m_currentTableStyle->setFrameStyle( m_doc->frameStyleCollection()->frameStyleAt(index) );
705 save();
706 updateGUI();
707}
708
709void KWTableStyleManager::selectStyle(int index)
710{
711 kdDebug() << "KWTableStyleManager::selectStyle index " << index << endl;
712 if ( (index>=0) && ( index < (int)m_doc->styleCollection()->styleList().count() ) )
713 m_currentTableStyle->setParagraphStyle( m_doc->styleCollection()->styleAt(index) );
714 save();
715 updateGUI();
716}
KWTableStyle * findStyle(const TQString &name) const
Find style based on the untranslated name name.
Table style (can created/modified/deleted by the user) A table style is simply a paragraph style and ...