kfontrequester.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00042 layout->addWidget( m_sampleLabel, 1 );
00043 layout->addWidget( m_button );
00044
00045 connect( m_button, SIGNAL( clicked() ), SLOT( buttonClicked() ) );
00046
00047 displaySampleText();
00048 setToolTip();
00049 }
00050
00051 void KFontRequester::setFont( const QFont &font, bool onlyFixed )
00052 {
00053 m_selFont = font;
00054 m_onlyFixed = onlyFixed;
00055
00056 displaySampleText();
00057 emit fontSelected( m_selFont );
00058 }
00059
00060 void KFontRequester::setSampleText( const QString &text )
00061 {
00062 m_sampleText = text;
00063 displaySampleText();
00064 }
00065
00066 void KFontRequester::setTitle( const QString &title )
00067 {
00068 m_title = title;
00069 setToolTip();
00070 }
00071
00072 void KFontRequester::buttonClicked()
00073 {
00074 int result = KFontDialog::getFont( m_selFont, m_onlyFixed, parentWidget() );
00075
00076 if ( result == KDialog::Accepted )
00077 {
00078 displaySampleText();
00079 emit fontSelected( m_selFont );
00080 }
00081 }
00082
00083 void KFontRequester::displaySampleText()
00084 {
00085 m_sampleLabel->setFont( m_selFont );
00086
00087 int size = m_selFont.pointSize();
00088 if(size == -1)
00089 size = m_selFont.pixelSize();
00090
00091 if ( m_sampleText.isEmpty() )
00092 m_sampleLabel->setText( QString( "%1 %2" ).arg( m_selFont.family() )
00093 .arg( size ) );
00094 else
00095 m_sampleLabel->setText( m_sampleText );
00096 }
00097
00098 void KFontRequester::setToolTip()
00099 {
00100 QToolTip::remove( m_button );
00101 QToolTip::add( m_button, i18n( "Click to select a font" ) );
00102
00103 QToolTip::remove( m_sampleLabel );
00104 QWhatsThis::remove( m_sampleLabel );
00105
00106 if ( m_title.isNull() )
00107 {
00108 QToolTip::add( m_sampleLabel, i18n( "Preview of the selected font" ) );
00109 QWhatsThis::add( m_sampleLabel,
00110 i18n( "This is a preview of the selected font. You can change it"
00111 " by clicking the \"Choose...\" button." ) );
00112 }
00113 else
00114 {
00115 QToolTip::add( m_sampleLabel,
00116 i18n( "Preview of the \"%1\" font" ).arg( m_title ) );
00117 QWhatsThis::add( m_sampleLabel,
00118 i18n( "This is a preview of the \"%1\" font. You can change it"
00119 " by clicking the \"Choose...\" button." ).arg( m_title ) );
00120 }
00121 }
00122
00123 #include "kfontrequester.moc"
00124
00125
00126
This file is part of the documentation for kdeui Library Version 3.2.3.