00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <config.h>
00028
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031
00032 #include <qcombobox.h>
00033 #include <qcheckbox.h>
00034 #include <qfile.h>
00035 #include <qfont.h>
00036 #include <qgroupbox.h>
00037 #include <qlabel.h>
00038 #include <qlayout.h>
00039 #include <qscrollbar.h>
00040 #include <qstringlist.h>
00041 #include <qfontdatabase.h>
00042 #include <qwhatsthis.h>
00043 #include <qtooltip.h>
00044
00045 #include <kapplication.h>
00046 #include <kcharsets.h>
00047 #include <kconfig.h>
00048 #include <kdialog.h>
00049 #include <kglobal.h>
00050 #include <kglobalsettings.h>
00051 #include <qlineedit.h>
00052 #include <klistbox.h>
00053 #include <klocale.h>
00054 #include <kstandarddirs.h>
00055 #include <kdebug.h>
00056 #include <knuminput.h>
00057 #ifdef Q_WS_X11
00058 #include <X11/Xlib.h>
00059 #endif
00060
00061 #include "kfontdialog.moc"
00062
00063 static int minimumListWidth( const QListBox *list )
00064 {
00065 int w=0;
00066 for( uint i=0; i<list->count(); i++ )
00067 {
00068 int itemWidth = list->item(i)->width(list);
00069 w = QMAX(w,itemWidth);
00070 }
00071 if( w == 0 ) { w = 40; }
00072 w += list->frameWidth() * 2;
00073 w += list->verticalScrollBar()->sizeHint().width();
00074 return( w );
00075 }
00076
00077 static int minimumListHeight( const QListBox *list, int numVisibleEntry )
00078 {
00079 int w = list->count() > 0 ? list->item(0)->height(list) :
00080 list->fontMetrics().lineSpacing();
00081
00082 if( w < 0 ) { w = 10; }
00083 if( numVisibleEntry <= 0 ) { numVisibleEntry = 4; }
00084 return( w * numVisibleEntry + 2 * list->frameWidth() );
00085 }
00086
00087 class KFontChooser::KFontChooserPrivate
00088 {
00089 public:
00090 KFontChooserPrivate()
00091 { m_palette.setColor(QPalette::Active, QColorGroup::Text, Qt::black);
00092 m_palette.setColor(QPalette::Active, QColorGroup::Base, Qt::white); }
00093 QPalette m_palette;
00094 };
00095
00096 KFontChooser::KFontChooser(QWidget *parent, const char *name,
00097 bool onlyFixed, const QStringList &fontList,
00098 bool makeFrame, int visibleListSize, bool diff,
00099 QButton::ToggleState *sizeIsRelativeState )
00100 : QWidget(parent, name), usingFixed(onlyFixed)
00101 {
00102 charsetsCombo = 0;
00103
00104 QString mainWhatsThisText =
00105 i18n( "Here you can choose the font to be used." );
00106 QWhatsThis::add( this, mainWhatsThisText );
00107
00108 d = new KFontChooserPrivate;
00109 QVBoxLayout *topLayout = new QVBoxLayout( this, 0, KDialog::spacingHint() );
00110 int checkBoxGap = KDialog::spacingHint() / 2;
00111
00112 QWidget *page;
00113 QGridLayout *gridLayout;
00114 int row = 0;
00115 if( makeFrame == true )
00116 {
00117 page = new QGroupBox( i18n("Requested Font"), this );
00118 topLayout->addWidget(page);
00119 gridLayout = new QGridLayout( page, 5, 3, KDialog::marginHint(), KDialog::spacingHint() );
00120 gridLayout->addRowSpacing( 0, fontMetrics().lineSpacing() );
00121 row = 1;
00122 }
00123 else
00124 {
00125 page = new QWidget( this );
00126 topLayout->addWidget(page);
00127 gridLayout = new QGridLayout( page, 4, 3, 0, KDialog::spacingHint() );
00128 }
00129
00130
00131
00132
00133 QHBoxLayout *familyLayout = new QHBoxLayout();
00134 familyLayout->addSpacing( checkBoxGap );
00135 if (diff) {
00136 familyCheckbox = new QCheckBox(i18n("Font"), page);
00137 connect(familyCheckbox, SIGNAL(toggled(bool)), SLOT(toggled_checkbox()));
00138 familyLayout->addWidget(familyCheckbox, 0, Qt::AlignLeft);
00139 QString familyCBToolTipText =
00140 i18n("Change font family?");
00141 QString familyCBWhatsThisText =
00142 i18n("Enable this checkbox to change the font family settings.");
00143 QWhatsThis::add( familyCheckbox, familyCBWhatsThisText );
00144 QToolTip::add( familyCheckbox, familyCBToolTipText );
00145 familyLabel = 0;
00146 } else {
00147 familyCheckbox = 0;
00148 familyLabel = new QLabel( i18n("Font:"), page, "familyLabel" );
00149 familyLayout->addWidget(familyLabel, 1, Qt::AlignLeft);
00150 }
00151 gridLayout->addLayout(familyLayout, row, 0 );
00152
00153 QHBoxLayout *styleLayout = new QHBoxLayout();
00154 if (diff) {
00155 styleCheckbox = new QCheckBox(i18n("Font style"), page);
00156 connect(styleCheckbox, SIGNAL(toggled(bool)), SLOT(toggled_checkbox()));
00157 styleLayout->addWidget(styleCheckbox, 0, Qt::AlignLeft);
00158 QString styleCBToolTipText =
00159 i18n("Change font style?");
00160 QString styleCBWhatsThisText =
00161 i18n("Enable this checkbox to change the font style settings.");
00162 QWhatsThis::add( styleCheckbox, styleCBWhatsThisText );
00163 QToolTip::add( styleCheckbox, styleCBToolTipText );
00164 styleLabel = 0;
00165 } else {
00166 styleCheckbox = 0;
00167 styleLabel = new QLabel( i18n("Font style:"), page, "styleLabel");
00168 styleLayout->addWidget(styleLabel, 1, Qt::AlignLeft);
00169 }
00170 styleLayout->addSpacing( checkBoxGap );
00171 gridLayout->addLayout(styleLayout, row, 1 );
00172
00173 QHBoxLayout *sizeLayout = new QHBoxLayout();
00174 if (diff) {
00175 sizeCheckbox = new QCheckBox(i18n("Size"),page);
00176 connect(sizeCheckbox, SIGNAL(toggled(bool)), SLOT(toggled_checkbox()));
00177 sizeLayout->addWidget(sizeCheckbox, 0, Qt::AlignLeft);
00178 QString sizeCBToolTipText =
00179 i18n("Change font size?");
00180 QString sizeCBWhatsThisText =
00181 i18n("Enable this checkbox to change the font size settings.");
00182 QWhatsThis::add( sizeCheckbox, sizeCBWhatsThisText );
00183 QToolTip::add( sizeCheckbox, sizeCBToolTipText );
00184 sizeLabel = 0;
00185 } else {
00186 sizeCheckbox = 0;
00187 sizeLabel = new QLabel( i18n("Size:"), page, "sizeLabel");
00188 sizeLayout->addWidget(sizeLabel, 1, Qt::AlignLeft);
00189 }
00190 sizeLayout->addSpacing( checkBoxGap );
00191 sizeLayout->addSpacing( checkBoxGap );
00192 gridLayout->addLayout(sizeLayout, row, 2 );
00193
00194 row ++;
00195
00196
00197
00198
00199 familyListBox = new KListBox( page, "familyListBox");
00200 familyListBox->setEnabled( !diff );
00201 gridLayout->addWidget( familyListBox, row, 0 );
00202 QString fontFamilyWhatsThisText =
00203 i18n("Here you can choose the font family to be used." );
00204 QWhatsThis::add( familyListBox, fontFamilyWhatsThisText );
00205 QWhatsThis::add(diff?(QWidget *) familyCheckbox:(QWidget *) familyLabel, fontFamilyWhatsThisText );
00206 connect(familyListBox, SIGNAL(highlighted(const QString &)),
00207 SLOT(family_chosen_slot(const QString &)));
00208 if(fontList.count() != 0)
00209 {
00210 familyListBox->insertStringList(fontList);
00211 }
00212 else
00213 {
00214 fillFamilyListBox(onlyFixed);
00215 }
00216
00217 familyListBox->setMinimumWidth( minimumListWidth( familyListBox ) );
00218 familyListBox->setMinimumHeight(
00219 minimumListHeight( familyListBox, visibleListSize ) );
00220
00221 styleListBox = new KListBox( page, "styleListBox");
00222 styleListBox->setEnabled( !diff );
00223 gridLayout->addWidget(styleListBox, row, 1);
00224 QString fontStyleWhatsThisText =
00225 i18n("Here you can choose the font style to be used." );
00226 QWhatsThis::add( styleListBox, fontStyleWhatsThisText );
00227 QWhatsThis::add(diff?(QWidget *)styleCheckbox:(QWidget *)styleLabel, fontFamilyWhatsThisText );
00228 styleListBox->insertItem(i18n("Regular"));
00229 styleListBox->insertItem(i18n("Italic"));
00230 styleListBox->insertItem(i18n("Bold"));
00231 styleListBox->insertItem(i18n("Bold Italic"));
00232 styleListBox->setMinimumWidth( minimumListWidth( styleListBox ) );
00233 styleListBox->setMinimumHeight(
00234 minimumListHeight( styleListBox, visibleListSize ) );
00235
00236 connect(styleListBox, SIGNAL(highlighted(const QString &)),
00237 SLOT(style_chosen_slot(const QString &)));
00238
00239
00240 sizeListBox = new KListBox( page, "sizeListBox");
00241 sizeOfFont = new KIntNumInput( page, "sizeOfFont");
00242 sizeOfFont->setMinValue(4);
00243
00244 sizeListBox->setEnabled( !diff );
00245 sizeOfFont->setEnabled( !diff );
00246 if( sizeIsRelativeState ) {
00247 QString sizeIsRelativeCBText =
00248 i18n("relative");
00249 QString sizeIsRelativeCBToolTipText =
00250 i18n("Font size<br><i>fixed</i> or <i>relative</i><br>to environment");
00251 QString sizeIsRelativeCBWhatsThisText =
00252 i18n("Here you can switch between fixed font size and font size "
00253 "to be calculated dynamically and adjusted to changing "
00254 "environment (e.g. widget dimensions, paper size)." );
00255 sizeIsRelativeCheckBox = new QCheckBox( sizeIsRelativeCBText,
00256 page,
00257 "sizeIsRelativeCheckBox" );
00258 sizeIsRelativeCheckBox->setTristate( diff );
00259 QGridLayout *sizeLayout2 = new QGridLayout( 3,2, KDialog::spacingHint()/2, "sizeLayout2" );
00260 gridLayout->addLayout(sizeLayout2, row, 2);
00261 sizeLayout2->setColStretch( 1, 1 );
00262 sizeLayout2->addMultiCellWidget( sizeOfFont, 0, 0, 0, 1);
00263 sizeLayout2->addMultiCellWidget(sizeListBox, 1,1, 0,1);
00264 sizeLayout2->addWidget(sizeIsRelativeCheckBox, 2, 0, Qt::AlignLeft);
00265 QWhatsThis::add( sizeIsRelativeCheckBox, sizeIsRelativeCBWhatsThisText );
00266 QToolTip::add( sizeIsRelativeCheckBox, sizeIsRelativeCBToolTipText );
00267 }
00268 else {
00269 sizeIsRelativeCheckBox = 0L;
00270 QGridLayout *sizeLayout2 = new QGridLayout( 2,1, KDialog::spacingHint()/2, "sizeLayout2" );
00271 gridLayout->addLayout(sizeLayout2, row, 2);
00272 sizeLayout2->addWidget( sizeOfFont, 0, 0);
00273 sizeLayout2->addMultiCellWidget(sizeListBox, 1,1, 0,0);
00274 }
00275 QString fontSizeWhatsThisText =
00276 i18n("Here you can choose the font size to be used." );
00277 QWhatsThis::add( sizeListBox, fontSizeWhatsThisText );
00278 QWhatsThis::add( diff?(QWidget *)sizeCheckbox:(QWidget *)sizeLabel, fontSizeWhatsThisText );
00279
00280 fillSizeList();
00281 sizeListBox->setMinimumWidth( minimumListWidth(sizeListBox) +
00282 sizeListBox->fontMetrics().maxWidth() );
00283 sizeListBox->setMinimumHeight(
00284 minimumListHeight( sizeListBox, visibleListSize ) );
00285
00286 connect( sizeOfFont, SIGNAL( valueChanged(int) ),
00287 SLOT(size_value_slot(int)));
00288
00289 connect( sizeListBox, SIGNAL(highlighted(const QString&)),
00290 SLOT(size_chosen_slot(const QString&)) );
00291 sizeListBox->setSelected(sizeListBox->findItem(QString::number(10)), true);
00292
00293 row ++;
00294
00295 row ++;
00296 sampleEdit = new QLineEdit( page, "sampleEdit");
00297 QFont tmpFont( KGlobalSettings::generalFont().family(), 64, QFont::Black );
00298 sampleEdit->setFont(tmpFont);
00299 sampleEdit->setText(i18n("The Quick Brown Fox Jumps Over The Lazy Dog"));
00300 sampleEdit->setMinimumHeight( sampleEdit->fontMetrics().lineSpacing() );
00301 sampleEdit->setAlignment(Qt::AlignCenter);
00302 gridLayout->addMultiCellWidget(sampleEdit, 4, 4, 0, 2);
00303 QString sampleEditWhatsThisText =
00304 i18n("This sample text illustrates the current settings. "
00305 "You may edit it to test special characters." );
00306 QWhatsThis::add( sampleEdit, sampleEditWhatsThisText );
00307 connect(this, SIGNAL(fontSelected(const QFont &)),
00308 SLOT(displaySample(const QFont &)));
00309
00310 QVBoxLayout *vbox;
00311 if( makeFrame == true )
00312 {
00313 page = new QGroupBox( i18n("Actual Font"), this );
00314 topLayout->addWidget(page);
00315 vbox = new QVBoxLayout( page, KDialog::spacingHint() );
00316 vbox->addSpacing( fontMetrics().lineSpacing() );
00317 }
00318 else
00319 {
00320 page = new QWidget( this );
00321 topLayout->addWidget(page);
00322 vbox = new QVBoxLayout( page, 0, KDialog::spacingHint() );
00323 QLabel *label = new QLabel( i18n("Actual Font"), page );
00324 vbox->addWidget( label );
00325 }
00326
00327 xlfdEdit = new QLineEdit( page, "xlfdEdit" );
00328 vbox->addWidget( xlfdEdit );
00329
00330
00331 setFont( KGlobalSettings::generalFont(), usingFixed );
00332
00333 if( sizeIsRelativeState && sizeIsRelativeCheckBox )
00334 setSizeIsRelative( *sizeIsRelativeState );
00335
00336 KConfig *config = KGlobal::config();
00337 KConfigGroupSaver saver(config, QString::fromLatin1("General"));
00338 showXLFDArea(config->readBoolEntry(QString::fromLatin1("fontSelectorShowXLFD"), false));
00339 }
00340
00341 KFontChooser::~KFontChooser()
00342 {
00343 delete d;
00344 }
00345
00346 void KFontChooser::fillSizeList() {
00347 if(! sizeListBox) return;
00348
00349 static const int c[] =
00350 {
00351 4, 5, 6, 7,
00352 8, 9, 10, 11,
00353 12, 13, 14, 15,
00354 16, 17, 18, 19,
00355 20, 22, 24, 26,
00356 28, 32, 48, 64,
00357 0
00358 };
00359 for(int i = 0; c[i] != 0; i++)
00360 {
00361 sizeListBox->insertItem(QString::number(c[i]));
00362 }
00363 }
00364
00365 void KFontChooser::setColor( const QColor & col )
00366 {
00367 d->m_palette.setColor( QPalette::Active, QColorGroup::Text, col );
00368 QPalette pal = sampleEdit->palette();
00369 pal.setColor( QPalette::Active, QColorGroup::Text, col );
00370 sampleEdit->setPalette( pal );
00371 }
00372
00373 QColor KFontChooser::color() const
00374 {
00375 return d->m_palette.color( QPalette::Active, QColorGroup::Text );
00376 }
00377
00378 void KFontChooser::setBackgroundColor( const QColor & col )
00379 {
00380 d->m_palette.setColor( QPalette::Active, QColorGroup::Base, col );
00381 QPalette pal = sampleEdit->palette();
00382 pal.setColor( QPalette::Active, QColorGroup::Base, col );
00383 sampleEdit->setPalette( pal );
00384 }
00385
00386 QColor KFontChooser::backgroundColor() const
00387 {
00388 return d->m_palette.color( QPalette::Active, QColorGroup::Base );
00389 }
00390
00391 void KFontChooser::setSizeIsRelative( QButton::ToggleState relative )
00392 {
00393
00394 if( sizeIsRelativeCheckBox ) {
00395 if( QButton::NoChange == relative )
00396 sizeIsRelativeCheckBox->setNoChange();
00397 else
00398 sizeIsRelativeCheckBox->setChecked( QButton::On == relative );
00399 }
00400 }
00401
00402 QButton::ToggleState KFontChooser::sizeIsRelative() const
00403 {
00404 return sizeIsRelativeCheckBox
00405 ? sizeIsRelativeCheckBox->state()
00406 : QButton::NoChange;
00407 }
00408
00409 QSize KFontChooser::sizeHint( void ) const
00410 {
00411 return( minimumSizeHint() );
00412 }
00413
00414
00415 void KFontChooser::enableColumn( int column, bool state )
00416 {
00417 if( column & FamilyList )
00418 {
00419 familyListBox->setEnabled(state);
00420 }
00421 if( column & StyleList )
00422 {
00423 styleListBox->setEnabled(state);
00424 }
00425 if( column & SizeList )
00426 {
00427 sizeListBox->setEnabled(state);
00428 }
00429 }
00430
00431
00432 void KFontChooser::setFont( const QFont& aFont, bool onlyFixed )
00433 {
00434 selFont = aFont;
00435 selectedSize=aFont.pointSize();
00436 if( onlyFixed != usingFixed)
00437 {
00438 usingFixed = onlyFixed;
00439 fillFamilyListBox(usingFixed);
00440 }
00441 setupDisplay();
00442 displaySample(selFont);
00443 }
00444
00445
00446 int KFontChooser::fontDiffFlags() {
00447 int diffFlags = 0;
00448 if (familyCheckbox && styleCheckbox && sizeCheckbox) {
00449 diffFlags = (int)(familyCheckbox->isChecked() ? FontDiffFamily : 0)
00450 | (int)( styleCheckbox->isChecked() ? FontDiffStyle : 0)
00451 | (int)( sizeCheckbox->isChecked() ? FontDiffSize : 0);
00452 }
00453 return diffFlags;
00454 }
00455
00456 void KFontChooser::toggled_checkbox()
00457 {
00458 familyListBox->setEnabled( familyCheckbox->isChecked() );
00459 styleListBox->setEnabled( styleCheckbox->isChecked() );
00460 sizeListBox->setEnabled( sizeCheckbox->isChecked() );
00461 sizeOfFont->setEnabled( sizeCheckbox->isChecked() );
00462 }
00463
00464 void KFontChooser::family_chosen_slot(const QString& family)
00465 {
00466 QFontDatabase dbase;
00467 QStringList styles = QStringList(dbase.styles(family));
00468 styleListBox->clear();
00469 currentStyles.clear();
00470 for ( QStringList::Iterator it = styles.begin(); it != styles.end(); ++it ) {
00471 QString style = *it;
00472 int pos = style.find("Plain");
00473 if(pos >=0) style = style.replace(pos,5,i18n("Regular"));
00474 pos = style.find("Normal");
00475 if(pos >=0) style = style.replace(pos,6,i18n("Regular"));
00476 pos = style.find("Oblique");
00477 if(pos >=0) style = style.replace(pos,7,i18n("Italic"));
00478 if(styleListBox->findItem(style) ==0) {
00479 styleListBox->insertItem(i18n(style.utf8()));
00480 currentStyles.insert(i18n(style.utf8()), *it);
00481 }
00482 }
00483 if(styleListBox->count()==0) {
00484 styleListBox->insertItem(i18n("Regular"));
00485 currentStyles.insert(i18n("Regular"), "Normal");
00486 }
00487
00488 styleListBox->blockSignals(true);
00489 QListBoxItem *item = styleListBox->findItem(selectedStyle);
00490 if (item)
00491 styleListBox->setSelected(styleListBox->findItem(selectedStyle), true);
00492 else
00493 styleListBox->setSelected(0, true);
00494 styleListBox->blockSignals(false);
00495
00496 style_chosen_slot(QString::null);
00497 }
00498
00499 void KFontChooser::size_chosen_slot(const QString& size){
00500
00501 selectedSize=size.toInt();
00502 sizeOfFont->setValue(selectedSize);
00503 selFont.setPointSize(selectedSize);
00504 emit fontSelected(selFont);
00505 }
00506
00507 void KFontChooser::size_value_slot(int val) {
00508 selFont.setPointSize(val);
00509 emit fontSelected(selFont);
00510 }
00511
00512 void KFontChooser::style_chosen_slot(const QString& style)
00513 {
00514 QString currentStyle;
00515 if (style.isEmpty())
00516 currentStyle = styleListBox->currentText();
00517 else
00518 currentStyle = style;
00519
00520 int diff=0;
00521
00522 sizeListBox->clear();
00523 QFontDatabase dbase;
00524 if(dbase.isSmoothlyScalable(familyListBox->currentText(), currentStyles[currentStyle])) {
00525
00526 fillSizeList();
00527 } else {
00528
00529 QValueList<int> sizes = dbase.smoothSizes(familyListBox->currentText(), currentStyles[currentStyle]);
00530 if(sizes.count() > 0) {
00531 QValueList<int>::iterator it;
00532 diff=1000;
00533 for ( it = sizes.begin(); it != sizes.end(); ++it ) {
00534 if(*it <= selectedSize || diff > *it - selectedSize) diff = selectedSize - *it;
00535 sizeListBox->insertItem(QString::number(*it));
00536 }
00537 } else
00538 fillSizeList();
00539 }
00540 sizeListBox->blockSignals(true);
00541 sizeListBox->setSelected(sizeListBox->findItem(QString::number(selectedSize)), true);
00542 sizeListBox->blockSignals(false);
00543 sizeListBox->ensureCurrentVisible();
00544
00545
00546 selFont = dbase.font(familyListBox->currentText(), currentStyles[currentStyle], selectedSize-diff);
00547 emit fontSelected(selFont);
00548 if (!style.isEmpty())
00549 selectedStyle = style;
00550 }
00551
00552 void KFontChooser::displaySample(const QFont& font)
00553 {
00554 sampleEdit->setFont(font);
00555 sampleEdit->setCursorPosition(0);
00556 xlfdEdit->setText(font.rawName());
00557 xlfdEdit->setCursorPosition(0);
00558
00559
00560
00561
00562 }
00563
00564 void KFontChooser::setupDisplay()
00565 {
00566
00567
00568 QString family = selFont.family().lower();
00569 int style = (selFont.bold() ? 2 : 0) + (selFont.italic() ? 1 : 0);
00570 int size = selFont.pointSize();
00571 QString sizeStr = QString::number(size);
00572
00573 int numEntries, i;
00574
00575 numEntries = familyListBox->count();
00576 for (i = 0; i < numEntries; i++) {
00577 if (family == familyListBox->text(i).lower()) {
00578 familyListBox->setCurrentItem(i);
00579 break;
00580 }
00581 }
00582
00583 styleListBox->setCurrentItem(style);
00584
00585 numEntries = sizeListBox->count();
00586 for (i = 0; i < numEntries; i++){
00587 if (sizeStr == sizeListBox->text(i)) {
00588 sizeListBox->setCurrentItem(i);
00589 break;
00590 }
00591 }
00592
00593 sizeOfFont->setValue(size);
00594 }
00595
00596
00597 void KFontChooser::getFontList( QStringList &list, uint fontListCriteria)
00598 {
00599 QFontDatabase dbase;
00600 QStringList lstSys(dbase.families());
00601
00602
00603 if (fontListCriteria)
00604 {
00605 QStringList lstFonts;
00606 for (QStringList::Iterator it = lstSys.begin(); it != lstSys.end(); ++it)
00607 {
00608 if ((fontListCriteria & FixedWidthFonts) > 0 && !dbase.isFixedPitch(*it)) continue;
00609 if ((fontListCriteria & (SmoothScalableFonts | ScalableFonts) == ScalableFonts) &&
00610 !dbase.isBitmapScalable(*it)) continue;
00611 if ((fontListCriteria & SmoothScalableFonts) > 0 && !dbase.isSmoothlyScalable(*it)) continue;
00612 lstFonts.append(*it);
00613 }
00614
00615 if((fontListCriteria & FixedWidthFonts) > 0) {
00616
00617
00618 if (lstFonts.count() == 0)
00619 lstFonts.append("fixed");
00620 }
00621
00622 lstSys = lstFonts;
00623 }
00624
00625 lstSys.sort();
00626
00627 list = lstSys;
00628 }
00629
00630 void KFontChooser::addFont( QStringList &list, const char *xfont )
00631 {
00632 const char *ptr = strchr( xfont, '-' );
00633 if ( !ptr )
00634 return;
00635
00636 ptr = strchr( ptr + 1, '-' );
00637 if ( !ptr )
00638 return;
00639
00640 QString font = QString::fromLatin1(ptr + 1);
00641
00642 int pos;
00643 if ( ( pos = font.find( '-' ) ) > 0 ) {
00644 font.truncate( pos );
00645
00646 if ( font.find( QString::fromLatin1("open look"), 0, false ) >= 0 )
00647 return;
00648
00649 QStringList::Iterator it = list.begin();
00650
00651 for ( ; it != list.end(); ++it )
00652 if ( *it == font )
00653 return;
00654 list.append( font );
00655 }
00656 }
00657
00658 void KFontChooser::fillFamilyListBox(bool onlyFixedFonts)
00659 {
00660 QStringList fontList;
00661 getFontList(fontList, onlyFixedFonts?FixedWidthFonts:0);
00662 familyListBox->clear();
00663 familyListBox->insertStringList(fontList);
00664 }
00665
00666 void KFontChooser::showXLFDArea(bool show)
00667 {
00668 if( show == true )
00669 {
00670 xlfdEdit->parentWidget()->show();
00671 }
00672 else
00673 {
00674 xlfdEdit->parentWidget()->hide();
00675 }
00676 }
00677
00679
00680 KFontDialog::KFontDialog( QWidget *parent, const char* name,
00681 bool onlyFixed, bool modal,
00682 const QStringList &fontList, bool makeFrame, bool diff,
00683 QButton::ToggleState *sizeIsRelativeState )
00684 : KDialogBase( parent, name, modal, i18n("Select Font"), Ok|Cancel, Ok )
00685 {
00686 chooser = new KFontChooser( this, "fontChooser",
00687 onlyFixed, fontList, makeFrame, 8,
00688 diff, sizeIsRelativeState );
00689 setMainWidget(chooser);
00690 }
00691
00692
00693 int KFontDialog::getFontDiff( QFont &theFont, int &diffFlags, bool onlyFixed,
00694 QWidget *parent, bool makeFrame,
00695 QButton::ToggleState *sizeIsRelativeState )
00696 {
00697 KFontDialog dlg( parent, "Font Selector", onlyFixed, true, QStringList(),
00698 makeFrame, true, sizeIsRelativeState );
00699 dlg.setFont( theFont, onlyFixed );
00700
00701 int result = dlg.exec();
00702 if( result == Accepted )
00703 {
00704 theFont = dlg.chooser->font();
00705 diffFlags = dlg.chooser->fontDiffFlags();
00706 if( sizeIsRelativeState )
00707 *sizeIsRelativeState = dlg.chooser->sizeIsRelative();
00708 }
00709 return( result );
00710 }
00711
00712 int KFontDialog::getFont( QFont &theFont, bool onlyFixed,
00713 QWidget *parent, bool makeFrame,
00714 QButton::ToggleState *sizeIsRelativeState )
00715 {
00716 KFontDialog dlg( parent, "Font Selector", onlyFixed, true, QStringList(),
00717 makeFrame, false, sizeIsRelativeState );
00718 dlg.setFont( theFont, onlyFixed );
00719
00720 int result = dlg.exec();
00721 if( result == Accepted )
00722 {
00723 theFont = dlg.chooser->font();
00724 if( sizeIsRelativeState )
00725 *sizeIsRelativeState = dlg.chooser->sizeIsRelative();
00726 }
00727 return( result );
00728 }
00729
00730
00731 int KFontDialog::getFontAndText( QFont &theFont, QString &theString,
00732 bool onlyFixed, QWidget *parent,
00733 bool makeFrame,
00734 QButton::ToggleState *sizeIsRelativeState )
00735 {
00736 KFontDialog dlg( parent, "Font and Text Selector", onlyFixed, true,
00737 QStringList(), makeFrame, false, sizeIsRelativeState );
00738 dlg.setFont( theFont, onlyFixed );
00739
00740 int result = dlg.exec();
00741 if( result == Accepted )
00742 {
00743 theFont = dlg.chooser->font();
00744 theString = dlg.chooser->sampleText();
00745 if( sizeIsRelativeState )
00746 *sizeIsRelativeState = dlg.chooser->sizeIsRelative();
00747 }
00748 return( result );
00749 }
00750
00751 void KFontChooser::virtual_hook( int, void* )
00752 { }
00753
00754 void KFontDialog::virtual_hook( int id, void* data )
00755 { KDialogBase::virtual_hook( id, data ); }