FreeCAD/src/Mod/TechDraw/Gui/QGIView.h

129 lines
4.7 KiB
C++

/***************************************************************************
* Copyright (c) 2012-2013 Luke Parry <l.parry@warwick.ac.uk> *
* *
* 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_QGRAPHICSITEMVIEW_H
#define DRAWINGGUI_QGRAPHICSITEMVIEW_H
#include <QGraphicsItemGroup>
#include <QPen>
#include <QFont>
#include <App/PropertyLinks.h>
#include <Base/Parameter.h>
#include <Mod/TechDraw/App/DrawView.h>
QT_BEGIN_NAMESPACE
class QGraphicsScene;
class QGraphicsSceneMouseEvent;
QT_END_NAMESPACE
namespace TechDrawGui
{
class QGCustomBorder;
class QGCustomLabel;
class TechDrawGuiExport QGIView : public QGraphicsItemGroup
{
public:
QGIView();
virtual ~QGIView() = default;
enum {Type = QGraphicsItem::UserType + 101};
int type() const override { return Type;}
const char * getViewName() const;
void setViewFeature(TechDraw::DrawView *obj);
TechDraw::DrawView * getViewObject() const;
virtual void toggleBorder(bool state = true);
virtual void drawBorder(void);
virtual void isVisible(bool state) { m_visibility = state; };
virtual bool isVisible(void) {return m_visibility;};
virtual void draw(void);
/** Methods to ensure that Y-Coordinates are orientated correctly.
* @{ */
void setPosition(qreal x, qreal y);
inline qreal getY() { return y() * -1; }
bool isInnerView() { return m_innerView; }
void isInnerView(bool state) { m_innerView = state; }
double getYInClip(double y);
/** @} */
void alignTo(QGraphicsItem*, const QString &alignment);
void setLocked(bool state = true) { locked = true; }
virtual void toggleCache(bool state);
virtual void updateView(bool update = false);
virtual void paint( QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget = nullptr ) override;
virtual QRectF boundingRect() const override;
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
protected:
QGIView* getQGIVByName(std::string name);
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
// Mouse handling
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
// Preselection events:
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
virtual QRectF customChildrenBoundingRect(void);
void dumpRect(char* text, QRectF r);
QColor getNormalColor(void);
QColor getPreColor(void);
QColor getSelectColor(void);
QString getPrefFont(void);
Base::Reference<ParameterGrp> getParmGroupCol(void);
TechDraw::DrawView *viewObj;
std::string viewName;
QHash<QString, QGraphicsItem*> alignHash;
bool locked;
bool borderVisible;
bool m_visibility;
bool m_innerView; //View is inside another View
QPen m_pen;
QBrush m_brush;
QColor m_colCurrent;
QColor m_colNormal;
QColor m_colPre;
QColor m_colSel;
QFont m_font;
QGCustomLabel* m_label;
QGCustomBorder* m_border;
QPen m_decorPen;
};
} // namespace
#endif // DRAWINGGUI_QGRAPHICSITEMVIEW_H