• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDEUI

kfontsizeaction.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 
00013     This library is free software; you can redistribute it and/or
00014     modify it under the terms of the GNU Library General Public
00015     License version 2 as published by the Free Software Foundation.
00016 
00017     This library is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020     Library General Public License for more details.
00021 
00022     You should have received a copy of the GNU Library General Public License
00023     along with this library; see the file COPYING.LIB.  If not, write to
00024     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00025     Boston, MA 02110-1301, USA.
00026 */
00027 
00028 #include "kfontsizeaction.h"
00029 
00030 #include <QtGui/QFontDatabase>
00031 #include <QtGui/QToolBar>
00032 #include <QtGui/QToolButton>
00033 
00034 #include <kdebug.h>
00035 #include <kicon.h>
00036 #include <klocale.h>
00037 
00038 #include "kmenu.h"
00039 
00040 class KFontSizeAction::Private
00041 {
00042     public:
00043         Private(KFontSizeAction *parent)
00044             : q(parent)
00045         {
00046         }
00047 
00048         void init();
00049 
00050         KFontSizeAction *q;
00051 };
00052 
00053 // BEGIN KFontSizeAction
00054 KFontSizeAction::KFontSizeAction(QObject *parent)
00055   : KSelectAction(parent),
00056     d(new Private(this))
00057 {
00058   d->init();
00059 }
00060 
00061 KFontSizeAction::KFontSizeAction(const QString &text, QObject *parent)
00062   : KSelectAction(text, parent),
00063     d(new Private(this))
00064 {
00065   d->init();
00066 }
00067 
00068 KFontSizeAction::KFontSizeAction(const KIcon &icon, const QString &text, QObject *parent)
00069   : KSelectAction(icon, text, parent),
00070     d(new Private(this))
00071 {
00072   d->init();
00073 }
00074 
00075 KFontSizeAction::~KFontSizeAction()
00076 {
00077   delete d;
00078 }
00079 
00080 void KFontSizeAction::Private::init()
00081 {
00082     q->setEditable( true );
00083     QFontDatabase fontDB;
00084     const QList<int> sizes = fontDB.standardSizes();
00085     QStringList lst;
00086     for ( QList<int>::ConstIterator it = sizes.begin(); it != sizes.end(); ++it )
00087         lst.append( QString::number( *it ) );
00088 
00089     q->setItems( lst );
00090 }
00091 
00092 void KFontSizeAction::setFontSize( int size )
00093 {
00094     if ( size == fontSize() ) {
00095         const QString test = QString::number( size );
00096         Q_FOREACH(QAction* action, actions())
00097         {
00098           if (action->text() == test)
00099           {
00100               setCurrentAction(action);
00101               return;
00102           }
00103         }
00104     }
00105 
00106     if ( size < 1 ) {
00107         kWarning() << "KFontSizeAction: Size " << size << " is out of range";
00108         return;
00109     }
00110 
00111     QAction* a = action( QString::number( size ) );
00112     if ( !a ) {
00113         // Insert at the correct position in the list (to keep sorting)
00114         QList<int> lst;
00115         // Convert to list of ints
00116         QStringListIterator itemsIt( items() );
00117         while ( itemsIt.hasNext() )
00118             lst.append( itemsIt.next().toInt() );
00119         // New size
00120         lst.append( size );
00121         // Sort the list
00122         qSort( lst );
00123         Q_FOREACH( int it, lst ) {
00124             KAction* const action = addAction( QString::number(it) );
00125             if (it == size)
00126               setCurrentAction(action);
00127         }
00128 
00129     } else {
00130         setCurrentAction( a );
00131     }
00132 }
00133 
00134 int KFontSizeAction::fontSize() const
00135 {
00136   return currentText().toInt();
00137 }
00138 
00139 void KFontSizeAction::actionTriggered( QAction* action )
00140 {
00141     emit fontSizeChanged( action->text().toInt() );
00142     KSelectAction::actionTriggered( action );
00143 }
00144 
00145 /* vim: et sw=2 ts=2
00146  */
00147 
00148 #include "kfontsizeaction.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
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
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