mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 02:47:50 +02:00
Custom URL handler
This commit is contained in:
parent
7fc66392cc
commit
b05967a514
4 changed files with 57 additions and 49 deletions
|
@ -101,6 +101,8 @@ const QString SKIP_FILENAME = QStandardPaths::writableLocation(QStandardPaths::D
|
||||||
|
|
||||||
const int STATS_PELS_PER_LINE = 20;
|
const int STATS_PELS_PER_LINE = 20;
|
||||||
|
|
||||||
|
const QString CUSTOM_URL_SCHEME = "hifi:";
|
||||||
|
|
||||||
void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) {
|
void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) {
|
||||||
if (message.size() > 0) {
|
if (message.size() > 0) {
|
||||||
QString messageWithNewLine = message + "\n";
|
QString messageWithNewLine = message + "\n";
|
||||||
|
@ -680,6 +682,21 @@ void Application::controlledBroadcastToNodes(const QByteArray& packet, const Nod
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Application::event(QEvent* event) {
|
||||||
|
|
||||||
|
// handle custom URL
|
||||||
|
if (event->type() == QEvent::FileOpen) {
|
||||||
|
QFileOpenEvent* fileEvent = static_cast<QFileOpenEvent*>(event);
|
||||||
|
if (!fileEvent->url().isEmpty() && fileEvent->url().toLocalFile().startsWith(CUSTOM_URL_SCHEME)) {
|
||||||
|
QString destination = fileEvent->url().toLocalFile().remove(QRegExp(CUSTOM_URL_SCHEME + "|/"));
|
||||||
|
Menu::getInstance()->goToDestination(destination);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return QApplication::event(event);
|
||||||
|
}
|
||||||
|
|
||||||
void Application::keyPressEvent(QKeyEvent* event) {
|
void Application::keyPressEvent(QKeyEvent* event) {
|
||||||
|
|
||||||
_controllerScriptingInterface.emitKeyPressEvent(event); // send events to any registered scripts
|
_controllerScriptingInterface.emitKeyPressEvent(event); // send events to any registered scripts
|
||||||
|
|
|
@ -127,7 +127,9 @@ public:
|
||||||
void touchUpdateEvent(QTouchEvent* event);
|
void touchUpdateEvent(QTouchEvent* event);
|
||||||
|
|
||||||
void wheelEvent(QWheelEvent* event);
|
void wheelEvent(QWheelEvent* event);
|
||||||
|
|
||||||
|
bool event(QEvent* event);
|
||||||
|
|
||||||
void makeVoxel(glm::vec3 position,
|
void makeVoxel(glm::vec3 position,
|
||||||
float scale,
|
float scale,
|
||||||
unsigned char red,
|
unsigned char red,
|
||||||
|
|
|
@ -913,6 +913,39 @@ void Menu::goToDomain() {
|
||||||
sendFakeEnterEvent();
|
sendFakeEnterEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Menu::goToDestination(QString destination) {
|
||||||
|
|
||||||
|
QStringList coordinateItems = destination.split(QRegExp("_|,"), QString::SkipEmptyParts);
|
||||||
|
|
||||||
|
const int NUMBER_OF_COORDINATE_ITEMS = 3;
|
||||||
|
const int X_ITEM = 0;
|
||||||
|
const int Y_ITEM = 1;
|
||||||
|
const int Z_ITEM = 2;
|
||||||
|
if (coordinateItems.size() == NUMBER_OF_COORDINATE_ITEMS) {
|
||||||
|
|
||||||
|
double x = replaceLastOccurrence('-', '.', coordinateItems[X_ITEM].trimmed()).toDouble();
|
||||||
|
double y = replaceLastOccurrence('-', '.', coordinateItems[Y_ITEM].trimmed()).toDouble();
|
||||||
|
double z = replaceLastOccurrence('-', '.', coordinateItems[Z_ITEM].trimmed()).toDouble();
|
||||||
|
|
||||||
|
glm::vec3 newAvatarPos(x, y, z);
|
||||||
|
|
||||||
|
MyAvatar* myAvatar = Application::getInstance()->getAvatar();
|
||||||
|
glm::vec3 avatarPos = myAvatar->getPosition();
|
||||||
|
if (newAvatarPos != avatarPos) {
|
||||||
|
// send a node kill request, indicating to other clients that they should play the "disappeared" effect
|
||||||
|
MyAvatar::sendKillAvatar();
|
||||||
|
|
||||||
|
qDebug("Going To Location: %f, %f, %f...", x, y, z);
|
||||||
|
myAvatar->setPosition(newAvatarPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// no coordinates were parsed
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void Menu::goTo() {
|
void Menu::goTo() {
|
||||||
|
|
||||||
QInputDialog gotoDialog(Application::getInstance()->getWindow());
|
QInputDialog gotoDialog(Application::getInstance()->getWindow());
|
||||||
|
@ -928,31 +961,8 @@ void Menu::goTo() {
|
||||||
|
|
||||||
destination = gotoDialog.textValue();
|
destination = gotoDialog.textValue();
|
||||||
|
|
||||||
QStringList coordinateItems = destination.split(QRegExp("_|,"), QString::SkipEmptyParts);
|
// go to coordinate destination or to Username
|
||||||
|
if (!goToDestination(destination)) {
|
||||||
const int NUMBER_OF_COORDINATE_ITEMS = 3;
|
|
||||||
const int X_ITEM = 0;
|
|
||||||
const int Y_ITEM = 1;
|
|
||||||
const int Z_ITEM = 2;
|
|
||||||
if (coordinateItems.size() == NUMBER_OF_COORDINATE_ITEMS) {
|
|
||||||
|
|
||||||
double x = replaceLastOccurrence('-', '.', coordinateItems[X_ITEM].trimmed()).toDouble();
|
|
||||||
double y = replaceLastOccurrence('-', '.', coordinateItems[Y_ITEM].trimmed()).toDouble();
|
|
||||||
double z = replaceLastOccurrence('-', '.', coordinateItems[Z_ITEM].trimmed()).toDouble();
|
|
||||||
|
|
||||||
glm::vec3 newAvatarPos(x, y, z);
|
|
||||||
|
|
||||||
MyAvatar* myAvatar = Application::getInstance()->getAvatar();
|
|
||||||
glm::vec3 avatarPos = myAvatar->getPosition();
|
|
||||||
if (newAvatarPos != avatarPos) {
|
|
||||||
// send a node kill request, indicating to other clients that they should play the "disappeared" effect
|
|
||||||
MyAvatar::sendKillAvatar();
|
|
||||||
|
|
||||||
qDebug("Going To Location: %f, %f, %f...", x, y, z);
|
|
||||||
myAvatar->setPosition(newAvatarPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// there's a username entered by the user, make a request to the data-server
|
// there's a username entered by the user, make a request to the data-server
|
||||||
DataServerClient::getValuesForKeysAndUserString(
|
DataServerClient::getValuesForKeysAndUserString(
|
||||||
QStringList()
|
QStringList()
|
||||||
|
@ -983,29 +993,7 @@ void Menu::goToLocation() {
|
||||||
|
|
||||||
int dialogReturn = coordinateDialog.exec();
|
int dialogReturn = coordinateDialog.exec();
|
||||||
if (dialogReturn == QDialog::Accepted && !coordinateDialog.textValue().isEmpty()) {
|
if (dialogReturn == QDialog::Accepted && !coordinateDialog.textValue().isEmpty()) {
|
||||||
QByteArray newCoordinates;
|
goToDestination(coordinateDialog.textValue());
|
||||||
|
|
||||||
QString delimiterPattern(",");
|
|
||||||
QStringList coordinateItems = coordinateDialog.textValue().split(delimiterPattern);
|
|
||||||
|
|
||||||
const int NUMBER_OF_COORDINATE_ITEMS = 3;
|
|
||||||
const int X_ITEM = 0;
|
|
||||||
const int Y_ITEM = 1;
|
|
||||||
const int Z_ITEM = 2;
|
|
||||||
if (coordinateItems.size() == NUMBER_OF_COORDINATE_ITEMS) {
|
|
||||||
double x = coordinateItems[X_ITEM].toDouble();
|
|
||||||
double y = coordinateItems[Y_ITEM].toDouble();
|
|
||||||
double z = coordinateItems[Z_ITEM].toDouble();
|
|
||||||
glm::vec3 newAvatarPos(x, y, z);
|
|
||||||
|
|
||||||
if (newAvatarPos != avatarPos) {
|
|
||||||
// send a node kill request, indicating to other clients that they should play the "disappeared" effect
|
|
||||||
MyAvatar::sendKillAvatar();
|
|
||||||
|
|
||||||
qDebug("Going To Location: %f, %f, %f...", x, y, z);
|
|
||||||
myAvatar->setPosition(newAvatarPos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sendFakeEnterEvent();
|
sendFakeEnterEvent();
|
||||||
|
|
|
@ -84,6 +84,7 @@ public:
|
||||||
const char* member = NULL,
|
const char* member = NULL,
|
||||||
QAction::MenuRole role = QAction::NoRole);
|
QAction::MenuRole role = QAction::NoRole);
|
||||||
virtual void removeAction(QMenu* menu, const QString& actionName);
|
virtual void removeAction(QMenu* menu, const QString& actionName);
|
||||||
|
bool goToDestination(QString destination);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void bandwidthDetails();
|
void bandwidthDetails();
|
||||||
|
|
Loading…
Reference in a new issue