File indexing completed on 2024-04-14 14:20:20
0001 /* 0002 0003 Requires the Qt widget libraries, available at no cost at 0004 http://www.troll.no 0005 0006 Copyright (C) 1996 Bernd Johannes Wuebben <wuebben@kde.org> 0007 Copyright (c) 1999 Preston Brown <pbrown@kde.org> 0008 Copyright (c) 1999 Mario Weilguni <mweilguni@kde.org> 0009 0010 This library is free software; you can redistribute it and/or 0011 modify it under the terms of the GNU Library General Public 0012 License as published by the Free Software Foundation; either 0013 version 2 of the License, or (at your option) any later version. 0014 0015 This library is distributed in the hope that it will be useful, 0016 but WITHOUT ANY WARRANTY; without even the implied warranty of 0017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0018 Library General Public License for more details. 0019 0020 You should have received a copy of the GNU Library General Public License 0021 along with this library; see the file COPYING.LIB. If not, write to 0022 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0023 Boston, MA 02110-1301, USA. 0024 */ 0025 0026 #include "kfontdialog.h" 0027 0028 #include <QDialogButtonBox> 0029 #include <QVBoxLayout> 0030 0031 #include <klocalizedstring.h> 0032 0033 class Q_DECL_HIDDEN KFontDialog::Private 0034 { 0035 public: 0036 Private() 0037 : chooser(nullptr) 0038 { 0039 } 0040 0041 KFontChooser *chooser; 0042 }; 0043 0044 KFontDialog::KFontDialog(QWidget *parent, 0045 const KFontChooser::DisplayFlags &flags, 0046 const QStringList &fontList, 0047 Qt::CheckState *sizeIsRelativeState) 0048 : KDialog(parent), 0049 d(new Private) 0050 { 0051 setWindowTitle(i18n("Select Font")); 0052 d->chooser = new KFontChooser(this, flags, fontList, 8, 0053 sizeIsRelativeState); 0054 d->chooser->setObjectName("fontChooser"); 0055 0056 connect(d->chooser, SIGNAL(fontSelected(QFont)), this, SIGNAL(fontSelected(QFont))); 0057 0058 setButtons(KDialog::Ok | KDialog::Cancel); 0059 setMainWidget(d->chooser); 0060 } 0061 0062 KFontDialog::~KFontDialog() 0063 { 0064 delete d; 0065 } 0066 0067 void KFontDialog::setFont(const QFont &font, bool onlyFixed) 0068 { 0069 d->chooser->setFont(font, onlyFixed); 0070 } 0071 0072 QFont KFontDialog::font() const 0073 { 0074 return d->chooser->font(); 0075 } 0076 0077 void KFontDialog::setSizeIsRelative(Qt::CheckState relative) 0078 { 0079 d->chooser->setSizeIsRelative(relative); 0080 } 0081 0082 Qt::CheckState KFontDialog::sizeIsRelative() const 0083 { 0084 return d->chooser->sizeIsRelative(); 0085 } 0086 0087 int KFontDialog::getFontDiff(QFont &theFont, 0088 KFontChooser::FontDiffFlags &diffFlags, 0089 const KFontChooser::DisplayFlags &flags, 0090 QWidget *parent, 0091 Qt::CheckState *sizeIsRelativeState) 0092 { 0093 KFontDialog dlg(parent, flags | KFontChooser::ShowDifferences, 0094 QStringList(), sizeIsRelativeState); 0095 dlg.setModal(true); 0096 dlg.setObjectName("Font Selector"); 0097 dlg.setFont(theFont, flags & KFontChooser::FixedFontsOnly); 0098 0099 int result = dlg.exec(); 0100 if (result == Accepted) { 0101 theFont = dlg.d->chooser->font(); 0102 diffFlags = dlg.d->chooser->fontDiffFlags(); 0103 if (sizeIsRelativeState) { 0104 *sizeIsRelativeState = dlg.d->chooser->sizeIsRelative(); 0105 } 0106 } 0107 return result; 0108 } 0109 0110 int KFontDialog::getFont(QFont &theFont, 0111 const KFontChooser::DisplayFlags &flags, 0112 QWidget *parent, 0113 Qt::CheckState *sizeIsRelativeState) 0114 { 0115 KFontDialog dlg(parent, flags, QStringList(), sizeIsRelativeState); 0116 dlg.setModal(true); 0117 dlg.setObjectName("Font Selector"); 0118 dlg.setFont(theFont, flags & KFontChooser::FixedFontsOnly); 0119 0120 int result = dlg.exec(); 0121 if (result == Accepted) { 0122 theFont = dlg.d->chooser->font(); 0123 if (sizeIsRelativeState) { 0124 *sizeIsRelativeState = dlg.d->chooser->sizeIsRelative(); 0125 } 0126 } 0127 return result; 0128 } 0129 0130 int KFontDialog::getFontAndText(QFont &theFont, QString &theString, 0131 const KFontChooser::DisplayFlags &flags, 0132 QWidget *parent, 0133 Qt::CheckState *sizeIsRelativeState) 0134 { 0135 KFontDialog dlg(parent, flags, 0136 QStringList(), sizeIsRelativeState); 0137 dlg.setModal(true); 0138 dlg.setObjectName("Font and Text Selector"); 0139 dlg.setFont(theFont, flags & KFontChooser::FixedFontsOnly); 0140 0141 int result = dlg.exec(); 0142 if (result == Accepted) { 0143 theFont = dlg.d->chooser->font(); 0144 theString = dlg.d->chooser->sampleText(); 0145 if (sizeIsRelativeState) { 0146 *sizeIsRelativeState = dlg.d->chooser->sizeIsRelative(); 0147 } 0148 } 0149 return result; 0150 } 0151 0152 #include "moc_kfontdialog.cpp"