1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
|
/* This file is part of the KDE project
Copyright (C) 2001 Andrea Rizzi <[email protected]>
Ulrich Kuettler <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <tqvariant.h> // first for gcc 2.7.2
#include <tqbuttongroup.h>
#include <tqcheckbox.h>
#include <tqgroupbox.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqmap.h>
#include <tqradiobutton.h>
#include <tqspinbox.h>
#include <tqstringlist.h>
#include <tqvbox.h>
#include <tqwidget.h>
//#include <algorithm>
#include <kcolorbutton.h>
#include <kconfig.h>
#include <kdebug.h>
#include <kdialog.h>
#include <kfontdialog.h>
#include <klistview.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <knuminput.h>
#include <kpushbutton.h>
#include "contextstyle.h"
#include "kformulaconfigpage.h"
#include "kformuladocument.h"
#include "symboltable.h"
KFORMULA_NAMESPACE_BEGIN
ConfigurePage::ConfigurePage( Document* document, TQWidget* view, KConfig* config, TQVBox* box, char* name )
: TQObject( box->parent(), name ), m_document( document ), m_view( view ), m_config( config ), m_changed( false )
{
const ContextStyle& contextStyle = document->getContextStyle( true );
// fonts
TQGroupBox *gbox = new TQGroupBox( i18n( "Fonts" ), box );
gbox->setColumnLayout( 0, Qt::Horizontal );
TQGridLayout* grid = new TQGridLayout( gbox->tqlayout(), 5, 3 );
grid->setSpacing( KDialog::spacingHint() );
grid->setColStretch(1, 1);
defaultFont = contextStyle.getDefaultFont();
nameFont = contextStyle.getNameFont();
numberFont = contextStyle.getNumberFont();
operatorFont = contextStyle.getOperatorFont();
connect( buildFontLine( gbox, grid, 0, defaultFont,
i18n( "Default font:" ), defaultFontName ),
TQT_SIGNAL( clicked() ), TQT_SLOT( selectNewDefaultFont() ) );
connect( buildFontLine( gbox, grid, 1, nameFont,
i18n( "Name font:" ), nameFontName ),
TQT_SIGNAL( clicked() ), TQT_SLOT( selectNewNameFont() ) );
connect( buildFontLine( gbox, grid, 2, numberFont,
i18n( "Number font:" ), numberFontName ),
TQT_SIGNAL( clicked() ), TQT_SLOT( selectNewNumberFont() ) );
connect( buildFontLine( gbox, grid, 3, operatorFont,
i18n( "Operator font:" ), operatorFontName ),
TQT_SIGNAL( clicked() ), TQT_SLOT( selectNewOperatorFont() ) );
TQLabel* sizeTitle = new TQLabel( i18n( "Default base size:" ), gbox );
grid->addWidget( sizeTitle, 4, 0 );
sizeSpin = new KIntNumInput( contextStyle.baseSize(), gbox );
sizeSpin->setRange( 8, 72, 1, true );
grid->addMultiCellWidget( sizeSpin, 4, 4, 1, 2 );
connect( sizeSpin, TQT_SIGNAL( valueChanged( int ) ),
TQT_SLOT( baseSizeChanged( int ) ) );
// syntax highlighting
syntaxHighlighting = new TQCheckBox( i18n( "Use syntax highlighting" ),box );
syntaxHighlighting->setChecked( contextStyle.syntaxHighlighting() );
// hlBox = new TQGroupBox( i18n( "Highlight Colors" ), box );
// hlBox->setColumnLayout( 0, Qt::Horizontal );
// grid = new TQGridLayout( hlBox->tqlayout(), 5, 2 );
// grid->setSpacing( KDialog::spacingHint() );
// TQLabel* defaultLabel = new TQLabel( hlBox, "defaultLabel" );
// defaultLabel->setText( i18n( "Default color:" ) );
// grid->addWidget( defaultLabel, 0, 0 );
// defaultColorBtn = new KColorButton( hlBox, "defaultColor" );
// defaultColorBtn->setColor( contextStyle.getDefaultColor() );
// grid->addWidget( defaultColorBtn, 0, 1 );
// TQLabel* numberLabel = new TQLabel( hlBox, "numberLabel" );
// numberLabel->setText( i18n( "Number color:" ) );
// grid->addWidget( numberLabel, 1, 0 );
// numberColorBtn = new KColorButton( hlBox, "numberColor" );
// numberColorBtn->setColor( contextStyle.getNumberColorPlain() );
// grid->addWidget( numberColorBtn, 1, 1 );
// TQLabel* operatorLabel = new TQLabel( hlBox, "operatorLabel" );
// operatorLabel->setText( i18n( "Operator color:" ) );
// grid->addWidget( operatorLabel, 2, 0 );
// operatorColorBtn = new KColorButton( hlBox, "operatorColor" );
// operatorColorBtn->setColor( contextStyle.getOperatorColorPlain() );
// grid->addWidget( operatorColorBtn, 2, 1 );
// TQLabel* emptyLabel = new TQLabel( hlBox, "emptyLabel" );
// emptyLabel->setText( i18n( "Empty color:" ) );
// grid->addWidget( emptyLabel, 3, 0 );
// emptyColorBtn = new KColorButton( hlBox, "emptyColor" );
// emptyColorBtn->setColor( contextStyle.getEmptyColorPlain() );
// grid->addWidget( emptyColorBtn, 3, 1 );
// TQLabel* errorLabel = new TQLabel( hlBox, "errorLabel" );
// errorLabel->setText( i18n( "Error color:" ) );
// grid->addWidget( errorLabel, 4, 0 );
// errorColorBtn = new KColorButton( hlBox, "errorColor" );
// errorColorBtn->setColor( contextStyle.getErrorColorPlain() );
// grid->addWidget( errorColorBtn, 4, 1 );
connect( syntaxHighlighting, TQT_SIGNAL( clicked() ),
TQT_SLOT( syntaxHighlightingClicked() ) );
syntaxHighlightingClicked();
connect( syntaxHighlighting, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotChanged() ) );
connect( sizeSpin, TQT_SIGNAL( valueChanged( int ) ), this, TQT_SLOT( slotChanged() ) );
Q_ASSERT( !m_changed );
}
TQPushButton* ConfigurePage::buildFontLine( TQWidget* parent,
TQGridLayout* tqlayout, int number, TQFont font, TQString name,
TQLabel*& fontName )
{
TQLabel* fontTitle = new TQLabel( name, parent );
TQString labelName = font.family() + ' ' + TQString::number( font.pointSize() );
fontName = new TQLabel( labelName, parent );
fontName->setFont( font );
fontName->setFrameStyle(TQFrame::StyledPanel | TQFrame::Sunken);
TQPushButton* chooseButton = new TQPushButton( i18n( "Choose..." ), parent );
tqlayout->addWidget( fontTitle, number, 0 );
tqlayout->addWidget( fontName, number, 1 );
tqlayout->addWidget( chooseButton, number, 2 );
return chooseButton;
}
void ConfigurePage::apply()
{
if ( !m_changed )
return;
ContextStyle& contextStyle = m_document->getContextStyle( true );
contextStyle.setDefaultFont( defaultFont );
contextStyle.setNameFont( nameFont );
contextStyle.setNumberFont( numberFont );
contextStyle.setOperatorFont( operatorFont );
contextStyle.setBaseSize( sizeSpin->value() );
contextStyle.setSyntaxHighlighting( syntaxHighlighting->isChecked() );
// contextStyle.setDefaultColor( defaultColorBtn->color() );
// contextStyle.setNumberColor( numberColorBtn->color() );
// contextStyle.setOperatorColor( operatorColorBtn->color() );
// contextStyle.setEmptyColor( emptyColorBtn->color() );
// contextStyle.setErrorColor( errorColorBtn->color() );
m_config->setGroup( "kformula Font" );
m_config->writeEntry( "defaultFont", TQString(defaultFont.toString()) );
m_config->writeEntry( "nameFont", TQString(nameFont.toString()) );
m_config->writeEntry( "numberFont", TQString(numberFont.toString()) );
m_config->writeEntry( "operatorFont", TQString(operatorFont.toString()) );
m_config->writeEntry( "baseSize", TQString::number( sizeSpin->value() ) );
// m_config->setGroup( "kformula Color" );
// m_config->writeEntry( "syntaxHighlighting", syntaxHighlighting->isChecked() );
// m_config->writeEntry( "defaultColor", defaultColorBtn->color() );
// m_config->writeEntry( "numberColor", numberColorBtn->color() );
// m_config->writeEntry( "operatorColor", operatorColorBtn->color() );
// m_config->writeEntry( "emptyColor", emptyColorBtn->color() );
// m_config->writeEntry( "errorColor", errorColorBtn->color() );
// notify!!!
m_document->updateConfig();
m_changed = false;
}
void ConfigurePage::slotDefault()
{
defaultFont = TQFont( "Times", 12, TQFont::Normal, true );
nameFont = TQFont( "Times" );
numberFont = nameFont;
operatorFont = nameFont;
sizeSpin->setValue( 20 );
updateFontLabel( defaultFont, defaultFontName );
updateFontLabel( nameFont, nameFontName );
updateFontLabel( numberFont, numberFontName );
updateFontLabel( operatorFont, operatorFontName );
syntaxHighlighting->setChecked( true );
syntaxHighlightingClicked();
// defaultColorBtn->setColor( TQt::black );
// numberColorBtn->setColor( TQt::blue );
// operatorColorBtn->setColor( TQt::darkGreen );
// emptyColorBtn->setColor( TQt::blue );
// errorColorBtn->setColor( TQt::darkRed );
slotChanged();
}
void ConfigurePage::syntaxHighlightingClicked()
{
// bool checked = syntaxHighlighting->isChecked();
// hlBox->setEnabled( checked );
}
void ConfigurePage::selectNewDefaultFont()
{
if ( selectFont( defaultFont ) )
updateFontLabel( defaultFont, defaultFontName );
}
void ConfigurePage::selectNewNameFont()
{
if ( selectFont( nameFont ) )
updateFontLabel( nameFont, nameFontName );
}
void ConfigurePage::selectNewNumberFont()
{
if ( selectFont( numberFont ) )
updateFontLabel( numberFont, numberFontName );
}
void ConfigurePage::selectNewOperatorFont()
{
if ( selectFont( operatorFont ) )
updateFontLabel( operatorFont, operatorFontName );
}
bool ConfigurePage::selectFont( TQFont & font )
{
TQStringList list;
KFontChooser::getFontList( list, KFontChooser::SmoothScalableFonts );
KFontDialog dlg( m_view, 0, false, true, list );
dlg.setFont( font );
int result = dlg.exec();
if ( KDialog::Accepted == result ) {
font = dlg.font();
slotChanged();
return true;
}
return false;
}
void ConfigurePage::baseSizeChanged( int /*value*/ )
{
}
void ConfigurePage::updateFontLabel( TQFont font, TQLabel* label )
{
label->setText( font.family() + ' ' + TQString::number( font.pointSize() ) );
label->setFont( font );
}
void ConfigurePage::slotChanged()
{
m_changed = true;
}
// class UsedFontItem : public KListViewItem {
// public:
// UsedFontItem( MathFontsConfigurePage* page, TQListView* parent, TQString font )
// : KListViewItem( parent, font ), m_page( page ) {}
// int compare( TQListViewItem* i, int col, bool ascending ) const;
// private:
// MathFontsConfigurePage* m_page;
// };
// int UsedFontItem::compare( TQListViewItem* i, int, bool ) const
// {
// TQValueVector<TQString>::iterator lhsIt = m_page->findUsedFont( text( 0 ) );
// TQValueVector<TQString>::iterator rhsIt = m_page->findUsedFont( i->text( 0 ) );
// if ( lhsIt < rhsIt ) {
// return -1;
// }
// else if ( lhsIt > rhsIt ) {
// return 1;
// }
// return 0;
// }
// MathFontsConfigurePage::MathFontsConfigurePage( Document* document, TQWidget* view,
// KConfig* config, TQVBox* box, char* name )
// : TQObject( box->parent(), name ), m_document( document ), m_view( view ), m_config( config )
// {
// TQWidget* fontWidget = new TQWidget( box );
// TQGridLayout* fontLayout = new TQGridLayout( fontWidget, 1, 1, KDialog::marginHint(), KDialog::spacingHint() );
// TQHBoxLayout* hLayout = new TQHBoxLayout( 0, 0, 6 );
// availableFonts = new KListView( fontWidget );
// availableFonts->addColumn( i18n( "Available Fonts" ) );
// hLayout->addWidget( availableFonts );
// TQVBoxLayout* vLayout = new TQVBoxLayout( 0, 0, 6 );
// TQSpacerItem* spacer1 = new TQSpacerItem( 20, 20, TQSizePolicy::Minimum, TQSizePolicy::Expanding );
// vLayout->addItem( spacer1 );
// addFont = new KPushButton( fontWidget );
// addFont->setText( "->" );
// vLayout->addWidget( addFont );
// removeFont = new KPushButton( fontWidget );
// removeFont->setText( "<-" );
// vLayout->addWidget( removeFont );
// TQSpacerItem* spacer2 = new TQSpacerItem( 20, 20, TQSizePolicy::Minimum, TQSizePolicy::Expanding );
// vLayout->addItem( spacer2 );
// hLayout->addLayout( vLayout );
// vLayout = new TQVBoxLayout( 0, 0, 6 );
// moveUp = new KPushButton( fontWidget );
// moveUp->setText( i18n( "Up" ) );
// vLayout->addWidget( moveUp );
// requestedFonts = new KListView( fontWidget );
// requestedFonts->addColumn( i18n( "Used Fonts" ) );
// vLayout->addWidget( requestedFonts );
// moveDown = new KPushButton( fontWidget );
// moveDown->setText( i18n( "Down" ) );
// vLayout->addWidget( moveDown );
// hLayout->addLayout( vLayout );
// fontLayout->addLayout( hLayout, 0, 0 );
// // connect( availableFonts, TQT_SIGNAL( executed( TQListViewItem* ) ),
// // this, TQT_SLOT( slotAddFont() ) );
// // connect( requestedFonts, TQT_SIGNAL( executed( TQListViewItem* ) ),
// // this, TQT_SLOT( slotRemoveFont() ) );
// connect( addFont, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotAddFont() ) );
// connect( removeFont, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotRemoveFont() ) );
// connect( moveUp, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotMoveUp() ) );
// connect( moveDown, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotMoveDown() ) );
// const ContextStyle& contextStyle = document->getContextStyle( true );
// const SymbolTable& symbolTable = contextStyle.symbolTable();
// const TQStringList& usedFonts = contextStyle.requestedFonts();
// TQMap<TQString, TQString> fontMap;
// // symbolTable.findAvailableFonts( &fontMap );
// setupLists( usedFonts );
// }
// void MathFontsConfigurePage::apply()
// {
// TQStringList strings;
// std::copy( usedFontList.begin(), usedFontList.end(), std::back_inserter( strings ) );
// m_config->setGroup( "kformula Font" );
// m_config->writeEntry( "usedMathFonts", strings );
// ContextStyle& contextStyle = m_document->getContextStyle( true );
// contextStyle.setRequestedFonts( strings );
// }
// void MathFontsConfigurePage::slotDefault()
// {
// TQStringList usedFonts;
// usedFonts.push_back( "esstixone" );
// usedFonts.push_back( "esstixtwo" );
// usedFonts.push_back( "esstixthree" );
// usedFonts.push_back( "esstixfour" );
// usedFonts.push_back( "esstixfive" );
// usedFonts.push_back( "esstixsix" );
// usedFonts.push_back( "esstixseven" );
// usedFonts.push_back( "esstixeight" );
// usedFonts.push_back( "esstixnine" );
// usedFonts.push_back( "esstixten" );
// usedFonts.push_back( "esstixeleven" );
// usedFonts.push_back( "esstixtwelve" );
// usedFonts.push_back( "esstixthirteen" );
// usedFonts.push_back( "esstixfourteen" );
// usedFonts.push_back( "esstixfifteen" );
// usedFonts.push_back( "esstixsixteen" );
// usedFonts.push_back( "esstixseventeen" );
// usedFontList.clear();
// requestedFonts->clear();
// availableFonts->clear();
// setupLists( usedFonts );
// }
// TQValueVector<TQString>::iterator MathFontsConfigurePage::findUsedFont( TQString name )
// {
// return std::find( usedFontList.begin(), usedFontList.end(), name );
// }
// void MathFontsConfigurePage::setupLists( const TQStringList& usedFonts )
// {
// const ContextStyle& contextStyle = m_document->getContextStyle( true );
// const SymbolTable& symbolTable = contextStyle.symbolTable();
// TQMap<TQString, TQString> fontMap;
// // symbolTable.findAvailableFonts( &fontMap );
// for ( TQStringList::const_iterator it = usedFonts.begin(); it != usedFonts.end(); ++it ) {
// TQMap<TQString, TQString>::iterator font = fontMap.find( *it );
// if ( font != fontMap.end() ) {
// fontMap.erase( font );
// new UsedFontItem( this, requestedFonts, *it );
// usedFontList.push_back( *it );
// }
// }
// for ( TQMap<TQString, TQString>::iterator it = fontMap.begin(); it != fontMap.end(); ++it ) {
// new KListViewItem( availableFonts, it.key() );
// }
// }
// void MathFontsConfigurePage::slotAddFont()
// {
// TQListViewItem* fontItem = availableFonts->selectedItem();
// if ( fontItem ) {
// TQString fontName = fontItem->text( 0 );
// //availableFonts->takeItem( fontItem );
// delete fontItem;
// new UsedFontItem( this, requestedFonts, fontName );
// usedFontList.push_back( fontName );
// }
// }
// void MathFontsConfigurePage::slotRemoveFont()
// {
// TQListViewItem* fontItem = requestedFonts->selectedItem();
// if ( fontItem ) {
// TQString fontName = fontItem->text( 0 );
// TQValueVector<TQString>::iterator it = std::find( usedFontList.begin(), usedFontList.end(), fontName );
// if ( it != usedFontList.end() ) {
// usedFontList.erase( it );
// }
// //requestedFonts->takeItem( fontItem );
// delete fontItem;
// new KListViewItem( availableFonts, fontName );
// }
// }
// void MathFontsConfigurePage::slotMoveUp()
// {
// TQListViewItem* fontItem = requestedFonts->selectedItem();
// if ( fontItem ) {
// TQString fontName = fontItem->text( 0 );
// TQValueVector<TQString>::iterator it = std::find( usedFontList.begin(), usedFontList.end(), fontName );
// if ( it != usedFontList.end() ) {
// uint pos = it - usedFontList.begin();
// if ( pos > 0 ) {
// TQValueVector<TQString>::iterator before = it-1;
// std::swap( *it, *before );
// requestedFonts->sort();
// }
// }
// }
// }
// void MathFontsConfigurePage::slotMoveDown()
// {
// TQListViewItem* fontItem = requestedFonts->selectedItem();
// if ( fontItem ) {
// TQString fontName = fontItem->text( 0 );
// TQValueVector<TQString>::iterator it = std::find( usedFontList.begin(), usedFontList.end(), fontName );
// if ( it != usedFontList.end() ) {
// uint pos = it - usedFontList.begin();
// if ( pos < usedFontList.size()-1 ) {
// TQValueVector<TQString>::iterator after = it+1;
// std::swap( *it, *after );
// requestedFonts->sort();
// }
// }
// }
// }
KFORMULA_NAMESPACE_END
using namespace KFormula;
#include "kformulaconfigpage.moc"
|