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

KDEUI

  • kdeui
  • actions
kfontaction.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 (C) 2007 Clarence Dang <dang@kde.org>
13
14 This library is free software; you can redistribute it and/or
15 modify it under the terms of the GNU Library General Public
16 License version 2 as published by the Free Software Foundation.
17
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Library General Public License for more details.
22
23 You should have received a copy of the GNU Library General Public License
24 along with this library; see the file COPYING.LIB. If not, write to
25 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 Boston, MA 02110-1301, USA.
27*/
28
29#include "kfontaction.h"
30
31#include <QtGui/QToolBar>
32
33#include <kdebug.h>
34#include <kfontdialog.h>
35#include <kicon.h>
36#include <klocale.h>
37#include <kfontchooser.h>
38#include <kfontcombobox.h>
39
40class KFontAction::KFontActionPrivate
41{
42 public:
43 KFontActionPrivate(KFontAction *parent)
44 : q(parent),
45 settingFont(0)
46 {
47 }
48
49 void _k_slotFontChanged(const QFont &font)
50 {
51 kDebug(129) << "KFontComboBox - slotFontChanged("
52 << font.family() << ") settingFont=" << settingFont;
53 if (settingFont)
54 return;
55
56 q->setFont(font.family());
57 q->triggered(font.family());
58
59 kDebug(129) << "\tslotFontChanged done";
60 }
61
62
63 KFontAction *q;
64 int settingFont;
65};
66
67KFontAction::KFontAction(uint fontListCriteria, QObject *parent)
68 : KSelectAction(parent), d(new KFontActionPrivate(this))
69{
70 QStringList list;
71 KFontChooser::getFontList( list, fontListCriteria );
72 KSelectAction::setItems( list );
73 setEditable( true );
74}
75
76KFontAction::KFontAction(QObject *parent)
77 : KSelectAction(parent), d(new KFontActionPrivate(this))
78{
79 QStringList list;
80 KFontChooser::getFontList( list, 0 );
81 KSelectAction::setItems( list );
82 setEditable( true );
83}
84
85KFontAction::KFontAction(const QString & text, QObject *parent)
86 : KSelectAction(text, parent), d(new KFontActionPrivate(this))
87{
88 QStringList list;
89 KFontChooser::getFontList( list, 0 );
90 KSelectAction::setItems( list );
91 setEditable( true );
92}
93
94KFontAction::KFontAction(const KIcon &icon, const QString &text, QObject *parent)
95 : KSelectAction(icon, text, parent), d(new KFontActionPrivate(this))
96{
97 QStringList list;
98 KFontChooser::getFontList( list, 0 );
99 KSelectAction::setItems( list );
100 setEditable( true );
101}
102
103KFontAction::~KFontAction()
104{
105 delete d;
106}
107
108QString KFontAction::font() const
109{
110 return currentText();
111}
112
113QWidget* KFontAction::createWidget(QWidget* parent)
114{
115 kDebug(129) << "KFontAction::createWidget()";
116#ifdef __GNUC__
117#warning FIXME: items need to be converted
118#endif
119 // This is the visual element on the screen. This method overrides
120 // the KSelectAction one, preventing KSelectAction from creating its
121 // regular KComboBox.
122 KFontComboBox *cb = new KFontComboBox( parent );
123 cb->setFontList(items());
124
125 kDebug(129) << "\tset=" << font();
126 // Do this before connecting the signal so that nothing will fire.
127 cb->setCurrentFont( QFont( font().toLower() ) );
128 kDebug(129) << "\tspit back=" << cb->currentFont().family();
129
130 connect( cb, SIGNAL(currentFontChanged(QFont)), SLOT(_k_slotFontChanged(QFont)) );
131 cb->setMinimumWidth( cb->sizeHint().width() );
132 return cb;
133}
134
135/*
136 * Maintenance note: Keep in sync with KFontComboBox::setCurrentFont()
137 */
138void KFontAction::setFont( const QString &family )
139{
140 kDebug(129) << "KFontAction::setFont(" << family << ")";
141
142 // Suppress triggered(QString) signal and prevent recursive call to ourself.
143 d->settingFont++;
144
145 foreach(QWidget *w, createdWidgets())
146 {
147 KFontComboBox *cb = qobject_cast<KFontComboBox *>(w);
148 kDebug(129) << "\tw=" << w << "cb=" << cb;
149
150 if(!cb) continue;
151
152 cb->setCurrentFont(QFont(family.toLower()));
153 kDebug(129) << "\t\tw spit back=" << cb->currentFont().family();
154 }
155
156 d->settingFont--;
157
158 kDebug(129) << "\tcalling setCurrentAction()";
159
160 QString lowerName = family.toLower();
161 if (setCurrentAction(lowerName, Qt::CaseInsensitive))
162 return;
163
164 int i = lowerName.indexOf(" [");
165 if (i > -1)
166 {
167 lowerName = lowerName.left(i);
168 i = 0;
169 if (setCurrentAction(lowerName, Qt::CaseInsensitive))
170 return;
171 }
172
173 lowerName += " [";
174 if (setCurrentAction(lowerName, Qt::CaseInsensitive))
175 return;
176
177 // TODO: Inconsistent state if KFontComboBox::setCurrentFont() succeeded
178 // but setCurrentAction() did not and vice-versa.
179 kDebug(129) << "Font not found " << family.toLower();
180}
181
182#include "kfontaction.moc"
KFontAction
An action to select a font family.
Definition: kfontaction.h:37
KFontAction::createWidget
virtual QWidget * createWidget(QWidget *parent)
Reimplemented from.
Definition: kfontaction.cpp:113
KFontAction::font
QString font
Definition: kfontaction.h:39
KFontAction::KFontAction
KFontAction(uint fontListCriteria, QObject *parent)
Definition: kfontaction.cpp:67
KFontAction::~KFontAction
virtual ~KFontAction()
Definition: kfontaction.cpp:103
KFontAction::setFont
void setFont(const QString &family)
Definition: kfontaction.cpp:138
KFontChooser::getFontList
static void getFontList(QStringList &list, uint fontListCriteria)
Creates a list of font strings.
Definition: kfontchooser.cpp:1000
KFontComboBox
A lightweight font selection widget.
Definition: kfontcombobox.h:50
KFontComboBox::sizeHint
virtual QSize sizeHint() const
The recommended size of the widget.
Definition: kfontcombobox.cpp:396
KFontComboBox::setCurrentFont
void setCurrentFont(const QFont &font)
Set the font to show as selected in the combobox.
Definition: kfontcombobox.cpp:359
KFontComboBox::currentFont
QFont currentFont
Definition: kfontcombobox.h:53
KFontComboBox::setFontList
void setFontList(const QStringList &fontList)
Set selectable fonts to be only those present in the list.
Definition: kfontcombobox.cpp:346
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::setItems
void setItems(const QStringList &lst)
Convenience function to create the list of selectable items.
Definition: kselectaction.cpp:349
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::setEditable
void setEditable(bool)
When this action is plugged into a toolbar, it creates a combobox.
Definition: kselectaction.cpp:404
QObject
QWidget
kDebug
#define kDebug
kdebug.h
kfontaction.h
kfontchooser.h
kfontcombobox.h
kfontdialog.h
kicon.h
klocale.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