Merge remote-tracking branch 'upstream/master' into plugins

This commit is contained in:
Brad Davis 2015-06-26 17:14:45 -07:00
commit 5ce79d6800
14 changed files with 207 additions and 86 deletions

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

View file

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

View file

@ -17,8 +17,9 @@
#include <avatar/AvatarManager.h> #include <avatar/AvatarManager.h>
#include <gpu/GLBackend.h> #include <gpu/GLBackend.h>
#include <CursorManager.h>
#include <Tooltip.h> #include "CursorManager.h"
#include "Tooltip.h"
#include "Application.h" #include "Application.h"
@ -128,9 +129,22 @@ ApplicationCompositor::ApplicationCompositor() {
_hoverItemId = entityItemID; _hoverItemId = entityItemID;
_hoverItemEnterUsecs = usecTimestampNow(); _hoverItemEnterUsecs = usecTimestampNow();
auto properties = entityScriptingInterface->getEntityProperties(_hoverItemId); 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(); auto cursor = Cursor::Manager::instance().getCursor();
if (!_hoverItemHref.isEmpty()) {
if (!href.isEmpty()) {
cursor->setIcon(Cursor::Icon::LINK); cursor->setIcon(Cursor::Icon::LINK);
} else { } else {
cursor->setIcon(Cursor::Icon::DEFAULT); cursor->setIcon(Cursor::Icon::DEFAULT);
@ -141,7 +155,10 @@ ApplicationCompositor::ApplicationCompositor() {
connect(entityScriptingInterface.data(), &EntityScriptingInterface::hoverLeaveEntity, [=](const EntityItemID& entityItemID, const MouseEvent& event) { connect(entityScriptingInterface.data(), &EntityScriptingInterface::hoverLeaveEntity, [=](const EntityItemID& entityItemID, const MouseEvent& event) {
if (_hoverItemId == entityItemID) { if (_hoverItemId == entityItemID) {
_hoverItemId = _noItemId; _hoverItemId = _noItemId;
_hoverItemHref.clear();
_hoverItemTitle.clear();
_hoverItemDescription.clear();
auto cursor = Cursor::Manager::instance().getCursor(); auto cursor = Cursor::Manager::instance().getCursor();
cursor->setIcon(Cursor::Icon::DEFAULT); cursor->setIcon(Cursor::Icon::DEFAULT);
if (!_tooltipId.isEmpty()) { if (!_tooltipId.isEmpty()) {
@ -754,10 +771,10 @@ glm::vec2 ApplicationCompositor::overlayToScreen(const glm::vec2& overlayPos) co
void ApplicationCompositor::updateTooltips() { void ApplicationCompositor::updateTooltips() {
if (_hoverItemId != _noItemId) { if (_hoverItemId != _noItemId) {
quint64 hoverDuration = usecTimestampNow() - _hoverItemEnterUsecs; 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 // TODO Enable and position the tooltip
_hoverItemEnterUsecs = UINT64_MAX; _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 // Support for hovering and tooltips
static EntityItemID _noItemId; static EntityItemID _noItemId;
EntityItemID _hoverItemId{ _noItemId }; EntityItemID _hoverItemId { _noItemId };
QString _hoverItemHref; QString _hoverItemTitle;
quint64 _hoverItemEnterUsecs{ 0 }; QString _hoverItemDescription;
quint64 _hoverItemEnterUsecs { 0 };
float _hmdUIAngularSize = DEFAULT_HMD_UI_ANGULAR_SIZE; float _hmdUIAngularSize = DEFAULT_HMD_UI_ANGULAR_SIZE;
float _textureFov{ glm::radians(DEFAULT_HMD_UI_ANGULAR_SIZE) }; float _textureFov{ glm::radians(DEFAULT_HMD_UI_ANGULAR_SIZE) };

View file

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

View file

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

View file

@ -340,8 +340,6 @@ void AddressManager::handleAPIError(QNetworkReply& errorReply) {
emit lookupResultsFinished(); emit lookupResultsFinished();
} }
const QString GET_PLACE = "/api/v1/places/%1";
void AddressManager::attemptPlaceNameLookup(const QString& lookupString, const QString& overridePath, LookupTrigger trigger) { 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 // assume this is a place name and see if we can get any info on it
QString placeName = QUrl::toPercentEncoding(lookupString); 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 DEFAULT_HIFI_ADDRESS = "hifi://entry";
const QString INDEX_PATH = "/"; const QString INDEX_PATH = "/";
const QString GET_PLACE = "/api/v1/places/%1";
typedef const glm::vec3& (*PositionGetter)(); typedef const glm::vec3& (*PositionGetter)();
typedef glm::quat (*OrientationGetter)(); typedef glm::quat (*OrientationGetter)();

View file

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

View file

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

View file

@ -1,5 +1,6 @@
// //
// Tooltip.cpp // Tooltip.cpp
// libraries/ui/src
// //
// Created by Bradley Austin Davis on 2015/04/14 // Created by Bradley Austin Davis on 2015/04/14
// Copyright 2015 High Fidelity, Inc. // Copyright 2015 High Fidelity, Inc.
@ -8,24 +9,41 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#include "Tooltip.h" #include "Tooltip.h"
#include <QUuid>
#include <QtCore/QJsonDocument>
#include <QtCore/QUuid>
#include <AccountManager.h>
#include <AddressManager.h>
HIFI_QML_DEF(Tooltip) HIFI_QML_DEF(Tooltip)
Tooltip::Tooltip(QQuickItem* parent) : QQuickItem(parent) { Tooltip::Tooltip(QQuickItem* parent) : QQuickItem(parent) {
connect(this, &Tooltip::titleChanged, this, &Tooltip::requestHyperlinkImage);
} }
Tooltip::~Tooltip() { Tooltip::~Tooltip() {
} }
QString Tooltip::text() const { void Tooltip::setTitle(const QString& title) {
return _text; if (title != _title) {
_title = title;
emit titleChanged();
}
} }
void Tooltip::setText(const QString& arg) { void Tooltip::setDescription(const QString& description) {
if (arg != _text) { if (description != _description) {
_text = arg; _description = description;
emit textChanged(); 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); QQuickItem::setVisible(visible);
} }
QString Tooltip::showTip(const QString& text) { QString Tooltip::showTip(const QString& title, const QString& description) {
const QString newTipId = QUuid().createUuid().toString(); const QString newTipId = QUuid().createUuid().toString();
Tooltip::show([&](QQmlContext*, QObject* object) { Tooltip::show([&](QQmlContext*, QObject* object) {
object->setObjectName(newTipId); object->setObjectName(newTipId);
object->setProperty("text", text); object->setProperty("title", title);
object->setProperty("description", description);
}); });
return newTipId; return newTipId;
} }
@ -49,3 +70,64 @@ void Tooltip::closeTip(const QString& tipId) {
that->deleteLater(); 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 // Tooltip.h
// libraries/ui/src
// //
// Created by Bradley Austin Davis on 2015/04/14 // Created by Bradley Austin Davis on 2015/04/14
// Copyright 2015 High Fidelity, Inc. // Copyright 2015 High Fidelity, Inc.
@ -12,6 +13,8 @@
#ifndef hifi_Tooltip_h #ifndef hifi_Tooltip_h
#define hifi_Tooltip_h #define hifi_Tooltip_h
#include <QtNetwork/QNetworkReply>
#include "OffscreenQmlDialog.h" #include "OffscreenQmlDialog.h"
class Tooltip : public QQuickItem class Tooltip : public QQuickItem
@ -20,26 +23,42 @@ class Tooltip : public QQuickItem
HIFI_QML_DECL HIFI_QML_DECL
private: 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: public:
Tooltip(QQuickItem* parent = 0); Tooltip(QQuickItem* parent = 0);
virtual ~Tooltip(); 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); static void closeTip(const QString& tipId);
public slots: public slots:
virtual void setVisible(bool v); 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: signals:
void textChanged(); void titleChanged();
void descriptionChanged();
void imageURLChanged();
private slots:
void handleAPIResponse(QNetworkReply& requestReply);
private: private:
QString _text; void requestHyperlinkImage();
QString _title;
QString _description;
QString _imageURL { "../images/no-picture-provided.svg" };
}; };
#endif // hifi_Tooltip_h #endif // hifi_Tooltip_h