diff --git a/src/EditProfileDialog.cpp b/src/EditProfileDialog.cpp index c4d503d13..b55eba68b 100644 --- a/src/EditProfileDialog.cpp +++ b/src/EditProfileDialog.cpp @@ -235,30 +235,9 @@ void EditProfileDialog::selectInitialDir() } void EditProfileDialog::setupAppearencePage(const Profile* info) { - const QString& name = SessionManager::instance()->profile(_profileKey)->colorScheme(); - const ColorScheme* currentScheme = ColorSchemeManager::instance()->findColorScheme(name); - // setup color list - QStandardItemModel* model = new QStandardItemModel(this); - QList schemeList = ColorSchemeManager::instance()->allColorSchemes(); - QListIterator schemeIter(schemeList); + updateColorSchemeList(); - while (schemeIter.hasNext()) - { - const ColorScheme* colors = schemeIter.next(); - QStandardItem* item = new QStandardItem(colors->description()); - item->setData( QVariant::fromValue(colors) , Qt::UserRole + 1); - item->setFlags( item->flags() | Qt::ItemIsUserCheckable ); - - if ( colors == currentScheme ) - item->setCheckState( Qt::Checked ); - else - item->setCheckState( Qt::Unchecked ); - - model->appendRow(item); - } - - _ui->colorSchemeList->setModel(model); _ui->colorSchemeList->setItemDelegate(new ColorSchemeViewDelegate(this)); _ui->colorSchemeList->setMouseTracking(true); _ui->colorSchemeList->installEventFilter(this); @@ -287,6 +266,74 @@ void EditProfileDialog::setupAppearencePage(const Profile* info) connect( _ui->editFontButton , SIGNAL(clicked()) , this , SLOT(showFontDialog()) ); } +void EditProfileDialog::updateColorSchemeList() +{ + delete _ui->colorSchemeList->model(); + + const QString& name = SessionManager::instance()->profile(_profileKey)->colorScheme(); + const ColorScheme* currentScheme = ColorSchemeManager::instance()->findColorScheme(name); + + QStandardItemModel* model = new QStandardItemModel(this); + QList schemeList = ColorSchemeManager::instance()->allColorSchemes(); + QListIterator schemeIter(schemeList); + + while (schemeIter.hasNext()) + { + const ColorScheme* colors = schemeIter.next(); + QStandardItem* item = new QStandardItem(colors->description()); + item->setData( QVariant::fromValue(colors) , Qt::UserRole + 1); + item->setFlags( item->flags() | Qt::ItemIsUserCheckable ); + + if ( colors == currentScheme ) + item->setCheckState( Qt::Checked ); + else + item->setCheckState( Qt::Unchecked ); + + model->appendRow(item); + } + + _ui->colorSchemeList->setModel(model); + +} +void EditProfileDialog::updateKeyBindingsList() +{ + delete _ui->keyBindingList->model(); + + const QString& name = SessionManager::instance()->profile(_profileKey)->property(Profile::KeyBindings) + .value(); + + const KeyboardTranslator* currentTranslator = KeyboardTranslatorManager::instance()->findTranslator(name); + + qDebug() << "Current translator = " << currentTranslator << ", name: " << name; + + QStandardItemModel* model = new QStandardItemModel(this); + + QList translatorNames = KeyboardTranslatorManager::instance()->allTranslators(); + QListIterator iter(translatorNames); + while (iter.hasNext()) + { + const QString& name = iter.next(); + + const KeyboardTranslator* translator = KeyboardTranslatorManager::instance()->findTranslator(name); + + qDebug() << "Translator:" << translator << ", name = " << translator->name() << "description = " << + translator->description(); + + // TODO Use translator->description() here + QStandardItem* item = new QStandardItem(translator->description()); + item->setData(QVariant::fromValue(translator),Qt::UserRole+1); + item->setFlags( item->flags() | Qt::ItemIsUserCheckable ); + + if ( translator == currentTranslator ) + item->setCheckState( Qt::Checked ); + else + item->setCheckState( Qt::Unchecked ); + + model->appendRow(item); + } + + _ui->keyBindingList->setModel(model); +} bool EditProfileDialog::eventFilter( QObject* watched , QEvent* event ) { if ( watched == _ui->colorSchemeList && event->type() == QEvent::Leave ) @@ -360,43 +407,53 @@ void EditProfileDialog::removeColorScheme() _ui->colorSchemeList->model()->removeRow(selected.first().row()); } } -void EditProfileDialog::showColorSchemeEditor(bool newScheme) +void EditProfileDialog::showColorSchemeEditor(bool isNewScheme) { QModelIndexList selected = _ui->colorSchemeList->selectionModel()->selectedIndexes(); + QAbstractItemModel* model = _ui->colorSchemeList->model(); + QModelIndex index; if ( !selected.isEmpty() ) + index = selected.first(); + else + index = model->index(0,0); // use the first item in the list + + const ColorScheme* colors = model->data(index,Qt::UserRole+1).value(); + + KDialog* dialog = new KDialog(this); + + if ( isNewScheme ) + dialog->setCaption(i18n("New Color Scheme")); + else + dialog->setCaption(i18n("Edit Color Scheme")); + + ColorSchemeEditor* editor = new ColorSchemeEditor; + dialog->setMainWidget(editor); + editor->setup(colors); + + if ( isNewScheme ) + editor->setDescription(i18n("New Color Scheme")); + + if ( dialog->exec() == QDialog::Accepted ) { - QAbstractItemModel* model = _ui->colorSchemeList->model(); - QModelIndex index = selected.first(); - const ColorScheme* colors = model->data(index,Qt::UserRole+1).value(); + ColorScheme* newScheme = new ColorScheme(*editor->colorScheme()); - KDialog* dialog = new KDialog(this); + // if this is a new color scheme, pick a name based on the description + if ( isNewScheme ) + newScheme->setName(newScheme->description()); - if ( newScheme ) - dialog->setCaption(i18n("New Color Scheme")); - else - dialog->setCaption(i18n("Edit Color Scheme")); + ColorSchemeManager::instance()->addColorScheme( newScheme ); + + updateColorSchemeList(); - ColorSchemeEditor* editor = new ColorSchemeEditor; - dialog->setMainWidget(editor); - editor->setup(colors); + const QString& currentScheme = SessionManager::instance()->profile(_profileKey)->colorScheme(); - if ( dialog->exec() == QDialog::Accepted ) + // the next couple of lines may seem slightly odd, + // but they force any open views based on the current profile + // to update their color schemes + if ( newScheme->name() == currentScheme ) { - ColorScheme* newScheme = new ColorScheme(*editor->colorScheme()); - ColorSchemeManager::instance()->addColorScheme( newScheme ); - model->setData(index, QVariant::fromValue( (const ColorScheme*)newScheme ) , Qt::UserRole+1); - model->setData(index, newScheme->description() , Qt::DisplayRole); - - const QString& currentScheme = SessionManager::instance()->profile(_profileKey)->colorScheme(); - - // the next couple of lines may seem slightly odd, - // but they force any open views based on the current profile - // to update their color schemes - if ( newScheme->name() == currentScheme ) - { - _tempProfile->setProperty(Profile::ColorScheme,newScheme->name()); - } + _tempProfile->setProperty(Profile::ColorScheme,newScheme->name()); } } } @@ -425,39 +482,8 @@ void EditProfileDialog::colorSchemeSelected() void EditProfileDialog::setupKeyboardPage(const Profile* info) { // setup translator list - const QString& name = SessionManager::instance()->profile(_profileKey)->property(Profile::KeyBindings) - .value(); - - - const KeyboardTranslator* currentTranslator = KeyboardTranslatorManager::instance()->findTranslator(name); - - qDebug() << "Current translator = " << currentTranslator << ", name: " << name; - - QStandardItemModel* model = new QStandardItemModel(this); - - QList translatorNames = KeyboardTranslatorManager::instance()->allTranslators(); - QListIterator iter(translatorNames); - while (iter.hasNext()) - { - const QString& name = iter.next(); - - const KeyboardTranslator* translator = KeyboardTranslatorManager::instance()->findTranslator(name); - - qDebug() << "Translator:" << translator << ", name = " << translator->name() << "description = " << - translator->description(); - - // TODO Use translator->description() here - QStandardItem* item = new QStandardItem(translator->description()); - item->setData(QVariant::fromValue(translator),Qt::UserRole+1); - item->setFlags( item->flags() | Qt::ItemIsUserCheckable ); - - if ( translator == currentTranslator ) - item->setCheckState( Qt::Checked ); - else - item->setCheckState( Qt::Unchecked ); - - model->appendRow(item); - } + + updateKeyBindingsList(); connect( _ui->keyBindingList , SIGNAL(doubleClicked(const QModelIndex&)) , this , SLOT(keyBindingSelected()) ); @@ -469,8 +495,6 @@ void EditProfileDialog::setupKeyboardPage(const Profile* info) SLOT(editKeyBinding()) ); connect( _ui->removeKeyBindingsButton , SIGNAL(clicked()) , this , SLOT(removeKeyBinding()) ); - - _ui->keyBindingList->setModel(model); } void EditProfileDialog::keyBindingSelected() { @@ -507,44 +531,51 @@ void EditProfileDialog::removeKeyBinding() _ui->keyBindingList->model()->removeRow(selected.first().row()); } } -void EditProfileDialog::showKeyBindingEditor(bool newTranslator) +void EditProfileDialog::showKeyBindingEditor(bool isNewTranslator) { QModelIndexList selected = _ui->keyBindingList->selectionModel()->selectedIndexes(); + QAbstractItemModel* model = _ui->keyBindingList->model(); + QModelIndex index; if ( !selected.isEmpty() ) + index = selected.first(); + else + index = model->index(0,0); // Use first item if there is no selection + + + const KeyboardTranslator* translator = model->data(index, + Qt::UserRole+1).value(); + KDialog* dialog = new KDialog(this); + + if ( isNewTranslator ) + dialog->setCaption(i18n("New Key Binding List")); + else + dialog->setCaption(i18n("Edit Key Binding List")); + + KeyBindingEditor* editor = new KeyBindingEditor; + dialog->setMainWidget(editor); + editor->setup(translator); + + if ( isNewTranslator ) + editor->setDescription(i18n("New Key Binding List")); + + if ( dialog->exec() == QDialog::Accepted ) { - QAbstractItemModel* model = _ui->keyBindingList->model(); - QModelIndex index = selected.first(); + KeyboardTranslator* newTranslator = new KeyboardTranslator(*editor->translator()); - const KeyboardTranslator* translator = model->data(index, - Qt::UserRole+1).value(); - KDialog* dialog = new KDialog(this); + if ( isNewTranslator ) + newTranslator->setName(newTranslator->description()); - if ( newTranslator ) - dialog->setCaption(i18n("New Key Binding List")); - else - dialog->setCaption(i18n("Edit Key Binding List")); + KeyboardTranslatorManager::instance()->addTranslator( newTranslator ); - KeyBindingEditor* editor = new KeyBindingEditor; - dialog->setMainWidget(editor); - editor->setup(translator); + updateKeyBindingsList(); + + const QString& currentTranslator = SessionManager::instance()->profile(_profileKey) + ->property(Profile::KeyBindings).value(); - if ( dialog->exec() == QDialog::Accepted ) + if ( newTranslator->name() == currentTranslator ) { - KeyboardTranslator* newTranslator = new KeyboardTranslator(*editor->translator()); - KeyboardTranslatorManager::instance()->addTranslator( newTranslator ); - - model->setData(index,QVariant::fromValue((const KeyboardTranslator*)newTranslator) - , Qt::UserRole+1); - model->setData(index,newTranslator->description(),Qt::DisplayRole); - - const QString& currentTranslator = SessionManager::instance()->profile(_profileKey) - ->property(Profile::KeyBindings).value(); - - if ( newTranslator->name() == currentTranslator ) - { - _tempProfile->setProperty(Profile::KeyBindings,newTranslator->name()); - } + _tempProfile->setProperty(Profile::KeyBindings,newTranslator->name()); } } } diff --git a/src/EditProfileDialog.h b/src/EditProfileDialog.h index 867bfe4f9..a0c4910a5 100644 --- a/src/EditProfileDialog.h +++ b/src/EditProfileDialog.h @@ -143,6 +143,9 @@ private: void setupScrollingPage(const Profile* info); void setupAdvancedPage(const Profile* info); + void updateColorSchemeList(); + void updateKeyBindingsList(); + void showColorSchemeEditor(bool newScheme); void showKeyBindingEditor(bool newTranslator); diff --git a/src/KeyBindingEditor.cpp b/src/KeyBindingEditor.cpp index 392bb2b51..f2eb22707 100644 --- a/src/KeyBindingEditor.cpp +++ b/src/KeyBindingEditor.cpp @@ -34,6 +34,9 @@ KeyBindingEditor::KeyBindingEditor(QWidget* parent) _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); @@ -50,6 +53,21 @@ KeyBindingEditor::~KeyBindingEditor() delete _ui; } +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 ) diff --git a/src/KeyBindingEditor.h b/src/KeyBindingEditor.h index ca021b190..88c991e20 100644 --- a/src/KeyBindingEditor.h +++ b/src/KeyBindingEditor.h @@ -45,6 +45,11 @@ public: KeyboardTranslator* translator() const; + QString description() const; + +public slots: + void setDescription(const QString& description); + private: void setupKeyBindingTable(const KeyboardTranslator* translator); diff --git a/src/KeyboardTranslator.cpp b/src/KeyboardTranslator.cpp index cfb7dcc8e..8538b45ed 100644 --- a/src/KeyboardTranslator.cpp +++ b/src/KeyboardTranslator.cpp @@ -442,6 +442,10 @@ QString KeyboardTranslator::description() const { return _description; } +void KeyboardTranslator::setName(const QString& name) +{ + _name = name; +} QString KeyboardTranslator::name() const { return _name; diff --git a/src/KeyboardTranslator.h b/src/KeyboardTranslator.h index 9fdb7687b..904888635 100644 --- a/src/KeyboardTranslator.h +++ b/src/KeyboardTranslator.h @@ -171,6 +171,9 @@ public: /** Returns the name of this keyboard translator */ QString name() const; + /** Sets the name of this keyboard translator */ + void setName(const QString& name); + /** Returns the descriptive name of this keyboard translator */ QString description() const; @@ -203,7 +206,7 @@ private: QMultiHash _entries; // entries in this keyboard translation, // entries are indexed according to // their keycode - const QString _name; + QString _name; QString _description; };