From 36d341f3df4e1f7affecd462e57483d6618bedc7 Mon Sep 17 00:00:00 2001 From: Franck Jullien Date: Mon, 22 Apr 2019 22:16:40 +0200 Subject: [PATCH] [TD] Add TaskPanel for Balloons TaskPanel can be open by double clicking either Balloon label on drawing page or Balloon object in tree view. --- src/Mod/TechDraw/App/DrawViewBalloon.h | 5 +- src/Mod/TechDraw/Gui/CMakeLists.txt | 6 + src/Mod/TechDraw/Gui/QGIViewBalloon.cpp | 12 +- src/Mod/TechDraw/Gui/QGIViewBalloon.h | 19 +- src/Mod/TechDraw/Gui/QGVPage.cpp | 1 + src/Mod/TechDraw/Gui/Resources/TechDraw.qrc | 7 + .../TechDraw/Gui/Resources/icons/circular.svg | 66 +++++++ .../TechDraw/Gui/Resources/icons/hexagon.svg | 99 +++++++++++ .../Gui/Resources/icons/inspection.svg | 89 ++++++++++ src/Mod/TechDraw/Gui/Resources/icons/none.svg | 54 ++++++ .../Gui/Resources/icons/rectangle.svg | 61 +++++++ .../TechDraw/Gui/Resources/icons/square.svg | 61 +++++++ .../TechDraw/Gui/Resources/icons/triangle.svg | 59 +++++++ src/Mod/TechDraw/Gui/TaskBalloon.cpp | 148 ++++++++++++++++ src/Mod/TechDraw/Gui/TaskBalloon.h | 91 ++++++++++ src/Mod/TechDraw/Gui/TaskBalloon.ui | 166 ++++++++++++++++++ src/Mod/TechDraw/Gui/ViewProviderBalloon.cpp | 46 ++++- src/Mod/TechDraw/Gui/ViewProviderBalloon.h | 3 + 18 files changed, 987 insertions(+), 6 deletions(-) create mode 100644 src/Mod/TechDraw/Gui/Resources/icons/circular.svg create mode 100644 src/Mod/TechDraw/Gui/Resources/icons/hexagon.svg create mode 100644 src/Mod/TechDraw/Gui/Resources/icons/inspection.svg create mode 100644 src/Mod/TechDraw/Gui/Resources/icons/none.svg create mode 100644 src/Mod/TechDraw/Gui/Resources/icons/rectangle.svg create mode 100644 src/Mod/TechDraw/Gui/Resources/icons/square.svg create mode 100644 src/Mod/TechDraw/Gui/Resources/icons/triangle.svg create mode 100644 src/Mod/TechDraw/Gui/TaskBalloon.cpp create mode 100644 src/Mod/TechDraw/Gui/TaskBalloon.h create mode 100644 src/Mod/TechDraw/Gui/TaskBalloon.ui diff --git a/src/Mod/TechDraw/App/DrawViewBalloon.h b/src/Mod/TechDraw/App/DrawViewBalloon.h index 3a2971818b..63c24844ca 100644 --- a/src/Mod/TechDraw/App/DrawViewBalloon.h +++ b/src/Mod/TechDraw/App/DrawViewBalloon.h @@ -73,13 +73,14 @@ public: return "TechDrawGui::ViewProviderBalloon"; } + static const char* balloonTypeEnums[]; + static const char* endTypeEnums[]; + protected: void onChanged(const App::Property* prop); virtual void onDocumentRestored(); private: - static const char* endTypeEnums[]; - static const char* balloonTypeEnums[]; }; } //namespace TechDraw diff --git a/src/Mod/TechDraw/Gui/CMakeLists.txt b/src/Mod/TechDraw/Gui/CMakeLists.txt index 92bde43dfb..9c5b46b250 100644 --- a/src/Mod/TechDraw/Gui/CMakeLists.txt +++ b/src/Mod/TechDraw/Gui/CMakeLists.txt @@ -48,6 +48,7 @@ set(TechDrawGui_MOC_HDRS QGMText.h mrichtextedit.h mtextedit.h + TaskBalloon.h ) fc_wrap_cpp(TechDrawGui_MOC_SRCS ${TechDrawGui_MOC_HDRS}) @@ -70,6 +71,7 @@ set(TechDrawGui_UIC_SRCS TaskLeaderLine.ui TaskRichAnno.ui mrichtextedit.ui + TaskBalloon.ui ) if(BUILD_QT5) @@ -123,6 +125,9 @@ SET(TechDrawGui_SRCS TaskSectionView.ui TaskSectionView.cpp TaskSectionView.h + TaskBalloon.ui + TaskBalloon.cpp + TaskBalloon.h TaskGeomHatch.ui TaskGeomHatch.cpp TaskGeomHatch.h @@ -281,6 +286,7 @@ SET(TechDrawGuiTaskDlgs_SRCS TaskLeaderLine.ui TaskRichAnno.ui mrichtextedit.ui + TaskBalloon.ui ) SOURCE_GROUP("TaskDialogs" FILES ${TechDrawGuiTaskDlgs_SRCS}) diff --git a/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp b/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp index 2fb0c4fbd0..31ef0af112 100644 --- a/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include #include @@ -68,6 +69,7 @@ #include "QGIViewDimension.h" #include "QGVPage.h" #include "MDIViewPage.h" +#include "TaskBalloon.h" #define PI 3.14159 @@ -76,6 +78,12 @@ using namespace TechDraw; using namespace TechDrawGui; +void QGIBalloonLabel::mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event) +{ + Gui::Control().showDialog(new TaskDlgBalloon(parent)); + QGraphicsItem::mouseDoubleClickEvent(event); +} + //************************************************************** QGIViewBalloon::QGIViewBalloon() : hasHover(false), @@ -85,7 +93,9 @@ QGIViewBalloon::QGIViewBalloon() : setFlag(QGraphicsItem::ItemIsMovable, false); setCacheMode(QGraphicsItem::NoCache); - balloonLabel = new QGIDatumLabel(); + balloonLabel = new QGIBalloonLabel(); + balloonLabel->parent = this; + addToGroup(balloonLabel); balloonLabel->setColor(getNormalColor()); balloonLabel->setPrettyNormal(); diff --git a/src/Mod/TechDraw/Gui/QGIViewBalloon.h b/src/Mod/TechDraw/Gui/QGIViewBalloon.h index d5e93faa4c..e4f1930670 100644 --- a/src/Mod/TechDraw/Gui/QGIViewBalloon.h +++ b/src/Mod/TechDraw/Gui/QGIViewBalloon.h @@ -52,6 +52,20 @@ class QGIArrow; class QGIDimLines; class QGIViewBalloon; +class QGIBalloonLabel : public QGIDatumLabel +{ +Q_OBJECT + +public: + enum {Type = QGraphicsItem::UserType + 141}; + int type() const override { return Type;} + + QGIViewBalloon *parent; + +protected: + virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override; +}; + //******************************************************************* class TechDrawGuiExport QGIViewBalloon : public QGIView @@ -76,6 +90,7 @@ public: QString getLabelText(void); void draw_modifier(bool modifier); void placeBalloon(QPointF pos); + TechDraw::DrawViewBalloon *dvBalloon; public Q_SLOTS: void balloonLabelDragged(bool ctrl); @@ -94,7 +109,7 @@ protected: protected: bool hasHover; - QGIDatumLabel* balloonLabel; + QGIBalloonLabel* balloonLabel; QGIDimLines* balloonLines; QGIDimLines* balloonShape; QGIArrow* arrow; @@ -102,7 +117,7 @@ protected: bool m_obtuse; void parentViewMousePressed(QGIView *view, QPointF pos); QPointF *oldLabelCenter; - QGIView *m_parent; + QGIView *parent; }; diff --git a/src/Mod/TechDraw/Gui/QGVPage.cpp b/src/Mod/TechDraw/Gui/QGVPage.cpp index 8d21b71f80..352ba3e315 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.cpp +++ b/src/Mod/TechDraw/Gui/QGVPage.cpp @@ -426,6 +426,7 @@ QGIView * QGVPage::addViewBalloon(TechDraw::DrawViewBalloon *balloon) ourScene->addItem(vBalloon); vBalloon->setViewPartFeature(balloon); + vBalloon->dvBalloon = balloon; QGIView *parent = 0; parent = findParent(vBalloon); diff --git a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc index aaa42289cc..5bc826b0dd 100644 --- a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc +++ b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc @@ -75,6 +75,13 @@ icons/arrow-cw.svg icons/techdraw-lock.png icons/cursor-balloon.png + icons/none.svg + icons/circular.svg + icons/hexagon.svg + icons/inspection.svg + icons/rectangle.svg + icons/triangle.svg + icons/square.svg icons/MRTE/menu.svg icons/MRTE/bgColor.svg icons/MRTE/fgColor.svg diff --git a/src/Mod/TechDraw/Gui/Resources/icons/circular.svg b/src/Mod/TechDraw/Gui/Resources/icons/circular.svg new file mode 100644 index 0000000000..6e545816a6 --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/circular.svg @@ -0,0 +1,66 @@ + + + + + + + + + + image/svg+xml + + + + + + + diff --git a/src/Mod/TechDraw/Gui/Resources/icons/hexagon.svg b/src/Mod/TechDraw/Gui/Resources/icons/hexagon.svg new file mode 100644 index 0000000000..19b1696646 --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/hexagon.svg @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + diff --git a/src/Mod/TechDraw/Gui/Resources/icons/inspection.svg b/src/Mod/TechDraw/Gui/Resources/icons/inspection.svg new file mode 100644 index 0000000000..97f3aaa6c4 --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/inspection.svg @@ -0,0 +1,89 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/Resources/icons/none.svg b/src/Mod/TechDraw/Gui/Resources/icons/none.svg new file mode 100644 index 0000000000..e25f9554ef --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/none.svg @@ -0,0 +1,54 @@ + + + + + + + + + + image/svg+xml + + + + + + diff --git a/src/Mod/TechDraw/Gui/Resources/icons/rectangle.svg b/src/Mod/TechDraw/Gui/Resources/icons/rectangle.svg new file mode 100644 index 0000000000..437db57d5b --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/rectangle.svg @@ -0,0 +1,61 @@ + + + + + + + + + + image/svg+xml + + + + + + + diff --git a/src/Mod/TechDraw/Gui/Resources/icons/square.svg b/src/Mod/TechDraw/Gui/Resources/icons/square.svg new file mode 100644 index 0000000000..3052021a61 --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/square.svg @@ -0,0 +1,61 @@ + + + + + + + + + + image/svg+xml + + + + + + + diff --git a/src/Mod/TechDraw/Gui/Resources/icons/triangle.svg b/src/Mod/TechDraw/Gui/Resources/icons/triangle.svg new file mode 100644 index 0000000000..ccb444c57e --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/triangle.svg @@ -0,0 +1,59 @@ + + + + + + + + + + image/svg+xml + + + + + + + diff --git a/src/Mod/TechDraw/Gui/TaskBalloon.cpp b/src/Mod/TechDraw/Gui/TaskBalloon.cpp new file mode 100644 index 0000000000..387ed04b2a --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskBalloon.cpp @@ -0,0 +1,148 @@ +/*************************************************************************** + * Copyright (c) 2016 WandererFan * + * Copyright (c) 2019 Franck Jullien * + * * + * 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 // #ifndef _PreComp_ + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include +#include +#include + +#include + +#include "QGIViewBalloon.h" +#include "TaskBalloon.h" + +using namespace Gui; +using namespace TechDraw; +using namespace TechDrawGui; + +TaskBalloon::TaskBalloon(QGIViewBalloon *parent) : + ui(new Ui_TaskBalloon) +{ + int i = 0; + + m_parent = parent; + + ui->setupUi(this); + + QString qs = QString::number(parent->dvBalloon->SymbolScale.getValue(), 'f', 2); + ui->inputScale->setText(qs); + + std::string value = parent->dvBalloon->Text.getValue(); + qs = QString::fromUtf8(value.data(), value.size()); + ui->inputValue->setText(qs); + ui->inputValue->selectAll(); + QTimer::singleShot(0, ui->inputValue, SLOT(setFocus())); + + i = ui->comboEndType->findText(QString::fromUtf8(parent->dvBalloon->EndType.getValueAsString())); + ui->comboEndType->setCurrentIndex(i); + + i = ui->comboSymbol->findText(QString::fromUtf8(parent->dvBalloon->Symbol.getValueAsString())); + ui->comboSymbol->setCurrentIndex(i); +} + +TaskBalloon::~TaskBalloon() +{ + delete ui; +} + + +bool TaskBalloon::accept() +{ + m_parent->dvBalloon->Text.setValue(ui->inputValue->text().toUtf8().constData()); + m_parent->dvBalloon->SymbolScale.setValue(ui->inputScale->text().toDouble()); + m_parent->dvBalloon->EndType.setValue(ui->comboEndType->currentText().toUtf8().constData()); + m_parent->dvBalloon->Symbol.setValue(ui->comboSymbol->currentText().toUtf8().constData()); + m_parent->updateView(true); + + return true; +} + +bool TaskBalloon::reject() +{ + return false; +} + + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +TaskDlgBalloon::TaskDlgBalloon(QGIViewBalloon *parent) : + TaskDialog() +{ + widget = new TaskBalloon(parent); + taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("TechDraw_Balloon"), widget->windowTitle(), true, 0); + taskbox->groupLayout()->addWidget(widget); + Content.push_back(taskbox); +} + +TaskDlgBalloon::~TaskDlgBalloon() +{ +} + +void TaskDlgBalloon::update() +{ + //widget->updateTask(); +} + +//==== calls from the TaskView =============================================================== +void TaskDlgBalloon::open() +{ +} + +void TaskDlgBalloon::clicked(int i) +{ + Q_UNUSED(i); +} + +bool TaskDlgBalloon::accept() +{ + widget->accept(); + return true; +} + +bool TaskDlgBalloon::reject() +{ + widget->reject(); + return true; +} + +#include diff --git a/src/Mod/TechDraw/Gui/TaskBalloon.h b/src/Mod/TechDraw/Gui/TaskBalloon.h new file mode 100644 index 0000000000..a06debc33e --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskBalloon.h @@ -0,0 +1,91 @@ +/*************************************************************************** + * Copyright (c) 2016 WandererFan * + * Copyright (c) 2019 Franck Jullien * + * * + * 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 GUI_TASKVIEW_TASKBALLOON_H +#define GUI_TASKVIEW_TASKBALLOON_H + +#include +#include + +#include + +#include + +#include "QGIViewBalloon.h" + +class Ui_TaskBalloon; + +namespace TechDrawGui +{ + +class TaskBalloon : public QWidget +{ + Q_OBJECT + +public: + TaskBalloon(QGIViewBalloon *parent); + ~TaskBalloon(); + +public: + virtual bool accept(); + virtual bool reject(); + +private: + Ui_TaskBalloon *ui; + QGIViewBalloon *m_parent; +}; + +class TaskDlgBalloon : public Gui::TaskView::TaskDialog +{ + Q_OBJECT + +public: + TaskDlgBalloon(QGIViewBalloon *parent); + ~TaskDlgBalloon(); + +public: + /// is called the TaskView when the dialog is opened + virtual void open(); + /// is called by the framework if an button is clicked which has no accept or reject role + virtual void clicked(int); + /// is called by the framework if the dialog is accepted (Ok) + virtual bool accept(); + /// is called by the framework if the dialog is rejected (Cancel) + virtual bool reject(); + /// is called by the framework if the user presses the help button + virtual void helpRequested() { return;} + virtual bool isAllowedAlterDocument(void) const + { return false; } + + void update(); + +protected: + +private: + TaskBalloon * widget; + Gui::TaskView::TaskBox* taskbox; +}; + +} //namespace TechDrawGui + +#endif // #ifndef GUI_TASKVIEW_TASKBALLOON_H diff --git a/src/Mod/TechDraw/Gui/TaskBalloon.ui b/src/Mod/TechDraw/Gui/TaskBalloon.ui new file mode 100644 index 0000000000..015fe4c385 --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskBalloon.ui @@ -0,0 +1,166 @@ + + + TechDrawGui::TaskBalloon + + + + 0 + 0 + 400 + 306 + + + + Balloon + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + + + Arrow + + + + :/icons/arrowfilled.svg:/icons/arrowfilled.svg + + + + + Dot + + + + :/icons/arrowdot.svg:/icons/arrowdot.svg + + + + + + + + Start Symbol + + + + + + + Symbol: + + + + + + + Value: + + + + + + + + Circular + + + + :/icons/circular.svg:/icons/circular.svg + + + + + None + + + + :/icons/none.svg:/icons/none.svg + + + + + Triangle + + + + :/icons/triangle.svg:/icons/triangle.svg + + + + + Inspection + + + + :/icons/inspection.svg:/icons/inspection.svg + + + + + Hexagon + + + + :/icons/hexagon.svg:/icons/hexagon.svg + + + + + Square + + + + :/icons/square.svg:/icons/square.svg + + + + + Rectangle + + + + :/icons/rectangle.svg:/icons/rectangle.svg + + + + + + + + Scale: + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/ViewProviderBalloon.cpp b/src/Mod/TechDraw/Gui/ViewProviderBalloon.cpp index cdd2138857..7e9dc544a3 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderBalloon.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderBalloon.cpp @@ -37,9 +37,18 @@ #include #include +#include +#include +#include +#include +#include +#include +#include +#include + #include - +#include "TaskBalloon.h" #include "ViewProviderBalloon.h" using namespace TechDrawGui; @@ -104,6 +113,41 @@ std::vector ViewProviderBalloon::getDisplayModes(void) const return StrList; } +bool ViewProviderBalloon::setEdit(int ModNum) +{ + if (ModNum == ViewProvider::Default ) { + if (Gui::Control().activeDialog()) { + return false; + } + // clear the selection (convenience) + Gui::Selection().clearSelection(); + auto qgivBalloon(dynamic_cast(getQView())); + if (qgivBalloon) { + Gui::Control().showDialog(new TaskDlgBalloon(qgivBalloon)); + } + return true; + } else { + return ViewProviderDrawingView::setEdit(ModNum); + } + return true; +} + +void ViewProviderBalloon::unsetEdit(int ModNum) +{ + if (ModNum == ViewProvider::Default) { + Gui::Control().closeDialog(); + } + else { + ViewProviderDrawingView::unsetEdit(ModNum); + } +} + +bool ViewProviderBalloon::doubleClicked(void) +{ + setEdit(ViewProvider::Default); + return true; +} + void ViewProviderBalloon::updateData(const App::Property* p) { ViewProviderDrawingView::updateData(p); diff --git a/src/Mod/TechDraw/Gui/ViewProviderBalloon.h b/src/Mod/TechDraw/Gui/ViewProviderBalloon.h index 3549cf49cc..b5b3461989 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderBalloon.h +++ b/src/Mod/TechDraw/Gui/ViewProviderBalloon.h @@ -58,6 +58,9 @@ public: virtual std::vector getDisplayModes(void) const; virtual void updateData(const App::Property*); virtual void onChanged(const App::Property* p); + virtual bool setEdit(int ModNum); + virtual void unsetEdit(int ModNum); + virtual bool doubleClicked(void); virtual TechDraw::DrawViewBalloon* getViewObject() const; };