lib Library API Documentation

koFontDia.cc

00001 /* This file is part of the KDE project
00002    Copyright (C)  2001, 2002 Montel Laurent <lmontel@mandrakesoft.com>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
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     const QString text ( i18n ( "Test string for shadow dialog", "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     // ### TODO: use KoUnitDoubleSpinBox instead
00098     distance = new QSpinBox( 0, 20, 1, shadowBox );
00099     distance->setSuffix(i18n("pt"));
00100     ldistance->setBuddy( distance );
00101     connect( distance, SIGNAL( valueChanged( int ) ), this, SLOT( distanceChanged( int ) ) );
00102     grid2->addWidget(distance,3,0);
00103 
00104     QLabel *ldirection = new QLabel( i18n( "Di&rection:" ), shadowBox );
00105     grid2->addWidget(ldirection,0,1);
00106 
00107     QGridLayout *grid3 = new QGridLayout( 0L, 3, 3, KDialog::marginHint(), KDialog::spacingHint() );
00108 
00109     lu = new QPushButton( shadowBox );
00110     grid3->addWidget(lu,0,0);
00111     lu->setToggleButton( true );
00112         ldirection->setBuddy( lu );
00113     u = new QPushButton( shadowBox );
00114     grid3->addWidget(u,0,1);
00115     u->setToggleButton( true );
00116     ru = new QPushButton( shadowBox );
00117     grid3->addWidget(ru,0,2);
00118     ru->setToggleButton( true );
00119     r = new QPushButton( shadowBox );
00120     grid3->addWidget(r,1,2);
00121     r->setToggleButton( true );
00122     rb = new QPushButton( shadowBox );
00123     grid3->addWidget(rb,2,2);
00124     rb->setToggleButton( true );
00125     b = new QPushButton( shadowBox );
00126     grid3->addWidget(b,2,1);
00127     b->setToggleButton( true );
00128     lb = new QPushButton( shadowBox );
00129     grid3->addWidget(lb,2,0);
00130     lb->setToggleButton( true );
00131     l = new QPushButton( shadowBox );
00132     grid3->addWidget(l,1,0);
00133     l->setToggleButton( true );
00134 
00135     lu->setPixmap( BarIcon( "shadowLU" ) );
00136     u->setPixmap( BarIcon( "shadowU" ) );
00137     ru->setPixmap( BarIcon( "shadowRU" ) );
00138     r->setPixmap( BarIcon( "shadowR" ) );
00139     rb->setPixmap( BarIcon( "shadowRB" ) );
00140     b->setPixmap( BarIcon( "shadowB" ) );
00141     lb->setPixmap( BarIcon( "shadowLB" ) );
00142     l->setPixmap( BarIcon( "shadowL" ) );
00143 
00144     connect( lu, SIGNAL( clicked() ), this, SLOT( luChanged() ) );
00145     connect( u, SIGNAL( clicked() ), this, SLOT( uChanged() ) );
00146     connect( ru, SIGNAL( clicked() ), this, SLOT( ruChanged() ) );
00147     connect( r, SIGNAL( clicked() ), this, SLOT( rChanged() ) );
00148     connect( rb, SIGNAL( clicked() ), this, SLOT( rbChanged() ) );
00149     connect( b, SIGNAL( clicked() ), this, SLOT( bChanged() ) );
00150     connect( lb, SIGNAL( clicked() ), this, SLOT( lbChanged() ) );
00151     connect( l, SIGNAL( clicked() ), this, SLOT( lChanged() ) );
00152 
00153 
00154     grid2->addMultiCellLayout (grid3, 1,3, 1, 1 );
00155 
00156     m_shadowPreview = new KoShadowPreview( this, "preview" );
00157     grid->addMultiCellWidget( m_shadowPreview, 0, 3, 1, 1 );
00158 }
00159 
00160 void KoTextShadowWidget::setShadowDirection( short int sd )
00161 {
00162     m_shadowDirection = sd;
00163     m_shadowPreview->setShadowDistanceX( shadowDistanceX() );
00164     m_shadowPreview->setShadowDistanceY( shadowDistanceY() );
00165 
00166     lu->setOn( false );
00167     u->setOn( false );
00168     ru->setOn( false );
00169     r->setOn( false );
00170     rb->setOn( false );
00171     b->setOn( false );
00172     lb->setOn( false );
00173     l->setOn( false );
00174 
00175     switch ( m_shadowDirection )
00176     {
00177     case SD_LEFT_UP:
00178         lu->setOn( true );
00179         break;
00180     case SD_UP:
00181         u->setOn( true );
00182         break;
00183     case SD_RIGHT_UP:
00184         ru->setOn( true );
00185         break;
00186     case SD_RIGHT:
00187         r->setOn( true );
00188         break;
00189     case SD_RIGHT_BOTTOM:
00190         rb->setOn( true );
00191         break;
00192     case SD_BOTTOM:
00193         b->setOn( true );
00194         break;
00195     case SD_LEFT_BOTTOM:
00196         lb->setOn( true );
00197         break;
00198     case SD_LEFT:
00199         l->setOn( true );
00200         break;
00201     }
00202 }
00203 
00204 void KoTextShadowWidget::setShadow( double shadowDistanceX, double shadowDistanceY, const QColor& shadowColor )
00205 {
00206     // Figure out shadow direction from x and y distance
00207     // Ugly temporary code
00208     m_shadowDirection = SD_RIGHT_BOTTOM;
00209     if ( shadowDistanceX > 0 ) // right
00210         if ( shadowDistanceY == 0 )
00211             m_shadowDirection = SD_RIGHT;
00212         else
00213             m_shadowDirection = shadowDistanceY > 0 ? SD_RIGHT_BOTTOM : SD_RIGHT_UP;
00214     else if ( shadowDistanceX == 0 ) // top/bottom
00215             m_shadowDirection = shadowDistanceY > 0 ? SD_BOTTOM : SD_UP;
00216     else // left
00217         if ( shadowDistanceY == 0 )
00218             m_shadowDirection = SD_LEFT;
00219         else
00220             m_shadowDirection = shadowDistanceY > 0 ? SD_LEFT_BOTTOM : SD_LEFT_UP;
00221 
00222     m_shadowDistance = QMAX( QABS(shadowDistanceX), QABS(shadowDistanceY) );
00223     m_shadowPreview->setShadowDistanceX( shadowDistanceX );
00224     m_shadowPreview->setShadowDistanceY( shadowDistanceY );
00225     // TODO turn distance into a KDoubleNumInput
00226     distance->setValue( (int)m_shadowDistance );
00227 
00228     m_shadowColor = shadowColor;
00229     m_shadowPreview->setShadowColor( m_shadowColor );
00230     color->setColor( m_shadowColor.isValid() ? m_shadowColor: gray  );
00231 }
00232 
00233 void KoTextShadowWidget::luChanged()
00234 {
00235     setShadowDirection( SD_LEFT_UP );
00236 }
00237 
00238 void KoTextShadowWidget::uChanged()
00239 {
00240     setShadowDirection( SD_UP );
00241 }
00242 
00243 void KoTextShadowWidget::ruChanged()
00244 {
00245     setShadowDirection( SD_RIGHT_UP );
00246 }
00247 
00248 void KoTextShadowWidget::rChanged()
00249 {
00250     setShadowDirection( SD_RIGHT );
00251 }
00252 
00253 void KoTextShadowWidget::rbChanged()
00254 {
00255     setShadowDirection( SD_RIGHT_BOTTOM );
00256 }
00257 
00258 void KoTextShadowWidget::bChanged()
00259 {
00260     setShadowDirection( SD_BOTTOM );
00261 }
00262 
00263 void KoTextShadowWidget::lbChanged()
00264 {
00265     setShadowDirection( SD_LEFT_BOTTOM );
00266 }
00267 
00268 void KoTextShadowWidget::lChanged()
00269 {
00270     setShadowDirection( SD_LEFT );
00271 }
00272 
00273 void KoTextShadowWidget::colorChanged( const QColor& col )
00274 {
00275     m_shadowColor = col;
00276     m_shadowPreview->setShadowColor( col );
00277     emit changed();
00278 }
00279 
00280 void KoTextShadowWidget::distanceChanged( int _val )
00281 {
00282     m_shadowDistance = _val;
00283     m_shadowPreview->setShadowDistanceX( shadowDistanceX() );
00284     m_shadowPreview->setShadowDistanceY( shadowDistanceY() );
00285     emit changed();
00286 }
00287 
00288 QString KoTextShadowWidget::tabName() {
00289     return i18n( "S&hadow" );
00290 }
00291 
00292 double KoTextShadowWidget::shadowDistanceX() const
00293 {
00294     switch ( m_shadowDirection )
00295     {
00296     case SD_LEFT_BOTTOM:
00297     case SD_LEFT:
00298     case SD_LEFT_UP:
00299         return - m_shadowDistance;
00300     case SD_UP:
00301     case SD_BOTTOM:
00302         return 0;
00303     case SD_RIGHT_UP:
00304     case SD_RIGHT:
00305     case SD_RIGHT_BOTTOM:
00306         return m_shadowDistance;
00307     }
00308     return 0;
00309 }
00310 
00311 double KoTextShadowWidget::shadowDistanceY() const
00312 {
00313     switch ( m_shadowDirection )
00314     {
00315     case SD_LEFT_UP:
00316     case SD_UP:
00317     case SD_RIGHT_UP:
00318         return - m_shadowDistance;
00319     case SD_LEFT:
00320     case SD_RIGHT:
00321         return 0;
00322     case SD_LEFT_BOTTOM:
00323     case SD_BOTTOM:
00324     case SD_RIGHT_BOTTOM:
00325         return m_shadowDistance;
00326     }
00327     return 0;
00328 }
00329 
00330 class KoFontChooser::KoFontChooserPrivate
00331 {
00332 public:
00333     QComboBox *m_strikeOut;
00334     QColor m_textColor;
00335     KoTextShadowWidget *m_shadowWidget;
00336     KIntNumInput *m_relativeSize;
00337     QLabel *m_lRelativeSize;
00338     KIntNumInput *m_offsetBaseLine;
00339     QCheckBox *m_wordByWord;
00340 #ifdef ATTRCOMBO
00341     QComboBox *m_fontAttribute;
00342 #else
00343     QButtonGroup* m_fontAttribute;
00344 #endif
00345     QComboBox *m_language;
00346 #ifdef HAVE_LIBKSPELL2
00347     KSpell2::Broker::Ptr m_broker;
00348 #endif
00349     QCheckBox *m_hyphenation;
00350 };
00351 
00352 KoFontChooser::KoFontChooser( QWidget* parent, const char* name, bool _withSubSuperScript, uint fontListCriteria
00353 #ifdef HAVE_LIBKSPELL2
00354                    , KSpell2::Broker::Ptr broker
00355 #endif
00356     )
00357     : QTabWidget( parent, name )
00358 {
00359     d = new KoFontChooserPrivate;
00360 #ifdef HAVE_LIBKSPELL2
00361     d->m_broker = broker;
00362 #endif
00363     setupTab1( fontListCriteria );
00364     setupTab2( _withSubSuperScript );
00365     // More modular solution: one widget per tab....
00366     d->m_shadowWidget = new KoTextShadowWidget( this );
00367     connect( d->m_shadowWidget, SIGNAL(changed()), this, SLOT(slotShadowChanged()) );
00368     addTab( d->m_shadowWidget, d->m_shadowWidget->tabName() );
00369     m_changedFlags = 0;
00370 }
00371 
00372 KoFontChooser::~KoFontChooser()
00373 {
00374     delete d; d = 0;
00375 }
00376 
00377 QColor KoFontChooser::color() const
00378 {
00379     return d->m_textColor;
00380 }
00381 
00382 void KoFontChooser::setupTab1( uint fontListCriteria )
00383 {
00384     QWidget *page = new QWidget( this );
00385     addTab( page, i18n( "&Fonts" ) );
00386     QVBoxLayout *lay1 = new QVBoxLayout( page, KDialog::marginHint(), KDialog::spacingHint() );
00387     QStringList list;
00388     KFontChooser::getFontList(list,fontListCriteria);
00389     m_chooseFont = new KFontChooser(page, "FontList", false, list);
00390     lay1->addWidget(m_chooseFont);
00391 
00392     QHGroupBox* colorsGrp = new QHGroupBox(i18n("Colors"), page);
00393     lay1->addWidget(colorsGrp);
00394     //grid = new QGridLayout( colorsGrp, 2, 2, KDialog::marginHint(), KDialog::spacingHint() );
00395     m_colorButton = new QPushButton( i18n( "Change Co&lor..." ), colorsGrp );
00396     //grid->addWidget(m_colorButton,0,0);
00397 
00398     m_backGroundColorButton = new QPushButton( i18n( "Change Bac&kground Color..." ), colorsGrp );
00399     //grid->addWidget(m_backGroundColorButton,0,1);
00400 
00401     connect( m_colorButton, SIGNAL(clicked()), this, SLOT( slotChangeColor() ) );
00402 
00403     connect( m_backGroundColorButton,  SIGNAL(clicked()), this, SLOT( slotChangeBackGroundColor() ) );
00404 
00405     connect( m_chooseFont, SIGNAL( fontSelected( const QFont & )),
00406              this, SLOT( slotFontChanged(const QFont &) ) );
00407 
00408 }
00409 
00410 void KoFontChooser::setupTab2( bool _withSubSuperScript )
00411 {
00412     QWidget *page = new QWidget( this );
00413     addTab( page, i18n( "Font &Effects" ) );
00414 
00415     //QVBoxLayout *lay1 = new QVBoxLayout( page, KDialog::marginHint(), KDialog::spacingHint() );
00416     // A single groupbox, without title, looks stupid.
00417     //QGroupBox *grp = new QGroupBox(page);
00418     //lay1->addWidget(grp);
00419     QWidget* grp = page; // just to be able to go back to a groupbox
00420 
00421     QGridLayout *grid = new QGridLayout( grp, 10, 2, KDialog::marginHint(), KDialog::spacingHint() );
00422 
00423     QLabel * lab = new QLabel( i18n("&Underlining:"), grp);
00424     grid->addWidget( lab, 0, 0);
00425 
00426     m_underlining = new QComboBox( grp );
00427     lab->setBuddy( m_underlining );
00428     grid->addWidget( m_underlining, 1, 0);
00429 
00430     m_underlining->insertStringList( KoTextFormat::underlineTypeList() );
00431 
00432     m_underlineType = new QComboBox(grp );
00433     grid->addWidget( m_underlineType, 1, 1);
00434     m_underlineType->insertStringList( KoTextFormat::underlineStyleList() );
00435 
00436 
00437     m_underlineColorButton = new QPushButton( i18n( "Change Co&lor..." ), grp );
00438     grid->addWidget(m_underlineColorButton,1,2);
00439 
00440 
00441     QLabel * lab2 = new QLabel( i18n("&Strikethrough:"), grp);
00442     grid->addWidget( lab2, 2, 0);
00443     d->m_strikeOut = new QComboBox( grp );
00444     lab2->setBuddy( d->m_strikeOut );
00445     grid->addWidget( d->m_strikeOut, 3, 0);
00446     d->m_strikeOut->insertStringList( KoTextFormat::strikeOutTypeList() );
00447 
00448 
00449     m_strikeOutType= new QComboBox(grp );
00450     grid->addWidget( m_strikeOutType, 3, 1);
00451     m_strikeOutType->insertStringList( KoTextFormat::strikeOutStyleList() );
00452 
00453     d->m_wordByWord = new QCheckBox( i18n("&Word by word"), grp);
00454     grid->addWidget( d->m_wordByWord, 4, 0);
00455 
00456     QVGroupBox *grp1 = new QVGroupBox(i18n("Position"), page);
00457     grid->addMultiCellWidget( grp1, 5, 5, 0, grid->numCols()-1 );
00458     QWidget* grpBox = new QWidget( grp1 ); // container for the grid - laid out inside the QVGroupBox
00459     QGridLayout *grid1 = new QGridLayout( grpBox, 2, 3, 0, KDialog::spacingHint() );
00460     grid1->setColStretch( 1, 1 ); // better stretch labels than spinboxes.
00461 
00462     // superscript/subscript need to be checkboxes, not radiobuttons.
00463     // otherwise it's not possible to disable both, and there's no room for a 3rd one like 'none'
00464     m_superScript = new QCheckBox(i18n("Su&perscript"),grpBox);
00465     grid1->addWidget(m_superScript,0,0);
00466 
00467     m_subScript = new QCheckBox(i18n("Su&bscript"),grpBox);
00468     grid1->addWidget(m_subScript,1,0);
00469 
00470     d->m_lRelativeSize = new QLabel ( i18n("Relative &size:"), grpBox);
00471     d->m_lRelativeSize->setAlignment( Qt::AlignRight );
00472     grid1->addWidget(d->m_lRelativeSize,0,1);
00473 
00474     // ## How to make this widget smaller? Sounds like the [minimum]sizeHint for KIntNumInput is big...
00475     d->m_relativeSize = new KIntNumInput( grpBox );
00476     d->m_lRelativeSize->setBuddy( d->m_relativeSize );
00477     grid1->addWidget(d->m_relativeSize,0,2);
00478 
00479     d->m_relativeSize-> setRange(1, 100, 1,false);
00480     d->m_relativeSize->setSuffix("%");
00481 
00482     QLabel *lab5 = new QLabel ( i18n("Offse&t from baseline:"), grpBox);
00483     lab5->setAlignment( Qt::AlignRight );
00484     grid1->addWidget(lab5,1,1);
00485 
00486     d->m_offsetBaseLine= new KIntNumInput( grpBox );
00487     lab5->setBuddy( d->m_offsetBaseLine );
00488     grid1->addWidget(d->m_offsetBaseLine,1,2);
00489 
00490     d->m_offsetBaseLine->setRange(-9, 9, 1,false);
00491     d->m_offsetBaseLine->setSuffix("pt");
00492 
00493     if(!_withSubSuperScript)
00494     {
00495         m_subScript->setEnabled(false);
00496         m_superScript->setEnabled(false);
00497         d->m_relativeSize->setEnabled( false );
00498         d->m_lRelativeSize->setEnabled( false );
00499     }
00500 
00501 
00502 #ifdef ATTRCOMBO
00503     QLabel * lab3 = new QLabel( i18n("A&ttribute:"), grp);
00504     grid->addWidget( lab3, 6, 0);
00505 
00506     d->m_fontAttribute = new QComboBox( grp );
00507     lab3->setBuddy( d->m_fontAttribute );
00508     grid->addWidget( d->m_fontAttribute, 7, 0);
00509 
00510     d->m_fontAttribute->insertStringList( KoTextFormat::fontAttributeList() );
00511     connect( d->m_fontAttribute, SIGNAL( activated( int ) ), this, SLOT( slotChangeAttributeFont( int )));
00512 #else
00513     d->m_fontAttribute = new QHButtonGroup( i18n("Capitalization"), grp );
00514     grid->addMultiCellWidget( d->m_fontAttribute, 6, 6, 0, grid->numCols()-1 );
00515     QStringList fontAttributes = KoTextFormat::fontAttributeList();
00516     for( QStringList::Iterator it = fontAttributes.begin(); it != fontAttributes.end(); ++it ) {
00517         (void) new QRadioButton( *it, d->m_fontAttribute );
00518     }
00519     connect( d->m_fontAttribute,  SIGNAL( clicked( int ) ), this, SLOT( slotChangeAttributeFont( int )));
00520 #endif
00521 
00522     QLabel * lab4 = new QLabel( i18n("La&nguage:"), grp);
00523     grid->addWidget( lab4, 8, 0);
00524 
00525     d->m_language = new QComboBox( grp );
00526     // TODO insert an icon in front of each language for which spellchecking is available, like in OOo.
00527     const QStringList langNames = KoGlobal::listOfLanguages();
00528     const QStringList langTags = KoGlobal::listTagOfLanguages();
00529     QStringList spellCheckLanguages;
00530 #ifdef HAVE_LIBKSPELL2
00531     if ( d->m_broker )
00532         spellCheckLanguages = d->m_broker->languages();
00533 #endif
00534     QStringList::ConstIterator itName = langNames.begin();
00535     QStringList::ConstIterator itTag = langTags.begin();
00536     for ( ; itName != langNames.end() && itTag != langTags.end(); ++itName, ++itTag )
00537     {
00538         if ( spellCheckLanguages.find( *itTag ) != spellCheckLanguages.end() )
00539             d->m_language->insertItem( SmallIcon( "spellcheck" ), *itName );
00540         else
00541             d->m_language->insertItem( *itName );
00542     }
00543     lab4->setBuddy( d->m_language );
00544     grid->addWidget( d->m_language, 9, 0 );
00545 
00546     d->m_hyphenation = new QCheckBox( i18n("Auto h&yphenation"), grp );
00547     grid->addWidget( d->m_hyphenation, 10, 0 );
00548 
00549     // Add one row that can stretch
00550     grid->expand( grid->numRows() + 1, grid->numCols() );
00551     grid->setRowStretch( grid->numRows(), 1 );
00552 
00553     connect( d->m_strikeOut, SIGNAL(activated ( int )), this, SLOT( slotStrikeOutTypeChanged( int ) ) );
00554     connect( m_underlineColorButton, SIGNAL(clicked()), this, SLOT( slotUnderlineColor() ) );
00555     connect( m_underlining,  SIGNAL( activated ( int ) ), this, SLOT( slotChangeUnderlining( int )));
00556     connect( m_strikeOutType,  SIGNAL( activated ( int ) ), this, SLOT( slotChangeStrikeOutType( int )));
00557     connect( m_underlineType,  SIGNAL( activated ( int ) ), this, SLOT( slotChangeUnderlineType( int )));
00558     connect( d->m_wordByWord, SIGNAL(clicked()), this, SLOT( slotWordByWordClicked() ) );
00559     connect( d->m_language,  SIGNAL( activated ( int ) ), this, SLOT( slotChangeLanguage( int )));
00560     connect( d->m_hyphenation, SIGNAL( clicked()), this, SLOT( slotHyphenationClicked()));
00561     connect( m_subScript, SIGNAL(clicked()), this, SLOT( slotSubScriptClicked() ) );
00562     connect( m_superScript, SIGNAL(clicked()), this, SLOT( slotSuperScriptClicked() ) );
00563     connect( d->m_relativeSize, SIGNAL( valueChanged(int) ), this, SLOT( slotRelativeSizeChanged( int )));
00564     connect( d->m_offsetBaseLine, SIGNAL( valueChanged(int) ), this, SLOT( slotOffsetFromBaseLineChanged( int )));
00565 
00566     updatePositionButton();
00567 
00568 
00569 }
00570 
00571 void KoFontChooser::updatePositionButton()
00572 {
00573     bool state = (m_superScript->isChecked() || m_subScript->isChecked());
00574     d->m_relativeSize->setEnabled( state );
00575     d->m_lRelativeSize->setEnabled( state );
00576 }
00577 
00578 void KoFontChooser::setLanguage( const QString & _tag)
00579 {
00580     d->m_language->setCurrentText( KoGlobal::languageFromTag( _tag ) );
00581 }
00582 
00583 QString KoFontChooser::language() const
00584 {
00585     return KoGlobal::tagOfLanguage( d->m_language->currentText() );
00586 }
00587 
00588 KoTextFormat::AttributeStyle KoFontChooser::fontAttribute()const
00589 {
00590 #ifdef ATTRCOMBO
00591     int currentItem = d->m_fontAttribute->currentItem ();
00592 #else
00593     int currentItem = 0;
00594     for ( int i = 0; i < d->m_fontAttribute->count(); ++i )
00595     {
00596         if ( d->m_fontAttribute->find( i )->isOn() )
00597         {
00598             currentItem = i;
00599             break;
00600         }
00601     }
00602 #endif
00603     switch ( currentItem )
00604     {
00605     case 0:
00606         return KoTextFormat::ATT_NONE;
00607         break;
00608     case 1:
00609         return KoTextFormat::ATT_UPPER;
00610         break;
00611     case 2:
00612         return KoTextFormat::ATT_LOWER;
00613         break;
00614     case 3:
00615         return KoTextFormat::ATT_SMALL_CAPS;
00616         break;
00617     default:
00618         return KoTextFormat::ATT_NONE;
00619     }
00620 }
00621 
00622 void KoFontChooser::setFontAttribute( KoTextFormat::AttributeStyle _att)
00623 {
00624     int currentItem = 0;
00625     if ( _att == KoTextFormat::ATT_NONE)
00626         currentItem = 0;
00627     else if ( _att == KoTextFormat::ATT_UPPER)
00628         currentItem = 1;
00629     else if ( _att == KoTextFormat::ATT_LOWER )
00630         currentItem = 2;
00631     else if ( _att == KoTextFormat::ATT_SMALL_CAPS )
00632         currentItem = 3;
00633 #ifdef ATTRCOMBO
00634     d->m_fontAttribute->setCurrentItem( currentItem );
00635 #else
00636     d->m_fontAttribute->setButton( currentItem );
00637 #endif
00638 }
00639 
00640 bool KoFontChooser::wordByWord()const
00641 {
00642     return d->m_wordByWord->isChecked();
00643 }
00644 
00645 void KoFontChooser::setWordByWord( bool _b)
00646 {
00647     d->m_wordByWord->setChecked( _b);
00648 }
00649 
00650 
00651 double KoFontChooser::relativeTextSize()const
00652 {
00653     return ((double)d->m_relativeSize->value()/100.0);
00654 }
00655 
00656 void KoFontChooser::setRelativeTextSize(double _size)
00657 {
00658     d->m_relativeSize->setValue( (int)(_size * 100) );
00659 }
00660 
00661 int KoFontChooser::offsetFromBaseLine()const
00662 {
00663     return d->m_offsetBaseLine->value();
00664 }
00665 
00666 void KoFontChooser::setOffsetFromBaseLine(int _offset)
00667 {
00668     d->m_offsetBaseLine->setValue( _offset );
00669 }
00670 
00671 void KoFontChooser::setFont( const QFont &_font, bool _subscript, bool _superscript )
00672 {
00673 
00674     m_newFont = _font;
00675     kdDebug()<<" setFont m_newFont.bold() :"<<m_newFont.bold()<<" m_newFont.italic():"<<m_newFont.italic()<<endl;
00676     kdDebug()<<" setfont m_newFont.family() :"<<m_newFont.family()<<endl;
00677 
00678     m_subScript->setChecked( _subscript );
00679     m_superScript->setChecked( _superscript );
00680 
00681     m_chooseFont->setFont( m_newFont );
00682     m_changedFlags = 0;
00683 }
00684 
00685 void KoFontChooser::setColor( const QColor & col )
00686 {
00687     d->m_textColor = col;
00688     if ( col.isValid() )
00689         m_chooseFont->setColor( col );
00690     else
00691         m_chooseFont->setColor( QApplication::palette().color( QPalette::Active, QColorGroup::Text ) );
00692     m_changedFlags = 0;
00693 }
00694 
00695 void KoFontChooser::setUnderlineColor( const QColor & col )
00696 {
00697     m_underlineColor = col;
00698     m_changedFlags = 0;
00699 }
00700 
00701 void KoFontChooser::setBackGroundColor ( const QColor & col )
00702 {
00703     m_backGroundColor = col;
00704     m_changedFlags = 0;
00705 }
00706 
00707 void KoFontChooser::slotFontChanged(const QFont & f)
00708 {
00709     kdDebug()<<" slotFontChanged m_newFont.bold() :"<<f.bold()<<" m_newFont.italic():"<<f.italic()<<endl;
00710     kdDebug()<<" slotFontChanged m_newFont.family() :"<<f.family()<<endl;
00711 
00712     if ( f.weight() != m_newFont.weight() )
00713         m_changedFlags |= KoTextFormat::Bold;
00714     if ( f.italic() != m_newFont.italic() )
00715         m_changedFlags |= KoTextFormat::Italic;
00716     if ( f.family() != m_newFont.family() )
00717         m_changedFlags |= KoTextFormat::Family;
00718     if ( f.pointSize() != m_newFont.pointSize() )
00719         m_changedFlags |= KoTextFormat::Size;
00720     kdDebug(32500) << "KWFontChooser::slotFontChanged m_changedFlags=" << m_changedFlags << endl;
00721     m_newFont = f;
00722 }
00723 
00724 bool KoFontChooser::hyphenation() const
00725 {
00726     return d->m_hyphenation->isChecked();
00727 }
00728 void KoFontChooser::setHyphenation( bool _b)
00729 {
00730     d->m_hyphenation->setChecked( _b);
00731 }
00732 
00733 void KoFontChooser::slotHyphenationClicked()
00734 {
00735     m_changedFlags |= KoTextFormat::Hyphenation;
00736 }
00737 
00738 void KoFontChooser::slotStrikeOutTypeChanged( int _val)
00739 {
00740     m_changedFlags |= KoTextFormat::StrikeOut;
00741     m_strikeOutType->setEnabled( _val!=0 );
00742     d->m_wordByWord->setEnabled( ( _val != 0 ) || ( m_underlining->currentItem()!=0 ));
00743 }
00744 
00745 void KoFontChooser::slotSubScriptClicked()
00746 {
00747     if(m_superScript->isChecked())
00748         m_superScript->setChecked(false);
00749     m_changedFlags |= KoTextFormat::VAlign;
00750     updatePositionButton();
00751 }
00752 
00753 void KoFontChooser::slotSuperScriptClicked()
00754 {
00755     if(m_subScript->isChecked())
00756         m_subScript->setChecked(false);
00757     m_changedFlags |= KoTextFormat::VAlign;
00758     updatePositionButton();
00759 }
00760 
00761 void KoFontChooser::slotRelativeSizeChanged( int )
00762 {
00763     m_changedFlags |= KoTextFormat::VAlign;
00764 }
00765 
00766 void KoFontChooser::slotOffsetFromBaseLineChanged( int )
00767 {
00768     m_changedFlags |= KoTextFormat::OffsetFromBaseLine;
00769 }
00770 
00771 void KoFontChooser::slotShadowChanged()
00772 {
00773     m_changedFlags |= KoTextFormat::ShadowText;
00774 }
00775 
00776 void KoFontChooser::slotWordByWordClicked()
00777 {
00778     m_changedFlags |= KoTextFormat::WordByWord;
00779 }
00780 
00781 void KoFontChooser::slotChangeAttributeFont( int )
00782 {
00783     m_changedFlags |= KoTextFormat::Attribute;
00784 }
00785 
00786 void KoFontChooser::slotChangeLanguage( int )
00787 {
00788     m_changedFlags |= KoTextFormat::Language;
00789 }
00790 
00791 void KoFontChooser::slotChangeColor()
00792 {
00793     QColor color = d->m_textColor;
00794     QColor defaultTextColor = QApplication::palette().color( QPalette::Active, QColorGroup::Text );
00795     if ( KColorDialog::getColor( color, defaultTextColor ) )
00796     {
00797         if ( color != d->m_textColor )
00798         {
00799             d->m_textColor = color;
00800             m_changedFlags |= KoTextFormat::Color;
00801             if ( color.isValid() )
00802                 m_chooseFont->setColor( color );
00803             else
00804                 m_chooseFont->setColor( defaultTextColor );
00805         }
00806     }
00807 }
00808 
00809 void KoFontChooser::slotChangeBackGroundColor()
00810 {
00811     QColor color = m_backGroundColor;
00812     if ( KColorDialog::getColor( color, QApplication::palette().color( QPalette::Active, QColorGroup::Base ) ) )
00813     {
00814         if ( color != m_chooseFont->color() )
00815         {
00816             m_changedFlags |= KoTextFormat::TextBackgroundColor;
00817             m_backGroundColor = color;
00818         }
00819     }
00820 }
00821 
00822 void KoFontChooser::slotUnderlineColor()
00823 {
00824     QColor color = m_underlineColor;
00825     if ( KColorDialog::getColor( color, QApplication::palette().color( QPalette::Active, QColorGroup::Base ) ) )
00826     {
00827         if ( color != m_underlineColor )
00828         {
00829             m_changedFlags |= KoTextFormat::ExtendUnderLine;
00830             m_underlineColor = color;
00831         }
00832     }
00833 }
00834 
00835 KoTextFormat::UnderlineType KoFontChooser::underlineType() const
00836 {
00837     switch (m_underlining->currentItem () )
00838     {
00839     case 0:
00840         return KoTextFormat::U_NONE;
00841         break;
00842     case 1:
00843         return KoTextFormat::U_SIMPLE;
00844         break;
00845     case 2:
00846         return KoTextFormat::U_SIMPLE_BOLD;
00847         break;
00848     case 3:
00849         return KoTextFormat::U_DOUBLE;
00850         break;
00851     case 4:
00852         return KoTextFormat::U_WAVE;
00853         break;
00854     default:
00855         return KoTextFormat::U_NONE;
00856     }
00857 
00858 }
00859 
00860 KoTextFormat::StrikeOutType KoFontChooser::strikeOutType() const
00861 {
00862     switch (d->m_strikeOut->currentItem () )
00863     {
00864     case 0:
00865         return KoTextFormat::S_NONE;
00866         break;
00867     case 1:
00868         return KoTextFormat::S_SIMPLE;
00869         break;
00870     case 2:
00871         return KoTextFormat::S_SIMPLE_BOLD;
00872         break;
00873     case 3:
00874         return KoTextFormat::S_DOUBLE;
00875         break;
00876     default:
00877         return KoTextFormat::S_NONE;
00878     }
00879 }
00880 
00881 
00882 void KoFontChooser::setStrikeOutlineType(KoTextFormat::StrikeOutType nb)
00883 {
00884     switch ( nb )
00885     {
00886     case KoTextFormat::S_NONE:
00887         d->m_strikeOut->setCurrentItem(0);
00888         break;
00889     case KoTextFormat::S_SIMPLE:
00890          d->m_strikeOut->setCurrentItem(1);
00891         break;
00892     case KoTextFormat::S_SIMPLE_BOLD:
00893         d->m_strikeOut->setCurrentItem(2);
00894         break;
00895     case KoTextFormat::S_DOUBLE:
00896          d->m_strikeOut->setCurrentItem(3);
00897         break;
00898     }
00899     m_strikeOutType->setEnabled( d->m_strikeOut->currentItem()!= 0);
00900     d->m_wordByWord->setEnabled( ( d->m_strikeOut->currentItem()!= 0 ) || ( m_underlining->currentItem()!=0 ));
00901 
00902     m_changedFlags = 0;
00903 }
00904 
00905 
00906 void KoFontChooser::setUnderlineType(KoTextFormat::UnderlineType nb)
00907 {
00908     switch ( nb )
00909     {
00910     case KoTextFormat::U_NONE:
00911         m_underlining->setCurrentItem(0);
00912         break;
00913     case KoTextFormat::U_SIMPLE:
00914         m_underlining->setCurrentItem(1);
00915         break;
00916     case KoTextFormat::U_SIMPLE_BOLD:
00917         m_underlining->setCurrentItem(2);
00918         break;
00919     case KoTextFormat::U_DOUBLE:
00920         m_underlining->setCurrentItem(3);
00921         break;
00922     case KoTextFormat::U_WAVE:
00923         m_underlining->setCurrentItem(4);
00924         break;
00925     default:
00926         m_underlining->setCurrentItem(0);
00927         break;
00928     }
00929     m_changedFlags = 0;
00930 }
00931 
00932 void KoFontChooser::setUnderlineStyle(KoTextFormat::UnderlineStyle _t)
00933 {
00934     switch ( _t )
00935     {
00936     case KoTextFormat::U_SOLID:
00937         m_underlineType->setCurrentItem( 0 );
00938         break;
00939     case KoTextFormat::U_DASH:
00940         m_underlineType->setCurrentItem( 1 );
00941         break;
00942     case KoTextFormat::U_DOT:
00943         m_underlineType->setCurrentItem( 2 );
00944         break;
00945     case KoTextFormat::U_DASH_DOT:
00946         m_underlineType->setCurrentItem( 3 );
00947         break;
00948     case KoTextFormat::U_DASH_DOT_DOT:
00949         m_underlineType->setCurrentItem( 4 );
00950         break;
00951     default:
00952         m_underlineType->setCurrentItem( 0 );
00953         break;
00954     }
00955     m_underlineType->setEnabled( m_underlining->currentItem()!= 0);
00956     m_underlineColorButton->setEnabled( m_underlining->currentItem()!=0);
00957 
00958     d->m_wordByWord->setEnabled( ( d->m_strikeOut->currentItem()!= 0 ) || ( m_underlining->currentItem()!=0 ));
00959 
00960     m_changedFlags = 0;
00961 }
00962 
00963 void KoFontChooser::setStrikeOutStyle(KoTextFormat::StrikeOutStyle _t)
00964 {
00965     switch ( _t )
00966     {
00967     case KoTextFormat::S_NONE:
00968         m_strikeOutType->setCurrentItem( 0 );
00969         break;
00970     case KoTextFormat::S_DASH:
00971         m_strikeOutType->setCurrentItem( 1 );
00972         break;
00973     case KoTextFormat::S_DOT:
00974         m_strikeOutType->setCurrentItem( 2 );
00975         break;
00976     case KoTextFormat::S_DASH_DOT:
00977         m_strikeOutType->setCurrentItem( 3 );
00978         break;
00979     case KoTextFormat::S_DASH_DOT_DOT:
00980         m_strikeOutType->setCurrentItem( 4 );
00981         break;
00982     default:
00983         m_strikeOutType->setCurrentItem( 0 );
00984         break;
00985     }
00986     m_changedFlags = 0;
00987 }
00988 
00989 KoTextFormat::UnderlineStyle KoFontChooser::underlineStyle() const
00990 {
00991     switch ( m_underlineType->currentItem() )
00992     {
00993     case 0:
00994         return KoTextFormat::U_SOLID;
00995         break;
00996     case 1:
00997         return KoTextFormat::U_DASH;
00998         break;
00999     case 2:
01000         return KoTextFormat::U_DOT;
01001         break;
01002     case 3:
01003         return KoTextFormat::U_DASH_DOT;
01004         break;
01005     case 4:
01006         return KoTextFormat::U_DASH_DOT_DOT;
01007         break;
01008     default:
01009         return KoTextFormat::U_SOLID;
01010     }
01011 }
01012 
01013 KoTextFormat::StrikeOutStyle KoFontChooser::strikeOutStyle() const
01014 {
01015 
01016     switch ( m_strikeOutType->currentItem() )
01017     {
01018     case 0:
01019         return KoTextFormat::S_SOLID;
01020         break;
01021     case 1:
01022         return KoTextFormat::S_DASH;
01023         break;
01024     case 2:
01025         return KoTextFormat::S_DOT;
01026         break;
01027     case 3:
01028         return KoTextFormat::S_DASH_DOT;
01029         break;
01030     case 4:
01031         return KoTextFormat::S_DASH_DOT_DOT;
01032         break;
01033     default:
01034         return KoTextFormat::S_SOLID;
01035     }
01036 }
01037 
01038 
01039 void KoFontChooser::slotChangeUnderlineType( int /*i*/)
01040 {
01041     m_changedFlags |= KoTextFormat::ExtendUnderLine;
01042 }
01043 
01044 void KoFontChooser::slotChangeUnderlining( int i)
01045 {
01046     m_changedFlags |= KoTextFormat::ExtendUnderLine;
01047     m_underlineType->setEnabled( i!= 0);
01048     m_underlineColorButton->setEnabled( i!=0);
01049     d->m_wordByWord->setEnabled( ( d->m_strikeOut->currentItem()!= 0 ) || ( i !=0 ));
01050 
01051 }
01052 
01053 void KoFontChooser::slotChangeStrikeOutType( int /*i*/ )
01054 {
01055     m_changedFlags |= KoTextFormat::StrikeOut;
01056 }
01057 
01058 
01059 void KoFontChooser::setShadow( double shadowDistanceX, double shadowDistanceY, const QColor& shadowColor )
01060 {
01061     d->m_shadowWidget->setShadow( shadowDistanceX, shadowDistanceY, shadowColor );
01062 }
01063 
01064 double KoFontChooser::shadowDistanceX() const
01065 {
01066     return d->m_shadowWidget->shadowDistanceX();
01067 }
01068 
01069 double KoFontChooser::shadowDistanceY() const
01070 {
01071     return d->m_shadowWidget->shadowDistanceY();
01072 }
01073 
01074 QColor KoFontChooser::shadowColor() const
01075 {
01076     return d->m_shadowWidget->shadowColor();
01077 }
01078 
01079 void KoFontChooser::setFormat( const KoTextFormat& format )
01080 {
01081     setFont( format.font(),
01082                         format.vAlign() & KoTextFormat::AlignSubScript,
01083                         format.vAlign() & KoTextFormat::AlignSuperScript );
01084     setColor( format.color() );
01085     setBackGroundColor( format.textBackgroundColor() );
01086     setUnderlineColor( format.textUnderlineColor() );
01087 
01088     setUnderlineType( format.underlineType() );
01089     setUnderlineStyle( format.underlineStyle() );
01090 
01091     setStrikeOutlineType( format.strikeOutType() );
01092     setStrikeOutStyle( format.strikeOutStyle() );
01093 
01094     setShadow( format.shadowDistanceX(), format.shadowDistanceY(), format.shadowColor() );
01095 
01096     setWordByWord( format.wordByWord() );
01097     setRelativeTextSize( format.relativeTextSize() );
01098     setOffsetFromBaseLine( format.offsetFromBaseLine() );
01099     setFontAttribute( format.attributeFont() );
01100     setLanguage( format.language() );
01101 
01102     setHyphenation( format.hyphenation() );
01103 
01104     updatePositionButton();
01105 }
01106 
01107 KoTextFormat KoFontChooser::newFormat() const
01108 {
01109     return KoTextFormat( newFont(),
01110                          vAlign(),
01111                          color(),
01112                          backGroundColor(),
01113                          underlineColor(),
01114                          underlineType(),
01115                          underlineStyle(),
01116                          strikeOutType(),
01117                          strikeOutStyle(),
01118                          fontAttribute(),
01119                          language(),
01120                          relativeTextSize(),
01121                          offsetFromBaseLine(),
01122                          wordByWord(),
01123                          hyphenation(),
01124                          shadowDistanceX(),
01125                          shadowDistanceY(),
01126                          shadowColor() );
01127 }
01128 
01130 
01131 KoFontDia::KoFontDia( const KoTextFormat& initialFormat, QWidget* parent, const char* name )
01132     : KDialogBase( parent, name, true,
01133                    i18n("Select Font"), Ok|Cancel|User1|Apply, Ok ),
01134       m_initialFormat(initialFormat)
01135 {
01136     m_chooser = new KoFontChooser( this, "kofontchooser", true /*_withSubSuperScript*/,
01137                                    KFontChooser::SmoothScalableFonts);
01138     init();
01139 }
01140 
01141 #ifdef HAVE_LIBKSPELL2
01142 KoFontDia::KoFontDia( const KoTextFormat& initialFormat,
01143                       KSpell2::Broker::Ptr broker,
01144                       QWidget* parent, const char* name )
01145     : KDialogBase( parent, name, true,
01146                    i18n("Select Font"), Ok|Cancel|User1|Apply, Ok ),
01147       m_initialFormat(initialFormat)
01148 {
01149     m_chooser = new KoFontChooser( this, "kofontchooser", true /*_withSubSuperScript*/,
01150                                    KFontChooser::SmoothScalableFonts, broker );
01151     init();
01152 }
01153 #endif
01154 
01155 void KoFontDia::init()
01156 {
01157     setButtonText( KDialogBase::User1, i18n("&Reset") );
01158 
01159     setMainWidget( m_chooser );
01160     connect( this, SIGNAL( user1Clicked() ), this, SLOT(slotReset()) );
01161 
01162     slotReset();
01163 }
01164 
01165 void KoFontDia::slotApply()
01166 {
01167     emit applyFont();
01168 }
01169 
01170 void KoFontDia::slotOk()
01171 {
01172     slotApply();
01173     KDialogBase::slotOk();
01174 }
01175 
01176 void KoFontDia::slotReset()
01177 {
01178     m_chooser->setFormat( m_initialFormat );
01179 }
01180 
01181 #include "koFontDia.moc"
01182 #include "koFontDia_p.moc"
KDE Logo
This file is part of the documentation for lib Library Version 1.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Feb 13 09:40:01 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003