krita/ui

kis_abstract_canvas_widget.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) Adrian Page <adrian@pagenet.plus.com>, (C) 2007
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #include "kis_abstract_canvas_widget.h"
00020 #include <QImage>
00021 #include <QPainter>
00022 
00023 #include <KoShapeManager.h>
00024 #include <KoViewConverter.h>
00025 #include <KoToolProxy.h>
00026 
00027 #include "kis_canvas_decoration.h"
00028 #include "../kis_config.h"
00029 #include "kis_canvas2.h"
00030 #include "../kis_view2.h"
00031 #include "../kis_selection_manager.h"
00032 
00033 void KisAbstractCanvasWidget::drawDecorations(QPainter & gc, bool tools,
00034         const QPoint & documentOffset,
00035         const QRect & clipRect,
00036         KisCanvas2 * canvas)
00037 {
00038     // Setup the painter to take care of the offset; all that the
00039     // classes that do painting need to keep track of is resolution
00040     gc.setRenderHint(QPainter::Antialiasing);
00041     gc.setRenderHint(QPainter::TextAntialiasing);
00042     gc.setRenderHint(QPainter::HighQualityAntialiasing);
00043     gc.setRenderHint(QPainter::SmoothPixmapTransform);
00044     gc.translate(QPoint(-documentOffset.x(), -documentOffset.y()));
00045     gc.translate(documentOrigin());
00046 
00047     // Paint the shapes (other than the layers)
00048     gc.save();
00049     gc.setClipRect(clipRect);
00050     canvas->globalShapeManager()->paint(gc, *canvas->viewConverter(), false);
00051     gc.restore();
00052 
00053     // ask the decorations to paint themselves
00054     foreach(KisCanvasDecoration* deco, m_decorations) {
00055         deco->paint(gc, documentOffset, clipRect, *canvas->viewConverter());
00056     }
00057 
00058     // Give the tool a chance to paint its stuff
00059     if (tools) {
00060         gc.save();
00061         toolProxy()->paint(gc, *canvas->viewConverter());
00062         gc.restore();
00063     }
00064 }
00065 
00066 QImage KisAbstractCanvasWidget::checkImage(qint32 checkSize)
00067 {
00068     KisConfig cfg;
00069 
00070     QImage tile(checkSize * 2, checkSize * 2, QImage::Format_RGB32);
00071     QPainter pt(&tile);
00072     pt.fillRect(tile.rect(), Qt::white);
00073     pt.fillRect(0, 0, checkSize, checkSize, cfg.checkersColor());
00074     pt.fillRect(checkSize, checkSize, checkSize, checkSize, cfg.checkersColor());
00075     pt.end();
00076 
00077     return tile;
00078 }
00079 
00080 void KisAbstractCanvasWidget::addDecoration(KisCanvasDecoration* deco)
00081 {
00082     m_decorations.push_back(deco);
00083 }
00084 
00085 KisCanvasDecoration* KisAbstractCanvasWidget::decoration(const QString& id)
00086 {
00087     foreach(KisCanvasDecoration* deco, m_decorations) {
00088         if (deco->id() == id) {
00089             return deco;
00090         }
00091     }
00092     return 0;
00093 }
00094