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 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
00127