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,30 +15,18 @@ 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
@ -77,8 +66,6 @@ AddressBarDialog {
}
}
}
}
}
}

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,11 +24,8 @@ LoginDialog {
loginDialog.statusText = ""
}
CustomDialog {
anchors.fill: parent
title: "Login"
Item {
id: item1
LoginDialog {
id: loginDialog
anchors.fill: parent
anchors.margins: parent.margins
anchors.topMargin: parent.topMargin
@ -187,5 +182,4 @@ LoginDialog {
}
}
}
}
}

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