mirror of
https://github.com/lubosz/overte.git
synced 2025-04-16 09:29:16 +02:00
initial image replacement for hyperlink preview
This commit is contained in:
parent
522b715628
commit
18e2b62ecc
6 changed files with 91 additions and 15 deletions
|
@ -55,7 +55,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
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include <gpu/GLBackend.h>
|
||||
|
||||
#include "CursorManager.h"
|
||||
#include "HyperLinkTooltip.h"
|
||||
#include "Tooltip.h"
|
||||
|
||||
#include "Application.h"
|
||||
|
||||
|
|
|
@ -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)();
|
||||
|
||||
|
|
|
@ -10,26 +10,22 @@
|
|||
//
|
||||
#include "Tooltip.h"
|
||||
|
||||
#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() {
|
||||
|
||||
}
|
||||
|
||||
const QString& Tooltip::getTitle() const {
|
||||
return _title;
|
||||
}
|
||||
|
||||
const QString& Tooltip::getDescription() const {
|
||||
return _description;
|
||||
}
|
||||
|
||||
void Tooltip::setTitle(const QString& title) {
|
||||
if (title != _title) {
|
||||
_title = title;
|
||||
|
@ -44,6 +40,13 @@ void Tooltip::setDescription(const QString& description) {
|
|||
}
|
||||
}
|
||||
|
||||
void Tooltip::setImageURL(const QString& imageURL) {
|
||||
if (imageURL != _imageURL) {
|
||||
_imageURL = imageURL;
|
||||
emit imageURLChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void Tooltip::setVisible(bool visible) {
|
||||
QQuickItem::setVisible(visible);
|
||||
}
|
||||
|
@ -56,6 +59,7 @@ QString Tooltip::showTip(const QString& title, const QString& description) {
|
|||
object->setProperty("title", title);
|
||||
object->setProperty("description", description);
|
||||
});
|
||||
|
||||
return newTipId;
|
||||
}
|
||||
|
||||
|
@ -66,3 +70,60 @@ 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) {
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
#ifndef hifi_Tooltip_h
|
||||
#define hifi_Tooltip_h
|
||||
|
||||
#include <QtNetwork/QNetworkReply>
|
||||
|
||||
#include "OffscreenQmlDialog.h"
|
||||
|
||||
class Tooltip : public QQuickItem
|
||||
|
@ -23,29 +25,40 @@ class Tooltip : public QQuickItem
|
|||
private:
|
||||
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();
|
||||
|
||||
const QString& getTitle() const;
|
||||
const QString& getDescription() const;
|
||||
const QString& getTitle() const { return _title; }
|
||||
const QString& getDescription() const { return _description; }
|
||||
const QString& getImageURL() const { return _imageURL; }
|
||||
|
||||
static QString showTip(const QString& title, const QString& description);
|
||||
static void closeTip(const QString& tipId);
|
||||
|
||||
public slots:
|
||||
virtual void setVisible(bool v);
|
||||
|
||||
void setTitle(const QString& title);
|
||||
void setDescription(const QString& description);
|
||||
void setImageURL(const QString& imageURL);
|
||||
|
||||
signals:
|
||||
void titleChanged();
|
||||
void descriptionChanged();
|
||||
void imageURLChanged();
|
||||
|
||||
private slots:
|
||||
void handleAPIResponse(QNetworkReply& requestReply);
|
||||
|
||||
private:
|
||||
void requestHyperlinkImage();
|
||||
|
||||
QString _title;
|
||||
QString _description;
|
||||
QString _imageURL { "../images/NoPictureProvided.svg" };
|
||||
};
|
||||
|
||||
#endif // hifi_Tooltip_h
|
||||
|
|
Loading…
Reference in a new issue