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

tdeui

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

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
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.8.8
This website is maintained by Timothy Pearson.