From fd0c130dc2ea6d302d8eeea7c93f1ab9a6286f77 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 16 Apr 2015 22:20:49 -0700 Subject: [PATCH] Working on simplifying new dialog creation --- interface/resources/qml/AddressBarDialog.qml | 85 +++--- interface/resources/qml/CustomDialog.qml | 35 ++- interface/resources/qml/LoginDialog.qml | 286 +++++++++--------- interface/src/ui/AddressBarDialog.cpp | 6 +- interface/src/ui/AddressBarDialog.h | 8 +- interface/src/ui/LoginDialog.cpp | 5 +- interface/src/ui/LoginDialog.h | 8 +- .../render-utils/src/OffscreenQmlDialog.cpp | 18 ++ .../render-utils/src/OffscreenQmlDialog.h | 56 ++++ libraries/render-utils/src/OffscreenUi.h | 30 +- 10 files changed, 290 insertions(+), 247 deletions(-) create mode 100644 libraries/render-utils/src/OffscreenQmlDialog.cpp create mode 100644 libraries/render-utils/src/OffscreenQmlDialog.h diff --git a/interface/resources/qml/AddressBarDialog.qml b/interface/resources/qml/AddressBarDialog.qml index df06fabbe6..9508481309 100644 --- a/interface/resources/qml/AddressBarDialog.qml +++ b/interface/resources/qml/AddressBarDialog.qml @@ -4,8 +4,9 @@ import QtQuick.Controls 1.2 import QtQuick.Window 2.2 import QtQuick.Controls.Styles 1.3 -AddressBarDialog { - id: addressBarDialog +CustomDialog { + id: dialog + title: "Go to..." objectName: "AddressBarDialog" SystemPalette { id: myPalette; colorGroup: SystemPalette.Active } height: 128 @@ -14,70 +15,56 @@ AddressBarDialog { onVisibleChanged: { if (!visible) { reset(); - } else { - addressLine.focus = true - addressLine.forceActiveFocus() } } - Component.onCompleted: { - addressLine.focus = true - addressLine.forceActiveFocus() - } - function reset() { addressLine.text = "" goButton.source = "../images/address-bar-submit.svg" } - CustomDialog { - id: dialog - anchors.fill: parent - title: "Go to..." + AddressBarDialog { + id: addressBarDialog // The client area - Item { - id: item1 - anchors.fill: parent - anchors.margins: parent.margins - anchors.topMargin: parent.topMargin + anchors.fill: parent + anchors.margins: parent.margins + anchors.topMargin: parent.topMargin - CustomBorder { - height: 64 - anchors.left: parent.left - anchors.leftMargin: 0 - anchors.right: goButton.left - anchors.rightMargin: 8 - anchors.verticalCenter: parent.verticalCenter - CustomTextInput { - id: addressLine - anchors.fill: parent - helperText: "domain, location, @user, /x,y,z" - anchors.margins: 8 - onAccepted: { - addressBarDialog.loadAddress(addressLine.text) - } + CustomBorder { + height: 64 + anchors.left: parent.left + anchors.leftMargin: 0 + anchors.right: goButton.left + anchors.rightMargin: 8 + anchors.verticalCenter: parent.verticalCenter + CustomTextInput { + id: addressLine + anchors.fill: parent + helperText: "domain, location, @user, /x,y,z" + anchors.margins: 8 + onAccepted: { + addressBarDialog.loadAddress(addressLine.text) } } + } - Image { - id: goButton - width: 32 - height: 32 - anchors.right: parent.right - anchors.rightMargin: 8 - source: "../images/address-bar-submit.svg" - anchors.verticalCenter: parent.verticalCenter + Image { + id: goButton + width: 32 + height: 32 + anchors.right: parent.right + anchors.rightMargin: 8 + source: "../images/address-bar-submit.svg" + anchors.verticalCenter: parent.verticalCenter - MouseArea { - anchors.fill: parent - onClicked: { - parent.source = "../images/address-bar-submit-active.svg" - addressBarDialog.loadAddress(addressLine.text) - } + MouseArea { + anchors.fill: parent + onClicked: { + parent.source = "../images/address-bar-submit-active.svg" + addressBarDialog.loadAddress(addressLine.text) } } - } } } diff --git a/interface/resources/qml/CustomDialog.qml b/interface/resources/qml/CustomDialog.qml index 828cd80231..a681612f2c 100644 --- a/interface/resources/qml/CustomDialog.qml +++ b/interface/resources/qml/CustomDialog.qml @@ -7,10 +7,34 @@ import "hifiConstants.js" as HifiConstants Item { SystemPalette { id: myPalette; colorGroup: SystemPalette.Active } - id: dialog width: 256 height: 256 + scale: 0.0 + enabled: false + visible: false + + onEnabledChanged: { + scale = enabled ? 1.0 : 0.0 + } + + onScaleChanged: { + visible = (scale != 0.0); + } + + Component.onCompleted: { + scale = 1.0 + } + + Behavior on scale { + NumberAnimation { + //This specifies how long the animation takes + duration: 400 + //This selects an easing curve to interpolate with, the default is Easing.Linear + easing.type: Easing.InOutBounce + } + } + property int topMargin: dialog.height - clientBorder.height + 8 property int margins: 8 property string title @@ -54,11 +78,11 @@ Item { anchors.top: parent.top anchors.rightMargin: 4 drag { - target: dialog.parent + target: dialog minimumX: 0 minimumY: 0 - maximumX: dialog.parent.parent.width - dialog.parent.width - maximumY: dialog.parent.parent.height - dialog.parent.height + maximumX: dialog.parent.width - dialog.width + maximumY: dialog.parent.height - dialog.height } } Image { @@ -73,11 +97,10 @@ Item { MouseArea { anchors.fill: parent onClicked: { - dialog.parent.destroy() + dialog.destroy() } } } - } // header border CustomBorder { diff --git a/interface/resources/qml/LoginDialog.qml b/interface/resources/qml/LoginDialog.qml index c306f4ed7e..e96309f625 100644 --- a/interface/resources/qml/LoginDialog.qml +++ b/interface/resources/qml/LoginDialog.qml @@ -5,9 +5,9 @@ import QtQuick.Window 2.2 import QtQuick.Controls.Styles 1.3 import "hifiConstants.js" as HifiConstants -LoginDialog { +CustomDialog { + title: "Login" SystemPalette { id: myPalette; colorGroup: SystemPalette.Active } - id: loginDialog objectName: "LoginDialog" height: 512 width: 384 @@ -15,8 +15,6 @@ LoginDialog { onVisibleChanged: { if (!visible) { reset() - } else { - username.forceActiveFocus() } } @@ -26,163 +24,159 @@ LoginDialog { loginDialog.statusText = "" } - CustomDialog { + LoginDialog { + id: loginDialog anchors.fill: parent - title: "Login" - Item { - id: item1 - anchors.fill: parent - anchors.margins: parent.margins - anchors.topMargin: parent.topMargin - Column { - anchors.topMargin: 8 - anchors.right: parent.right - anchors.rightMargin: 0 - anchors.left: parent.left - anchors.top: parent.top - spacing: 8 + anchors.margins: parent.margins + anchors.topMargin: parent.topMargin + Column { + anchors.topMargin: 8 + anchors.right: parent.right + anchors.rightMargin: 0 + anchors.left: parent.left + anchors.top: parent.top + spacing: 8 - Image { - height: 64 - anchors.horizontalCenter: parent.horizontalCenter - width: 64 - source: "../images/hifi-logo.svg" - } + Image { + height: 64 + anchors.horizontalCenter: parent.horizontalCenter + width: 64 + source: "../images/hifi-logo.svg" + } - CustomBorder { - width: 304 - height: 64 - anchors.horizontalCenter: parent.horizontalCenter - CustomTextInput { - id: username - anchors.fill: parent - helperText: "Username or Email" - anchors.margins: 8 - KeyNavigation.tab: password - KeyNavigation.backtab: password - onAccepted: { - password.forceActiveFocus() - } + CustomBorder { + width: 304 + height: 64 + anchors.horizontalCenter: parent.horizontalCenter + CustomTextInput { + id: username + anchors.fill: parent + helperText: "Username or Email" + anchors.margins: 8 + KeyNavigation.tab: password + KeyNavigation.backtab: password + onAccepted: { + password.forceActiveFocus() } } - - CustomBorder { - width: 304 - height: 64 - anchors.horizontalCenter: parent.horizontalCenter - CustomTextInput { - id: password - anchors.fill: parent - echoMode: TextInput.Password - helperText: "Password" - anchors.margins: 8 - KeyNavigation.tab: username - KeyNavigation.backtab: username - onAccepted: { - if (username.text == "") { - username.forceActiveFocus() - } else { - loginDialog.login(username.text, password.text) - } - } - onFocusChanged: { - if (password.focus) { - password.selectAll() - } - } - } - } - - CustomText { - anchors.horizontalCenter: parent.horizontalCenter - textFormat: Text.StyledText - width: parent.width - height: 96 - wrapMode: Text.WordWrap - verticalAlignment: Text.AlignVCenter - horizontalAlignment: Text.AlignHCenter - text: loginDialog.statusText - } } - Column { - anchors.bottomMargin: 5 - anchors.right: parent.right - anchors.rightMargin: 0 - anchors.left: parent.left - anchors.bottom: parent.bottom - - Rectangle { - width: 192 - height: 64 - anchors.horizontalCenter: parent.horizontalCenter - color: HifiConstants.color - border.width: 0 - radius: 10 - - MouseArea { - anchors.bottom: parent.bottom - anchors.bottomMargin: 0 - anchors.top: parent.top - anchors.right: parent.right - anchors.left: parent.left - onClicked: { + CustomBorder { + width: 304 + height: 64 + anchors.horizontalCenter: parent.horizontalCenter + CustomTextInput { + id: password + anchors.fill: parent + echoMode: TextInput.Password + helperText: "Password" + anchors.margins: 8 + KeyNavigation.tab: username + KeyNavigation.backtab: username + onAccepted: { + if (username.text == "") { + username.forceActiveFocus() + } else { loginDialog.login(username.text, password.text) } } - - Row { - anchors.centerIn: parent - anchors.verticalCenter: parent.verticalCenter - spacing: 8 - Image { - id: loginIcon - height: 32 - width: 32 - source: "../images/login.svg" - } - CustomText { - text: "Login" - color: "white" - width: 64 - height: parent.height - } - } - - } - - CustomText { - width: parent.width - height: 24 - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - text:"Create Account" - font.pointSize: 12 - font.bold: true - color: HifiConstants.color - - MouseArea { - anchors.fill: parent - onClicked: { - loginDialog.openUrl(loginDialog.rootUrl + "/signup") + onFocusChanged: { + if (password.focus) { + password.selectAll() } } } + } - CustomText { - width: parent.width - height: 24 - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - font.pointSize: 12 - text: "Recover Password" - color: HifiConstants.color + CustomText { + anchors.horizontalCenter: parent.horizontalCenter + textFormat: Text.StyledText + width: parent.width + height: 96 + wrapMode: Text.WordWrap + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignHCenter + text: loginDialog.statusText + } + } - MouseArea { - anchors.fill: parent - onClicked: { - loginDialog.openUrl(loginDialog.rootUrl + "/users/password/new") - } + Column { + anchors.bottomMargin: 5 + anchors.right: parent.right + anchors.rightMargin: 0 + anchors.left: parent.left + anchors.bottom: parent.bottom + + Rectangle { + width: 192 + height: 64 + anchors.horizontalCenter: parent.horizontalCenter + color: HifiConstants.color + border.width: 0 + radius: 10 + + MouseArea { + anchors.bottom: parent.bottom + anchors.bottomMargin: 0 + anchors.top: parent.top + anchors.right: parent.right + anchors.left: parent.left + onClicked: { + loginDialog.login(username.text, password.text) + } + } + + Row { + anchors.centerIn: parent + anchors.verticalCenter: parent.verticalCenter + spacing: 8 + Image { + id: loginIcon + height: 32 + width: 32 + source: "../images/login.svg" + } + CustomText { + text: "Login" + color: "white" + width: 64 + height: parent.height + } + } + + } + + CustomText { + width: parent.width + height: 24 + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + text:"Create Account" + font.pointSize: 12 + font.bold: true + color: HifiConstants.color + + MouseArea { + anchors.fill: parent + onClicked: { + loginDialog.openUrl(loginDialog.rootUrl + "/signup") + } + } + } + + CustomText { + width: parent.width + height: 24 + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + font.pointSize: 12 + text: "Recover Password" + color: HifiConstants.color + + MouseArea { + anchors.fill: parent + onClicked: { + loginDialog.openUrl(loginDialog.rootUrl + "/users/password/new") } } } diff --git a/interface/src/ui/AddressBarDialog.cpp b/interface/src/ui/AddressBarDialog.cpp index 49158265ba..befeb40cce 100644 --- a/interface/src/ui/AddressBarDialog.cpp +++ b/interface/src/ui/AddressBarDialog.cpp @@ -17,17 +17,15 @@ QML_DIALOG_DEF(AddressBarDialog) -AddressBarDialog::AddressBarDialog(QQuickItem *parent) : QQuickItem(parent) { +AddressBarDialog::AddressBarDialog(QQuickItem *parent) : OffscreenQmlDialog(parent) { auto addressManager = DependencyManager::get(); connect(addressManager.data(), &AddressManager::lookupResultIsOffline, this, &AddressBarDialog::displayAddressOfflineMessage); connect(addressManager.data(), &AddressManager::lookupResultIsNotFound, this, &AddressBarDialog::displayAddressNotFoundMessage); connect(addressManager.data(), &AddressManager::lookupResultsFinished, this, &AddressBarDialog::hide); } - void AddressBarDialog::hide() { - setEnabled(false); - setVisible(false); + ((QQuickItem *)parent())->setEnabled(false); } void AddressBarDialog::loadAddress(const QString & address) { diff --git a/interface/src/ui/AddressBarDialog.h b/interface/src/ui/AddressBarDialog.h index 00e55ceb10..b4f4c44e0f 100644 --- a/interface/src/ui/AddressBarDialog.h +++ b/interface/src/ui/AddressBarDialog.h @@ -8,15 +8,13 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#pragma once #ifndef hifi_AddressBarDialog_h #define hifi_AddressBarDialog_h -#pragma once -#include +#include -#include "OffscreenUi.h" - -class AddressBarDialog : public QQuickItem +class AddressBarDialog : public OffscreenQmlDialog { Q_OBJECT QML_DIALOG_DECL diff --git a/interface/src/ui/LoginDialog.cpp b/interface/src/ui/LoginDialog.cpp index 3b164041fa..3637d824fb 100644 --- a/interface/src/ui/LoginDialog.cpp +++ b/interface/src/ui/LoginDialog.cpp @@ -17,7 +17,7 @@ QML_DIALOG_DEF(LoginDialog) -LoginDialog::LoginDialog(QQuickItem *parent) : QQuickItem(parent), _rootUrl(NetworkingConstants::METAVERSE_SERVER_URL.toString()) { +LoginDialog::LoginDialog(QQuickItem *parent) : OffscreenQmlDialog(parent), _rootUrl(NetworkingConstants::METAVERSE_SERVER_URL.toString()) { connect(&AccountManager::getInstance(), &AccountManager::loginComplete, this, &LoginDialog::handleLoginCompleted); connect(&AccountManager::getInstance(), &AccountManager::loginFailed, @@ -42,8 +42,7 @@ void LoginDialog::toggleAction() { } void LoginDialog::handleLoginCompleted(const QUrl& authURL) { - setEnabled(false); - setVisible(false); + hide(); } void LoginDialog::handleLoginFailed() { diff --git a/interface/src/ui/LoginDialog.h b/interface/src/ui/LoginDialog.h index 3c9a98a9a4..d3f54981a5 100644 --- a/interface/src/ui/LoginDialog.h +++ b/interface/src/ui/LoginDialog.h @@ -8,15 +8,13 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#pragma once #ifndef hifi_LoginDialog_h #define hifi_LoginDialog_h -#pragma once -#include +#include -#include "OffscreenUi.h" - -class LoginDialog : public QQuickItem +class LoginDialog : public OffscreenQmlDialog { Q_OBJECT QML_DIALOG_DECL diff --git a/libraries/render-utils/src/OffscreenQmlDialog.cpp b/libraries/render-utils/src/OffscreenQmlDialog.cpp new file mode 100644 index 0000000000..d6cfc9951b --- /dev/null +++ b/libraries/render-utils/src/OffscreenQmlDialog.cpp @@ -0,0 +1,18 @@ +// +// OffscreenQmlDialog.cpp +// +// Created by Bradley Austin Davis on 2015/04/14 +// Copyright 2015 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 "OffscreenQmlDialog.h" + +OffscreenQmlDialog::OffscreenQmlDialog(QQuickItem *parent) + : QQuickItem(parent) { } + +void OffscreenQmlDialog::hide() { + ((QQuickItem *)parent())->setEnabled(false); +} diff --git a/libraries/render-utils/src/OffscreenQmlDialog.h b/libraries/render-utils/src/OffscreenQmlDialog.h new file mode 100644 index 0000000000..6e94587fd2 --- /dev/null +++ b/libraries/render-utils/src/OffscreenQmlDialog.h @@ -0,0 +1,56 @@ +// +// OffscreenQmlDialog.h +// +// Created by Bradley Austin Davis on 2015/04/14 +// Copyright 2015 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 +// + +#pragma once +#ifndef hifi_OffscreenQmlDialog_h +#define hifi_OffscreenQmlDialog_h + +#include +#include "OffscreenUi.h" + +#define QML_DIALOG_DECL \ +private: \ + static const QString NAME; \ + static const QUrl QML; \ +public: \ + static void registerType(); \ + static void show(); \ + static void toggle(); \ +private: + +#define QML_DIALOG_DEF(x) \ + const QUrl x::QML = QUrl(#x ".qml"); \ + const QString x::NAME = #x; \ + \ + void x::registerType() { \ + qmlRegisterType("Hifi", 1, 0, NAME.toLocal8Bit().constData()); \ + } \ + \ + void x::show() { \ + auto offscreenUi = DependencyManager::get(); \ + offscreenUi->show(QML, NAME); \ + } \ + \ + void x::toggle() { \ + auto offscreenUi = DependencyManager::get(); \ + offscreenUi->toggle(QML, NAME); \ + } + +class OffscreenQmlDialog : public QQuickItem +{ + Q_OBJECT +public: + OffscreenQmlDialog(QQuickItem *parent = 0); + +protected: + void hide(); +}; + +#endif diff --git a/libraries/render-utils/src/OffscreenUi.h b/libraries/render-utils/src/OffscreenUi.h index 60302d9860..b9cf5d2226 100644 --- a/libraries/render-utils/src/OffscreenUi.h +++ b/libraries/render-utils/src/OffscreenUi.h @@ -33,34 +33,6 @@ #include "FboCache.h" #include "OffscreenGlCanvas.h" -#define QML_DIALOG_DECL \ -private: \ - static const QString NAME; \ - static const QUrl QML; \ -public: \ - static void registerType(); \ - static void show(); \ - static void toggle(); \ -private: - -#define QML_DIALOG_DEF(x) \ - const QUrl x::QML = QUrl(#x ".qml"); \ - const QString x::NAME = #x; \ - \ - void x::registerType() { \ - qmlRegisterType("Hifi", 1, 0, NAME.toLocal8Bit().constData()); \ - } \ - \ - void x::show() { \ - auto offscreenUi = DependencyManager::get(); \ - offscreenUi->show(QML, NAME); \ - } \ - \ - void x::toggle() { \ - auto offscreenUi = DependencyManager::get(); \ - offscreenUi->toggle(QML, NAME); \ - } - class OffscreenUi : public OffscreenGlCanvas, public Dependency { Q_OBJECT @@ -133,4 +105,4 @@ private: MouseTranslator _mouseTranslator{ [](const QPointF & p) { return p; } }; }; -#endif \ No newline at end of file +#endif