diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index edb7b3cb67..2b4b07f898 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -78,6 +78,17 @@ Menu::Menu() : Qt::CTRL | Qt::Key_G, appInstance->getAvatar(), SLOT(goHome())); + addActionToQMenuAndActionHash(fileMenu, + MenuOption::GoToDomain, + Qt::CTRL | Qt::Key_D, + this, + SLOT(goToDomain())); + addActionToQMenuAndActionHash(fileMenu, + MenuOption::GoToLocation, + Qt::CTRL | Qt::SHIFT | Qt::Key_L, + this, + SLOT(goToLocation())); + addDisabledActionAndSeparator(fileMenu, "Settings"); addActionToQMenuAndActionHash(fileMenu, MenuOption::SettingsImport, 0, this, SLOT(importSettings())); @@ -625,7 +636,7 @@ bool Menu::isVoxelModeActionChecked() { } void Menu::editPreferences() { - Application *applicationInstance = Application::getInstance(); + Application* applicationInstance = Application::getInstance(); QDialog dialog(applicationInstance->getGLWidget()); dialog.setWindowTitle("Interface Preferences"); QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom); @@ -669,9 +680,11 @@ void Menu::editPreferences() { dialog.connect(buttons, SIGNAL(rejected()), SLOT(reject())); layout->addWidget(buttons); - if (dialog.exec() != QDialog::Accepted) { - return; - } + int ret = dialog.exec(); + applicationInstance->getWindow()->activateWindow(); + if (ret != QDialog::Accepted) { + return; + } QByteArray newHostname; @@ -716,6 +729,118 @@ void Menu::editPreferences() { applicationInstance->resizeGL(applicationInstance->getGLWidget()->width(), applicationInstance->getGLWidget()->height()); } +void Menu::goToDomain() { + Application* applicationInstance = Application::getInstance(); + QDialog dialog(applicationInstance->getGLWidget()); + dialog.setWindowTitle("Go To Domain"); + QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom); + dialog.setLayout(layout); + + QFormLayout* form = new QFormLayout(); + layout->addLayout(form, 1); + + const int QLINE_MINIMUM_WIDTH = 400; + + QLineEdit* domainServerHostname = new QLineEdit(QString(NodeList::getInstance()->getDomainHostname())); + domainServerHostname->setMinimumWidth(QLINE_MINIMUM_WIDTH); + form->addRow("Domain server:", domainServerHostname); + + QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + dialog.connect(buttons, SIGNAL(accepted()), SLOT(accept())); + dialog.connect(buttons, SIGNAL(rejected()), SLOT(reject())); + layout->addWidget(buttons); + + int ret = dialog.exec(); + applicationInstance->getWindow()->activateWindow(); + if (ret != QDialog::Accepted) { + return; + } + + QByteArray newHostname; + + if (domainServerHostname->text().size() > 0) { + // the user input a new hostname, use that + newHostname = domainServerHostname->text().toLocal8Bit(); + } else { + // the user left the field blank, use the default hostname + newHostname = QByteArray(DEFAULT_DOMAIN_HOSTNAME); + } + + // check if the domain server hostname is new + if (memcmp(NodeList::getInstance()->getDomainHostname(), newHostname.constData(), newHostname.size()) != 0) { + + NodeList::getInstance()->clear(); + + // kill the local voxels + applicationInstance->getVoxels()->killLocalVoxels(); + + // reset the environment to default + applicationInstance->getEnvironment()->resetToDefault(); + + // set the new hostname + NodeList::getInstance()->setDomainHostname(newHostname.constData()); + } +} + +void Menu::goToLocation() { + Application* applicationInstance = Application::getInstance(); + QDialog dialog(applicationInstance->getGLWidget()); + dialog.setWindowTitle("Go To Location"); + QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom); + dialog.setLayout(layout); + + QFormLayout* form = new QFormLayout(); + layout->addLayout(form, 1); + + const int QLINE_MINIMUM_WIDTH = 300; + + Application* appInstance = Application::getInstance(); + MyAvatar* myAvatar = appInstance->getAvatar(); + glm::vec3 avatarPos = myAvatar->getPosition(); + QString currentLocation = QString("%1, %2, %3").arg(QString::number(avatarPos.x), + QString::number(avatarPos.y), QString::number(avatarPos.z)); + + QLineEdit* coordinates = new QLineEdit(currentLocation); + coordinates->setMinimumWidth(QLINE_MINIMUM_WIDTH); + form->addRow("Coordinates as x,y,z:", coordinates); + + QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + dialog.connect(buttons, SIGNAL(accepted()), SLOT(accept())); + dialog.connect(buttons, SIGNAL(rejected()), SLOT(reject())); + layout->addWidget(buttons); + + int ret = dialog.exec(); + applicationInstance->getWindow()->activateWindow(); + if (ret != QDialog::Accepted) { + return; + } + + QByteArray newCoordinates; + + if (coordinates->text().size() > 0) { + // the user input a new hostname, use that + + QString delimiterPattern(","); + QStringList coordinateItems = coordinates->text().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) { + qDebug("Going To Location: %f, %f, %f...\n", x, y, z); + myAvatar->setPosition(newAvatarPos); + } + } + } +} + void Menu::bandwidthDetails() { diff --git a/interface/src/Menu.h b/interface/src/Menu.h index e484fe5c04..37d1644e5c 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -62,6 +62,8 @@ public slots: private slots: void editPreferences(); + void goToDomain(); + void goToLocation(); void bandwidthDetailsClosed(); void voxelStatsDetailsClosed(); void cycleFrustumRenderMode(); @@ -143,6 +145,8 @@ namespace MenuOption { const QString FrustumRenderMode = "Render Mode"; const QString Fullscreen = "Fullscreen"; const QString GlowMode = "Cycle Glow Mode"; + const QString GoToDomain = "Go To Domain..."; + const QString GoToLocation = "Go To Location..."; const QString ImportVoxels = "Import Voxels"; const QString ImportVoxelsClipboard = "Import Voxels to Clipboard"; const QString IncreaseAvatarSize = "Increase Avatar Size";