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