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 #ifdef __GNUC__
00117 #warning FIXME: items need to be converted
00118 #endif
00119
00120
00121
00122 KFontComboBox *cb = new KFontComboBox( parent );
00123
00124 kDebug(129) << "\tset=" << font();
00125
00126 cb->setCurrentFont( QFont( font().toLower() ) );
00127 kDebug(129) << "\tspit back=" << cb->currentFont().family();
00128
00129 connect( cb, SIGNAL( currentFontChanged( const QFont & ) ), SLOT(_k_slotFontChanged( const QFont& ) ) );
00130 cb->setMinimumWidth( cb->sizeHint().width() );
00131 return cb;
00132 }
00133
00134
00135
00136
00137 void KFontAction::setFont( const QString &family )
00138 {
00139 kDebug(129) << "KFontAction::setFont(" << family << ")";
00140
00141
00142 d->settingFont++;
00143
00144 foreach(QWidget *w, createdWidgets())
00145 {
00146 KFontComboBox *cb = qobject_cast<KFontComboBox *>(w);
00147 kDebug(129) << "\tw=" << w << "cb=" << cb;
00148
00149 if(!cb) continue;
00150
00151 cb->setCurrentFont(QFont(family.toLower()));
00152 kDebug(129) << "\t\tw spit back=" << cb->currentFont().family();
00153 }
00154
00155 d->settingFont--;
00156
00157 kDebug(129) << "\tcalling setCurrentAction()";
00158
00159 QString lowerName = family.toLower();
00160 if (setCurrentAction(lowerName, Qt::CaseInsensitive))
00161 return;
00162
00163 int i = lowerName.indexOf(" [");
00164 if (i > -1)
00165 {
00166 lowerName = lowerName.left(i);
00167 i = 0;
00168 if (setCurrentAction(lowerName, Qt::CaseInsensitive))
00169 return;
00170 }
00171
00172 lowerName += " [";
00173 if (setCurrentAction(lowerName, Qt::CaseInsensitive))
00174 return;
00175
00176
00177
00178 kDebug(129) << "Font not found " << family.toLower();
00179 }
00180
00181 #include "kfontaction.moc"