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 #include <config.h>
00027
00028 #include <stdio.h>
00029 #include <stdlib.h>
00030
00031 #include <qcombobox.h>
00032 #include <qcheckbox.h>
00033 #include <qfile.h>
00034 #include <qfont.h>
00035 #include <qgroupbox.h>
00036 #include <qlabel.h>
00037 #include <qlayout.h>
00038 #include <qscrollbar.h>
00039 #include <qstringlist.h>
00040 #include <qfontdatabase.h>
00041 #include <qwhatsthis.h>
00042 #include <qtooltip.h>
00043
00044 #include <kapplication.h>
00045 #include <kcharsets.h>
00046 #include <kconfig.h>
00047 #include <kdialog.h>
00048 #include <kglobal.h>
00049 #include <kglobalsettings.h>
00050 #include <qlineedit.h>
00051 #include <klistbox.h>
00052 #include <klocale.h>
00053 #include <kstandarddirs.h>
00054 #include <kdebug.h>
00055 #include <knuminput.h>
00056
00057 #include "kfontdialog.moc"
00058
00059 static int minimumListWidth( const QListBox *list )
00060 {
00061 int w=0;
00062 for( uint i=0; i<list->count(); i++ )
00063 {
00064 int itemWidth = list->item(i)->width(list);
00065 w = QMAX(w,itemWidth);
00066 }
00067 if( w == 0 ) { w = 40; }
00068 w += list->frameWidth() * 2;
00069 w += list->verticalScrollBar()->sizeHint().width();
00070 return w;
00071 }
00072
00073 static int minimumListHeight( const QListBox *list, int numVisibleEntry )
00074 {
00075 int w = list->count() > 0 ? list->item(0)->height(list) :
00076 list->fontMetrics().lineSpacing();
00077
00078 if( w < 0 ) { w = 10; }
00079 if( numVisibleEntry <= 0 ) { numVisibleEntry = 4; }
00080 return ( w * numVisibleEntry + 2 * list->frameWidth() );
00081 }
00082
00083 class KFontChooser::KFontChooserPrivate
00084 {
00085 public:
00086 KFontChooserPrivate()
00087 { m_palette.setColor(QPalette::Active, QColorGroup::Text, Qt::black);
00088 m_palette.setColor(QPalette::Active, QColorGroup::Base, Qt::white); }
00089 QPalette m_palette;
00090 };
00091
00092 KFontChooser::KFontChooser(QWidget *parent, const char *name,
00093 bool onlyFixed, const QStringList &fontList,
00094 bool makeFrame, int visibleListSize, bool diff,
00095 QButton::ToggleState *sizeIsRelativeState )
00096 : QWidget(parent, name), usingFixed(onlyFixed)
00097 {
00098 charsetsCombo = 0;
00099
00100 QString mainWhatsThisText =
00101 i18n( "Here you can choose the font to be used." );
00102 QWhatsThis::add( this, mainWhatsThisText );
00103
00104 d = new KFontChooserPrivate;
00105 QVBoxLayout *topLayout = new QVBoxLayout( this, 0, KDialog::spacingHint() );
00106 int checkBoxGap = KDialog::spacingHint() / 2;
00107
00108 QWidget *page;
00109 QGridLayout *gridLayout;
00110 int row = 0;
00111 if( makeFrame )
00112 {
00113 page = new QGroupBox( i18n("Requested Font"), this );
00114 topLayout->addWidget(page);
00115 gridLayout = new QGridLayout( page, 5, 3, KDialog::marginHint(), KDialog::spacingHint() );
00116 gridLayout->addRowSpacing( 0, fontMetrics().lineSpacing() );
00117 row = 1;
00118 }
00119 else
00120 {
00121 page = new QWidget( this );
00122 topLayout->addWidget(page);
00123 gridLayout = new QGridLayout( page, 4, 3, 0, KDialog::spacingHint() );
00124 }
00125
00126
00127
00128
00129 QHBoxLayout *familyLayout = new QHBoxLayout();
00130 familyLayout->addSpacing( checkBoxGap );
00131 if (diff) {
00132 familyCheckbox = new QCheckBox(i18n("Font"), page);
00133 connect(familyCheckbox, SIGNAL(toggled(bool)), SLOT(toggled_checkbox()));
00134 familyLayout->addWidget(familyCheckbox, 0, Qt::AlignLeft);
00135 QString familyCBToolTipText =
00136 i18n("Change font family?");
00137 QString familyCBWhatsThisText =
00138 i18n("Enable this checkbox to change the font family settings.");
00139 QWhatsThis::add( familyCheckbox, familyCBWhatsThisText );
00140 QToolTip::add( familyCheckbox, familyCBToolTipText );
00141 familyLabel = 0;
00142 } else {
00143 familyCheckbox = 0;
00144 familyLabel = new QLabel( i18n("Font:"), page, "familyLabel" );
00145 familyLayout->addWidget(familyLabel, 1, Qt::AlignLeft);
00146 }
00147 gridLayout->addLayout(familyLayout, row, 0 );
00148
00149 QHBoxLayout *styleLayout = new QHBoxLayout();
00150 if (diff) {
00151 styleCheckbox = new QCheckBox(i18n("Font style"), page);
00152 connect(styleCheckbox, SIGNAL(toggled(bool)), SLOT(toggled_checkbox()));
00153 styleLayout->addWidget(styleCheckbox, 0, Qt::AlignLeft);
00154 QString styleCBToolTipText =
00155 i18n("Change font style?");
00156 QString styleCBWhatsThisText =
00157 i18n("Enable this checkbox to change the font style settings.");
00158 QWhatsThis::add( styleCheckbox, styleCBWhatsThisText );
00159 QToolTip::add( styleCheckbox, styleCBToolTipText );
00160 styleLabel = 0;
00161 } else {
00162 styleCheckbox = 0;
00163 styleLabel = new QLabel( i18n("Font style:"), page, "styleLabel");
00164 styleLayout->addWidget(styleLabel, 1, Qt::AlignLeft);
00165 }
00166 styleLayout->addSpacing( checkBoxGap );
00167 gridLayout->addLayout(styleLayout, row, 1 );
00168
00169 QHBoxLayout *sizeLayout = new QHBoxLayout();
00170 if (diff) {
00171 sizeCheckbox = new QCheckBox(i18n("Size"),page);
00172 connect(sizeCheckbox, SIGNAL(toggled(bool)), SLOT(toggled_checkbox()));
00173 sizeLayout->addWidget(sizeCheckbox, 0, Qt::AlignLeft);
00174 QString sizeCBToolTipText =
00175 i18n("Change font size?");
00176 QString sizeCBWhatsThisText =
00177 i18n("Enable this checkbox to change the font size settings.");
00178 QWhatsThis::add( sizeCheckbox, sizeCBWhatsThisText );
00179 QToolTip::add( sizeCheckbox, sizeCBToolTipText );
00180 sizeLabel = 0;
00181 } else {
00182 sizeCheckbox = 0;
00183 sizeLabel = new QLabel( i18n("Size:"), page, "sizeLabel");
00184 sizeLayout->addWidget(sizeLabel, 1, Qt::AlignLeft);
00185 }
00186 sizeLayout->addSpacing( checkBoxGap );
00187 sizeLayout->addSpacing( checkBoxGap );
00188 gridLayout->addLayout(sizeLayout, row, 2 );
00189
00190 row ++;
00191
00192
00193
00194
00195 familyListBox = new KListBox( page, "familyListBox");
00196 familyListBox->setEnabled( !diff );
00197 gridLayout->addWidget( familyListBox, row, 0 );
00198 QString fontFamilyWhatsThisText =
00199 i18n("Here you can choose the font family to be used." );
00200 QWhatsThis::add( familyListBox, fontFamilyWhatsThisText );
00201 QWhatsThis::add(diff?(QWidget *) familyCheckbox:(QWidget *) familyLabel, fontFamilyWhatsThisText );
00202 connect(familyListBox, SIGNAL(highlighted(const QString &)),
00203 SLOT(family_chosen_slot(const QString &)));
00204 if(!fontList.isEmpty())
00205 {
00206 familyListBox->insertStringList(fontList);
00207 }
00208 else
00209 {
00210 fillFamilyListBox(onlyFixed);
00211 }
00212
00213 familyListBox->setMinimumWidth( minimumListWidth( familyListBox ) );
00214 familyListBox->setMinimumHeight(
00215 minimumListHeight( familyListBox, visibleListSize ) );
00216
00217 styleListBox = new KListBox( page, "styleListBox");
00218 styleListBox->setEnabled( !diff );
00219 gridLayout->addWidget(styleListBox, row, 1);
00220 QString fontStyleWhatsThisText =
00221 i18n("Here you can choose the font style to be used." );
00222 QWhatsThis::add( styleListBox, fontStyleWhatsThisText );
00223 QWhatsThis::add(diff?(QWidget *)styleCheckbox:(QWidget *)styleLabel, fontFamilyWhatsThisText );
00224 styleListBox->insertItem(i18n("Regular"));
00225 styleListBox->insertItem(i18n("Italic"));
00226 styleListBox->insertItem(i18n("Bold"));
00227 styleListBox->insertItem(i18n("Bold Italic"));
00228 styleListBox->setMinimumWidth( minimumListWidth( styleListBox ) );
00229 styleListBox->setMinimumHeight(
00230 minimumListHeight( styleListBox, visibleListSize ) );
00231
00232 connect(styleListBox, SIGNAL(highlighted(const QString &)),
00233 SLOT(style_chosen_slot(const QString &)));
00234
00235
00236 sizeListBox = new KListBox( page, "sizeListBox");
00237 sizeOfFont = new KIntNumInput( page, "sizeOfFont");
00238 sizeOfFont->setMinValue(4);
00239
00240 sizeListBox->setEnabled( !diff );
00241 sizeOfFont->setEnabled( !diff );
00242 if( sizeIsRelativeState ) {
00243 QString sizeIsRelativeCBText =
00244 i18n("Relative");
00245 QString sizeIsRelativeCBToolTipText =
00246 i18n("Font size<br><i>fixed</i> or <i>relative</i><br>to environment");
00247 QString sizeIsRelativeCBWhatsThisText =
00248 i18n("Here you can switch between fixed font size and font size "
00249 "to be calculated dynamically and adjusted to changing "
00250 "environment (e.g. widget dimensions, paper size)." );
00251 sizeIsRelativeCheckBox = new QCheckBox( sizeIsRelativeCBText,
00252 page,
00253 "sizeIsRelativeCheckBox" );
00254 sizeIsRelativeCheckBox->setTristate( diff );
00255 QGridLayout *sizeLayout2 = new QGridLayout( 3,2, KDialog::spacingHint()/2, "sizeLayout2" );
00256 gridLayout->addLayout(sizeLayout2, row, 2);
00257 sizeLayout2->setColStretch( 1, 1 );
00258 sizeLayout2->addMultiCellWidget( sizeOfFont, 0, 0, 0, 1);
00259 sizeLayout2->addMultiCellWidget(sizeListBox, 1,1, 0,1);
00260 sizeLayout2->addWidget(sizeIsRelativeCheckBox, 2, 0, Qt::AlignLeft);
00261 QWhatsThis::add( sizeIsRelativeCheckBox, sizeIsRelativeCBWhatsThisText );
00262 QToolTip::add( sizeIsRelativeCheckBox, sizeIsRelativeCBToolTipText );
00263 }
00264 else {
00265 sizeIsRelativeCheckBox = 0L;
00266 QGridLayout *sizeLayout2 = new QGridLayout( 2,1, KDialog::spacingHint()/2, "sizeLayout2" );
00267 gridLayout->addLayout(sizeLayout2, row, 2);
00268 sizeLayout2->addWidget( sizeOfFont, 0, 0);
00269 sizeLayout2->addMultiCellWidget(sizeListBox, 1,1, 0,0);
00270 }
00271 QString fontSizeWhatsThisText =
00272 i18n("Here you can choose the font size to be used." );
00273 QWhatsThis::add( sizeListBox, fontSizeWhatsThisText );
00274 QWhatsThis::add( diff?(QWidget *)sizeCheckbox:(QWidget *)sizeLabel, fontSizeWhatsThisText );
00275
00276 fillSizeList();
00277 sizeListBox->setMinimumWidth( minimumListWidth(sizeListBox) +
00278 sizeListBox->fontMetrics().maxWidth() );
00279 sizeListBox->setMinimumHeight(
00280 minimumListHeight( sizeListBox, visibleListSize ) );
00281
00282 connect( sizeOfFont, SIGNAL( valueChanged(int) ),
00283 SLOT(size_value_slot(int)));
00284
00285 connect( sizeListBox, SIGNAL(highlighted(const QString&)),
00286 SLOT(size_chosen_slot(const QString&)) );
00287 sizeListBox->setSelected(sizeListBox->findItem(QString::number(10)), true);
00288
00289 row ++;
00290
00291 row ++;
00292 sampleEdit = new QLineEdit( page, "sampleEdit");
00293 QFont tmpFont( KGlobalSettings::generalFont().family(), 64, QFont::Black );
00294 sampleEdit->setFont(tmpFont);
00295
00296 sampleEdit->setText(i18n("The Quick Brown Fox Jumps Over The Lazy Dog"));
00297 sampleEdit->setMinimumHeight( sampleEdit->fontMetrics().lineSpacing() );
00298 sampleEdit->setAlignment(Qt::AlignCenter);
00299 gridLayout->addMultiCellWidget(sampleEdit, 4, 4, 0, 2);
00300 QString sampleEditWhatsThisText =
00301 i18n("This sample text illustrates the current settings. "
00302 "You may edit it to test special characters." );
00303 QWhatsThis::add( sampleEdit, sampleEditWhatsThisText );
00304 connect(this, SIGNAL(fontSelected(const QFont &)),
00305 SLOT(displaySample(const QFont &)));
00306
00307 QVBoxLayout *vbox;
00308 if( makeFrame )
00309 {
00310 page = new QGroupBox( i18n("Actual Font"), this );
00311 topLayout->addWidget(page);
00312 vbox = new QVBoxLayout( page, KDialog::spacingHint() );
00313 vbox->addSpacing( fontMetrics().lineSpacing() );
00314 }
00315 else
00316 {
00317 page = new QWidget( this );
00318 topLayout->addWidget(page);
00319 vbox = new QVBoxLayout( page, 0, KDialog::spacingHint() );
00320 QLabel *label = new QLabel( i18n("Actual Font"), page );
00321 vbox->addWidget( label );
00322 }
00323
00324 xlfdEdit = new QLineEdit( page, "xlfdEdit" );
00325 vbox->addWidget( xlfdEdit );
00326
00327
00328 setFont( KGlobalSettings::generalFont(), usingFixed );
00329
00330 if( sizeIsRelativeState && sizeIsRelativeCheckBox )
00331 setSizeIsRelative( *sizeIsRelativeState );
00332
00333 KConfig *config = KGlobal::config();
00334 KConfigGroupSaver saver(config, QString::fromLatin1("General"));
00335 showXLFDArea(config->readBoolEntry(QString::fromLatin1("fontSelectorShowXLFD"), false));
00336 }
00337
00338 KFontChooser::~KFontChooser()
00339 {
00340 delete d;
00341 }
00342
00343 void KFontChooser::fillSizeList() {
00344 if(! sizeListBox) return;
00345
00346 static const int c[] =
00347 {
00348 4, 5, 6, 7,
00349 8, 9, 10, 11,
00350 12, 13, 14, 15,
00351 16, 17, 18, 19,
00352 20, 22, 24, 26,
00353 28, 32, 48, 64,
00354 0
00355 };
00356 for(int i = 0; c[i]; ++i)
00357 {
00358 sizeListBox->insertItem(QString::number(c[i]));
00359 }
00360 }
00361
00362 void KFontChooser::setColor( const QColor & col )
00363 {
00364 d->m_palette.setColor( QPalette::Active, QColorGroup::Text, col );
00365 QPalette pal = sampleEdit->palette();
00366 pal.setColor( QPalette::Active, QColorGroup::Text, col );
00367 sampleEdit->setPalette( pal );
00368 }
00369
00370 QColor KFontChooser::color() const
00371 {
00372 return d->m_palette.color( QPalette::Active, QColorGroup::Text );
00373 }
00374
00375 void KFontChooser::setBackgroundColor( const QColor & col )
00376 {
00377 d->m_palette.setColor( QPalette::Active, QColorGroup::Base, col );
00378 QPalette pal = sampleEdit->palette();
00379 pal.setColor( QPalette::Active, QColorGroup::Base, col );
00380 sampleEdit->setPalette( pal );
00381 }
00382
00383 QColor KFontChooser::backgroundColor() const
00384 {
00385 return d->m_palette.color( QPalette::Active, QColorGroup::Base );
00386 }
00387
00388 void KFontChooser::setSizeIsRelative( QButton::ToggleState relative )
00389 {
00390
00391 if( sizeIsRelativeCheckBox ) {
00392 if( QButton::NoChange == relative )
00393 sizeIsRelativeCheckBox->setNoChange();
00394 else
00395 sizeIsRelativeCheckBox->setChecked( QButton::On == relative );
00396 }
00397 }
00398
00399 QButton::ToggleState KFontChooser::sizeIsRelative() const
00400 {
00401 return sizeIsRelativeCheckBox
00402 ? sizeIsRelativeCheckBox->state()
00403 : QButton::NoChange;
00404 }
00405
00406 QSize KFontChooser::sizeHint( void ) const
00407 {
00408 return minimumSizeHint();
00409 }
00410
00411
00412 void KFontChooser::enableColumn( int column, bool state )
00413 {
00414 if( column & FamilyList )
00415 {
00416 familyListBox->setEnabled(state);
00417 }
00418 if( column & StyleList )
00419 {
00420 styleListBox->setEnabled(state);
00421 }
00422 if( column & SizeList )
00423 {
00424 sizeListBox->setEnabled(state);
00425 }
00426 }
00427
00428
00429 void KFontChooser::setFont( const QFont& aFont, bool onlyFixed )
00430 {
00431 selFont = aFont;
00432 selectedSize=aFont.pointSize();
00433 if (selectedSize == -1)
00434 selectedSize = QFontInfo(aFont).pointSize();
00435
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)) {
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 if (size == -1)
00572 size = QFontInfo(selFont).pointSize();
00573 QString sizeStr = QString::number(size);
00574
00575 int numEntries, i;
00576
00577 numEntries = familyListBox->count();
00578 for (i = 0; i < numEntries; i++) {
00579 if (family == familyListBox->text(i).lower()) {
00580 familyListBox->setCurrentItem(i);
00581 break;
00582 }
00583 }
00584
00585
00586 if ( (i == numEntries) )
00587 {
00588 if (family.contains('['))
00589 {
00590 family = family.left(family.find('[')).stripWhiteSpace();
00591 for (i = 0; i < numEntries; i++) {
00592 if (family == familyListBox->text(i).lower()) {
00593 familyListBox->setCurrentItem(i);
00594 break;
00595 }
00596 }
00597 }
00598 }
00599
00600
00601 if ( (i == numEntries) )
00602 {
00603 QString fallback = family+" [";
00604 for (i = 0; i < numEntries; i++) {
00605 if (familyListBox->text(i).lower().startsWith(fallback)) {
00606 familyListBox->setCurrentItem(i);
00607 break;
00608 }
00609 }
00610 }
00611
00612
00613 if ( (i == numEntries) )
00614 {
00615 for (i = 0; i < numEntries; i++) {
00616 if (familyListBox->text(i).lower().startsWith(family)) {
00617 familyListBox->setCurrentItem(i);
00618 break;
00619 }
00620 }
00621 }
00622
00623
00624 if ( i == numEntries )
00625 familyListBox->setCurrentItem( 0 );
00626
00627 styleListBox->setCurrentItem(style);
00628
00629 numEntries = sizeListBox->count();
00630 for (i = 0; i < numEntries; i++){
00631 if (sizeStr == sizeListBox->text(i)) {
00632 sizeListBox->setCurrentItem(i);
00633 break;
00634 }
00635 }
00636
00637 sizeOfFont->setValue(size);
00638 }
00639
00640
00641 void KFontChooser::getFontList( QStringList &list, uint fontListCriteria)
00642 {
00643 QFontDatabase dbase;
00644 QStringList lstSys(dbase.families());
00645
00646
00647 if (fontListCriteria)
00648 {
00649 QStringList lstFonts;
00650 for (QStringList::Iterator it = lstSys.begin(); it != lstSys.end(); ++it)
00651 {
00652 if ((fontListCriteria & FixedWidthFonts) > 0 && !dbase.isFixedPitch(*it)) continue;
00653 if (((fontListCriteria & (SmoothScalableFonts | ScalableFonts)) == ScalableFonts) &&
00654 !dbase.isBitmapScalable(*it)) continue;
00655 if ((fontListCriteria & SmoothScalableFonts) > 0 && !dbase.isSmoothlyScalable(*it)) continue;
00656 lstFonts.append(*it);
00657 }
00658
00659 if((fontListCriteria & FixedWidthFonts) > 0) {
00660
00661
00662 if (lstFonts.count() == 0)
00663 lstFonts.append("fixed");
00664 }
00665
00666 lstSys = lstFonts;
00667 }
00668
00669 lstSys.sort();
00670
00671 list = lstSys;
00672 }
00673
00674 void KFontChooser::addFont( QStringList &list, const char *xfont )
00675 {
00676 const char *ptr = strchr( xfont, '-' );
00677 if ( !ptr )
00678 return;
00679
00680 ptr = strchr( ptr + 1, '-' );
00681 if ( !ptr )
00682 return;
00683
00684 QString font = QString::fromLatin1(ptr + 1);
00685
00686 int pos;
00687 if ( ( pos = font.find( '-' ) ) > 0 ) {
00688 font.truncate( pos );
00689
00690 if ( font.find( QString::fromLatin1("open look"), 0, false ) >= 0 )
00691 return;
00692
00693 QStringList::Iterator it = list.begin();
00694
00695 for ( ; it != list.end(); ++it )
00696 if ( *it == font )
00697 return;
00698 list.append( font );
00699 }
00700 }
00701
00702 void KFontChooser::fillFamilyListBox(bool onlyFixedFonts)
00703 {
00704 QStringList fontList;
00705 getFontList(fontList, onlyFixedFonts?FixedWidthFonts:0);
00706 familyListBox->clear();
00707 familyListBox->insertStringList(fontList);
00708 }
00709
00710 void KFontChooser::showXLFDArea(bool show)
00711 {
00712 if( show )
00713 {
00714 xlfdEdit->parentWidget()->show();
00715 }
00716 else
00717 {
00718 xlfdEdit->parentWidget()->hide();
00719 }
00720 }
00721
00723
00724 KFontDialog::KFontDialog( QWidget *parent, const char* name,
00725 bool onlyFixed, bool modal,
00726 const QStringList &fontList, bool makeFrame, bool diff,
00727 QButton::ToggleState *sizeIsRelativeState )
00728 : KDialogBase( parent, name, modal, i18n("Select Font"), Ok|Cancel, Ok )
00729 {
00730 chooser = new KFontChooser( this, "fontChooser",
00731 onlyFixed, fontList, makeFrame, 8,
00732 diff, sizeIsRelativeState );
00733 setMainWidget(chooser);
00734 }
00735
00736
00737 int KFontDialog::getFontDiff( QFont &theFont, int &diffFlags, bool onlyFixed,
00738 QWidget *parent, bool makeFrame,
00739 QButton::ToggleState *sizeIsRelativeState )
00740 {
00741 KFontDialog dlg( parent, "Font Selector", onlyFixed, true, QStringList(),
00742 makeFrame, true, sizeIsRelativeState );
00743 dlg.setFont( theFont, onlyFixed );
00744
00745 int result = dlg.exec();
00746 if( result == Accepted )
00747 {
00748 theFont = dlg.chooser->font();
00749 diffFlags = dlg.chooser->fontDiffFlags();
00750 if( sizeIsRelativeState )
00751 *sizeIsRelativeState = dlg.chooser->sizeIsRelative();
00752 }
00753 return result;
00754 }
00755
00756 int KFontDialog::getFont( QFont &theFont, bool onlyFixed,
00757 QWidget *parent, bool makeFrame,
00758 QButton::ToggleState *sizeIsRelativeState )
00759 {
00760 KFontDialog dlg( parent, "Font Selector", onlyFixed, true, QStringList(),
00761 makeFrame, false, sizeIsRelativeState );
00762 dlg.setFont( theFont, onlyFixed );
00763
00764 int result = dlg.exec();
00765 if( result == Accepted )
00766 {
00767 theFont = dlg.chooser->font();
00768 if( sizeIsRelativeState )
00769 *sizeIsRelativeState = dlg.chooser->sizeIsRelative();
00770 }
00771 return result;
00772 }
00773
00774
00775 int KFontDialog::getFontAndText( QFont &theFont, QString &theString,
00776 bool onlyFixed, QWidget *parent,
00777 bool makeFrame,
00778 QButton::ToggleState *sizeIsRelativeState )
00779 {
00780 KFontDialog dlg( parent, "Font and Text Selector", onlyFixed, true,
00781 QStringList(), makeFrame, false, sizeIsRelativeState );
00782 dlg.setFont( theFont, onlyFixed );
00783
00784 int result = dlg.exec();
00785 if( result == Accepted )
00786 {
00787 theFont = dlg.chooser->font();
00788 theString = dlg.chooser->sampleText();
00789 if( sizeIsRelativeState )
00790 *sizeIsRelativeState = dlg.chooser->sizeIsRelative();
00791 }
00792 return result;
00793 }
00794
00795 void KFontChooser::virtual_hook( int, void* )
00796 { }
00797
00798 void KFontDialog::virtual_hook( int id, void* data )
00799 { KDialogBase::virtual_hook( id, data ); }