1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
// Copyright (c) 2008 GeometryFactory Sarl (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
//
// $URL: https://github.com/CGAL/cgal/blob/v6.1.1/GraphicsView/include/CGAL/Qt/LineGraphicsItem.h $
// $Id: include/CGAL/Qt/LineGraphicsItem.h 08b27d3db14 $
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
//
//
// Author(s) : Andreas Fabri <Andreas.Fabri@geometryfactory.com>
// Laurent Rineau <Laurent.Rineau@geometryfactory.com>
#ifndef CGAL_QT_LINE_GRAPHICS_ITEM_H
#define CGAL_QT_LINE_GRAPHICS_ITEM_H
#include <CGAL/license/GraphicsView.h>
#include <CGAL/Bbox_2.h>
#include <CGAL/Qt/PainterOstream.h>
#include <CGAL/Qt/GraphicsItem.h>
#include <CGAL/Qt/utility.h>
#include <QGraphicsScene>
#include <QPainter>
#include <QStyleOption>
namespace CGAL {
namespace Qt {
template <typename CK>
class LineGraphicsItem : public GraphicsItem
{
typedef typename CK::Line_2 Line_2;
public:
LineGraphicsItem();
void modelChanged();
public:
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
const QPen& Pen() const
{
return this->pen;
}
void setPen(const QPen& pen_)
{
this->pen = pen_;
}
void setLine(const Line_2& a);
Line_2 line() const
{
return line_;
}
protected:
QPainter* m_painter;
PainterOstream<CK> painterostream;
QPen pen;
Line_2 line_;
};
template <typename CK>
void
LineGraphicsItem<CK>::setLine(const Line_2& a)
{
line_ = a;
update();
}
template <typename CK>
LineGraphicsItem<CK>::LineGraphicsItem()
: painterostream(0)
{
this->hide();
setZValue(13);
}
template <typename CK>
QRectF
LineGraphicsItem<CK>::boundingRect() const
{
if(scene()){
return CGAL::Qt::viewportsBbox(scene());
}
return QRectF();
}
template <typename CK>
void
LineGraphicsItem<CK>::paint(QPainter *painter,
const QStyleOptionGraphicsItem * /*option*/,
QWidget * /*widget*/)
{
painter->setPen(this->Pen());
painterostream = PainterOstream<CK>(painter, boundingRect());
painterostream << line_;
}
template <typename CK>
void
LineGraphicsItem<CK>::modelChanged()
{
update();
}
} // namespace Qt
} // namespace CGAL
#endif // CGAL_QT_LINE_GRAPHICS_ITEM_H
|