Commit 67cb7af0 authored by Halla Rempt's avatar Halla Rempt
Browse files

Krita starts up again, and the first part of moving the timer for

autopreview for filters ot the filtermanager instead of individual
widgets.

svn path=/trunk/koffice/; revision=603087
parent f9b97ccb
......@@ -20,6 +20,8 @@
#include <QWidget>
#include <kdebug.h>
#include <KoUnit.h>
#include <KoViewConverter.h>
#include <KoShapeManager.h>
......@@ -31,6 +33,7 @@
#include "kis_abstract_canvas_widget.h"
#include "kis_qpainter_canvas.h"
#include "kis_opengl_canvas2.h"
#include "kis_dummy_shape.h"
class KisCanvas2::KisCanvas2Private {
......@@ -42,6 +45,7 @@ public:
, canvasWidget( 0 )
, shapeManager( new KoShapeManager(parent) )
{
kDebug() << ">>>>>>>>>>>>> " << shapeManager << endl;
}
~KisCanvas2Private()
......@@ -60,7 +64,6 @@ KisCanvas2::KisCanvas2(KoViewConverter * viewConverter, KisCanvasType canvasType
{
m_d = new KisCanvas2Private(this, viewConverter, view);
switch( canvasType ) {
case OPENGL:
setCanvasWidget( new KisOpenGLCanvas2( this, view ) );
......@@ -79,7 +82,6 @@ void KisCanvas2::setCanvasWidget(QWidget * widget)
m_d->canvasWidget = tmp;
}
KisCanvas2::~KisCanvas2()
{
delete m_d;
......@@ -105,7 +107,7 @@ void KisCanvas2::addCommand(KCommand *command, bool execute)
KoShapeManager* KisCanvas2::shapeManager() const
{
return 0;
return m_d->shapeManager;
}
......
......@@ -28,6 +28,8 @@
class KisView2;
class KoToolProxy;
class KisDummyShape;
enum KisCanvasType {
QPAINTER,
OPENGL,
......@@ -77,7 +79,7 @@ public: // KoCanvasBase implementation
virtual QWidget* canvasWidget();
virtual KoUnit::Unit unit();
virtual KoToolProxy* toolProxy();
public: // KisCanvas2 methods
......
......@@ -28,7 +28,6 @@
#include <QFrame>
#include <QWidget>
#include <QEvent>
#include <QTimer>
#include <QHBoxLayout>
#include <QKeyEvent>
#include <QMenu>
......
......@@ -28,7 +28,6 @@
#include <ktoolbar.h>
class QWidget;
class QTimer;
class QTabWidget;
class KToolBar;
......
......@@ -19,6 +19,7 @@
#include "qsignalmapper.h"
#include <QLayout>
#include <QFrame>
#include <QTimer>
#include <QCursor>
#include <QApplication>
#include <QGridLayout>
......@@ -48,29 +49,64 @@
#include "kis_view2.h"
#include <kis_progress_display_interface.h>
class KisFilterManager::KisFilterManagerPrivate {
public:
KisView2 * view;
KisDoc2 * doc;
KAction * reapplyAction;
Q3PtrList<KAction> filterActions;
KisFilterConfiguration * lastFilterConfig;
KisFilter * lastFilter;
KisPreviewDialog * lastDialog;
KisFilterConfigWidget * lastWidget;
QList<KoID> filterList; // Map the actions in the signalmapper to the filters
QSignalMapper * filterMapper;
Q3Dict<KActionMenu> filterActionMenus;
QTimer * timer;
~KisFilterManagerPrivate()
{
//delete m_d->reapplyAction;
//delete m_d->lastFilterConfig;
//delete m_d->filterMapper;
delete timer;
}
};
KisFilterManager::KisFilterManager(KisView2 * view, KisDoc2 * doc)
: m_view(view),
m_doc(doc)
{
// XXX: Store & restore last filter & last filter configuration in session settings
m_reapplyAction = 0;
m_lastFilterConfig = 0;
m_lastDialog = 0;
m_lastFilter = 0;
m_lastWidget = 0;
m_d = new KisFilterManagerPrivate();
m_d->view = view;
m_d->doc = doc;
m_filterMapper = new QSignalMapper(this);
// XXX: Store & restore last filter & last filter configuration in session settings
m_d->reapplyAction = 0;
m_d->lastFilterConfig = 0;
m_d->lastDialog = 0;
m_d->lastFilter = 0;
m_d->lastWidget = 0;
connect(m_filterMapper, SIGNAL(mapped(int)), this, SLOT(slotApplyFilter(int)));
m_d->filterMapper = new QSignalMapper(this);
m_d->timer = new QTimer( this );
m_d->timer->setSingleShot( true );
connect( m_d->timer, SIGNAL( timeout() ), this, SLOT(slotDelayedRefreshPreview()) );
connect(m_d->filterMapper, SIGNAL(mapped(int)), this, SLOT(slotApplyFilter(int)));
setup( view->actionCollection() );
}
KisFilterManager::~KisFilterManager()
{
//delete m_reapplyAction;
//delete m_lastFilterConfig;
//delete m_filterMapper;
delete m_d;
}
void KisFilterManager::setup(KActionCollection * ac)
......@@ -84,112 +120,112 @@ void KisFilterManager::setup(KActionCollection * ac)
KActionMenu * other = 0;
KActionMenu * am = 0;
m_filterList = KisFilterRegistry::instance()->listKeys();
m_d->filterList = KisFilterRegistry::instance()->listKeys();
for ( QList<KoID>::Iterator it = m_filterList.begin(); it != m_filterList.end(); ++it ) {
for ( QList<KoID>::Iterator it = m_d->filterList.begin(); it != m_d->filterList.end(); ++it ) {
f = KisFilterRegistry::instance()->get(*it);
if (!f) break;
QString s = f->menuCategory();
if (s == "adjust" && !m_filterActionMenus.find("adjust")) {
if (s == "adjust" && !m_d->filterActionMenus.find("adjust")) {
am = new KActionMenu(i18n("Adjust"), ac, "adjust_filters");
m_filterActionMenus.insert("adjust", am);
m_d->filterActionMenus.insert("adjust", am);
}
else if (s == "artistic" && !m_filterActionMenus.find("artistic")) {
else if (s == "artistic" && !m_d->filterActionMenus.find("artistic")) {
am = new KActionMenu(i18n("Artistic"), ac, "artistic_filters");
m_filterActionMenus.insert("artistic", am);
m_d->filterActionMenus.insert("artistic", am);
}
else if (s == "blur" && !m_filterActionMenus.find("blur")) {
else if (s == "blur" && !m_d->filterActionMenus.find("blur")) {
am = new KActionMenu(i18n("Blur"), ac, "blur_filters");
m_filterActionMenus.insert("blur", am);
m_d->filterActionMenus.insert("blur", am);
}
else if (s == "colors" && !m_filterActionMenus.find("colors")) {
else if (s == "colors" && !m_d->filterActionMenus.find("colors")) {
am = new KActionMenu(i18n("Colors"), ac, "color_filters");
m_filterActionMenus.insert("colors", am);
m_d->filterActionMenus.insert("colors", am);
}
else if (s == "decor" && !m_filterActionMenus.find("decor")) {
else if (s == "decor" && !m_d->filterActionMenus.find("decor")) {
am = new KActionMenu(i18n("Decor"), ac, "decor_filters");
m_filterActionMenus.insert("decor", am);
m_d->filterActionMenus.insert("decor", am);
}
else if (s == "edge" && !m_filterActionMenus.find("edge")) {
else if (s == "edge" && !m_d->filterActionMenus.find("edge")) {
am = new KActionMenu(i18n("Edge Detection"), ac, "edge_filters");
m_filterActionMenus.insert("edge", am);
m_d->filterActionMenus.insert("edge", am);
}
else if (s == "emboss" && !m_filterActionMenus.find("emboss")) {
else if (s == "emboss" && !m_d->filterActionMenus.find("emboss")) {
am = new KActionMenu(i18n("Emboss"), ac, "emboss_filters");
m_filterActionMenus.insert("emboss", am);
m_d->filterActionMenus.insert("emboss", am);
}
else if (s == "enhance" && !m_filterActionMenus.find("enhance")) {
else if (s == "enhance" && !m_d->filterActionMenus.find("enhance")) {
am = new KActionMenu(i18n("Enhance"), ac, "enhance_filters");
m_filterActionMenus.insert("enhance", am);
m_d->filterActionMenus.insert("enhance", am);
}
else if (s == "map" && !m_filterActionMenus.find("map")) {
else if (s == "map" && !m_d->filterActionMenus.find("map")) {
am = new KActionMenu(i18n("Map"), ac, "map_filters");
m_filterActionMenus.insert("map", am);
m_d->filterActionMenus.insert("map", am);
}
else if (s == "nonphotorealistic" && !m_filterActionMenus.find("nonphotorealistic")) {
else if (s == "nonphotorealistic" && !m_d->filterActionMenus.find("nonphotorealistic")) {
am = new KActionMenu(i18n("Non-photorealistic"), ac, "nonphotorealistic_filters");
m_filterActionMenus.insert("nonphotorealistic", am);
m_d->filterActionMenus.insert("nonphotorealistic", am);
}
else if (s == "other" && !m_filterActionMenus.find("other")) {
else if (s == "other" && !m_d->filterActionMenus.find("other")) {
other = new KActionMenu(i18n("Other"), ac, "misc_filters");
m_filterActionMenus.insert("other", am);
m_d->filterActionMenus.insert("other", am);
}
}
m_reapplyAction = new KAction(i18n("Apply Filter Again"), ac, "filter_apply_again");
m_reapplyAction->setShortcut(Qt::CTRL+Qt::SHIFT+Qt::Key_F);
connect(m_reapplyAction, SIGNAL(triggered()), this , SLOT(slotApply()));
m_d->reapplyAction = new KAction(i18n("Apply Filter Again"), ac, "filter_apply_again");
m_d->reapplyAction->setShortcut(Qt::CTRL+Qt::SHIFT+Qt::Key_F);
connect(m_d->reapplyAction, SIGNAL(triggered()), this , SLOT(slotApply()));
m_reapplyAction->setEnabled(false);
m_d->reapplyAction->setEnabled(false);
f = 0;
i = 0;
for ( QList<KoID>::Iterator it = m_filterList.begin(); it != m_filterList.end(); ++it ) {
for ( QList<KoID>::Iterator it = m_d->filterList.begin(); it != m_d->filterList.end(); ++it ) {
f = KisFilterRegistry::instance()->get(*it);
if (!f) break;
// Create action
KAction * a = new KAction(f->menuEntry(), ac, QString("krita_filter_%1").arg((*it).id()).toAscii());
connect(a, SIGNAL(triggered()), m_filterMapper, SLOT(map()));
connect(a, SIGNAL(triggered()), m_d->filterMapper, SLOT(map()));
// Add action to the right submenu
KActionMenu * m = m_filterActionMenus.find( f->menuCategory() );
KActionMenu * m = m_d->filterActionMenus.find( f->menuCategory() );
if (m) {
m->addAction(a);
}
else {
if (!other) {
other = new KActionMenu(i18n("Other"), ac, "misc_filters");
m_filterActionMenus.insert("other", am);
m_d->filterActionMenus.insert("other", am);
}
other->addAction(a);
}
// Add filter to list of filters for mapper
m_filterMapper->setMapping( a, i );
m_d->filterMapper->setMapping( a, i );
m_filterActions.append( a );
m_d->filterActions.append( a );
++i;
}
}
void KisFilterManager::updateGUI()
{
KisImageSP img = m_view->image();
KisImageSP img = m_d->view->image();
if (!img) return;
KisLayerSP layer = img->activeLayer();
......@@ -203,17 +239,17 @@ void KisFilterManager::updateGUI()
{
enable = false;
}
m_reapplyAction->setEnabled(m_lastFilterConfig);
if (m_lastFilterConfig)
m_reapplyAction->setText(i18n("Apply Filter Again") + ": "
+ KisFilterRegistry::instance()->get(m_lastFilterConfig->name())->id().name());
m_d->reapplyAction->setEnabled(m_d->lastFilterConfig);
if (m_d->lastFilterConfig)
m_d->reapplyAction->setText(i18n("Apply Filter Again") + ": "
+ KisFilterRegistry::instance()->get(m_d->lastFilterConfig->name())->id().name());
else
m_reapplyAction->setText(i18n("Apply Filter Again"));
m_d->reapplyAction->setText(i18n("Apply Filter Again"));
KAction * a;
int i = 0;
for (a = m_filterActions.first(); a; a = m_filterActions.next() , i++) {
KisFilterSP filter = KisFilterRegistry::instance()->get(m_filterList[i]);
for (a = m_d->filterActions.first(); a; a = m_d->filterActions.next() , i++) {
KisFilterSP filter = KisFilterRegistry::instance()->get(m_d->filterList[i]);
if(player && filter->workWith( player->paintDevice()->colorSpace()))
{
a->setEnabled(enable);
......@@ -231,9 +267,9 @@ void KisFilterManager::slotApply()
bool KisFilterManager::apply()
{
if (!m_lastFilter) return false;
if (!m_d->lastFilter) return false;
KisImageSP img = m_view->image();
KisImageSP img = m_d->view->image();
if (!img) return false;
KisPaintDeviceSP dev = img->activeDevice();
......@@ -242,7 +278,7 @@ bool KisFilterManager::apply()
QApplication::setOverrideCursor( Qt::WaitCursor );
//Apply the filter
m_lastFilterConfig = m_lastWidget->configuration();
m_d->lastFilterConfig = m_d->lastWidget->configuration();
QRect r1 = dev->extent();
QRect r2 = img->bounds();
......@@ -255,38 +291,38 @@ bool KisFilterManager::apply()
rect = rect.intersect(r3);
}
m_lastFilter->enableProgress();
m_d->lastFilter->enableProgress();
//m_view->progressDisplay()->setSubject(m_lastFilter, true, true);
//m_lastFilter->setProgressDisplay( m_view->progressDisplay());
//m_d->view->progressDisplay()->setSubject(m_d->lastFilter, true, true);
//m_d->lastFilter->setProgressDisplay( m_d->view->progressDisplay());
KisTransaction * cmd = 0;
if (img->undo()) cmd = new KisTransaction(m_lastFilter->id().name(), dev);
if (img->undo()) cmd = new KisTransaction(m_d->lastFilter->id().name(), dev);
m_lastFilter->process(dev, rect, m_lastFilterConfig);
m_reapplyAction->setEnabled(m_lastFilterConfig);
if (m_lastFilterConfig)
m_reapplyAction->setText(i18n("Apply Filter Again") + ": "
+ KisFilterRegistry::instance()->get(m_lastFilterConfig->name())->id().name());
m_d->lastFilter->process(dev, rect, m_d->lastFilterConfig);
m_d->reapplyAction->setEnabled(m_d->lastFilterConfig);
if (m_d->lastFilterConfig)
m_d->reapplyAction->setText(i18n("Apply Filter Again") + ": "
+ KisFilterRegistry::instance()->get(m_d->lastFilterConfig->name())->id().name());
else
m_reapplyAction->setText(i18n("Apply Filter Again"));
m_d->reapplyAction->setText(i18n("Apply Filter Again"));
if (m_lastFilter->cancelRequested()) {
delete m_lastFilterConfig;
if (m_d->lastFilter->cancelRequested()) {
delete m_d->lastFilterConfig;
if (cmd) {
cmd->unexecute();
delete cmd;
}
m_lastFilter->disableProgress();
m_d->lastFilter->disableProgress();
QApplication::restoreOverrideCursor();
return false;
} else {
if (dev->parentLayer()) dev->parentLayer()->setDirty(rect);
m_doc->setModified(true);
m_d->doc->setModified(true);
if (img->undo() && cmd) img->undoAdapter()->addCommand(cmd);
m_lastFilter->disableProgress();
m_d->lastFilter->disableProgress();
QApplication::restoreOverrideCursor();
return true;
}
......@@ -294,39 +330,39 @@ bool KisFilterManager::apply()
void KisFilterManager::slotApplyFilter(int i)
{
KisPreviewDialog * oldDialog = m_lastDialog;
KisFilterConfiguration * oldConfig = m_lastFilterConfig;
KisFilter * oldFilter = m_lastFilter;
KisPreviewDialog * oldDialog = m_d->lastDialog;
KisFilterConfiguration * oldConfig = m_d->lastFilterConfig;
KisFilter * oldFilter = m_d->lastFilter;
m_lastFilter = KisFilterRegistry::instance()->get(m_filterList[i]).data();
m_d->lastFilter = KisFilterRegistry::instance()->get(m_d->filterList[i]).data();
if (!m_lastFilter) {
m_lastFilter = oldFilter;
if (!m_d->lastFilter) {
m_d->lastFilter = oldFilter;
return;
}
KisImageSP img = m_view->image();
KisImageSP img = m_d->view->image();
if (!img) return;
KisPaintDeviceSP dev = img->activeDevice();
if (!dev) return;
if (dev->colorSpace()->willDegrade(m_lastFilter->colorSpaceIndependence())) {
if (dev->colorSpace()->willDegrade(m_d->lastFilter->colorSpaceIndependence())) {
// Warning bells!
if (m_lastFilter->colorSpaceIndependence() == TO_LAB16) {
if (KMessageBox::warningContinueCancel(m_view,
if (m_d->lastFilter->colorSpaceIndependence() == TO_LAB16) {
if (KMessageBox::warningContinueCancel(m_d->view,
i18n("The %1 filter will convert your %2 data to 16-bit L*a*b* and vice versa. "
, m_lastFilter->id().name()
, m_d->lastFilter->id().name()
, dev->colorSpace()->name()),
i18n("Filter Will Convert Your Layer Data"),
KGuiItem(i18n("Continue")),
"lab16degradation") != KMessageBox::Continue) return;
}
else if (m_lastFilter->colorSpaceIndependence() == TO_RGBA8) {
if (KMessageBox::warningContinueCancel(m_view,
else if (m_d->lastFilter->colorSpaceIndependence() == TO_RGBA8) {
if (KMessageBox::warningContinueCancel(m_d->view,
i18n("The %1 filter will convert your %2 data to 8-bit RGBA and vice versa. "
, m_lastFilter->id().name()
, m_d->lastFilter->id().name()
, dev->colorSpace()->name()),
i18n("Filter Will Convert Your Layer Data"),
KGuiItem(i18n("Continue")),
......@@ -334,76 +370,81 @@ void KisFilterManager::slotApplyFilter(int i)
}
}
m_lastFilter->disableProgress();
m_d->lastFilter->disableProgress();
// Create the config dialog
m_lastDialog = new KisPreviewDialog(m_view, m_lastFilter->id().name().toAscii(), m_lastFilter->id().name());
Q_CHECK_PTR(m_lastDialog);
m_lastWidget = m_lastFilter->createConfigurationWidget( (QWidget*)m_lastDialog->container(), dev );
m_d->lastDialog = new KisPreviewDialog(m_d->view, m_d->lastFilter->id().name().toAscii(), m_d->lastFilter->id().name());
Q_CHECK_PTR(m_d->lastDialog);
m_d->lastWidget = m_d->lastFilter->createConfigurationWidget( (QWidget*)m_d->lastDialog->container(), dev );
if( m_lastWidget != 0)
if( m_d->lastWidget != 0)
{
connect(m_lastWidget, SIGNAL(sigPleaseUpdatePreview()), this, SLOT(slotConfigChanged()));
connect(m_d->lastWidget, SIGNAL(sigPleaseUpdatePreview()), this, SLOT(slotConfigChanged()));
m_lastDialog->previewWidget()->slotSetDevice( dev );
m_d->lastDialog->previewWidget()->slotSetDevice( dev );
connect(m_lastDialog->previewWidget(), SIGNAL(updated()), this, SLOT(refreshPreview()));
connect(m_d->lastDialog->previewWidget(), SIGNAL(updated()), this, SLOT(refreshPreview()));
QGridLayout *widgetLayout = new QGridLayout(m_lastDialog->container());
QGridLayout *widgetLayout = new QGridLayout(m_d->lastDialog->container());
widgetLayout->addWidget(m_lastWidget, 0 , 0);
widgetLayout->addWidget(m_d->lastWidget, 0 , 0);
m_lastDialog->container()->setMinimumSize(m_lastWidget->minimumSize());
m_d->lastDialog->container()->setMinimumSize(m_d->lastWidget->minimumSize());
refreshPreview();
if(m_lastDialog->exec() == QDialog::Rejected )
if(m_d->lastDialog->exec() == QDialog::Rejected )
{
delete m_lastDialog;
m_lastFilterConfig = oldConfig;
m_lastDialog = oldDialog;
m_lastFilter = oldFilter;
delete m_d->lastDialog;
m_d->lastFilterConfig = oldConfig;
m_d->lastDialog = oldDialog;
m_d->lastFilter = oldFilter;
return;
}
}
if (!apply()) {
delete m_lastDialog;
m_lastFilterConfig = oldConfig;
m_lastDialog = oldDialog;
m_lastFilter = oldFilter;
delete m_d->lastDialog;
m_d->lastFilterConfig = oldConfig;
m_d->lastDialog = oldDialog;
m_d->lastFilter = oldFilter;
}
}
void KisFilterManager::slotConfigChanged()
{
if( m_lastDialog == 0 )
if( m_d->lastDialog == 0 )
return;
if(m_lastDialog->previewWidget()->getAutoUpdate())
if(m_d->lastDialog->previewWidget()->getAutoUpdate())
{
refreshPreview();
} else {
m_lastDialog->previewWidget()->needUpdate();
m_d->lastDialog->previewWidget()->needUpdate();
}
}
void KisFilterManager::refreshPreview( )
{
if( m_lastDialog == 0 )
m_d->timer->start ( 500 );
}
void KisFilterManager::slotDelayedRefreshPreview()
{
if( m_d->lastDialog == 0 )
return;
KisPaintDeviceSP dev = m_lastDialog->previewWidget()->getDevice();
KisPaintDeviceSP dev = m_d->lastDialog->previewWidget()->getDevice();
if (!dev) return;
KisFilterConfiguration* config = m_lastWidget->configuration();
KisFilterConfiguration* config = m_d->lastWidget->configuration();
QRect rect = dev->extent();
KisTransaction cmd("Temporary transaction", dev);
m_lastFilter->process(dev, rect, config);
m_lastDialog->previewWidget()->slotUpdate();
m_d->lastFilter->process(dev, rect, config);
m_d->lastDialog->previewWidget()->slotUpdate();
cmd.unexecute();
}
......
......@@ -62,25 +62,13 @@ protected slots:
void slotConfigChanged();
void slotApplyFilter(int);
void refreshPreview();
void slotDelayedRefreshPreview();
private:
KisView2 * m_view;
KisDoc2 * m_doc;
class KisFilterManagerPrivate;
KisFilterManagerPrivate * m_d;