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

tdeui

  • tdeui
tdefontrequester.cpp
1 /*
2  Copyright (C) 2003 Nadeem Hasan <nhasan@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "tdefontrequester.h"
21 
22 #include <tqlabel.h>
23 #include <tqpushbutton.h>
24 #include <tqlayout.h>
25 #include <tqtooltip.h>
26 #include <tqwhatsthis.h>
27 
28 #include <tdefontdialog.h>
29 #include <tdelocale.h>
30 
31 TDEFontRequester::TDEFontRequester( TQWidget *parent, const char *name,
32  bool onlyFixed ) : TQWidget( parent, name ),
33  m_onlyFixed( onlyFixed )
34 {
35  TQHBoxLayout *layout = new TQHBoxLayout( this, 0, KDialog::spacingHint() );
36 
37  m_sampleLabel = new TQLabel( this, "m_sampleLabel" );
38  m_button = new TQPushButton( i18n( "Choose..." ), this, "m_button" );
39 
40  m_sampleLabel->setFrameStyle( TQFrame::StyledPanel | TQFrame::Sunken );
41  setFocusProxy( m_button );
42 
43  layout->addWidget( m_sampleLabel, 1 );
44  layout->addWidget( m_button );
45 
46  connect( m_button, TQ_SIGNAL( clicked() ), TQ_SLOT( buttonClicked() ) );
47 
48  displaySampleText();
49  setToolTip();
50 }
51 
52 void TDEFontRequester::setFont( const TQFont &font, bool onlyFixed )
53 {
54  m_selFont = font;
55  m_onlyFixed = onlyFixed;
56 
57  displaySampleText();
58  emit fontSelected( m_selFont );
59 }
60 
61 void TDEFontRequester::setSampleText( const TQString &text )
62 {
63  m_sampleText = text;
64  displaySampleText();
65 }
66 
67 void TDEFontRequester::setTitle( const TQString &title )
68 {
69  m_title = title;
70  setToolTip();
71 }
72 
73 void TDEFontRequester::buttonClicked()
74 {
75  int result = TDEFontDialog::getFont( m_selFont, m_onlyFixed, parentWidget() );
76 
77  if ( result == KDialog::Accepted )
78  {
79  displaySampleText();
80  emit fontSelected( m_selFont );
81  }
82 }
83 
84 void TDEFontRequester::displaySampleText()
85 {
86  m_sampleLabel->setFont( m_selFont );
87 
88  int size = m_selFont.pointSize();
89  if(size == -1)
90  size = m_selFont.pixelSize();
91 
92  if ( m_sampleText.isEmpty() )
93  m_sampleLabel->setText( TQString( "%1 %2" ).arg( m_selFont.family() )
94  .arg( size ) );
95  else
96  m_sampleLabel->setText( m_sampleText );
97 }
98 
99 void TDEFontRequester::setToolTip()
100 {
101  TQToolTip::remove( m_button );
102  TQToolTip::add( m_button, i18n( "Click to select a font" ) );
103 
104  TQToolTip::remove( m_sampleLabel );
105  TQWhatsThis::remove( m_sampleLabel );
106 
107  if ( m_title.isNull() )
108  {
109  TQToolTip::add( m_sampleLabel, i18n( "Preview of the selected font" ) );
110  TQWhatsThis::add( m_sampleLabel,
111  i18n( "This is a preview of the selected font. You can change it"
112  " by clicking the \"Choose...\" button." ) );
113  }
114  else
115  {
116  TQToolTip::add( m_sampleLabel,
117  i18n( "Preview of the \"%1\" font" ).arg( m_title ) );
118  TQWhatsThis::add( m_sampleLabel,
119  i18n( "This is a preview of the \"%1\" font. You can change it"
120  " by clicking the \"Choose...\" button." ).arg( m_title ) );
121  }
122 }
123 
124 #include "tdefontrequester.moc"
KDialog::spacingHint
static int spacingHint()
Return the number of pixels you shall use between widgets inside a dialog according to the KDE standa...
Definition: kdialog.cpp:110
TDEFontDialog::getFont
static int getFont(TQFont &theFont, bool onlyFixed=false, TQWidget *parent=0L, bool makeFrame=true, TQButton::ToggleState *sizeIsRelativeState=0L)
Creates a modal font dialog, lets the user choose a font, and returns when the dialog is closed.
Definition: tdefontdialog.cpp:798
TDEFontRequester::fontSelected
void fontSelected(const TQFont &font)
Emitted when a new font has been selected in the underlying dialog.
TDEFontRequester::title
TQString title() const
Definition: tdefontrequester.h:83
TDEFontRequester::setSampleText
virtual void setSampleText(const TQString &text)
Sets the sample text.
Definition: tdefontrequester.cpp:61
TDEFontRequester::setFont
virtual void setFont(const TQFont &font, bool onlyFixed=false)
Sets the currently selected font in the requester.
Definition: tdefontrequester.cpp:52
TDEFontRequester::TDEFontRequester
TDEFontRequester(TQWidget *parent=0L, const char *name=0L, bool onlyFixed=false)
Constructs a font requester widget.
Definition: tdefontrequester.cpp:31
TDEFontRequester::setTitle
virtual void setTitle(const TQString &title)
Set the title for the widget that will be used in the tooltip and what's this text.
Definition: tdefontrequester.cpp:67
TDEFontRequester::font
TQFont font() const
Definition: tdefontrequester.h:68
tdelocale.h

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.9.1
This website is maintained by Timothy Pearson.