1
/* This file is part of the KDE project
2
Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org>
3
Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Library General Public License for more details.
15
You should have received a copy of the GNU Library General Public License
16
along with this library; see the file COPYING.LIB. If not, write to
17
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
Boston, MA 02111-1307, USA.
21
#include <qvariant.h> // first for gcc 2.7.2
22
#include <qbuttongroup.h>
23
#include <qcheckbox.h>
24
#include <qgroupbox.h>
28
#include <qradiobutton.h>
30
#include <qstringlist.h>
34
//#include <algorithm>
36
#include <kcolorbutton.h>
40
#include <kfontdialog.h>
41
#include <klistview.h>
43
#include <kmessagebox.h>
44
#include <knuminput.h>
45
#include <kpushbutton.h>
47
#include "contextstyle.h"
48
#include "kformulaconfigpage.h"
49
#include "kformuladocument.h"
50
#include "symboltable.h"
52
KFORMULA_NAMESPACE_BEGIN
54
class ConfigurePage::Private
57
QCheckBox* syntaxHighlighting;
61
ConfigurePage::ConfigurePage( Document* document, QWidget* view, KConfig* config, QVBox* box, char* name )
62
: QObject( box->parent(), name ), m_document( document ), m_view( view ), m_config( config )
66
const ContextStyle& contextStyle = document->getContextStyle( true );
70
QGroupBox *gbox = new QGroupBox( i18n( "Fonts" ), box );
71
gbox->setColumnLayout( 0, Qt::Horizontal );
73
QGridLayout* grid = new QGridLayout( gbox->layout(), 5, 3 );
74
grid->setSpacing( KDialog::spacingHint() );
76
grid->setColStretch(1, 1);
78
defaultFont = contextStyle.getDefaultFont();
79
nameFont = contextStyle.getNameFont();
80
numberFont = contextStyle.getNumberFont();
81
operatorFont = contextStyle.getOperatorFont();
83
connect( buildFontLine( gbox, grid, 0, defaultFont,
84
i18n( "Default font:" ), defaultFontName ),
85
SIGNAL( clicked() ), SLOT( selectNewDefaultFont() ) );
87
connect( buildFontLine( gbox, grid, 1, nameFont,
88
i18n( "Name font:" ), nameFontName ),
89
SIGNAL( clicked() ), SLOT( selectNewNameFont() ) );
91
connect( buildFontLine( gbox, grid, 2, numberFont,
92
i18n( "Number font:" ), numberFontName ),
93
SIGNAL( clicked() ), SLOT( selectNewNumberFont() ) );
95
connect( buildFontLine( gbox, grid, 3, operatorFont,
96
i18n( "Operator font:" ), operatorFontName ),
97
SIGNAL( clicked() ), SLOT( selectNewOperatorFont() ) );
99
QLabel* sizeTitle = new QLabel( i18n( "Default base size:" ), gbox );
100
grid->addWidget( sizeTitle, 4, 0 );
102
sizeSpin = new KIntNumInput( contextStyle.baseSize(), gbox );
103
sizeSpin->setRange( 8, 72, 1, true );
105
grid->addMultiCellWidget( sizeSpin, 4, 4, 1, 2 );
107
connect( sizeSpin, SIGNAL( valueChanged( int ) ),
108
SLOT( baseSizeChanged( int ) ) );
110
// syntax highlighting
112
d->syntaxHighlighting = new QCheckBox( i18n( "Use syntax highlighting" ),box );
113
d->syntaxHighlighting->setChecked( contextStyle.syntaxHighlighting() );
115
// hlBox = new QGroupBox( i18n( "Highlight Colors" ), box );
116
// hlBox->setColumnLayout( 0, Qt::Horizontal );
118
// grid = new QGridLayout( hlBox->layout(), 5, 2 );
119
// grid->setSpacing( KDialog::spacingHint() );
121
// QLabel* defaultLabel = new QLabel( hlBox, "defaultLabel" );
122
// defaultLabel->setText( i18n( "Default color:" ) );
123
// grid->addWidget( defaultLabel, 0, 0 );
125
// defaultColorBtn = new KColorButton( hlBox, "defaultColor" );
126
// defaultColorBtn->setColor( contextStyle.getDefaultColor() );
127
// grid->addWidget( defaultColorBtn, 0, 1 );
130
// QLabel* numberLabel = new QLabel( hlBox, "numberLabel" );
131
// numberLabel->setText( i18n( "Number color:" ) );
132
// grid->addWidget( numberLabel, 1, 0 );
134
// numberColorBtn = new KColorButton( hlBox, "numberColor" );
135
// numberColorBtn->setColor( contextStyle.getNumberColorPlain() );
136
// grid->addWidget( numberColorBtn, 1, 1 );
139
// QLabel* operatorLabel = new QLabel( hlBox, "operatorLabel" );
140
// operatorLabel->setText( i18n( "Operator color:" ) );
141
// grid->addWidget( operatorLabel, 2, 0 );
143
// operatorColorBtn = new KColorButton( hlBox, "operatorColor" );
144
// operatorColorBtn->setColor( contextStyle.getOperatorColorPlain() );
145
// grid->addWidget( operatorColorBtn, 2, 1 );
148
// QLabel* emptyLabel = new QLabel( hlBox, "emptyLabel" );
149
// emptyLabel->setText( i18n( "Empty color:" ) );
150
// grid->addWidget( emptyLabel, 3, 0 );
152
// emptyColorBtn = new KColorButton( hlBox, "emptyColor" );
153
// emptyColorBtn->setColor( contextStyle.getEmptyColorPlain() );
154
// grid->addWidget( emptyColorBtn, 3, 1 );
157
// QLabel* errorLabel = new QLabel( hlBox, "errorLabel" );
158
// errorLabel->setText( i18n( "Error color:" ) );
159
// grid->addWidget( errorLabel, 4, 0 );
161
// errorColorBtn = new KColorButton( hlBox, "errorColor" );
162
// errorColorBtn->setColor( contextStyle.getErrorColorPlain() );
163
// grid->addWidget( errorColorBtn, 4, 1 );
165
connect( d->syntaxHighlighting, SIGNAL( clicked() ),
166
SLOT( syntaxHighlightingClicked() ) );
168
syntaxHighlightingClicked();
170
styleBox = new QButtonGroup( i18n( "Font Style" ), box );
171
styleBox->setColumnLayout( 0, Qt::Horizontal );
173
grid = new QGridLayout( styleBox->layout(), 3, 1 );
174
grid->setSpacing( KDialog::spacingHint() );
176
esstixStyle = new QRadioButton( i18n( "Esstix font style" ), styleBox, "esstixStyle" );
177
esstixStyle->setChecked( contextStyle.getFontStyle() == "esstix" );
179
cmStyle = new QRadioButton( i18n( "Computer modern (TeX) style" ), styleBox, "cmStyle" );
180
cmStyle->setChecked( contextStyle.getFontStyle() == "tex" );
182
symbolStyle = new QRadioButton( i18n( "Symbol font style" ), styleBox, "symbolStyle" );
183
symbolStyle->setChecked( !esstixStyle->isChecked() && !cmStyle->isChecked() );
185
grid->addWidget( symbolStyle, 0, 0 );
186
grid->addWidget( esstixStyle, 1, 0 );
187
grid->addWidget( cmStyle, 2, 0 );
189
connect( styleBox, SIGNAL( clicked( int ) ), this, SLOT( slotChanged() ) );
190
connect( d->syntaxHighlighting, SIGNAL( clicked() ), this, SLOT( slotChanged() ) );
191
connect( sizeSpin, SIGNAL( valueChanged( int ) ), this, SLOT( slotChanged() ) );
193
Q_ASSERT( !d->m_changed );
196
ConfigurePage::~ConfigurePage()
201
QPushButton* ConfigurePage::buildFontLine( QWidget* parent,
202
QGridLayout* layout, int number, QFont font, QString name,
205
QLabel* fontTitle = new QLabel( name, parent );
207
QString labelName = font.family() + ' ' + QString::number( font.pointSize() );
208
fontName = new QLabel( labelName, parent );
209
fontName->setFont( font );
210
fontName->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
212
QPushButton* chooseButton = new QPushButton( i18n( "Choose..." ), parent );
214
layout->addWidget( fontTitle, number, 0 );
215
layout->addWidget( fontName, number, 1 );
216
layout->addWidget( chooseButton, number, 2 );
222
static bool fontAvailable( QString fontName )
225
QStringList fields = QStringList::split( '-', f.rawName() );
226
if ( ( fields.size() > 1 ) &&
227
( ( fields[1].upper() == fontName.upper() ) ||
228
( fields[0].upper() == fontName.upper() ) ) ) {
232
kdWarning(39001) << "Font '" << fontName << "' not found but '" << f.rawName() << "'." << endl;
238
inline void testFont( QStringList& missing, const QString& fontName ) {
239
if ( !fontAvailable( fontName ) ) {
240
missing.append( fontName );
244
void ConfigurePage::apply()
249
if ( esstixStyle->isChecked() ) {
250
fontStyle = "esstix";
253
testFont( missing, "esstixeight" );
254
testFont( missing, "esstixeleven" );
255
testFont( missing, "esstixfifteen" );
256
testFont( missing, "esstixfive" );
257
testFont( missing, "esstixfour" );
258
testFont( missing, "esstixfourteen" );
259
testFont( missing, "esstixnine" );
260
testFont( missing, "esstixone" );
261
testFont( missing, "esstixseven" );
262
testFont( missing, "esstixseventeen" );
263
testFont( missing, "esstixsix" );
264
testFont( missing, "esstixsixteen" );
265
testFont( missing, "esstixten" );
266
testFont( missing, "esstixthirteen" );
267
testFont( missing, "esstixthree" );
268
testFont( missing, "esstixtwelve" );
269
testFont( missing, "esstixtwo" );
271
if ( missing.count() > 0 ) {
272
QString text = i18n( "The fonts '%1' are missing."
273
" Do you want to change the font style anyway?" )
274
.arg( missing.join( "', '" ) );
275
if ( KMessageBox::warningContinueCancel( m_view, text ) ==
276
KMessageBox::Cancel ) {
281
else if ( cmStyle->isChecked() ) {
285
testFont( missing, "cmbx10" );
286
testFont( missing, "cmex10" );
287
testFont( missing, "cmmi10" );
288
testFont( missing, "cmr10" );
289
testFont( missing, "cmsy10" );
290
testFont( missing, "msam10" );
291
testFont( missing, "msbm10" );
293
if ( missing.count() > 0 ) {
294
QString text = i18n( "The fonts '%1' are missing."
295
" Do you want to change the font style anyway?" )
296
.arg( missing.join( "', '" ) );
297
if ( KMessageBox::warningContinueCancel( m_view, text ) ==
298
KMessageBox::Cancel ) {
303
else { // symbolStyle->isChecked ()
304
fontStyle = "symbol";
307
testFont( missing, "symbol" );
309
if ( missing.count() > 0 ) {
310
QString text = i18n( "The font 'symbol' is missing."
311
" Do you want to change the font style anyway?" );
312
if ( KMessageBox::warningContinueCancel( m_view, text ) ==
313
KMessageBox::Cancel ) {
320
ContextStyle& contextStyle = m_document->getContextStyle( true );
322
contextStyle.setDefaultFont( defaultFont );
323
contextStyle.setNameFont( nameFont );
324
contextStyle.setNumberFont( numberFont );
325
contextStyle.setOperatorFont( operatorFont );
326
contextStyle.setBaseSize( sizeSpin->value() );
328
contextStyle.setFontStyle( fontStyle );
330
contextStyle.setSyntaxHighlighting( d->syntaxHighlighting->isChecked() );
331
// contextStyle.setDefaultColor( defaultColorBtn->color() );
332
// contextStyle.setNumberColor( numberColorBtn->color() );
333
// contextStyle.setOperatorColor( operatorColorBtn->color() );
334
// contextStyle.setEmptyColor( emptyColorBtn->color() );
335
// contextStyle.setErrorColor( errorColorBtn->color() );
337
m_config->setGroup( "kformula Font" );
338
m_config->writeEntry( "defaultFont", defaultFont.toString() );
339
m_config->writeEntry( "nameFont", nameFont.toString() );
340
m_config->writeEntry( "numberFont", numberFont.toString() );
341
m_config->writeEntry( "operatorFont", operatorFont.toString() );
342
m_config->writeEntry( "baseSize", QString::number( sizeSpin->value() ) );
344
m_config->writeEntry( "fontStyle", fontStyle );
346
// m_config->setGroup( "kformula Color" );
347
// m_config->writeEntry( "syntaxHighlighting", d->syntaxHighlighting->isChecked() );
348
// m_config->writeEntry( "defaultColor", defaultColorBtn->color() );
349
// m_config->writeEntry( "numberColor", numberColorBtn->color() );
350
// m_config->writeEntry( "operatorColor", operatorColorBtn->color() );
351
// m_config->writeEntry( "emptyColor", emptyColorBtn->color() );
352
// m_config->writeEntry( "errorColor", errorColorBtn->color() );
355
m_document->updateConfig();
356
d->m_changed = false;
359
void ConfigurePage::slotDefault()
361
defaultFont = QFont( "Times", 12, QFont::Normal, true );
362
nameFont = QFont( "Times" );
363
numberFont = nameFont;
364
operatorFont = nameFont;
366
sizeSpin->setValue( 20 );
368
updateFontLabel( defaultFont, defaultFontName );
369
updateFontLabel( nameFont, nameFontName );
370
updateFontLabel( numberFont, numberFontName );
371
updateFontLabel( operatorFont, operatorFontName );
373
symbolStyle->setChecked( true );
375
d->syntaxHighlighting->setChecked( true );
376
syntaxHighlightingClicked();
378
// defaultColorBtn->setColor( Qt::black );
379
// numberColorBtn->setColor( Qt::blue );
380
// operatorColorBtn->setColor( Qt::darkGreen );
381
// emptyColorBtn->setColor( Qt::blue );
382
// errorColorBtn->setColor( Qt::darkRed );
386
void ConfigurePage::syntaxHighlightingClicked()
388
// bool checked = d->syntaxHighlighting->isChecked();
389
// hlBox->setEnabled( checked );
392
void ConfigurePage::selectNewDefaultFont()
394
if ( selectFont( defaultFont ) )
395
updateFontLabel( defaultFont, defaultFontName );
398
void ConfigurePage::selectNewNameFont()
400
if ( selectFont( nameFont ) )
401
updateFontLabel( nameFont, nameFontName );
404
void ConfigurePage::selectNewNumberFont()
406
if ( selectFont( numberFont ) )
407
updateFontLabel( numberFont, numberFontName );
410
void ConfigurePage::selectNewOperatorFont()
412
if ( selectFont( operatorFont ) )
413
updateFontLabel( operatorFont, operatorFontName );
416
bool ConfigurePage::selectFont( QFont & font )
420
KFontChooser::getFontList( list, KFontChooser::SmoothScalableFonts );
422
KFontDialog dlg( m_view, 0, false, true, list );
425
int result = dlg.exec();
426
if ( KDialog::Accepted == result ) {
435
void ConfigurePage::baseSizeChanged( int /*value*/ )
439
void ConfigurePage::updateFontLabel( QFont font, QLabel* label )
441
label->setText( font.family() + ' ' + QString::number( font.pointSize() ) );
442
label->setFont( font );
445
void ConfigurePage::slotChanged()
450
// class UsedFontItem : public KListViewItem {
452
// UsedFontItem( MathFontsConfigurePage* page, QListView* parent, QString font )
453
// : KListViewItem( parent, font ), m_page( page ) {}
455
// int compare( QListViewItem* i, int col, bool ascending ) const;
458
// MathFontsConfigurePage* m_page;
461
// int UsedFontItem::compare( QListViewItem* i, int, bool ) const
463
// QValueVector<QString>::iterator lhsIt = m_page->findUsedFont( text( 0 ) );
464
// QValueVector<QString>::iterator rhsIt = m_page->findUsedFont( i->text( 0 ) );
465
// if ( lhsIt < rhsIt ) {
468
// else if ( lhsIt > rhsIt ) {
474
// MathFontsConfigurePage::MathFontsConfigurePage( Document* document, QWidget* view,
475
// KConfig* config, QVBox* box, char* name )
476
// : QObject( box->parent(), name ), m_document( document ), m_view( view ), m_config( config )
478
// QWidget* fontWidget = new QWidget( box );
479
// QGridLayout* fontLayout = new QGridLayout( fontWidget, 1, 1, KDialog::marginHint(), KDialog::spacingHint() );
481
// QHBoxLayout* hLayout = new QHBoxLayout( 0, 0, 6 );
483
// availableFonts = new KListView( fontWidget );
484
// availableFonts->addColumn( i18n( "Available Fonts" ) );
485
// hLayout->addWidget( availableFonts );
487
// QVBoxLayout* vLayout = new QVBoxLayout( 0, 0, 6 );
488
// QSpacerItem* spacer1 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
489
// vLayout->addItem( spacer1 );
491
// addFont = new KPushButton( fontWidget );
492
// addFont->setText( "->" );
493
// vLayout->addWidget( addFont );
495
// removeFont = new KPushButton( fontWidget );
496
// removeFont->setText( "<-" );
497
// vLayout->addWidget( removeFont );
499
// QSpacerItem* spacer2 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
500
// vLayout->addItem( spacer2 );
502
// hLayout->addLayout( vLayout );
504
// vLayout = new QVBoxLayout( 0, 0, 6 );
506
// moveUp = new KPushButton( fontWidget );
507
// moveUp->setText( i18n( "Up" ) );
508
// vLayout->addWidget( moveUp );
510
// requestedFonts = new KListView( fontWidget );
511
// requestedFonts->addColumn( i18n( "Used Fonts" ) );
512
// vLayout->addWidget( requestedFonts );
514
// moveDown = new KPushButton( fontWidget );
515
// moveDown->setText( i18n( "Down" ) );
516
// vLayout->addWidget( moveDown );
518
// hLayout->addLayout( vLayout );
520
// fontLayout->addLayout( hLayout, 0, 0 );
522
// // connect( availableFonts, SIGNAL( executed( QListViewItem* ) ),
523
// // this, SLOT( slotAddFont() ) );
524
// // connect( requestedFonts, SIGNAL( executed( QListViewItem* ) ),
525
// // this, SLOT( slotRemoveFont() ) );
526
// connect( addFont, SIGNAL( clicked() ), this, SLOT( slotAddFont() ) );
527
// connect( removeFont, SIGNAL( clicked() ), this, SLOT( slotRemoveFont() ) );
528
// connect( moveUp, SIGNAL( clicked() ), this, SLOT( slotMoveUp() ) );
529
// connect( moveDown, SIGNAL( clicked() ), this, SLOT( slotMoveDown() ) );
531
// const ContextStyle& contextStyle = document->getContextStyle( true );
532
// const SymbolTable& symbolTable = contextStyle.symbolTable();
533
// const QStringList& usedFonts = contextStyle.requestedFonts();
535
// QMap<QString, QString> fontMap;
536
// // symbolTable.findAvailableFonts( &fontMap );
538
// setupLists( usedFonts );
541
// void MathFontsConfigurePage::apply()
543
// QStringList strings;
544
// std::copy( usedFontList.begin(), usedFontList.end(), std::back_inserter( strings ) );
546
// m_config->setGroup( "kformula Font" );
547
// m_config->writeEntry( "usedMathFonts", strings );
549
// ContextStyle& contextStyle = m_document->getContextStyle( true );
550
// contextStyle.setRequestedFonts( strings );
553
// void MathFontsConfigurePage::slotDefault()
555
// QStringList usedFonts;
557
// usedFonts.push_back( "esstixone" );
558
// usedFonts.push_back( "esstixtwo" );
559
// usedFonts.push_back( "esstixthree" );
560
// usedFonts.push_back( "esstixfour" );
561
// usedFonts.push_back( "esstixfive" );
562
// usedFonts.push_back( "esstixsix" );
563
// usedFonts.push_back( "esstixseven" );
564
// usedFonts.push_back( "esstixeight" );
565
// usedFonts.push_back( "esstixnine" );
566
// usedFonts.push_back( "esstixten" );
567
// usedFonts.push_back( "esstixeleven" );
568
// usedFonts.push_back( "esstixtwelve" );
569
// usedFonts.push_back( "esstixthirteen" );
570
// usedFonts.push_back( "esstixfourteen" );
571
// usedFonts.push_back( "esstixfifteen" );
572
// usedFonts.push_back( "esstixsixteen" );
573
// usedFonts.push_back( "esstixseventeen" );
575
// usedFontList.clear();
576
// requestedFonts->clear();
577
// availableFonts->clear();
579
// setupLists( usedFonts );
582
// QValueVector<QString>::iterator MathFontsConfigurePage::findUsedFont( QString name )
584
// return std::find( usedFontList.begin(), usedFontList.end(), name );
587
// void MathFontsConfigurePage::setupLists( const QStringList& usedFonts )
589
// const ContextStyle& contextStyle = m_document->getContextStyle( true );
590
// const SymbolTable& symbolTable = contextStyle.symbolTable();
592
// QMap<QString, QString> fontMap;
593
// // symbolTable.findAvailableFonts( &fontMap );
595
// for ( QStringList::const_iterator it = usedFonts.begin(); it != usedFonts.end(); ++it ) {
596
// QMap<QString, QString>::iterator font = fontMap.find( *it );
597
// if ( font != fontMap.end() ) {
598
// fontMap.erase( font );
599
// new UsedFontItem( this, requestedFonts, *it );
600
// usedFontList.push_back( *it );
603
// for ( QMap<QString, QString>::iterator it = fontMap.begin(); it != fontMap.end(); ++it ) {
604
// new KListViewItem( availableFonts, it.key() );
608
// void MathFontsConfigurePage::slotAddFont()
610
// QListViewItem* fontItem = availableFonts->selectedItem();
612
// QString fontName = fontItem->text( 0 );
613
// //availableFonts->takeItem( fontItem );
616
// new UsedFontItem( this, requestedFonts, fontName );
617
// usedFontList.push_back( fontName );
621
// void MathFontsConfigurePage::slotRemoveFont()
623
// QListViewItem* fontItem = requestedFonts->selectedItem();
625
// QString fontName = fontItem->text( 0 );
626
// QValueVector<QString>::iterator it = std::find( usedFontList.begin(), usedFontList.end(), fontName );
627
// if ( it != usedFontList.end() ) {
628
// usedFontList.erase( it );
630
// //requestedFonts->takeItem( fontItem );
632
// new KListViewItem( availableFonts, fontName );
636
// void MathFontsConfigurePage::slotMoveUp()
638
// QListViewItem* fontItem = requestedFonts->selectedItem();
640
// QString fontName = fontItem->text( 0 );
641
// QValueVector<QString>::iterator it = std::find( usedFontList.begin(), usedFontList.end(), fontName );
642
// if ( it != usedFontList.end() ) {
643
// uint pos = it - usedFontList.begin();
645
// QValueVector<QString>::iterator before = it-1;
646
// std::swap( *it, *before );
647
// requestedFonts->sort();
653
// void MathFontsConfigurePage::slotMoveDown()
655
// QListViewItem* fontItem = requestedFonts->selectedItem();
657
// QString fontName = fontItem->text( 0 );
658
// QValueVector<QString>::iterator it = std::find( usedFontList.begin(), usedFontList.end(), fontName );
659
// if ( it != usedFontList.end() ) {
660
// uint pos = it - usedFontList.begin();
661
// if ( pos < usedFontList.size()-1 ) {
662
// QValueVector<QString>::iterator after = it+1;
663
// std::swap( *it, *after );
664
// requestedFonts->sort();
670
KFORMULA_NAMESPACE_END
672
using namespace KFormula;
673
#include "kformulaconfigpage.moc"