Merge branch 'master' of https://github.com/highfidelity/hifi into avatar-collision-sounds

This commit is contained in:
Howard Stearns 2015-06-27 08:37:30 -07:00
commit dc7360cdc2
21 changed files with 246 additions and 103 deletions

4
examples/html/jquery-2.1.4.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

@ -41,7 +41,7 @@ Hifi.Tooltip {
anchors.left: parent.left
anchors.right: parent.right
font.pixelSize: hifi.fonts.pixelSize * 2
text: root.text
text: root.title
wrapMode: Text.WrapAnywhere
/* Uncomment for debugging to see the extent of the
@ -63,7 +63,9 @@ Hifi.Tooltip {
Image {
id: tooltipPic
source: "../images/NoPictureProvided.svg"
source: root.imageURL
height: 180
width: 320
anchors.left: parent.left
anchors.right: parent.right
verticalAlignment: Image.AlignVCenter
@ -75,8 +77,8 @@ Hifi.Tooltip {
width: border.implicitWidth
anchors.left: parent.left
anchors.right: parent.right
text: root.description
font.pixelSize: hifi.fonts.pixelSize
text: root.text
wrapMode: Text.WrapAnywhere
}
}

View file

@ -13,14 +13,14 @@
#include <QScriptEngine>
#ifdef __GNUC__
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdouble-promotion"
#endif
#include <glm/gtx/string_cast.hpp>
#ifdef __GNUC__
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif

View file

@ -17,8 +17,9 @@
#include <avatar/AvatarManager.h>
#include <gpu/GLBackend.h>
#include <CursorManager.h>
#include <Tooltip.h>
#include "CursorManager.h"
#include "Tooltip.h"
#include "Application.h"
@ -128,9 +129,22 @@ ApplicationCompositor::ApplicationCompositor() {
_hoverItemId = entityItemID;
_hoverItemEnterUsecs = usecTimestampNow();
auto properties = entityScriptingInterface->getEntityProperties(_hoverItemId);
_hoverItemHref = properties.getHref();
// check the format of this href string before we parse it
QString hrefString = properties.getHref();
if (!hrefString.startsWith("hifi:")) {
hrefString.prepend("hifi://");
}
// parse out a QUrl from the hrefString
QUrl href = QUrl(hrefString);
_hoverItemTitle = href.host();
_hoverItemDescription = properties.getDescription();
auto cursor = Cursor::Manager::instance().getCursor();
if (!_hoverItemHref.isEmpty()) {
if (!href.isEmpty()) {
cursor->setIcon(Cursor::Icon::LINK);
} else {
cursor->setIcon(Cursor::Icon::DEFAULT);
@ -141,7 +155,10 @@ ApplicationCompositor::ApplicationCompositor() {
connect(entityScriptingInterface.data(), &EntityScriptingInterface::hoverLeaveEntity, [=](const EntityItemID& entityItemID, const MouseEvent& event) {
if (_hoverItemId == entityItemID) {
_hoverItemId = _noItemId;
_hoverItemHref.clear();
_hoverItemTitle.clear();
_hoverItemDescription.clear();
auto cursor = Cursor::Manager::instance().getCursor();
cursor->setIcon(Cursor::Icon::DEFAULT);
if (!_tooltipId.isEmpty()) {
@ -754,10 +771,10 @@ glm::vec2 ApplicationCompositor::overlayToScreen(const glm::vec2& overlayPos) co
void ApplicationCompositor::updateTooltips() {
if (_hoverItemId != _noItemId) {
quint64 hoverDuration = usecTimestampNow() - _hoverItemEnterUsecs;
if (_hoverItemEnterUsecs != UINT64_MAX && !_hoverItemHref.isEmpty() && hoverDuration > TOOLTIP_DELAY) {
if (_hoverItemEnterUsecs != UINT64_MAX && !_hoverItemTitle.isEmpty() && hoverDuration > TOOLTIP_DELAY) {
// TODO Enable and position the tooltip
_hoverItemEnterUsecs = UINT64_MAX;
_tooltipId = Tooltip::showTip("URL: " + _hoverItemHref);
_tooltipId = Tooltip::showTip(_hoverItemTitle, _hoverItemDescription);
}
}
}

View file

@ -83,9 +83,10 @@ private:
// Support for hovering and tooltips
static EntityItemID _noItemId;
EntityItemID _hoverItemId{ _noItemId };
QString _hoverItemHref;
quint64 _hoverItemEnterUsecs{ 0 };
EntityItemID _hoverItemId { _noItemId };
QString _hoverItemTitle;
QString _hoverItemDescription;
quint64 _hoverItemEnterUsecs { 0 };
float _hmdUIAngularSize = DEFAULT_HMD_UI_ANGULAR_SIZE;
float _textureFov{ glm::radians(DEFAULT_HMD_UI_ANGULAR_SIZE) };

View file

@ -11,7 +11,7 @@
#include "InterfaceConfig.h"
#ifdef __GNUC__
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdouble-promotion"
#endif
@ -20,7 +20,7 @@
#include <QTextBlock>
#include <QtGui>
#ifdef __GNUC__
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif

View file

@ -122,9 +122,9 @@ void EntityTreeRenderer::init() {
// first chance, we'll check for enter/leave entity events.
_lastAvatarPosition = _viewState->getAvatarPosition() + glm::vec3((float)TREE_SCALE);
connect(entityTree, &EntityTree::deletingEntity, this, &EntityTreeRenderer::deletingEntity);
connect(entityTree, &EntityTree::addingEntity, this, &EntityTreeRenderer::addingEntity);
connect(entityTree, &EntityTree::entityScriptChanging, this, &EntityTreeRenderer::entitySciptChanging);
connect(entityTree, &EntityTree::deletingEntity, this, &EntityTreeRenderer::deletingEntity, Qt::QueuedConnection);
connect(entityTree, &EntityTree::addingEntity, this, &EntityTreeRenderer::addingEntity, Qt::QueuedConnection);
connect(entityTree, &EntityTree::entityScriptChanging, this, &EntityTreeRenderer::entitySciptChanging, Qt::QueuedConnection);
}
void EntityTreeRenderer::shutdown() {

View file

@ -11,7 +11,7 @@
#include <QByteArray>
#ifdef __GNUC__
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdouble-promotion"
#endif
@ -19,7 +19,7 @@
#include <glm/gtx/quaternion.hpp>
#include <glm/gtx/string_cast.hpp>
#ifdef __GNUC__
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif

View file

@ -126,7 +126,7 @@ enum EntityPropertyList {
PROP_SCRIPT_TIMESTAMP,
////////////////////////////////////////////////////////////////////////////////////////////////////
// ATTENTION: add new properties ABOVE this line
// ATTENTION: add new properties to end of list just ABOVE this line
PROP_AFTER_LAST_ITEM,
////////////////////////////////////////////////////////////////////////////////////////////////////

View file

@ -340,8 +340,6 @@ void AddressManager::handleAPIError(QNetworkReply& errorReply) {
emit lookupResultsFinished();
}
const QString GET_PLACE = "/api/v1/places/%1";
void AddressManager::attemptPlaceNameLookup(const QString& lookupString, const QString& overridePath, LookupTrigger trigger) {
// assume this is a place name and see if we can get any info on it
QString placeName = QUrl::toPercentEncoding(lookupString);

View file

@ -26,6 +26,8 @@ const QString HIFI_URL_SCHEME = "hifi";
const QString DEFAULT_HIFI_ADDRESS = "hifi://entry";
const QString INDEX_PATH = "/";
const QString GET_PLACE = "/api/v1/places/%1";
typedef const glm::vec3& (*PositionGetter)();
typedef glm::quat (*OrientationGetter)();

View file

@ -743,6 +743,14 @@ void LimitedNodeList::startSTUNPublicSocketUpdate() {
// if we don't know the STUN IP yet we need to have ourselves be called once it is known
if (_stunSockAddr.getAddress().isNull()) {
connect(&_stunSockAddr, &HifiSockAddr::lookupCompleted, this, &LimitedNodeList::startSTUNPublicSocketUpdate);
// in case we just completely fail to lookup the stun socket - add a 10s timeout that will trigger the fail case
const quint64 STUN_DNS_LOOKUP_TIMEOUT_MSECS = 10 * 1000;
QTimer* stunLookupFailTimer = new QTimer(this);
connect(stunLookupFailTimer, &QTimer::timeout, this, &LimitedNodeList::possiblyTimeoutSTUNAddressLookup);
stunLookupFailTimer->start(STUN_DNS_LOOKUP_TIMEOUT_MSECS);
} else {
// setup our initial STUN timer here so we can quickly find out our public IP address
_initialSTUNTimer = new QTimer(this);
@ -758,6 +766,13 @@ void LimitedNodeList::startSTUNPublicSocketUpdate() {
}
}
void LimitedNodeList::possiblyTimeoutSTUNAddressLookup() {
if (_stunSockAddr.getAddress().isNull()) {
// our stun address is still NULL, but we've been waiting for long enough - time to force a fail
stopInitialSTUNUpdate(false);
}
}
void LimitedNodeList::stopInitialSTUNUpdate(bool success) {
_hasCompletedInitialSTUN = true;
@ -777,8 +792,6 @@ void LimitedNodeList::stopInitialSTUNUpdate(bool success) {
flagTimeForConnectionStep(ConnectionStep::SetPublicSocketFromSTUN);
}
assert(_initialSTUNTimer);
// stop our initial fast timer
if (_initialSTUNTimer) {
_initialSTUNTimer->stop();

View file

@ -317,6 +317,7 @@ protected:
}
private slots:
void flagTimeForConnectionStep(ConnectionStep connectionStep, quint64 timestamp);
void possiblyTimeoutSTUNAddressLookup();
};
#endif // hifi_LimitedNodeList_h

View file

@ -12,14 +12,14 @@
#ifndef hifi_ProgramObject_h
#define hifi_ProgramObject_h
#ifdef __GNUC__
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdouble-promotion"
#endif
#include <QGLShaderProgram>
#ifdef __GNUC__
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif

View file

@ -28,7 +28,7 @@ using glm::vec3;
using glm::vec4;
using glm::quat;
#ifdef __GNUC__
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdouble-promotion"
#endif
@ -37,7 +37,7 @@ using glm::quat;
#include <QtGui/QMatrix4x4>
#include <QtGui/QColor>
#ifdef __GNUC__
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif

View file

@ -63,6 +63,10 @@ void vec4FromScriptValue(const QScriptValue& object, glm::vec4& vec4) {
QScriptValue vec3toScriptValue(QScriptEngine* engine, const glm::vec3 &vec3) {
QScriptValue obj = engine->newObject();
if (vec3.x != vec3.x || vec3.y != vec3.y || vec3.z != vec3.z) {
// if vec3 contains a NaN don't try to convert it
return obj;
}
obj.setProperty("x", vec3.x);
obj.setProperty("y", vec3.y);
obj.setProperty("z", vec3.z);

View file

@ -1,5 +1,6 @@
//
// Tooltip.cpp
// libraries/ui/src
//
// Created by Bradley Austin Davis on 2015/04/14
// Copyright 2015 High Fidelity, Inc.
@ -8,24 +9,41 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "Tooltip.h"
#include <QUuid>
#include <QtCore/QJsonDocument>
#include <QtCore/QUuid>
#include <AccountManager.h>
#include <AddressManager.h>
HIFI_QML_DEF(Tooltip)
Tooltip::Tooltip(QQuickItem* parent) : QQuickItem(parent) {
connect(this, &Tooltip::titleChanged, this, &Tooltip::requestHyperlinkImage);
}
Tooltip::~Tooltip() {
}
QString Tooltip::text() const {
return _text;
void Tooltip::setTitle(const QString& title) {
if (title != _title) {
_title = title;
emit titleChanged();
}
}
void Tooltip::setText(const QString& arg) {
if (arg != _text) {
_text = arg;
emit textChanged();
void Tooltip::setDescription(const QString& description) {
if (description != _description) {
_description = description;
emit descriptionChanged();
}
}
void Tooltip::setImageURL(const QString& imageURL) {
if (imageURL != _imageURL) {
_imageURL = imageURL;
emit imageURLChanged();
}
}
@ -33,12 +51,15 @@ void Tooltip::setVisible(bool visible) {
QQuickItem::setVisible(visible);
}
QString Tooltip::showTip(const QString& text) {
QString Tooltip::showTip(const QString& title, const QString& description) {
const QString newTipId = QUuid().createUuid().toString();
Tooltip::show([&](QQmlContext*, QObject* object) {
object->setObjectName(newTipId);
object->setProperty("text", text);
object->setProperty("title", title);
object->setProperty("description", description);
});
return newTipId;
}
@ -49,3 +70,64 @@ void Tooltip::closeTip(const QString& tipId) {
that->deleteLater();
}
}
void Tooltip::requestHyperlinkImage() {
if (!_title.isEmpty()) {
// we need to decide if this is a place name - if so we should ask the API for the associated image
// and description (if we weren't given one via the entity properties)
const QString PLACE_NAME_REGEX_STRING = "^[0-9A-Za-z](([0-9A-Za-z]|-(?!-))*[^\\W_]$|$)";
QRegExp placeNameRegex(PLACE_NAME_REGEX_STRING);
if (placeNameRegex.indexIn(_title) != -1) {
// NOTE: I'm currently not 100% sure why the UI library needs networking, but it's linked for now
// so I'm leveraging that here to get the place preview. We could also do this from the interface side
// should the network link be removed from UI at a later date.
// we possibly have a valid place name - so ask the API for the associated info
AccountManager& accountManager = AccountManager::getInstance();
JSONCallbackParameters callbackParams;
callbackParams.jsonCallbackReceiver = this;
callbackParams.jsonCallbackMethod = "handleAPIResponse";
accountManager.sendRequest(GET_PLACE.arg(_title),
AccountManagerAuth::None,
QNetworkAccessManager::GetOperation,
callbackParams);
}
}
}
void Tooltip::handleAPIResponse(QNetworkReply& requestReply) {
// did a preview image come back?
QJsonObject responseObject = QJsonDocument::fromJson(requestReply.readAll()).object();
QJsonObject dataObject = responseObject["data"].toObject();
const QString PLACE_KEY = "place";
if (dataObject.contains(PLACE_KEY)) {
QJsonObject placeObject = dataObject[PLACE_KEY].toObject();
const QString PREVIEWS_KEY = "previews";
const QString LOBBY_KEY = "lobby";
if (placeObject.contains(PREVIEWS_KEY) && placeObject[PREVIEWS_KEY].toObject().contains(LOBBY_KEY)) {
// we have previews - time to change the image URL
setImageURL(placeObject[PREVIEWS_KEY].toObject()[LOBBY_KEY].toString());
}
if (_description.isEmpty()) {
const QString DESCRIPTION_KEY = "description";
// we have an empty description - did a non-empty desciption come back?
if (placeObject.contains(DESCRIPTION_KEY)) {
QString placeDescription = placeObject[DESCRIPTION_KEY].toString();
if (!placeDescription.isEmpty()) {
// we got a non-empty description so change our description to that
setDescription(placeDescription);
}
}
}
}
}

View file

@ -1,5 +1,6 @@
//
// Tooltip.h
// libraries/ui/src
//
// Created by Bradley Austin Davis on 2015/04/14
// Copyright 2015 High Fidelity, Inc.
@ -12,6 +13,8 @@
#ifndef hifi_Tooltip_h
#define hifi_Tooltip_h
#include <QtNetwork/QNetworkReply>
#include "OffscreenQmlDialog.h"
class Tooltip : public QQuickItem
@ -20,26 +23,42 @@ class Tooltip : public QQuickItem
HIFI_QML_DECL
private:
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
Q_PROPERTY(QString title READ getTitle WRITE setTitle NOTIFY titleChanged)
Q_PROPERTY(QString description READ getDescription WRITE setDescription NOTIFY descriptionChanged)
Q_PROPERTY(QString imageURL READ getImageURL WRITE setImageURL NOTIFY imageURLChanged)
public:
Tooltip(QQuickItem* parent = 0);
virtual ~Tooltip();
QString text() const;
const QString& getTitle() const { return _title; }
const QString& getDescription() const { return _description; }
const QString& getImageURL() const { return _imageURL; }
static QString showTip(const QString& text);
static QString showTip(const QString& title, const QString& description);
static void closeTip(const QString& tipId);
public slots:
virtual void setVisible(bool v);
void setText(const QString& arg);
void setTitle(const QString& title);
void setDescription(const QString& description);
void setImageURL(const QString& imageURL);
signals:
void textChanged();
void titleChanged();
void descriptionChanged();
void imageURLChanged();
private slots:
void handleAPIResponse(QNetworkReply& requestReply);
private:
QString _text;
void requestHyperlinkImage();
QString _title;
QString _description;
QString _imageURL { "../images/no-picture-provided.svg" };
};
#endif // hifi_Tooltip_h