diff options
author | Andy Nichols <andy.nichols@qt.io> | 2018-07-09 14:19:06 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2018-07-26 13:00:46 +0000 |
commit | 1a69613dcd7e414b9928a91229b0c04ee8499f49 (patch) | |
tree | db4309a2d5552e9c1fcfcc834160f4739fd52f05 /tests/manual | |
parent | 56ede8f0f6aacb9eb018717addf53d1adc6e0d1e (diff) |
Update Qt 3D Studio Explorer application
Add many of the feature improvments that are present in the viewer app.
Change-Id: I2c307b4cb05773b3f258f61db07114d22a0bd156
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'tests/manual')
-rw-r--r-- | tests/manual/qt3dsexplorer/main.cpp | 80 | ||||
-rw-r--r-- | tests/manual/qt3dsexplorer/q3dsexplorermainwindow.cpp | 108 | ||||
-rw-r--r-- | tests/manual/qt3dsexplorer/q3dsexplorermainwindow.h | 8 |
3 files changed, 173 insertions, 23 deletions
diff --git a/tests/manual/qt3dsexplorer/main.cpp b/tests/manual/qt3dsexplorer/main.cpp index 0e2b793..90612cd 100644 --- a/tests/manual/qt3dsexplorer/main.cpp +++ b/tests/manual/qt3dsexplorer/main.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2018 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of Qt 3D Studio. @@ -28,15 +28,25 @@ ****************************************************************************/ #include "q3dsexplorermainwindow.h" + #include <QApplication> #include <QCommandLineParser> #include <QFileDialog> + #include <private/q3dsengine_p.h> #include <private/q3dswindow_p.h> #include <private/q3dsutils_p.h> +#include <private/q3dsviewportsettings_p.h> +#include <private/q3dsremotedeploymentmanager_p.h> int main(int argc, char *argv[]) { + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QCoreApplication::setOrganizationName(QStringLiteral("The Qt Company")); + QCoreApplication::setOrganizationDomain(QStringLiteral("qt.io")); + QCoreApplication::setApplicationName(QStringLiteral("Qt 3D Scene Explorer")); + QCoreApplication::setApplicationVersion(QStringLiteral("2.0")); + QApplication app(argc, argv); QSurfaceFormat::setDefaultFormat(Q3DS::surfaceFormat()); @@ -47,20 +57,27 @@ int main(int argc, char *argv[]) cmdLineParser.addOption(msaaOption); QCommandLineOption noProfOption({ "p", "no-profile" }, QObject::tr("Opens presentation without profiling enabled")); cmdLineParser.addOption(noProfOption); + QCommandLineOption remoteOption("port", + QObject::tr("Sets the <port> to listen on in remote connection mode. The default <port> is 36000."), + QObject::tr("port"), QLatin1String("36000")); + cmdLineParser.addOption(remoteOption); + QCommandLineOption autoExitOption({ "x", "exitafter" }, QObject::tr("Exit after <n> seconds."), QObject::tr("n"), QLatin1String("5")); + cmdLineParser.addOption(autoExitOption); + QCommandLineOption scaleModeOption("scalemode", + QObject::tr("Specifies scaling mode.\n" + "The default value is 'center'."), + QObject::tr("center|fit|fill"), + QStringLiteral("center")); + cmdLineParser.addOption(scaleModeOption); + QCommandLineOption matteColorOption("mattecolor", + QObject::tr("Specifies custom matte color\n" + "using #000000 syntax.\n" + "For example, white matte: #ffffff"), + QObject::tr("color"), QStringLiteral("#333333")); + cmdLineParser.addOption(matteColorOption); cmdLineParser.process(app); QStringList fn = cmdLineParser.positionalArguments(); - if (fn.isEmpty()) { - QString fileName = QFileDialog::getOpenFileName(nullptr, QObject::tr("Open"), - QString(), Q3DSExplorerMainWindow::fileFilter()); - if (!fileName.isEmpty()) - fn.append(fileName); - } - - if (fn.isEmpty()) { - Q3DSUtils::showMessage(QObject::tr("No file specified.")); - return 0; - } Q3DSEngine::Flags flags = 0; if (cmdLineParser.isSet(msaaOption)) @@ -69,20 +86,51 @@ int main(int argc, char *argv[]) flags |= Q3DSEngine::EnableProfiling; QScopedPointer<Q3DSEngine> engine(new Q3DSEngine); - engine->setAutoStart(false); QScopedPointer<Q3DSWindow> view(new Q3DSWindow); view->setEngine(engine.data()); engine->setFlags(flags); - if (!engine->setSource(fn.first())) - return 0; + + // Setup Remote Viewer + int port = 36000; + if (cmdLineParser.isSet(remoteOption)) + port = cmdLineParser.value(remoteOption).toInt(); + QScopedPointer<Q3DSRemoteDeploymentManager> remote(new Q3DSRemoteDeploymentManager(engine.data(), port, true)); + if (fn.isEmpty()) { + remote->startServer(); + remote->showConnectionSetup(); + } else { + // Try and set the source for the engine + if (!engine->setSource(fn.first())) + return 0; + } + + // Setup Viewport Settings + Q3DSViewportSettings *viewportSettings = new Q3DSViewportSettings; + engine->setViewportSettings(viewportSettings); + viewportSettings->setMatteEnabled(true); + viewportSettings->setScaleMode(Q3DSViewportSettings::ScaleModeCenter); + if (cmdLineParser.isSet(scaleModeOption)) { + const QString scaleMode = cmdLineParser.value(scaleModeOption); + if (scaleMode == QStringLiteral("center")) + viewportSettings->setScaleMode(Q3DSViewportSettings::ScaleModeCenter); + else if (scaleMode == QStringLiteral("fit")) + viewportSettings->setScaleMode(Q3DSViewportSettings::ScaleModeFit); + else + viewportSettings->setScaleMode(Q3DSViewportSettings::ScaleModeFill); + } + if (cmdLineParser.isSet(matteColorOption)) + viewportSettings->setMatteColor(cmdLineParser.value(matteColorOption)); QScopedPointer<Q3DSExplorerMainWindow> mw; - mw.reset(new Q3DSExplorerMainWindow(view.take())); + mw.reset(new Q3DSExplorerMainWindow(view.take(), remote.data())); mw->show(); int r = app.exec(); // make sure the engine is destroyed before the view (which is owned by mw by now) engine.reset(); +#ifdef Q3DSVIEWER_WIDGETS + delete mw; +#endif return r; } diff --git a/tests/manual/qt3dsexplorer/q3dsexplorermainwindow.cpp b/tests/manual/qt3dsexplorer/q3dsexplorermainwindow.cpp index d2fb28b..9b3a271 100644 --- a/tests/manual/qt3dsexplorer/q3dsexplorermainwindow.cpp +++ b/tests/manual/qt3dsexplorer/q3dsexplorermainwindow.cpp @@ -31,6 +31,8 @@ #include <private/q3dswindow_p.h> #include <private/q3dsengine_p.h> +#include <private/q3dsremotedeploymentmanager_p.h> +#include <private/q3dsviewportsettings_p.h> #include <QApplication> #include <QMenuBar> #include <QMenu> @@ -54,13 +56,15 @@ QString Q3DSExplorerMainWindow::fileFilter() return tr("All Supported Formats (*.uia *.uip);;Studio UI Presentation (*.uip);;Application File (*.uia);;All Files (*)"); } -Q3DSExplorerMainWindow::Q3DSExplorerMainWindow(Q3DSWindow *view, QWidget *parent) +Q3DSExplorerMainWindow::Q3DSExplorerMainWindow(Q3DSWindow *view, Q3DSRemoteDeploymentManager *remote, QWidget *parent) : QMainWindow(parent) , m_view(view) { QWidget *wrapper = QWidget::createWindowContainer(view); setCentralWidget(wrapper); + connect(view->engine(), &Q3DSEngine::presentationLoaded, this, &Q3DSExplorerMainWindow::updatePresentation); + // Add Dock Widgets auto slideDockWidget = new QDockWidget("Presentation", this); m_slideExplorer = new SlideExplorerWidget(slideDockWidget); @@ -85,12 +89,21 @@ Q3DSExplorerMainWindow::Q3DSExplorerMainWindow(Q3DSWindow *view, QWidget *parent QString fn = QFileDialog::getOpenFileName(this, tr("Open"), QString(), fileFilter()); if (!fn.isEmpty()) { view->engine()->setSource(fn); - updatePresentation(); + if (remote) + remote->setState(Q3DSRemoteDeploymentManager::LocalProject); } }, QKeySequence::Open); + if (remote) + fileMenu->addAction(tr("Remote Setup"), this, [remote] { + remote->showConnectionSetup(); + }); fileMenu->addAction(tr("&Reload"), this, [=] { + // Don't reload if on the ConnectionInfo screen + if (remote && + remote->state() != Q3DSRemoteDeploymentManager::LocalProject && + remote->state() != Q3DSRemoteDeploymentManager::RemoteProject) + return; view->engine()->setSource(view->engine()->source()); - updatePresentation(); }, QKeySequence::Refresh); fileMenu->addAction(tr("E&xit"), this, &QWidget::close); @@ -108,6 +121,70 @@ Q3DSExplorerMainWindow::Q3DSExplorerMainWindow(Q3DSWindow *view, QWidget *parent wrapper->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); } }); + QAction *showMatte = viewMenu->addAction(tr("Show Matte")); + addAction(showMatte); + showMatte->setCheckable(true); + showMatte->setChecked(view->engine()->viewportSettings()->matteEnabled()); + showMatte->setShortcut(QKeySequence(tr("Ctrl+D"))); + connect(showMatte, &QAction::toggled, [=]() { + view->engine()->viewportSettings()->setMatteEnabled(showMatte->isChecked()); + }); + QAction *scaleModeAction = new QAction(tr("Scale Mode")); + addAction(scaleModeAction); + scaleModeAction->setShortcut(QKeySequence(tr("Ctrl+Shift+S"))); + QMenu *scaleModeMenu = new QMenu(); + scaleModeAction->setMenu(scaleModeMenu); + QAction *scaleModeCenter = new QAction(tr("Center")); + scaleModeCenter->setCheckable(true); + scaleModeCenter->setChecked(view->engine()->viewportSettings()->scaleMode() == Q3DSViewportSettings::ScaleModeCenter); + scaleModeMenu->addAction(scaleModeCenter); + + QAction *scaleModeFit = new QAction(tr("Scale to Fit")); + scaleModeFit->setCheckable(true); + scaleModeFit->setChecked(view->engine()->viewportSettings()->scaleMode() == Q3DSViewportSettings::ScaleModeFit); + scaleModeMenu->addAction(scaleModeFit); + + QAction *scaleModeFill = new QAction(tr("Scale to Fill")); + scaleModeFill->setCheckable(true); + scaleModeFill->setChecked(view->engine()->viewportSettings()->scaleMode() == Q3DSViewportSettings::ScaleModeFill); + scaleModeMenu->addAction(scaleModeFill); + + connect(scaleModeFit, &QAction::triggered, [=]() { + view->engine()->viewportSettings()->setScaleMode(Q3DSViewportSettings::ScaleModeFit); + scaleModeCenter->setChecked(false); + scaleModeFill->setChecked(false); + scaleModeFit->setChecked(true); + }); + connect(scaleModeCenter, &QAction::triggered, [=]() { + view->engine()->viewportSettings()->setScaleMode(Q3DSViewportSettings::ScaleModeCenter); + scaleModeCenter->setChecked(true); + scaleModeFill->setChecked(false); + scaleModeFit->setChecked(false); + }); + connect(scaleModeFill, &QAction::triggered, [=]() { + view->engine()->viewportSettings()->setScaleMode(Q3DSViewportSettings::ScaleModeFill); + scaleModeCenter->setChecked(false); + scaleModeFill->setChecked(true); + scaleModeFit->setChecked(false); + }); + connect(scaleModeAction, &QAction::triggered, [=]() { + // toggle between the 3 scale modes + if (scaleModeCenter->isChecked()) { + scaleModeCenter->setChecked(false); + scaleModeFit->setChecked(true); + view->engine()->viewportSettings()->setScaleMode(Q3DSViewportSettings::ScaleModeFit); + } else if (scaleModeFit->isChecked()) { + scaleModeFit->setChecked(false); + scaleModeFill->setChecked(true); + view->engine()->viewportSettings()->setScaleMode(Q3DSViewportSettings::ScaleModeFill); + } else { + scaleModeFill->setChecked(false); + scaleModeCenter->setChecked(true); + view->engine()->viewportSettings()->setScaleMode(Q3DSViewportSettings::ScaleModeCenter); + } + }); + + viewMenu->addMenu(scaleModeMenu); QAction *renderOnDemand = viewMenu->addAction(tr("&Render on demand only")); renderOnDemand->setCheckable(true); @@ -126,10 +203,33 @@ Q3DSExplorerMainWindow::Q3DSExplorerMainWindow(Q3DSWindow *view, QWidget *parent else qDeleteAll(p); }); + QMenu *profileSubMenu = new QMenu(tr("&Profile and Debug")); + QAction *showDebugView = profileSubMenu->addAction(tr("Toggle in-scene &debug view"), this, [view] { + Q3DSEngine *engine = view->engine(); + engine->setProfileUiVisible(!engine->isProfileUiVisible()); + }, Qt::Key_F10); + addAction(showDebugView); + QAction *showConsole = profileSubMenu->addAction(tr("Toggle &console"), this, [view] { + view->requestActivate(); // get key events flowing right away even without any click + Q3DSEngine *engine = view->engine(); + engine->setProfileUiVisible(!engine->isProfileUiVisible(), true); + }, Qt::Key_QuoteLeft); + addAction(showConsole); + QAction *scaleUpDebugView = profileSubMenu->addAction(tr("Scale in-scene debug view up"), this, [view] { + Q3DSEngine *engine = view->engine(); + engine->configureProfileUi(engine->profileUiScaleFactor() + 0.2f); + }, QKeySequence(QLatin1String("Ctrl+F10"))); + addAction(scaleUpDebugView); + QAction *scaleDownDebugView = profileSubMenu->addAction(tr("Scale in-scene debug view down"), this, [view] { + Q3DSEngine *engine = view->engine(); + engine->configureProfileUi(engine->profileUiScaleFactor() - 0.2f); + }, QKeySequence(QLatin1String("Alt+F10"))); + addAction(scaleDownDebugView); + devMenu->addMenu(profileSubMenu); QMenu *helpMenu = menuBar()->addMenu(tr("&Help")); helpMenu->addAction(tr("&About"), this, [this]() { - QMessageBox::about(this, tr("About q3dsviewer"), tr("Qt 3D Studio Viewer 2.0")); + QMessageBox::about(this, tr("About q3dsexplorer"), tr("Qt 3D Studio Explorer 2.0")); }); helpMenu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt); diff --git a/tests/manual/qt3dsexplorer/q3dsexplorermainwindow.h b/tests/manual/qt3dsexplorer/q3dsexplorermainwindow.h index 15d9324..ec38d5a 100644 --- a/tests/manual/qt3dsexplorer/q3dsexplorermainwindow.h +++ b/tests/manual/qt3dsexplorer/q3dsexplorermainwindow.h @@ -39,18 +39,20 @@ class SlideExplorerWidget; class SceneExplorerWidget; class Q3DSComponentNode; class ManualPresentationTest; +class Q3DSRemoteDeploymentManager; class Q3DSExplorerMainWindow : public QMainWindow { Q_OBJECT public: - explicit Q3DSExplorerMainWindow(Q3DSWindow *view, QWidget *parent = 0); + explicit Q3DSExplorerMainWindow(Q3DSWindow *view, Q3DSRemoteDeploymentManager *remote = nullptr, QWidget *parent = 0); ~Q3DSExplorerMainWindow(); - void updatePresentation(); - static QString fileFilter(); +public Q_SLOTS: + void updatePresentation(); + private Q_SLOTS: void handleComponentSelected(Q3DSComponentNode *component); |