mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-07 03:12:36 +01:00
Overhaul Model Viewer behaviour with visibility toggle
This commit is contained in:
parent
0f4152d099
commit
efc79e8ec6
@ -165,7 +165,7 @@ GameWorld* ViewerWidget::world()
|
|||||||
return gworld;
|
return gworld;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewerWidget::showItem(qint16 item)
|
void ViewerWidget::showObject(qint16 item)
|
||||||
{
|
{
|
||||||
currentObjectID = item;
|
currentObjectID = item;
|
||||||
|
|
||||||
@ -244,6 +244,11 @@ Model* ViewerWidget::currentModel() const
|
|||||||
return activeModel;
|
return activeModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GameObject* ViewerWidget::currentObject() const
|
||||||
|
{
|
||||||
|
return dummyObject;
|
||||||
|
}
|
||||||
|
|
||||||
void ViewerWidget::mousePressEvent(QMouseEvent* e)
|
void ViewerWidget::mousePressEvent(QMouseEvent* e)
|
||||||
{
|
{
|
||||||
dragging = true;
|
dragging = true;
|
||||||
|
@ -55,12 +55,13 @@ public:
|
|||||||
virtual void paintGL();
|
virtual void paintGL();
|
||||||
|
|
||||||
Model *currentModel() const;
|
Model *currentModel() const;
|
||||||
|
GameObject* currentObject() const;
|
||||||
|
|
||||||
GameWorld* world();
|
GameWorld* world();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void showItem(qint16 item);
|
void showObject(qint16 item);
|
||||||
void showModel(Model* model);
|
void showModel(Model* model);
|
||||||
void selectFrame(ModelFrame* frame);
|
void selectFrame(ModelFrame* frame);
|
||||||
|
|
||||||
|
@ -57,7 +57,8 @@ ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags)
|
|||||||
viewSwitcher->addWidget(objectViewer);
|
viewSwitcher->addWidget(objectViewer);
|
||||||
viewSwitcher->addWidget(modelViewer);
|
viewSwitcher->addWidget(modelViewer);
|
||||||
|
|
||||||
connect(objectViewer, SIGNAL(modelChanged(Model*)), modelViewer, SLOT(showModel(Model*)));
|
//connect(objectViewer, SIGNAL(modelChanged(Model*)), modelViewer, SLOT(showModel(Model*)));
|
||||||
|
connect(objectViewer, SIGNAL(showObjectModel(uint16_t)), this, SLOT(showObjectModel(uint16_t)));
|
||||||
|
|
||||||
objectViewer->setViewerWidget( viewerWidget );
|
objectViewer->setViewerWidget( viewerWidget );
|
||||||
|
|
||||||
@ -199,6 +200,14 @@ void ViewerWindow::switchWidget()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ViewerWindow::showObjectModel(uint16_t object)
|
||||||
|
{
|
||||||
|
// Switch to the model viewer
|
||||||
|
modelViewer->setViewerWidget( viewerWidget );
|
||||||
|
viewSwitcher->setCurrentIndex( viewSwitcher->indexOf(modelViewer) );
|
||||||
|
modelViewer->showObject(object);
|
||||||
|
}
|
||||||
|
|
||||||
void ViewerWindow::updateRecentGames()
|
void ViewerWindow::updateRecentGames()
|
||||||
{
|
{
|
||||||
QSettings settings("OpenRW", "rwviewer");
|
QSettings settings("OpenRW", "rwviewer");
|
||||||
|
@ -63,6 +63,8 @@ private slots:
|
|||||||
|
|
||||||
void switchWidget();
|
void switchWidget();
|
||||||
|
|
||||||
|
void showObjectModel(uint16_t object);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
QList<QAction*> recentGames;
|
QList<QAction*> recentGames;
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
#include "DFFFramesTreeModel.hpp"
|
#include "DFFFramesTreeModel.hpp"
|
||||||
#include <render/Model.hpp>
|
#include <render/Model.hpp>
|
||||||
|
#include <data/Skeleton.hpp>
|
||||||
|
|
||||||
DFFFramesTreeModel::DFFFramesTreeModel(Model *m, QObject* parent)
|
DFFFramesTreeModel::DFFFramesTreeModel(Model *m, Skeleton* skel, QObject* parent)
|
||||||
: QAbstractItemModel(parent), model(m)
|
: QAbstractItemModel(parent), model(m), skeleton(skel)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -63,9 +64,65 @@ QVariant DFFFramesTreeModel::data(const QModelIndex& index, int role) const
|
|||||||
return QString(f->getName().c_str());
|
return QString(f->getName().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if( role == Qt::CheckStateRole )
|
||||||
|
{
|
||||||
|
if( index.column() == 0 )
|
||||||
|
{
|
||||||
|
if( skeleton )
|
||||||
|
{
|
||||||
|
return skeleton->getData(f->getIndex()).enabled ?
|
||||||
|
Qt::Checked : Qt::Unchecked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DFFFramesTreeModel::setData(const QModelIndex& index, const QVariant& value, int role)
|
||||||
|
{
|
||||||
|
if(! index.isValid() )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ModelFrame* f = static_cast<ModelFrame*>(index.internalPointer());
|
||||||
|
|
||||||
|
if( role == Qt::CheckStateRole )
|
||||||
|
{
|
||||||
|
if( index.column() == 0 && skeleton )
|
||||||
|
{
|
||||||
|
if( (Qt::CheckState)value.toInt() == Qt::Checked )
|
||||||
|
{
|
||||||
|
skeleton->setEnabled(f, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
skeleton->setEnabled(f, false);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Qt::ItemFlags DFFFramesTreeModel::flags(const QModelIndex& index) const
|
||||||
|
{
|
||||||
|
if(! index.isValid() )
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||||
|
|
||||||
|
if( index.column() == 0 && skeleton )
|
||||||
|
{
|
||||||
|
flags |= Qt::ItemIsUserCheckable;
|
||||||
|
}
|
||||||
|
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
|
||||||
QVariant DFFFramesTreeModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant DFFFramesTreeModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
{
|
{
|
||||||
if(orientation == Qt::Horizontal) {
|
if(orientation == Qt::Horizontal) {
|
||||||
|
@ -5,19 +5,25 @@
|
|||||||
#include <engine/RWTypes.hpp>
|
#include <engine/RWTypes.hpp>
|
||||||
|
|
||||||
class Model;
|
class Model;
|
||||||
|
class Skeleton;
|
||||||
|
|
||||||
class DFFFramesTreeModel : public QAbstractItemModel
|
class DFFFramesTreeModel : public QAbstractItemModel
|
||||||
{
|
{
|
||||||
Model* model;
|
Model* model;
|
||||||
|
Skeleton* skeleton;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
explicit DFFFramesTreeModel(Model* m, QObject* parent = 0);
|
explicit DFFFramesTreeModel(Model* m, Skeleton* skel, QObject* parent = 0);
|
||||||
|
|
||||||
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
|
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
|
||||||
|
|
||||||
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
||||||
|
|
||||||
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
||||||
|
|
||||||
|
virtual bool setData(const QModelIndex& index, const QVariant& value, int role);
|
||||||
|
|
||||||
|
virtual Qt::ItemFlags flags(const QModelIndex& index) const;
|
||||||
|
|
||||||
virtual QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const;
|
virtual QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const;
|
||||||
|
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
#include "ModelViewer.hpp"
|
#include "ModelViewer.hpp"
|
||||||
#include <widgets/ModelFramesWidget.hpp>
|
#include <widgets/ModelFramesWidget.hpp>
|
||||||
#include "ViewerWidget.hpp"
|
#include "ViewerWidget.hpp"
|
||||||
|
#include <data/Skeleton.hpp>
|
||||||
|
#include <engine/GameObject.hpp>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
ModelViewer::ModelViewer(ViewerWidget* viewer, QWidget* parent, Qt::WindowFlags f)
|
ModelViewer::ModelViewer(ViewerWidget* viewer, QWidget* parent, Qt::WindowFlags f)
|
||||||
: QWidget(parent, f), _world(nullptr), viewing(nullptr)
|
: QWidget(parent, f), _world(nullptr), viewing(nullptr), skeleton(nullptr)
|
||||||
{
|
{
|
||||||
mainSplit = new QSplitter;
|
mainSplit = new QSplitter;
|
||||||
mainLayout = new QVBoxLayout;
|
mainLayout = new QVBoxLayout;
|
||||||
@ -40,6 +42,19 @@ void ModelViewer::showData(GameWorld* world)
|
|||||||
void ModelViewer::showModel(Model* model)
|
void ModelViewer::showModel(Model* model)
|
||||||
{
|
{
|
||||||
viewing = model;
|
viewing = model;
|
||||||
|
if( skeleton )
|
||||||
|
{
|
||||||
|
delete skeleton;
|
||||||
|
}
|
||||||
|
skeleton = new Skeleton();
|
||||||
viewerWidget->showModel(model);
|
viewerWidget->showModel(model);
|
||||||
frames->setModel(model);
|
frames->setModel(model, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModelViewer::showObject(uint16_t object)
|
||||||
|
{
|
||||||
|
viewerWidget->showObject(object);
|
||||||
|
viewing = viewerWidget->currentModel();
|
||||||
|
skeleton = viewerWidget->currentObject()->skeleton;
|
||||||
|
frames->setModel(viewing, skeleton);
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
class ViewerWidget;
|
class ViewerWidget;
|
||||||
class Model;
|
class Model;
|
||||||
|
class Skeleton;
|
||||||
class ModelFramesWidget;
|
class ModelFramesWidget;
|
||||||
|
|
||||||
class ModelViewer : public QWidget
|
class ModelViewer : public QWidget
|
||||||
@ -20,6 +21,7 @@ class ModelViewer : public QWidget
|
|||||||
|
|
||||||
GameWorld* _world;
|
GameWorld* _world;
|
||||||
Model* viewing;
|
Model* viewing;
|
||||||
|
Skeleton* skeleton;
|
||||||
|
|
||||||
QSplitter* mainSplit;
|
QSplitter* mainSplit;
|
||||||
QVBoxLayout* mainLayout;
|
QVBoxLayout* mainLayout;
|
||||||
@ -39,8 +41,16 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display a raw model
|
||||||
|
*/
|
||||||
void showModel(Model* model);
|
void showModel(Model* model);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display a game object's model
|
||||||
|
*/
|
||||||
|
void showObject(uint16_t object);
|
||||||
|
|
||||||
void showData(GameWorld* world);
|
void showData(GameWorld* world);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include <models/ObjectListModel.hpp>
|
#include <models/ObjectListModel.hpp>
|
||||||
#include "ViewerWidget.hpp"
|
#include "ViewerWidget.hpp"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
ObjectViewer::ObjectViewer(ViewerWidget* viewer, QWidget* parent, Qt::WindowFlags f)
|
ObjectViewer::ObjectViewer(ViewerWidget* viewer, QWidget* parent, Qt::WindowFlags f)
|
||||||
: QWidget(parent, f)
|
: QWidget(parent, f)
|
||||||
@ -10,6 +11,13 @@ ObjectViewer::ObjectViewer(ViewerWidget* viewer, QWidget* parent, Qt::WindowFlag
|
|||||||
|
|
||||||
objectList = new QTableView;
|
objectList = new QTableView;
|
||||||
|
|
||||||
|
objectMenu = new QMenu(objectList);
|
||||||
|
objectList->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
auto viewModelAction = new QAction("View Model", objectMenu);
|
||||||
|
objectMenu->addAction(viewModelAction);
|
||||||
|
connect(viewModelAction, SIGNAL(triggered()), this, SLOT(menuViewModel()));
|
||||||
|
connect(objectList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onCustomContextMenu(QPoint)));
|
||||||
|
|
||||||
mainLayout->addWidget(objectList);
|
mainLayout->addWidget(objectList);
|
||||||
|
|
||||||
previewWidget = viewer;
|
previewWidget = viewer;
|
||||||
@ -27,8 +35,6 @@ ObjectViewer::ObjectViewer(ViewerWidget* viewer, QWidget* parent, Qt::WindowFlag
|
|||||||
infoLayout->addWidget(new QLabel("Model"), 3, 0);
|
infoLayout->addWidget(new QLabel("Model"), 3, 0);
|
||||||
infoLayout->addWidget(previewModel, 3, 1);
|
infoLayout->addWidget(previewModel, 3, 1);
|
||||||
|
|
||||||
//infoLayout->addStretch(100);
|
|
||||||
|
|
||||||
mainLayout->addLayout(infoLayout);
|
mainLayout->addLayout(infoLayout);
|
||||||
|
|
||||||
this->setLayout(mainLayout);
|
this->setLayout(mainLayout);
|
||||||
@ -77,8 +83,7 @@ void ObjectViewer::showItem(qint16 item)
|
|||||||
previewModel->setText(QString::fromStdString(v->modelName));
|
previewModel->setText(QString::fromStdString(v->modelName));
|
||||||
}
|
}
|
||||||
|
|
||||||
previewWidget->showItem(item);
|
previewWidget->showObject(item);
|
||||||
modelChanged( previewWidget->currentModel() );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,3 +112,22 @@ void ObjectViewer::showItem(QModelIndex model)
|
|||||||
showItem(model.internalId());
|
showItem(model.internalId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ObjectViewer::onCustomContextMenu(const QPoint& p)
|
||||||
|
{
|
||||||
|
contextMenuIndex = objectList->indexAt(p);
|
||||||
|
if ( contextMenuIndex.isValid() )
|
||||||
|
{
|
||||||
|
objectMenu->exec(objectList->mapToGlobal(p));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectViewer::menuViewModel()
|
||||||
|
{
|
||||||
|
if( contextMenuIndex.isValid() )
|
||||||
|
{
|
||||||
|
auto id = contextMenuIndex.internalId();
|
||||||
|
showObjectModel(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,6 +25,9 @@ class ObjectViewer : public QWidget
|
|||||||
QLabel* previewID;
|
QLabel* previewID;
|
||||||
QLabel* previewModel;
|
QLabel* previewModel;
|
||||||
QLabel* previewClass;
|
QLabel* previewClass;
|
||||||
|
|
||||||
|
QMenu* objectMenu;
|
||||||
|
QModelIndex contextMenuIndex;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ObjectViewer(ViewerWidget *viewer = 0, QWidget* parent = 0, Qt::WindowFlags f = 0);
|
ObjectViewer(ViewerWidget *viewer = 0, QWidget* parent = 0, Qt::WindowFlags f = 0);
|
||||||
@ -40,6 +43,8 @@ signals:
|
|||||||
|
|
||||||
void modelChanged(Model* model);
|
void modelChanged(Model* model);
|
||||||
|
|
||||||
|
void showObjectModel(uint16_t object);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void showItem(qint16 item);
|
void showItem(qint16 item);
|
||||||
@ -50,6 +55,8 @@ private slots:
|
|||||||
|
|
||||||
void showItem(QModelIndex model);
|
void showItem(QModelIndex model);
|
||||||
|
|
||||||
|
void onCustomContextMenu(const QPoint &);
|
||||||
|
void menuViewModel();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -48,7 +48,7 @@ ModelFramesWidget::ModelFramesWidget(QWidget* parent, Qt::WindowFlags flags)
|
|||||||
setLayout(_layout);
|
setLayout(_layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelFramesWidget::setModel(Model *model)
|
void ModelFramesWidget::setModel(Model *model, Skeleton* skeleton)
|
||||||
{
|
{
|
||||||
if(framemodel) {
|
if(framemodel) {
|
||||||
delete framemodel;
|
delete framemodel;
|
||||||
@ -57,7 +57,7 @@ void ModelFramesWidget::setModel(Model *model)
|
|||||||
}
|
}
|
||||||
gmodel = model;
|
gmodel = model;
|
||||||
if(model != nullptr) {
|
if(model != nullptr) {
|
||||||
framemodel = new DFFFramesTreeModel(model, this);
|
framemodel = new DFFFramesTreeModel(model, skeleton, this);
|
||||||
tree->setModel(framemodel);
|
tree->setModel(framemodel);
|
||||||
tree->setDisabled(false);
|
tree->setDisabled(false);
|
||||||
connect(tree->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
|
connect(tree->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
|
||||||
|
@ -31,7 +31,7 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void setModel(Model *model);
|
void setModel(Model *model, Skeleton* skeleton);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user