Beispiel #1
0
void KKeyChooser::readGlobalKeys()
{
    d->mapGlobals.clear();
    if(m_type == Global)
        return; // they will be checked normally, because we're configuring them
    readGlobalKeys(d->mapGlobals);
}
Beispiel #2
0
KKeyChooser::KKeyChooser( QDict<KKeyEntry> *aKeyDict, QWidget *parent )
    : 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 );
	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();
	while ( aIt->current() ) {
		aIt->current()->aConfigKeyCode = aIt->current()->aCurrentKeyCode;
		
		KSplitListItem *sli = new KSplitListItem(
		 	item( aIt->current()->aConfigKeyCode, aIt->currentKey() )
		);
		
		connect( wList, SIGNAL( newWidth( int ) ),
				 sli, SLOT( setWidth( int ) ) );
		wList->insertItem( sli );
		
		++ ( *aIt );
	}

	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> ( 37, false );
	globalDict->setAutoDelete( true );
	readGlobalKeys();
	
	topLayout->activate();
}
Beispiel #3
0
bool KKeyChooser::checkGlobalShortcutsConflict(const KShortcut &cut, bool bWarnUser, QWidget *parent)
{
    QMap< QString, KShortcut > map;
    readGlobalKeys(map);
    return checkGlobalShortcutsConflict(cut, bWarnUser, parent, map, QString::null);
}
Beispiel #4
0
void KKeyChooser::slotSettingsChanged(int category)
{
    if(category == KApplication::SETTINGS_SHORTCUTS)
        readGlobalKeys(); // reread
}
Beispiel #5
0
void KKeyChooser::initGUI(ActionType type, bool bAllowLetterShortcuts)
{
    d = new KKeyChooserPrivate();

    m_type = type;
    d->bAllowLetterShortcuts = bAllowLetterShortcuts;

    d->bPreferFourModifierKeys = KGlobalAccel::useFourModifierKeys();

    //
    // 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, KDialog::spacingHint());

    //
    // ADD SEARCHLINE
    //
    QHBoxLayout *searchLayout = new QHBoxLayout(0, 0, KDialog::spacingHint());
    topLayout->addLayout(searchLayout, 10);

    QToolButton *clearSearch = new QToolButton(this);
    clearSearch->setTextLabel(i18n("Clear Search"), true);
    clearSearch->setIconSet(SmallIconSet(QApplication::reverseLayout() ? "clear_left" : "locationbar_erase"));
    searchLayout->addWidget(clearSearch);
    QLabel *slbl = new QLabel(i18n("&Search:"), this);
    searchLayout->addWidget(slbl);
    KListViewSearchLine *listViewSearch = new KListViewSearchLine(this);
    searchLayout->addWidget(listViewSearch);
    slbl->setBuddy(listViewSearch);
    connect(clearSearch, SIGNAL(pressed()), listViewSearch, SLOT(clear()));

    QString wtstr = i18n(
        "Search interactively for shortcut names (e.g. Copy) "
        "or combination of keys (e.g. Ctrl+C) by typing them here.");

    QWhatsThis::add(slbl, wtstr);
    QWhatsThis::add(listViewSearch, wtstr);

    //
    // CREATE SPLIT LIST BOX
    //
    // fill up the split list box with the action/key pairs.
    //
    QGridLayout *stackLayout = new QGridLayout(2, 2, 2);
    topLayout->addLayout(stackLayout, 10);
    stackLayout->setRowStretch(1, 10); // Only list will stretch

    d->pList = new KListView(this);
    listViewSearch->setListView(d->pList); // Plug into search line
    QValueList< int > columns;
    columns.append(0);
    listViewSearch->setSearchColumns(columns);

    stackLayout->addMultiCellWidget(d->pList, 1, 1, 0, 1);

    wtstr = i18n(
        "Here you can see a list of key bindings, "
        "i.e. associations between actions (e.g. 'Copy') "
        "shown in the left column and keys or combination "
        "of keys (e.g. Ctrl+V) shown in the right column.");

    QWhatsThis::add(d->pList, wtstr);
    new KKeyChooserWhatsThis(d->pList);

    d->pList->setAllColumnsShowFocus(true);
    d->pList->addColumn(i18n("Action"));
    d->pList->addColumn(i18n("Shortcut"));
    d->pList->addColumn(i18n("Alternate"));

    connect(d->pList, SIGNAL(currentChanged(QListViewItem *)), SLOT(slotListItemSelected(QListViewItem *)));

    // handle double clicking an item
    connect(d->pList, SIGNAL(doubleClicked(QListViewItem *, const QPoint &, int)), SLOT(captureCurrentItem()));
    connect(d->pList, SIGNAL(spacePressed(QListViewItem *)), SLOT(captureCurrentItem()));
    //
    // CREATE CHOOSE KEY GROUP
    //
    d->fCArea = new QGroupBox(this);
    topLayout->addWidget(d->fCArea, 1);

    d->fCArea->setTitle(i18n("Shortcut for Selected Action"));
    d->fCArea->setFrameStyle(QFrame::GroupBoxPanel | QFrame::Plain);

    //
    // CHOOSE KEY GROUP LAYOUT MANAGER
    //
    QGridLayout *grid = new QGridLayout(d->fCArea, 3, 4, KDialog::spacingHint());
    grid->addRowSpacing(0, fontMetrics().lineSpacing());

    d->kbGroup = new QButtonGroup(d->fCArea);
    d->kbGroup->hide();
    d->kbGroup->setExclusive(true);

    m_prbNone = new QRadioButton(i18n("no key", "&None"), d->fCArea);
    d->kbGroup->insert(m_prbNone, NoKey);
    m_prbNone->setEnabled(false);
    // grid->addMultiCellWidget( rb, 1, 1, 1, 2 );
    grid->addWidget(m_prbNone, 1, 0);
    QWhatsThis::add(m_prbNone, i18n("The selected action will not be associated with any key."));
    connect(m_prbNone, SIGNAL(clicked()), SLOT(slotNoKey()));

    m_prbDef = new QRadioButton(i18n("default key", "De&fault"), d->fCArea);
    d->kbGroup->insert(m_prbDef, DefaultKey);
    m_prbDef->setEnabled(false);
    // grid->addMultiCellWidget( rb, 2, 2, 1, 2 );
    grid->addWidget(m_prbDef, 1, 1);
    QWhatsThis::add(m_prbDef, i18n("This will bind the default key to the selected action. Usually a reasonable choice."));
    connect(m_prbDef, SIGNAL(clicked()), SLOT(slotDefaultKey()));

    m_prbCustom = new QRadioButton(i18n("C&ustom"), d->fCArea);
    d->kbGroup->insert(m_prbCustom, CustomKey);
    m_prbCustom->setEnabled(false);
    // grid->addMultiCellWidget( rb, 3, 3, 1, 2 );
    grid->addWidget(m_prbCustom, 1, 2);
    QWhatsThis::add(m_prbCustom, i18n("If this option is selected you can create a customized key binding for the"
                                      " selected action using the buttons below."));
    connect(m_prbCustom, SIGNAL(clicked()), SLOT(slotCustomKey()));

    // connect( d->kbGroup, SIGNAL( clicked( int ) ), SLOT( keyMode( int ) ) );

    QBoxLayout *pushLayout = new QHBoxLayout(KDialog::spacingHint());
    grid->addLayout(pushLayout, 1, 3);

    d->pbtnShortcut = new KKeyButton(d->fCArea, "key");
    d->pbtnShortcut->setEnabled(false);
    connect(d->pbtnShortcut, SIGNAL(capturedShortcut(const KShortcut &)), SLOT(capturedShortcut(const KShortcut &)));
    grid->addRowSpacing(1, d->pbtnShortcut->sizeHint().height() + 5);

    wtstr = i18n(
        "Use this button to choose a new shortcut key. Once you click it, "
        "you can press the key-combination which you would like to be assigned "
        "to the currently selected action.");
    QWhatsThis::add(d->pbtnShortcut, wtstr);

    //
    // Add widgets to the geometry manager
    //
    pushLayout->addSpacing(KDialog::spacingHint() * 2);
    pushLayout->addWidget(d->pbtnShortcut);
    pushLayout->addStretch(10);

    d->lInfo = new QLabel(d->fCArea);
    // resize(0,0);
    // d->lInfo->setAlignment( AlignCenter );
    // d->lInfo->setEnabled( false );
    // d->lInfo->hide();
    grid->addMultiCellWidget(d->lInfo, 2, 2, 0, 3);

    // d->globalDict = new QDict<int> ( 100, false );
    // d->globalDict->setAutoDelete( true );
    readGlobalKeys();
    // d->stdDict = new QDict<int> ( 100, false );
    // d->stdDict->setAutoDelete( true );
    // if (type == Application || type == ApplicationGlobal)
    //  readStdKeys();
    connect(kapp, SIGNAL(settingsChanged(int)), SLOT(slotSettingsChanged(int)));
    if(allChoosers == NULL)
        allChoosers = allChoosersDeleter.setObject(allChoosers, new QValueList< KKeyChooser * >);
    allChoosers->append(this);
}