mirror of
https://github.com/overte-org/overte.git
synced 2025-08-11 04:18:35 +02:00
Move dock window to ToolWindow
This commit is contained in:
parent
3658d65028
commit
604b1b620b
5 changed files with 131 additions and 4 deletions
|
@ -373,7 +373,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
||||||
// enable mouse tracking; otherwise, we only get drag events
|
// enable mouse tracking; otherwise, we only get drag events
|
||||||
_glWidget->setMouseTracking(true);
|
_glWidget->setMouseTracking(true);
|
||||||
|
|
||||||
_toolWindow = new QMainWindow();
|
_toolWindow = new ToolWindow();
|
||||||
_toolWindow->setWindowFlags(_toolWindow->windowFlags() | Qt::WindowStaysOnTopHint);
|
_toolWindow->setWindowFlags(_toolWindow->windowFlags() | Qt::WindowStaysOnTopHint);
|
||||||
_toolWindow->setWindowTitle("Tools");
|
_toolWindow->setWindowTitle("Tools");
|
||||||
|
|
||||||
|
|
|
@ -82,6 +82,7 @@
|
||||||
#include "ui/overlays/Overlays.h"
|
#include "ui/overlays/Overlays.h"
|
||||||
#include "ui/ApplicationOverlay.h"
|
#include "ui/ApplicationOverlay.h"
|
||||||
#include "ui/RunningScriptsWidget.h"
|
#include "ui/RunningScriptsWidget.h"
|
||||||
|
#include "ui/ToolWindow.h"
|
||||||
#include "ui/VoxelImportDialog.h"
|
#include "ui/VoxelImportDialog.h"
|
||||||
#include "voxels/VoxelFade.h"
|
#include "voxels/VoxelFade.h"
|
||||||
#include "voxels/VoxelHideShowThread.h"
|
#include "voxels/VoxelHideShowThread.h"
|
||||||
|
@ -246,7 +247,7 @@ public:
|
||||||
void lockOctreeSceneStats() { _octreeSceneStatsLock.lockForRead(); }
|
void lockOctreeSceneStats() { _octreeSceneStatsLock.lockForRead(); }
|
||||||
void unlockOctreeSceneStats() { _octreeSceneStatsLock.unlock(); }
|
void unlockOctreeSceneStats() { _octreeSceneStatsLock.unlock(); }
|
||||||
|
|
||||||
QMainWindow* getToolWindow() { return _toolWindow ; }
|
ToolWindow* getToolWindow() { return _toolWindow ; }
|
||||||
|
|
||||||
GeometryCache* getGeometryCache() { return &_geometryCache; }
|
GeometryCache* getGeometryCache() { return &_geometryCache; }
|
||||||
AnimationCache* getAnimationCache() { return &_animationCache; }
|
AnimationCache* getAnimationCache() { return &_animationCache; }
|
||||||
|
@ -461,7 +462,7 @@ private:
|
||||||
MainWindow* _window;
|
MainWindow* _window;
|
||||||
GLCanvas* _glWidget; // our GLCanvas has a couple extra features
|
GLCanvas* _glWidget; // our GLCanvas has a couple extra features
|
||||||
|
|
||||||
QMainWindow* _toolWindow;
|
ToolWindow* _toolWindow;
|
||||||
|
|
||||||
BandwidthMeter _bandwidthMeter;
|
BandwidthMeter _bandwidthMeter;
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ WebWindowClass::WebWindowClass(const QString& title, const QString& url, int wid
|
||||||
: QObject(NULL),
|
: QObject(NULL),
|
||||||
_eventBridge(new ScriptEventBridge(this)) {
|
_eventBridge(new ScriptEventBridge(this)) {
|
||||||
|
|
||||||
QMainWindow* toolWindow = Application::getInstance()->getToolWindow();
|
ToolWindow* toolWindow = Application::getInstance()->getToolWindow();
|
||||||
|
|
||||||
_dockWidget = new QDockWidget(title, toolWindow);
|
_dockWidget = new QDockWidget(title, toolWindow);
|
||||||
_dockWidget->setFeatures(QDockWidget::DockWidgetMovable);
|
_dockWidget->setFeatures(QDockWidget::DockWidgetMovable);
|
||||||
|
@ -55,6 +55,10 @@ WebWindowClass::~WebWindowClass() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebWindowClass::setVisible(bool visible) {
|
void WebWindowClass::setVisible(bool visible) {
|
||||||
|
if (visible) {
|
||||||
|
QMetaObject::invokeMethod(
|
||||||
|
Application::getInstance()->getToolWindow(), "setVisible", Qt::BlockingQueuedConnection, Q_ARG(bool, visible));
|
||||||
|
}
|
||||||
QMetaObject::invokeMethod(_dockWidget, "setVisible", Qt::BlockingQueuedConnection, Q_ARG(bool, visible));
|
QMetaObject::invokeMethod(_dockWidget, "setVisible", Qt::BlockingQueuedConnection, Q_ARG(bool, visible));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
82
interface/src/ui/ToolWindow.cpp
Normal file
82
interface/src/ui/ToolWindow.cpp
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
//
|
||||||
|
// ToolWindow.cpp
|
||||||
|
// interface/src/ui
|
||||||
|
//
|
||||||
|
// Created by Ryan Huffman on 11/13/14.
|
||||||
|
// Copyright 2014 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 "Application.h"
|
||||||
|
#include "ToolWindow.h"
|
||||||
|
#include "UIUtil.h"
|
||||||
|
|
||||||
|
const int DEFAULT_WIDTH = 300;
|
||||||
|
|
||||||
|
ToolWindow::ToolWindow(QWidget* parent) :
|
||||||
|
QMainWindow(parent),
|
||||||
|
_hasShown(false),
|
||||||
|
_lastGeometry() {
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ToolWindow::event(QEvent* event) {
|
||||||
|
QEvent::Type type = event->type();
|
||||||
|
if (type == QEvent::Show) {
|
||||||
|
if (!_hasShown) {
|
||||||
|
_hasShown = true;
|
||||||
|
|
||||||
|
QMainWindow* mainWindow = Application::getInstance()->getWindow();
|
||||||
|
QRect mainGeometry = mainWindow->geometry();
|
||||||
|
|
||||||
|
int titleBarHeight = UIUtil::getWindowTitleBarHeight(this);
|
||||||
|
int menuBarHeight = Menu::getInstance()->geometry().height();
|
||||||
|
int topMargin = titleBarHeight + menuBarHeight;
|
||||||
|
|
||||||
|
_lastGeometry = QRect(mainGeometry.topLeft().x(), mainGeometry.topLeft().y() + topMargin,
|
||||||
|
DEFAULT_WIDTH, mainGeometry.height() - topMargin);
|
||||||
|
}
|
||||||
|
setGeometry(_lastGeometry);
|
||||||
|
return true;
|
||||||
|
} else if (type == QEvent::Hide) {
|
||||||
|
_lastGeometry = geometry();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QMainWindow::event(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ToolWindow::onChildVisibilityUpdated(bool visible) {
|
||||||
|
if (visible) {
|
||||||
|
setVisible(true);
|
||||||
|
} else {
|
||||||
|
bool hasVisible = false;
|
||||||
|
QList<QDockWidget*> dockWidgets = findChildren<QDockWidget*>();
|
||||||
|
for (int i = 0; i < dockWidgets.count(); i++) {
|
||||||
|
if (dockWidgets[i]->isVisible()) {
|
||||||
|
hasVisible = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setVisible(hasVisible);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ToolWindow::addDockWidget(Qt::DockWidgetArea area, QDockWidget* dockWidget) {
|
||||||
|
QMainWindow::addDockWidget(area, dockWidget);
|
||||||
|
|
||||||
|
connect(dockWidget, &QDockWidget::visibilityChanged, this, &ToolWindow::onChildVisibilityUpdated);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ToolWindow::addDockWidget(Qt::DockWidgetArea area, QDockWidget* dockWidget, Qt::Orientation orientation) {
|
||||||
|
QMainWindow::addDockWidget(area, dockWidget, orientation);
|
||||||
|
|
||||||
|
connect(dockWidget, &QDockWidget::visibilityChanged, this, &ToolWindow::onChildVisibilityUpdated);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ToolWindow::removeDockWidget(QDockWidget* dockWidget) {
|
||||||
|
QMainWindow::removeDockWidget(dockWidget);
|
||||||
|
|
||||||
|
disconnect(dockWidget, &QDockWidget::visibilityChanged, this, &ToolWindow::onChildVisibilityUpdated);
|
||||||
|
}
|
40
interface/src/ui/ToolWindow.h
Normal file
40
interface/src/ui/ToolWindow.h
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
//
|
||||||
|
// ToolWindow.h
|
||||||
|
// interface/src/ui
|
||||||
|
//
|
||||||
|
// Created by Ryan Huffman on 11/13/14.
|
||||||
|
// Copyright 2014 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_ToolWindow_h
|
||||||
|
#define hifi_ToolWindow_h
|
||||||
|
|
||||||
|
#include <QDockWidget>
|
||||||
|
#include <QEvent>
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QRect>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
class ToolWindow : public QMainWindow {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
ToolWindow(QWidget* parent = NULL);
|
||||||
|
|
||||||
|
virtual bool event(QEvent* event);
|
||||||
|
virtual void addDockWidget(Qt::DockWidgetArea area, QDockWidget* dockWidget);
|
||||||
|
virtual void addDockWidget(Qt::DockWidgetArea area, QDockWidget* dockWidget, Qt::Orientation orientation);
|
||||||
|
virtual void removeDockWidget(QDockWidget* dockWidget);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void onChildVisibilityUpdated(bool visible);
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool _hasShown;
|
||||||
|
QRect _lastGeometry;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_ToolWindow_h
|
Loading…
Reference in a new issue