diff --git a/libs/ui/widgets/kis_wdg_generator.cpp b/libs/ui/widgets/kis_wdg_generator.cpp index 75c3d25530..8c00b90bbc 100644 --- a/libs/ui/widgets/kis_wdg_generator.cpp +++ b/libs/ui/widgets/kis_wdg_generator.cpp @@ -1,197 +1,187 @@ /* 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 #include "ui_wdggenerators.h" class KisGeneratorItem : public QListWidgetItem { public: KisGeneratorItem(KisGeneratorSP _generator, QListWidget *parent = 0, int type = Type) : QListWidgetItem(_generator->name(), parent, type) , generator(_generator) { currentConfiguration = generator->defaultConfiguration(KisGlobalResourcesInterface::instance()); } 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()) { KisPaintDeviceSP dev = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8(0)); } KisWdgGenerator::~KisWdgGenerator() { 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); } 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! - activateGenerator(i, config); - d->uiWdgGenerators.lstGenerators->blockSignals(true); + slotGeneratorActivated(i); d->uiWdgGenerators.lstGenerators->setCurrentRow(i); - d->uiWdgGenerators.lstGenerators->blockSignals(false); + 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(KisGlobalResourcesInterface::instance()); } return 0; } void KisWdgGenerator::slotGeneratorActivated(int row) -{ - // Retrieve the new configuration - KisGeneratorItem * item = static_cast(d->uiWdgGenerators.lstGenerators->item(row)); - KisFilterConfigurationSP config = static_cast(item->currentConfiguration.data()); - - activateGenerator(row, config); -} - -void KisWdgGenerator::activateGenerator(int row, const KisFilterConfigurationSP config) { // 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(); - break; } } } + // 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); 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); - - if (config) { - widget->setConfiguration(config); - } + widget->setConfiguration(item->currentConfiguration); } } d->widgetLayout->addWidget(d->centralWidget, 0 , 0); d->uiWdgGenerators.centralWidgetHolder->setMinimumSize(d->centralWidget->minimumSize()); } diff --git a/libs/ui/widgets/kis_wdg_generator.h b/libs/ui/widgets/kis_wdg_generator.h index 774a1c4f9c..e62872cea4 100644 --- a/libs/ui/widgets/kis_wdg_generator.h +++ b/libs/ui/widgets/kis_wdg_generator.h @@ -1,69 +1,67 @@ /* 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. */ #ifndef KIS_WDG_GENERATOR_H #define KIS_WDG_GENERATOR_H #include #include class KisFilterConfiguration; class KisViewManager; class KoColor; /** * A widget that allows users to select a generator and * create a config object for it. * * XXX: make use of bookmarked configuration things, like * in the filter widget. */ class KisWdgGenerator : public QWidget { Q_OBJECT public: KisWdgGenerator(QWidget * parent); KisWdgGenerator(QWidget * parent, KisPaintDeviceSP dev); ~KisWdgGenerator() override; void initialize(KisViewManager *view); void setConfiguration(const KisFilterConfigurationSP config); KisFilterConfigurationSP configuration(); Q_SIGNALS: void previewConfiguration(); private Q_SLOTS: void slotGeneratorActivated(int); private: struct Private; Private * const d; - - void activateGenerator(int row, const KisFilterConfigurationSP config); }; #endif