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

tdeui

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