00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qvariant.h>
00022 #include <qbuttongroup.h>
00023 #include <qcheckbox.h>
00024 #include <qgroupbox.h>
00025 #include <qlabel.h>
00026 #include <qlayout.h>
00027 #include <qmap.h>
00028 #include <qradiobutton.h>
00029 #include <qspinbox.h>
00030 #include <qstringlist.h>
00031 #include <qvbox.h>
00032 #include <qwidget.h>
00033
00034
00035
00036 #include <kcolorbutton.h>
00037 #include <kconfig.h>
00038 #include <kdebug.h>
00039 #include <kdialog.h>
00040 #include <kfontdialog.h>
00041 #include <klistview.h>
00042 #include <klocale.h>
00043 #include <kmessagebox.h>
00044 #include <knuminput.h>
00045 #include <kpushbutton.h>
00046
00047 #include "contextstyle.h"
00048 #include "kformulaconfigpage.h"
00049 #include "kformuladocument.h"
00050 #include "symboltable.h"
00051 #include "esstixfontstyle.h"
00052 #include "cmstyle.h"
00053 #include "symbolfontstyle.h"
00054
00055
00056 KFORMULA_NAMESPACE_BEGIN
00057
00058
00059 ConfigurePage::ConfigurePage( Document* document, QWidget* view, KConfig* config, QVBox* box, char* name )
00060 : QObject( box->parent(), name ), m_document( document ), m_view( view ), m_config( config ), m_changed( false )
00061 {
00062 const ContextStyle& contextStyle = document->getContextStyle( true );
00063
00064
00065
00066 QGroupBox *gbox = new QGroupBox( i18n( "Fonts" ), box );
00067 gbox->setColumnLayout( 0, Qt::Horizontal );
00068
00069 QGridLayout* grid = new QGridLayout( gbox->layout(), 5, 3 );
00070 grid->setSpacing( KDialog::spacingHint() );
00071
00072 grid->setColStretch(1, 1);
00073
00074 defaultFont = contextStyle.getDefaultFont();
00075 nameFont = contextStyle.getNameFont();
00076 numberFont = contextStyle.getNumberFont();
00077 operatorFont = contextStyle.getOperatorFont();
00078
00079 connect( buildFontLine( gbox, grid, 0, defaultFont,
00080 i18n( "Default font:" ), defaultFontName ),
00081 SIGNAL( clicked() ), SLOT( selectNewDefaultFont() ) );
00082
00083 connect( buildFontLine( gbox, grid, 1, nameFont,
00084 i18n( "Name font:" ), nameFontName ),
00085 SIGNAL( clicked() ), SLOT( selectNewNameFont() ) );
00086
00087 connect( buildFontLine( gbox, grid, 2, numberFont,
00088 i18n( "Number font:" ), numberFontName ),
00089 SIGNAL( clicked() ), SLOT( selectNewNumberFont() ) );
00090
00091 connect( buildFontLine( gbox, grid, 3, operatorFont,
00092 i18n( "Operator font:" ), operatorFontName ),
00093 SIGNAL( clicked() ), SLOT( selectNewOperatorFont() ) );
00094
00095 QLabel* sizeTitle = new QLabel( i18n( "Default base size:" ), gbox );
00096 grid->addWidget( sizeTitle, 4, 0 );
00097
00098 sizeSpin = new KIntNumInput( contextStyle.baseSize(), gbox );
00099 sizeSpin->setRange( 8, 72, 1, true );
00100
00101 grid->addMultiCellWidget( sizeSpin, 4, 4, 1, 2 );
00102
00103 connect( sizeSpin, SIGNAL( valueChanged( int ) ),
00104 SLOT( baseSizeChanged( int ) ) );
00105
00106
00107
00108 syntaxHighlighting = new QCheckBox( i18n( "Use syntax highlighting" ),box );
00109 syntaxHighlighting->setChecked( contextStyle.syntaxHighlighting() );
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 connect( syntaxHighlighting, SIGNAL( clicked() ),
00162 SLOT( syntaxHighlightingClicked() ) );
00163
00164 syntaxHighlightingClicked();
00165
00166 styleBox = new QButtonGroup( i18n( "Font Style" ), box );
00167 styleBox->setColumnLayout( 0, Qt::Horizontal );
00168
00169 grid = new QGridLayout( styleBox->layout(), 3, 1 );
00170 grid->setSpacing( KDialog::spacingHint() );
00171
00172 esstixStyle = new QRadioButton( i18n( "Esstix font style" ), styleBox, "esstixStyle" );
00173 esstixStyle->setChecked( contextStyle.getFontStyle() == "esstix" );
00174
00175 cmStyle = new QRadioButton( i18n( "Computer modern (TeX) style" ), styleBox, "cmStyle" );
00176 cmStyle->setChecked( contextStyle.getFontStyle() == "tex" );
00177
00178 symbolStyle = new QRadioButton( i18n( "Symbol font style" ), styleBox, "symbolStyle" );
00179 symbolStyle->setChecked( !esstixStyle->isChecked() && !cmStyle->isChecked() );
00180
00181 grid->addWidget( symbolStyle, 0, 0 );
00182 grid->addWidget( esstixStyle, 1, 0 );
00183 grid->addWidget( cmStyle, 2, 0 );
00184
00185 connect( styleBox, SIGNAL( clicked( int ) ), this, SLOT( slotChanged() ) );
00186 connect( syntaxHighlighting, SIGNAL( clicked() ), this, SLOT( slotChanged() ) );
00187 connect( sizeSpin, SIGNAL( valueChanged( int ) ), this, SLOT( slotChanged() ) );
00188
00189 Q_ASSERT( !m_changed );
00190 }
00191
00192
00193 QPushButton* ConfigurePage::buildFontLine( QWidget* parent,
00194 QGridLayout* layout, int number, QFont font, QString name,
00195 QLabel*& fontName )
00196 {
00197 QLabel* fontTitle = new QLabel( name, parent );
00198
00199 QString labelName = font.family() + ' ' + QString::number( font.pointSize() );
00200 fontName = new QLabel( labelName, parent );
00201 fontName->setFont( font );
00202 fontName->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
00203
00204 QPushButton* chooseButton = new QPushButton( i18n( "Choose..." ), parent );
00205
00206 layout->addWidget( fontTitle, number, 0 );
00207 layout->addWidget( fontName, number, 1 );
00208 layout->addWidget( chooseButton, number, 2 );
00209
00210 return chooseButton;
00211 }
00212
00213
00214 void ConfigurePage::apply()
00215 {
00216 if ( !m_changed )
00217 return;
00218 QString fontStyle;
00219 if ( esstixStyle->isChecked() ) {
00220 fontStyle = "esstix";
00221
00222 QStringList missing = EsstixFontStyle::missingFonts();
00223
00224 if ( missing.count() > 0 ) {
00225 QString text = i18n( "The fonts '%1' are missing."
00226 " Do you want to change the font style anyway?" )
00227 .arg( missing.join( "', '" ) );
00228 if ( KMessageBox::warningContinueCancel( m_view, text ) ==
00229 KMessageBox::Cancel ) {
00230 return;
00231 }
00232 }
00233 }
00234 else if ( cmStyle->isChecked() ) {
00235 fontStyle = "tex";
00236
00237 QStringList missing = CMStyle::missingFonts();
00238
00239 if ( missing.count() > 0 && !CMStyle::m_installed) {
00240 QString text = i18n( "The fonts '%1' are missing."
00241 " Do you want to change the font style anyway?" )
00242 .arg( missing.join( "', '" ) );
00243 if ( KMessageBox::warningContinueCancel( m_view, text ) ==
00244 KMessageBox::Cancel ) {
00245 return;
00246 }
00247 }
00248 }
00249 else {
00250 fontStyle = "symbol";
00251
00252 QStringList missing = SymbolFontStyle::missingFonts();
00253
00254 if ( missing.count() > 0 ) {
00255 QString text = i18n( "The font 'symbol' is missing."
00256 " Do you want to change the font style anyway?" );
00257 if ( KMessageBox::warningContinueCancel( m_view, text ) ==
00258 KMessageBox::Cancel ) {
00259 return;
00260 }
00261
00262 }
00263 }
00264
00265 ContextStyle& contextStyle = m_document->getContextStyle( true );
00266
00267 contextStyle.setDefaultFont( defaultFont );
00268 contextStyle.setNameFont( nameFont );
00269 contextStyle.setNumberFont( numberFont );
00270 contextStyle.setOperatorFont( operatorFont );
00271 contextStyle.setBaseSize( sizeSpin->value() );
00272
00273 contextStyle.setFontStyle( fontStyle );
00274
00275 contextStyle.setSyntaxHighlighting( syntaxHighlighting->isChecked() );
00276
00277
00278
00279
00280
00281
00282 m_config->setGroup( "kformula Font" );
00283 m_config->writeEntry( "defaultFont", defaultFont.toString() );
00284 m_config->writeEntry( "nameFont", nameFont.toString() );
00285 m_config->writeEntry( "numberFont", numberFont.toString() );
00286 m_config->writeEntry( "operatorFont", operatorFont.toString() );
00287 m_config->writeEntry( "baseSize", QString::number( sizeSpin->value() ) );
00288
00289 m_config->writeEntry( "fontStyle", fontStyle );
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300 m_document->updateConfig();
00301 m_changed = false;
00302 }
00303
00304 void ConfigurePage::slotDefault()
00305 {
00306 defaultFont = QFont( "Times", 12, QFont::Normal, true );
00307 nameFont = QFont( "Times" );
00308 numberFont = nameFont;
00309 operatorFont = nameFont;
00310
00311 sizeSpin->setValue( 20 );
00312
00313 updateFontLabel( defaultFont, defaultFontName );
00314 updateFontLabel( nameFont, nameFontName );
00315 updateFontLabel( numberFont, numberFontName );
00316 updateFontLabel( operatorFont, operatorFontName );
00317
00318 symbolStyle->setChecked( true );
00319 if (CMStyle::missingFonts().isEmpty())
00320 cmStyle->setChecked( true );
00321 else if (EsstixFontStyle::missingFonts().isEmpty())
00322 esstixStyle->setChecked( true );
00323 else
00324 symbolStyle->setChecked( true );
00325
00326 syntaxHighlighting->setChecked( true );
00327 syntaxHighlightingClicked();
00328
00329
00330
00331
00332
00333
00334 slotChanged();
00335 }
00336
00337 void ConfigurePage::syntaxHighlightingClicked()
00338 {
00339
00340
00341 }
00342
00343 void ConfigurePage::selectNewDefaultFont()
00344 {
00345 if ( selectFont( defaultFont ) )
00346 updateFontLabel( defaultFont, defaultFontName );
00347 }
00348
00349 void ConfigurePage::selectNewNameFont()
00350 {
00351 if ( selectFont( nameFont ) )
00352 updateFontLabel( nameFont, nameFontName );
00353 }
00354
00355 void ConfigurePage::selectNewNumberFont()
00356 {
00357 if ( selectFont( numberFont ) )
00358 updateFontLabel( numberFont, numberFontName );
00359 }
00360
00361 void ConfigurePage::selectNewOperatorFont()
00362 {
00363 if ( selectFont( operatorFont ) )
00364 updateFontLabel( operatorFont, operatorFontName );
00365 }
00366
00367 bool ConfigurePage::selectFont( QFont & font )
00368 {
00369 QStringList list;
00370
00371 KFontChooser::getFontList( list, KFontChooser::SmoothScalableFonts );
00372
00373 KFontDialog dlg( m_view, 0, false, true, list );
00374 dlg.setFont( font );
00375
00376 int result = dlg.exec();
00377 if ( KDialog::Accepted == result ) {
00378 font = dlg.font();
00379 slotChanged();
00380 return true;
00381 }
00382
00383 return false;
00384 }
00385
00386 void ConfigurePage::baseSizeChanged( int )
00387 {
00388 }
00389
00390 void ConfigurePage::updateFontLabel( QFont font, QLabel* label )
00391 {
00392 label->setText( font.family() + ' ' + QString::number( font.pointSize() ) );
00393 label->setFont( font );
00394 }
00395
00396 void ConfigurePage::slotChanged()
00397 {
00398 m_changed = true;
00399 }
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621 KFORMULA_NAMESPACE_END
00622
00623 using namespace KFormula;
00624 #include "kformulaconfigpage.moc"