mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 20:19:57 +00:00
added framework for drag operations
This commit is contained in:
parent
8e87b48866
commit
0a5bfb2107
4 changed files with 116 additions and 11 deletions
|
@ -38,3 +38,24 @@ void CSVRender::EditMode::primaryEditPressed (osg::ref_ptr<TagBase> tag) {}
|
|||
void CSVRender::EditMode::secondaryEditPressed (osg::ref_ptr<TagBase> tag) {}
|
||||
|
||||
void CSVRender::EditMode::selectPressed (osg::ref_ptr<TagBase> tag) {}
|
||||
|
||||
bool CSVRender::EditMode::primaryEditStartDrag (osg::ref_ptr<TagBase> tag)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CSVRender::EditMode::secondaryEditStartDrag (osg::ref_ptr<TagBase> tag)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CSVRender::EditMode::selectStartDrag (osg::ref_ptr<TagBase> tag)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void CSVRender::EditMode::drag (int diffX, int diffY) {}
|
||||
|
||||
void CSVRender::EditMode::dragCompleted() {}
|
||||
|
||||
void CSVRender::EditMode::dragAborted() {}
|
||||
|
|
|
@ -44,6 +44,33 @@ namespace CSVRender
|
|||
|
||||
/// Default-implementation: Ignored.
|
||||
virtual void selectPressed (osg::ref_ptr<TagBase> tag);
|
||||
|
||||
/// Default-implementation: ignore and return false
|
||||
///
|
||||
/// \return Drag accepted?
|
||||
virtual bool primaryEditStartDrag (osg::ref_ptr<TagBase> tag);
|
||||
|
||||
/// Default-implementation: ignore and return false
|
||||
///
|
||||
/// \return Drag accepted?
|
||||
virtual bool secondaryEditStartDrag (osg::ref_ptr<TagBase> tag);
|
||||
|
||||
/// Default-implementation: ignore and return false
|
||||
///
|
||||
/// \return Drag accepted?
|
||||
virtual bool selectStartDrag (osg::ref_ptr<TagBase> tag);
|
||||
|
||||
/// Default-implementation: ignored
|
||||
virtual void drag (int diffX, int diffY);
|
||||
|
||||
/// Default-implementation: ignored
|
||||
virtual void dragCompleted();
|
||||
|
||||
/// Default-implementation: ignored
|
||||
///
|
||||
/// \note dragAborted will not be called, if the drag is aborted via changing
|
||||
/// editing mode
|
||||
virtual void dragAborted();
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ namespace
|
|||
|
||||
CSVRender::WorldspaceWidget::WorldspaceWidget (CSMDoc::Document& document, QWidget* parent)
|
||||
: SceneWidget (document.getData().getResourceSystem(), parent), mSceneElements(0), mRun(0), mDocument(document),
|
||||
mInteractionMask (0), mEditMode (0), mLocked (false)
|
||||
mInteractionMask (0), mEditMode (0), mLocked (false), mDragging (false)
|
||||
{
|
||||
setAcceptDrops(true);
|
||||
|
||||
|
@ -480,6 +480,7 @@ void CSVRender::WorldspaceWidget::debugProfileAboutToBeRemoved (const QModelInde
|
|||
void CSVRender::WorldspaceWidget::editModeChanged (const std::string& id)
|
||||
{
|
||||
dynamic_cast<CSVRender::EditMode&> (*mEditMode->getCurrent()).setEditLock (mLocked);
|
||||
mDragging = false;
|
||||
}
|
||||
|
||||
void CSVRender::WorldspaceWidget::elementSelectionChanged()
|
||||
|
@ -495,10 +496,45 @@ void CSVRender::WorldspaceWidget::updateOverlay()
|
|||
|
||||
void CSVRender::WorldspaceWidget::mouseMoveEvent (QMouseEvent *event)
|
||||
{
|
||||
if(event->buttons() & Qt::RightButton)
|
||||
if (!mDragging)
|
||||
{
|
||||
//mMouse->mouseMoveEvent(event);
|
||||
if (mDragMode=="p-navi" || mDragMode=="s-navi")
|
||||
{
|
||||
|
||||
}
|
||||
else if (mDragMode=="p-edit" || mDragMode=="s-edit" || mDragMode=="select")
|
||||
{
|
||||
osg::ref_ptr<TagBase> tag = mousePick (event);
|
||||
|
||||
EditMode& editMode = dynamic_cast<CSVRender::EditMode&> (*mEditMode->getCurrent());
|
||||
|
||||
if (mDragMode=="p-edit")
|
||||
mDragging = editMode.primaryEditStartDrag (tag);
|
||||
else if (mDragMode=="s-edit")
|
||||
mDragging = editMode.secondaryEditStartDrag (tag);
|
||||
else if (mDragMode=="select")
|
||||
mDragging = editMode.selectStartDrag (tag);
|
||||
|
||||
if (mDragging)
|
||||
{
|
||||
mDragX = event->posF().x();
|
||||
mDragY = height() - event->posF().y();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int diffX = event->x() - mDragX;
|
||||
int diffY = (height() - event->y()) - mDragY;
|
||||
|
||||
mDragX = event->x();
|
||||
mDragY = height() - event->y();
|
||||
|
||||
EditMode& editMode = dynamic_cast<CSVRender::EditMode&> (*mEditMode->getCurrent());
|
||||
|
||||
editMode.drag (diffX, diffY);
|
||||
}
|
||||
|
||||
RenderWidget::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
|
@ -506,6 +542,9 @@ void CSVRender::WorldspaceWidget::mousePressEvent (QMouseEvent *event)
|
|||
{
|
||||
std::string button = mapButton (event);
|
||||
|
||||
if (!mDragging)
|
||||
mDragMode = button;
|
||||
|
||||
if (button=="p-navi" || button=="s-navi")
|
||||
{
|
||||
|
||||
|
@ -527,17 +566,25 @@ void CSVRender::WorldspaceWidget::mousePressEvent (QMouseEvent *event)
|
|||
|
||||
void CSVRender::WorldspaceWidget::mouseReleaseEvent (QMouseEvent *event)
|
||||
{
|
||||
if(event->button() == Qt::RightButton)
|
||||
if (mDragging)
|
||||
{
|
||||
/*
|
||||
if(!getViewport())
|
||||
std::string button = mapButton (event);
|
||||
|
||||
if (mDragMode=="p-navi" || mDragMode=="s-navi")
|
||||
{
|
||||
SceneWidget::mouseReleaseEvent(event);
|
||||
return;
|
||||
|
||||
}
|
||||
*/
|
||||
//mMouse->mouseReleaseEvent(event);
|
||||
else if (mDragMode=="p-edit" || mDragMode=="s-edit" || mDragMode=="select")
|
||||
{
|
||||
EditMode& editMode = dynamic_cast<CSVRender::EditMode&> (*mEditMode->getCurrent());
|
||||
|
||||
editMode.dragCompleted();
|
||||
mDragging = false;
|
||||
}
|
||||
}
|
||||
|
||||
mDragMode.clear();
|
||||
|
||||
RenderWidget::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
|
@ -560,7 +607,13 @@ void CSVRender::WorldspaceWidget::keyPressEvent (QKeyEvent *event)
|
|||
{
|
||||
if(event->key() == Qt::Key_Escape)
|
||||
{
|
||||
//mMouse->cancelDrag();
|
||||
if (mDragging)
|
||||
{
|
||||
EditMode& editMode = dynamic_cast<CSVRender::EditMode&> (*mEditMode->getCurrent());
|
||||
|
||||
editMode.dragAborted();
|
||||
mDragging = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
RenderWidget::keyPressEvent(event);
|
||||
|
|
|
@ -39,6 +39,10 @@ namespace CSVRender
|
|||
std::map<std::pair<Qt::MouseButton, bool>, std::string> mButtonMapping;
|
||||
CSVWidget::SceneToolMode *mEditMode;
|
||||
bool mLocked;
|
||||
std::string mDragMode;
|
||||
bool mDragging;
|
||||
int mDragX;
|
||||
int mDragY;
|
||||
|
||||
public:
|
||||
|
||||
|
|
Loading…
Reference in a new issue