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

tdeui

tdefontdialog.cpp

00001 /*
00002 
00003     Requires the Qt widget libraries, available at no cost at
00004     http://www.troll.no
00005 
00006     Copyright (C) 1996 Bernd Johannes Wuebben  <wuebben@kde.org>
00007     Copyright (c) 1999 Preston Brown <pbrown@kde.org>
00008     Copyright (c) 1999 Mario Weilguni <mweilguni@kde.org>
00009 
00010     This library is free software; you can redistribute it and/or
00011     modify it under the terms of the GNU Library General Public
00012     License as published by the Free Software Foundation; either
00013     version 2 of the License, or (at your option) any later version.
00014 
00015     This library is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018     Library General Public License for more details.
00019 
00020     You should have received a copy of the GNU Library General Public License
00021     along with this library; see the file COPYING.LIB.  If not, write to
00022     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00023     Boston, MA 02110-1301, USA.
00024 */
00025 
00026 #include <config.h>
00027 
00028 #include <stdio.h>
00029 #include <stdlib.h>
00030 
00031 #include <tqcombobox.h>
00032 #include <tqcheckbox.h>
00033 #include <tqfile.h>
00034 #include <tqfont.h>
00035 #include <tqgroupbox.h>
00036 #include <tqlabel.h>
00037 #include <tqlayout.h>
00038 #include <tqscrollbar.h>
00039 #include <tqstringlist.h>
00040 #include <tqfontdatabase.h>
00041 #include <tqwhatsthis.h>
00042 #include <tqtooltip.h>
00043 
00044 #include <tdeapplication.h>
00045 #include <kcharsets.h>
00046 #include <tdeconfig.h>
00047 #include <kdialog.h>
00048 #include <tdeglobal.h>
00049 #include <tdeglobalsettings.h>
00050 #include <tqlineedit.h>
00051 #include <tdelistbox.h>
00052 #include <tdelocale.h>
00053 #include <kstandarddirs.h>
00054 #include <kdebug.h>
00055 #include <knuminput.h>
00056 
00057 #include "tdefontdialog.moc"
00058 
00059 static int minimumListWidth( const TQListBox *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 = TQMAX(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 TQListBox *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 TDEFontChooser::TDEFontChooserPrivate
00084 {
00085 public:
00086     TDEFontChooserPrivate()
00087         { m_palette.setColor(TQPalette::Active, TQColorGroup::Text, Qt::black);
00088           m_palette.setColor(TQPalette::Active, TQColorGroup::Base, Qt::white); }
00089     TQPalette m_palette;
00090 };
00091 
00092 TDEFontChooser::TDEFontChooser(TQWidget *parent, const char *name,
00093                bool onlyFixed, const TQStringList &fontList,
00094                bool makeFrame, int visibleListSize, bool diff,
00095                            TQButton::ToggleState *sizeIsRelativeState )
00096   : TQWidget(parent, name), usingFixed(onlyFixed)
00097 {
00098   charsetsCombo = 0;
00099 
00100   TQString mainWhatsThisText =
00101     i18n( "Here you can choose the font to be used." );
00102   TQWhatsThis::add( this, mainWhatsThisText );
00103 
00104   d = new TDEFontChooserPrivate;
00105   TQVBoxLayout *topLayout = new TQVBoxLayout( this, 0, KDialog::spacingHint() );
00106   int checkBoxGap = KDialog::spacingHint() / 2;
00107 
00108   TQWidget *page;
00109   TQGridLayout *gridLayout;
00110   int row = 0;
00111   if( makeFrame )
00112   {
00113     page = new TQGroupBox( i18n("Requested Font"), this );
00114     topLayout->addWidget(page);
00115     gridLayout = new TQGridLayout( page, 5, 3, KDialog::marginHint(), KDialog::spacingHint() );
00116     gridLayout->addRowSpacing( 0, fontMetrics().lineSpacing() );
00117     row = 1;
00118   }
00119   else
00120   {
00121     page = new TQWidget( this );
00122     topLayout->addWidget(page);
00123     gridLayout = new TQGridLayout( page, 4, 3, 0, KDialog::spacingHint() );
00124   }
00125 
00126   //
00127   // first, create the labels across the top
00128   //
00129   TQHBoxLayout *familyLayout = new TQHBoxLayout();
00130   familyLayout->addSpacing( checkBoxGap );
00131   if (diff) {
00132     familyCheckbox = new TQCheckBox(i18n("Font"), page);
00133     connect(familyCheckbox, TQT_SIGNAL(toggled(bool)), TQT_SLOT(toggled_checkbox()));
00134     familyLayout->addWidget(familyCheckbox, 0, Qt::AlignLeft);
00135     TQString familyCBToolTipText =
00136       i18n("Change font family?");
00137     TQString familyCBWhatsThisText =
00138       i18n("Enable this checkbox to change the font family settings.");
00139     TQWhatsThis::add( familyCheckbox, familyCBWhatsThisText );
00140     TQToolTip::add(   familyCheckbox, familyCBToolTipText );
00141     familyLabel = 0;
00142   } else {
00143     familyCheckbox = 0;
00144     familyLabel = new TQLabel( i18n("Font:"), page, "familyLabel" );
00145     familyLayout->addWidget(familyLabel, 1, Qt::AlignLeft);
00146   }
00147   gridLayout->addLayout(familyLayout, row, 0 );
00148 
00149   TQHBoxLayout *styleLayout = new TQHBoxLayout();
00150   if (diff) {
00151      styleCheckbox = new TQCheckBox(i18n("Font style"), page);
00152      connect(styleCheckbox, TQT_SIGNAL(toggled(bool)), TQT_SLOT(toggled_checkbox()));
00153      styleLayout->addWidget(styleCheckbox, 0, Qt::AlignLeft);
00154     TQString styleCBToolTipText =
00155       i18n("Change font style?");
00156     TQString styleCBWhatsThisText =
00157       i18n("Enable this checkbox to change the font style settings.");
00158     TQWhatsThis::add( styleCheckbox, styleCBWhatsThisText );
00159     TQToolTip::add(   styleCheckbox, styleCBToolTipText );
00160     styleLabel = 0;
00161   } else {
00162     styleCheckbox = 0;
00163     styleLabel = new TQLabel( 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   TQHBoxLayout *sizeLayout = new TQHBoxLayout();
00170   if (diff) {
00171     sizeCheckbox = new TQCheckBox(i18n("Size"),page);
00172     connect(sizeCheckbox, TQT_SIGNAL(toggled(bool)), TQT_SLOT(toggled_checkbox()));
00173     sizeLayout->addWidget(sizeCheckbox, 0, Qt::AlignLeft);
00174     TQString sizeCBToolTipText =
00175       i18n("Change font size?");
00176     TQString sizeCBWhatsThisText =
00177       i18n("Enable this checkbox to change the font size settings.");
00178     TQWhatsThis::add( sizeCheckbox, sizeCBWhatsThisText );
00179     TQToolTip::add(   sizeCheckbox, sizeCBToolTipText );
00180     sizeLabel = 0;
00181   } else {
00182     sizeCheckbox = 0;
00183     sizeLabel = new TQLabel( i18n("Size:"), page, "sizeLabel");
00184     sizeLayout->addWidget(sizeLabel, 1, Qt::AlignLeft);
00185   }
00186   sizeLayout->addSpacing( checkBoxGap );
00187   sizeLayout->addSpacing( checkBoxGap ); // prevent label from eating border
00188   gridLayout->addLayout(sizeLayout, row, 2 );
00189 
00190   row ++;
00191 
00192   //
00193   // now create the actual boxes that hold the info
00194   //
00195   familyListBox = new TDEListBox( page, "familyListBox");
00196   familyListBox->setEnabled( !diff );
00197   gridLayout->addWidget( familyListBox, row, 0 );
00198   TQString fontFamilyWhatsThisText =
00199     i18n("Here you can choose the font family to be used." );
00200   TQWhatsThis::add( familyListBox, fontFamilyWhatsThisText );
00201   TQWhatsThis::add(diff?(TQWidget *) familyCheckbox:(TQWidget *) familyLabel, fontFamilyWhatsThisText );
00202   connect(familyListBox, TQT_SIGNAL(highlighted(const TQString &)),
00203       TQT_SLOT(family_chosen_slot(const TQString &)));
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 TDEListBox( page, "styleListBox");
00218   styleListBox->setEnabled( !diff );
00219   gridLayout->addWidget(styleListBox, row, 1);
00220   TQString fontStyleWhatsThisText =
00221     i18n("Here you can choose the font style to be used." );
00222   TQWhatsThis::add( styleListBox, fontStyleWhatsThisText );
00223   TQWhatsThis::add(diff?(TQWidget *)styleCheckbox:(TQWidget *)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, TQT_SIGNAL(highlighted(const TQString &)),
00233       TQT_SLOT(style_chosen_slot(const TQString &)));
00234 
00235 
00236   sizeListBox = new TDEListBox( 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     TQString sizeIsRelativeCBText =
00244       i18n("Relative");
00245     TQString sizeIsRelativeCBToolTipText =
00246       i18n("Font size<br><i>fixed</i> or <i>relative</i><br>to environment");
00247     TQString 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 TQCheckBox( sizeIsRelativeCBText,
00252                                             page,
00253                                            "sizeIsRelativeCheckBox" );
00254     sizeIsRelativeCheckBox->setTristate( diff );
00255     TQGridLayout *sizeLayout2 = new TQGridLayout( 3,2, KDialog::spacingHint()/2, "sizeLayout2" );
00256     gridLayout->addLayout(sizeLayout2, row, 2);
00257     sizeLayout2->setColStretch( 1, 1 ); // to prevent text from eating the right border
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     TQWhatsThis::add( sizeIsRelativeCheckBox, sizeIsRelativeCBWhatsThisText );
00262     TQToolTip::add(   sizeIsRelativeCheckBox, sizeIsRelativeCBToolTipText );
00263   }
00264   else {
00265     sizeIsRelativeCheckBox = 0L;
00266     TQGridLayout *sizeLayout2 = new TQGridLayout( 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   TQString fontSizeWhatsThisText =
00272     i18n("Here you can choose the font size to be used." );
00273   TQWhatsThis::add( sizeListBox, fontSizeWhatsThisText );
00274   TQWhatsThis::add( diff?(TQWidget *)sizeCheckbox:(TQWidget *)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, TQT_SIGNAL( valueChanged(int) ),
00283            TQT_SLOT(size_value_slot(int)));
00284 
00285   connect( sizeListBox, TQT_SIGNAL(highlighted(const TQString&)),
00286        TQT_SLOT(size_chosen_slot(const TQString&)) );
00287   sizeListBox->setSelected(sizeListBox->findItem(TQString::number(10)), true); // default to 10pt.
00288 
00289   row ++;
00290 
00291   row ++;
00292   sampleEdit = new TQLineEdit( page, "sampleEdit");
00293   TQFont tmpFont( TDEGlobalSettings::generalFont().family(), 64, TQFont::Black );
00294   sampleEdit->setFont(tmpFont);
00295   //i18n: This is a classical test phrase. (It contains all letters from A to Z.)
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   TQString sampleEditWhatsThisText =
00301     i18n("This sample text illustrates the current settings. "
00302          "You may edit it to test special characters." );
00303   TQWhatsThis::add( sampleEdit, sampleEditWhatsThisText );
00304   connect(this, TQT_SIGNAL(fontSelected(const TQFont &)),
00305       TQT_SLOT(displaySample(const TQFont &)));
00306 
00307   TQVBoxLayout *vbox;
00308   if( makeFrame )
00309   {
00310     page = new TQGroupBox( i18n("Actual Font"), this );
00311     topLayout->addWidget(page);
00312     vbox = new TQVBoxLayout( page, KDialog::spacingHint() );
00313     vbox->addSpacing( fontMetrics().lineSpacing() );
00314   }
00315   else
00316   {
00317     page = new TQWidget( this );
00318     topLayout->addWidget(page);
00319     vbox = new TQVBoxLayout( page, 0, KDialog::spacingHint() );
00320     TQLabel *label = new TQLabel( i18n("Actual Font"), page );
00321     vbox->addWidget( label );
00322   }
00323 
00324   xlfdEdit = new TQLineEdit( page, "xlfdEdit" );
00325   vbox->addWidget( xlfdEdit );
00326 
00327   // lets initialize the display if possible
00328   setFont( TDEGlobalSettings::generalFont(), usingFixed );
00329   // check or uncheck or gray out the "relative" checkbox
00330   if( sizeIsRelativeState && sizeIsRelativeCheckBox )
00331     setSizeIsRelative( *sizeIsRelativeState );
00332 
00333   TDEConfig *config = TDEGlobal::config();
00334   TDEConfigGroupSaver saver(config, TQString::fromLatin1("General"));
00335   showXLFDArea(config->readBoolEntry(TQString::fromLatin1("fontSelectorShowXLFD"), false));
00336 }
00337 
00338 TDEFontChooser::~TDEFontChooser()
00339 {
00340   delete d;
00341 }
00342 
00343 void TDEFontChooser::fillSizeList() {
00344   if(! sizeListBox) return; //assertion.
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(TQString::number(c[i]));
00359   }
00360 }
00361 
00362 void TDEFontChooser::setColor( const TQColor & col )
00363 {
00364   d->m_palette.setColor( TQPalette::Active, TQColorGroup::Text, col );
00365   TQPalette pal = sampleEdit->palette();
00366   pal.setColor( TQPalette::Active, TQColorGroup::Text, col );
00367   sampleEdit->setPalette( pal );
00368 }
00369 
00370 TQColor TDEFontChooser::color() const
00371 {
00372   return d->m_palette.color( TQPalette::Active, TQColorGroup::Text );
00373 }
00374 
00375 void TDEFontChooser::setBackgroundColor( const TQColor & col )
00376 {
00377   d->m_palette.setColor( TQPalette::Active, TQColorGroup::Base, col );
00378   TQPalette pal = sampleEdit->palette();
00379   pal.setColor( TQPalette::Active, TQColorGroup::Base, col );
00380   sampleEdit->setPalette( pal );
00381 }
00382 
00383 TQColor TDEFontChooser::backgroundColor() const
00384 {
00385   return d->m_palette.color( TQPalette::Active, TQColorGroup::Base );
00386 }
00387 
00388 void TDEFontChooser::setSizeIsRelative( TQButton::ToggleState relative )
00389 {
00390   // check or uncheck or gray out the "relative" checkbox
00391   if( sizeIsRelativeCheckBox ) {
00392     if( TQButton::NoChange == relative )
00393       sizeIsRelativeCheckBox->setNoChange();
00394     else
00395       sizeIsRelativeCheckBox->setChecked(  TQButton::On == relative );
00396   }
00397 }
00398 
00399 TQButton::ToggleState TDEFontChooser::sizeIsRelative() const
00400 {
00401   return sizeIsRelativeCheckBox
00402        ? sizeIsRelativeCheckBox->state()
00403        : TQButton::NoChange;
00404 }
00405 
00406 TQSize TDEFontChooser::sizeHint( void ) const
00407 {
00408   return minimumSizeHint();
00409 }
00410 
00411 
00412 void TDEFontChooser::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 TDEFontChooser::setFont( const TQFont& aFont, bool onlyFixed )
00430 {
00431   selFont = aFont;
00432   selectedSize=aFont.pointSize();
00433   if (selectedSize == -1)
00434      selectedSize = TQFontInfo(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 TDEFontChooser::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 TDEFontChooser::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 TDEFontChooser::family_chosen_slot(const TQString& family)
00465 {
00466     TQFontDatabase dbase;
00467     TQStringList styles = TQStringList(dbase.styles(family));
00468     styleListBox->clear();
00469     currentStyles.clear();
00470     for ( TQStringList::Iterator it = styles.begin(); it != styles.end(); ++it ) {
00471         TQString 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     TQListBoxItem *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(TQString::null);
00497 }
00498 
00499 void TDEFontChooser::size_chosen_slot(const TQString& size){
00500 
00501   selectedSize=size.toInt();
00502   sizeOfFont->setValue(selectedSize);
00503   selFont.setPointSize(selectedSize);
00504   emit fontSelected(selFont);
00505 }
00506 
00507 void TDEFontChooser::size_value_slot(int val) {
00508   selFont.setPointSize(val);
00509   emit fontSelected(selFont);
00510 }
00511 
00512 void TDEFontChooser::style_chosen_slot(const TQString& style)
00513 {
00514     TQString currentStyle;
00515     if (style.isEmpty())
00516        currentStyle = styleListBox->currentText();
00517     else
00518        currentStyle = style;
00519 
00520     int diff=0; // the difference between the font size requested and what we can show.
00521 
00522     sizeListBox->clear();
00523     TQFontDatabase dbase;
00524     if(dbase.isSmoothlyScalable(familyListBox->currentText(), currentStyles[currentStyle])) {  // is vector font
00525         //sampleEdit->setPaletteBackgroundPixmap( VectorPixmap ); // TODO
00526         fillSizeList();
00527     } else {                                // is bitmap font.
00528         //sampleEdit->setPaletteBackgroundPixmap( BitmapPixmap ); // TODO
00529         TQValueList<int> sizes = dbase.smoothSizes(familyListBox->currentText(), currentStyles[currentStyle]);
00530         if(sizes.count() > 0) {
00531             TQValueList<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(TQString::number(*it));
00536             }
00537         } else // there are times QT does not provide the list..
00538             fillSizeList();
00539     }
00540     sizeListBox->blockSignals(true);
00541     sizeListBox->setSelected(sizeListBox->findItem(TQString::number(selectedSize)), true);
00542     sizeListBox->blockSignals(false);
00543     sizeListBox->ensureCurrentVisible();
00544 
00545     //kdDebug() << "Showing: " << familyListBox->currentText() << ", " << currentStyles[currentStyle] << ", " << selectedSize-diff << endl;
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 TDEFontChooser::displaySample(const TQFont& font)
00553 {
00554   sampleEdit->setFont(font);
00555   sampleEdit->setCursorPosition(0);
00556   xlfdEdit->setText(font.rawName());
00557   xlfdEdit->setCursorPosition(0);
00558 
00559   //TQFontInfo a = TQFontInfo(font);
00560   //kdDebug() << "font: " << a.family () << ", " << a.pointSize () << endl;
00561   //kdDebug() << "      (" << font.toString() << ")\n";
00562 }
00563 
00564 void TDEFontChooser::setupDisplay()
00565 {
00566   // Calling familyListBox->setCurrentItem() causes the value of selFont
00567   // to change, so we save the family, style and size beforehand.
00568   TQString family = TQString(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 = TQFontInfo(selFont).pointSize();
00573   TQString sizeStr = TQString::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   // 1st Fallback
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   // 2nd Fallback
00601   if ( (i == numEntries) )
00602   {
00603     TQString 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   // 3rd Fallback
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   // Fall back in case nothing matched. Otherwise, diff doesn't work
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 TDEFontChooser::getFontList( TQStringList &list, uint fontListCriteria)
00642 {
00643   TQFontDatabase dbase;
00644   TQStringList lstSys(dbase.families());
00645 
00646   // if we have criteria; then check fonts before adding
00647   if (fontListCriteria)
00648   {
00649     TQStringList lstFonts;
00650     for (TQStringList::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         // Fallback.. if there are no fixed fonts found, it's probably a
00661         // bug in the font server or Qt.  In this case, just use 'fixed'
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 TDEFontChooser::addFont( TQStringList &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   TQString font = TQString::fromLatin1(ptr + 1);
00685 
00686   int pos;
00687   if ( ( pos = font.find( '-' ) ) > 0 ) {
00688     font.truncate( pos );
00689 
00690     if ( font.find( TQString::fromLatin1("open look"), 0, false ) >= 0 )
00691       return;
00692 
00693     TQStringList::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 TDEFontChooser::fillFamilyListBox(bool onlyFixedFonts)
00703 {
00704   TQStringList fontList;
00705   getFontList(fontList, onlyFixedFonts?FixedWidthFonts:0);
00706   familyListBox->clear();
00707   familyListBox->insertStringList(fontList);
00708 }
00709 
00710 void TDEFontChooser::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 TDEFontDialog::TDEFontDialog( TQWidget *parent, const char* name,
00725               bool onlyFixed, bool modal,
00726               const TQStringList &fontList, bool makeFrame, bool diff,
00727                           TQButton::ToggleState *sizeIsRelativeState )
00728   : KDialogBase( parent, name, modal, i18n("Select Font"), Ok|Cancel, Ok )
00729 {
00730   chooser = new TDEFontChooser( this, "fontChooser",
00731                               onlyFixed, fontList, makeFrame, 8,
00732                               diff, sizeIsRelativeState );
00733   setMainWidget(chooser);
00734 }
00735 
00736 
00737 int TDEFontDialog::getFontDiff( TQFont &theFont, int &diffFlags, bool onlyFixed,
00738                              TQWidget *parent, bool makeFrame,
00739                              TQButton::ToggleState *sizeIsRelativeState )
00740 {
00741   TDEFontDialog dlg( parent, "Font Selector", onlyFixed, true, TQStringList(),
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 TDEFontDialog::getFont( TQFont &theFont, bool onlyFixed,
00757                           TQWidget *parent, bool makeFrame,
00758                           TQButton::ToggleState *sizeIsRelativeState )
00759 {
00760   TDEFontDialog dlg( parent, "Font Selector", onlyFixed, true, TQStringList(),
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 TDEFontDialog::getFontAndText( TQFont &theFont, TQString &theString,
00776                  bool onlyFixed, TQWidget *parent,
00777                  bool makeFrame,
00778                                  TQButton::ToggleState *sizeIsRelativeState )
00779 {
00780   TDEFontDialog dlg( parent, "Font and Text Selector", onlyFixed, true,
00781            TQStringList(), 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 TDEFontChooser::virtual_hook( int, void* )
00796 { /*BASE::virtual_hook( id, data );*/ }
00797 
00798 void TDEFontDialog::virtual_hook( int id, void* data )
00799 { KDialogBase::virtual_hook( id, data ); }

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.7.1
This website is maintained by Timothy Pearson.