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
00052 KFORMULA_NAMESPACE_BEGIN
00053
00054
class ConfigurePage::Private
00055 {
00056
public:
00057
QCheckBox* syntaxHighlighting;
00058
bool m_changed;
00059 };
00060
00061 ConfigurePage::ConfigurePage(
Document* document,
QWidget* view, KConfig* config,
QVBox* box,
char* name )
00062 :
QObject( box->parent(), name ), m_document( document ), m_view( view ), m_config( config )
00063 {
00064 d =
new Private;
00065 d->m_changed =
false;
00066
const ContextStyle& contextStyle = document->
getContextStyle(
true );
00067
00068
00069
00070
QGroupBox *gbox =
new QGroupBox( i18n(
"Fonts" ), box );
00071 gbox->setColumnLayout( 0, Qt::Horizontal );
00072
00073
QGridLayout* grid =
new QGridLayout( gbox->layout(), 5, 3 );
00074 grid->setSpacing( KDialog::spacingHint() );
00075
00076 grid->setColStretch(1, 1);
00077
00078 defaultFont = contextStyle.
getDefaultFont();
00079 nameFont = contextStyle.
getNameFont();
00080 numberFont = contextStyle.
getNumberFont();
00081 operatorFont = contextStyle.getOperatorFont();
00082
00083 connect( buildFontLine( gbox, grid, 0, defaultFont,
00084 i18n(
"Default font:" ), defaultFontName ),
00085 SIGNAL( clicked() ), SLOT( selectNewDefaultFont() ) );
00086
00087 connect( buildFontLine( gbox, grid, 1, nameFont,
00088 i18n(
"Name font:" ), nameFontName ),
00089 SIGNAL( clicked() ), SLOT( selectNewNameFont() ) );
00090
00091 connect( buildFontLine( gbox, grid, 2, numberFont,
00092 i18n(
"Number font:" ), numberFontName ),
00093 SIGNAL( clicked() ), SLOT( selectNewNumberFont() ) );
00094
00095 connect( buildFontLine( gbox, grid, 3, operatorFont,
00096 i18n(
"Operator font:" ), operatorFontName ),
00097 SIGNAL( clicked() ), SLOT( selectNewOperatorFont() ) );
00098
00099
QLabel* sizeTitle =
new QLabel( i18n(
"Default base size:" ), gbox );
00100 grid->addWidget( sizeTitle, 4, 0 );
00101
00102 sizeSpin =
new KIntNumInput( contextStyle.
baseSize(), gbox );
00103 sizeSpin->setRange( 8, 72, 1,
true );
00104
00105 grid->addMultiCellWidget( sizeSpin, 4, 4, 1, 2 );
00106
00107 connect( sizeSpin, SIGNAL( valueChanged(
int ) ),
00108 SLOT( baseSizeChanged(
int ) ) );
00109
00110
00111
00112 d->syntaxHighlighting =
new QCheckBox( i18n(
"Use syntax highlighting" ),box );
00113 d->syntaxHighlighting->setChecked( contextStyle.
syntaxHighlighting() );
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
00162
00163
00164
00165 connect( d->syntaxHighlighting, SIGNAL( clicked() ),
00166 SLOT( syntaxHighlightingClicked() ) );
00167
00168 syntaxHighlightingClicked();
00169
00170 styleBox =
new QButtonGroup( i18n(
"Font Style" ), box );
00171 styleBox->setColumnLayout( 0, Qt::Horizontal );
00172
00173 grid =
new QGridLayout( styleBox->layout(), 3, 1 );
00174 grid->setSpacing( KDialog::spacingHint() );
00175
00176 esstixStyle =
new QRadioButton( i18n(
"Esstix font style" ), styleBox,
"esstixStyle" );
00177 esstixStyle->setChecked( contextStyle.
getFontStyle() ==
"esstix" );
00178
00179 cmStyle =
new QRadioButton( i18n(
"Computer modern (TeX) style" ), styleBox,
"cmStyle" );
00180 cmStyle->setChecked( contextStyle.
getFontStyle() ==
"tex" );
00181
00182 symbolStyle =
new QRadioButton( i18n(
"Symbol font style" ), styleBox,
"symbolStyle" );
00183 symbolStyle->setChecked( !esstixStyle->isChecked() && !cmStyle->isChecked() );
00184
00185 grid->addWidget( symbolStyle, 0, 0 );
00186 grid->addWidget( esstixStyle, 1, 0 );
00187 grid->addWidget( cmStyle, 2, 0 );
00188
00189 connect( styleBox, SIGNAL( clicked(
int ) ),
this, SLOT( slotChanged() ) );
00190 connect( d->syntaxHighlighting, SIGNAL( clicked() ),
this, SLOT( slotChanged() ) );
00191 connect( sizeSpin, SIGNAL( valueChanged(
int ) ),
this, SLOT( slotChanged() ) );
00192
00193 Q_ASSERT( !d->m_changed );
00194 }
00195
00196 ConfigurePage::~ConfigurePage()
00197 {
00198
delete d;
00199 }
00200
00201
QPushButton* ConfigurePage::buildFontLine(
QWidget* parent,
00202 QGridLayout* layout,
int number,
QFont font,
QString name,
00203 QLabel*& fontName )
00204 {
00205 QLabel* fontTitle =
new QLabel( name, parent );
00206
00207
QString labelName = font.family() +
' ' + QString::number( font.
pointSize() );
00208 fontName =
new QLabel( labelName, parent );
00209 fontName->setFont( font );
00210 fontName->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
00211
00212
QPushButton* chooseButton =
new QPushButton( i18n(
"Choose..." ), parent );
00213
00214 layout->addWidget( fontTitle, number, 0 );
00215 layout->addWidget( fontName, number, 1 );
00216 layout->addWidget( chooseButton, number, 2 );
00217
00218
return chooseButton;
00219 }
00220
00221
00222
static bool fontAvailable(
QString fontName )
00223 {
00224
QFont f( fontName );
00225
QStringList fields = QStringList::split(
'-', f.rawName() );
00226
if ( ( fields.size() > 1 ) &&
00227 ( ( fields[1].upper() == fontName.upper() ) ||
00228 ( fields[0].upper() == fontName.upper() ) ) ) {
00229
return true;
00230 }
00231
else {
00232 kdWarning(39001) <<
"Font '" << fontName <<
"' not found but '" << f.rawName() <<
"'." << endl;
00233
return false;
00234 }
00235 }
00236
00237
00238
inline void testFont(
QStringList& missing,
const QString& fontName ) {
00239
if ( !fontAvailable( fontName ) ) {
00240 missing.append( fontName );
00241 }
00242 }
00243
00244
void ConfigurePage::apply()
00245 {
00246
if ( !d->m_changed )
00247
return;
00248
QString fontStyle;
00249
if ( esstixStyle->isChecked() ) {
00250 fontStyle =
"esstix";
00251
00252
QStringList missing;
00253 testFont( missing,
"esstixeight" );
00254 testFont( missing,
"esstixeleven" );
00255 testFont( missing,
"esstixfifteen" );
00256 testFont( missing,
"esstixfive" );
00257 testFont( missing,
"esstixfour" );
00258 testFont( missing,
"esstixfourteen" );
00259 testFont( missing,
"esstixnine" );
00260 testFont( missing,
"esstixone" );
00261 testFont( missing,
"esstixseven" );
00262 testFont( missing,
"esstixseventeen" );
00263 testFont( missing,
"esstixsix" );
00264 testFont( missing,
"esstixsixteen" );
00265 testFont( missing,
"esstixten" );
00266 testFont( missing,
"esstixthirteen" );
00267 testFont( missing,
"esstixthree" );
00268 testFont( missing,
"esstixtwelve" );
00269 testFont( missing,
"esstixtwo" );
00270
00271
if ( missing.count() > 0 ) {
00272
QString text = i18n(
"The fonts '%1' are missing."
00273
" Do you want to change the font style anyway?" )
00274 .arg( missing.join(
"', '" ) );
00275
if ( KMessageBox::warningContinueCancel( m_view, text ) ==
00276 KMessageBox::Cancel ) {
00277
return;
00278 }
00279 }
00280 }
00281
else if ( cmStyle->isChecked() ) {
00282 fontStyle =
"tex";
00283
00284
QStringList missing;
00285 testFont( missing,
"cmbx10" );
00286 testFont( missing,
"cmex10" );
00287 testFont( missing,
"cmmi10" );
00288 testFont( missing,
"cmr10" );
00289 testFont( missing,
"cmsy10" );
00290 testFont( missing,
"msam10" );
00291 testFont( missing,
"msbm10" );
00292
00293
if ( missing.count() > 0 ) {
00294
QString text = i18n(
"The fonts '%1' are missing."
00295
" Do you want to change the font style anyway?" )
00296 .arg( missing.join(
"', '" ) );
00297
if ( KMessageBox::warningContinueCancel( m_view, text ) ==
00298 KMessageBox::Cancel ) {
00299
return;
00300 }
00301 }
00302 }
00303
else {
00304 fontStyle =
"symbol";
00305
00306
QStringList missing;
00307 testFont( missing,
"symbol" );
00308
00309
if ( missing.count() > 0 ) {
00310
QString text = i18n(
"The font 'symbol' is missing."
00311
" Do you want to change the font style anyway?" );
00312
if ( KMessageBox::warningContinueCancel( m_view, text ) ==
00313 KMessageBox::Cancel ) {
00314
return;
00315 }
00316
00317 }
00318 }
00319
00320
ContextStyle& contextStyle = m_document->getContextStyle(
true );
00321
00322 contextStyle.
setDefaultFont( defaultFont );
00323 contextStyle.
setNameFont( nameFont );
00324 contextStyle.
setNumberFont( numberFont );
00325 contextStyle.
setOperatorFont( operatorFont );
00326 contextStyle.
setBaseSize( sizeSpin->value() );
00327
00328 contextStyle.
setFontStyle( fontStyle );
00329
00330 contextStyle.
setSyntaxHighlighting( d->syntaxHighlighting->isChecked() );
00331
00332
00333
00334
00335
00336
00337 m_config->setGroup(
"kformula Font" );
00338 m_config->writeEntry(
"defaultFont", defaultFont.toString() );
00339 m_config->writeEntry(
"nameFont", nameFont.toString() );
00340 m_config->writeEntry(
"numberFont", numberFont.toString() );
00341 m_config->writeEntry(
"operatorFont", operatorFont.toString() );
00342 m_config->writeEntry(
"baseSize", QString::number( sizeSpin->value() ) );
00343
00344 m_config->writeEntry(
"fontStyle", fontStyle );
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355 m_document->updateConfig();
00356 d->m_changed =
false;
00357 }
00358
00359
void ConfigurePage::slotDefault()
00360 {
00361 defaultFont =
QFont(
"Times", 12, QFont::Normal,
true );
00362 nameFont = QFont(
"Times" );
00363 numberFont = nameFont;
00364 operatorFont = nameFont;
00365
00366 sizeSpin->setValue( 20 );
00367
00368 updateFontLabel( defaultFont, defaultFontName );
00369 updateFontLabel( nameFont, nameFontName );
00370 updateFontLabel( numberFont, numberFontName );
00371 updateFontLabel( operatorFont, operatorFontName );
00372
00373 symbolStyle->setChecked(
true );
00374
00375 d->syntaxHighlighting->setChecked(
true );
00376 syntaxHighlightingClicked();
00377
00378
00379
00380
00381
00382
00383 slotChanged();
00384 }
00385
00386
void ConfigurePage::syntaxHighlightingClicked()
00387 {
00388
00389
00390 }
00391
00392
void ConfigurePage::selectNewDefaultFont()
00393 {
00394
if ( selectFont( defaultFont ) )
00395 updateFontLabel( defaultFont, defaultFontName );
00396 }
00397
00398
void ConfigurePage::selectNewNameFont()
00399 {
00400
if ( selectFont( nameFont ) )
00401 updateFontLabel( nameFont, nameFontName );
00402 }
00403
00404
void ConfigurePage::selectNewNumberFont()
00405 {
00406
if ( selectFont( numberFont ) )
00407 updateFontLabel( numberFont, numberFontName );
00408 }
00409
00410
void ConfigurePage::selectNewOperatorFont()
00411 {
00412
if ( selectFont( operatorFont ) )
00413 updateFontLabel( operatorFont, operatorFontName );
00414 }
00415
00416
bool ConfigurePage::selectFont(
QFont & font )
00417 {
00418
QStringList list;
00419
00420 KFontChooser::getFontList( list, KFontChooser::SmoothScalableFonts );
00421
00422 KFontDialog dlg( m_view, 0,
false,
true, list );
00423 dlg.setFont( font );
00424
00425
int result = dlg.exec();
00426
if ( KDialog::Accepted == result ) {
00427 font = dlg.font();
00428 slotChanged();
00429
return true;
00430 }
00431
00432
return false;
00433 }
00434
00435
void ConfigurePage::baseSizeChanged(
int )
00436 {
00437 }
00438
00439
void ConfigurePage::updateFontLabel(
QFont font, QLabel* label )
00440 {
00441 label->setText( font.family() +
' ' + QString::number( font.
pointSize() ) );
00442 label->setFont( font );
00443 }
00444
00445
void ConfigurePage::slotChanged()
00446 {
00447 d->m_changed =
true;
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
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670 KFORMULA_NAMESPACE_END
00671
00672
using namespace KFormula;
00673
#include "kformulaconfigpage.moc"