1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-31 14:36:39 +00:00

working on worldspace drops

This commit is contained in:
Marek Kochanowicz 2014-05-01 15:09:47 +02:00
parent 57131332f4
commit d00dbf47d5
6 changed files with 184 additions and 45 deletions

View file

@ -8,11 +8,8 @@
#include <apps/opencs/model/world/tablemimedata.hpp> #include <apps/opencs/model/world/tablemimedata.hpp>
CSVRender::PagedWorldspaceWidget::PagedWorldspaceWidget (QWidget *parent, const CSMDoc::Document& document) CSVRender::PagedWorldspaceWidget::PagedWorldspaceWidget (QWidget *parent, const CSMDoc::Document& document)
: WorldspaceWidget (parent), : WorldspaceWidget (document, parent)
mDocument(document) {}
{
setAcceptDrops(true);
}
void CSVRender::PagedWorldspaceWidget::useViewHint (const std::string& hint) void CSVRender::PagedWorldspaceWidget::useViewHint (const std::string& hint)
{ {
@ -53,48 +50,55 @@ void CSVRender::PagedWorldspaceWidget::setCellSelection (const CSMWorld::CellSel
emit cellSelectionChanged (mSelection); emit cellSelectionChanged (mSelection);
} }
void CSVRender::PagedWorldspaceWidget::dragEnterEvent (QDragEnterEvent* event)
{
event->accept();
}
void CSVRender::PagedWorldspaceWidget::dragMoveEvent (QDragMoveEvent* event)
{
event->accept();
}
void CSVRender::PagedWorldspaceWidget::dropEvent (QDropEvent* event) void CSVRender::PagedWorldspaceWidget::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());
if (mime->fromDocument(mDocument)) if (mime->fromDocument(mDocument))
{ {
std::vector<CSMWorld::UniversalId> data(mime->getData()); const std::vector<CSMWorld::UniversalId> data(mime->getData());
CSVRender::WorldspaceWidget::dropType whatHappend = getDropType(data);
for (unsigned i = 0; i < data.size(); ++i) std::cout<<whatHappend<<std::endl;
switch (whatHappend)
{ {
if (data[i].getType() == CSMWorld::UniversalId::Type_Cell || case CSVRender::WorldspaceWidget::cellsExterior:
data[i].getType() == CSMWorld::UniversalId::Type_Cell_Missing) handleDrop(data);
{ break;
if (*(data[i].getId().begin()) == '#')
{ case CSVRender::WorldspaceWidget::cellsInterior:
std::pair<int, int> coordinate(getCoordinatesFromId(data[i].getId())); emit interiorCellsDropped(data);
mSelection.add(CSMWorld::CellCoordinates(coordinate.first, coordinate.second)); break;
}
} default:
} //not interior or exterior = either mixed or not actually cells. We don't need to do anything in this case.
break;
} }
} //not handling drops from different documents at the moment
} }
std::pair< int, int > CSVRender::PagedWorldspaceWidget::getCoordinatesFromId (const std::string& record) const std::pair< int, int > CSVRender::PagedWorldspaceWidget::getCoordinatesFromId (const std::string& record) const
{ {
std::istringstream stream (record.c_str()); std::istringstream stream (record.c_str());
char ignore; char ignore;
stream >> ignore;
char ignore1; // : or ;
char ignore2; // #
int x, y; int x, y;
stream >> ignore >> x >> y;
stream >> ignore1 >> ignore2 >> x >> y;
return std::make_pair(x, y); return std::make_pair(x, y);
} }
void CSVRender::PagedWorldspaceWidget::handleDrop (const std::vector< CSMWorld::UniversalId >& data)
{
bool selectionChanged = false;
for (unsigned i = 0; i < data.size(); ++i)
{
std::pair<int, int> coordinates(getCoordinatesFromId(data[i].getId()));
if (mSelection.add(CSMWorld::CellCoordinates(coordinates.first, coordinates.second)))
{
selectionChanged = true;
}
}
if (selectionChanged)
{
emit cellSelectionChanged(mSelection);
}
}

View file

@ -2,7 +2,6 @@
#define OPENCS_VIEW_PAGEDWORLDSPACEWIDGET_H #define OPENCS_VIEW_PAGEDWORLDSPACEWIDGET_H
#include "../../model/world/cellselection.hpp" #include "../../model/world/cellselection.hpp"
#include <apps/opencs/model/doc/document.hpp>
#include "worldspacewidget.hpp" #include "worldspacewidget.hpp"
@ -13,18 +12,15 @@ namespace CSVRender
Q_OBJECT Q_OBJECT
CSMWorld::CellSelection mSelection; CSMWorld::CellSelection mSelection;
const CSMDoc::Document& mDocument; //for checking if drop comes from same document
private: private:
void dropEvent(QDropEvent* event); void dropEvent(QDropEvent* event);
void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
std::pair<int, int> getCoordinatesFromId(const std::string& record) const; std::pair<int, int> getCoordinatesFromId(const std::string& record) const;
void handleDrop(const std::vector<CSMWorld::UniversalId>& data);
public: public:
PagedWorldspaceWidget (QWidget *parent, const CSMDoc::Document& document); PagedWorldspaceWidget (QWidget *parent, const CSMDoc::Document& document);
@ -39,6 +35,8 @@ namespace CSVRender
signals: signals:
void cellSelectionChanged (const CSMWorld::CellSelection& selection); void cellSelectionChanged (const CSMWorld::CellSelection& selection);
void interiorCellsDropped(const std::vector<CSMWorld::UniversalId>& data);
}; };
} }

View file

@ -3,10 +3,13 @@
#include <OgreColourValue.h> #include <OgreColourValue.h>
#include <qt4/QtGui/qevent.h>
#include "../../model/doc/document.hpp" #include "../../model/doc/document.hpp"
#include "../../model/world/data.hpp" #include "../../model/world/data.hpp"
#include "../../model/world/idtable.hpp" #include "../../model/world/idtable.hpp"
#include "../../model/world/tablemimedata.hpp"
void CSVRender::UnpagedWorldspaceWidget::update() void CSVRender::UnpagedWorldspaceWidget::update()
{ {
@ -22,7 +25,7 @@ void CSVRender::UnpagedWorldspaceWidget::update()
CSVRender::UnpagedWorldspaceWidget::UnpagedWorldspaceWidget (const std::string& cellId, CSVRender::UnpagedWorldspaceWidget::UnpagedWorldspaceWidget (const std::string& cellId,
CSMDoc::Document& document, QWidget *parent) CSMDoc::Document& document, QWidget *parent)
: WorldspaceWidget (parent), mCellId (cellId) : WorldspaceWidget (document, parent), mCellId (cellId)
{ {
mCellsModel = &dynamic_cast<CSMWorld::IdTable&> ( mCellsModel = &dynamic_cast<CSMWorld::IdTable&> (
*document.getData().getTableModel (CSMWorld::UniversalId::Type_Cells)); *document.getData().getTableModel (CSMWorld::UniversalId::Type_Cells));
@ -64,3 +67,34 @@ void CSVRender::UnpagedWorldspaceWidget::cellRowsAboutToBeRemoved (const QModelI
if (cellIndex.row()>=start && cellIndex.row()<=end) if (cellIndex.row()>=start && cellIndex.row()<=end)
emit closeRequest(); emit closeRequest();
} }
void CSVRender::UnpagedWorldspaceWidget::dropEvent (QDropEvent* event)
{
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());
if (mime->fromDocument (mDocument))
{
const std::vector<CSMWorld::UniversalId> data (mime->getData());
CSVRender::WorldspaceWidget::dropType whatHappend = getDropType (data);
switch (whatHappend)
{
case CSVRender::WorldspaceWidget::cellsExterior:
emit exteriorCellsDropped(data);
break;
case CSVRender::WorldspaceWidget::cellsInterior:
handleDrop(data);
break;
default:
//not interior or exterior = either mixed or not actually cells. We don't need to do anything in this case.
break;
}
} //not handling drops from different documents at the moment
}
void CSVRender::UnpagedWorldspaceWidget::handleDrop (const std::vector< CSMWorld::UniversalId >& data)
{
}

View file

@ -33,11 +33,22 @@ namespace CSVRender
UnpagedWorldspaceWidget (const std::string& cellId, CSMDoc::Document& document, UnpagedWorldspaceWidget (const std::string& cellId, CSMDoc::Document& document,
QWidget *parent); QWidget *parent);
private:
void handleDrop(const std::vector<CSMWorld::UniversalId>& data);
void dropEvent(QDropEvent* event);
private slots: private slots:
void cellDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight); void cellDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight);
void cellRowsAboutToBeRemoved (const QModelIndex& parent, int start, int end); void cellRowsAboutToBeRemoved (const QModelIndex& parent, int start, int end);
signals:
void exteriorCellsDropped(const std::vector<CSMWorld::UniversalId>& data);
}; };
} }

View file

@ -5,15 +5,20 @@
#include <OgreSceneManager.h> #include <OgreSceneManager.h>
#include <OgreEntity.h> #include <OgreEntity.h>
#include "../world/scenetoolmode.hpp" #include <qt4/QtGui/qevent.h>
CSVRender::WorldspaceWidget::WorldspaceWidget (QWidget *parent) #include "../world/scenetoolmode.hpp"
: SceneWidget (parent) #include <apps/opencs/model/world/universalid.hpp>
CSVRender::WorldspaceWidget::WorldspaceWidget (const CSMDoc::Document& document, QWidget* parent)
: SceneWidget (parent), mDocument(document)
{ {
Ogre::Entity* ent = getSceneManager()->createEntity("cube", Ogre::SceneManager::PT_CUBE); Ogre::Entity* ent = getSceneManager()->createEntity("cube", Ogre::SceneManager::PT_CUBE);
ent->setMaterialName("BaseWhite"); ent->setMaterialName("BaseWhite");
getSceneManager()->getRootSceneNode()->attachObject(ent); getSceneManager()->getRootSceneNode()->attachObject(ent);
setAcceptDrops(true);
} }
void CSVRender::WorldspaceWidget::selectNavigationMode (const std::string& mode) void CSVRender::WorldspaceWidget::selectNavigationMode (const std::string& mode)
@ -47,3 +52,66 @@ CSVWorld::SceneToolMode *CSVRender::WorldspaceWidget::makeNavigationSelector (
return tool; return tool;
} }
CSVRender::WorldspaceWidget::dropType CSVRender::WorldspaceWidget::getDropType (
const std::vector< CSMWorld::UniversalId >& data) const
{
dropType output = notCells;
bool firstIteration = true;
for (unsigned i = 0; i < data.size(); ++i)
{
if (data[i].getType() == CSMWorld::UniversalId::Type_Cell ||
data[i].getType() == CSMWorld::UniversalId::Type_Cell_Missing)
{
if (*(data[i].getId().begin()) == '#') //exterior
{
if (firstIteration)
{
output = cellsExterior;
firstIteration = false;
continue;
}
if (output == cellsInterior)
{
output = cellsMixed;
break;
} else {
output = cellsInterior;
}
} else //interior
{
if (firstIteration)
{
output = cellsInterior;
firstIteration = false;
continue;
}
if (output == cellsExterior)
{
output = cellsMixed;
break;
} else {
output = cellsInterior;
}
}
} else {
output = notCells;
break;
}
}
return output;
}
void CSVRender::WorldspaceWidget::dragEnterEvent (QDragEnterEvent* event)
{
event->accept();
}
void CSVRender::WorldspaceWidget::dragMoveEvent(QDragMoveEvent *event)
{
event->accept();
}

View file

@ -6,7 +6,12 @@
#include "navigation1st.hpp" #include "navigation1st.hpp"
#include "navigationfree.hpp" #include "navigationfree.hpp"
#include "navigationorbit.hpp" #include "navigationorbit.hpp"
#include <apps/opencs/model/doc/document.hpp>
namespace CSMWorld
{
class UniversalId;
}
namespace CSVWorld namespace CSVWorld
{ {
class SceneToolMode; class SceneToolMode;
@ -25,7 +30,7 @@ namespace CSVRender
public: public:
WorldspaceWidget (QWidget *parent = 0); WorldspaceWidget (const CSMDoc::Document& document, QWidget *parent = 0);
CSVWorld::SceneToolMode *makeNavigationSelector (CSVWorld::SceneToolbar *parent); CSVWorld::SceneToolMode *makeNavigationSelector (CSVWorld::SceneToolbar *parent);
///< \attention The created tool is not added to the toolbar (via addTool). Doing that ///< \attention The created tool is not added to the toolbar (via addTool). Doing that
@ -36,6 +41,25 @@ namespace CSVRender
virtual void useViewHint (const std::string& hint); virtual void useViewHint (const std::string& hint);
///< Default-implementation: ignored. ///< Default-implementation: ignored.
protected:
const CSMDoc::Document& mDocument; //for checking if drop comes from same document
enum dropType
{
cellsMixed,
cellsInterior,
cellsExterior,
notCells
};
dropType getDropType(const std::vector<CSMWorld::UniversalId>& data) const;
private:
void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
private slots: private slots:
void selectNavigationMode (const std::string& mode); void selectNavigationMode (const std::string& mode);