mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-11-04 00:26:39 +00:00 
			
		
		
		
	Merge branch 'tooltip'
This commit is contained in:
		
						commit
						b0d79ee790
					
				
					 9 changed files with 113 additions and 8 deletions
				
			
		| 
						 | 
				
			
			@ -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:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 +=
 | 
			
		||||
            "<p>"
 | 
			
		||||
            "Modify which cells are shown"
 | 
			
		||||
            "<ul><li>Primary-Edit: Add cell in given direction</li>"
 | 
			
		||||
            "<li>Secondary-Edit: Add cell and remove old cell</li>"
 | 
			
		||||
            "<li>Shift Primary-Edit: Add cells in given direction</li>"
 | 
			
		||||
            "<li>Shift Secondary-Edit: Add cells and remove old cells</li>"
 | 
			
		||||
            "</ul>";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return text;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void CSVRender::CellArrow::adjustTransform()
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,6 +26,8 @@ namespace CSVRender
 | 
			
		|||
            CellArrowTag (CellArrow *arrow);
 | 
			
		||||
 | 
			
		||||
            CellArrow *getCellArrow() const;
 | 
			
		||||
 | 
			
		||||
            virtual QString getToolTip (bool hideBasics) const;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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()
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -46,6 +46,8 @@ namespace CSVRender
 | 
			
		|||
            ObjectTag (Object* object);
 | 
			
		||||
 | 
			
		||||
            Object* mObject;
 | 
			
		||||
 | 
			
		||||
            virtual QString getToolTip (bool hideBasics) const;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,3 +7,8 @@ CSVRender::Elements CSVRender::TagBase::getElement() const
 | 
			
		|||
{
 | 
			
		||||
    return mElement;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString CSVRender::TagBase::getToolTip (bool hideBasics) const
 | 
			
		||||
{
 | 
			
		||||
    return "";
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,6 +3,8 @@
 | 
			
		|||
 | 
			
		||||
#include <osg/Referenced>
 | 
			
		||||
 | 
			
		||||
#include <QString>
 | 
			
		||||
 | 
			
		||||
#include "elements.hpp"
 | 
			
		||||
 | 
			
		||||
namespace CSVRender
 | 
			
		||||
| 
						 | 
				
			
			@ -16,6 +18,9 @@ namespace CSVRender
 | 
			
		|||
            TagBase (Elements element);
 | 
			
		||||
 | 
			
		||||
            Elements getElement() const;
 | 
			
		||||
 | 
			
		||||
            virtual QString getToolTip (bool hideBasics) const;
 | 
			
		||||
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,6 +10,7 @@
 | 
			
		|||
#include <QMouseEvent>
 | 
			
		||||
#include <QKeyEvent>
 | 
			
		||||
#include <QApplication>
 | 
			
		||||
#include <QToolTip>
 | 
			
		||||
 | 
			
		||||
#include <osgGA/TrackballManipulator>
 | 
			
		||||
#include <osgGA/FirstPersonManipulator>
 | 
			
		||||
| 
						 | 
				
			
			@ -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<CSVRender::EditMode&> (*mEditMode->getCurrent()).updateUserSetting (name, value);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -368,11 +380,11 @@ bool CSVRender::WorldspaceWidget::storeMappingSetting (const QString& key, const
 | 
			
		|||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
osg::ref_ptr<CSVRender::TagBase> CSVRender::WorldspaceWidget::mousePick (QMouseEvent *event)
 | 
			
		||||
osg::ref_ptr<CSVRender::TagBase> 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<osgUtil::LineSegmentIntersector> 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<TagBase> 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<TagBase> tag = mousePick (event);
 | 
			
		||||
            osg::ref_ptr<TagBase> tag = mousePick (event->pos());
 | 
			
		||||
 | 
			
		||||
            EditMode& editMode = dynamic_cast<CSVRender::EditMode&> (*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<TagBase> tag = mousePick (event);
 | 
			
		||||
            osg::ref_ptr<TagBase> tag = mousePick (event->pos());
 | 
			
		||||
 | 
			
		||||
            handleMouseClick (tag, button, event->modifiers() & Qt::ShiftModifier);
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,6 +5,8 @@
 | 
			
		|||
 | 
			
		||||
#include <boost/shared_ptr.hpp>
 | 
			
		||||
 | 
			
		||||
#include <QTimer>
 | 
			
		||||
 | 
			
		||||
#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<TagBase> mousePick (QMouseEvent *event);
 | 
			
		||||
            osg::ref_ptr<TagBase> 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();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue