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

KDEUI

  • sources
  • kde-4.14
  • kdelibs
  • kdeui
  • actions
kfontsizeaction.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 1999 Reginald Stadlbauer <reggie@kde.org>
3  (C) 1999 Simon Hausmann <hausmann@kde.org>
4  (C) 2000 Nicolas Hadacek <haadcek@kde.org>
5  (C) 2000 Kurt Granroth <granroth@kde.org>
6  (C) 2000 Michael Koch <koch@kde.org>
7  (C) 2001 Holger Freyther <freyther@kde.org>
8  (C) 2002 Ellis Whitehead <ellis@kde.org>
9  (C) 2002 Joseph Wenninger <jowenn@kde.org>
10  (C) 2003 Andras Mantia <amantia@kde.org>
11  (C) 2005-2006 Hamish Rodda <rodda@kde.org>
12 
13  This library is free software; you can redistribute it and/or
14  modify it under the terms of the GNU Library General Public
15  License version 2 as published by the Free Software Foundation.
16 
17  This library is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  Library General Public License for more details.
21 
22  You should have received a copy of the GNU Library General Public License
23  along with this library; see the file COPYING.LIB. If not, write to
24  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25  Boston, MA 02110-1301, USA.
26 */
27 
28 #include "kfontsizeaction.h"
29 
30 #include <QtGui/QFontDatabase>
31 #include <QtGui/QToolBar>
32 #include <QtGui/QToolButton>
33 
34 #include <kdebug.h>
35 #include <kicon.h>
36 #include <klocale.h>
37 
38 #include "kmenu.h"
39 
40 class KFontSizeAction::Private
41 {
42  public:
43  Private(KFontSizeAction *parent)
44  : q(parent)
45  {
46  }
47 
48  void init();
49 
50  KFontSizeAction *q;
51 };
52 
53 // BEGIN KFontSizeAction
54 KFontSizeAction::KFontSizeAction(QObject *parent)
55  : KSelectAction(parent),
56  d(new Private(this))
57 {
58  d->init();
59 }
60 
61 KFontSizeAction::KFontSizeAction(const QString &text, QObject *parent)
62  : KSelectAction(text, parent),
63  d(new Private(this))
64 {
65  d->init();
66 }
67 
68 KFontSizeAction::KFontSizeAction(const KIcon &icon, const QString &text, QObject *parent)
69  : KSelectAction(icon, text, parent),
70  d(new Private(this))
71 {
72  d->init();
73 }
74 
75 KFontSizeAction::~KFontSizeAction()
76 {
77  delete d;
78 }
79 
80 void KFontSizeAction::Private::init()
81 {
82  q->setEditable( true );
83  QFontDatabase fontDB;
84  const QList<int> sizes = fontDB.standardSizes();
85  QStringList lst;
86  for ( QList<int>::ConstIterator it = sizes.begin(); it != sizes.end(); ++it )
87  lst.append( QString::number( *it ) );
88 
89  q->setItems( lst );
90 }
91 
92 void KFontSizeAction::setFontSize( int size )
93 {
94  if ( size == fontSize() ) {
95  const QString test = QString::number( size );
96  Q_FOREACH(QAction* action, actions())
97  {
98  if (action->text() == test)
99  {
100  setCurrentAction(action);
101  return;
102  }
103  }
104  }
105 
106  if ( size < 1 ) {
107  kWarning() << "KFontSizeAction: Size " << size << " is out of range";
108  return;
109  }
110 
111  QAction* a = action( QString::number( size ) );
112  if ( !a ) {
113  // Insert at the correct position in the list (to keep sorting)
114  QList<int> lst;
115  // Convert to list of ints
116  QStringListIterator itemsIt( items() );
117  while ( itemsIt.hasNext() )
118  lst.append( itemsIt.next().toInt() );
119  // New size
120  lst.append( size );
121  // Sort the list
122  qSort( lst );
123  Q_FOREACH( int it, lst ) {
124  KAction* const action = addAction( QString::number(it) );
125  if (it == size)
126  setCurrentAction(action);
127  }
128 
129  } else {
130  setCurrentAction( a );
131  }
132 }
133 
134 int KFontSizeAction::fontSize() const
135 {
136  return currentText().toInt();
137 }
138 
139 void KFontSizeAction::actionTriggered( QAction* action )
140 {
141  emit fontSizeChanged( action->text().toInt() );
142  KSelectAction::actionTriggered( action );
143 }
144 
145 /* vim: et sw=2 ts=2
146  */
147 
148 #include "kfontsizeaction.moc"
QAction::text
text
QFontDatabase::standardSizes
QList< int > standardSizes()
kdebug.h
KFontSizeAction::fontSize
int fontSize() const
KFontSizeAction
An action to allow changing of the font size.
Definition: kfontsizeaction.h:36
KSelectAction::addAction
virtual void addAction(QAction *action)
Add action to the list of selectable actions.
Definition: kselectaction.cpp:230
klocale.h
KSelectAction
Action for selecting one of several items.
Definition: kselectaction.h:51
QString::number
QString number(int n, int base)
QList::append
void append(const T &value)
KFontSizeAction::KFontSizeAction
KFontSizeAction(QObject *parent)
Definition: kfontsizeaction.cpp:54
KStandardGuiItem::test
KGuiItem test()
Returns the 'Test' gui item.
Definition: kstandardguiitem.cpp:294
kmenu.h
QObject
KSelectAction::items
QStringList items() const
Convenience function which returns the items that can be selected with this action.
QString::toInt
int toInt(bool *ok, int base) const
KIcon
A wrapper around QIcon that provides KDE icon features.
Definition: kicon.h:40
QString
KSelectAction::currentText
QString currentText() const
Returns the text of the currently selected item.
QList< int >
KSelectAction::actions
QList< QAction * > actions() const
Returns the list of selectable actions.
Definition: kselectaction.cpp:110
KFontSizeAction::fontSizeChanged
void fontSizeChanged(int)
QStringList
QList::end
iterator end()
KSelectAction::action
QAction * action(int index) const
Returns the action at index, if one exists.
Definition: kselectaction.cpp:162
QAction
KAction
Class to encapsulate user-driven action or event.
Definition: kaction.h:216
kWarning
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KSelectAction::actionTriggered
virtual void actionTriggered(QAction *action)
This function is called whenever an action from the selections is triggered.
Definition: kselectaction.cpp:309
kicon.h
QObject::parent
QObject * parent() const
KFontSizeAction::actionTriggered
virtual void actionTriggered(QAction *action)
This function is called whenever an action from the selections is triggered.
Definition: kfontsizeaction.cpp:139
KSelectAction::setCurrentAction
bool setCurrentAction(QAction *action)
Sets the currently checked item.
Definition: kselectaction.cpp:133
kfontsizeaction.h
QFontDatabase
QList::begin
iterator begin()
KFontSizeAction::setFontSize
void setFontSize(int size)
Definition: kfontsizeaction.cpp:92
KFontSizeAction::~KFontSizeAction
virtual ~KFontSizeAction()
Definition: kfontsizeaction.cpp:75
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:23:59 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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

Search



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