diff --git a/kdeui/fonts/kfontrequester.cpp b/kdeui/fonts/kfontrequester.cpp index 3164839b..246f1e83 100644 --- a/kdeui/fonts/kfontrequester.cpp +++ b/kdeui/fonts/kfontrequester.cpp @@ -32,7 +32,7 @@ // Determine if the font with given properties is available on the system, // otherwise find and return the best fitting combination. -static QFont nearestExistingFont (const QFont &font) +static QFont nearestExistingFont(const QFont &font) { QFontDatabase dbase; @@ -56,12 +56,12 @@ static QFont nearestExistingFont (const QFont &font) // Check if the family has the requested size. // Only for bitmap fonts. if (!dbase.isScalable(family, style)) { - QList sizes = dbase.pointSizes(family, style); + const QList sizes = dbase.pointSizes(family, style); if (!sizes.contains(size)) { // Find nearest available size. int mindiff = 1000; int refsize = size; - foreach (int lsize, sizes) { + foreach (const int lsize, sizes) { int diff = qAbs(refsize - lsize); if (mindiff > diff) { mindiff = diff; @@ -82,52 +82,56 @@ static QFont nearestExistingFont (const QFont &font) class KFontRequester::KFontRequesterPrivate { public: - KFontRequesterPrivate(KFontRequester *q): q(q) {} + KFontRequesterPrivate(KFontRequester *qq) + : q(qq) + { + } - void displaySampleText(); - void setToolTip(); + void displaySampleText(); + void setToolTip(); - void _k_buttonClicked(); + void _k_buttonClicked(); - KFontRequester *q; - bool m_onlyFixed; - QString m_sampleText, m_title; - QLabel *m_sampleLabel; - QPushButton *m_button; - QFont m_selFont; + KFontRequester *q; + bool m_onlyFixed; + QString m_sampleText, m_title; + QLabel *m_sampleLabel; + QPushButton *m_button; + QFont m_selFont; }; -KFontRequester::KFontRequester( QWidget *parent, bool onlyFixed ) - : QWidget( parent ), d(new KFontRequesterPrivate(this)) +KFontRequester::KFontRequester(QWidget *parent, bool onlyFixed) + : QWidget(parent), + d(new KFontRequesterPrivate(this)) { - d->m_onlyFixed = onlyFixed; + d->m_onlyFixed = onlyFixed; - QHBoxLayout *layout = new QHBoxLayout( this ); - layout->setMargin( 0 ); + QHBoxLayout *layout = new QHBoxLayout(this); + layout->setMargin(0); - d->m_sampleLabel = new QLabel( this ); - d->m_button = new QPushButton( i18n( "Choose..." ), this ); + d->m_sampleLabel = new QLabel(this); + d->m_button = new QPushButton(i18n("Choose..."), this); - d->m_sampleLabel->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken ); - setFocusProxy( d->m_button ); + d->m_sampleLabel->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); + setFocusProxy(d->m_button); - layout->addWidget( d->m_sampleLabel, 1 ); - layout->addWidget( d->m_button ); + layout->addWidget(d->m_sampleLabel, 1); + layout->addWidget(d->m_button); - connect( d->m_button, SIGNAL(clicked()), SLOT(_k_buttonClicked()) ); + connect(d->m_button, SIGNAL(clicked()), SLOT(_k_buttonClicked())); - d->displaySampleText(); - d->setToolTip(); + d->displaySampleText(); + d->setToolTip(); } KFontRequester::~KFontRequester() { - delete d; + delete d; } QFont KFontRequester::font() const { - return d->m_selFont; + return d->m_selFont; } bool KFontRequester::isFixedOnly() const @@ -137,100 +141,101 @@ bool KFontRequester::isFixedOnly() const QString KFontRequester::sampleText() const { - return d->m_sampleText; + return d->m_sampleText; } QString KFontRequester::title() const { - return d->m_title; + return d->m_title; } QLabel *KFontRequester::label() const { - return d->m_sampleLabel; + return d->m_sampleLabel; } QPushButton *KFontRequester::button() const { - return d->m_button; + return d->m_button; } -void KFontRequester::setFont( const QFont &font, bool onlyFixed ) +void KFontRequester::setFont(const QFont &font, bool onlyFixed) { - d->m_selFont = nearestExistingFont(font); - d->m_onlyFixed = onlyFixed; + d->m_selFont = nearestExistingFont(font); + d->m_onlyFixed = onlyFixed; - d->displaySampleText(); - emit fontSelected( d->m_selFont ); + d->displaySampleText(); + emit fontSelected(d->m_selFont); } -void KFontRequester::setSampleText( const QString &text ) +void KFontRequester::setSampleText(const QString &text) { - d->m_sampleText = text; - d->displaySampleText(); + d->m_sampleText = text; + d->displaySampleText(); } -void KFontRequester::setTitle( const QString &title ) +void KFontRequester::setTitle(const QString &title) { - d->m_title = title; - d->setToolTip(); + d->m_title = title; + d->setToolTip(); } void KFontRequester::KFontRequesterPrivate::_k_buttonClicked() { KFontChooser::DisplayFlags flags = KFontChooser::NoDisplayFlags; - if ( m_onlyFixed ) { + if (m_onlyFixed) { flags |= KFontChooser::FixedFontsOnly; } - int result = KFontDialog::getFont( m_selFont, flags, q->parentWidget() ); + int result = KFontDialog::getFont(m_selFont, flags, q->parentWidget()); - if ( result == KDialog::Accepted ) - { + if (result == KDialog::Accepted) { displaySampleText(); - emit q->fontSelected( m_selFont ); + emit q->fontSelected(m_selFont); } } void KFontRequester::KFontRequesterPrivate::displaySampleText() { - m_sampleLabel->setFont( m_selFont ); + m_sampleLabel->setFont(m_selFont); - qreal size = m_selFont.pointSizeF(); - if(size == -1) - size = m_selFont.pixelSize(); + qreal size = m_selFont.pointSizeF(); + if (size == -1) { + size = m_selFont.pixelSize(); + } - if ( m_sampleText.isEmpty() ) { - QString family = translateFontName(m_selFont.family()); - m_sampleLabel->setText( QString( "%1 %2" ).arg( family ).arg( KGlobal::locale()->formatNumber( size, (size == floor(size)) ? 0 : 1 ) ) ); - } - else { - m_sampleLabel->setText( m_sampleText ); - } + if (m_sampleText.isEmpty()) { + QString family = translateFontName(m_selFont.family()); + m_sampleLabel->setText(QString::fromLatin1( "%1 %2").arg(family).arg(KGlobal::locale()->formatNumber(size, (size == floor(size)) ? 0 : 1))); + } else { + m_sampleLabel->setText( m_sampleText ); + } } void KFontRequester::KFontRequesterPrivate::setToolTip() { - m_button->setToolTip( i18n( "Click to select a font" ) ); + m_button->setToolTip(i18n("Click to select a font")); - m_sampleLabel->setToolTip( QString() ); - m_sampleLabel->setWhatsThis(QString()); + m_sampleLabel->setToolTip(QString()); + m_sampleLabel->setWhatsThis(QString()); - if ( m_title.isNull() ) - { - m_sampleLabel->setToolTip( i18n( "Preview of the selected font" ) ); - m_sampleLabel->setWhatsThis( i18n( "This is a preview of the selected font. You can change it" - " by clicking the \"Choose...\" button." ) ); - } - else - { - m_sampleLabel->setToolTip( i18n( "Preview of the \"%1\" font" , m_title ) ); - m_sampleLabel->setWhatsThis( i18n( "This is a preview of the \"%1\" font. You can change it" - " by clicking the \"Choose...\" button." , m_title ) ); - } + if (m_title.isNull()) { + m_sampleLabel->setToolTip(i18n("Preview of the selected font")); + m_sampleLabel->setWhatsThis( + i18n( + "This is a preview of the selected font. You can change it" + " by clicking the \"Choose...\" button." + ) + ); + } else { + m_sampleLabel->setToolTip(i18n("Preview of the \"%1\" font", m_title)); + m_sampleLabel->setWhatsThis( + i18n( + "This is a preview of the \"%1\" font. You can change it" + " by clicking the \"Choose...\" button.", m_title + ) + ); + } } #include "moc_kfontrequester.cpp" - -/* vim: et sw=2 ts=2 -*/ diff --git a/kdeui/fonts/kfontrequester.h b/kdeui/fonts/kfontrequester.h index fb8b10fc..4f29faa4 100644 --- a/kdeui/fonts/kfontrequester.h +++ b/kdeui/fonts/kfontrequester.h @@ -43,14 +43,12 @@ */ class KDEUI_EXPORT KFontRequester : public QWidget { - Q_OBJECT - - Q_PROPERTY( QString title READ title WRITE setTitle ) - Q_PROPERTY( QString sampleText READ sampleText WRITE setSampleText ) - Q_PROPERTY( QFont font READ font WRITE setFont NOTIFY fontSelected USER true) - - public: + Q_OBJECT + Q_PROPERTY(QString title READ title WRITE setTitle) + Q_PROPERTY(QString sampleText READ sampleText WRITE setSampleText) + Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontSelected USER true) +public: /** * Constructs a font requester widget. * @@ -58,7 +56,7 @@ class KDEUI_EXPORT KFontRequester : public QWidget * @param onlyFixed Only display fonts which have fixed-width character * sizes. */ - explicit KFontRequester( QWidget *parent=0L, bool onlyFixed=false ); + explicit KFontRequester(QWidget *parent = 0L, bool onlyFixed = false); ~KFontRequester(); @@ -99,7 +97,7 @@ class KDEUI_EXPORT KFontRequester : public QWidget * @param onlyFixed Display only fixed-width fonts in the font dialog * if @p true, or vice-versa. */ - virtual void setFont( const QFont &font, bool onlyFixed=false ); + virtual void setFont(const QFont &font, bool onlyFixed = false); /** * Sets the sample text. @@ -112,7 +110,7 @@ class KDEUI_EXPORT KFontRequester : public QWidget * * @param text The new sample text. The current will be removed. */ - virtual void setSampleText( const QString &text ); + virtual void setSampleText(const QString &text); /** * Set the title for the widget that will be used in the tooltip and @@ -120,25 +118,22 @@ class KDEUI_EXPORT KFontRequester : public QWidget * * @param title The title to be set. */ - virtual void setTitle( const QString & title ); + virtual void setTitle(const QString &title); - Q_SIGNALS: +Q_SIGNALS: /** * Emitted when a new @p font has been selected in the underlying dialog */ - void fontSelected( const QFont &font ); + void fontSelected(const QFont &font); - private: +private: class KFontRequesterPrivate; friend class KFontRequesterPrivate; KFontRequesterPrivate *const d; - Q_PRIVATE_SLOT( d, void _k_buttonClicked() ) + Q_PRIVATE_SLOT(d, void _k_buttonClicked()) Q_DISABLE_COPY(KFontRequester) }; #endif // KFONTREQUESTER_H - -/* vim: et sw=2 ts=2 -*/