00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "koParagDia.h"
00021 #include "koParagDia_p.h"
00022 #include "koDocument.h"
00023 #include "kotextformat.h"
00024 #include "kotextparag.h"
00025 #include "kotextdocument.h"
00026
00027 #include <qcheckbox.h>
00028 #include <qcombobox.h>
00029 #include <qhbuttongroup.h>
00030 #include <qlabel.h>
00031 #include <qradiobutton.h>
00032 #include <qvbox.h>
00033 #include <qhbox.h>
00034
00035 #include <koCharSelectDia.h>
00036 #include <kcolorbutton.h>
00037 #include <kdebug.h>
00038 #include <kiconloader.h>
00039 #include <klocale.h>
00040 #include <knumvalidator.h>
00041 #include <kozoomhandler.h>
00042 #include <koGlobal.h>
00043 #include <qgroupbox.h>
00044 #include <knuminput.h>
00045 #include <kdeversion.h>
00046 #include <kcombobox.h>
00047
00048 KoCounterStyleWidget::KoCounterStyleWidget( bool displayDepth, bool onlyStyleTypeLetter, bool disableAll, QWidget * parent, const char* name )
00049 :QWidget( parent, name ),
00050 stylesList()
00051 {
00052 noSignals = true;
00053 styleBuffer = 999;
00054 QVBoxLayout *vbox = new QVBoxLayout( this,0, 0 );
00055 gStyle = new QGroupBox( i18n( "St&yle" ), this, "styleLayout" );
00056 vbox->addWidget( gStyle);
00057 QGridLayout * grid = new QGridLayout(gStyle, 12, 5, KDialog::marginHint(), KDialog::spacingHint());
00058 grid->addRowSpacing(0, fontMetrics().height()/2);
00059
00060 makeCounterRepresenterList( stylesList, onlyStyleTypeLetter );
00061
00062 lstStyle = new QListBox( gStyle, "styleListBox" );
00063 grid->addMultiCellWidget( lstStyle, 1, 11, 0, 0);
00064 fillStyleCombo();
00065 connect( lstStyle, SIGNAL( selectionChanged() ), this, SLOT( numStyleChanged() ) );
00066
00067
00068 QLabel *lPrefix = new QLabel( gStyle, "lPrefix" );
00069 lPrefix->setText( i18n( "Pre&fix text:" ) );
00070 grid->addWidget( lPrefix, 1, 1);
00071
00072 sPrefix = new QLineEdit( gStyle, "sPrefix" );
00073 lPrefix->setBuddy( sPrefix );
00074 grid->addWidget( sPrefix, 1, 2);
00075
00076 QLabel *lSuffix = new QLabel( gStyle, "lSuffix" );
00077 lSuffix->setText( i18n( "Suffi&x text:" ) );
00078 grid->addWidget( lSuffix, 1, 3);
00079
00080 sSuffix = new QLineEdit( gStyle, "sSuffix" );
00081 lSuffix->setBuddy( sSuffix );
00082 grid->addWidget( sSuffix, 1, 4 );
00083
00084 lStart = new QLabel( gStyle, "lStart" );
00085 lStart->setText( i18n( "&Start at:" ) );
00086 grid->addWidget( lStart, 2, 1 );
00087
00088
00089 spnDepth = new QSpinBox( 0, 15, 1, gStyle );
00090 if ( displayDepth )
00091 grid->addWidget( spnDepth, 3, 2 );
00092 else
00093 spnDepth->hide();
00094
00095 spnDisplayLevels = new QSpinBox( 0, 15, 1, gStyle );
00096 spnDisplayLevels->setMinValue( 1 );
00097 if ( displayDepth )
00098 grid->addWidget( spnDisplayLevels, 3, 4 );
00099 else
00100 spnDisplayLevels->hide();
00101
00102
00103 QHBoxLayout *customCharBox = new QHBoxLayout(0, 0, 6);
00104 lCustom = new QLabel( i18n( "Custo&m character:" ), gStyle, "custom char label" );
00105 customCharBox->addWidget( lCustom );
00106
00107 bCustom = new QPushButton( "", gStyle, "bCustom" );
00108 lCustom->setBuddy( bCustom );
00109 customCharBox->addWidget( bCustom );
00110 connect( bCustom, SIGNAL( clicked() ), this, SLOT( selectCustomBullet() ) );
00111
00112 QSpacerItem* spacer_2 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
00113 customCharBox->addItem( spacer_2 );
00114
00115 grid->addMultiCellLayout(customCharBox, 4, 4, 1, 4, Qt::AlignLeft);
00116
00117 spnStart = new KoSpinBox( gStyle );
00118 spnStart->setMinValue ( 1);
00119 lStart->setBuddy( spnStart );
00120 grid->addWidget( spnStart, 2, 2);
00121
00122 lAlignment = new QLabel( gStyle, "lAlignment" );
00123 lAlignment->setText( i18n( "Counter alignment:" ) );
00124 grid->addWidget( lAlignment, 2, 3 );
00125
00126 cbAlignment = new KComboBox( gStyle, "cbAlignment" );
00127 cbAlignment->insertItem(i18n("Align Auto"));
00128 cbAlignment->insertItem(i18n("Align Left"));
00129 cbAlignment->insertItem(i18n("Align Right"));
00130 cbAlignment->setCurrentItem(0);
00131 grid->addWidget( cbAlignment, 2, 4 );
00132
00133 QLabel *lDepth = new QLabel( gStyle, "lDepth" );
00134 lDepth->setText( i18n( "&Depth:" ) );
00135 lDepth->setBuddy( spnDepth );
00136 if ( displayDepth )
00137 grid->addWidget( lDepth, 3, 1 );
00138 else
00139 lDepth->hide();
00140
00141 QLabel *lDisplayLevels = new QLabel( gStyle );
00142 lDisplayLevels->setText( i18n( "Display le&vels:" ) );
00143 lDisplayLevels->setBuddy( spnDisplayLevels );
00144 if ( displayDepth )
00145 grid->addWidget( lDisplayLevels, 3, 3 );
00146 else
00147 lDisplayLevels->hide();
00148
00149 cbRestart = new QCheckBox( i18n( "&Restart numbering at this paragraph" ), gStyle );
00150 grid->addMultiCellWidget( cbRestart, 5, 5, 1, 3 );
00151
00152 if ( onlyStyleTypeLetter )
00153 {
00154 lCustom->hide();
00155 bCustom->hide();
00156 cbRestart->hide();
00157 }
00158
00159
00160 connect( cbRestart, SIGNAL( toggled(bool) ), this, SLOT( restartChanged(bool) ) );
00161
00162 connect( sSuffix, SIGNAL( textChanged (const QString &) ), this, SLOT( suffixChanged(const QString &) ) );
00163 connect( sPrefix, SIGNAL( textChanged (const QString &) ), this, SLOT( prefixChanged(const QString &) ) );
00164 connect( spnStart, SIGNAL( valueChanged (int) ), this, SLOT( startChanged(int) ) );
00165 connect( spnDepth, SIGNAL( valueChanged (int) ), this, SLOT( depthChanged(int) ) );
00166 connect( spnDisplayLevels, SIGNAL( valueChanged (int) ), this, SLOT( displayLevelsChanged(int) ) );
00167 connect( cbAlignment, SIGNAL( activated (const QString&) ), this, SLOT( alignmentChanged(const QString&) ) );
00168 noSignals = false;
00169 if ( disableAll )
00170 {
00171 gStyle->setEnabled( false );
00172 lstStyle->setEnabled( false );
00173 sSuffix->setEnabled( false );
00174 sPrefix->setEnabled( false );
00175 bCustom->setEnabled( false );
00176 spnStart->setEnabled( false );
00177 spnDepth->setEnabled( false );
00178 spnDisplayLevels->setEnabled( false );
00179 lStart->setEnabled( false );
00180 lCustom->setEnabled( false );
00181 cbRestart->setEnabled( false );
00182 cbAlignment->setEnabled( false );
00183 }
00184 }
00185
00186 void KoCounterStyleWidget::alignmentChanged(const QString& s)
00187 {
00188 int a;
00189 if(s==i18n("Align Left"))
00190 a=Qt::AlignLeft;
00191 else if(s==i18n("Align Right"))
00192 a=Qt::AlignRight;
00193 else if(s==i18n("Align Auto"))
00194 a=Qt::AlignAuto;
00195 else {
00196 kdError()<<"Not Implemented"<<endl;
00197 return;
00198 }
00199 m_counter.setAlignment(a);
00200 emit sig_alignmentChanged(a);
00201 }
00202
00203 void KoCounterStyleWidget::setCounter( const KoParagCounter& counter )
00204 {
00205 noSignals = true;
00206 KoParagCounter::Style st = counter.style();
00207 m_counter = counter;
00208
00209
00210 changeKWSpinboxType( st);
00211 displayStyle( st );
00212 noSignals = false;
00213 }
00214
00215 void KoCounterStyleWidget::changeKWSpinboxType(KoParagCounter::Style st) {
00216 switch(st)
00217 {
00218 case KoParagCounter::STYLE_NONE:
00219 spnStart->setCounterType(KoSpinBox::NONE);
00220 break;
00221 case KoParagCounter::STYLE_NUM:
00222 spnStart->setCounterType(KoSpinBox::NUM);
00223 break;
00224 case KoParagCounter::STYLE_ALPHAB_L:
00225 spnStart->setCounterType(KoSpinBox::ALPHAB_L);
00226 break;
00227 case KoParagCounter::STYLE_ALPHAB_U:
00228 spnStart->setCounterType(KoSpinBox::ALPHAB_U);
00229 break;
00230 case KoParagCounter::STYLE_ROM_NUM_L:
00231 spnStart->setCounterType(KoSpinBox::ROM_NUM_L);
00232 break;
00233 case KoParagCounter::STYLE_ROM_NUM_U:
00234 spnStart->setCounterType(KoSpinBox::ROM_NUM_U);
00235 break;
00236 default:
00237 spnStart->setCounterType(KoSpinBox::NONE);
00238 }
00239 }
00240
00241
00242 void KoCounterStyleWidget::fillStyleCombo(KoParagCounter::Numbering type) {
00243 if(lstStyle==NULL) return;
00244 noSignals=true;
00245 unsigned int cur = lstStyle->currentItem();
00246 lstStyle->clear();
00247 QPtrListIterator<StyleRepresenter> style( stylesList );
00248 while ( style.current() ) {
00249 if(style.current()->style() == KoParagCounter::STYLE_NONE) {
00250 if(type == KoParagCounter::NUM_NONE)
00251 lstStyle->insertItem( style.current()->name() );
00252 }
00253 else if(type == KoParagCounter::NUM_LIST || !style.current()->isBullet())
00254 if(type != KoParagCounter::NUM_NONE)
00255 lstStyle->insertItem( style.current()->name() );
00256 ++style;
00257 }
00258
00259 if(styleBuffer <= lstStyle->count())
00260 lstStyle->setCurrentItem(styleBuffer);
00261 else
00262 if(cur <= lstStyle->count())
00263 lstStyle->setCurrentItem(cur);
00264
00265 if(cur > lstStyle->count()) {
00266 styleBuffer = cur;
00267 }
00268 noSignals=false;
00269 }
00270
00271 void KoCounterStyleWidget::displayStyle( KoParagCounter::Style style )
00272 {
00273 unsigned int i = 0;
00274 while ( stylesList.count() > i && stylesList.at(i)->style() != style )
00275 ++i;
00276 lstStyle->setCurrentItem(i);
00277
00278 bCustom->setText( m_counter.customBulletCharacter() );
00279 if ( !m_counter.customBulletFont().isEmpty() )
00280 bCustom->setFont( QFont( m_counter.customBulletFont() ) );
00281
00282 sPrefix->setText( m_counter.prefix() );
00283 sSuffix->setText( m_counter.suffix() );
00284
00285 spnDepth->setValue( m_counter.depth() );
00286 spnDisplayLevels->setValue( m_counter.displayLevels() );
00287 spnStart->setValue( m_counter.startNumber() );
00288
00289 cbRestart->setChecked( m_counter.restartCounter() );
00290 if(m_counter.alignment()==Qt::AlignLeft)
00291 cbAlignment->setCurrentText(i18n("Align Left"));
00292 else if(m_counter.alignment()==Qt::AlignRight)
00293 cbAlignment->setCurrentText(i18n("Align Right"));
00294 else if(m_counter.alignment()==Qt::AlignAuto)
00295 cbAlignment->setCurrentText(i18n("Align Auto"));
00296 else
00297 kdError()<<"Not Implemented"<<endl;
00298 }
00299
00300 void KoCounterStyleWidget::display( const KoParagLayout & lay ) {
00301 KoParagCounter::Style style = KoParagCounter::STYLE_NONE;
00302 if ( lay.counter )
00303 {
00304 style=lay.counter->style();
00305 m_counter = *lay.counter;
00306 }
00307 else
00308 {
00309 m_counter = KoParagCounter();
00310 }
00311 styleBuffer = 999;
00312
00313 numTypeChanged( m_counter.numbering() );
00314 emit sig_numTypeChanged( m_counter.numbering() );
00315
00316 displayStyle( style );
00317 }
00318
00319
00320 void KoCounterStyleWidget::numTypeChanged( int nType ) {
00321 m_counter.setNumbering( static_cast<KoParagCounter::Numbering>( nType ) );
00322 gStyle->setEnabled( m_counter.numbering() != KoParagCounter::NUM_NONE );
00323 fillStyleCombo(m_counter.numbering());
00324 bool state=m_counter.numbering()==KoParagCounter::NUM_LIST;
00325 bCustom->setEnabled(state);
00326 lCustom->setEnabled(state);
00327 }
00328
00329
00330 void KoCounterStyleWidget::makeCounterRepresenterList( QPtrList<StyleRepresenter>& stylesList, bool onlyStyleTypeLetter )
00331 {
00332 stylesList.setAutoDelete( true );
00333 stylesList.append( new StyleRepresenter(i18n( "Arabic Numbers" )
00334 , KoParagCounter::STYLE_NUM));
00335 stylesList.append( new StyleRepresenter(i18n( "Lower Alphabetical" )
00336 , KoParagCounter::STYLE_ALPHAB_L ));
00337 stylesList.append( new StyleRepresenter(i18n( "Upper Alphabetical" )
00338 , KoParagCounter::STYLE_ALPHAB_U ));
00339 stylesList.append( new StyleRepresenter(i18n( "Lower Roman Numbers" )
00340 , KoParagCounter::STYLE_ROM_NUM_L ));
00341 stylesList.append( new StyleRepresenter(i18n( "Upper Roman Numbers" )
00342 , KoParagCounter::STYLE_ROM_NUM_U ));
00343 if ( !onlyStyleTypeLetter )
00344 {
00345 stylesList.append( new StyleRepresenter(i18n( "Disc Bullet" )
00346 , KoParagCounter::STYLE_DISCBULLET , true));
00347 stylesList.append( new StyleRepresenter(i18n( "Square Bullet" )
00348 , KoParagCounter::STYLE_SQUAREBULLET , true));
00349 stylesList.append( new StyleRepresenter(i18n( "Box Bullet" )
00350 , KoParagCounter::STYLE_BOXBULLET , true));
00351 stylesList.append( new StyleRepresenter(i18n( "Circle Bullet" )
00352 , KoParagCounter::STYLE_CIRCLEBULLET , true));
00353 stylesList.append( new StyleRepresenter(i18n( "Custom Bullet" )
00354 , KoParagCounter::STYLE_CUSTOMBULLET , true));
00355 }
00356 stylesList.append( new StyleRepresenter(i18n( "None" ), KoParagCounter::STYLE_NONE));
00357 }
00358
00359
00360 void KoCounterStyleWidget::selectCustomBullet() {
00361 unsigned int i = 0;
00362 while ( stylesList.count() > i && stylesList.at(i)->style() != KoParagCounter::STYLE_CUSTOMBULLET )
00363 ++i;
00364 lstStyle->setCurrentItem(i);
00365
00366 QString f = m_counter.customBulletFont();
00367 if ( f.isEmpty() )
00368 f = "symbol";
00369 QChar c = m_counter.customBulletCharacter();
00370
00371 if ( KoCharSelectDia::selectChar( f, c ) ) {
00372 emit changeCustomBullet( f, c );
00373 m_counter.setCustomBulletFont( f );
00374 m_counter.setCustomBulletCharacter( c );
00375 if ( !f.isEmpty() )
00376 bCustom->setFont( QFont( f ) );
00377 bCustom->setText( c );
00378 }
00379 }
00380
00381 void KoCounterStyleWidget::numStyleChanged() {
00382 if ( noSignals )
00383 return;
00384
00385 styleBuffer = 999;
00386 StyleRepresenter *sr = stylesList.at(lstStyle->currentItem());
00387 emit changeStyle( sr->style() );
00388 m_counter.setStyle( sr->style() );
00389 bool isNumbered = !sr->isBullet() && !sr->style() == KoParagCounter::STYLE_NONE;
00390 lStart->setEnabled( isNumbered );
00391 spnStart->setEnabled( isNumbered );
00392 cbRestart->setEnabled( isNumbered );
00393 spnDisplayLevels->setEnabled( isNumbered );
00394 changeKWSpinboxType(sr->style() );
00395 }
00396
00397
00398
00399 KoSpinBox::KoSpinBox( QWidget * parent, const char * name )
00400 : QSpinBox(parent,name)
00401 {
00402 m_Etype=NONE;
00403
00404 setMaxValue ( 3999 );
00405 }
00406 KoSpinBox::~KoSpinBox( )
00407 {
00408 }
00409
00410 KoSpinBox::KoSpinBox( int minValue, int maxValue, int step ,
00411 QWidget * parent , const char * name )
00412 : QSpinBox(minValue, maxValue,step ,
00413 parent , name)
00414 {
00415 m_Etype=NONE;
00416 }
00417
00418 void KoSpinBox::setCounterType(counterType _type)
00419 {
00420 m_Etype=_type;
00421 editor()->setText(mapValueToText(value()));
00422 }
00423
00424
00425 QString KoSpinBox::mapValueToText( int value )
00426 {
00427 if(value==0 && m_Etype==NUM)
00428 return QString("0");
00429 else if(value==0 && m_Etype!=NUM)
00430 return QString::null;
00431 switch(m_Etype)
00432 {
00433 case NUM:
00434 return QString::number(value);
00435 case ALPHAB_L:
00436 return KoParagCounter::makeAlphaLowerNumber( value );
00437 case ALPHAB_U:
00438 return KoParagCounter::makeAlphaUpperNumber( value );
00439 case ROM_NUM_L:
00440 return KoParagCounter::makeRomanNumber( value );
00441 case ROM_NUM_U:
00442 return KoParagCounter::makeRomanNumber( value ).upper();
00443 case NONE:
00444 default:
00445 return QString::null;
00446 }
00447
00448 return QString::null;
00449 }
00450
00451 int KoSpinBox::mapTextToValue( bool * ok )
00452 {
00453 int ret;
00454 QString txt = text();
00455
00456 *ok = TRUE;
00457 switch(m_Etype)
00458 {
00459 case NUM:
00460 ret = txt.toInt ( ok );
00461 break;
00462 case ALPHAB_L:
00463 ret = KoParagCounter::fromAlphaLowerNumber( txt.lower() );
00464 break;
00465 case ALPHAB_U:
00466 ret = KoParagCounter::fromAlphaUpperNumber( txt.upper() );
00467 break;
00468 case ROM_NUM_L:
00469 ret = KoParagCounter::fromRomanNumber( txt.lower() );
00470 break;
00471 case ROM_NUM_U:
00472 ret = KoParagCounter::fromRomanNumber( txt.lower() );
00473 break;
00474 case NONE:
00475 default:
00476 ret = -1;
00477 break;
00478 }
00479
00480 if (ret == -1)
00481 *ok = FALSE;
00482
00483 return ret;
00484 }
00485
00486
00487
00488
00489
00490
00491 KPagePreview::KPagePreview( QWidget* parent, const char* name )
00492 : QGroupBox( i18n( "Preview" ), parent, name )
00493 {
00494 left = 0;
00495 right = 0;
00496 first = 0;
00497 spacing = 0;
00498 before = 0;
00499 after = 0;
00500 }
00501
00502 void KPagePreview::drawContents( QPainter* p )
00503 {
00504 int wid = 148;
00505 int hei = 210;
00506 int _x = ( width() - wid ) / 5;
00507 int _y = ( height() - hei ) / 5;
00508
00509 int dl = convert(left);
00510 int dr = convert(right);
00511
00512
00513 int df = convert(first) + dl;
00514
00515 int spc = convert(spacing);
00516
00517
00518 p->setPen( QPen( black ) );
00519 p->setBrush( QBrush( black ) );
00520
00521 p->drawRect( _x + 1, _y + 1, wid, hei );
00522
00523 p->setBrush( QBrush( white ) );
00524 p->drawRect( _x, _y, wid, hei );
00525
00526
00527 p->setPen( NoPen );
00528 p->setBrush( QBrush( lightGray ) );
00529
00530 for ( int i = 1; i <= 4; i++ )
00531 p->drawRect( _x + 6, _y + 6 + ( i - 1 ) * 12 + 2, wid - 12 - ( ( i / 4 ) * 4 == i ? 50 : 0 ), 6 );
00532
00533 p->setBrush( QBrush( darkGray ) );
00534
00535 for ( int i = 5; i <= 8; i++ )
00536 {
00537 QRect rect( ( i == 5 ? df : dl ) + _x + 6, _y + 6 + ( i - 1 ) * 12 + 2 + ( i - 5 ) * spc + static_cast<int>( before / 2 ),
00538 wid - 12 - ( ( i / 4 ) * 4 == i ? 50 : 0 ) - ( ( i == 12 ? 0 : dr ) + ( i == 5 ? df : dl ) ), 6);
00539
00540 if(rect.width ()>=0)
00541 p->drawRect( rect );
00542 }
00543 p->setBrush( QBrush( lightGray ) );
00544
00545 for ( int i = 9; i <= 12; i++ )
00546 p->drawRect( _x + 6, _y + 6 + ( i - 1 ) * 12 + 2 + 3 * spc +
00547 static_cast<int>( before / 2 ) + static_cast<int>( after / 2 ),
00548 wid - 12 - ( ( i / 4 ) * 4 == i ? 50 : 0 ), 6 );
00549
00550 }
00551
00552 int KPagePreview::convert(double input) {
00553 if(input < 1) return 0;
00554 if(input <= 5) return 3;
00555 if(input <= 10) return 4 + static_cast<int>( (input-5) / 2.5 );
00556 if(input <= 20) return 6 + static_cast<int>( (input-10) / 4 );
00557 if(input <= 100) return 10 + static_cast<int>( (input-20) / 8 );
00558 return static_cast<int>( input / 5);
00559 }
00560
00561
00562
00563
00564
00565 KPagePreview2::KPagePreview2( QWidget* parent, const char* name )
00566 : QGroupBox( i18n( "Preview" ), parent, name )
00567 {
00568 align = Qt::AlignLeft;
00569 }
00570
00571 void KPagePreview2::drawContents( QPainter* p )
00572 {
00573 int wid = 148;
00574 int hei = 210;
00575 int _x = ( width() - wid ) / 2;
00576 int _y = ( height() - hei ) / 2;
00577
00578
00579 p->setPen( QPen( black ) );
00580 p->setBrush( QBrush( black ) );
00581
00582 p->drawRect( _x + 1, _y + 1, wid, hei );
00583
00584 p->setBrush( QBrush( white ) );
00585 p->drawRect( _x, _y, wid, hei );
00586
00587
00588 p->setPen( NoPen );
00589 p->setBrush( QBrush( lightGray ) );
00590
00591 for ( int i = 1; i <= 4; i++ )
00592 p->drawRect( _x + 6, _y + 6 + ( i - 1 ) * 12 + 2, wid - 12 - ( ( i / 4 ) * 4 == i ? 50 : 0 ), 6 );
00593
00594 p->setBrush( QBrush( darkGray ) );
00595
00596 int __x = 0, __w = 0;
00597 for ( int i = 5; i <= 8; i++ ) {
00598 switch ( i ) {
00599 case 5: __w = wid - 12;
00600 break;
00601 case 6: __w = wid - 52;
00602 break;
00603 case 7: __w = wid - 33;
00604 break;
00605 case 8: __w = wid - 62;
00606 default: break;
00607 }
00608
00609 switch ( align ) {
00610 case Qt::AlignAuto:
00611 case Qt::AlignLeft:
00612 __x = _x + 6;
00613 break;
00614 case Qt::AlignHCenter:
00615 __x = _x + ( wid - __w ) / 2;
00616 break;
00617 case Qt::AlignRight:
00618 __x = _x + ( wid - __w ) - 6;
00619 break;
00620 case Qt::AlignJustify:
00621 {
00622 if ( i < 8 ) __w = wid - 12;
00623 __x = _x + 6;
00624 } break;
00625 }
00626
00627 p->drawRect( __x, _y + 6 + ( i - 1 ) * 12 + 2 + ( i - 5 ), __w, 6 );
00628 }
00629
00630 p->setBrush( QBrush( lightGray ) );
00631
00632 for ( int i = 9; i <= 12; i++ )
00633 p->drawRect( _x + 6, _y + 6 + ( i - 1 ) * 12 + 2 + 3, wid - 12 - ( ( i / 4 ) * 4 == i ? 50 : 0 ), 6 );
00634
00635 }
00636
00637
00638
00639
00640
00641
00642 KoBorderPreview::KoBorderPreview( QWidget* parent, const char* name )
00643 :QFrame(parent,name)
00644 {
00645 }
00646
00647 void KoBorderPreview::mousePressEvent( QMouseEvent *_ev )
00648 {
00649 emit choosearea(_ev);
00650 }
00651
00652
00653 void KoBorderPreview::drawContents( QPainter* painter )
00654 {
00655 QRect r = contentsRect();
00656 QFontMetrics fm( font() );
00657
00658 painter->fillRect( r.x() + fm.width( 'W' ), r.y() + fm.height(), r.width() - 2 * fm.width( 'W' ),
00659 r.height() - 2 * fm.height(), white );
00660 painter->setClipRect( r.x() + fm.width( 'W' ), r.y() + fm.height(), r.width() - 2 * fm.width( 'W' ),
00661 r.height() - 2 * fm.height() );
00662
00663 if ( m_topBorder.width() > 0 ) {
00664 painter->setPen( setBorderPen( m_topBorder ) );
00665 painter->drawLine( r.x() + 20, r.y() + 30, r.right() - 20, r.y() + 30 );
00666 if ( m_topBorder.getStyle()==KoBorder::DOUBLE_LINE)
00667 painter->drawLine( r.x() + 20, int(r.y() + 30+m_topBorder.width()+1), r.right() - 20, int(r.y() + 30+m_topBorder.width()+1) );
00668
00669
00670 }
00671
00672 if ( m_bottomBorder.width() > 0 ) {
00673 painter->setPen( setBorderPen( m_bottomBorder ) );
00674 painter->drawLine( r.x() + 20, r.bottom() - 30, r.right() - 20, r.bottom() - 30 );
00675 if ( m_bottomBorder.getStyle()==KoBorder::DOUBLE_LINE)
00676 painter->drawLine( r.x() + 20, int(r.bottom() - 30 - m_bottomBorder.width()-1), r.right() - 20, int(r.bottom() - 30 - m_bottomBorder.width() - 1) );
00677
00678 }
00679
00680 if ( m_leftBorder.width() > 0 ) {
00681 painter->setPen( setBorderPen( m_leftBorder ) );
00682 painter->drawLine( r.x() + 20, r.y() + 30, r.x() + 20, r.bottom() - 30 );
00683 if ( m_leftBorder.getStyle()==KoBorder::DOUBLE_LINE)
00684 painter->drawLine( int(r.x() + 20 + m_leftBorder.width() +1) , r.y() + 30, int(r.x() + 20+ m_leftBorder.width() +1), r.bottom() - 30 );
00685
00686 }
00687
00688 if ( m_rightBorder.width() > 0 ) {
00689 painter->setPen( setBorderPen( m_rightBorder ) );
00690 painter->drawLine( r.right() - 20, r.y() + 30, r.right() - 20, r.bottom() - 30 );
00691 if ( m_rightBorder.getStyle()==KoBorder::DOUBLE_LINE)
00692 painter->drawLine( int(r.right() - 20 - m_rightBorder.width() - 1), r.y() + 30, int(r.right() - 20 - m_rightBorder.width() - 1), r.bottom() - 30 );
00693
00694 }
00695 }
00696
00697 QPen KoBorderPreview::setBorderPen( KoBorder _brd )
00698 {
00699 QPen pen( black, 1, SolidLine );
00700
00701 pen.setWidth( static_cast<int>( _brd.penWidth() ) );
00702 pen.setColor( _brd.color );
00703
00704 switch ( _brd.getStyle() ) {
00705 case KoBorder::SOLID:
00706 pen.setStyle( SolidLine );
00707 break;
00708 case KoBorder::DASH:
00709 pen.setStyle( DashLine );
00710 break;
00711 case KoBorder::DOT:
00712 pen.setStyle( DotLine );
00713 break;
00714 case KoBorder::DASH_DOT:
00715 pen.setStyle( DashDotLine );
00716 break;
00717 case KoBorder::DASH_DOT_DOT:
00718 pen.setStyle( DashDotDotLine );
00719 break;
00720 case KoBorder::DOUBLE_LINE:
00721 pen.setStyle( SolidLine );
00722 break;
00723 }
00724
00725 return QPen( pen );
00726 }
00727
00728
00729
00730
00731 KoStylePreview::KoStylePreview( const QString& title, const QString& text, QWidget* parent, const char* name )
00732 : QGroupBox( title, parent, name )
00733 {
00734 setMinimumHeight(80);
00735 m_zoomHandler = new KoZoomHandler;
00736 QFont font = KoGlobal::defaultFont();
00737 m_textdoc = new KoTextDocument( m_zoomHandler, new KoTextFormatCollection( font, QColor(), KGlobal::locale()->language(), false ) );
00738
00739 KoTextParag * parag = m_textdoc->firstParag();
00740 parag->insert( 0, text );
00741 }
00742
00743 KoStylePreview::~KoStylePreview()
00744 {
00745 delete m_textdoc;
00746 delete m_zoomHandler;
00747 }
00748
00749 void KoStylePreview::setCounter( const KoParagCounter & counter )
00750 {
00751 KoTextParag * parag = m_textdoc->firstParag();
00752 parag->setCounter( counter );
00753 repaint( true );
00754 }
00755
00756 void KoStylePreview::setStyle( KoParagStyle * style )
00757 {
00758 KoTextParag * parag = m_textdoc->firstParag();
00759 parag->applyStyle( style );
00760 repaint(true);
00761 }
00762
00763 void KoStylePreview::drawContents( QPainter *painter )
00764 {
00765 painter->save();
00766 QRect r = contentsRect();
00767
00768
00769 QRect whiteRect( r.x() + 10, r.y() + 10,
00770 r.width() - 20, r.height() - 20 );
00771 QColorGroup cg = QApplication::palette().active();
00772 painter->fillRect( whiteRect, cg.brush( QColorGroup::Base ) );
00773
00774 KoTextParag * parag = m_textdoc->firstParag();
00775 int widthLU = m_zoomHandler->pixelToLayoutUnitX( whiteRect.width() - 2 );
00776 if ( m_textdoc->width() != widthLU )
00777 {
00778
00779 m_textdoc->setWidth( widthLU );
00780 parag->invalidate(0);
00781 }
00782
00783 parag->format();
00784 QRect textRect = parag->pixelRect( m_zoomHandler );
00785
00786
00787 textRect.moveTopLeft( QPoint( whiteRect.x(),
00788 whiteRect.y() + ( whiteRect.height() - textRect.height() ) / 2 ) );
00789
00790 textRect.rLeft() += 4;
00791 textRect.rRight() += 4;
00792
00793
00794 painter->setClipRect( textRect.intersect( whiteRect ) );
00795 painter->translate( textRect.x(), textRect.y() );
00796
00797 m_textdoc->drawWYSIWYG( painter, 0, 0, textRect.width(), textRect.height(), cg, m_zoomHandler );
00798 painter->restore();
00799 }
00800
00801 KoIndentSpacingWidget::KoIndentSpacingWidget( KoUnit::Unit unit, double _frameWidth,QWidget * parent, const char * name )
00802 : KoParagLayoutWidget( KoParagDia::PD_SPACING, parent, name ), m_unit( unit )
00803 {
00804 QString unitName = KoUnit::unitName( m_unit );
00805 QGridLayout *mainGrid = new QGridLayout( this, 3, 2, KDialog::marginHint(), KDialog::spacingHint() );
00806
00807
00808
00809
00810
00811
00812
00813
00814 double frameWidth=_frameWidth;
00815 QString length;
00816 if(frameWidth==-1) {
00817 frameWidth=9999;
00818 } else {
00819 length=i18n("Frame width: %1").arg(KoUnit::toUserStringValue(frameWidth,m_unit));
00820 frameWidth=KoUnit::toUserValue(frameWidth,m_unit);
00821 }
00822
00823 QGroupBox * indentFrame = new QGroupBox( i18n( "Indent" ), this );
00824 QGridLayout * indentGrid = new QGridLayout( indentFrame, 5, 2, KDialog::marginHint(), KDialog::spacingHint() );
00825
00826 QLabel * lLimit = new QLabel(length , indentFrame );
00827 if(frameWidth!=-1)
00828 {
00829 lLimit->setAlignment( AlignRight );
00830 indentGrid->addWidget( lLimit, 1,0 );
00831 }
00832
00833 QLabel * lLeft = new QLabel( i18n("&Left (%1):").arg(unitName), indentFrame );
00834 lLeft->setAlignment( AlignRight );
00835 indentGrid->addWidget( lLeft, 2, 0 );
00836
00837 eLeft = new KDoubleNumInput( indentFrame );
00838 eLeft->setRange( 0, 9999, 1, false);
00839 lLeft->setBuddy( eLeft );
00840 indentGrid->addWidget( eLeft, 2, 1 );
00841 connect( eLeft, SIGNAL( valueChanged(double ) ), this, SLOT( leftChanged( double ) ) );
00842
00843 QLabel * lRight = new QLabel( i18n("&Right (%1):").arg(unitName), indentFrame );
00844 lRight->setAlignment( AlignRight );
00845 indentGrid->addWidget( lRight, 3, 0 );
00846
00847 eRight = new KDoubleNumInput( indentFrame );
00848 eRight->setRange( 0, 9999, 1, false);
00849 lRight->setBuddy( eRight );
00850 indentGrid->addWidget( eRight, 3, 1 );
00851 connect( eRight, SIGNAL( valueChanged( double ) ), this, SLOT( rightChanged( double ) ) );
00852
00853 QLabel * lFirstLine = new QLabel( i18n("&First line (%1):").arg(unitName), indentFrame );
00854 lFirstLine->setAlignment( AlignRight );
00855 indentGrid->addWidget( lFirstLine, 4, 0 );
00856
00857 eFirstLine = new KDoubleNumInput( indentFrame );
00858 eFirstLine->setRange( -9999, 9999, 1, false);
00859 lFirstLine->setBuddy( eFirstLine );
00860 connect( eFirstLine, SIGNAL( valueChanged( double ) ), this, SLOT( firstChanged( double ) ) );
00861 indentGrid->addWidget( eFirstLine, 4, 1 );
00862
00863
00864 indentGrid->addRowSpacing( 0, fontMetrics().height() / 2 );
00865 for ( int i = 1 ; i < indentGrid->numRows() ; ++i )
00866 indentGrid->setRowStretch( i, 1 );
00867 mainGrid->addWidget( indentFrame, 0, 0 );
00868
00869
00870 QGroupBox * spacingFrame = new QGroupBox( i18n( "Line &Spacing" ), this, "spacingFrame" );
00871 QGridLayout * spacingGrid = new QGridLayout( spacingFrame, 2, 1,
00872 KDialog::marginHint(), KDialog::spacingHint() );
00873
00874 cSpacing = new QComboBox( false, spacingFrame, "" );
00875
00876 cSpacing->insertItem( i18n( "Line spacing value", "Single" ) );
00877 cSpacing->insertItem( i18n( "Line spacing value", "1.5 Lines" ) );
00878 cSpacing->insertItem( i18n( "Line spacing value", "Double" ) );
00879 cSpacing->insertItem( i18n( "Proportional") );
00880 cSpacing->insertItem( i18n( "Line Distance (%1)" ).arg(unitName) );
00881 cSpacing->insertItem( i18n( "At Least (%1)" ).arg(unitName) );
00882 cSpacing->insertItem( i18n( "Fixed (%1)").arg(unitName) );
00883
00884 connect( cSpacing, SIGNAL( activated( int ) ), this, SLOT( spacingActivated( int ) ) );
00885 spacingGrid->addWidget( cSpacing, 1, 0 );
00886
00887 eSpacing = new KDoubleNumInput( spacingFrame );
00888 eSpacing->setRange( 0, 9999, 1, false);
00889 connect( eSpacing, SIGNAL( valueChanged( double ) ), this, SLOT( spacingChanged( double ) ) );
00890 spacingGrid->addWidget( eSpacing, 1, 1 );
00891
00892
00893 spacingGrid->addRowSpacing( 0, fontMetrics().height() / 2 );
00894 for ( int i = 1 ; i < spacingGrid->numRows() ; ++i )
00895 spacingGrid->setRowStretch( i, 1 );
00896 mainGrid->addWidget( spacingFrame, 1, 0 );
00897
00898 eSpacing->setEnabled( true );
00899
00900
00901 QGroupBox * pSpaceFrame = new QGroupBox( i18n( "Para&graph Space" ), this, "pSpaceFrame" );
00902 QGridLayout * pSpaceGrid = new QGridLayout( pSpaceFrame, 3, 2,
00903 KDialog::marginHint(), KDialog::spacingHint() );
00904
00905 QLabel * lBefore = new QLabel( i18n("Before (%1):").arg(unitName), pSpaceFrame );
00906 lBefore->setAlignment( AlignRight );
00907 pSpaceGrid->addWidget( lBefore, 1, 0 );
00908
00909 eBefore = new KDoubleNumInput( pSpaceFrame );
00910 eBefore->setRange( 0 , 9999, 1, false);
00911 connect( eBefore, SIGNAL( valueChanged( double ) ), this, SLOT( beforeChanged( double ) ) );
00912 pSpaceGrid->addWidget( eBefore, 1, 1 );
00913
00914 QLabel * lAfter = new QLabel( i18n("After (%1):").arg(unitName), pSpaceFrame );
00915 lAfter->setAlignment( AlignRight );
00916 pSpaceGrid->addWidget( lAfter, 2, 0 );
00917
00918 eAfter = new KDoubleNumInput( pSpaceFrame );
00919 eAfter->setRange( 0 , 9999, 1, false);
00920 connect( eAfter, SIGNAL( valueChanged( double ) ), this, SLOT( afterChanged( double ) ) );
00921 pSpaceGrid->addWidget( eAfter, 2, 1 );
00922
00923
00924 pSpaceGrid->addRowSpacing( 0, fontMetrics().height() / 2 );
00925 for ( int i = 1 ; i < pSpaceGrid->numRows() ; ++i )
00926 pSpaceGrid->setRowStretch( i, 1 );
00927 mainGrid->addWidget( pSpaceFrame, 2, 0 );
00928
00929
00930 prev1 = new KPagePreview( this, "KPagePreview" );
00931 mainGrid->addMultiCellWidget( prev1, 0, mainGrid->numRows()-1, 1, 1 );
00932
00933 mainGrid->setColStretch( 1, 1 );
00934
00935 }
00936
00937 double KoIndentSpacingWidget::leftIndent() const
00938 {
00939 return QMAX(0,KoUnit::fromUserValue( eLeft->value(), m_unit ));
00940 }
00941
00942 double KoIndentSpacingWidget::rightIndent() const
00943 {
00944 return QMAX(0,KoUnit::fromUserValue( eRight->value(), m_unit ));
00945 }
00946
00947 double KoIndentSpacingWidget::firstLineIndent() const
00948 {
00949 return KoUnit::fromUserValue( eFirstLine->value(), m_unit );
00950 }
00951
00952 double KoIndentSpacingWidget::spaceBeforeParag() const
00953 {
00954 return QMAX(0, KoUnit::fromUserValue( eBefore->value(), m_unit ));
00955 }
00956
00957 double KoIndentSpacingWidget::spaceAfterParag() const
00958 {
00959 return QMAX(0,KoUnit::fromUserValue( eAfter->value(), m_unit ));
00960 }
00961
00962 KoParagLayout::SpacingType KoIndentSpacingWidget::lineSpacingType() const
00963 {
00964 int index = cSpacing->currentItem();
00965 switch ( index ) {
00966 case 0:
00967 return KoParagLayout::LS_SINGLE;
00968 case 1:
00969 return KoParagLayout::LS_ONEANDHALF;
00970 case 2:
00971 return KoParagLayout::LS_DOUBLE;
00972 case 3:
00973 return KoParagLayout::LS_MULTIPLE;
00974 case 4:
00975 return KoParagLayout::LS_CUSTOM;
00976 case 5:
00977 return KoParagLayout::LS_AT_LEAST;
00978 case 6:
00979 return KoParagLayout::LS_FIXED;
00980 default:
00981 kdError(32500) << "Error in KoIndentSpacingWidget::lineSpacingType" << endl;
00982 return KoParagLayout::LS_SINGLE;
00983 }
00984 }
00985
00986 double KoIndentSpacingWidget::lineSpacing() const
00987 {
00988 return (lineSpacingType() == KoParagLayout::LS_MULTIPLE)
00989 ? QMAX(1, eSpacing->value())
00990 : QMAX(0, KoUnit::fromUserValue( eSpacing->value(), m_unit ));
00991 }
00992
00993
00994 void KoIndentSpacingWidget::display( const KoParagLayout & lay )
00995 {
00996 double _left = lay.margins[QStyleSheetItem::MarginLeft];
00997 double leftInUnit = KoUnit::toUserValue( _left, m_unit );
00998 eLeft->setValue( leftInUnit );
00999
01000 leftChanged( _left );
01001
01002 double _right = lay.margins[QStyleSheetItem::MarginRight];
01003 eRight->setValue( KoUnit::toUserValue( _right, m_unit ) );
01004 prev1->setRight( _right );
01005
01006 double _first = lay.margins[QStyleSheetItem::MarginFirstLine];
01007 eFirstLine->setValue( KoUnit::toUserValue( _first, m_unit ) );
01008 prev1->setFirst( _first );
01009
01010 double _before = lay.margins[QStyleSheetItem::MarginTop];
01011 eBefore->setValue( KoUnit::toUserValue( _before, m_unit ) );
01012 prev1->setBefore( _before );
01013
01014 double _after = lay.margins[QStyleSheetItem::MarginBottom];
01015 eAfter->setValue( KoUnit::toUserValue( _after, m_unit ) );
01016 prev1->setAfter( _after );
01017
01018 double _spacing = lay.lineSpacingValue();
01019 KoParagLayout::SpacingType _type = lay.lineSpacingType;
01020 switch ( _type ) {
01021 case KoParagLayout::LS_SINGLE:
01022 cSpacing->setCurrentItem( 0 );
01023 break;
01024 case KoParagLayout::LS_ONEANDHALF:
01025 cSpacing->setCurrentItem( 1 );
01026 break;
01027 case KoParagLayout::LS_DOUBLE:
01028 cSpacing->setCurrentItem( 2 );
01029 break;
01030 case KoParagLayout::LS_MULTIPLE:
01031 cSpacing->setCurrentItem( 3 );
01032 break;
01033 case KoParagLayout::LS_CUSTOM:
01034 cSpacing->setCurrentItem( 4 );
01035 break;
01036 case KoParagLayout::LS_AT_LEAST:
01037 cSpacing->setCurrentItem( 5 );
01038 break;
01039 case KoParagLayout::LS_FIXED:
01040 cSpacing->setCurrentItem( 6 );
01041 break;
01042 default:
01043 cSpacing->setCurrentItem( 0 );
01044 break;
01045 }
01046
01047 updateLineSpacing( _type );
01048 eSpacing->setValue( (_type == KoParagLayout::LS_MULTIPLE) ? QMAX( 1, _spacing )
01049 : KoUnit::toUserValue( _spacing, m_unit ) );
01050
01051 }
01052
01053 void KoIndentSpacingWidget::save( KoParagLayout & lay )
01054 {
01055 lay.setLineSpacingValue(lineSpacing());
01056 lay.lineSpacingType = lineSpacingType();
01057 lay.margins[QStyleSheetItem::MarginLeft] = leftIndent();
01058 lay.margins[QStyleSheetItem::MarginRight] = rightIndent();
01059 lay.margins[QStyleSheetItem::MarginFirstLine] = firstLineIndent();
01060 lay.margins[QStyleSheetItem::MarginTop] = spaceBeforeParag();
01061 lay.margins[QStyleSheetItem::MarginBottom] = spaceAfterParag();
01062 }
01063
01064 QString KoIndentSpacingWidget::tabName()
01065 {
01066 return i18n( "Indent && S&pacing" );
01067 }
01068
01069 void KoIndentSpacingWidget::leftChanged( double _val )
01070 {
01071 prev1->setLeft( _val );
01072
01073 eFirstLine->setMinValue( -QMAX( 0, _val ) );
01074 }
01075
01076 void KoIndentSpacingWidget::rightChanged( double _val )
01077 {
01078 prev1->setRight( _val );
01079 }
01080
01081 void KoIndentSpacingWidget::firstChanged( double _val )
01082 {
01083 prev1->setFirst( _val );
01084 }
01085
01086 void KoIndentSpacingWidget::updateLineSpacing( KoParagLayout::SpacingType _type )
01087 {
01088 bool needsValue = (_type != KoParagLayout::LS_SINGLE &&
01089 _type != KoParagLayout::LS_ONEANDHALF &&
01090 _type != KoParagLayout::LS_DOUBLE);
01091
01092 eSpacing->setEnabled( needsValue );
01093 if ( needsValue )
01094 prev1->setSpacing( eSpacing->value() );
01095 else
01096 {
01097 prev1->setSpacing( _type == KoParagLayout::LS_ONEANDHALF ? 8 :
01098 _type == KoParagLayout::LS_DOUBLE ? 16 :0 );
01099 }
01100 }
01101
01102 void KoIndentSpacingWidget::spacingActivated( int )
01103 {
01104 updateLineSpacing( lineSpacingType() );
01105 if ( eSpacing->isEnabled() )
01106 eSpacing->setFocus();
01107 }
01108
01109 void KoIndentSpacingWidget::spacingChanged( double _val )
01110 {
01111 prev1->setSpacing( _val );
01112 }
01113
01114 void KoIndentSpacingWidget::beforeChanged( double _val )
01115 {
01116 prev1->setBefore( _val );
01117 }
01118
01119 void KoIndentSpacingWidget::afterChanged( double _val )
01120 {
01121 prev1->setAfter( _val );
01122 }
01123
01124
01125 KoParagAlignWidget::KoParagAlignWidget( bool breakLine, QWidget * parent, const char * name )
01126 : KoParagLayoutWidget( KoParagDia::PD_ALIGN, parent, name )
01127 {
01128 QGridLayout *grid = new QGridLayout( this, 3, 2, KDialog::marginHint(), KDialog::spacingHint() );
01129
01130 QVGroupBox * AlignGroup = new QVGroupBox( i18n( "Alignment" ), this );
01131
01132 rLeft = new QRadioButton( i18n( "&Left" ), AlignGroup );
01133 connect( rLeft, SIGNAL( clicked() ), this, SLOT( alignLeft() ) );
01134
01135 rCenter = new QRadioButton( i18n( "C&enter" ), AlignGroup );
01136 connect( rCenter, SIGNAL( clicked() ), this, SLOT( alignCenter() ) );
01137
01138 rRight = new QRadioButton( i18n( "&Right" ), AlignGroup );
01139 connect( rRight, SIGNAL( clicked() ), this, SLOT( alignRight() ) );
01140
01141 rJustify = new QRadioButton( i18n( "&Justify" ), AlignGroup );
01142 connect( rJustify, SIGNAL( clicked() ), this, SLOT( alignJustify() ) );
01143
01144 clearAligns();
01145 rLeft->setChecked( true );
01146
01147 grid->addWidget(AlignGroup, 0, 0);
01148
01149
01150 QGroupBox * endFramePage = new QGroupBox( i18n( "Behavior at &End of Frame/Page" ), this );
01151 QGridLayout * endFramePageGrid = new QGridLayout( endFramePage, 4, 1,
01152 KDialog::marginHint(), KDialog::spacingHint() );
01153
01154 cKeepLinesTogether = new QCheckBox( i18n("&Keep lines together"),endFramePage);
01155 endFramePageGrid->addWidget( cKeepLinesTogether, 1, 0 );
01156 cHardBreakBefore = new QCheckBox( i18n("Insert break before paragraph"),endFramePage);
01157 endFramePageGrid->addWidget( cHardBreakBefore, 2, 0 );
01158 cHardBreakAfter = new QCheckBox( i18n("Insert break after paragraph"),endFramePage);
01159 endFramePageGrid->addWidget( cHardBreakAfter, 3, 0 );
01160
01161 endFramePageGrid->addRowSpacing( 0, fontMetrics().height() / 2 );
01162 for ( int i = 0 ; i < endFramePageGrid->numRows()-1 ; ++i )
01163 endFramePageGrid->setRowStretch( 0, 0 );
01164 endFramePageGrid->setRowStretch( endFramePageGrid->numRows()-1, 1 );
01165 grid->addWidget( endFramePage, 2, 0 );
01166
01167 endFramePage->setEnabled(breakLine);
01168
01169
01170 prev2 = new KPagePreview2( this, "KPagePreview2" );
01171 grid->addMultiCellWidget( prev2, 0, 2, 1, 1 );
01172
01173
01174 grid->setColStretch( 1, 1 );
01175 grid->setRowStretch( 1, 1 );
01176 }
01177
01178 int KoParagAlignWidget::pageBreaking() const
01179 {
01180 int pb = 0;
01181 if ( cKeepLinesTogether->isChecked() )
01182 pb |= KoParagLayout::KeepLinesTogether;
01183 if ( cHardBreakBefore->isChecked() )
01184 pb |= KoParagLayout::HardFrameBreakBefore;
01185 if ( cHardBreakAfter->isChecked() )
01186 pb |= KoParagLayout::HardFrameBreakAfter;
01187 return pb;
01188 }
01189
01190
01191 void KoParagAlignWidget::display( const KoParagLayout & lay )
01192 {
01193 int align = lay.alignment;
01194 prev2->setAlign( align );
01195
01196 clearAligns();
01197 switch ( align ) {
01198 case Qt::AlignAuto:
01199 case Qt::AlignLeft:
01200 rLeft->setChecked( true );
01201 break;
01202 case Qt::AlignHCenter:
01203 rCenter->setChecked( true );
01204 break;
01205 case Qt::AlignRight:
01206 rRight->setChecked( true );
01207 break;
01208 case Qt::AlignJustify:
01209 rJustify->setChecked( true );
01210 break;
01211
01212 cKeepLinesTogether->setChecked( lay.pageBreaking & KoParagLayout::KeepLinesTogether );
01213 cHardBreakBefore->setChecked( lay.pageBreaking & KoParagLayout::HardFrameBreakBefore );
01214 cHardBreakAfter->setChecked( lay.pageBreaking & KoParagLayout::HardFrameBreakAfter );
01215
01216
01217 }
01218 }
01219
01220 void KoParagAlignWidget::save( KoParagLayout & lay )
01221 {
01222 lay.alignment = align();
01223 lay.pageBreaking = pageBreaking();
01224 }
01225
01226 int KoParagAlignWidget::align() const
01227 {
01228 if ( rLeft->isChecked() ) return Qt::AlignLeft;
01229 else if ( rCenter->isChecked() ) return Qt::AlignHCenter;
01230 else if ( rRight->isChecked() ) return Qt::AlignRight;
01231 else if ( rJustify->isChecked() ) return Qt::AlignJustify;
01232
01233 return Qt::AlignLeft;
01234 }
01235
01236 QString KoParagAlignWidget::tabName()
01237 {
01238 return i18n( "General &Layout" );
01239 }
01240
01241 void KoParagAlignWidget::alignLeft()
01242 {
01243 prev2->setAlign( Qt::AlignLeft );
01244 clearAligns();
01245 rLeft->setChecked( true );
01246 }
01247
01248 void KoParagAlignWidget::alignCenter()
01249 {
01250 prev2->setAlign( Qt::AlignHCenter );
01251 clearAligns();
01252 rCenter->setChecked( true );
01253 }
01254
01255 void KoParagAlignWidget::alignRight()
01256 {
01257 prev2->setAlign( Qt::AlignRight );
01258 clearAligns();
01259 rRight->setChecked( true );
01260 }
01261
01262 void KoParagAlignWidget::alignJustify()
01263 {
01264 prev2->setAlign( Qt::AlignJustify );
01265 clearAligns();
01266 rJustify->setChecked( true );
01267 }
01268
01269 void KoParagAlignWidget::clearAligns()
01270 {
01271 rLeft->setChecked( false );
01272 rCenter->setChecked( false );
01273 rRight->setChecked( false );
01274 rJustify->setChecked( false );
01275 }
01276
01277 KoParagBorderWidget::KoParagBorderWidget( QWidget * parent, const char * name )
01278 : KoParagLayoutWidget( KoParagDia::PD_BORDERS, parent, name )
01279 {
01280 QGridLayout *grid = new QGridLayout( this, 8, 2, KDialog::marginHint(), KDialog::spacingHint() );
01281
01282 QLabel * lStyle = new QLabel( i18n( "St&yle:" ), this );
01283 grid->addWidget( lStyle, 0, 0 );
01284
01285 cStyle = new QComboBox( false, this );
01286 cStyle->insertItem( KoBorder::getStyle( KoBorder::SOLID ) );
01287 cStyle->insertItem( KoBorder::getStyle( KoBorder::DASH ) );
01288 cStyle->insertItem( KoBorder::getStyle( KoBorder::DOT ) );
01289 cStyle->insertItem( KoBorder::getStyle( KoBorder::DASH_DOT ) );
01290 cStyle->insertItem( KoBorder::getStyle( KoBorder::DASH_DOT_DOT ) );
01291 cStyle->insertItem( KoBorder::getStyle( KoBorder::DOUBLE_LINE ) );
01292 lStyle->setBuddy( cStyle );
01293 grid->addWidget( cStyle, 1, 0 );
01294
01295
01296 QLabel * lWidth = new QLabel( i18n( "&Width:" ), this );
01297 grid->addWidget( lWidth, 2, 0 );
01298
01299 cWidth = new QComboBox( false, this );
01300 for( unsigned int i = 1; i <= 10; i++ )
01301 cWidth->insertItem(QString::number(i));
01302 lWidth->setBuddy( cWidth );
01303 grid->addWidget( cWidth, 3, 0 );
01304
01305
01306 QLabel * lColor = new QLabel( i18n( "Co&lor:" ), this );
01307 grid->addWidget( lColor, 4, 0 );
01308
01309 bColor = new KColorButton( black,
01310 black,
01311 this );
01312
01313 lColor->setBuddy( bColor );
01314 grid->addWidget( bColor, 5, 0 );
01315
01316
01317 QButtonGroup * bb = new QHButtonGroup( this );
01318 bb->setFrameStyle(QFrame::NoFrame);
01319 bLeft = new QPushButton(bb);
01320 bLeft->setPixmap( BarIcon( "borderleft" ) );
01321 bLeft->setToggleButton( true );
01322 bRight = new QPushButton(bb);
01323 bRight->setPixmap( BarIcon( "borderright" ) );
01324 bRight->setToggleButton( true );
01325 bTop = new QPushButton(bb);
01326 bTop->setPixmap( BarIcon( "bordertop" ) );
01327 bTop->setToggleButton( true );
01328 bBottom = new QPushButton(bb);
01329 bBottom->setPixmap( BarIcon( "borderbottom" ) );
01330 bBottom->setToggleButton( true );
01331 grid->addWidget( bb, 6, 0 );
01332
01333 connect( bLeft, SIGNAL( toggled( bool ) ), this, SLOT( brdLeftToggled( bool ) ) );
01334 connect( bRight, SIGNAL( toggled( bool ) ), this, SLOT( brdRightToggled( bool ) ) );
01335 connect( bTop, SIGNAL( toggled( bool ) ), this, SLOT( brdTopToggled( bool ) ) );
01336 connect( bBottom, SIGNAL( toggled( bool ) ), this, SLOT( brdBottomToggled( bool ) ) );
01337
01338 QGroupBox *grp=new QGroupBox( 0, Qt::Vertical, i18n( "Preview" ), this, "previewgrp" );
01339 grid->addMultiCellWidget( grp , 0, 7, 1, 1 );
01340 grp->layout()->setSpacing(KDialog::spacingHint());
01341 grp->layout()->setMargin(KDialog::marginHint());
01342 prev3 = new KoBorderPreview( grp );
01343 QVBoxLayout *lay1 = new QVBoxLayout( grp->layout() );
01344 lay1->addWidget(prev3);
01345
01346 connect( prev3, SIGNAL( choosearea(QMouseEvent * ) ),
01347 this, SLOT( slotPressEvent(QMouseEvent *) ) );
01348
01349 grid->setRowStretch( 7, 1 );
01350 grid->setColStretch( 1, 1 );
01351 }
01352
01353 void KoParagBorderWidget::display( const KoParagLayout & lay )
01354 {
01355 m_leftBorder = lay.leftBorder;
01356 m_rightBorder = lay.rightBorder;
01357 m_topBorder = lay.topBorder;
01358 m_bottomBorder = lay.bottomBorder;
01359 bLeft->blockSignals( true );
01360 bRight->blockSignals( true );
01361 bTop->blockSignals( true );
01362 bBottom->blockSignals( true );
01363 updateBorders();
01364 bLeft->blockSignals( false );
01365 bRight->blockSignals( false );
01366 bTop->blockSignals( false );
01367 bBottom->blockSignals( false );
01368 }
01369
01370 void KoParagBorderWidget::save( KoParagLayout & lay )
01371 {
01372 lay.leftBorder = m_leftBorder;
01373 lay.rightBorder = m_rightBorder;
01374 lay.topBorder = m_topBorder;
01375 lay.bottomBorder = m_bottomBorder;
01376 }
01377
01378 #define OFFSETX 15
01379 #define OFFSETY 7
01380 #define Ko_SPACE 30
01381 void KoParagBorderWidget::slotPressEvent(QMouseEvent *_ev)
01382 {
01383 QRect r = prev3->contentsRect();
01384 QRect rect(r.x()+OFFSETX,r.y()+OFFSETY,r.width()-OFFSETX,r.y()+OFFSETY+Ko_SPACE);
01385 if(rect.contains(QPoint(_ev->x(),_ev->y())))
01386 {
01387 if( ( ((int)m_topBorder.penWidth() != cWidth->currentText().toInt()) ||(m_topBorder.color != bColor->color() )
01388 ||(m_topBorder.getStyle()!=KoBorder::getStyle(cStyle->currentText()) )) && bTop->isOn() )
01389 {
01390 m_topBorder.setPenWidth( cWidth->currentText().toInt() );
01391 m_topBorder.color = QColor( bColor->color() );
01392 m_topBorder.setStyle(KoBorder::getStyle(cStyle->currentText()));
01393 prev3->setTopBorder( m_topBorder );
01394 }
01395 else
01396 bTop->setOn(!bTop->isOn());
01397 }
01398 rect.setCoords(r.x()+OFFSETX,r.height()-OFFSETY-Ko_SPACE,r.width()-OFFSETX,r.height()-OFFSETY);
01399 if(rect.contains(QPoint(_ev->x(),_ev->y())))
01400 {
01401 if( ( ((int)m_bottomBorder.penWidth() != cWidth->currentText().toInt()) ||(m_bottomBorder.color != bColor->color() )
01402 ||(m_bottomBorder.getStyle()!=KoBorder::getStyle(cStyle->currentText()) )) && bBottom->isOn() )
01403 {
01404 m_bottomBorder.setPenWidth(cWidth->currentText().toInt());
01405 m_bottomBorder.color = QColor( bColor->color() );
01406 m_bottomBorder.setStyle(KoBorder::getStyle(cStyle->currentText()));
01407 prev3->setBottomBorder( m_bottomBorder );
01408 }
01409 else
01410 bBottom->setOn(!bBottom->isOn());
01411 }
01412
01413 rect.setCoords(r.x()+OFFSETX,r.y()+OFFSETY,r.x()+Ko_SPACE+OFFSETX,r.height()-OFFSETY);
01414 if(rect.contains(QPoint(_ev->x(),_ev->y())))
01415 {
01416
01417 if( ( ((int)m_leftBorder.penWidth() != cWidth->currentText().toInt()) ||(m_leftBorder.color != bColor->color() )
01418 ||(m_leftBorder.getStyle()!=KoBorder::getStyle(cStyle->currentText()) )) && bLeft->isOn() )
01419 {
01420 m_leftBorder.setPenWidth( cWidth->currentText().toInt());
01421 m_leftBorder.color = QColor( bColor->color() );
01422 m_leftBorder.setStyle(KoBorder::getStyle(cStyle->currentText()));
01423 prev3->setLeftBorder( m_leftBorder );
01424 }
01425 else
01426 bLeft->setOn(!bLeft->isOn());
01427 }
01428 rect.setCoords(r.width()-OFFSETX-Ko_SPACE,r.y()+OFFSETY,r.width()-OFFSETX,r.height()-OFFSETY);
01429 if(rect.contains(QPoint(_ev->x(),_ev->y())))
01430 {
01431
01432 if( ( ((int)m_rightBorder.penWidth() != cWidth->currentText().toInt()) ||(m_rightBorder.color != bColor->color() )
01433 ||(m_rightBorder.getStyle()!=KoBorder::getStyle(cStyle->currentText()) )) && bRight->isOn() )
01434 {
01435 m_rightBorder.setPenWidth( cWidth->currentText().toInt());
01436 m_rightBorder.color = bColor->color();
01437 m_rightBorder.setStyle(KoBorder::getStyle(cStyle->currentText()));
01438 prev3->setRightBorder( m_rightBorder );
01439 }
01440 else
01441 bRight->setOn(!bRight->isOn());
01442 }
01443 }
01444 #undef OFFSETX
01445 #undef OFFSETY
01446 #undef Ko_SPACE
01447
01448 void KoParagBorderWidget::updateBorders()
01449 {
01450 bLeft->setOn( m_leftBorder.penWidth() > 0 );
01451 bRight->setOn( m_rightBorder.penWidth() > 0 );
01452 bTop->setOn( m_topBorder.penWidth() > 0 );
01453 bBottom->setOn( m_bottomBorder.penWidth() > 0 );
01454 prev3->setLeftBorder( m_leftBorder );
01455 prev3->setRightBorder( m_rightBorder );
01456 prev3->setTopBorder( m_topBorder );
01457 prev3->setBottomBorder( m_bottomBorder );
01458 }
01459
01460 void KoParagBorderWidget::brdLeftToggled( bool _on )
01461 {
01462 if ( !_on )
01463 m_leftBorder.setPenWidth(0);
01464 else {
01465 m_leftBorder.setPenWidth(cWidth->currentText().toInt());
01466 m_leftBorder.color = bColor->color();
01467 m_leftBorder.setStyle(KoBorder::getStyle( cStyle->currentText() ));
01468 }
01469 prev3->setLeftBorder( m_leftBorder );
01470 }
01471
01472 void KoParagBorderWidget::brdRightToggled( bool _on )
01473 {
01474 if ( !_on )
01475 m_rightBorder.setPenWidth(0);
01476 else {
01477 m_rightBorder.setPenWidth(cWidth->currentText().toInt());
01478 m_rightBorder.color = bColor->color();
01479 m_rightBorder.setStyle( KoBorder::getStyle( cStyle->currentText() ));
01480 }
01481 prev3->setRightBorder( m_rightBorder );
01482 }
01483
01484 void KoParagBorderWidget::brdTopToggled( bool _on )
01485 {
01486 if ( !_on )
01487 m_topBorder.setPenWidth(0);
01488 else {
01489 m_topBorder.setPenWidth(cWidth->currentText().toInt());
01490 m_topBorder.color = bColor->color();
01491 m_topBorder.setStyle(KoBorder::getStyle( cStyle->currentText() ));
01492 }
01493 prev3->setTopBorder( m_topBorder );
01494 }
01495
01496 void KoParagBorderWidget::brdBottomToggled( bool _on )
01497 {
01498 if ( !_on )
01499 m_bottomBorder.setPenWidth ( 0 );
01500 else {
01501 m_bottomBorder.setPenWidth( cWidth->currentText().toInt());
01502 m_bottomBorder.color = bColor->color();
01503 m_bottomBorder.setStyle(KoBorder::getStyle(cStyle->currentText()));
01504 }
01505 prev3->setBottomBorder( m_bottomBorder );
01506 }
01507
01508 QString KoParagBorderWidget::tabName()
01509 {
01510 return i18n( "&Borders" );
01511 }
01512
01513
01514 KoParagCounterWidget::KoParagCounterWidget( bool disableAll, QWidget * parent, const char * name )
01515 : KoParagLayoutWidget( KoParagDia::PD_NUMBERING, parent, name )
01516 {
01517
01518 QVBoxLayout *Form1Layout = new QVBoxLayout( this );
01519 Form1Layout->setSpacing( KDialog::spacingHint() );
01520 Form1Layout->setMargin( KDialog::marginHint() );
01521
01522 gNumbering = new QButtonGroup( this, "numberingGroup" );
01523 gNumbering->setTitle( i18n( "Numbering" ) );
01524 gNumbering->setColumnLayout(0, Qt::Vertical );
01525 gNumbering->layout()->setSpacing( 0 );
01526 gNumbering->layout()->setMargin( 0 );
01527 QHBoxLayout *numberingGroupLayout = new QHBoxLayout( gNumbering->layout() );
01528 numberingGroupLayout->setAlignment( Qt::AlignTop );
01529 numberingGroupLayout->setSpacing( KDialog::spacingHint() );
01530 numberingGroupLayout->setMargin( KDialog::marginHint() );
01531
01532
01533 QRadioButton *rNone = new QRadioButton( gNumbering, "rNone" );
01534 rNone->setText( i18n( "&None" ) );
01535 numberingGroupLayout->addWidget( rNone );
01536
01537 gNumbering->insert( rNone , KoParagCounter::NUM_NONE);
01538
01539 QRadioButton *rList = new QRadioButton( gNumbering, "rList" );
01540 rList->setText( i18n( "&List" ) );
01541 gNumbering->insert( rList , KoParagCounter::NUM_LIST);
01542 numberingGroupLayout->addWidget( rList );
01543
01544 QRadioButton *rChapter = new QRadioButton( gNumbering, "rChapter" );
01545 rChapter->setText( i18n( "Chapt&er" ) );
01546 gNumbering->insert( rChapter , KoParagCounter::NUM_CHAPTER);
01547 numberingGroupLayout->addWidget( rChapter );
01548 Form1Layout->addWidget( gNumbering );
01549 connect( gNumbering, SIGNAL( clicked( int ) ), this, SLOT( numTypeChanged( int ) ) );
01550
01551 m_styleWidget = new KoCounterStyleWidget( true, false, disableAll, this );
01552
01553 connect( m_styleWidget, SIGNAL( sig_suffixChanged (const QString &) ), this, SLOT( suffixChanged(const QString &) ) );
01554 connect( m_styleWidget, SIGNAL( sig_prefixChanged (const QString &) ), this, SLOT( prefixChanged(const QString &) ) );
01555 connect( m_styleWidget, SIGNAL( sig_startChanged(int) ), this, SLOT( startChanged(int) ) );
01556 connect( m_styleWidget, SIGNAL( sig_restartChanged(bool) ), this, SLOT( restartChanged(bool) ) );
01557 connect( m_styleWidget, SIGNAL( sig_depthChanged (int) ), this, SLOT( depthChanged(int) ) );
01558 connect( m_styleWidget, SIGNAL( sig_displayLevelsChanged (int) ), this, SLOT( displayLevelsChanged(int) ) );
01559 connect( m_styleWidget, SIGNAL( sig_alignmentChanged (int) ), this, SLOT( alignmentChanged(int) ) );
01560 connect( m_styleWidget, SIGNAL( changeCustomBullet( const QString & , QChar ) ), this, SLOT( slotChangeCustomBullet( const QString & , QChar ) ) );
01561
01562 connect( m_styleWidget, SIGNAL( sig_numTypeChanged( int ) ), this, SLOT( numTypeChanged(int ) ) );
01563 connect( m_styleWidget, SIGNAL( changeStyle( KoParagCounter::Style ) ), this, SLOT( styleChanged (KoParagCounter::Style ) ) );
01564
01565 Form1Layout->addWidget( m_styleWidget );
01566
01567
01568 preview = new KoStylePreview( i18n( "Preview" ), i18n("Normal paragraph text"), this, "counter preview" );
01569 Form1Layout->addWidget( preview );
01570 if ( disableAll)
01571 {
01572 gNumbering->setEnabled( false);
01573 preview->setEnabled( false );
01574 }
01575
01576 QSpacerItem* spacer = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
01577 Form1Layout->addItem( spacer );
01578 }
01579
01580 void KoParagCounterWidget::styleChanged( KoParagCounter::Style st )
01581 {
01582 m_counter.setStyle( st );
01583 updatePreview();
01584 }
01585
01586 void KoParagCounterWidget::slotChangeCustomBullet( const QString & f, QChar c)
01587 {
01588 m_counter.setCustomBulletFont( f );
01589 m_counter.setCustomBulletCharacter( c );
01590 preview->setCounter( m_counter );
01591 }
01592
01593 QString KoParagCounterWidget::tabName() {
01594 return i18n( "B&ullets/Numbers" );
01595 }
01596
01597 void KoParagCounterWidget::numTypeChanged( int nType ) {
01598
01599 m_counter.setNumbering( static_cast<KoParagCounter::Numbering>( nType ) );
01600 preview->setEnabled( m_counter.numbering() != KoParagCounter::NUM_NONE );
01601 m_styleWidget->numTypeChanged( nType );
01602
01603 updatePreview();
01604 }
01605
01606 void KoParagCounterWidget::display( const KoParagLayout & lay ) {
01607 KoParagCounter::Style style = KoParagCounter::STYLE_NONE;
01608 if ( lay.counter )
01609 {
01610 style=lay.counter->style();
01611 m_counter = *lay.counter;
01612 }
01613 else
01614 {
01615 m_counter = KoParagCounter();
01616 }
01617 gNumbering->setButton( m_counter.numbering() );
01618 preview->setStyle( lay.style );
01619 preview->setCounter( m_counter );
01620 m_styleWidget->display( lay );
01621 }
01622
01623 void KoParagCounterWidget::updatePreview() {
01624 preview->setCounter(m_counter);
01625 preview->repaint(true);
01626 }
01627
01628 void KoParagCounterWidget::save( KoParagLayout & lay ) {
01629
01630
01631
01632
01633
01634 if ( lay.counter )
01635 *lay.counter = m_counter;
01636 else
01637 lay.counter = new KoParagCounter( m_counter );
01638 }
01639
01640 KoTabulatorsLineEdit::KoTabulatorsLineEdit( QWidget * parent, const char * name)
01641 :KDoubleNumInput ( parent, name )
01642 {
01643 setRange( 0, 9999, 1, false);
01644 }
01645
01646 void KoTabulatorsLineEdit::keyPressEvent ( QKeyEvent *ke )
01647 {
01648 if( ke->key() == QKeyEvent::Key_Return ||
01649 ke->key() == QKeyEvent::Key_Enter )
01650 {
01651 emit keyReturnPressed();
01652 return;
01653 }
01654 KDoubleNumInput::keyPressEvent (ke);
01655 }
01656
01657 KoParagTabulatorsWidget::KoParagTabulatorsWidget( KoUnit::Unit unit, double frameWidth,QWidget * parent, const char * name )
01658 : KoParagLayoutWidget( KoParagDia::PD_TABS, parent, name ), m_unit(unit) {
01659 QString length;
01660 if(frameWidth==-1) {
01661 frameWidth=9999;
01662 m_toplimit=9999;
01663 } else {
01664 m_toplimit=frameWidth;
01665 length=i18n("\nFrame width: %1").arg(KoUnit::toUserStringValue(frameWidth,m_unit));
01666 frameWidth=KoUnit::toUserValue(frameWidth,m_unit);
01667 }
01668 QVBoxLayout* Form1Layout = new QVBoxLayout( this );
01669 Form1Layout->setSpacing( KDialog::spacingHint() );
01670 Form1Layout->setMargin( KDialog::marginHint() );
01671
01672 QHBoxLayout* Layout13 = new QHBoxLayout;
01673 Layout13->setSpacing( KDialog::spacingHint() );
01674 Layout13->setMargin( 0 );
01675
01676 lstTabs = new QListBox( this);
01677 lstTabs->insertItem( "mytabvalue" );
01678 lstTabs->setMaximumSize( QSize( 300, 32767 ) );
01679 Layout13->addWidget( lstTabs );
01680
01681 editLayout = new QVBoxLayout;
01682 editLayout->setSpacing( KDialog::spacingHint() );
01683 editLayout->setMargin( 0 );
01684
01685 gPosition = new QGroupBox( this, "gPosition" );
01686 gPosition->setTitle( i18n( "Po&sition" ) );
01687 gPosition->setColumnLayout(0, Qt::Vertical );
01688 gPosition->layout()->setSpacing( 0 );
01689 gPosition->layout()->setMargin( 0 );
01690 QVBoxLayout* GroupBox2Layout = new QVBoxLayout( gPosition->layout() );
01691 GroupBox2Layout->setAlignment( Qt::AlignTop );
01692 GroupBox2Layout->setSpacing( KDialog::spacingHint() );
01693 GroupBox2Layout->setMargin( KDialog::marginHint() );
01694
01695 QHBoxLayout* Layout5 = new QHBoxLayout;
01696 Layout5->setSpacing( KDialog::spacingHint() );
01697 Layout5->setMargin( 0 );
01698
01699 sTabPos = new KoTabulatorsLineEdit( gPosition);
01700 sTabPos->setMaximumSize( QSize( 100, 32767 ) );
01701 Layout5->addWidget( sTabPos );
01702 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
01703 Layout5->addItem( spacer );
01704 GroupBox2Layout->addLayout( Layout5 );
01705 editLayout->addWidget( gPosition );
01706
01707 QLabel* TextLabel1 = new QLabel( gPosition );
01708 QString unitDescription = KoUnit::unitDescription( m_unit );
01709 TextLabel1->setText( i18n( "1 is a unit name", "Tabulator positions are given in %1" ).arg(unitDescription)+length);
01710 GroupBox2Layout->addWidget( TextLabel1 );
01711
01712
01713 bgAlign = new QButtonGroup( this );
01714 bgAlign->setTitle( i18n( "Alignment" ) );
01715 bgAlign->setColumnLayout(0, Qt::Vertical );
01716 bgAlign->layout()->setSpacing( 0 );
01717 bgAlign->layout()->setMargin( 0 );
01718 QVBoxLayout* ButtonGroup1Layout = new QVBoxLayout( bgAlign->layout() );
01719 ButtonGroup1Layout->setAlignment( Qt::AlignTop );
01720 ButtonGroup1Layout->setSpacing( KDialog::spacingHint() );
01721 ButtonGroup1Layout->setMargin( KDialog::marginHint() );
01722
01723 rAlignLeft = new QRadioButton( bgAlign );
01724 rAlignLeft->setText( i18n( "&Left" ) );
01725 ButtonGroup1Layout->addWidget( rAlignLeft );
01726
01727 rAlignCentre = new QRadioButton( bgAlign );
01728 rAlignCentre->setText( i18n( "C&enter" ) );
01729 ButtonGroup1Layout->addWidget( rAlignCentre );
01730
01731 rAlignRight = new QRadioButton( bgAlign );
01732 rAlignRight->setText( i18n( "&Right" ) );
01733 ButtonGroup1Layout->addWidget( rAlignRight );
01734
01735 QHBoxLayout* Layout8 = new QHBoxLayout;
01736 Layout8->setSpacing( KDialog::spacingHint() );
01737 Layout8->setMargin( 0 );
01738
01739 rAlignVar = new QRadioButton( bgAlign );
01740 rAlignVar->setText( i18n( "On followin&g character: " ) );
01741 Layout8->addWidget( rAlignVar );
01742
01743 sAlignChar = new QLineEdit( bgAlign);
01744 sAlignChar->setMaximumSize( QSize( 60, 32767 ) );
01745 sAlignChar->setText(QString(KGlobal::locale()->decimalSymbol()[0]));
01746 Layout8->addWidget( sAlignChar );
01747 QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
01748 Layout8->addItem( spacer_2 );
01749 ButtonGroup1Layout->addLayout( Layout8 );
01750 editLayout->addWidget( bgAlign );
01751
01752 gTabLeader = new QGroupBox( this, "gTabLeader" );
01753 gTabLeader->setTitle( i18n( "Tab Leader" ) );
01754 QVBoxLayout* GroupBox5Layout = new QVBoxLayout( gTabLeader );
01755 GroupBox5Layout->setAlignment( Qt::AlignTop );
01756 GroupBox5Layout->setSpacing( KDialog::spacingHint() );
01757 GroupBox5Layout->setMargin( KDialog::marginHint() );
01758 GroupBox5Layout->addSpacing( fontMetrics().height() / 2 );
01759
01760 QLabel* TextLabel1_2 = new QLabel( gTabLeader );
01761 TextLabel1_2->setText( i18n( "The space a tab uses can be filled with a pattern." ) );
01762 GroupBox5Layout->addWidget( TextLabel1_2 );
01763
01764 QGridLayout *fillingGrid = new QGridLayout( 0L, 2, 2, 0, KDialog::spacingHint() );
01765
01766 QLabel* TextLabel2 = new QLabel( gTabLeader);
01767 TextLabel2->setText( i18n( "&Filling:" ) );
01768 TextLabel2->setAlignment( AlignRight );
01769 fillingGrid->addWidget( TextLabel2, 0, 0 );
01770
01771 cFilling = new QComboBox( FALSE, gTabLeader);
01772 cFilling->insertItem( i18n( "Blank" ) );
01773 cFilling->insertItem( "_ _ _ _ _ _");
01774 cFilling->insertItem( "_________");
01775 cFilling->insertItem( "___ ___ __");
01776 cFilling->insertItem( "___ _ ___ _");
01777 cFilling->insertItem( "___ _ _ ___");
01778 TextLabel2->setBuddy( cFilling );
01779 fillingGrid->addWidget( cFilling, 0, 1 );
01780
01781 QString unitName = KoUnit::unitName( m_unit );
01782 QLabel * TextLabel3 = new QLabel( i18n("&Width (%1):").arg( unitName ), gTabLeader );
01783 TextLabel3->setAlignment( AlignRight );
01784 fillingGrid->addWidget( TextLabel3, 1, 0 );
01785
01786 eWidth = new KDoubleNumInput( gTabLeader );
01787 TextLabel3->setBuddy( eWidth );
01788 fillingGrid->addWidget( eWidth, 1, 1 );
01789
01790 GroupBox5Layout->addLayout( fillingGrid );
01791 editLayout->addWidget( gTabLeader );
01792 QSpacerItem* spacer_4 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
01793 editLayout->addItem( spacer_4 );
01794 Layout13->addLayout( editLayout );
01795 Form1Layout->addLayout( Layout13 );
01796
01797 QHBoxLayout* Layout4 = new QHBoxLayout;
01798 Layout4->setSpacing( KDialog::spacingHint() );
01799 Layout4->setMargin( 0 );
01800
01801 bNew = new QPushButton( this);
01802 bNew->setText( i18n( "&New" ) );
01803 Layout4->addWidget( bNew );
01804
01805 bDelete = new QPushButton( this);
01806 bDelete->setText( i18n( "&Delete" ) );
01807 Layout4->addWidget( bDelete );
01808
01809 bDeleteAll = new QPushButton( this);
01810 bDeleteAll->setText( i18n( "Delete All" ) );
01811 Layout4->addWidget( bDeleteAll );
01812
01813 QSpacerItem* spacer_5 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
01814 Layout4->addItem( spacer_5 );
01815 Form1Layout->addLayout( Layout4 );
01816
01817 connect(sTabPos,SIGNAL(valueChanged(double)), this, SLOT(slotTabValueChanged(double )));
01818 connect(sTabPos,SIGNAL( keyReturnPressed()),this,SLOT(newClicked()));
01819 connect(sAlignChar,SIGNAL(textChanged( const QString & )), this, SLOT(slotAlignCharChanged( const QString & )));
01820 connect(bNew,SIGNAL(clicked ()),this,SLOT(newClicked()));
01821 connect(bDelete,SIGNAL(clicked ()),this,SLOT(deleteClicked()));
01822 connect(bDeleteAll,SIGNAL(clicked ()),this,SLOT(deleteAllClicked()));
01823 connect(bgAlign,SIGNAL(clicked (int)),this,SLOT(updateAlign(int)));
01824 connect(cFilling,SIGNAL(activated (int)),this,SLOT(updateFilling(int)));
01825 connect(eWidth,SIGNAL(valueChanged ( double ) ),this,SLOT(updateWidth()));
01826 connect(lstTabs,SIGNAL(highlighted (int)),this,SLOT(setActiveItem(int)));
01827 noSignals=false;
01828 }
01829
01830 void KoParagTabulatorsWidget::slotTabValueChanged( double val ) {
01831 if(noSignals) return;
01832 noSignals=true;
01833 m_tabList[lstTabs->currentItem()].ptPos = KoUnit::fromUserValue( val, m_unit );
01834 lstTabs->changeItem(tabToString(m_tabList[lstTabs->currentItem()]), lstTabs->currentItem());
01835
01836 sortLists();
01837 noSignals=false;
01838 }
01839
01840 void KoParagTabulatorsWidget::slotAlignCharChanged( const QString & ) {
01841
01842 bgAlign->setButton(3);
01843 m_tabList[lstTabs->currentItem()].alignChar=sAlignChar->text()[0];
01844 m_tabList[lstTabs->currentItem()].type=T_DEC_PNT;
01845 }
01846
01847 void KoParagTabulatorsWidget::newClicked() {
01848 int selected=lstTabs->currentItem();
01849 KoTabulator newTab;
01850 if(selected < 0) {
01851 newTab.ptPos=0;
01852 newTab.type=T_LEFT;
01853 newTab.filling=TF_BLANK;
01854 newTab.ptWidth=0.5;
01855 m_tabList.append(newTab);
01856 lstTabs->insertItem(tabToString(newTab));
01857 lstTabs->setCurrentItem(0);
01858 } else {
01859 double pos = m_tabList[selected].ptPos;
01860 double add=1.0;
01861 if(m_unit==KoUnit::U_INCH)
01862 add=0.1;
01863
01864 pos=pos + KoUnit::fromUserValue( add, m_unit );
01865 if(pos<m_toplimit)
01866 {
01867 newTab.ptPos=pos + KoUnit::fromUserValue( add, m_unit );
01868 newTab.type=m_tabList[selected].type;
01869 newTab.filling=m_tabList[selected].filling;
01870 newTab.ptWidth=m_tabList[selected].ptWidth;
01871 m_tabList.insert(m_tabList.at(selected), newTab);
01872 lstTabs->insertItem( tabToString(newTab), selected);
01873 lstTabs->setCurrentItem(lstTabs->findItem(tabToString(newTab)));
01874 sortLists();
01875 }
01876 }
01877 }
01878
01879 void KoParagTabulatorsWidget::deleteClicked() {
01880 int selected = lstTabs->currentItem();
01881 if (selected < 0) return;
01882 noSignals=true;
01883 sTabPos->setValue(0.0);
01884 noSignals=false;
01885 lstTabs->removeItem(selected);
01886 m_tabList.remove(m_tabList[selected]);
01887 if(lstTabs->count() >0) {
01888 lstTabs->setCurrentItem(QMIN(static_cast<unsigned int>(selected), lstTabs->count()-1 ));
01889 } else {
01890 bDeleteAll->setEnabled(false);
01891 bDelete->setEnabled(false);
01892 gPosition->setEnabled(false);
01893 bgAlign->setEnabled(false);
01894 gTabLeader->setEnabled(false);
01895 }
01896 }
01897
01898 void KoParagTabulatorsWidget::deleteAllClicked()
01899 {
01900 noSignals=true;
01901 sTabPos->setValue(0.0);
01902 noSignals=false;
01903 lstTabs->clear();
01904 m_tabList.clear();
01905 bDeleteAll->setEnabled(false);
01906 bDelete->setEnabled(false);
01907 gPosition->setEnabled(false);
01908 bgAlign->setEnabled(false);
01909 gTabLeader->setEnabled(false);
01910 }
01911
01912 void KoParagTabulatorsWidget::setActiveItem(int selected) {
01913 if(noSignals) return;
01914 if(selected < 0) return;
01915 noSignals=true;
01916 KoTabulator *selectedTab = &m_tabList[selected];
01917 switch( selectedTab->type) {
01918 case T_CENTER:
01919 bgAlign->setButton(1); break;
01920 case T_RIGHT:
01921 bgAlign->setButton(2); break;
01922 case T_DEC_PNT:
01923 bgAlign->setButton(3);
01924 sAlignChar->setText(QString(selectedTab->alignChar));
01925 break;
01926 case T_LEFT:
01927 default:
01928 bgAlign->setButton(0);
01929 }
01930 switch( selectedTab->filling) {
01931 case TF_DOTS:
01932 cFilling->setCurrentItem(1); break;
01933 case TF_LINE:
01934 cFilling->setCurrentItem(2); break;
01935 case TF_DASH:
01936 cFilling->setCurrentItem(3); break;
01937 case TF_DASH_DOT:
01938 cFilling->setCurrentItem(4); break;
01939 case TF_DASH_DOT_DOT:
01940 cFilling->setCurrentItem(5); break;
01941 case TF_BLANK:
01942 default:
01943 cFilling->setCurrentItem(0);
01944 }
01945 eWidth->setValue( KoUnit::toUserValue( selectedTab->ptWidth, m_unit ) );
01946 sTabPos->setValue( KoUnit::toUserValue(selectedTab->ptPos, m_unit));
01947 bDelete->setEnabled(true);
01948 bDeleteAll->setEnabled(true);
01949 gPosition->setEnabled(true);
01950 bgAlign->setEnabled(true);
01951 gTabLeader->setEnabled(true);
01952 noSignals=false;
01953 }
01954
01955 void KoParagTabulatorsWidget::setCurrentTab( double tabPos ) {
01956 KoTabulatorList::ConstIterator it = m_tabList.begin();
01957 for ( int i = 0; it != m_tabList.end(); ++it, ++i )
01958 if ( (*it).ptPos == tabPos ) {
01959 lstTabs->setCurrentItem(i);
01960 setActiveItem( i );
01961 return;
01962 }
01963 kdWarning() << "KoParagTabulatorsWidget::setCurrentTab: no tab found at pos=" << tabPos << endl;
01964 }
01965
01966 QString KoParagTabulatorsWidget::tabToString(const KoTabulator &tab) {
01967 return KoUnit::toUserStringValue( tab.ptPos, m_unit);
01968 }
01969
01970 void KoParagTabulatorsWidget::updateAlign(int selected) {
01971 KoTabulator *selectedTab = &m_tabList[lstTabs->currentItem()];
01972
01973 switch( selected) {
01974 case 1:
01975 selectedTab->type=T_CENTER; break;
01976 case 2:
01977 selectedTab->type=T_RIGHT; break;
01978 case 3:
01979 selectedTab->type=T_DEC_PNT;
01980 selectedTab->alignChar=sAlignChar->text()[0];
01981 break;
01982 case 0:
01983 default:
01984 selectedTab->type=T_LEFT;
01985 }
01986 }
01987
01988 void KoParagTabulatorsWidget::updateFilling(int selected) {
01989 KoTabulator *selectedTab = &m_tabList[lstTabs->currentItem()];
01990
01991 switch( selected) {
01992 case 1:
01993 selectedTab->filling=TF_DOTS; break;
01994 case 2:
01995 selectedTab->filling=TF_LINE; break;
01996 case 3:
01997 selectedTab->filling=TF_DASH; break;
01998 case 4:
01999 selectedTab->filling=TF_DASH_DOT; break;
02000 case 5:
02001 selectedTab->filling=TF_DASH_DOT_DOT; break;
02002 case 0:
02003 default:
02004 selectedTab->filling=TF_BLANK;
02005 }
02006 }
02007
02008 void KoParagTabulatorsWidget::updateWidth() {
02009 KoTabulator *selectedTab = &m_tabList[lstTabs->currentItem()];
02010 selectedTab->ptWidth = QMAX( 0, KoUnit::fromUserValue( eWidth->value(), m_unit ) );
02011 }
02012
02013 void KoParagTabulatorsWidget::sortLists() {
02014
02015 noSignals=true;
02016 qHeapSort( m_tabList );
02017
02018
02019
02020 QString curValue=lstTabs->currentText();
02021 lstTabs->clear();
02022 KoTabulatorList::ConstIterator it = m_tabList.begin();
02023 for ( ; it != m_tabList.end(); ++it )
02024 lstTabs->insertItem( KoUnit::toUserStringValue( (*it).ptPos, m_unit ) );
02025
02026 lstTabs->setCurrentItem(lstTabs->findItem(curValue));
02027 noSignals=false;
02028 }
02029
02030 void KoParagTabulatorsWidget::display( const KoParagLayout &lay ) {
02031 m_tabList.clear();
02032 lstTabs->clear();
02033 m_tabList = lay.tabList();
02034 KoTabulatorList::ConstIterator it = m_tabList.begin();
02035 for ( ; it != m_tabList.end(); ++it )
02036 lstTabs->insertItem( KoUnit::toUserStringValue( (*it).ptPos, m_unit ) );
02037
02038 if(lstTabs->count() > 0)
02039 lstTabs->setCurrentItem(0);
02040 else {
02041 bDelete->setEnabled(false);
02042 bDeleteAll->setEnabled(false);
02043 gPosition->setEnabled(false);
02044 bgAlign->setEnabled(false);
02045 gTabLeader->setEnabled(false);
02046 }
02047 }
02048
02049 void KoParagTabulatorsWidget::save( KoParagLayout & lay ) {
02050 lay.setTabList( m_tabList );
02051 }
02052
02053 QString KoParagTabulatorsWidget::tabName() {
02054 return i18n( "&Tabulators" );
02055 }
02056
02057
02058
02059
02060 KoParagDia::KoParagDia( QWidget* parent, const char* name,
02061 int flags, KoUnit::Unit unit, double _frameWidth, bool breakLine, bool disableAll )
02062 : KDialogBase(Tabbed, QString::null, Ok | Cancel | User1 | Apply, Ok, parent, name, true )
02063 {
02064 m_flags = flags;
02065 setButtonText( KDialogBase::User1, i18n("Reset") );
02066
02067 if ( m_flags & PD_SPACING )
02068 {
02069 QVBox * page = addVBoxPage( i18n( "Indent && S&pacing" ) );
02070 m_indentSpacingWidget = new KoIndentSpacingWidget( unit,_frameWidth,page, "indent-spacing" );
02071 }
02072 if ( m_flags & PD_ALIGN )
02073 {
02074 QVBox * page = addVBoxPage( i18n( "General &Layout" ) );
02075 m_alignWidget = new KoParagAlignWidget( breakLine, page, "align" );
02076 }
02077 if ( m_flags & PD_BORDERS )
02078 {
02079 QVBox * page = addVBoxPage( i18n( "&Borders" ) );
02080 m_borderWidget = new KoParagBorderWidget( page, "border" );
02081 }
02082 if ( m_flags & PD_NUMBERING )
02083 {
02084 QVBox * page = addVBoxPage( i18n( "B&ullets/Numbers" ) );
02085 m_counterWidget = new KoParagCounterWidget( disableAll , page, "numbers" );
02086 }
02087 if ( m_flags & PD_TABS )
02088 {
02089 QVBox * page = addVBoxPage( i18n( "&Tabulators" ) );
02090 m_tabulatorsWidget = new KoParagTabulatorsWidget( unit,_frameWidth, page, "tabs");
02091 }
02092
02093 connect( this, SIGNAL( user1Clicked() ), this, SLOT(slotReset()));
02094 setInitialSize( QSize(630, 500) );
02095 }
02096
02097 KoParagDia::~KoParagDia()
02098 {
02099 }
02100
02101 void KoParagDia::slotApply()
02102 {
02103 emit applyParagStyle();
02104 }
02105
02106 void KoParagDia::slotOk()
02107 {
02108 slotApply();
02109 KDialogBase::slotOk();
02110 }
02111
02112 void KoParagDia::setCurrentPage( int page )
02113 {
02114 switch( page )
02115 {
02116 case PD_SPACING:
02117 showPage( pageIndex( m_indentSpacingWidget->parentWidget() ) );
02118 break;
02119 case PD_ALIGN:
02120 showPage( pageIndex( m_alignWidget->parentWidget() ) );
02121 break;
02122 case PD_BORDERS:
02123 showPage( pageIndex( m_borderWidget->parentWidget() ) );
02124 break;
02125 case PD_NUMBERING:
02126 showPage( pageIndex( m_counterWidget->parentWidget() ) );
02127 break;
02128 case PD_TABS:
02129 showPage( pageIndex( m_tabulatorsWidget->parentWidget() ) );
02130 break;
02131 default:
02132 break;
02133 }
02134 }
02135
02136 void KoParagDia::setParagLayout( const KoParagLayout & lay )
02137 {
02138 m_indentSpacingWidget->display( lay );
02139 m_alignWidget->display( lay );
02140 m_borderWidget->display( lay );
02141 m_counterWidget->display( lay );
02142 m_tabulatorsWidget->display( lay );
02143 oldLayout = lay;
02144 }
02145
02146 void KoParagDia::slotReset()
02147 {
02148 if( m_indentSpacingWidget )
02149 m_indentSpacingWidget->display( oldLayout );
02150 if( m_alignWidget )
02151 m_alignWidget->display( oldLayout );
02152 if( m_borderWidget )
02153 m_borderWidget->display( oldLayout );
02154 if( m_counterWidget )
02155 m_counterWidget->display( oldLayout );
02156 if( m_tabulatorsWidget )
02157 m_tabulatorsWidget->display( oldLayout );
02158 }
02159
02160 bool KoParagDia::isCounterChanged() const
02161 {
02162 if ( oldLayout.counter )
02163 return ! ( *oldLayout.counter == counter() );
02164 else
02165 return counter().numbering() != KoParagCounter::NUM_NONE;
02166 }
02167
02168 int KoParagDia::changedFlags() const
02169 {
02170 return paragLayout().compare( oldLayout );
02171 }
02172
02173 KoParagLayout KoParagDia::paragLayout() const
02174 {
02175 KoParagLayout newLayout;
02176 newLayout.setLineSpacingValue( lineSpacing() );
02177 newLayout.lineSpacingType = lineSpacingType();
02178 newLayout.setTabList( tabListTabulator() );
02179 newLayout.alignment = align();
02180 newLayout.margins[QStyleSheetItem::MarginFirstLine] = firstLineIndent();
02181 newLayout.margins[QStyleSheetItem::MarginLeft] = leftIndent();
02182 newLayout.margins[QStyleSheetItem::MarginRight] = rightIndent();
02183 newLayout.margins[QStyleSheetItem::MarginTop] = spaceBeforeParag();
02184 newLayout.margins[QStyleSheetItem::MarginBottom] = spaceAfterParag();
02185 newLayout.pageBreaking = pageBreaking();
02186 newLayout.leftBorder = leftBorder();
02187 newLayout.rightBorder = rightBorder();
02188 newLayout.topBorder = topBorder();
02189 newLayout.bottomBorder = bottomBorder();
02190 newLayout.counter = new KoParagCounter( counter() );
02191 return newLayout;
02192 }
02193
02194 #include "koParagDia.moc"
02195 #include "koParagDia_p.moc"