mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 22:53:50 +00:00
Drag and drop works.
This commit is contained in:
parent
7f1df878f6
commit
5e99381019
9 changed files with 186 additions and 154 deletions
|
@ -50,32 +50,6 @@ void CSVRender::PagedWorldspaceWidget::setCellSelection (const CSMWorld::CellSel
|
|||
emit cellSelectionChanged (mSelection);
|
||||
}
|
||||
|
||||
void CSVRender::PagedWorldspaceWidget::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:
|
||||
handleDrop(data);
|
||||
break;
|
||||
|
||||
case CSVRender::WorldspaceWidget::cellsInterior:
|
||||
emit interiorCellsDropped(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
|
||||
}
|
||||
|
||||
std::pair< int, int > CSVRender::PagedWorldspaceWidget::getCoordinatesFromId (const std::string& record) const
|
||||
{
|
||||
std::istringstream stream (record.c_str());
|
||||
|
@ -101,3 +75,18 @@ void CSVRender::PagedWorldspaceWidget::handleDrop (const std::vector< CSMWorld::
|
|||
emit cellSelectionChanged(mSelection);
|
||||
}
|
||||
}
|
||||
|
||||
CSVRender::WorldspaceWidget::dropRequirments CSVRender::PagedWorldspaceWidget::getDropRequirements (CSVRender::WorldspaceWidget::dropType type) const
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case cellsExterior:
|
||||
return canHandle;
|
||||
|
||||
case cellsInterior:
|
||||
return needUnpaged;
|
||||
|
||||
default:
|
||||
return ignored;
|
||||
}
|
||||
}
|
|
@ -15,8 +15,6 @@ namespace CSVRender
|
|||
|
||||
private:
|
||||
|
||||
void dropEvent(QDropEvent* event);
|
||||
|
||||
std::pair<int, int> getCoordinatesFromId(const std::string& record) const;
|
||||
|
||||
public:
|
||||
|
@ -32,11 +30,11 @@ namespace CSVRender
|
|||
|
||||
virtual void handleDrop(const std::vector<CSMWorld::UniversalId>& data);
|
||||
|
||||
virtual dropRequirments getDropRequirements(dropType type) const;
|
||||
|
||||
signals:
|
||||
|
||||
void cellSelectionChanged (const CSMWorld::CellSelection& selection);
|
||||
|
||||
void interiorCellsDropped(const std::vector<CSMWorld::UniversalId>& data);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -320,7 +320,7 @@ namespace CSVRender
|
|||
|
||||
}
|
||||
|
||||
if (mUpdate)
|
||||
if (mUpdate && mWindow)
|
||||
{
|
||||
mUpdate = false;
|
||||
mWindow->update();
|
||||
|
|
|
@ -67,34 +67,24 @@ void CSVRender::UnpagedWorldspaceWidget::cellRowsAboutToBeRemoved (const QModelI
|
|||
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)
|
||||
{
|
||||
mCellId = data.begin()->getId();
|
||||
update();
|
||||
emit cellChanged(*data.begin());
|
||||
}
|
||||
|
||||
CSVRender::WorldspaceWidget::dropRequirments CSVRender::UnpagedWorldspaceWidget::getDropRequirements (CSVRender::WorldspaceWidget::dropType type) const
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case cellsInterior:
|
||||
return canHandle;
|
||||
|
||||
case cellsExterior:
|
||||
return needPaged;
|
||||
|
||||
default:
|
||||
return ignored;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,12 +33,9 @@ namespace CSVRender
|
|||
UnpagedWorldspaceWidget (const std::string& cellId, CSMDoc::Document& document,
|
||||
QWidget *parent);
|
||||
|
||||
virtual dropRequirments getDropRequirements(dropType type) const;
|
||||
|
||||
private:
|
||||
|
||||
void handleDrop(const std::vector<CSMWorld::UniversalId>& data);
|
||||
|
||||
void dropEvent(QDropEvent* event);
|
||||
virtual void handleDrop(const std::vector<CSMWorld::UniversalId>& data);
|
||||
|
||||
private slots:
|
||||
|
||||
|
@ -48,8 +45,7 @@ namespace CSVRender
|
|||
|
||||
signals:
|
||||
|
||||
void exteriorCellsDropped(const std::vector<CSMWorld::UniversalId>& data);
|
||||
|
||||
void cellChanged(const CSMWorld::UniversalId& id);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -115,3 +115,14 @@ void CSVRender::WorldspaceWidget::dragMoveEvent(QDragMoveEvent *event)
|
|||
{
|
||||
event->accept();
|
||||
}
|
||||
|
||||
|
||||
void CSVRender::WorldspaceWidget::dropEvent (QDropEvent* event)
|
||||
{
|
||||
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());
|
||||
|
||||
if (mime->fromDocument (mDocument))
|
||||
{
|
||||
emit dataDropped(mime->getData());
|
||||
} //not handling drops from different documents at the moment
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
#include "navigationfree.hpp"
|
||||
#include "navigationorbit.hpp"
|
||||
#include <apps/opencs/model/doc/document.hpp>
|
||||
#include <apps/opencs/model/world/tablemimedata.hpp>
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
|
@ -38,6 +39,14 @@ namespace CSVRender
|
|||
notCells
|
||||
};
|
||||
|
||||
enum dropRequirments
|
||||
{
|
||||
canHandle,
|
||||
needPaged,
|
||||
needUnpaged,
|
||||
ignored //either mixed cells, or not cells
|
||||
};
|
||||
|
||||
WorldspaceWidget (const CSMDoc::Document& document, QWidget *parent = 0);
|
||||
|
||||
CSVWorld::SceneToolMode *makeNavigationSelector (CSVWorld::SceneToolbar *parent);
|
||||
|
@ -48,9 +57,13 @@ namespace CSVRender
|
|||
|
||||
static dropType getDropType(const std::vector<CSMWorld::UniversalId>& data);
|
||||
|
||||
virtual dropRequirments getDropRequirements(dropType type) const = 0;
|
||||
|
||||
virtual void useViewHint (const std::string& hint);
|
||||
///< Default-implementation: ignored.
|
||||
|
||||
virtual void handleDrop(const std::vector<CSMWorld::UniversalId>& data) = 0;
|
||||
|
||||
protected:
|
||||
const CSMDoc::Document& mDocument; //for checking if drop comes from same document
|
||||
|
||||
|
@ -58,6 +71,8 @@ namespace CSVRender
|
|||
|
||||
void dragEnterEvent(QDragEnterEvent *event);
|
||||
|
||||
void dropEvent(QDropEvent* event);
|
||||
|
||||
void dragMoveEvent(QDragMoveEvent *event);
|
||||
|
||||
private slots:
|
||||
|
@ -67,6 +82,7 @@ namespace CSVRender
|
|||
signals:
|
||||
|
||||
void closeRequest();
|
||||
void dataDropped(const std::vector<CSMWorld::UniversalId>& data);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <cassert>
|
||||
|
||||
#include "../../model/doc/document.hpp"
|
||||
|
||||
|
@ -21,7 +22,7 @@
|
|||
#include "scenetoolmode.hpp"
|
||||
|
||||
CSVWorld::SceneSubView::SceneSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
|
||||
: SubView (id), mLayout(new QHBoxLayout), mDocument(document)
|
||||
: SubView (id), mLayout(new QHBoxLayout), mDocument(document), mScene(NULL), mToolbar(NULL)
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout;
|
||||
|
||||
|
@ -33,39 +34,26 @@ CSVWorld::SceneSubView::SceneSubView (const CSMWorld::UniversalId& id, CSMDoc::D
|
|||
|
||||
mLayout->setContentsMargins (QMargins (0, 0, 0, 0));
|
||||
|
||||
mToolbar = new SceneToolbar (48+6, this);
|
||||
CSVRender::WorldspaceWidget* wordspaceWidget = NULL;
|
||||
|
||||
if (id.getId()=="sys::default")
|
||||
{
|
||||
CSVRender::PagedWorldspaceWidget *widget = new CSVRender::PagedWorldspaceWidget (this, document);
|
||||
CSVRender::PagedWorldspaceWidget *newWidget = new CSVRender::PagedWorldspaceWidget (this, document);
|
||||
|
||||
mScene = widget;
|
||||
wordspaceWidget = newWidget;
|
||||
|
||||
connect (widget, SIGNAL (cellSelectionChanged (const CSMWorld::CellSelection&)),
|
||||
this, SLOT (cellSelectionChanged (const CSMWorld::CellSelection&)));
|
||||
|
||||
connect (widget, SIGNAL(interiorCellsDropped (const std::vector<CSMWorld::UniversalId>&)),
|
||||
this, SLOT(changeToUnpaged (const std::vector<CSMWorld::UniversalId>&)));
|
||||
makeConnections(newWidget);
|
||||
}
|
||||
else
|
||||
{
|
||||
CSVRender::UnpagedWorldspaceWidget *widget = new CSVRender::UnpagedWorldspaceWidget (id.getId(), document, this);
|
||||
CSVRender::UnpagedWorldspaceWidget *newWidget = new CSVRender::UnpagedWorldspaceWidget (id.getId(), document, this);
|
||||
|
||||
mScene = widget;
|
||||
wordspaceWidget = newWidget;
|
||||
|
||||
connect (widget, SIGNAL(exteriorCellsDropped(const std::vector<CSMWorld::UniversalId>&)),
|
||||
this, SLOT(changeToUnpaged(const std::vector<CSMWorld::UniversalId>&)));
|
||||
makeConnections(newWidget);
|
||||
}
|
||||
|
||||
SceneToolMode *navigationTool = mScene->makeNavigationSelector (mToolbar);
|
||||
mToolbar->addTool (navigationTool);
|
||||
|
||||
SceneToolMode *lightingTool = mScene->makeLightingSelector (mToolbar);
|
||||
mToolbar->addTool (lightingTool);
|
||||
|
||||
mLayout->addWidget (mToolbar, 0);
|
||||
|
||||
mLayout->addWidget (mScene, 1);
|
||||
replaceToolbarAndWorldspace(wordspaceWidget, makeToolbar(wordspaceWidget));
|
||||
|
||||
layout->insertLayout (0, mLayout, 1);
|
||||
|
||||
|
@ -78,10 +66,41 @@ CSVWorld::SceneSubView::SceneSubView (const CSMWorld::UniversalId& id, CSMDoc::D
|
|||
widget->setLayout (layout);
|
||||
|
||||
setWidget (widget);
|
||||
}
|
||||
|
||||
mScene->selectDefaultNavigationMode();
|
||||
void CSVWorld::SceneSubView::makeConnections (CSVRender::UnpagedWorldspaceWidget* widget)
|
||||
{
|
||||
connect (widget, SIGNAL (closeRequest()), this, SLOT (closeRequest()));
|
||||
|
||||
connect (mScene, SIGNAL (closeRequest()), this, SLOT (closeRequest()));
|
||||
connect(widget, SIGNAL(dataDropped(const std::vector<CSMWorld::UniversalId>&)),
|
||||
this, SLOT(handleDrop(const std::vector<CSMWorld::UniversalId>&)));
|
||||
|
||||
connect(widget, SIGNAL(cellChanged(const CSMWorld::UniversalId&)),
|
||||
this, SLOT(cellSelectionChanged(const CSMWorld::UniversalId&)));
|
||||
}
|
||||
|
||||
void CSVWorld::SceneSubView::makeConnections (CSVRender::PagedWorldspaceWidget* widget)
|
||||
{
|
||||
connect (widget, SIGNAL (closeRequest()), this, SLOT (closeRequest()));
|
||||
|
||||
connect(widget, SIGNAL(dataDropped(const std::vector<CSMWorld::UniversalId>&)),
|
||||
this, SLOT(handleDrop(const std::vector<CSMWorld::UniversalId>&)));
|
||||
|
||||
connect (widget, SIGNAL (cellSelectionChanged (const CSMWorld::CellSelection&)),
|
||||
this, SLOT (cellSelectionChanged (const CSMWorld::CellSelection&)));
|
||||
}
|
||||
|
||||
CSVWorld::SceneToolbar* CSVWorld::SceneSubView::makeToolbar (CSVRender::WorldspaceWidget* widget)
|
||||
{
|
||||
CSVWorld::SceneToolbar* toolbar = new SceneToolbar (48+6, this);
|
||||
|
||||
SceneToolMode *navigationTool = widget->makeNavigationSelector (toolbar);
|
||||
toolbar->addTool (navigationTool);
|
||||
|
||||
SceneToolMode *lightingTool = widget->makeLightingSelector (toolbar);
|
||||
toolbar->addTool (lightingTool);
|
||||
|
||||
return toolbar;
|
||||
}
|
||||
|
||||
void CSVWorld::SceneSubView::setEditLock (bool locked)
|
||||
|
@ -111,8 +130,19 @@ void CSVWorld::SceneSubView::closeRequest()
|
|||
deleteLater();
|
||||
}
|
||||
|
||||
void CSVWorld::SceneSubView::cellSelectionChanged (const CSMWorld::UniversalId& id)
|
||||
{
|
||||
setUniversalId(id);
|
||||
std::ostringstream stream;
|
||||
stream << "Scene: " << getUniversalId().getId();
|
||||
|
||||
setWindowTitle (QString::fromUtf8 (stream.str().c_str()));
|
||||
}
|
||||
|
||||
|
||||
void CSVWorld::SceneSubView::cellSelectionChanged (const CSMWorld::CellSelection& selection)
|
||||
{
|
||||
setUniversalId(CSMWorld::UniversalId(CSMWorld::UniversalId::Type_Cell, "sys::default"));
|
||||
int size = selection.getSize();
|
||||
|
||||
std::ostringstream stream;
|
||||
|
@ -137,70 +167,60 @@ void CSVWorld::SceneSubView::cellSelectionChanged (const CSMWorld::CellSelection
|
|||
setWindowTitle (QString::fromUtf8 (stream.str().c_str()));
|
||||
}
|
||||
|
||||
void CSVWorld::SceneSubView::changeToPaged (const std::vector< CSMWorld::UniversalId >& data)
|
||||
void CSVWorld::SceneSubView::handleDrop (const std::vector< CSMWorld::UniversalId >& data)
|
||||
{
|
||||
CSVRender::PagedWorldspaceWidget* pagedNewWidget = NULL;
|
||||
CSVRender::UnpagedWorldspaceWidget* unPagedNewWidget = NULL;
|
||||
SceneToolbar* toolbar = NULL;
|
||||
|
||||
switch (mScene->getDropRequirements(CSVRender::WorldspaceWidget::getDropType(data)))
|
||||
{
|
||||
case CSVRender::WorldspaceWidget::canHandle:
|
||||
mScene->handleDrop(data);
|
||||
break;
|
||||
|
||||
case CSVRender::WorldspaceWidget::needPaged:
|
||||
pagedNewWidget = new CSVRender::PagedWorldspaceWidget(this, mDocument);
|
||||
toolbar = makeToolbar(pagedNewWidget);
|
||||
makeConnections(pagedNewWidget);
|
||||
replaceToolbarAndWorldspace(pagedNewWidget, toolbar);
|
||||
mScene->handleDrop(data);
|
||||
break;
|
||||
|
||||
case CSVRender::WorldspaceWidget::needUnpaged:
|
||||
unPagedNewWidget = new CSVRender::UnpagedWorldspaceWidget(data.begin()->getId(), mDocument, this);
|
||||
toolbar = makeToolbar(unPagedNewWidget);
|
||||
makeConnections(unPagedNewWidget);
|
||||
replaceToolbarAndWorldspace(unPagedNewWidget, toolbar);
|
||||
cellSelectionChanged(*(data.begin()));
|
||||
break;
|
||||
|
||||
case CSVRender::WorldspaceWidget::ignored:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void CSVWorld::SceneSubView::replaceToolbarAndWorldspace (CSVRender::WorldspaceWidget* widget, CSVWorld::SceneToolbar* toolbar)
|
||||
{
|
||||
assert(mLayout);
|
||||
|
||||
if (mScene)
|
||||
{
|
||||
mLayout->removeWidget(mScene);
|
||||
mScene->deleteLater();
|
||||
}
|
||||
|
||||
if (mToolbar)
|
||||
{
|
||||
mLayout->removeWidget(mToolbar);
|
||||
mLayout->removeWidget(mScene);
|
||||
|
||||
delete mScene;
|
||||
delete mToolbar;
|
||||
|
||||
setUniversalId(CSMWorld::UniversalId(CSMWorld::UniversalId::Type_Cell, "sys::default"));
|
||||
mToolbar = new SceneToolbar (48+6, this);
|
||||
|
||||
CSVRender::PagedWorldspaceWidget* widget = new CSVRender::PagedWorldspaceWidget (this, mDocument);
|
||||
mToolbar->deleteLater();
|
||||
}
|
||||
|
||||
mScene = widget;
|
||||
|
||||
SceneToolMode* navigationTool = mScene->makeNavigationSelector (mToolbar);
|
||||
mToolbar->addTool (navigationTool);
|
||||
|
||||
SceneToolMode* lightingTool = mScene->makeLightingSelector (mToolbar);
|
||||
mToolbar->addTool (lightingTool);
|
||||
|
||||
connect (widget, SIGNAL (cellSelectionChanged (const CSMWorld::CellSelection&)),
|
||||
this, SLOT (cellSelectionChanged (const CSMWorld::CellSelection&)));
|
||||
|
||||
connect (widget, SIGNAL (interiorCellsDropped (const std::vector<CSMWorld::UniversalId>&)),
|
||||
this, SLOT (changeToUnpaged (const std::vector<CSMWorld::UniversalId>&)));
|
||||
mToolbar = toolbar;
|
||||
|
||||
mLayout->addWidget (mToolbar, 0);
|
||||
mLayout->addWidget (mScene, 1);
|
||||
|
||||
mScene->selectDefaultNavigationMode();
|
||||
|
||||
connect (mScene, SIGNAL (closeRequest()), this, SLOT (closeRequest()));
|
||||
|
||||
widget->handleDrop (data);
|
||||
}
|
||||
|
||||
void CSVWorld::SceneSubView::changeToUnpaged (const std::vector< CSMWorld::UniversalId >& data)
|
||||
{
|
||||
mLayout->removeWidget(mToolbar);
|
||||
mLayout->removeWidget(mScene);
|
||||
|
||||
delete mScene;
|
||||
delete mToolbar;
|
||||
|
||||
mToolbar = new SceneToolbar (48+6, this);
|
||||
CSVRender::UnpagedWorldspaceWidget* widget = new CSVRender::UnpagedWorldspaceWidget (data.begin()->getId(), mDocument, this);
|
||||
setUniversalId(*(data.begin()));
|
||||
|
||||
mScene = widget;
|
||||
|
||||
SceneToolMode* navigationTool = mScene->makeNavigationSelector (mToolbar);
|
||||
mToolbar->addTool (navigationTool);
|
||||
|
||||
SceneToolMode* lightingTool = mScene->makeLightingSelector (mToolbar);
|
||||
mToolbar->addTool (lightingTool);
|
||||
|
||||
connect (widget, SIGNAL (exteriorCellsDropped (const std::vector<CSMWorld::UniversalId>&)),
|
||||
this, SLOT (changeToPaged (const std::vector<CSMWorld::UniversalId>&)));
|
||||
|
||||
mLayout->addWidget (mToolbar, 0);
|
||||
mLayout->addWidget (mScene, 1);
|
||||
|
||||
mScene->selectDefaultNavigationMode();
|
||||
|
||||
connect (mScene, SIGNAL (closeRequest()), this, SLOT (closeRequest()));
|
||||
}
|
|
@ -21,6 +21,8 @@ namespace CSMDoc
|
|||
namespace CSVRender
|
||||
{
|
||||
class WorldspaceWidget;
|
||||
class PagedWorldspaceWidget;
|
||||
class UnpagedWorldspaceWidget;
|
||||
}
|
||||
|
||||
namespace CSVWorld
|
||||
|
@ -51,15 +53,25 @@ namespace CSVWorld
|
|||
|
||||
virtual void useHint (const std::string& hint);
|
||||
|
||||
private:
|
||||
|
||||
void makeConnections(CSVRender::PagedWorldspaceWidget* widget);
|
||||
|
||||
void makeConnections(CSVRender::UnpagedWorldspaceWidget* widget);
|
||||
|
||||
void replaceToolbarAndWorldspace(CSVRender::WorldspaceWidget* widget, SceneToolbar* toolbar);
|
||||
|
||||
SceneToolbar* makeToolbar(CSVRender::WorldspaceWidget* widget);
|
||||
|
||||
private slots:
|
||||
|
||||
void closeRequest();
|
||||
|
||||
void cellSelectionChanged (const CSMWorld::CellSelection& selection);
|
||||
|
||||
void changeToPaged(const std::vector<CSMWorld::UniversalId>& data);
|
||||
void cellSelectionChanged (const CSMWorld::UniversalId& id);
|
||||
|
||||
void changeToUnpaged(const std::vector<CSMWorld::UniversalId>& data);
|
||||
void handleDrop(const std::vector<CSMWorld::UniversalId>& data);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue