Commit 1cba3bdb authored by Boudewijn Rempt's avatar Boudewijn Rempt

Fix the issues with toolbox and paintstuff bar and duplicating views.

svn path=/trunk/koffice/; revision=461198
parent 26843687
......@@ -59,7 +59,7 @@ Core
* Histogram computations. Make histogram widget zoomable for 16-bit channel/images
* Adjustment layers (Layers that dynamically apply a filter to
the layer they are linked to, these do not store actual
image date, except for an occasional mask) These should work on object
image data, except for an occasional mask) These should work on object
layers (embedded KOFfice objects), too. (BSAR)
* Mask layers (mask layers created from selection -- vv) (BSAR)
* Layer groups or even better: a hierachy of collapsable folders with layers (with d&d)
......
......@@ -310,7 +310,6 @@ bool KisDoc::loadXML(QIODevice *, const QDomDocument& doc)
}
}
}
return true;
}
......@@ -654,6 +653,7 @@ bool KisDoc::completeSaving(KoStore *store)
store -> close();
}
}
// Composite rendition of the entire image for easier kimgio loading
// and to speed up loading the image into Krita: show the composite png first,
// then load the layers.
......@@ -661,6 +661,7 @@ bool KisDoc::completeSaving(KoStore *store)
QPixmap * pix = new QPixmap(m_currentImage -> width(), m_currentImage -> height());
QPainter gc(pix);
//m_currentImage->notify();
m_currentImage -> renderToPainter(0, 0, m_currentImage -> width(), m_currentImage -> height(), gc, m_currentImage -> profile());
gc.end();
QImage composite = pix -> convertToImage();
......@@ -782,12 +783,13 @@ KisImageSP KisDoc::newImage(const QString& name, Q_INT32 width, Q_INT32 height,
KisFillPainter painter;
painter.begin(layer.data());
painter.fillRect(0, 0, width, height, Qt::white, OPACITY_OPAQUE);
painter.end();
painter.begin(layer.data());
painter.fillRect(0, 0, width, height, Qt::white, OPACITY_OPAQUE);
painter.end();
img -> add(layer, -1);
img->notify();
m_currentImage = img;
return img;
}
......@@ -827,13 +829,13 @@ bool KisDoc::slotNewImage()
Q_CHECK_PTR(layer);
KisFillPainter painter;
painter.begin(layer.data());
painter.fillRect(0, 0, dlg.imgWidth(), dlg.imgHeight(), KisColor(c, opacity, cs), opacity);
painter.end();
painter.begin(layer.data());
painter.fillRect(0, 0, dlg.imgWidth(), dlg.imgHeight(), KisColor(c, opacity, cs), opacity);
painter.end();
img -> add(layer, -1);
img -> notify();
m_currentImage = img;
cfg.defImgWidth(dlg.imgWidth());
......
......@@ -72,11 +72,11 @@ namespace {
public:
KisResizeImageCmd(KisUndoAdapter *adapter,
KisImageSP img,
Q_INT32 width,
Q_INT32 height,
Q_INT32 oldWidth,
Q_INT32 oldHeight) : super(i18n("Resize Image"))
KisImageSP img,
Q_INT32 width,
Q_INT32 height,
Q_INT32 oldWidth,
Q_INT32 oldHeight) : super(i18n("Resize Image"))
{
m_adapter = adapter;
m_img = img;
......@@ -180,9 +180,9 @@ namespace {
public:
KisConvertImageTypeCmd(KisUndoAdapter *adapter, KisImageSP img,
KisColorSpace * beforeColorSpace, KisProfile * beforeProfile,
KisColorSpace * afterColorSpace, KisProfile * afterProfile
) : super(i18n("Convert Image Type"))
KisColorSpace * beforeColorSpace, KisProfile * beforeProfile,
KisColorSpace * afterColorSpace, KisProfile * afterProfile
) : super(i18n("Convert Image Type"))
{
m_adapter = adapter;
m_img = img;
......@@ -382,11 +382,11 @@ namespace {
public:
LayerPropsCmd(KisLayerSP layer,
KisImageSP img,
KisUndoAdapter *adapter,
const QString& name,
Q_INT32 opacity,
const KisCompositeOp& compositeOp) : super(i18n("Layer Property Changes"))
KisImageSP img,
KisUndoAdapter *adapter,
const QString& name,
Q_INT32 opacity,
const KisCompositeOp& compositeOp) : super(i18n("Layer Property Changes"))
{
m_layer = layer;
m_img = img;
......@@ -409,9 +409,9 @@ namespace {
m_adapter -> setUndo(false);
m_img -> setLayerProperties(m_layer,
m_opacity,
m_compositeOp,
m_name);
m_opacity,
m_compositeOp,
m_name);
m_adapter -> setUndo(true);
m_name = name;
m_opacity = opacity;
......@@ -487,7 +487,7 @@ KisImage::KisImage(const KisImage& rhs) : QObject(), KShared(rhs)
Q_CHECK_PTR(m_nserver);
m_guides = rhs.m_guides;
m_pixmap = rhs.m_pixmap;
}
}
......@@ -564,6 +564,8 @@ void KisImage::init(KisDoc *doc, Q_INT32 width, Q_INT32 height, KisColorSpace *
Q_CHECK_PTR(m_bkg);
m_projection = new KisLayer(this, "projection", OPACITY_OPAQUE);
Q_CHECK_PTR(m_projection);
m_xres = 1.0;
......@@ -583,7 +585,7 @@ void KisImage::init(KisDoc *doc, Q_INT32 width, Q_INT32 height, KisColorSpace *
INTENT_PERCEPTUAL,
0);
#endif
m_paintInit = true;
}
void KisImage::resize(Q_INT32 w, Q_INT32 h, bool cropLayers)
......@@ -600,7 +602,7 @@ void KisImage::resize(Q_INT32 w, Q_INT32 h, bool cropLayers)
m_projection = new KisLayer(this, "projection", OPACITY_OPAQUE);
Q_CHECK_PTR(m_projection);
m_bkg = new KisBackground(this, w, h);
m_bkg = new KisBackground(this, w, h);
Q_CHECK_PTR(m_bkg);
if (cropLayers) {
......@@ -610,7 +612,7 @@ void KisImage::resize(Q_INT32 w, Q_INT32 h, bool cropLayers)
KisTransaction * t = new KisTransaction("crop", layer.data());
Q_CHECK_PTR(t);
layer -> crop(0, 0, w, h);
if (m_adapter && m_adapter -> undo())
if (m_adapter && m_adapter -> undo())
m_adapter->addCommand(t);
}
}
......@@ -620,6 +622,7 @@ void KisImage::resize(Q_INT32 w, Q_INT32 h, bool cropLayers)
}
emit sizeChanged(KisImageSP(this), w, h);
notify();
}
}
......@@ -640,7 +643,7 @@ void KisImage::scale(double sx, double sy, KisProgressDisplayInterface *m_progre
if (w != width() || h != height()) {
if (m_adapter && m_adapter -> undo()) {
m_adapter->beginMacro("Scale image");
m_adapter->beginMacro("Scale image");
}
vKisLayerSP_it it;
......@@ -676,8 +679,9 @@ void KisImage::scale(double sx, double sy, KisProgressDisplayInterface *m_progre
if (m_adapter && m_adapter -> undo()) {
m_adapter->endMacro();
}
notify();
emit sizeChanged(KisImageSP(this), w, h);
}
}
......@@ -714,7 +718,7 @@ void KisImage::rotate(double angle, KisProgressDisplayInterface *m_progress)
//XXX: This is very ugly.
KNamedCommand *moveCommand = layer -> moveCommand(layer -> getX() + oldCentreToNewCentreXOffset,
layer -> getY() + oldCentreToNewCentreYOffset);
layer -> getY() + oldCentreToNewCentreYOffset);
if (undoAdapter() && m_adapter->undo()) {
m_adapter->addCommand(moveCommand);
} else {
......@@ -736,33 +740,34 @@ void KisImage::rotate(double angle, KisProgressDisplayInterface *m_progress)
undoAdapter()->endMacro();
emit sizeChanged(KisImageSP(this), w, h);
notify();
}
void KisImage::shear(double angleX, double angleY, KisProgressDisplayInterface *m_progress)
{
const double pi=3.1415926535897932385;
if (m_layers.empty()) return; // Nothing to scale
if (m_layers.empty()) return; // Nothing to scale
//new image size
//new image size
Q_INT32 w=width();
Q_INT32 h=height();
if(angleX != 0 || angleY != 0){
double deltaY=height()*QABS(tan(angleX*pi/180)*tan(angleY*pi/180));
w = (Q_INT32) ( width() + QABS(height()*tan(angleX*pi/180)) );
//ugly fix for the problem of having two extra pixels if only a shear along one
//axis is done. This has to be fixed in the cropping code in KisRotateVisitor!
if (angleX == 0 || angleY == 0)
h = (Q_INT32) ( height() + QABS(w*tan(angleY*pi/180)) );
else if (angleX > 0 && angleY > 0)
h = (Q_INT32) ( height() + QABS(w*tan(angleY*pi/180))- 2 * deltaY + 2 );
else if (angleX < 0 && angleY < 0)
h = (Q_INT32) ( height() + QABS(w*tan(angleY*pi/180))- 2 * deltaY + 2 );
else
h = (Q_INT32) ( height() + QABS(w*tan(angleY*pi/180)) );
}
Q_INT32 h=height();
if(angleX != 0 || angleY != 0){
double deltaY=height()*QABS(tan(angleX*pi/180)*tan(angleY*pi/180));
w = (Q_INT32) ( width() + QABS(height()*tan(angleX*pi/180)) );
//ugly fix for the problem of having two extra pixels if only a shear along one
//axis is done. This has to be fixed in the cropping code in KisRotateVisitor!
if (angleX == 0 || angleY == 0)
h = (Q_INT32) ( height() + QABS(w*tan(angleY*pi/180)) );
else if (angleX > 0 && angleY > 0)
h = (Q_INT32) ( height() + QABS(w*tan(angleY*pi/180))- 2 * deltaY + 2 );
else if (angleX < 0 && angleY < 0)
h = (Q_INT32) ( height() + QABS(w*tan(angleY*pi/180))- 2 * deltaY + 2 );
else
h = (Q_INT32) ( height() + QABS(w*tan(angleY*pi/180)) );
}
if (w != width() || h != height()) {
......@@ -800,6 +805,7 @@ void KisImage::shear(double angleX, double angleY, KisProgressDisplayInterface *
undoAdapter()->endMacro();
emit sizeChanged(KisImageSP(this), w, h);
notify();
}
}
......@@ -835,7 +841,7 @@ void KisImage::convertTo(KisColorSpace * dstColorSpace, KisProfile * dstProfile
if (undoAdapter() && m_adapter->undo()) {
m_adapter->addCommand(new KisConvertImageTypeCmd(undoAdapter(), this,
m_colorSpace, m_profile, dstColorSpace, dstProfile));
m_colorSpace, m_profile, dstColorSpace, dstProfile));
m_adapter->endMacro();
}
......@@ -1005,7 +1011,7 @@ KisLayerSP KisImage::layerAdd(KisLayerSP l, Q_INT32 position)
emit layersUpdated(this);
if (!m_adapter->undo())
emit imageUpdated(this);
emit imageUpdated(this);
return l;
}
......@@ -1184,10 +1190,10 @@ KisLayerSP KisImage::layer(Q_INT32 n)
KisLayerSP KisImage::findLayer(const QString & name)
{
for (Q_UINT32 i = 0; i < m_layers.size(); i++) {
if (m_layers[i]->name() == name)
return m_layers[i];
}
for (Q_UINT32 i = 0; i < m_layers.size(); i++) {
if (m_layers[i]->name() == name)
return m_layers[i];
}
return 0;
}
......@@ -1556,7 +1562,6 @@ void KisImage::renderToProjection(Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h)
{
KisPainter gc;
// kdDebug () << "Rendering onto projection " << m_projection->colorSpace()->id().name() << "\n";
gc.begin(m_projection.data());
gc.bitBlt(x, y, COMPOSITE_COPY, m_bkg.data(), x, y, w, h);
......@@ -1572,45 +1577,40 @@ void KisImage::renderToProjection(Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h)
}
void KisImage::renderToPainter(Q_INT32 x1,
Q_INT32 y1,
Q_INT32 x2,
Q_INT32 y2,
QPainter &painter,
KisProfile * monitorProfile,
float exposure)
Q_INT32 y1,
Q_INT32 x2,
Q_INT32 y2,
QPainter &painter,
KisProfile * monitorProfile,
float exposure)
{
Q_INT32 x;
Q_INT32 y;
// Flatten the layers onto the projection layer of the current image
for (y = y1; y <= y2; ) {
Q_INT32 h = QMIN(y2 - y + 1, RENDER_HEIGHT);
for (x = x1; x <= x2; ) {
Q_INT32 w = QMIN(x2 - x + 1, RENDER_WIDTH);
// QRect r = m_projection->extent();
// kdDebug() << "projection extent: " << r.x() << ", " << r.y() << ", " << r.width() << ", " << r.height() << "...\n";
Q_INT32 w = x2 - x1 + 1;
Q_INT32 h = y2 - y1 + 1;
// if (m_paintInit) {
renderToProjection(x1, y1, w, h);
// m_paintInit = false;
// }
renderToProjection(x, y, w, h);
QImage img = m_projection -> convertToQImage(monitorProfile, x, y, w, h, exposure);
QImage img = m_projection->convertToQImage(monitorProfile, x1, y1, w, h, exposure);
if (m_activeLayer != 0 && m_activeLayer -> hasSelection())
m_activeLayer -> selection()->paintSelection(img, x, y, w, h);
if (m_activeLayer != 0 && m_activeLayer -> hasSelection()) {
m_activeLayer -> selection()->paintSelection(img, x1, y1, w, h);
}
if (!img.isNull()) {
if (!img.isNull()) {
#ifdef __BIG_ENDIAN__
cmsDoTransform(m_bigEndianTransform, img.bits(), img.bits(), w * h);
cmsDoTransform(m_bigEndianTransform, img.bits(), img.bits(), w * h);
#endif
m_pixmap.convertFromImage(img);
painter.drawPixmap(x, y, m_pixmap, 0, 0, w, h);
}
x += w;
}
y += h;
painter.drawImage(x1, y1, img, 0, 0, w, h);
}
}
KisPaintDeviceImplSP KisImage::mergedImage()
......@@ -1664,6 +1664,8 @@ void KisImage::notify(Q_INT32 x, Q_INT32 y, Q_INT32 width, Q_INT32 height)
void KisImage::notify(const QRect& rc)
{
//renderToProjection(rc.x(), rc.y(), rc.width(), rc.height());
if (rc.isValid()) {
emit update(KisImageSP(this), rc);
}
......
......@@ -275,10 +275,8 @@ private:
KisImageIface *m_dcop;
QPixmap m_pixmap;
vKisAnnotationSP m_annotations;
bool m_paintInit;
#ifdef __BIG_ENDIAN__
cmsHTRANSFORM m_bigEndianTransform;
#endif
......
......@@ -37,6 +37,7 @@ KisToolManager::KisToolManager(KisCanvasSubject * parent, KisCanvasControllerInt
m_paletteManager = 0;
m_actionCollection = 0;
m_tools_disabled = false;
setup = false;
}
KisToolManager::~KisToolManager()
......@@ -46,6 +47,11 @@ KisToolManager::~KisToolManager()
void KisToolManager::setUp(KisToolBox * toolbox, KoPaletteManager * paletteManager, KActionCollection * actionCollection)
{
if (setup) {
resetToolBox( toolbox );
return;
}
m_toolBox = toolbox;
m_paletteManager = paletteManager;
m_actionCollection = actionCollection;
......@@ -59,8 +65,8 @@ void KisToolManager::setUp(KisToolBox * toolbox, KoPaletteManager * paletteManag
m_inputDeviceToolSetMap[INPUT_DEVICE_ERASER] = KisToolRegistry::instance() -> createTools(actionCollection, m_subject);
m_inputDeviceToolSetMap[INPUT_DEVICE_PUCK] = KisToolRegistry::instance() -> createTools(actionCollection, m_subject);
vKisTool tools = m_inputDeviceToolSetMap[INPUT_DEVICE_MOUSE];
for (vKisTool_it it = tools.begin(); it != tools.end(); ++it) {
m_tools = m_inputDeviceToolSetMap[INPUT_DEVICE_MOUSE];
for (vKisTool_it it = m_tools.begin(); it != m_tools.end(); ++it) {
KisTool * t = *it;
if (!t) continue;
toolbox->registerTool( t->action(), t->toolType(), t->priority() );
......@@ -68,7 +74,40 @@ void KisToolManager::setUp(KisToolBox * toolbox, KoPaletteManager * paletteManag
toolbox->setupTools();
setCurrentTool(findTool("tool_brush"));
KisTool * t = findTool("tool_brush");
kdDebug() << "found " << t << " when looking for brush tool.\n";
setCurrentTool(t);
setup = true;
}
void KisToolManager::youAintGotNoToolBox()
{
m_toolBox = 0;
m_oldTool = currentTool();
}
void KisToolManager::resetToolBox(KisToolBox * toolbox)
{
m_toolBox = toolbox;
m_tools = m_inputDeviceToolSetMap[INPUT_DEVICE_MOUSE];
for (vKisTool_it it = m_tools.begin(); it != m_tools.end(); ++it) {
KisTool * t = *it;
if (!t) continue;
m_toolBox->registerTool( t->action(), t->toolType(), t->priority() );
}
toolbox->setupTools();
if (m_oldTool) {
// restore the old current tool
setCurrentTool(m_oldTool);
m_oldTool = 0;
}
}
void KisToolManager::updateGUI()
......@@ -116,7 +155,9 @@ void KisToolManager::updateGUI()
}
else {
m_oldTool = 0;
setCurrentTool(findTool("tool_brush"));
KisTool * t = findTool("tool_brush");
kdDebug() << "found " << t << " when looking for brush tool.\n";
setCurrentTool(t);
}
}
}
......@@ -151,6 +192,7 @@ void KisToolManager::setCurrentTool(KisTool *tool)
m_subject->notify();
tool->action()->setChecked( true );
tool->action()->activate();
} else {
m_inputDeviceToolMap[m_controller->currentInputDevice()] = 0;
......
......@@ -26,6 +26,7 @@
#include "kis_global.h"
#include "kis_types.h"
class KoView;
class KisCanvasSubject;
class KisView;
class KisTool;
......@@ -50,6 +51,10 @@ public:
public:
void setUp(KisToolBox * toolbox, KoPaletteManager * paletteManager, KActionCollection * collection);
// Called when the toolbox is deleted because the view was made inactive in favour of another view
void youAintGotNoToolBox();
void updateGUI();
virtual void setCurrentTool(KisTool *tool);
......@@ -62,6 +67,10 @@ public:
KisTool *findTool(const QString &toolName, enumInputDevice inputDevice = INPUT_DEVICE_UNKNOWN) const;
void activateCurrentTool();
private:
void resetToolBox(KisToolBox * toolbox);
private:
......@@ -81,8 +90,11 @@ private:
KisTool * m_oldTool;
KisTool * m_dummyTool;
vKisTool m_tools;
bool m_tools_disabled;
bool setup;
};
......
......@@ -60,6 +60,7 @@
#include <kpopupmenu.h>
#include <kdebug.h>
#include <ksharedptr.h>
#include <ktoolbar.h>
// KOffice
#include <koPartSelectAction.h>
......@@ -76,13 +77,13 @@
#include "kis_color.h"
#include "kis_colorspace_registry.h"
#include "kis_config.h"
#include "kis_controlframe.h"
#include "kis_cursor.h"
#include "kis_doc.h"
#include "kis_double_click_event.h"
#include "kis_factory.h"
#include "kis_gradient.h"
#include "kis_guide.h"
#include "kis_imagepipe_brush.h"
#include "kis_layerbox.h"
#include "kis_layer.h"
#include "kis_move_event.h"
......@@ -91,12 +92,14 @@
#include "kis_painter.h"
#include "kis_paintop_registry.h"
#include "kis_part_layer.h"
#include "kis_pattern.h"
#include "kis_profile.h"
#include "kis_rect.h"
#include "kis_resource.h"
#include "kis_ruler.h"
#include "kis_selection.h"
#include "kis_tool.h"
#include "kis_toolbox.h"
#include "kis_tool.h"
#include "kis_tool_manager.h"
#include "kis_transaction.h"
#include "kis_types.h"
......@@ -106,8 +109,19 @@
#include "labels/kis_label_cursor_pos.h"
#include "labels/kis_label_progress.h"
#include "strategy/kis_strategy_move.h"
#include "kis_resource.h"
#include "kis_pattern.h"
#include <kis_resourceserver.h>
#include <kis_resource_mediator.h>
#include "kis_gray_widget.h"
#include "kis_hsv_widget.h"
#include "kis_icon_item.h"
#include "kis_palette_widget.h"
#include "kis_rgb_widget.h"
#include "kis_birdeye_box.h"
#include "kis_color.h"
#include "kis_factory.h"
// Dialog boxes
#include "kis_dlg_progress.h"
......@@ -132,6 +146,7 @@
KisView::KisView(KisDoc *doc, KisUndoAdapter *adapter, QWidget *parent, const char *name)
: super(doc, parent, name)
, KXMLGUIBuilder( shell() )
, m_doc( doc )
, m_canvas( 0 )
, m_selectionManager( 0 )
......@@ -187,16 +202,19 @@ KisView::KisView(KisDoc *doc, KisUndoAdapter *adapter, QWidget *parent, const ch
, m_inputDevice ( INPUT_DEVICE_MOUSE )
{
kdDebug() << "Creating the view\n";
setFocusPolicy( QWidget::StrongFocus );
setClientBuilder( this );
if (!doc -> isReadWrite())
setXMLFile("krita_readonly.rc");
else
setXMLFile("krita.rc");
m_paletteManager = new KoPaletteManager(this, actionCollection(), "Krita palette manager");
m_paletteManager->createPalette( krita::PAINTBOX, i18n("Brushes and stuff"));
m_paletteManager->createPalette( krita::CONTROL_PALETTE , i18n("Control box"));
m_paletteManager->createPalette( krita::CONTROL_PALETTE, i18n("Control box"));
m_paletteManager->createPalette( krita::COLORBOX, i18n("Colors"));
m_paletteManager->createPalette( krita::LAYERBOX, i18n("Layers"));
......@@ -204,10 +222,11 @@ KisView::KisView(KisDoc *doc, KisUndoAdapter *adapter, QWidget *parent, const ch
m_filterManager = new KisFilterManager(this, doc);
m_toolManager = new KisToolManager(getCanvasSubject(), getCanvasController());
createDockers();
m_fg = KisColor(Qt::black);
m_bg = KisColor(Qt::white);
createToolBox();
createLayerBox();
// Now the view plugins will be loaded.
......@@ -229,14 +248,11 @@ KisView::KisView(KisDoc *doc, KisUndoAdapter *adapter, QWidget *parent, const ch
qApp -> installEventFilter(this);
m_tabletEventTimer.start();
// XXX: Remember this
m_toolBox->setBarPos(KToolBar::Left);
m_toolManager->setUp(m_toolBox, m_paletteManager, actionCollection());
m_brushesAndStuffToolBar = new KisControlFrame(mainWindow(), this);
}
KisView::~KisView()
{
KisConfig cfg;
......@@ -247,6 +263,32 @@ KisView::~KisView()
delete m_selectionManager;
delete m_filterManager;
delete m_toolManager;
}
QWidget * KisView::createContainer( QWidget *parent, int index, const QDomElement &element, int &id )
{
if( element.attribute( "name" ) == "ToolBox" )
{
m_toolBox = new KisToolBox(mainWindow(), "toolbox");
m_toolManager->setUp(m_toolBox, m_paletteManager, actionCollection());
return m_toolBox;
}
return KXMLGUIBuilder::createContainer( parent, index, element, id );
}
void KisView::removeContainer( QWidget *container, QWidget *parent, QDomElement &element, int id )
{
if( shell() && container == m_toolBox )
{
delete m_toolBox;
m_toolManager->youAintGotNoToolBox();
}
else {
KXMLGUIBuilder::removeContainer( container, parent, element, id );
}
}
KoPaletteManager * KisView::paletteManager()
......@@ -284,11 +326,6 @@ void KisView::createLayerBox()
}
void KisView::createToolBox()
{