Commit bb696c3c authored by Robert Knight's avatar Robert Knight
Browse files

Allow removal of existing entries and adding of new entries in the key binding...

Allow removal of existing entries and adding of new entries in the key binding editor.  Fix binding table referring to old entries when making changes.

svn path=/trunk/KDE/kdebase/apps/konsole/; revision=677166
parent c2412a1c
......@@ -44,12 +44,18 @@ KeyBindingEditor::KeyBindingEditor(QWidget* parent)
_ui->keyBindingTable->setColumnCount(2);
QStringList labels;
labels << i18n("Key Combination") << i18n("Binding");
labels << i18n("Key Combination") << i18n("Output");
_ui->keyBindingTable->setHorizontalHeaderLabels(labels);
_ui->keyBindingTable->horizontalHeader()->setStretchLastSection(true);
_ui->keyBindingTable->verticalHeader()->hide();
// add and remove buttons
_ui->addEntryButton->setIcon( KIcon("list-add") );
_ui->removeEntryButton->setIcon( KIcon("list-remove") );
connect( _ui->removeEntryButton , SIGNAL(clicked()) , this , SLOT(removeSelectedEntry()) );
connect( _ui->addEntryButton , SIGNAL(clicked()) , this , SLOT(addNewEntry()) );
// test area
_ui->testAreaInputEdit->installEventFilter(this);
......@@ -60,6 +66,42 @@ KeyBindingEditor::~KeyBindingEditor()
delete _ui;
}
void KeyBindingEditor::removeSelectedEntry()
{
QListIterator<QTableWidgetItem*> iter( _ui->keyBindingTable->selectedItems() );
while ( iter.hasNext() )
{
// get the first item in the row which has the entry
QTableWidgetItem* item = _ui->keyBindingTable->item(iter.next()->row(),0);
KeyboardTranslator::Entry existing = item->data(Qt::UserRole).
value<KeyboardTranslator::Entry>();
_translator->removeEntry(existing);
_ui->keyBindingTable->removeRow( item->row() );
}
}
void KeyBindingEditor::addNewEntry()
{
_ui->keyBindingTable->insertRow( _ui->keyBindingTable->rowCount() );
int newRowCount = _ui->keyBindingTable->rowCount();
// block signals here to avoid triggering bindingTableItemChanged() slot call
_ui->keyBindingTable->blockSignals(true);
_ui->keyBindingTable->setItem(newRowCount-1,0,new QTableWidgetItem() );
_ui->keyBindingTable->setItem(newRowCount-1,1,new QTableWidgetItem() );
_ui->keyBindingTable->blockSignals(false);
// make sure user can see new row
_ui->keyBindingTable->scrollToItem(_ui->keyBindingTable->item(newRowCount-1,0));
}
bool KeyBindingEditor::eventFilter( QObject* watched , QEvent* event )
{
if ( watched == _ui->testAreaInputEdit )
......@@ -68,13 +110,31 @@ bool KeyBindingEditor::eventFilter( QObject* watched , QEvent* event )
{
QKeyEvent* keyEvent = (QKeyEvent*)event;
// The state here is currently set to the state that a newly started
// terminal in Konsole will be in ( which is also the same as the
// state just after a reset ), this has 'Ansi' turned on and all other
// states off.
//
// TODO: It may be useful to be able to specify the state in the 'test input'
// area, but preferably not in a way which clutters the UI with lots of
// checkboxes.
//
const KeyboardTranslator::State state = KeyboardTranslator::AnsiState;
int modifiers = keyEvent->modifiers();
KeyboardTranslator::Entry entry = _translator->findEntry( keyEvent->key() ,
(Qt::KeyboardModifier)modifiers );
_ui->testAreaInputEdit->setText(entry.conditionToString());
_ui->testAreaOutputEdit->setText(entry.resultToString());
(Qt::KeyboardModifier)modifiers, state );
if ( !entry.isNull() )
{
_ui->testAreaInputEdit->setText(entry.conditionToString());
_ui->testAreaOutputEdit->setText(entry.resultToString());
}
else
{
_ui->testAreaInputEdit->setText(keyEvent->text());
_ui->testAreaOutputEdit->setText(keyEvent->text());
}
//qDebug() << "Entry: " << entry.resultToString();
keyEvent->accept();
......@@ -130,12 +190,12 @@ void KeyBindingEditor::bindingTableItemChanged(QTableWidgetItem* item)
qDebug() << "Created entry: " << entry.conditionToString() << " , " << entry.resultToString();
_translator->replaceEntry(existing,entry);
_translator->replaceEntry(existing,entry);
// block signals to prevent this slot from being called repeatedly
_ui->keyBindingTable->blockSignals(true);
key->setData(Qt::UserRole,QVariant::fromValue(existing));
key->setData(Qt::UserRole,QVariant::fromValue(entry));
_ui->keyBindingTable->blockSignals(false);
}
......
......@@ -85,6 +85,8 @@ public slots:
private slots:
void bindingTableItemChanged(QTableWidgetItem* item);
void removeSelectedEntry();
void addNewEntry();
private:
void setupKeyBindingTable(const KeyboardTranslator* translator);
......
......@@ -5,8 +5,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>302</width>
<height>395</height>
<width>374</width>
<height>530</height>
</rect>
</property>
<property name="windowTitle" >
......@@ -49,6 +49,37 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<item>
<widget class="QPushButton" name="addEntryButton" >
<property name="text" >
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="removeEntryButton" >
<property name="text" >
<string>Remove</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer>
<property name="orientation" >
......
......@@ -649,7 +649,7 @@ QKeySequence KeyboardTranslator::Entry::keySequence() const
}
#endif
bool KeyboardTranslator::Entry::operator==(const Entry& rhs)
bool KeyboardTranslator::Entry::operator==(const Entry& rhs) const
{
return _keyCode == rhs._keyCode &&
_modifiers == rhs._modifiers &&
......@@ -827,7 +827,7 @@ void KeyboardTranslator::Entry::insertState( QString& item , int state ) const
else if ( state == KeyboardTranslator::NewLineState )
item += "NewLine";
else if ( state == KeyboardTranslator::AnsiState )
item += "ansi";
item += "Ansi";
else if ( state == KeyboardTranslator::CursorKeysState )
item += "AppCuKeys";
else if ( state == KeyboardTranslator::AnyModifierState )
......@@ -914,7 +914,8 @@ void KeyboardTranslator::addEntry(const Entry& entry)
}
void KeyboardTranslator::replaceEntry(const Entry& existing , const Entry& replacement)
{
_entries.remove(existing.keyCode(),existing);
if ( !existing.isNull() )
_entries.remove(existing.keyCode(),existing);
_entries.insert(replacement.keyCode(),replacement);
}
void KeyboardTranslator::removeEntry(const Entry& entry)
......
......@@ -119,6 +119,12 @@ public:
*/
Entry();
/**
* Returns true if this entry is null.
* This is true for newly constructed entries which have no properties set.
*/
bool isNull() const;
/** Returns the commands associated with this entry */
Command command() const;
/** Sets the command associated with this entry. */
......@@ -202,7 +208,7 @@ public:
*/
bool matches( int keyCode , Qt::KeyboardModifier modifiers , State flags ) const;
bool operator==(const Entry& rhs);
bool operator==(const Entry& rhs) const;
private:
void insertModifier( QString& item , int modifier ) const;
......@@ -256,7 +262,8 @@ public:
void addEntry(const Entry& entry);
/**
* Replaces an entry in the translator.
* Replaces an entry in the translator. If the @p existing entry is null,
* then this is equivalent to calling addEntry(@p replacement)
*/
void replaceEntry(const Entry& existing , const Entry& replacement);
......@@ -476,6 +483,11 @@ inline void KeyboardTranslator::Entry::setModifierMask( Qt::KeyboardModifier ma
}
inline Qt::KeyboardModifier KeyboardTranslator::Entry::modifierMask() const { return _modifierMask; }
inline bool KeyboardTranslator::Entry::isNull() const
{
return ( *this == Entry() );
}
inline void KeyboardTranslator::Entry::setCommand( Command command )
{
_command = command;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment