Source Code (Use browser search to find items of interest.)
Class Index
kdelibs'KKeyDialog (./kdelibs/kdeui/kkeydialog.h:173)
class KKeyDialog : public KDialogBase
{
Q_OBJECT
public:
KKeyDialog( QDict<KKeyEntry>* aKeyDict, QWidget *parent = 0,
bool check_against_std_keys = false );
~KKeyDialog() {};
static int configureKeys( KAccel *keys, bool save_settings = true,
QWidget *parent = 0 );
static int configureKeys( KGlobalAccel *keys, bool save_settings = true,
QWidget *parent = 0 );
static int configureKeys( KActionCollection *coll, const QString& xmlfile,
bool save_settings = true, QWidget *parent = 0 );
private:
QPushButton* bDefaults;
QPushButton* bOk;
QPushButton* bCancel;
QPushButton* bHelp;
class KKeyDialogPrivate;
KKeyDialogPrivate *d;
};
/**
* Configure dictionaries of key/action associations for KAccel and
* KGlobalAccel.
*
* The class takes care of all aspects of configuration, including
* handling key conflicts internally. Connect to the @ref allDefault()
* slot if you want to set all configurable keybindings to their
* default values.
*
* @short Widget for configuration of @ref KAccel and @ref KGlobalAccel.
* @see KKeyDialog
* @version $Id: kkeydialog.h,v 1.19 2000/04/01 17:56:47 granroth Exp $
* @author Nicolas Hadacek <hadacek@via.ecp.fr>
*/
kdelibs'KKeyDialog::KKeyDialog() (./kdelibs/kdeui/kkeydialog.cpp:241)
KKeyDialog::KKeyDialog( QDict<KKeyEntry> *aKeyDict, QWidget *parent,
bool check_against_std_keys)
: KDialogBase( parent, 0, TRUE, i18n("Configure Key Bindings"),
Help|Default|Ok|Cancel, Ok )
{
KKeyChooser *kc = new KKeyChooser( aKeyDict, this, check_against_std_keys );
setMainWidget(kc);
connect( this, SIGNAL(defaultClicked()), kc, SLOT(allDefault()) );
enableButton ( Help, false );
}
kdelibs'KKeyDialog::configureKeys() (./kdelibs/kdeui/kkeydialog.cpp:254)
int KKeyDialog::configureKeys( KAccel *keys, bool save_settings,
QWidget *parent )
{
QDict<KKeyEntry> dict = keys->keyDict();
KKeyDialog *kd = new KKeyDialog( &dict, parent );
CHECK_PTR( kd );
int retcode = kd->exec();
delete kd;
if( retcode == Accepted )
{
keys->setKeyDict( dict );
if (save_settings)
keys->writeSettings();
}
return retcode;
}
kdelibs'KKeyDialog::configureKeys() (./kdelibs/kdeui/kkeydialog.cpp:272)
int KKeyDialog::configureKeys( KGlobalAccel *keys, bool save_settings,
QWidget *parent )
{
QDict<KKeyEntry> dict = keys->keyDict();
KKeyDialog *kd = new KKeyDialog( &dict, parent );
CHECK_PTR( kd );
int retcode = kd->exec();
delete kd;
if( retcode == Accepted )
{
keys->setKeyDict( dict );
if (save_settings)
keys->writeSettings();
}
return retcode;
}
kdelibs'KKeyDialog::configureKeys() (./kdelibs/kdeui/kkeydialog.cpp:291)
int KKeyDialog::configureKeys( KActionCollection *coll, const QString& file,
bool save_settings, QWidget *parent )
{
QDict<KKeyEntry> *dict = coll->keyDict();
KKeyDialog *kd = new KKeyDialog( dict, parent );
CHECK_PTR( kd );
int retcode = kd->exec();
delete kd;
if( retcode != Accepted )
return retcode;
if (!save_settings)
{
coll->setKeyDict( *dict );
return retcode;
}
// let's start saving this info
QString raw_xml(KXMLGUIFactory::readConfigFile(file));
QDomDocument doc;
doc.setContent(raw_xml);
QString tagActionProp = QString::fromLatin1( "ActionProperties" );
QString tagAction = QString::fromLatin1( "Action" );
QString attrName = QString::fromLatin1( "name" );
QString attrAccel = QString::fromLatin1( "accel" );
// first, lets see if we have existing properties
QDomElement elem;
QDomElement it = doc.firstChild().firstChild().toElement();
for ( ; !it.isNull(); it = it.nextSibling().toElement() )
{
if ( it.tagName() == tagActionProp )
{
elem = it;
break;
}
}
// if there was none, create one
if ( elem.isNull() )
{
elem = doc.createElement( tagActionProp );
doc.firstChild().appendChild(elem);
}
// now, iterate through our actions
for (unsigned int i = 0; i < coll->count(); i++)
{
KAction *action = coll->action(i);
// see if we changed
KKeyEntry *key = (*dict)[action->name()];
if (key->aCurrentKeyCode == key->aConfigKeyCode)
continue;
// now see if this element already exists
QDomElement act_elem;
for ( it = elem.firstChild().toElement(); !it.isNull(); it = it.nextSibling().toElement() )
{
if ( it.attribute( attrName ) == action->name() )
{
act_elem = it;
break;
}
}
// nope, create a new one
if ( act_elem.isNull() )
{
act_elem = doc.createElement( tagAction );
act_elem.setAttribute( attrName, action->name() );
}
act_elem.setAttribute( attrAccel,
KAccel::keyToString( key->aConfigKeyCode ) );
elem.appendChild( act_elem );
}
// finally, write out the result
KXMLGUIFactory::saveConfigFile(doc, file);
coll->setKeyDict( *dict );
return retcode;
}