mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 17:14:59 +02:00
commit
2cee5992a0
6 changed files with 87 additions and 14 deletions
|
@ -665,7 +665,8 @@ function checkController(deltaTime) {
|
|||
|
||||
moveOverlays();
|
||||
}
|
||||
|
||||
var newModel;
|
||||
var browser;
|
||||
function initToolBar() {
|
||||
toolBar = new ToolBar(0, 0, ToolBar.VERTICAL);
|
||||
// New Model
|
||||
|
@ -676,6 +677,12 @@ function initToolBar() {
|
|||
visible: true,
|
||||
alpha: 0.9
|
||||
});
|
||||
browser = toolBar.addTool({
|
||||
imageURL: toolIconUrl + "list-icon.png",
|
||||
width: toolWidth, height: toolHeight,
|
||||
visible: true,
|
||||
alpha: 0.7
|
||||
});
|
||||
}
|
||||
|
||||
function moveOverlays() {
|
||||
|
@ -780,8 +787,25 @@ function mousePressEvent(event) {
|
|||
var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y});
|
||||
|
||||
if (newModel == toolBar.clicked(clickedOverlay)) {
|
||||
var url = Window.prompt("Model url", modelURLs[Math.floor(Math.random() * modelURLs.length)]);
|
||||
if (url == null) {
|
||||
var url = Window.prompt("Model URL", modelURLs[Math.floor(Math.random() * modelURLs.length)]);
|
||||
if (url == null || url == "") {
|
||||
return;
|
||||
}
|
||||
|
||||
var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE));
|
||||
|
||||
if (position.x > 0 && position.y > 0 && position.z > 0) {
|
||||
Models.addModel({ position: position,
|
||||
radius: radiusDefault,
|
||||
modelURL: url
|
||||
});
|
||||
} else {
|
||||
print("Can't create model: Model would be out of bounds.");
|
||||
}
|
||||
|
||||
} else if (browser == toolBar.clicked(clickedOverlay)) {
|
||||
var url = Window.s3Browse();
|
||||
if (url == null || url == "") {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -90,11 +90,18 @@ Tool = function(properties, selectable, selected) { // selectable and selected a
|
|||
return selected;
|
||||
}
|
||||
this.select = function(doSelect) {
|
||||
if (!selectable) {
|
||||
return;
|
||||
}
|
||||
|
||||
selected = doSelect;
|
||||
properties.subImage.y = (selected ? 2 : 1) * properties.subImage.height;
|
||||
Overlays.editOverlay(this.overlay(), { subImage: properties.subImage });
|
||||
}
|
||||
this.toggle = function() {
|
||||
if (!selectable) {
|
||||
return;
|
||||
}
|
||||
selected = !selected;
|
||||
properties.subImage.y = (selected ? 2 : 1) * properties.subImage.height;
|
||||
Overlays.editOverlay(this.overlay(), { subImage: properties.subImage });
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include "Application.h"
|
||||
#include "Menu.h"
|
||||
#include "ui/ModelsBrowser.h"
|
||||
|
||||
#include "WindowScriptingInterface.h"
|
||||
|
||||
|
@ -66,6 +67,14 @@ QScriptValue WindowScriptingInterface::browse(const QString& title, const QStrin
|
|||
return retVal;
|
||||
}
|
||||
|
||||
QScriptValue WindowScriptingInterface::s3Browse(const QString& nameFilter) {
|
||||
QScriptValue retVal;
|
||||
QMetaObject::invokeMethod(this, "showS3Browse", Qt::BlockingQueuedConnection,
|
||||
Q_RETURN_ARG(QScriptValue, retVal),
|
||||
Q_ARG(const QString&, nameFilter));
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/// Display an alert box
|
||||
/// \param const QString& message message to display
|
||||
/// \return QScriptValue::UndefinedValue
|
||||
|
@ -182,7 +191,7 @@ QScriptValue WindowScriptingInterface::showBrowse(const QString& title, const QS
|
|||
fileInfo.setFile(directory, "__HIFI_INVALID_FILE__");
|
||||
path = fileInfo.filePath();
|
||||
}
|
||||
|
||||
|
||||
QFileDialog fileDialog(Application::getInstance()->getWindow(), title, path, nameFilter);
|
||||
fileDialog.setFileMode(QFileDialog::ExistingFile);
|
||||
if (fileDialog.exec()) {
|
||||
|
@ -191,6 +200,22 @@ QScriptValue WindowScriptingInterface::showBrowse(const QString& title, const QS
|
|||
return QScriptValue::NullValue;
|
||||
}
|
||||
|
||||
/// Display a browse window for S3 models
|
||||
/// \param const QString& nameFilter filter to filter filenames
|
||||
/// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue`
|
||||
QScriptValue WindowScriptingInterface::showS3Browse(const QString& nameFilter) {
|
||||
ModelsBrowser browser(ENTITY_MODEL);
|
||||
if (nameFilter != "") {
|
||||
browser.setNameFilter(nameFilter);
|
||||
}
|
||||
QEventLoop loop;
|
||||
connect(&browser, &ModelsBrowser::selected, &loop, &QEventLoop::quit);
|
||||
QMetaObject::invokeMethod(&browser, "browse", Qt::QueuedConnection);
|
||||
loop.exec();
|
||||
|
||||
return browser.getSelectedFile();
|
||||
}
|
||||
|
||||
int WindowScriptingInterface::getInnerWidth() {
|
||||
return Application::getInstance()->getWindow()->geometry().width();
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ public slots:
|
|||
QScriptValue form(const QString& title, QScriptValue array);
|
||||
QScriptValue prompt(const QString& message = "", const QString& defaultText = "");
|
||||
QScriptValue browse(const QString& title = "", const QString& directory = "", const QString& nameFilter = "");
|
||||
QScriptValue s3Browse(const QString& nameFilter = "");
|
||||
|
||||
private slots:
|
||||
QScriptValue showAlert(const QString& message);
|
||||
|
@ -38,6 +39,7 @@ private slots:
|
|||
QScriptValue showForm(const QString& title, QScriptValue form);
|
||||
QScriptValue showPrompt(const QString& message, const QString& defaultText);
|
||||
QScriptValue showBrowse(const QString& title, const QString& directory, const QString& nameFilter);
|
||||
QScriptValue showS3Browse(const QString& nameFilter);
|
||||
|
||||
private:
|
||||
WindowScriptingInterface();
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
#include "ModelsBrowser.h"
|
||||
|
||||
const char* MODEL_TYPE_NAMES[] = { "heads", "skeletons", "attachments" };
|
||||
const char* MODEL_TYPE_NAMES[] = { "entities", "heads", "skeletons", "attachments" };
|
||||
|
||||
static const QString S3_URL = "http://highfidelity-public.s3-us-west-1.amazonaws.com";
|
||||
static const QString PUBLIC_URL = "http://public.highfidelity.io";
|
||||
|
@ -122,11 +122,7 @@ void ModelsBrowser::applyFilter(const QString &filter) {
|
|||
}
|
||||
|
||||
// Hid the row if it doesn't match (Make sure it's not it it does)
|
||||
if (match) {
|
||||
_view.setRowHidden(i, QModelIndex(), false);
|
||||
} else {
|
||||
_view.setRowHidden(i, QModelIndex(), true);
|
||||
}
|
||||
_view.setRowHidden(i, QModelIndex(), !match);
|
||||
}
|
||||
_handler->unlockModel();
|
||||
}
|
||||
|
@ -142,7 +138,13 @@ void ModelsBrowser::enableSearchBar() {
|
|||
_searchBar->setEnabled(true);
|
||||
}
|
||||
|
||||
void ModelsBrowser::setNameFilter(QString nameFilter) {
|
||||
_handler->setNameFilter(nameFilter);
|
||||
}
|
||||
|
||||
void ModelsBrowser::browse() {
|
||||
_selectedFile = "";
|
||||
|
||||
QDialog dialog;
|
||||
dialog.setWindowTitle("Browse models");
|
||||
dialog.setMinimumSize(570, 500);
|
||||
|
@ -160,14 +162,16 @@ void ModelsBrowser::browse() {
|
|||
dialog.connect(buttons, SIGNAL(accepted()), SLOT(accept()));
|
||||
dialog.connect(buttons, SIGNAL(rejected()), SLOT(reject()));
|
||||
|
||||
QVariant selectedFile;
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
_handler->lockModel();
|
||||
QVariant selectedFile = _handler->getModel()->data(_view.currentIndex(), Qt::UserRole);
|
||||
selectedFile = _handler->getModel()->data(_view.currentIndex(), Qt::UserRole);
|
||||
_handler->unlockModel();
|
||||
if (selectedFile.isValid()) {
|
||||
emit selected(selectedFile.toString());
|
||||
_selectedFile = selectedFile.toString();
|
||||
}
|
||||
}
|
||||
emit selected(_selectedFile);
|
||||
|
||||
// So that we don't have to reconstruct the view
|
||||
_view.setParent(NULL);
|
||||
|
@ -177,7 +181,8 @@ void ModelsBrowser::browse() {
|
|||
ModelHandler::ModelHandler(ModelType modelsType, QWidget* parent) :
|
||||
QObject(parent),
|
||||
_initiateExit(false),
|
||||
_type(modelsType)
|
||||
_type(modelsType),
|
||||
_nameFilter(".*(fst|fbx|FST|FBX)")
|
||||
{
|
||||
// set headers data
|
||||
QStringList headerData;
|
||||
|
@ -187,6 +192,10 @@ ModelHandler::ModelHandler(ModelType modelsType, QWidget* parent) :
|
|||
_model.setHorizontalHeaderLabels(headerData);
|
||||
}
|
||||
|
||||
void ModelHandler::setNameFilter(QString nameFilter) {
|
||||
_nameFilter = nameFilter;
|
||||
}
|
||||
|
||||
void ModelHandler::download() {
|
||||
_lock.lockForWrite();
|
||||
if (_initiateExit) {
|
||||
|
@ -278,7 +287,7 @@ bool ModelHandler::parseXML(QByteArray xmlFile) {
|
|||
}
|
||||
|
||||
QXmlStreamReader xml(xmlFile);
|
||||
QRegExp rx(".*fst");
|
||||
QRegExp rx(_nameFilter);
|
||||
bool truncated = false;
|
||||
QString lastKey;
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <QTreeView>
|
||||
|
||||
enum ModelType {
|
||||
ENTITY_MODEL,
|
||||
HEAD_MODEL,
|
||||
SKELETON_MODEL,
|
||||
ATTACHMENT_MODEL
|
||||
|
@ -38,6 +39,7 @@ signals:
|
|||
void updated();
|
||||
|
||||
public slots:
|
||||
void setNameFilter(QString nameFilter);
|
||||
void download();
|
||||
void update();
|
||||
void exit();
|
||||
|
@ -50,6 +52,7 @@ private:
|
|||
ModelType _type;
|
||||
QReadWriteLock _lock;
|
||||
QStandardItemModel _model;
|
||||
QString _nameFilter;
|
||||
|
||||
void queryNewFiles(QString marker = QString());
|
||||
bool parseXML(QByteArray xmlFile);
|
||||
|
@ -62,6 +65,7 @@ class ModelsBrowser : public QWidget {
|
|||
public:
|
||||
|
||||
ModelsBrowser(ModelType modelsType, QWidget* parent = NULL);
|
||||
QString getSelectedFile() { return _selectedFile; }
|
||||
|
||||
signals:
|
||||
void startDownloading();
|
||||
|
@ -69,6 +73,7 @@ signals:
|
|||
void selected(QString filename);
|
||||
|
||||
public slots:
|
||||
void setNameFilter(QString nameFilter);
|
||||
void browse();
|
||||
|
||||
private slots:
|
||||
|
@ -80,6 +85,7 @@ private:
|
|||
ModelHandler* _handler;
|
||||
QLineEdit* _searchBar;
|
||||
QTreeView _view;
|
||||
QString _selectedFile;
|
||||
};
|
||||
|
||||
#endif // hifi_ModelsBrowser_h
|
||||
|
|
Loading…
Reference in a new issue