KDEUI
kfontdialog.cpp
Go to the documentation of this file.
00001 /* 00002 00003 Requires the Qt widget libraries, available at no cost at 00004 http://www.troll.no 00005 00006 Copyright (C) 1996 Bernd Johannes Wuebben <wuebben@kde.org> 00007 Copyright (c) 1999 Preston Brown <pbrown@kde.org> 00008 Copyright (c) 1999 Mario Weilguni <mweilguni@kde.org> 00009 00010 This library is free software; you can redistribute it and/or 00011 modify it under the terms of the GNU Library General Public 00012 License as published by the Free Software Foundation; either 00013 version 2 of the License, or (at your option) any later version. 00014 00015 This library is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 Library General Public License for more details. 00019 00020 You should have received a copy of the GNU Library General Public License 00021 along with this library; see the file COPYING.LIB. If not, write to 00022 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00023 Boston, MA 02110-1301, USA. 00024 */ 00025 00026 #include "kfontdialog.h" 00027 00028 #include <config.h> 00029 00030 #include <stdio.h> 00031 #include <stdlib.h> 00032 00033 00034 #include <QtGui/QComboBox> 00035 #include <QtGui/QCheckBox> 00036 #include <QtCore/QFile> 00037 #include <QtGui/QFont> 00038 #include <QtGui/QLabel> 00039 #include <QtGui/QLayout> 00040 #include <QtGui/QScrollBar> 00041 #include <QtCore/QMutableStringListIterator> 00042 #include <QtGui/QFontDatabase> 00043 #include <QList> 00044 #include <QtGui/QGroupBox> 00045 #include <kcharsets.h> 00046 #include <kconfig.h> 00047 #include <kdialog.h> 00048 #include <kglobal.h> 00049 #include <kglobalsettings.h> 00050 #include <klistwidget.h> 00051 #include <klocale.h> 00052 #include <kstandarddirs.h> 00053 #include <kdebug.h> 00054 #include <knuminput.h> 00055 #include <kconfiggroup.h> 00056 00057 class KFontDialog::Private 00058 { 00059 public: 00060 Private() 00061 : chooser( 0 ) 00062 { 00063 } 00064 00065 KFontChooser *chooser; 00066 }; 00067 00068 KFontDialog::KFontDialog( QWidget *parent, 00069 const KFontChooser::DisplayFlags& flags, 00070 const QStringList &fontList, 00071 Qt::CheckState *sizeIsRelativeState ) 00072 : KDialog( parent ), 00073 d( new Private ) 00074 { 00075 setCaption( i18n("Select Font") ); 00076 setButtons( Ok | Cancel ); 00077 setDefaultButton(Ok); 00078 d->chooser = new KFontChooser( this, flags, fontList, 8, 00079 sizeIsRelativeState ); 00080 d->chooser->setObjectName( "fontChooser" ); 00081 00082 connect( d->chooser , SIGNAL(fontSelected(const QFont&)) , this , SIGNAL(fontSelected(const QFont&)) ); 00083 00084 setMainWidget( d->chooser ); 00085 } 00086 00087 KFontDialog::~KFontDialog() 00088 { 00089 delete d; 00090 } 00091 00092 void KFontDialog::setFont( const QFont &font, bool onlyFixed) 00093 { 00094 d->chooser->setFont(font, onlyFixed); 00095 } 00096 00097 QFont KFontDialog::font() const 00098 { 00099 return d->chooser->font(); 00100 } 00101 00102 void KFontDialog::setSizeIsRelative( Qt::CheckState relative ) 00103 { 00104 d->chooser->setSizeIsRelative( relative ); 00105 } 00106 00107 Qt::CheckState KFontDialog::sizeIsRelative() const 00108 { 00109 return d->chooser->sizeIsRelative(); 00110 } 00111 00112 00113 int KFontDialog::getFontDiff( QFont &theFont, 00114 KFontChooser::FontDiffFlags& diffFlags, 00115 const KFontChooser::DisplayFlags& flags, 00116 QWidget *parent, 00117 Qt::CheckState *sizeIsRelativeState ) 00118 { 00119 KFontDialog dlg( parent, flags | KFontChooser::ShowDifferences, 00120 QStringList(), sizeIsRelativeState ); 00121 dlg.setModal( true ); 00122 dlg.setObjectName( "Font Selector" ); 00123 dlg.setFont( theFont, flags & KFontChooser::FixedFontsOnly ); 00124 00125 int result = dlg.exec(); 00126 if( result == Accepted ) 00127 { 00128 theFont = dlg.d->chooser->font(); 00129 diffFlags = dlg.d->chooser->fontDiffFlags(); 00130 if( sizeIsRelativeState ) 00131 *sizeIsRelativeState = dlg.d->chooser->sizeIsRelative(); 00132 } 00133 return result; 00134 } 00135 00136 int KFontDialog::getFont( QFont &theFont, 00137 const KFontChooser::DisplayFlags& flags, 00138 QWidget *parent, 00139 Qt::CheckState *sizeIsRelativeState ) 00140 { 00141 KFontDialog dlg( parent, flags, QStringList(), sizeIsRelativeState ); 00142 dlg.setModal( true ); 00143 dlg.setObjectName( "Font Selector" ); 00144 dlg.setFont( theFont, flags & KFontChooser::FixedFontsOnly ); 00145 00146 int result = dlg.exec(); 00147 if( result == Accepted ) 00148 { 00149 theFont = dlg.d->chooser->font(); 00150 if( sizeIsRelativeState ) 00151 *sizeIsRelativeState = dlg.d->chooser->sizeIsRelative(); 00152 } 00153 return result; 00154 } 00155 00156 00157 int KFontDialog::getFontAndText( QFont &theFont, QString &theString, 00158 const KFontChooser::DisplayFlags& flags, 00159 QWidget *parent, 00160 Qt::CheckState *sizeIsRelativeState ) 00161 { 00162 KFontDialog dlg( parent, flags, 00163 QStringList(), sizeIsRelativeState ); 00164 dlg.setModal( true ); 00165 dlg.setObjectName( "Font and Text Selector" ); 00166 dlg.setFont( theFont, flags & KFontChooser::FixedFontsOnly ); 00167 00168 int result = dlg.exec(); 00169 if( result == Accepted ) 00170 { 00171 theFont = dlg.d->chooser->font(); 00172 theString = dlg.d->chooser->sampleText(); 00173 if( sizeIsRelativeState ) 00174 *sizeIsRelativeState = dlg.d->chooser->sizeIsRelative(); 00175 } 00176 return result; 00177 } 00178 00179 00180 #include "kfontdialog.moc"
KDE 4.6 API Reference