Fix some bugs.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-10-28 17:31:18 +03:00
parent 46d6fcd29d
commit d3cf15f5b8
14 changed files with 156 additions and 87 deletions

View file

@ -694,7 +694,7 @@ void MainWindow::ClosedDialog(int result)
// Do not check for nullptr! See issue #719.
ui->view->itemClicked(tool);
}
ArrowTool();
ArrowTool(true);
}
//---------------------------------------------------------------------------------------------------------------------
@ -718,7 +718,7 @@ void MainWindow::ClosedDialogWithApply(int result, VMainGraphicsScene *scene)
vtool->DialogLinkDestroy();
connect(vtool, &DrawTool::ToolTip, this, &MainWindow::ShowToolTip);
}
ArrowTool();
ArrowTool(true);
ui->view->itemClicked(vtool);// Don't check for nullptr here
// If insert not to the end of file call lite parse
if (doc->getCursor() > 0)
@ -1131,7 +1131,7 @@ void MainWindow::ClosedDialogDuplicateDetail(int result)
// Do not check for nullptr! See issue #719.
ui->view->itemClicked(tool);
}
ArrowTool();
ArrowTool(true);
}
//---------------------------------------------------------------------------------------------------------------------
@ -1209,7 +1209,7 @@ void MainWindow::ClosedDialogGroup(int result)
qApp->getUndoStack()->push(addGroup);
}
}
ArrowTool();
ArrowTool(true);
}
//---------------------------------------------------------------------------------------------------------------------
@ -1220,7 +1220,7 @@ void MainWindow::ClosedDialogPiecePath(int result)
{
VToolPiecePath::Create(dialogTool, sceneDetails, doc, pattern);
}
ArrowTool();
ArrowTool(true);
doc->LiteParseTree(Document::LiteParse);
}
@ -1232,7 +1232,7 @@ void MainWindow::ClosedDialogPin(int result)
{
VToolPin::Create(dialogTool, doc, pattern);
}
ArrowTool();
ArrowTool(true);
doc->LiteParseTree(Document::LiteParse);
}
@ -1244,7 +1244,7 @@ void MainWindow::ClosedDialogPlaceLabel(int result)
{
VToolPlaceLabel::Create(dialogTool, doc, pattern);
}
ArrowTool();
ArrowTool(true);
doc->LiteParseTree(Document::LiteParse);
}
@ -1258,7 +1258,7 @@ void MainWindow::ClosedDialogInsertNode(int result)
SCASSERT(dTool != nullptr)
VToolSeamAllowance::InsertNode(dTool->GetNode(), dTool->GetPieceId(), sceneDetails, pattern, doc);
}
ArrowTool();
ArrowTool(true);
doc->LiteParseTree(Document::LiteParse);
}
@ -2271,49 +2271,58 @@ QT_WARNING_POP
/**
* @brief ArrowTool enable arrow tool.
*/
void MainWindow::ArrowTool()
void MainWindow::ArrowTool(bool checked)
{
qCDebug(vMainWindow, "Arrow tool.");
CancelTool();
for (auto pointer : toolButtonPointerList)
if (checked)
{
pointer->setChecked(true);
qCDebug(vMainWindow, "Arrow tool.");
CancelTool();
for (auto pointer : toolButtonPointerList)
{
pointer->setChecked(true);
}
currentTool = Tool::Arrow;
emit EnableItemMove(true);
emit ItemsSelection(SelectionType::ByMouseRelease);
VAbstractTool::m_suppressContextMenu = false;
// Only true for rubber band selection
emit EnableLabelSelection(true);
emit EnablePointSelection(false);
emit EnableLineSelection(false);
emit EnableArcSelection(false);
emit EnableElArcSelection(false);
emit EnableSplineSelection(false);
emit EnableSplinePathSelection(false);
emit EnableNodeLabelSelection(true);
emit EnableNodePointSelection(true);
emit EnableDetailSelection(true);// Disable when done visualization details
// Hovering
emit EnableLabelHover(true);
emit EnablePointHover(true);
emit EnableLineHover(true);
emit EnableArcHover(true);
emit EnableElArcHover(true);
emit EnableSplineHover(true);
emit EnableSplinePathHover(true);
emit EnableNodeLabelHover(true);
emit EnableNodePointHover(true);
emit EnableDetailHover(true);
ui->view->AllowRubberBand(true);
ui->view->viewport()->setCursor(QCursor(Qt::ArrowCursor));
helpLabel->setText("");
ui->view->setShowToolOptions(true);
qCDebug(vMainWindow, "Enabled arrow tool.");
}
else
{
for (auto pointer : toolButtonPointerList)
{
pointer->setChecked(true);
}
}
currentTool = Tool::Arrow;
emit EnableItemMove(true);
emit ItemsSelection(SelectionType::ByMouseRelease);
VAbstractTool::m_suppressContextMenu = false;
// Only true for rubber band selection
emit EnableLabelSelection(true);
emit EnablePointSelection(false);
emit EnableLineSelection(false);
emit EnableArcSelection(false);
emit EnableElArcSelection(false);
emit EnableSplineSelection(false);
emit EnableSplinePathSelection(false);
emit EnableNodeLabelSelection(true);
emit EnableNodePointSelection(true);
emit EnableDetailSelection(true);// Disable when done visualization details
// Hovering
emit EnableLabelHover(true);
emit EnablePointHover(true);
emit EnableLineHover(true);
emit EnableArcHover(true);
emit EnableElArcHover(true);
emit EnableSplineHover(true);
emit EnableSplinePathHover(true);
emit EnableNodeLabelHover(true);
emit EnableNodePointHover(true);
emit EnableDetailHover(true);
ui->view->AllowRubberBand(true);
ui->view->viewport()->unsetCursor();
helpLabel->setText("");
ui->view->setShowToolOptions(true);
qCDebug(vMainWindow, "Enabled arrow tool.");
}
//---------------------------------------------------------------------------------------------------------------------
@ -2326,7 +2335,7 @@ void MainWindow::keyPressEvent ( QKeyEvent * event )
switch (event->key())
{
case Qt::Key_Escape:
ArrowTool();
ArrowTool(true);
break;
case Qt::Key_Return:
case Qt::Key_Enter:
@ -2387,7 +2396,7 @@ void MainWindow::ActionDraw(bool checked)
if (checked)
{
qCDebug(vMainWindow, "Show draw scene");
ArrowTool();
ArrowTool(true);
leftGoToStage->setPixmap(QPixmap("://icon/24x24/fast_forward_left_to_right_arrow.png"));
rightGoToStage->setPixmap(QPixmap("://icon/24x24/left_to_right_arrow.png"));
@ -2437,7 +2446,7 @@ void MainWindow::ActionDetails(bool checked)
{
if (checked)
{
ArrowTool();
ArrowTool(true);
if(drawMode)
{
@ -2514,7 +2523,7 @@ void MainWindow::ActionLayout(bool checked)
{
if (checked)
{
ArrowTool();
ArrowTool(true);
if(drawMode)
{
@ -2879,7 +2888,7 @@ void MainWindow::Clear()
qCDebug(vMainWindow, "Clearing scenes.");
sceneDraw->clear();
sceneDetails->clear();
ArrowTool();
ArrowTool(true);
comboBoxDraws->clear();
ui->actionDraw->setEnabled(false);
ui->actionDetails->setEnabled(false);
@ -3151,7 +3160,7 @@ void MainWindow::SetEnabledGUI(bool enabled)
{
if (enabled == false)
{
ArrowTool();
ArrowTool(true);
qApp->getUndoStack()->clear();
}
SetEnableWidgets(enabled);
@ -3794,7 +3803,7 @@ void MainWindow::LastUsedTool()
{
pointer->setChecked(true);
}
ArrowTool();
ArrowTool(true);
break;
case Tool::BasePoint:
case Tool::SinglePoint:
@ -4912,7 +4921,7 @@ void MainWindow::ChangePP(int index, bool zoomBestFit)
emit RefreshHistory();
if (drawMode)
{
ArrowTool();
ArrowTool(true);
if (zoomBestFit)
{
ZoomFitBestCurrent();

View file

@ -124,7 +124,7 @@ private slots:
void ExportLayoutAs();
void ExportDetailsAs();
void ArrowTool();
void ArrowTool(bool checked);
void ToolEndLine(bool checked);
void ToolLine(bool checked);
void ToolAlongLine(bool checked);

View file

@ -210,7 +210,9 @@ VPointF *VToolCutSplinePath::CutSplinePath(qreal length, const QSharedPointer<VA
spl2.SetApproximationScale(splPath->GetApproximationScale());
*splPath1 = new VSplinePath();
(*splPath1)->SetApproximationScale(splPath->GetApproximationScale());
*splPath2 = new VSplinePath();
(*splPath2)->SetApproximationScale(splPath->GetApproximationScale());
for (qint32 i = 0; i < points.size(); i++)
{

View file

@ -237,7 +237,7 @@ void VToolSinglePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (selectionType == SelectionType::ByMouseRelease)
{
if (event->button() == Qt::LeftButton)
if (event->button() == Qt::LeftButton && contains(event->pos()))
{
PointChoosed();
}

View file

@ -141,6 +141,7 @@ VToolSeamAllowance *VToolSeamAllowance::Create(VToolSeamAllowanceInitData &initD
VAbstractTool::AddRecord(initData.id, Tool::Piece, initData.doc);
piece = new VToolSeamAllowance(initData);
initData.scene->addItem(piece);
VMainGraphicsView::NewSceneRect(initData.scene, qApp->getSceneView(), piece);
VAbstractPattern::AddTool(initData.id, piece);
}
//Very important to delete it. Only this tool need this special variable.
@ -584,12 +585,19 @@ void VToolSeamAllowance::FullUpdateFromFile()
void VToolSeamAllowance::EnableToolMove(bool move)
{
setFlag(QGraphicsItem::ItemIsMovable, move);
m_dataLabel->setFlag(QGraphicsItem::ItemIsMovable, move);
m_patternInfo->setFlag(QGraphicsItem::ItemIsMovable, move);
m_grainLine->setFlag(QGraphicsItem::ItemIsMovable, move);
}
//---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::AllowHover(bool enabled)
{
setAcceptHoverEvents(enabled);
m_dataLabel->setAcceptHoverEvents(enabled);
m_patternInfo->setAcceptHoverEvents(enabled);
m_grainLine->setAcceptHoverEvents(enabled);
}
//---------------------------------------------------------------------------------------------------------------------
@ -1086,13 +1094,18 @@ void VToolSeamAllowance::mousePressEvent(QGraphicsSceneMouseEvent *event)
}
}
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
if (selectionType == SelectionType::ByMouseRelease)
{
doc->SelectedDetail(m_id);
emit ChoosedTool(m_id, SceneObject::Detail);
event->accept();// Special for not selectable item first need to call standard mousePressEvent then accept event
}
else
{
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
{
doc->SelectedDetail(m_id);
emit ChoosedTool(m_id, SceneObject::Detail);
}
}
event->accept();// Special for not selectable item first need to call standard mousePressEvent then accept event
}
//---------------------------------------------------------------------------------------------------------------------
@ -1102,6 +1115,15 @@ void VToolSeamAllowance::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
}
if (selectionType == SelectionType::ByMouseRelease)
{
if (event->button() == Qt::LeftButton && contains(event->pos()))
{
doc->SelectedDetail(m_id);
emit ChoosedTool(m_id, SceneObject::Detail);
}
}
QGraphicsPathItem::mouseReleaseEvent(event);
}
@ -1112,16 +1134,6 @@ void VToolSeamAllowance::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
}
else
{
if (QGraphicsScene *scene = this->scene())
{
if (QGraphicsView *view = scene->views().at(0))
{
setCursor(view->viewport()->cursor());
}
}
}
QGraphicsPathItem::hoverEnterEvent(event);
}
@ -1258,6 +1270,8 @@ VToolSeamAllowance::VToolSeamAllowance(const VToolSeamAllowanceInitData &initDat
setAcceptHoverEvents(true);
connect(this, &VToolSeamAllowance::ChoosedTool, m_sceneDetails, &VMainGraphicsScene::ChoosedItem);
connect(m_sceneDetails, &VMainGraphicsScene::EnableToolMove, this, &VToolSeamAllowance::EnableToolMove);
connect(m_sceneDetails, &VMainGraphicsScene::ItemSelection, this, &VToolSeamAllowance::ToolSelectionType);
ConnectOutsideSignals();
}

View file

@ -76,8 +76,10 @@ void VisToolCutSpline::RefreshGeometry()
QPointF spl2p3;
const QPointF p = spl->CutSpline (length, spl1p2, spl1p3, spl2p2, spl2p3 );
const VSpline sp1 = VSpline(spl->GetP1(), spl1p2, spl1p3, VPointF(p));
const VSpline sp2 = VSpline(VPointF(p), spl2p2, spl2p3, spl->GetP4());
VSpline sp1 = VSpline(spl->GetP1(), spl1p2, spl1p3, VPointF(p));
sp1.SetApproximationScale(spl->GetApproximationScale());
VSpline sp2 = VSpline(VPointF(p), spl2p2, spl2p3, spl->GetP4());
sp2.SetApproximationScale(spl->GetApproximationScale());
DrawPoint(point, p, mainColor);

View file

@ -45,10 +45,12 @@ void VisToolDuplicateDetail::RefreshGeometry()
{
m_start = Visualization::scenePos;
m_started = true;
setPos(QPointF(piece.GetMx(), piece.GetMy()));
}
else
{
m_diff = Visualization::scenePos - m_start;
m_diff = QPointF(m_diff.x() + piece.GetMx(), m_diff.y() + piece.GetMy());
setPos(m_diff);
}

View file

@ -271,7 +271,8 @@ bool VGrainlineItem::IsContained(const QPointF& pt, qreal dRot, qreal &dX, qreal
*/
void VGrainlineItem::mousePressEvent(QGraphicsSceneMouseEvent* pME)
{
if (pME->button() == Qt::LeftButton && pME->type() != QEvent::GraphicsSceneMouseDoubleClick)
if (pME->button() == Qt::LeftButton && pME->type() != QEvent::GraphicsSceneMouseDoubleClick
&& (flags() & QGraphicsItem::ItemIsMovable))
{
if (m_moveType == NotMovable)
{
@ -457,7 +458,7 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME)
{
if (pME->button() == Qt::LeftButton)
{
if (m_eMode == mMove || m_eMode == mRotate || m_eMode == mResize)
if ((m_eMode == mMove || m_eMode == mRotate || m_eMode == mResize) && (flags() & QGraphicsItem::ItemIsMovable))
{
SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
}
@ -508,14 +509,22 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME)
//---------------------------------------------------------------------------------------------------------------------
void VGrainlineItem::hoverEnterEvent(QGraphicsSceneHoverEvent *pME)
{
m_penWidth = LINE_PEN_WIDTH + 1;
if (flags() & QGraphicsItem::ItemIsMovable)
{
SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
m_penWidth = LINE_PEN_WIDTH + 1;
}
VPieceItem::hoverEnterEvent(pME);
}
//---------------------------------------------------------------------------------------------------------------------
void VGrainlineItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *pME)
{
m_penWidth = LINE_PEN_WIDTH;
if (flags() & QGraphicsItem::ItemIsMovable)
{
setCursor(QCursor());
m_penWidth = LINE_PEN_WIDTH;
}
VPieceItem::hoverLeaveEvent(pME);
}

View file

@ -289,7 +289,7 @@ void VGraphicsSimpleTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
}
}
if (selectionType == SelectionType::ByMouseRelease)
if (selectionType == SelectionType::ByMouseRelease && contains(event->pos()))
{
emit PointChoosed();
}

View file

@ -596,9 +596,21 @@ void VMainGraphicsView::NewSceneRect(QGraphicsScene *sc, QGraphicsView *view, QG
//Unite two rects
sc->setSceneRect(itemsRect.united(viewRect));
}
else if (not sc->sceneRect().contains(item->sceneBoundingRect()))
else
{
sc->setSceneRect(sc->sceneRect().united(item->sceneBoundingRect()));
QRectF rect = item->sceneBoundingRect();
foreach(QGraphicsItem *child, item->childItems())
{
if(child->isVisible())
{
rect = rect.united(child->sceneBoundingRect());
}
}
if (not sc->sceneRect().contains(rect))
{
sc->setSceneRect(sc->sceneRect().united(rect));
}
}
}

View file

@ -116,7 +116,7 @@ void VSimpleCurve::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (selectionType == SelectionType::ByMouseRelease)
{
if (event->button() == Qt::LeftButton)
if (event->button() == Qt::LeftButton && contains(event->pos()))
{
emit Choosed(id);
}

View file

@ -177,7 +177,7 @@ void VSimplePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (selectionType == SelectionType::ByMouseRelease)
{
if (event->button() == Qt::LeftButton)
if (event->button() == Qt::LeftButton && contains(event->pos()))
{
emit Choosed(id);
}

View file

@ -375,7 +375,8 @@ int VTextGraphicsItem::GetFontSize() const
*/
void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME)
{
if (pME->button() == Qt::LeftButton && pME->type() != QEvent::GraphicsSceneMouseDoubleClick)
if (pME->button() == Qt::LeftButton && pME->type() != QEvent::GraphicsSceneMouseDoubleClick
&& (flags() & QGraphicsItem::ItemIsMovable))
{
if (m_moveType == NotMovable)
{
@ -455,6 +456,10 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME)
pME->ignore();
}
}
else
{
pME->ignore();
}
}
//---------------------------------------------------------------------------------------------------------------------
@ -552,7 +557,7 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME)
if (pME->button() == Qt::LeftButton)
{
// restore the cursor
if (m_eMode == mMove || m_eMode == mRotate || m_eMode == mResize)
if ((m_eMode == mMove || m_eMode == mRotate || m_eMode == mResize) && (flags() & QGraphicsItem::ItemIsMovable))
{
SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
}
@ -620,6 +625,16 @@ void VTextGraphicsItem::hoverMoveEvent(QGraphicsSceneHoverEvent* pHE)
VPieceItem::hoverMoveEvent(pHE);
}
//---------------------------------------------------------------------------------------------------------------------
void VTextGraphicsItem::hoverEnterEvent(QGraphicsSceneHoverEvent *pME)
{
if (flags() & QGraphicsItem::ItemIsMovable)
{
SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
}
VPieceItem::hoverEnterEvent(pME);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VTextGraphicsItem::hoverLeaveEvent tries to restore normal mouse cursor
@ -627,7 +642,10 @@ void VTextGraphicsItem::hoverMoveEvent(QGraphicsSceneHoverEvent* pHE)
*/
void VTextGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* pHE)
{
setCursor(QCursor());
if (flags() & QGraphicsItem::ItemIsMovable)
{
setCursor(QCursor());
}
VPieceItem::hoverLeaveEvent(pHE);
}

View file

@ -73,6 +73,7 @@ protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent* pME) Q_DECL_OVERRIDE;
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* pME) Q_DECL_OVERRIDE;
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) Q_DECL_OVERRIDE;
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *pME) Q_DECL_OVERRIDE;
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent* pHE) Q_DECL_OVERRIDE;
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* pHE) Q_DECL_OVERRIDE;