# kdeui Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kfontrequester.cpp

    00001 /*
    00002     Copyright (C) 2003 Nadeem Hasan <nhasan@kde.org>
    00003
    00004     This library is free software; you can redistribute it and/or
    00005     modify it under the terms of the GNU Library General Public
    00006     License as published by the Free Software Foundation; either
    00007     version 2 of the License, or (at your option) any later version.
    00008
    00009     This library is distributed in the hope that it will be useful,
    00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012     Library General Public License for more details.
    00013
    00014     You should have received a copy of the GNU Library General Public License
    00015     along with this library; see the file COPYING.LIB.  If not, write to
    00016     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00017     Boston, MA 02111-1307, USA.
    00018 */
    00019
    00020 #include "kfontrequester.h"
    00021
    00022 #include <qlabel.h>
    00023 #include <qpushbutton.h>
    00024 #include <qlayout.h>
    00025 #include <qtooltip.h>
    00026 #include <qwhatsthis.h>
    00027
    00028 #include <kfontdialog.h>
    00029 #include <klocale.h>
    00030
    00031 KFontRequester::KFontRequester( QWidget *parent, const char *name,
    00032     bool onlyFixed ) : QWidget( parent, name ),
    00033     m_onlyFixed( onlyFixed )
    00034 {
    00035   QHBoxLayout *layout = new QHBoxLayout( this, 0, KDialog::spacingHint() );
    00036
    00037   m_sampleLabel = new QLabel( this, "m_sampleLabel" );
    00038   m_button = new QPushButton( i18n( "Choose..." ), this, "m_button" );
    00039
    00040   m_sampleLabel->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
    00041   setFocusProxy( m_button );
    00042
    00043   layout->addWidget( m_sampleLabel, 1 );
    00044   layout->addWidget( m_button );
    00045
    00046   connect( m_button, SIGNAL( clicked() ), SLOT( buttonClicked() ) );
    00047
    00048   displaySampleText();
    00049   setToolTip();
    00050 }
    00051
    00052 void KFontRequester::setFont( const QFont &font, bool onlyFixed )
    00053 {
    00054   m_selFont = font;
    00055   m_onlyFixed = onlyFixed;
    00056
    00057   displaySampleText();
    00058   emit fontSelected( m_selFont );
    00059 }
    00060
    00061 void KFontRequester::setSampleText( const QString &text )
    00062 {
    00063   m_sampleText = text;
    00064   displaySampleText();
    00065 }
    00066
    00067 void KFontRequester::setTitle( const QString &title )
    00068 {
    00069   m_title = title;
    00070   setToolTip();
    00071 }
    00072
    00073 void KFontRequester::buttonClicked()
    00074 {
    00075   int result = KFontDialog::getFont( m_selFont, m_onlyFixed, parentWidget() );
    00076
    00077   if ( result == KDialog::Accepted )
    00078   {
    00079     displaySampleText();
    00080     emit fontSelected( m_selFont );
    00081   }
    00082 }
    00083
    00084 void KFontRequester::displaySampleText()
    00085 {
    00086   m_sampleLabel->setFont( m_selFont );
    00087
    00088   int size = m_selFont.pointSize();
    00089   if(size == -1)
    00090     size = m_selFont.pixelSize();
    00091
    00092   if ( m_sampleText.isEmpty() )
    00093     m_sampleLabel->setText( QString( "%1 %2" ).arg( m_selFont.family() )
    00094       .arg( size ) );
    00095   else
    00096     m_sampleLabel->setText( m_sampleText );
    00097 }
    00098
    00099 void KFontRequester::setToolTip()
    00100 {
    00101   QToolTip::remove( m_button );
    00102   QToolTip::add( m_button, i18n( "Click to select a font" ) );
    00103
    00104   QToolTip::remove( m_sampleLabel );
    00105   QWhatsThis::remove( m_sampleLabel );
    00106
    00107   if ( m_title.isNull() )
    00108   {
    00109     QToolTip::add( m_sampleLabel, i18n( "Preview of the selected font" ) );
    00110     QWhatsThis::add( m_sampleLabel,
    00111         i18n( "This is a preview of the selected font. You can change it"
    00112         " by clicking the \"Choose...\" button." ) );
    00113   }
    00114   else
    00115   {
    00116     QToolTip::add( m_sampleLabel,
    00117         i18n( "Preview of the \"%1\" font" ).arg( m_title ) );
    00118     QWhatsThis::add( m_sampleLabel,
    00119         i18n( "This is a preview of the \"%1\" font. You can change it"
    00120         " by clicking the \"Choose...\" button." ).arg( m_title ) );
    00121   }
    00122 }
    00123
    00124 #include "kfontrequester.moc"
    00125
    00126 /* vim: et sw=2 ts=2
    00127 */

This file is part of the documentation for kdeui Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:20:17 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003