krita

kis_grid_drawer.h

00001 /*
00002  * This file is part of Krita
00003  *
00004  *  Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #ifndef KIS_GRID_DRAWER_H
00022 #define KIS_GRID_DRAWER_H
00023 
00024 #include <math.h>
00025 
00026 #include <qobject.h>
00027 #include <qpainter.h>
00028 
00029 #include "kis_types.h"
00030 #include "kis_point.h"
00031 
00032 class KisSubPerspectiveGrid;
00033 
00034 class GridDrawer {
00035     public:
00036         GridDrawer() {}
00037         virtual ~GridDrawer() {}
00038     
00039     public:
00040         void drawGrid(KisImageSP image, const QRect& wr);
00041         void drawPerspectiveGrid(KisImageSP image, const QRect& wr, const KisSubPerspectiveGrid* grid);
00042     
00043         virtual void setPen(const QPen& pen) = 0;
00044         virtual void drawLine(Q_INT32 x1, Q_INT32 y1, Q_INT32 x2, Q_INT32 y2) = 0;
00045         inline void drawLine(const QPoint& p1, const QPoint& p2) { drawLine(p1.x(), p1.y(), p2.x(), p2.y() ); }
00046         inline void drawLine(const KisPoint* p1, const KisPoint* p2) { drawLine( p1->roundQPoint(), p2->roundQPoint()); }
00047     private:
00048         Qt::PenStyle gs2style(Q_UINT32 s);
00049 };
00050 
00051 class QPainterGridDrawer : public GridDrawer {
00052 public:
00053     QPainterGridDrawer(QPainter *p) { m_painter = p; }
00054 
00055     virtual void setPen(const QPen& pen) { m_painter->setPen(pen); }
00056     virtual void drawLine(Q_INT32 x1, Q_INT32 y1, Q_INT32 x2, Q_INT32 y2) { m_painter->drawLine(x1, y1, x2, y2); }
00057 
00058 private:
00059     QPainter *m_painter;
00060 };
00061 
00062 class OpenGLGridDrawer : public GridDrawer {
00063 public:
00064     OpenGLGridDrawer();
00065     virtual ~OpenGLGridDrawer();
00066 
00067     virtual void setPen(const QPen& pen);
00068     virtual void drawLine(Q_INT32 x1, Q_INT32 y1, Q_INT32 x2, Q_INT32 y2);
00069 };
00070 
00071 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys