• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • 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 
00124     kDebug(129) << "\tset=" << font();
00125     // Do this before connecting the signal so that nothing will fire.
00126     cb->setCurrentFont( QFont( font().toLower() ) );
00127     kDebug(129) << "\tspit back=" << cb->currentFont().family();
00128 
00129     connect( cb, SIGNAL( currentFontChanged( const QFont & ) ), SLOT(_k_slotFontChanged( const QFont&  ) ) );
00130     cb->setMinimumWidth( cb->sizeHint().width() );
00131     return cb;
00132 }
00133 
00134 /*
00135  * Maintenance note: Keep in sync with KFontComboBox::setCurrentFont()
00136  */
00137 void KFontAction::setFont( const QString &family )
00138 {
00139     kDebug(129) << "KFontAction::setFont(" << family << ")";
00140 
00141     // Suppress triggered(QString) signal and prevent recursive call to ourself.
00142     d->settingFont++;
00143 
00144     foreach(QWidget *w, createdWidgets())
00145     {
00146         KFontComboBox *cb = qobject_cast<KFontComboBox *>(w);
00147         kDebug(129) << "\tw=" << w << "cb=" << cb;
00148 
00149         if(!cb) continue;
00150 
00151         cb->setCurrentFont(QFont(family.toLower()));
00152         kDebug(129) << "\t\tw spit back=" << cb->currentFont().family();
00153     }
00154 
00155     d->settingFont--;
00156 
00157     kDebug(129) << "\tcalling setCurrentAction()";
00158 
00159     QString lowerName = family.toLower();
00160     if (setCurrentAction(lowerName, Qt::CaseInsensitive))
00161        return;
00162 
00163     int i = lowerName.indexOf(" [");
00164     if (i > -1)
00165     {
00166        lowerName = lowerName.left(i);
00167        i = 0;
00168        if (setCurrentAction(lowerName, Qt::CaseInsensitive))
00169           return;
00170     }
00171 
00172     lowerName += " [";
00173     if (setCurrentAction(lowerName, Qt::CaseInsensitive))
00174       return;
00175 
00176     // TODO: Inconsistent state if KFontComboBox::setCurrentFont() succeeded
00177     //       but setCurrentAction() did not and vice-versa.
00178     kDebug(129) << "Font not found " << family.toLower();
00179 }
00180 
00181 #include "kfontaction.moc"

KDEUI

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal