SVN commit 971745 by eapap: FEATURE: Adds the ability to change the canvas size in Krita GUI: Added 'Size Canvas' item under the Image menu in Krita
M +25 -0 image/kis_image.cc M +11 -0 image/kis_image.h M +4 -1 plugins/extensions/imagesize/CMakeLists.txt A plugins/extensions/imagesize/dlg_canvassize.cc [License: GPL (v2+)] A plugins/extensions/imagesize/dlg_canvassize.h [License: GPL (v2+)] M +25 -0 plugins/extensions/imagesize/imagesize.cc M +1 -0 plugins/extensions/imagesize/imagesize.h M +1 -0 plugins/extensions/imagesize/imagesize.rc A plugins/extensions/imagesize/kcanvaspreview.cc [License: GPL (v2+)] A plugins/extensions/imagesize/kcanvaspreview.h [License: GPL (v2+)] A plugins/extensions/imagesize/pics (directory) A plugins/extensions/imagesize/pics/CMakeLists.txt AM plugins/extensions/imagesize/pics/arrow_east.png AM plugins/extensions/imagesize/pics/arrow_north.png AM plugins/extensions/imagesize/pics/arrow_north_east.png AM plugins/extensions/imagesize/pics/arrow_north_west.png AM plugins/extensions/imagesize/pics/arrow_south.png AM plugins/extensions/imagesize/pics/arrow_south_east.png AM plugins/extensions/imagesize/pics/arrow_south_west.png AM plugins/extensions/imagesize/pics/arrow_west.png A plugins/extensions/imagesize/wdg_canvassize.ui M +9 -0 ui/kis_image_manager.cc M +1 -0 ui/kis_image_manager.h --- trunk/koffice/krita/image/kis_image.cc #971744:971745 @@ -403,7 +403,32 @@ } } +void KisImage::resizeWithOffset(qint32 w, qint32 h, qint32 xOffset, qint32 yOffset) +{ + if (w == width() && h == height() && xOffset == 0 && yOffset == 0) + return; + lock(); + if (undo()) { + m_d->adapter->beginMacro(i18n("Size Canvas")); + m_d->adapter->addCommand(new KisImageLockCommand(KisImageSP(this), true)); + m_d->adapter->addCommand(new KisImageResizeCommand(KisImageSP(this), w, h, width(), height())); + } + + KisCropVisitor v(QRect(-xOffset, -yOffset, w, h), m_d->adapter); + m_d->rootLayer->accept(v); + + emitSizeChanged(); + + unlock(); + + if (undo()) { + m_d->adapter->addCommand(new KisImageLockCommand(KisImageSP(this), false)); + m_d->adapter->endMacro(); + } + +} + void KisImage::emitSizeChanged() { if (!locked()) { --- trunk/koffice/krita/image/kis_image.h #971744:971745 @@ -194,6 +194,17 @@ void resize(const QRect& rc, bool cropLayers = false); /** + * Resize the image to the specified width and height. The previous + * image is offset by the amount specified. + * + * @param w the width of the image + * @param h the height of the image + * @param xOffset the horizontal offset of the previous image + * @param yOffset the vertical offset of the previous image + */ + void resizeWithOffset(qint32 w, qint32 h, qint32 xOffset = 0, qint32 yOffset = 0); + + /** * Execute a scale transform on all layers in this image. */ void scale(double sx, double sy, KoUpdater *m_progress, KisFilterStrategy *filterStrategy); --- trunk/koffice/krita/plugins/extensions/imagesize/CMakeLists.txt #971744:971745 @@ -1,13 +1,16 @@ +add_subdirectory( pics ) - set(kritaimagesize_PART_SRCS imagesize.cc dlg_imagesize.cc + dlg_canvassize.cc dlg_layersize.cc + kcanvaspreview.cc ) kde4_add_ui_files(kritaimagesize_PART_SRCS wdg_imagescale.ui + wdg_canvassize.ui wdg_layersize.ui ) --- trunk/koffice/krita/plugins/extensions/imagesize/imagesize.cc #971744:971745 @@ -56,6 +56,7 @@ #include "dlg_imagesize.h" +#include "dlg_canvassize.h" #include "dlg_layersize.h" #include "kis_filter_strategy.h" @@ -74,6 +75,10 @@ actionCollection()->addAction("imagesize", action); connect(action, SIGNAL(triggered()), this, SLOT(slotImageSize())); + action = new KAction(i18n("Size Canvas..."), this); + actionCollection()->addAction("canvassize", action); + connect(action, SIGNAL(triggered()), this, SLOT(slotCanvasSize())); + action = new KAction(i18n("Scale &Layer..."), this); actionCollection()->addAction("layersize", action); connect(action, SIGNAL(triggered()), this, SLOT(slotLayerSize())); @@ -121,6 +126,26 @@ delete dlgImageSize; } +void ImageSize::slotCanvasSize() +{ + KisImageSP image = m_view->image(); + + if (!image) return; + + DlgCanvasSize * dlgCanvasSize = new DlgCanvasSize(m_view, image->width(), image->height()); + Q_CHECK_PTR(dlgCanvasSize); + + if (dlgCanvasSize->exec() == QDialog::Accepted) { + qint32 width = dlgCanvasSize->width(); + qint32 height = dlgCanvasSize->height(); + qint32 xOffset = dlgCanvasSize->xOffset(); + qint32 yOffset = dlgCanvasSize->yOffset(); + + m_view->imageManager()->resizeCurrentImage(width, height, xOffset, yOffset); + } + delete dlgCanvasSize; +} + void ImageSize::slotLayerSize() { KisImageSP image = m_view->image(); --- trunk/koffice/krita/plugins/extensions/imagesize/imagesize.h #971744:971745 @@ -35,6 +35,7 @@ private slots: void slotImageSize(); + void slotCanvasSize(); void slotLayerSize(); void slotSelectionScale(); --- trunk/koffice/krita/plugins/extensions/imagesize/imagesize.rc #971744:971745 @@ -4,6 +4,7 @@ <Menu name="Image"><text>Image</text> <Action name="imagesize"/> <Action name="imageresolution"/> + <Action name="canvassize"/> </Menu> <Menu name="Layer"><text>Layer</text> <Action name="layersize"/> ** trunk/koffice/krita/plugins/extensions/imagesize/pics/arrow_east.png #property svn:mime-type + application/octet-stream ** trunk/koffice/krita/plugins/extensions/imagesize/pics/arrow_north.png #property svn:mime-type + application/octet-stream ** trunk/koffice/krita/plugins/extensions/imagesize/pics/arrow_north_east.png #property svn:mime-type + application/octet-stream ** trunk/koffice/krita/plugins/extensions/imagesize/pics/arrow_north_west.png #property svn:mime-type + application/octet-stream ** trunk/koffice/krita/plugins/extensions/imagesize/pics/arrow_south.png #property svn:mime-type + application/octet-stream ** trunk/koffice/krita/plugins/extensions/imagesize/pics/arrow_south_east.png #property svn:mime-type + application/octet-stream ** trunk/koffice/krita/plugins/extensions/imagesize/pics/arrow_south_west.png #property svn:mime-type + application/octet-stream ** trunk/koffice/krita/plugins/extensions/imagesize/pics/arrow_west.png #property svn:mime-type + application/octet-stream --- trunk/koffice/krita/ui/kis_image_manager.cc #971744:971745 @@ -114,6 +114,15 @@ m_view->layerManager()->layersUpdated(); } +void KisImageManager::resizeCurrentImage(qint32 w, qint32 h, qint32 xOffset, qint32 yOffset) +{ + if (!m_view->image()) return; + + m_view->image()->resizeWithOffset(w, h, xOffset, yOffset); + m_view->image()->setModified(); + m_view->layerManager()->layersUpdated(); +} + void KisImageManager::scaleCurrentImage(double sx, double sy, KisFilterStrategy *filterStrategy) { if (!m_view->image()) return; --- trunk/koffice/krita/ui/kis_image_manager.h #971744:971745 @@ -56,6 +56,7 @@ qint32 importImage(const KUrl& url = KUrl()); void resizeCurrentImage(qint32 w, qint32 h, bool cropLayers = false); + void resizeCurrentImage(qint32 w, qint32 h, qint32 xOffset, qint32 yOffset); void scaleCurrentImage(double sx, double sy, KisFilterStrategy *filterStrategy); void rotateCurrentImage(double radians); void shearCurrentImage(double angleX, double angleY);