diff --git a/apps/opencs/model/settings/usersettings.cpp b/apps/opencs/model/settings/usersettings.cpp
index e8568cac1..8bf24ae34 100644
--- a/apps/opencs/model/settings/usersettings.cpp
+++ b/apps/opencs/model/settings/usersettings.cpp
@@ -426,6 +426,20 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
dragShiftFactor->setRange (0.001, 100.0);
}
+ declareSection ("tooltips", "Tooltips");
+ {
+ Setting *scene = createSetting (Type_CheckBox, "scene", "Show Tooltips in 3D scenes");
+ scene->setDefaultValue ("true");
+
+ Setting *sceneHideBasic = createSetting (Type_CheckBox, "scene-hide-basic", "Hide basic 3D scenes tooltips");
+ sceneHideBasic->setDefaultValue ("false");
+
+ Setting *sceneDelay = createSetting (Type_SpinBox, "scene-delay",
+ "Tooltip delay in milliseconds");
+ sceneDelay->setDefaultValue (500);
+ sceneDelay->setRange (1, 10000);
+ }
+
{
/******************************************************************
* There are three types of values:
diff --git a/apps/opencs/view/render/cellarrow.cpp b/apps/opencs/view/render/cellarrow.cpp
index fce5ffda5..1356aa0fb 100644
--- a/apps/opencs/view/render/cellarrow.cpp
+++ b/apps/opencs/view/render/cellarrow.cpp
@@ -18,6 +18,33 @@ CSVRender::CellArrow *CSVRender::CellArrowTag::getCellArrow() const
return mArrow;
}
+QString CSVRender::CellArrowTag::getToolTip (bool hideBasics) const
+{
+ QString text ("Direction: ");
+
+ switch (mArrow->getDirection())
+ {
+ case CellArrow::Direction_North: text += "North"; break;
+ case CellArrow::Direction_West: text += "West"; break;
+ case CellArrow::Direction_South: text += "South"; break;
+ case CellArrow::Direction_East: text += "East"; break;
+ }
+
+ if (!hideBasics)
+ {
+ text +=
+ "
"
+ "Modify which cells are shown"
+ "
- Primary-Edit: Add cell in given direction
"
+ "- Secondary-Edit: Add cell and remove old cell
"
+ "- Shift Primary-Edit: Add cells in given direction
"
+ "- Shift Secondary-Edit: Add cells and remove old cells
"
+ "
";
+ }
+
+ return text;
+}
+
void CSVRender::CellArrow::adjustTransform()
{
diff --git a/apps/opencs/view/render/cellarrow.hpp b/apps/opencs/view/render/cellarrow.hpp
index cbbcc9d5e..452356194 100644
--- a/apps/opencs/view/render/cellarrow.hpp
+++ b/apps/opencs/view/render/cellarrow.hpp
@@ -26,6 +26,8 @@ namespace CSVRender
CellArrowTag (CellArrow *arrow);
CellArrow *getCellArrow() const;
+
+ virtual QString getToolTip (bool hideBasics) const;
};
diff --git a/apps/opencs/view/render/object.cpp b/apps/opencs/view/render/object.cpp
index ac96cb283..c295a023a 100644
--- a/apps/opencs/view/render/object.cpp
+++ b/apps/opencs/view/render/object.cpp
@@ -42,6 +42,11 @@ CSVRender::ObjectTag::ObjectTag (Object* object)
: TagBase (Element_Reference), mObject (object)
{}
+QString CSVRender::ObjectTag::getToolTip (bool hideBasics) const
+{
+ return QString::fromUtf8 (mObject->getReferenceableId().c_str());
+}
+
void CSVRender::Object::clear()
{
diff --git a/apps/opencs/view/render/object.hpp b/apps/opencs/view/render/object.hpp
index 0858a2edb..e7638e7a9 100644
--- a/apps/opencs/view/render/object.hpp
+++ b/apps/opencs/view/render/object.hpp
@@ -46,6 +46,8 @@ namespace CSVRender
ObjectTag (Object* object);
Object* mObject;
+
+ virtual QString getToolTip (bool hideBasics) const;
};
diff --git a/apps/opencs/view/render/tagbase.cpp b/apps/opencs/view/render/tagbase.cpp
index af9a37624..79412c132 100644
--- a/apps/opencs/view/render/tagbase.cpp
+++ b/apps/opencs/view/render/tagbase.cpp
@@ -7,3 +7,8 @@ CSVRender::Elements CSVRender::TagBase::getElement() const
{
return mElement;
}
+
+QString CSVRender::TagBase::getToolTip (bool hideBasics) const
+{
+ return "";
+}
diff --git a/apps/opencs/view/render/tagbase.hpp b/apps/opencs/view/render/tagbase.hpp
index 874b856c6..9f169c3b1 100644
--- a/apps/opencs/view/render/tagbase.hpp
+++ b/apps/opencs/view/render/tagbase.hpp
@@ -3,6 +3,8 @@
#include
+#include
+
#include "elements.hpp"
namespace CSVRender
@@ -16,6 +18,9 @@ namespace CSVRender
TagBase (Elements element);
Elements getElement() const;
+
+ virtual QString getToolTip (bool hideBasics) const;
+
};
}
diff --git a/apps/opencs/view/render/worldspacewidget.cpp b/apps/opencs/view/render/worldspacewidget.cpp
index e76582b94..0deb49840 100644
--- a/apps/opencs/view/render/worldspacewidget.cpp
+++ b/apps/opencs/view/render/worldspacewidget.cpp
@@ -10,6 +10,7 @@
#include
#include
#include
+#include
#include
#include
@@ -43,7 +44,8 @@ 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), mDragging (false)
+ mInteractionMask (0), mEditMode (0), mLocked (false), mDragging (false),
+ mToolTipPos (-1, -1)
{
setAcceptDrops(true);
@@ -85,6 +87,12 @@ CSVRender::WorldspaceWidget::WorldspaceWidget (CSMDoc::Document& document, QWidg
mDragFactor = CSMSettings::UserSettings::instance().settingValue ("scene-input/drag-factor").toDouble();
mDragWheelFactor = CSMSettings::UserSettings::instance().settingValue ("scene-input/drag-wheel-factor").toDouble();
mDragShiftFactor = CSMSettings::UserSettings::instance().settingValue ("scene-input/drag-shift-factor").toDouble();
+
+ mShowToolTips = CSMSettings::UserSettings::instance().settingValue ("tooltips/scene") == "true";
+ mToolTipDelay = CSMSettings::UserSettings::instance().settingValue ("tooltips/scene-delay").toInt();
+
+ mToolTipDelayTimer.setSingleShot (true);
+ connect (&mToolTipDelayTimer, SIGNAL (timeout()), this, SLOT (showToolTip()));
}
CSVRender::WorldspaceWidget::~WorldspaceWidget ()
@@ -294,6 +302,10 @@ void CSVRender::WorldspaceWidget::updateUserSetting (const QString& name, const
mDragWheelFactor = value.at (0).toDouble();
else if (name=="scene-input/drag-shift-factor")
mDragShiftFactor = value.at (0).toDouble();
+ else if (name=="tooltips/scene-delay")
+ mToolTipDelay = value.at (0).toInt();
+ else if (name=="tooltips/scene")
+ mShowToolTips = value.at (0)=="true";
else
dynamic_cast (*mEditMode->getCurrent()).updateUserSetting (name, value);
}
@@ -368,11 +380,11 @@ bool CSVRender::WorldspaceWidget::storeMappingSetting (const QString& key, const
return false;
}
-osg::ref_ptr CSVRender::WorldspaceWidget::mousePick (QMouseEvent *event)
+osg::ref_ptr CSVRender::WorldspaceWidget::mousePick (const QPoint& localPos)
{
// (0,0) is considered the lower left corner of an OpenGL window
- int x = event->x();
- int y = height() - event->y();
+ int x = localPos.x();
+ int y = height() - localPos.y();
osg::ref_ptr intersector (new osgUtil::LineSegmentIntersector(osgUtil::Intersector::WINDOW, x, y));
@@ -494,6 +506,21 @@ void CSVRender::WorldspaceWidget::editModeChanged (const std::string& id)
mDragging = false;
}
+void CSVRender::WorldspaceWidget::showToolTip()
+{
+ if (mShowToolTips)
+ {
+ QPoint pos = QCursor::pos();
+
+ if (osg::ref_ptr tag = mousePick (mapFromGlobal (pos)))
+ {
+ bool hideBasics =
+ CSMSettings::UserSettings::instance().settingValue ("tooltips/scene-hide-basic")=="true";
+ QToolTip::showText (pos, tag->getToolTip (hideBasics), this);
+ }
+ }
+}
+
void CSVRender::WorldspaceWidget::elementSelectionChanged()
{
setVisibilityMask (getVisibilityMask());
@@ -509,13 +536,23 @@ void CSVRender::WorldspaceWidget::mouseMoveEvent (QMouseEvent *event)
{
if (!mDragging)
{
- if (mDragMode=="p-navi" || mDragMode=="s-navi")
+ 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);
+ osg::ref_ptr tag = mousePick (event->pos());
EditMode& editMode = dynamic_cast (*mEditMode->getCurrent());
@@ -595,7 +632,7 @@ void CSVRender::WorldspaceWidget::mouseReleaseEvent (QMouseEvent *event)
else if (button=="p-edit" || button=="s-edit" ||
button=="p-select" || button=="s-select")
{
- osg::ref_ptr tag = mousePick (event);
+ osg::ref_ptr tag = mousePick (event->pos());
handleMouseClick (tag, button, event->modifiers() & Qt::ShiftModifier);
}
diff --git a/apps/opencs/view/render/worldspacewidget.hpp b/apps/opencs/view/render/worldspacewidget.hpp
index c2d61e75b..0b5ae2523 100644
--- a/apps/opencs/view/render/worldspacewidget.hpp
+++ b/apps/opencs/view/render/worldspacewidget.hpp
@@ -5,6 +5,8 @@
#include
+#include
+
#include "../../model/doc/document.hpp"
#include "../../model/world/tablemimedata.hpp"
@@ -47,6 +49,10 @@ namespace CSVRender
double mDragFactor;
double mDragWheelFactor;
double mDragShiftFactor;
+ QTimer mToolTipDelayTimer;
+ QPoint mToolTipPos;
+ bool mShowToolTips;
+ int mToolTipDelay;
public:
@@ -147,7 +153,7 @@ namespace CSVRender
/// \return Is \a key a button mapping setting? (ignored otherwise)
bool storeMappingSetting (const QString& key, const QString& value);
- osg::ref_ptr mousePick (QMouseEvent *event);
+ osg::ref_ptr mousePick (const QPoint& localPos);
std::string mapButton (QMouseEvent *event);
@@ -179,6 +185,8 @@ namespace CSVRender
void editModeChanged (const std::string& id);
+ void showToolTip();
+
protected slots:
void elementSelectionChanged();