| # kdeui Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kkeybutton.cpp

    00001 /* This file is part of the KDE libraries
    00002     Copyright (C) 1998 Mark Donohoe <donohoe@kde.org>
    00003     Copyright (C) 2001 Ellis Whitehead <ellis@kde.org>
    00004
    00005     This library is free software; you can redistribute it and/or
    00006     modify it under the terms of the GNU Library General Public
    00007     License as published by the Free Software Foundation; either
    00008     version 2 of the License, or (at your option) any later version.
    00009
    00010     This library is distributed in the hope that it will be useful,
    00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013     Library General Public License for more details.
    00014
    00015     You should have received a copy of the GNU Library General Public License
    00016     along with this library; see the file COPYING.LIB.  If not, write to
    00017     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00018     Boston, MA 02111-1307, USA.
    00019 */
    00020
    00021 #include "kkeybutton.h"
    00022 #include "kshortcutdialog.h"
    00023
    00024 #include <qcursor.h>
    00025 #include <qdrawutil.h>
    00026 #include <qpainter.h>
    00027 #include <kapplication.h>
    00028 #include <kdebug.h>
    00029 #include <kglobalaccel.h>
    00030 #include <klocale.h>
    00031
    00032 #include "config.h"
    00033 #ifdef Q_WS_X11
    00034 #define XK_XKB_KEYS
    00035 #define XK_MISCELLANY
    00036 #include <X11/Xlib.h>   // For x11Event()
    00037 #include <X11/keysymdef.h> // For XK_...
    00038
    00039 #ifdef KeyPress
    00040 const int XFocusOut = FocusOut;
    00041 const int XFocusIn = FocusIn;
    00042 const int XKeyPress = KeyPress;
    00043 const int XKeyRelease = KeyRelease;
    00044 #undef KeyRelease
    00045 #undef KeyPress
    00046 #undef FocusOut
    00047 #undef FocusIn
    00048 #endif // KeyPress
    00049 #endif // Q_WS_X11
    00050
    00051 //static const char* psTemp[] = {
    00052 //  I18N_NOOP("Primary"), I18N_NOOP("Alternate"), I18N_NOOP("Multi-Key")
    00053 //};
    00054
    00055 class KKeyButtonPrivate
    00056 {
    00057  public:
    00058     bool bQtShortcut;
    00059 };
    00060
    00061 /***********************************************************************/
    00062 /* KKeyButton                                                          */
    00063 /*                                                                     */
    00064 /* Initially added by Mark Donohoe <donohoe@kde.org>                   */
    00065 /*                                                                     */
    00066 /***********************************************************************/
    00067
    00068 KKeyButton::KKeyButton(QWidget *parent, const char *name)
    00069 :   QPushButton( parent, name )
    00070 {
    00071     d = new KKeyButtonPrivate;
    00072     setFocusPolicy( QWidget::StrongFocus );
    00073     m_bEditing = false;
    00074     connect( this, SIGNAL(clicked()), this, SLOT(captureShortcut()) );
    00075     setShortcut( KShortcut(), true );
    00076 }
    00077
    00078 KKeyButton::~KKeyButton ()
    00079 {
    00080     delete d;
    00081 }
    00082
    00083 void KKeyButton::setShortcut( const KShortcut& cut, bool bQtShortcut )
    00084 {
    00085     d->bQtShortcut = bQtShortcut;
    00086     m_cut = cut;
    00087     QString keyStr = m_cut.toString();
    00088     keyStr.replace('&', QString::fromLatin1("&&"));
    00089     setText( keyStr.isEmpty() ? i18n("None") : keyStr );
    00090 }
    00091
    00092 // deprecated //
    00093 void KKeyButton::setShortcut( const KShortcut& cut )
    00094 {
    00095     setShortcut( cut, false );
    00096 }
    00097
    00098 void KKeyButton::setText( const QString& text )
    00099 {
    00100     QPushButton::setText( text );
    00101     setFixedSize( sizeHint().width()+12, sizeHint().height()+8 );
    00102 }
    00103
    00104 void KKeyButton::captureShortcut()
    00105 {
    00106     KShortcut cut;
    00107
    00108     m_bEditing = true;
    00109     repaint();
    00110
    00111         {
    00112     KShortcutDialog dlg( m_cut, d->bQtShortcut, this );
    00113     if( dlg.exec() == KDialog::Accepted )
    00114                 cut = dlg.shortcut();
    00115         } // emit the signal after the dialog is destroyed, otherwise it still has grab
    00116         if( !cut.isNull())
    00117         emit capturedShortcut( cut );
    00118
    00119     m_bEditing = false;
    00120     repaint();
    00121 }
    00122
    00123 void KKeyButton::drawButton( QPainter *painter )
    00124 {
    00125   QPointArray a( 4 );
    00126   a.setPoint( 0, 0, 0) ;
    00127   a.setPoint( 1, width(), 0 );
    00128   a.setPoint( 2, 0, height() );
    00129   a.setPoint( 3, 0, 0 );
    00130
    00131   QRegion r1( a );
    00132   painter->setClipRegion( r1 );
    00133   painter->setBrush( backgroundColor().light() );
    00134   painter->drawRoundRect( 0, 0, width(), height(), 20, 20);
    00135
    00136   a.setPoint( 0, width(), height() );
    00137   a.setPoint( 1, width(), 0 );
    00138   a.setPoint( 2, 0, height() );
    00139   a.setPoint( 3, width(), height() );
    00140
    00141   QRegion r2( a );
    00142   painter->setClipRegion( r2 );
    00143   painter->setBrush( backgroundColor().dark() );
    00144   painter->drawRoundRect( 0, 0, width(), height(), 20, 20 );
    00145
    00146   painter->setClipping( false );
    00147   if( width() > 12 && height() > 8 )
    00148     qDrawShadePanel( painter, 6, 4, width() - 12, height() - 8,
    00149                      colorGroup(), true, 1, 0L );
    00150   if ( m_bEditing )
    00151   {
    00152     painter->setPen( colorGroup().base() );
    00153     painter->setBrush( colorGroup().base() );
    00154   }
    00155   else
    00156   {
    00157     painter->setPen( backgroundColor() );
    00158     painter->setBrush( backgroundColor() );
    00159   }
    00160   if( width() > 14 && height() > 10 )
    00161     painter->drawRect( 7, 5, width() - 14, height() - 10 );
    00162
    00163   drawButtonLabel( painter );
    00164
    00165   painter->setPen( colorGroup().text() );
    00166   painter->setBrush( NoBrush );
    00167   if( hasFocus() || m_bEditing )
    00168   {
    00169     if( width() > 16 && height() > 12 )
    00170       painter->drawRect( 8, 6, width() - 16, height() - 12 );
    00171   }
    00172
    00173 }
    00174
    00175 void KKeyButton::virtual_hook( int, void* )
    00176 { /*BASE::virtual_hook( id, data );*/ }
    00177
    00178 #include "kkeybutton.moc"

This file is part of the documentation for kdeui Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:20:17 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003