1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-23 06:23:52 +00:00
openmw/apps/opencs/view/world/scenesubview.cpp

267 lines
8 KiB
C++
Raw Normal View History

#include "scenesubview.hpp"
2022-10-19 17:02:00 +00:00
#include <algorithm>
#include <cassert>
#include <map>
#include <sstream>
#include <QHBoxLayout>
2022-10-19 17:02:00 +00:00
#include <QMargins>
2022-09-22 18:26:05 +00:00
#include <QVBoxLayout>
2022-10-19 17:02:00 +00:00
#include <QWidget>
#include <apps/opencs/model/world/cellcoordinates.hpp>
#include <apps/opencs/view/doc/subview.hpp>
#include <apps/opencs/view/render/worldspacewidget.hpp>
#include <components/esm3/cellid.hpp>
#include "../../model/doc/document.hpp"
2014-09-24 20:59:04 +00:00
#include "../../model/world/cellselection.hpp"
#include "../filter/filterbox.hpp"
#include "../render/pagedworldspacewidget.hpp"
#include "../render/unpagedworldspacewidget.hpp"
2013-11-02 01:48:30 +00:00
#include "../widget/scenetoolbar.hpp"
#include "../widget/scenetoolmode.hpp"
2022-09-22 18:26:05 +00:00
#include "../widget/scenetoolrun.hpp"
2014-11-28 08:14:02 +00:00
#include "../widget/scenetooltoggle2.hpp"
#include "creator.hpp"
2022-09-22 18:26:05 +00:00
#include "tablebottombox.hpp"
2022-09-22 18:26:05 +00:00
CSVWorld::SceneSubView::SceneSubView(const CSMWorld::UniversalId& id, CSMDoc::Document& document)
: SubView(id)
, mScene(nullptr)
, mLayout(new QHBoxLayout)
, mDocument(document)
, mToolbar(nullptr)
{
2022-09-22 18:26:05 +00:00
QVBoxLayout* layout = new QVBoxLayout;
2022-09-22 18:26:05 +00:00
layout->addWidget(mBottom = new TableBottomBox(NullCreatorFactory(), document, id, this), 0);
2022-09-22 18:26:05 +00:00
mLayout->setContentsMargins(QMargins(0, 0, 0, 0));
2018-10-09 06:21:12 +00:00
CSVRender::WorldspaceWidget* worldspaceWidget = nullptr;
2014-05-04 10:30:15 +00:00
widgetType whatWidget;
2014-02-25 13:59:46 +00:00
if (ESM::RefId::stringRefId(id.getId()) == ESM::CellId::sDefaultWorldspace)
{
2014-05-04 10:30:15 +00:00
whatWidget = widget_Paged;
2022-09-22 18:26:05 +00:00
CSVRender::PagedWorldspaceWidget* newWidget = new CSVRender::PagedWorldspaceWidget(this, document);
worldspaceWidget = newWidget;
2014-05-03 12:00:30 +00:00
makeConnections(newWidget);
}
else
{
2014-05-04 10:30:15 +00:00
whatWidget = widget_Unpaged;
2022-09-22 18:26:05 +00:00
CSVRender::UnpagedWorldspaceWidget* newWidget
= new CSVRender::UnpagedWorldspaceWidget(id.getId(), document, this);
worldspaceWidget = newWidget;
2014-03-23 14:14:26 +00:00
2014-05-03 12:00:30 +00:00
makeConnections(newWidget);
}
replaceToolbarAndWorldspace(worldspaceWidget, makeToolbar(worldspaceWidget, whatWidget));
2022-09-22 18:26:05 +00:00
layout->insertLayout(0, mLayout, 1);
2022-09-22 18:26:05 +00:00
CSVFilter::FilterBox* filterBox = new CSVFilter::FilterBox(document.getData(), this);
2022-09-22 18:26:05 +00:00
layout->insertWidget(0, filterBox);
2022-09-22 18:26:05 +00:00
QWidget* widget = new QWidget;
2022-09-22 18:26:05 +00:00
widget->setLayout(layout);
2022-09-22 18:26:05 +00:00
setWidget(widget);
2014-05-03 12:00:30 +00:00
}
2022-09-22 18:26:05 +00:00
void CSVWorld::SceneSubView::makeConnections(CSVRender::UnpagedWorldspaceWidget* widget)
2014-05-03 12:00:30 +00:00
{
2022-09-22 18:26:05 +00:00
connect(widget, &CSVRender::UnpagedWorldspaceWidget::closeRequest, this, qOverload<>(&SceneSubView::closeRequest));
2014-05-03 12:00:30 +00:00
2022-09-22 18:26:05 +00:00
connect(widget, &CSVRender::UnpagedWorldspaceWidget::dataDropped, this, &SceneSubView::handleDrop);
2022-09-22 18:26:05 +00:00
connect(widget, &CSVRender::UnpagedWorldspaceWidget::cellChanged, this,
qOverload<const CSMWorld::UniversalId&>(&SceneSubView::cellSelectionChanged));
2022-09-22 18:26:05 +00:00
connect(widget, &CSVRender::UnpagedWorldspaceWidget::requestFocus, this, &SceneSubView::requestFocus);
2014-05-03 12:00:30 +00:00
}
2022-09-22 18:26:05 +00:00
void CSVWorld::SceneSubView::makeConnections(CSVRender::PagedWorldspaceWidget* widget)
2014-05-03 12:00:30 +00:00
{
2022-09-22 18:26:05 +00:00
connect(widget, &CSVRender::PagedWorldspaceWidget::closeRequest, this, qOverload<>(&SceneSubView::closeRequest));
2014-05-03 12:00:30 +00:00
2022-09-22 18:26:05 +00:00
connect(widget, &CSVRender::PagedWorldspaceWidget::dataDropped, this, &SceneSubView::handleDrop);
2014-05-03 12:00:30 +00:00
2022-09-22 18:26:05 +00:00
connect(widget, &CSVRender::PagedWorldspaceWidget::cellSelectionChanged, this,
qOverload<const CSMWorld::CellSelection&>(&SceneSubView::cellSelectionChanged));
2022-09-22 18:26:05 +00:00
connect(widget, &CSVRender::PagedWorldspaceWidget::requestFocus, this, &SceneSubView::requestFocus);
2014-05-03 12:00:30 +00:00
}
2022-09-22 18:26:05 +00:00
CSVWidget::SceneToolbar* CSVWorld::SceneSubView::makeToolbar(CSVRender::WorldspaceWidget* widget, widgetType type)
2014-05-03 12:00:30 +00:00
{
2022-09-22 18:26:05 +00:00
CSVWidget::SceneToolbar* toolbar = new CSVWidget::SceneToolbar(48 + 6, this);
2014-05-03 12:00:30 +00:00
2022-09-22 18:26:05 +00:00
CSVWidget::SceneToolMode* navigationTool = widget->makeNavigationSelector(toolbar);
toolbar->addTool(navigationTool);
2014-05-03 12:00:30 +00:00
2022-09-22 18:26:05 +00:00
CSVWidget::SceneToolMode* lightingTool = widget->makeLightingSelector(toolbar);
toolbar->addTool(lightingTool);
2014-05-03 12:00:30 +00:00
2022-09-22 18:26:05 +00:00
CSVWidget::SceneToolToggle2* sceneVisibilityTool = widget->makeSceneVisibilitySelector(toolbar);
toolbar->addTool(sceneVisibilityTool);
2022-09-22 18:26:05 +00:00
if (type == widget_Paged)
2014-05-04 10:30:15 +00:00
{
2022-09-22 18:26:05 +00:00
CSVWidget::SceneToolToggle2* controlVisibilityTool
= dynamic_cast<CSVRender::PagedWorldspaceWidget&>(*widget).makeControlVisibilitySelector(toolbar);
2014-05-04 10:30:15 +00:00
2022-09-22 18:26:05 +00:00
toolbar->addTool(controlVisibilityTool);
2014-05-04 10:30:15 +00:00
}
2022-09-22 18:26:05 +00:00
CSVWidget::SceneToolRun* runTool = widget->makeRunTool(toolbar);
toolbar->addTool(runTool);
2022-09-22 18:26:05 +00:00
toolbar->addTool(widget->makeEditModeSelector(toolbar), runTool);
2014-05-03 12:00:30 +00:00
return toolbar;
}
2022-09-22 18:26:05 +00:00
void CSVWorld::SceneSubView::setEditLock(bool locked)
{
2022-09-22 18:26:05 +00:00
mScene->setEditLock(locked);
}
2022-09-22 18:26:05 +00:00
void CSVWorld::SceneSubView::setStatusBar(bool show)
{
2022-09-22 18:26:05 +00:00
mBottom->setStatusBar(show);
2013-11-02 01:48:30 +00:00
}
2022-09-22 18:26:05 +00:00
void CSVWorld::SceneSubView::useHint(const std::string& hint)
{
2022-09-22 18:26:05 +00:00
mScene->useViewHint(hint);
}
std::string CSVWorld::SceneSubView::getTitle() const
{
return mTitle;
}
2022-09-22 18:26:05 +00:00
void CSVWorld::SceneSubView::cellSelectionChanged(const CSMWorld::UniversalId& id)
2014-05-03 12:00:30 +00:00
{
setUniversalId(id);
2019-01-07 13:47:39 +00:00
mTitle = "Scene: " + getUniversalId().getId();
2022-09-22 18:26:05 +00:00
setWindowTitle(QString::fromUtf8(mTitle.c_str()));
emit updateTitle();
2014-05-03 12:00:30 +00:00
}
2022-09-22 18:26:05 +00:00
void CSVWorld::SceneSubView::cellSelectionChanged(const CSMWorld::CellSelection& selection)
{
setUniversalId(CSMWorld::UniversalId(CSMWorld::UniversalId::Type_Scene, ESM::CellId::sDefaultWorldspace));
int size = selection.getSize();
std::ostringstream stream;
stream << "Scene: " << getUniversalId().getId();
2022-09-22 18:26:05 +00:00
if (size == 0)
stream << " (empty)";
2022-09-22 18:26:05 +00:00
else if (size == 1)
{
stream << " (" << *selection.begin() << ")";
}
else
{
2022-09-22 18:26:05 +00:00
stream << " (" << selection.getCentre() << " and " << size - 1 << " more ";
2022-09-22 18:26:05 +00:00
if (size > 1)
stream << "cells around it)";
else
stream << "cell around it)";
}
mTitle = stream.str();
2022-09-22 18:26:05 +00:00
setWindowTitle(QString::fromUtf8(mTitle.c_str()));
emit updateTitle();
}
2022-09-22 18:26:05 +00:00
void CSVWorld::SceneSubView::handleDrop(const std::vector<CSMWorld::UniversalId>& universalIdData)
{
2018-10-09 06:21:12 +00:00
CSVRender::PagedWorldspaceWidget* pagedNewWidget = nullptr;
CSVRender::UnpagedWorldspaceWidget* unPagedNewWidget = nullptr;
CSVWidget::SceneToolbar* toolbar = nullptr;
2022-09-22 18:26:05 +00:00
CSVRender::WorldspaceWidget::DropType type = CSVRender::WorldspaceWidget::getDropType(universalIdData);
2022-09-22 18:26:05 +00:00
switch (mScene->getDropRequirements(type))
2014-05-03 12:00:30 +00:00
{
case CSVRender::WorldspaceWidget::canHandle:
2022-09-22 18:26:05 +00:00
mScene->handleDrop(universalIdData, type);
2014-05-03 12:00:30 +00:00
break;
case CSVRender::WorldspaceWidget::needPaged:
pagedNewWidget = new CSVRender::PagedWorldspaceWidget(this, mDocument);
2014-05-04 10:30:15 +00:00
toolbar = makeToolbar(pagedNewWidget, widget_Paged);
2014-05-03 12:00:30 +00:00
makeConnections(pagedNewWidget);
replaceToolbarAndWorldspace(pagedNewWidget, toolbar);
2022-09-22 18:26:05 +00:00
mScene->handleDrop(universalIdData, type);
2014-05-03 12:00:30 +00:00
break;
case CSVRender::WorldspaceWidget::needUnpaged:
2022-09-22 18:26:05 +00:00
unPagedNewWidget
= new CSVRender::UnpagedWorldspaceWidget(universalIdData.begin()->getId(), mDocument, this);
2014-05-04 10:30:15 +00:00
toolbar = makeToolbar(unPagedNewWidget, widget_Unpaged);
2014-05-03 12:00:30 +00:00
makeConnections(unPagedNewWidget);
replaceToolbarAndWorldspace(unPagedNewWidget, toolbar);
2016-10-15 16:34:54 +00:00
cellSelectionChanged(*(universalIdData.begin()));
2014-05-03 12:00:30 +00:00
break;
case CSVRender::WorldspaceWidget::ignored:
return;
}
}
2022-09-22 18:26:05 +00:00
void CSVWorld::SceneSubView::replaceToolbarAndWorldspace(
CSVRender::WorldspaceWidget* widget, CSVWidget::SceneToolbar* toolbar)
{
2014-05-03 12:00:30 +00:00
assert(mLayout);
2014-05-03 12:00:30 +00:00
if (mScene)
{
mLayout->removeWidget(mScene);
mScene->deleteLater();
}
2014-05-03 12:00:30 +00:00
if (mToolbar)
{
mLayout->removeWidget(mToolbar);
mToolbar->deleteLater();
}
mScene = widget;
2014-05-03 12:00:30 +00:00
mToolbar = toolbar;
2022-09-22 18:26:05 +00:00
connect(mScene, &CSVRender::WorldspaceWidget::focusToolbarRequest, mToolbar,
qOverload<>(&CSVWidget::SceneToolbar::setFocus));
connect(mToolbar, &CSVWidget::SceneToolbar::focusSceneRequest, mScene,
qOverload<>(&CSVRender::WorldspaceWidget::setFocus));
2022-09-22 18:26:05 +00:00
mLayout->addWidget(mToolbar, 0);
mLayout->addWidget(mScene, 1);
mScene->selectDefaultNavigationMode();
2022-09-22 18:26:05 +00:00
setFocusProxy(mScene);
}