1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-30 13:45:32 +00:00

Input restructuring.

This commit is contained in:
Aesylwinn 2016-03-10 04:29:24 -05:00
parent f4f7afb53b
commit 9afb0e0f90
4 changed files with 206 additions and 128 deletions

View file

@ -18,6 +18,8 @@
#include "../widget/scenetoolmode.hpp" #include "../widget/scenetoolmode.hpp"
#include "../../model/prefs/state.hpp"
#include "lighting.hpp" #include "lighting.hpp"
#include "mask.hpp" #include "mask.hpp"
@ -143,7 +145,8 @@ void CompositeViewer::update()
// --------------------------------------------------- // ---------------------------------------------------
SceneWidget::SceneWidget(boost::shared_ptr<Resource::ResourceSystem> resourceSystem, QWidget *parent, Qt::WindowFlags f) SceneWidget::SceneWidget(boost::shared_ptr<Resource::ResourceSystem> resourceSystem, QWidget *parent, Qt::WindowFlags f,
bool retrieveInput)
: RenderWidget(parent, f) : RenderWidget(parent, f)
, mResourceSystem(resourceSystem) , mResourceSystem(resourceSystem)
, mLighting(NULL) , mLighting(NULL)
@ -159,6 +162,16 @@ SceneWidget::SceneWidget(boost::shared_ptr<Resource::ResourceSystem> resourceSys
/// \todo make shortcut configurable /// \todo make shortcut configurable
QShortcut *focusToolbar = new QShortcut (Qt::Key_T, this, 0, 0, Qt::WidgetWithChildrenShortcut); QShortcut *focusToolbar = new QShortcut (Qt::Key_T, this, 0, 0, Qt::WidgetWithChildrenShortcut);
connect (focusToolbar, SIGNAL (activated()), this, SIGNAL (focusToolbarRequest())); 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() SceneWidget::~SceneWidget()
@ -238,4 +251,85 @@ void SceneWidget::setDefaultAmbient (const osg::Vec4f& colour)
setAmbient(mLighting->getAmbientColour(&mDefaultAmbient)); 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<Qt::MouseButton, bool> phyiscal (
event->button(), event->modifiers() & Qt::ControlModifier);
std::map<std::pair<Qt::MouseButton, bool>, std::string>::const_iterator iter =
mButtonMapping.find (phyiscal);
if (iter!=mButtonMapping.end())
return iter->second;
return "";
}
} }

View file

@ -1,6 +1,8 @@
#ifndef OPENCS_VIEW_SCENEWIDGET_H #ifndef OPENCS_VIEW_SCENEWIDGET_H
#define OPENCS_VIEW_SCENEWIDGET_H #define OPENCS_VIEW_SCENEWIDGET_H
#include <map>
#include <QWidget> #include <QWidget>
#include <QTimer> #include <QTimer>
@ -30,6 +32,11 @@ namespace CSVWidget
class SceneToolbar; class SceneToolbar;
} }
namespace CSMPrefs
{
class Setting;
}
namespace CSVRender namespace CSVRender
{ {
class Lighting; class Lighting;
@ -62,7 +69,8 @@ namespace CSVRender
{ {
Q_OBJECT Q_OBJECT
public: public:
SceneWidget(boost::shared_ptr<Resource::ResourceSystem> resourceSystem, QWidget* parent = 0, Qt::WindowFlags f = 0); SceneWidget(boost::shared_ptr<Resource::ResourceSystem> resourceSystem, QWidget* parent = 0,
Qt::WindowFlags f = 0, bool retrieveInput = true);
virtual ~SceneWidget(); virtual ~SceneWidget();
CSVWidget::SceneToolMode *makeLightingSelector (CSVWidget::SceneToolbar *parent); CSVWidget::SceneToolMode *makeLightingSelector (CSVWidget::SceneToolbar *parent);
@ -78,6 +86,14 @@ namespace CSVRender
void setAmbient(const osg::Vec4f& ambient); 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<Resource::ResourceSystem> mResourceSystem; boost::shared_ptr<Resource::ResourceSystem> mResourceSystem;
Lighting* mLighting; Lighting* mLighting;
@ -88,6 +104,12 @@ namespace CSVRender
LightingNight mLightingNight; LightingNight mLightingNight;
LightingBright mLightingBright; LightingBright mLightingBright;
std::map<std::pair<Qt::MouseButton, bool>, std::string> mButtonMapping;
protected slots:
virtual void settingChanged (const CSMPrefs::Setting *setting);
private slots: private slots:
void selectLightingMode (const std::string& mode); void selectLightingMode (const std::string& mode);

View file

@ -32,7 +32,7 @@
#include "instancemode.hpp" #include "instancemode.hpp"
CSVRender::WorldspaceWidget::WorldspaceWidget (CSMDoc::Document& document, QWidget* parent) 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), mInteractionMask (0), mEditMode (0), mLocked (false), mDragging (false), mDragX(0), mDragY(0), mDragFactor(0),
mDragWheelFactor(0), mDragShiftFactor(0), mDragWheelFactor(0), mDragShiftFactor(0),
mToolTipPos (-1, -1), mShowToolTips(false), mToolTipDelay(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)), connect (debugProfiles, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)),
this, SLOT (debugProfileAboutToBeRemoved (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); mToolTipDelayTimer.setSingleShot (true);
connect (&mToolTipDelayTimer, SIGNAL (timeout()), this, SLOT (showToolTip())); connect (&mToolTipDelayTimer, SIGNAL (timeout()), this, SLOT (showToolTip()));
CSMPrefs::get()["3D Scene Input"].update();
CSMPrefs::get()["Tooltips"].update();
} }
CSVRender::WorldspaceWidget::~WorldspaceWidget () CSVRender::WorldspaceWidget::~WorldspaceWidget ()
@ -82,9 +80,6 @@ CSVRender::WorldspaceWidget::~WorldspaceWidget ()
void CSVRender::WorldspaceWidget::settingChanged (const CSMPrefs::Setting *setting) void CSVRender::WorldspaceWidget::settingChanged (const CSMPrefs::Setting *setting)
{ {
if (storeMappingSetting (setting))
return;
if (*setting=="3D Scene Input/drag-factor") if (*setting=="3D Scene Input/drag-factor")
mDragFactor = setting->toDouble(); mDragFactor = setting->toDouble();
else if (*setting=="3D Scene Input/drag-wheel-factor") else if (*setting=="3D Scene Input/drag-wheel-factor")
@ -95,6 +90,8 @@ void CSVRender::WorldspaceWidget::settingChanged (const CSMPrefs::Setting *setti
mToolTipDelay = setting->toInt(); mToolTipDelay = setting->toInt();
else if (*setting=="Tooltips/scene") else if (*setting=="Tooltips/scene")
mShowToolTips = setting->isTrue(); mShowToolTips = setting->isTrue();
else
SceneWidget::settingChanged(setting);
} }
void CSVRender::WorldspaceWidget::selectNavigationMode (const std::string& mode) 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) bool CSVRender::WorldspaceWidget::storeMappingSetting (const CSMPrefs::Setting *setting)
{ {
if (setting->getParent()->getKey()!="3D Scene Input")
return false;
static const char * const sMappingSettings[] = static const char * const sMappingSettings[] =
{ {
"p-navi", "s-navi",
"p-edit", "s-edit", "p-edit", "s-edit",
"p-select", "s-select", "p-select", "s-select",
0 0
}; };
for (int i=0; sMappingSettings[i]; ++i) if (setting->getParent()->getKey()=="3D Scene Input")
if (setting->getKey()==sMappingSettings[i]) {
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")) if (value.endsWith ("Left Mouse-Button"))
button = Qt::LeftButton; button = Qt::LeftButton;
else if (value.endsWith ("Right Mouse-Button")) else if (value.endsWith ("Right Mouse-Button"))
button = Qt::RightButton; button = Qt::RightButton;
else if (value.endsWith ("Middle Mouse-Button")) else if (value.endsWith ("Middle Mouse-Button"))
button = Qt::MiddleButton; button = Qt::MiddleButton;
else else
return false; return false;
bool ctrl = value.startsWith ("Ctrl-"); bool ctrl = value.startsWith ("Ctrl-");
mButtonMapping[std::make_pair (button, ctrl)] = sMappingSettings[i]; mButtonMapping[std::make_pair (button, ctrl)] = sMappingSettings[i];
return true; return true;
}
} }
}
return false; return SceneWidget::storeMappingSetting(setting);
} }
osg::ref_ptr<CSVRender::TagBase> CSVRender::WorldspaceWidget::mousePick (const QPoint& localPos) osg::ref_ptr<CSVRender::TagBase> CSVRender::WorldspaceWidget::mousePick (const QPoint& localPos)
@ -496,20 +494,6 @@ osg::ref_ptr<CSVRender::TagBase> CSVRender::WorldspaceWidget::mousePick (const Q
return osg::ref_ptr<CSVRender::TagBase>(); return osg::ref_ptr<CSVRender::TagBase>();
} }
std::string CSVRender::WorldspaceWidget::mapButton (QMouseEvent *event)
{
std::pair<Qt::MouseButton, bool> phyiscal (
event->button(), event->modifiers() & Qt::ControlModifier);
std::map<std::pair<Qt::MouseButton, bool>, std::string>::const_iterator iter =
mButtonMapping.find (phyiscal);
if (iter!=mButtonMapping.end())
return iter->second;
return "";
}
void CSVRender::WorldspaceWidget::dropEvent (QDropEvent* event) void CSVRender::WorldspaceWidget::dropEvent (QDropEvent* event)
{ {
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData()); const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());
@ -615,50 +599,7 @@ void CSVRender::WorldspaceWidget::updateOverlay()
void CSVRender::WorldspaceWidget::mouseMoveEvent (QMouseEvent *event) void CSVRender::WorldspaceWidget::mouseMoveEvent (QMouseEvent *event)
{ {
if (!mDragging) 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<TagBase> tag = mousePick (event->pos());
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=="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
{ {
int diffX = event->x() - mDragX; int diffX = event->x() - mDragX;
int diffY = (height() - event->y()) - mDragY; int diffY = (height() - event->y()) - mDragY;
@ -675,59 +616,84 @@ void CSVRender::WorldspaceWidget::mouseMoveEvent (QMouseEvent *event)
editMode.drag (diffX, diffY, factor); editMode.drag (diffX, diffY, factor);
} }
else if (mDragMode=="p-edit" || mDragMode=="s-edit" || mDragMode=="p-select" || mDragMode=="s-select")
{
osg::ref_ptr<TagBase> tag = mousePick (event->pos());
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=="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) void CSVRender::WorldspaceWidget::mousePressEvent (QMouseEvent *event)
{ {
std::string button = mapButton (event); std::string button = mapButton (event);
if (!mDragging) if (button=="p-edit" || button=="s-edit" ||
mDragMode = button; button=="p-select" || button=="s-select")
{
if (!mDragging)
mDragMode = button;
}
else
SceneWidget::mousePressEvent(event);
} }
void CSVRender::WorldspaceWidget::mouseReleaseEvent (QMouseEvent *event) void CSVRender::WorldspaceWidget::mouseReleaseEvent (QMouseEvent *event)
{ {
std::string button = mapButton (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") if (mDragging)
{
}
else if (mDragMode=="p-edit" || mDragMode=="s-edit" ||
mDragMode=="p-select" || mDragMode=="s-select")
{ {
EditMode& editMode = dynamic_cast<CSVRender::EditMode&> (*mEditMode->getCurrent()); EditMode& editMode = dynamic_cast<CSVRender::EditMode&> (*mEditMode->getCurrent());
editMode.dragCompleted(); editMode.dragCompleted();
mDragging = false; mDragging = false;
} }
} else
else
{
if (button=="p-navi" || button=="s-navi")
{
}
else if (button=="p-edit" || button=="s-edit" ||
button=="p-select" || button=="s-select")
{ {
osg::ref_ptr<TagBase> tag = mousePick (event->pos()); osg::ref_ptr<TagBase> tag = mousePick (event->pos());
handleMouseClick (tag, button, event->modifiers() & Qt::ShiftModifier); handleMouseClick (tag, button, event->modifiers() & Qt::ShiftModifier);
} }
} }
else
mDragMode.clear(); SceneWidget::mouseReleaseEvent(event);
}
void CSVRender::WorldspaceWidget::mouseDoubleClickEvent (QMouseEvent *event)
{
if(event->button() == Qt::RightButton)
{
//mMouse->mouseDoubleClickEvent(event);
}
} }
void CSVRender::WorldspaceWidget::wheelEvent (QWheelEvent *event) void CSVRender::WorldspaceWidget::wheelEvent (QWheelEvent *event)
@ -743,6 +709,8 @@ void CSVRender::WorldspaceWidget::wheelEvent (QWheelEvent *event)
editMode.dragWheel (event->delta(), factor); editMode.dragWheel (event->delta(), factor);
} }
else
SceneWidget::wheelEvent(event);
} }
void CSVRender::WorldspaceWidget::keyPressEvent (QKeyEvent *event) void CSVRender::WorldspaceWidget::keyPressEvent (QKeyEvent *event)

View file

@ -1,8 +1,6 @@
#ifndef OPENCS_VIEW_WORLDSPACEWIDGET_H #ifndef OPENCS_VIEW_WORLDSPACEWIDGET_H
#define OPENCS_VIEW_WORLDSPACEWIDGET_H #define OPENCS_VIEW_WORLDSPACEWIDGET_H
#include <map>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <QTimer> #include <QTimer>
@ -45,7 +43,6 @@ namespace CSVRender
CSVWidget::SceneToolRun *mRun; CSVWidget::SceneToolRun *mRun;
CSMDoc::Document& mDocument; CSMDoc::Document& mDocument;
unsigned int mInteractionMask; unsigned int mInteractionMask;
std::map<std::pair<Qt::MouseButton, bool>, std::string> mButtonMapping;
CSVWidget::SceneToolMode *mEditMode; CSVWidget::SceneToolMode *mEditMode;
bool mLocked; bool mLocked;
std::string mDragMode; std::string mDragMode;
@ -189,13 +186,17 @@ namespace CSVRender
virtual void mouseMoveEvent (QMouseEvent *event); virtual void mouseMoveEvent (QMouseEvent *event);
virtual void mousePressEvent (QMouseEvent *event); virtual void mousePressEvent (QMouseEvent *event);
virtual void mouseReleaseEvent (QMouseEvent *event); virtual void mouseReleaseEvent (QMouseEvent *event);
virtual void mouseDoubleClickEvent (QMouseEvent *event);
virtual void wheelEvent (QWheelEvent *event); virtual void wheelEvent (QWheelEvent *event);
virtual void keyPressEvent (QKeyEvent *event); virtual void keyPressEvent (QKeyEvent *event);
virtual void handleMouseClick (osg::ref_ptr<TagBase> tag, const std::string& button, virtual void handleMouseClick (osg::ref_ptr<TagBase> tag, const std::string& button,
bool shift); 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(); EditMode *getEditMode();
private: private:
@ -206,19 +207,12 @@ namespace CSVRender
void dragMoveEvent(QDragMoveEvent *event); void dragMoveEvent(QDragMoveEvent *event);
/// \return Is \a key a button mapping setting? (ignored otherwise)
bool storeMappingSetting (const CSMPrefs::Setting *setting);
osg::ref_ptr<TagBase> mousePick (const QPoint& localPos); osg::ref_ptr<TagBase> mousePick (const QPoint& localPos);
std::string mapButton (QMouseEvent *event);
virtual std::string getStartupInstruction() = 0; virtual std::string getStartupInstruction() = 0;
private slots: private slots:
void settingChanged (const CSMPrefs::Setting *setting);
void selectNavigationMode (const std::string& mode); void selectNavigationMode (const std::string& mode);
virtual void referenceableDataChanged (const QModelIndex& topLeft, virtual void referenceableDataChanged (const QModelIndex& topLeft,