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

KDEUI

  • 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
40class 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
54KFontSizeAction::KFontSizeAction(QObject *parent)
55 : KSelectAction(parent),
56 d(new Private(this))
57{
58 d->init();
59}
60
61KFontSizeAction::KFontSizeAction(const QString &text, QObject *parent)
62 : KSelectAction(text, parent),
63 d(new Private(this))
64{
65 d->init();
66}
67
68KFontSizeAction::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
75KFontSizeAction::~KFontSizeAction()
76{
77 delete d;
78}
79
80void 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
92void 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
134int KFontSizeAction::fontSize() const
135{
136 return currentText().toInt();
137}
138
139void 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"
KAction
Class to encapsulate user-driven action or event.
Definition: kaction.h:217
KFontSizeAction
An action to allow changing of the font size.
Definition: kfontsizeaction.h:37
KFontSizeAction::setFontSize
void setFontSize(int size)
Definition: kfontsizeaction.cpp:92
KFontSizeAction::fontSize
int fontSize
Definition: kfontsizeaction.h:39
KFontSizeAction::KFontSizeAction
KFontSizeAction(QObject *parent)
Definition: kfontsizeaction.cpp:54
KFontSizeAction::actionTriggered
virtual void actionTriggered(QAction *action)
This function is called whenever an action from the selections is triggered.
Definition: kfontsizeaction.cpp:139
KFontSizeAction::~KFontSizeAction
virtual ~KFontSizeAction()
Definition: kfontsizeaction.cpp:75
KFontSizeAction::fontSizeChanged
void fontSizeChanged(int)
KIcon
A wrapper around QIcon that provides KDE icon features.
Definition: kicon.h:41
KSelectAction
Action for selecting one of several items.
Definition: kselectaction.h:52
KSelectAction::addAction
virtual void addAction(QAction *action)
Add action to the list of selectable actions.
Definition: kselectaction.cpp:230
KSelectAction::setCurrentAction
bool setCurrentAction(QAction *action)
Sets the currently checked item.
Definition: kselectaction.cpp:133
KSelectAction::items
QStringList items
Definition: kselectaction.h:62
KSelectAction::currentText
QString currentText
Definition: kselectaction.h:57
KSelectAction::actions
QList< QAction * > actions() const
Returns the list of selectable actions.
Definition: kselectaction.cpp:110
KSelectAction::actionTriggered
virtual void actionTriggered(QAction *action)
This function is called whenever an action from the selections is triggered.
Definition: kselectaction.cpp:309
KSelectAction::action
QAction * action(int index) const
Returns the action at index, if one exists.
Definition: kselectaction.cpp:162
QAction
QList
QObject
kWarning
#define kWarning
kdebug.h
kfontsizeaction.h
kicon.h
klocale.h
kmenu.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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.14.38 API Reference

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