Allow a user interact only with items from active pattern piece.

--HG--
branch : develop
This commit is contained in:
dismine 2014-10-02 16:34:49 +03:00
parent a9c496e065
commit 50f82eee27
9 changed files with 55 additions and 133 deletions

View File

@ -80,22 +80,11 @@ void VAbstractSpline::Disable(bool disable)
*/
void VAbstractSpline::ChangedActivDraw(const QString &newName)
{
bool selectable = false;
if (nameActivDraw == newName)
{
selectable = true;
currentColor = Qt::black;
}
else
{
selectable = false;
currentColor = Qt::gray;
}
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor));
this->setFlag(QGraphicsItem::ItemIsSelectable, selectable);
this->setAcceptHoverEvents (selectable);
emit setEnabledPoint(selectable);
VDrawTool::ChangedActivDraw(newName);
const bool selectable = (nameActivDraw == newName);
this->setEnabled(selectable);
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor));
emit setEnabledPoint(selectable);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -46,7 +46,7 @@ qreal VDrawTool::factor = 1;
* @param id object id in container.
*/
VDrawTool::VDrawTool(VPattern *doc, VContainer *data, quint32 id)
:VAbstractTool(doc, data, id), ignoreContextMenuEvent(false), ignoreFullUpdate(false),
:VAbstractTool(doc, data, id), ignoreFullUpdate(false),
nameActivDraw(doc->GetNameActivPP()), dialog(nullptr)
{
connect(this->doc, &VPattern::ChangedActivPP, this, &VDrawTool::ChangedActivDraw);
@ -83,11 +83,11 @@ void VDrawTool::ChangedActivDraw(const QString &newName)
{
if (nameActivDraw == newName)
{
ignoreContextMenuEvent = false;
currentColor = Qt::black;
}
else
{
ignoreContextMenuEvent = true;
currentColor = Qt::gray;
}
}

View File

@ -54,7 +54,6 @@ public:
/** @brief setDialog set dialog when user want change tool option. */
virtual void setDialog() {}
virtual void DialogLinkDestroy();
void ignoreContextMenu(bool enable);
static qreal CheckFormula(const quint32 &toolId, QString &formula, VContainer *data);
public slots:
virtual void ShowTool(quint32 id, Qt::GlobalColor color, bool enable);
@ -64,8 +63,6 @@ public slots:
virtual void FullUpdateFromGuiApply();
virtual void SetFactor(qreal factor);
protected:
/** @brief ignoreContextMenuEvent ignore or not context menu events. */
bool ignoreContextMenuEvent;
/** @brief ignoreFullUpdate ignore or not full updates. */
bool ignoreFullUpdate;
@ -95,50 +92,48 @@ protected:
{
SCASSERT(tool != nullptr);
SCASSERT(event != nullptr);
if (ignoreContextMenuEvent == false)
QMenu menu;
QAction *actionOption = menu.addAction(tr("Options"));
QAction *actionRemove = nullptr;
actionRemove = menu.addAction(tr("Delete"));
if (showRemove)
{
QMenu menu;
QAction *actionOption = menu.addAction(tr("Options"));
QAction *actionRemove = nullptr;
actionRemove = menu.addAction(tr("Delete"));
if (showRemove)
{
if (_referens > 1)
{
actionRemove->setEnabled(false);
}
else
{
actionRemove->setEnabled(true);
}
}
else
if (_referens > 1)
{
actionRemove->setEnabled(false);
}
QAction *selectedAction = menu.exec(event->screenPos());
if (selectedAction == actionOption)
else
{
qApp->getSceneView()->itemClicked(nullptr);
dialog = new Dialog(getData(), id, qApp->getMainWindow());
dialog->setModal(true);
connect(dialog, &DialogTool::DialogClosed, tool, &Tool::FullUpdateFromGuiOk);
connect(dialog, &DialogTool::DialogApplied, tool, &Tool::FullUpdateFromGuiApply);
if (ignoreFullUpdate == false)
{
connect(doc, &VPattern::FullUpdateFromFile, dialog, &DialogTool::UpdateList);
}
tool->setDialog();
dialog->show();
actionRemove->setEnabled(true);
}
if (selectedAction == actionRemove)
}
else
{
actionRemove->setEnabled(false);
}
QAction *selectedAction = menu.exec(event->screenPos());
if (selectedAction == actionOption)
{
qApp->getSceneView()->itemClicked(nullptr);
dialog = new Dialog(getData(), id, qApp->getMainWindow());
dialog->setModal(true);
connect(dialog, &DialogTool::DialogClosed, tool, &Tool::FullUpdateFromGuiOk);
connect(dialog, &DialogTool::DialogApplied, tool, &Tool::FullUpdateFromGuiApply);
if (ignoreFullUpdate == false)
{
DeleteTool();
connect(doc, &VPattern::FullUpdateFromFile, dialog, &DialogTool::UpdateList);
}
tool->setDialog();
dialog->show();
}
if (selectedAction == actionRemove)
{
DeleteTool();
}
}
template <typename Item>
@ -183,14 +178,4 @@ private:
Q_DISABLE_COPY(VDrawTool)
};
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ignoreContextMenu set ignore contect menu tool.
* @param enable true - ignore.
*/
inline void VDrawTool::ignoreContextMenu(bool enable)
{
ignoreContextMenuEvent = enable;
}
#endif // VDRAWTOOL_H

View File

@ -59,20 +59,11 @@ VToolCut::VToolCut(VPattern *doc, VContainer *data, const quint32 &id, const QSt
*/
void VToolCut::ChangedActivDraw(const QString &newName)
{
bool flag = true;
if (nameActivDraw == newName)
{
currentColor = Qt::black;
flag = true;
}
else
{
currentColor = Qt::gray;
flag = false;
}
VToolPoint::ChangedActivDraw(newName);
const bool flag = (nameActivDraw == newName);
this->setEnabled(flag);
firstCurve->ChangedActivDraw(flag);
secondCurve->ChangedActivDraw(flag);
VToolPoint::ChangedActivDraw(newName);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -237,20 +237,8 @@ void VToolLine::Disable(bool disable)
*/
void VToolLine::ChangedActivDraw(const QString &newName)
{
bool selectable = false;
if (nameActivDraw == newName)
{
selectable = true;
currentColor = Qt::black;
}
else
{
selectable = false;
currentColor = Qt::gray;
}
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor, LineStyle(typeLine)));
this->setAcceptHoverEvents (selectable);
VDrawTool::ChangedActivDraw(newName);
this->setEnabled(nameActivDraw == newName);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -63,16 +63,8 @@ VToolLinePoint::VToolLinePoint(VPattern *doc, VContainer *data, const quint32 &i
*/
void VToolLinePoint::ChangedActivDraw(const QString &newName)
{
if (nameActivDraw == newName)
{
currentColor = Qt::black;
}
else
{
currentColor = Qt::gray;
}
mainLine->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor, LineStyle(typeLine)));
VToolPoint::ChangedActivDraw(newName);
this->setEnabled(nameActivDraw == newName);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -132,27 +132,9 @@ void VToolPoint::UpdateNamePosition(qreal mx, qreal my)
*/
void VToolPoint::ChangedActivDraw(const QString &newName)
{
bool selectable = false;
if (nameActivDraw == newName)
{
selectable = true;
currentColor = baseColor;
}
else
{
selectable = false;
currentColor = Qt::gray;
}
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor));
this->setFlag(QGraphicsItem::ItemIsSelectable, selectable);
this->setAcceptHoverEvents (selectable);
namePoint->setFlag(QGraphicsItem::ItemIsMovable, selectable);
namePoint->setFlag(QGraphicsItem::ItemIsSelectable, selectable);
namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, selectable);
namePoint->setBrush(QBrush(currentColor));
namePoint->setAcceptHoverEvents(selectable);
lineName->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor));
VDrawTool::ChangedActivDraw(newName);
this->setEnabled(nameActivDraw == newName);
namePoint->setBrush(QBrush(currentColor));
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -306,18 +306,8 @@ void VToolSinglePoint::FullUpdateFromFile()
*/
void VToolSinglePoint::ChangedActivDraw(const QString &newName)
{
if (nameActivDraw == newName)
{
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
VToolPoint::ChangedActivDraw(newName);
setColorLabel(Qt::black);
}
else
{
this->setFlag(QGraphicsItem::ItemIsSelectable, false);
VToolPoint::ChangedActivDraw(newName);
setColorLabel(Qt::gray);
}
VToolPoint::ChangedActivDraw(newName);
this->setEnabled(nameActivDraw == newName);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -297,6 +297,11 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property)
//---------------------------------------------------------------------------------------------------------------------
void VToolOptionsPropertyBrowser::itemClicked(QGraphicsItem *item)
{
if (item != nullptr && item->isEnabled()==false)
{
return;
}
if (currentItem == item)
{
UpdateOptions();