diff --git a/interface/resources/images/address-bar-submit-active.svg b/interface/resources/images/address-bar-submit-active.svg new file mode 100644 index 0000000000..313b366033 --- /dev/null +++ b/interface/resources/images/address-bar-submit-active.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + diff --git a/interface/resources/images/address-bar-submit.svg b/interface/resources/images/address-bar-submit.svg new file mode 100644 index 0000000000..df4d7e90f6 --- /dev/null +++ b/interface/resources/images/address-bar-submit.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index ce15f319cd..bf5241427f 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -921,12 +921,11 @@ void Application::keyPressEvent(QKeyEvent* event) { case Qt::Key_Return: case Qt::Key_Enter: - if (isMeta) { - Menu::getInstance()->triggerOption(MenuOption::AddressBar); - } else { - Menu::getInstance()->triggerOption(MenuOption::Chat); - } + Menu::getInstance()->triggerOption(MenuOption::AddressBar); + break; + case Qt::Key_Backslash: + Menu::getInstance()->triggerOption(MenuOption::Chat); break; case Qt::Key_N: diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index a4ef9cc022..cd5677e9e5 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -176,7 +176,7 @@ Menu::Menu() : SLOT(toggleLocationList())); addActionToQMenuAndActionHash(fileMenu, MenuOption::AddressBar, - Qt::CTRL | Qt::Key_Enter, + Qt::Key_Enter, this, SLOT(toggleAddressBar())); @@ -1156,22 +1156,13 @@ void Menu::changePrivateKey() { } void Menu::toggleAddressBar() { - - QInputDialog addressBarDialog(Application::getInstance()->getWindow()); - addressBarDialog.setWindowTitle("Address Bar"); - addressBarDialog.setWindowFlags(Qt::Sheet); - addressBarDialog.setLabelText("place, domain, @user, example.com, /position/orientation"); - - addressBarDialog.resize(addressBarDialog.parentWidget()->size().width() * DIALOG_RATIO_OF_WINDOW, - addressBarDialog.size().height()); - - int dialogReturn = addressBarDialog.exec(); - if (dialogReturn == QDialog::Accepted && !addressBarDialog.textValue().isEmpty()) { - // let the AddressManger figure out what to do with this - AddressManager::getInstance().handleLookupString(addressBarDialog.textValue()); + if (!_addressBarDialog) { + _addressBarDialog = new AddressBarDialog(); } - sendFakeEnterEvent(); + if (!_addressBarDialog->isVisible()) { + _addressBarDialog->show(); + } } void Menu::displayAddressOfflineMessage() { diff --git a/interface/src/Menu.h b/interface/src/Menu.h index c5588da074..b267ab8b2c 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -27,6 +27,7 @@ #include "SpeechRecognizer.h" #endif +#include "ui/AddressBarDialog.h" #include "ui/ChatWindow.h" #include "ui/DataWebDialog.h" #include "ui/JSConsole.h" @@ -298,6 +299,7 @@ private: QPointer _preferencesDialog; QPointer _attachmentsDialog; QPointer _animationsDialog; + QPointer _addressBarDialog; QPointer _loginDialog; bool _hasLoginDialogDisplayed; QAction* _chatAction; diff --git a/interface/src/ui/AddressBarDialog.cpp b/interface/src/ui/AddressBarDialog.cpp new file mode 100644 index 0000000000..25a4299d6c --- /dev/null +++ b/interface/src/ui/AddressBarDialog.cpp @@ -0,0 +1,131 @@ +// +// AddressBarDialog.cpp +// interface/src/ui +// +// Created by Stojce Slavkovski on 9/22/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "AddressBarDialog.h" +#include "AddressManager.h" +#include "Application.h" + +const QString ADDRESSBAR_GO_BUTTON_ICON = "images/address-bar-submit.svg"; +const QString ADDRESSBAR_GO_BUTTON_ACTIVE_ICON = "images/address-bar-submit-active.svg"; + +AddressBarDialog::AddressBarDialog() : + FramelessDialog(Application::getInstance()->getWindow(), 0, FramelessDialog::POSITION_TOP) { + + setAttribute(Qt::WA_DeleteOnClose, false); + setupUI(); +} + +void AddressBarDialog::setupUI() { + + const QString DIALOG_STYLESHEET = "font-family: Helvetica, Arial, sans-serif;"; + const QString ADDRESSBAR_PLACEHOLDER = "Go to: domain, @user, #location"; + const QString ADDRESSBAR_STYLESHEET = "padding: 0 10px;"; + const QString ADDRESSBAR_FONT_FAMILY = "Helvetica,Arial,sans-serif"; + const int ADDRESSBAR_FONT_SIZE = 20; + + const int ADDRESSBAR_MIN_WIDTH = 200; + const int ADDRESSBAR_MAX_WIDTH = 615; + const int ADDRESSBAR_HEIGHT = 54; + const int ADDRESSBAR_STRETCH = 60; + + const int BUTTON_SPACER_SIZE = 10; + const int DEFAULT_SPACER_SIZE = 20; + const int ADDRESS_LAYOUT_RIGHT_MARGIN = 10; + + const int GO_BUTTON_SIZE = 55; + const int CLOSE_BUTTON_SIZE = 16; + const QString CLOSE_BUTTON_ICON = "styles/close.svg"; + + const int DIALOG_HEIGHT = 100; + const int DIALOG_INITIAL_WIDTH = 560; + + setModal(true); + setWindowModality(Qt::WindowModal); + setHideOnBlur(false); + + QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + setSizePolicy(sizePolicy); + setMinimumSize(QSize(DIALOG_INITIAL_WIDTH, DIALOG_HEIGHT)); + setStyleSheet(DIALOG_STYLESHEET); + + _verticalLayout = new QVBoxLayout(this); + + _addressLayout = new QHBoxLayout(); + _addressLayout->setContentsMargins(0, 0, ADDRESS_LAYOUT_RIGHT_MARGIN, 0); + + _leftSpacer = new QSpacerItem(DEFAULT_SPACER_SIZE, + DEFAULT_SPACER_SIZE, + QSizePolicy::MinimumExpanding, + QSizePolicy::Minimum); + + _addressLayout->addItem(_leftSpacer); + + _addressLineEdit = new QLineEdit(this); + _addressLineEdit->setPlaceholderText(ADDRESSBAR_PLACEHOLDER); + QSizePolicy sizePolicyLineEdit(QSizePolicy::Preferred, QSizePolicy::Fixed); + sizePolicyLineEdit.setHorizontalStretch(ADDRESSBAR_STRETCH); + _addressLineEdit->setSizePolicy(sizePolicyLineEdit); + _addressLineEdit->setMinimumSize(QSize(ADDRESSBAR_MIN_WIDTH, ADDRESSBAR_HEIGHT)); + _addressLineEdit->setMaximumSize(QSize(ADDRESSBAR_MAX_WIDTH, ADDRESSBAR_HEIGHT)); + QFont font(ADDRESSBAR_FONT_FAMILY, ADDRESSBAR_FONT_SIZE); + _addressLineEdit->setFont(font); + _addressLineEdit->setStyleSheet(ADDRESSBAR_STYLESHEET); + _addressLayout->addWidget(_addressLineEdit); + + _buttonSpacer = new QSpacerItem(BUTTON_SPACER_SIZE, BUTTON_SPACER_SIZE, QSizePolicy::Fixed, QSizePolicy::Minimum); + _addressLayout->addItem(_buttonSpacer); + + _goButton = new QPushButton(this); + _goButton->setSizePolicy(sizePolicy); + _goButton->setMinimumSize(QSize(GO_BUTTON_SIZE, GO_BUTTON_SIZE)); + _goButton->setMaximumSize(QSize(GO_BUTTON_SIZE, GO_BUTTON_SIZE)); + _goButton->setIcon(QIcon(Application::resourcesPath() + ADDRESSBAR_GO_BUTTON_ICON)); + _goButton->setIconSize(QSize(GO_BUTTON_SIZE, GO_BUTTON_SIZE)); + _goButton->setDefault(true); + _goButton->setFlat(true); + _addressLayout->addWidget(_goButton); + + _rightSpacer = new QSpacerItem(DEFAULT_SPACER_SIZE, + DEFAULT_SPACER_SIZE, + QSizePolicy::MinimumExpanding, + QSizePolicy::Minimum); + + _addressLayout->addItem(_rightSpacer); + + _closeButton = new QPushButton(this); + _closeButton->setSizePolicy(sizePolicy); + _closeButton->setMinimumSize(QSize(CLOSE_BUTTON_SIZE, CLOSE_BUTTON_SIZE)); + _closeButton->setMaximumSize(QSize(CLOSE_BUTTON_SIZE, CLOSE_BUTTON_SIZE)); + QIcon icon(Application::resourcesPath() + CLOSE_BUTTON_ICON); + _closeButton->setIcon(icon); + _closeButton->setFlat(true); + _addressLayout->addWidget(_closeButton, 0, Qt::AlignRight); + + _verticalLayout->addLayout(_addressLayout); + + connect(_goButton, &QPushButton::clicked, this, &AddressBarDialog::accept); + connect(_closeButton, &QPushButton::clicked, this, &QDialog::close); +} + +void AddressBarDialog::showEvent(QShowEvent* event) { + _goButton->setIcon(QIcon(Application::resourcesPath() + ADDRESSBAR_GO_BUTTON_ICON)); + _addressLineEdit->setText(QString()); + FramelessDialog::showEvent(event); +} + +void AddressBarDialog::accept() { + if (!_addressLineEdit->text().isEmpty()) { + _goButton->setIcon(QIcon(Application::resourcesPath() + ADDRESSBAR_GO_BUTTON_ACTIVE_ICON)); + AddressManager& addressManager = AddressManager::getInstance(); + connect(&addressManager, &AddressManager::lookupResultsFinished, this, &QDialog::hide); + addressManager.handleLookupString(_addressLineEdit->text()); + } +} \ No newline at end of file diff --git a/interface/src/ui/AddressBarDialog.h b/interface/src/ui/AddressBarDialog.h new file mode 100644 index 0000000000..8f2cf2d7b8 --- /dev/null +++ b/interface/src/ui/AddressBarDialog.h @@ -0,0 +1,46 @@ +// +// AddressBarDialog.h +// interface/src/ui +// +// Created by Stojce Slavkovski on 9/22/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_AddressBarDialog_h +#define hifi_AddressBarDialog_h + +#include "FramelessDialog.h" + +#include +#include +#include +#include + +class AddressBarDialog : public FramelessDialog { + Q_OBJECT + +public: + AddressBarDialog(); + +private: + void setupUI(); + void showEvent(QShowEvent* event); + + QVBoxLayout *_verticalLayout; + QHBoxLayout *_addressLayout; + QSpacerItem *_leftSpacer; + QSpacerItem *_rightSpacer; + QSpacerItem *_buttonSpacer; + QPushButton *_goButton; + QPushButton *_closeButton; + QLineEdit *_addressLineEdit; + +private slots: + void accept(); + +}; + +#endif // hifi_AddressBarDialog_h diff --git a/libraries/networking/src/AddressManager.cpp b/libraries/networking/src/AddressManager.cpp index 8ea6d1107a..9a7da955d6 100644 --- a/libraries/networking/src/AddressManager.cpp +++ b/libraries/networking/src/AddressManager.cpp @@ -80,6 +80,7 @@ bool AddressManager::handleUrl(const QUrl& lookupUrl) { // if this is a relative path then handle it as a relative viewpoint handleRelativeViewpoint(lookupUrl.path()); + emit lookupResultsFinished(); } return false; @@ -149,6 +150,7 @@ void AddressManager::handleAPIResponse(const QJsonObject &jsonObject) { // we've been told that this result exists but is offline, emit our signal so the application can handle emit lookupResultIsOffline(); } + emit lookupResultsFinished(); } void AddressManager::handleAPIError(QNetworkReply& errorReply) { @@ -157,6 +159,7 @@ void AddressManager::handleAPIError(QNetworkReply& errorReply) { if (errorReply.error() == QNetworkReply::ContentNotFoundError) { emit lookupResultIsNotFound(); } + emit lookupResultsFinished(); } const QString GET_PLACE = "/api/v1/places/%1"; @@ -164,7 +167,7 @@ const QString GET_PLACE = "/api/v1/places/%1"; void AddressManager::attemptPlaceNameLookup(const QString& lookupString) { // assume this is a place name and see if we can get any info on it QString placeName = QUrl::toPercentEncoding(lookupString); - AccountManager::getInstance().authenticatedRequest(GET_PLACE.arg(placeName), + AccountManager::getInstance().unauthenticatedRequest(GET_PLACE.arg(placeName), QNetworkAccessManager::GetOperation, apiCallbackParameters()); } @@ -180,6 +183,7 @@ bool AddressManager::handleNetworkAddress(const QString& lookupString) { if (hostnameRegex.indexIn(lookupString) != -1) { emit possibleDomainChangeRequired(hostnameRegex.cap(0)); + emit lookupResultsFinished(); return true; } @@ -187,6 +191,7 @@ bool AddressManager::handleNetworkAddress(const QString& lookupString) { if (ipAddressRegex.indexIn(lookupString) != -1) { emit possibleDomainChangeRequired(ipAddressRegex.cap(0)); + emit lookupResultsFinished(); return true; } @@ -263,7 +268,7 @@ bool AddressManager::handleUsername(const QString& lookupString) { void AddressManager::goToUser(const QString& username) { QString formattedUsername = QUrl::toPercentEncoding(username); // this is a username - pull the captured name and lookup that user's location - AccountManager::getInstance().authenticatedRequest(GET_USER_LOCATION.arg(formattedUsername), + AccountManager::getInstance().unauthenticatedRequest(GET_USER_LOCATION.arg(formattedUsername), QNetworkAccessManager::GetOperation, apiCallbackParameters()); } diff --git a/libraries/networking/src/AddressManager.h b/libraries/networking/src/AddressManager.h index 2590e8f80c..f7cc7c52ee 100644 --- a/libraries/networking/src/AddressManager.h +++ b/libraries/networking/src/AddressManager.h @@ -37,6 +37,7 @@ public slots: void handleAPIError(QNetworkReply& errorReply); void goToUser(const QString& username); signals: + void lookupResultsFinished(); void lookupResultIsOffline(); void lookupResultIsNotFound(); void possibleDomainChangeRequired(const QString& newHostname);