Commit 34bf6ea3 authored by Boudewijn Rempt's avatar Boudewijn Rempt

* Added section on function names to HACKING guide

* Added infrastructure for scaling and resizing of layers and images
* Scaling images works (but with generic transform, nothing fancy like smootscale,
  bicubic interpolation or Bessel functions of the first order.
* Resizing images works
  Todo is: scaling images (scale all layers), resizing layers, enabling
  the resolution controls in the imagesize dialog and storing and restoring the
  preferred settings in the dialog. And a better scale algorithm.

svn path=/trunk/koffice/; revision=317564
parent 8a8f7526
......@@ -50,6 +50,14 @@ Class naming
The only exception to this rule are interfaces.
Example: kis_tool.h/KisToolInterface.
Function naming
Functions should be named in camelBackedFashion, to conform to Qt's standards.
If you encounter functions in c_style_like_this, feel free to rename. Also:
verbNoun -- i.e., rotateLayer, not layer_rotate. The latter is a true c-ism,
introduced by a language that needs to prefix the 'class' name to every function
in order to have something that not quite OO.
Designer
Krita doesn't use .ui files. Yet. When we get down to the great UI redesign,
......
......@@ -120,32 +120,32 @@ void KRayonViewIface::preferences()
m_view->preferences();
}
void KRayonViewIface::layer_rotate180()
void KRayonViewIface::rotateLayer180()
{
m_view->layer_rotate180();
m_view->rotateLayer180();
}
void KRayonViewIface::layer_rotateleft90()
void KRayonViewIface::rotateLayerLeft90()
{
m_view->layer_rotateleft90();
m_view->rotateLayerLeft90();
}
void KRayonViewIface::layer_rotateright90()
void KRayonViewIface::rotateLayerRight90()
{
m_view->layer_rotateright90();
m_view->rotateLayerRight90();
}
void KRayonViewIface::layer_rotate_custom()
void KRayonViewIface::rotateLayerCustom()
{
m_view->layer_rotate_custom();
m_view->rotateLayerCustom();
}
void KRayonViewIface::layer_mirrorX()
void KRayonViewIface::mirrorLayerX()
{
m_view->layer_mirrorX();
m_view->mirrorLayerX();
}
void KRayonViewIface::layer_mirrorY()
void KRayonViewIface::mirrorLayerY()
{
m_view->layer_mirrorY();
m_view->mirrorLayerY();
}
......@@ -64,12 +64,12 @@ class KRayonViewIface : public KoViewIface
// settings action slots
void preferences();
void layer_rotate180();
void layer_rotateleft90();
void layer_rotateright90();
void layer_rotate_custom();
void layer_mirrorX();
void layer_mirrorY();
void rotateLayer180();
void rotateLayerLeft90();
void rotateLayerRight90();
void rotateLayerCustom();
void mirrorLayerX();
void mirrorLayerY();
private:
KisView *m_view;
......
......@@ -142,7 +142,6 @@ KisView::KisView(KisDoc *doc, KisUndoAdapter *adapter, QWidget *parent, const ch
m_layerHide = 0;
m_layerProperties = 0;
m_layerSaveAs = 0;
m_layerResize = 0;
m_layerResizeToImage = 0;
m_layerToImage = 0;
m_layerTransform = 0;
......@@ -228,20 +227,6 @@ DCOPObject* KisView::dcopObject()
return m_dcop;
}
void KisView::resize(Q_INT32 w, Q_INT32 h)
{
KisImageSP img = currentImg();
if (img) {
img -> resize(w, h);
img -> invalidate();
resizeEvent(0);
layersUpdated();
canvasRefresh();
}
}
void KisView::setupDockers()
{
......@@ -525,18 +510,17 @@ void KisView::setupActions()
m_layerProperties = new KAction(i18n("Layer Properties..."), 0, this, SLOT(layerProperties()), actionCollection(), "layer_properties");
(void)new KAction(i18n("I&nsert Image as Layer..."), 0, this, SLOT(slotInsertImageAsLayer()), actionCollection(), "insert_image_as_layer");
m_layerSaveAs = new KAction(i18n("Save Layer as Image..."), 0, this, SLOT(save_layer_as_image()), actionCollection(), "save_layer_as_image");
m_layerResize = new KAction(i18n("Resize Layer..."), 0, this, SLOT(layerResize()), actionCollection(), "resizelayer");
m_layerResizeToImage = new KAction(i18n("Resize Layer to Image"), 0, this, SLOT(layerResizeToImage()), actionCollection(), "resizelayertoowner");
m_layerToImage = new KAction(i18n("Layer to Image"), 0, this, SLOT(layerToImage()), actionCollection(), "layer_to_image");
// layer transformations - should be generic, for selection too
m_layerTransform = new KAction(i18n("Scale Layer..."), 0, this, SLOT(layerTransform()), actionCollection(), "transformlayer");
(void)new KAction(i18n("Rotate &180"), 0, this, SLOT(layer_rotate180()), actionCollection(), "layer_rotate180");
(void)new KAction(i18n("Rotate &270"), 0, this, SLOT(layer_rotateleft90()), actionCollection(), "layer_rotateleft90");
(void)new KAction(i18n("Rotate &90"), 0, this, SLOT(layer_rotateright90()), actionCollection(), "layer_rotateright90");
(void)new KAction(i18n("Rotate &Custom..."), 0, this, SLOT(layer_rotate_custom()), actionCollection(), "layer_rotate_custom");
(void)new KAction(i18n("Mirror Along &X Axis"), 0, this, SLOT(layer_mirrorX()), actionCollection(), "layer_mirrorX");
(void)new KAction(i18n("Mirror Along &Y Axis"), 0, this, SLOT(layer_mirrorY()), actionCollection(), "layer_mirrorY");
(void)new KAction(i18n("Rotate &180"), 0, this, SLOT(rotateLayer180()), actionCollection(), "rotateLayer180");
(void)new KAction(i18n("Rotate &270"), 0, this, SLOT(rotateLayerLeft90()), actionCollection(), "rotateLayerLeft90");
(void)new KAction(i18n("Rotate &90"), 0, this, SLOT(rotateLayerRight90()), actionCollection(), "rotateLayerRight90");
(void)new KAction(i18n("Rotate &Custom..."), 0, this, SLOT(rotateLayerCustom()), actionCollection(), "rotateLayerCustom");
(void)new KAction(i18n("Mirror Along &X Axis"), 0, this, SLOT(mirrorLayerX()), actionCollection(), "mirrorLayerX");
(void)new KAction(i18n("Mirror Along &Y Axis"), 0, this, SLOT(mirrorLayerY()), actionCollection(), "mirrorLayerY");
// color actions
(void)new KAction(i18n("Select Foreground Color..."), 0, this, SLOT(selectFGColor()), actionCollection(), "select_fgColor");
......@@ -839,7 +823,6 @@ void KisView::layerUpdateGUI(bool enable)
m_layerHide -> setEnabled(enable);
m_layerProperties -> setEnabled(enable);
m_layerSaveAs -> setEnabled(enable);
m_layerResize -> setEnabled(enable);
m_layerResizeToImage -> setEnabled(enable);
m_layerToImage -> setEnabled(enable);
m_layerTransform -> setEnabled(enable);
......@@ -1510,57 +1493,8 @@ Q_INT32 KisView::importImage(bool createLayer, bool modal, const QString& filena
return rc;
}
void KisView::layerTransform(bool )
{
#if 0
KisImageSP img = m_doc->currentImg();
if (!img) return;
KisLayerSP lay = img->getCurrentLayer();
if (!lay) return;
KisFrameBuffer *fb = m_doc->frameBuffer();
if (!fb) return;
NewLayerDialog *pNewLayerDialog = new NewLayerDialog();
pNewLayerDialog->exec();
if(!pNewLayerDialog->result() == QDialog::Accepted)
return;
QRect srcR(lay->imageExtents());
// only get the part of the layer which is inside the
// image boundaries - layer can be bigger or can overlap
srcR = srcR.intersect(img->imageExtents());
bool ok;
if(smooth)
ok = fb->scaleSmooth(srcR,
pNewLayerDialog->width(), pNewLayerDialog->height());
else
ok = fb->scaleRough(srcR,
pNewLayerDialog->width(), pNewLayerDialog->height());
if(!ok)
{
kdDebug() << "layer_transform() failed" << endl;
}
else
{
// bring new scaled layer to front
uint indx = img->layerList().size() - 1;
img->setCurrentLayer(indx);
img->markDirty(img->getCurrentLayer()->imageExtents());
layerSelected(indx);
layersUpdated();
m_doc->setModified(true);
}
#endif
}
void KisView::layer_rotate180()
void KisView::rotateLayer180()
{
if (!currentImg()) return;
KisLayerSP layer = currentImg() -> activeLayer();
......@@ -1577,7 +1511,7 @@ void KisView::layer_rotate180()
updateCanvas();
}
void KisView::layer_rotateleft90()
void KisView::rotateLayerLeft90()
{
if (!currentImg()) return;
KisLayerSP layer = currentImg() -> activeLayer();
......@@ -1594,7 +1528,7 @@ void KisView::layer_rotateleft90()
}
void KisView::layer_rotateright90()
void KisView::rotateLayerRight90()
{
if (!currentImg()) return;
KisLayerSP layer = currentImg() -> activeLayer();
......@@ -1603,7 +1537,7 @@ void KisView::layer_rotateright90()
QWMatrix m;
m.rotate(90);
layer->transform(m);
layer -> transform(m);
layersUpdated();
resizeEvent(0);
......@@ -1612,12 +1546,12 @@ void KisView::layer_rotateright90()
}
void KisView::layer_rotate_custom()
void KisView::rotateLayerCustom()
{
// XXX
}
void KisView::layer_mirrorX()
void KisView::mirrorLayerX()
{
if (!currentImg()) return;
KisLayerSP layer = currentImg() -> activeLayer();
......@@ -1629,7 +1563,7 @@ void KisView::layer_mirrorX()
updateCanvas();
}
void KisView::layer_mirrorY()
void KisView::mirrorLayerY()
{
if (!currentImg()) return;
KisLayerSP layer = currentImg() -> activeLayer();
......@@ -1641,6 +1575,21 @@ void KisView::layer_mirrorY()
updateCanvas();
}
void KisView::scaleLayer(double sx, double sy)
{
if (!currentImg()) return;
KisLayerSP layer = currentImg() -> activeLayer();
if (!layer) return;
QWMatrix m;
m.scale(sx, sy);
layer -> transform(m);
layersUpdated();
resizeEvent(0);
currentImg() -> invalidate();
updateCanvas();
}
void KisView::add_new_image_tab()
{
m_doc -> slotNewImage();
......@@ -2471,29 +2420,9 @@ void KisView::imgUpdated(KisImageSP img, const QRect& rc)
}
}
void KisView::layerResize()
void KisView::resizeLayer(Q_INT32 w, Q_INT32 h)
{
// XXX: use new dialog
// KisImageSP img = currentImg();
// if (img) {
// KisLayerSP layer = img -> activeLayer();
// if (layer) {
// KisConfig cfg;
// KisDlgDimension dlg(cfg.maxLayerWidth(), layer -> width(), cfg.maxLayerHeight(), layer -> height(), this);
// if (dlg.exec() == QDialog::Accepted) {
// QSize size = dlg.getSize();
// layer -> resize(size.width(), size.height());
// img -> invalidate();
// layersUpdated();
// resizeEvent(0);
// canvasRefresh();
// }
// }
// }
// XXX
}
void KisView::layerResizeToImage()
......@@ -2560,6 +2489,56 @@ void KisView::layerTransform()
// }
}
void KisView::resizeCurrentImage(Q_INT32 w, Q_INT32 h)
{
KisImageSP img = currentImg();
if (img) {
img -> resize(w, h);
img -> invalidate();
resizeEvent(0);
layersUpdated();
canvasRefresh();
}
}
void KisView::scaleCurrentImage(double sx, double sy)
{
if (!currentImg()) return;
// New image size. XXX: Pass along to discourage rounding errors?
Q_INT32 w, h;
w = (currentImg() -> width() * sx) + 0.5;
h = (currentImg() -> height() * sy) + 0.5;
// Check whether we need to make the image bigger
if (sx > 1 && sy > 1) {
resizeCurrentImage(w, h);
}
else if (sx > 1 && sy <= 1) {
resizeCurrentImage(w, currentImg() -> height());
}
else if (sx <= 1 && sy > 1) {
resizeCurrentImage(currentImg() -> width(), h);
}
// For every layer in the image, scale the layer
QWMatrix m = QWMatrix();
m.scale(sx, sy);
// Make the image smaller only after we've scaled all layers
if (sx < 1 || sy < 1) {
resizeCurrentImage(w, h);
}
}
QPoint KisView::viewToWindow(const QPoint& pt)
{
QPoint converted;
......
......@@ -69,9 +69,12 @@ class KisLayerBox;
class KisView : public KoView,
private KisCanvasSubject,
private KisCanvasControllerInterface,
private KisToolControllerInterface {
private KisToolControllerInterface
{
Q_OBJECT
typedef KoView super;
typedef KoView super;
typedef std::list<KisCanvasObserver*> vKisCanvasObserver;
typedef vKisCanvasObserver::iterator vKisCanvasObserver_it;
typedef vKisCanvasObserver::const_iterator vKisCanvasObserver_cit;
......@@ -90,7 +93,6 @@ public:
virtual void updateReadWrite(bool readwrite);
virtual void guiActivateEvent(KParts::GUIActivateEvent *event);
virtual void resize(Q_INT32 w, Q_INT32 h);
public:
Q_INT32 docWidth() const;
......@@ -110,7 +112,7 @@ signals:
void cursorEnter();
void cursorLeave();
public slots:
public slots:
void dialog_gradient();
void slotSetFGColor(const KoColor& c);
void slotSetBGColor(const KoColor& c);
......@@ -124,25 +126,33 @@ signals:
void imgResizeToActiveLayer();
void add_new_image_tab();
void remove_current_image_tab();
void resizeCurrentImage(Q_INT32 w, Q_INT32 h);
void scaleCurrentImage(double sx, double sy);
// tool action slots
void tool_properties();
// settings action slots
void preferences();
// Layer action slots
void copy();
void cut();
void removeSelection();
void paste();
void copySelectionToNewLayer();
void layer_rotate180();
void layer_rotateleft90();
void layer_rotateright90();
void layer_rotate_custom();
void layer_mirrorX();
void layer_mirrorY();
void rotateLayer180();
void rotateLayerLeft90();
void rotateLayerRight90();
void rotateLayerCustom();
void mirrorLayerX();
void mirrorLayerY();
void resizeLayer(Q_INT32 w, Q_INT32 h);
void scaleLayer(double sx, double sy);
void selectAll();
void unSelectAll();
// settings action slots
void preferences();
protected:
virtual void resizeEvent(QResizeEvent*);
......@@ -253,7 +263,7 @@ private slots:
void layerSelected(int n);
void layerToggleLinked();
void layerProperties();
void layerResize();
void layerResizeToImage();
void layerToImage();
void layerTransform();
......@@ -269,7 +279,6 @@ private slots:
void layerLevel(int n);
void layersUpdated();
void layersUpdated(KisImageSP img);
void layerTransform(bool smooth);
QPoint mapToScreen(const QPoint& pt);
void merge_all_layers();
......@@ -333,7 +342,6 @@ private:
KAction *m_layerLower;
KAction *m_layerProperties;
KAction *m_layerRaise;
KAction *m_layerResize;
KAction *m_layerResizeToImage;
KAction *m_layerRm;
KAction *m_layerSaveAs;
......
......@@ -60,13 +60,13 @@
<Action name="save_layer_as_image"/>
<Action name="layer_to_image"/>
<Separator/>
<Action name="layer_rotateright90"/>
<Action name="layer_rotate180"/>
<Action name="layer_rotateleft90"/>
<!--Action name="layer_rotate_custom"/-->
<Action name="rotateLayerRight90"/>
<Action name="rotateLayer180"/>
<Action name="rotateLayerLeft90"/>
<!--Action name="rotateLayerCustom"/-->
<Separator/>
<Action name="layer_mirrorX"/>
<Action name="layer_mirrorY"/>
<Action name="mirrorLayerX"/>
<Action name="mirrorLayerY"/>
<Separator/>
<Action name="layer_properties"/>
<Separator/>
......
......@@ -50,7 +50,7 @@ DlgImageSize::DlgImageSize( QWidget * parent,
m_lock = false;
m_page = new WdgImageSize(this, "image_size");
setCaption(i18n("Image Size"));
setMainWidget(m_page);
resize(m_page -> sizeHint());
......
......@@ -55,13 +55,15 @@
typedef KGenericFactory<ImageSize> ImageSizeFactory;
K_EXPORT_COMPONENT_FACTORY( imagesize, ImageSizeFactory( "krita" ) )
// XXX: this plugin could also provide layer scaling/resizing
ImageSize::ImageSize(QObject *parent, const char *name, const QStringList &)
: KParts::Plugin(parent, name)
{
setInstance(ImageSizeFactory::instance());
kdDebug() << "ImageSize\n";
(void) new KAction(i18n("&Image Size..."), 0, 0, this, SLOT(slotActivated()), actionCollection(), "imagesize");
(void) new KAction(i18n("&Image Size..."), 0, 0, this, SLOT(slotImageSize()), actionCollection(), "imagesize");
(void) new KAction(i18n("&Layer Size..."), 0, 0, this, SLOT(slotLayerSize()), actionCollection(), "layersize");
if ( !parent->inherits("KisView") )
{
......@@ -76,13 +78,14 @@ ImageSize::~ImageSize()
m_view = 0;
}
void ImageSize::slotActivated()
void ImageSize::slotImageSize()
{
KisImageSP image = m_view -> currentImg();
if (!image) return;
DlgImageSize * dlgImageSize = new DlgImageSize(m_view, "ImageSize");
dlgImageSize -> setCaption(i18n("Image Size"));
KisConfig cfg;
......@@ -101,44 +104,53 @@ void ImageSize::slotActivated()
Q_INT32 h = dlgImageSize -> height();
if (dlgImageSize -> scale()) {
imageScale(w, h);
m_view -> scaleCurrentImage((double)w / ((double)(image -> width())),
(double)h / ((double)(image -> height())));
}
else {
imageResize(w, h);
m_view -> resizeCurrentImage(w, h);
}
}
delete dlgImageSize;
}
void ImageSize::imageResize(Q_INT32 w, Q_INT32 h)
void ImageSize::slotLayerSize()
{
kdDebug() << "Resizing to: Width: " << w << ", Height: " << h << "\n";
if (m_view) {
#if 1
m_view -> resize(w, h);
#else
// XXX: this doesn't work -- but why?
KisImageSP image = m_view -> currentImg();
if (image) {
image -> resize(w, h);
image -> invalidate();
m_view -> refresh();
}
#endif
}
}
KisImageSP image = m_view -> currentImg();
void ImageSize::imageScale(Q_INT32 w, Q_INT32 h)
{
if (m_view) {
// XXX
if (!image) return;
DlgImageSize * dlgImageSize = new DlgImageSize(m_view, "LayerSize");
dlgImageSize -> setCaption("Layer Size");
// dlgImageSize -> chkConstrain -> setCaption("Resample layer");
KisConfig cfg;
dlgImageSize -> setWidth(image -> width());
dlgImageSize -> setHeight(image -> height());
dlgImageSize -> setMaximumWidth(cfg.maxImgWidth());
dlgImageSize -> setMaximumHeight(cfg.maxImgHeight());
double x, y;
image -> resolution(&x, &y);
dlgImageSize -> setXRes(x);
dlgImageSize -> setYRes(y);
if (dlgImageSize -> exec() == QDialog::Accepted) {
Q_INT32 w = dlgImageSize -> width();
Q_INT32 h = dlgImageSize -> height();
if (dlgImageSize -> scale()) {
m_view -> scaleLayer((double)w / ((double)(image -> width())), (double)h / ((double)(image -> height())));
}
else {
m_view -> resizeLayer(w, h);
}
}
delete dlgImageSize;
}
#include "imagesize.moc"
......@@ -35,13 +35,11 @@ public:
private slots:
void slotActivated();
void slotImageSize();
void slotLayerSize();
private:
void imageResize(Q_INT32 w, Q_INT32 h);
void imageScale(Q_INT32 w, Q_INT32 h);
KisView * m_view;
KisPainter * m_painter;
......
......@@ -4,7 +4,10 @@
<Menu name="Image"><text>Image</text>
<Separator/>
<Action name="imagesize"/>
</Menu>
<Menu name="Layer"><text>Layer</text>
<Separator/>
<Action name="layersize">
</Menu>
</MenuBar>
</kpartgui>
......@@ -42,7 +42,7 @@ KisDlgTransform::KisDlgTransform( QWidget * parent,
resize(m_page -> sizeHint());
}
QWMatrix & KisDlgTransform::matrix()
KisDlgTransform::~KisDlgTransform()
{
delete m_page;
}
......
......@@ -41,10 +41,9 @@ public:
KisDlgTransform( QWidget * parent = 0,
const char * name = 0);
virtual ~KisDlgTransform();
QWMatrix & matrix();
private:
private:
WdgMatrix * m_page;
};
......
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