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