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