summaryrefslogtreecommitdiffstats
path: root/src/dialogs/qfontdialog.cpp
blob: 3f713d9e03eb0cb4796bc787b59b209318ee0737 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
/****************************************************************************
**
** Implementation of TQFontDialog
**
** Created : 970605
**
** Copyright (C) 1992-2008 Trolltech ASA.  All rights reserved.
**
** This file is part of the dialogs module of the TQt GUI Toolkit.
**
** This file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free
** Software Foundation and appearing in the files LICENSE.GPL2
** and LICENSE.GPL3 included in the packaging of this file.
** Alternatively you may (at your option) use any later version
** of the GNU General Public License if such license has been
** publicly approved by Trolltech ASA (or its successors, if any)
** and the KDE Free TQt Foundation.
**
** Please review the following information to ensure GNU General
** Public Licensing requirements will be met:
** http://trolltech.com/products/qt/licenses/licensing/opensource/.
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
** or contact the sales department at [email protected].
**
** This file may be used under the terms of the Q Public License as
** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
** included in the packaging of this file.  Licensees holding valid TQt
** Commercial licenses may use this file in accordance with the TQt
** Commercial License Agreement provided with the Software.
**
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
** herein.
**
**********************************************************************/

#include "ntqwindowdefs.h"

#ifndef TQT_NO_FONTDIALOG

#include "ntqfontdialog.h"

#include "ntqlineedit.h"
#include "ntqlistbox.h"
#include "ntqpushbutton.h"
#include "ntqcheckbox.h"
#include "ntqcombobox.h"
#include "ntqlayout.h"
#include "ntqvgroupbox.h"
#include "ntqhgroupbox.h"
#include "ntqlabel.h"
#include "ntqapplication.h"
#include "ntqfontdatabase.h"
#include "ntqstyle.h"
#include <private/qfontdata_p.h>
#include <ntqvalidator.h>

#ifdef Q_WS_X11
#include "private/tqttdeintegration_x11_p.h"
#endif

/*!
  \class TQFontDialog ntqfontdialog.h
  \ingroup dialogs
  \mainclass
  \brief The TQFontDialog class provides a dialog widget for selecting a font.

  The usual way to use this class is to call one of the static convenience
  functions, e.g. getFont().

  Examples:

  \code
    bool ok;
    TQFont font = TQFontDialog::getFont(
		    &ok, TQFont( "Helvetica [Cronyx]", 10 ), this );
    if ( ok ) {
	// font is set to the font the user selected
    } else {
	// the user canceled the dialog; font is set to the initial
	// value, in this case Helvetica [Cronyx], 10
    }
  \endcode

    The dialog can also be used to set a widget's font directly:
  \code
    myWidget.setFont( TQFontDialog::getFont( 0, myWidget.font() ) );
  \endcode
  If the user clicks OK the font they chose will be used for myWidget,
  and if they click Cancel the original font is used.

  \sa TQFont TQFontInfo TQFontMetrics

  <img src=qfontdlg-w.png>
*/

class TQFontDialogPrivate
{
public:
    TQFontDialogPrivate() : script( TQFontPrivate::defaultScript ) {};
    TQLabel * familyAccel;
    TQLineEdit * familyEdit;
    TQListBox * familyList;

    TQLabel * styleAccel;
    TQLineEdit * styleEdit;
    TQListBox * styleList;

    TQLabel * sizeAccel;
    TQLineEdit * sizeEdit;
    TQListBox * sizeList;

    TQVGroupBox * effects;
    TQCheckBox * strikeout;
    TQCheckBox * underline;
    TQComboBox * color;

    TQHGroupBox * sample;
    TQLineEdit * sampleEdit;

    TQLabel * scriptAccel;
    TQComboBox * scriptCombo;

    TQPushButton * ok;
    TQPushButton * cancel;

    TQBoxLayout * buttonLayout;
    TQBoxLayout * effectsLayout;
    TQBoxLayout * sampleLayout;
    TQBoxLayout * sampleEditLayout;

    TQFontDatabase fdb;

    TQString       family;
    TQFont::Script script;
    TQString       style;
    int           size;

    bool smoothScalable;
};


/*!
  \internal
  Constructs a standard font dialog.

  Use setFont() to set the initial font attributes.

  The \a parent, \a name, \a modal and \a f parameters are passed to
  the TQDialog constructor.

  \sa getFont()
*/

TQFontDialog::TQFontDialog( TQWidget *parent, const char *name,
			  bool modal, WFlags f )
    : TQDialog( parent, name, modal, f )
{
    setSizeGripEnabled( TRUE );
    d = new TQFontDialogPrivate;
    // grid
    d->familyEdit = new TQLineEdit( this, "font family I" );
    d->familyEdit->setReadOnly( TRUE );
    d->familyList = new TQListBox( this, "font family II" );
    d->familyEdit->setFocusProxy( d->familyList );

    d->familyAccel
	= new TQLabel( d->familyList, tr("&Font"), this, "family accelerator" );
    d->familyAccel->setIndent( 2 );

    d->styleEdit = new TQLineEdit( this, "font style I" );
    d->styleEdit->setReadOnly( TRUE );
    d->styleList = new TQListBox( this, "font style II" );
    d->styleEdit->setFocusProxy( d->styleList );

    d->styleAccel
	= new TQLabel( d->styleList, tr("Font st&yle"), this, "style accelerator" );
    d->styleAccel->setIndent( 2 );

    d->sizeEdit = new TQLineEdit( this, "font size I" );
    d->sizeEdit->setFocusPolicy( ClickFocus );
    TQIntValidator *validator = new TQIntValidator( 1, 512, this );
    d->sizeEdit->setValidator( validator );
    d->sizeList = new TQListBox( this, "font size II" );

    d->sizeAccel
	= new TQLabel ( d->sizeEdit, tr("&Size"), this, "size accelerator" );
    d->sizeAccel->setIndent( 2 );

    // effects box
    d->effects = new TQVGroupBox( tr("Effects"), this, "font effects" );
    d->strikeout = new TQCheckBox( d->effects, "strikeout on/off" );
    d->strikeout->setText( tr("Stri&keout") );
    d->underline = new TQCheckBox( d->effects, "underline on/off" );
    d->underline->setText( tr("&Underline") );

    d->sample = new TQHGroupBox( tr("Sample"), this, "sample text" );
    d->sampleEdit = new TQLineEdit( d->sample, "r/w sample text" );
    d->sampleEdit->setSizePolicy( TQSizePolicy( TQSizePolicy::Ignored, TQSizePolicy::Ignored) );
    d->sampleEdit->setAlignment( AlignCenter );
    // Note that the sample text is *not* translated with tr(), as the
    // characters used depend on the charset encoding.
    d->sampleEdit->setText( "AaBbYyZz" );

    d->scriptCombo = new TQComboBox( FALSE, this, "font encoding" );

    d->scriptAccel
	= new TQLabel( d->scriptCombo, tr("Scr&ipt"), this,"encoding label");
    d->scriptAccel->setIndent( 2 );

    d->size = 0;
    d->smoothScalable = FALSE;

    connect( d->scriptCombo, TQ_SIGNAL(activated(int)),
	     TQ_SLOT(scriptHighlighted(int)) );
    connect( d->familyList, TQ_SIGNAL(highlighted(int)),
	     TQ_SLOT(familyHighlighted(int)) );
    connect( d->styleList, TQ_SIGNAL(highlighted(int)),
	     TQ_SLOT(styleHighlighted(int)) );
    connect( d->sizeList, TQ_SIGNAL(highlighted(const TQString&)),
	     TQ_SLOT(sizeHighlighted(const TQString&)) );
    connect( d->sizeEdit, TQ_SIGNAL(textChanged(const TQString&)),
	     TQ_SLOT(sizeChanged(const TQString&)) );

    connect( d->strikeout, TQ_SIGNAL(clicked()),
	     TQ_SLOT(updateSample()) );
    connect( d->underline, TQ_SIGNAL(clicked()),
	     TQ_SLOT(updateSample()) );

    (void)d->familyList->sizeHint();
    (void)d->styleList->sizeHint();
    (void)d->sizeList->sizeHint();

    for (int i = 0; i < TQFont::NScripts; i++) {
	TQString scriptname = TQFontDatabase::scriptName((TQFont::Script) i);
	if ( !scriptname.isEmpty() )
	    d->scriptCombo->insertItem( scriptname );
    }

    updateFamilies();
    if ( d->familyList->count() != 0 )
	d->familyList->setCurrentItem( 0 );

    // grid layout
    TQGridLayout * mainGrid = new TQGridLayout( this, 9, 6, 12, 0 );

    mainGrid->addWidget( d->familyAccel, 0, 0 );
    mainGrid->addWidget( d->familyEdit, 1, 0 );
    mainGrid->addWidget( d->familyList, 2, 0 );

    mainGrid->addWidget( d->styleAccel, 0, 2 );
    mainGrid->addWidget( d->styleEdit, 1, 2 );
    mainGrid->addWidget( d->styleList, 2, 2 );

    mainGrid->addWidget( d->sizeAccel, 0, 4 );
    mainGrid->addWidget( d->sizeEdit, 1, 4 );
    mainGrid->addWidget( d->sizeList, 2, 4 );

    mainGrid->setColStretch( 0, 38 );
    mainGrid->setColStretch( 2, 24 );
    mainGrid->setColStretch( 4, 10 );

    mainGrid->addColSpacing( 1, 6 );
    mainGrid->addColSpacing( 3, 6 );
    mainGrid->addColSpacing( 5, 6 );

    mainGrid->addRowSpacing( 3, 12 );

    mainGrid->addWidget( d->effects, 4, 0 );

    mainGrid->addMultiCellWidget( d->sample, 4, 7, 2, 4 );

    mainGrid->addWidget( d->scriptAccel, 5, 0 );
    mainGrid->addRowSpacing( 6, 2 );
    mainGrid->addWidget( d->scriptCombo, 7, 0 );

    mainGrid->addRowSpacing( 8, 12 );

    TQHBoxLayout *buttonBox = new TQHBoxLayout;
    mainGrid->addMultiCell( buttonBox, 9, 9, 0, 4 );

    buttonBox->addStretch( 1 );
    TQString okt = modal ? tr("OK") : tr("Apply");
    d->ok = new TQPushButton( okt, this, "accept font selection" );
    buttonBox->addWidget( d->ok );
    if ( modal )
	connect( d->ok, TQ_SIGNAL(clicked()), TQ_SLOT(accept()) );
    d->ok->setDefault( TRUE );

    buttonBox->addSpacing( 12 );

    TQString cancelt = modal ? tr("Cancel") : tr("Close");
    d->cancel = new TQPushButton( cancelt, this, "cancel/close" );
    buttonBox->addWidget( d->cancel );
    connect( d->cancel, TQ_SIGNAL(clicked()), TQ_SLOT(reject()) );

    resize( 500, 360 );

    d->sizeEdit->installEventFilter( this );
    d->familyList->installEventFilter( this );
    d->styleList->installEventFilter( this );
    d->sizeList->installEventFilter( this );

    d->familyList->setFocus();
}

/*!
  \internal
 Destroys the font dialog and frees up its storage.
*/

TQFontDialog::~TQFontDialog()
{
    delete d;
    d = 0;
}

/*!
  Executes a modal font dialog and returns a font.

  If the user clicks OK, the selected font is returned. If the user
  clicks Cancel, the \a initial font is returned.

  The dialog is called \a name, with the parent \a parent.
  \a initial is the initially selected font.
  If the \a ok parameter is not-null, \e *\a ok is set to TRUE if the
  user clicked OK, and set to FALSE if the user clicked Cancel.

  This static function is less flexible than the full TQFontDialog
  object, but is convenient and easy to use.

  Examples:
  \code
    bool ok;
    TQFont font = TQFontDialog::getFont( &ok, TQFont( "Times", 12 ), this );
    if ( ok ) {
	// font is set to the font the user selected
    } else {
	// the user canceled the dialog; font is set to the initial
	// value, in this case Times, 12.
    }
  \endcode

    The dialog can also be used to set a widget's font directly:
  \code
    myWidget.setFont( TQFontDialog::getFont( 0, myWidget.font() ) );
  \endcode
  In this example, if the user clicks OK the font they chose will be
  used, and if they click Cancel the original font is used.
*/
TQFont TQFontDialog::getFont( bool *ok, const TQFont &initial,
			    TQWidget *parent, const char* name)
{
    return getFont( ok, &initial, parent, name );
}

/*!
    \overload

  Executes a modal font dialog and returns a font.

  If the user clicks OK, the selected font is returned. If the user
  clicks Cancel, the TQt default font is returned.

  The dialog is called \a name, with parent \a parent.
  If the \a ok parameter is not-null, \e *\a ok is set to TRUE if the
  user clicked OK, and FALSE if the user clicked Cancel.

  This static function is less functional than the full TQFontDialog
  object, but is convenient and easy to use.

  Example:
  \code
    bool ok;
    TQFont font = TQFontDialog::getFont( &ok, this );
    if ( ok ) {
	// font is set to the font the user selected
    } else {
	// the user canceled the dialog; font is set to the default
	// application font, TQApplication::font()
    }
  \endcode

*/
TQFont TQFontDialog::getFont( bool *ok, TQWidget *parent,const char* name)
{
    return getFont( ok, 0, parent, name );
}

extern bool tqt_use_native_dialogs;

TQFont TQFontDialog::getFont( bool *ok, const TQFont *def,
			    TQWidget *parent, const char* name)
{
#if defined(Q_WS_X11)
    if ( tqt_use_native_dialogs && TQTDEIntegration::enabled())
        return TQTDEIntegration::getFont( ok, def, parent, name );
#endif
    TQFont result;
    if ( def )
	result = *def;

    TQFontDialog *dlg = new TQFontDialog( parent, name, TRUE );

    dlg->setFont( ( def ? *def : TQFont() ) );
#ifndef TQT_NO_WIDGET_TOPEXTRA
    dlg->setCaption( tr("Select Font") );
#endif

    bool res = (dlg->exec() == TQDialog::Accepted);
    if ( res )
	result = dlg->font();
    if ( ok )
	*ok = res;
    delete dlg;
    return result;
}


/*!
    \internal
    An event filter to make the Up, Down, PageUp and PageDown keys work
    correctly in the line edits. The source of the event is the object
    \a o and the event is \a e.
*/

bool TQFontDialog::eventFilter( TQObject * o , TQEvent * e )
{
    if ( e->type() == TQEvent::KeyPress) {
	TQKeyEvent * k = (TQKeyEvent *)e;
	if ( o == d->sizeEdit &&
        (k->key() == Key_Up ||
	     k->key() == Key_Down ||
         k->key() == Key_Prior ||
         k->key() == Key_Next) ) {

	    int ci = d->sizeList->currentItem();
	    (void)TQApplication::sendEvent( d->sizeList, k );

	    if ( ci != d->sizeList->currentItem() &&
		style().styleHint(TQStyle::SH_FontDialog_SelectAssociatedText, this))
		d->sizeEdit->selectAll();
	    return TRUE;
	} else if ( ( o == d->familyList || o == d->styleList ) &&
	            ( k->key() == Key_Return || k->key() == Key_Enter) ) {
	    k->accept();
        accept();
	    return TRUE;
	}
    } else if ( e->type() == TQEvent::FocusIn &&
		style().styleHint(TQStyle::SH_FontDialog_SelectAssociatedText, this) ) {
	if ( o == d->familyList )
	    d->familyEdit->selectAll();
	else if ( o == d->styleList )
	    d->styleEdit->selectAll();
	else if ( o == d->sizeList )
	    d->sizeEdit->selectAll();
    } else if ( e->type() == TQEvent::MouseButtonPress && o == d->sizeList ) {
	    d->sizeEdit->setFocus();
    }
    return TQDialog::eventFilter( o, e );
}

#ifdef Q_WS_MAC
// #define SHOW_FONTS_IN_FAMILIES
#endif

#ifdef SHOW_FONTS_IN_FAMILIES
#include "ntqpainter.h"
#include <sizeedit.h>

class TQListBoxFontText : public TQListBoxText
{
    TQFont cfont;
public:
    TQListBoxFontText( const TQString & text );
    ~TQListBoxFontText() { }

    int	 height( const TQListBox * ) const;
    int	 width( const TQListBox * )  const;

protected:
    void  paint( TQPainter * );
};

TQListBoxFontText::TQListBoxFontText( const TQString & text )
    : TQListBoxText(text), cfont(text)
{
}

int TQListBoxFontText::height( const TQListBox * ) const
{
    TQFontMetrics fm(cfont);
    return TQMAX( fm.lineSpacing() + 2, TQApplication::globalStrut().height() );
}

int TQListBoxFontText::width( const TQListBox * )  const
{
    TQFontMetrics fm(cfont);
    return TQMAX( fm.width( text() ) + 6, TQApplication::globalStrut().width() );
}

void TQListBoxFontText::paint( TQPainter *painter )
{
    painter->save();
    painter->setFont(cfont);
    TQListBoxText::paint(painter);
    painter->restore();
}

#endif

/*!
  \internal
    Updates the contents of the "font family" list box. This
  function can be reimplemented if you have special requirements.
*/

void TQFontDialog::updateFamilies()
{
    d->familyList->blockSignals( TRUE );

    enum match_t { MATCH_NONE=0, MATCH_LAST_RESORT=1, MATCH_APP=2, MATCH_FALLBACK, MATCH_FAMILY=3 };

    TQStringList familyNames = d->fdb.families(d->script);
    {
	// merge the unicode/unknown family list with the above list.
	TQStringList l = d->fdb.families(TQFont::Unicode) +
			d->fdb.families(TQFont::UnknownScript);
	TQStringList::ConstIterator it = l.begin(), end = l.end();
	for (; it != end; ++it) {
	    if (! familyNames.contains(*it))
		familyNames << *it;
	}
    }

    familyNames.sort();

    d->familyList->clear();
#ifdef SHOW_FONTS_IN_FAMILIES
    TQStringList::Iterator it = familyNames.begin();
    int idx = 0;
    for( ; it != familyNames.end() ; ++it )
	d->familyList->insertItem(new TQListBoxFontText(*it), idx++);
#else
    d->familyList->insertStringList( familyNames );
#endif

    TQString foundryName1, familyName1, foundryName2, familyName2;
    int bestFamilyMatch = -1;
    match_t bestFamilyType = MATCH_NONE;

    TQFont f;

    // ##### do the right thing for a list of family names in the font.
    TQFontDatabase::parseFontName(d->family, foundryName1, familyName1);

    TQStringList::Iterator it = familyNames.begin();
    int i = 0;
    for( ; it != familyNames.end(); ++it, ++i ) {

	TQFontDatabase::parseFontName(*it, foundryName2, familyName2);

	//try to match..
	if ( familyName1 == familyName2 ) {
	    bestFamilyType = MATCH_FAMILY;
	    if ( foundryName1 == foundryName2 ) {
		bestFamilyMatch = i;
		break;
	    }
	    if ( bestFamilyMatch < MATCH_FAMILY )
		bestFamilyMatch = i;
	}

	//and try some fall backs
	match_t type = MATCH_NONE;
	if ( bestFamilyType <= MATCH_NONE && familyName2 == f.lastResortFamily() )
		type = MATCH_LAST_RESORT;
	if ( bestFamilyType <= MATCH_LAST_RESORT && familyName2 == f.family() )
		type = MATCH_APP;
	// ### add fallback for script
	if ( type != MATCH_NONE ) {
	    bestFamilyType = type;
	    bestFamilyMatch = i;
	}
    }

    if (i != -1 && bestFamilyType != MATCH_NONE)
	d->familyList->setCurrentItem(bestFamilyMatch);
    else
	d->familyList->setCurrentItem( 0 );
    d->familyEdit->setText( d->familyList->currentText() );
    if ( style().styleHint(TQStyle::SH_FontDialog_SelectAssociatedText, this) &&
	 d->familyList->hasFocus() )
	d->familyEdit->selectAll();

    d->familyList->blockSignals( FALSE );
    updateStyles();
}

/*!
    \internal
    Updates the contents of the "font style" list box. This
  function can be reimplemented if you have special requirements.
*/

void TQFontDialog::updateStyles()
{
    d->styleList->blockSignals( TRUE );

    d->styleList->clear();

    TQStringList styles = d->fdb.styles( d->familyList->currentText() );

    if ( styles.isEmpty() ) {
	d->styleEdit->clear();
	d->smoothScalable = FALSE;
    } else {
	d->styleList->insertStringList( styles );

	if ( !d->style.isEmpty() ) {
	    bool found = FALSE;
	    bool first = TRUE;
	    TQString cstyle = d->style;
	redo:
	    for ( int i = 0 ; i < (int)d->styleList->count() ; i++ ) {
		if ( cstyle == d->styleList->text(i) ) {
		    d->styleList->setCurrentItem( i );
		    found = TRUE;
		    break;
		}
	    }
	    if (!found && first) {
		if (cstyle.contains("Italic")) {
		    cstyle.replace("Italic", "Oblique");
		    first = FALSE;
		    goto redo;
		} else if (cstyle.contains("Oblique")) {
		    cstyle.replace("Oblique", "Italic");
		    first = FALSE;
		    goto redo;
		}
	    }
	    if ( !found )
		d->styleList->setCurrentItem( 0 );
	}

	d->styleEdit->setText( d->styleList->currentText() );
	if ( style().styleHint(TQStyle::SH_FontDialog_SelectAssociatedText, this) &&
	     d->styleList->hasFocus() )
	    d->styleEdit->selectAll();

	d->smoothScalable = d->fdb.isSmoothlyScalable( d->familyList->currentText(), d->styleList->currentText() );
    }

    d->styleList->blockSignals( FALSE );

    updateSizes();
}

/*!
    \internal
    Updates the contents of the "font size" list box. This
  function can be reimplemented if you have special requirements.
*/

void TQFontDialog::updateSizes()
{
    d->sizeList->blockSignals( TRUE );

    d->sizeList->clear();

    if ( !d->familyList->currentText().isEmpty() ) {
	TQValueList<int> sizes = d->fdb.pointSizes( d->familyList->currentText(), d->styleList->currentText() );

	int i = 0;
	bool found = FALSE;
	for( TQValueList<int>::iterator it = sizes.begin() ; it != sizes.end(); ++it ) {
	    d->sizeList->insertItem( TQString::number( *it ) );
	    if ( !found && *it >= d->size ) {
		d->sizeList->setCurrentItem( i );
		found = TRUE;
	    }
	    ++i;
	}
	if ( !found ) {
	    // we request a size bigger than the ones in the list, select the biggest one
	    d->sizeList->setCurrentItem( d->sizeList->count() - 1 );
	}

	d->sizeEdit->blockSignals( TRUE );
	d->sizeEdit->setText( ( d->smoothScalable ? TQString::number( d->size ) : d->sizeList->currentText() ) );
	if ( style().styleHint(TQStyle::SH_FontDialog_SelectAssociatedText, this) &&
	     d->sizeList->hasFocus() )
	    d->sizeEdit->selectAll();
	d->sizeEdit->blockSignals( FALSE );
    } else {
	d->sizeEdit->clear();
    }

    d->sizeList->blockSignals( FALSE );
    updateSample();
}

void TQFontDialog::updateSample()
{
    if ( d->familyList->currentText().isEmpty() )
	d->sampleEdit->clear();
    else
	d->sampleEdit->setFont( font() );
}

/*!
    \internal
*/
void TQFontDialog::scriptHighlighted( int index )
{
    d->script = (TQFont::Script)index;
    d->sampleEdit->setText( d->fdb.scriptSample( d->script ) );
    updateFamilies();
}

/*!
    \internal
*/
void TQFontDialog::familyHighlighted( int i )
{
    d->family = d->familyList->text( i );
    d->familyEdit->setText( d->family );
    if ( style().styleHint(TQStyle::SH_FontDialog_SelectAssociatedText, this) &&
	 d->familyList->hasFocus() )
	d->familyEdit->selectAll();

    updateStyles();
}


/*!
    \internal
*/

void TQFontDialog::styleHighlighted( int index )
{
    TQString s = d->styleList->text( index );
    d->styleEdit->setText( s );
    if ( style().styleHint(TQStyle::SH_FontDialog_SelectAssociatedText, this) &&
	 d->styleList->hasFocus() )
	d->styleEdit->selectAll();

    d->style = s;

    updateSizes();
}


/*!
    \internal
*/

void TQFontDialog::sizeHighlighted( const TQString &s )
{
    d->sizeEdit->setText( s );
    if ( style().styleHint(TQStyle::SH_FontDialog_SelectAssociatedText, this) &&
	 d->sizeEdit->hasFocus() )
	d->sizeEdit->selectAll();

    d->size = s.toInt();
    updateSample();
}

/*!
    \internal
    This slot is called if the user changes the font size.
    The size is passed in the \a s argument as a \e string.
*/

void TQFontDialog::sizeChanged( const TQString &s )
{
    // no need to check if the conversion is valid, since we have an TQIntValidator in the size edit
    int size = s.toInt();
    if ( d->size == size )
	return;

    d->size = size;
    if ( d->sizeList->count() != 0 ) {
	int i;
	for ( i = 0 ; i < (int)d->sizeList->count() - 1 ; i++ ) {
	    if ( d->sizeList->text(i).toInt() >= d->size )
		break;
	}
	d->sizeList->blockSignals( TRUE );
	d->sizeList->setCurrentItem( i );
	d->sizeList->blockSignals( FALSE );
    }
    updateSample();
}

/*!
  \internal
  Sets the font highlighted in the TQFontDialog to font \a f.

  \sa font()
*/

void TQFontDialog::setFont( const TQFont &f )
{
    d->family = f.family();
    d->style = d->fdb.styleString( f );
    d->size = f.pointSize();
    if ( d->size == -1 ) {
	    TQFontInfo fi( f );
	    d->size = fi.pointSize();
    }
    d->strikeout->setChecked( f.strikeOut() );
    d->underline->setChecked( f.underline() );

    updateFamilies();
}

/*!
  \internal
  Returns the font which the user has chosen.

  \sa setFont()
*/

TQFont TQFontDialog::font() const
{
    int pSize = d->sizeEdit->text().toInt();

    TQFont f = d->fdb.font( d->familyList->currentText(), d->style, pSize );
    f.setStrikeOut( d->strikeout->isChecked() );
    f.setUnderline( d->underline->isChecked() );
    return f;
}

#endif