From 5bfdad804affed84f1b85991f3bd1f550ad54e05 Mon Sep 17 00:00:00 2001 From: WandererFan Date: Sun, 6 Nov 2016 11:54:07 -0500 Subject: [PATCH] Basic working ViewImage --- src/Mod/TechDraw/App/AppTechDraw.cpp | 2 + src/Mod/TechDraw/App/CMakeLists.txt | 4 +- src/Mod/TechDraw/App/DrawViewImage.cpp | 98 ++++ src/Mod/TechDraw/App/DrawViewImage.h | 74 +++ src/Mod/TechDraw/Gui/AppTechDrawGui.cpp | 3 + src/Mod/TechDraw/Gui/CMakeLists.txt | 6 + src/Mod/TechDraw/Gui/CommandDecorate.cpp | 53 ++ src/Mod/TechDraw/Gui/MDIViewPage.cpp | 4 + src/Mod/TechDraw/Gui/QGCustomImage.cpp | 92 ++++ src/Mod/TechDraw/Gui/QGCustomImage.h | 63 +++ src/Mod/TechDraw/Gui/QGIUserTypes.h | 2 + src/Mod/TechDraw/Gui/QGIView.cpp | 2 + src/Mod/TechDraw/Gui/QGIViewImage.cpp | 144 ++++++ src/Mod/TechDraw/Gui/QGIViewImage.h | 64 +++ src/Mod/TechDraw/Gui/QGVPage.cpp | 13 + src/Mod/TechDraw/Gui/QGVPage.h | 3 + src/Mod/TechDraw/Gui/Resources/TechDraw.qrc | 1 + .../icons/actions/techdraw-image.svg | 481 ++++++++++++++++++ src/Mod/TechDraw/Gui/ViewProviderImage.cpp | 87 ++++ src/Mod/TechDraw/Gui/ViewProviderImage.h | 59 +++ src/Mod/TechDraw/Gui/Workbench.cpp | 3 + 21 files changed, 1257 insertions(+), 1 deletion(-) create mode 100644 src/Mod/TechDraw/App/DrawViewImage.cpp create mode 100644 src/Mod/TechDraw/App/DrawViewImage.h create mode 100644 src/Mod/TechDraw/Gui/QGCustomImage.cpp create mode 100644 src/Mod/TechDraw/Gui/QGCustomImage.h create mode 100644 src/Mod/TechDraw/Gui/QGIViewImage.cpp create mode 100644 src/Mod/TechDraw/Gui/QGIViewImage.h create mode 100644 src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-image.svg create mode 100644 src/Mod/TechDraw/Gui/ViewProviderImage.cpp create mode 100644 src/Mod/TechDraw/Gui/ViewProviderImage.h diff --git a/src/Mod/TechDraw/App/AppTechDraw.cpp b/src/Mod/TechDraw/App/AppTechDraw.cpp index 986f8a05b..7bd8d5367 100644 --- a/src/Mod/TechDraw/App/AppTechDraw.cpp +++ b/src/Mod/TechDraw/App/AppTechDraw.cpp @@ -35,6 +35,7 @@ #include "DrawViewArch.h" #include "DrawViewSpreadsheet.h" #include "DrawViewMulti.h" +#include "DrawViewImage.h" namespace TechDraw { extern PyObject* initModule(); @@ -81,6 +82,7 @@ PyMODINIT_FUNC initTechDraw() TechDraw::DrawHatch ::init(); TechDraw::DrawViewDraft ::init(); TechDraw::DrawViewArch ::init(); + TechDraw::DrawViewImage ::init(); // Python Types TechDraw::DrawViewPython ::init(); diff --git a/src/Mod/TechDraw/App/CMakeLists.txt b/src/Mod/TechDraw/App/CMakeLists.txt index 85e16d677..65b351f24 100644 --- a/src/Mod/TechDraw/App/CMakeLists.txt +++ b/src/Mod/TechDraw/App/CMakeLists.txt @@ -80,7 +80,9 @@ SET(Draw_SRCS DrawViewArch.cpp DrawViewArch.h DrawViewMulti.cpp - DrawViewMulti.h) + DrawViewMulti.h + DrawViewImage.cpp + DrawViewImage.h) SET(TechDraw_SRCS AppTechDraw.cpp diff --git a/src/Mod/TechDraw/App/DrawViewImage.cpp b/src/Mod/TechDraw/App/DrawViewImage.cpp new file mode 100644 index 000000000..d93fc06a1 --- /dev/null +++ b/src/Mod/TechDraw/App/DrawViewImage.cpp @@ -0,0 +1,98 @@ +/*************************************************************************** + * 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 +#endif + +#include +#include +#include + +#include +#include +#include + +#include "DrawViewImage.h" + +using namespace TechDraw; +using namespace std; + + +//=========================================================================== +// DrawViewImage +//=========================================================================== + +PROPERTY_SOURCE(TechDraw::DrawViewImage, TechDraw::DrawView) + + +DrawViewImage::DrawViewImage(void) +{ + static const char *vgroup = "Image"; + + ADD_PROPERTY_TYPE(ImageFile,(""),vgroup,App::Prop_None,"The file containing this bitmap"); + ADD_PROPERTY_TYPE(Width ,(100),vgroup,App::Prop_None,"The width of the image view"); + ADD_PROPERTY_TYPE(Height ,(100),vgroup,App::Prop_None,"The height of the view"); + ScaleType.setValue("Custom"); +} + +DrawViewImage::~DrawViewImage() +{ +} + +void DrawViewImage::onChanged(const App::Property* prop) +{ + if (prop == &ImageFile) { + if (!isRestoring()) { + } + } + TechDraw::DrawView::onChanged(prop); +} + +App::DocumentObjectExecReturn *DrawViewImage::execute(void) +{ + return DrawView::execute(); +} + +QRectF DrawViewImage::getRect() const +{ + QRectF result(0.0,0.0,Width.getValue(),Height.getValue()); + return result; +} + + +// Python Drawing feature --------------------------------------------------------- + +namespace App { +/// @cond DOXERR +PROPERTY_SOURCE_TEMPLATE(TechDraw::DrawViewImagePython, TechDraw::DrawViewImage) +template<> const char* TechDraw::DrawViewImagePython::getViewProviderName(void) const { + return "TechDrawGui::ViewProviderImage"; +} +/// @endcond + +// explicit template instantiation +template class TechDrawExport FeaturePythonT; +} diff --git a/src/Mod/TechDraw/App/DrawViewImage.h b/src/Mod/TechDraw/App/DrawViewImage.h new file mode 100644 index 000000000..9f241138e --- /dev/null +++ b/src/Mod/TechDraw/App/DrawViewImage.h @@ -0,0 +1,74 @@ +/*************************************************************************** + * 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 _DrawViewImage_h_ +#define _DrawViewImage_h_ + +#include +#include +#include +#include "DrawView.h" +#include + +#include + +namespace TechDraw +{ + + +class TechDrawExport DrawViewImage : public TechDraw::DrawView +{ + PROPERTY_HEADER(TechDraw::DrawViewImage); + +public: + /// Constructor + DrawViewImage(void); + virtual ~DrawViewImage(); + + App::PropertyFile ImageFile; + App::PropertyFloat Width; + App::PropertyFloat Height; + + /** @name methods overide Feature */ + //@{ + /// recalculate the Feature + virtual App::DocumentObjectExecReturn *execute(void); + //@} + + /// returns the type name of the ViewProvider + virtual const char* getViewProviderName(void) const { + return "TechDrawGui::ViewProviderImage"; + } + virtual QRectF getRect() const; + +protected: + virtual void onChanged(const App::Property* prop); + Base::BoundBox3d bbox; +}; + +typedef App::FeaturePythonT DrawViewImagePython; + + +} //namespace TechDraw + + +#endif diff --git a/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp b/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp index dfb5ba097..7a651a47b 100644 --- a/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp +++ b/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp @@ -48,6 +48,8 @@ #include "ViewProviderViewClip.h" #include "ViewProviderHatch.h" #include "ViewProviderSpreadsheet.h" +#include "ViewProviderImage.h" + // use a different name to CreateCommand() void CreateTechDrawCommands(void); @@ -100,6 +102,7 @@ void TechDrawGuiExport initTechDrawGui() TechDrawGui::ViewProviderArch::init(); TechDrawGui::ViewProviderHatch::init(); TechDrawGui::ViewProviderSpreadsheet::init(); + TechDrawGui::ViewProviderImage::init(); // register preferences pages new Gui::PrefPageProducer ("TechDraw"); diff --git a/src/Mod/TechDraw/Gui/CMakeLists.txt b/src/Mod/TechDraw/Gui/CMakeLists.txt index a89b583d4..4c941aed6 100644 --- a/src/Mod/TechDraw/Gui/CMakeLists.txt +++ b/src/Mod/TechDraw/Gui/CMakeLists.txt @@ -103,6 +103,8 @@ SET(TechDrawGuiView_SRCS QGCustomLabel.h QGCustomBorder.cpp QGCustomBorder.h + QGCustomImage.cpp + QGCustomImage.h QGIView.cpp QGIView.h QGIArrow.cpp @@ -135,6 +137,8 @@ SET(TechDrawGuiView_SRCS QGIViewSymbol.h QGIViewSpreadsheet.cpp QGIViewSpreadsheet.h + QGIViewImage.cpp + QGIViewImage.h QGIViewClip.cpp QGIViewClip.h QGIPrimPath.cpp @@ -180,6 +184,8 @@ SET(TechDrawGuiViewProvider_SRCS ViewProviderViewClip.h ViewProviderHatch.cpp ViewProviderHatch.h + ViewProviderImage.cpp + ViewProviderImage.h ) SOURCE_GROUP("Mod" FILES ${TechDrawGui_SRCS}) diff --git a/src/Mod/TechDraw/Gui/CommandDecorate.cpp b/src/Mod/TechDraw/Gui/CommandDecorate.cpp index 60e3cb366..322499d15 100644 --- a/src/Mod/TechDraw/Gui/CommandDecorate.cpp +++ b/src/Mod/TechDraw/Gui/CommandDecorate.cpp @@ -126,6 +126,58 @@ bool CmdTechDrawNewHatch::isActive(void) return (havePage && haveView); } +//=========================================================================== +// TechDraw_Image +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawImage); + +CmdTechDrawImage::CmdTechDrawImage() + : Command("TechDraw_Image") +{ + // setting the Gui eye-candy + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert bitmap image"); + sToolTipText = QT_TR_NOOP("Inserts a bitmap from a file in the active drawing"); + sWhatsThis = "TechDraw_Image"; + sStatusTip = QT_TR_NOOP("Inserts a bitmap from a file in the active drawing"); + sPixmap = "actions/techdraw-image"; +} + +void CmdTechDrawImage::activated(int iMsg) +{ + Q_UNUSED(iMsg); + TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); + if (!page) { + return; + } + std::string PageName = page->getNameInDocument(); + + // Reading an image + std::string defaultDir = App::Application::getResourceDir(); + QString qDir = QString::fromUtf8(defaultDir.data(),defaultDir.size()); + QString fileName = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), + QString::fromUtf8(QT_TR_NOOP("Select an Image File")), + qDir, + QString::fromUtf8(QT_TR_NOOP("Image (*.png *.jpg *.jpeg)"))); + + if (!fileName.isEmpty()) + { + std::string FeatName = getUniqueObjectName("Image"); + openCommand("Create Image"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewImage','%s')",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.ImageFile = '%s'",FeatName.c_str(),fileName.toUtf8().constData()); + doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); + updateActive(); + commitCommand(); + } +} + +bool CmdTechDrawImage::isActive(void) +{ + return DrawGuiUtil::needPage(this); +} + //=========================================================================== // TechDraw_ToggleFrame //=========================================================================== @@ -178,6 +230,7 @@ void CreateTechDrawCommandsDecorate(void) Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); rcCmdMgr.addCommand(new CmdTechDrawNewHatch()); + rcCmdMgr.addCommand(new CmdTechDrawImage()); rcCmdMgr.addCommand(new CmdTechDrawToggleFrame()); } diff --git a/src/Mod/TechDraw/Gui/MDIViewPage.cpp b/src/Mod/TechDraw/Gui/MDIViewPage.cpp index 1e5845a52..545c8f988 100644 --- a/src/Mod/TechDraw/Gui/MDIViewPage.cpp +++ b/src/Mod/TechDraw/Gui/MDIViewPage.cpp @@ -75,6 +75,7 @@ #include #include #include +#include #include "QGIDrawingTemplate.h" #include "QGIView.h" @@ -315,6 +316,9 @@ bool MDIViewPage::attachView(App::DocumentObject *obj) } else if (typeId.isDerivedFrom(TechDraw::DrawViewSpreadsheet::getClassTypeId()) ) { qview = m_view->addDrawViewSpreadsheet( static_cast(obj) ); + } else if (typeId.isDerivedFrom(TechDraw::DrawViewImage::getClassTypeId()) ) { + qview = m_view->addDrawViewImage( static_cast(obj) ); + } else if (typeId.isDerivedFrom(TechDraw::DrawHatch::getClassTypeId()) ) { //Hatch is not attached like other Views (since it isn't really a View) return true; diff --git a/src/Mod/TechDraw/Gui/QGCustomImage.cpp b/src/Mod/TechDraw/Gui/QGCustomImage.cpp new file mode 100644 index 000000000..034439144 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGCustomImage.cpp @@ -0,0 +1,92 @@ +/*************************************************************************** + * 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 +#include +#include +#endif + +#include + +#include +#include +#include "QGCustomImage.h" + +using namespace TechDrawGui; + +QGCustomImage::QGCustomImage() +{ + setCacheMode(QGraphicsItem::NoCache); + setAcceptHoverEvents(false); + setFlag(QGraphicsItem::ItemIsSelectable, false); + setFlag(QGraphicsItem::ItemIsMovable, false); + setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); +} + +QGCustomImage::~QGCustomImage() +{ +} + +void QGCustomImage::centerAt(QPointF centerPos) +{ + centerAt(centerPos.x(),centerPos.y()); +} + +void QGCustomImage::centerAt(double cX, double cY) +{ +// QGraphicsItemGroup* g = group(); +// if (g == nullptr) { +// return; +// } + QPointF parentPt(cX,cY); + QPointF myPt = mapFromParent(parentPt); + + QRectF br = boundingRect(); + double width = br.width(); + double height = br.height(); + double newX = width/2.0; + double newY = height/2.0; + QPointF off(myPt.x() - newX,myPt.y() - newY); + setOffset(off); +} + +bool QGCustomImage::load(QString fileSpec) +{ + bool success = true; + QPixmap px(fileSpec); + m_px = px; +// if (m_px.isNull()) { +// Base::Console().Message("TRACE - QGCustomImage::load - pixmap no good\n"); +// } + prepareGeometryChange(); + setPixmap(m_px); + return(success); +} + +void QGCustomImage::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { + QStyleOptionGraphicsItem myOption(*option); + myOption.state &= ~QStyle::State_Selected; + + QGraphicsPixmapItem::paint (painter, &myOption, widget); +} diff --git a/src/Mod/TechDraw/Gui/QGCustomImage.h b/src/Mod/TechDraw/Gui/QGCustomImage.h new file mode 100644 index 000000000..535323bd8 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGCustomImage.h @@ -0,0 +1,63 @@ +/*************************************************************************** + * 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_QGCUSTOMIMAGE_H +#define DRAWINGGUI_QGCUSTOMIMAGE_H + +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QPainter; +class QStyleOptionGraphicsItem; +QT_END_NAMESPACE + +namespace TechDrawGui +{ + +class TechDrawGuiExport QGCustomImage : public QGraphicsPixmapItem +{ +public: + explicit QGCustomImage(void); + ~QGCustomImage(); + + enum {Type = QGraphicsItem::UserType + 201}; + int type() const override { return Type;} + + virtual void paint( QPainter *painter, + const QStyleOptionGraphicsItem *option, + QWidget *widget = nullptr ) override; + virtual void centerAt(QPointF centerPos); + virtual void centerAt(double cX, double cY); + virtual bool load(QString fileSpec); + +protected: + QPixmap m_px; + +}; + +} // namespace TechDrawGui + +#endif // DRAWINGGUI_QGCUSTOMIMAGE_H diff --git a/src/Mod/TechDraw/Gui/QGIUserTypes.h b/src/Mod/TechDraw/Gui/QGIUserTypes.h index 46333ed88..3203f9400 100644 --- a/src/Mod/TechDraw/Gui/QGIUserTypes.h +++ b/src/Mod/TechDraw/Gui/QGIUserTypes.h @@ -35,6 +35,8 @@ QGISectionLine: 172 QGIDecoration: 173 QGICenterLine: 174 QGICaption: 180 +QGIViewImage: 200 +QGCustomImage: 201 */ /* diff --git a/src/Mod/TechDraw/Gui/QGIView.cpp b/src/Mod/TechDraw/Gui/QGIView.cpp index eea359bd2..adf830064 100644 --- a/src/Mod/TechDraw/Gui/QGIView.cpp +++ b/src/Mod/TechDraw/Gui/QGIView.cpp @@ -403,6 +403,8 @@ void QGIView::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q QStyleOptionGraphicsItem myOption(*option); myOption.state &= ~QStyle::State_Selected; + //painter->drawRect(boundingRect()); + QGraphicsItemGroup::paint(painter, &myOption, widget); } diff --git a/src/Mod/TechDraw/Gui/QGIViewImage.cpp b/src/Mod/TechDraw/Gui/QGIViewImage.cpp new file mode 100644 index 000000000..d441fcfb2 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIViewImage.cpp @@ -0,0 +1,144 @@ +/*************************************************************************** + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#endif + +//#include + +#include +#include +#include +#include + +#include + +#include "QGCustomImage.h" +#include "QGCustomClip.h" +#include "QGIViewImage.h" + +using namespace TechDrawGui; + +QGIViewImage::QGIViewImage() +{ + setHandlesChildEvents(false); + setFlag(QGraphicsItem::ItemClipsChildrenToShape, false); + setCacheMode(QGraphicsItem::NoCache); + setAcceptHoverEvents(true); + setFlag(QGraphicsItem::ItemIsMovable, true); + setFlag(QGraphicsItem::ItemIsSelectable, true); + setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); + + m_cliparea = new QGCustomClip(); + addToGroup(m_cliparea); + m_cliparea->setPos(0.,0.); + m_cliparea->setRect(0.,0.,5.,5.); + + m_imageItem = new QGCustomImage(); + m_cliparea->addToGroup(m_imageItem); + m_imageItem->setPos(0.,0.); +} + +QGIViewImage::~QGIViewImage() +{ + // m_imageItem belongs to this group and will be deleted by Qt +} + +QVariant QGIViewImage::itemChange(GraphicsItemChange change, const QVariant &value) +{ + + return QGIView::itemChange(change, value); +} + +void QGIViewImage::setViewImageFeature(TechDraw::DrawViewImage *obj) +{ + setViewFeature(static_cast(obj)); +} + +void QGIViewImage::updateView(bool update) +{ + auto viewImage( dynamic_cast(getViewObject()) ); + if( viewImage == nullptr ) { + return; + } + + if (update || + viewImage->isTouched() || + viewImage->Width.isTouched() || + viewImage->Height.isTouched() || + viewImage->ImageFile.isTouched()) { + draw(); + } + + if (viewImage->Scale.isTouched()) { + draw(); + } + + QGIView::updateView(update); +} + +void QGIViewImage::draw() +{ + if (!isVisible()) { + return; + } + + auto viewImage( dynamic_cast(getViewObject()) ); + QRectF newRect(0.0,0.0,viewImage->Width.getValue(),viewImage->Height.getValue()); + m_cliparea->setRect(newRect.adjusted(-1,-1,1,1)); + + drawImage(); + if (borderVisible) { + drawBorder(); + } +} + +void QGIViewImage::drawImage() +{ + auto viewImage( dynamic_cast(getViewObject()) ); + if( viewImage == nullptr ) { + return; + } + + if (!viewImage->ImageFile.isEmpty()) { + QString fileSpec = QString::fromUtf8(viewImage->ImageFile.getValue(),strlen(viewImage->ImageFile.getValue())); + m_imageItem->load(fileSpec); + m_imageItem->setScale(viewImage->Scale.getValue()); + QRectF br = m_cliparea->rect(); + double midX = br.width()/2.0; + double midY = br.height()/2.0; + m_imageItem->centerAt(midX,midY); + m_imageItem->show(); + } +} + + diff --git a/src/Mod/TechDraw/Gui/QGIViewImage.h b/src/Mod/TechDraw/Gui/QGIViewImage.h new file mode 100644 index 000000000..7ca5298f7 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIViewImage.h @@ -0,0 +1,64 @@ +/*************************************************************************** + * 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_QGRAPHICSITEMVIEWIMAGE_H +#define DRAWINGGUI_QGRAPHICSITEMVIEWIMAGE_H + +#include +#include +#include + +#include "QGIView.h" + +namespace TechDraw { +class DrawViewImage; +} + +namespace TechDrawGui +{ +class QGCustomImage; +class QGCustomClip; + +class TechDrawGuiExport QGIViewImage : public QGIView +{ +public: + QGIViewImage(); + ~QGIViewImage(); + + enum {Type = QGraphicsItem::UserType + 200}; + int type() const override { return Type;} + + virtual void updateView(bool update = false) override; + void setViewImageFeature(TechDraw::DrawViewImage *obj); + + virtual void draw() override; + +protected: + virtual void drawImage(); + QVariant itemChange(GraphicsItemChange change, const QVariant &value) override; + + QGCustomImage* m_imageItem; + QGCustomClip* m_cliparea; +}; + +} // namespace +#endif // DRAWINGGUI_QGRAPHICSITEMVIEWIMAGE_H diff --git a/src/Mod/TechDraw/Gui/QGVPage.cpp b/src/Mod/TechDraw/Gui/QGVPage.cpp index 3e6d8701c..c850f5abb 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.cpp +++ b/src/Mod/TechDraw/Gui/QGVPage.cpp @@ -58,6 +58,7 @@ #include #include #include +#include #include "QGIDrawingTemplate.h" @@ -73,6 +74,7 @@ #include "QGIViewSymbol.h" #include "QGIViewClip.h" #include "QGIViewSpreadsheet.h" +#include "QGIViewImage.h" #include "QGIFace.h" #include "ZVALUE.h" @@ -287,6 +289,17 @@ QGIView * QGVPage::addDrawViewSpreadsheet(TechDraw::DrawViewSpreadsheet *view) return qview; } +QGIView * QGVPage::addDrawViewImage(TechDraw::DrawViewImage *view) +{ + QPoint qp(view->X.getValue(),view->Y.getValue()); + auto qview( new QGIViewImage ); + + qview->setViewFeature(view); + + addView(qview); + return qview; +} + QGIView * QGVPage::addViewDimension(TechDraw::DrawViewDimension *dim) { auto dimGroup( new QGIViewDimension ); diff --git a/src/Mod/TechDraw/Gui/QGVPage.h b/src/Mod/TechDraw/Gui/QGVPage.h index 9976bfd89..01f6b83ef 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.h +++ b/src/Mod/TechDraw/Gui/QGVPage.h @@ -37,6 +37,7 @@ class DrawViewSymbol; class DrawViewClip; class DrawViewCollection; class DrawViewSpreadsheet; +class DrawViewImage; } namespace TechDrawGui @@ -69,6 +70,8 @@ public: QGIView * addDrawViewSymbol(TechDraw::DrawViewSymbol *view); QGIView * addDrawViewClip(TechDraw::DrawViewClip *view); QGIView * addDrawViewSpreadsheet(TechDraw::DrawViewSpreadsheet *view); + QGIView * addDrawViewImage(TechDraw::DrawViewImage *view); + QGIView * findView(App::DocumentObject *obj) const; QGIView * findParent(QGIView *) const; diff --git a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc index 91745a848..90bd99318 100644 --- a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc +++ b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc @@ -47,6 +47,7 @@ icons/actions/techdraw-toggleframe.svg icons/actions/techdraw-projgroup.svg icons/actions/techdraw-spreadsheet.svg + icons/actions/techdraw-image.svg icons/actions/section-up.svg icons/actions/section-down.svg icons/actions/section-left.svg diff --git a/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-image.svg b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-image.svg new file mode 100644 index 000000000..276e9b7c6 --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-image.svg @@ -0,0 +1,481 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + Jakub Steiner + + + http://jimmac.musichall.cz + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/ViewProviderImage.cpp b/src/Mod/TechDraw/Gui/ViewProviderImage.cpp new file mode 100644 index 000000000..e3f997475 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderImage.cpp @@ -0,0 +1,87 @@ +/*************************************************************************** + * 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_ +#endif + +/// Here the FreeCAD includes sorted by Base,App,Gui...... +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ViewProviderImage.h" + +using namespace TechDrawGui; + +PROPERTY_SOURCE(TechDrawGui::ViewProviderImage, TechDrawGui::ViewProviderDrawingView) + +//************************************************************************** +// Construction/Destruction + +ViewProviderImage::ViewProviderImage() +{ + sPixmap = "actions/techdraw-image"; +} + +ViewProviderImage::~ViewProviderImage() +{ +} + +void ViewProviderImage::attach(App::DocumentObject *pcFeat) +{ + // call parent attach method + ViewProviderDrawingView::attach(pcFeat); +} + +void ViewProviderImage::setDisplayMode(const char* ModeName) +{ + ViewProviderDrawingView::setDisplayMode(ModeName); +} + +std::vector ViewProviderImage::getDisplayModes(void) const +{ + // get the modes of the father + std::vector StrList = ViewProviderDrawingView::getDisplayModes(); + + return StrList; +} + +void ViewProviderImage::updateData(const App::Property* prop) +{ + ViewProviderDrawingView::updateData(prop); +} + +TechDraw::DrawViewImage* ViewProviderImage::getViewObject() const +{ + return dynamic_cast(pcObject); +} + + diff --git a/src/Mod/TechDraw/Gui/ViewProviderImage.h b/src/Mod/TechDraw/Gui/ViewProviderImage.h new file mode 100644 index 000000000..b6ee285a5 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderImage.h @@ -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_VIEWPROVIDERIMAGE_H +#define DRAWINGGUI_VIEWPROVIDERIMAGE_H + +#include +#include +#include "ViewProviderDrawingView.h" + +namespace TechDrawGui { + + +class TechDrawGuiExport ViewProviderImage : public ViewProviderDrawingView +{ + PROPERTY_HEADER(TechDrawGui::ViewProviderImage); + +public: + /// constructor + ViewProviderImage(); + /// destructor + virtual ~ViewProviderImage(); + + + virtual void attach(App::DocumentObject *); + virtual void setDisplayMode(const char* ModeName); + virtual bool useNewSelectionModel(void) const {return false;} + /// returns a list of all possible modes + virtual std::vector getDisplayModes(void) const; + virtual void updateData(const App::Property*); + + virtual TechDraw::DrawViewImage* getViewObject() const; +}; + + +} // namespace TechDrawGui + + +#endif // DRAWINGGUI_VIEWPROVIDERIMAGE_H diff --git a/src/Mod/TechDraw/Gui/Workbench.cpp b/src/Mod/TechDraw/Gui/Workbench.cpp index 351a94f6c..66b64fd0c 100644 --- a/src/Mod/TechDraw/Gui/Workbench.cpp +++ b/src/Mod/TechDraw/Gui/Workbench.cpp @@ -76,6 +76,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const *draw << "TechDraw_DraftView"; *draw << "TechDraw_ArchView"; *draw << "TechDraw_ExportPage"; + *draw << "TechDraw_Image"; //*draw << "TechDraw_Open"; //*part << "TechDraw_NewA3Landscape"; //*part << "TechDraw_OpenBrowserView"; @@ -130,6 +131,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const Gui::ToolBarItem *decor = new Gui::ToolBarItem(root); decor->setCommand("TechDraw Decoration"); *decor << "TechDraw_NewHatch"; + *decor << "TechDraw_Image"; *decor << "TechDraw_ToggleFrame"; return root; } @@ -177,6 +179,7 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const Gui::ToolBarItem *decor = new Gui::ToolBarItem(root); decor->setCommand("TechDraw Decoration"); *decor << "TechDraw_NewHatch"; + *decor << "TechDraw_Image"; *decor << "TechDraw_ToggleFrame"; return root;