• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.9.5 API Reference
  • KDE Home
  • Contact Us
 

KDEUI

kfontaction.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002     Copyright (C) 1999 Reginald Stadlbauer <reggie@kde.org>
00003               (C) 1999 Simon Hausmann <hausmann@kde.org>
00004               (C) 2000 Nicolas Hadacek <haadcek@kde.org>
00005               (C) 2000 Kurt Granroth <granroth@kde.org>
00006               (C) 2000 Michael Koch <koch@kde.org>
00007               (C) 2001 Holger Freyther <freyther@kde.org>
00008               (C) 2002 Ellis Whitehead <ellis@kde.org>
00009               (C) 2002 Joseph Wenninger <jowenn@kde.org>
00010               (C) 2003 Andras Mantia <amantia@kde.org>
00011               (C) 2005-2006 Hamish Rodda <rodda@kde.org>
00012               (C) 2007 Clarence Dang <dang@kde.org>
00013 
00014     This library is free software; you can redistribute it and/or
00015     modify it under the terms of the GNU Library General Public
00016     License version 2 as published by the Free Software Foundation.
00017 
00018     This library is distributed in the hope that it will be useful,
00019     but WITHOUT ANY WARRANTY; without even the implied warranty of
00020     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021     Library General Public License for more details.
00022 
00023     You should have received a copy of the GNU Library General Public License
00024     along with this library; see the file COPYING.LIB.  If not, write to
00025     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00026     Boston, MA 02110-1301, USA.
00027 */
00028 
00029 #include "kfontaction.h"
00030 
00031 #include <QtGui/QToolBar>
00032 
00033 #include <kdebug.h>
00034 #include <kfontdialog.h>
00035 #include <kicon.h>
00036 #include <klocale.h>
00037 #include <kfontchooser.h>
00038 #include <kfontcombobox.h>
00039 
00040 class KFontAction::KFontActionPrivate
00041 {
00042     public:
00043         KFontActionPrivate(KFontAction *parent)
00044             : q(parent),
00045               settingFont(0)
00046         {
00047         }
00048 
00049         void _k_slotFontChanged(const QFont &font)
00050         {
00051             kDebug(129) << "KFontComboBox - slotFontChanged("
00052                         << font.family() << ") settingFont=" << settingFont;
00053             if (settingFont)
00054                 return;
00055 
00056             q->setFont(font.family());
00057             q->triggered(font.family());
00058 
00059             kDebug(129) << "\tslotFontChanged done";
00060         }
00061 
00062 
00063         KFontAction *q;
00064         int settingFont;
00065 };
00066 
00067 KFontAction::KFontAction(uint fontListCriteria, QObject *parent)
00068   : KSelectAction(parent), d(new KFontActionPrivate(this))
00069 {
00070     QStringList list;
00071     KFontChooser::getFontList( list, fontListCriteria );
00072     KSelectAction::setItems( list );
00073     setEditable( true );
00074 }
00075 
00076 KFontAction::KFontAction(QObject *parent)
00077   : KSelectAction(parent), d(new KFontActionPrivate(this))
00078 {
00079     QStringList list;
00080     KFontChooser::getFontList( list, 0 );
00081     KSelectAction::setItems( list );
00082     setEditable( true );
00083 }
00084 
00085 KFontAction::KFontAction(const QString & text, QObject *parent)
00086   : KSelectAction(text, parent), d(new KFontActionPrivate(this))
00087 {
00088     QStringList list;
00089     KFontChooser::getFontList( list, 0 );
00090     KSelectAction::setItems( list );
00091     setEditable( true );
00092 }
00093 
00094 KFontAction::KFontAction(const KIcon &icon, const QString &text, QObject *parent)
00095   : KSelectAction(icon, text, parent), d(new KFontActionPrivate(this))
00096 {
00097     QStringList list;
00098     KFontChooser::getFontList( list, 0 );
00099     KSelectAction::setItems( list );
00100     setEditable( true );
00101 }
00102 
00103 KFontAction::~KFontAction()
00104 {
00105     delete d;
00106 }
00107 
00108 QString KFontAction::font() const
00109 {
00110     return currentText();
00111 }
00112 
00113 QWidget* KFontAction::createWidget(QWidget* parent)
00114 {
00115     kDebug(129) << "KFontAction::createWidget()";
00116 #ifdef __GNUC__
00117 #warning FIXME: items need to be converted
00118 #endif
00119     // This is the visual element on the screen.  This method overrides
00120     // the KSelectAction one, preventing KSelectAction from creating its
00121     // regular KComboBox.
00122     KFontComboBox *cb = new KFontComboBox( parent );
00123     cb->setFontList(items());
00124 
00125     kDebug(129) << "\tset=" << font();
00126     // Do this before connecting the signal so that nothing will fire.
00127     cb->setCurrentFont( QFont( font().toLower() ) );
00128     kDebug(129) << "\tspit back=" << cb->currentFont().family();
00129 
00130     connect( cb, SIGNAL(currentFontChanged(QFont)), SLOT(_k_slotFontChanged(QFont)) );
00131     cb->setMinimumWidth( cb->sizeHint().width() );
00132     return cb;
00133 }
00134 
00135 /*
00136  * Maintenance note: Keep in sync with KFontComboBox::setCurrentFont()
00137  */
00138 void KFontAction::setFont( const QString &family )
00139 {
00140     kDebug(129) << "KFontAction::setFont(" << family << ")";
00141 
00142     // Suppress triggered(QString) signal and prevent recursive call to ourself.
00143     d->settingFont++;
00144 
00145     foreach(QWidget *w, createdWidgets())
00146     {
00147         KFontComboBox *cb = qobject_cast<KFontComboBox *>(w);
00148         kDebug(129) << "\tw=" << w << "cb=" << cb;
00149 
00150         if(!cb) continue;
00151 
00152         cb->setCurrentFont(QFont(family.toLower()));
00153         kDebug(129) << "\t\tw spit back=" << cb->currentFont().family();
00154     }
00155 
00156     d->settingFont--;
00157 
00158     kDebug(129) << "\tcalling setCurrentAction()";
00159 
00160     QString lowerName = family.toLower();
00161     if (setCurrentAction(lowerName, Qt::CaseInsensitive))
00162        return;
00163 
00164     int i = lowerName.indexOf(" [");
00165     if (i > -1)
00166     {
00167        lowerName = lowerName.left(i);
00168        i = 0;
00169        if (setCurrentAction(lowerName, Qt::CaseInsensitive))
00170           return;
00171     }
00172 
00173     lowerName += " [";
00174     if (setCurrentAction(lowerName, Qt::CaseInsensitive))
00175       return;
00176 
00177     // TODO: Inconsistent state if KFontComboBox::setCurrentFont() succeeded
00178     //       but setCurrentAction() did not and vice-versa.
00179     kDebug(129) << "Font not found " << family.toLower();
00180 }
00181 
00182 #include "kfontaction.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Mon Jan 21 2019 12:32:39 by doxygen 1.7.5.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.9.5 API Reference

Skip menu "kdelibs-4.9.5 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal