Removing old infoview, testing new dialogs

This commit is contained in:
Brad Davis 2015-04-27 00:02:11 -07:00
parent 4740674da2
commit b216689b45
6 changed files with 27 additions and 142 deletions

View file

@ -1,4 +1,4 @@
import Hifi 1.0
import Hifi 1.0 as Hifi
import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.3
@ -7,11 +7,11 @@ import "controls"
Dialog {
id: root
width: 720
height: 1024
width: 800
height: 800
resizable: true
InfoView {
Hifi.InfoView {
id: infoView
// Fille the client area
anchors.fill: parent

View file

@ -84,7 +84,7 @@
#include <UserActivityLogger.h>
#include <UUID.h>
#include <MessageDialog.h>
#include <InfoView.h>
#include <SceneScriptingInterface.h>
#include "Application.h"
@ -132,7 +132,6 @@
#include "ui/DataWebDialog.h"
#include "ui/DialogsManager.h"
#include "ui/InfoView.h"
#include "ui/LoginDialog.h"
#include "ui/Snapshot.h"
#include "ui/StandAloneJSConsole.h"
@ -761,8 +760,8 @@ void Application::initializeGL() {
// update before the first render
update(1.0f / _fps);
InfoView::showFirstTime(INFO_HELP_PATH);
InfoView::show(INFO_HELP_PATH, true);
}
void Application::initializeUi() {
@ -910,11 +909,11 @@ void Application::audioMuteToggled() {
}
void Application::aboutApp() {
InfoView::forcedShow(INFO_HELP_PATH);
InfoView::show(INFO_HELP_PATH);
}
void Application::showEditEntitiesHelp() {
InfoView::forcedShow(INFO_EDIT_ENTITIES_PATH);
InfoView::show(INFO_EDIT_ENTITIES_PATH);
}
void Application::resetCamerasOnResizeGL(Camera& camera, int width, int height) {

View file

@ -1,94 +0,0 @@
//
// InfoView.cpp
// interface/src/ui
//
// Created by Stojce Slavkovski on 9/7/13.
// Copyright 2013 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 <QApplication>
#include <QDesktopWidget>
#include <QDesktopServices>
#include <QFileInfo>
#include <QtWebKitWidgets/QWebFrame>
#include <QtWebKit/QWebElement>
#include <PathUtils.h>
#include <SettingHandle.h>
#include "InfoView.h"
static const float MAX_DIALOG_HEIGHT_RATIO = 0.9f;
Setting::Handle<QString> infoVersion("info-version", QString());
InfoView::InfoView(bool forced, QString path) :
_forced(forced)
{
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint);
QString absPath = QFileInfo(PathUtils::resourcesPath() + path).absoluteFilePath();
QUrl url = QUrl::fromLocalFile(absPath);
page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks);
connect(this, SIGNAL(linkClicked(QUrl)), this, SLOT(linkClickedInfoView(QUrl)));
load(url);
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(loaded(bool)));
}
void InfoView::showFirstTime(QString path) {
new InfoView(false, path);
}
void InfoView::forcedShow(QString path) {
new InfoView(true, path);
}
bool InfoView::shouldShow() {
bool shouldShow = false;
if (_forced) {
return true;
}
QString lastVersion = infoVersion.get();
QWebElement versionTag = page()->mainFrame()->findFirstElement("#version");
QString version = versionTag.attribute("value");
if (version != QString::null && (lastVersion == QString::null || lastVersion != version)) {
infoVersion.set(version);
shouldShow = true;
} else {
shouldShow = false;
}
return shouldShow;
}
void InfoView::loaded(bool ok) {
if (!ok || !shouldShow()) {
deleteLater();
return;
}
QDesktopWidget* desktop = qApp->desktop();
QWebFrame* mainFrame = page()->mainFrame();
int height = mainFrame->contentsSize().height() > desktop->height() ?
desktop->height() * MAX_DIALOG_HEIGHT_RATIO :
mainFrame->contentsSize().height();
resize(mainFrame->contentsSize().width(), height);
move(desktop->screen()->rect().center() - rect().center());
setWindowTitle(title());
setAttribute(Qt::WA_DeleteOnClose);
show();
}
void InfoView::linkClickedInfoView(QUrl url) {
close();
QDesktopServices::openUrl(url);
}

View file

@ -1,33 +0,0 @@
//
// InfoView.h
// interface/src/ui
//
// Created by Stojce Slavkovski on 9/7/13.
// Copyright 2013 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_InfoView_h
#define hifi_InfoView_h
#include <QtWebKitWidgets/QWebView>
class InfoView : public QWebView {
Q_OBJECT
public:
static void showFirstTime(QString path);
static void forcedShow(QString path);
private:
InfoView(bool forced, QString path);
bool _forced;
bool shouldShow();
private slots:
void loaded(bool ok);
void linkClickedInfoView(QUrl url);
};
#endif // hifi_InfoView_h

View file

@ -14,7 +14,7 @@
#include <SettingHandle.h>
#include <PathUtils.h>
#include <QXmlQuery>
#include <QDir>
const QUrl InfoView::QML{ "InfoView.qml" };
const QString InfoView::NAME{ "InfoView" };
@ -37,9 +37,19 @@ QString fetchVersion(const QUrl& url) {
return r.trimmed();
}
void InfoView::show(const QString& path, bool forced) {
QUrl url = QUrl::fromLocalFile(path);
if (!forced) {
void InfoView::show(const QString& path, bool firstOrChangedOnly) {
static bool registered{ false };
if (!registered) {
registerType();
registered = true;
}
QUrl url;
if (QDir(path).isRelative()) {
url = QUrl::fromLocalFile(PathUtils::resourcesPath() + path);
} else {
url = QUrl::fromLocalFile(path);
}
if (firstOrChangedOnly) {
const QString lastVersion = infoVersion.get();
// If we have version information stored
if (lastVersion != QString::null) {
@ -54,6 +64,9 @@ void InfoView::show(const QString& path, bool forced) {
auto offscreenUi = DependencyManager::get<OffscreenUi>();
QString infoViewName(NAME + "_" + path);
offscreenUi->show(QML, NAME + "_" + path, [=](QQmlContext* context, QObject* newObject){
QQuickItem* item = dynamic_cast<QQuickItem*>(newObject);
item->setWidth(720);
item->setHeight(720);
InfoView* newInfoView = newObject->findChild<InfoView*>();
Q_ASSERT(newInfoView);
newInfoView->parent()->setObjectName(infoViewName);

View file

@ -22,7 +22,7 @@ class InfoView : public QQuickItem {
static const QString NAME;
public:
static void registerType();
static void show(const QString& path, bool forced = false);
static void show(const QString& path, bool firstOrChangedOnly = false);
InfoView(QQuickItem* parent = nullptr);
QUrl url();