• Skip to content
  • Skip to link menu
KDE 4.1 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 
00117     QToolBar *parent = qobject_cast<QToolBar *>(_parent);
00118     if (!parent)
00119         return KSelectAction::createWidget(_parent);
00120 
00121 #ifdef __GNUC__
00122 #warning FIXME: items need to be converted
00123 #endif
00124     // This is the visual element on the screen.  This method overrides
00125     // the KSelectAction one, preventing KSelectAction from creating its
00126     // regular KComboBox.
00127     KFontComboBox *cb = new KFontComboBox( parent );
00128 
00129     kDebug(129) << "\tset=" << font();
00130     // Do this before connecting the signal so that nothing will fire.
00131     cb->setCurrentFont( QFont( font().toLower() ) );
00132     kDebug(129) << "\tspit back=" << cb->currentFont().family();
00133 
00134     connect( cb, SIGNAL( currentFontChanged( const QFont & ) ), SLOT(_k_slotFontChanged( const QFont&  ) ) );
00135     cb->setMinimumWidth( cb->sizeHint().width() );
00136     return cb;
00137 }
00138 
00139 /*
00140  * Maintenance note: Keep in sync with KFontComboBox::setCurrentFont()
00141  */
00142 void KFontAction::setFont( const QString &family )
00143 {
00144     kDebug(129) << "KFontAction::setFont(" << family << ")";
00145 
00146     // Suppress triggered(QString) signal and prevent recursive call to ourself.
00147     d->settingFont++;
00148 
00149     foreach(QWidget *w, createdWidgets())
00150     {
00151         KFontComboBox *cb = qobject_cast<KFontComboBox *>(w);
00152         kDebug(129) << "\tw=" << w << "cb=" << cb;
00153 
00154         if(!cb) continue;
00155 
00156         cb->setCurrentFont(QFont(family.toLower()));
00157         kDebug(129) << "\t\tw spit back=" << cb->currentFont().family();
00158     }
00159 
00160     d->settingFont--;
00161 
00162     kDebug(129) << "\tcalling setCurrentAction()";
00163 
00164     QString lowerName = family.toLower();
00165     if (setCurrentAction(lowerName, Qt::CaseInsensitive))
00166        return;
00167 
00168     int i = lowerName.indexOf(" [");
00169     if (i > -1)
00170     {
00171        lowerName = lowerName.left(i);
00172        i = 0;
00173        if (setCurrentAction(lowerName, Qt::CaseInsensitive))
00174           return;
00175     }
00176 
00177     lowerName += " [";
00178     if (setCurrentAction(lowerName, Qt::CaseInsensitive))
00179       return;
00180 
00181     // TODO: Inconsistent state if KFontComboBox::setCurrentFont() succeeded
00182     //       but setCurrentAction() did not and vice-versa.
00183     kDebug(129) << "Font not found " << family.toLower();
00184 }
00185 
00186 /* vim: et sw=2 ts=2
00187  */
00188 
00189 #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
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
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