lib

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