Merge pull request #3183 from Atlante45/js_s3_browse

Js s3 browse
This commit is contained in:
Philip Rosedale 2014-07-17 18:31:30 -07:00
commit 2cee5992a0
6 changed files with 87 additions and 14 deletions

View file

@ -665,7 +665,8 @@ function checkController(deltaTime) {
moveOverlays(); moveOverlays();
} }
var newModel;
var browser;
function initToolBar() { function initToolBar() {
toolBar = new ToolBar(0, 0, ToolBar.VERTICAL); toolBar = new ToolBar(0, 0, ToolBar.VERTICAL);
// New Model // New Model
@ -676,6 +677,12 @@ function initToolBar() {
visible: true, visible: true,
alpha: 0.9 alpha: 0.9
}); });
browser = toolBar.addTool({
imageURL: toolIconUrl + "list-icon.png",
width: toolWidth, height: toolHeight,
visible: true,
alpha: 0.7
});
} }
function moveOverlays() { function moveOverlays() {
@ -780,8 +787,25 @@ function mousePressEvent(event) {
var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y});
if (newModel == toolBar.clicked(clickedOverlay)) { if (newModel == toolBar.clicked(clickedOverlay)) {
var url = Window.prompt("Model url", modelURLs[Math.floor(Math.random() * modelURLs.length)]); var url = Window.prompt("Model URL", modelURLs[Math.floor(Math.random() * modelURLs.length)]);
if (url == null) { 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; return;
} }

View file

@ -90,11 +90,18 @@ Tool = function(properties, selectable, selected) { // selectable and selected a
return selected; return selected;
} }
this.select = function(doSelect) { this.select = function(doSelect) {
if (!selectable) {
return;
}
selected = doSelect; selected = doSelect;
properties.subImage.y = (selected ? 2 : 1) * properties.subImage.height; properties.subImage.y = (selected ? 2 : 1) * properties.subImage.height;
Overlays.editOverlay(this.overlay(), { subImage: properties.subImage }); Overlays.editOverlay(this.overlay(), { subImage: properties.subImage });
} }
this.toggle = function() { this.toggle = function() {
if (!selectable) {
return;
}
selected = !selected; selected = !selected;
properties.subImage.y = (selected ? 2 : 1) * properties.subImage.height; properties.subImage.y = (selected ? 2 : 1) * properties.subImage.height;
Overlays.editOverlay(this.overlay(), { subImage: properties.subImage }); Overlays.editOverlay(this.overlay(), { subImage: properties.subImage });

View file

@ -18,6 +18,7 @@
#include "Application.h" #include "Application.h"
#include "Menu.h" #include "Menu.h"
#include "ui/ModelsBrowser.h"
#include "WindowScriptingInterface.h" #include "WindowScriptingInterface.h"
@ -66,6 +67,14 @@ QScriptValue WindowScriptingInterface::browse(const QString& title, const QStrin
return retVal; 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 /// Display an alert box
/// \param const QString& message message to display /// \param const QString& message message to display
/// \return QScriptValue::UndefinedValue /// \return QScriptValue::UndefinedValue
@ -191,6 +200,22 @@ QScriptValue WindowScriptingInterface::showBrowse(const QString& title, const QS
return QScriptValue::NullValue; 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() { int WindowScriptingInterface::getInnerWidth() {
return Application::getInstance()->getWindow()->geometry().width(); return Application::getInstance()->getWindow()->geometry().width();
} }

View file

@ -31,6 +31,7 @@ public slots:
QScriptValue form(const QString& title, QScriptValue array); QScriptValue form(const QString& title, QScriptValue array);
QScriptValue prompt(const QString& message = "", const QString& defaultText = ""); QScriptValue prompt(const QString& message = "", const QString& defaultText = "");
QScriptValue browse(const QString& title = "", const QString& directory = "", const QString& nameFilter = ""); QScriptValue browse(const QString& title = "", const QString& directory = "", const QString& nameFilter = "");
QScriptValue s3Browse(const QString& nameFilter = "");
private slots: private slots:
QScriptValue showAlert(const QString& message); QScriptValue showAlert(const QString& message);
@ -38,6 +39,7 @@ private slots:
QScriptValue showForm(const QString& title, QScriptValue form); QScriptValue showForm(const QString& title, QScriptValue form);
QScriptValue showPrompt(const QString& message, const QString& defaultText); QScriptValue showPrompt(const QString& message, const QString& defaultText);
QScriptValue showBrowse(const QString& title, const QString& directory, const QString& nameFilter); QScriptValue showBrowse(const QString& title, const QString& directory, const QString& nameFilter);
QScriptValue showS3Browse(const QString& nameFilter);
private: private:
WindowScriptingInterface(); WindowScriptingInterface();

View file

@ -23,7 +23,7 @@
#include "ModelsBrowser.h" #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 S3_URL = "http://highfidelity-public.s3-us-west-1.amazonaws.com";
static const QString PUBLIC_URL = "http://public.highfidelity.io"; 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) // Hid the row if it doesn't match (Make sure it's not it it does)
if (match) { _view.setRowHidden(i, QModelIndex(), !match);
_view.setRowHidden(i, QModelIndex(), false);
} else {
_view.setRowHidden(i, QModelIndex(), true);
}
} }
_handler->unlockModel(); _handler->unlockModel();
} }
@ -142,7 +138,13 @@ void ModelsBrowser::enableSearchBar() {
_searchBar->setEnabled(true); _searchBar->setEnabled(true);
} }
void ModelsBrowser::setNameFilter(QString nameFilter) {
_handler->setNameFilter(nameFilter);
}
void ModelsBrowser::browse() { void ModelsBrowser::browse() {
_selectedFile = "";
QDialog dialog; QDialog dialog;
dialog.setWindowTitle("Browse models"); dialog.setWindowTitle("Browse models");
dialog.setMinimumSize(570, 500); dialog.setMinimumSize(570, 500);
@ -160,14 +162,16 @@ void ModelsBrowser::browse() {
dialog.connect(buttons, SIGNAL(accepted()), SLOT(accept())); dialog.connect(buttons, SIGNAL(accepted()), SLOT(accept()));
dialog.connect(buttons, SIGNAL(rejected()), SLOT(reject())); dialog.connect(buttons, SIGNAL(rejected()), SLOT(reject()));
QVariant selectedFile;
if (dialog.exec() == QDialog::Accepted) { if (dialog.exec() == QDialog::Accepted) {
_handler->lockModel(); _handler->lockModel();
QVariant selectedFile = _handler->getModel()->data(_view.currentIndex(), Qt::UserRole); selectedFile = _handler->getModel()->data(_view.currentIndex(), Qt::UserRole);
_handler->unlockModel(); _handler->unlockModel();
if (selectedFile.isValid()) { if (selectedFile.isValid()) {
emit selected(selectedFile.toString()); _selectedFile = selectedFile.toString();
} }
} }
emit selected(_selectedFile);
// So that we don't have to reconstruct the view // So that we don't have to reconstruct the view
_view.setParent(NULL); _view.setParent(NULL);
@ -177,7 +181,8 @@ void ModelsBrowser::browse() {
ModelHandler::ModelHandler(ModelType modelsType, QWidget* parent) : ModelHandler::ModelHandler(ModelType modelsType, QWidget* parent) :
QObject(parent), QObject(parent),
_initiateExit(false), _initiateExit(false),
_type(modelsType) _type(modelsType),
_nameFilter(".*(fst|fbx|FST|FBX)")
{ {
// set headers data // set headers data
QStringList headerData; QStringList headerData;
@ -187,6 +192,10 @@ ModelHandler::ModelHandler(ModelType modelsType, QWidget* parent) :
_model.setHorizontalHeaderLabels(headerData); _model.setHorizontalHeaderLabels(headerData);
} }
void ModelHandler::setNameFilter(QString nameFilter) {
_nameFilter = nameFilter;
}
void ModelHandler::download() { void ModelHandler::download() {
_lock.lockForWrite(); _lock.lockForWrite();
if (_initiateExit) { if (_initiateExit) {
@ -278,7 +287,7 @@ bool ModelHandler::parseXML(QByteArray xmlFile) {
} }
QXmlStreamReader xml(xmlFile); QXmlStreamReader xml(xmlFile);
QRegExp rx(".*fst"); QRegExp rx(_nameFilter);
bool truncated = false; bool truncated = false;
QString lastKey; QString lastKey;

View file

@ -17,6 +17,7 @@
#include <QTreeView> #include <QTreeView>
enum ModelType { enum ModelType {
ENTITY_MODEL,
HEAD_MODEL, HEAD_MODEL,
SKELETON_MODEL, SKELETON_MODEL,
ATTACHMENT_MODEL ATTACHMENT_MODEL
@ -38,6 +39,7 @@ signals:
void updated(); void updated();
public slots: public slots:
void setNameFilter(QString nameFilter);
void download(); void download();
void update(); void update();
void exit(); void exit();
@ -50,6 +52,7 @@ private:
ModelType _type; ModelType _type;
QReadWriteLock _lock; QReadWriteLock _lock;
QStandardItemModel _model; QStandardItemModel _model;
QString _nameFilter;
void queryNewFiles(QString marker = QString()); void queryNewFiles(QString marker = QString());
bool parseXML(QByteArray xmlFile); bool parseXML(QByteArray xmlFile);
@ -62,6 +65,7 @@ class ModelsBrowser : public QWidget {
public: public:
ModelsBrowser(ModelType modelsType, QWidget* parent = NULL); ModelsBrowser(ModelType modelsType, QWidget* parent = NULL);
QString getSelectedFile() { return _selectedFile; }
signals: signals:
void startDownloading(); void startDownloading();
@ -69,6 +73,7 @@ signals:
void selected(QString filename); void selected(QString filename);
public slots: public slots:
void setNameFilter(QString nameFilter);
void browse(); void browse();
private slots: private slots:
@ -80,6 +85,7 @@ private:
ModelHandler* _handler; ModelHandler* _handler;
QLineEdit* _searchBar; QLineEdit* _searchBar;
QTreeView _view; QTreeView _view;
QString _selectedFile;
}; };
#endif // hifi_ModelsBrowser_h #endif // hifi_ModelsBrowser_h