00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "KoFontDia.h"
00021
00022
00023
00024
00025 #include "KoRichText.h"
00026
00027 #include <kcolordialog.h>
00028 #include <klocale.h>
00029 #include <kdebug.h>
00030
00031 #include <q3groupbox.h>
00032 #include <QPushButton>
00033 #include <QTabWidget>
00034 #include <QLabel>
00035 #include <QComboBox>
00036 #include <QRadioButton>
00037 #include <QCheckBox>
00038 #include <knuminput.h>
00039 #include <KoGlobal.h>
00040 #include <QGroupBox>
00041
00042
00043 #include <QButtonGroup>
00044 #include <kcolorbutton.h>
00045 #include <kiconloader.h>
00046 #include <kvbox.h>
00047
00048 KoFontDia::KoFontDia( const KoTextFormat& initialFormat,
00049 KSpell2::Loader::Ptr loader, QWidget* parent, const char* name )
00050 : KDialog( parent ),
00051 m_initialFormat(initialFormat),
00052 m_changedFlags(KoTextFormat::NoFlags)
00053 {
00054 setCaption(i18n("Select Font") );
00055 setModal( true );
00056 setObjectName( name );
00057 setButtons( Ok|Cancel|User1|Apply );
00058 setDefaultButton( Ok );
00059
00060 setButtonText( KDialog::User1, i18n("&Reset") );
00061
00062 KVBox *mainWidget = new KVBox( this );
00063 KHBox *mainHBox = new KHBox( mainWidget );
00064
00065 QTabWidget *fontTabWidget = new QTabWidget( mainHBox );
00066
00067
00068 fontTab = new KoFontTab( KFontChooser::SmoothScalableFonts, this );
00069 fontTabWidget->addTab( fontTab, i18n( "Font" ) );
00070
00071 connect( fontTab, SIGNAL( familyChanged() ), this, SLOT( slotFontFamilyChanged() ) );
00072 connect( fontTab, SIGNAL( boldChanged() ), this, SLOT( slotFontBoldChanged() ) );
00073 connect( fontTab, SIGNAL( italicChanged() ), this, SLOT( slotFontItalicChanged() ) );
00074 connect( fontTab, SIGNAL( sizeChanged() ), this, SLOT( slotFontSizeChanged() ) );
00075
00076
00077 highlightingTab = new KoHighlightingTab( this );
00078 fontTabWidget->addTab( highlightingTab, i18n( "Highlighting" ) );
00079
00080 connect( highlightingTab, SIGNAL( underlineChanged( int ) ), this, SLOT( slotUnderlineChanged( int ) ) );
00081 connect( highlightingTab, SIGNAL( underlineStyleChanged( int ) ), this, SLOT( slotUnderlineStyleChanged( int ) ) );
00082 connect( highlightingTab, SIGNAL( underlineColorChanged( const QColor & ) ), this, SLOT( slotUnderlineColorChanged( const QColor & ) ) );
00083 connect( highlightingTab, SIGNAL( strikethroughChanged( int ) ), this, SLOT( slotStrikethroughChanged( int ) ) );
00084 connect( highlightingTab, SIGNAL( strikethroughStyleChanged( int ) ), this, SLOT( slotStrikethroughStyleChanged( int ) ) );
00085 connect( highlightingTab, SIGNAL( wordByWordChanged( bool ) ), this, SLOT( slotWordByWordChanged( bool ) ) );
00086 connect( highlightingTab, SIGNAL( capitalisationChanged( int ) ), this, SLOT( slotCapitalisationChanged( int ) ) );
00087
00088
00089 decorationTab = new KoDecorationTab( this );
00090 fontTabWidget->addTab( decorationTab, i18n( "Decoration" ) );
00091
00092 connect( decorationTab, SIGNAL( fontColorChanged( const QColor& ) ), this, SLOT( slotFontColorChanged( const QColor& ) ) );
00093 connect( decorationTab, SIGNAL( backgroundColorChanged( const QColor& ) ), this, SLOT( slotBackgroundColorChanged( const QColor& ) ) );
00094 connect( decorationTab, SIGNAL( shadowColorChanged( const QColor& ) ), this, SLOT( slotShadowColorChanged( const QColor& ) ) );
00095 connect( decorationTab, SIGNAL( shadowDistanceChanged( double ) ), this, SLOT( slotShadowDistanceChanged( double ) ) );
00096 connect( decorationTab, SIGNAL( shadowDirectionChanged( int ) ), this, SLOT( slotShadowDirectionChanged( int ) ) );
00097
00098
00099 layoutTab = new KoLayoutTab( true, this );
00100 fontTabWidget->addTab( layoutTab, i18n( "Layout" ) );
00101 connect( layoutTab, SIGNAL( subSuperScriptChanged() ), this, SLOT( slotSubSuperChanged() ) );;
00102 connect( layoutTab, SIGNAL( offsetChanged( int ) ), this, SLOT( slotOffsetChanged( int ) ) );
00103 connect( layoutTab, SIGNAL( relativeSizeChanged( double ) ), this, SLOT( slotRelativeSizeChanged( double ) ) );
00104 connect( layoutTab, SIGNAL( hyphenationChanged( bool ) ), this, SLOT( slotHyphenationChanged( bool ) ) );
00105
00106
00107 languageTab = new KoLanguageTab( loader, this );
00108 fontTabWidget->addTab( languageTab, i18n( "Language" ) );
00109 connect( languageTab, SIGNAL( languageChanged() ), this, SLOT( slotLanguageChanged() ) );
00110
00111
00112
00113
00114
00115 fontDiaPreview = new KoFontDiaPreview( mainWidget );
00116
00117 setMainWidget( mainWidget );
00118
00119 init();
00120 }
00121
00122 void KoFontDia::init()
00123 {
00124 connect( this, SIGNAL( user1Clicked() ), this, SLOT(slotReset()) );
00125
00126 slotReset();
00127 }
00128
00129 KoTextFormat KoFontDia::newFormat() const
00130 {
00131 return KoTextFormat( fontTab->getSelection(),
00132 layoutTab->getSubSuperScript(),
00133 decorationTab->getTextColor(),
00134 decorationTab->getBackgroundColor(),
00135 highlightingTab->getUnderlineColor(),
00136 highlightingTab->getUnderline(),
00137 highlightingTab->getUnderlineStyle(),
00138 highlightingTab->getStrikethrough(),
00139 highlightingTab->getStrikethroughStyle(),
00140 highlightingTab->getCapitalisation(),
00141 languageTab->getLanguage(),
00142 layoutTab->getRelativeTextSize(),
00143 layoutTab->getOffsetFromBaseline(),
00144 highlightingTab->getWordByWord(),
00145 layoutTab->getAutoHyphenation(),
00146 decorationTab->getShadowDistanceX(),
00147 decorationTab->getShadowDistanceY(),
00148 decorationTab->getShadowColor()
00149 );
00150 }
00151
00152 void KoFontDia::slotApply()
00153 {
00154 emit applyFont();
00155 }
00156
00157 void KoFontDia::slotOk()
00158 {
00159 slotApply();
00160 slotButtonClicked( Ok );
00161 }
00162
00163 void KoFontDia::slotReset()
00164 {
00165 fontTab->setSelection( m_initialFormat.font() );
00166 highlightingTab->setUnderline( m_initialFormat.underlineType() );
00167 highlightingTab->setUnderlineStyle( m_initialFormat.underlineStyle() );
00168 highlightingTab->setUnderlineColor( m_initialFormat.textUnderlineColor() );
00169 highlightingTab->setStrikethrough( m_initialFormat.strikeOutType() );
00170 highlightingTab->setStrikethroughStyle( m_initialFormat.strikeOutStyle() );
00171 highlightingTab->setWordByWord( m_initialFormat.wordByWord() );
00172 highlightingTab->setCapitalisation( m_initialFormat.attributeFont() );
00173 decorationTab->setTextColor( m_initialFormat.color() );
00174 decorationTab->setBackgroundColor( m_initialFormat.textBackgroundColor() );
00175 decorationTab->setShadow( m_initialFormat.shadowDistanceX(), m_initialFormat.shadowDistanceY(), m_initialFormat.shadowColor() );
00176 layoutTab->setSubSuperScript( m_initialFormat.vAlign(), m_initialFormat.offsetFromBaseLine(), m_initialFormat.relativeTextSize() );
00177 layoutTab->setAutoHyphenation( m_initialFormat.hyphenation() );
00178 languageTab->setLanguage( m_initialFormat.language() );
00179 }
00180
00181 void KoFontDia::slotFontFamilyChanged()
00182 {
00183 m_changedFlags |= KoTextFormat::Family;
00184 fontDiaPreview->setFont( fontTab->getSelection() );
00185 }
00186
00187 void KoFontDia::slotFontBoldChanged()
00188 {
00189 m_changedFlags |= KoTextFormat::Bold;
00190 fontDiaPreview->setFont( fontTab->getSelection() );
00191 }
00192
00193 void KoFontDia::slotFontItalicChanged()
00194 {
00195 m_changedFlags |= KoTextFormat::Italic;
00196 fontDiaPreview->setFont( fontTab->getSelection() );
00197 }
00198
00199 void KoFontDia::slotFontSizeChanged()
00200 {
00201 m_changedFlags |= KoTextFormat::Size;
00202 fontDiaPreview->setFont( fontTab->getSelection() );
00203 }
00204
00205 void KoFontDia::slotFontColorChanged( const QColor& color )
00206 {
00207 m_changedFlags |= KoTextFormat::Color;
00208 fontDiaPreview->setFontColor( color );
00209 }
00210
00211 void KoFontDia::slotBackgroundColorChanged( const QColor& color )
00212 {
00213 m_changedFlags |= KoTextFormat::TextBackgroundColor;
00214 fontDiaPreview->setBackgroundColor( color );
00215 }
00216
00217 void KoFontDia::slotCapitalisationChanged( int item )
00218 {
00219 m_changedFlags |= KoTextFormat::Attribute;
00220 fontDiaPreview->setCapitalisation( item );
00221 }
00222
00223 void KoFontDia::slotUnderlineChanged( int item )
00224 {
00225 m_changedFlags |= KoTextFormat::ExtendUnderLine;
00226 if ( !item ) fontDiaPreview->setUnderlining( item, 0, Qt::black, false );
00227 else fontDiaPreview->setUnderlining( item, highlightingTab->getUnderlineStyle(), highlightingTab->getUnderlineColor(), highlightingTab->getWordByWord() );
00228 }
00229
00230 void KoFontDia::slotUnderlineStyleChanged( int item )
00231 {
00232 m_changedFlags |= KoTextFormat::ExtendUnderLine;
00233 if ( !highlightingTab->getUnderline() ) fontDiaPreview->setUnderlining( 0, 0, Qt::black, false );
00234 else fontDiaPreview->setUnderlining( highlightingTab->getUnderline(), item, highlightingTab->getUnderlineColor(), highlightingTab->getWordByWord() );
00235 }
00236
00237 void KoFontDia::slotUnderlineColorChanged( const QColor &color )
00238 {
00239 m_changedFlags |= KoTextFormat::ExtendUnderLine;
00240 if ( !highlightingTab->getUnderline() ) fontDiaPreview->setUnderlining( 0, 0, Qt::black, false );
00241 else fontDiaPreview->setUnderlining( highlightingTab->getUnderline(), highlightingTab->getUnderlineStyle(), color, highlightingTab->getWordByWord() );
00242 }
00243
00244 void KoFontDia::slotWordByWordChanged( bool state )
00245 {
00246 m_changedFlags |= KoTextFormat::WordByWord;
00247 fontDiaPreview->setWordByWord( state );
00248 }
00249
00250 void KoFontDia::slotStrikethroughChanged( int item )
00251 {
00252 m_changedFlags |= KoTextFormat::StrikeOut;
00253 if ( !item ) fontDiaPreview->setStrikethrough( item, 0, false );
00254 else fontDiaPreview->setStrikethrough( item, highlightingTab->getStrikethroughStyle(), highlightingTab->getWordByWord() );
00255 }
00256
00257 void KoFontDia::slotStrikethroughStyleChanged( int item )
00258 {
00259 m_changedFlags |= KoTextFormat::StrikeOut;
00260 if ( !highlightingTab->getStrikethrough() ) fontDiaPreview->setStrikethrough( 0, 0, false );
00261 else fontDiaPreview->setStrikethrough( highlightingTab->getStrikethrough(), item, highlightingTab->getWordByWord() );
00262 }
00263
00264 void KoFontDia::slotShadowDistanceChanged( double )
00265 {
00266 m_changedFlags |= KoTextFormat::ShadowText;
00267 fontDiaPreview->setShadow( decorationTab->getShadowDistanceX(), decorationTab->getShadowDistanceY(), decorationTab->getShadowColor() );
00268 }
00269
00270 void KoFontDia::slotShadowDirectionChanged( int )
00271 {
00272 m_changedFlags |= KoTextFormat::ShadowText;
00273 fontDiaPreview->setShadow( decorationTab->getShadowDistanceX(), decorationTab->getShadowDistanceY(), decorationTab->getShadowColor() );
00274 }
00275
00276 void KoFontDia::slotShadowColorChanged( const QColor & )
00277 {
00278 m_changedFlags |= KoTextFormat::ShadowText;
00279 fontDiaPreview->setShadow( decorationTab->getShadowDistanceX(), decorationTab->getShadowDistanceY(), decorationTab->getShadowColor() );
00280 }
00281
00282 void KoFontDia::slotSubSuperChanged()
00283 {
00284 m_changedFlags |= KoTextFormat::VAlign;
00285 fontDiaPreview->setSubSuperscript( layoutTab->getSubSuperScript(), layoutTab->getOffsetFromBaseline(), layoutTab->getRelativeTextSize() );
00286 }
00287
00288 void KoFontDia::slotOffsetChanged( int offset )
00289 {
00290 m_changedFlags |= KoTextFormat::OffsetFromBaseLine;
00291 fontDiaPreview->setSubSuperscript( layoutTab->getSubSuperScript(), offset, layoutTab->getRelativeTextSize() );
00292 }
00293
00294 void KoFontDia::slotRelativeSizeChanged( double relativeSize )
00295 {
00296 m_changedFlags |= KoTextFormat::VAlign;
00297 fontDiaPreview->setSubSuperscript( layoutTab->getSubSuperScript(), layoutTab->getOffsetFromBaseline(), relativeSize );
00298 }
00299
00300 void KoFontDia::slotHyphenationChanged( bool )
00301 {
00302 m_changedFlags |= KoTextFormat::Hyphenation;
00303 }
00304
00305 void KoFontDia::slotLanguageChanged()
00306 {
00307 m_changedFlags |= KoTextFormat::Language;
00308 }
00309
00310 #include "KoFontDia.moc"
00311