55
51
_ui->keyBindingTable->setSelectionBehavior(QAbstractItemView::SelectRows);
57
53
// add and remove buttons
58
_ui->addEntryButton->setIcon( KIcon("list-add") );
59
_ui->removeEntryButton->setIcon( KIcon("list-remove") );
54
_ui->addEntryButton->setIcon(KIcon("list-add"));
55
_ui->removeEntryButton->setIcon(KIcon("list-remove"));
61
connect( _ui->removeEntryButton , SIGNAL(clicked()) , this , SLOT(removeSelectedEntry()) );
62
connect( _ui->addEntryButton , SIGNAL(clicked()) , this , SLOT(addNewEntry()) );
57
connect(_ui->removeEntryButton , SIGNAL(clicked()) , this , SLOT(removeSelectedEntry()));
58
connect(_ui->addEntryButton , SIGNAL(clicked()) , this , SLOT(addNewEntry()));
65
61
_ui->testAreaInputEdit->installEventFilter(this);
74
70
void KeyBindingEditor::removeSelectedEntry()
76
QList<QTableWidgetItem*> selectedList = _ui->keyBindingTable->selectedItems();
77
72
QList<QTableWidgetItem*> uniqueList;
80
QListIterator<QTableWidgetItem*> iter( selectedList );
81
while ( iter.hasNext() )
83
QTableWidgetItem* item = iter.next();
74
foreach(QTableWidgetItem* item, _ui->keyBindingTable->selectedItems()) {
84
75
if (item->column() == 1) //Select item at the first column
85
item = _ui->keyBindingTable->item(item->row(),0);
76
item = _ui->keyBindingTable->item(item->row(), 0);
87
if ( !uniqueList.contains(item) )
78
if (!uniqueList.contains(item))
88
79
uniqueList.append(item);
91
iter = QListIterator<QTableWidgetItem*>( uniqueList );
92
while ( iter.hasNext() )
82
foreach(QTableWidgetItem* item, uniqueList) {
94
83
// get the first item in the row which has the entry
95
QTableWidgetItem* item = iter.next();
97
85
KeyboardTranslator::Entry existing = item->data(Qt::UserRole).
98
value<KeyboardTranslator::Entry>();
86
value<KeyboardTranslator::Entry>();
100
88
_translator->removeEntry(existing);
102
_ui->keyBindingTable->removeRow( item->row() );
90
_ui->keyBindingTable->removeRow(item->row());
106
94
void KeyBindingEditor::addNewEntry()
108
_ui->keyBindingTable->insertRow( _ui->keyBindingTable->rowCount() );
110
int newRowCount = _ui->keyBindingTable->rowCount();
112
// block signals here to avoid triggering bindingTableItemChanged() slot call
113
_ui->keyBindingTable->blockSignals(true);
115
_ui->keyBindingTable->setItem(newRowCount-1,0,new QTableWidgetItem() );
116
_ui->keyBindingTable->setItem(newRowCount-1,1,new QTableWidgetItem() );
118
_ui->keyBindingTable->blockSignals(false);
120
// make sure user can see new row
121
_ui->keyBindingTable->scrollToItem(_ui->keyBindingTable->item(newRowCount-1,0));
96
_ui->keyBindingTable->insertRow(_ui->keyBindingTable->rowCount());
98
int newRowCount = _ui->keyBindingTable->rowCount();
100
// block signals here to avoid triggering bindingTableItemChanged() slot call
101
_ui->keyBindingTable->blockSignals(true);
103
_ui->keyBindingTable->setItem(newRowCount - 1, 0, new QTableWidgetItem());
104
_ui->keyBindingTable->setItem(newRowCount - 1, 1, new QTableWidgetItem());
106
_ui->keyBindingTable->blockSignals(false);
108
// make sure user can see new row
109
_ui->keyBindingTable->scrollToItem(_ui->keyBindingTable->item(newRowCount - 1, 0));
124
bool KeyBindingEditor::eventFilter( QObject* watched , QEvent* event )
112
bool KeyBindingEditor::eventFilter(QObject* watched , QEvent* event)
126
if ( watched == _ui->testAreaInputEdit )
128
if ( event->type() == QEvent::KeyPress )
114
if (watched == _ui->testAreaInputEdit) {
115
if (event->type() == QEvent::KeyPress) {
130
116
QKeyEvent* keyEvent = (QKeyEvent*)event;
132
// The state here is currently set to the state that a newly started
133
// terminal in Konsole will be in ( which is also the same as the
118
// The state here is currently set to the state that a newly started
119
// terminal in Konsole will be in ( which is also the same as the
134
120
// state just after a reset ), this has 'Ansi' turned on and all other
137
// TODO: It may be useful to be able to specify the state in the 'test input'
138
// area, but preferably not in a way which clutters the UI with lots of
123
// TODO: It may be useful to be able to specify the state in the 'test input'
124
// area, but preferably not in a way which clutters the UI with lots of
141
127
const KeyboardTranslator::States states = KeyboardTranslator::AnsiState;
143
KeyboardTranslator::Entry entry = _translator->findEntry( keyEvent->key() ,
144
keyEvent->modifiers(),
129
KeyboardTranslator::Entry entry = _translator->findEntry(keyEvent->key() ,
130
keyEvent->modifiers(),
147
if ( !entry.isNull() )
133
if (!entry.isNull()) {
149
134
_ui->testAreaInputEdit->setText(entry.conditionToString());
150
_ui->testAreaOutputEdit->setText(entry.resultToString(true,keyEvent->modifiers()));
135
_ui->testAreaOutputEdit->setText(entry.resultToString(true, keyEvent->modifiers()));
154
137
_ui->testAreaInputEdit->setText(keyEvent->text());
155
138
_ui->testAreaOutputEdit->setText(keyEvent->text());
158
141
keyEvent->accept();
165
148
void KeyBindingEditor::setDescription(const QString& newDescription)
167
_ui->descriptionEdit->setText(newDescription);
150
_ui->descriptionEdit->setText(newDescription);
170
_translator->setDescription(newDescription);
153
_translator->setDescription(newDescription);
172
155
QString KeyBindingEditor::description() const
196
179
void KeyBindingEditor::bindingTableItemChanged(QTableWidgetItem* item)
198
QTableWidgetItem* key = _ui->keyBindingTable->item( item->row() , 0 );
199
KeyboardTranslator::Entry existing = key->data(Qt::UserRole).value<KeyboardTranslator::Entry>();
201
QString condition = key->text();
202
QString result = _ui->keyBindingTable->item( item->row() , 1 )->text();
204
KeyboardTranslator::Entry entry = KeyboardTranslatorReader::createEntry(condition,result);
205
_translator->replaceEntry(existing,entry);
181
QTableWidgetItem* key = _ui->keyBindingTable->item(item->row() , 0);
182
KeyboardTranslator::Entry existing = key->data(Qt::UserRole).value<KeyboardTranslator::Entry>();
184
QString condition = key->text();
185
QString result = _ui->keyBindingTable->item(item->row() , 1)->text();
187
KeyboardTranslator::Entry entry = KeyboardTranslatorReader::createEntry(condition, result);
188
_translator->replaceEntry(existing, entry);
207
190
// block signals to prevent this slot from being called repeatedly
208
_ui->keyBindingTable->blockSignals(true);
210
key->setData(Qt::UserRole,QVariant::fromValue(entry));
212
_ui->keyBindingTable->blockSignals(false);
191
_ui->keyBindingTable->blockSignals(true);
193
key->setData(Qt::UserRole, QVariant::fromValue(entry));
195
_ui->keyBindingTable->blockSignals(false);
215
198
void KeyBindingEditor::setupKeyBindingTable(const KeyboardTranslator* translator)
217
disconnect( _ui->keyBindingTable , SIGNAL(itemChanged(QTableWidgetItem*)) , this ,
218
SLOT(bindingTableItemChanged(QTableWidgetItem*)) );
200
disconnect(_ui->keyBindingTable , SIGNAL(itemChanged(QTableWidgetItem*)) , this ,
201
SLOT(bindingTableItemChanged(QTableWidgetItem*)));
220
203
QList<KeyboardTranslator::Entry> entries = translator->entries();
221
204
_ui->keyBindingTable->setRowCount(entries.count());
223
for ( int row = 0 ; row < entries.count() ; row++ )
206
for (int row = 0 ; row < entries.count() ; row++) {
225
207
const KeyboardTranslator::Entry& entry = entries.at(row);
227
209
QTableWidgetItem* keyItem = new QTableWidgetItem(entry.conditionToString());
228
keyItem->setData( Qt::UserRole , QVariant::fromValue(entry) );
210
keyItem->setData(Qt::UserRole , QVariant::fromValue(entry));
230
212
QTableWidgetItem* textItem = new QTableWidgetItem(QString(entry.resultToString()));
232
_ui->keyBindingTable->setItem(row,0,keyItem);
233
_ui->keyBindingTable->setItem(row,1,textItem);
214
_ui->keyBindingTable->setItem(row, 0, keyItem);
215
_ui->keyBindingTable->setItem(row, 1, textItem);
235
217
_ui->keyBindingTable->sortItems(0);
237
connect( _ui->keyBindingTable , SIGNAL(itemChanged(QTableWidgetItem*)) , this ,
238
SLOT(bindingTableItemChanged(QTableWidgetItem*)) );
219
connect(_ui->keyBindingTable , SIGNAL(itemChanged(QTableWidgetItem*)) , this ,
220
SLOT(bindingTableItemChanged(QTableWidgetItem*)));
241
223
#include "KeyBindingEditor.moc"