fix BRect calc for non-custom items
This commit is contained in:
parent
665bea53cf
commit
c37df54c0f
|
@ -94,6 +94,10 @@ SET(TechDrawGuiView_SRCS
|
|||
QGCustomSvg.h
|
||||
QGCustomClip.cpp
|
||||
QGCustomClip.h
|
||||
QGCustomLabel.cpp
|
||||
QGCustomLabel.h
|
||||
QGCustomBorder.cpp
|
||||
QGCustomBorder.h
|
||||
QGIView.cpp
|
||||
QGIView.h
|
||||
QGIArrow.cpp
|
||||
|
|
75
src/Mod/TechDraw/Gui/QGCustomBorder.cpp
Normal file
75
src/Mod/TechDraw/Gui/QGCustomBorder.cpp
Normal file
|
@ -0,0 +1,75 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2016 WandererFan <wandererfan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
#include <assert.h>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSceneHoverEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Material.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
|
||||
#include <qmath.h>
|
||||
#include <QRectF>
|
||||
#include "QGCustomBorder.h"
|
||||
|
||||
using namespace TechDrawGui;
|
||||
|
||||
QGCustomBorder::QGCustomBorder()
|
||||
{
|
||||
setCacheMode(QGraphicsItem::NoCache);
|
||||
}
|
||||
|
||||
void QGCustomBorder::centerAt(QPointF centerPos)
|
||||
{
|
||||
QRectF box = boundingRect();
|
||||
double width = box.width();
|
||||
double height = box.height();
|
||||
double newX = centerPos.x() - width/2.;
|
||||
double newY = centerPos.y() - height/2.;
|
||||
setPos(newX,newY);
|
||||
}
|
||||
|
||||
void QGCustomBorder::centerAt(double cX, double cY)
|
||||
{
|
||||
QRectF box = boundingRect();
|
||||
double width = box.width();
|
||||
double height = box.height();
|
||||
double newX = cX - width/2.;
|
||||
double newY = cY - height/2.;
|
||||
setPos(newX,newY);
|
||||
}
|
||||
|
||||
|
||||
void QGCustomBorder::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) {
|
||||
QStyleOptionGraphicsItem myOption(*option);
|
||||
myOption.state &= ~QStyle::State_Selected;
|
||||
|
||||
QGraphicsRectItem::paint (painter, &myOption, widget);
|
||||
}
|
59
src/Mod/TechDraw/Gui/QGCustomBorder.h
Normal file
59
src/Mod/TechDraw/Gui/QGCustomBorder.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2016 WandererFan <wandererfan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef DRAWINGGUI_QGCUSTOMBORDER_H
|
||||
#define DRAWINGGUI_QGCUSTOMBORDER_H
|
||||
|
||||
#include <QGraphicsItem>
|
||||
#include <QGraphicsRectItem>
|
||||
#include <QPointF>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QPainter;
|
||||
class QStyleOptionGraphicsItem;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace TechDrawGui
|
||||
{
|
||||
|
||||
class TechDrawGuiExport QGCustomBorder : public QGraphicsRectItem
|
||||
{
|
||||
public:
|
||||
explicit QGCustomBorder(void);
|
||||
~QGCustomBorder() {}
|
||||
|
||||
enum {Type = QGraphicsItem::UserType + 136};
|
||||
int type() const { return Type;}
|
||||
|
||||
virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );
|
||||
virtual void centerAt(QPointF centerPos);
|
||||
virtual void centerAt(double cX, double cY);
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
} // namespace MDIViewPageGui
|
||||
|
||||
#endif // DRAWINGGUI_QGCUSTOMBORDER_H
|
76
src/Mod/TechDraw/Gui/QGCustomLabel.cpp
Normal file
76
src/Mod/TechDraw/Gui/QGCustomLabel.cpp
Normal file
|
@ -0,0 +1,76 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2015 WandererFan <wandererfan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
#include <assert.h>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSceneHoverEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QPaintDevice>
|
||||
#include <QPainter>
|
||||
#include <QPrinter>
|
||||
#include <QSvgGenerator>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Material.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
|
||||
#include <qmath.h>
|
||||
#include <QRectF>
|
||||
#include "QGCustomLabel.h"
|
||||
|
||||
using namespace TechDrawGui;
|
||||
|
||||
QGCustomLabel::QGCustomLabel()
|
||||
{
|
||||
setCacheMode(QGraphicsItem::NoCache);
|
||||
}
|
||||
|
||||
void QGCustomLabel::centerAt(QPointF centerPos)
|
||||
{
|
||||
QRectF box = boundingRect();
|
||||
double width = box.width();
|
||||
double height = box.height();
|
||||
double newX = centerPos.x() - width/2.;
|
||||
double newY = centerPos.y() - height/2.;
|
||||
setPos(newX,newY);
|
||||
}
|
||||
|
||||
void QGCustomLabel::centerAt(double cX, double cY)
|
||||
{
|
||||
QRectF box = boundingRect();
|
||||
double width = box.width();
|
||||
double height = box.height();
|
||||
double newX = cX - width/2.;
|
||||
double newY = cY - height/2.;
|
||||
setPos(newX,newY);
|
||||
}
|
||||
|
||||
void QGCustomLabel::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) {
|
||||
QStyleOptionGraphicsItem myOption(*option);
|
||||
myOption.state &= ~QStyle::State_Selected;
|
||||
QGraphicsTextItem::paint (painter, &myOption, widget);
|
||||
}
|
59
src/Mod/TechDraw/Gui/QGCustomLabel.h
Normal file
59
src/Mod/TechDraw/Gui/QGCustomLabel.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2015 WandererFan <wandererfan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef DRAWINGGUI_QGCUSTOMLABEL_H
|
||||
#define DRAWINGGUI_QGCUSTOMLABEL_H
|
||||
|
||||
#include <QGraphicsItem>
|
||||
#include <QGraphicsTextItem>
|
||||
#include <QPointF>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QPainter;
|
||||
class QStyleOptionGraphicsItem;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace TechDrawGui
|
||||
{
|
||||
|
||||
class TechDrawGuiExport QGCustomLabel : public QGraphicsTextItem
|
||||
{
|
||||
public:
|
||||
explicit QGCustomLabel(void);
|
||||
~QGCustomLabel() {}
|
||||
|
||||
enum {Type = QGraphicsItem::UserType + 135};
|
||||
int type() const { return Type;}
|
||||
|
||||
virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );
|
||||
virtual void centerAt(QPointF centerPos);
|
||||
virtual void centerAt(double cX, double cY);
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
} // namespace MDIViewPageGui
|
||||
|
||||
#endif // DRAWINGGUI_QGCUSTOMLABEL_H
|
|
@ -47,12 +47,15 @@
|
|||
#include <Gui/Selection.h>
|
||||
#include <Gui/Command.h>
|
||||
|
||||
#include "../App/DrawView.h"
|
||||
#include "../App/DrawViewClip.h"
|
||||
#include "QGCustomBorder.h"
|
||||
#include "QGCustomLabel.h"
|
||||
|
||||
#include "QGIView.h"
|
||||
#include "QGCustomClip.h"
|
||||
#include "QGIViewClip.h"
|
||||
|
||||
#include "../App/DrawViewClip.h"
|
||||
|
||||
using namespace TechDrawGui;
|
||||
|
||||
void _debugRect(char* text, QRectF r);
|
||||
|
@ -90,14 +93,15 @@ QGIView::QGIView(const QPoint &pos, QGraphicsScene *scene)
|
|||
if(scene) // TODO: Get rid of the ctor args as in the refactor attempt
|
||||
scene->addItem(this);
|
||||
|
||||
m_label = new QGraphicsTextItem();
|
||||
m_decorPen.setStyle(Qt::DashLine);
|
||||
m_decorPen.setWidth(0); // 0 => 1px "cosmetic pen"
|
||||
|
||||
m_label = new QGCustomLabel();
|
||||
addToGroup(m_label);
|
||||
m_label->setFont(m_font);
|
||||
|
||||
m_border = new QGraphicsRectItem();
|
||||
m_border = new QGCustomBorder();
|
||||
addToGroup(m_border);
|
||||
m_decorPen.setStyle(Qt::DashLine);
|
||||
m_decorPen.setWidth(0); // 0 => 1px "cosmetic pen"
|
||||
}
|
||||
|
||||
|
||||
|
@ -354,16 +358,17 @@ void QGIView::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q
|
|||
QGraphicsItemGroup::paint(painter, &myOption, widget);
|
||||
}
|
||||
|
||||
//This should count everything except Frame,Label,Dimension - custom or not
|
||||
QRectF QGIView::customChildrenBoundingRect() {
|
||||
QList<QGraphicsItem*> children = childItems();
|
||||
int dimItemType = QGraphicsItem::UserType + 106;
|
||||
int dimItemType = QGraphicsItem::UserType + 106; // TODO: Magic number warning. make include file for custom types?
|
||||
int borderItemType = QGraphicsItem::UserType + 136; // TODO: Magic number warning
|
||||
int labelItemType = QGraphicsItem::UserType + 135; // TODO: Magic number warning
|
||||
QRectF result;
|
||||
for (QList<QGraphicsItem*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
if ((*it)->type() >= QGraphicsItem::UserType) {
|
||||
if ((*it)->type() != dimItemType) { //Dimensions don't count towards bRect
|
||||
result = result.united((*it)->boundingRect());
|
||||
}
|
||||
if ( ((*it)->type() != dimItemType) &&
|
||||
((*it)->type() != borderItemType) &&
|
||||
((*it)->type() != labelItemType) ) {
|
||||
result = result.united((*it)->boundingRect());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -27,17 +27,17 @@
|
|||
#include <QObject>
|
||||
#include <App/PropertyLinks.h>
|
||||
|
||||
#include "../App/DrawView.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QGraphicsScene;
|
||||
class QGraphicsSceneMouseEvent;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace TechDraw {
|
||||
class DrawView;
|
||||
}
|
||||
|
||||
namespace TechDrawGui
|
||||
{
|
||||
class QGCustomBorder;
|
||||
class QGCustomLabel;
|
||||
|
||||
class TechDrawGuiExport QGIView : public QObject, public QGraphicsItemGroup
|
||||
{
|
||||
|
@ -102,8 +102,8 @@ protected:
|
|||
QColor m_colPre;
|
||||
QColor m_colSel;
|
||||
QFont m_font;
|
||||
QGraphicsTextItem* m_label;
|
||||
QGraphicsRectItem* m_border;
|
||||
QGCustomLabel* m_label;
|
||||
QGCustomBorder* m_border;
|
||||
QPen m_decorPen;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user