Merge branch 'master' into feature/tool-bit-poc

This commit is contained in:
mlampert
2019-12-04 19:17:47 -08:00
committed by GitHub
10 changed files with 654 additions and 784 deletions

View File

@@ -139,11 +139,11 @@ class ViewProviderLayer:
vobj.OverrideChildren = True
c = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View").GetUnsigned("DefaultShapeLineColor",255)
vobj.LineColor = (((c>>24)&0xFF)/255,((c>>16)&0xFF)/255,((c>>8)&0xFF)/255)
vobj.LineColor = (((c>>24)&0xFF)/255.0,((c>>16)&0xFF)/255.0,((c>>8)&0xFF)/255.0)
w = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View").GetInt("DefaultShapeLineWidth",2)
vobj.LineWidth = w
c = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View").GetUnsigned("DefaultShapeColor",4294967295)
vobj.ShapeColor = (((c>>24)&0xFF)/255,((c>>16)&0xFF)/255,((c>>8)&0xFF)/255)
vobj.ShapeColor = (((c>>24)&0xFF)/255.0,((c>>16)&0xFF)/255.0,((c>>8)&0xFF)/255.0)
vobj.DrawStyle = "Solid"
vobj.Proxy = self
@@ -225,6 +225,7 @@ class ViewProviderLayer:
b.open(QtCore.QIODevice.WriteOnly)
im.save(b,"XPM")
self.icondata = ba.data().decode("latin1")
vobj.signalChangeIcon()
def canDragObject(self,obj):
return True

View File

@@ -56,7 +56,6 @@ DrawRichAnno::DrawRichAnno(void)
Scale.setStatus(App::Property::Hidden,true);
ScaleType.setStatus(App::Property::Hidden,true);
}
DrawRichAnno::~DrawRichAnno()
@@ -87,7 +86,7 @@ short DrawRichAnno::mustExecute() const
App::DocumentObjectExecReturn *DrawRichAnno::execute(void)
{
// Base::Console().Message("DRA::execute()\n");
// Base::Console().Message("DRA::execute() - @ (%.3f, %.3f)\n", X.getValue(), Y.getValue());
if (!keepUpdated()) {
return App::DocumentObject::StdReturn;
}

View File

@@ -42,10 +42,8 @@ public:
App::PropertyLink AnnoParent;
App::PropertyString AnnoText;
// App::PropertyVector TextPosition;
App::PropertyBool ShowFrame;
App::PropertyFloat MaxWidth;
App::PropertyVector AttachPoint;
virtual short mustExecute() const;
virtual App::DocumentObjectExecReturn *execute(void);

View File

@@ -192,8 +192,7 @@ void CmdTechDrawRichTextAnnotation::activated(int iMsg)
bool CmdTechDrawRichTextAnnotation::isActive(void)
{
bool havePage = DrawGuiUtil::needPage(this);
bool haveView = DrawGuiUtil::needView(this, false);
return (havePage && haveView);
return havePage;
}

View File

@@ -66,6 +66,8 @@
#include "QGEPath.h"
#include "QGMText.h"
#include "QGIView.h"
#include "QGCustomText.h"
#include "QGCustomRect.h"
#include "QGIRichAnno.h"
@@ -79,38 +81,30 @@ QGIRichAnno::QGIRichAnno(QGraphicsItem* myParent,
{
setHandlesChildEvents(false);
setAcceptHoverEvents(false);
setFlag(QGraphicsItem::ItemIsSelectable, false); //we actually select & drag m_text
setFlag(QGraphicsItem::ItemIsMovable, false);
setFlag(QGraphicsItem::ItemIsSelectable, true);
setFlag(QGraphicsItem::ItemIsMovable, true);
setFlag(QGraphicsItem::ItemSendsScenePositionChanges, true);
setFlag(QGraphicsItem::ItemSendsGeometryChanges,true);
if (myParent != nullptr) {
setParentItem(myParent);
}
setViewFeature(anno);
m_text = new QGMText();
m_text = new QGCustomText();
m_text->setTextInteractionFlags(Qt::NoTextInteraction);
addToGroup(m_text);
m_text->setZValue(ZVALUE::DIMENSION);
m_text->centerAt(0.0, 0.0);
m_rect = new QGCustomRect();
addToGroup(m_rect);
m_rect->setZValue(ZVALUE::DIMENSION - 1);
m_rect->centerAt(0.0, 0.0);
setZValue(ZVALUE::DIMENSION);
QObject::connect(
m_text, SIGNAL(dragging()),
this , SLOT (textDragging())
);
QObject::connect(
m_text, SIGNAL(dragFinished()),
this , SLOT (textDragFinished())
);
QObject::connect(
m_text, SIGNAL(selected(bool)),
this , SLOT (select(bool)));
QObject::connect(
m_text, SIGNAL(hover(bool)),
this , SLOT (hover(bool)));
}
QVariant QGIRichAnno::itemChange(GraphicsItemChange change, const QVariant &value)
@@ -123,52 +117,17 @@ QVariant QGIRichAnno::itemChange(GraphicsItemChange change, const QVariant &valu
return QGIView::itemChange(change, value);
}
void QGIRichAnno::textDragging(void)
{
// Base::Console().Message("QGIRA::textDragging()\n");
//this is the long way around. can we do it without crossing the App/Gui boundary?
//just update graphics until drag finished.
// auto lead( dynamic_cast<TechDraw::DrawRichAnno*>(getFeature()) );
//void QGIRichAnno::select(bool state)
//{
// setSelected(state);
// draw();
//}
// if( lead == nullptr ) {
// return;
// }
// double x = Rez::appX(m_text->x()),
// y = Rez::appX(m_text->y());
// Base::Vector3d tPos(x,-y,0.0);
// Gui::Command::openCommand("Drag Text");
// lead->TextPosition.setValue(tPos);
// Gui::Command::commitCommand();
// draw();
}
void QGIRichAnno::textDragFinished(void)
{
// Base::Console().Message("QGIRA::textDragFinished()\n");
auto anno( dynamic_cast<TechDraw::DrawRichAnno*>(getFeature()) );
if( anno == nullptr ) {
return;
}
double x = Rez::appX(m_text->x()) / getScale();
double y = - Rez::appX(m_text->y()) / getScale();
anno->X.setValue(x);
anno->Y.setValue(y);
}
void QGIRichAnno::select(bool state)
{
setSelected(state);
draw();
}
void QGIRichAnno::hover(bool state)
{
m_hasHover = state;
draw();
}
//void QGIRichAnno::hover(bool state)
//{
// m_hasHover = state;
// draw();
//}
void QGIRichAnno::updateView(bool update)
{
@@ -184,6 +143,13 @@ void QGIRichAnno::updateView(bool update)
if ( vp == nullptr ) {
return;
}
if (annoFeat->X.isTouched() ||
annoFeat->Y.isTouched()) {
float x = Rez::guiX(annoFeat->X.getValue());
float y = Rez::guiX(annoFeat->Y.getValue());
m_text->centerAt(x, -y);
m_rect->centerAt(x, -y);
}
draw();
}
@@ -197,23 +163,25 @@ void QGIRichAnno::drawBorder()
void QGIRichAnno::draw()
{
// Base::Console().Log("QGITL::draw() - %s\n",getFeature()->getNameInDocument());
// Base::Console().Log("QGIRA::draw() - %s - parent: %X\n",getFeature()->getNameInDocument(), parentItem());
if (!isVisible()) {
Base::Console().Log("QGITL::draw - not visible\n");
// Base::Console().Message("QGIRA::draw - not visible\n");
return;
}
TechDraw::DrawRichAnno* annoFeat = getFeature();
if((!annoFeat) ) {
Base::Console().Log("QGITL::draw - no feature\n");
// Base::Console().Message("QGIRA::draw - no feature\n");
return;
}
auto vp = static_cast<ViewProviderRichAnno*>(getViewProvider(getFeature()));
if ( vp == nullptr ) {
Base::Console().Log("QGITL::draw - no viewprovider\n");
// Base::Console().Message("QGIRA::draw - no viewprovider\n");
return;
}
// double appX = Rez::guiX(annoFeat->X.getValue());
// double appY = Rez::guiX(annoFeat->Y.getValue());
QGIView::draw();
@@ -257,14 +225,20 @@ void QGIRichAnno::setTextItem()
m_text->setHtml(outHtml);
m_text->setTextWidth(Rez::guiX(annoFeat->MaxWidth.getValue()));
m_text->showBox(annoFeat->ShowFrame.getValue());
double scale = getScale();
double x = Rez::guiX(annoFeat->X.getValue());
double y = Rez::guiX(annoFeat->Y.getValue());
Base::Vector3d textPos(x,y,0.0);
QPointF tPos(textPos.x * scale,- textPos.y * scale);
m_text->setPos(tPos);
// m_text->showBox(annoFeat->ShowFrame.getValue());
if (annoFeat->ShowFrame.getValue()) {
QRectF r = m_text->boundingRect().adjusted(1,1,-1,-1);
m_rect->setPen(rectPen());
m_rect->setBrush(Qt::NoBrush);
m_rect->setRect(r);
m_rect->show();
} else {
m_rect->hide();
}
m_text->centerAt(0.0, 0.0);
m_rect->centerAt(0.0, 0.0);
}
//void QGIRichAnno::drawBorder()
@@ -301,4 +275,12 @@ void QGIRichAnno::paint ( QPainter * painter, const QStyleOptionGraphicsItem * o
QGIView::paint (painter, &myOption, widget);
}
QPen QGIRichAnno::rectPen() const
{
QPen pen(Qt::SolidLine);
pen.setWidthF(1.0);
return pen;
}
#include <Mod/TechDraw/Gui/moc_QGIRichAnno.cpp>

View File

@@ -32,6 +32,7 @@
#include <QColor>
#include <QFont>
#include <QPointF>
#include <QPen>
#include <Base/Vector3D.h>
#include "QGILeaderLine.h"
@@ -47,6 +48,8 @@ class QGIPrimPath;
class QGIArrow;
class QGEPath;
class QGMText;
class QGCustomText;
class QGCustomRect;
//*******************************************************************
@@ -75,12 +78,14 @@ public:
void setTextItem(void);
virtual TechDraw::DrawRichAnno* getFeature(void);
QPen rectPen() const;
public Q_SLOTS:
void textDragging(void);
void textDragFinished(void);
void hover(bool state);
void select(bool state);
/* void textDragging(void);*/
/* void textDragFinished(void);*/
/* void hover(bool state);*/
/* void select(bool state);*/
protected:
virtual void draw() override;
@@ -88,8 +93,10 @@ protected:
const QVariant &value ) override;
protected:
QGMText* m_text;
/* QGMText* m_text;*/
QGCustomText* m_text;
bool m_hasHover;
QGCustomRect* m_rect;
};

File diff suppressed because it is too large Load Diff

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 29 KiB

View File

@@ -145,6 +145,7 @@ TaskRichAnno::TaskRichAnno(TechDraw::DrawView* baseFeat,
return;
}
ui->setupUi(this);
m_title = QObject::tr("Rich text creator");
@@ -278,7 +279,7 @@ void TaskRichAnno::createAnnoFeature()
std::string PageName = m_basePage->getNameInDocument();
Gui::Command::openCommand("Create Leader");
Gui::Command::openCommand("Create Anno");
Command::doCommand(Command::Doc,"App.activeDocument().addObject('%s','%s')",
annoType.c_str(),annoName.c_str());
Command::doCommand(Command::Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",
@@ -309,7 +310,7 @@ void TaskRichAnno::createAnnoFeature()
void TaskRichAnno::updateAnnoFeature()
{
// Base::Console().Message("TRA::updateAnnoFeature()\n");
Gui::Command::openCommand("Edit Leader");
Gui::Command::openCommand("Edit Anno");
commonFeatureUpdate();
Gui::Command::commitCommand();
@@ -375,16 +376,19 @@ QPointF TaskRichAnno::calcTextStartPos(double scale)
TechDraw::DrawLeaderLine* dll = dynamic_cast<TechDraw::DrawLeaderLine*>(m_baseFeat);
points = dll->WayPoints.getValues();
} else {
Base::Console().Log("TRA::calcTextPos - m_baseFeat is not Leader\n");
// Base::Console().Message("TRA::calcTextPos - m_baseFeat is not Leader\n");
QPointF result(0.0,0.0);
return result;
}
} else {
// Base::Console().Message("TRA::calcStartPos - no m_baseFeat\n");
if (m_basePage != nullptr) {
double w = Rez::guiX(m_basePage->getPageWidth() / 2.0);
double h = Rez::guiX(m_basePage->getPageHeight() / 2.0);
QPointF result(w,h);
return result;
} else {
Base::Console().Message("TRA::calcStartPos - no m_basePage\n");
}
}

View File

@@ -87,6 +87,8 @@ TaskSectionView::TaskSectionView(TechDraw::DrawViewPart* base) :
Base::Console().Error((msg + "\n").c_str());
return;
}
m_saveBaseName = m_base->getNameInDocument();
m_savePageName = m_base->findParentPage()->getNameInDocument();
ui->setupUi(this);
@@ -129,6 +131,9 @@ TaskSectionView::TaskSectionView(TechDraw::DrawViewSection* section) :
throw Base::RuntimeError("TaskSectionView - BaseView not found");
}
m_saveBaseName = m_base->getNameInDocument();
m_savePageName = m_base->findParentPage()->getNameInDocument();
ui->setupUi(this);
connect(ui->pbUp, SIGNAL(clicked(bool)),
@@ -269,9 +274,15 @@ void TaskSectionView::onApplyClicked(bool b)
apply();
}
void TaskSectionView::apply(void)
bool TaskSectionView::apply(void)
{
// Base::Console().Message("TSV::apply() - m_dirName: %s\n", m_dirName.c_str());
App::Document* doc = m_section->getDocument();
App::DocumentObject* baseObj = doc->getObject(m_saveBaseName.c_str());
TechDraw::DrawViewPart* dvp = dynamic_cast<TechDraw::DrawViewPart*>(baseObj);
if (dvp == nullptr) {
return false;
}
if (m_dirName.empty()) {
std::string msg = Base::Tools::toStdString(tr("TSV::apply - No section direction picked yet"));
Base::Console().Error((msg + "\n").c_str());
@@ -279,6 +290,7 @@ void TaskSectionView::apply(void)
checkAll(false);
applyQuick(m_dirName);
}
return true;
}
void TaskSectionView::checkAll(bool b)
@@ -295,12 +307,15 @@ void TaskSectionView::applyQuick(std::string dir)
// Base::Console().Message("TSV::applyQuick(%s)\n", dir.c_str());
m_dirName = dir;
Gui::Command::openCommand("Apply Quick");
m_dirName = dir;
if (m_section == nullptr) {
m_section = createSectionView();
}
if (m_section != nullptr) {
updateSectionView();
m_section->recomputeFeature();
m_section->recomputeFeature();
}
if (m_base != nullptr) {
m_base->requestPaint();
}
}
@@ -385,6 +400,7 @@ void TaskSectionView::updateSectionView(void)
}
}
//******************************************************************************
bool TaskSectionView::accept()
@@ -394,10 +410,12 @@ bool TaskSectionView::accept()
if (m_section == nullptr) {
apply();
}
Gui::Command::updateActive();
Gui::Command::commitCommand();
} else {
Gui::Command::openCommand("Edit SectionView");
try {
apply();
updateSectionView();
}
catch (...) {
Base::Console().Error("TSV::accept - failed to update section\n");
@@ -409,9 +427,12 @@ bool TaskSectionView::accept()
Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()");
if (m_section != nullptr) {
m_section->requestPaint();
}
if (m_base != nullptr) {
m_base->requestPaint();
App::Document* doc = m_section->getDocument();
App::DocumentObject* baseObj = doc->getObject(m_saveBaseName.c_str());
TechDraw::DrawViewPart* dvp = dynamic_cast<TechDraw::DrawViewPart*>(baseObj);
if (dvp != nullptr) {
dvp->requestPaint();
}
}
return true;
}
@@ -419,21 +440,27 @@ bool TaskSectionView::accept()
bool TaskSectionView::reject()
{
// Base::Console().Message("TSV::reject()\n");
std::string PageName = m_base->findParentPage()->getNameInDocument();
if (m_section != nullptr) {
if (m_createMode) {
std::string SectionName = m_section->getNameInDocument();
Gui::Command::doCommand(Gui::Command::Gui,
"App.activeDocument().%s.removeView(App.activeDocument().%s)",
PageName.c_str(),SectionName.c_str());
m_savePageName.c_str(),SectionName.c_str());
Gui::Command::doCommand(Gui::Command::Gui,
"App.activeDocument().removeObject('%s')",
SectionName.c_str());
} else {
restoreSectionState();
//check undo stack?
m_section->requestPaint();
m_base->requestPaint();
if (m_section != nullptr) {
m_section->requestPaint();
App::Document* doc = m_section->getDocument();
App::DocumentObject* baseObj = doc->getObject(m_saveBaseName.c_str());
TechDraw::DrawViewPart* dvp = dynamic_cast<TechDraw::DrawViewPart*>(baseObj);
if (dvp != nullptr) {
dvp->requestPaint();
}
}
}
}
@@ -490,6 +517,13 @@ bool TaskDlgSectionView::accept()
return true;
}
//bool TaskDlgSectionView::apply()
//{
// Base::Console().Message("TDSV::apply()\n");
// widget->apply();
// return true;
//}
bool TaskDlgSectionView::reject()
{
widget->reject();

View File

@@ -64,7 +64,7 @@ protected:
void saveSectionState();
void restoreSectionState();
void apply(void);
bool apply(void);
void applyQuick(std::string dir);
void applyAligned(void);
@@ -97,6 +97,9 @@ private:
bool m_createMode;
bool m_saved;
std::string m_saveBaseName;
std::string m_savePageName;
};
class TaskDlgSectionView : public Gui::TaskView::TaskDialog