You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
179 lines
4.9 KiB
179 lines
4.9 KiB
15 years ago
|
/* This file is part of the KDE libraries
|
||
|
Copyright (C) 1998 Mark Donohoe <donohoe@kde.org>
|
||
|
Copyright (C) 2001 Ellis Whitehead <ellis@kde.org>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include "kkeybutton.h"
|
||
|
#include "kshortcutdialog.h"
|
||
|
|
||
15 years ago
|
#include <tqcursor.h>
|
||
|
#include <tqdrawutil.h>
|
||
|
#include <tqpainter.h>
|
||
15 years ago
|
#include <kapplication.h>
|
||
|
#include <kdebug.h>
|
||
|
#include <kglobalaccel.h>
|
||
|
#include <klocale.h>
|
||
|
|
||
|
#include "config.h"
|
||
|
#ifdef Q_WS_X11
|
||
|
#define XK_XKB_KEYS
|
||
|
#define XK_MISCELLANY
|
||
|
#include <X11/Xlib.h> // For x11Event()
|
||
|
#include <X11/keysymdef.h> // For XK_...
|
||
|
|
||
|
#ifdef KeyPress
|
||
|
const int XFocusOut = FocusOut;
|
||
|
const int XFocusIn = FocusIn;
|
||
|
const int XKeyPress = KeyPress;
|
||
|
const int XKeyRelease = KeyRelease;
|
||
|
#undef KeyRelease
|
||
|
#undef KeyPress
|
||
|
#undef FocusOut
|
||
|
#undef FocusIn
|
||
|
#endif // KeyPress
|
||
|
#endif // Q_WS_X11
|
||
|
|
||
|
//static const char* psTemp[] = {
|
||
|
// I18N_NOOP("Primary"), I18N_NOOP("Alternate"), I18N_NOOP("Multi-Key")
|
||
|
//};
|
||
|
|
||
|
class KKeyButtonPrivate
|
||
|
{
|
||
|
public:
|
||
|
bool bQtShortcut;
|
||
|
};
|
||
|
|
||
|
/***********************************************************************/
|
||
|
/* KKeyButton */
|
||
|
/* */
|
||
|
/* Initially added by Mark Donohoe <donohoe@kde.org> */
|
||
|
/* */
|
||
|
/***********************************************************************/
|
||
|
|
||
15 years ago
|
KKeyButton::KKeyButton(TQWidget *parent, const char *name)
|
||
|
: TQPushButton( parent, name )
|
||
15 years ago
|
{
|
||
|
d = new KKeyButtonPrivate;
|
||
14 years ago
|
setFocusPolicy( TQ_StrongFocus );
|
||
15 years ago
|
m_bEditing = false;
|
||
15 years ago
|
connect( this, TQT_SIGNAL(clicked()), this, TQT_SLOT(captureShortcut()) );
|
||
15 years ago
|
setShortcut( KShortcut(), true );
|
||
|
}
|
||
|
|
||
|
KKeyButton::~KKeyButton ()
|
||
|
{
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
|
void KKeyButton::setShortcut( const KShortcut& cut, bool bQtShortcut )
|
||
|
{
|
||
|
d->bQtShortcut = bQtShortcut;
|
||
|
m_cut = cut;
|
||
15 years ago
|
TQString keyStr = m_cut.toString();
|
||
14 years ago
|
keyStr.replace('&', TQString::tqfromLatin1("&&"));
|
||
15 years ago
|
setText( keyStr.isEmpty() ? i18n("None") : keyStr );
|
||
|
}
|
||
|
|
||
|
// deprecated //
|
||
|
void KKeyButton::setShortcut( const KShortcut& cut )
|
||
|
{
|
||
|
setShortcut( cut, false );
|
||
|
}
|
||
|
|
||
15 years ago
|
void KKeyButton::setText( const TQString& text )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQPushButton::setText( text );
|
||
14 years ago
|
setFixedSize( tqsizeHint().width()+12, tqsizeHint().height()+8 );
|
||
15 years ago
|
}
|
||
|
|
||
|
void KKeyButton::captureShortcut()
|
||
|
{
|
||
|
KShortcut cut;
|
||
|
|
||
|
m_bEditing = true;
|
||
14 years ago
|
tqrepaint();
|
||
15 years ago
|
|
||
|
{
|
||
|
KShortcutDialog dlg( m_cut, d->bQtShortcut, this );
|
||
|
if( dlg.exec() == KDialog::Accepted )
|
||
|
cut = dlg.shortcut();
|
||
|
} // emit the signal after the dialog is destroyed, otherwise it still has grab
|
||
|
if( !cut.isNull())
|
||
|
emit capturedShortcut( cut );
|
||
|
|
||
|
m_bEditing = false;
|
||
14 years ago
|
tqrepaint();
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void KKeyButton::drawButton( TQPainter *painter )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQPointArray a( 4 );
|
||
15 years ago
|
a.setPoint( 0, 0, 0) ;
|
||
|
a.setPoint( 1, width(), 0 );
|
||
|
a.setPoint( 2, 0, height() );
|
||
|
a.setPoint( 3, 0, 0 );
|
||
|
|
||
15 years ago
|
TQRegion r1( a );
|
||
15 years ago
|
painter->setClipRegion( r1 );
|
||
|
painter->setBrush( backgroundColor().light() );
|
||
|
painter->drawRoundRect( 0, 0, width(), height(), 20, 20);
|
||
|
|
||
|
a.setPoint( 0, width(), height() );
|
||
|
a.setPoint( 1, width(), 0 );
|
||
|
a.setPoint( 2, 0, height() );
|
||
|
a.setPoint( 3, width(), height() );
|
||
|
|
||
15 years ago
|
TQRegion r2( a );
|
||
15 years ago
|
painter->setClipRegion( r2 );
|
||
|
painter->setBrush( backgroundColor().dark() );
|
||
|
painter->drawRoundRect( 0, 0, width(), height(), 20, 20 );
|
||
|
|
||
|
painter->setClipping( false );
|
||
|
if( width() > 12 && height() > 8 )
|
||
|
qDrawShadePanel( painter, 6, 4, width() - 12, height() - 8,
|
||
14 years ago
|
tqcolorGroup(), true, 1, 0L );
|
||
15 years ago
|
if ( m_bEditing )
|
||
|
{
|
||
14 years ago
|
painter->setPen( tqcolorGroup().base() );
|
||
|
painter->setBrush( tqcolorGroup().base() );
|
||
15 years ago
|
}
|
||
|
else
|
||
|
{
|
||
|
painter->setPen( backgroundColor() );
|
||
|
painter->setBrush( backgroundColor() );
|
||
|
}
|
||
|
if( width() > 14 && height() > 10 )
|
||
|
painter->drawRect( 7, 5, width() - 14, height() - 10 );
|
||
|
|
||
|
drawButtonLabel( painter );
|
||
|
|
||
14 years ago
|
painter->setPen( tqcolorGroup().text() );
|
||
15 years ago
|
painter->setBrush( NoBrush );
|
||
|
if( hasFocus() || m_bEditing )
|
||
|
{
|
||
|
if( width() > 16 && height() > 12 )
|
||
|
painter->drawRect( 8, 6, width() - 16, height() - 12 );
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
void KKeyButton::virtual_hook( int, void* )
|
||
|
{ /*BASE::virtual_hook( id, data );*/ }
|
||
|
|
||
|
#include "kkeybutton.moc"
|