mirror of
https://github.com/KDE/konsole.git
synced 2026-05-05 13:14:22 -04:00
124 lines
3.5 KiB
C++
124 lines
3.5 KiB
C++
/*
|
|
Copyright (C) 2007 by Robert Knight <robertknight@gmail.com>
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program 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 General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
02110-1301 USA.
|
|
*/
|
|
|
|
// Own
|
|
#include "KeyBindingEditor.h"
|
|
|
|
// Qt
|
|
#include <QtGui/QHeaderView>
|
|
|
|
// Konsole
|
|
#include "ui_KeyBindingEditor.h"
|
|
#include "KeyboardTranslator.h"
|
|
|
|
using namespace Konsole;
|
|
|
|
KeyBindingEditor::KeyBindingEditor(QWidget* parent)
|
|
: QWidget(parent)
|
|
, _translator(0)
|
|
{
|
|
_ui = new Ui::KeyBindingEditor();
|
|
_ui->setupUi(this);
|
|
|
|
// description edit
|
|
connect( _ui->descriptionEdit , SIGNAL(textChanged(const QString&)) , this , SLOT(setDescription(const QString&)) );
|
|
|
|
// key bindings table
|
|
_ui->keyBindingTable->setColumnCount(2);
|
|
|
|
QStringList labels;
|
|
labels << i18n("Key Combination") << i18n("Binding");
|
|
|
|
_ui->keyBindingTable->setHorizontalHeaderLabels(labels);
|
|
_ui->keyBindingTable->horizontalHeader()->setStretchLastSection(true);
|
|
_ui->keyBindingTable->verticalHeader()->hide();
|
|
|
|
// test area
|
|
connect( _ui->testAreaInputEdit , SIGNAL(textChanged(const QString&)) , this ,
|
|
SLOT(updateTestAreaOutput(const QString&)) );
|
|
}
|
|
|
|
KeyBindingEditor::~KeyBindingEditor()
|
|
{
|
|
delete _ui;
|
|
}
|
|
|
|
void KeyBindingEditor::updateTestAreaOutput(const QString& input)
|
|
{
|
|
// TODO : Run 'input' text through the keyboard translator
|
|
|
|
|
|
}
|
|
|
|
void KeyBindingEditor::setDescription(const QString& newDescription)
|
|
{
|
|
if ( description() != newDescription )
|
|
{
|
|
_ui->descriptionEdit->setText(newDescription);
|
|
|
|
if ( _translator )
|
|
_translator->setDescription(newDescription);
|
|
}
|
|
}
|
|
QString KeyBindingEditor::description() const
|
|
{
|
|
return _ui->descriptionEdit->text();
|
|
}
|
|
|
|
void KeyBindingEditor::setup(const KeyboardTranslator* translator)
|
|
{
|
|
if ( _translator )
|
|
delete _translator;
|
|
|
|
_translator = new KeyboardTranslator(*translator);
|
|
|
|
// setup description edit
|
|
_ui->descriptionEdit->setText(translator->description());
|
|
|
|
// setup key binding table
|
|
setupKeyBindingTable(translator);
|
|
}
|
|
|
|
KeyboardTranslator* KeyBindingEditor::translator() const
|
|
{
|
|
return _translator;
|
|
}
|
|
|
|
void KeyBindingEditor::setupKeyBindingTable(const KeyboardTranslator* translator)
|
|
{
|
|
QList<KeyboardTranslator::Entry> entries = translator->entries();
|
|
_ui->keyBindingTable->setRowCount(entries.count());
|
|
qDebug() << "Keyboard translator has" << entries.count() << "entries.";
|
|
|
|
for ( int row = 0 ; row < entries.count() ; row++ )
|
|
{
|
|
const KeyboardTranslator::Entry& entry = entries.at(row);
|
|
|
|
QTableWidgetItem* keyItem = new QTableWidgetItem(entry.keySequence().toString());
|
|
QTableWidgetItem* textItem = new QTableWidgetItem(QString(entry.text()));
|
|
|
|
_ui->keyBindingTable->setItem(row,0,keyItem);
|
|
_ui->keyBindingTable->setItem(row,1,textItem);
|
|
}
|
|
_ui->keyBindingTable->sortItems(0);
|
|
}
|
|
|
|
#include "KeyBindingEditor.moc"
|
|
|