kdeui Library API Documentation

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 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 /* vim: et sw=2 ts=2 00126 */
KDE Logo
This file is part of the documentation for kdeui Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Sep 29 09:40:33 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003