Commit ff4f2cc7 authored by Cyrille Berger's avatar Cyrille Berger

* initial work on a model for the bookmarked configuration manager, extended...

* initial work on a model for the bookmarked configuration manager, extended with a model for filters
* use the model in the filter dialog
* create a bookmark manager for each filter, it should be override by filters creating their own configuration objects

svn path=/trunk/koffice/; revision=689012
parent 60967fb5
......@@ -73,7 +73,16 @@ QList<QString> KisBookmarkedConfigurationManager::configurations() const
{
KSharedConfig::Ptr cfg = KGlobal::config();
QMap< QString, QString > m = cfg->entryMap(configEntryGroup());
return m.keys();
QList<QString> keys = m.keys();
QList<QString> configsKey;
foreach(QString key, keys)
{
if(key != ConfigDefault.id() and key != ConfigLastUsed.id())
{
configsKey << key;
}
}
return configsKey;
}
KisSerializableConfiguration* KisBookmarkedConfigurationManager::defaultConfiguration()
......
......@@ -51,6 +51,7 @@ KisFilter::KisFilter(const KoID& id, const KoID & category, const QString & entr
, m_category(category)
, m_entry(entry)
{
setBookmarkManager(new KisBookmarkedConfigurationManager(configEntryGroup(), new KisFilterConfigurationFactory(id.id(), 1) ));
}
KisFilterConfiguration * KisFilter::designerConfiguration(const KisPaintDeviceSP)
......@@ -185,4 +186,10 @@ KisBookmarkedConfigurationManager* KisFilter::bookmarkManager()
return d->bookmarkManager;
}
void KisFilter::setBookmarkManager(KisBookmarkedConfigurationManager* bm)
{
delete d->bookmarkManager;
d->bookmarkManager = bm;
}
#include "kis_filter.moc"
......@@ -211,7 +211,7 @@ protected:
void setBookmarkManager(KisBookmarkedConfigurationManager* );
/// @return the name of config group in KConfig
// inline QString configEntryGroup() { return id() + "_filter_bookmarks"; }
inline QString configEntryGroup() { return id() + "_filter_bookmarks"; }
/// @return the default configuration as defined by whoever wrote the plugin
virtual KisFilterConfiguration* designerConfiguration(const KisPaintDeviceSP); // FIXME: this name sucks so much
......
......@@ -94,7 +94,7 @@ private:
Private* const d;
};
class KisFilterConfigurationFactory : public KisSerializableConfigurationFactory {
class KRITAIMAGE_EXPORT KisFilterConfigurationFactory : public KisSerializableConfigurationFactory {
public:
KisFilterConfigurationFactory(const QString & name, qint32 version);
virtual ~KisFilterConfigurationFactory();
......
......@@ -32,25 +32,6 @@
#include "kis_wdg_blur.h"
#include "ui_wdgblur.h"
// KisKernelSP kernelFromQImage(const QImage& img)
// {
// KisKernelSP k = new KisKernel;
// k->width = img.width();
// k->height = img.height();
// k->offset = 0;
// uint count = k->width * k->height;
// k->data = new qint32[count];
// qint32* itData = k->data;
// quint8* itImg = img.bits();
// k->factor = 0;
// for(uint i = 0; i < count; ++i , ++itData, itImg+=4)
// {
// *itData = 255 - ( *itImg + *(itImg+1) + *(itImg+2) ) / 3;
// k->factor += *itData;
// }
// return k;
// }
KisBlurFilter::KisBlurFilter() : KisFilter(id(), CategoryBlur, i18n("&Blur..."))
{
}
......
......@@ -20,6 +20,8 @@ set(kritaui_LIB_SRCS
kis_autobrush.cc
kis_autogradient.cc
kis_birdeye_box.cc
kis_bookmarked_filter_configurations_model.cc
kis_bookmarked_configurations_model.cc
kis_boundary_painter.cc
kis_brush_chooser.cc
kis_canvas2.cpp
......
/*
* Copyright (c) 2007 Cyrille Berger <cberger@cberger.net>
*
* 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.
*/
#include "kis_bookmarked_configurations_model.h"
#include <QList>
#include <KoID.h>
#include <kis_bookmarked_configuration_manager.h>
struct KisBookmarkedConfigurationsModel::Private
{
KisBookmarkedConfigurationManager* bookmarkManager;
QList<QString> configsKey;
};
KisBookmarkedConfigurationsModel::KisBookmarkedConfigurationsModel(KisBookmarkedConfigurationManager* bm) : d(new Private)
{
d->bookmarkManager = bm;
d->configsKey = d->bookmarkManager->configurations();
qSort( d->configsKey );
}
KisBookmarkedConfigurationsModel::~KisBookmarkedConfigurationsModel()
{
delete d;
}
int KisBookmarkedConfigurationsModel::rowCount(const QModelIndex &parent ) const
{
return 2 + d->configsKey.size();
}
QVariant KisBookmarkedConfigurationsModel::data(const QModelIndex &index, int role) const
{
if(not index.isValid())
{
return QVariant();
}
if(role == Qt::DisplayRole)
{
switch(index.row())
{
case 0:
return KisBookmarkedConfigurationManager::ConfigDefault.name();
case 1:
return KisBookmarkedConfigurationManager::ConfigLastUsed.name();
default:
return d->configsKey[ index.row() - 2 ];
}
}
return QVariant();
}
KisSerializableConfiguration* KisBookmarkedConfigurationsModel::configuration(const QModelIndex &index) const
{
return 0;
}
/*
* Copyright (c) 2007 Cyrille Berger <cberger@cberger.net>
*
* 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.
*/
#ifndef _KIS_BOOKMARKED_CONFIGURATIONS_MODEL_H_
#define _KIS_BOOKMARKED_CONFIGURATIONS_MODEL_H_
#include <QAbstractListModel>
class KisBookmarkedConfigurationManager;
class KisSerializableConfiguration;
class KisBookmarkedConfigurationsModel : public QAbstractListModel {
public:
KisBookmarkedConfigurationsModel(KisBookmarkedConfigurationManager*);
~KisBookmarkedConfigurationsModel();
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
KisSerializableConfiguration* configuration(const QModelIndex &index) const;
private:
struct Private;
Private* const d;
};
#endif
/*
* Copyright (c) 2007 Cyrille Berger <cberger@cberger.net>
*
* 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.
*/
#include "kis_bookmarked_filter_configurations_model.h"
#include <QPixmap>
#include <kis_filter.h>
#include <kis_filter_configuration.h>
#include <kis_paint_device.h>
struct KisBookmarkedFilterConfigurationsModel::Private {
KisPaintDeviceSP thumb;
KisFilterSP filter;
};
KisBookmarkedFilterConfigurationsModel::KisBookmarkedFilterConfigurationsModel(KisPaintDeviceSP thumb, KisFilterSP filter)
: KisBookmarkedConfigurationsModel(filter->bookmarkManager()), d(new Private)
{
d->thumb = thumb;
d->filter = filter;
}
KisBookmarkedFilterConfigurationsModel::~KisBookmarkedFilterConfigurationsModel()
{
delete d;
}
QVariant KisBookmarkedFilterConfigurationsModel::data(const QModelIndex &index, int role) const
{
if(not index.isValid())
{
return QVariant();
}
if(role == Qt::DecorationRole)
{
QImage pm(100,100, QImage::Format_ARGB32);
KisPaintDeviceSP target = new KisPaintDevice(*d->thumb);
d->filter->process(target, QRect(0,0,100,100), configuration(index));
return target->convertToQImage(0,0.0);
} else {
return KisBookmarkedConfigurationsModel::data(index, role);
}
}
KisFilterConfiguration* KisBookmarkedFilterConfigurationsModel::configuration(const QModelIndex &index) const
{
KisFilterConfiguration* config = dynamic_cast<KisFilterConfiguration*>(KisBookmarkedConfigurationsModel::configuration(index));
if(config) return config;
return d->filter->defaultConfiguration( d->thumb );
}
/*
* Copyright (c) 2007 Cyrille Berger <cberger@cberger.net>
*
* 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.
*/
#ifndef _KIS_BOOKMARKED_FILTER_CONFIGURATIONS_MODEL_H_
#define _KIS_BOOKMARKED_FILTER_CONFIGURATIONS_MODEL_H_
#include "kis_bookmarked_configurations_model.h"
#include "kis_types.h"
class KisFilterConfiguration;
class KisBookmarkedFilterConfigurationsModel : public KisBookmarkedConfigurationsModel {
public:
KisBookmarkedFilterConfigurationsModel(KisPaintDeviceSP thumb, KisFilterSP filter);
~KisBookmarkedFilterConfigurationsModel();
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
KisFilterConfiguration* configuration(const QModelIndex &index) const;
private:
struct Private;
Private* const d;
};
#endif
......@@ -19,10 +19,14 @@
#include "kis_filter_dialog.h"
#include "kis_filter.h"
#include "kis_filter_config_widget.h"
#include "kis_filter_mask.h"
#include "kis_layer.h"
// From krita/image
#include <kis_filter.h>
#include <kis_filter_config_widget.h>
#include <kis_filter_mask.h>
#include <kis_layer.h>
// From krita/ui
#include "kis_bookmarked_filter_configurations_model.h"
#include "ui_wdgfilterdialog.h"
......@@ -40,6 +44,7 @@ struct KisFilterDialog::Private {
KisFilterConfigWidget* currentFilterConfigurationWidget;
KisFilterSP currentFilter;
KisLayerSP layer;
KisPaintDeviceSP thumb;
Ui_FilterDialog uiFilterDialog;
KisFilterMaskSP mask;
QGridLayout *widgetLayout;
......@@ -53,6 +58,7 @@ KisFilterDialog::KisFilterDialog(QWidget* parent, KisLayerSP layer ) :
d->uiFilterDialog.setupUi( this );
d->widgetLayout = new QGridLayout( d->uiFilterDialog.centralWidgetHolder );
d->layer = layer;
d->thumb = layer->paintDevice()->createThumbnailDevice(100, 100);
d->mask = new KisFilterMask();
d->layer->setPreviewMask( d->mask );
connect(d->uiFilterDialog.pushButtonOk, SIGNAL(pressed ()), SLOT(accept()));
......@@ -81,6 +87,7 @@ void KisFilterDialog::setFilter(KisFilterSP f)
d->currentFilterConfigurationWidget->setConfiguration( d->currentFilter->defaultConfiguration( d->layer->paintDevice() ) );
connect(d->currentFilterConfigurationWidget, SIGNAL(sigPleaseUpdatePreview()), SLOT(updatePreview()));
}
d->uiFilterDialog.comboBoxPresets->setModel( new KisBookmarkedFilterConfigurationsModel(d->thumb, f ) );
d->widgetLayout->addWidget( d->currentCentralWidget, 0 , 0);
d->uiFilterDialog.centralWidgetHolder->setMinimumSize( d->currentCentralWidget->minimumSize() );
updatePreview();
......
......@@ -136,6 +136,9 @@
<property name="text" >
<string>Ok</string>
</property>
<property name="default" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment