FreeCAD
1/***************************************************************************
2* Copyright (c) 2015 WandererFan <wandererfan@gmail.com> *
3* *
4* This file is part of the FreeCAD CAx development system. *
5* *
6* This library is free software; you can redistribute it and/or *
7* modify it under the terms of the GNU Library General Public *
8* License as published by the Free Software Foundation; either *
9* version 2 of the License, or (at your option) any later version. *
10* *
11* This library is distributed in the hope that it will be useful, *
12* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14* GNU Library General Public License for more details. *
15* *
16* You should have received a copy of the GNU Library General Public *
17* License along with this library; see the file COPYING.LIB. If not, *
18* write to the Free Software Foundation, Inc., 59 Temple Place, *
19* Suite 330, Boston, MA 02111-1307, USA *
20* *
21***************************************************************************/
22
23#include "PreCompiled.h"24#ifndef _PreComp_25# include <cassert>26
27# include <QPainter>28# include <QRectF>29# include <QStyleOptionGraphicsItem>30#endif31
32#include "QGCustomLabel.h"33
34
35using namespace TechDrawGui;36
37QGCustomLabel::QGCustomLabel()38{
39setCacheMode(QGraphicsItem::NoCache);40setAcceptHoverEvents(false);41setFlag(QGraphicsItem::ItemIsSelectable, false);42setFlag(QGraphicsItem::ItemIsMovable, false);43}
44
45void QGCustomLabel::centerAt(QPointF centerPos)46{
47centerAt(centerPos.x(), centerPos.y());48}
49
50void QGCustomLabel::centerAt(double cX, double cY)51{
52QRectF box = boundingRect();53double width = box.width();54double height = box.height();55double newX = cX - width/2.;56double newY = cY - height/2.;57setPos(newX, newY);58}
59
60void QGCustomLabel::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) {61QStyleOptionGraphicsItem myOption(*option);62myOption.state &= ~QStyle::State_Selected;63
64// painter->drawRect(boundingRect()); //good for debugging
65
66QGraphicsTextItem::paint (painter, &myOption, widget);67}
68