diff --git a/libs/ui/dialogs/kis_dlg_generator_layer.cpp b/libs/ui/dialogs/kis_dlg_generator_layer.cpp index d4819e6bef..04145a6e00 100644 --- a/libs/ui/dialogs/kis_dlg_generator_layer.cpp +++ b/libs/ui/dialogs/kis_dlg_generator_layer.cpp @@ -1,128 +1,130 @@ /* This file is part of the KDE project * Copyright (C) Boudewijn Rempt , (C) 2008 * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "kis_dlg_generator_layer.h" #include #include #include #include #include #include #include #include #include #include #include #include #include KisDlgGeneratorLayer::KisDlgGeneratorLayer(const QString & defaultName, KisViewManager *view, QWidget *parent, KisGeneratorLayerSP glayer = 0, const KisFilterConfigurationSP previousConfig = 0) : KoDialog(parent) , m_customName(false) , m_freezeName(false) { setButtons(Ok | Cancel); setDefaultButton(Ok); isEditing = glayer && previousConfig; if(isEditing){ setModal(false); layer = glayer; configBefore = previousConfig; } QWidget *page = new QWidget(this); m_view = view; dlgWidget.setupUi(page); dlgWidget.wdgGenerator->initialize(m_view); setMainWidget(page); dlgWidget.txtLayerName->setText( isEditing ? layer->name() : defaultName ); connect(dlgWidget.txtLayerName, SIGNAL(textChanged(QString)), this, SLOT(slotNameChanged(QString))); connect(dlgWidget.wdgGenerator, SIGNAL(previewConfiguration()), this, SLOT(previewGenerator())); } KisDlgGeneratorLayer::~KisDlgGeneratorLayer() { - /*Editing a layer should be using the show function with automatic deletion on close. - *Because of this, the action should be taken care of when the window is closed and - *the user has accepted the changes.*/ - if(isEditing && result() == QDialog::Accepted) { + /* + * Editing a layer should be using the show function with automatic deletion on close. + * Because of this, the action should be taken care of when the window is closed and + * the user has accepted the changes. + */ + if (isEditing && result() == QDialog::Accepted) { layer->setName(layerName()); KisFilterConfigurationSP configAfter(configuration()); Q_ASSERT(configAfter); QString xmlBefore = configBefore->toXML(); QString xmlAfter = configAfter->toXML(); if (xmlBefore != xmlAfter) { KisChangeFilterCmd *cmd = new KisChangeFilterCmd(layer, configBefore->name(), xmlBefore, configAfter->name(), xmlAfter, true); m_view->undoAdapter()->addCommand(cmd); m_view->document()->setModified(true); } } - else if(isEditing && result() == QDialog::Rejected){ + else if (isEditing && result() == QDialog::Rejected){ layer->setFilter(configBefore); } } void KisDlgGeneratorLayer::slotNameChanged(const QString & text) { if (m_freezeName) return; m_customName = !text.isEmpty(); enableButtonOk(m_customName); } void KisDlgGeneratorLayer::previewGenerator() { if (isEditing && layer) layer->setFilter(configuration()); } void KisDlgGeneratorLayer::setConfiguration(const KisFilterConfigurationSP config) { dlgWidget.wdgGenerator->setConfiguration(config); } KisFilterConfigurationSP KisDlgGeneratorLayer::configuration() const { return dlgWidget.wdgGenerator->configuration(); } QString KisDlgGeneratorLayer::layerName() const { return dlgWidget.txtLayerName->text(); } diff --git a/libs/ui/widgets/kis_wdg_generator.cpp b/libs/ui/widgets/kis_wdg_generator.cpp index 7c0d5d429a..efce77504c 100644 --- a/libs/ui/widgets/kis_wdg_generator.cpp +++ b/libs/ui/widgets/kis_wdg_generator.cpp @@ -1,174 +1,186 @@ /* This file is part of the KDE project + * * Copyright (C) Boudewijn Rempt , (C) 2008 * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "widgets/kis_wdg_generator.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include "ui_wdggenerators.h" class KisGeneratorItem : public QListWidgetItem { public: - KisGeneratorItem(const QString & text, QListWidget * parent = 0, int type = Type) - : QListWidgetItem(text, parent, type) { + KisGeneratorItem(KisGeneratorSP _generator, QListWidget *parent = 0, int type = Type) + : QListWidgetItem(_generator->name(), parent, type) + , generator(_generator) + { + currentConfiguration = generator->defaultConfiguration(); } KisGeneratorSP generator; - + KisPropertiesConfigurationSP currentConfiguration; }; struct KisWdgGenerator::Private { public: Private() : centralWidget(0), view(0) { } QWidget * centralWidget; // Active generator settings widget KisGeneratorSP currentGenerator; Ui_WdgGenerators uiWdgGenerators; KisPaintDeviceSP dev; QGridLayout *widgetLayout; KisViewManager *view; }; KisWdgGenerator::KisWdgGenerator(QWidget * parent) - : QWidget(parent) - , d(new Private()) + : QWidget(parent) + , d(new Private()) { KisPaintDeviceSP dev = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8(0)); } KisWdgGenerator::~KisWdgGenerator() { - delete d; + delete d; } void KisWdgGenerator::initialize(KisViewManager *view) { d->view = view; d->uiWdgGenerators.setupUi(this); d->widgetLayout = new QGridLayout(d->uiWdgGenerators.centralWidgetHolder); QStringList generatorNames = KisGeneratorRegistry::instance()->keys(); generatorNames.sort(); Q_FOREACH (const QString &generatorName, generatorNames) { KisGeneratorSP generator = KisGeneratorRegistry::instance()->get(generatorName); + // The item is automatically added to the lstGenerators listwidget + new KisGeneratorItem(generator, + d->uiWdgGenerators.lstGenerators, + QListWidgetItem::UserType + 1); - Q_ASSERT(generator); - KisGeneratorItem * item = new KisGeneratorItem(generator->name(), - d->uiWdgGenerators.lstGenerators, - QListWidgetItem::UserType + 1); - - item->generator = generator; } connect(d->uiWdgGenerators.lstGenerators, SIGNAL(currentRowChanged(int)), this, SLOT(slotGeneratorActivated(int))); if (d->uiWdgGenerators.lstGenerators->count() > 0) { d->uiWdgGenerators.lstGenerators->setCurrentRow(0); } } void KisWdgGenerator::setConfiguration(const KisFilterConfigurationSP config) { for (int i = 0; i < d->uiWdgGenerators.lstGenerators->count(); ++i) { KisGeneratorItem * item = static_cast(d->uiWdgGenerators.lstGenerators->item(i)); if (item->generator->id() == config->name()) { // match! slotGeneratorActivated(i); d->uiWdgGenerators.lstGenerators->setCurrentRow(i); KisConfigWidget * wdg = dynamic_cast(d->centralWidget); if (wdg) { wdg->setConfiguration(config); } return; } } } KisFilterConfigurationSP KisWdgGenerator::configuration() { KisConfigWidget * wdg = dynamic_cast(d->centralWidget); if (wdg) { KisFilterConfigurationSP config = dynamic_cast(wdg->configuration().data()); if (config) { return config; } } else { return d->currentGenerator->defaultConfiguration(); } return 0; } + void KisWdgGenerator::slotGeneratorActivated(int row) { + // Store the old settings + KisConfigWidget *wdg = dynamic_cast(d->centralWidget); + if (wdg) { + KisPropertiesConfigurationSP config = wdg->configuration(); + for (int i = 0; i < d->uiWdgGenerators.lstGenerators->count(); ++i) { + KisGeneratorItem * item = static_cast(d->uiWdgGenerators.lstGenerators->item(i)); + if (item->generator->id() == static_cast(config.data())->name()) { + item->currentConfiguration = wdg->configuration(); + } + } + } + + // Retrieve the new configuration KisGeneratorItem *item = dynamic_cast(d->uiWdgGenerators.lstGenerators->item(row)); if (!item) { d->centralWidget = new QLabel(i18n("No configuration options."), d->uiWdgGenerators.centralWidgetHolder); } else { d->currentGenerator = item->generator; delete d->centralWidget; KisConfigWidget* widget = - d->currentGenerator->createConfigurationWidget(d->uiWdgGenerators.centralWidgetHolder, d->dev, true); + d->currentGenerator->createConfigurationWidget(d->uiWdgGenerators.centralWidgetHolder, d->dev, true); if (!widget) { // No widget, so display a label instead d->centralWidget = new QLabel(i18n("No configuration options."), d->uiWdgGenerators.centralWidgetHolder); } else { d->centralWidget = widget; connect( widget, SIGNAL(sigConfigurationUpdated()), this, SIGNAL(previewConfiguration())); widget->setView(d->view); - widget->setConfiguration(d->currentGenerator->defaultConfiguration()); + widget->setConfiguration(item->currentConfiguration); } } d->widgetLayout->addWidget(d->centralWidget, 0 , 0); d->uiWdgGenerators.centralWidgetHolder->setMinimumSize(d->centralWidget->minimumSize()); - - } - -