Working on simplifying new dialog creation

This commit is contained in:
Brad Davis 2015-04-16 22:20:49 -07:00
parent 759acfa175
commit fd0c130dc2
10 changed files with 290 additions and 247 deletions

View file

@ -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)
}
}
}
}
}

View file

@ -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 {

View file

@ -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")
}
}
}

View file

@ -17,17 +17,15 @@
QML_DIALOG_DEF(AddressBarDialog)
AddressBarDialog::AddressBarDialog(QQuickItem *parent) : QQuickItem(parent) {
AddressBarDialog::AddressBarDialog(QQuickItem *parent) : OffscreenQmlDialog(parent) {
auto addressManager = DependencyManager::get<AddressManager>();
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) {

View file

@ -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 <QQuickItem>
#include <OffscreenQmlDialog.h>
#include "OffscreenUi.h"
class AddressBarDialog : public QQuickItem
class AddressBarDialog : public OffscreenQmlDialog
{
Q_OBJECT
QML_DIALOG_DECL

View file

@ -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() {

View file

@ -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 <QQuickItem>
#include <OffscreenQmlDialog.h>
#include "OffscreenUi.h"
class LoginDialog : public QQuickItem
class LoginDialog : public OffscreenQmlDialog
{
Q_OBJECT
QML_DIALOG_DECL

View file

@ -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);
}

View file

@ -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 <QQuickItem>
#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<x>("Hifi", 1, 0, NAME.toLocal8Bit().constData()); \
} \
\
void x::show() { \
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \
offscreenUi->show(QML, NAME); \
} \
\
void x::toggle() { \
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \
offscreenUi->toggle(QML, NAME); \
}
class OffscreenQmlDialog : public QQuickItem
{
Q_OBJECT
public:
OffscreenQmlDialog(QQuickItem *parent = 0);
protected:
void hide();
};
#endif

View file

@ -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<x>("Hifi", 1, 0, NAME.toLocal8Bit().constData()); \
} \
\
void x::show() { \
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \
offscreenUi->show(QML, NAME); \
} \
\
void x::toggle() { \
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \
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
#endif