mirror of
https://github.com/rwengine/openrw.git
synced 2024-09-03 00:59:47 +02: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;
|
||||
}
|
||||
|
||||
void ViewerWidget::showItem(qint16 item)
|
||||
void ViewerWidget::showObject(qint16 item)
|
||||
{
|
||||
currentObjectID = item;
|
||||
|
||||
@ -244,6 +244,11 @@ Model* ViewerWidget::currentModel() const
|
||||
return activeModel;
|
||||
}
|
||||
|
||||
GameObject* ViewerWidget::currentObject() const
|
||||
{
|
||||
return dummyObject;
|
||||
}
|
||||
|
||||
void ViewerWidget::mousePressEvent(QMouseEvent* e)
|
||||
{
|
||||
dragging = true;
|
||||
|
@ -55,12 +55,13 @@ public:
|
||||
virtual void paintGL();
|
||||
|
||||
Model *currentModel() const;
|
||||
GameObject* currentObject() const;
|
||||
|
||||
GameWorld* world();
|
||||
|
||||
public slots:
|
||||
|
||||
void showItem(qint16 item);
|
||||
void showObject(qint16 item);
|
||||
void showModel(Model* model);
|
||||
void selectFrame(ModelFrame* frame);
|
||||
|
||||
|
@ -57,7 +57,8 @@ ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags)
|
||||
viewSwitcher->addWidget(objectViewer);
|
||||
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 );
|
||||
|
||||
@ -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()
|
||||
{
|
||||
QSettings settings("OpenRW", "rwviewer");
|
||||
|
@ -63,6 +63,8 @@ private slots:
|
||||
|
||||
void switchWidget();
|
||||
|
||||
void showObjectModel(uint16_t object);
|
||||
|
||||
private:
|
||||
|
||||
QList<QAction*> recentGames;
|
||||
|
@ -1,8 +1,9 @@
|
||||
#include "DFFFramesTreeModel.hpp"
|
||||
#include <render/Model.hpp>
|
||||
#include <data/Skeleton.hpp>
|
||||
|
||||
DFFFramesTreeModel::DFFFramesTreeModel(Model *m, QObject* parent)
|
||||
: QAbstractItemModel(parent), model(m)
|
||||
DFFFramesTreeModel::DFFFramesTreeModel(Model *m, Skeleton* skel, QObject* parent)
|
||||
: 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());
|
||||
}
|
||||
}
|
||||
else if( role == Qt::CheckStateRole )
|
||||
{
|
||||
if( index.column() == 0 )
|
||||
{
|
||||
if( skeleton )
|
||||
{
|
||||
return skeleton->getData(f->getIndex()).enabled ?
|
||||
Qt::Checked : Qt::Unchecked;
|
||||
}
|
||||
}
|
||||
}
|
||||
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
|
||||
{
|
||||
if(orientation == Qt::Horizontal) {
|
||||
|
@ -5,20 +5,26 @@
|
||||
#include <engine/RWTypes.hpp>
|
||||
|
||||
class Model;
|
||||
class Skeleton;
|
||||
|
||||
class DFFFramesTreeModel : public QAbstractItemModel
|
||||
{
|
||||
Model* model;
|
||||
Skeleton* skeleton;
|
||||
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 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 parent(const QModelIndex& child) const;
|
||||
|
@ -1,10 +1,12 @@
|
||||
#include "ModelViewer.hpp"
|
||||
#include <widgets/ModelFramesWidget.hpp>
|
||||
#include "ViewerWidget.hpp"
|
||||
#include <data/Skeleton.hpp>
|
||||
#include <engine/GameObject.hpp>
|
||||
#include <QDebug>
|
||||
|
||||
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;
|
||||
mainLayout = new QVBoxLayout;
|
||||
@ -40,6 +42,19 @@ void ModelViewer::showData(GameWorld* world)
|
||||
void ModelViewer::showModel(Model* model)
|
||||
{
|
||||
viewing = model;
|
||||
if( skeleton )
|
||||
{
|
||||
delete skeleton;
|
||||
}
|
||||
skeleton = new Skeleton();
|
||||
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 Model;
|
||||
class Skeleton;
|
||||
class ModelFramesWidget;
|
||||
|
||||
class ModelViewer : public QWidget
|
||||
@ -20,6 +21,7 @@ class ModelViewer : public QWidget
|
||||
|
||||
GameWorld* _world;
|
||||
Model* viewing;
|
||||
Skeleton* skeleton;
|
||||
|
||||
QSplitter* mainSplit;
|
||||
QVBoxLayout* mainLayout;
|
||||
@ -39,8 +41,16 @@ public:
|
||||
|
||||
public slots:
|
||||
|
||||
/**
|
||||
* Display a raw model
|
||||
*/
|
||||
void showModel(Model* model);
|
||||
|
||||
/**
|
||||
* Display a game object's model
|
||||
*/
|
||||
void showObject(uint16_t object);
|
||||
|
||||
void showData(GameWorld* world);
|
||||
};
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include <models/ObjectListModel.hpp>
|
||||
#include "ViewerWidget.hpp"
|
||||
#include <QDebug>
|
||||
#include <QMenu>
|
||||
|
||||
ObjectViewer::ObjectViewer(ViewerWidget* viewer, QWidget* parent, Qt::WindowFlags f)
|
||||
: QWidget(parent, f)
|
||||
@ -10,6 +11,13 @@ ObjectViewer::ObjectViewer(ViewerWidget* viewer, QWidget* parent, Qt::WindowFlag
|
||||
|
||||
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);
|
||||
|
||||
previewWidget = viewer;
|
||||
@ -27,8 +35,6 @@ ObjectViewer::ObjectViewer(ViewerWidget* viewer, QWidget* parent, Qt::WindowFlag
|
||||
infoLayout->addWidget(new QLabel("Model"), 3, 0);
|
||||
infoLayout->addWidget(previewModel, 3, 1);
|
||||
|
||||
//infoLayout->addStretch(100);
|
||||
|
||||
mainLayout->addLayout(infoLayout);
|
||||
|
||||
this->setLayout(mainLayout);
|
||||
@ -77,8 +83,7 @@ void ObjectViewer::showItem(qint16 item)
|
||||
previewModel->setText(QString::fromStdString(v->modelName));
|
||||
}
|
||||
|
||||
previewWidget->showItem(item);
|
||||
modelChanged( previewWidget->currentModel() );
|
||||
previewWidget->showObject(item);
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,3 +112,22 @@ void ObjectViewer::showItem(QModelIndex model)
|
||||
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* previewModel;
|
||||
QLabel* previewClass;
|
||||
|
||||
QMenu* objectMenu;
|
||||
QModelIndex contextMenuIndex;
|
||||
public:
|
||||
|
||||
ObjectViewer(ViewerWidget *viewer = 0, QWidget* parent = 0, Qt::WindowFlags f = 0);
|
||||
@ -40,6 +43,8 @@ signals:
|
||||
|
||||
void modelChanged(Model* model);
|
||||
|
||||
void showObjectModel(uint16_t object);
|
||||
|
||||
public slots:
|
||||
|
||||
void showItem(qint16 item);
|
||||
@ -50,6 +55,8 @@ private slots:
|
||||
|
||||
void showItem(QModelIndex model);
|
||||
|
||||
void onCustomContextMenu(const QPoint &);
|
||||
void menuViewModel();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -48,7 +48,7 @@ ModelFramesWidget::ModelFramesWidget(QWidget* parent, Qt::WindowFlags flags)
|
||||
setLayout(_layout);
|
||||
}
|
||||
|
||||
void ModelFramesWidget::setModel(Model *model)
|
||||
void ModelFramesWidget::setModel(Model *model, Skeleton* skeleton)
|
||||
{
|
||||
if(framemodel) {
|
||||
delete framemodel;
|
||||
@ -57,7 +57,7 @@ void ModelFramesWidget::setModel(Model *model)
|
||||
}
|
||||
gmodel = model;
|
||||
if(model != nullptr) {
|
||||
framemodel = new DFFFramesTreeModel(model, this);
|
||||
framemodel = new DFFFramesTreeModel(model, skeleton, this);
|
||||
tree->setModel(framemodel);
|
||||
tree->setDisabled(false);
|
||||
connect(tree->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
|
||||
public slots:
|
||||
|
||||
void setModel(Model *model);
|
||||
void setModel(Model *model, Skeleton* skeleton);
|
||||
|
||||
signals:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user