diff --git a/includes/CMakeLists.txt b/includes/CMakeLists.txt index fa37a5d9..273e9f60 100644 --- a/includes/CMakeLists.txt +++ b/includes/CMakeLists.txt @@ -122,7 +122,6 @@ install( KFloatValidator KFontAction KFontChooser - KFontComboBox KFontDialog KFontRequester KFontSizeAction diff --git a/includes/KFontComboBox b/includes/KFontComboBox deleted file mode 100644 index 84ff5dcf..00000000 --- a/includes/KFontComboBox +++ /dev/null @@ -1 +0,0 @@ -#include "../kfontcombobox.h" diff --git a/kdeui/CMakeLists.txt b/kdeui/CMakeLists.txt index 2f8941f8..5ba02248 100644 --- a/kdeui/CMakeLists.txt +++ b/kdeui/CMakeLists.txt @@ -111,7 +111,6 @@ set(kdeui_LIB_SRCS findreplace/kreplacedialog.cpp fonts/fonthelpers.cpp fonts/kfontchooser.cpp - fonts/kfontcombobox.cpp fonts/kfontdialog.cpp fonts/kfontrequester.cpp icons/kiconeffect.cpp @@ -400,7 +399,6 @@ install( findreplace/kfinddialog.h findreplace/kreplacedialog.h fonts/kfontchooser.h - fonts/kfontcombobox.h fonts/kfontdialog.h fonts/kfontrequester.h icons/kiconeffect.h diff --git a/kdeui/actions/kfontaction.cpp b/kdeui/actions/kfontaction.cpp index 9bab141f..8e3f440c 100644 --- a/kdeui/actions/kfontaction.cpp +++ b/kdeui/actions/kfontaction.cpp @@ -28,14 +28,15 @@ #include "kfontaction.h" -#include +#include +#include +#include #include #include #include #include #include -#include class KFontAction::KFontActionPrivate { @@ -48,7 +49,7 @@ class KFontAction::KFontActionPrivate void _k_slotFontChanged(const QFont &font) { - kDebug(129) << "KFontComboBox - slotFontChanged(" + kDebug(129) << "KFontAction - slotFontChanged(" << font.family() << ") settingFont=" << settingFont; if (settingFont) return; @@ -117,8 +118,10 @@ QWidget* KFontAction::createWidget(QWidget* parent) // This is the visual element on the screen. This method overrides // the KSelectAction one, preventing KSelectAction from creating its // regular KComboBox. - KFontComboBox *cb = new KFontComboBox( parent ); - cb->setFontList(items()); + QFontComboBox *cb = new QFontComboBox( parent ); + QStringListModel *cbmodel = qobject_cast(cb->model()); + Q_ASSERT(cbmodel); + cbmodel->setStringList(items()); kDebug(129) << "\tset=" << font(); // Do this before connecting the signal so that nothing will fire. @@ -130,9 +133,6 @@ QWidget* KFontAction::createWidget(QWidget* parent) return cb; } -/* - * Maintenance note: Keep in sync with KFontComboBox::setCurrentFont() - */ void KFontAction::setFont( const QString &family ) { kDebug(129) << "KFontAction::setFont(" << family << ")"; @@ -142,7 +142,7 @@ void KFontAction::setFont( const QString &family ) foreach(QWidget *w, createdWidgets()) { - KFontComboBox *cb = qobject_cast(w); + QFontComboBox *cb = qobject_cast(w); kDebug(129) << "\tw=" << w << "cb=" << cb; if(!cb) continue; @@ -171,7 +171,7 @@ void KFontAction::setFont( const QString &family ) if (setCurrentAction(lowerName, Qt::CaseInsensitive)) return; - // TODO: Inconsistent state if KFontComboBox::setCurrentFont() succeeded + // TODO: Inconsistent state if QFontComboBox::setCurrentFont() succeeded // but setCurrentAction() did not and vice-versa. kDebug(129) << "Font not found " << family.toLower(); } diff --git a/kdeui/dialogs/kconfigdialogmanager.cpp b/kdeui/dialogs/kconfigdialogmanager.cpp index 806f92a0..a5350273 100644 --- a/kdeui/dialogs/kconfigdialogmanager.cpp +++ b/kdeui/dialogs/kconfigdialogmanager.cpp @@ -125,7 +125,6 @@ void KConfigDialogManager::initMaps() // KDE s_changedMap->insert( "KComboBox", SIGNAL(activated(int))); - s_changedMap->insert( "KFontComboBox", SIGNAL(activated(int))); s_changedMap->insert( "KFontRequester", SIGNAL(fontSelected(QFont))); s_changedMap->insert( "KFontChooser", SIGNAL(fontSelected(QFont))); s_changedMap->insert( "KHistoryCombo", SIGNAL(activated(int))); diff --git a/kdeui/fonts/kfontcombobox.cpp b/kdeui/fonts/kfontcombobox.cpp deleted file mode 100644 index a669f284..00000000 --- a/kdeui/fonts/kfontcombobox.cpp +++ /dev/null @@ -1,371 +0,0 @@ -/* This file is part of the KDE libraries - - Copyright (C) 2008 Chusslove Illich - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "kfontcombobox.h" -#include "fonthelpers_p.h" - -#include "kdebug.h" -#include "klocale.h" -#include "kcolorscheme.h" -#include "kglobalsettings.h" -#include "kfontchooser.h" -#include "kcompletion.h" -#include "kiconloader.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static QString alphabetSample () -{ - return i18nc("short", - // i18n: A shorter version of the alphabet test phrase translated in - // another message. It is displayed in the dropdown list of font previews - // (the font selection combo box), so keep it under the length equivalent - // to 60 or so proportional Latin characters. - "The Quick Brown Fox Jumps Over The Lazy Dog"); -} - -class KFontFamilyDelegate : public QAbstractItemDelegate -{ - Q_OBJECT -public: - explicit KFontFamilyDelegate (QObject *parent); - - void paint (QPainter *painter, - const QStyleOptionViewItem &option, - const QModelIndex &index) const; - - QSize sizeHint (const QStyleOptionViewItem &option, - const QModelIndex &index) const; - - QIcon truetype; - QIcon bitmap; - double sizeFactFamily; - double sizeFactSample; - - QHash fontFamilyTrMap; - QFontDatabase fontdb; -}; - -KFontFamilyDelegate::KFontFamilyDelegate (QObject *parent) - : QAbstractItemDelegate(parent) -{ - truetype = SmallIcon(QString::fromLatin1("application-x-font-ttf")); - bitmap = SmallIcon(QString::fromLatin1("application-x-font-bdf")); - - // Font size factors for family name and text sample in font previes, - // multiplies normal font size. - sizeFactFamily = 1.0; - sizeFactSample = 1.0; // better leave at 1, so that user can relate sizes to default -} - -void KFontFamilyDelegate::paint (QPainter *painter, - const QStyleOptionViewItem &option, - const QModelIndex &index) const -{ - QBrush sampleBrush; - if (option.state & QStyle::State_Selected) { - painter->save(); - painter->setBrush(option.palette.highlight()); - painter->setPen(Qt::NoPen); - painter->drawRect(option.rect); - painter->setPen(QPen(option.palette.highlightedText(), 0)); - sampleBrush = option.palette.highlightedText(); - } else { - sampleBrush = KColorScheme(QPalette::Normal).foreground(KColorScheme::InactiveText); - } - - QFont baseFont = KGlobalSettings::generalFont(); - QString trFontFamily = index.data(Qt::DisplayRole).toString(); - QString fontFamily = fontFamilyTrMap[trFontFamily]; - - // Choose and paint an icon according to the font type, scalable or bitmat. - const QIcon *icon = &bitmap; - if (fontdb.isScalable(fontFamily)) { - icon = &truetype; - } - QRect r = option.rect; - icon->paint(painter, r, Qt::AlignLeft|Qt::AlignTop); - - // Claim space taken up by the icon. - QSize actualSize = icon->actualSize(r.size()); - if (option.direction == Qt::RightToLeft) { - r.setRight(r.right() - actualSize.width() - 4); - } else { - r.setLeft(r.left() + actualSize.width() + 4); - } - - // Draw the font family. - QFont oldPainterFont = painter->font(); - QFont familyFont = baseFont; - familyFont.setPointSizeF(familyFont.pointSizeF() * sizeFactFamily); - painter->setFont(familyFont); - painter->drawText(r, Qt::AlignTop|Qt::AlignLeading|Qt::TextSingleLine, trFontFamily); - - // Claim space taken up by the font family name. - int h = painter->fontMetrics().lineSpacing(); - r.setTop(r.top() + h); - - // Show text sample in user's language if the writing system is supported, - // otherwise show a collage of generic script samples provided by Qt. - // If the font does not report what it supports, assume all. - QString sample = alphabetSample(); - QFont sampleFont; - sampleFont.setFamily(fontFamily); - sampleFont.setPointSizeF(sampleFont.pointSizeF() * sizeFactSample); - painter->setFont(sampleFont); - QPen oldPen = painter->pen(); - painter->setPen(sampleBrush.color()); - painter->drawText(r, Qt::AlignTop|Qt::AlignLeading|Qt::TextSingleLine, sample); - painter->setFont(oldPainterFont); - painter->setPen(oldPen); - - if (option.state & QStyle::State_Selected) { - painter->restore(); - } -} - -QSize KFontFamilyDelegate::sizeHint (const QStyleOptionViewItem &option, - const QModelIndex &index) const -{ - Q_UNUSED(option); - - QFont baseFont = KGlobalSettings::generalFont(); - QString trFontFamily = index.data(Qt::DisplayRole).toString(); - QString fontFamily = fontFamilyTrMap[trFontFamily]; - - QFont familyFont = baseFont; - familyFont.setPointSizeF(familyFont.pointSizeF() * sizeFactFamily); - QFontMetrics familyMetrics(familyFont); - - QFont sampleFont = baseFont; - sampleFont.setFamily(fontFamily); - sampleFont.setPointSizeF(sampleFont.pointSizeF() * sizeFactSample); - QFontMetrics sampleMetrics(sampleFont); - QString sample = alphabetSample(); - - // Only the hight matters here, the width is mandated by KFontComboBox::event() - return QSize(qMax(familyMetrics.width(trFontFamily), sampleMetrics.width(sample)), - qRound(familyMetrics.lineSpacing() + sampleMetrics.lineSpacing() * 1.2)); -} - -class KFontComboBoxPrivate -{ -public: - KFontComboBoxPrivate (KFontComboBox *parent); - void updateDatabase (); - void updateIndexToFont (); - void _k_currentFontChanged (int index); - - KFontComboBox *k; - QFont currentFont; - bool onlyFixed; - bool signalsAllowed; - KFontFamilyDelegate *delegate; - QStringListModel *model; - QStringList fontList; -}; - -KFontComboBoxPrivate::KFontComboBoxPrivate (KFontComboBox *parent) - : k(parent), - currentFont(KGlobalSettings::generalFont()), - onlyFixed(false), - signalsAllowed(true) -{ -} - -void KFontComboBoxPrivate::updateDatabase () -{ - QStringList fontFamilies = fontList; - if (fontList.isEmpty()) { - KFontChooser::getFontList(fontFamilies, - onlyFixed ? KFontChooser::FixedWidthFonts : 0); - } - - // Translate font families for the list model. - delegate->fontFamilyTrMap.clear(); - QStringList trFontFamilies = - translateFontNameList(fontFamilies, &(delegate->fontFamilyTrMap)); - - // Add families to the list model and completion. - model->setStringList(trFontFamilies); - KCompletion *completion = k->completionObject(); - if (completion) { - completion->setItems(trFontFamilies); - completion->setIgnoreCase(true); - } -} - -void KFontComboBoxPrivate::updateIndexToFont () -{ - // QFontDatabase necessary to return the family with proper casing. - QFontDatabase fdb; - QString selectedFontFamily = fdb.font(currentFont.family(), currentFont.styleName(), currentFont.pointSize()).family(); - QString trSelectedFontFamily = translateFontName(selectedFontFamily); - const QStringList trFontFamilies = model->stringList(); - if (!trFontFamilies.count()) { - return; - } - - // Match the font's family with an item in the list. - int index = 0; - foreach (const QString &trFontFamily, trFontFamilies) { - if (trSelectedFontFamily == trFontFamily) { - break; - } - ++index; - } - if (index == trFontFamilies.count()) { - // If no family matched, change font to first on the list. - index = 0; - currentFont = QFont(delegate->fontFamilyTrMap[trFontFamilies[0]]); - emit k->currentFontChanged(currentFont); - } - - // Set the new list item. - signalsAllowed = false; - k->setCurrentIndex(index); - signalsAllowed = true; -} - -void KFontComboBoxPrivate::_k_currentFontChanged (int index) -{ - if (!signalsAllowed) { - return; - } - - QString trFontFamily = k->itemText(index); - QString fontFamily = delegate->fontFamilyTrMap[trFontFamily]; - if (!fontFamily.isEmpty()) { - currentFont = QFont(fontFamily); - emit k->currentFontChanged(currentFont); - } else { - // Unknown font family given. Just remove from the list. - // This should not happen, as adding arbitrary font names is prevented. - QStringList lst = model->stringList(); - lst.removeAll(trFontFamily); - model->setStringList(lst); - } -} - -KFontComboBox::KFontComboBox (QWidget *parent) -: KComboBox(true, parent), d(new KFontComboBoxPrivate(this)) -{ - // Inputing arbitrary font names does not make sense. - setEditable(false); - - // Special list item painter showing font previews and its list model. - d->delegate = new KFontFamilyDelegate(this); - setItemDelegate(d->delegate); - d->model = new QStringListModel(this); - setModel(d->model); - - // Set current font when a new family has been chosen in the combo. - connect(this, SIGNAL(currentIndexChanged(int)), - this, SLOT(_k_currentFontChanged(int))); - - // Initialize font selection and list of available fonts. - d->updateDatabase(); - d->updateIndexToFont(); -} - -KFontComboBox::~KFontComboBox () -{ - delete d; -} - -void KFontComboBox::setOnlyFixed (bool onlyFixed) -{ - if (onlyFixed != d->onlyFixed) { - d->onlyFixed = onlyFixed; - d->updateDatabase(); - } -} - -void KFontComboBox::setFontList (const QStringList &fontList) -{ - if (fontList != d->fontList) { - d->fontList = fontList; - d->updateDatabase(); - } -} - -QFont KFontComboBox::currentFont () const -{ - return d->currentFont; -} - -void KFontComboBox::setCurrentFont (const QFont &font) -{ - if (font != d->currentFont) { - d->currentFont = font; - emit currentFontChanged(d->currentFont); - d->updateIndexToFont(); - } -} - -bool KFontComboBox::event (QEvent *e) -{ - if (e->type() == QEvent::Resize) { - QListView *lview = qobject_cast(view()); - if (lview) { - QString sample = alphabetSample(); - // Limit text sample length to avoid too wide list view. - if (sample.length() > 60) { - sample = sample.left(57) + "..."; - } - QFont approxFont = KGlobalSettings::generalFont(); - approxFont.setPointSizeF(approxFont.pointSizeF() - * d->delegate->sizeFactSample); - int widgetWidth = width(); - int sampleWidth = QFontMetrics(approxFont).width(sample); - sampleWidth = qRound(sampleWidth * 1.1); // extra for wider fonts - int iconWidth = d->delegate->truetype.actualSize(size()).width(); - int vsbarWidth = 0; - if (lview->verticalScrollBar()) { - vsbarWidth = lview->verticalScrollBar()->width(); - } - lview->window()->setFixedWidth( qMax(widgetWidth, sampleWidth) - + iconWidth + vsbarWidth); - } - } - return KComboBox::event(e); -} - -QSize KFontComboBox::sizeHint() const -{ - QSize sz = KComboBox::sizeHint(); - QFontMetrics fm(KGlobalSettings::generalFont()); - sz.setWidth(fm.width("m") * 14); - return sz; -} - -#include "kfontcombobox.moc" -#include "moc_kfontcombobox.moc" - diff --git a/kdeui/fonts/kfontcombobox.h b/kdeui/fonts/kfontcombobox.h deleted file mode 100644 index 536acbe5..00000000 --- a/kdeui/fonts/kfontcombobox.h +++ /dev/null @@ -1,133 +0,0 @@ -/* This file is part of the KDE libraries - - Copyright (C) 2008 Chusslove Illich - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -#ifndef KFONTCOMBOBOX_P_H -#define KFONTCOMBOBOX_P_H - -#include - -#include - -class KFontComboBoxPrivate; - -/** - * @short A lightweight font selection widget. - * - * A combobox to select the font from. Lightweight counterpart to KFontChooser, - * for situations where only the font family should be selected, while the - * font style and size are handled by other means. Like in KFontChooser, - * this widget will show the font previews in the unrolled dropdown list. - * - * @note The class is similar to QFontComboBox, but more tightly integrated - * with KDE desktop. Use it instead of QFontComboBox by default in KDE code. - * - * \image html kfontcombobox.png "KDE Font Combo Box" - * - * @author Chusslove Illich \ - * - * @see KFontAction - * @see KFontChooser - * - * @since 4.1 - */ -class KDEUI_EXPORT KFontComboBox : public KComboBox -{ - Q_OBJECT - - Q_PROPERTY(QFont currentFont READ currentFont WRITE setCurrentFont NOTIFY currentFontChanged USER true) - -public: - - /** - * Constructor. - * - * @param parent the parent widget - */ - explicit KFontComboBox (QWidget *parent = 0); - - /** - * Toggle selectable fonts to be only those of fixed width or all. - * - * @param onlyFixed only fixed width fonts when @p true, - * all fonts when @p false - */ - void setOnlyFixed (bool onlyFixed); - - /** - * Set selectable fonts to be only those present in the list. - * - * @param fontList a list of fonts as returned by QFontDatabase::families() or - * QFontChooser::getFontList(). If this is empty (default), then the list - * of fonts is constructed according to the @p onlyFixed setting. - * @since 4.9.2 - */ - void setFontList (const QStringList &fontList); - - /** - * Destructor. - */ - virtual ~KFontComboBox (); - - /** - * The font currently selected from the list. - * - * @return the selected font - */ - QFont currentFont () const; - - /** - * The recommended size of the widget. - * Reimplemented to make the recommended width independent - * of the particular fonts installed. - * - * @return recommended size - */ - virtual QSize sizeHint() const; - -public Q_SLOTS: - /** - * Set the font to show as selected in the combobox. - * - * @param font the new font - */ - void setCurrentFont (const QFont &font); - -Q_SIGNALS: - /** - * Emitted when a new font has been selected, - * either through user input or by setFont(). - * - * @param font the new font - */ - void currentFontChanged (const QFont &font); - -protected: - bool event (QEvent *e); - -private: - - friend class KFontComboBoxPrivate; - KFontComboBoxPrivate * const d; - - Q_DISABLE_COPY(KFontComboBox) - - Q_PRIVATE_SLOT(d, void _k_currentFontChanged (int)) -}; - -#endif diff --git a/kdewidgets/kde.widgets b/kdewidgets/kde.widgets index e4c54608..dc35a4ed 100644 --- a/kdewidgets/kde.widgets +++ b/kdewidgets/kde.widgets @@ -105,12 +105,6 @@ ToolTip=Font Chooser (KDE) WhatsThis=A font type, size and style selection widget complete with preview Group=Input (KDE) -[KFontComboBox] -IncludeFile=kfontcombobox.h -ToolTip=Font Combo Box (KDE) -WhatsThis=A combo box for font selection with language-specific previews -Group=Input (KDE) - [KFontRequester] IncludeFile=kfontrequester.h ToolTip=Font Requester (KDE)