00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "koFontDia_p.h"
00021 #include "koFontDia.h"
00022 #include "korichtext.h"
00023
00024 #include <kcolordialog.h>
00025 #include <klocale.h>
00026 #include <kdebug.h>
00027
00028 #include <qgroupbox.h>
00029 #include <qpushbutton.h>
00030 #include <qtabwidget.h>
00031 #include <qlabel.h>
00032 #include <qcombobox.h>
00033 #include <qradiobutton.h>
00034 #include <qcheckbox.h>
00035 #include <knuminput.h>
00036 #include <koGlobal.h>
00037 #include <qvgroupbox.h>
00038 #include <qvbox.h>
00039 #include <qhgroupbox.h>
00040 #include <qhbuttongroup.h>
00041 #include <kcolorbutton.h>
00042 #include <kiconloader.h>
00043
00044 KoShadowPreview::KoShadowPreview( QWidget* parent, const char* name )
00045 : QFrame( parent, name )
00046 {
00047 setFrameStyle( WinPanel | Sunken );
00048 setBackgroundColor( white );
00049 }
00050
00051 void KoShadowPreview::drawContents( QPainter* painter )
00052 {
00053 QFont font(KoGlobal::defaultFont().family(), 30, QFont::Bold);
00054 QFontMetrics fm( font );
00055
00056 QString text = "KOffice";
00057 QRect br = fm.boundingRect( text );
00058 int x = ( width() - br.width() ) / 2;
00059 int y = ( height() - br.height() ) / 2 + br.height();
00060 painter->save();
00061
00062 int sx = x + qRound(shadowDistanceX);
00063 int sy = y + qRound(shadowDistanceY);
00064
00065 painter->setFont( font );
00066 painter->setPen( shadowColor );
00067 painter->drawText( sx, sy, text );
00068
00069 painter->setPen( blue );
00070 painter->drawText( x, y, text );
00071
00072 painter->restore();
00073 }
00074
00075 KoTextShadowWidget::KoTextShadowWidget( QWidget * parent, const char * name )
00076 : QWidget( parent, name )
00077 {
00078 QGridLayout *grid = new QGridLayout( this, 8, 2, KDialog::marginHint(), KDialog::spacingHint() );
00079
00080 QGroupBox *shadowBox = new QGroupBox( i18n( "Shadow" ), this, "shadow" );
00081 grid->addMultiCellWidget( shadowBox, 0, 3,0,0 );
00082
00083 QGridLayout *grid2 = new QGridLayout( shadowBox, 4, 2, 2*KDialog::marginHint(), 2*KDialog::spacingHint() );
00084
00085 QLabel *lcolor = new QLabel( i18n( "Co&lor:" ), shadowBox );
00086 grid2->addWidget(lcolor,0,0);
00087 color = new KColorButton( black,
00088 black,
00089 shadowBox );
00090 lcolor->setBuddy( color );
00091 grid2->addWidget(color,1,0);
00092 connect( color, SIGNAL( changed( const QColor& ) ), this, SLOT( colorChanged( const QColor& ) ) );
00093
00094 QLabel *ldistance = new QLabel( i18n( "&Distance (pt):" ), shadowBox );
00095 grid2->addWidget(ldistance,2,0);
00096
00097 distance = new QSpinBox( 0, 20, 1, shadowBox );
00098 distance->setSuffix(i18n("pt"));
00099 ldistance->setBuddy( distance );
00100 connect( distance, SIGNAL( valueChanged( int ) ), this, SLOT( distanceChanged( int ) ) );
00101 grid2->addWidget(distance,3,0);
00102
00103 QLabel *ldirection = new QLabel( i18n( "Di&rection:" ), shadowBox );
00104 grid2->addWidget(ldirection,0,1);
00105
00106 QGridLayout *grid3 = new QGridLayout( 0L, 3, 3, KDialog::marginHint(), KDialog::spacingHint() );
00107
00108 lu = new QPushButton( shadowBox );
00109 grid3->addWidget(lu,0,0);
00110 lu->setToggleButton( true );
00111 ldirection->setBuddy( lu );
00112 u = new QPushButton( shadowBox );
00113 grid3->addWidget(u,0,1);
00114 u->setToggleButton( true );
00115 ru = new QPushButton( shadowBox );
00116 grid3->addWidget(ru,0,2);
00117 ru->setToggleButton( true );
00118 r = new QPushButton( shadowBox );
00119 grid3->addWidget(r,1,2);
00120 r->setToggleButton( true );
00121 rb = new QPushButton( shadowBox );
00122 grid3->addWidget(rb,2,2);
00123 rb->setToggleButton( true );
00124 b = new QPushButton( shadowBox );
00125 grid3->addWidget(b,2,1);
00126 b->setToggleButton( true );
00127 lb = new QPushButton( shadowBox );
00128 grid3->addWidget(lb,2,0);
00129 lb->setToggleButton( true );
00130 l = new QPushButton( shadowBox );
00131 grid3->addWidget(l,1,0);
00132 l->setToggleButton( true );
00133
00134 lu->setPixmap( BarIcon( "shadowLU" ) );
00135 u->setPixmap( BarIcon( "shadowU" ) );
00136 ru->setPixmap( BarIcon( "shadowRU" ) );
00137 r->setPixmap( BarIcon( "shadowR" ) );
00138 rb->setPixmap( BarIcon( "shadowRB" ) );
00139 b->setPixmap( BarIcon( "shadowB" ) );
00140 lb->setPixmap( BarIcon( "shadowLB" ) );
00141 l->setPixmap( BarIcon( "shadowL" ) );
00142
00143 connect( lu, SIGNAL( clicked() ), this, SLOT( luChanged() ) );
00144 connect( u, SIGNAL( clicked() ), this, SLOT( uChanged() ) );
00145 connect( ru, SIGNAL( clicked() ), this, SLOT( ruChanged() ) );
00146 connect( r, SIGNAL( clicked() ), this, SLOT( rChanged() ) );
00147 connect( rb, SIGNAL( clicked() ), this, SLOT( rbChanged() ) );
00148 connect( b, SIGNAL( clicked() ), this, SLOT( bChanged() ) );
00149 connect( lb, SIGNAL( clicked() ), this, SLOT( lbChanged() ) );
00150 connect( l, SIGNAL( clicked() ), this, SLOT( lChanged() ) );
00151
00152
00153 grid2->addMultiCellLayout (grid3, 1,3, 1, 1 );
00154
00155 m_shadowPreview = new KoShadowPreview( this, "preview" );
00156 grid->addMultiCellWidget( m_shadowPreview, 0, 3, 1, 1 );
00157 }
00158
00159 void KoTextShadowWidget::setShadowDirection( short int sd )
00160 {
00161 m_shadowDirection = sd;
00162 m_shadowPreview->setShadowDistanceX( shadowDistanceX() );
00163 m_shadowPreview->setShadowDistanceY( shadowDistanceY() );
00164
00165 lu->setOn( false );
00166 u->setOn( false );
00167 ru->setOn( false );
00168 r->setOn( false );
00169 rb->setOn( false );
00170 b->setOn( false );
00171 lb->setOn( false );
00172 l->setOn( false );
00173
00174 switch ( m_shadowDirection )
00175 {
00176 case SD_LEFT_UP:
00177 lu->setOn( true );
00178 break;
00179 case SD_UP:
00180 u->setOn( true );
00181 break;
00182 case SD_RIGHT_UP:
00183 ru->setOn( true );
00184 break;
00185 case SD_RIGHT:
00186 r->setOn( true );
00187 break;
00188 case SD_RIGHT_BOTTOM:
00189 rb->setOn( true );
00190 break;
00191 case SD_BOTTOM:
00192 b->setOn( true );
00193 break;
00194 case SD_LEFT_BOTTOM:
00195 lb->setOn( true );
00196 break;
00197 case SD_LEFT:
00198 l->setOn( true );
00199 break;
00200 }
00201 }
00202
00203 void KoTextShadowWidget::setShadow( double shadowDistanceX, double shadowDistanceY, const QColor& shadowColor )
00204 {
00205
00206
00207 m_shadowDirection = SD_RIGHT_BOTTOM;
00208 if ( shadowDistanceX > 0 )
00209 if ( shadowDistanceY == 0 )
00210 m_shadowDirection = SD_RIGHT;
00211 else
00212 m_shadowDirection = shadowDistanceY > 0 ? SD_RIGHT_BOTTOM : SD_RIGHT_UP;
00213 else if ( shadowDistanceX == 0 )
00214 m_shadowDirection = shadowDistanceY > 0 ? SD_BOTTOM : SD_UP;
00215 else
00216 if ( shadowDistanceY == 0 )
00217 m_shadowDirection = SD_LEFT;
00218 else
00219 m_shadowDirection = shadowDistanceY > 0 ? SD_LEFT_BOTTOM : SD_LEFT_UP;
00220
00221 m_shadowDistance = QMAX( QABS(shadowDistanceX), QABS(shadowDistanceY) );
00222 m_shadowPreview->setShadowDistanceX( shadowDistanceX );
00223 m_shadowPreview->setShadowDistanceY( shadowDistanceY );
00224
00225 distance->setValue( (int)m_shadowDistance );
00226
00227 m_shadowColor = shadowColor;
00228 m_shadowPreview->setShadowColor( m_shadowColor );
00229 color->setColor( m_shadowColor.isValid() ? m_shadowColor: gray );
00230 }
00231
00232 void KoTextShadowWidget::luChanged()
00233 {
00234 setShadowDirection( SD_LEFT_UP );
00235 }
00236
00237 void KoTextShadowWidget::uChanged()
00238 {
00239 setShadowDirection( SD_UP );
00240 }
00241
00242 void KoTextShadowWidget::ruChanged()
00243 {
00244 setShadowDirection( SD_RIGHT_UP );
00245 }
00246
00247 void KoTextShadowWidget::rChanged()
00248 {
00249 setShadowDirection( SD_RIGHT );
00250 }
00251
00252 void KoTextShadowWidget::rbChanged()
00253 {
00254 setShadowDirection( SD_RIGHT_BOTTOM );
00255 }
00256
00257 void KoTextShadowWidget::bChanged()
00258 {
00259 setShadowDirection( SD_BOTTOM );
00260 }
00261
00262 void KoTextShadowWidget::lbChanged()
00263 {
00264 setShadowDirection( SD_LEFT_BOTTOM );
00265 }
00266
00267 void KoTextShadowWidget::lChanged()
00268 {
00269 setShadowDirection( SD_LEFT );
00270 }
00271
00272 void KoTextShadowWidget::colorChanged( const QColor& col )
00273 {
00274 m_shadowColor = col;
00275 m_shadowPreview->setShadowColor( col );
00276 emit changed();
00277 }
00278
00279 void KoTextShadowWidget::distanceChanged( int _val )
00280 {
00281 m_shadowDistance = _val;
00282 m_shadowPreview->setShadowDistanceX( shadowDistanceX() );
00283 m_shadowPreview->setShadowDistanceY( shadowDistanceY() );
00284 emit changed();
00285 }
00286
00287 QString KoTextShadowWidget::tabName() {
00288 return i18n( "S&hadow" );
00289 }
00290
00291 double KoTextShadowWidget::shadowDistanceX() const
00292 {
00293 switch ( m_shadowDirection )
00294 {
00295 case SD_LEFT_BOTTOM:
00296 case SD_LEFT:
00297 case SD_LEFT_UP:
00298 return - m_shadowDistance;
00299 case SD_UP:
00300 case SD_BOTTOM:
00301 return 0;
00302 case SD_RIGHT_UP:
00303 case SD_RIGHT:
00304 case SD_RIGHT_BOTTOM:
00305 return m_shadowDistance;
00306 }
00307 return 0;
00308 }
00309
00310 double KoTextShadowWidget::shadowDistanceY() const
00311 {
00312 switch ( m_shadowDirection )
00313 {
00314 case SD_LEFT_UP:
00315 case SD_UP:
00316 case SD_RIGHT_UP:
00317 return - m_shadowDistance;
00318 case SD_LEFT:
00319 case SD_RIGHT:
00320 return 0;
00321 case SD_LEFT_BOTTOM:
00322 case SD_BOTTOM:
00323 case SD_RIGHT_BOTTOM:
00324 return m_shadowDistance;
00325 }
00326 return 0;
00327 }
00328
00329 class KoFontChooser::KoFontChooserPrivate
00330 {
00331 public:
00332 QComboBox *m_strikeOut;
00333 QColor m_textColor;
00334 KoTextShadowWidget *m_shadowWidget;
00335 KIntNumInput *m_relativeSize;
00336 QLabel *m_lRelativeSize;
00337 KIntNumInput *m_offsetBaseLine;
00338 QCheckBox *m_wordByWord;
00339 #ifdef ATTRCOMBO
00340 QComboBox *m_fontAttribute;
00341 #else
00342 QButtonGroup* m_fontAttribute;
00343 #endif
00344 QComboBox *m_language;
00345 QCheckBox *m_hyphenation;
00346 };
00347
00348 KoFontChooser::KoFontChooser( QWidget* parent, const char* name, bool _withSubSuperScript, uint fontListCriteria)
00349 : QTabWidget( parent, name )
00350 {
00351 d = new KoFontChooserPrivate;
00352 setupTab1(_withSubSuperScript, fontListCriteria );
00353 setupTab2();
00354
00355 d->m_shadowWidget = new KoTextShadowWidget( this );
00356 connect( d->m_shadowWidget, SIGNAL(changed()), this, SLOT(slotShadowChanged()) );
00357 addTab( d->m_shadowWidget, d->m_shadowWidget->tabName() );
00358 m_changedFlags = 0;
00359 }
00360
00361 KoFontChooser::~KoFontChooser()
00362 {
00363 delete d; d = 0;
00364 }
00365
00366 QColor KoFontChooser::color() const
00367 {
00368 return d->m_textColor;
00369 }
00370
00371 void KoFontChooser::setupTab1(bool _withSubSuperScript, uint fontListCriteria )
00372 {
00373 QWidget *page = new QWidget( this );
00374 addTab( page, i18n( "&Fonts" ) );
00375 QVBoxLayout *lay1 = new QVBoxLayout( page, KDialog::marginHint(), KDialog::spacingHint() );
00376 QStringList list;
00377 KFontChooser::getFontList(list,fontListCriteria);
00378 m_chooseFont = new KFontChooser(page, "FontList", false, list);
00379 lay1->addWidget(m_chooseFont);
00380
00381 QVGroupBox *grp = new QVGroupBox(i18n("Position"), page);
00382 lay1->addWidget(grp);
00383 QWidget* grpBox = new QWidget( grp );
00384 QGridLayout *grid = new QGridLayout( grpBox, 2, 3, 0, KDialog::spacingHint() );
00385 grid->setColStretch( 1, 1 );
00386
00387
00388
00389 m_superScript = new QCheckBox(i18n("Su&perscript"),grpBox);
00390 grid->addWidget(m_superScript,0,0);
00391
00392 m_subScript = new QCheckBox(i18n("Su&bscript"),grpBox);
00393 grid->addWidget(m_subScript,1,0);
00394
00395 d->m_lRelativeSize = new QLabel ( i18n("Relative &size:"), grpBox);
00396 d->m_lRelativeSize->setAlignment( Qt::AlignRight );
00397 grid->addWidget(d->m_lRelativeSize,0,1);
00398
00399
00400 d->m_relativeSize = new KIntNumInput( grpBox );
00401 d->m_lRelativeSize->setBuddy( d->m_relativeSize );
00402 grid->addWidget(d->m_relativeSize,0,2);
00403
00404 d->m_relativeSize-> setRange(1, 100, 1,false);
00405 d->m_relativeSize->setSuffix("%");
00406
00407 QLabel *lab = new QLabel ( i18n("Offse&t from baseline:"), grpBox);
00408 lab->setAlignment( Qt::AlignRight );
00409 grid->addWidget(lab,1,1);
00410
00411 d->m_offsetBaseLine= new KIntNumInput( grpBox );
00412 lab->setBuddy( d->m_offsetBaseLine );
00413 grid->addWidget(d->m_offsetBaseLine,1,2);
00414
00415 d->m_offsetBaseLine->setRange(-9, 9, 1,false);
00416 d->m_offsetBaseLine->setSuffix("pt");
00417
00418 if(!_withSubSuperScript)
00419 {
00420 m_subScript->setEnabled(false);
00421 m_superScript->setEnabled(false);
00422 d->m_relativeSize->setEnabled( false );
00423 d->m_lRelativeSize->setEnabled( false );
00424 }
00425
00426 QHGroupBox* colorsGrp = new QHGroupBox(i18n("Colors"), page);
00427 lay1->addWidget(colorsGrp);
00428
00429 m_colorButton = new QPushButton( i18n( "Change Co&lor..." ), colorsGrp );
00430
00431
00432 m_backGroundColorButton = new QPushButton( i18n( "Change Bac&kground Color..." ), colorsGrp );
00433
00434
00435 connect( m_subScript, SIGNAL(clicked()), this, SLOT( slotSubScriptClicked() ) );
00436 connect( m_superScript, SIGNAL(clicked()), this, SLOT( slotSuperScriptClicked() ) );
00437 connect( m_colorButton, SIGNAL(clicked()), this, SLOT( slotChangeColor() ) );
00438
00439 connect( m_backGroundColorButton, SIGNAL(clicked()), this, SLOT( slotChangeBackGroundColor() ) );
00440
00441 connect( m_chooseFont, SIGNAL( fontSelected( const QFont & )),
00442 this, SLOT( slotFontChanged(const QFont &) ) );
00443
00444 connect( d->m_relativeSize, SIGNAL( valueChanged(int) ), this, SLOT( slotRelativeSizeChanged( int )));
00445 connect( d->m_offsetBaseLine, SIGNAL( valueChanged(int) ), this, SLOT( slotOffsetFromBaseLineChanged( int )));
00446
00447 updatePositionButton();
00448
00449 }
00450
00451 void KoFontChooser::setupTab2()
00452 {
00453 QWidget *page = new QWidget( this );
00454 addTab( page, i18n( "Font &Effects" ) );
00455
00456
00457
00458
00459
00460 QWidget* grp = page;
00461
00462 QGridLayout *grid = new QGridLayout( grp, 10, 2, KDialog::marginHint(), KDialog::spacingHint() );
00463
00464 QLabel * lab = new QLabel( i18n("&Underlining:"), grp);
00465 grid->addWidget( lab, 0, 0);
00466
00467 m_underlining = new QComboBox( grp );
00468 lab->setBuddy( m_underlining );
00469 grid->addWidget( m_underlining, 1, 0);
00470
00471 m_underlining->insertStringList( KoTextFormat::underlineTypeList() );
00472
00473 m_underlineType = new QComboBox(grp );
00474 grid->addWidget( m_underlineType, 1, 1);
00475 m_underlineType->insertStringList( KoTextFormat::underlineStyleList() );
00476
00477
00478 m_underlineColorButton = new QPushButton( i18n( "Change Co&lor..." ), grp );
00479 grid->addWidget(m_underlineColorButton,1,2);
00480
00481
00482 QLabel * lab2 = new QLabel( i18n("&Strikethrough:"), grp);
00483 grid->addWidget( lab2, 2, 0);
00484 d->m_strikeOut = new QComboBox( grp );
00485 lab2->setBuddy( d->m_strikeOut );
00486 grid->addWidget( d->m_strikeOut, 3, 0);
00487 d->m_strikeOut->insertStringList( KoTextFormat::strikeOutTypeList() );
00488
00489
00490 m_strikeOutType= new QComboBox(grp );
00491 grid->addWidget( m_strikeOutType, 3, 1);
00492 m_strikeOutType->insertStringList( KoTextFormat::strikeOutStyleList() );
00493
00494 d->m_wordByWord = new QCheckBox( i18n("&Word by word"), grp);
00495 grid->addWidget( d->m_wordByWord, 5, 0);
00496
00497 #ifdef ATTRCOMBO
00498 QLabel * lab3 = new QLabel( i18n("A&ttribute:"), grp);
00499 grid->addWidget( lab3, 6, 0);
00500
00501 d->m_fontAttribute = new QComboBox( grp );
00502 lab3->setBuddy( d->m_fontAttribute );
00503 grid->addWidget( d->m_fontAttribute, 7, 0);
00504
00505 d->m_fontAttribute->insertStringList( KoTextFormat::fontAttributeList() );
00506 connect( d->m_fontAttribute, SIGNAL( activated( int ) ), this, SLOT( slotChangeAttributeFont( int )));
00507 #else
00508 d->m_fontAttribute = new QHButtonGroup( i18n("Capitalization"), grp );
00509 grid->addMultiCellWidget( d->m_fontAttribute, 6, 6, 0, grid->numCols()-1 );
00510 QStringList fontAttributes = KoTextFormat::fontAttributeList();
00511 for( QStringList::Iterator it = fontAttributes.begin(); it != fontAttributes.end(); ++it ) {
00512 (void) new QRadioButton( *it, d->m_fontAttribute );
00513 }
00514 connect( d->m_fontAttribute, SIGNAL( clicked( int ) ), this, SLOT( slotChangeAttributeFont( int )));
00515 #endif
00516
00517 QLabel * lab4 = new QLabel( i18n("La&nguage:"), grp);
00518 grid->addWidget( lab4, 8, 0);
00519
00520 d->m_language = new QComboBox( grp );
00521 d->m_language->insertStringList( KoGlobal::listOfLanguages() );
00522 lab4->setBuddy( d->m_language );
00523 grid->addWidget( d->m_language, 9, 0 );
00524
00525 d->m_hyphenation = new QCheckBox( i18n("Auto h&yphenation"), grp );
00526 grid->addWidget( d->m_hyphenation, 10, 0 );
00527
00528
00529 grid->expand( grid->numRows() + 1, grid->numCols() );
00530 grid->setRowStretch( grid->numRows(), 1 );
00531
00532 connect( d->m_strikeOut, SIGNAL(activated ( int )), this, SLOT( slotStrikeOutTypeChanged( int ) ) );
00533 connect( m_underlineColorButton, SIGNAL(clicked()), this, SLOT( slotUnderlineColor() ) );
00534 connect( m_underlining, SIGNAL( activated ( int ) ), this, SLOT( slotChangeUnderlining( int )));
00535 connect( m_strikeOutType, SIGNAL( activated ( int ) ), this, SLOT( slotChangeStrikeOutType( int )));
00536 connect( m_underlineType, SIGNAL( activated ( int ) ), this, SLOT( slotChangeUnderlineType( int )));
00537 connect( d->m_wordByWord, SIGNAL(clicked()), this, SLOT( slotWordByWordClicked() ) );
00538 connect( d->m_language, SIGNAL( activated ( int ) ), this, SLOT( slotChangeLanguage( int )));
00539 connect( d->m_hyphenation, SIGNAL( clicked()), this, SLOT( slotHyphenationClicked()));
00540 }
00541
00542 void KoFontChooser::updatePositionButton()
00543 {
00544 bool state = (m_superScript->isChecked() || m_subScript->isChecked());
00545 d->m_relativeSize->setEnabled( state );
00546 d->m_lRelativeSize->setEnabled( state );
00547 }
00548
00549 void KoFontChooser::setLanguage( const QString & _tag)
00550 {
00551 d->m_language->setCurrentItem (KoGlobal::languageIndexFromTag( _tag));
00552 }
00553
00554 QString KoFontChooser::language() const
00555 {
00556 return KoGlobal::tagOfLanguage( d->m_language->currentText() );
00557 }
00558
00559 KoTextFormat::AttributeStyle KoFontChooser::fontAttribute()const
00560 {
00561 #ifdef ATTRCOMBO
00562 int currentItem = d->m_fontAttribute->currentItem ();
00563 #else
00564 int currentItem = 0;
00565 for ( int i = 0; i < d->m_fontAttribute->count(); ++i )
00566 {
00567 if ( d->m_fontAttribute->find( i )->isOn() )
00568 {
00569 currentItem = i;
00570 break;
00571 }
00572 }
00573 #endif
00574 switch ( currentItem )
00575 {
00576 case 0:
00577 return KoTextFormat::ATT_NONE;
00578 break;
00579 case 1:
00580 return KoTextFormat::ATT_UPPER;
00581 break;
00582 case 2:
00583 return KoTextFormat::ATT_LOWER;
00584 break;
00585 case 3:
00586 return KoTextFormat::ATT_SMALL_CAPS;
00587 break;
00588 default:
00589 return KoTextFormat::ATT_NONE;
00590 }
00591 }
00592
00593 void KoFontChooser::setFontAttribute( KoTextFormat::AttributeStyle _att)
00594 {
00595 int currentItem = 0;
00596 if ( _att == KoTextFormat::ATT_NONE)
00597 currentItem = 0;
00598 else if ( _att == KoTextFormat::ATT_UPPER)
00599 currentItem = 1;
00600 else if ( _att == KoTextFormat::ATT_LOWER )
00601 currentItem = 2;
00602 else if ( _att == KoTextFormat::ATT_SMALL_CAPS )
00603 currentItem = 3;
00604 #ifdef ATTRCOMBO
00605 d->m_fontAttribute->setCurrentItem( currentItem );
00606 #else
00607 d->m_fontAttribute->setButton( currentItem );
00608 #endif
00609 }
00610
00611 bool KoFontChooser::wordByWord()const
00612 {
00613 return d->m_wordByWord->isChecked();
00614 }
00615
00616 void KoFontChooser::setWordByWord( bool _b)
00617 {
00618 d->m_wordByWord->setChecked( _b);
00619 }
00620
00621
00622 double KoFontChooser::relativeTextSize()const
00623 {
00624 return ((double)d->m_relativeSize->value()/100.0);
00625 }
00626
00627 void KoFontChooser::setRelativeTextSize(double _size)
00628 {
00629 d->m_relativeSize->setValue( (int)(_size * 100) );
00630 }
00631
00632 int KoFontChooser::offsetFromBaseLine()const
00633 {
00634 return d->m_offsetBaseLine->value();
00635 }
00636
00637 void KoFontChooser::setOffsetFromBaseLine(int _offset)
00638 {
00639 d->m_offsetBaseLine->setValue( _offset );
00640 }
00641
00642 void KoFontChooser::setFont( const QFont &_font, bool _subscript, bool _superscript )
00643 {
00644
00645 m_newFont = _font;
00646 kdDebug()<<" setFont m_newFont.bold() :"<<m_newFont.bold()<<" m_newFont.italic():"<<m_newFont.italic()<<endl;
00647 kdDebug()<<" setfont m_newFont.family() :"<<m_newFont.family()<<endl;
00648
00649 m_subScript->setChecked( _subscript );
00650 m_superScript->setChecked( _superscript );
00651
00652 m_chooseFont->setFont( m_newFont );
00653 m_changedFlags = 0;
00654 }
00655
00656 void KoFontChooser::setColor( const QColor & col )
00657 {
00658 d->m_textColor = col;
00659 if ( col.isValid() )
00660 m_chooseFont->setColor( col );
00661 else
00662 m_chooseFont->setColor( QApplication::palette().color( QPalette::Active, QColorGroup::Text ) );
00663 m_changedFlags = 0;
00664 }
00665
00666 void KoFontChooser::setUnderlineColor( const QColor & col )
00667 {
00668 m_underlineColor = col;
00669 m_changedFlags = 0;
00670 }
00671
00672 void KoFontChooser::setBackGroundColor ( const QColor & col )
00673 {
00674 m_backGroundColor = col;
00675 m_changedFlags = 0;
00676 }
00677
00678 void KoFontChooser::slotFontChanged(const QFont & f)
00679 {
00680 kdDebug()<<" slotFontChanged m_newFont.bold() :"<<f.bold()<<" m_newFont.italic():"<<f.italic()<<endl;
00681 kdDebug()<<" slotFontChanged m_newFont.family() :"<<f.family()<<endl;
00682
00683 if ( f.weight() != m_newFont.weight() )
00684 m_changedFlags |= KoTextFormat::Bold;
00685 if ( f.italic() != m_newFont.italic() )
00686 m_changedFlags |= KoTextFormat::Italic;
00687 if ( f.family() != m_newFont.family() )
00688 m_changedFlags |= KoTextFormat::Family;
00689 if ( f.pointSize() != m_newFont.pointSize() )
00690 m_changedFlags |= KoTextFormat::Size;
00691 kdDebug(32500) << "KWFontChooser::slotFontChanged m_changedFlags=" << m_changedFlags << endl;
00692 m_newFont = f;
00693 }
00694
00695 bool KoFontChooser::hyphenation() const
00696 {
00697 return d->m_hyphenation->isChecked();
00698 }
00699 void KoFontChooser::setHyphenation( bool _b)
00700 {
00701 d->m_hyphenation->setChecked( _b);
00702 }
00703
00704 void KoFontChooser::slotHyphenationClicked()
00705 {
00706 m_changedFlags |= KoTextFormat::Hyphenation;
00707 }
00708
00709 void KoFontChooser::slotStrikeOutTypeChanged( int _val)
00710 {
00711 m_changedFlags |= KoTextFormat::StrikeOut;
00712 m_strikeOutType->setEnabled( _val!=0 );
00713 d->m_wordByWord->setEnabled( ( _val != 0 ) || ( m_underlining->currentItem()!=0 ));
00714 }
00715
00716 void KoFontChooser::slotSubScriptClicked()
00717 {
00718 if(m_superScript->isChecked())
00719 m_superScript->setChecked(false);
00720 m_changedFlags |= KoTextFormat::VAlign;
00721 updatePositionButton();
00722 }
00723
00724 void KoFontChooser::slotSuperScriptClicked()
00725 {
00726 if(m_subScript->isChecked())
00727 m_subScript->setChecked(false);
00728 m_changedFlags |= KoTextFormat::VAlign;
00729 updatePositionButton();
00730 }
00731
00732 void KoFontChooser::slotRelativeSizeChanged( int )
00733 {
00734 m_changedFlags |= KoTextFormat::VAlign;
00735 }
00736
00737 void KoFontChooser::slotOffsetFromBaseLineChanged( int )
00738 {
00739 m_changedFlags |= KoTextFormat::OffsetFromBaseLine;
00740 }
00741
00742 void KoFontChooser::slotShadowChanged()
00743 {
00744 m_changedFlags |= KoTextFormat::ShadowText;
00745 }
00746
00747 void KoFontChooser::slotWordByWordClicked()
00748 {
00749 m_changedFlags |= KoTextFormat::WordByWord;
00750 }
00751
00752 void KoFontChooser::slotChangeAttributeFont( int )
00753 {
00754 m_changedFlags |= KoTextFormat::Attribute;
00755 }
00756
00757 void KoFontChooser::slotChangeLanguage( int )
00758 {
00759 m_changedFlags |= KoTextFormat::Language;
00760 }
00761
00762 void KoFontChooser::slotChangeColor()
00763 {
00764 QColor color = d->m_textColor;
00765 QColor defaultTextColor = QApplication::palette().color( QPalette::Active, QColorGroup::Text );
00766 if ( KColorDialog::getColor( color, defaultTextColor ) )
00767 {
00768 if ( color != d->m_textColor )
00769 {
00770 d->m_textColor = color;
00771 m_changedFlags |= KoTextFormat::Color;
00772 if ( color.isValid() )
00773 m_chooseFont->setColor( color );
00774 else
00775 m_chooseFont->setColor( defaultTextColor );
00776 }
00777 }
00778 }
00779
00780 void KoFontChooser::slotChangeBackGroundColor()
00781 {
00782 QColor color = m_backGroundColor;
00783 if ( KColorDialog::getColor( color, QApplication::palette().color( QPalette::Active, QColorGroup::Base ) ) )
00784 {
00785 if ( color != m_chooseFont->color() )
00786 {
00787 m_changedFlags |= KoTextFormat::TextBackgroundColor;
00788 m_backGroundColor = color;
00789 }
00790 }
00791 }
00792
00793 void KoFontChooser::slotUnderlineColor()
00794 {
00795 QColor color = m_underlineColor;
00796 if ( KColorDialog::getColor( color, QApplication::palette().color( QPalette::Active, QColorGroup::Base ) ) )
00797 {
00798 if ( color != m_underlineColor )
00799 {
00800 m_changedFlags |= KoTextFormat::ExtendUnderLine;
00801 m_underlineColor = color;
00802 }
00803 }
00804 }
00805
00806 KoTextFormat::UnderlineType KoFontChooser::underlineType() const
00807 {
00808 switch (m_underlining->currentItem () )
00809 {
00810 case 0:
00811 return KoTextFormat::U_NONE;
00812 break;
00813 case 1:
00814 return KoTextFormat::U_SIMPLE;
00815 break;
00816 case 2:
00817 return KoTextFormat::U_SIMPLE_BOLD;
00818 break;
00819 case 3:
00820 return KoTextFormat::U_DOUBLE;
00821 break;
00822 case 4:
00823 return KoTextFormat::U_WAVE;
00824 break;
00825 default:
00826 return KoTextFormat::U_NONE;
00827 }
00828
00829 }
00830
00831 KoTextFormat::StrikeOutType KoFontChooser::strikeOutType() const
00832 {
00833 switch (d->m_strikeOut->currentItem () )
00834 {
00835 case 0:
00836 return KoTextFormat::S_NONE;
00837 break;
00838 case 1:
00839 return KoTextFormat::S_SIMPLE;
00840 break;
00841 case 2:
00842 return KoTextFormat::S_SIMPLE_BOLD;
00843 break;
00844 case 3:
00845 return KoTextFormat::S_DOUBLE;
00846 break;
00847 default:
00848 return KoTextFormat::S_NONE;
00849 }
00850 }
00851
00852
00853 void KoFontChooser::setStrikeOutlineType(KoTextFormat::StrikeOutType nb)
00854 {
00855 switch ( nb )
00856 {
00857 case KoTextFormat::S_NONE:
00858 d->m_strikeOut->setCurrentItem(0);
00859 break;
00860 case KoTextFormat::S_SIMPLE:
00861 d->m_strikeOut->setCurrentItem(1);
00862 break;
00863 case KoTextFormat::S_SIMPLE_BOLD:
00864 d->m_strikeOut->setCurrentItem(2);
00865 break;
00866 case KoTextFormat::S_DOUBLE:
00867 d->m_strikeOut->setCurrentItem(3);
00868 break;
00869 }
00870 m_strikeOutType->setEnabled( d->m_strikeOut->currentItem()!= 0);
00871 d->m_wordByWord->setEnabled( ( d->m_strikeOut->currentItem()!= 0 ) || ( m_underlining->currentItem()!=0 ));
00872 m_changedFlags = 0;
00873 }
00874
00875
00876 void KoFontChooser::setUnderlineType(KoTextFormat::UnderlineType nb)
00877 {
00878 switch ( nb )
00879 {
00880 case KoTextFormat::U_NONE:
00881 m_underlining->setCurrentItem(0);
00882 break;
00883 case KoTextFormat::U_SIMPLE:
00884 m_underlining->setCurrentItem(1);
00885 break;
00886 case KoTextFormat::U_SIMPLE_BOLD:
00887 m_underlining->setCurrentItem(2);
00888 break;
00889 case KoTextFormat::U_DOUBLE:
00890 m_underlining->setCurrentItem(3);
00891 break;
00892 case KoTextFormat::U_WAVE:
00893 m_underlining->setCurrentItem(4);
00894 break;
00895 default:
00896 m_underlining->setCurrentItem(0);
00897 break;
00898 }
00899 m_changedFlags = 0;
00900 }
00901
00902 void KoFontChooser::setUnderlineStyle(KoTextFormat::UnderlineStyle _t)
00903 {
00904 switch ( _t )
00905 {
00906 case KoTextFormat::U_SOLID:
00907 m_underlineType->setCurrentItem( 0 );
00908 break;
00909 case KoTextFormat::U_DASH:
00910 m_underlineType->setCurrentItem( 1 );
00911 break;
00912 case KoTextFormat::U_DOT:
00913 m_underlineType->setCurrentItem( 2 );
00914 break;
00915 case KoTextFormat::U_DASH_DOT:
00916 m_underlineType->setCurrentItem( 3 );
00917 break;
00918 case KoTextFormat::U_DASH_DOT_DOT:
00919 m_underlineType->setCurrentItem( 4 );
00920 break;
00921 default:
00922 m_underlineType->setCurrentItem( 0 );
00923 break;
00924 }
00925 m_underlineType->setEnabled( m_underlining->currentItem()!= 0);
00926 m_underlineColorButton->setEnabled( m_underlining->currentItem()!=0);
00927
00928 d->m_wordByWord->setEnabled( ( d->m_strikeOut->currentItem()!= 0 ) || ( m_underlining->currentItem()!=0 ));
00929
00930 m_changedFlags = 0;
00931 }
00932
00933 void KoFontChooser::setStrikeOutStyle(KoTextFormat::StrikeOutStyle _t)
00934 {
00935 switch ( _t )
00936 {
00937 case KoTextFormat::S_NONE:
00938 m_strikeOutType->setCurrentItem( 0 );
00939 break;
00940 case KoTextFormat::S_DASH:
00941 m_strikeOutType->setCurrentItem( 1 );
00942 break;
00943 case KoTextFormat::S_DOT:
00944 m_strikeOutType->setCurrentItem( 2 );
00945 break;
00946 case KoTextFormat::S_DASH_DOT:
00947 m_strikeOutType->setCurrentItem( 3 );
00948 break;
00949 case KoTextFormat::S_DASH_DOT_DOT:
00950 m_strikeOutType->setCurrentItem( 4 );
00951 break;
00952 default:
00953 m_strikeOutType->setCurrentItem( 0 );
00954 break;
00955 }
00956 m_changedFlags = 0;
00957 }
00958
00959 KoTextFormat::UnderlineStyle KoFontChooser::underlineStyle() const
00960 {
00961 switch ( m_underlineType->currentItem() )
00962 {
00963 case 0:
00964 return KoTextFormat::U_SOLID;
00965 break;
00966 case 1:
00967 return KoTextFormat::U_DASH;
00968 break;
00969 case 2:
00970 return KoTextFormat::U_DOT;
00971 break;
00972 case 3:
00973 return KoTextFormat::U_DASH_DOT;
00974 break;
00975 case 4:
00976 return KoTextFormat::U_DASH_DOT_DOT;
00977 break;
00978 default:
00979 return KoTextFormat::U_SOLID;
00980 }
00981 }
00982
00983 KoTextFormat::StrikeOutStyle KoFontChooser::strikeOutStyle() const
00984 {
00985
00986 switch ( m_strikeOutType->currentItem() )
00987 {
00988 case 0:
00989 return KoTextFormat::S_SOLID;
00990 break;
00991 case 1:
00992 return KoTextFormat::S_DASH;
00993 break;
00994 case 2:
00995 return KoTextFormat::S_DOT;
00996 break;
00997 case 3:
00998 return KoTextFormat::S_DASH_DOT;
00999 break;
01000 case 4:
01001 return KoTextFormat::S_DASH_DOT_DOT;
01002 break;
01003 default:
01004 return KoTextFormat::S_SOLID;
01005 }
01006 }
01007
01008
01009 void KoFontChooser::slotChangeUnderlineType( int )
01010 {
01011 m_changedFlags |= KoTextFormat::ExtendUnderLine;
01012 }
01013
01014 void KoFontChooser::slotChangeUnderlining( int i)
01015 {
01016 m_changedFlags |= KoTextFormat::ExtendUnderLine;
01017 m_underlineType->setEnabled( i!= 0);
01018 m_underlineColorButton->setEnabled( i!=0);
01019 d->m_wordByWord->setEnabled( ( d->m_strikeOut->currentItem()!= 0 ) || ( i !=0 ));
01020
01021 }
01022
01023 void KoFontChooser::slotChangeStrikeOutType( int )
01024 {
01025 m_changedFlags |= KoTextFormat::StrikeOut;
01026 }
01027
01028
01029 void KoFontChooser::setShadow( double shadowDistanceX, double shadowDistanceY, const QColor& shadowColor )
01030 {
01031 d->m_shadowWidget->setShadow( shadowDistanceX, shadowDistanceY, shadowColor );
01032 }
01033
01034 double KoFontChooser::shadowDistanceX() const
01035 {
01036 return d->m_shadowWidget->shadowDistanceX();
01037 }
01038
01039 double KoFontChooser::shadowDistanceY() const
01040 {
01041 return d->m_shadowWidget->shadowDistanceY();
01042 }
01043
01044 QColor KoFontChooser::shadowColor() const
01045 {
01046 return d->m_shadowWidget->shadowColor();
01047 }
01048
01049 void KoFontChooser::setFormat( const KoTextFormat& format )
01050 {
01051 setFont( format.font(),
01052 format.vAlign() & KoTextFormat::AlignSubScript,
01053 format.vAlign() & KoTextFormat::AlignSuperScript );
01054 setColor( format.color() );
01055 setBackGroundColor( format.textBackgroundColor() );
01056 setUnderlineColor( format.textUnderlineColor() );
01057
01058 setUnderlineType( format.underlineType() );
01059 setUnderlineStyle( format.underlineStyle() );
01060
01061 setStrikeOutlineType( format.strikeOutType() );
01062 setStrikeOutStyle( format.strikeOutStyle() );
01063
01064 setShadow( format.shadowDistanceX(), format.shadowDistanceY(), format.shadowColor() );
01065
01066 setWordByWord( format.wordByWord() );
01067 setRelativeTextSize( format.relativeTextSize() );
01068 setOffsetFromBaseLine( format.offsetFromBaseLine() );
01069 setFontAttribute( format.attributeFont() );
01070 setLanguage( format.language() );
01071
01072 setHyphenation( format.hyphenation() );
01073
01074 updatePositionButton();
01075 }
01076
01077 KoTextFormat KoFontChooser::newFormat() const
01078 {
01079 return KoTextFormat( newFont(),
01080 vAlign(),
01081 color(),
01082 backGroundColor(),
01083 underlineColor(),
01084 underlineType(),
01085 underlineStyle(),
01086 strikeOutType(),
01087 strikeOutStyle(),
01088 fontAttribute(),
01089 language(),
01090 relativeTextSize(),
01091 offsetFromBaseLine(),
01092 wordByWord(),
01093 hyphenation(),
01094 shadowDistanceX(),
01095 shadowDistanceY(),
01096 shadowColor() );
01097 }
01098
01100
01101 KoFontDia::KoFontDia( const KoTextFormat& initialFormat, QWidget* parent, const char* name )
01102 : KDialogBase( parent, name, true,
01103 i18n("Select Font"), Ok|Cancel|User1|Apply, Ok ),
01104 m_initialFormat(initialFormat)
01105 {
01106 setButtonText( KDialogBase::User1, i18n("&Reset") );
01107
01108 m_chooser = new KoFontChooser( this, "kofontchooser", true ,
01109 KFontChooser::SmoothScalableFonts);
01110 setMainWidget( m_chooser );
01111 connect( this, SIGNAL( user1Clicked() ), this, SLOT(slotReset()) );
01112
01113 slotReset();
01114 }
01115
01116 void KoFontDia::slotApply()
01117 {
01118 emit applyFont();
01119 }
01120
01121 void KoFontDia::slotOk()
01122 {
01123 slotApply();
01124 KDialogBase::slotOk();
01125 }
01126
01127 void KoFontDia::slotReset()
01128 {
01129 m_chooser->setFormat( m_initialFormat );
01130 }
01131
01132 #include "koFontDia.moc"
01133 #include "koFontDia_p.moc"