1
/***************************************************************************
2
* Copyright (c) 2012-2013 Luke Parry <l.parry@warwick.ac.uk> *
4
* This file is part of the FreeCAD CAx development system. *
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. *
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. *
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 *
21
***************************************************************************/
23
#include "PreCompiled.h"
25
# include <QGraphicsScene>
26
# include <QGraphicsSceneMouseEvent>
30
#include <App/Document.h>
31
#include <Base/Console.h>
32
#include <Gui/Selection.h>
33
#include <Mod/TechDraw/App/DrawProjGroup.h>
34
#include <Mod/TechDraw/App/DrawProjGroupItem.h>
36
#include "QGIProjGroup.h"
40
using namespace TechDrawGui;
42
QGIProjGroup::QGIProjGroup()
44
m_origin = new QGraphicsItemGroup(); //QGIG added to this QGIG??
45
m_origin->setParentItem(this);
47
setFlag(ItemIsSelectable, false);
48
setFlag(ItemIsMovable, true);
49
setFiltersChildEvents(true);
50
// setFrameState(false);
53
TechDraw::DrawProjGroup * QGIProjGroup::getDrawView() const
55
App::DocumentObject *obj = getViewObject();
56
return dynamic_cast<TechDraw::DrawProjGroup *>(obj);
59
bool QGIProjGroup::sceneEventFilter(QGraphicsItem* watched, QEvent *event)
61
// i want to handle events before the child item that would ordinarily receive them
62
if(event->type() == QEvent::GraphicsSceneMousePress ||
63
event->type() == QEvent::GraphicsSceneMouseMove ||
64
event->type() == QEvent::GraphicsSceneMouseRelease) {
66
QGIView *qAnchor = getAnchorQItem();
67
if(qAnchor && watched == qAnchor) {
68
QGraphicsSceneMouseEvent *mEvent = dynamic_cast<QGraphicsSceneMouseEvent*>(event);
70
switch(event->type()) {
71
case QEvent::GraphicsSceneMousePress:
72
// TODO - Perhaps just pass the mouse event on to the anchor somehow?
73
if (scene() && !qAnchor->isSelected()) {
74
scene()->clearSelection();
75
qAnchor->setSelected(true);
77
mousePressEvent(mEvent);
79
case QEvent::GraphicsSceneMouseMove:
80
mouseMoveEvent(mEvent);
82
case QEvent::GraphicsSceneMouseRelease:
83
mouseReleaseEvent(mEvent);
94
QVariant QGIProjGroup::itemChange(GraphicsItemChange change, const QVariant &value)
96
if(change == ItemChildAddedChange && scene()) {
97
QGraphicsItem*childItem = value.value<QGraphicsItem*>();
98
QGIView* gView = dynamic_cast<QGIView *>(childItem);
100
TechDraw::DrawView *fView = gView->getViewObject();
101
if(fView->isDerivedFrom<TechDraw::DrawProjGroupItem>()) {
102
TechDraw::DrawProjGroupItem *projItemPtr = static_cast<TechDraw::DrawProjGroupItem *>(fView);
103
QString type = QString::fromLatin1(projItemPtr->Type.getValueAsString());
105
if (type == QString::fromLatin1("Front")) {
106
gView->alignTo(m_origin, QString::fromLatin1("None"));
107
installSceneEventFilter(gView);
108
} else if ( type == QString::fromLatin1("Top") ||
109
type == QString::fromLatin1("Bottom")) {
110
gView->alignTo(m_origin, QString::fromLatin1("Vertical"));
111
} else if ( type == QString::fromLatin1("Left") ||
112
type == QString::fromLatin1("Right") ||
113
type == QString::fromLatin1("Rear") ) {
114
gView->alignTo(m_origin, QString::fromLatin1("Horizontal"));
115
} else if ( type == QString::fromLatin1("FrontTopRight") ||
116
type == QString::fromLatin1("FrontBottomLeft") ) {
117
gView->alignTo(m_origin, QString::fromLatin1("45slash"));
118
} else if ( type == QString::fromLatin1("FrontTopLeft") ||
119
type == QString::fromLatin1("FrontBottomRight") ) {
120
gView->alignTo(m_origin, QString::fromLatin1("45backslash"));
125
return QGIViewCollection::itemChange(change, value);
128
void QGIProjGroup::mousePressEvent(QGraphicsSceneMouseEvent * event)
130
QGIView *qAnchor = getAnchorQItem();
132
QPointF transPos = qAnchor->mapFromScene(event->scenePos());
133
if(qAnchor->shape().contains(transPos)) {
134
mousePos = event->screenPos();
140
void QGIProjGroup::mouseMoveEvent(QGraphicsSceneMouseEvent * event)
142
QGIView *qAnchor = getAnchorQItem();
143
if(scene() && qAnchor && (qAnchor == scene()->mouseGrabberItem())) {
144
if((mousePos - event->screenPos()).manhattanLength() > 5) { //if the mouse has moved more than 5, process the mouse event
145
QGIViewCollection::mouseMoveEvent(event);
152
void QGIProjGroup::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
155
QGIView *qAnchor = getAnchorQItem();
156
if((mousePos - event->screenPos()).manhattanLength() < 5) {
157
if(qAnchor && qAnchor->shape().contains(event->pos())) {
159
qAnchor->mouseReleaseEvent(event);
161
} else if(scene() && qAnchor) {
163
getViewObject()->setPosition(Rez::appX(x()), Rez::appX(getY()));
166
QGIViewCollection::mouseReleaseEvent(event);
169
QGIView * QGIProjGroup::getAnchorQItem() const
171
// Get the currently assigned anchor view
172
App::DocumentObject *anchorObj = getDrawView()->Anchor.getValue();
173
auto anchorView( dynamic_cast<TechDraw::DrawView *>(anchorObj) );
178
// Locate the anchor view's qgraphicsitemview
179
QList<QGraphicsItem*> list = childItems();
181
for (QList<QGraphicsItem*>::iterator it = list.begin(); it != list.end(); ++it) {
182
QGIView *view = dynamic_cast<QGIView *>(*it);
183
if(view && strcmp(view->getViewName(), anchorView->getNameInDocument()) == 0) {
190
//QGIPG does not rotate. Only individual views rotate
191
void QGIProjGroup::rotateView()
193
Base::Console().Warning("QGIPG: Projection Groups do not rotate. Change ignored\n");
196
void QGIProjGroup::drawBorder()
198
//QGIProjGroup does not have a border!
199
// Base::Console().Message("TRACE - QGIProjGroup::drawBorder - doing nothing!!\n");