PageRenderTime 38ms CodeModel.GetById 13ms app.highlight 20ms RepoModel.GetById 2ms app.codeStats 0ms

/vp_plugins/global/mygraphicsview.cpp

http://cupsfilter.googlecode.com/
C++ | 55 lines | 45 code | 9 blank | 1 comment | 3 complexity | a9e4868724021d6cb72b8689e4ea72f3 MD5 | raw file
 1#include "mygraphicsview.h"
 2#include "mytypes.h"
 3#include <QVarLengthArray>
 4
 5myGraphicsView::myGraphicsView( QWidget * parent)
 6    :QGraphicsView(parent)
 7    ,gridInterval(int (MM_TO_POINT(5)))
 8    ,gridShow(true)
 9{
10}
11myGraphicsView::myGraphicsView(QGraphicsScene * scene, QWidget * parent)
12    :QGraphicsView(scene,parent)
13    ,gridInterval(int (MM_TO_POINT(5)))
14    ,gridShow(true)
15{
16}
17
18void myGraphicsView::setShowGrid(bool g_show)
19{
20    gridShow = g_show;
21    this->repaint();
22}
23
24void myGraphicsView::setInterval(int i)
25{
26    gridInterval = int(MM_TO_POINT(i) >MM_TO_POINT(5) ? MM_TO_POINT(i) :MM_TO_POINT(5));
27    gridShow = true;
28   this->repaint();
29}
30
31void myGraphicsView::drawForeground  ( QPainter * painter, const QRectF & rect )
32{
33    painter->setWorldMatrixEnabled(true);
34
35    if ( gridShow ){
36        //interval to draw grid lines at        
37         painter->setPen(QPen(Qt::green, 1, Qt::SolidLine));
38    }else{
39         painter->setPen(QPen(Qt::white, 1, Qt::SolidLine));
40    }
41
42    qreal left = int(rect.left()) - (int(rect.left()) % gridInterval );
43    qreal top = int(rect.top()) - (int(rect.top()) % gridInterval );
44
45    QVarLengthArray<QLineF> linesX;
46    for (qreal x = left; x < rect.right(); x += gridInterval )
47        linesX.append(QLineF(x, rect.top(), x, rect.bottom()));
48
49    QVarLengthArray<QLineF> linesY;
50    for (qreal y = top; y < rect.bottom(); y += gridInterval )
51        linesY.append(QLineF(rect.left(), y, rect.right(), y));
52
53    painter->drawLines(linesX.data(), linesX.size());
54    painter->drawLines(linesY.data(), linesY.size());
55}