Commit 6103bda7 authored by Boudewijn Rempt's avatar Boudewijn Rempt

cleanup construction of paintop box

svn path=/trunk/koffice/; revision=1029622
parent 75b8fa68
......@@ -169,18 +169,14 @@ KoShapeManager* KisCanvas2::shapeManager() const
if (activeLayer) {
KisShapeLayer * shapeLayer = dynamic_cast<KisShapeLayer*>(activeLayer.data());
if (shapeLayer) {
dbgUI << "Current shape manager belongs to a shape layer " << shapeLayer->shapeManager();
return shapeLayer->shapeManager();
}
if (activeLayer->selection() && activeLayer->selection()->hasShapeSelection()) {
KoShapeManager* m = static_cast<KisShapeSelection*>(activeLayer->selection()->shapeSelection())->shapeManager();
dbgUI << "Current shape manager belongs to a shape selection " << m;
return m;
}
}
dbgUI << "current shape manager belongs to the main canvas " << m_d->shapeManager;
return m_d->shapeManager;
}
......@@ -259,7 +255,7 @@ void KisCanvas2::createOpenGLCanvas()
setCanvasWidget( canvasWidget );
m_d->currentCanvasIsOpenGL = true;
m_d->currentCanvasUsesOpenGLShaders = m_d->openGLImageTextures->usingHDRExposureProgram();
connect(canvasWidget, SIGNAL(documentOriginChanged(const QPoint&) ), this, SLOT(updateRulers()));
} else {
......@@ -316,8 +312,8 @@ void KisCanvas2::updateCanvasProjection(const QRect & rc)
QRect vRect = m_d->prescaledProjection->updateCanvasProjection(rc);
if(!vRect.isEmpty()) {
vRect.translate(m_d->canvasWidget->documentOrigin());
m_d->canvasWidget->widget()->update(vRect);
vRect.translate(m_d->canvasWidget->documentOrigin());
m_d->canvasWidget->widget()->update(vRect);
//m_d->canvasWidget->widget()->update();
}
}
......
......@@ -179,10 +179,14 @@ void KisCanvasResourceProvider::slotGradientActivated(KoResource *res)
void KisCanvasResourceProvider::slotPaintOpPresetActivated(const KisPaintOpPresetSP preset)
{
Q_ASSERT( preset->valid() );
Q_ASSERT( !preset->paintOp().id().isEmpty() );
Q_ASSERT( preset->settings() );
if (!preset) return;
dbgUI << "slotPaintOpPresetActivated" << preset->paintOp();
QVariant v;
v.setValue(preset);
m_resourceProvider->setResource(CurrentPaintOpPreset, v);
......
......@@ -57,6 +57,8 @@ public:
KisControlFrame(KisView2 * view, const char *name = 0);
virtual ~KisControlFrame() {}
KisPaintopBox* paintopBox() { return m_paintopBox; }
public slots:
void slotSetPattern(KisPattern * pattern);
......
......@@ -97,7 +97,6 @@ void KisFilterManager::insertFilter(const QString & name)
actionMenu = new KActionMenu(category.name(), this);
d->actionCollection->addAction(category.id(), actionMenu);
d->filterActionMenus[category.id()] = actionMenu;
dbgUI << "Creating entry menu for" << category.id() << " with name" << category.name();
}
KisFilterHandler* handler = new KisFilterHandler(this, f, d->view);
......
......@@ -183,11 +183,10 @@ void KisLayerManager::updateGUI()
m_imgMergeLayer->setEnabled(nlayers > 1 && layer && layer->prevSibling());
m_flattenLayer->setEnabled(nlayers > 1 && layer && layer->firstChild());
// XXX: Check whether the colorspace was really changed
if (activeDevice()) {
emit currentColorSpaceChanged(activeDevice()->colorSpace());
}
// // XXX: Check whether the colorspace was really changed
// if (activeDevice()) {
// emit currentColorSpaceChanged(activeDevice()->colorSpace());
// }
m_imgResizeToLayer->setEnabled(activeLayer());
......
......@@ -98,25 +98,16 @@ KisPaintopBox::KisPaintopBox(KisView2 * view, QWidget *parent, const char * name
QList<KoID> keys = KisPaintOpRegistry::instance()->listKeys();
for (QList<KoID>::Iterator it = keys.begin(); it != keys.end(); ++it) {
// add all paintops, and show/hide them afterwards
addItem(*it);
m_paintops.append(*it);
}
m_colorspace = view->image()->colorSpace();
updatePaintops();
setCurrentPaintop(defaultPaintop(KoToolManager::instance()->currentInputDevice()));
connect(m_cmbPaintops, SIGNAL(activated(int)), this, SLOT(slotItemSelected(int)));
connect(view->layerManager(), SIGNAL(currentColorSpaceChanged(const KoColorSpace*)),
this, SLOT(colorSpaceChanged(const KoColorSpace*)));
connect(view->nodeManager(), SIGNAL(sigNodeActivated(KisNodeSP)),
SLOT(slotCurrentNodeChanged(KisNodeSP)));
connect(KoToolManager::instance(), SIGNAL(inputDeviceChanged(const KoInputDevice &)),
SLOT(slotInputDeviceChanged(const KoInputDevice &)));
connect(m_presetsPopup, SIGNAL( savePresetClicked()),
this, SLOT( slotSaveActivePreset()));
connect(m_presetsPopup, SIGNAL( savePresetClicked()), this, SLOT( slotSaveActivePreset()));
}
KisPaintopBox::~KisPaintopBox()
......@@ -131,48 +122,34 @@ KisPaintopBox::~KisPaintopBox()
}
}
void KisPaintopBox::addItem(const KoID & paintop, const QString & /*category*/)
{
dbgUI << "KisPaintopBox::addItem " << paintop;
m_paintops.append(paintop);
}
void KisPaintopBox::slotItemSelected(int index)
{
dbgUI << "KisPaintopBox::slotItemSelected " << index;
if (index < m_displayedOps.count()) {
KoID paintop = m_displayedOps.at(index);
dbgUI << "\t\t selected " << paintop;
setCurrentPaintop(paintop);
/*
m_cmbPaintopPresets->clear();
KisPaintOpPresetSP preset =
activePreset(currentPaintop(), KoToolManager::instance()->currentInputDevice());
m_cmbPaintopPresets->addItem(preset->name(), QVariant::fromValue<KisPaintOpPresetSP>(preset));
foreach(KisPaintOpPreset* preset,
KisResourceServerProvider::instance()->paintOpPresetServer()->resources()) {
dbgUI << "\t\t " << preset << ", " << preset->paintOp();
if (preset->paintOp() == paintop) {
m_cmbPaintopPresets->addItem(preset->name(), QVariant::fromValue<KisPaintOpPresetSP>(preset));
}
}
*/
}
}
void KisPaintopBox::colorSpaceChanged(const KoColorSpace *cs)
{
dbgUI << "KisPaintopBox::colorSpaceChanged " << cs;
dbgUI << "KisPaintopBox::colorSpaceChanged " << m_colorspace << "to" << cs;
if (cs != m_colorspace) {
m_colorspace = cs;
updatePaintops();
}
}
void KisPaintopBox::updatePaintops()
{
dbgUI << "updating paintop list";
m_displayedOps.clear();
m_cmbPaintops->clear();
foreach(const KoID & paintopId, m_paintops) {
if (KisPaintOpRegistry::instance()->userVisible(paintopId, cs)) {
if (KisPaintOpRegistry::instance()->userVisible(paintopId, m_colorspace)) {
QPixmap pm = paintopPixmap(paintopId);
if (pm.isNull()) {
......@@ -303,6 +280,15 @@ void KisPaintopBox::setCurrentPaintop(const KoID & paintop)
preset->settings()->setNode( m_resourceProvider->currentNode() );
m_resourceProvider->slotPaintOpPresetActivated(preset);
int index = m_displayedOps.indexOf(paintop);
if (index == -1) {
// Must change the paintop as the current one is not supported
// by the new colorspace.
index = 0;
}
m_cmbPaintops->setCurrentIndex(index);
m_activePreset = preset;
m_presetWidget->setPreset(m_activePreset);
m_presetsPopup->presetPreview()->setPreset(m_activePreset);
......
......@@ -68,9 +68,9 @@ public:
private slots:
void addItem(const KoID & paintop, const QString & category = "");
void updatePaintops();
private slots:
public slots:
void slotItemSelected(int index);
void colorSpaceChanged(const KoColorSpace *cs);
......@@ -89,6 +89,8 @@ private:
private:
const KoColorSpace* m_colorspace;
KisCanvasResourceProvider *m_resourceProvider;
QComboBox* m_cmbPaintops;
......
......@@ -82,6 +82,7 @@
#include "kis_selection_manager.h"
#include "kis_image_manager.h"
#include "kis_control_frame.h"
#include "kis_paintop_box.h"
#include "kis_birdeye_box.h"
#include "kis_layer_box.h"
#include "kis_layer_manager.h"
......@@ -510,7 +511,6 @@ void KisView2::createGUI()
KisBirdEyeBoxFactory birdeyeFactory(this);
m_d->birdEyeBox = qobject_cast<KisBirdEyeBox*>(createDockWidget(&birdeyeFactory));
KisPaletteDockerFactory paletteDockerFactory(this);
createDockWidget(&paletteDockerFactory);
......@@ -521,12 +521,22 @@ void KisView2::createGUI()
connect(m_d->canvasController, SIGNAL(documentMousePositionChanged(const QPointF &)),
m_d->statusBar, SLOT(documentMousePositionChanged(const QPointF &)));
connect(m_d->nodeManager, SIGNAL(sigNodeActivated(KisNodeSP)),
m_d->resourceProvider, SLOT(slotNodeActivated(KisNodeSP)));
m_d->controlFrame = new KisControlFrame(this);
show();
connect(layerManager(), SIGNAL(currentColorSpaceChanged(const KoColorSpace*)),
m_d->controlFrame->paintopBox(), SLOT(colorSpaceChanged(const KoColorSpace*)));
connect(m_d->nodeManager, SIGNAL(sigNodeActivated(KisNodeSP)),
m_d->resourceProvider, SLOT(slotNodeActivated(KisNodeSP)));
m_d->controlFrame->paintopBox(), SLOT(slotCurrentNodeChanged(KisNodeSP)));
connect(KoToolManager::instance(), SIGNAL(inputDeviceChanged(const KoInputDevice &)),
m_d->controlFrame->paintopBox(), SLOT(slotInputDeviceChanged(const KoInputDevice &)));
show();
}
......@@ -621,6 +631,12 @@ void KisView2::connectCurrentImage()
if (m_d->birdEyeBox)
m_d->birdEyeBox->setImage(img);
if (m_d->controlFrame) {
dbgUI << "connecting image colorchanged to paintopbox";
connect(img.data(), SIGNAL(sigColorSpaceChanged(const KoColorSpace *)), m_d->controlFrame->paintopBox(), SLOT(colorSpaceChanged(const KoColorSpace*)));
}
}
void KisView2::disconnectCurrentImage()
......
......@@ -87,7 +87,7 @@ KisTool::KisTool(KoCanvasBase * canvas, const QCursor & cursor)
m_mode = XOR_MODE;
connect(KisConfigNotifier::instance(), SIGNAL(configChanged()), SLOT(slotSelectCursorStyle()) );
}
KisTool::~KisTool()
......@@ -99,7 +99,7 @@ void KisTool::activate(bool)
{
slotSelectCursorStyle();
d->currentFgColor = m_canvas->resourceProvider()->resource(KoCanvasResource::ForegroundColor).value<KoColor>();
d->currentBgColor = m_canvas->resourceProvider()->resource(KoCanvasResource::BackgroundColor).value<KoColor>();
d->currentPattern = static_cast<KisPattern *>(m_canvas->resourceProvider()->
......@@ -117,10 +117,6 @@ void KisTool::activate(bool)
d->currentNode = m_canvas->resourceProvider()->
resource(KisCanvasResourceProvider::CurrentKritaNode).value<KisNodeSP>();
if (d->currentNode)
dbgUI << "Activating tool " << toolId() << " with node " << d->currentNode->name();
else
dbgUI << "Activating tool " << toolId() << " with no node ";
d->currentExposure = static_cast<float>(m_canvas->resourceProvider()->
resource(KisCanvasResourceProvider::HdrExposure).toDouble());
d->currentGenerator = static_cast<KisFilterConfiguration*>(m_canvas->resourceProvider()->
......@@ -157,8 +153,6 @@ void KisTool::resourceChanged(int key, const QVariant & v)
d->currentGenerator = static_cast<KisFilterConfiguration*>(v.value<void *>());
case(KisCanvasResourceProvider::CurrentKritaNode):
d->currentNode = (v.value<KisNodeSP>());
if (d->currentNode)
dbgUI << " node changed to " << d->currentNode->name();
default:
;
// Do nothing
......@@ -387,7 +381,7 @@ void KisTool::paintToolOutline(QPainter* painter, QPainterPath &path)
painter->drawPath(path);
break;
}
default:
default:
break;
}
}
......
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