diff --git a/apps/opencs/view/render/scenewidget.cpp b/apps/opencs/view/render/scenewidget.cpp index 504f5cc25..ff6ae2551 100644 --- a/apps/opencs/view/render/scenewidget.cpp +++ b/apps/opencs/view/render/scenewidget.cpp @@ -18,6 +18,8 @@ #include "../widget/scenetoolmode.hpp" +#include "../../model/prefs/state.hpp" + #include "lighting.hpp" #include "mask.hpp" @@ -143,7 +145,8 @@ void CompositeViewer::update() // --------------------------------------------------- -SceneWidget::SceneWidget(boost::shared_ptr resourceSystem, QWidget *parent, Qt::WindowFlags f) +SceneWidget::SceneWidget(boost::shared_ptr resourceSystem, QWidget *parent, Qt::WindowFlags f, + bool retrieveInput) : RenderWidget(parent, f) , mResourceSystem(resourceSystem) , mLighting(NULL) @@ -159,6 +162,16 @@ SceneWidget::SceneWidget(boost::shared_ptr resourceSys /// \todo make shortcut configurable QShortcut *focusToolbar = new QShortcut (Qt::Key_T, this, 0, 0, Qt::WidgetWithChildrenShortcut); connect (focusToolbar, SIGNAL (activated()), this, SIGNAL (focusToolbarRequest())); + + connect (&CSMPrefs::State::get(), SIGNAL (settingChanged (const CSMPrefs::Setting *)), + this, SLOT (settingChanged (const CSMPrefs::Setting *))); + + // TODO update this outside of the constructor where virtual methods can be used + if (retrieveInput) + { + CSMPrefs::get()["3D Scene Input"].update(); + CSMPrefs::get()["Tooltips"].update(); + } } SceneWidget::~SceneWidget() @@ -238,4 +251,85 @@ void SceneWidget::setDefaultAmbient (const osg::Vec4f& colour) setAmbient(mLighting->getAmbientColour(&mDefaultAmbient)); } +void SceneWidget::mousePressEvent (QMouseEvent *event) +{ + std::string button = mapButton(event); + + // TODO placeholders + if (button == "p-navi") + { + } + else if (button == "s-navi") + { + } +} + +void SceneWidget::mouseReleaseEvent (QMouseEvent *event) +{ + std::string button = mapButton(event); + + // TODO placeholders + if (button == "p-navi") + { + } + else if (button == "s-navi") + { + } +} + +void SceneWidget::settingChanged (const CSMPrefs::Setting *setting) +{ + storeMappingSetting(setting); +} + +bool SceneWidget::storeMappingSetting (const CSMPrefs::Setting *setting) +{ + if (setting->getParent()->getKey()!="3D Scene Input") + return false; + + static const char * const sMappingSettings[] = + { + "p-navi", "s-navi", + 0 + }; + + for (int i=0; sMappingSettings[i]; ++i) + if (setting->getKey()==sMappingSettings[i]) + { + QString value = QString::fromUtf8 (setting->toString().c_str()); + + Qt::MouseButton button = Qt::NoButton; + + if (value.endsWith ("Left Mouse-Button")) + button = Qt::LeftButton; + else if (value.endsWith ("Right Mouse-Button")) + button = Qt::RightButton; + else if (value.endsWith ("Middle Mouse-Button")) + button = Qt::MiddleButton; + else + return false; + + bool ctrl = value.startsWith ("Ctrl-"); + + mButtonMapping[std::make_pair (button, ctrl)] = sMappingSettings[i]; + return true; + } + + return false; +} + +std::string SceneWidget::mapButton (QMouseEvent *event) +{ + std::pair phyiscal ( + event->button(), event->modifiers() & Qt::ControlModifier); + + std::map, std::string>::const_iterator iter = + mButtonMapping.find (phyiscal); + + if (iter!=mButtonMapping.end()) + return iter->second; + + return ""; +} + } diff --git a/apps/opencs/view/render/scenewidget.hpp b/apps/opencs/view/render/scenewidget.hpp index e759e78c4..8d17fb8a5 100644 --- a/apps/opencs/view/render/scenewidget.hpp +++ b/apps/opencs/view/render/scenewidget.hpp @@ -1,6 +1,8 @@ #ifndef OPENCS_VIEW_SCENEWIDGET_H #define OPENCS_VIEW_SCENEWIDGET_H +#include + #include #include @@ -30,6 +32,11 @@ namespace CSVWidget class SceneToolbar; } +namespace CSMPrefs +{ + class Setting; +} + namespace CSVRender { class Lighting; @@ -62,7 +69,8 @@ namespace CSVRender { Q_OBJECT public: - SceneWidget(boost::shared_ptr resourceSystem, QWidget* parent = 0, Qt::WindowFlags f = 0); + SceneWidget(boost::shared_ptr resourceSystem, QWidget* parent = 0, + Qt::WindowFlags f = 0, bool retrieveInput = true); virtual ~SceneWidget(); CSVWidget::SceneToolMode *makeLightingSelector (CSVWidget::SceneToolbar *parent); @@ -78,6 +86,14 @@ namespace CSVRender void setAmbient(const osg::Vec4f& ambient); + virtual void mousePressEvent (QMouseEvent *event); + virtual void mouseReleaseEvent (QMouseEvent *event); + + /// \return Is \a key a button mapping setting? (ignored otherwise) + virtual bool storeMappingSetting (const CSMPrefs::Setting *setting); + + std::string mapButton (QMouseEvent *event); + boost::shared_ptr mResourceSystem; Lighting* mLighting; @@ -88,6 +104,12 @@ namespace CSVRender LightingNight mLightingNight; LightingBright mLightingBright; + std::map, std::string> mButtonMapping; + + protected slots: + + virtual void settingChanged (const CSMPrefs::Setting *setting); + private slots: void selectLightingMode (const std::string& mode); diff --git a/apps/opencs/view/render/worldspacewidget.cpp b/apps/opencs/view/render/worldspacewidget.cpp index df5790473..70aaf7e85 100644 --- a/apps/opencs/view/render/worldspacewidget.cpp +++ b/apps/opencs/view/render/worldspacewidget.cpp @@ -32,7 +32,7 @@ #include "instancemode.hpp" CSVRender::WorldspaceWidget::WorldspaceWidget (CSMDoc::Document& document, QWidget* parent) -: SceneWidget (document.getData().getResourceSystem(), parent), mSceneElements(0), mRun(0), mDocument(document), +: SceneWidget (document.getData().getResourceSystem(), parent, 0, false), mSceneElements(0), mRun(0), mDocument(document), mInteractionMask (0), mEditMode (0), mLocked (false), mDragging (false), mDragX(0), mDragY(0), mDragFactor(0), mDragWheelFactor(0), mDragShiftFactor(0), mToolTipPos (-1, -1), mShowToolTips(false), mToolTipDelay(0) @@ -67,13 +67,11 @@ CSVRender::WorldspaceWidget::WorldspaceWidget (CSMDoc::Document& document, QWidg connect (debugProfiles, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)), this, SLOT (debugProfileAboutToBeRemoved (const QModelIndex&, int, int))); - connect (&CSMPrefs::State::get(), SIGNAL (settingChanged (const CSMPrefs::Setting *)), - this, SLOT (settingChanged (const CSMPrefs::Setting *))); - CSMPrefs::get()["3D Scene Input"].update(); - CSMPrefs::get()["Tooltips"].update(); - mToolTipDelayTimer.setSingleShot (true); connect (&mToolTipDelayTimer, SIGNAL (timeout()), this, SLOT (showToolTip())); + + CSMPrefs::get()["3D Scene Input"].update(); + CSMPrefs::get()["Tooltips"].update(); } CSVRender::WorldspaceWidget::~WorldspaceWidget () @@ -82,9 +80,6 @@ CSVRender::WorldspaceWidget::~WorldspaceWidget () void CSVRender::WorldspaceWidget::settingChanged (const CSMPrefs::Setting *setting) { - if (storeMappingSetting (setting)) - return; - if (*setting=="3D Scene Input/drag-factor") mDragFactor = setting->toDouble(); else if (*setting=="3D Scene Input/drag-wheel-factor") @@ -95,6 +90,8 @@ void CSVRender::WorldspaceWidget::settingChanged (const CSMPrefs::Setting *setti mToolTipDelay = setting->toInt(); else if (*setting=="Tooltips/scene") mShowToolTips = setting->isTrue(); + else + SceneWidget::settingChanged(setting); } void CSVRender::WorldspaceWidget::selectNavigationMode (const std::string& mode) @@ -418,40 +415,41 @@ void CSVRender::WorldspaceWidget::dragMoveEvent(QDragMoveEvent *event) bool CSVRender::WorldspaceWidget::storeMappingSetting (const CSMPrefs::Setting *setting) { - if (setting->getParent()->getKey()!="3D Scene Input") - return false; - static const char * const sMappingSettings[] = { - "p-navi", "s-navi", "p-edit", "s-edit", "p-select", "s-select", 0 }; - for (int i=0; sMappingSettings[i]; ++i) - if (setting->getKey()==sMappingSettings[i]) + if (setting->getParent()->getKey()=="3D Scene Input") + { + for (int i=0; sMappingSettings[i]; ++i) { - QString value = QString::fromUtf8 (setting->toString().c_str()); + if (setting->getKey()==sMappingSettings[i]) + { + QString value = QString::fromUtf8 (setting->toString().c_str()); - Qt::MouseButton button = Qt::NoButton; + Qt::MouseButton button = Qt::NoButton; - if (value.endsWith ("Left Mouse-Button")) - button = Qt::LeftButton; - else if (value.endsWith ("Right Mouse-Button")) - button = Qt::RightButton; - else if (value.endsWith ("Middle Mouse-Button")) - button = Qt::MiddleButton; - else - return false; + if (value.endsWith ("Left Mouse-Button")) + button = Qt::LeftButton; + else if (value.endsWith ("Right Mouse-Button")) + button = Qt::RightButton; + else if (value.endsWith ("Middle Mouse-Button")) + button = Qt::MiddleButton; + else + return false; - bool ctrl = value.startsWith ("Ctrl-"); + bool ctrl = value.startsWith ("Ctrl-"); - mButtonMapping[std::make_pair (button, ctrl)] = sMappingSettings[i]; - return true; + mButtonMapping[std::make_pair (button, ctrl)] = sMappingSettings[i]; + return true; + } } + } - return false; + return SceneWidget::storeMappingSetting(setting); } osg::ref_ptr CSVRender::WorldspaceWidget::mousePick (const QPoint& localPos) @@ -496,20 +494,6 @@ osg::ref_ptr CSVRender::WorldspaceWidget::mousePick (const Q return osg::ref_ptr(); } -std::string CSVRender::WorldspaceWidget::mapButton (QMouseEvent *event) -{ - std::pair phyiscal ( - event->button(), event->modifiers() & Qt::ControlModifier); - - std::map, std::string>::const_iterator iter = - mButtonMapping.find (phyiscal); - - if (iter!=mButtonMapping.end()) - return iter->second; - - return ""; -} - void CSVRender::WorldspaceWidget::dropEvent (QDropEvent* event) { const CSMWorld::TableMimeData* mime = dynamic_cast (event->mimeData()); @@ -615,50 +599,7 @@ void CSVRender::WorldspaceWidget::updateOverlay() void CSVRender::WorldspaceWidget::mouseMoveEvent (QMouseEvent *event) { - if (!mDragging) - { - if (mDragMode.empty()) - { - if (event->globalPos()!=mToolTipPos) - { - mToolTipPos = event->globalPos(); - - if (mShowToolTips) - mToolTipDelayTimer.start (mToolTipDelay); - } - } - else if (mDragMode=="p-navi" || mDragMode=="s-navi") - { - - } - else if (mDragMode=="p-edit" || mDragMode=="s-edit" || mDragMode=="p-select" || mDragMode=="s-select") - { - osg::ref_ptr tag = mousePick (event->pos()); - - EditMode& editMode = dynamic_cast (*mEditMode->getCurrent()); - - if (mDragMode=="p-edit") - mDragging = editMode.primaryEditStartDrag (tag); - else if (mDragMode=="s-edit") - mDragging = editMode.secondaryEditStartDrag (tag); - else if (mDragMode=="p-select") - mDragging = editMode.primarySelectStartDrag (tag); - else if (mDragMode=="s-select") - mDragging = editMode.secondarySelectStartDrag (tag); - - if (mDragging) - { -#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) - mDragX = event->localPos().x(); - mDragY = height() - event->localPos().y(); -#else - mDragX = event->posF().x(); - mDragY = height() - event->posF().y(); -#endif - } - } - } - else + if (mDragging) { int diffX = event->x() - mDragX; int diffY = (height() - event->y()) - mDragY; @@ -675,59 +616,84 @@ void CSVRender::WorldspaceWidget::mouseMoveEvent (QMouseEvent *event) editMode.drag (diffX, diffY, factor); } + else if (mDragMode=="p-edit" || mDragMode=="s-edit" || mDragMode=="p-select" || mDragMode=="s-select") + { + osg::ref_ptr tag = mousePick (event->pos()); + + EditMode& editMode = dynamic_cast (*mEditMode->getCurrent()); + + if (mDragMode=="p-edit") + mDragging = editMode.primaryEditStartDrag (tag); + else if (mDragMode=="s-edit") + mDragging = editMode.secondaryEditStartDrag (tag); + else if (mDragMode=="p-select") + mDragging = editMode.primarySelectStartDrag (tag); + else if (mDragMode=="s-select") + mDragging = editMode.secondarySelectStartDrag (tag); + + if (mDragging) + { +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) + mDragX = event->localPos().x(); + mDragY = height() - event->localPos().y(); +#else + mDragX = event->posF().x(); + mDragY = height() - event->posF().y(); +#endif + } + } + else + { + if (event->globalPos()!=mToolTipPos) + { + mToolTipPos = event->globalPos(); + + if (mShowToolTips) + mToolTipDelayTimer.start (mToolTipDelay); + } + + SceneWidget::mouseMoveEvent(event); + } } void CSVRender::WorldspaceWidget::mousePressEvent (QMouseEvent *event) { std::string button = mapButton (event); - if (!mDragging) - mDragMode = button; + if (button=="p-edit" || button=="s-edit" || + button=="p-select" || button=="s-select") + { + if (!mDragging) + mDragMode = button; + } + else + SceneWidget::mousePressEvent(event); } void CSVRender::WorldspaceWidget::mouseReleaseEvent (QMouseEvent *event) { std::string button = mapButton (event); + mDragMode.clear(); - if (mDragging) + if (button=="p-edit" || button=="s-edit" || + button=="p-select" || button=="s-select") { - if (mDragMode=="p-navi" || mDragMode=="s-navi") - { - - } - else if (mDragMode=="p-edit" || mDragMode=="s-edit" || - mDragMode=="p-select" || mDragMode=="s-select") + if (mDragging) { EditMode& editMode = dynamic_cast (*mEditMode->getCurrent()); editMode.dragCompleted(); mDragging = false; } - } - else - { - if (button=="p-navi" || button=="s-navi") - { - - } - else if (button=="p-edit" || button=="s-edit" || - button=="p-select" || button=="s-select") + else { osg::ref_ptr tag = mousePick (event->pos()); handleMouseClick (tag, button, event->modifiers() & Qt::ShiftModifier); } } - - mDragMode.clear(); -} - -void CSVRender::WorldspaceWidget::mouseDoubleClickEvent (QMouseEvent *event) -{ - if(event->button() == Qt::RightButton) - { - //mMouse->mouseDoubleClickEvent(event); - } + else + SceneWidget::mouseReleaseEvent(event); } void CSVRender::WorldspaceWidget::wheelEvent (QWheelEvent *event) @@ -743,6 +709,8 @@ void CSVRender::WorldspaceWidget::wheelEvent (QWheelEvent *event) editMode.dragWheel (event->delta(), factor); } + else + SceneWidget::wheelEvent(event); } void CSVRender::WorldspaceWidget::keyPressEvent (QKeyEvent *event) diff --git a/apps/opencs/view/render/worldspacewidget.hpp b/apps/opencs/view/render/worldspacewidget.hpp index 4c9c0c31e..87f22581c 100644 --- a/apps/opencs/view/render/worldspacewidget.hpp +++ b/apps/opencs/view/render/worldspacewidget.hpp @@ -1,8 +1,6 @@ #ifndef OPENCS_VIEW_WORLDSPACEWIDGET_H #define OPENCS_VIEW_WORLDSPACEWIDGET_H -#include - #include #include @@ -45,7 +43,6 @@ namespace CSVRender CSVWidget::SceneToolRun *mRun; CSMDoc::Document& mDocument; unsigned int mInteractionMask; - std::map, std::string> mButtonMapping; CSVWidget::SceneToolMode *mEditMode; bool mLocked; std::string mDragMode; @@ -189,13 +186,17 @@ namespace CSVRender virtual void mouseMoveEvent (QMouseEvent *event); virtual void mousePressEvent (QMouseEvent *event); virtual void mouseReleaseEvent (QMouseEvent *event); - virtual void mouseDoubleClickEvent (QMouseEvent *event); virtual void wheelEvent (QWheelEvent *event); virtual void keyPressEvent (QKeyEvent *event); virtual void handleMouseClick (osg::ref_ptr tag, const std::string& button, bool shift); + /// \return Is \a key a button mapping setting? (ignored otherwise) + virtual bool storeMappingSetting (const CSMPrefs::Setting *setting); + + virtual void settingChanged (const CSMPrefs::Setting *setting); + EditMode *getEditMode(); private: @@ -206,19 +207,12 @@ namespace CSVRender void dragMoveEvent(QDragMoveEvent *event); - /// \return Is \a key a button mapping setting? (ignored otherwise) - bool storeMappingSetting (const CSMPrefs::Setting *setting); - osg::ref_ptr mousePick (const QPoint& localPos); - std::string mapButton (QMouseEvent *event); - virtual std::string getStartupInstruction() = 0; private slots: - void settingChanged (const CSMPrefs::Setting *setting); - void selectNavigationMode (const std::string& mode); virtual void referenceableDataChanged (const QModelIndex& topLeft,