• 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
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 
40 class 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 
67 KFontAction::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 
76 KFontAction::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 
85 KFontAction::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 
94 KFontAction::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 
103 KFontAction::~KFontAction()
104 {
105  delete d;
106 }
107 
108 QString KFontAction::font() const
109 {
110  return currentText();
111 }
112 
113 QWidget* 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  */
138 void 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"
kfontdialog.h
KFontComboBox::sizeHint
virtual QSize sizeHint() const
The recommended size of the widget.
Definition: kfontcombobox.cpp:396
QString::indexOf
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
QWidget
QSize::width
int width() const
kdebug.h
KFontComboBox
A lightweight font selection widget.
Definition: kfontcombobox.h:49
KFontAction::KFontAction
KFontAction(uint fontListCriteria, QObject *parent)
Definition: kfontaction.cpp:67
QFont
KFontChooser::getFontList
static void getFontList(QStringList &list, uint fontListCriteria)
Creates a list of font strings.
Definition: kfontchooser.cpp:1000
QWidget::setMinimumWidth
void setMinimumWidth(int minw)
KFontAction::setFont
void setFont(const QString &family)
Definition: kfontaction.cpp:138
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
klocale.h
KFontAction::~KFontAction
virtual ~KFontAction()
Definition: kfontaction.cpp:103
KFontAction::font
QString font() const
KSelectAction
Action for selecting one of several items.
Definition: kselectaction.h:51
kfontaction.h
KSelectAction::setEditable
void setEditable(bool)
When this action is plugged into a toolbar, it creates a combobox.
Definition: kselectaction.cpp:404
KFontAction
An action to select a font family.
Definition: kfontaction.h:36
kfontcombobox.h
QObject
KSelectAction::items
QStringList items() const
Convenience function which returns the items that can be selected with this action.
KSelectAction::setItems
void setItems(const QStringList &lst)
Convenience function to create the list of selectable items.
Definition: kselectaction.cpp:349
KIcon
A wrapper around QIcon that provides KDE icon features.
Definition: kicon.h:40
KFontComboBox::setFontList
void setFontList(const QStringList &fontList)
Set selectable fonts to be only those present in the list.
Definition: kfontcombobox.cpp:346
kfontchooser.h
QString
KSelectAction::currentText
QString currentText() const
Returns the text of the currently selected item.
QStringList
QString::toLower
QString toLower() const
QFont::family
QString family() const
KFontAction::createWidget
virtual QWidget * createWidget(QWidget *parent)
Reimplemented from.
Definition: kfontaction.cpp:113
QString::left
QString left(int n) const
kicon.h
KFontComboBox::currentFont
QFont currentFont
Definition: kfontcombobox.h:53
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject::parent
QObject * parent() const
QWidgetAction::createdWidgets
QList< QWidget * > createdWidgets() const
KSelectAction::setCurrentAction
bool setCurrentAction(QAction *action)
Sets the currently checked item.
Definition: kselectaction.cpp:133
KFontComboBox::setCurrentFont
void setCurrentFont(const QFont &font)
Set the font to show as selected in the combobox.
Definition: kfontcombobox.cpp:359
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