• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

  • tdeui
tdefontdialog.cpp
1
2/*
3
4 Requires the Qt widget libraries, available at no cost at
5 http://www.troll.no
6
7 Copyright (C) 1996 Bernd Johannes Wuebben <wuebben@kde.org>
8 Copyright (c) 1999 Preston Brown <pbrown@kde.org>
9 Copyright (c) 1999 Mario Weilguni <mweilguni@kde.org>
10
11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Library General Public
13 License as published by the Free Software Foundation; either
14 version 2 of the License, or (at your option) any later version.
15
16 This library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Library General Public License for more details.
20
21 You should have received a copy of the GNU Library General Public License
22 along with this library; see the file COPYING.LIB. If not, write to
23 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 Boston, MA 02110-1301, USA.
25*/
26
27#include <config.h>
28
29#include <stdio.h>
30#include <stdlib.h>
31
32#include <tqcombobox.h>
33#include <tqcheckbox.h>
34#include <tqfile.h>
35#include <tqfont.h>
36#include <tqgroupbox.h>
37#include <tqlabel.h>
38#include <tqlayout.h>
39#include <tqscrollbar.h>
40#include <tqstringlist.h>
41#include <tqfontdatabase.h>
42#include <tqwhatsthis.h>
43#include <tqtooltip.h>
44
45#include <tdeapplication.h>
46#include <kcharsets.h>
47#include <tdeconfig.h>
48#include <kdialog.h>
49#include <tdeglobal.h>
50#include <tdeglobalsettings.h>
51#include <tqlineedit.h>
52#include <tdelistbox.h>
53#include <tdelocale.h>
54#include <tdestandarddirs.h>
55#include <kdebug.h>
56#include <knuminput.h>
57
58#include "tdefontdialog.moc"
59
60static int minimumListWidth( const TQListBox *list )
61{
62 int w=0;
63 for( uint i=0; i<list->count(); i++ )
64 {
65 int itemWidth = list->item(i)->width(list);
66 w = TQMAX(w,itemWidth);
67 }
68 if( w == 0 ) { w = 40; }
69 w += list->frameWidth() * 2;
70 w += list->verticalScrollBar()->sizeHint().width();
71 return w;
72}
73
74static int minimumListHeight( const TQListBox *list, int numVisibleEntry )
75{
76 int w = list->count() > 0 ? list->item(0)->height(list) :
77 list->fontMetrics().lineSpacing();
78
79 if( w < 0 ) { w = 10; }
80 if( numVisibleEntry <= 0 ) { numVisibleEntry = 4; }
81 return ( w * numVisibleEntry + 2 * list->frameWidth() );
82}
83
84class TDEFontChooser::TDEFontChooserPrivate
85{
86public:
87 TDEFontChooserPrivate()
88 { m_palette.setColor(TQPalette::Active, TQColorGroup::Text, TQt::black);
89 m_palette.setColor(TQPalette::Active, TQColorGroup::Base, TQt::white); }
90 TQPalette m_palette;
91};
92
93TDEFontChooser::TDEFontChooser(TQWidget *parent, const char *name,
94 bool onlyFixed, const TQStringList &fontList,
95 bool makeFrame, int visibleListSize, bool diff,
96 TQButton::ToggleState *sizeIsRelativeState )
97 : TQWidget(parent, name), usingFixed(onlyFixed)
98{
99 charsetsCombo = 0;
100
101 TQString mainWhatsThisText =
102 i18n( "Here you can choose the font to be used." );
103 TQWhatsThis::add( this, mainWhatsThisText );
104
105 d = new TDEFontChooserPrivate;
106 TQVBoxLayout *topLayout = new TQVBoxLayout( this, 0, KDialog::spacingHint() );
107 int checkBoxGap = KDialog::spacingHint() / 2;
108
109 TQWidget *page;
110 TQGridLayout *gridLayout;
111 int row = 0;
112 if( makeFrame )
113 {
114 page = new TQGroupBox( i18n("Requested Font"), this );
115 topLayout->addWidget(page);
116 gridLayout = new TQGridLayout( page, 5, 3, KDialog::marginHint(), KDialog::spacingHint() );
117 gridLayout->addRowSpacing( 0, fontMetrics().lineSpacing() );
118 row = 1;
119 }
120 else
121 {
122 page = new TQWidget( this );
123 topLayout->addWidget(page);
124 gridLayout = new TQGridLayout( page, 4, 3, 0, KDialog::spacingHint() );
125 }
126
127 //
128 // first, create the labels across the top
129 //
130 TQHBoxLayout *familyLayout = new TQHBoxLayout();
131 familyLayout->addSpacing( checkBoxGap );
132 if (diff) {
133 familyCheckbox = new TQCheckBox(i18n("Font"), page);
134 connect(familyCheckbox, TQ_SIGNAL(toggled(bool)), TQ_SLOT(toggled_checkbox()));
135 familyLayout->addWidget(familyCheckbox, 0, TQt::AlignLeft);
136 TQString familyCBToolTipText =
137 i18n("Change font family?");
138 TQString familyCBWhatsThisText =
139 i18n("Enable this checkbox to change the font family settings.");
140 TQWhatsThis::add( familyCheckbox, familyCBWhatsThisText );
141 TQToolTip::add( familyCheckbox, familyCBToolTipText );
142 familyLabel = 0;
143 } else {
144 familyCheckbox = 0;
145 familyLabel = new TQLabel( i18n("Font:"), page, "familyLabel" );
146 familyLayout->addWidget(familyLabel, 1, TQt::AlignLeft);
147 }
148 gridLayout->addLayout(familyLayout, row, 0 );
149
150 TQHBoxLayout *styleLayout = new TQHBoxLayout();
151 if (diff) {
152 styleCheckbox = new TQCheckBox(i18n("Font style"), page);
153 connect(styleCheckbox, TQ_SIGNAL(toggled(bool)), TQ_SLOT(toggled_checkbox()));
154 styleLayout->addWidget(styleCheckbox, 0, TQt::AlignLeft);
155 TQString styleCBToolTipText =
156 i18n("Change font style?");
157 TQString styleCBWhatsThisText =
158 i18n("Enable this checkbox to change the font style settings.");
159 TQWhatsThis::add( styleCheckbox, styleCBWhatsThisText );
160 TQToolTip::add( styleCheckbox, styleCBToolTipText );
161 styleLabel = 0;
162 } else {
163 styleCheckbox = 0;
164 styleLabel = new TQLabel( i18n("Font style:"), page, "styleLabel");
165 styleLayout->addWidget(styleLabel, 1, TQt::AlignLeft);
166 }
167 styleLayout->addSpacing( checkBoxGap );
168 gridLayout->addLayout(styleLayout, row, 1 );
169
170 TQHBoxLayout *sizeLayout = new TQHBoxLayout();
171 if (diff) {
172 sizeCheckbox = new TQCheckBox(i18n("Size"),page);
173 connect(sizeCheckbox, TQ_SIGNAL(toggled(bool)), TQ_SLOT(toggled_checkbox()));
174 sizeLayout->addWidget(sizeCheckbox, 0, TQt::AlignLeft);
175 TQString sizeCBToolTipText =
176 i18n("Change font size?");
177 TQString sizeCBWhatsThisText =
178 i18n("Enable this checkbox to change the font size settings.");
179 TQWhatsThis::add( sizeCheckbox, sizeCBWhatsThisText );
180 TQToolTip::add( sizeCheckbox, sizeCBToolTipText );
181 sizeLabel = 0;
182 } else {
183 sizeCheckbox = 0;
184 sizeLabel = new TQLabel( i18n("Size:"), page, "sizeLabel");
185 sizeLayout->addWidget(sizeLabel, 1, TQt::AlignLeft);
186 }
187 sizeLayout->addSpacing( checkBoxGap );
188 sizeLayout->addSpacing( checkBoxGap ); // prevent label from eating border
189 gridLayout->addLayout(sizeLayout, row, 2 );
190
191 row ++;
192
193 //
194 // now create the actual boxes that hold the info
195 //
196 familyListBox = new TDEListBox( page, "familyListBox");
197 familyListBox->setEnabled( !diff );
198 gridLayout->addWidget( familyListBox, row, 0 );
199 TQString fontFamilyWhatsThisText =
200 i18n("Here you can choose the font family to be used." );
201 TQWhatsThis::add( familyListBox, fontFamilyWhatsThisText );
202 TQWhatsThis::add(diff?(TQWidget *) familyCheckbox:(TQWidget *) familyLabel, fontFamilyWhatsThisText );
203 connect(familyListBox, TQ_SIGNAL(highlighted(const TQString &)),
204 TQ_SLOT(family_chosen_slot(const TQString &)));
205 if(!fontList.isEmpty())
206 {
207 familyListBox->insertStringList(fontList);
208 }
209 else
210 {
211 fillFamilyListBox(onlyFixed);
212 }
213
214 familyListBox->setMinimumWidth( minimumListWidth( familyListBox ) );
215 familyListBox->setMinimumHeight(
216 minimumListHeight( familyListBox, visibleListSize ) );
217
218 styleListBox = new TDEListBox( page, "styleListBox");
219 styleListBox->setEnabled( !diff );
220 gridLayout->addWidget(styleListBox, row, 1);
221 TQString fontStyleWhatsThisText =
222 i18n("Here you can choose the font style to be used." );
223 TQWhatsThis::add( styleListBox, fontStyleWhatsThisText );
224 TQWhatsThis::add(diff?(TQWidget *)styleCheckbox:(TQWidget *)styleLabel, fontFamilyWhatsThisText );
225 styleListBox->insertItem(i18n("Regular"));
226 styleListBox->insertItem(i18n("Italic"));
227 styleListBox->insertItem(i18n("Bold"));
228 styleListBox->insertItem(i18n("Bold Italic"));
229 styleListBox->setMinimumWidth( minimumListWidth( styleListBox ) );
230 styleListBox->setMinimumHeight(
231 minimumListHeight( styleListBox, visibleListSize ) );
232
233 connect(styleListBox, TQ_SIGNAL(highlighted(const TQString &)),
234 TQ_SLOT(style_chosen_slot(const TQString &)));
235
236
237 sizeListBox = new TDEListBox( page, "sizeListBox");
238 sizeOfFont = new KIntNumInput( page, "sizeOfFont");
239 sizeOfFont->setMinValue(4);
240
241 sizeListBox->setEnabled( !diff );
242 sizeOfFont->setEnabled( !diff );
243 if( sizeIsRelativeState ) {
244 TQString sizeIsRelativeCBText =
245 i18n("Relative");
246 TQString sizeIsRelativeCBToolTipText =
247 i18n("Font size<br><i>fixed</i> or <i>relative</i><br>to environment");
248 TQString sizeIsRelativeCBWhatsThisText =
249 i18n("Here you can switch between fixed font size and font size "
250 "to be calculated dynamically and adjusted to changing "
251 "environment (e.g. widget dimensions, paper size)." );
252 sizeIsRelativeCheckBox = new TQCheckBox( sizeIsRelativeCBText,
253 page,
254 "sizeIsRelativeCheckBox" );
255 sizeIsRelativeCheckBox->setTristate( diff );
256 TQGridLayout *sizeLayout2 = new TQGridLayout( 3,2, KDialog::spacingHint()/2, "sizeLayout2" );
257 gridLayout->addLayout(sizeLayout2, row, 2);
258 sizeLayout2->setColStretch( 1, 1 ); // to prevent text from eating the right border
259 sizeLayout2->addMultiCellWidget( sizeOfFont, 0, 0, 0, 1);
260 sizeLayout2->addMultiCellWidget(sizeListBox, 1,1, 0,1);
261 sizeLayout2->addWidget(sizeIsRelativeCheckBox, 2, 0, TQt::AlignLeft);
262 TQWhatsThis::add( sizeIsRelativeCheckBox, sizeIsRelativeCBWhatsThisText );
263 TQToolTip::add( sizeIsRelativeCheckBox, sizeIsRelativeCBToolTipText );
264 }
265 else {
266 sizeIsRelativeCheckBox = 0L;
267 TQGridLayout *sizeLayout2 = new TQGridLayout( 2,1, KDialog::spacingHint()/2, "sizeLayout2" );
268 gridLayout->addLayout(sizeLayout2, row, 2);
269 sizeLayout2->addWidget( sizeOfFont, 0, 0);
270 sizeLayout2->addMultiCellWidget(sizeListBox, 1,1, 0,0);
271 }
272 TQString fontSizeWhatsThisText =
273 i18n("Here you can choose the font size to be used." );
274 TQWhatsThis::add( sizeListBox, fontSizeWhatsThisText );
275 TQWhatsThis::add( diff?(TQWidget *)sizeCheckbox:(TQWidget *)sizeLabel, fontSizeWhatsThisText );
276
277 fillSizeList();
278 sizeListBox->setMinimumWidth( minimumListWidth(sizeListBox) +
279 sizeListBox->fontMetrics().maxWidth() );
280 sizeListBox->setMinimumHeight(
281 minimumListHeight( sizeListBox, visibleListSize ) );
282
283 connect( sizeOfFont, TQ_SIGNAL( valueChanged(int) ),
284 TQ_SLOT(size_value_slot(int)));
285
286 connect( sizeListBox, TQ_SIGNAL(highlighted(const TQString&)),
287 TQ_SLOT(size_chosen_slot(const TQString&)) );
288 sizeListBox->setSelected(sizeListBox->findItem(TQString::number(10)), true); // default to 10pt.
289
290 row ++;
291
292 row ++;
293 sampleEdit = new TQLineEdit( page, "sampleEdit");
294 TQFont tmpFont( TDEGlobalSettings::generalFont().family(), 64, TQFont::Black );
295 sampleEdit->setFont(tmpFont);
296 //i18n: This is a classical test phrase. (It contains all letters from A to Z.)
297 sampleEdit->setText(i18n("The Quick Brown Fox Jumps Over The Lazy Dog"));
298 sampleEdit->setMinimumHeight( sampleEdit->fontMetrics().lineSpacing() );
299 sampleEdit->setAlignment(TQt::AlignCenter);
300 gridLayout->addMultiCellWidget(sampleEdit, 4, 4, 0, 2);
301 TQString sampleEditWhatsThisText =
302 i18n("This sample text illustrates the current settings. "
303 "You may edit it to test special characters." );
304 TQWhatsThis::add( sampleEdit, sampleEditWhatsThisText );
305 connect(this, TQ_SIGNAL(fontSelected(const TQFont &)),
306 TQ_SLOT(displaySample(const TQFont &)));
307
308 TQVBoxLayout *vbox;
309 if( makeFrame )
310 {
311 page = new TQGroupBox( i18n("Actual Font"), this );
312 topLayout->addWidget(page);
313 vbox = new TQVBoxLayout( page, KDialog::spacingHint() );
314 vbox->addSpacing( fontMetrics().lineSpacing() );
315 }
316 else
317 {
318 page = new TQWidget( this );
319 topLayout->addWidget(page);
320 vbox = new TQVBoxLayout( page, 0, KDialog::spacingHint() );
321 TQLabel *label = new TQLabel( i18n("Actual Font"), page );
322 vbox->addWidget( label );
323 }
324
325 xlfdEdit = new TQLineEdit( page, "xlfdEdit" );
326 vbox->addWidget( xlfdEdit );
327
328 // lets initialize the display if possible
329 setFont( TDEGlobalSettings::generalFont(), usingFixed );
330 // check or uncheck or gray out the "relative" checkbox
331 if( sizeIsRelativeState && sizeIsRelativeCheckBox )
332 setSizeIsRelative( *sizeIsRelativeState );
333
334 TDEConfig *config = TDEGlobal::config();
335 TDEConfigGroupSaver saver(config, TQString::fromLatin1("General"));
336 showXLFDArea(config->readBoolEntry(TQString::fromLatin1("fontSelectorShowXLFD"), false));
337}
338
339TDEFontChooser::~TDEFontChooser()
340{
341 delete d;
342}
343
344void TDEFontChooser::fillSizeList() {
345 if(! sizeListBox) return; //assertion.
346
347 static const int c[] =
348 {
349 4, 5, 6, 7,
350 8, 9, 10, 11,
351 12, 13, 14, 15,
352 16, 17, 18, 19,
353 20, 22, 24, 26,
354 28, 32, 48, 64,
355 0
356 };
357 for(int i = 0; c[i]; ++i)
358 {
359 sizeListBox->insertItem(TQString::number(c[i]));
360 }
361}
362
363void TDEFontChooser::setColor( const TQColor & col )
364{
365 d->m_palette.setColor( TQPalette::Active, TQColorGroup::Text, col );
366 TQPalette pal = sampleEdit->palette();
367 pal.setColor( TQPalette::Active, TQColorGroup::Text, col );
368 sampleEdit->setPalette( pal );
369}
370
371TQColor TDEFontChooser::color() const
372{
373 return d->m_palette.color( TQPalette::Active, TQColorGroup::Text );
374}
375
376void TDEFontChooser::setBackgroundColor( const TQColor & col )
377{
378 d->m_palette.setColor( TQPalette::Active, TQColorGroup::Base, col );
379 TQPalette pal = sampleEdit->palette();
380 pal.setColor( TQPalette::Active, TQColorGroup::Base, col );
381 sampleEdit->setPalette( pal );
382}
383
384TQColor TDEFontChooser::backgroundColor() const
385{
386 return d->m_palette.color( TQPalette::Active, TQColorGroup::Base );
387}
388
389void TDEFontChooser::setSizeIsRelative( TQButton::ToggleState relative )
390{
391 // check or uncheck or gray out the "relative" checkbox
392 if( sizeIsRelativeCheckBox ) {
393 if( TQButton::NoChange == relative )
394 sizeIsRelativeCheckBox->setNoChange();
395 else
396 sizeIsRelativeCheckBox->setChecked( TQButton::On == relative );
397 }
398}
399
400TQButton::ToggleState TDEFontChooser::sizeIsRelative() const
401{
402 return sizeIsRelativeCheckBox
403 ? sizeIsRelativeCheckBox->state()
404 : TQButton::NoChange;
405}
406
407TQSize TDEFontChooser::sizeHint( void ) const
408{
409 return minimumSizeHint();
410}
411
412
413void TDEFontChooser::enableColumn( int column, bool state )
414{
415 if( column & FamilyList )
416 {
417 familyListBox->setEnabled(state);
418 }
419 if( column & StyleList )
420 {
421 styleListBox->setEnabled(state);
422 }
423 if( column & SizeList )
424 {
425 sizeListBox->setEnabled(state);
426 }
427}
428
429
430void TDEFontChooser::setFont( const TQFont& aFont, bool onlyFixed )
431{
432 selFont = aFont;
433 selectedSize=aFont.pointSize();
434 if (selectedSize == -1)
435 selectedSize = TQFontInfo(aFont).pointSize();
436
437 if( onlyFixed != usingFixed)
438 {
439 usingFixed = onlyFixed;
440 fillFamilyListBox(usingFixed);
441 }
442 setupDisplay();
443 displaySample(selFont);
444}
445
446
447int TDEFontChooser::fontDiffFlags() {
448 int diffFlags = 0;
449 if (familyCheckbox && styleCheckbox && sizeCheckbox) {
450 diffFlags = (int)(familyCheckbox->isChecked() ? FontDiffFamily : 0)
451 | (int)( styleCheckbox->isChecked() ? FontDiffStyle : 0)
452 | (int)( sizeCheckbox->isChecked() ? FontDiffSize : 0);
453 }
454 return diffFlags;
455}
456
457void TDEFontChooser::toggled_checkbox()
458{
459 familyListBox->setEnabled( familyCheckbox->isChecked() );
460 styleListBox->setEnabled( styleCheckbox->isChecked() );
461 sizeListBox->setEnabled( sizeCheckbox->isChecked() );
462 sizeOfFont->setEnabled( sizeCheckbox->isChecked() );
463}
464
465TQString TDEFontChooser::style_name(const TQString &style)
466{
467 return i18n(
468 TQString(style).replace("Plain", "Regular")
469 .replace("Normal", "Regular")
470 .replace("Oblique", "Italic")
471 .utf8());
472}
473
474void TDEFontChooser::family_chosen_slot(const TQString& family)
475{
476 TQString currentFamily;
477 if (family.isEmpty())
478 {
479 currentFamily = familyListBox->currentText();
480 }
481 else
482 {
483 currentFamily = family;
484 }
485
486 TQFontDatabase dbase;
487 TQStringList styles = dbase.styles(currentFamily);
488 styleListBox->clear();
489 currentStyles.clear();
490 for ( TQStringList::Iterator it = styles.begin(); it != styles.end(); ++it ) {
491 TQString style = style_name(*it);
492 if(!styleListBox->findItem(style)) {
493 styleListBox->insertItem(style);
494 currentStyles.insert(style, *it);
495 }
496 }
497 if(styleListBox->count()==0) {
498 styleListBox->insertItem(i18n("Regular"));
499 currentStyles.insert(i18n("Regular"), "Normal");
500 }
501
502 styleListBox->blockSignals(true);
503 TQListBoxItem *item = styleListBox->findItem(selectedStyle);
504 if (item)
505 {
506 styleListBox->setSelected(styleListBox->findItem(selectedStyle), true);
507 }
508 else
509 {
510 styleListBox->setSelected(0, true);
511 }
512 styleListBox->blockSignals(false);
513
514 style_chosen_slot(TQString::null);
515
516 if (!family.isEmpty() )
517 {
518 selectedFamily = family;
519 }
520}
521
522void TDEFontChooser::size_chosen_slot(const TQString& size){
523
524 selectedSize=size.toInt();
525 sizeOfFont->setValue(selectedSize);
526 selFont.setPointSize(selectedSize);
527 emit fontSelected(selFont);
528}
529
530void TDEFontChooser::size_value_slot(int val) {
531 selFont.setPointSize(val);
532 emit fontSelected(selFont);
533}
534
535void TDEFontChooser::style_chosen_slot(const TQString& style)
536{
537 TQString currentStyle;
538 if (style.isEmpty())
539 currentStyle = styleListBox->currentText();
540 else
541 currentStyle = style;
542
543 int diff=0; // the difference between the font size requested and what we can show.
544
545 sizeListBox->clear();
546 TQFontDatabase dbase;
547 if(dbase.isSmoothlyScalable(familyListBox->currentText(), currentStyles[currentStyle])) { // is vector font
548 //sampleEdit->setPaletteBackgroundPixmap( VectorPixmap ); // TODO
549 fillSizeList();
550 } else { // is bitmap font.
551 //sampleEdit->setPaletteBackgroundPixmap( BitmapPixmap ); // TODO
552 TQValueList<int> sizes = dbase.smoothSizes(familyListBox->currentText(), currentStyles[currentStyle]);
553 if(sizes.count() > 0) {
554 TQValueList<int>::iterator it;
555 diff=1000;
556 for ( it = sizes.begin(); it != sizes.end(); ++it ) {
557 if(*it <= selectedSize || diff > *it - selectedSize) diff = selectedSize - *it;
558 sizeListBox->insertItem(TQString::number(*it));
559 }
560 } else // there are times QT does not provide the list..
561 fillSizeList();
562 }
563 sizeListBox->blockSignals(true);
564 sizeListBox->setSelected(sizeListBox->findItem(TQString::number(selectedSize)), true);
565 sizeListBox->blockSignals(false);
566 sizeListBox->ensureCurrentVisible();
567
568 //kdDebug() << "Showing: " << familyListBox->currentText() << ", " << currentStyles[currentStyle] << ", " << selectedSize-diff << endl;
569 selFont = dbase.font(familyListBox->currentText(), currentStyles[currentStyle], selectedSize-diff);
570 emit fontSelected(selFont);
571 if (!style.isEmpty())
572 selectedStyle = style;
573}
574
575void TDEFontChooser::displaySample(const TQFont& font)
576{
577 sampleEdit->setFont(font);
578 sampleEdit->setCursorPosition(0);
579 xlfdEdit->setText(font.rawName());
580 xlfdEdit->setCursorPosition(0);
581
582 //TQFontInfo a = TQFontInfo(font);
583 //kdDebug() << "font: " << a.family () << ", " << a.pointSize () << endl;
584 //kdDebug() << " (" << font.toString() << ")\n";
585}
586
587void TDEFontChooser::setupDisplay()
588{
589 // Calling familyListBox->setCurrentItem() causes the value of selFont
590 // to change, so we save the family, style and size beforehand.
591 TQFontDatabase dbase;
592 TQString family = TQString(selFont.family()).lower();
593 TQString style = style_name(dbase.styleString(selFont));
594 int size = selFont.pointSize();
595 if (size == -1)
596 size = TQFontInfo(selFont).pointSize();
597 TQString sizeStr = TQString::number(size);
598
599 int numEntries, i;
600
601 numEntries = familyListBox->count();
602 for (i = 0; i < numEntries; i++) {
603 if (family == familyListBox->text(i).lower()) {
604 familyListBox->setCurrentItem(i);
605 break;
606 }
607 }
608
609 // 1st Fallback
610 if ( (i == numEntries) )
611 {
612 if (family.contains('['))
613 {
614 family = family.left(family.find('[')).stripWhiteSpace();
615 for (i = 0; i < numEntries; i++) {
616 if (family == familyListBox->text(i).lower()) {
617 familyListBox->setCurrentItem(i);
618 break;
619 }
620 }
621 }
622 }
623
624 // 2nd Fallback
625 if ( (i == numEntries) )
626 {
627 TQString fallback = family+" [";
628 for (i = 0; i < numEntries; i++) {
629 if (familyListBox->text(i).lower().startsWith(fallback)) {
630 familyListBox->setCurrentItem(i);
631 break;
632 }
633 }
634 }
635
636 // 3rd Fallback
637 if ( (i == numEntries) )
638 {
639 for (i = 0; i < numEntries; i++) {
640 if (familyListBox->text(i).lower().startsWith(family)) {
641 familyListBox->setCurrentItem(i);
642 break;
643 }
644 }
645 }
646
647 // Fall back in case nothing matched. Otherwise, diff doesn't work
648 if ( i == numEntries )
649 familyListBox->setCurrentItem( 0 );
650
651 int item = 0;
652 for (int i = 0; i < (int)styleListBox->count(); ++i)
653 {
654 if (styleListBox->text(i) == style)
655 {
656 item = i;
657 break;
658 }
659 }
660 styleListBox->setCurrentItem(item);
661
662 numEntries = sizeListBox->count();
663 for (i = 0; i < numEntries; i++){
664 if (sizeStr == sizeListBox->text(i)) {
665 sizeListBox->setCurrentItem(i);
666 break;
667 }
668 }
669
670 sizeOfFont->setValue(size);
671}
672
673
674void TDEFontChooser::getFontList( TQStringList &list, uint fontListCriteria)
675{
676 TQFontDatabase dbase;
677 TQStringList lstSys(dbase.families());
678
679 // if we have criteria; then check fonts before adding
680 if (fontListCriteria)
681 {
682 TQStringList lstFonts;
683 for (TQStringList::Iterator it = lstSys.begin(); it != lstSys.end(); ++it)
684 {
685 if ((fontListCriteria & FixedWidthFonts) > 0 && !dbase.isFixedPitch(*it)) continue;
686 if (((fontListCriteria & (SmoothScalableFonts | ScalableFonts)) == ScalableFonts) &&
687 !dbase.isBitmapScalable(*it)) continue;
688 if ((fontListCriteria & SmoothScalableFonts) > 0 && !dbase.isSmoothlyScalable(*it)) continue;
689 lstFonts.append(*it);
690 }
691
692 if((fontListCriteria & FixedWidthFonts) > 0) {
693 // Fallback.. if there are no fixed fonts found, it's probably a
694 // bug in the font server or Qt. In this case, just use 'fixed'
695 if (lstFonts.count() == 0)
696 lstFonts.append("fixed");
697 }
698
699 lstSys = lstFonts;
700 }
701
702 lstSys.sort();
703
704 list = lstSys;
705}
706
707void TDEFontChooser::setFamilyList( TQStringList list )
708{
709 familyListBox->blockSignals(true);
710 familyListBox->clear();
711 familyListBox->insertStringList(list);
712 setFont( TDEGlobalSettings::generalFont(), usingFixed );
713 familyListBox->blockSignals(false);
714}
715
716void TDEFontChooser::addFont( TQStringList &list, const char *xfont )
717{
718 const char *ptr = strchr( xfont, '-' );
719 if ( !ptr )
720 return;
721
722 ptr = strchr( ptr + 1, '-' );
723 if ( !ptr )
724 return;
725
726 TQString font = TQString::fromLatin1(ptr + 1);
727
728 int pos;
729 if ( ( pos = font.find( '-' ) ) > 0 ) {
730 font.truncate( pos );
731
732 if ( font.find( TQString::fromLatin1("open look"), 0, false ) >= 0 )
733 return;
734
735 TQStringList::Iterator it = list.begin();
736
737 for ( ; it != list.end(); ++it )
738 if ( *it == font )
739 return;
740 list.append( font );
741 }
742}
743
744void TDEFontChooser::fillFamilyListBox(bool onlyFixedFonts)
745{
746 TQStringList fontList;
747 getFontList(fontList, onlyFixedFonts?FixedWidthFonts:0);
748 familyListBox->clear();
749 familyListBox->insertStringList(fontList);
750}
751
752void TDEFontChooser::showXLFDArea(bool show)
753{
754 if( show )
755 {
756 xlfdEdit->parentWidget()->show();
757 }
758 else
759 {
760 xlfdEdit->parentWidget()->hide();
761 }
762}
763
765
766TDEFontDialog::TDEFontDialog( TQWidget *parent, const char* name,
767 bool onlyFixed, bool modal,
768 const TQStringList &fontList, bool makeFrame, bool diff,
769 TQButton::ToggleState *sizeIsRelativeState )
770 : KDialogBase( parent, name, modal, i18n("Select Font"), Ok|Cancel, Ok )
771{
772 chooser = new TDEFontChooser( this, "fontChooser",
773 onlyFixed, fontList, makeFrame, 8,
774 diff, sizeIsRelativeState );
775 setMainWidget(chooser);
776}
777
778
779int TDEFontDialog::getFontDiff( TQFont &theFont, int &diffFlags, bool onlyFixed,
780 TQWidget *parent, bool makeFrame,
781 TQButton::ToggleState *sizeIsRelativeState )
782{
783 TDEFontDialog dlg( parent, "Font Selector", onlyFixed, true, TQStringList(),
784 makeFrame, true, sizeIsRelativeState );
785 dlg.setFont( theFont, onlyFixed );
786
787 int result = dlg.exec();
788 if( result == Accepted )
789 {
790 theFont = dlg.chooser->font();
791 diffFlags = dlg.chooser->fontDiffFlags();
792 if( sizeIsRelativeState )
793 *sizeIsRelativeState = dlg.chooser->sizeIsRelative();
794 }
795 return result;
796}
797
798int TDEFontDialog::getFont( TQFont &theFont, bool onlyFixed,
799 TQWidget *parent, bool makeFrame,
800 TQButton::ToggleState *sizeIsRelativeState )
801{
802 TDEFontDialog dlg( parent, "Font Selector", onlyFixed, true, TQStringList(),
803 makeFrame, false, sizeIsRelativeState );
804 dlg.setFont( theFont, onlyFixed );
805
806 int result = dlg.exec();
807 if( result == Accepted )
808 {
809 theFont = dlg.chooser->font();
810 if( sizeIsRelativeState )
811 *sizeIsRelativeState = dlg.chooser->sizeIsRelative();
812 }
813 return result;
814}
815
816
817int TDEFontDialog::getFontAndText( TQFont &theFont, TQString &theString,
818 bool onlyFixed, TQWidget *parent,
819 bool makeFrame,
820 TQButton::ToggleState *sizeIsRelativeState )
821{
822 TDEFontDialog dlg( parent, "Font and Text Selector", onlyFixed, true,
823 TQStringList(), makeFrame, false, sizeIsRelativeState );
824 dlg.setFont( theFont, onlyFixed );
825
826 int result = dlg.exec();
827 if( result == Accepted )
828 {
829 theFont = dlg.chooser->font();
830 theString = dlg.chooser->sampleText();
831 if( sizeIsRelativeState )
832 *sizeIsRelativeState = dlg.chooser->sizeIsRelative();
833 }
834 return result;
835}
836
837void TDEFontChooser::virtual_hook( int, void* )
838{ /*BASE::virtual_hook( id, data );*/ }
839
840void TDEFontDialog::virtual_hook( int id, void* data )
841{ KDialogBase::virtual_hook( id, data ); }
KDialogBase
A dialog base class with standard buttons and predefined layouts.
Definition: kdialogbase.h:192
KDialogBase::setMainWidget
void setMainWidget(TQWidget *widget)
Sets the main user definable widget.
Definition: kdialogbase.cpp:1431
KDialog::marginHint
static int marginHint()
Return the number of pixels you shall use between a dialog edge and the outermost widget(s) according...
Definition: kdialog.cpp:104
KDialog::spacingHint
static int spacingHint()
Return the number of pixels you shall use between widgets inside a dialog according to the KDE standa...
Definition: kdialog.cpp:110
KIntNumInput
An input widget for integer numbers, consisting of a spinbox and a slider.
Definition: knuminput.h:189
KIntNumInput::setMinValue
void setMinValue(int min)
Sets the minimum value.
Definition: knuminput.cpp:371
KIntNumInput::setValue
void setValue(int)
Sets the value of the control.
Definition: knuminput.cpp:494
TDEConfigBase::readBoolEntry
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
TDEConfigGroupSaver
TDEConfig
TDEFontChooser
A font selection widget.
Definition: tdefontdialog.h:55
TDEFontChooser::backgroundColor
TQColor backgroundColor() const
Definition: tdefontdialog.cpp:384
TDEFontChooser::setFont
void setFont(const TQFont &font, bool onlyFixed=false)
Sets the currently selected font in the chooser.
Definition: tdefontdialog.cpp:430
TDEFontChooser::fontSelected
void fontSelected(const TQFont &font)
Emitted whenever the selected font changes.
TDEFontChooser::sampleText
TQString sampleText() const
Definition: tdefontdialog.h:192
TDEFontChooser::sizeIsRelative
TQButton::ToggleState sizeIsRelative() const
Definition: tdefontdialog.cpp:400
TDEFontChooser::fontDiffFlags
int fontDiffFlags()
Definition: tdefontdialog.cpp:447
TDEFontChooser::TDEFontChooser
TDEFontChooser(TQWidget *parent=0L, const char *name=0L, bool onlyFixed=false, const TQStringList &fontList=TQStringList(), bool makeFrame=true, int visibleListSize=8, bool diff=false, TQButton::ToggleState *sizeIsRelativeState=0L)
Constructs a font picker widget.
Definition: tdefontdialog.cpp:93
TDEFontChooser::~TDEFontChooser
virtual ~TDEFontChooser()
Destructs the font chooser.
Definition: tdefontdialog.cpp:339
TDEFontChooser::setBackgroundColor
void setBackgroundColor(const TQColor &col)
Sets the background color to use in the preview.
Definition: tdefontdialog.cpp:376
TDEFontChooser::setColor
void setColor(const TQColor &col)
Sets the color to use in the preview.
Definition: tdefontdialog.cpp:363
TDEFontChooser::color
TQColor color() const
Definition: tdefontdialog.cpp:371
TDEFontChooser::font
TQFont font() const
Definition: tdefontdialog.h:150
TDEFontChooser::sizeHint
virtual TQSize sizeHint(void) const
Reimplemented for internal reasons.
Definition: tdefontdialog.cpp:407
TDEFontChooser::enableColumn
void enableColumn(int column, bool state)
Enables or disable a font column in the chooser.
Definition: tdefontdialog.cpp:413
TDEFontChooser::setSizeIsRelative
void setSizeIsRelative(TQButton::ToggleState relative)
Sets the state of the checkbox indicating whether the font size is to be interpreted as relative size...
Definition: tdefontdialog.cpp:389
TDEFontChooser::getFontList
static void getFontList(TQStringList &list, uint fontListCriteria)
Creates a list of font strings.
Definition: tdefontdialog.cpp:674
TDEFontChooser::setFamilyList
void setFamilyList(TQStringList list)
Fill the font family list of the TDEFontChooser.
Definition: tdefontdialog.cpp:707
TDEFontDialog
A font selection dialog.
Definition: tdefontdialog.h:349
TDEFontDialog::setFont
void setFont(const TQFont &font, bool onlyFixed=false)
Sets the currently selected font in the dialog.
Definition: tdefontdialog.h:388
TDEFontDialog::getFontAndText
static int getFontAndText(TQFont &theFont, TQString &theString, bool onlyFixed=false, TQWidget *parent=0L, bool makeFrame=true, TQButton::ToggleState *sizeIsRelativeState=0L)
When you are not only interested in the font selected, but also in the example string typed in,...
Definition: tdefontdialog.cpp:817
TDEFontDialog::TDEFontDialog
TDEFontDialog(TQWidget *parent=0L, const char *name=0, bool onlyFixed=false, bool modal=false, const TQStringList &fontlist=TQStringList(), bool makeFrame=true, bool diff=false, TQButton::ToggleState *sizeIsRelativeState=0L)
Constructs a font selection dialog.
Definition: tdefontdialog.cpp:766
TDEFontDialog::getFontDiff
static int getFontDiff(TQFont &theFont, int &diffFlags, bool onlyFixed=false, TQWidget *parent=0L, bool makeFrame=true, TQButton::ToggleState *sizeIsRelativeState=0L)
Creates a modal font difference dialog, lets the user choose a selection of changes that should be ma...
Definition: tdefontdialog.cpp:779
TDEFontDialog::getFont
static int getFont(TQFont &theFont, bool onlyFixed=false, TQWidget *parent=0L, bool makeFrame=true, TQButton::ToggleState *sizeIsRelativeState=0L)
Creates a modal font dialog, lets the user choose a font, and returns when the dialog is closed.
Definition: tdefontdialog.cpp:798
TDEGlobalSettings::generalFont
static TQFont generalFont()
TDEGlobal::config
static TDEConfig * config()
TDEListBox
A variant of TQListBox that honors KDE's system-wide settings.
Definition: tdelistbox.h:41
TDEStdAccel::replace
const TDEShortcut & replace()
tdelocale.h

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.9.4
This website is maintained by Timothy Pearson.