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