keep sub mode over mode changes

move
Marc Zinnschlag 9 years ago
parent a63453846b
commit b5005f7812

@ -27,8 +27,8 @@ int CSVRender::InstanceMode::getSubModeFromId (const std::string& id) const
CSVRender::InstanceMode::InstanceMode (WorldspaceWidget *worldspaceWidget, QWidget *parent) CSVRender::InstanceMode::InstanceMode (WorldspaceWidget *worldspaceWidget, QWidget *parent)
: EditMode (worldspaceWidget, QIcon (":placeholder"), Mask_Reference, "Instance editing", : EditMode (worldspaceWidget, QIcon (":placeholder"), Mask_Reference, "Instance editing",
parent), mSubMode (0), mSelectionMode (0), mDragMode (DragMode_None), mDragAxis (-1), parent), mSubMode (0), mSubModeId ("move"), mSelectionMode (0), mDragMode (DragMode_None),
mLocked (false) mDragAxis (-1), mLocked (false)
{ {
} }
@ -51,6 +51,8 @@ void CSVRender::InstanceMode::activate (CSVWidget::SceneToolbar *toolbar)
"</ul>" "</ul>"
"<font color=Red>Not implemented yet</font color>"); "<font color=Red>Not implemented yet</font color>");
mSubMode->setButton (mSubModeId);
connect (mSubMode, SIGNAL (modeChanged (const std::string&)), connect (mSubMode, SIGNAL (modeChanged (const std::string&)),
this, SLOT (subModeChanged (const std::string&))); this, SLOT (subModeChanged (const std::string&)));
} }
@ -454,6 +456,7 @@ int CSVRender::InstanceMode::getSubMode() const
void CSVRender::InstanceMode::subModeChanged (const std::string& id) void CSVRender::InstanceMode::subModeChanged (const std::string& id)
{ {
mSubModeId = id;
getWorldspaceWidget().abortDrag(); getWorldspaceWidget().abortDrag();
getWorldspaceWidget().setSubMode (getSubModeFromId (id), Mask_Reference); getWorldspaceWidget().setSubMode (getSubModeFromId (id), Mask_Reference);
} }

@ -23,6 +23,7 @@ namespace CSVRender
}; };
CSVWidget::SceneToolMode *mSubMode; CSVWidget::SceneToolMode *mSubMode;
std::string mSubModeId;
InstanceSelectionMode *mSelectionMode; InstanceSelectionMode *mSelectionMode;
DragMode mDragMode; DragMode mDragMode;
int mDragAxis; int mDragAxis;

@ -38,6 +38,27 @@ void CSVWidget::SceneToolMode::adjustToolTip (const ModeButton *activeMode)
setToolTip (toolTip); setToolTip (toolTip);
} }
void CSVWidget::SceneToolMode::setButton (std::map<ModeButton *, std::string>::iterator iter)
{
for (std::map<ModeButton *, std::string>::const_iterator iter2 = mButtons.begin();
iter2!=mButtons.end(); ++iter2)
iter2->first->setChecked (iter2==iter);
setIcon (iter->first->icon());
adjustToolTip (iter->first);
if (mCurrent!=iter->first)
{
if (mCurrent)
mCurrent->deactivate (mToolbar);
mCurrent = iter->first;
mCurrent->activate (mToolbar);
}
emit modeChanged (iter->second);
}
CSVWidget::SceneToolMode::SceneToolMode (SceneToolbar *parent, const QString& toolTip) CSVWidget::SceneToolMode::SceneToolMode (SceneToolbar *parent, const QString& toolTip)
: SceneTool (parent), mButtonSize (parent->getButtonSize()), mIconSize (parent->getIconSize()), : SceneTool (parent), mButtonSize (parent->getButtonSize()), mIconSize (parent->getIconSize()),
mToolTip (toolTip), mFirst (0), mCurrent (0), mToolbar (parent) mToolTip (toolTip), mFirst (0), mCurrent (0), mToolbar (parent)
@ -101,9 +122,20 @@ std::string CSVWidget::SceneToolMode::getCurrentId() const
return mButtons.find (mCurrent)->second; return mButtons.find (mCurrent)->second;
} }
void CSVWidget::SceneToolMode::setButton (const std::string& id)
{
for (std::map<ModeButton *, std::string>::iterator iter = mButtons.begin();
iter!=mButtons.end(); ++iter)
if (iter->second==id)
{
setButton (iter);
break;
}
}
void CSVWidget::SceneToolMode::selected() void CSVWidget::SceneToolMode::selected()
{ {
std::map<ModeButton *, std::string>::const_iterator iter = std::map<ModeButton *, std::string>::iterator iter =
mButtons.find (dynamic_cast<ModeButton *> (sender())); mButtons.find (dynamic_cast<ModeButton *> (sender()));
if (iter!=mButtons.end()) if (iter!=mButtons.end())
@ -111,22 +143,6 @@ void CSVWidget::SceneToolMode::selected()
if (!iter->first->hasKeepOpen()) if (!iter->first->hasKeepOpen())
mPanel->hide(); mPanel->hide();
for (std::map<ModeButton *, std::string>::const_iterator iter2 = mButtons.begin(); setButton (iter);
iter2!=mButtons.end(); ++iter2)
iter2->first->setChecked (iter2==iter);
setIcon (iter->first->icon());
adjustToolTip (iter->first);
if (mCurrent!=iter->first)
{
if (mCurrent)
mCurrent->deactivate (mToolbar);
mCurrent = iter->first;
mCurrent->activate (mToolbar);
}
emit modeChanged (iter->second);
} }
} }

@ -41,6 +41,8 @@ namespace CSVWidget
/// items to be added, the function must return true anyway. /// items to be added, the function must return true anyway.
virtual bool createContextMenu (QMenu *menu); virtual bool createContextMenu (QMenu *menu);
void setButton (std::map<ModeButton *, std::string>::iterator iter);
public: public:
SceneToolMode (SceneToolbar *parent, const QString& toolTip); SceneToolMode (SceneToolbar *parent, const QString& toolTip);
@ -59,6 +61,9 @@ namespace CSVWidget
/// Must not be called if there aren't any buttons yet. /// Must not be called if there aren't any buttons yet.
std::string getCurrentId() const; std::string getCurrentId() const;
/// Manually change the current mode
void setButton (const std::string& id);
signals: signals:
void modeChanged (const std::string& id); void modeChanged (const std::string& id);

Loading…
Cancel
Save