#include "pagedworldspacewidget.hpp" #include #include #include CSVRender::PagedWorldspaceWidget::PagedWorldspaceWidget (QWidget *parent, const CSMDoc::Document& document) : WorldspaceWidget (parent), mDocument(document) { setAcceptDrops(true); } void CSVRender::PagedWorldspaceWidget::useViewHint (const std::string& hint) { if (!hint.empty()) { CSMWorld::CellSelection selection; if (hint[0]=='c') { // syntax: c:#x1 y1; #x2 y2 (number of coordinate pairs can be 0 or larger) char ignore; std::istringstream stream (hint.c_str()); if (stream >> ignore) { char ignore1; // : or ; char ignore2; // # int x, y; while (stream >> ignore1 >> ignore2 >> x >> y) selection.add (CSMWorld::CellCoordinates (x, y)); /// \todo adjust camera position } } else if (hint[0]=='r') { /// \todo implement 'r' type hints } setCellSelection (selection); } } void CSVRender::PagedWorldspaceWidget::setCellSelection (const CSMWorld::CellSelection& selection) { mSelection = selection; 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) { const CSMWorld::TableMimeData* mime = dynamic_cast (event->mimeData()); if (mime->fromDocument(mDocument)) { std::vector data(mime->getData()); 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()) == '#') { std::pair coordinate(getCoordinatesFromId(data[i].getId())); mSelection.add(CSMWorld::CellCoordinates(coordinate.first, coordinate.second)); } } } } } std::pair< int, int > CSVRender::PagedWorldspaceWidget::getCoordinatesFromId (const std::string& record) const { std::istringstream stream (record.c_str()); char ignore; stream >> ignore; char ignore1; // : or ; char ignore2; // # int x, y; stream >> ignore1 >> ignore2 >> x >> y; return std::make_pair(x, y); }