KDEUI
kfontaction.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "kfontaction.h"
00030
00031 #include <QtGui/QToolBar>
00032
00033 #include <kdebug.h>
00034 #include <kfontdialog.h>
00035 #include <kicon.h>
00036 #include <klocale.h>
00037 #include <kfontchooser.h>
00038 #include <kfontcombobox.h>
00039
00040 class KFontAction::KFontActionPrivate
00041 {
00042 public:
00043 KFontActionPrivate(KFontAction *parent)
00044 : q(parent),
00045 settingFont(0)
00046 {
00047 }
00048
00049 void _k_slotFontChanged(const QFont &font)
00050 {
00051 kDebug(129) << "KFontComboBox - slotFontChanged("
00052 << font.family() << ") settingFont=" << settingFont;
00053 if (settingFont)
00054 return;
00055
00056 q->setFont(font.family());
00057 q->triggered(font.family());
00058
00059 kDebug(129) << "\tslotFontChanged done";
00060 }
00061
00062
00063 KFontAction *q;
00064 int settingFont;
00065 };
00066
00067 KFontAction::KFontAction(uint fontListCriteria, QObject *parent)
00068 : KSelectAction(parent), d(new KFontActionPrivate(this))
00069 {
00070 QStringList list;
00071 KFontChooser::getFontList( list, fontListCriteria );
00072 KSelectAction::setItems( list );
00073 setEditable( true );
00074 }
00075
00076 KFontAction::KFontAction(QObject *parent)
00077 : KSelectAction(parent), d(new KFontActionPrivate(this))
00078 {
00079 QStringList list;
00080 KFontChooser::getFontList( list, 0 );
00081 KSelectAction::setItems( list );
00082 setEditable( true );
00083 }
00084
00085 KFontAction::KFontAction(const QString & text, QObject *parent)
00086 : KSelectAction(text, parent), d(new KFontActionPrivate(this))
00087 {
00088 QStringList list;
00089 KFontChooser::getFontList( list, 0 );
00090 KSelectAction::setItems( list );
00091 setEditable( true );
00092 }
00093
00094 KFontAction::KFontAction(const KIcon &icon, const QString &text, QObject *parent)
00095 : KSelectAction(icon, text, parent), d(new KFontActionPrivate(this))
00096 {
00097 QStringList list;
00098 KFontChooser::getFontList( list, 0 );
00099 KSelectAction::setItems( list );
00100 setEditable( true );
00101 }
00102
00103 KFontAction::~KFontAction()
00104 {
00105 delete d;
00106 }
00107
00108 QString KFontAction::font() const
00109 {
00110 return currentText();
00111 }
00112
00113 QWidget* KFontAction::createWidget(QWidget* _parent)
00114 {
00115 kDebug(129) << "KFontAction::createWidget()";
00116
00117 QToolBar *parent = qobject_cast<QToolBar *>(_parent);
00118 if (!parent)
00119 return KSelectAction::createWidget(_parent);
00120
00121 #ifdef __GNUC__
00122 #warning FIXME: items need to be converted
00123 #endif
00124
00125
00126
00127 KFontComboBox *cb = new KFontComboBox( parent );
00128
00129 kDebug(129) << "\tset=" << font();
00130
00131 cb->setCurrentFont( QFont( font().toLower() ) );
00132 kDebug(129) << "\tspit back=" << cb->currentFont().family();
00133
00134 connect( cb, SIGNAL( currentFontChanged( const QFont & ) ), SLOT(_k_slotFontChanged( const QFont& ) ) );
00135 cb->setMinimumWidth( cb->sizeHint().width() );
00136 return cb;
00137 }
00138
00139
00140
00141
00142 void KFontAction::setFont( const QString &family )
00143 {
00144 kDebug(129) << "KFontAction::setFont(" << family << ")";
00145
00146
00147 d->settingFont++;
00148
00149 foreach(QWidget *w, createdWidgets())
00150 {
00151 KFontComboBox *cb = qobject_cast<KFontComboBox *>(w);
00152 kDebug(129) << "\tw=" << w << "cb=" << cb;
00153
00154 if(!cb) continue;
00155
00156 cb->setCurrentFont(QFont(family.toLower()));
00157 kDebug(129) << "\t\tw spit back=" << cb->currentFont().family();
00158 }
00159
00160 d->settingFont--;
00161
00162 kDebug(129) << "\tcalling setCurrentAction()";
00163
00164 QString lowerName = family.toLower();
00165 if (setCurrentAction(lowerName, Qt::CaseInsensitive))
00166 return;
00167
00168 int i = lowerName.indexOf(" [");
00169 if (i > -1)
00170 {
00171 lowerName = lowerName.left(i);
00172 i = 0;
00173 if (setCurrentAction(lowerName, Qt::CaseInsensitive))
00174 return;
00175 }
00176
00177 lowerName += " [";
00178 if (setCurrentAction(lowerName, Qt::CaseInsensitive))
00179 return;
00180
00181
00182
00183 kDebug(129) << "Font not found " << family.toLower();
00184 }
00185
00186
00187
00188
00189 #include "kfontaction.moc"