lib

KoParagDia.cpp
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
3 Copyright (C) 2005 Martin Ellis <martin.ellis@kdemail.net>
4 Copyright (C) 2006 Thomas Zander <zander@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20*/
21
22#include "KoParagDia.h"
23#include "KoParagDia_p.h"
24#include "KoDocument.h"
25#include "KoTextFormat.h"
26#include "KoTextParag.h"
27#include "KoTextDocument.h"
28#include "KoTextZoomHandler.h"
29#include "KoParagDecorationTab.h"
30
31#include <KoCharSelectDia.h>
32#include <KoUnitWidgets.h>
33#include <kcolorbutton.h>
34#include <kdebug.h>
35#include <kiconloader.h>
36#include <tdelocale.h>
37#include <knumvalidator.h>
38#include <KoGlobal.h>
39#include <tqgroupbox.h>
40#include <knuminput.h>
41#include <kpushbutton.h>
42#include <kcombobox.h>
43
44#include <tqcheckbox.h>
45#include <tqcombobox.h>
46#include <tqhbuttongroup.h>
47#include <tqlabel.h>
48#include <tqradiobutton.h>
49#include <tqvbox.h>
50#include <tqhbox.h>
51#include <tqtooltip.h>
52#include <tqlayout.h>
53#include <tqapplication.h>
54#include <tqwidgetstack.h>
55
56KoCounterStyleWidget::KoCounterStyleWidget( bool displayDepth, bool onlyStyleTypeLetter, bool disableAll, TQWidget * parent, const char* name )
57 :TQWidget( parent, name ),
58 stylesList()
59{
60 noSignals = true;
61 styleBuffer = 999;
62 TQVBoxLayout *vbox = new TQVBoxLayout( this,0, 0/*KDialog::marginHint(), KDialog::spacingHint()*/ );
63 gStyle = new TQGroupBox( i18n( "St&yle" ), this, "styleLayout" );
64 vbox->addWidget( gStyle);
65 TQGridLayout * grid = new TQGridLayout(gStyle, 12, 5, KDialog::marginHint(), KDialog::spacingHint());
66 grid->addRowSpacing(0, fontMetrics().height()/2);
67
68 makeCounterRepresenterList( stylesList, onlyStyleTypeLetter );
69
70 lstStyle = new TQListBox( gStyle, "styleListBox" );
71 grid->addMultiCellWidget( lstStyle, 1, 11, 0, 0);
72 fillStyleCombo();
73 connect( lstStyle, TQ_SIGNAL( selectionChanged() ), this, TQ_SLOT( numStyleChanged() ) );
74
75
76 TQLabel *lPrefix = new TQLabel( gStyle, "lPrefix" );
77 lPrefix->setText( i18n( "Pre&fix text:" ) );
78 grid->addWidget( lPrefix, 1, 1);
79
80 sPrefix = new TQLineEdit( gStyle, "sPrefix" );
81 lPrefix->setBuddy( sPrefix );
82 grid->addWidget( sPrefix, 1, 2);
83
84 TQLabel *lSuffix = new TQLabel( gStyle, "lSuffix" );
85 lSuffix->setText( i18n( "Suffi&x text:" ) );
86 grid->addWidget( lSuffix, 1, 3);
87
88 sSuffix = new TQLineEdit( gStyle, "sSuffix" );
89 lSuffix->setBuddy( sSuffix );
90 grid->addWidget( sSuffix, 1, 4 );
91
92 lStart = new TQLabel( gStyle, "lStart" );
93 lStart->setText( i18n( "&Start at:" ) );
94 grid->addWidget( lStart, 2, 1 );
95
96
97 spnDepth = new TQSpinBox( 0, 15, 1, gStyle );
98 if ( displayDepth )
99 grid->addWidget( spnDepth, 3, 2 );
100 else
101 spnDepth->hide();
102
103 spnDisplayLevels = new TQSpinBox( 0, 15, 1, gStyle );
104 spnDisplayLevels->setMinValue( 1 );
105 if ( displayDepth )
106 grid->addWidget( spnDisplayLevels, 3, 4 );
107 else
108 spnDisplayLevels->hide();
109
110
111 TQHBoxLayout *customCharBox = new TQHBoxLayout(0, 0, 6);
112 lCustom = new TQLabel( i18n( "Custo&m character:" ), gStyle, "custom char label" );
113 customCharBox->addWidget( lCustom );
114
115 bCustom = new TQPushButton( "", gStyle, "bCustom" );
116 lCustom->setBuddy( bCustom );
117 customCharBox->addWidget( bCustom );
118 connect( bCustom, TQ_SIGNAL( clicked() ), this, TQ_SLOT( selectCustomBullet() ) );
119
120 TQSpacerItem* spacer_2 = new TQSpacerItem( 0, 0, TQSizePolicy::Expanding, TQSizePolicy::Minimum );
121 customCharBox->addItem( spacer_2 );
122
123 grid->addMultiCellLayout(customCharBox, 4, 4, 1, 4, TQt::AlignLeft);
124
125 spnStart = new KoSpinBox( gStyle );
126 spnStart->setMinValue ( 1);
127 lStart->setBuddy( spnStart );
128 grid->addWidget( spnStart, 2, 2);
129
130 lAlignment = new TQLabel( gStyle, "lAlignment" );
131 lAlignment->setText( i18n( "Counter alignment:" ) );
132 grid->addWidget( lAlignment, 2, 3 );
133
134 cbAlignment = new KComboBox( gStyle, "cbAlignment" );
135 cbAlignment->insertItem(i18n("Align Auto"));
136 cbAlignment->insertItem(i18n("Align Left"));
137 cbAlignment->insertItem(i18n("Align Right"));
138 cbAlignment->setCurrentItem(0);
139 grid->addWidget( cbAlignment, 2, 4 );
140
141 TQLabel *lDepth = new TQLabel( gStyle, "lDepth" );
142 lDepth->setText( i18n( "&Depth:" ) );
143 lDepth->setBuddy( spnDepth );
144 if ( displayDepth )
145 grid->addWidget( lDepth, 3, 1 );
146 else
147 lDepth->hide();
148
149 TQLabel *lDisplayLevels = new TQLabel( gStyle );
150 lDisplayLevels->setText( i18n( "Display le&vels:" ) );
151 lDisplayLevels->setBuddy( spnDisplayLevels );
152 if ( displayDepth )
153 grid->addWidget( lDisplayLevels, 3, 3 );
154 else
155 lDisplayLevels->hide();
156
157 cbRestart = new TQCheckBox( i18n( "&Restart numbering at this paragraph" ), gStyle );
158 grid->addMultiCellWidget( cbRestart, 5, 5, 1, 3 );
159
160 if ( onlyStyleTypeLetter )
161 {
162 lCustom->hide();
163 bCustom->hide();
164 cbRestart->hide();
165 }
166
167
168 connect( cbRestart, TQ_SIGNAL( toggled(bool) ), this, TQ_SLOT( restartChanged(bool) ) );
169
170 connect( sSuffix, TQ_SIGNAL( textChanged (const TQString &) ), this, TQ_SLOT( suffixChanged(const TQString &) ) );
171 connect( sPrefix, TQ_SIGNAL( textChanged (const TQString &) ), this, TQ_SLOT( prefixChanged(const TQString &) ) );
172 connect( spnStart, TQ_SIGNAL( valueChanged (int) ), this, TQ_SLOT( startChanged(int) ) );
173 connect( spnDepth, TQ_SIGNAL( valueChanged (int) ), this, TQ_SLOT( depthChanged(int) ) );
174 connect( spnDisplayLevels, TQ_SIGNAL( valueChanged (int) ), this, TQ_SLOT( displayLevelsChanged(int) ) );
175 connect( cbAlignment, TQ_SIGNAL( activated (const TQString&) ), this, TQ_SLOT( alignmentChanged(const TQString&) ) );
176 noSignals = false;
177 if ( disableAll )
178 {
179 gStyle->setEnabled( false );
180 lstStyle->setEnabled( false );
181 sSuffix->setEnabled( false );
182 sPrefix->setEnabled( false );
183 bCustom->setEnabled( false );
184 spnStart->setEnabled( false );
185 spnDepth->setEnabled( false );
186 spnDisplayLevels->setEnabled( false );
187 lStart->setEnabled( false );
188 lCustom->setEnabled( false );
189 cbRestart->setEnabled( false );
190 cbAlignment->setEnabled( false );
191 }
192}
193
194void KoCounterStyleWidget::alignmentChanged(const TQString& s)
195{
196 int a;
197 if(s==i18n("Align Left"))
198 a=TQt::AlignLeft;
199 else if(s==i18n("Align Right"))
200 a=TQt::AlignRight;
201 else if(s==i18n("Align Auto"))
202 a=TQt::AlignAuto;
203 else {
204 kdError()<<"Not Implemented"<<endl;
205 return;
206 }
207 m_counter.setAlignment(a);
208 emit sig_alignmentChanged(a);
209}
210
211void KoCounterStyleWidget::setCounter( const KoParagCounter& counter )
212{
213 noSignals = true;
214 KoParagCounter::Style st = counter.style();
215 m_counter = counter;
216 // Huh? doesn't the line above do this already?
217 //m_counter.setStyle( st );
218 changeKWSpinboxType( st);
219 displayStyle( st );
220 noSignals = false;
221}
222
223void KoCounterStyleWidget::changeKWSpinboxType(KoParagCounter::Style st) {
224 switch(st)
225 {
226 case KoParagCounter::STYLE_NONE:
227 spnStart->setCounterType(KoSpinBox::NONE);
228 break;
229 case KoParagCounter::STYLE_NUM:
230 spnStart->setCounterType(KoSpinBox::NUM);
231 break;
232 case KoParagCounter::STYLE_ALPHAB_L:
233 spnStart->setCounterType(KoSpinBox::ALPHAB_L);
234 break;
235 case KoParagCounter::STYLE_ALPHAB_U:
236 spnStart->setCounterType(KoSpinBox::ALPHAB_U);
237 break;
238 case KoParagCounter::STYLE_ROM_NUM_L:
239 spnStart->setCounterType(KoSpinBox::ROM_NUM_L);
240 break;
241 case KoParagCounter::STYLE_ROM_NUM_U:
242 spnStart->setCounterType(KoSpinBox::ROM_NUM_U);
243 break;
244 default:
245 spnStart->setCounterType(KoSpinBox::NONE);
246 }
247}
248
249
250void KoCounterStyleWidget::fillStyleCombo(KoParagCounter::Numbering type) {
251 if(lstStyle==NULL) return;
252 noSignals=true;
253 unsigned int cur = lstStyle->currentItem();
254 lstStyle->clear();
255 TQPtrListIterator<StyleRepresenter> style( stylesList );
256 while ( style.current() ) {
257 if(style.current()->style() == KoParagCounter::STYLE_NONE) {
258 if(type == KoParagCounter::NUM_NONE)
259 lstStyle->insertItem( style.current()->name() );
260 }
261 else if(type == KoParagCounter::NUM_LIST || !style.current()->isBullet())
262 if(type != KoParagCounter::NUM_NONE)
263 lstStyle->insertItem( style.current()->name() );
264 ++style;
265 }
266
267 if(styleBuffer <= lstStyle->count())
268 lstStyle->setCurrentItem(styleBuffer);
269 else
270 if(cur <= lstStyle->count())
271 lstStyle->setCurrentItem(cur);
272
273 if(cur > lstStyle->count()) {
274 styleBuffer = cur;
275 }
276 noSignals=false;
277}
278
279void KoCounterStyleWidget::displayStyle( KoParagCounter::Style style )
280{
281 unsigned int i = 0;
282 while ( stylesList.count() > i && stylesList.at(i)->style() != style )
283 ++i;
284 lstStyle->setCurrentItem(i);
285
286 bCustom->setText( m_counter.customBulletCharacter() );
287 if ( !m_counter.customBulletFont().isEmpty() )
288 bCustom->setFont( TQFont( m_counter.customBulletFont() ) );
289
290 sPrefix->setText( m_counter.prefix() );
291 sSuffix->setText( m_counter.suffix() );
292
293 spnDepth->setValue( m_counter.depth() );
294 spnDisplayLevels->setValue( m_counter.displayLevels() );
295 spnStart->setValue( m_counter.startNumber() );
296
297 cbRestart->setChecked( m_counter.restartCounter() );
298 if(m_counter.alignment()==TQt::AlignLeft)
299 cbAlignment->setCurrentText(i18n("Align Left"));
300 else if(m_counter.alignment()==TQt::AlignRight)
301 cbAlignment->setCurrentText(i18n("Align Right"));
302 else if(m_counter.alignment()==TQt::AlignAuto)
303 cbAlignment->setCurrentText(i18n("Align Auto"));
304 else
305 kdError()<<"Not Implemented"<<endl;
306}
307
308void KoCounterStyleWidget::display( const KoParagLayout & lay ) {
309 KoParagCounter::Style style = KoParagCounter::STYLE_NONE;
310 if ( lay.counter )
311 {
312 style=lay.counter->style();
313 m_counter = *lay.counter;
314 }
315 else
316 {
317 m_counter = KoParagCounter();
318 }
319 styleBuffer = 999;
320
321 numTypeChanged( m_counter.numbering() );
322 emit sig_numTypeChanged( m_counter.numbering() );
323
324 displayStyle( style );
325}
326
327
328void KoCounterStyleWidget::numTypeChanged( int nType ) {
329 m_counter.setNumbering( static_cast<KoParagCounter::Numbering>( nType ) );
330 gStyle->setEnabled( m_counter.numbering() != KoParagCounter::NUM_NONE );
331 fillStyleCombo(m_counter.numbering());
332 bool state=m_counter.numbering()==KoParagCounter::NUM_LIST;
333 bCustom->setEnabled(state);
334 lCustom->setEnabled(state);
335}
336
337
338void KoCounterStyleWidget::makeCounterRepresenterList( TQPtrList<StyleRepresenter>& stylesList, bool onlyStyleTypeLetter )
339{
340 stylesList.setAutoDelete( true );
341 stylesList.append( new StyleRepresenter(i18n( "Arabic Numbers" )
342 , KoParagCounter::STYLE_NUM));
343 stylesList.append( new StyleRepresenter(i18n( "Lower Alphabetical" )
344 , KoParagCounter::STYLE_ALPHAB_L ));
345 stylesList.append( new StyleRepresenter(i18n( "Upper Alphabetical" )
346 , KoParagCounter::STYLE_ALPHAB_U ));
347 stylesList.append( new StyleRepresenter(i18n( "Lower Roman Numbers" )
348 , KoParagCounter::STYLE_ROM_NUM_L ));
349 stylesList.append( new StyleRepresenter(i18n( "Upper Roman Numbers" )
350 , KoParagCounter::STYLE_ROM_NUM_U ));
351 if ( !onlyStyleTypeLetter )
352 {
353 stylesList.append( new StyleRepresenter(i18n( "Disc Bullet" )
354 , KoParagCounter::STYLE_DISCBULLET , true));
355 stylesList.append( new StyleRepresenter(i18n( "Square Bullet" )
356 , KoParagCounter::STYLE_SQUAREBULLET , true));
357 stylesList.append( new StyleRepresenter(i18n( "Box Bullet" )
358 , KoParagCounter::STYLE_BOXBULLET , true));
359 stylesList.append( new StyleRepresenter(i18n( "Circle Bullet" )
360 , KoParagCounter::STYLE_CIRCLEBULLET , true));
361 stylesList.append( new StyleRepresenter(i18n( "Custom Bullet" )
362 , KoParagCounter::STYLE_CUSTOMBULLET , true));
363 }
364 stylesList.append( new StyleRepresenter(i18n( "None" ), KoParagCounter::STYLE_NONE));
365}
366
367
368void KoCounterStyleWidget::selectCustomBullet() {
369 unsigned int i = 0;
370 while ( stylesList.count() > i && stylesList.at(i)->style() != KoParagCounter::STYLE_CUSTOMBULLET )
371 ++i;
372 lstStyle->setCurrentItem(i);
373
374 TQString f = m_counter.customBulletFont();
375 if ( f.isEmpty() )
376 f = "symbol";
377 TQChar c = m_counter.customBulletCharacter();
378
379 if ( KoCharSelectDia::selectChar( f, c ) ) {
380 emit changeCustomBullet( f, c );
381 m_counter.setCustomBulletFont( f );
382 m_counter.setCustomBulletCharacter( c );
383 if ( !f.isEmpty() )
384 bCustom->setFont( TQFont( f ) );
385 bCustom->setText( c );
386 }
387}
388
389void KoCounterStyleWidget::numStyleChanged() {
390 if ( noSignals )
391 return;
392 // We selected another style from the list box.
393 styleBuffer = 999;
394 StyleRepresenter *sr = stylesList.at(lstStyle->currentItem());
395 emit changeStyle( sr->style() );
396 m_counter.setStyle( sr->style() );
397 bool isNumbered = !sr->isBullet() && !sr->style() == KoParagCounter::STYLE_NONE;
398 lStart->setEnabled( isNumbered );
399 spnStart->setEnabled( isNumbered );
400 cbRestart->setEnabled( isNumbered );
401 spnDisplayLevels->setEnabled( isNumbered );
402 changeKWSpinboxType(sr->style() );
403}
404
405
406
407KoSpinBox::KoSpinBox( TQWidget * parent, const char * name )
408 : TQSpinBox(parent,name)
409{
410 m_Etype=NONE;
411 //max value supported by roman number
412 setMaxValue ( 3999 );
413}
414KoSpinBox::~KoSpinBox( )
415{
416}
417
418KoSpinBox::KoSpinBox( int minValue, int maxValue, int step ,
419 TQWidget * parent , const char * name )
420 : TQSpinBox(minValue, maxValue,step ,
421 parent , name)
422{
423 m_Etype=NONE;
424}
425
426void KoSpinBox::setCounterType(counterType _type)
427{
428 m_Etype=_type;
429 editor()->setText(mapValueToText(value()));
430}
431
432
433TQString KoSpinBox::mapValueToText( int value )
434{
435 if(value==0 && m_Etype==NUM)
436 return TQString("0");
437 else if(value==0 && m_Etype!=NUM)
438 return TQString();
439 switch(m_Etype)
440 {
441 case NUM:
442 return TQString::number(value);
443 case ALPHAB_L:
444 return KoParagCounter::makeAlphaLowerNumber( value );
445 case ALPHAB_U:
446 return KoParagCounter::makeAlphaUpperNumber( value );
447 case ROM_NUM_L:
448 return KoParagCounter::makeRomanNumber( value );
449 case ROM_NUM_U:
450 return KoParagCounter::makeRomanNumber( value ).upper();
451 case NONE:
452 default:
453 return TQString();
454 }
455 //never here
456 return TQString();
457}
458
459int KoSpinBox::mapTextToValue( bool * ok )
460{
461 int ret;
462 TQString txt = text();
463
464 *ok = true;
465 switch(m_Etype)
466 {
467 case NUM:
468 ret = txt.toInt ( ok );
469 break;
470 case ALPHAB_L:
471 ret = KoParagCounter::fromAlphaLowerNumber( txt.lower() );
472 break;
473 case ALPHAB_U:
474 ret = KoParagCounter::fromAlphaUpperNumber( txt.upper() );
475 break;
476 case ROM_NUM_L:
477 ret = KoParagCounter::fromRomanNumber( txt.lower() );
478 break;
479 case ROM_NUM_U:
480 ret = KoParagCounter::fromRomanNumber( txt.lower() ); // _not_ upper()
481 break;
482 case NONE:
483 default:
484 ret = -1;
485 break;
486 }
487
488 if (ret == -1)
489 *ok = false;
490
491 return ret;
492}
493
494
495/******************************************************************/
496/* class KPagePreview */
497/******************************************************************/
498
499KPagePreview::KPagePreview( TQWidget* parent, const char* name )
500 : TQGroupBox( i18n( "Preview" ), parent, name )
501{
502 left = 0;
503 right = 0;
504 first = 0;
505 spacing = 0;
506 before = 0;
507 after = 0;
508}
509
510void KPagePreview::drawContents( TQPainter* p )
511{
512 int wid = 148;
513 int hei = 210;
514 int _x = ( width() - wid ) / 5;
515 int _y = ( height() - hei ) / 5;
516
517 int dl = convert(left);
518 int dr = convert(right);
519
520 //first+left because firstlineIndent is relative to leftIndent
521 int df = convert(first + left);
522
523 int spc = convert(spacing);
524
525 // draw page
526 p->setPen( TQPen( black ) );
527 p->setBrush( TQBrush( black ) );
528
529 p->drawRect( _x + 1, _y + 1, wid, hei );
530
531 p->setBrush( TQBrush( white ) );
532 p->drawRect( _x, _y, wid, hei );
533
534 // draw parags
535 p->setPen( NoPen );
536 p->setBrush( TQBrush( lightGray ) );
537
538 for ( int i = 1; i <= 4; i++ )
539 p->drawRect( _x + 6, _y + 6 + ( i - 1 ) * 12 + 2, wid - 12 - ( ( i / 4 ) * 4 == i ? 50 : 0 ), 6 );
540
541 p->setBrush( TQBrush( darkGray ) );
542
543 for ( int i = 5; i <= 8; i++ )
544 {
545 TQRect rect( ( i == 5 ? df : dl ) + _x + 6, _y + 6 + ( i - 1 ) * 12 + 2 + ( i - 5 ) * spc + static_cast<int>( before / 2 ),
546 wid - 12 - ( ( i / 4 ) * 4 == i ? 50 : 0 ) - ( ( i == 12 ? 0 : dr ) + ( i == 5 ? df : dl ) ), 6);
547
548 if(rect.width ()>=0)
549 p->drawRect( rect );
550 }
551 p->setBrush( TQBrush( lightGray ) );
552
553 for ( int i = 9; i <= 12; i++ )
554 p->drawRect( _x + 6, _y + 6 + ( i - 1 ) * 12 + 2 + 3 * spc +
555 static_cast<int>( before / 2 ) + static_cast<int>( after / 2 ),
556 wid - 12 - ( ( i / 4 ) * 4 == i ? 50 : 0 ), 6 );
557
558}
559
560int KPagePreview::convert(double input) {
561 if(input < 1) return 0;
562 if(input <= 5) return 3;
563 if(input <= 10) return 4 + static_cast<int>( (input-5) / 2.5 );
564 if(input <= 20) return 6 + static_cast<int>( (input-10) / 4 );
565 if(input <= 100) return 10 + static_cast<int>( (input-20) / 8 );
566 return static_cast<int>( input / 5);
567}
568
569/******************************************************************/
570/* class KPagePreview2 */
571/******************************************************************/
572
573KPagePreview2::KPagePreview2( TQWidget* parent, const char* name )
574 : TQGroupBox( i18n( "Preview" ), parent, name )
575{
576 align = TQt::AlignLeft;
577}
578
579void KPagePreview2::drawContents( TQPainter* p )
580{
581 int wid = 148;
582 int hei = 210;
583 int _x = ( width() - wid ) / 2;
584 int _y = ( height() - hei ) / 2;
585
586 // draw page
587 p->setPen( TQPen( black ) );
588 p->setBrush( TQBrush( black ) );
589
590 p->drawRect( _x + 1, _y + 1, wid, hei );
591
592 p->setBrush( TQBrush( white ) );
593 p->drawRect( _x, _y, wid, hei );
594
595 // draw parags
596 p->setPen( NoPen );
597 p->setBrush( TQBrush( lightGray ) );
598
599 for ( int i = 1; i <= 4; i++ )
600 p->drawRect( _x + 6, _y + 6 + ( i - 1 ) * 12 + 2, wid - 12 - ( ( i / 4 ) * 4 == i ? 50 : 0 ), 6 );
601
602 p->setBrush( TQBrush( darkGray ) );
603
604 int __x = 0, __w = 0;
605 for ( int i = 5; i <= 8; i++ ) {
606 switch ( i ) {
607 case 5: __w = wid - 12;
608 break;
609 case 6: __w = wid - 52;
610 break;
611 case 7: __w = wid - 33;
612 break;
613 case 8: __w = wid - 62;
614 default: break;
615 }
616
617 switch ( align ) {
618 case TQt::AlignAuto:
619 case TQt::AlignLeft:
620 __x = _x + 6;
621 break;
622 case TQt::AlignHCenter:
623 __x = _x + ( wid - __w ) / 2;
624 break;
625 case TQt::AlignRight:
626 __x = _x + ( wid - __w ) - 6;
627 break;
628 case TQt::AlignJustify:
629 {
630 if ( i < 8 ) __w = wid - 12;
631 __x = _x + 6;
632 } break;
633 }
634
635 p->drawRect( __x, _y + 6 + ( i - 1 ) * 12 + 2 + ( i - 5 ), __w, 6 );
636 }
637
638 p->setBrush( TQBrush( lightGray ) );
639
640 for ( int i = 9; i <= 12; i++ )
641 p->drawRect( _x + 6, _y + 6 + ( i - 1 ) * 12 + 2 + 3, wid - 12 - ( ( i / 4 ) * 4 == i ? 50 : 0 ), 6 );
642
643}
644
645/******************************************************************/
646/* class KoBorderPreview */
647/******************************************************************/
648
649
650KoBorderPreview::KoBorderPreview( TQWidget* parent, const char* name )
651 :TQFrame(parent,name)
652{
653}
654
655void KoBorderPreview::mousePressEvent( TQMouseEvent *_ev )
656{
657 emit choosearea(_ev);
658}
659
660void KoBorderPreview::setBorder( KoBorder::BorderType which, const KoBorder& border)
661{
662 switch( which ) {
663 case KoBorder::TopBorder:
664 setTopBorder( border );
665 break;
666 case KoBorder::BottomBorder:
667 setBottomBorder( border );
668 break;
669 case KoBorder::LeftBorder:
670 setLeftBorder( border );
671 break;
672 case KoBorder::RightBorder:
673 setRightBorder( border );
674 break;
675 default:
676 kdError() << "KoBorderPreview: unknown border type" << endl;
677 }
678}
679
680void KoBorderPreview::drawContents( TQPainter* painter )
681{
682 TQRect r = contentsRect();
683 TQFontMetrics fm( font() );
684
685 painter->fillRect( r.x() + fm.width( 'W' ), r.y() + fm.height(), r.width() - 2 * fm.width( 'W' ),
686 r.height() - 2 * fm.height(), white );
687 painter->setClipRect( r.x() + fm.width( 'W' ), r.y() + fm.height(), r.width() - 2 * fm.width( 'W' ),
688 r.height() - 2 * fm.height() );
689
690 bool leftdouble = m_leftBorder.width() > 0 && m_leftBorder.getStyle() == KoBorder::DOUBLE_LINE;
691 bool rightdouble = m_rightBorder.width() > 0 && m_rightBorder.getStyle() == KoBorder::DOUBLE_LINE;
692 bool topdouble = m_topBorder.width() > 0 && m_topBorder.getStyle() == KoBorder::DOUBLE_LINE;
693 bool bottomdouble = m_bottomBorder.width() > 0 && m_bottomBorder.getStyle() == KoBorder::DOUBLE_LINE;
694
695 if ( m_topBorder.width() > 0 ) {
696 painter->setPen( setBorderPen( m_topBorder ) );
697 painter->drawLine( r.x() + 20, r.y() + 30, r.right() - 19, r.y() + 30 );
698 if ( m_topBorder.getStyle()==KoBorder::DOUBLE_LINE)
699 painter->drawLine( int(r.x() + 20 + ( leftdouble ? m_leftBorder.width() + 1 : 0) ),
700 int(r.y() + 30 + m_topBorder.width()+1),
701 int(r.right() - 19 - ( rightdouble ? m_rightBorder.width() + 1 : 0) ),
702 int(r.y() + 30 + m_topBorder.width()+1)
703 );
704 }
705
706 if ( m_bottomBorder.width() > 0 ) {
707 painter->setPen( setBorderPen( m_bottomBorder ) );
708 painter->drawLine( r.x() + 20, r.bottom() - 30, r.right() - 19, r.bottom() - 30 );
709 if ( m_bottomBorder.getStyle()==KoBorder::DOUBLE_LINE)
710 painter->drawLine( int(r.x() + 20 + ( leftdouble ? m_leftBorder.width() + 1 : 0) ),
711 int(r.bottom() - 30 - m_bottomBorder.width()-1),
712 int(r.right() - 19 - ( rightdouble ? m_rightBorder.width() + 1 : 0) ),
713 int(r.bottom() - 30 - m_bottomBorder.width() - 1)
714 );
715 }
716
717 if ( m_leftBorder.width() > 0 ) {
718 painter->setPen( setBorderPen( m_leftBorder ) );
719 painter->drawLine( r.x() + 20, r.y() + 30, r.x() + 20, r.bottom() - 29 );
720 if ( m_leftBorder.getStyle()==KoBorder::DOUBLE_LINE)
721 painter->drawLine( int(r.x() + 20 + m_leftBorder.width() +1),
722 int(r.y() + 30 + ( topdouble ? m_topBorder.width() + 1 : 0) ),
723 int(r.x() + 20 + m_leftBorder.width() +1),
724 int(r.bottom() - 29 - ( bottomdouble ? m_bottomBorder.width() + 1 : 0) )
725 );
726 }
727
728 if ( m_rightBorder.width() > 0 ) {
729 painter->setPen( setBorderPen( m_rightBorder ) );
730 painter->drawLine( r.right() - 20, r.y() + 30, r.right() - 20, r.bottom() - 29 );
731 if ( m_rightBorder.getStyle()==KoBorder::DOUBLE_LINE)
732 painter->drawLine( int(r.right() - 20 - m_rightBorder.width() - 1 ),
733 int(r.y() + 30 + ( topdouble ? m_topBorder.width() + 1 : 0) ),
734 int(r.right() - 20 - m_rightBorder.width() - 1),
735 int(r.bottom() - 29 - ( bottomdouble ? m_bottomBorder.width() + 1 : 0) )
736 );
737 }
738}
739
740TQPen KoBorderPreview::setBorderPen( KoBorder _brd )
741{
742 TQPen pen( black, 1, SolidLine );
743
744 pen.setWidth( static_cast<int>( _brd.penWidth() ) );
745 pen.setColor( _brd.color );
746
747 switch ( _brd.getStyle() ) {
748 case KoBorder::SOLID:
749 pen.setStyle( TQt::SolidLine );
750 break;
751 case KoBorder::DASH:
752 pen.setStyle( TQt::DashLine );
753 break;
754 case KoBorder::DOT:
755 pen.setStyle( TQt::DotLine );
756 break;
757 case KoBorder::DASH_DOT:
758 pen.setStyle( TQt::DashDotLine );
759 break;
760 case KoBorder::DASH_DOT_DOT:
761 pen.setStyle( TQt::DashDotDotLine );
762 break;
763 case KoBorder::DOUBLE_LINE:
764 pen.setStyle( TQt::SolidLine );
765 break;
766 }
767
768 return TQPen( pen );
769}
770
771/******************************************************************/
772/* Class: KoStylePreview. Previewing text with style ;) */
773/******************************************************************/
774class MyFlow : public KoTextFlow {
775 public:
776 MyFlow(TQWidget *parent, KoTextZoomHandler *zoom) {
777 m_parent = parent;
778 m_zoomHandler = zoom;
779 }
780 int availableHeight() const {
781 return m_zoomHandler->pixelToLayoutUnitY(m_parent->height());
782 }
783 private:
784 TQWidget *m_parent;
785 KoTextZoomHandler *m_zoomHandler;
786};
787
788KoStylePreview::KoStylePreview( const TQString& title, const TQString& text, TQWidget* parent, const char* name )
789 : TQGroupBox( title, parent, name )
790{
791 setMinimumHeight(80);
792 m_zoomHandler = new KoTextZoomHandler;
793 TQFont font = KoGlobal::defaultFont();
794 m_textdoc = new KoTextDocument( m_zoomHandler, new KoTextFormatCollection( font, TQColor(), TDEGlobal::locale()->language(), false ) );
795
796 m_textdoc->setFlow( new MyFlow(this, m_zoomHandler) );
797 //m_textdoc->setWidth( KoTextZoomHandler::ptToLayoutUnitPt( 1000 ) );
798 KoTextParag * parag = m_textdoc->firstParag();
799 parag->insert( 0, text );
800}
801
802KoStylePreview::~KoStylePreview()
803{
804 delete m_textdoc;
805 delete m_zoomHandler;
806}
807
809{
810 KoTextParag * parag = m_textdoc->firstParag();
811 parag->setCounter( counter );
812 repaint( true );
813}
814
816{
817 KoTextParag * parag = m_textdoc->firstParag();
818 parag->applyStyle( style );
819 repaint(true);
820}
821
822void KoStylePreview::drawContents( TQPainter *painter )
823{
824 painter->save();
825 TQRect r = contentsRect();
826 //kdDebug(32500) << "KoStylePreview::drawContents contentsRect=" << DEBUGRECT(r) << endl;
827
828 TQRect whiteRect( r.x() + 10, r.y() + 10,
829 r.width() - 20, r.height() - 20 );
830 TQColorGroup cg = TQApplication::palette().active();
831 painter->fillRect( whiteRect, cg.brush( TQColorGroup::Base ) );
832
833 KoTextParag * parag = m_textdoc->firstParag();
834 int widthLU = m_zoomHandler->pixelToLayoutUnitX( whiteRect.width() - 2 ); // keep one pixel border horizontally
835 if ( m_textdoc->width() != widthLU )
836 {
837 // For centering to work, and to even get word wrapping when the thing is too big :)
838 m_textdoc->setWidth( widthLU );
839 parag->invalidate(0);
840 }
841
842 parag->format();
843 TQRect textRect = parag->pixelRect( m_zoomHandler );
844
845 // Center vertically, but not horizontally, to keep the parag alignment working,
846 textRect.moveTopLeft( TQPoint( whiteRect.x(),
847 whiteRect.y() + ( whiteRect.height() - textRect.height() ) / 2 ) );
848 // Move it from the left border a little
849 textRect.rLeft() += 4;
850 textRect.rRight() += 4;
851 //kdDebug(32500) << "KoStylePreview::drawContents textRect=" << DEBUGRECT(textRect)
852 // << " textSize=" << textSize.width() << "," << textSize.height() << endl;
853 painter->setClipRect( textRect.intersect( whiteRect ) );
854 painter->translate( textRect.x(), textRect.y() );
855
856 m_textdoc->drawWYSIWYG( painter, 0, 0, textRect.width(), textRect.height(), cg, m_zoomHandler );
857 painter->restore();
858}
859
860KoIndentSpacingWidget::KoIndentSpacingWidget( KoUnit::Unit unit, double _frameWidth,TQWidget * parent, const char * name )
861 : KoParagLayoutWidget( KoParagDia::PD_SPACING, parent, name ), m_unit( unit )
862{
863 TQString unitName = KoUnit::unitName( m_unit );
864 TQGridLayout *mainGrid = new TQGridLayout( this, 3, 2, KDialog::marginHint(), KDialog::spacingHint() );
865
866 // mainGrid gives equal space to each groupbox, apparently
867 // I tried setRowStretch but the result is awful (much space between them and not equal!)
868 // Any other way (in order to make the 2nd, the one with a single checkbox, a bit
869 // smaller than the other 3) ? (DF)
870
871
872 // --------------- indent ---------------
873 double frameWidth=_frameWidth;
874 TQString length;
875 if(frameWidth==-1) {
876 frameWidth=9999;
877 } else {
878 length=i18n("Frame width: %1 %2")
879 .arg(KoUnit::toUserStringValue(frameWidth,m_unit))
880 .arg(KoUnit::unitName(m_unit));
881 frameWidth=KoUnit::toUserValue(frameWidth,m_unit);
882 }
883
884 TQGroupBox * indentFrame = new TQGroupBox( i18n( "Indent" ), this );
885 TQGridLayout * indentGrid = new TQGridLayout( indentFrame, 5, 2, KDialog::marginHint(), KDialog::spacingHint() );
886
887 TQLabel * lLimit = new TQLabel(length , indentFrame );
888 if(frameWidth!=-1)
889 {
890 lLimit->setAlignment( AlignRight );
891 indentGrid->addWidget( lLimit, 1,0 );
892 }
893
894 TQLabel * lLeft = new TQLabel( i18n("&Left:"), indentFrame );
895 lLeft->setAlignment( TQt::AlignVCenter | TQt::AlignRight );
896 indentGrid->addWidget( lLeft, 1, 0 );
897
898 eLeft = new KoUnitDoubleSpinBox( indentFrame, 0, 9999, 1, 0.0, m_unit );
899 lLeft->setBuddy( eLeft );
900 indentGrid->addWidget( eLeft, 1, 1 );
901 connect( eLeft, TQ_SIGNAL( valueChangedPt(double ) ), this, TQ_SLOT( leftChanged( double ) ) );
902
903 TQLabel * lRight = new TQLabel( i18n("&Right:"), indentFrame );
904 lRight->setAlignment( TQt::AlignVCenter | TQt::AlignRight );
905 indentGrid->addWidget( lRight, 2, 0 );
906
907 eRight = new KoUnitDoubleSpinBox( indentFrame, 0, 9999, 1, 0.0, m_unit );
908 lRight->setBuddy( eRight );
909 indentGrid->addWidget( eRight, 2, 1 );
910 connect( eRight, TQ_SIGNAL( valueChangedPt( double ) ), this, TQ_SLOT( rightChanged( double ) ) );
911
912 TQLabel * lFirstLine = new TQLabel( i18n("&First line:"), indentFrame );
913 lFirstLine->setAlignment( TQt::AlignVCenter | TQt::AlignRight );
914 indentGrid->addWidget( lFirstLine, 3, 0 );
915
916 eFirstLine = new KoUnitDoubleSpinBox( indentFrame, -9999, 9999, 1, 0.0, m_unit );
917 lFirstLine->setBuddy( eFirstLine );
918 connect( eFirstLine, TQ_SIGNAL( valueChangedPt( double ) ), this, TQ_SLOT( firstChanged( double ) ) );
919 indentGrid->addWidget( eFirstLine, 3, 1 );
920
921 // grid row spacing
922 indentGrid->addRowSpacing( 0, fontMetrics().height() / 2 ); // groupbox title
923 for ( int i = 1 ; i < indentGrid->numRows() ; ++i )
924 indentGrid->setRowStretch( i, 1 );
925 mainGrid->addWidget( indentFrame, 0, 0 );
926
927 // --------------- line spacing ---------------
928 TQGroupBox * spacingFrame = new TQGroupBox( i18n( "Line &Spacing" ), this, "spacingFrame" );
929 TQGridLayout * spacingGrid = new TQGridLayout( spacingFrame, 2, 1,
931
932 cSpacing = new TQComboBox( false, spacingFrame, "" );
933 // Keep order in sync with lineSpacingType() and display()
934 cSpacing->insertItem( i18n( "Line spacing value", "Single" ) );
935 cSpacing->insertItem( i18n( "Line spacing value", "1.5 Lines" ) );
936 cSpacing->insertItem( i18n( "Line spacing value", "Double" ) );
937 cSpacing->insertItem( i18n( "Proportional") ); // LS_MULTIPLE, called Proportional like in OO
938 cSpacing->insertItem( i18n( "Line Distance (%1)" ).arg(unitName) ); // LS_CUSTOM
939 cSpacing->insertItem( i18n( "At Least (%1)" ).arg(unitName) );
940 cSpacing->insertItem( i18n( "Fixed (%1)").arg(unitName) ); // LS_FIXED
941
942 connect( cSpacing, TQ_SIGNAL( activated( int ) ), this, TQ_SLOT( spacingActivated( int ) ) );
943 spacingGrid->addWidget( cSpacing, 1, 0 );
944
945 sSpacingStack = new TQWidgetStack( spacingFrame );
946
947 eSpacing = new KoUnitDoubleSpinBox( spacingFrame, 0, 9999, CM_TO_POINT(1),
948 0.0, m_unit );
949 eSpacing->setRange( 0, 9999, 1, false);
950 connect( eSpacing, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( spacingChanged( double ) ) );
951 eSpacingPercent = new KIntNumInput( 100, spacingFrame );
952 eSpacingPercent->setRange( 0, 1000, 10, false );
953 eSpacingPercent->setSuffix( " %" );
954 connect( eSpacingPercent, TQ_SIGNAL( valueChanged( int ) ), this, TQ_SLOT( spacingChanged( int ) ) );
955
956 sSpacingStack->addWidget( eSpacing );
957 sSpacingStack->addWidget( eSpacingPercent );
958 spacingGrid->addWidget( sSpacingStack, 1, 1 );
959
960 // grid row spacing
961 spacingGrid->addRowSpacing( 0, fontMetrics().height() / 2 ); // groupbox title
962 for ( int i = 1 ; i < spacingGrid->numRows() ; ++i )
963 spacingGrid->setRowStretch( i, 1 );
964 mainGrid->addWidget( spacingFrame, 1, 0 );
965
966 eSpacing->setEnabled( true );
967
968 // --------------- paragraph spacing ---------------
969 TQGroupBox * pSpaceFrame = new TQGroupBox( i18n( "Para&graph Space" ), this, "pSpaceFrame" );
970 TQGridLayout * pSpaceGrid = new TQGridLayout( pSpaceFrame, 3, 2,
972
973 TQLabel * lBefore = new TQLabel( i18n("Before:"), pSpaceFrame );
974 lBefore->setAlignment( AlignRight );
975 pSpaceGrid->addWidget( lBefore, 1, 0 );
976
977 eBefore = new KoUnitDoubleSpinBox( pSpaceFrame, 0, 9999, CM_TO_POINT(1), 0.0, m_unit );
978 eBefore->setRange( 0 , 9999, 1, false);
979 connect( eBefore, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( beforeChanged( double ) ) );
980 pSpaceGrid->addWidget( eBefore, 1, 1 );
981
982 TQLabel * lAfter = new TQLabel( i18n("After:"), pSpaceFrame );
983 lAfter->setAlignment( AlignRight );
984 pSpaceGrid->addWidget( lAfter, 2, 0 );
985
986 eAfter = new KoUnitDoubleSpinBox( pSpaceFrame, 0, 9999, 1, 0.0, m_unit );
987 eAfter->setRange( 0, 9999, 1, false);
988 connect( eAfter, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( afterChanged( double ) ) );
989 pSpaceGrid->addWidget( eAfter, 2, 1 );
990
991 // grid row spacing
992 pSpaceGrid->addRowSpacing( 0, fontMetrics().height() / 2 ); // groupbox title
993 for ( int i = 1 ; i < pSpaceGrid->numRows() ; ++i )
994 pSpaceGrid->setRowStretch( i, 1 );
995 mainGrid->addWidget( pSpaceFrame, 2, 0 );
996
997 // --------------- preview --------------------
998 prev1 = new KPagePreview( this, "KPagePreview" );
999 mainGrid->addMultiCellWidget( prev1, 0, mainGrid->numRows()-1, 1, 1 );
1000
1001 mainGrid->setColStretch( 1, 1 );
1002 //mainGrid->setRowStretch( 4, 1 );
1003}
1004
1005double KoIndentSpacingWidget::leftIndent() const
1006{
1007 return TQMAX(0, eLeft->value() );
1008}
1009
1010double KoIndentSpacingWidget::rightIndent() const
1011{
1012 return TQMAX(0,eRight->value() );
1013}
1014
1015double KoIndentSpacingWidget::firstLineIndent() const
1016{
1017 return eFirstLine->value();
1018}
1019
1020double KoIndentSpacingWidget::spaceBeforeParag() const
1021{
1022 return TQMAX(0, eBefore->value() );
1023}
1024
1025double KoIndentSpacingWidget::spaceAfterParag() const
1026{
1027 return TQMAX(0, eAfter->value() );
1028}
1029
1030KoParagLayout::SpacingType KoIndentSpacingWidget::lineSpacingType() const
1031{
1032 int index = cSpacing->currentItem();
1033 switch ( index ) {
1034 case 0:
1035 return KoParagLayout::LS_SINGLE;
1036 case 1:
1037 return KoParagLayout::LS_ONEANDHALF;
1038 case 2:
1039 return KoParagLayout::LS_DOUBLE;
1040 case 3:
1041 return KoParagLayout::LS_MULTIPLE;
1042 case 4:
1043 return KoParagLayout::LS_CUSTOM;
1044 case 5:
1045 return KoParagLayout::LS_AT_LEAST;
1046 case 6:
1047 return KoParagLayout::LS_FIXED;
1048 default:
1049 kdError(32500) << "Error in KoIndentSpacingWidget::lineSpacingType" << endl;
1050 return KoParagLayout::LS_SINGLE;
1051 }
1052}
1053
1054double KoIndentSpacingWidget::lineSpacing() const
1055{
1056 return (lineSpacingType() == KoParagLayout::LS_MULTIPLE)
1057 ? TQMAX( 1, eSpacingPercent->value() ) / 100.0
1058 : TQMAX( 0, eSpacing->value() );
1059}
1060
1061
1062void KoIndentSpacingWidget::display( const KoParagLayout & lay )
1063{
1064 double _left = lay.margins[TQStyleSheetItem::MarginLeft];
1065 eLeft->changeValue( _left );
1066 //prev1->setLeft( _left ); done by leftChanged() below
1067 leftChanged( _left ); // sets min value for eFirstLine
1068
1069 double _right = lay.margins[TQStyleSheetItem::MarginRight];
1070 eRight->changeValue( _right );
1071 prev1->setRight( _right );
1072
1073 double _first = lay.margins[TQStyleSheetItem::MarginFirstLine];
1074 eFirstLine->changeValue( _first );
1075 prev1->setFirst( _first );
1076
1077 double _before = lay.margins[TQStyleSheetItem::MarginTop];
1078 eBefore->changeValue( _before );
1079 prev1->setBefore( _before );
1080
1081 double _after = lay.margins[TQStyleSheetItem::MarginBottom];
1082 eAfter->changeValue( _after );
1083 prev1->setAfter( _after );
1084
1085 double _spacing = lay.lineSpacingValue();
1086 KoParagLayout::SpacingType _type = lay.lineSpacingType;
1087 switch ( _type ) {
1088 case KoParagLayout::LS_SINGLE: // single
1089 cSpacing->setCurrentItem( 0 );
1090 break;
1091 case KoParagLayout::LS_ONEANDHALF:
1092 cSpacing->setCurrentItem( 1 );
1093 break;
1094 case KoParagLayout::LS_DOUBLE:
1095 cSpacing->setCurrentItem( 2 );
1096 break;
1097 case KoParagLayout::LS_MULTIPLE:
1098 cSpacing->setCurrentItem( 3 );
1099 break;
1100 case KoParagLayout::LS_CUSTOM:
1101 cSpacing->setCurrentItem( 4 );
1102 break;
1103 case KoParagLayout::LS_AT_LEAST:
1104 cSpacing->setCurrentItem( 5 );
1105 break;
1106 case KoParagLayout::LS_FIXED:
1107 cSpacing->setCurrentItem( 6 );
1108 break;
1109 default:
1110 cSpacing->setCurrentItem( 0 );
1111 break;
1112 }
1113
1114 updateLineSpacing( _type );
1115 eSpacing->setValue( (_type == KoParagLayout::LS_MULTIPLE) ? TQMAX( 1, _spacing )
1116 : KoUnit::toUserValue( _spacing, m_unit ) );
1117 eSpacingPercent->setValue( ( _type == KoParagLayout::LS_MULTIPLE ) ? tqRound( _spacing * 100 ) : 100 );
1118}
1119
1120void KoIndentSpacingWidget::save( KoParagLayout & lay )
1121{
1122 lay.setLineSpacingValue(lineSpacing());
1123 lay.lineSpacingType = lineSpacingType();
1124 lay.margins[TQStyleSheetItem::MarginLeft] = leftIndent();
1125 lay.margins[TQStyleSheetItem::MarginRight] = rightIndent();
1126 lay.margins[TQStyleSheetItem::MarginFirstLine] = firstLineIndent();
1127 lay.margins[TQStyleSheetItem::MarginTop] = spaceBeforeParag();
1128 lay.margins[TQStyleSheetItem::MarginBottom] = spaceAfterParag();
1129}
1130
1132{
1133 return i18n( "Indent && S&pacing" );
1134}
1135
1136void KoIndentSpacingWidget::leftChanged( double val )
1137{
1138 prev1->setLeft( val );
1139 // The minimum first-line margin is -leftMargin() (where leftMargin>=0)
1140 eFirstLine->setMinValue( -TQMAX( 0, val ) );
1141}
1142
1143void KoIndentSpacingWidget::rightChanged( double val )
1144{
1145 prev1->setRight( val );
1146}
1147
1148void KoIndentSpacingWidget::firstChanged( double val )
1149{
1150 prev1->setFirst( val );
1151}
1152
1153void KoIndentSpacingWidget::updateLineSpacing( KoParagLayout::SpacingType _type )
1154{
1155 bool needsValue = (_type != KoParagLayout::LS_SINGLE &&
1156 _type != KoParagLayout::LS_ONEANDHALF &&
1157 _type != KoParagLayout::LS_DOUBLE);
1158
1159 if ( _type == KoParagLayout::LS_MULTIPLE )
1160 {
1161 sSpacingStack->raiseWidget( eSpacingPercent );
1162 }
1163 else
1164 {
1165 sSpacingStack->raiseWidget( eSpacing );
1166 }
1167 eSpacing->setEnabled( needsValue );
1168 if ( needsValue )
1169 prev1->setSpacing( eSpacing->value() );
1170 else
1171 {
1172 prev1->setSpacing( _type == KoParagLayout::LS_ONEANDHALF ? 8 :
1173 _type == KoParagLayout::LS_DOUBLE ? 16 :0 );
1174 }
1175}
1176
1177void KoIndentSpacingWidget::spacingActivated( int /*_index*/ )
1178{
1179 updateLineSpacing( lineSpacingType() );
1180 if ( eSpacing->isEnabled() ) // i.e. needsValue = true
1181 eSpacing->setFocus();
1182}
1183
1184void KoIndentSpacingWidget::spacingChanged( double _val )
1185{
1186 prev1->setSpacing( _val );
1187}
1188
1189void KoIndentSpacingWidget::spacingChanged( int _val )
1190{
1191 prev1->setSpacing( _val / 100.0 );
1192}
1193
1194void KoIndentSpacingWidget::beforeChanged( double _val )
1195{
1196 prev1->setBefore( KoUnit::fromUserValue( _val, m_unit ) );
1197}
1198
1199void KoIndentSpacingWidget::afterChanged( double _val )
1200{
1201 prev1->setAfter( KoUnit::fromUserValue( _val, m_unit ) );
1202}
1203
1204
1205KoParagAlignWidget::KoParagAlignWidget( bool breakLine, TQWidget * parent, const char * name )
1206 : KoParagLayoutWidget( KoParagDia::PD_ALIGN, parent, name )
1207{
1208 TQGridLayout *grid = new TQGridLayout( this, 3, 2, KDialog::marginHint(), KDialog::spacingHint() );
1209
1210 TQVGroupBox * AlignGroup = new TQVGroupBox( i18n( "Alignment" ), this );
1211
1212 rLeft = new TQRadioButton( i18n( "&Left" ), AlignGroup );
1213 connect( rLeft, TQ_SIGNAL( clicked() ), this, TQ_SLOT( alignLeft() ) );
1214
1215 rCenter = new TQRadioButton( i18n( "C&enter" ), AlignGroup );
1216 connect( rCenter, TQ_SIGNAL( clicked() ), this, TQ_SLOT( alignCenter() ) );
1217
1218 rRight = new TQRadioButton( i18n( "&Right" ), AlignGroup );
1219 connect( rRight, TQ_SIGNAL( clicked() ), this, TQ_SLOT( alignRight() ) );
1220
1221 rJustify = new TQRadioButton( i18n( "&Justify" ), AlignGroup );
1222 connect( rJustify, TQ_SIGNAL( clicked() ), this, TQ_SLOT( alignJustify() ) );
1223
1224 clearAligns();
1225 rLeft->setChecked( true );
1226
1227 grid->addWidget(AlignGroup, 0, 0);
1228
1229 // --------------- End of page /frame ---------------
1230 TQGroupBox * endFramePage = new TQGroupBox( i18n( "Behavior at &End of Frame/Page" ), this );
1231 TQGridLayout * endFramePageGrid = new TQGridLayout( endFramePage, 4, 1,
1233
1234 cKeepLinesTogether = new TQCheckBox( i18n("&Keep lines together"),endFramePage);
1235 endFramePageGrid->addWidget( cKeepLinesTogether, 1, 0 );
1236 cHardBreakBefore = new TQCheckBox( i18n("Insert break before paragraph"),endFramePage);
1237 endFramePageGrid->addWidget( cHardBreakBefore, 2, 0 );
1238 cHardBreakAfter = new TQCheckBox( i18n("Insert break after paragraph"),endFramePage);
1239 endFramePageGrid->addWidget( cHardBreakAfter, 3, 0 );
1240
1241 endFramePageGrid->addRowSpacing( 0, fontMetrics().height() / 2 ); // groupbox title
1242 for ( int i = 0 ; i < endFramePageGrid->numRows()-1 ; ++i )
1243 endFramePageGrid->setRowStretch( 0, 0 );
1244 endFramePageGrid->setRowStretch( endFramePageGrid->numRows()-1, 1 );
1245 grid->addWidget( endFramePage, 2, 0 );
1246
1247 endFramePage->setEnabled(breakLine);
1248
1249 // --------------- preview --------------------
1250 prev2 = new KPagePreview2( this, "KPagePreview2" );
1251 grid->addMultiCellWidget( prev2, 0, 2, 1, 1 );
1252
1253 // --------------- main grid ------------------
1254 grid->setColStretch( 1, 1 );
1255 grid->setRowStretch( 1, 1 );
1256}
1257
1258int KoParagAlignWidget::pageBreaking() const
1259{
1260 int pb = 0;
1261 if ( cKeepLinesTogether->isChecked() )
1262 pb |= KoParagLayout::KeepLinesTogether;
1263 if ( cHardBreakBefore->isChecked() )
1264 pb |= KoParagLayout::HardFrameBreakBefore;
1265 if ( cHardBreakAfter->isChecked() )
1266 pb |= KoParagLayout::HardFrameBreakAfter;
1267 return pb;
1268}
1269
1270
1271void KoParagAlignWidget::display( const KoParagLayout & lay )
1272{
1273 int align = lay.alignment;
1274 prev2->setAlign( align );
1275
1276 clearAligns();
1277 switch ( align ) {
1278 case TQt::AlignAuto: // see KoView::setAlign
1279 case TQt::AlignLeft:
1280 rLeft->setChecked( true );
1281 break;
1282 case TQt::AlignHCenter:
1283 rCenter->setChecked( true );
1284 break;
1285 case TQt::AlignRight:
1286 rRight->setChecked( true );
1287 break;
1288 case TQt::AlignJustify:
1289 rJustify->setChecked( true );
1290 }
1291
1292 cKeepLinesTogether->setChecked( lay.pageBreaking & KoParagLayout::KeepLinesTogether );
1293 cHardBreakBefore->setChecked( lay.pageBreaking & KoParagLayout::HardFrameBreakBefore );
1294 cHardBreakAfter->setChecked( lay.pageBreaking & KoParagLayout::HardFrameBreakAfter );
1295 // ## preview support for end-of-frame ?
1296}
1297
1298void KoParagAlignWidget::save( KoParagLayout & lay )
1299{
1300 lay.alignment = align();
1301 lay.pageBreaking = pageBreaking();
1302}
1303
1304int KoParagAlignWidget::align() const
1305{
1306 if ( rLeft->isChecked() ) return TQt::AlignLeft;
1307 else if ( rCenter->isChecked() ) return TQt::AlignHCenter;
1308 else if ( rRight->isChecked() ) return TQt::AlignRight;
1309 else if ( rJustify->isChecked() ) return TQt::AlignJustify;
1310
1311 return TQt::AlignLeft;
1312}
1313
1315{
1316 return i18n( "General &Layout" );
1317}
1318
1319void KoParagAlignWidget::alignLeft()
1320{
1321 prev2->setAlign( TQt::AlignLeft );
1322 clearAligns();
1323 rLeft->setChecked( true );
1324}
1325
1326void KoParagAlignWidget::alignCenter()
1327{
1328 prev2->setAlign( TQt::AlignHCenter );
1329 clearAligns();
1330 rCenter->setChecked( true );
1331}
1332
1333void KoParagAlignWidget::alignRight()
1334{
1335 prev2->setAlign( TQt::AlignRight );
1336 clearAligns();
1337 rRight->setChecked( true );
1338}
1339
1340void KoParagAlignWidget::alignJustify()
1341{
1342 prev2->setAlign( TQt::AlignJustify );
1343 clearAligns();
1344 rJustify->setChecked( true );
1345}
1346
1347void KoParagAlignWidget::clearAligns()
1348{
1349 rLeft->setChecked( false );
1350 rCenter->setChecked( false );
1351 rRight->setChecked( false );
1352 rJustify->setChecked( false );
1353}
1354
1356
1357KoParagDecorationWidget::KoParagDecorationWidget( TQWidget * parent,
1358 const char * name )
1359 : KoParagLayoutWidget( KoParagDia::PD_DECORATION, parent, name )
1360{
1361 TQVBoxLayout *tabLayout = new TQVBoxLayout( this );
1362 wDeco = new KoParagDecorationTab( this );
1363 tabLayout->add( wDeco );
1364
1365 // Set up Border Style combo box
1366 wDeco->cbBorderStyle->insertItem( KoBorder::getStyle( KoBorder::SOLID ) );
1367 wDeco->cbBorderStyle->insertItem( KoBorder::getStyle( KoBorder::DASH ) );
1368 wDeco->cbBorderStyle->insertItem( KoBorder::getStyle( KoBorder::DOT ) );
1369 wDeco->cbBorderStyle->insertItem( KoBorder::getStyle( KoBorder::DASH_DOT ) );
1370 wDeco->cbBorderStyle->insertItem( KoBorder::getStyle( KoBorder::DASH_DOT_DOT ) );
1371 wDeco->cbBorderStyle->insertItem( KoBorder::getStyle( KoBorder::DOUBLE_LINE ) );
1372
1373 // Set up Border Width combo box
1374 for( unsigned int i = 1; i <= 10; i++ )
1375 wDeco->cbBorderWidth->insertItem(TQString::number(i));
1376
1377 // Setup the border toggle buttons, and merge checkbox
1378 connect( wDeco->bBorderLeft, TQ_SIGNAL( toggled( bool ) ),
1379 this, TQ_SLOT( brdLeftToggled( bool ) ) );
1380 connect( wDeco->bBorderRight, TQ_SIGNAL( toggled( bool ) ),
1381 this, TQ_SLOT( brdRightToggled( bool ) ) );
1382 connect( wDeco->bBorderTop, TQ_SIGNAL( toggled( bool ) ),
1383 this, TQ_SLOT( brdTopToggled( bool ) ) );
1384 connect( wDeco->bBorderBottom, TQ_SIGNAL( toggled( bool ) ),
1385 this, TQ_SLOT( brdBottomToggled( bool ) ) );
1386 connect( wDeco->cbJoinBorder, TQ_SIGNAL( toggled( bool ) ),
1387 this, TQ_SLOT( brdJoinToggled( bool ) ) );
1388
1389 // Set up Border preview widget
1390 wPreview = new KoBorderPreview( wDeco->borderPreview );
1391 TQVBoxLayout *previewLayout = new TQVBoxLayout( wDeco->borderPreview );
1392 previewLayout->addWidget( wPreview );
1393 connect( wPreview, TQ_SIGNAL( choosearea(TQMouseEvent * ) ),
1394 this, TQ_SLOT( slotPressEvent(TQMouseEvent *) ) );
1395}
1396
1398// Current GUI selections
1399KoBorder::BorderStyle KoParagDecorationWidget::curBorderStyle() const
1400{
1401 TQString selection = wDeco->cbBorderStyle->currentText();
1402 return KoBorder::getStyle( selection );
1403}
1404
1405unsigned int KoParagDecorationWidget::curBorderWidth() const {
1406 return wDeco->cbBorderWidth->currentText().toUInt();
1407}
1408
1409TQColor KoParagDecorationWidget::curBorderColor() const {
1410 return wDeco->bBorderColor->color();
1411}
1413
1414// Check whether a border is the same as that selected in the GUI
1415bool KoParagDecorationWidget::borderChanged( const KoBorder& border ) {
1416 return (unsigned int)border.penWidth() != curBorderWidth() ||
1417 border.color != curBorderColor() ||
1418 border.getStyle() != curBorderStyle();
1419}
1420
1421// Set a given border according to the values selected in the GUI
1422void KoParagDecorationWidget::updateBorder( KoBorder& border )
1423{
1424 border.setPenWidth( curBorderWidth() );
1425 border.color = curBorderColor();
1426 border.setStyle( curBorderStyle () );
1427}
1428
1429void KoParagDecorationWidget::clickedBorderPreview( KoBorder& border,
1430 KoBorder::BorderType position,
1431 KPushButton *corresponding )
1432{
1433 if ( borderChanged( border ) && corresponding->isOn() ) {
1434 updateBorder( border );
1435 wPreview->setBorder( position, border );
1436 }
1437 else
1438 corresponding->setOn( !corresponding->isOn() );
1439}
1440
1441// Establish which border position was clicked in the border preview,
1442// and update the appropriate border
1443void KoParagDecorationWidget::slotPressEvent(TQMouseEvent *_ev)
1444{
1445 const int OFFSETX = 15;
1446 const int OFFSETY = 7;
1447 const int Ko_SPACE = 30;
1448
1449 TQRect r = wPreview->contentsRect();
1450 TQRect rect(r.x() + OFFSETX, r.y() + OFFSETY,
1451 r.width() - OFFSETX, r.y() + OFFSETY + Ko_SPACE);
1452 if(rect.contains(TQPoint(_ev->x(),_ev->y())))
1453 {
1454 clickedBorderPreview( m_topBorder, KoBorder::TopBorder,
1455 wDeco->bBorderTop );
1456 }
1457
1458 rect.setCoords(r.x() + OFFSETX, r.height() - OFFSETY - Ko_SPACE,
1459 r.width() - OFFSETX, r.height() - OFFSETY);
1460 if(rect.contains(TQPoint(_ev->x(),_ev->y())))
1461 {
1462 clickedBorderPreview( m_bottomBorder, KoBorder::BottomBorder,
1463 wDeco->bBorderBottom );
1464 }
1465
1466 rect.setCoords(r.x() + OFFSETX, r.y() + OFFSETY,
1467 r.x() + Ko_SPACE + OFFSETX, r.height() - OFFSETY);
1468 if(rect.contains(TQPoint(_ev->x(),_ev->y())))
1469 {
1470 clickedBorderPreview( m_leftBorder, KoBorder::LeftBorder,
1471 wDeco->bBorderLeft );
1472 }
1473
1474 rect.setCoords(r.width() - OFFSETX - Ko_SPACE, r.y() + OFFSETY,
1475 r.width() - OFFSETX, r.height() - OFFSETY);
1476 if(rect.contains(TQPoint(_ev->x(),_ev->y())))
1477 {
1478 clickedBorderPreview( m_rightBorder, KoBorder::RightBorder,
1479 wDeco->bBorderRight );
1480 }
1481}
1482
1483void KoParagDecorationWidget::display( const KoParagLayout & lay )
1484{
1485 wDeco->bBackgroundColor->setColor( lay.backgroundColor );
1486
1487 m_leftBorder = lay.leftBorder;
1488 m_rightBorder = lay.rightBorder;
1489 m_topBorder = lay.topBorder;
1490 m_bottomBorder = lay.bottomBorder;
1491 m_joinBorder = lay.joinBorder;
1492
1493 wDeco->bBorderLeft->blockSignals( true );
1494 wDeco->bBorderRight->blockSignals( true );
1495 wDeco->bBorderTop->blockSignals( true );
1496 wDeco->bBorderBottom->blockSignals( true );
1497 updateBorders();
1498 wDeco->bBorderLeft->blockSignals( false );
1499 wDeco->bBorderRight->blockSignals( false );
1500 wDeco->bBorderTop->blockSignals( false );
1501 wDeco->bBorderBottom->blockSignals( false );
1502}
1503
1504void KoParagDecorationWidget::updateBorders()
1505{
1506 wDeco->bBorderLeft->setOn( m_leftBorder.penWidth() > 0 );
1507 wDeco->bBorderRight->setOn( m_rightBorder.penWidth() > 0 );
1508 wDeco->bBorderTop->setOn( m_topBorder.penWidth() > 0 );
1509 wDeco->bBorderBottom->setOn( m_bottomBorder.penWidth() > 0 );
1510 wDeco->cbJoinBorder->setChecked( m_joinBorder );
1511 wPreview->setLeftBorder( m_leftBorder );
1512 wPreview->setRightBorder( m_rightBorder );
1513 wPreview->setTopBorder( m_topBorder );
1514 wPreview->setBottomBorder( m_bottomBorder );
1515}
1516
1517
1518void KoParagDecorationWidget::save( KoParagLayout & lay )
1519{
1520 lay.backgroundColor = wDeco->bBackgroundColor->color();
1521 lay.topBorder = m_topBorder;
1522 lay.bottomBorder = m_bottomBorder;
1523 lay.leftBorder = m_leftBorder;
1524 lay.rightBorder = m_rightBorder;
1525 lay.joinBorder = m_joinBorder;
1526}
1527
1528TQColor KoParagDecorationWidget::backgroundColor() const {
1529 return wDeco->bBackgroundColor->color();
1530}
1531
1533 // Why D&e..? Because &De.. conflicts with &Delete in
1534 // the style manager.
1535 return i18n( "D&ecorations" );
1536}
1537
1538void KoParagDecorationWidget::brdLeftToggled( bool _on )
1539{
1540 if ( !_on )
1541 m_leftBorder.setPenWidth(0);
1542 else {
1543 m_leftBorder.setPenWidth( curBorderWidth() );
1544 m_leftBorder.color = curBorderColor();
1545 m_leftBorder.setStyle( curBorderStyle() );
1546 }
1547 wPreview->setLeftBorder( m_leftBorder );
1548}
1549
1550void KoParagDecorationWidget::brdRightToggled( bool _on )
1551{
1552 if ( !_on )
1553 m_rightBorder.setPenWidth(0);
1554 else {
1555 m_rightBorder.setPenWidth( curBorderWidth() );
1556 m_rightBorder.color = curBorderColor();
1557 m_rightBorder.setStyle( curBorderStyle() );
1558 }
1559 wPreview->setRightBorder( m_rightBorder );
1560}
1561
1562void KoParagDecorationWidget::brdTopToggled( bool _on )
1563{
1564 if ( !_on )
1565 m_topBorder.setPenWidth(0);
1566 else {
1567 m_topBorder.setPenWidth( curBorderWidth() );
1568 m_topBorder.color = curBorderColor();
1569 m_topBorder.setStyle( curBorderStyle() );
1570 }
1571 wPreview->setTopBorder( m_topBorder );
1572}
1573
1574void KoParagDecorationWidget::brdBottomToggled( bool _on )
1575{
1576 if ( !_on )
1577 m_bottomBorder.setPenWidth ( 0 );
1578 else {
1579 m_bottomBorder.setPenWidth( curBorderWidth() );
1580 m_bottomBorder.color = curBorderColor();
1581 m_bottomBorder.setStyle( curBorderStyle() );
1582 }
1583 wPreview->setBottomBorder( m_bottomBorder );
1584}
1585
1586void KoParagDecorationWidget::brdJoinToggled( bool _on ) {
1587 m_joinBorder = _on;
1588}
1590
1591
1592KoParagCounterWidget::KoParagCounterWidget( bool disableAll, TQWidget * parent, const char * name )
1593 : KoParagLayoutWidget( KoParagDia::PD_NUMBERING, parent, name )
1594{
1595
1596 TQVBoxLayout *Form1Layout = new TQVBoxLayout( this );
1597 Form1Layout->setSpacing( KDialog::spacingHint() );
1598 Form1Layout->setMargin( KDialog::marginHint() );
1599
1600 gNumbering = new TQButtonGroup( this, "numberingGroup" );
1601 gNumbering->setTitle( i18n( "Numbering" ) );
1602 gNumbering->setColumnLayout(0, TQt::Vertical );
1603 gNumbering->layout()->setSpacing( 0 );
1604 gNumbering->layout()->setMargin( 0 );
1605 TQHBoxLayout *numberingGroupLayout = new TQHBoxLayout( gNumbering->layout() );
1606 numberingGroupLayout->setAlignment( TQt::AlignTop );
1607 numberingGroupLayout->setSpacing( KDialog::spacingHint() );
1608 numberingGroupLayout->setMargin( KDialog::marginHint() );
1609
1610 // What type of numbering is required?
1611 TQRadioButton *rNone = new TQRadioButton( gNumbering, "rNone" );
1612 rNone->setText( i18n( "&None" ) );
1613 numberingGroupLayout->addWidget( rNone );
1614
1615 gNumbering->insert( rNone , KoParagCounter::NUM_NONE);
1616
1617 TQRadioButton *rList = new TQRadioButton( gNumbering, "rList" );
1618 rList->setText( i18n( "&List" ) );
1619 gNumbering->insert( rList , KoParagCounter::NUM_LIST);
1620 numberingGroupLayout->addWidget( rList );
1621
1622 TQRadioButton *rChapter = new TQRadioButton( gNumbering, "rChapter" );
1623 rChapter->setText( i18n( "Chapt&er" ) );
1624 gNumbering->insert( rChapter , KoParagCounter::NUM_CHAPTER);
1625 numberingGroupLayout->addWidget( rChapter );
1626 Form1Layout->addWidget( gNumbering );
1627 connect( gNumbering, TQ_SIGNAL( clicked( int ) ), this, TQ_SLOT( numTypeChanged( int ) ) );
1628
1629 m_styleWidget = new KoCounterStyleWidget( true, false, disableAll, this );
1630
1631 connect( m_styleWidget, TQ_SIGNAL( sig_suffixChanged (const TQString &) ), this, TQ_SLOT( suffixChanged(const TQString &) ) );
1632 connect( m_styleWidget, TQ_SIGNAL( sig_prefixChanged (const TQString &) ), this, TQ_SLOT( prefixChanged(const TQString &) ) );
1633 connect( m_styleWidget, TQ_SIGNAL( sig_startChanged(int) ), this, TQ_SLOT( startChanged(int) ) );
1634 connect( m_styleWidget, TQ_SIGNAL( sig_restartChanged(bool) ), this, TQ_SLOT( restartChanged(bool) ) );
1635 connect( m_styleWidget, TQ_SIGNAL( sig_depthChanged (int) ), this, TQ_SLOT( depthChanged(int) ) );
1636 connect( m_styleWidget, TQ_SIGNAL( sig_displayLevelsChanged (int) ), this, TQ_SLOT( displayLevelsChanged(int) ) );
1637 connect( m_styleWidget, TQ_SIGNAL( sig_alignmentChanged (int) ), this, TQ_SLOT( alignmentChanged(int) ) );
1638 connect( m_styleWidget, TQ_SIGNAL( changeCustomBullet( const TQString & , TQChar ) ), this, TQ_SLOT( slotChangeCustomBullet( const TQString & , TQChar ) ) );
1639
1640 connect( m_styleWidget, TQ_SIGNAL( sig_numTypeChanged( int ) ), this, TQ_SLOT( numTypeChanged(int ) ) );
1641 connect( m_styleWidget, TQ_SIGNAL( changeStyle( KoParagCounter::Style ) ), this, TQ_SLOT( styleChanged (KoParagCounter::Style ) ) );
1642
1643 Form1Layout->addWidget( m_styleWidget );
1644
1645
1646 preview = new KoStylePreview( i18n( "Preview" ), i18n("Normal paragraph text"), this, "counter preview" );
1647 Form1Layout->addWidget( preview );
1648 if ( disableAll)
1649 {
1650 gNumbering->setEnabled( false);
1651 preview->setEnabled( false );
1652 }
1653
1654 TQSpacerItem* spacer = new TQSpacerItem( 0, 0, TQSizePolicy::Minimum, TQSizePolicy::Expanding);
1655 Form1Layout->addItem( spacer );
1656}
1657
1658void KoParagCounterWidget::styleChanged( KoParagCounter::Style st )
1659{
1660 m_counter.setStyle( st );
1661 updatePreview();
1662}
1663
1664void KoParagCounterWidget::slotChangeCustomBullet( const TQString & f, TQChar c)
1665{
1666 m_counter.setCustomBulletFont( f );
1667 m_counter.setCustomBulletCharacter( c );
1668 preview->setCounter( m_counter );
1669}
1670
1672 return i18n( "B&ullets/Numbers" );
1673}
1674
1675void KoParagCounterWidget::numTypeChanged( int nType ) {
1676 // radio buttons pressed to change numbering type
1677 m_counter.setNumbering( static_cast<KoParagCounter::Numbering>( nType ) );
1678 preview->setEnabled( m_counter.numbering() != KoParagCounter::NUM_NONE );
1679 m_styleWidget->numTypeChanged( nType );
1680
1681 updatePreview();
1682}
1683
1684void KoParagCounterWidget::display( const KoParagLayout & lay ) {
1685 KoParagCounter::Style style = KoParagCounter::STYLE_NONE;
1686 if ( lay.counter )
1687 {
1688 style=lay.counter->style();
1689 m_counter = *lay.counter;
1690 }
1691 else
1692 {
1693 m_counter = KoParagCounter();
1694 }
1695 gNumbering->setButton( m_counter.numbering() );
1696 preview->setStyle( lay.style );
1697 preview->setCounter( m_counter );
1698 m_styleWidget->display( lay );
1699}
1700
1701void KoParagCounterWidget::updatePreview() {
1702 preview->setCounter(m_counter);
1703 preview->repaint(true);
1704}
1705
1706void KoParagCounterWidget::save( KoParagLayout & lay ) {
1707/* m_counter.setDepth(spnDepth->value());
1708 m_counter.setStartNumber(spnStart->value());
1709 m_counter.setPrefix(sPrefix->text());
1710 m_counter.setSuffix(sSuffix->text()); */
1711
1712 if ( lay.counter )
1713 *lay.counter = m_counter;
1714 else
1715 lay.counter = new KoParagCounter( m_counter );
1716}
1717
1718KoTabulatorsLineEdit::KoTabulatorsLineEdit( TQWidget *parent, double lower, double upper, double step, double value /*= 0.0*/, KoUnit::Unit unit /*= KoUnit::U_PT*/, unsigned int precision /*= 2*/, const char *name /*= 0*/ )
1719 : KoUnitDoubleSpinBox ( parent, lower, upper, step, value, unit, precision, name )
1720{
1721 setRange( 0, 9999, 1, false);
1722}
1723
1724void KoTabulatorsLineEdit::keyPressEvent ( TQKeyEvent *ke )
1725{
1726 if( ke->key() == TQt::Key_Return ||
1727 ke->key() == TQt::Key_Enter )
1728 {
1729 emit keyReturnPressed();
1730 return;
1731 }
1732 KoUnitDoubleSpinBox::keyPressEvent (ke);
1733}
1734
1735KoParagTabulatorsWidget::KoParagTabulatorsWidget( KoUnit::Unit unit, double frameWidth,TQWidget * parent, const char * name )
1736 : KoParagLayoutWidget( KoParagDia::PD_TABS, parent, name ), m_unit(unit) {
1737 TQString length;
1738 if(frameWidth==-1) {
1739 frameWidth=9999;
1740 m_toplimit=9999;
1741 } else {
1742 m_toplimit=frameWidth;
1743 length=i18n("Frame width: %1 %2")
1744 .arg(KoUnit::toUserStringValue(frameWidth,m_unit))
1745 .arg(KoUnit::unitName(m_unit));
1746 frameWidth=KoUnit::toUserValue(frameWidth,m_unit);
1747 }
1748 TQVBoxLayout* Form1Layout = new TQVBoxLayout( this );
1749 Form1Layout->setSpacing( KDialog::spacingHint() );
1750 Form1Layout->setMargin( KDialog::marginHint() );
1751
1752 TQHBoxLayout* Layout13 = new TQHBoxLayout;
1753 Layout13->setSpacing( KDialog::spacingHint() );
1754 Layout13->setMargin( 0 ); //?
1755
1756 lstTabs = new TQListBox( this);
1757 lstTabs->insertItem( "mytabvalue" );
1758 lstTabs->setMaximumSize( TQSize( 300, 32767 ) );
1759 Layout13->addWidget( lstTabs );
1760
1761 editLayout = new TQVBoxLayout;
1762 editLayout->setSpacing( KDialog::spacingHint() );
1763 editLayout->setMargin( 0 ); //?
1764
1765 gPosition = new TQGroupBox( this, "gPosition" );
1766 gPosition->setTitle( i18n( "Po&sition" ) );
1767 gPosition->setColumnLayout(0, TQt::Vertical );
1768 gPosition->layout()->setSpacing( 0 );
1769 gPosition->layout()->setMargin( 0 );
1770 TQVBoxLayout* GroupBox2Layout = new TQVBoxLayout( gPosition->layout() );
1771 GroupBox2Layout->setAlignment( TQt::AlignTop );
1772 GroupBox2Layout->setSpacing( KDialog::spacingHint() );
1773 GroupBox2Layout->setMargin( KDialog::marginHint() );
1774
1775 TQHBoxLayout* Layout5 = new TQHBoxLayout;
1776 Layout5->setSpacing( KDialog::spacingHint() );
1777 Layout5->setMargin( 0 ); //?
1778
1779 sTabPos = new KoTabulatorsLineEdit( gPosition, 0, 9999, 1, 0.0, m_unit );
1780 sTabPos->setRange( 0, 9999, 1 );
1781 sTabPos->setMaximumSize( TQSize( 100, 32767 ) );
1782 Layout5->addWidget( sTabPos );
1783 TQSpacerItem* spacer = new TQSpacerItem( 20, 20, TQSizePolicy::Expanding, TQSizePolicy::Minimum );
1784 Layout5->addItem( spacer );
1785 GroupBox2Layout->addLayout( Layout5 );
1786 editLayout->addWidget( gPosition );
1787
1788 TQLabel* TextLabel1 = new TQLabel( gPosition );
1789 TQString unitDescription = KoUnit::unitDescription( m_unit );
1790 TextLabel1->setText( length );
1791 GroupBox2Layout->addWidget( TextLabel1 );
1792
1793 bgAlign = new TQButtonGroup( this );
1794 bgAlign->setTitle( i18n( "Alignment" ) );
1795 bgAlign->setColumnLayout(0, TQt::Vertical );
1796 bgAlign->layout()->setSpacing( 0 );
1797 bgAlign->layout()->setMargin( 0 );
1798 TQVBoxLayout* ButtonGroup1Layout = new TQVBoxLayout( bgAlign->layout() );
1799 ButtonGroup1Layout->setAlignment( TQt::AlignTop );
1800 ButtonGroup1Layout->setSpacing( KDialog::spacingHint() );
1801 ButtonGroup1Layout->setMargin( KDialog::marginHint() );
1802
1803 rAlignLeft = new TQRadioButton( bgAlign );
1804 rAlignLeft->setText( i18n( "&Left" ) );
1805 ButtonGroup1Layout->addWidget( rAlignLeft );
1806
1807 rAlignCentre = new TQRadioButton( bgAlign );
1808 rAlignCentre->setText( i18n( "C&enter" ) );
1809 ButtonGroup1Layout->addWidget( rAlignCentre );
1810
1811 rAlignRight = new TQRadioButton( bgAlign );
1812 rAlignRight->setText( i18n( "&Right" ) );
1813 ButtonGroup1Layout->addWidget( rAlignRight );
1814
1815 TQHBoxLayout* Layout8 = new TQHBoxLayout;
1816 Layout8->setSpacing( KDialog::spacingHint() );
1817 Layout8->setMargin( 0 );
1818
1819 rAlignVar = new TQRadioButton( bgAlign );
1820 rAlignVar->setText( i18n( "On followin&g character: " ) );
1821 Layout8->addWidget( rAlignVar );
1822
1823 sAlignChar = new TQLineEdit( bgAlign);
1824 sAlignChar->setMaximumSize( TQSize( 60, 32767 ) );
1825 sAlignChar->setText(TQString(TDEGlobal::locale()->decimalSymbol()[0]));
1826 Layout8->addWidget( sAlignChar );
1827 TQSpacerItem* spacer_2 = new TQSpacerItem( 20, 20, TQSizePolicy::Expanding, TQSizePolicy::Minimum );
1828 Layout8->addItem( spacer_2 );
1829 ButtonGroup1Layout->addLayout( Layout8 );
1830 editLayout->addWidget( bgAlign );
1831
1832 gTabLeader = new TQGroupBox( this, "gTabLeader" );
1833 gTabLeader->setTitle( i18n( "Tab Leader" ) );
1834 TQVBoxLayout* GroupBox5Layout = new TQVBoxLayout( gTabLeader );
1835 GroupBox5Layout->setAlignment( TQt::AlignTop );
1836 GroupBox5Layout->setSpacing( KDialog::spacingHint() );
1837 GroupBox5Layout->setMargin( KDialog::marginHint() );
1838 GroupBox5Layout->addSpacing( fontMetrics().height() / 2 ); // groupbox title
1839
1840 TQLabel* TextLabel1_2 = new TQLabel( gTabLeader );
1841 TextLabel1_2->setText( i18n( "The space a tab uses can be filled with a pattern." ) );
1842 GroupBox5Layout->addWidget( TextLabel1_2 );
1843
1844 TQGridLayout *fillingGrid = new TQGridLayout( 0L, 2, 2, 0, KDialog::spacingHint() );
1845
1846 TQLabel* TextLabel2 = new TQLabel( gTabLeader);
1847 TextLabel2->setText( i18n( "&Filling:" ) );
1848 TextLabel2->setAlignment( AlignRight );
1849 fillingGrid->addWidget( TextLabel2, 0, 0 );
1850
1851 cFilling = new TQComboBox( false, gTabLeader);
1852 cFilling->insertItem( i18n( "Blank" ) );
1853 cFilling->insertItem( "_ _ _ _ _ _"); // DOT
1854 cFilling->insertItem( "_________"); // SOLID
1855 cFilling->insertItem( "___ ___ __"); // DASH
1856 cFilling->insertItem( "___ _ ___ _"); // DASH_DOT
1857 cFilling->insertItem( "___ _ _ ___"); // DASH_DOT_DOT
1858 TextLabel2->setBuddy( cFilling );
1859 fillingGrid->addWidget( cFilling, 0, 1 );
1860
1861 TQLabel * TextLabel3 = new TQLabel( i18n("&Width:"), gTabLeader );
1862 TextLabel3->setAlignment( AlignRight );
1863 fillingGrid->addWidget( TextLabel3, 1, 0 );
1864
1865 eWidth = new KoUnitDoubleSpinBox( gTabLeader );
1866 eWidth->setMinValue(0.01);
1867 eWidth->setUnit( m_unit );
1868 TextLabel3->setBuddy( eWidth );
1869 fillingGrid->addWidget( eWidth, 1, 1 );
1870
1871 GroupBox5Layout->addLayout( fillingGrid );
1872 editLayout->addWidget( gTabLeader );
1873 TQSpacerItem* spacer_4 = new TQSpacerItem( 20, 20, TQSizePolicy::Minimum, TQSizePolicy::Expanding );
1874 editLayout->addItem( spacer_4 );
1875 Layout13->addLayout( editLayout );
1876 Form1Layout->addLayout( Layout13 );
1877
1878 TQHBoxLayout* Layout4 = new TQHBoxLayout;
1879 Layout4->setSpacing( KDialog::spacingHint() );
1880 Layout4->setMargin( 0 );
1881
1882 bNew = new TQPushButton( this);
1883 bNew->setText( i18n( "&New" ) );
1884 Layout4->addWidget( bNew );
1885
1886 bDelete = new TQPushButton( this);
1887 bDelete->setText( i18n( "&Delete" ) );
1888 Layout4->addWidget( bDelete );
1889
1890 bDeleteAll = new TQPushButton( this);
1891 bDeleteAll->setText( i18n( "Delete All" ) );
1892 Layout4->addWidget( bDeleteAll );
1893
1894 TQSpacerItem* spacer_5 = new TQSpacerItem( 20, 20, TQSizePolicy::Expanding, TQSizePolicy::Minimum );
1895 Layout4->addItem( spacer_5 );
1896 Form1Layout->addLayout( Layout4 );
1897
1898 //signal valueChanged passes value which the user see (unlike the value() function)
1899 //so fromUserValue has to be used in slotTabValueChanged
1900 connect(sTabPos,TQ_SIGNAL(valueChanged(double)), this, TQ_SLOT(slotTabValueChanged(double )));
1901 connect(sTabPos,TQ_SIGNAL( keyReturnPressed()),this,TQ_SLOT(newClicked()));
1902 connect(sAlignChar,TQ_SIGNAL(textChanged( const TQString & )), this, TQ_SLOT(slotAlignCharChanged( const TQString & )));
1903 connect(bNew,TQ_SIGNAL(clicked ()),this,TQ_SLOT(newClicked()));
1904 connect(bDelete,TQ_SIGNAL(clicked ()),this,TQ_SLOT(deleteClicked()));
1905 connect(bDeleteAll,TQ_SIGNAL(clicked ()),this,TQ_SLOT(deleteAllClicked()));
1906 connect(bgAlign,TQ_SIGNAL(clicked (int)),this,TQ_SLOT(updateAlign(int)));
1907 connect(cFilling,TQ_SIGNAL(activated (int)),this,TQ_SLOT(updateFilling(int)));
1908 connect(eWidth,TQ_SIGNAL(valueChangedPt( double ) ),this,TQ_SLOT(updateWidth()));
1909 connect(lstTabs,TQ_SIGNAL(highlighted (int)),this,TQ_SLOT(setActiveItem(int)));
1910 noSignals=false;
1911}
1912
1913void KoParagTabulatorsWidget::slotTabValueChanged( double val ) {
1914 if(noSignals) return;
1915 noSignals=true;
1916 //see comment where this slot is connected
1917 m_tabList[lstTabs->currentItem()].ptPos = KoUnit::fromUserValue( val, m_unit );
1918
1919 lstTabs->changeItem(tabToString(m_tabList[lstTabs->currentItem()]), lstTabs->currentItem());
1920
1921 sortLists();
1922 noSignals=false;
1923}
1924
1925void KoParagTabulatorsWidget::slotAlignCharChanged( const TQString &/*_text*/ ) {
1926 // select align 3 and update data structures.
1927 bgAlign->setButton(3);
1928 m_tabList[lstTabs->currentItem()].alignChar=sAlignChar->text()[0];
1929 m_tabList[lstTabs->currentItem()].type=T_DEC_PNT;
1930}
1931
1932void KoParagTabulatorsWidget::newClicked() {
1933 int selected=lstTabs->currentItem();
1934 KoTabulator newTab;
1935 if(selected < 0) {
1936 newTab.ptPos=0;
1937 newTab.type=T_LEFT;
1938 newTab.filling=TF_BLANK;
1939 newTab.ptWidth=0.5;
1940 m_tabList.append(newTab);
1941 lstTabs->insertItem(tabToString(newTab));
1942 lstTabs->setCurrentItem(0);
1943 } else {
1944 double pos = m_tabList[selected].ptPos;
1945 double add=1.0;
1946 if(m_unit==KoUnit::U_INCH) // inches are 25 times as big as mm, take it easy with adding..
1947 add=0.1;
1948
1949 pos=pos + KoUnit::fromUserValue( add, m_unit );
1950 if(pos<m_toplimit)
1951 {
1952 newTab.ptPos=pos + KoUnit::fromUserValue( add, m_unit );
1953 newTab.type=m_tabList[selected].type;
1954 newTab.filling=m_tabList[selected].filling;
1955 newTab.ptWidth=m_tabList[selected].ptWidth;
1956 m_tabList.insert(m_tabList.at(selected), newTab);
1957 lstTabs->insertItem( tabToString(newTab), selected);
1958 lstTabs->setCurrentItem(lstTabs->findItem(tabToString(newTab)));
1959 sortLists();
1960 }
1961 }
1962}
1963
1964void KoParagTabulatorsWidget::deleteClicked() {
1965 int selected = lstTabs->currentItem();
1966 if (selected < 0) return;
1967 noSignals=true;
1968 sTabPos->changeValue(0.0);
1969 noSignals=false;
1970 lstTabs->removeItem(selected);
1971 m_tabList.remove(m_tabList[selected]);
1972 if(lstTabs->count() >0) {
1973 lstTabs->setCurrentItem(TQMIN(static_cast<unsigned int>(selected), lstTabs->count()-1 ));
1974 } else {
1975 bDeleteAll->setEnabled(false);
1976 bDelete->setEnabled(false);
1977 gPosition->setEnabled(false);
1978 bgAlign->setEnabled(false);
1979 gTabLeader->setEnabled(false);
1980 }
1981}
1982
1983void KoParagTabulatorsWidget::deleteAllClicked()
1984{
1985 noSignals=true;
1986 sTabPos->changeValue(0.0);
1987 noSignals=false;
1988 lstTabs->clear();
1989 m_tabList.clear();
1990 bDeleteAll->setEnabled(false);
1991 bDelete->setEnabled(false);
1992 gPosition->setEnabled(false);
1993 bgAlign->setEnabled(false);
1994 gTabLeader->setEnabled(false);
1995}
1996
1997void KoParagTabulatorsWidget::setActiveItem(int selected) {
1998 if(noSignals) return;
1999 if(selected < 0) return;
2000 noSignals=true;
2001 KoTabulator *selectedTab = &m_tabList[selected];
2002 switch( selectedTab->type) {
2003 case T_CENTER:
2004 bgAlign->setButton(1); break;
2005 case T_RIGHT:
2006 bgAlign->setButton(2); break;
2007 case T_DEC_PNT:
2008 bgAlign->setButton(3);
2009 sAlignChar->setText(TQString(selectedTab->alignChar));
2010 break;
2011 case T_LEFT:
2012 default:
2013 bgAlign->setButton(0);
2014 }
2015 switch( selectedTab->filling) {
2016 case TF_DOTS:
2017 cFilling->setCurrentItem(1); break;
2018 case TF_LINE:
2019 cFilling->setCurrentItem(2); break;
2020 case TF_DASH:
2021 cFilling->setCurrentItem(3); break;
2022 case TF_DASH_DOT:
2023 cFilling->setCurrentItem(4); break;
2024 case TF_DASH_DOT_DOT:
2025 cFilling->setCurrentItem(5); break;
2026 case TF_BLANK:
2027 default:
2028 cFilling->setCurrentItem(0);
2029 }
2030 eWidth->changeValue( selectedTab->ptWidth );
2031 sTabPos->setValue( KoUnit::toUserValue(selectedTab->ptPos, m_unit));
2032 bDelete->setEnabled(true);
2033 bDeleteAll->setEnabled(true);
2034 gPosition->setEnabled(true);
2035 bgAlign->setEnabled(true);
2036 gTabLeader->setEnabled(true);
2037 noSignals=false;
2038}
2039
2040void KoParagTabulatorsWidget::setCurrentTab( double tabPos ) {
2041 KoTabulatorList::ConstIterator it = m_tabList.begin();
2042 for ( int i = 0; it != m_tabList.end(); ++it, ++i )
2043 if ( (*it).ptPos == tabPos ) {
2044 lstTabs->setCurrentItem(i);
2045 setActiveItem( i );
2046 return;
2047 }
2048 kdWarning() << "KoParagTabulatorsWidget::setCurrentTab: no tab found at pos=" << tabPos << endl;
2049}
2050
2051TQString KoParagTabulatorsWidget::tabToString(const KoTabulator &tab) {
2052 return KoUnit::toUserStringValue( tab.ptPos, m_unit);
2053}
2054
2055void KoParagTabulatorsWidget::updateAlign(int selected) {
2056 KoTabulator *selectedTab = &m_tabList[lstTabs->currentItem()];
2057
2058 switch( selected) {
2059 case 1:
2060 selectedTab->type=T_CENTER; break;
2061 case 2:
2062 selectedTab->type=T_RIGHT; break;
2063 case 3:
2064 selectedTab->type=T_DEC_PNT;
2065 selectedTab->alignChar=sAlignChar->text()[0];
2066 break;
2067 case 0:
2068 default:
2069 selectedTab->type=T_LEFT;
2070 }
2071}
2072
2073void KoParagTabulatorsWidget::updateFilling(int selected) {
2074 KoTabulator *selectedTab = &m_tabList[lstTabs->currentItem()];
2075
2076 switch( selected) {
2077 case 1:
2078 selectedTab->filling=TF_DOTS; break;
2079 case 2:
2080 selectedTab->filling=TF_LINE; break;
2081 case 3:
2082 selectedTab->filling=TF_DASH; break;
2083 case 4:
2084 selectedTab->filling=TF_DASH_DOT; break;
2085 case 5:
2086 selectedTab->filling=TF_DASH_DOT_DOT; break;
2087 case 0:
2088 default:
2089 selectedTab->filling=TF_BLANK;
2090 }
2091}
2092
2093void KoParagTabulatorsWidget::updateWidth() {
2094 KoTabulator *selectedTab = &m_tabList[lstTabs->currentItem()];
2095 selectedTab->ptWidth = TQMAX( 0, eWidth->value() );
2096}
2097
2098void KoParagTabulatorsWidget::sortLists() {
2099
2100 noSignals=true;
2101 qHeapSort( m_tabList );
2102
2103 // we could just sort the listView, but to make sure we never have any problems with
2104 // inconsistent lists, just re-add..
2105 TQString curValue=lstTabs->currentText();
2106 lstTabs->clear();
2107 KoTabulatorList::ConstIterator it = m_tabList.begin();
2108 for ( ; it != m_tabList.end(); ++it )
2109 lstTabs->insertItem( KoUnit::toUserStringValue( (*it).ptPos, m_unit ) );
2110
2111 lstTabs->setCurrentItem(lstTabs->findItem(curValue));
2112 noSignals=false;
2113}
2114
2115void KoParagTabulatorsWidget::display( const KoParagLayout &lay ) {
2116 m_tabList.clear();
2117 lstTabs->clear();
2118 m_tabList = lay.tabList();
2119 KoTabulatorList::ConstIterator it = m_tabList.begin();
2120 for ( ; it != m_tabList.end(); ++it )
2121 lstTabs->insertItem( KoUnit::toUserStringValue( (*it).ptPos, m_unit ) );
2122
2123 if(lstTabs->count() > 0)
2124 lstTabs->setCurrentItem(0);
2125 else {
2126 bDelete->setEnabled(false);
2127 bDeleteAll->setEnabled(false);
2128 gPosition->setEnabled(false);
2129 bgAlign->setEnabled(false);
2130 gTabLeader->setEnabled(false);
2131 }
2132}
2133
2134void KoParagTabulatorsWidget::save( KoParagLayout & lay ) {
2135 lay.setTabList( m_tabList );
2136}
2137
2139 return i18n( "&Tabulators" );
2140}
2141
2142/******************************************************************/
2143/* Class: KoParagDia */
2144/******************************************************************/
2145KoParagDia::KoParagDia( TQWidget* parent, const char* name,
2146 int flags, KoUnit::Unit unit, double _frameWidth, bool breakLine, bool disableAll )
2147 : KDialogBase(Tabbed, TQString(), Ok | Cancel | User1 | Apply, Ok, parent, name, true )
2148{
2149 m_decorationsWidget = 0;
2150 m_flags = flags;
2151 setButtonText( KDialogBase::User1, i18n("Reset") );
2152
2153 if ( m_flags & PD_SPACING )
2154 {
2155 TQVBox * page = addVBoxPage( i18n( "Indent && S&pacing" ) );
2156 m_indentSpacingWidget = new KoIndentSpacingWidget( unit,_frameWidth,page, "indent-spacing" );
2157 m_indentSpacingWidget->layout()->setMargin(0);
2158 }
2159 if ( m_flags & PD_ALIGN )
2160 {
2161 TQVBox * page = addVBoxPage( i18n( "General &Layout" ) );
2162 m_alignWidget = new KoParagAlignWidget( breakLine, page, "align" );
2163 m_alignWidget->layout()->setMargin(0);
2164 }
2165 if ( m_flags & PD_DECORATION )
2166 {
2167 TQVBox * page = addVBoxPage( i18n( "D&ecorations" ) );
2168 m_decorationsWidget = new KoParagDecorationWidget( page, "decorations");
2169 m_decorationsWidget->layout()->setMargin(0);
2170 }
2171 if ( m_flags & PD_NUMBERING )
2172 {
2173 TQVBox * page = addVBoxPage( i18n( "B&ullets/Numbers" ) );
2174 m_counterWidget = new KoParagCounterWidget( disableAll , page, "numbers" );
2175 m_counterWidget->layout()->setMargin(0);
2176 }
2177 if ( m_flags & PD_TABS )
2178 {
2179 TQVBox * page = addVBoxPage( i18n( "&Tabulators" ) );
2180 m_tabulatorsWidget = new KoParagTabulatorsWidget( unit,_frameWidth, page, "tabs");
2181 m_tabulatorsWidget->layout()->setMargin(0);
2182 }
2183
2184 connect( this, TQ_SIGNAL( user1Clicked() ), this, TQ_SLOT(slotReset()));
2185 setInitialSize( TQSize(630, 500) );
2186}
2187
2188KoParagDia::~KoParagDia()
2189{
2190}
2191
2193{
2194 emit applyParagStyle();
2195}
2196
2197void KoParagDia::slotOk()
2198{
2199 slotApply();
2201}
2202
2204{
2205 switch( page )
2206 {
2207 case PD_SPACING:
2208 showPage( pageIndex( m_indentSpacingWidget->parentWidget() ) );
2209 break;
2210 case PD_ALIGN:
2211 showPage( pageIndex( m_alignWidget->parentWidget() ) );
2212 break;
2213 case PD_DECORATION:
2214 showPage( pageIndex( m_decorationsWidget->parentWidget() ) );
2215 break;
2216 case PD_NUMBERING:
2217 showPage( pageIndex( m_counterWidget->parentWidget() ) );
2218 break;
2219 case PD_TABS:
2220 showPage( pageIndex( m_tabulatorsWidget->parentWidget() ) );
2221 break;
2222 default:
2223 break;
2224 }
2225}
2226
2228{
2229 m_indentSpacingWidget->display( lay );
2230 m_alignWidget->display( lay );
2231 m_decorationsWidget->display( lay );
2232 m_counterWidget->display( lay );
2233 m_tabulatorsWidget->display( lay );
2234 oldLayout = lay;
2235}
2236
2237void KoParagDia::slotReset()
2238{
2239 if( m_indentSpacingWidget )
2240 m_indentSpacingWidget->display( oldLayout );
2241 if( m_alignWidget )
2242 m_alignWidget->display( oldLayout );
2243 if ( m_decorationsWidget )
2244 m_decorationsWidget->display( oldLayout );
2245 if( m_counterWidget )
2246 m_counterWidget->display( oldLayout );
2247 if( m_tabulatorsWidget )
2248 m_tabulatorsWidget->display( oldLayout );
2249}
2250
2251bool KoParagDia::isCounterChanged() const
2252{
2253 if ( oldLayout.counter ) // We had a counter
2254 return ! ( *oldLayout.counter == counter() );
2255 else // We had no counter -> changed if we have one now
2256 return counter().numbering() != KoParagCounter::NUM_NONE;
2257}
2258
2260{
2261 return paragLayout().compare( oldLayout );
2262}
2263
2264KoParagLayout KoParagDia::paragLayout() const
2265{
2266 KoParagLayout newLayout;
2267 newLayout.setLineSpacingValue( lineSpacing() );
2268 newLayout.lineSpacingType = lineSpacingType();
2269 newLayout.setTabList( tabListTabulator() );
2270 newLayout.alignment = align();
2271 newLayout.margins[TQStyleSheetItem::MarginFirstLine] = firstLineIndent();
2272 newLayout.margins[TQStyleSheetItem::MarginLeft] = leftIndent();
2273 newLayout.margins[TQStyleSheetItem::MarginRight] = rightIndent();
2274 newLayout.margins[TQStyleSheetItem::MarginTop] = spaceBeforeParag();
2275 newLayout.margins[TQStyleSheetItem::MarginBottom] = spaceAfterParag();
2276 newLayout.pageBreaking = pageBreaking();
2277 newLayout.leftBorder = leftBorder();
2278 newLayout.rightBorder = rightBorder();
2279 newLayout.topBorder = topBorder();
2280 newLayout.bottomBorder = bottomBorder();
2281 newLayout.joinBorder = joinBorder();
2282 newLayout.backgroundColor = backgroundColor();
2283 newLayout.counter = new KoParagCounter( counter() );
2284 return newLayout;
2285}
2286
2287#include "KoParagDia.moc"
2288#include "KoParagDia_p.moc"
bool showPage(int index)
virtual void slotApply()
TQVBox * addVBoxPage(const TQString &itemName, const TQString &header=TQString::null, const TQPixmap &pixmap=TQPixmap())
KDialogBase(TQWidget *parent=0, const char *name=0, bool modal=true, const TQString &caption=TQString::null, int buttonMask=Ok|Apply|Cancel, ButtonCode defaultButton=Ok, bool separator=false, const KGuiItem &user1=KGuiItem(), const KGuiItem &user2=KGuiItem(), const KGuiItem &user3=KGuiItem())
void setInitialSize(const TQSize &s, bool noResize=false)
void user1Clicked()
int pageIndex(TQWidget *widget) const
virtual void slotOk()
void setButtonText(ButtonCode id, const TQString &text)
static int marginHint()
static int spacingHint()
This class represents a border - for anything, like paragraph, or frame.
Definition KoBorder.h:34
The widget for editing idents and spacings (tab 1).
Definition KoParagDia.h:109
virtual TQString tabName()
return the (i18n-ed) name of the tab
The widget for editing paragraph alignment (tab 2).
Definition KoParagDia.h:153
virtual TQString tabName()
return the (i18n-ed) name of the tab
The widget for editing counters (bullets & numbering) (tab 4).
Definition KoParagDia.h:346
virtual TQString tabName()
return the (i18n-ed) name of the tab
This is the structure associated with a paragraph (KoTextParag), to define the bullet or numbering of...
Numbering numbering() const
Numbering type and style.
The widget for editing paragraph borders (tab 3).
Definition KoParagDia.h:187
virtual TQString tabName()
return the (i18n-ed) name of the tab
The complete(*) dialog for changing attributes of a paragraph.
Definition KoParagDia.h:499
void setCurrentPage(int page)
Make a given page the current one - page is a flag (PD_something) value.
void setParagLayout(const KoParagLayout &lay)
Set the values to be displayed.
KoParagDia(TQWidget *, const char *, int flags, KoUnit::Unit unit, double _frameWidth=-1, bool breakLine=true, bool disableAll=false)
breakLine : kpresenter didn't used this attibute, kword use it.
int changedFlags() const
This is the base class for any widget [usually used in a tab] that handles modifying a part of a KoPa...
Definition KoParagDia.h:73
This class holds the paragraph-specific formatting information It's separated from KoTextParag so tha...
SpacingType
Line spacing values Assuming h is the height of the biggest char in the line, and v is the linespacin...
TQColor backgroundColor
The background color of the paragraph.
double margins[5]
left, right, top, bottom, firstLineSpacing - in pt
KoParagCounter * counter
can be 0 if no counter set
char alignment
Alignment flag (AlignAuto/AlignLeft/AlignRight/AlignJustify).
A paragraph style is a combination of a character style and paragraph-layout attributes,...
The widget for editing tabulators (tab 5).
Definition KoParagDia.h:408
virtual TQString tabName()
return the (i18n-ed) name of the tab
void setCounter(const KoParagCounter &counter)
Set the given counter to the preview.
void setStyle(KoParagStyle *style)
Apply the given style to the preview.
This class extends KoZoomHandler to add support for WYSIWYG text layouting.
int pixelToLayoutUnitX(int x) const
The "[zoomed] view pixel" -> "layout unit pixel" conversions.
Spin box for double precision numbers with unit display.
void setMinValue(double min)
Set minimum value in points.
static double toUserValue(double ptValue, Unit unit)
This method is the one to use to display a value in a dialog.
Definition KoUnit.cpp:68
static double fromUserValue(double value, Unit unit)
This method is the one to use to read a value from a dialog.
Definition KoUnit.cpp:120
static TQString unitDescription(Unit _unit)
Get the full (translated) description of a unit.
Definition KoUnit.cpp:43
static TQString toUserStringValue(double ptValue, Unit unit)
This method is the one to use to display a value in a dialog.
Definition KoUnit.cpp:115
Unit
Length units supported by KOffice.
Definition KoUnit.h:63
static TQString unitName(Unit _unit)
Get the name of a unit.
Definition KoUnit.cpp:200
TDEAction * zoom(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
const char * name(StdAction id)
Struct: KoTabulator Defines the position of a tabulation (in pt), and its type.
Definition KoRuler.h:46
KoTabulators type
Type of tab (left/center/right/decimalpoint).
Definition KoRuler.h:54
KoTabulatorFilling filling
Type of tab filling.
Definition KoRuler.h:58
double ptPos
Position of the tab in pt.
Definition KoRuler.h:50
TQChar alignChar
Alignment character.
Definition KoRuler.h:66
double ptWidth
Width of the tab filling line.
Definition KoRuler.h:62