mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 13:50:35 +02:00
Merge remote-tracking branch 'upstream/master' into plugins
This commit is contained in:
commit
5ce79d6800
14 changed files with 207 additions and 86 deletions
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,7 +84,8 @@ private:
|
|||
// Support for hovering and tooltips
|
||||
static EntityItemID _noItemId;
|
||||
EntityItemID _hoverItemId { _noItemId };
|
||||
QString _hoverItemHref;
|
||||
QString _hoverItemTitle;
|
||||
QString _hoverItemDescription;
|
||||
quint64 _hoverItemEnterUsecs { 0 };
|
||||
|
||||
float _hmdUIAngularSize = DEFAULT_HMD_UI_ANGULAR_SIZE;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)();
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue