• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

tdefontrequester.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., 51 Franklin Street, Fifth Floor,
00017     Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "tdefontrequester.h"
00021 
00022 #include <tqlabel.h>
00023 #include <tqpushbutton.h>
00024 #include <tqlayout.h>
00025 #include <tqtooltip.h>
00026 #include <tqwhatsthis.h>
00027 
00028 #include <tdefontdialog.h>
00029 #include <tdelocale.h>
00030 
00031 TDEFontRequester::TDEFontRequester( TQWidget *parent, const char *name,
00032     bool onlyFixed ) : TQWidget( parent, name ),
00033     m_onlyFixed( onlyFixed )
00034 {
00035   TQHBoxLayout *layout = new TQHBoxLayout( this, 0, KDialog::spacingHint() );
00036 
00037   m_sampleLabel = new TQLabel( this, "m_sampleLabel" );
00038   m_button = new TQPushButton( i18n( "Choose..." ), this, "m_button" );
00039 
00040   m_sampleLabel->setFrameStyle( TQFrame::StyledPanel | TQFrame::Sunken );
00041   setFocusProxy( m_button );
00042 
00043   layout->addWidget( m_sampleLabel, 1 );
00044   layout->addWidget( m_button );
00045 
00046   connect( m_button, TQT_SIGNAL( clicked() ), TQT_SLOT( buttonClicked() ) );
00047 
00048   displaySampleText();
00049   setToolTip();
00050 }
00051 
00052 void TDEFontRequester::setFont( const TQFont &font, bool onlyFixed )
00053 {
00054   m_selFont = font;
00055   m_onlyFixed = onlyFixed;
00056 
00057   displaySampleText();
00058   emit fontSelected( m_selFont );
00059 }
00060 
00061 void TDEFontRequester::setSampleText( const TQString &text )
00062 {
00063   m_sampleText = text;
00064   displaySampleText();
00065 }
00066 
00067 void TDEFontRequester::setTitle( const TQString &title )
00068 {
00069   m_title = title;
00070   setToolTip();
00071 }
00072 
00073 void TDEFontRequester::buttonClicked()
00074 {
00075   int result = TDEFontDialog::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 TDEFontRequester::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( TQString( "%1 %2" ).arg( m_selFont.family() )
00094       .arg( size ) );
00095   else
00096     m_sampleLabel->setText( m_sampleText );
00097 }
00098 
00099 void TDEFontRequester::setToolTip()
00100 {
00101   TQToolTip::remove( m_button );
00102   TQToolTip::add( m_button, i18n( "Click to select a font" ) );
00103 
00104   TQToolTip::remove( m_sampleLabel );
00105   TQWhatsThis::remove( m_sampleLabel );
00106 
00107   if ( m_title.isNull() )
00108   {
00109     TQToolTip::add( m_sampleLabel, i18n( "Preview of the selected font" ) );
00110     TQWhatsThis::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     TQToolTip::add( m_sampleLabel, 
00117         i18n( "Preview of the \"%1\" font" ).arg( m_title ) );
00118     TQWhatsThis::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 "tdefontrequester.moc"
00125 
00126 /* vim: et sw=2 ts=2
00127 */

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.