2022-12-18 14:19:04 +00:00
|
|
|
/*##############################################################################
|
|
|
|
## Author: Shaun Reed ##
|
2023-01-02 03:26:58 +00:00
|
|
|
## Legal: All Content (c) 2023 Shaun Reed, all rights reserved ##
|
2022-12-18 14:19:04 +00:00
|
|
|
## About: MainWindow for Qtk application ##
|
|
|
|
## ##
|
|
|
|
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
|
|
|
##############################################################################*/
|
|
|
|
|
|
|
|
#include "qtkmainwindow.h"
|
2023-01-15 00:01:34 +00:00
|
|
|
#include "examplescene.h"
|
2022-12-18 14:19:04 +00:00
|
|
|
#include "ui_qtkmainwindow.h"
|
|
|
|
|
|
|
|
MainWindow * MainWindow::mainWindow_ = Q_NULLPTR;
|
|
|
|
|
2023-01-02 03:26:58 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* Constructors / Destructors
|
|
|
|
******************************************************************************/
|
|
|
|
|
2022-12-18 14:19:04 +00:00
|
|
|
MainWindow::MainWindow(QWidget * parent) : QMainWindow(parent) {
|
|
|
|
ui_ = new Ui::MainWindow;
|
|
|
|
setObjectName("MainWindow");
|
|
|
|
// For use in design mode using Qt Creator
|
|
|
|
// + We can use the `ui` member to access nested widgets by name
|
|
|
|
ui_->setupUi(this);
|
|
|
|
ui_->menuView->addAction(ui_->toolBar->toggleViewAction());
|
|
|
|
|
|
|
|
// Initialize static container for all active QtkWidgets
|
|
|
|
auto qtkWidgets = findChildren<Qtk::QtkWidget *>();
|
|
|
|
for(auto & qtkWidget : qtkWidgets) {
|
|
|
|
qtkWidget->setScene(new ExampleScene);
|
|
|
|
views_.emplace(qtkWidget->getScene()->getSceneName(), qtkWidget);
|
|
|
|
ui_->menuView->addAction(qtkWidget->getActionToggleConsole());
|
|
|
|
connect(
|
|
|
|
qtkWidget->getScene(), &Qtk::Scene::sceneUpdated, this,
|
|
|
|
&MainWindow::refreshScene);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto docks = findChildren<QDockWidget *>();
|
|
|
|
for(auto & dock : docks) {
|
|
|
|
addDockWidget(Qt::RightDockWidgetArea, dock);
|
|
|
|
ui_->menuView->addAction(dock->toggleViewAction());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the window icon used for Qtk.
|
|
|
|
setWindowIcon(Qtk::getIcon());
|
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow() {
|
|
|
|
delete ui_;
|
|
|
|
}
|
|
|
|
|
2023-01-02 03:26:58 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* Public Methods
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
MainWindow * MainWindow::getMainWindow() {
|
|
|
|
if(mainWindow_ == Q_NULLPTR) {
|
|
|
|
mainWindow_ = new MainWindow;
|
|
|
|
}
|
|
|
|
return mainWindow_;
|
|
|
|
}
|
|
|
|
|
|
|
|
Qtk::QtkWidget * MainWindow::getQtkWidget(const QString & name) {
|
|
|
|
if(!views_.count(name)) {
|
|
|
|
return Q_NULLPTR;
|
|
|
|
}
|
|
|
|
return views_[name];
|
|
|
|
}
|
|
|
|
|
2022-12-18 14:19:04 +00:00
|
|
|
void MainWindow::refreshScene(QString sceneName) {
|
2023-01-02 03:26:58 +00:00
|
|
|
// TODO: Select TreeView using sceneName>
|
2022-12-18 14:19:04 +00:00
|
|
|
ui_->qtk__TreeView->updateView(getQtkWidget(sceneName)->getScene());
|
|
|
|
}
|