1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 21:23:52 +00:00

added run button to scene subview toolbar

This commit is contained in:
Marc Zinnschlag 2014-09-06 16:11:06 +02:00
parent 64cf0870c6
commit 51128d2d57
14 changed files with 182 additions and 7 deletions

View file

@ -69,7 +69,7 @@ opencs_units_noqt (view/world
)
opencs_units (view/widget
scenetoolbar scenetool scenetoolmode pushbutton scenetooltoggle
scenetoolbar scenetool scenetoolmode pushbutton scenetooltoggle scenetoolrun
)
opencs_units (view/render

View file

@ -133,6 +133,20 @@ void CSVRender::PagedWorldspaceWidget::referenceAdded (const QModelIndex& parent
flagAsModified();
}
std::string CSVRender::PagedWorldspaceWidget::getStartupInstruction()
{
Ogre::Vector3 position = getCamera()->getPosition();
std::ostringstream stream;
stream
<< "player->position "
<< position.x << ", " << position.y << ", " << position.z
<< ", 0";
return stream.str();
}
CSVRender::PagedWorldspaceWidget::PagedWorldspaceWidget (QWidget* parent, CSMDoc::Document& document)
: WorldspaceWidget (document, parent), mDocument (document), mWorldspace ("std::default")
{

View file

@ -42,6 +42,8 @@ namespace CSVRender
virtual void referenceAdded (const QModelIndex& index, int start, int end);
virtual std::string getStartupInstruction();
public:
PagedWorldspaceWidget (QWidget *parent, CSMDoc::Document& document);

View file

@ -1,7 +1,10 @@
#include "unpagedworldspacewidget.hpp"
#include <sstream>
#include <OgreColourValue.h>
#include <OgreCamera.h>
#include <QtGui/qevent.h>
@ -149,6 +152,20 @@ void CSVRender::UnpagedWorldspaceWidget::referenceAdded (const QModelIndex& pare
flagAsModified();
}
std::string CSVRender::UnpagedWorldspaceWidget::getStartupInstruction()
{
Ogre::Vector3 position = getCamera()->getPosition();
std::ostringstream stream;
stream
<< "player->positionCell "
<< position.x << ", " << position.y << ", " << position.z
<< ", 0, \"" << mCellId << "\"";
return stream.str();
}
CSVRender::WorldspaceWidget::dropRequirments CSVRender::UnpagedWorldspaceWidget::getDropRequirements (CSVRender::WorldspaceWidget::dropType type) const
{
switch(type)

View file

@ -60,6 +60,8 @@ namespace CSVRender
virtual void referenceAdded (const QModelIndex& index, int start, int end);
virtual std::string getStartupInstruction();
private slots:
void cellDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight);

View file

@ -1,6 +1,8 @@
#include "worldspacewidget.hpp"
#include <algorithm>
#include <OgreSceneNode.h>
#include <OgreSceneManager.h>
#include <OgreEntity.h>
@ -8,14 +10,16 @@
#include <QtGui/qevent.h>
#include "../../model/world/universalid.hpp"
#include "../../model/world/idtable.hpp"
#include "../widget/scenetoolmode.hpp"
#include "../widget/scenetooltoggle.hpp"
#include "../widget/scenetoolrun.hpp"
#include "elements.hpp"
CSVRender::WorldspaceWidget::WorldspaceWidget (CSMDoc::Document& document, QWidget* parent)
: SceneWidget (parent), mDocument(document)
: SceneWidget (parent), mDocument(document), mRun (0)
{
setAcceptDrops(true);
@ -112,6 +116,44 @@ CSVWidget::SceneToolToggle *CSVRender::WorldspaceWidget::makeSceneVisibilitySele
return mSceneElements;
}
CSVWidget::SceneToolRun *CSVRender::WorldspaceWidget::makeRunTool (
CSVWidget::SceneToolbar *parent)
{
CSMWorld::IdTable& debugProfiles = dynamic_cast<CSMWorld::IdTable&> (
*mDocument.getData().getTableModel (CSMWorld::UniversalId::Type_DebugProfiles));
std::vector<std::string> profiles;
int idColumn = debugProfiles.findColumnIndex (CSMWorld::Columns::ColumnId_Id);
int stateColumn = debugProfiles.findColumnIndex (CSMWorld::Columns::ColumnId_Modification);
int defaultColumn = debugProfiles.findColumnIndex (
CSMWorld::Columns::ColumnId_DefaultProfile);
int size = debugProfiles.rowCount();
for (int i=0; i<size; ++i)
{
int state = debugProfiles.data (debugProfiles.index (i, stateColumn)).toInt();
bool default_ = debugProfiles.data (debugProfiles.index (i, defaultColumn)).toInt();
if (state!=CSMWorld::RecordBase::State_Deleted && default_)
profiles.push_back (
debugProfiles.data (debugProfiles.index (i, idColumn)).
toString().toUtf8().constData());
}
std::sort (profiles.begin(), profiles.end());
mRun = new CSVWidget::SceneToolRun (parent, "Run OpenMW from the current camera position",
":door.png", ":faction.png", profiles);
connect (mRun, SIGNAL (runRequest (const std::string&)),
this, SLOT (runRequest (const std::string&)));
return mRun;
}
CSVRender::WorldspaceWidget::dropType CSVRender::WorldspaceWidget::getDropType (
const std::vector< CSMWorld::UniversalId >& data)
{
@ -201,6 +243,11 @@ void CSVRender::WorldspaceWidget::dropEvent (QDropEvent* event)
} //not handling drops from different documents at the moment
}
void CSVRender::WorldspaceWidget::runRequest (const std::string& profile)
{
mDocument.startRunning (profile, getStartupInstruction());
}
void CSVRender::WorldspaceWidget::elementSelectionChanged()
{
setVisibilityMask (getElementMask());

View file

@ -18,6 +18,7 @@ namespace CSVWidget
class SceneToolMode;
class SceneToolToggle;
class SceneToolbar;
class SceneToolRun;
}
namespace CSVRender
@ -30,6 +31,8 @@ namespace CSVRender
CSVRender::NavigationFree mFree;
CSVRender::NavigationOrbit mOrbit;
CSVWidget::SceneToolToggle *mSceneElements;
CSVWidget::SceneToolRun *mRun;
CSMDoc::Document& mDocument;
public:
@ -60,6 +63,10 @@ namespace CSVRender
CSVWidget::SceneToolToggle *makeSceneVisibilitySelector (
CSVWidget::SceneToolbar *parent);
/// \attention The created tool is not added to the toolbar (via addTool). Doing
/// that is the responsibility of the calling function.
CSVWidget::SceneToolRun *makeRunTool (CSVWidget::SceneToolbar *parent);
void selectDefaultNavigationMode();
static dropType getDropType(const std::vector<CSMWorld::UniversalId>& data);
@ -77,8 +84,6 @@ namespace CSVRender
virtual void addVisibilitySelectorButtons (CSVWidget::SceneToolToggle *tool);
const CSMDoc::Document& mDocument;
private:
void dragEnterEvent(QDragEnterEvent *event);
@ -87,6 +92,8 @@ namespace CSVRender
void dragMoveEvent(QDragMoveEvent *event);
virtual std::string getStartupInstruction() = 0;
private slots:
void selectNavigationMode (const std::string& mode);
@ -104,6 +111,8 @@ namespace CSVRender
virtual void referenceAdded (const QModelIndex& index, int start, int end) = 0;
virtual void runRequest (const std::string& profile);
protected slots:
void elementSelectionChanged();

View file

@ -20,6 +20,10 @@ void CSVWidget::PushButton::setExtendedToolTip()
break;
case Type_TopAction:
break;
case Type_Mode:
tooltip +=

View file

@ -14,6 +14,7 @@ namespace CSVWidget
enum Type
{
Type_TopMode, // top level button for mode selector panel
Type_TopAction, // top level button that triggers an action
Type_Mode, // mode button
Type_Toggle
};

View file

@ -3,8 +3,8 @@
#include "scenetoolbar.hpp"
CSVWidget::SceneTool::SceneTool (SceneToolbar *parent)
: PushButton (PushButton::Type_TopMode, "", parent)
CSVWidget::SceneTool::SceneTool (SceneToolbar *parent, Type type)
: PushButton (type, "", parent)
{
setSizePolicy (QSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed));
setIconSize (QSize (parent->getIconSize(), parent->getIconSize()));

View file

@ -14,7 +14,7 @@ namespace CSVWidget
public:
SceneTool (SceneToolbar *parent);
SceneTool (SceneToolbar *parent, Type type = Type_TopMode);
virtual void showPanel (const QPoint& position) = 0;

View file

@ -0,0 +1,35 @@
#include "scenetoolrun.hpp"
void CSVWidget::SceneToolRun::adjustToolTips()
{
QString toolTip = mToolTip;
if (mCurrentIndex==-1)
toolTip += "<p>No debug profile selected (function disabled)";
else
toolTip += "<p>Debug profile: " + QString::fromUtf8 (mProfiles[mCurrentIndex].c_str());
setToolTip (toolTip);
}
void CSVWidget::SceneToolRun::updateIcon()
{
setIcon (QIcon (mCurrentIndex==-1 ? mIconDisabled : mIcon));
}
CSVWidget::SceneToolRun::SceneToolRun (SceneToolbar *parent, const QString& toolTip,
const QString& icon, const QString& iconDisabled, const std::vector<std::string>& profiles)
: SceneTool (parent, Type_TopAction), mProfiles (profiles),
mCurrentIndex (profiles.empty() ? -1 : 0), mToolTip (toolTip), mIcon (icon),
mIconDisabled (iconDisabled)
{
updateIcon();
adjustToolTips();
}
void CSVWidget::SceneToolRun::showPanel (const QPoint& position)
{
if (mCurrentIndex!=-1)
emit runRequest (mProfiles[mCurrentIndex]);
}

View file

@ -0,0 +1,40 @@
#ifndef CSV_WIDGET_SCENETOOLRUN_H
#define CSV_WIDGET_SCENETOOLRUN_H
#include <vector>
#include <string>
#include "scenetool.hpp"
namespace CSVWidget
{
class SceneToolRun : public SceneTool
{
Q_OBJECT
std::vector<std::string> mProfiles;
int mCurrentIndex;
QString mToolTip;
QString mIcon;
QString mIconDisabled;
private:
void adjustToolTips();
void updateIcon();
public:
SceneToolRun (SceneToolbar *parent, const QString& toolTip, const QString& icon,
const QString& iconDisabled, const std::vector<std::string>& profiles);
virtual void showPanel (const QPoint& position);
signals:
void runRequest (const std::string& profile);
};
}
#endif

View file

@ -20,6 +20,7 @@
#include "../widget/scenetoolbar.hpp"
#include "../widget/scenetoolmode.hpp"
#include "../widget/scenetooltoggle.hpp"
#include "../widget/scenetoolrun.hpp"
#include "tablebottombox.hpp"
#include "creator.hpp"
@ -121,6 +122,9 @@ CSVWidget::SceneToolbar* CSVWorld::SceneSubView::makeToolbar (CSVRender::Worldsp
toolbar->addTool (controlVisibilityTool);
}
CSVWidget::SceneToolRun *runTool = widget->makeRunTool (toolbar);
toolbar->addTool (runTool);
return toolbar;
}