⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kkeydialog.cpp

📁 PIXIL is a small footprint operating environment, complete with PDA PIM applications, a browser and
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* This file is part of the KDE libraries    Copyright (C) 1998 Mark Donohoe <donohoe@kde.org>    Copyright (C) 1997 Nicolas Hadacek <hadacek@via.ecp.fr>    Copyright (C) 1998 Matthias Ettrich <ettrich@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., 59 Temple Place - Suite 330,    Boston, MA 02111-1307, USA.*/#include <qkeycode.h>#include <qlayout.h>#include <qpainter.h>#include <qapplication.h>#include <qdrawutil.h>#include <qmessagebox.h>#include <qradiobutton.h>#include <kapp.h>#include <kbuttonbox.h>#include "kkeydialog.h"#include "kkeydialog.h"/*****************************************************************************//* KSplitListItem                                                            *//*                                                                           *//* Added by Mark Donohoe <donohoe@kde.org>                                   *//*                                                                           *//*****************************************************************************/KSplitListItem::KSplitListItem( const char *s, int _id )	:  QListBoxItem(){	id = _id;	setText( s );		QString str( s );	int i = str.find( ":" );		actionName = str.left( i );	actionName.simplifyWhiteSpace();		str.remove( 0, i+1 );		keyName = str.simplifyWhiteSpace();		halfWidth = 0;}void KSplitListItem::setWidth( int newWidth ){	halfWidth = newWidth/2;}void KSplitListItem::paint( QPainter *p ){    QFontMetrics fm = p->fontMetrics();    int yPos;                       // vertical text position    yPos = fm.ascent() + fm.leading()/2;    p->drawText( 5, yPos, actionName );	p->drawText( 5 + halfWidth, yPos, keyName );}int KSplitListItem::height(const QListBox *lb ) const{    return lb->fontMetrics().lineSpacing() + 1;}int KSplitListItem::width(const QListBox *lb ) const{    return lb->fontMetrics().width( text() ) + 6;}/*****************************************************************************//* KSplitList                                                                 *//*                                                                           *//* Added by Mark Donohoe <donohoe@kde.org>                                   *//*                                                                           *//*****************************************************************************/KSplitList::KSplitList( QWidget *parent , const char *name )	: QListBox( parent, name ){	setFocusPolicy( QWidget::StrongFocus );	if( style() == MotifStyle )		setFrameStyle( QFrame::Panel | QFrame::Sunken );	else		setFrameStyle( QFrame::WinPanel | QFrame::Sunken );	selectColor = KApplication::getKApplication()->selectColor;	selectTextColor = KApplication::getKApplication()->selectTextColor;}void KSplitList::resizeEvent( QResizeEvent *e ){	emit newWidth( width() );	QListBox::resizeEvent( e );}void KSplitList::styleChange( GUIStyle ){	if( style() == MotifStyle )		setFrameStyle( QFrame::Panel | QFrame::Sunken );	else		setFrameStyle( QFrame::WinPanel | QFrame::Sunken );}void KSplitList::paletteChange ( const QPalette & oldPalette ){	selectColor = KApplication::getKApplication()->selectColor;	selectTextColor = KApplication::getKApplication()->selectTextColor;	QListBox::paletteChange( oldPalette );	}/*****************************************************************************//* KKeyButton                                                                 *//*                                                                           *//* Added by Mark Donohoe <donohoe@kde.org>                                   *//*                                                                           *//*****************************************************************************/KKeyButton::KKeyButton( const char* name, QWidget *parent)	: QPushButton( parent, name ){    setFocusPolicy( QWidget::StrongFocus );	editing = FALSE;}KKeyButton::~KKeyButton (){}void KKeyButton::setText( QString text ){	QPushButton::setText( text );	setFixedSize( sizeHint().width()+12, sizeHint().height()+8 );}void KKeyButton::setEdit( bool edit ){	editing = edit;	repaint();}void KKeyButton::paint( QPainter *painter ){	QPointArray a( 4 );	a.setPoint( 0, 0, 0) ;	a.setPoint( 1, width(), 0 );	a.setPoint( 2, 0, height() );	a.setPoint( 3, 0, 0 );	QRegion r1( a );	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() );	QRegion r2( a );	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,								colorGroup(), TRUE, 1, 0L );	if ( editing ) {		painter->setPen( colorGroup().base() );		painter->setBrush( colorGroup().base() );	} else {		painter->setPen( backgroundColor() );		painter->setBrush( backgroundColor() );	}	if( width() > 14 && height() > 10 )	painter->drawRect( 7, 5, width() - 14, height() - 10 );	drawButtonLabel( painter );		painter->setPen( colorGroup().text() );	painter->setBrush( NoBrush );	if( hasFocus() || editing ) {		if( width() > 16 && height() > 12 )		painter->drawRect( 8, 6, width() - 16, height() - 12 );	}	}/*****************************************************************************//* KKeyDialog                                                     *//*                                                                           *//* Originally by Nicolas Hadacek <hadacek@via.ecp.fr>                        *//*                                                                           *//* Substantially revised by Mark Donohoe <donohoe@kde.org>                   *//*                                                                           *//*****************************************************************************/KKeyDialog::KKeyDialog( QDict<KKeyEntry> *aKeyDict, QWidget *parent,			bool check_against_std_keys)    : QDialog( parent, 0, TRUE ){	setCaption( i18n("Configure key bindings") );	setFocusPolicy( QWidget::StrongFocus );		QBoxLayout *topLayout = new QVBoxLayout( this, 10 );		KKeyChooser *kc =  new KKeyChooser( aKeyDict, this, check_against_std_keys );		topLayout->addWidget( kc, 10 );		// CREATE BUTTONS		KButtonBox *bbox = new KButtonBox( this );		bHelp = bbox->addButton( i18n("&Help") );	//connect( bHelp, SIGNAL(clicked()), SLOT(help()) );	bHelp->setEnabled( false );		bDefaults = bbox->addButton( i18n("&Defaults") );	connect( bDefaults, SIGNAL(clicked()), kc, SLOT(allDefault()) );	//bDefaults->setEnabled( false );		bbox->addStretch( 10 );			bOk = bbox->addButton( i18n("&OK") );	connect( bOk, SIGNAL(clicked()), SLOT(accept()) );		bCancel = bbox->addButton( i18n("&Cancel") );	connect( bCancel, SIGNAL(clicked()), SLOT(reject()) );			bbox->layout();	topLayout->addWidget( bbox );		topLayout->activate();		resize( 400, 350 );}int KKeyDialog::configureKeys( KAccel *keys, bool save_settings ){	QDict<KKeyEntry> dict = keys->keyDict();    KKeyDialog *kd = new KKeyDialog( &dict );    CHECK_PTR( kd );	int retcode = kd->exec();    delete kd;	if( retcode ) {		keys->setKeyDict( dict );		if (save_settings)		  keys->writeSettings();	}    return retcode;}int KKeyDialog::configureKeys( KGlobalAccel *keys, bool save_settings ){	QDict<KKeyEntry> dict = keys->keyDict();    KKeyDialog *kd = new KKeyDialog( &dict );    CHECK_PTR( kd );	int retcode = kd->exec();    delete kd;	if( retcode ) {		keys->setKeyDict( dict );		if (save_settings)		  keys->writeSettings();	}    return retcode;}KKeyChooser::KKeyChooser( QDict<KKeyEntry> *aKeyDict, QWidget *parent ,			  bool check_against_std_keys)    : QWidget( parent ){		bKeyIntercept = FALSE;	kbMode = NoKey;		aKeyIt = new QDictIterator<KKeyEntry> ( *aKeyDict );		// TOP LAYOUT MANAGER		// The following layout is used for the dialog	// 		LIST LABELS LAYOUT	//		SPLIT LIST BOX WIDGET	//		CHOOSE KEY GROUP BOX WIDGET	//		BUTTONS LAYOUT	// Items are added to topLayout as they are created.		QBoxLayout *topLayout = new QVBoxLayout( this, 0, 10 );		// CREATE LIST LABELS		QGridLayout *stackLayout = new QGridLayout( 2, 2, 2);	topLayout->addLayout( stackLayout, 50 );		stackLayout->setRowStretch(1,10);	keyLabel = new QLabel(this);	stackLayout->addWidget(keyLabel, 0, 1);	keyLabel->setText( i18n("Current key") );	keyLabel->setFixedHeight( keyLabel->sizeHint().height() );		// CREATE SPLIT LIST BOX		// Copy all currentKeyCodes to configKeyCodes	// and fill up the split list box with the action/key pairs.		wList = new KSplitList( this );	wList->setMinimumHeight(80);	stackLayout->addMultiCellWidget( wList, 1, 1, 0, 1 );		actLabel = new QLabel( wList, i18n("&Action"), this );	stackLayout->addWidget( actLabel, 0, 0 );	actLabel->setFixedHeight( actLabel->sizeHint().height() );		wList->setAutoUpdate(FALSE);	wList->setFocus();		aIt = aKeyIt;	aIt->toFirst();	int id = 0;	while ( aIt->current() ) {		aIt->current()->aConfigKeyCode = aIt->current()->aCurrentKeyCode;				KSplitListItem *sli = new KSplitListItem(		 	item( aIt->current()->aConfigKeyCode, aIt->current()->descr ),			id);				connect( wList, SIGNAL( newWidth( int ) ),				 sli, SLOT( setWidth( int ) ) );		wList->inSort( sli );				++ ( *aIt );		++id;	}	if ( wList->count() == 0 ) wList->setEnabled( FALSE );	//connect( wList, SIGNAL( selected( int ) ), SLOT( toChange( int ) ) );	connect( wList, SIGNAL( highlighted( int ) ), SLOT( updateAction( int ) ) );		// CREATE CHOOSE KEY GROUP		fCArea = new QGroupBox( this );	topLayout->addWidget( fCArea, 1 );		fCArea->setTitle( i18n("Choose a key for the selected action") );	fCArea->setFrameStyle( QFrame::Box | QFrame::Sunken );		// CHOOSE KEY GROUP LAYOUT MANAGER		QGridLayout *grid = new QGridLayout( fCArea, 6, 4, 5 );		grid->setRowStretch(0,10);	grid->setRowStretch(1,10);	grid->setRowStretch(2,10);	grid->setRowStretch(3,10);	grid->setRowStretch(4,10);	grid->setRowStretch(5,10);	grid->setColStretch(0,0);	grid->setColStretch(1,10);	grid->setColStretch(2,90);	grid->setColStretch(3,0);		grid->addRowSpacing(0,15);	grid->addRowSpacing(5,1);			kbGroup = new QButtonGroup( fCArea );    kbGroup->hide();    kbGroup->setExclusive( true );		QRadioButton *rb = new QRadioButton( i18n("&No key"), fCArea );    rb->adjustSize();    rb->setFixedHeight( rb->height() );    rb->setMinimumWidth( rb->width() );    kbGroup->insert( rb, NoKey );		grid->addMultiCellWidget( rb, 1, 1, 1, 2 );		rb = new QRadioButton( i18n("&Default key"), fCArea );    rb->adjustSize();    rb->setFixedHeight( rb->height() );    rb->setMinimumWidth( rb->width() );    kbGroup->insert( rb, DefaultKey );		grid->addMultiCellWidget( rb, 2, 2, 1, 2 );		rb = new QRadioButton( i18n("&Custom key"), fCArea );    rb->adjustSize();    rb->setFixedHeight( rb->height() );    rb->setMinimumWidth( rb->width() );    kbGroup->insert( rb, CustomKey );		connect( kbGroup, SIGNAL( clicked( int ) ), SLOT( keyMode( int ) ) );		grid->addMultiCellWidget( rb, 3, 3, 1, 2 );		QBoxLayout *pushLayout = new QHBoxLayout( 2 );	grid->addLayout( pushLayout, 4, 2 );		cShift = new QCheckBox( fCArea );	cShift->setText( "SHIFT" );	cShift->setEnabled( FALSE );	connect( cShift, SIGNAL( clicked() ), SLOT( shiftClicked() ) );		cCtrl = new QCheckBox( fCArea );	cCtrl->setText( "CTRL" );	cCtrl->setEnabled( FALSE );	connect( cCtrl, SIGNAL( clicked() ), SLOT( ctrlClicked() ) );		cAlt = new QCheckBox( fCArea );	cAlt->setText( "ALT" );	cAlt->setEnabled( FALSE );	connect( cAlt, SIGNAL( clicked() ), SLOT( altClicked() ) );		bChange = new KKeyButton("key", fCArea);	bChange->setEnabled( FALSE );	connect( bChange, SIGNAL( clicked() ), SLOT( changeKey() ) );		// Set height of checkboxes to basic key button height.	// Basic key button height = push button height.	cAlt->adjustSize();	cAlt->setFixedHeight( bChange->sizeHint().height() );	cAlt->setMinimumWidth( cAlt->width() );	cShift->adjustSize();	cShift->setFixedHeight( bChange->sizeHint().height() );	cShift->setMinimumWidth( cShift->width() );	cCtrl->adjustSize();	cCtrl->setFixedHeight( bChange->sizeHint().height() );	cCtrl->setMinimumWidth( cCtrl->width() );	fCArea->setMinimumHeight( bChange->sizeHint().height() + 20 +		3*rb->height() + 4*10);		// Add widgets to the geometry manager		pushLayout->addWidget( cShift );	pushLayout->addSpacing( 8 );	pushLayout->addWidget( cCtrl );	pushLayout->addSpacing( 8 );	pushLayout->addWidget( cAlt );	pushLayout->addSpacing( 18 );	pushLayout->addWidget( bChange );	pushLayout->addStretch( 10 );		lNotConfig = new QLabel(fCArea);	lNotConfig->resize(0,0);	lNotConfig->setFont( QFont("Helvetica", 14, QFont::Bold) );	lNotConfig->setAlignment( AlignCenter );	lNotConfig->setFrameStyle( QFrame::Panel | QFrame::Sunken );	if ( wList->count()==0 )		lNotConfig->setText( i18n("No keys defined") );	else {		lNotConfig->setText( i18n("Not configurable") );		lNotConfig->hide();	}	lNotConfig->hide();	lInfo = new QLabel(fCArea);	resize(0,0);	lInfo->setAlignment( AlignCenter );	lInfo->setEnabled( FALSE );	lInfo->hide();		wList->setAutoUpdate(TRUE);	wList->update();		globalDict = new QDict<int> ( 100, false );	globalDict->setAutoDelete( true );	readGlobalKeys();	stdDict = new QDict<int> ( 100, false );	stdDict->setAutoDelete( true );	if (check_against_std_keys)	  readStdKeys();	wList->setCurrentItem( 0 );	topLayout->activate();}KKeyChooser::~KKeyChooser(){}void KKeyChooser::updateAction( int index ){	aIt->toFirst();		(*aIt) += wList->getId(index);	sEntryKey = aIt->currentKey();	pEntry = aIt->current();		if ( pEntry->aConfigKeyCode == 0 )		kbMode = NoKey;	else if ( pEntry->aConfigKeyCode == pEntry->aDefaultKeyCode )		kbMode = DefaultKey;	else kbMode = CustomKey;	toChange( index );}void KKeyChooser::readGlobalKeys(){	//debug("KKeyChooser::readGlobalKeys()");		globalDict->clear();			// Insert all global keys into globalDict	int *keyCode;	KConfig pConfig;	KEntryIterator *gIt = pConfig.entryIterator( i18n("Global Keys") );	if (gIt){	  gIt->toFirst();	  while ( gIt->current() ) {	    keyCode = new int;	    *keyCode = stringToKey( gIt->current()->aValue );	    globalDict->insert( gIt->currentKey(), keyCode);	    ++(*gIt);	  }	}		// Only insert global keys which don't appear in the dictionary to be configured	aIt->toFirst();	while ( aIt->current() ) {		if ( globalDict->find( aIt->currentKey() ) ) {		  globalDict->remove( aIt->currentKey());		}		++ ( *aIt );	}	}void KKeyChooser::readStdKeys()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -