1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-10 04:42:38 +01:00
openrw/rwviewer/views/ObjectViewer.cpp

92 lines
2.7 KiB
C++
Raw Normal View History

#include "ObjectViewer.hpp"
2014-09-21 17:13:01 +02:00
#include <QDebug>
#include <QMenu>
2016-09-09 22:13:21 +02:00
#include <models/ObjectListModel.hpp>
#include "ViewerWidget.hpp"
2016-09-09 22:13:21 +02:00
ObjectViewer::ObjectViewer(ViewerWidget* viewer, QWidget* parent,
Qt::WindowFlags f)
: ViewerInterface(parent, f) {
mainLayout = new QHBoxLayout;
2016-09-09 22:13:21 +02:00
objectList = new QTableView;
2016-09-09 22:13:21 +02:00
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)));
2016-09-09 22:13:21 +02:00
mainLayout->addWidget(objectList);
2016-09-09 22:13:21 +02:00
previewWidget = viewer;
previewWidget->setMinimumSize(250, 250);
2016-09-09 22:13:21 +02:00
infoLayout = new QGridLayout;
2016-09-09 22:13:21 +02:00
previewID = new QLabel;
previewModel = new QLabel;
previewClass = new QLabel;
infoLayout->addWidget(new QLabel("ID"), 1, 0);
infoLayout->addWidget(previewID, 1, 1);
infoLayout->addWidget(new QLabel("Type"), 2, 0);
infoLayout->addWidget(previewClass, 2, 1);
infoLayout->addWidget(new QLabel("Model"), 3, 0);
infoLayout->addWidget(previewModel, 3, 1);
2014-09-21 17:13:01 +02:00
2016-09-09 22:13:21 +02:00
mainLayout->addLayout(infoLayout);
2016-09-09 22:13:21 +02:00
this->setLayout(mainLayout);
2016-09-09 22:13:21 +02:00
setViewerWidget(previewWidget);
2014-09-21 17:13:01 +02:00
}
2016-09-09 22:13:21 +02:00
void ObjectViewer::setViewerWidget(ViewerWidget* widget) {
// widgetLayout->removeWidget(previewWidget);
previewWidget = widget;
infoLayout->addWidget(previewWidget, 0, 0, 1, 2);
}
2016-09-09 22:13:21 +02:00
void ObjectViewer::worldChanged() {
if (objectList->model()) {
delete objectList->model();
}
2016-09-09 22:13:21 +02:00
objectList->setModel(new ObjectListModel(world()->data, objectList));
connect(objectList->selectionModel(),
SIGNAL(currentChanged(QModelIndex, QModelIndex)), this,
SLOT(showItem(QModelIndex)));
}
2016-09-09 22:13:21 +02:00
void ObjectViewer::showItem(qint16 item) {
auto def = world()->data->modelinfo[item].get();
2016-09-09 22:13:21 +02:00
if (def) {
previewID->setText(QString::number(def->id()));
previewClass->setText(
QString::fromStdString(BaseModelInfo::getTypeName(def->type())));
previewModel->setText(QString::fromStdString(def->name));
2016-09-09 22:13:21 +02:00
previewWidget->showObject(item);
}
}
2016-09-09 22:13:21 +02:00
void ObjectViewer::showItem(QModelIndex model) {
showItem(model.internalId());
}
2016-09-09 22:13:21 +02:00
void ObjectViewer::onCustomContextMenu(const QPoint& p) {
contextMenuIndex = objectList->indexAt(p);
if (contextMenuIndex.isValid()) {
objectMenu->exec(objectList->mapToGlobal(p));
2016-09-09 22:13:21 +02:00
}
}
2016-09-09 22:13:21 +02:00
void ObjectViewer::menuViewModel() {
if (contextMenuIndex.isValid()) {
auto id = contextMenuIndex.internalId();
showObjectModel(id);
}
}